bfd_section_* macros
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994-2019 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
36 #ifdef OBJ_ELF
37 #include "elf/arm.h"
38 #include "dw2gencfi.h"
39 #endif
40
41 #include "dwarf2dbg.h"
42
43 #ifdef OBJ_ELF
44 /* Must be at least the size of the largest unwind opcode (currently two). */
45 #define ARM_OPCODE_CHUNK_SIZE 8
46
47 /* This structure holds the unwinding state. */
48
49 static struct
50 {
51 symbolS * proc_start;
52 symbolS * table_entry;
53 symbolS * personality_routine;
54 int personality_index;
55 /* The segment containing the function. */
56 segT saved_seg;
57 subsegT saved_subseg;
58 /* Opcodes generated from this function. */
59 unsigned char * opcodes;
60 int opcode_count;
61 int opcode_alloc;
62 /* The number of bytes pushed to the stack. */
63 offsetT frame_size;
64 /* We don't add stack adjustment opcodes immediately so that we can merge
65 multiple adjustments. We can also omit the final adjustment
66 when using a frame pointer. */
67 offsetT pending_offset;
68 /* These two fields are set by both unwind_movsp and unwind_setfp. They
69 hold the reg+offset to use when restoring sp from a frame pointer. */
70 offsetT fp_offset;
71 int fp_reg;
72 /* Nonzero if an unwind_setfp directive has been seen. */
73 unsigned fp_used:1;
74 /* Nonzero if the last opcode restores sp from fp_reg. */
75 unsigned sp_restored:1;
76 } unwind;
77
78 /* Whether --fdpic was given. */
79 static int arm_fdpic;
80
81 #endif /* OBJ_ELF */
82
83 /* Results from operand parsing worker functions. */
84
85 typedef enum
86 {
87 PARSE_OPERAND_SUCCESS,
88 PARSE_OPERAND_FAIL,
89 PARSE_OPERAND_FAIL_NO_BACKTRACK
90 } parse_operand_result;
91
92 enum arm_float_abi
93 {
94 ARM_FLOAT_ABI_HARD,
95 ARM_FLOAT_ABI_SOFTFP,
96 ARM_FLOAT_ABI_SOFT
97 };
98
99 /* Types of processor to assemble for. */
100 #ifndef CPU_DEFAULT
101 /* The code that was here used to select a default CPU depending on compiler
102 pre-defines which were only present when doing native builds, thus
103 changing gas' default behaviour depending upon the build host.
104
105 If you have a target that requires a default CPU option then the you
106 should define CPU_DEFAULT here. */
107 #endif
108
109 #ifndef FPU_DEFAULT
110 # ifdef TE_LINUX
111 # define FPU_DEFAULT FPU_ARCH_FPA
112 # elif defined (TE_NetBSD)
113 # ifdef OBJ_ELF
114 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115 # else
116 /* Legacy a.out format. */
117 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118 # endif
119 # elif defined (TE_VXWORKS)
120 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
121 # else
122 /* For backwards compatibility, default to FPA. */
123 # define FPU_DEFAULT FPU_ARCH_FPA
124 # endif
125 #endif /* ifndef FPU_DEFAULT */
126
127 #define streq(a, b) (strcmp (a, b) == 0)
128
129 /* Current set of feature bits available (CPU+FPU). Different from
130 selected_cpu + selected_fpu in case of autodetection since the CPU
131 feature bits are then all set. */
132 static arm_feature_set cpu_variant;
133 /* Feature bits used in each execution state. Used to set build attribute
134 (in particular Tag_*_ISA_use) in CPU autodetection mode. */
135 static arm_feature_set arm_arch_used;
136 static arm_feature_set thumb_arch_used;
137
138 /* Flags stored in private area of BFD structure. */
139 static int uses_apcs_26 = FALSE;
140 static int atpcs = FALSE;
141 static int support_interwork = FALSE;
142 static int uses_apcs_float = FALSE;
143 static int pic_code = FALSE;
144 static int fix_v4bx = FALSE;
145 /* Warn on using deprecated features. */
146 static int warn_on_deprecated = TRUE;
147
148 /* Understand CodeComposer Studio assembly syntax. */
149 bfd_boolean codecomposer_syntax = FALSE;
150
151 /* Variables that we set while parsing command-line options. Once all
152 options have been read we re-process these values to set the real
153 assembly flags. */
154
155 /* CPU and FPU feature bits set for legacy CPU and FPU options (eg. -marm1
156 instead of -mcpu=arm1). */
157 static const arm_feature_set *legacy_cpu = NULL;
158 static const arm_feature_set *legacy_fpu = NULL;
159
160 /* CPU, extension and FPU feature bits selected by -mcpu. */
161 static const arm_feature_set *mcpu_cpu_opt = NULL;
162 static arm_feature_set *mcpu_ext_opt = NULL;
163 static const arm_feature_set *mcpu_fpu_opt = NULL;
164
165 /* CPU, extension and FPU feature bits selected by -march. */
166 static const arm_feature_set *march_cpu_opt = NULL;
167 static arm_feature_set *march_ext_opt = NULL;
168 static const arm_feature_set *march_fpu_opt = NULL;
169
170 /* Feature bits selected by -mfpu. */
171 static const arm_feature_set *mfpu_opt = NULL;
172
173 /* Constants for known architecture features. */
174 static const arm_feature_set fpu_default = FPU_DEFAULT;
175 static const arm_feature_set fpu_arch_vfp_v1 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V1;
176 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
177 static const arm_feature_set fpu_arch_vfp_v3 ATTRIBUTE_UNUSED = FPU_ARCH_VFP_V3;
178 static const arm_feature_set fpu_arch_neon_v1 ATTRIBUTE_UNUSED = FPU_ARCH_NEON_V1;
179 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
180 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
181 #ifdef OBJ_ELF
182 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
183 #endif
184 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
185
186 #ifdef CPU_DEFAULT
187 static const arm_feature_set cpu_default = CPU_DEFAULT;
188 #endif
189
190 static const arm_feature_set arm_ext_v1 = ARM_FEATURE_CORE_LOW (ARM_EXT_V1);
191 static const arm_feature_set arm_ext_v2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V2);
192 static const arm_feature_set arm_ext_v2s = ARM_FEATURE_CORE_LOW (ARM_EXT_V2S);
193 static const arm_feature_set arm_ext_v3 = ARM_FEATURE_CORE_LOW (ARM_EXT_V3);
194 static const arm_feature_set arm_ext_v3m = ARM_FEATURE_CORE_LOW (ARM_EXT_V3M);
195 static const arm_feature_set arm_ext_v4 = ARM_FEATURE_CORE_LOW (ARM_EXT_V4);
196 static const arm_feature_set arm_ext_v4t = ARM_FEATURE_CORE_LOW (ARM_EXT_V4T);
197 static const arm_feature_set arm_ext_v5 = ARM_FEATURE_CORE_LOW (ARM_EXT_V5);
198 static const arm_feature_set arm_ext_v4t_5 =
199 ARM_FEATURE_CORE_LOW (ARM_EXT_V4T | ARM_EXT_V5);
200 static const arm_feature_set arm_ext_v5t = ARM_FEATURE_CORE_LOW (ARM_EXT_V5T);
201 static const arm_feature_set arm_ext_v5e = ARM_FEATURE_CORE_LOW (ARM_EXT_V5E);
202 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP);
203 static const arm_feature_set arm_ext_v5j = ARM_FEATURE_CORE_LOW (ARM_EXT_V5J);
204 static const arm_feature_set arm_ext_v6 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6);
205 static const arm_feature_set arm_ext_v6k = ARM_FEATURE_CORE_LOW (ARM_EXT_V6K);
206 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE_CORE_LOW (ARM_EXT_V6T2);
207 /* Only for compatability of hint instructions. */
208 static const arm_feature_set arm_ext_v6k_v6t2 =
209 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K | ARM_EXT_V6T2);
210 static const arm_feature_set arm_ext_v6_notm =
211 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
212 static const arm_feature_set arm_ext_v6_dsp =
213 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
214 static const arm_feature_set arm_ext_barrier =
215 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
216 static const arm_feature_set arm_ext_msr =
217 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
218 static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
219 static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
220 static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
221 static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
222 #ifdef OBJ_ELF
223 static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
224 #endif
225 static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
226 static const arm_feature_set arm_ext_m =
227 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
228 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
229 static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
230 static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
231 static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
232 static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
233 static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
234 static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
235 static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
236 static const arm_feature_set arm_ext_v8m_main =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
238 static const arm_feature_set arm_ext_v8_1m_main =
239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_1M_MAIN);
240 /* Instructions in ARMv8-M only found in M profile architectures. */
241 static const arm_feature_set arm_ext_v8m_m_only =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
243 static const arm_feature_set arm_ext_v6t2_v8m =
244 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
245 /* Instructions shared between ARMv8-A and ARMv8-M. */
246 static const arm_feature_set arm_ext_atomics =
247 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
248 #ifdef OBJ_ELF
249 /* DSP instructions Tag_DSP_extension refers to. */
250 static const arm_feature_set arm_ext_dsp =
251 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
252 #endif
253 static const arm_feature_set arm_ext_ras =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
255 /* FP16 instructions. */
256 static const arm_feature_set arm_ext_fp16 =
257 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
258 static const arm_feature_set arm_ext_fp16_fml =
259 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
260 static const arm_feature_set arm_ext_v8_2 =
261 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
262 static const arm_feature_set arm_ext_v8_3 =
263 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
264 static const arm_feature_set arm_ext_sb =
265 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB);
266 static const arm_feature_set arm_ext_predres =
267 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES);
268
269 static const arm_feature_set arm_arch_any = ARM_ANY;
270 #ifdef OBJ_ELF
271 static const arm_feature_set fpu_any = FPU_ANY;
272 #endif
273 static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
274 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
275 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
276
277 static const arm_feature_set arm_cext_iwmmxt2 =
278 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
279 static const arm_feature_set arm_cext_iwmmxt =
280 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
281 static const arm_feature_set arm_cext_xscale =
282 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
283 static const arm_feature_set arm_cext_maverick =
284 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
285 static const arm_feature_set fpu_fpa_ext_v1 =
286 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
287 static const arm_feature_set fpu_fpa_ext_v2 =
288 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
289 static const arm_feature_set fpu_vfp_ext_v1xd =
290 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
291 static const arm_feature_set fpu_vfp_ext_v1 =
292 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
293 static const arm_feature_set fpu_vfp_ext_v2 =
294 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
295 static const arm_feature_set fpu_vfp_ext_v3xd =
296 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
297 static const arm_feature_set fpu_vfp_ext_v3 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
299 static const arm_feature_set fpu_vfp_ext_d32 =
300 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
301 static const arm_feature_set fpu_neon_ext_v1 =
302 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
303 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
304 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
305 static const arm_feature_set mve_ext =
306 ARM_FEATURE_COPROC (FPU_MVE);
307 static const arm_feature_set mve_fp_ext =
308 ARM_FEATURE_COPROC (FPU_MVE_FP);
309 #ifdef OBJ_ELF
310 static const arm_feature_set fpu_vfp_fp16 =
311 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
312 static const arm_feature_set fpu_neon_ext_fma =
313 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
314 #endif
315 static const arm_feature_set fpu_vfp_ext_fma =
316 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
317 static const arm_feature_set fpu_vfp_ext_armv8 =
318 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
319 static const arm_feature_set fpu_vfp_ext_armv8xd =
320 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
321 static const arm_feature_set fpu_neon_ext_armv8 =
322 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
323 static const arm_feature_set fpu_crypto_ext_armv8 =
324 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
325 static const arm_feature_set crc_ext_armv8 =
326 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
327 static const arm_feature_set fpu_neon_ext_v8_1 =
328 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
329 static const arm_feature_set fpu_neon_ext_dotprod =
330 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
331
332 static int mfloat_abi_opt = -1;
333 /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
334 directive. */
335 static arm_feature_set selected_arch = ARM_ARCH_NONE;
336 /* Extension feature bits selected by the last -mcpu/-march or .arch_extension
337 directive. */
338 static arm_feature_set selected_ext = ARM_ARCH_NONE;
339 /* Feature bits selected by the last -mcpu/-march or by the combination of the
340 last .cpu/.arch directive .arch_extension directives since that
341 directive. */
342 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
343 /* FPU feature bits selected by the last -mfpu or .fpu directive. */
344 static arm_feature_set selected_fpu = FPU_NONE;
345 /* Feature bits selected by the last .object_arch directive. */
346 static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
347 /* Must be long enough to hold any of the names in arm_cpus. */
348 static char selected_cpu_name[20];
349
350 extern FLONUM_TYPE generic_floating_point_number;
351
352 /* Return if no cpu was selected on command-line. */
353 static bfd_boolean
354 no_cpu_selected (void)
355 {
356 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
357 }
358
359 #ifdef OBJ_ELF
360 # ifdef EABI_DEFAULT
361 static int meabi_flags = EABI_DEFAULT;
362 # else
363 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
364 # endif
365
366 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
367
368 bfd_boolean
369 arm_is_eabi (void)
370 {
371 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
372 }
373 #endif
374
375 #ifdef OBJ_ELF
376 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
377 symbolS * GOT_symbol;
378 #endif
379
380 /* 0: assemble for ARM,
381 1: assemble for Thumb,
382 2: assemble for Thumb even though target CPU does not support thumb
383 instructions. */
384 static int thumb_mode = 0;
385 /* A value distinct from the possible values for thumb_mode that we
386 can use to record whether thumb_mode has been copied into the
387 tc_frag_data field of a frag. */
388 #define MODE_RECORDED (1 << 4)
389
390 /* Specifies the intrinsic IT insn behavior mode. */
391 enum implicit_it_mode
392 {
393 IMPLICIT_IT_MODE_NEVER = 0x00,
394 IMPLICIT_IT_MODE_ARM = 0x01,
395 IMPLICIT_IT_MODE_THUMB = 0x02,
396 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
397 };
398 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
399
400 /* If unified_syntax is true, we are processing the new unified
401 ARM/Thumb syntax. Important differences from the old ARM mode:
402
403 - Immediate operands do not require a # prefix.
404 - Conditional affixes always appear at the end of the
405 instruction. (For backward compatibility, those instructions
406 that formerly had them in the middle, continue to accept them
407 there.)
408 - The IT instruction may appear, and if it does is validated
409 against subsequent conditional affixes. It does not generate
410 machine code.
411
412 Important differences from the old Thumb mode:
413
414 - Immediate operands do not require a # prefix.
415 - Most of the V6T2 instructions are only available in unified mode.
416 - The .N and .W suffixes are recognized and honored (it is an error
417 if they cannot be honored).
418 - All instructions set the flags if and only if they have an 's' affix.
419 - Conditional affixes may be used. They are validated against
420 preceding IT instructions. Unlike ARM mode, you cannot use a
421 conditional affix except in the scope of an IT instruction. */
422
423 static bfd_boolean unified_syntax = FALSE;
424
425 /* An immediate operand can start with #, and ld*, st*, pld operands
426 can contain [ and ]. We need to tell APP not to elide whitespace
427 before a [, which can appear as the first operand for pld.
428 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
429 const char arm_symbol_chars[] = "#[]{}";
430
431 enum neon_el_type
432 {
433 NT_invtype,
434 NT_untyped,
435 NT_integer,
436 NT_float,
437 NT_poly,
438 NT_signed,
439 NT_unsigned
440 };
441
442 struct neon_type_el
443 {
444 enum neon_el_type type;
445 unsigned size;
446 };
447
448 #define NEON_MAX_TYPE_ELS 4
449
450 struct neon_type
451 {
452 struct neon_type_el el[NEON_MAX_TYPE_ELS];
453 unsigned elems;
454 };
455
456 enum pred_instruction_type
457 {
458 OUTSIDE_PRED_INSN,
459 INSIDE_VPT_INSN,
460 INSIDE_IT_INSN,
461 INSIDE_IT_LAST_INSN,
462 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
463 if inside, should be the last one. */
464 NEUTRAL_IT_INSN, /* This could be either inside or outside,
465 i.e. BKPT and NOP. */
466 IT_INSN, /* The IT insn has been parsed. */
467 VPT_INSN, /* The VPT/VPST insn has been parsed. */
468 MVE_OUTSIDE_PRED_INSN , /* Instruction to indicate a MVE instruction without
469 a predication code. */
470 MVE_UNPREDICABLE_INSN /* MVE instruction that is non-predicable. */
471 };
472
473 /* The maximum number of operands we need. */
474 #define ARM_IT_MAX_OPERANDS 6
475 #define ARM_IT_MAX_RELOCS 3
476
477 struct arm_it
478 {
479 const char * error;
480 unsigned long instruction;
481 int size;
482 int size_req;
483 int cond;
484 /* "uncond_value" is set to the value in place of the conditional field in
485 unconditional versions of the instruction, or -1 if nothing is
486 appropriate. */
487 int uncond_value;
488 struct neon_type vectype;
489 /* This does not indicate an actual NEON instruction, only that
490 the mnemonic accepts neon-style type suffixes. */
491 int is_neon;
492 /* Set to the opcode if the instruction needs relaxation.
493 Zero if the instruction is not relaxed. */
494 unsigned long relax;
495 struct
496 {
497 bfd_reloc_code_real_type type;
498 expressionS exp;
499 int pc_rel;
500 } relocs[ARM_IT_MAX_RELOCS];
501
502 enum pred_instruction_type pred_insn_type;
503
504 struct
505 {
506 unsigned reg;
507 signed int imm;
508 struct neon_type_el vectype;
509 unsigned present : 1; /* Operand present. */
510 unsigned isreg : 1; /* Operand was a register. */
511 unsigned immisreg : 2; /* .imm field is a second register.
512 0: imm, 1: gpr, 2: MVE Q-register. */
513 unsigned isscalar : 2; /* Operand is a (SIMD) scalar:
514 0) not scalar,
515 1) Neon scalar,
516 2) MVE scalar. */
517 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
518 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
519 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
520 instructions. This allows us to disambiguate ARM <-> vector insns. */
521 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
522 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
523 unsigned isquad : 1; /* Operand is SIMD quad register. */
524 unsigned issingle : 1; /* Operand is VFP single-precision register. */
525 unsigned iszr : 1; /* Operand is ZR register. */
526 unsigned hasreloc : 1; /* Operand has relocation suffix. */
527 unsigned writeback : 1; /* Operand has trailing ! */
528 unsigned preind : 1; /* Preindexed address. */
529 unsigned postind : 1; /* Postindexed address. */
530 unsigned negative : 1; /* Index register was negated. */
531 unsigned shifted : 1; /* Shift applied to operation. */
532 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
533 } operands[ARM_IT_MAX_OPERANDS];
534 };
535
536 static struct arm_it inst;
537
538 #define NUM_FLOAT_VALS 8
539
540 const char * fp_const[] =
541 {
542 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
543 };
544
545 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
546
547 #define FAIL (-1)
548 #define SUCCESS (0)
549
550 #define SUFF_S 1
551 #define SUFF_D 2
552 #define SUFF_E 3
553 #define SUFF_P 4
554
555 #define CP_T_X 0x00008000
556 #define CP_T_Y 0x00400000
557
558 #define CONDS_BIT 0x00100000
559 #define LOAD_BIT 0x00100000
560
561 #define DOUBLE_LOAD_FLAG 0x00000001
562
563 struct asm_cond
564 {
565 const char * template_name;
566 unsigned long value;
567 };
568
569 #define COND_ALWAYS 0xE
570
571 struct asm_psr
572 {
573 const char * template_name;
574 unsigned long field;
575 };
576
577 struct asm_barrier_opt
578 {
579 const char * template_name;
580 unsigned long value;
581 const arm_feature_set arch;
582 };
583
584 /* The bit that distinguishes CPSR and SPSR. */
585 #define SPSR_BIT (1 << 22)
586
587 /* The individual PSR flag bits. */
588 #define PSR_c (1 << 16)
589 #define PSR_x (1 << 17)
590 #define PSR_s (1 << 18)
591 #define PSR_f (1 << 19)
592
593 struct reloc_entry
594 {
595 const char * name;
596 bfd_reloc_code_real_type reloc;
597 };
598
599 enum vfp_reg_pos
600 {
601 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
602 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
603 };
604
605 enum vfp_ldstm_type
606 {
607 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
608 };
609
610 /* Bits for DEFINED field in neon_typed_alias. */
611 #define NTA_HASTYPE 1
612 #define NTA_HASINDEX 2
613
614 struct neon_typed_alias
615 {
616 unsigned char defined;
617 unsigned char index;
618 struct neon_type_el eltype;
619 };
620
621 /* ARM register categories. This includes coprocessor numbers and various
622 architecture extensions' registers. Each entry should have an error message
623 in reg_expected_msgs below. */
624 enum arm_reg_type
625 {
626 REG_TYPE_RN,
627 REG_TYPE_CP,
628 REG_TYPE_CN,
629 REG_TYPE_FN,
630 REG_TYPE_VFS,
631 REG_TYPE_VFD,
632 REG_TYPE_NQ,
633 REG_TYPE_VFSD,
634 REG_TYPE_NDQ,
635 REG_TYPE_NSD,
636 REG_TYPE_NSDQ,
637 REG_TYPE_VFC,
638 REG_TYPE_MVF,
639 REG_TYPE_MVD,
640 REG_TYPE_MVFX,
641 REG_TYPE_MVDX,
642 REG_TYPE_MVAX,
643 REG_TYPE_MQ,
644 REG_TYPE_DSPSC,
645 REG_TYPE_MMXWR,
646 REG_TYPE_MMXWC,
647 REG_TYPE_MMXWCG,
648 REG_TYPE_XSCALE,
649 REG_TYPE_RNB,
650 REG_TYPE_ZR
651 };
652
653 /* Structure for a hash table entry for a register.
654 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
655 information which states whether a vector type or index is specified (for a
656 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
657 struct reg_entry
658 {
659 const char * name;
660 unsigned int number;
661 unsigned char type;
662 unsigned char builtin;
663 struct neon_typed_alias * neon;
664 };
665
666 /* Diagnostics used when we don't get a register of the expected type. */
667 const char * const reg_expected_msgs[] =
668 {
669 [REG_TYPE_RN] = N_("ARM register expected"),
670 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
671 [REG_TYPE_CN] = N_("co-processor register expected"),
672 [REG_TYPE_FN] = N_("FPA register expected"),
673 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
674 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
675 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
676 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
677 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
678 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
679 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
680 " expected"),
681 [REG_TYPE_VFC] = N_("VFP system register expected"),
682 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
683 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
684 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
685 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
686 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
687 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
688 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
689 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
690 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
691 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
692 [REG_TYPE_MQ] = N_("MVE vector register expected"),
693 [REG_TYPE_RNB] = N_("")
694 };
695
696 /* Some well known registers that we refer to directly elsewhere. */
697 #define REG_R12 12
698 #define REG_SP 13
699 #define REG_LR 14
700 #define REG_PC 15
701
702 /* ARM instructions take 4bytes in the object file, Thumb instructions
703 take 2: */
704 #define INSN_SIZE 4
705
706 struct asm_opcode
707 {
708 /* Basic string to match. */
709 const char * template_name;
710
711 /* Parameters to instruction. */
712 unsigned int operands[8];
713
714 /* Conditional tag - see opcode_lookup. */
715 unsigned int tag : 4;
716
717 /* Basic instruction code. */
718 unsigned int avalue;
719
720 /* Thumb-format instruction code. */
721 unsigned int tvalue;
722
723 /* Which architecture variant provides this instruction. */
724 const arm_feature_set * avariant;
725 const arm_feature_set * tvariant;
726
727 /* Function to call to encode instruction in ARM format. */
728 void (* aencode) (void);
729
730 /* Function to call to encode instruction in Thumb format. */
731 void (* tencode) (void);
732
733 /* Indicates whether this instruction may be vector predicated. */
734 unsigned int mayBeVecPred : 1;
735 };
736
737 /* Defines for various bits that we will want to toggle. */
738 #define INST_IMMEDIATE 0x02000000
739 #define OFFSET_REG 0x02000000
740 #define HWOFFSET_IMM 0x00400000
741 #define SHIFT_BY_REG 0x00000010
742 #define PRE_INDEX 0x01000000
743 #define INDEX_UP 0x00800000
744 #define WRITE_BACK 0x00200000
745 #define LDM_TYPE_2_OR_3 0x00400000
746 #define CPSI_MMOD 0x00020000
747
748 #define LITERAL_MASK 0xf000f000
749 #define OPCODE_MASK 0xfe1fffff
750 #define V4_STR_BIT 0x00000020
751 #define VLDR_VMOV_SAME 0x0040f000
752
753 #define T2_SUBS_PC_LR 0xf3de8f00
754
755 #define DATA_OP_SHIFT 21
756 #define SBIT_SHIFT 20
757
758 #define T2_OPCODE_MASK 0xfe1fffff
759 #define T2_DATA_OP_SHIFT 21
760 #define T2_SBIT_SHIFT 20
761
762 #define A_COND_MASK 0xf0000000
763 #define A_PUSH_POP_OP_MASK 0x0fff0000
764
765 /* Opcodes for pushing/poping registers to/from the stack. */
766 #define A1_OPCODE_PUSH 0x092d0000
767 #define A2_OPCODE_PUSH 0x052d0004
768 #define A2_OPCODE_POP 0x049d0004
769
770 /* Codes to distinguish the arithmetic instructions. */
771 #define OPCODE_AND 0
772 #define OPCODE_EOR 1
773 #define OPCODE_SUB 2
774 #define OPCODE_RSB 3
775 #define OPCODE_ADD 4
776 #define OPCODE_ADC 5
777 #define OPCODE_SBC 6
778 #define OPCODE_RSC 7
779 #define OPCODE_TST 8
780 #define OPCODE_TEQ 9
781 #define OPCODE_CMP 10
782 #define OPCODE_CMN 11
783 #define OPCODE_ORR 12
784 #define OPCODE_MOV 13
785 #define OPCODE_BIC 14
786 #define OPCODE_MVN 15
787
788 #define T2_OPCODE_AND 0
789 #define T2_OPCODE_BIC 1
790 #define T2_OPCODE_ORR 2
791 #define T2_OPCODE_ORN 3
792 #define T2_OPCODE_EOR 4
793 #define T2_OPCODE_ADD 8
794 #define T2_OPCODE_ADC 10
795 #define T2_OPCODE_SBC 11
796 #define T2_OPCODE_SUB 13
797 #define T2_OPCODE_RSB 14
798
799 #define T_OPCODE_MUL 0x4340
800 #define T_OPCODE_TST 0x4200
801 #define T_OPCODE_CMN 0x42c0
802 #define T_OPCODE_NEG 0x4240
803 #define T_OPCODE_MVN 0x43c0
804
805 #define T_OPCODE_ADD_R3 0x1800
806 #define T_OPCODE_SUB_R3 0x1a00
807 #define T_OPCODE_ADD_HI 0x4400
808 #define T_OPCODE_ADD_ST 0xb000
809 #define T_OPCODE_SUB_ST 0xb080
810 #define T_OPCODE_ADD_SP 0xa800
811 #define T_OPCODE_ADD_PC 0xa000
812 #define T_OPCODE_ADD_I8 0x3000
813 #define T_OPCODE_SUB_I8 0x3800
814 #define T_OPCODE_ADD_I3 0x1c00
815 #define T_OPCODE_SUB_I3 0x1e00
816
817 #define T_OPCODE_ASR_R 0x4100
818 #define T_OPCODE_LSL_R 0x4080
819 #define T_OPCODE_LSR_R 0x40c0
820 #define T_OPCODE_ROR_R 0x41c0
821 #define T_OPCODE_ASR_I 0x1000
822 #define T_OPCODE_LSL_I 0x0000
823 #define T_OPCODE_LSR_I 0x0800
824
825 #define T_OPCODE_MOV_I8 0x2000
826 #define T_OPCODE_CMP_I8 0x2800
827 #define T_OPCODE_CMP_LR 0x4280
828 #define T_OPCODE_MOV_HR 0x4600
829 #define T_OPCODE_CMP_HR 0x4500
830
831 #define T_OPCODE_LDR_PC 0x4800
832 #define T_OPCODE_LDR_SP 0x9800
833 #define T_OPCODE_STR_SP 0x9000
834 #define T_OPCODE_LDR_IW 0x6800
835 #define T_OPCODE_STR_IW 0x6000
836 #define T_OPCODE_LDR_IH 0x8800
837 #define T_OPCODE_STR_IH 0x8000
838 #define T_OPCODE_LDR_IB 0x7800
839 #define T_OPCODE_STR_IB 0x7000
840 #define T_OPCODE_LDR_RW 0x5800
841 #define T_OPCODE_STR_RW 0x5000
842 #define T_OPCODE_LDR_RH 0x5a00
843 #define T_OPCODE_STR_RH 0x5200
844 #define T_OPCODE_LDR_RB 0x5c00
845 #define T_OPCODE_STR_RB 0x5400
846
847 #define T_OPCODE_PUSH 0xb400
848 #define T_OPCODE_POP 0xbc00
849
850 #define T_OPCODE_BRANCH 0xe000
851
852 #define THUMB_SIZE 2 /* Size of thumb instruction. */
853 #define THUMB_PP_PC_LR 0x0100
854 #define THUMB_LOAD_BIT 0x0800
855 #define THUMB2_LOAD_BIT 0x00100000
856
857 #define BAD_SYNTAX _("syntax error")
858 #define BAD_ARGS _("bad arguments to instruction")
859 #define BAD_SP _("r13 not allowed here")
860 #define BAD_PC _("r15 not allowed here")
861 #define BAD_ODD _("Odd register not allowed here")
862 #define BAD_EVEN _("Even register not allowed here")
863 #define BAD_COND _("instruction cannot be conditional")
864 #define BAD_OVERLAP _("registers may not be the same")
865 #define BAD_HIREG _("lo register required")
866 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
867 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode")
868 #define BAD_BRANCH _("branch must be last instruction in IT block")
869 #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
870 #define BAD_NOT_IT _("instruction not allowed in IT block")
871 #define BAD_NOT_VPT _("instruction missing MVE vector predication code")
872 #define BAD_FPU _("selected FPU does not support instruction")
873 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
874 #define BAD_OUT_VPT \
875 _("vector predicated instruction should be in VPT/VPST block")
876 #define BAD_IT_COND _("incorrect condition in IT block")
877 #define BAD_VPT_COND _("incorrect condition in VPT/VPST block")
878 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
879 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
880 #define BAD_PC_ADDRESSING \
881 _("cannot use register index with PC-relative addressing")
882 #define BAD_PC_WRITEBACK \
883 _("cannot use writeback with PC-relative addressing")
884 #define BAD_RANGE _("branch out of range")
885 #define BAD_FP16 _("selected processor does not support fp16 instruction")
886 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
887 #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
888 #define MVE_NOT_IT _("Warning: instruction is UNPREDICTABLE in an IT " \
889 "block")
890 #define MVE_NOT_VPT _("Warning: instruction is UNPREDICTABLE in a VPT " \
891 "block")
892 #define MVE_BAD_PC _("Warning: instruction is UNPREDICTABLE with PC" \
893 " operand")
894 #define MVE_BAD_SP _("Warning: instruction is UNPREDICTABLE with SP" \
895 " operand")
896 #define BAD_SIMD_TYPE _("bad type in SIMD instruction")
897 #define BAD_MVE_AUTO \
898 _("GAS auto-detection mode and -march=all is deprecated for MVE, please" \
899 " use a valid -march or -mcpu option.")
900 #define BAD_MVE_SRCDEST _("Warning: 32-bit element size and same destination "\
901 "and source operands makes instruction UNPREDICTABLE")
902 #define BAD_EL_TYPE _("bad element type for instruction")
903 #define MVE_BAD_QREG _("MVE vector register Q[0..7] expected")
904
905 static struct hash_control * arm_ops_hsh;
906 static struct hash_control * arm_cond_hsh;
907 static struct hash_control * arm_vcond_hsh;
908 static struct hash_control * arm_shift_hsh;
909 static struct hash_control * arm_psr_hsh;
910 static struct hash_control * arm_v7m_psr_hsh;
911 static struct hash_control * arm_reg_hsh;
912 static struct hash_control * arm_reloc_hsh;
913 static struct hash_control * arm_barrier_opt_hsh;
914
915 /* Stuff needed to resolve the label ambiguity
916 As:
917 ...
918 label: <insn>
919 may differ from:
920 ...
921 label:
922 <insn> */
923
924 symbolS * last_label_seen;
925 static int label_is_thumb_function_name = FALSE;
926
927 /* Literal pool structure. Held on a per-section
928 and per-sub-section basis. */
929
930 #define MAX_LITERAL_POOL_SIZE 1024
931 typedef struct literal_pool
932 {
933 expressionS literals [MAX_LITERAL_POOL_SIZE];
934 unsigned int next_free_entry;
935 unsigned int id;
936 symbolS * symbol;
937 segT section;
938 subsegT sub_section;
939 #ifdef OBJ_ELF
940 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
941 #endif
942 struct literal_pool * next;
943 unsigned int alignment;
944 } literal_pool;
945
946 /* Pointer to a linked list of literal pools. */
947 literal_pool * list_of_pools = NULL;
948
949 typedef enum asmfunc_states
950 {
951 OUTSIDE_ASMFUNC,
952 WAITING_ASMFUNC_NAME,
953 WAITING_ENDASMFUNC
954 } asmfunc_states;
955
956 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
957
958 #ifdef OBJ_ELF
959 # define now_pred seg_info (now_seg)->tc_segment_info_data.current_pred
960 #else
961 static struct current_pred now_pred;
962 #endif
963
964 static inline int
965 now_pred_compatible (int cond)
966 {
967 return (cond & ~1) == (now_pred.cc & ~1);
968 }
969
970 static inline int
971 conditional_insn (void)
972 {
973 return inst.cond != COND_ALWAYS;
974 }
975
976 static int in_pred_block (void);
977
978 static int handle_pred_state (void);
979
980 static void force_automatic_it_block_close (void);
981
982 static void it_fsm_post_encode (void);
983
984 #define set_pred_insn_type(type) \
985 do \
986 { \
987 inst.pred_insn_type = type; \
988 if (handle_pred_state () == FAIL) \
989 return; \
990 } \
991 while (0)
992
993 #define set_pred_insn_type_nonvoid(type, failret) \
994 do \
995 { \
996 inst.pred_insn_type = type; \
997 if (handle_pred_state () == FAIL) \
998 return failret; \
999 } \
1000 while(0)
1001
1002 #define set_pred_insn_type_last() \
1003 do \
1004 { \
1005 if (inst.cond == COND_ALWAYS) \
1006 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN); \
1007 else \
1008 set_pred_insn_type (INSIDE_IT_LAST_INSN); \
1009 } \
1010 while (0)
1011
1012 /* Toggle value[pos]. */
1013 #define TOGGLE_BIT(value, pos) (value ^ (1 << pos))
1014
1015 /* Pure syntax. */
1016
1017 /* This array holds the chars that always start a comment. If the
1018 pre-processor is disabled, these aren't very useful. */
1019 char arm_comment_chars[] = "@";
1020
1021 /* This array holds the chars that only start a comment at the beginning of
1022 a line. If the line seems to have the form '# 123 filename'
1023 .line and .file directives will appear in the pre-processed output. */
1024 /* Note that input_file.c hand checks for '#' at the beginning of the
1025 first line of the input file. This is because the compiler outputs
1026 #NO_APP at the beginning of its output. */
1027 /* Also note that comments like this one will always work. */
1028 const char line_comment_chars[] = "#";
1029
1030 char arm_line_separator_chars[] = ";";
1031
1032 /* Chars that can be used to separate mant
1033 from exp in floating point numbers. */
1034 const char EXP_CHARS[] = "eE";
1035
1036 /* Chars that mean this number is a floating point constant. */
1037 /* As in 0f12.456 */
1038 /* or 0d1.2345e12 */
1039
1040 const char FLT_CHARS[] = "rRsSfFdDxXeEpPHh";
1041
1042 /* Prefix characters that indicate the start of an immediate
1043 value. */
1044 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
1045
1046 /* Separator character handling. */
1047
1048 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1049
1050 enum fp_16bit_format
1051 {
1052 ARM_FP16_FORMAT_IEEE = 0x1,
1053 ARM_FP16_FORMAT_ALTERNATIVE = 0x2,
1054 ARM_FP16_FORMAT_DEFAULT = 0x3
1055 };
1056
1057 static enum fp_16bit_format fp16_format = ARM_FP16_FORMAT_DEFAULT;
1058
1059
1060 static inline int
1061 skip_past_char (char ** str, char c)
1062 {
1063 /* PR gas/14987: Allow for whitespace before the expected character. */
1064 skip_whitespace (*str);
1065
1066 if (**str == c)
1067 {
1068 (*str)++;
1069 return SUCCESS;
1070 }
1071 else
1072 return FAIL;
1073 }
1074
1075 #define skip_past_comma(str) skip_past_char (str, ',')
1076
1077 /* Arithmetic expressions (possibly involving symbols). */
1078
1079 /* Return TRUE if anything in the expression is a bignum. */
1080
1081 static bfd_boolean
1082 walk_no_bignums (symbolS * sp)
1083 {
1084 if (symbol_get_value_expression (sp)->X_op == O_big)
1085 return TRUE;
1086
1087 if (symbol_get_value_expression (sp)->X_add_symbol)
1088 {
1089 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1090 || (symbol_get_value_expression (sp)->X_op_symbol
1091 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
1092 }
1093
1094 return FALSE;
1095 }
1096
1097 static bfd_boolean in_my_get_expression = FALSE;
1098
1099 /* Third argument to my_get_expression. */
1100 #define GE_NO_PREFIX 0
1101 #define GE_IMM_PREFIX 1
1102 #define GE_OPT_PREFIX 2
1103 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1104 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1105 #define GE_OPT_PREFIX_BIG 3
1106
1107 static int
1108 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
1109 {
1110 char * save_in;
1111
1112 /* In unified syntax, all prefixes are optional. */
1113 if (unified_syntax)
1114 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
1115 : GE_OPT_PREFIX;
1116
1117 switch (prefix_mode)
1118 {
1119 case GE_NO_PREFIX: break;
1120 case GE_IMM_PREFIX:
1121 if (!is_immediate_prefix (**str))
1122 {
1123 inst.error = _("immediate expression requires a # prefix");
1124 return FAIL;
1125 }
1126 (*str)++;
1127 break;
1128 case GE_OPT_PREFIX:
1129 case GE_OPT_PREFIX_BIG:
1130 if (is_immediate_prefix (**str))
1131 (*str)++;
1132 break;
1133 default:
1134 abort ();
1135 }
1136
1137 memset (ep, 0, sizeof (expressionS));
1138
1139 save_in = input_line_pointer;
1140 input_line_pointer = *str;
1141 in_my_get_expression = TRUE;
1142 expression (ep);
1143 in_my_get_expression = FALSE;
1144
1145 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1146 {
1147 /* We found a bad or missing expression in md_operand(). */
1148 *str = input_line_pointer;
1149 input_line_pointer = save_in;
1150 if (inst.error == NULL)
1151 inst.error = (ep->X_op == O_absent
1152 ? _("missing expression") :_("bad expression"));
1153 return 1;
1154 }
1155
1156 /* Get rid of any bignums now, so that we don't generate an error for which
1157 we can't establish a line number later on. Big numbers are never valid
1158 in instructions, which is where this routine is always called. */
1159 if (prefix_mode != GE_OPT_PREFIX_BIG
1160 && (ep->X_op == O_big
1161 || (ep->X_add_symbol
1162 && (walk_no_bignums (ep->X_add_symbol)
1163 || (ep->X_op_symbol
1164 && walk_no_bignums (ep->X_op_symbol))))))
1165 {
1166 inst.error = _("invalid constant");
1167 *str = input_line_pointer;
1168 input_line_pointer = save_in;
1169 return 1;
1170 }
1171
1172 *str = input_line_pointer;
1173 input_line_pointer = save_in;
1174 return SUCCESS;
1175 }
1176
1177 /* Turn a string in input_line_pointer into a floating point constant
1178 of type TYPE, and store the appropriate bytes in *LITP. The number
1179 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1180 returned, or NULL on OK.
1181
1182 Note that fp constants aren't represent in the normal way on the ARM.
1183 In big endian mode, things are as expected. However, in little endian
1184 mode fp constants are big-endian word-wise, and little-endian byte-wise
1185 within the words. For example, (double) 1.1 in big endian mode is
1186 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1187 the byte sequence 99 99 f1 3f 9a 99 99 99.
1188
1189 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1190
1191 const char *
1192 md_atof (int type, char * litP, int * sizeP)
1193 {
1194 int prec;
1195 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1196 char *t;
1197 int i;
1198
1199 switch (type)
1200 {
1201 case 'H':
1202 case 'h':
1203 prec = 1;
1204 break;
1205
1206 case 'f':
1207 case 'F':
1208 case 's':
1209 case 'S':
1210 prec = 2;
1211 break;
1212
1213 case 'd':
1214 case 'D':
1215 case 'r':
1216 case 'R':
1217 prec = 4;
1218 break;
1219
1220 case 'x':
1221 case 'X':
1222 prec = 5;
1223 break;
1224
1225 case 'p':
1226 case 'P':
1227 prec = 5;
1228 break;
1229
1230 default:
1231 *sizeP = 0;
1232 return _("Unrecognized or unsupported floating point constant");
1233 }
1234
1235 t = atof_ieee (input_line_pointer, type, words);
1236 if (t)
1237 input_line_pointer = t;
1238 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1239
1240 if (target_big_endian || prec == 1)
1241 for (i = 0; i < prec; i++)
1242 {
1243 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1244 litP += sizeof (LITTLENUM_TYPE);
1245 }
1246 else if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1247 for (i = prec - 1; i >= 0; i--)
1248 {
1249 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1250 litP += sizeof (LITTLENUM_TYPE);
1251 }
1252 else
1253 /* For a 4 byte float the order of elements in `words' is 1 0.
1254 For an 8 byte float the order is 1 0 3 2. */
1255 for (i = 0; i < prec; i += 2)
1256 {
1257 md_number_to_chars (litP, (valueT) words[i + 1],
1258 sizeof (LITTLENUM_TYPE));
1259 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1260 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1261 litP += 2 * sizeof (LITTLENUM_TYPE);
1262 }
1263
1264 return NULL;
1265 }
1266
1267 /* We handle all bad expressions here, so that we can report the faulty
1268 instruction in the error message. */
1269
1270 void
1271 md_operand (expressionS * exp)
1272 {
1273 if (in_my_get_expression)
1274 exp->X_op = O_illegal;
1275 }
1276
1277 /* Immediate values. */
1278
1279 #ifdef OBJ_ELF
1280 /* Generic immediate-value read function for use in directives.
1281 Accepts anything that 'expression' can fold to a constant.
1282 *val receives the number. */
1283
1284 static int
1285 immediate_for_directive (int *val)
1286 {
1287 expressionS exp;
1288 exp.X_op = O_illegal;
1289
1290 if (is_immediate_prefix (*input_line_pointer))
1291 {
1292 input_line_pointer++;
1293 expression (&exp);
1294 }
1295
1296 if (exp.X_op != O_constant)
1297 {
1298 as_bad (_("expected #constant"));
1299 ignore_rest_of_line ();
1300 return FAIL;
1301 }
1302 *val = exp.X_add_number;
1303 return SUCCESS;
1304 }
1305 #endif
1306
1307 /* Register parsing. */
1308
1309 /* Generic register parser. CCP points to what should be the
1310 beginning of a register name. If it is indeed a valid register
1311 name, advance CCP over it and return the reg_entry structure;
1312 otherwise return NULL. Does not issue diagnostics. */
1313
1314 static struct reg_entry *
1315 arm_reg_parse_multi (char **ccp)
1316 {
1317 char *start = *ccp;
1318 char *p;
1319 struct reg_entry *reg;
1320
1321 skip_whitespace (start);
1322
1323 #ifdef REGISTER_PREFIX
1324 if (*start != REGISTER_PREFIX)
1325 return NULL;
1326 start++;
1327 #endif
1328 #ifdef OPTIONAL_REGISTER_PREFIX
1329 if (*start == OPTIONAL_REGISTER_PREFIX)
1330 start++;
1331 #endif
1332
1333 p = start;
1334 if (!ISALPHA (*p) || !is_name_beginner (*p))
1335 return NULL;
1336
1337 do
1338 p++;
1339 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1340
1341 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1342
1343 if (!reg)
1344 return NULL;
1345
1346 *ccp = p;
1347 return reg;
1348 }
1349
1350 static int
1351 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1352 enum arm_reg_type type)
1353 {
1354 /* Alternative syntaxes are accepted for a few register classes. */
1355 switch (type)
1356 {
1357 case REG_TYPE_MVF:
1358 case REG_TYPE_MVD:
1359 case REG_TYPE_MVFX:
1360 case REG_TYPE_MVDX:
1361 /* Generic coprocessor register names are allowed for these. */
1362 if (reg && reg->type == REG_TYPE_CN)
1363 return reg->number;
1364 break;
1365
1366 case REG_TYPE_CP:
1367 /* For backward compatibility, a bare number is valid here. */
1368 {
1369 unsigned long processor = strtoul (start, ccp, 10);
1370 if (*ccp != start && processor <= 15)
1371 return processor;
1372 }
1373 /* Fall through. */
1374
1375 case REG_TYPE_MMXWC:
1376 /* WC includes WCG. ??? I'm not sure this is true for all
1377 instructions that take WC registers. */
1378 if (reg && reg->type == REG_TYPE_MMXWCG)
1379 return reg->number;
1380 break;
1381
1382 default:
1383 break;
1384 }
1385
1386 return FAIL;
1387 }
1388
1389 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1390 return value is the register number or FAIL. */
1391
1392 static int
1393 arm_reg_parse (char **ccp, enum arm_reg_type type)
1394 {
1395 char *start = *ccp;
1396 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1397 int ret;
1398
1399 /* Do not allow a scalar (reg+index) to parse as a register. */
1400 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1401 return FAIL;
1402
1403 if (reg && reg->type == type)
1404 return reg->number;
1405
1406 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1407 return ret;
1408
1409 *ccp = start;
1410 return FAIL;
1411 }
1412
1413 /* Parse a Neon type specifier. *STR should point at the leading '.'
1414 character. Does no verification at this stage that the type fits the opcode
1415 properly. E.g.,
1416
1417 .i32.i32.s16
1418 .s32.f32
1419 .u16
1420
1421 Can all be legally parsed by this function.
1422
1423 Fills in neon_type struct pointer with parsed information, and updates STR
1424 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1425 type, FAIL if not. */
1426
1427 static int
1428 parse_neon_type (struct neon_type *type, char **str)
1429 {
1430 char *ptr = *str;
1431
1432 if (type)
1433 type->elems = 0;
1434
1435 while (type->elems < NEON_MAX_TYPE_ELS)
1436 {
1437 enum neon_el_type thistype = NT_untyped;
1438 unsigned thissize = -1u;
1439
1440 if (*ptr != '.')
1441 break;
1442
1443 ptr++;
1444
1445 /* Just a size without an explicit type. */
1446 if (ISDIGIT (*ptr))
1447 goto parsesize;
1448
1449 switch (TOLOWER (*ptr))
1450 {
1451 case 'i': thistype = NT_integer; break;
1452 case 'f': thistype = NT_float; break;
1453 case 'p': thistype = NT_poly; break;
1454 case 's': thistype = NT_signed; break;
1455 case 'u': thistype = NT_unsigned; break;
1456 case 'd':
1457 thistype = NT_float;
1458 thissize = 64;
1459 ptr++;
1460 goto done;
1461 default:
1462 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1463 return FAIL;
1464 }
1465
1466 ptr++;
1467
1468 /* .f is an abbreviation for .f32. */
1469 if (thistype == NT_float && !ISDIGIT (*ptr))
1470 thissize = 32;
1471 else
1472 {
1473 parsesize:
1474 thissize = strtoul (ptr, &ptr, 10);
1475
1476 if (thissize != 8 && thissize != 16 && thissize != 32
1477 && thissize != 64)
1478 {
1479 as_bad (_("bad size %d in type specifier"), thissize);
1480 return FAIL;
1481 }
1482 }
1483
1484 done:
1485 if (type)
1486 {
1487 type->el[type->elems].type = thistype;
1488 type->el[type->elems].size = thissize;
1489 type->elems++;
1490 }
1491 }
1492
1493 /* Empty/missing type is not a successful parse. */
1494 if (type->elems == 0)
1495 return FAIL;
1496
1497 *str = ptr;
1498
1499 return SUCCESS;
1500 }
1501
1502 /* Errors may be set multiple times during parsing or bit encoding
1503 (particularly in the Neon bits), but usually the earliest error which is set
1504 will be the most meaningful. Avoid overwriting it with later (cascading)
1505 errors by calling this function. */
1506
1507 static void
1508 first_error (const char *err)
1509 {
1510 if (!inst.error)
1511 inst.error = err;
1512 }
1513
1514 /* Parse a single type, e.g. ".s32", leading period included. */
1515 static int
1516 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1517 {
1518 char *str = *ccp;
1519 struct neon_type optype;
1520
1521 if (*str == '.')
1522 {
1523 if (parse_neon_type (&optype, &str) == SUCCESS)
1524 {
1525 if (optype.elems == 1)
1526 *vectype = optype.el[0];
1527 else
1528 {
1529 first_error (_("only one type should be specified for operand"));
1530 return FAIL;
1531 }
1532 }
1533 else
1534 {
1535 first_error (_("vector type expected"));
1536 return FAIL;
1537 }
1538 }
1539 else
1540 return FAIL;
1541
1542 *ccp = str;
1543
1544 return SUCCESS;
1545 }
1546
1547 /* Special meanings for indices (which have a range of 0-7), which will fit into
1548 a 4-bit integer. */
1549
1550 #define NEON_ALL_LANES 15
1551 #define NEON_INTERLEAVE_LANES 14
1552
1553 /* Record a use of the given feature. */
1554 static void
1555 record_feature_use (const arm_feature_set *feature)
1556 {
1557 if (thumb_mode)
1558 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
1559 else
1560 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
1561 }
1562
1563 /* If the given feature available in the selected CPU, mark it as used.
1564 Returns TRUE iff feature is available. */
1565 static bfd_boolean
1566 mark_feature_used (const arm_feature_set *feature)
1567 {
1568
1569 /* Do not support the use of MVE only instructions when in auto-detection or
1570 -march=all. */
1571 if (((feature == &mve_ext) || (feature == &mve_fp_ext))
1572 && ARM_CPU_IS_ANY (cpu_variant))
1573 {
1574 first_error (BAD_MVE_AUTO);
1575 return FALSE;
1576 }
1577 /* Ensure the option is valid on the current architecture. */
1578 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
1579 return FALSE;
1580
1581 /* Add the appropriate architecture feature for the barrier option used.
1582 */
1583 record_feature_use (feature);
1584
1585 return TRUE;
1586 }
1587
1588 /* Parse either a register or a scalar, with an optional type. Return the
1589 register number, and optionally fill in the actual type of the register
1590 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1591 type/index information in *TYPEINFO. */
1592
1593 static int
1594 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1595 enum arm_reg_type *rtype,
1596 struct neon_typed_alias *typeinfo)
1597 {
1598 char *str = *ccp;
1599 struct reg_entry *reg = arm_reg_parse_multi (&str);
1600 struct neon_typed_alias atype;
1601 struct neon_type_el parsetype;
1602
1603 atype.defined = 0;
1604 atype.index = -1;
1605 atype.eltype.type = NT_invtype;
1606 atype.eltype.size = -1;
1607
1608 /* Try alternate syntax for some types of register. Note these are mutually
1609 exclusive with the Neon syntax extensions. */
1610 if (reg == NULL)
1611 {
1612 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1613 if (altreg != FAIL)
1614 *ccp = str;
1615 if (typeinfo)
1616 *typeinfo = atype;
1617 return altreg;
1618 }
1619
1620 /* Undo polymorphism when a set of register types may be accepted. */
1621 if ((type == REG_TYPE_NDQ
1622 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1623 || (type == REG_TYPE_VFSD
1624 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1625 || (type == REG_TYPE_NSDQ
1626 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1627 || reg->type == REG_TYPE_NQ))
1628 || (type == REG_TYPE_NSD
1629 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1630 || (type == REG_TYPE_MMXWC
1631 && (reg->type == REG_TYPE_MMXWCG)))
1632 type = (enum arm_reg_type) reg->type;
1633
1634 if (type == REG_TYPE_MQ)
1635 {
1636 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1637 return FAIL;
1638
1639 if (!reg || reg->type != REG_TYPE_NQ)
1640 return FAIL;
1641
1642 if (reg->number > 14 && !mark_feature_used (&fpu_vfp_ext_d32))
1643 {
1644 first_error (_("expected MVE register [q0..q7]"));
1645 return FAIL;
1646 }
1647 type = REG_TYPE_NQ;
1648 }
1649 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
1650 && (type == REG_TYPE_NQ))
1651 return FAIL;
1652
1653
1654 if (type != reg->type)
1655 return FAIL;
1656
1657 if (reg->neon)
1658 atype = *reg->neon;
1659
1660 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1661 {
1662 if ((atype.defined & NTA_HASTYPE) != 0)
1663 {
1664 first_error (_("can't redefine type for operand"));
1665 return FAIL;
1666 }
1667 atype.defined |= NTA_HASTYPE;
1668 atype.eltype = parsetype;
1669 }
1670
1671 if (skip_past_char (&str, '[') == SUCCESS)
1672 {
1673 if (type != REG_TYPE_VFD
1674 && !(type == REG_TYPE_VFS
1675 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2))
1676 && !(type == REG_TYPE_NQ
1677 && ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
1678 {
1679 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
1680 first_error (_("only D and Q registers may be indexed"));
1681 else
1682 first_error (_("only D registers may be indexed"));
1683 return FAIL;
1684 }
1685
1686 if ((atype.defined & NTA_HASINDEX) != 0)
1687 {
1688 first_error (_("can't change index for operand"));
1689 return FAIL;
1690 }
1691
1692 atype.defined |= NTA_HASINDEX;
1693
1694 if (skip_past_char (&str, ']') == SUCCESS)
1695 atype.index = NEON_ALL_LANES;
1696 else
1697 {
1698 expressionS exp;
1699
1700 my_get_expression (&exp, &str, GE_NO_PREFIX);
1701
1702 if (exp.X_op != O_constant)
1703 {
1704 first_error (_("constant expression required"));
1705 return FAIL;
1706 }
1707
1708 if (skip_past_char (&str, ']') == FAIL)
1709 return FAIL;
1710
1711 atype.index = exp.X_add_number;
1712 }
1713 }
1714
1715 if (typeinfo)
1716 *typeinfo = atype;
1717
1718 if (rtype)
1719 *rtype = type;
1720
1721 *ccp = str;
1722
1723 return reg->number;
1724 }
1725
1726 /* Like arm_reg_parse, but also allow the following extra features:
1727 - If RTYPE is non-zero, return the (possibly restricted) type of the
1728 register (e.g. Neon double or quad reg when either has been requested).
1729 - If this is a Neon vector type with additional type information, fill
1730 in the struct pointed to by VECTYPE (if non-NULL).
1731 This function will fault on encountering a scalar. */
1732
1733 static int
1734 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1735 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1736 {
1737 struct neon_typed_alias atype;
1738 char *str = *ccp;
1739 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1740
1741 if (reg == FAIL)
1742 return FAIL;
1743
1744 /* Do not allow regname(... to parse as a register. */
1745 if (*str == '(')
1746 return FAIL;
1747
1748 /* Do not allow a scalar (reg+index) to parse as a register. */
1749 if ((atype.defined & NTA_HASINDEX) != 0)
1750 {
1751 first_error (_("register operand expected, but got scalar"));
1752 return FAIL;
1753 }
1754
1755 if (vectype)
1756 *vectype = atype.eltype;
1757
1758 *ccp = str;
1759
1760 return reg;
1761 }
1762
1763 #define NEON_SCALAR_REG(X) ((X) >> 4)
1764 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1765
1766 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1767 have enough information to be able to do a good job bounds-checking. So, we
1768 just do easy checks here, and do further checks later. */
1769
1770 static int
1771 parse_scalar (char **ccp, int elsize, struct neon_type_el *type, enum
1772 arm_reg_type reg_type)
1773 {
1774 int reg;
1775 char *str = *ccp;
1776 struct neon_typed_alias atype;
1777 unsigned reg_size;
1778
1779 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
1780
1781 switch (reg_type)
1782 {
1783 case REG_TYPE_VFS:
1784 reg_size = 32;
1785 break;
1786 case REG_TYPE_VFD:
1787 reg_size = 64;
1788 break;
1789 case REG_TYPE_MQ:
1790 reg_size = 128;
1791 break;
1792 default:
1793 gas_assert (0);
1794 return FAIL;
1795 }
1796
1797 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1798 return FAIL;
1799
1800 if (reg_type != REG_TYPE_MQ && atype.index == NEON_ALL_LANES)
1801 {
1802 first_error (_("scalar must have an index"));
1803 return FAIL;
1804 }
1805 else if (atype.index >= reg_size / elsize)
1806 {
1807 first_error (_("scalar index out of range"));
1808 return FAIL;
1809 }
1810
1811 if (type)
1812 *type = atype.eltype;
1813
1814 *ccp = str;
1815
1816 return reg * 16 + atype.index;
1817 }
1818
1819 /* Types of registers in a list. */
1820
1821 enum reg_list_els
1822 {
1823 REGLIST_RN,
1824 REGLIST_CLRM,
1825 REGLIST_VFP_S,
1826 REGLIST_VFP_S_VPR,
1827 REGLIST_VFP_D,
1828 REGLIST_VFP_D_VPR,
1829 REGLIST_NEON_D
1830 };
1831
1832 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1833
1834 static long
1835 parse_reg_list (char ** strp, enum reg_list_els etype)
1836 {
1837 char *str = *strp;
1838 long range = 0;
1839 int another_range;
1840
1841 gas_assert (etype == REGLIST_RN || etype == REGLIST_CLRM);
1842
1843 /* We come back here if we get ranges concatenated by '+' or '|'. */
1844 do
1845 {
1846 skip_whitespace (str);
1847
1848 another_range = 0;
1849
1850 if (*str == '{')
1851 {
1852 int in_range = 0;
1853 int cur_reg = -1;
1854
1855 str++;
1856 do
1857 {
1858 int reg;
1859 const char apsr_str[] = "apsr";
1860 int apsr_str_len = strlen (apsr_str);
1861
1862 reg = arm_reg_parse (&str, REGLIST_RN);
1863 if (etype == REGLIST_CLRM)
1864 {
1865 if (reg == REG_SP || reg == REG_PC)
1866 reg = FAIL;
1867 else if (reg == FAIL
1868 && !strncasecmp (str, apsr_str, apsr_str_len)
1869 && !ISALPHA (*(str + apsr_str_len)))
1870 {
1871 reg = 15;
1872 str += apsr_str_len;
1873 }
1874
1875 if (reg == FAIL)
1876 {
1877 first_error (_("r0-r12, lr or APSR expected"));
1878 return FAIL;
1879 }
1880 }
1881 else /* etype == REGLIST_RN. */
1882 {
1883 if (reg == FAIL)
1884 {
1885 first_error (_(reg_expected_msgs[REGLIST_RN]));
1886 return FAIL;
1887 }
1888 }
1889
1890 if (in_range)
1891 {
1892 int i;
1893
1894 if (reg <= cur_reg)
1895 {
1896 first_error (_("bad range in register list"));
1897 return FAIL;
1898 }
1899
1900 for (i = cur_reg + 1; i < reg; i++)
1901 {
1902 if (range & (1 << i))
1903 as_tsktsk
1904 (_("Warning: duplicated register (r%d) in register list"),
1905 i);
1906 else
1907 range |= 1 << i;
1908 }
1909 in_range = 0;
1910 }
1911
1912 if (range & (1 << reg))
1913 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1914 reg);
1915 else if (reg <= cur_reg)
1916 as_tsktsk (_("Warning: register range not in ascending order"));
1917
1918 range |= 1 << reg;
1919 cur_reg = reg;
1920 }
1921 while (skip_past_comma (&str) != FAIL
1922 || (in_range = 1, *str++ == '-'));
1923 str--;
1924
1925 if (skip_past_char (&str, '}') == FAIL)
1926 {
1927 first_error (_("missing `}'"));
1928 return FAIL;
1929 }
1930 }
1931 else if (etype == REGLIST_RN)
1932 {
1933 expressionS exp;
1934
1935 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1936 return FAIL;
1937
1938 if (exp.X_op == O_constant)
1939 {
1940 if (exp.X_add_number
1941 != (exp.X_add_number & 0x0000ffff))
1942 {
1943 inst.error = _("invalid register mask");
1944 return FAIL;
1945 }
1946
1947 if ((range & exp.X_add_number) != 0)
1948 {
1949 int regno = range & exp.X_add_number;
1950
1951 regno &= -regno;
1952 regno = (1 << regno) - 1;
1953 as_tsktsk
1954 (_("Warning: duplicated register (r%d) in register list"),
1955 regno);
1956 }
1957
1958 range |= exp.X_add_number;
1959 }
1960 else
1961 {
1962 if (inst.relocs[0].type != 0)
1963 {
1964 inst.error = _("expression too complex");
1965 return FAIL;
1966 }
1967
1968 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
1969 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
1970 inst.relocs[0].pc_rel = 0;
1971 }
1972 }
1973
1974 if (*str == '|' || *str == '+')
1975 {
1976 str++;
1977 another_range = 1;
1978 }
1979 }
1980 while (another_range);
1981
1982 *strp = str;
1983 return range;
1984 }
1985
1986 /* Parse a VFP register list. If the string is invalid return FAIL.
1987 Otherwise return the number of registers, and set PBASE to the first
1988 register. Parses registers of type ETYPE.
1989 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1990 - Q registers can be used to specify pairs of D registers
1991 - { } can be omitted from around a singleton register list
1992 FIXME: This is not implemented, as it would require backtracking in
1993 some cases, e.g.:
1994 vtbl.8 d3,d4,d5
1995 This could be done (the meaning isn't really ambiguous), but doesn't
1996 fit in well with the current parsing framework.
1997 - 32 D registers may be used (also true for VFPv3).
1998 FIXME: Types are ignored in these register lists, which is probably a
1999 bug. */
2000
2001 static int
2002 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype,
2003 bfd_boolean *partial_match)
2004 {
2005 char *str = *ccp;
2006 int base_reg;
2007 int new_base;
2008 enum arm_reg_type regtype = (enum arm_reg_type) 0;
2009 int max_regs = 0;
2010 int count = 0;
2011 int warned = 0;
2012 unsigned long mask = 0;
2013 int i;
2014 bfd_boolean vpr_seen = FALSE;
2015 bfd_boolean expect_vpr =
2016 (etype == REGLIST_VFP_S_VPR) || (etype == REGLIST_VFP_D_VPR);
2017
2018 if (skip_past_char (&str, '{') == FAIL)
2019 {
2020 inst.error = _("expecting {");
2021 return FAIL;
2022 }
2023
2024 switch (etype)
2025 {
2026 case REGLIST_VFP_S:
2027 case REGLIST_VFP_S_VPR:
2028 regtype = REG_TYPE_VFS;
2029 max_regs = 32;
2030 break;
2031
2032 case REGLIST_VFP_D:
2033 case REGLIST_VFP_D_VPR:
2034 regtype = REG_TYPE_VFD;
2035 break;
2036
2037 case REGLIST_NEON_D:
2038 regtype = REG_TYPE_NDQ;
2039 break;
2040
2041 default:
2042 gas_assert (0);
2043 }
2044
2045 if (etype != REGLIST_VFP_S && etype != REGLIST_VFP_S_VPR)
2046 {
2047 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
2048 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
2049 {
2050 max_regs = 32;
2051 if (thumb_mode)
2052 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
2053 fpu_vfp_ext_d32);
2054 else
2055 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
2056 fpu_vfp_ext_d32);
2057 }
2058 else
2059 max_regs = 16;
2060 }
2061
2062 base_reg = max_regs;
2063 *partial_match = FALSE;
2064
2065 do
2066 {
2067 int setmask = 1, addregs = 1;
2068 const char vpr_str[] = "vpr";
2069 int vpr_str_len = strlen (vpr_str);
2070
2071 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
2072
2073 if (expect_vpr)
2074 {
2075 if (new_base == FAIL
2076 && !strncasecmp (str, vpr_str, vpr_str_len)
2077 && !ISALPHA (*(str + vpr_str_len))
2078 && !vpr_seen)
2079 {
2080 vpr_seen = TRUE;
2081 str += vpr_str_len;
2082 if (count == 0)
2083 base_reg = 0; /* Canonicalize VPR only on d0 with 0 regs. */
2084 }
2085 else if (vpr_seen)
2086 {
2087 first_error (_("VPR expected last"));
2088 return FAIL;
2089 }
2090 else if (new_base == FAIL)
2091 {
2092 if (regtype == REG_TYPE_VFS)
2093 first_error (_("VFP single precision register or VPR "
2094 "expected"));
2095 else /* regtype == REG_TYPE_VFD. */
2096 first_error (_("VFP/Neon double precision register or VPR "
2097 "expected"));
2098 return FAIL;
2099 }
2100 }
2101 else if (new_base == FAIL)
2102 {
2103 first_error (_(reg_expected_msgs[regtype]));
2104 return FAIL;
2105 }
2106
2107 *partial_match = TRUE;
2108 if (vpr_seen)
2109 continue;
2110
2111 if (new_base >= max_regs)
2112 {
2113 first_error (_("register out of range in list"));
2114 return FAIL;
2115 }
2116
2117 /* Note: a value of 2 * n is returned for the register Q<n>. */
2118 if (regtype == REG_TYPE_NQ)
2119 {
2120 setmask = 3;
2121 addregs = 2;
2122 }
2123
2124 if (new_base < base_reg)
2125 base_reg = new_base;
2126
2127 if (mask & (setmask << new_base))
2128 {
2129 first_error (_("invalid register list"));
2130 return FAIL;
2131 }
2132
2133 if ((mask >> new_base) != 0 && ! warned && !vpr_seen)
2134 {
2135 as_tsktsk (_("register list not in ascending order"));
2136 warned = 1;
2137 }
2138
2139 mask |= setmask << new_base;
2140 count += addregs;
2141
2142 if (*str == '-') /* We have the start of a range expression */
2143 {
2144 int high_range;
2145
2146 str++;
2147
2148 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
2149 == FAIL)
2150 {
2151 inst.error = gettext (reg_expected_msgs[regtype]);
2152 return FAIL;
2153 }
2154
2155 if (high_range >= max_regs)
2156 {
2157 first_error (_("register out of range in list"));
2158 return FAIL;
2159 }
2160
2161 if (regtype == REG_TYPE_NQ)
2162 high_range = high_range + 1;
2163
2164 if (high_range <= new_base)
2165 {
2166 inst.error = _("register range not in ascending order");
2167 return FAIL;
2168 }
2169
2170 for (new_base += addregs; new_base <= high_range; new_base += addregs)
2171 {
2172 if (mask & (setmask << new_base))
2173 {
2174 inst.error = _("invalid register list");
2175 return FAIL;
2176 }
2177
2178 mask |= setmask << new_base;
2179 count += addregs;
2180 }
2181 }
2182 }
2183 while (skip_past_comma (&str) != FAIL);
2184
2185 str++;
2186
2187 /* Sanity check -- should have raised a parse error above. */
2188 if ((!vpr_seen && count == 0) || count > max_regs)
2189 abort ();
2190
2191 *pbase = base_reg;
2192
2193 if (expect_vpr && !vpr_seen)
2194 {
2195 first_error (_("VPR expected last"));
2196 return FAIL;
2197 }
2198
2199 /* Final test -- the registers must be consecutive. */
2200 mask >>= base_reg;
2201 for (i = 0; i < count; i++)
2202 {
2203 if ((mask & (1u << i)) == 0)
2204 {
2205 inst.error = _("non-contiguous register range");
2206 return FAIL;
2207 }
2208 }
2209
2210 *ccp = str;
2211
2212 return count;
2213 }
2214
2215 /* True if two alias types are the same. */
2216
2217 static bfd_boolean
2218 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2219 {
2220 if (!a && !b)
2221 return TRUE;
2222
2223 if (!a || !b)
2224 return FALSE;
2225
2226 if (a->defined != b->defined)
2227 return FALSE;
2228
2229 if ((a->defined & NTA_HASTYPE) != 0
2230 && (a->eltype.type != b->eltype.type
2231 || a->eltype.size != b->eltype.size))
2232 return FALSE;
2233
2234 if ((a->defined & NTA_HASINDEX) != 0
2235 && (a->index != b->index))
2236 return FALSE;
2237
2238 return TRUE;
2239 }
2240
2241 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2242 The base register is put in *PBASE.
2243 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
2244 the return value.
2245 The register stride (minus one) is put in bit 4 of the return value.
2246 Bits [6:5] encode the list length (minus one).
2247 The type of the list elements is put in *ELTYPE, if non-NULL. */
2248
2249 #define NEON_LANE(X) ((X) & 0xf)
2250 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
2251 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2252
2253 static int
2254 parse_neon_el_struct_list (char **str, unsigned *pbase,
2255 int mve,
2256 struct neon_type_el *eltype)
2257 {
2258 char *ptr = *str;
2259 int base_reg = -1;
2260 int reg_incr = -1;
2261 int count = 0;
2262 int lane = -1;
2263 int leading_brace = 0;
2264 enum arm_reg_type rtype = REG_TYPE_NDQ;
2265 const char *const incr_error = mve ? _("register stride must be 1") :
2266 _("register stride must be 1 or 2");
2267 const char *const type_error = _("mismatched element/structure types in list");
2268 struct neon_typed_alias firsttype;
2269 firsttype.defined = 0;
2270 firsttype.eltype.type = NT_invtype;
2271 firsttype.eltype.size = -1;
2272 firsttype.index = -1;
2273
2274 if (skip_past_char (&ptr, '{') == SUCCESS)
2275 leading_brace = 1;
2276
2277 do
2278 {
2279 struct neon_typed_alias atype;
2280 if (mve)
2281 rtype = REG_TYPE_MQ;
2282 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2283
2284 if (getreg == FAIL)
2285 {
2286 first_error (_(reg_expected_msgs[rtype]));
2287 return FAIL;
2288 }
2289
2290 if (base_reg == -1)
2291 {
2292 base_reg = getreg;
2293 if (rtype == REG_TYPE_NQ)
2294 {
2295 reg_incr = 1;
2296 }
2297 firsttype = atype;
2298 }
2299 else if (reg_incr == -1)
2300 {
2301 reg_incr = getreg - base_reg;
2302 if (reg_incr < 1 || reg_incr > 2)
2303 {
2304 first_error (_(incr_error));
2305 return FAIL;
2306 }
2307 }
2308 else if (getreg != base_reg + reg_incr * count)
2309 {
2310 first_error (_(incr_error));
2311 return FAIL;
2312 }
2313
2314 if (! neon_alias_types_same (&atype, &firsttype))
2315 {
2316 first_error (_(type_error));
2317 return FAIL;
2318 }
2319
2320 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2321 modes. */
2322 if (ptr[0] == '-')
2323 {
2324 struct neon_typed_alias htype;
2325 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2326 if (lane == -1)
2327 lane = NEON_INTERLEAVE_LANES;
2328 else if (lane != NEON_INTERLEAVE_LANES)
2329 {
2330 first_error (_(type_error));
2331 return FAIL;
2332 }
2333 if (reg_incr == -1)
2334 reg_incr = 1;
2335 else if (reg_incr != 1)
2336 {
2337 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2338 return FAIL;
2339 }
2340 ptr++;
2341 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2342 if (hireg == FAIL)
2343 {
2344 first_error (_(reg_expected_msgs[rtype]));
2345 return FAIL;
2346 }
2347 if (! neon_alias_types_same (&htype, &firsttype))
2348 {
2349 first_error (_(type_error));
2350 return FAIL;
2351 }
2352 count += hireg + dregs - getreg;
2353 continue;
2354 }
2355
2356 /* If we're using Q registers, we can't use [] or [n] syntax. */
2357 if (rtype == REG_TYPE_NQ)
2358 {
2359 count += 2;
2360 continue;
2361 }
2362
2363 if ((atype.defined & NTA_HASINDEX) != 0)
2364 {
2365 if (lane == -1)
2366 lane = atype.index;
2367 else if (lane != atype.index)
2368 {
2369 first_error (_(type_error));
2370 return FAIL;
2371 }
2372 }
2373 else if (lane == -1)
2374 lane = NEON_INTERLEAVE_LANES;
2375 else if (lane != NEON_INTERLEAVE_LANES)
2376 {
2377 first_error (_(type_error));
2378 return FAIL;
2379 }
2380 count++;
2381 }
2382 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2383
2384 /* No lane set by [x]. We must be interleaving structures. */
2385 if (lane == -1)
2386 lane = NEON_INTERLEAVE_LANES;
2387
2388 /* Sanity check. */
2389 if (lane == -1 || base_reg == -1 || count < 1 || (!mve && count > 4)
2390 || (count > 1 && reg_incr == -1))
2391 {
2392 first_error (_("error parsing element/structure list"));
2393 return FAIL;
2394 }
2395
2396 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2397 {
2398 first_error (_("expected }"));
2399 return FAIL;
2400 }
2401
2402 if (reg_incr == -1)
2403 reg_incr = 1;
2404
2405 if (eltype)
2406 *eltype = firsttype.eltype;
2407
2408 *pbase = base_reg;
2409 *str = ptr;
2410
2411 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2412 }
2413
2414 /* Parse an explicit relocation suffix on an expression. This is
2415 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2416 arm_reloc_hsh contains no entries, so this function can only
2417 succeed if there is no () after the word. Returns -1 on error,
2418 BFD_RELOC_UNUSED if there wasn't any suffix. */
2419
2420 static int
2421 parse_reloc (char **str)
2422 {
2423 struct reloc_entry *r;
2424 char *p, *q;
2425
2426 if (**str != '(')
2427 return BFD_RELOC_UNUSED;
2428
2429 p = *str + 1;
2430 q = p;
2431
2432 while (*q && *q != ')' && *q != ',')
2433 q++;
2434 if (*q != ')')
2435 return -1;
2436
2437 if ((r = (struct reloc_entry *)
2438 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2439 return -1;
2440
2441 *str = q + 1;
2442 return r->reloc;
2443 }
2444
2445 /* Directives: register aliases. */
2446
2447 static struct reg_entry *
2448 insert_reg_alias (char *str, unsigned number, int type)
2449 {
2450 struct reg_entry *new_reg;
2451 const char *name;
2452
2453 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2454 {
2455 if (new_reg->builtin)
2456 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2457
2458 /* Only warn about a redefinition if it's not defined as the
2459 same register. */
2460 else if (new_reg->number != number || new_reg->type != type)
2461 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2462
2463 return NULL;
2464 }
2465
2466 name = xstrdup (str);
2467 new_reg = XNEW (struct reg_entry);
2468
2469 new_reg->name = name;
2470 new_reg->number = number;
2471 new_reg->type = type;
2472 new_reg->builtin = FALSE;
2473 new_reg->neon = NULL;
2474
2475 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2476 abort ();
2477
2478 return new_reg;
2479 }
2480
2481 static void
2482 insert_neon_reg_alias (char *str, int number, int type,
2483 struct neon_typed_alias *atype)
2484 {
2485 struct reg_entry *reg = insert_reg_alias (str, number, type);
2486
2487 if (!reg)
2488 {
2489 first_error (_("attempt to redefine typed alias"));
2490 return;
2491 }
2492
2493 if (atype)
2494 {
2495 reg->neon = XNEW (struct neon_typed_alias);
2496 *reg->neon = *atype;
2497 }
2498 }
2499
2500 /* Look for the .req directive. This is of the form:
2501
2502 new_register_name .req existing_register_name
2503
2504 If we find one, or if it looks sufficiently like one that we want to
2505 handle any error here, return TRUE. Otherwise return FALSE. */
2506
2507 static bfd_boolean
2508 create_register_alias (char * newname, char *p)
2509 {
2510 struct reg_entry *old;
2511 char *oldname, *nbuf;
2512 size_t nlen;
2513
2514 /* The input scrubber ensures that whitespace after the mnemonic is
2515 collapsed to single spaces. */
2516 oldname = p;
2517 if (strncmp (oldname, " .req ", 6) != 0)
2518 return FALSE;
2519
2520 oldname += 6;
2521 if (*oldname == '\0')
2522 return FALSE;
2523
2524 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2525 if (!old)
2526 {
2527 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2528 return TRUE;
2529 }
2530
2531 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2532 the desired alias name, and p points to its end. If not, then
2533 the desired alias name is in the global original_case_string. */
2534 #ifdef TC_CASE_SENSITIVE
2535 nlen = p - newname;
2536 #else
2537 newname = original_case_string;
2538 nlen = strlen (newname);
2539 #endif
2540
2541 nbuf = xmemdup0 (newname, nlen);
2542
2543 /* Create aliases under the new name as stated; an all-lowercase
2544 version of the new name; and an all-uppercase version of the new
2545 name. */
2546 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2547 {
2548 for (p = nbuf; *p; p++)
2549 *p = TOUPPER (*p);
2550
2551 if (strncmp (nbuf, newname, nlen))
2552 {
2553 /* If this attempt to create an additional alias fails, do not bother
2554 trying to create the all-lower case alias. We will fail and issue
2555 a second, duplicate error message. This situation arises when the
2556 programmer does something like:
2557 foo .req r0
2558 Foo .req r1
2559 The second .req creates the "Foo" alias but then fails to create
2560 the artificial FOO alias because it has already been created by the
2561 first .req. */
2562 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2563 {
2564 free (nbuf);
2565 return TRUE;
2566 }
2567 }
2568
2569 for (p = nbuf; *p; p++)
2570 *p = TOLOWER (*p);
2571
2572 if (strncmp (nbuf, newname, nlen))
2573 insert_reg_alias (nbuf, old->number, old->type);
2574 }
2575
2576 free (nbuf);
2577 return TRUE;
2578 }
2579
2580 /* Create a Neon typed/indexed register alias using directives, e.g.:
2581 X .dn d5.s32[1]
2582 Y .qn 6.s16
2583 Z .dn d7
2584 T .dn Z[0]
2585 These typed registers can be used instead of the types specified after the
2586 Neon mnemonic, so long as all operands given have types. Types can also be
2587 specified directly, e.g.:
2588 vadd d0.s32, d1.s32, d2.s32 */
2589
2590 static bfd_boolean
2591 create_neon_reg_alias (char *newname, char *p)
2592 {
2593 enum arm_reg_type basetype;
2594 struct reg_entry *basereg;
2595 struct reg_entry mybasereg;
2596 struct neon_type ntype;
2597 struct neon_typed_alias typeinfo;
2598 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2599 int namelen;
2600
2601 typeinfo.defined = 0;
2602 typeinfo.eltype.type = NT_invtype;
2603 typeinfo.eltype.size = -1;
2604 typeinfo.index = -1;
2605
2606 nameend = p;
2607
2608 if (strncmp (p, " .dn ", 5) == 0)
2609 basetype = REG_TYPE_VFD;
2610 else if (strncmp (p, " .qn ", 5) == 0)
2611 basetype = REG_TYPE_NQ;
2612 else
2613 return FALSE;
2614
2615 p += 5;
2616
2617 if (*p == '\0')
2618 return FALSE;
2619
2620 basereg = arm_reg_parse_multi (&p);
2621
2622 if (basereg && basereg->type != basetype)
2623 {
2624 as_bad (_("bad type for register"));
2625 return FALSE;
2626 }
2627
2628 if (basereg == NULL)
2629 {
2630 expressionS exp;
2631 /* Try parsing as an integer. */
2632 my_get_expression (&exp, &p, GE_NO_PREFIX);
2633 if (exp.X_op != O_constant)
2634 {
2635 as_bad (_("expression must be constant"));
2636 return FALSE;
2637 }
2638 basereg = &mybasereg;
2639 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2640 : exp.X_add_number;
2641 basereg->neon = 0;
2642 }
2643
2644 if (basereg->neon)
2645 typeinfo = *basereg->neon;
2646
2647 if (parse_neon_type (&ntype, &p) == SUCCESS)
2648 {
2649 /* We got a type. */
2650 if (typeinfo.defined & NTA_HASTYPE)
2651 {
2652 as_bad (_("can't redefine the type of a register alias"));
2653 return FALSE;
2654 }
2655
2656 typeinfo.defined |= NTA_HASTYPE;
2657 if (ntype.elems != 1)
2658 {
2659 as_bad (_("you must specify a single type only"));
2660 return FALSE;
2661 }
2662 typeinfo.eltype = ntype.el[0];
2663 }
2664
2665 if (skip_past_char (&p, '[') == SUCCESS)
2666 {
2667 expressionS exp;
2668 /* We got a scalar index. */
2669
2670 if (typeinfo.defined & NTA_HASINDEX)
2671 {
2672 as_bad (_("can't redefine the index of a scalar alias"));
2673 return FALSE;
2674 }
2675
2676 my_get_expression (&exp, &p, GE_NO_PREFIX);
2677
2678 if (exp.X_op != O_constant)
2679 {
2680 as_bad (_("scalar index must be constant"));
2681 return FALSE;
2682 }
2683
2684 typeinfo.defined |= NTA_HASINDEX;
2685 typeinfo.index = exp.X_add_number;
2686
2687 if (skip_past_char (&p, ']') == FAIL)
2688 {
2689 as_bad (_("expecting ]"));
2690 return FALSE;
2691 }
2692 }
2693
2694 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2695 the desired alias name, and p points to its end. If not, then
2696 the desired alias name is in the global original_case_string. */
2697 #ifdef TC_CASE_SENSITIVE
2698 namelen = nameend - newname;
2699 #else
2700 newname = original_case_string;
2701 namelen = strlen (newname);
2702 #endif
2703
2704 namebuf = xmemdup0 (newname, namelen);
2705
2706 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2707 typeinfo.defined != 0 ? &typeinfo : NULL);
2708
2709 /* Insert name in all uppercase. */
2710 for (p = namebuf; *p; p++)
2711 *p = TOUPPER (*p);
2712
2713 if (strncmp (namebuf, newname, namelen))
2714 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2715 typeinfo.defined != 0 ? &typeinfo : NULL);
2716
2717 /* Insert name in all lowercase. */
2718 for (p = namebuf; *p; p++)
2719 *p = TOLOWER (*p);
2720
2721 if (strncmp (namebuf, newname, namelen))
2722 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2723 typeinfo.defined != 0 ? &typeinfo : NULL);
2724
2725 free (namebuf);
2726 return TRUE;
2727 }
2728
2729 /* Should never be called, as .req goes between the alias and the
2730 register name, not at the beginning of the line. */
2731
2732 static void
2733 s_req (int a ATTRIBUTE_UNUSED)
2734 {
2735 as_bad (_("invalid syntax for .req directive"));
2736 }
2737
2738 static void
2739 s_dn (int a ATTRIBUTE_UNUSED)
2740 {
2741 as_bad (_("invalid syntax for .dn directive"));
2742 }
2743
2744 static void
2745 s_qn (int a ATTRIBUTE_UNUSED)
2746 {
2747 as_bad (_("invalid syntax for .qn directive"));
2748 }
2749
2750 /* The .unreq directive deletes an alias which was previously defined
2751 by .req. For example:
2752
2753 my_alias .req r11
2754 .unreq my_alias */
2755
2756 static void
2757 s_unreq (int a ATTRIBUTE_UNUSED)
2758 {
2759 char * name;
2760 char saved_char;
2761
2762 name = input_line_pointer;
2763
2764 while (*input_line_pointer != 0
2765 && *input_line_pointer != ' '
2766 && *input_line_pointer != '\n')
2767 ++input_line_pointer;
2768
2769 saved_char = *input_line_pointer;
2770 *input_line_pointer = 0;
2771
2772 if (!*name)
2773 as_bad (_("invalid syntax for .unreq directive"));
2774 else
2775 {
2776 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2777 name);
2778
2779 if (!reg)
2780 as_bad (_("unknown register alias '%s'"), name);
2781 else if (reg->builtin)
2782 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2783 name);
2784 else
2785 {
2786 char * p;
2787 char * nbuf;
2788
2789 hash_delete (arm_reg_hsh, name, FALSE);
2790 free ((char *) reg->name);
2791 if (reg->neon)
2792 free (reg->neon);
2793 free (reg);
2794
2795 /* Also locate the all upper case and all lower case versions.
2796 Do not complain if we cannot find one or the other as it
2797 was probably deleted above. */
2798
2799 nbuf = strdup (name);
2800 for (p = nbuf; *p; p++)
2801 *p = TOUPPER (*p);
2802 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2803 if (reg)
2804 {
2805 hash_delete (arm_reg_hsh, nbuf, FALSE);
2806 free ((char *) reg->name);
2807 if (reg->neon)
2808 free (reg->neon);
2809 free (reg);
2810 }
2811
2812 for (p = nbuf; *p; p++)
2813 *p = TOLOWER (*p);
2814 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2815 if (reg)
2816 {
2817 hash_delete (arm_reg_hsh, nbuf, FALSE);
2818 free ((char *) reg->name);
2819 if (reg->neon)
2820 free (reg->neon);
2821 free (reg);
2822 }
2823
2824 free (nbuf);
2825 }
2826 }
2827
2828 *input_line_pointer = saved_char;
2829 demand_empty_rest_of_line ();
2830 }
2831
2832 /* Directives: Instruction set selection. */
2833
2834 #ifdef OBJ_ELF
2835 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2836 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2837 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2838 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2839
2840 /* Create a new mapping symbol for the transition to STATE. */
2841
2842 static void
2843 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2844 {
2845 symbolS * symbolP;
2846 const char * symname;
2847 int type;
2848
2849 switch (state)
2850 {
2851 case MAP_DATA:
2852 symname = "$d";
2853 type = BSF_NO_FLAGS;
2854 break;
2855 case MAP_ARM:
2856 symname = "$a";
2857 type = BSF_NO_FLAGS;
2858 break;
2859 case MAP_THUMB:
2860 symname = "$t";
2861 type = BSF_NO_FLAGS;
2862 break;
2863 default:
2864 abort ();
2865 }
2866
2867 symbolP = symbol_new (symname, now_seg, value, frag);
2868 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2869
2870 switch (state)
2871 {
2872 case MAP_ARM:
2873 THUMB_SET_FUNC (symbolP, 0);
2874 ARM_SET_THUMB (symbolP, 0);
2875 ARM_SET_INTERWORK (symbolP, support_interwork);
2876 break;
2877
2878 case MAP_THUMB:
2879 THUMB_SET_FUNC (symbolP, 1);
2880 ARM_SET_THUMB (symbolP, 1);
2881 ARM_SET_INTERWORK (symbolP, support_interwork);
2882 break;
2883
2884 case MAP_DATA:
2885 default:
2886 break;
2887 }
2888
2889 /* Save the mapping symbols for future reference. Also check that
2890 we do not place two mapping symbols at the same offset within a
2891 frag. We'll handle overlap between frags in
2892 check_mapping_symbols.
2893
2894 If .fill or other data filling directive generates zero sized data,
2895 the mapping symbol for the following code will have the same value
2896 as the one generated for the data filling directive. In this case,
2897 we replace the old symbol with the new one at the same address. */
2898 if (value == 0)
2899 {
2900 if (frag->tc_frag_data.first_map != NULL)
2901 {
2902 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2903 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2904 }
2905 frag->tc_frag_data.first_map = symbolP;
2906 }
2907 if (frag->tc_frag_data.last_map != NULL)
2908 {
2909 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2910 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2911 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2912 }
2913 frag->tc_frag_data.last_map = symbolP;
2914 }
2915
2916 /* We must sometimes convert a region marked as code to data during
2917 code alignment, if an odd number of bytes have to be padded. The
2918 code mapping symbol is pushed to an aligned address. */
2919
2920 static void
2921 insert_data_mapping_symbol (enum mstate state,
2922 valueT value, fragS *frag, offsetT bytes)
2923 {
2924 /* If there was already a mapping symbol, remove it. */
2925 if (frag->tc_frag_data.last_map != NULL
2926 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2927 {
2928 symbolS *symp = frag->tc_frag_data.last_map;
2929
2930 if (value == 0)
2931 {
2932 know (frag->tc_frag_data.first_map == symp);
2933 frag->tc_frag_data.first_map = NULL;
2934 }
2935 frag->tc_frag_data.last_map = NULL;
2936 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2937 }
2938
2939 make_mapping_symbol (MAP_DATA, value, frag);
2940 make_mapping_symbol (state, value + bytes, frag);
2941 }
2942
2943 static void mapping_state_2 (enum mstate state, int max_chars);
2944
2945 /* Set the mapping state to STATE. Only call this when about to
2946 emit some STATE bytes to the file. */
2947
2948 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2949 void
2950 mapping_state (enum mstate state)
2951 {
2952 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2953
2954 if (mapstate == state)
2955 /* The mapping symbol has already been emitted.
2956 There is nothing else to do. */
2957 return;
2958
2959 if (state == MAP_ARM || state == MAP_THUMB)
2960 /* PR gas/12931
2961 All ARM instructions require 4-byte alignment.
2962 (Almost) all Thumb instructions require 2-byte alignment.
2963
2964 When emitting instructions into any section, mark the section
2965 appropriately.
2966
2967 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2968 but themselves require 2-byte alignment; this applies to some
2969 PC- relative forms. However, these cases will involve implicit
2970 literal pool generation or an explicit .align >=2, both of
2971 which will cause the section to me marked with sufficient
2972 alignment. Thus, we don't handle those cases here. */
2973 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2974
2975 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2976 /* This case will be evaluated later. */
2977 return;
2978
2979 mapping_state_2 (state, 0);
2980 }
2981
2982 /* Same as mapping_state, but MAX_CHARS bytes have already been
2983 allocated. Put the mapping symbol that far back. */
2984
2985 static void
2986 mapping_state_2 (enum mstate state, int max_chars)
2987 {
2988 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2989
2990 if (!SEG_NORMAL (now_seg))
2991 return;
2992
2993 if (mapstate == state)
2994 /* The mapping symbol has already been emitted.
2995 There is nothing else to do. */
2996 return;
2997
2998 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2999 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
3000 {
3001 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
3002 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
3003
3004 if (add_symbol)
3005 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
3006 }
3007
3008 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
3009 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
3010 }
3011 #undef TRANSITION
3012 #else
3013 #define mapping_state(x) ((void)0)
3014 #define mapping_state_2(x, y) ((void)0)
3015 #endif
3016
3017 /* Find the real, Thumb encoded start of a Thumb function. */
3018
3019 #ifdef OBJ_COFF
3020 static symbolS *
3021 find_real_start (symbolS * symbolP)
3022 {
3023 char * real_start;
3024 const char * name = S_GET_NAME (symbolP);
3025 symbolS * new_target;
3026
3027 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
3028 #define STUB_NAME ".real_start_of"
3029
3030 if (name == NULL)
3031 abort ();
3032
3033 /* The compiler may generate BL instructions to local labels because
3034 it needs to perform a branch to a far away location. These labels
3035 do not have a corresponding ".real_start_of" label. We check
3036 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
3037 the ".real_start_of" convention for nonlocal branches. */
3038 if (S_IS_LOCAL (symbolP) || name[0] == '.')
3039 return symbolP;
3040
3041 real_start = concat (STUB_NAME, name, NULL);
3042 new_target = symbol_find (real_start);
3043 free (real_start);
3044
3045 if (new_target == NULL)
3046 {
3047 as_warn (_("Failed to find real start of function: %s\n"), name);
3048 new_target = symbolP;
3049 }
3050
3051 return new_target;
3052 }
3053 #endif
3054
3055 static void
3056 opcode_select (int width)
3057 {
3058 switch (width)
3059 {
3060 case 16:
3061 if (! thumb_mode)
3062 {
3063 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
3064 as_bad (_("selected processor does not support THUMB opcodes"));
3065
3066 thumb_mode = 1;
3067 /* No need to force the alignment, since we will have been
3068 coming from ARM mode, which is word-aligned. */
3069 record_alignment (now_seg, 1);
3070 }
3071 break;
3072
3073 case 32:
3074 if (thumb_mode)
3075 {
3076 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
3077 as_bad (_("selected processor does not support ARM opcodes"));
3078
3079 thumb_mode = 0;
3080
3081 if (!need_pass_2)
3082 frag_align (2, 0, 0);
3083
3084 record_alignment (now_seg, 1);
3085 }
3086 break;
3087
3088 default:
3089 as_bad (_("invalid instruction size selected (%d)"), width);
3090 }
3091 }
3092
3093 static void
3094 s_arm (int ignore ATTRIBUTE_UNUSED)
3095 {
3096 opcode_select (32);
3097 demand_empty_rest_of_line ();
3098 }
3099
3100 static void
3101 s_thumb (int ignore ATTRIBUTE_UNUSED)
3102 {
3103 opcode_select (16);
3104 demand_empty_rest_of_line ();
3105 }
3106
3107 static void
3108 s_code (int unused ATTRIBUTE_UNUSED)
3109 {
3110 int temp;
3111
3112 temp = get_absolute_expression ();
3113 switch (temp)
3114 {
3115 case 16:
3116 case 32:
3117 opcode_select (temp);
3118 break;
3119
3120 default:
3121 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
3122 }
3123 }
3124
3125 static void
3126 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
3127 {
3128 /* If we are not already in thumb mode go into it, EVEN if
3129 the target processor does not support thumb instructions.
3130 This is used by gcc/config/arm/lib1funcs.asm for example
3131 to compile interworking support functions even if the
3132 target processor should not support interworking. */
3133 if (! thumb_mode)
3134 {
3135 thumb_mode = 2;
3136 record_alignment (now_seg, 1);
3137 }
3138
3139 demand_empty_rest_of_line ();
3140 }
3141
3142 static void
3143 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
3144 {
3145 s_thumb (0);
3146
3147 /* The following label is the name/address of the start of a Thumb function.
3148 We need to know this for the interworking support. */
3149 label_is_thumb_function_name = TRUE;
3150 }
3151
3152 /* Perform a .set directive, but also mark the alias as
3153 being a thumb function. */
3154
3155 static void
3156 s_thumb_set (int equiv)
3157 {
3158 /* XXX the following is a duplicate of the code for s_set() in read.c
3159 We cannot just call that code as we need to get at the symbol that
3160 is created. */
3161 char * name;
3162 char delim;
3163 char * end_name;
3164 symbolS * symbolP;
3165
3166 /* Especial apologies for the random logic:
3167 This just grew, and could be parsed much more simply!
3168 Dean - in haste. */
3169 delim = get_symbol_name (& name);
3170 end_name = input_line_pointer;
3171 (void) restore_line_pointer (delim);
3172
3173 if (*input_line_pointer != ',')
3174 {
3175 *end_name = 0;
3176 as_bad (_("expected comma after name \"%s\""), name);
3177 *end_name = delim;
3178 ignore_rest_of_line ();
3179 return;
3180 }
3181
3182 input_line_pointer++;
3183 *end_name = 0;
3184
3185 if (name[0] == '.' && name[1] == '\0')
3186 {
3187 /* XXX - this should not happen to .thumb_set. */
3188 abort ();
3189 }
3190
3191 if ((symbolP = symbol_find (name)) == NULL
3192 && (symbolP = md_undefined_symbol (name)) == NULL)
3193 {
3194 #ifndef NO_LISTING
3195 /* When doing symbol listings, play games with dummy fragments living
3196 outside the normal fragment chain to record the file and line info
3197 for this symbol. */
3198 if (listing & LISTING_SYMBOLS)
3199 {
3200 extern struct list_info_struct * listing_tail;
3201 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
3202
3203 memset (dummy_frag, 0, sizeof (fragS));
3204 dummy_frag->fr_type = rs_fill;
3205 dummy_frag->line = listing_tail;
3206 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
3207 dummy_frag->fr_symbol = symbolP;
3208 }
3209 else
3210 #endif
3211 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3212
3213 #ifdef OBJ_COFF
3214 /* "set" symbols are local unless otherwise specified. */
3215 SF_SET_LOCAL (symbolP);
3216 #endif /* OBJ_COFF */
3217 } /* Make a new symbol. */
3218
3219 symbol_table_insert (symbolP);
3220
3221 * end_name = delim;
3222
3223 if (equiv
3224 && S_IS_DEFINED (symbolP)
3225 && S_GET_SEGMENT (symbolP) != reg_section)
3226 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3227
3228 pseudo_set (symbolP);
3229
3230 demand_empty_rest_of_line ();
3231
3232 /* XXX Now we come to the Thumb specific bit of code. */
3233
3234 THUMB_SET_FUNC (symbolP, 1);
3235 ARM_SET_THUMB (symbolP, 1);
3236 #if defined OBJ_ELF || defined OBJ_COFF
3237 ARM_SET_INTERWORK (symbolP, support_interwork);
3238 #endif
3239 }
3240
3241 /* Directives: Mode selection. */
3242
3243 /* .syntax [unified|divided] - choose the new unified syntax
3244 (same for Arm and Thumb encoding, modulo slight differences in what
3245 can be represented) or the old divergent syntax for each mode. */
3246 static void
3247 s_syntax (int unused ATTRIBUTE_UNUSED)
3248 {
3249 char *name, delim;
3250
3251 delim = get_symbol_name (& name);
3252
3253 if (!strcasecmp (name, "unified"))
3254 unified_syntax = TRUE;
3255 else if (!strcasecmp (name, "divided"))
3256 unified_syntax = FALSE;
3257 else
3258 {
3259 as_bad (_("unrecognized syntax mode \"%s\""), name);
3260 return;
3261 }
3262 (void) restore_line_pointer (delim);
3263 demand_empty_rest_of_line ();
3264 }
3265
3266 /* Directives: sectioning and alignment. */
3267
3268 static void
3269 s_bss (int ignore ATTRIBUTE_UNUSED)
3270 {
3271 /* We don't support putting frags in the BSS segment, we fake it by
3272 marking in_bss, then looking at s_skip for clues. */
3273 subseg_set (bss_section, 0);
3274 demand_empty_rest_of_line ();
3275
3276 #ifdef md_elf_section_change_hook
3277 md_elf_section_change_hook ();
3278 #endif
3279 }
3280
3281 static void
3282 s_even (int ignore ATTRIBUTE_UNUSED)
3283 {
3284 /* Never make frag if expect extra pass. */
3285 if (!need_pass_2)
3286 frag_align (1, 0, 0);
3287
3288 record_alignment (now_seg, 1);
3289
3290 demand_empty_rest_of_line ();
3291 }
3292
3293 /* Directives: CodeComposer Studio. */
3294
3295 /* .ref (for CodeComposer Studio syntax only). */
3296 static void
3297 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3298 {
3299 if (codecomposer_syntax)
3300 ignore_rest_of_line ();
3301 else
3302 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3303 }
3304
3305 /* If name is not NULL, then it is used for marking the beginning of a
3306 function, whereas if it is NULL then it means the function end. */
3307 static void
3308 asmfunc_debug (const char * name)
3309 {
3310 static const char * last_name = NULL;
3311
3312 if (name != NULL)
3313 {
3314 gas_assert (last_name == NULL);
3315 last_name = name;
3316
3317 if (debug_type == DEBUG_STABS)
3318 stabs_generate_asm_func (name, name);
3319 }
3320 else
3321 {
3322 gas_assert (last_name != NULL);
3323
3324 if (debug_type == DEBUG_STABS)
3325 stabs_generate_asm_endfunc (last_name, last_name);
3326
3327 last_name = NULL;
3328 }
3329 }
3330
3331 static void
3332 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3333 {
3334 if (codecomposer_syntax)
3335 {
3336 switch (asmfunc_state)
3337 {
3338 case OUTSIDE_ASMFUNC:
3339 asmfunc_state = WAITING_ASMFUNC_NAME;
3340 break;
3341
3342 case WAITING_ASMFUNC_NAME:
3343 as_bad (_(".asmfunc repeated."));
3344 break;
3345
3346 case WAITING_ENDASMFUNC:
3347 as_bad (_(".asmfunc without function."));
3348 break;
3349 }
3350 demand_empty_rest_of_line ();
3351 }
3352 else
3353 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3354 }
3355
3356 static void
3357 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3358 {
3359 if (codecomposer_syntax)
3360 {
3361 switch (asmfunc_state)
3362 {
3363 case OUTSIDE_ASMFUNC:
3364 as_bad (_(".endasmfunc without a .asmfunc."));
3365 break;
3366
3367 case WAITING_ASMFUNC_NAME:
3368 as_bad (_(".endasmfunc without function."));
3369 break;
3370
3371 case WAITING_ENDASMFUNC:
3372 asmfunc_state = OUTSIDE_ASMFUNC;
3373 asmfunc_debug (NULL);
3374 break;
3375 }
3376 demand_empty_rest_of_line ();
3377 }
3378 else
3379 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3380 }
3381
3382 static void
3383 s_ccs_def (int name)
3384 {
3385 if (codecomposer_syntax)
3386 s_globl (name);
3387 else
3388 as_bad (_(".def pseudo-op only available with -mccs flag."));
3389 }
3390
3391 /* Directives: Literal pools. */
3392
3393 static literal_pool *
3394 find_literal_pool (void)
3395 {
3396 literal_pool * pool;
3397
3398 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3399 {
3400 if (pool->section == now_seg
3401 && pool->sub_section == now_subseg)
3402 break;
3403 }
3404
3405 return pool;
3406 }
3407
3408 static literal_pool *
3409 find_or_make_literal_pool (void)
3410 {
3411 /* Next literal pool ID number. */
3412 static unsigned int latest_pool_num = 1;
3413 literal_pool * pool;
3414
3415 pool = find_literal_pool ();
3416
3417 if (pool == NULL)
3418 {
3419 /* Create a new pool. */
3420 pool = XNEW (literal_pool);
3421 if (! pool)
3422 return NULL;
3423
3424 pool->next_free_entry = 0;
3425 pool->section = now_seg;
3426 pool->sub_section = now_subseg;
3427 pool->next = list_of_pools;
3428 pool->symbol = NULL;
3429 pool->alignment = 2;
3430
3431 /* Add it to the list. */
3432 list_of_pools = pool;
3433 }
3434
3435 /* New pools, and emptied pools, will have a NULL symbol. */
3436 if (pool->symbol == NULL)
3437 {
3438 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3439 (valueT) 0, &zero_address_frag);
3440 pool->id = latest_pool_num ++;
3441 }
3442
3443 /* Done. */
3444 return pool;
3445 }
3446
3447 /* Add the literal in the global 'inst'
3448 structure to the relevant literal pool. */
3449
3450 static int
3451 add_to_lit_pool (unsigned int nbytes)
3452 {
3453 #define PADDING_SLOT 0x1
3454 #define LIT_ENTRY_SIZE_MASK 0xFF
3455 literal_pool * pool;
3456 unsigned int entry, pool_size = 0;
3457 bfd_boolean padding_slot_p = FALSE;
3458 unsigned imm1 = 0;
3459 unsigned imm2 = 0;
3460
3461 if (nbytes == 8)
3462 {
3463 imm1 = inst.operands[1].imm;
3464 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3465 : inst.relocs[0].exp.X_unsigned ? 0
3466 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
3467 if (target_big_endian)
3468 {
3469 imm1 = imm2;
3470 imm2 = inst.operands[1].imm;
3471 }
3472 }
3473
3474 pool = find_or_make_literal_pool ();
3475
3476 /* Check if this literal value is already in the pool. */
3477 for (entry = 0; entry < pool->next_free_entry; entry ++)
3478 {
3479 if (nbytes == 4)
3480 {
3481 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3482 && (inst.relocs[0].exp.X_op == O_constant)
3483 && (pool->literals[entry].X_add_number
3484 == inst.relocs[0].exp.X_add_number)
3485 && (pool->literals[entry].X_md == nbytes)
3486 && (pool->literals[entry].X_unsigned
3487 == inst.relocs[0].exp.X_unsigned))
3488 break;
3489
3490 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3491 && (inst.relocs[0].exp.X_op == O_symbol)
3492 && (pool->literals[entry].X_add_number
3493 == inst.relocs[0].exp.X_add_number)
3494 && (pool->literals[entry].X_add_symbol
3495 == inst.relocs[0].exp.X_add_symbol)
3496 && (pool->literals[entry].X_op_symbol
3497 == inst.relocs[0].exp.X_op_symbol)
3498 && (pool->literals[entry].X_md == nbytes))
3499 break;
3500 }
3501 else if ((nbytes == 8)
3502 && !(pool_size & 0x7)
3503 && ((entry + 1) != pool->next_free_entry)
3504 && (pool->literals[entry].X_op == O_constant)
3505 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3506 && (pool->literals[entry].X_unsigned
3507 == inst.relocs[0].exp.X_unsigned)
3508 && (pool->literals[entry + 1].X_op == O_constant)
3509 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3510 && (pool->literals[entry + 1].X_unsigned
3511 == inst.relocs[0].exp.X_unsigned))
3512 break;
3513
3514 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3515 if (padding_slot_p && (nbytes == 4))
3516 break;
3517
3518 pool_size += 4;
3519 }
3520
3521 /* Do we need to create a new entry? */
3522 if (entry == pool->next_free_entry)
3523 {
3524 if (entry >= MAX_LITERAL_POOL_SIZE)
3525 {
3526 inst.error = _("literal pool overflow");
3527 return FAIL;
3528 }
3529
3530 if (nbytes == 8)
3531 {
3532 /* For 8-byte entries, we align to an 8-byte boundary,
3533 and split it into two 4-byte entries, because on 32-bit
3534 host, 8-byte constants are treated as big num, thus
3535 saved in "generic_bignum" which will be overwritten
3536 by later assignments.
3537
3538 We also need to make sure there is enough space for
3539 the split.
3540
3541 We also check to make sure the literal operand is a
3542 constant number. */
3543 if (!(inst.relocs[0].exp.X_op == O_constant
3544 || inst.relocs[0].exp.X_op == O_big))
3545 {
3546 inst.error = _("invalid type for literal pool");
3547 return FAIL;
3548 }
3549 else if (pool_size & 0x7)
3550 {
3551 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3552 {
3553 inst.error = _("literal pool overflow");
3554 return FAIL;
3555 }
3556
3557 pool->literals[entry] = inst.relocs[0].exp;
3558 pool->literals[entry].X_op = O_constant;
3559 pool->literals[entry].X_add_number = 0;
3560 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3561 pool->next_free_entry += 1;
3562 pool_size += 4;
3563 }
3564 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3565 {
3566 inst.error = _("literal pool overflow");
3567 return FAIL;
3568 }
3569
3570 pool->literals[entry] = inst.relocs[0].exp;
3571 pool->literals[entry].X_op = O_constant;
3572 pool->literals[entry].X_add_number = imm1;
3573 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3574 pool->literals[entry++].X_md = 4;
3575 pool->literals[entry] = inst.relocs[0].exp;
3576 pool->literals[entry].X_op = O_constant;
3577 pool->literals[entry].X_add_number = imm2;
3578 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3579 pool->literals[entry].X_md = 4;
3580 pool->alignment = 3;
3581 pool->next_free_entry += 1;
3582 }
3583 else
3584 {
3585 pool->literals[entry] = inst.relocs[0].exp;
3586 pool->literals[entry].X_md = 4;
3587 }
3588
3589 #ifdef OBJ_ELF
3590 /* PR ld/12974: Record the location of the first source line to reference
3591 this entry in the literal pool. If it turns out during linking that the
3592 symbol does not exist we will be able to give an accurate line number for
3593 the (first use of the) missing reference. */
3594 if (debug_type == DEBUG_DWARF2)
3595 dwarf2_where (pool->locs + entry);
3596 #endif
3597 pool->next_free_entry += 1;
3598 }
3599 else if (padding_slot_p)
3600 {
3601 pool->literals[entry] = inst.relocs[0].exp;
3602 pool->literals[entry].X_md = nbytes;
3603 }
3604
3605 inst.relocs[0].exp.X_op = O_symbol;
3606 inst.relocs[0].exp.X_add_number = pool_size;
3607 inst.relocs[0].exp.X_add_symbol = pool->symbol;
3608
3609 return SUCCESS;
3610 }
3611
3612 bfd_boolean
3613 tc_start_label_without_colon (void)
3614 {
3615 bfd_boolean ret = TRUE;
3616
3617 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3618 {
3619 const char *label = input_line_pointer;
3620
3621 while (!is_end_of_line[(int) label[-1]])
3622 --label;
3623
3624 if (*label == '.')
3625 {
3626 as_bad (_("Invalid label '%s'"), label);
3627 ret = FALSE;
3628 }
3629
3630 asmfunc_debug (label);
3631
3632 asmfunc_state = WAITING_ENDASMFUNC;
3633 }
3634
3635 return ret;
3636 }
3637
3638 /* Can't use symbol_new here, so have to create a symbol and then at
3639 a later date assign it a value. That's what these functions do. */
3640
3641 static void
3642 symbol_locate (symbolS * symbolP,
3643 const char * name, /* It is copied, the caller can modify. */
3644 segT segment, /* Segment identifier (SEG_<something>). */
3645 valueT valu, /* Symbol value. */
3646 fragS * frag) /* Associated fragment. */
3647 {
3648 size_t name_length;
3649 char * preserved_copy_of_name;
3650
3651 name_length = strlen (name) + 1; /* +1 for \0. */
3652 obstack_grow (&notes, name, name_length);
3653 preserved_copy_of_name = (char *) obstack_finish (&notes);
3654
3655 #ifdef tc_canonicalize_symbol_name
3656 preserved_copy_of_name =
3657 tc_canonicalize_symbol_name (preserved_copy_of_name);
3658 #endif
3659
3660 S_SET_NAME (symbolP, preserved_copy_of_name);
3661
3662 S_SET_SEGMENT (symbolP, segment);
3663 S_SET_VALUE (symbolP, valu);
3664 symbol_clear_list_pointers (symbolP);
3665
3666 symbol_set_frag (symbolP, frag);
3667
3668 /* Link to end of symbol chain. */
3669 {
3670 extern int symbol_table_frozen;
3671
3672 if (symbol_table_frozen)
3673 abort ();
3674 }
3675
3676 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3677
3678 obj_symbol_new_hook (symbolP);
3679
3680 #ifdef tc_symbol_new_hook
3681 tc_symbol_new_hook (symbolP);
3682 #endif
3683
3684 #ifdef DEBUG_SYMS
3685 verify_symbol_chain (symbol_rootP, symbol_lastP);
3686 #endif /* DEBUG_SYMS */
3687 }
3688
3689 static void
3690 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3691 {
3692 unsigned int entry;
3693 literal_pool * pool;
3694 char sym_name[20];
3695
3696 pool = find_literal_pool ();
3697 if (pool == NULL
3698 || pool->symbol == NULL
3699 || pool->next_free_entry == 0)
3700 return;
3701
3702 /* Align pool as you have word accesses.
3703 Only make a frag if we have to. */
3704 if (!need_pass_2)
3705 frag_align (pool->alignment, 0, 0);
3706
3707 record_alignment (now_seg, 2);
3708
3709 #ifdef OBJ_ELF
3710 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3711 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3712 #endif
3713 sprintf (sym_name, "$$lit_\002%x", pool->id);
3714
3715 symbol_locate (pool->symbol, sym_name, now_seg,
3716 (valueT) frag_now_fix (), frag_now);
3717 symbol_table_insert (pool->symbol);
3718
3719 ARM_SET_THUMB (pool->symbol, thumb_mode);
3720
3721 #if defined OBJ_COFF || defined OBJ_ELF
3722 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3723 #endif
3724
3725 for (entry = 0; entry < pool->next_free_entry; entry ++)
3726 {
3727 #ifdef OBJ_ELF
3728 if (debug_type == DEBUG_DWARF2)
3729 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3730 #endif
3731 /* First output the expression in the instruction to the pool. */
3732 emit_expr (&(pool->literals[entry]),
3733 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3734 }
3735
3736 /* Mark the pool as empty. */
3737 pool->next_free_entry = 0;
3738 pool->symbol = NULL;
3739 }
3740
3741 #ifdef OBJ_ELF
3742 /* Forward declarations for functions below, in the MD interface
3743 section. */
3744 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3745 static valueT create_unwind_entry (int);
3746 static void start_unwind_section (const segT, int);
3747 static void add_unwind_opcode (valueT, int);
3748 static void flush_pending_unwind (void);
3749
3750 /* Directives: Data. */
3751
3752 static void
3753 s_arm_elf_cons (int nbytes)
3754 {
3755 expressionS exp;
3756
3757 #ifdef md_flush_pending_output
3758 md_flush_pending_output ();
3759 #endif
3760
3761 if (is_it_end_of_statement ())
3762 {
3763 demand_empty_rest_of_line ();
3764 return;
3765 }
3766
3767 #ifdef md_cons_align
3768 md_cons_align (nbytes);
3769 #endif
3770
3771 mapping_state (MAP_DATA);
3772 do
3773 {
3774 int reloc;
3775 char *base = input_line_pointer;
3776
3777 expression (& exp);
3778
3779 if (exp.X_op != O_symbol)
3780 emit_expr (&exp, (unsigned int) nbytes);
3781 else
3782 {
3783 char *before_reloc = input_line_pointer;
3784 reloc = parse_reloc (&input_line_pointer);
3785 if (reloc == -1)
3786 {
3787 as_bad (_("unrecognized relocation suffix"));
3788 ignore_rest_of_line ();
3789 return;
3790 }
3791 else if (reloc == BFD_RELOC_UNUSED)
3792 emit_expr (&exp, (unsigned int) nbytes);
3793 else
3794 {
3795 reloc_howto_type *howto = (reloc_howto_type *)
3796 bfd_reloc_type_lookup (stdoutput,
3797 (bfd_reloc_code_real_type) reloc);
3798 int size = bfd_get_reloc_size (howto);
3799
3800 if (reloc == BFD_RELOC_ARM_PLT32)
3801 {
3802 as_bad (_("(plt) is only valid on branch targets"));
3803 reloc = BFD_RELOC_UNUSED;
3804 size = 0;
3805 }
3806
3807 if (size > nbytes)
3808 as_bad (ngettext ("%s relocations do not fit in %d byte",
3809 "%s relocations do not fit in %d bytes",
3810 nbytes),
3811 howto->name, nbytes);
3812 else
3813 {
3814 /* We've parsed an expression stopping at O_symbol.
3815 But there may be more expression left now that we
3816 have parsed the relocation marker. Parse it again.
3817 XXX Surely there is a cleaner way to do this. */
3818 char *p = input_line_pointer;
3819 int offset;
3820 char *save_buf = XNEWVEC (char, input_line_pointer - base);
3821
3822 memcpy (save_buf, base, input_line_pointer - base);
3823 memmove (base + (input_line_pointer - before_reloc),
3824 base, before_reloc - base);
3825
3826 input_line_pointer = base + (input_line_pointer-before_reloc);
3827 expression (&exp);
3828 memcpy (base, save_buf, p - base);
3829
3830 offset = nbytes - size;
3831 p = frag_more (nbytes);
3832 memset (p, 0, nbytes);
3833 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3834 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3835 free (save_buf);
3836 }
3837 }
3838 }
3839 }
3840 while (*input_line_pointer++ == ',');
3841
3842 /* Put terminator back into stream. */
3843 input_line_pointer --;
3844 demand_empty_rest_of_line ();
3845 }
3846
3847 /* Emit an expression containing a 32-bit thumb instruction.
3848 Implementation based on put_thumb32_insn. */
3849
3850 static void
3851 emit_thumb32_expr (expressionS * exp)
3852 {
3853 expressionS exp_high = *exp;
3854
3855 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3856 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3857 exp->X_add_number &= 0xffff;
3858 emit_expr (exp, (unsigned int) THUMB_SIZE);
3859 }
3860
3861 /* Guess the instruction size based on the opcode. */
3862
3863 static int
3864 thumb_insn_size (int opcode)
3865 {
3866 if ((unsigned int) opcode < 0xe800u)
3867 return 2;
3868 else if ((unsigned int) opcode >= 0xe8000000u)
3869 return 4;
3870 else
3871 return 0;
3872 }
3873
3874 static bfd_boolean
3875 emit_insn (expressionS *exp, int nbytes)
3876 {
3877 int size = 0;
3878
3879 if (exp->X_op == O_constant)
3880 {
3881 size = nbytes;
3882
3883 if (size == 0)
3884 size = thumb_insn_size (exp->X_add_number);
3885
3886 if (size != 0)
3887 {
3888 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3889 {
3890 as_bad (_(".inst.n operand too big. "\
3891 "Use .inst.w instead"));
3892 size = 0;
3893 }
3894 else
3895 {
3896 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
3897 set_pred_insn_type_nonvoid (OUTSIDE_PRED_INSN, 0);
3898 else
3899 set_pred_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3900
3901 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3902 emit_thumb32_expr (exp);
3903 else
3904 emit_expr (exp, (unsigned int) size);
3905
3906 it_fsm_post_encode ();
3907 }
3908 }
3909 else
3910 as_bad (_("cannot determine Thumb instruction size. " \
3911 "Use .inst.n/.inst.w instead"));
3912 }
3913 else
3914 as_bad (_("constant expression required"));
3915
3916 return (size != 0);
3917 }
3918
3919 /* Like s_arm_elf_cons but do not use md_cons_align and
3920 set the mapping state to MAP_ARM/MAP_THUMB. */
3921
3922 static void
3923 s_arm_elf_inst (int nbytes)
3924 {
3925 if (is_it_end_of_statement ())
3926 {
3927 demand_empty_rest_of_line ();
3928 return;
3929 }
3930
3931 /* Calling mapping_state () here will not change ARM/THUMB,
3932 but will ensure not to be in DATA state. */
3933
3934 if (thumb_mode)
3935 mapping_state (MAP_THUMB);
3936 else
3937 {
3938 if (nbytes != 0)
3939 {
3940 as_bad (_("width suffixes are invalid in ARM mode"));
3941 ignore_rest_of_line ();
3942 return;
3943 }
3944
3945 nbytes = 4;
3946
3947 mapping_state (MAP_ARM);
3948 }
3949
3950 do
3951 {
3952 expressionS exp;
3953
3954 expression (& exp);
3955
3956 if (! emit_insn (& exp, nbytes))
3957 {
3958 ignore_rest_of_line ();
3959 return;
3960 }
3961 }
3962 while (*input_line_pointer++ == ',');
3963
3964 /* Put terminator back into stream. */
3965 input_line_pointer --;
3966 demand_empty_rest_of_line ();
3967 }
3968
3969 /* Parse a .rel31 directive. */
3970
3971 static void
3972 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3973 {
3974 expressionS exp;
3975 char *p;
3976 valueT highbit;
3977
3978 highbit = 0;
3979 if (*input_line_pointer == '1')
3980 highbit = 0x80000000;
3981 else if (*input_line_pointer != '0')
3982 as_bad (_("expected 0 or 1"));
3983
3984 input_line_pointer++;
3985 if (*input_line_pointer != ',')
3986 as_bad (_("missing comma"));
3987 input_line_pointer++;
3988
3989 #ifdef md_flush_pending_output
3990 md_flush_pending_output ();
3991 #endif
3992
3993 #ifdef md_cons_align
3994 md_cons_align (4);
3995 #endif
3996
3997 mapping_state (MAP_DATA);
3998
3999 expression (&exp);
4000
4001 p = frag_more (4);
4002 md_number_to_chars (p, highbit, 4);
4003 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
4004 BFD_RELOC_ARM_PREL31);
4005
4006 demand_empty_rest_of_line ();
4007 }
4008
4009 /* Directives: AEABI stack-unwind tables. */
4010
4011 /* Parse an unwind_fnstart directive. Simply records the current location. */
4012
4013 static void
4014 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
4015 {
4016 demand_empty_rest_of_line ();
4017 if (unwind.proc_start)
4018 {
4019 as_bad (_("duplicate .fnstart directive"));
4020 return;
4021 }
4022
4023 /* Mark the start of the function. */
4024 unwind.proc_start = expr_build_dot ();
4025
4026 /* Reset the rest of the unwind info. */
4027 unwind.opcode_count = 0;
4028 unwind.table_entry = NULL;
4029 unwind.personality_routine = NULL;
4030 unwind.personality_index = -1;
4031 unwind.frame_size = 0;
4032 unwind.fp_offset = 0;
4033 unwind.fp_reg = REG_SP;
4034 unwind.fp_used = 0;
4035 unwind.sp_restored = 0;
4036 }
4037
4038
4039 /* Parse a handlerdata directive. Creates the exception handling table entry
4040 for the function. */
4041
4042 static void
4043 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
4044 {
4045 demand_empty_rest_of_line ();
4046 if (!unwind.proc_start)
4047 as_bad (MISSING_FNSTART);
4048
4049 if (unwind.table_entry)
4050 as_bad (_("duplicate .handlerdata directive"));
4051
4052 create_unwind_entry (1);
4053 }
4054
4055 /* Parse an unwind_fnend directive. Generates the index table entry. */
4056
4057 static void
4058 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
4059 {
4060 long where;
4061 char *ptr;
4062 valueT val;
4063 unsigned int marked_pr_dependency;
4064
4065 demand_empty_rest_of_line ();
4066
4067 if (!unwind.proc_start)
4068 {
4069 as_bad (_(".fnend directive without .fnstart"));
4070 return;
4071 }
4072
4073 /* Add eh table entry. */
4074 if (unwind.table_entry == NULL)
4075 val = create_unwind_entry (0);
4076 else
4077 val = 0;
4078
4079 /* Add index table entry. This is two words. */
4080 start_unwind_section (unwind.saved_seg, 1);
4081 frag_align (2, 0, 0);
4082 record_alignment (now_seg, 2);
4083
4084 ptr = frag_more (8);
4085 memset (ptr, 0, 8);
4086 where = frag_now_fix () - 8;
4087
4088 /* Self relative offset of the function start. */
4089 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
4090 BFD_RELOC_ARM_PREL31);
4091
4092 /* Indicate dependency on EHABI-defined personality routines to the
4093 linker, if it hasn't been done already. */
4094 marked_pr_dependency
4095 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
4096 if (unwind.personality_index >= 0 && unwind.personality_index < 3
4097 && !(marked_pr_dependency & (1 << unwind.personality_index)))
4098 {
4099 static const char *const name[] =
4100 {
4101 "__aeabi_unwind_cpp_pr0",
4102 "__aeabi_unwind_cpp_pr1",
4103 "__aeabi_unwind_cpp_pr2"
4104 };
4105 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
4106 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
4107 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
4108 |= 1 << unwind.personality_index;
4109 }
4110
4111 if (val)
4112 /* Inline exception table entry. */
4113 md_number_to_chars (ptr + 4, val, 4);
4114 else
4115 /* Self relative offset of the table entry. */
4116 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
4117 BFD_RELOC_ARM_PREL31);
4118
4119 /* Restore the original section. */
4120 subseg_set (unwind.saved_seg, unwind.saved_subseg);
4121
4122 unwind.proc_start = NULL;
4123 }
4124
4125
4126 /* Parse an unwind_cantunwind directive. */
4127
4128 static void
4129 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
4130 {
4131 demand_empty_rest_of_line ();
4132 if (!unwind.proc_start)
4133 as_bad (MISSING_FNSTART);
4134
4135 if (unwind.personality_routine || unwind.personality_index != -1)
4136 as_bad (_("personality routine specified for cantunwind frame"));
4137
4138 unwind.personality_index = -2;
4139 }
4140
4141
4142 /* Parse a personalityindex directive. */
4143
4144 static void
4145 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
4146 {
4147 expressionS exp;
4148
4149 if (!unwind.proc_start)
4150 as_bad (MISSING_FNSTART);
4151
4152 if (unwind.personality_routine || unwind.personality_index != -1)
4153 as_bad (_("duplicate .personalityindex directive"));
4154
4155 expression (&exp);
4156
4157 if (exp.X_op != O_constant
4158 || exp.X_add_number < 0 || exp.X_add_number > 15)
4159 {
4160 as_bad (_("bad personality routine number"));
4161 ignore_rest_of_line ();
4162 return;
4163 }
4164
4165 unwind.personality_index = exp.X_add_number;
4166
4167 demand_empty_rest_of_line ();
4168 }
4169
4170
4171 /* Parse a personality directive. */
4172
4173 static void
4174 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
4175 {
4176 char *name, *p, c;
4177
4178 if (!unwind.proc_start)
4179 as_bad (MISSING_FNSTART);
4180
4181 if (unwind.personality_routine || unwind.personality_index != -1)
4182 as_bad (_("duplicate .personality directive"));
4183
4184 c = get_symbol_name (& name);
4185 p = input_line_pointer;
4186 if (c == '"')
4187 ++ input_line_pointer;
4188 unwind.personality_routine = symbol_find_or_make (name);
4189 *p = c;
4190 demand_empty_rest_of_line ();
4191 }
4192
4193
4194 /* Parse a directive saving core registers. */
4195
4196 static void
4197 s_arm_unwind_save_core (void)
4198 {
4199 valueT op;
4200 long range;
4201 int n;
4202
4203 range = parse_reg_list (&input_line_pointer, REGLIST_RN);
4204 if (range == FAIL)
4205 {
4206 as_bad (_("expected register list"));
4207 ignore_rest_of_line ();
4208 return;
4209 }
4210
4211 demand_empty_rest_of_line ();
4212
4213 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4214 into .unwind_save {..., sp...}. We aren't bothered about the value of
4215 ip because it is clobbered by calls. */
4216 if (unwind.sp_restored && unwind.fp_reg == 12
4217 && (range & 0x3000) == 0x1000)
4218 {
4219 unwind.opcode_count--;
4220 unwind.sp_restored = 0;
4221 range = (range | 0x2000) & ~0x1000;
4222 unwind.pending_offset = 0;
4223 }
4224
4225 /* Pop r4-r15. */
4226 if (range & 0xfff0)
4227 {
4228 /* See if we can use the short opcodes. These pop a block of up to 8
4229 registers starting with r4, plus maybe r14. */
4230 for (n = 0; n < 8; n++)
4231 {
4232 /* Break at the first non-saved register. */
4233 if ((range & (1 << (n + 4))) == 0)
4234 break;
4235 }
4236 /* See if there are any other bits set. */
4237 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4238 {
4239 /* Use the long form. */
4240 op = 0x8000 | ((range >> 4) & 0xfff);
4241 add_unwind_opcode (op, 2);
4242 }
4243 else
4244 {
4245 /* Use the short form. */
4246 if (range & 0x4000)
4247 op = 0xa8; /* Pop r14. */
4248 else
4249 op = 0xa0; /* Do not pop r14. */
4250 op |= (n - 1);
4251 add_unwind_opcode (op, 1);
4252 }
4253 }
4254
4255 /* Pop r0-r3. */
4256 if (range & 0xf)
4257 {
4258 op = 0xb100 | (range & 0xf);
4259 add_unwind_opcode (op, 2);
4260 }
4261
4262 /* Record the number of bytes pushed. */
4263 for (n = 0; n < 16; n++)
4264 {
4265 if (range & (1 << n))
4266 unwind.frame_size += 4;
4267 }
4268 }
4269
4270
4271 /* Parse a directive saving FPA registers. */
4272
4273 static void
4274 s_arm_unwind_save_fpa (int reg)
4275 {
4276 expressionS exp;
4277 int num_regs;
4278 valueT op;
4279
4280 /* Get Number of registers to transfer. */
4281 if (skip_past_comma (&input_line_pointer) != FAIL)
4282 expression (&exp);
4283 else
4284 exp.X_op = O_illegal;
4285
4286 if (exp.X_op != O_constant)
4287 {
4288 as_bad (_("expected , <constant>"));
4289 ignore_rest_of_line ();
4290 return;
4291 }
4292
4293 num_regs = exp.X_add_number;
4294
4295 if (num_regs < 1 || num_regs > 4)
4296 {
4297 as_bad (_("number of registers must be in the range [1:4]"));
4298 ignore_rest_of_line ();
4299 return;
4300 }
4301
4302 demand_empty_rest_of_line ();
4303
4304 if (reg == 4)
4305 {
4306 /* Short form. */
4307 op = 0xb4 | (num_regs - 1);
4308 add_unwind_opcode (op, 1);
4309 }
4310 else
4311 {
4312 /* Long form. */
4313 op = 0xc800 | (reg << 4) | (num_regs - 1);
4314 add_unwind_opcode (op, 2);
4315 }
4316 unwind.frame_size += num_regs * 12;
4317 }
4318
4319
4320 /* Parse a directive saving VFP registers for ARMv6 and above. */
4321
4322 static void
4323 s_arm_unwind_save_vfp_armv6 (void)
4324 {
4325 int count;
4326 unsigned int start;
4327 valueT op;
4328 int num_vfpv3_regs = 0;
4329 int num_regs_below_16;
4330 bfd_boolean partial_match;
4331
4332 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D,
4333 &partial_match);
4334 if (count == FAIL)
4335 {
4336 as_bad (_("expected register list"));
4337 ignore_rest_of_line ();
4338 return;
4339 }
4340
4341 demand_empty_rest_of_line ();
4342
4343 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4344 than FSTMX/FLDMX-style ones). */
4345
4346 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4347 if (start >= 16)
4348 num_vfpv3_regs = count;
4349 else if (start + count > 16)
4350 num_vfpv3_regs = start + count - 16;
4351
4352 if (num_vfpv3_regs > 0)
4353 {
4354 int start_offset = start > 16 ? start - 16 : 0;
4355 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4356 add_unwind_opcode (op, 2);
4357 }
4358
4359 /* Generate opcode for registers numbered in the range 0 .. 15. */
4360 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4361 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4362 if (num_regs_below_16 > 0)
4363 {
4364 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4365 add_unwind_opcode (op, 2);
4366 }
4367
4368 unwind.frame_size += count * 8;
4369 }
4370
4371
4372 /* Parse a directive saving VFP registers for pre-ARMv6. */
4373
4374 static void
4375 s_arm_unwind_save_vfp (void)
4376 {
4377 int count;
4378 unsigned int reg;
4379 valueT op;
4380 bfd_boolean partial_match;
4381
4382 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D,
4383 &partial_match);
4384 if (count == FAIL)
4385 {
4386 as_bad (_("expected register list"));
4387 ignore_rest_of_line ();
4388 return;
4389 }
4390
4391 demand_empty_rest_of_line ();
4392
4393 if (reg == 8)
4394 {
4395 /* Short form. */
4396 op = 0xb8 | (count - 1);
4397 add_unwind_opcode (op, 1);
4398 }
4399 else
4400 {
4401 /* Long form. */
4402 op = 0xb300 | (reg << 4) | (count - 1);
4403 add_unwind_opcode (op, 2);
4404 }
4405 unwind.frame_size += count * 8 + 4;
4406 }
4407
4408
4409 /* Parse a directive saving iWMMXt data registers. */
4410
4411 static void
4412 s_arm_unwind_save_mmxwr (void)
4413 {
4414 int reg;
4415 int hi_reg;
4416 int i;
4417 unsigned mask = 0;
4418 valueT op;
4419
4420 if (*input_line_pointer == '{')
4421 input_line_pointer++;
4422
4423 do
4424 {
4425 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4426
4427 if (reg == FAIL)
4428 {
4429 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4430 goto error;
4431 }
4432
4433 if (mask >> reg)
4434 as_tsktsk (_("register list not in ascending order"));
4435 mask |= 1 << reg;
4436
4437 if (*input_line_pointer == '-')
4438 {
4439 input_line_pointer++;
4440 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4441 if (hi_reg == FAIL)
4442 {
4443 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4444 goto error;
4445 }
4446 else if (reg >= hi_reg)
4447 {
4448 as_bad (_("bad register range"));
4449 goto error;
4450 }
4451 for (; reg < hi_reg; reg++)
4452 mask |= 1 << reg;
4453 }
4454 }
4455 while (skip_past_comma (&input_line_pointer) != FAIL);
4456
4457 skip_past_char (&input_line_pointer, '}');
4458
4459 demand_empty_rest_of_line ();
4460
4461 /* Generate any deferred opcodes because we're going to be looking at
4462 the list. */
4463 flush_pending_unwind ();
4464
4465 for (i = 0; i < 16; i++)
4466 {
4467 if (mask & (1 << i))
4468 unwind.frame_size += 8;
4469 }
4470
4471 /* Attempt to combine with a previous opcode. We do this because gcc
4472 likes to output separate unwind directives for a single block of
4473 registers. */
4474 if (unwind.opcode_count > 0)
4475 {
4476 i = unwind.opcodes[unwind.opcode_count - 1];
4477 if ((i & 0xf8) == 0xc0)
4478 {
4479 i &= 7;
4480 /* Only merge if the blocks are contiguous. */
4481 if (i < 6)
4482 {
4483 if ((mask & 0xfe00) == (1 << 9))
4484 {
4485 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4486 unwind.opcode_count--;
4487 }
4488 }
4489 else if (i == 6 && unwind.opcode_count >= 2)
4490 {
4491 i = unwind.opcodes[unwind.opcode_count - 2];
4492 reg = i >> 4;
4493 i &= 0xf;
4494
4495 op = 0xffff << (reg - 1);
4496 if (reg > 0
4497 && ((mask & op) == (1u << (reg - 1))))
4498 {
4499 op = (1 << (reg + i + 1)) - 1;
4500 op &= ~((1 << reg) - 1);
4501 mask |= op;
4502 unwind.opcode_count -= 2;
4503 }
4504 }
4505 }
4506 }
4507
4508 hi_reg = 15;
4509 /* We want to generate opcodes in the order the registers have been
4510 saved, ie. descending order. */
4511 for (reg = 15; reg >= -1; reg--)
4512 {
4513 /* Save registers in blocks. */
4514 if (reg < 0
4515 || !(mask & (1 << reg)))
4516 {
4517 /* We found an unsaved reg. Generate opcodes to save the
4518 preceding block. */
4519 if (reg != hi_reg)
4520 {
4521 if (reg == 9)
4522 {
4523 /* Short form. */
4524 op = 0xc0 | (hi_reg - 10);
4525 add_unwind_opcode (op, 1);
4526 }
4527 else
4528 {
4529 /* Long form. */
4530 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4531 add_unwind_opcode (op, 2);
4532 }
4533 }
4534 hi_reg = reg - 1;
4535 }
4536 }
4537
4538 return;
4539 error:
4540 ignore_rest_of_line ();
4541 }
4542
4543 static void
4544 s_arm_unwind_save_mmxwcg (void)
4545 {
4546 int reg;
4547 int hi_reg;
4548 unsigned mask = 0;
4549 valueT op;
4550
4551 if (*input_line_pointer == '{')
4552 input_line_pointer++;
4553
4554 skip_whitespace (input_line_pointer);
4555
4556 do
4557 {
4558 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4559
4560 if (reg == FAIL)
4561 {
4562 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4563 goto error;
4564 }
4565
4566 reg -= 8;
4567 if (mask >> reg)
4568 as_tsktsk (_("register list not in ascending order"));
4569 mask |= 1 << reg;
4570
4571 if (*input_line_pointer == '-')
4572 {
4573 input_line_pointer++;
4574 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4575 if (hi_reg == FAIL)
4576 {
4577 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4578 goto error;
4579 }
4580 else if (reg >= hi_reg)
4581 {
4582 as_bad (_("bad register range"));
4583 goto error;
4584 }
4585 for (; reg < hi_reg; reg++)
4586 mask |= 1 << reg;
4587 }
4588 }
4589 while (skip_past_comma (&input_line_pointer) != FAIL);
4590
4591 skip_past_char (&input_line_pointer, '}');
4592
4593 demand_empty_rest_of_line ();
4594
4595 /* Generate any deferred opcodes because we're going to be looking at
4596 the list. */
4597 flush_pending_unwind ();
4598
4599 for (reg = 0; reg < 16; reg++)
4600 {
4601 if (mask & (1 << reg))
4602 unwind.frame_size += 4;
4603 }
4604 op = 0xc700 | mask;
4605 add_unwind_opcode (op, 2);
4606 return;
4607 error:
4608 ignore_rest_of_line ();
4609 }
4610
4611
4612 /* Parse an unwind_save directive.
4613 If the argument is non-zero, this is a .vsave directive. */
4614
4615 static void
4616 s_arm_unwind_save (int arch_v6)
4617 {
4618 char *peek;
4619 struct reg_entry *reg;
4620 bfd_boolean had_brace = FALSE;
4621
4622 if (!unwind.proc_start)
4623 as_bad (MISSING_FNSTART);
4624
4625 /* Figure out what sort of save we have. */
4626 peek = input_line_pointer;
4627
4628 if (*peek == '{')
4629 {
4630 had_brace = TRUE;
4631 peek++;
4632 }
4633
4634 reg = arm_reg_parse_multi (&peek);
4635
4636 if (!reg)
4637 {
4638 as_bad (_("register expected"));
4639 ignore_rest_of_line ();
4640 return;
4641 }
4642
4643 switch (reg->type)
4644 {
4645 case REG_TYPE_FN:
4646 if (had_brace)
4647 {
4648 as_bad (_("FPA .unwind_save does not take a register list"));
4649 ignore_rest_of_line ();
4650 return;
4651 }
4652 input_line_pointer = peek;
4653 s_arm_unwind_save_fpa (reg->number);
4654 return;
4655
4656 case REG_TYPE_RN:
4657 s_arm_unwind_save_core ();
4658 return;
4659
4660 case REG_TYPE_VFD:
4661 if (arch_v6)
4662 s_arm_unwind_save_vfp_armv6 ();
4663 else
4664 s_arm_unwind_save_vfp ();
4665 return;
4666
4667 case REG_TYPE_MMXWR:
4668 s_arm_unwind_save_mmxwr ();
4669 return;
4670
4671 case REG_TYPE_MMXWCG:
4672 s_arm_unwind_save_mmxwcg ();
4673 return;
4674
4675 default:
4676 as_bad (_(".unwind_save does not support this kind of register"));
4677 ignore_rest_of_line ();
4678 }
4679 }
4680
4681
4682 /* Parse an unwind_movsp directive. */
4683
4684 static void
4685 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4686 {
4687 int reg;
4688 valueT op;
4689 int offset;
4690
4691 if (!unwind.proc_start)
4692 as_bad (MISSING_FNSTART);
4693
4694 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4695 if (reg == FAIL)
4696 {
4697 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4698 ignore_rest_of_line ();
4699 return;
4700 }
4701
4702 /* Optional constant. */
4703 if (skip_past_comma (&input_line_pointer) != FAIL)
4704 {
4705 if (immediate_for_directive (&offset) == FAIL)
4706 return;
4707 }
4708 else
4709 offset = 0;
4710
4711 demand_empty_rest_of_line ();
4712
4713 if (reg == REG_SP || reg == REG_PC)
4714 {
4715 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4716 return;
4717 }
4718
4719 if (unwind.fp_reg != REG_SP)
4720 as_bad (_("unexpected .unwind_movsp directive"));
4721
4722 /* Generate opcode to restore the value. */
4723 op = 0x90 | reg;
4724 add_unwind_opcode (op, 1);
4725
4726 /* Record the information for later. */
4727 unwind.fp_reg = reg;
4728 unwind.fp_offset = unwind.frame_size - offset;
4729 unwind.sp_restored = 1;
4730 }
4731
4732 /* Parse an unwind_pad directive. */
4733
4734 static void
4735 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4736 {
4737 int offset;
4738
4739 if (!unwind.proc_start)
4740 as_bad (MISSING_FNSTART);
4741
4742 if (immediate_for_directive (&offset) == FAIL)
4743 return;
4744
4745 if (offset & 3)
4746 {
4747 as_bad (_("stack increment must be multiple of 4"));
4748 ignore_rest_of_line ();
4749 return;
4750 }
4751
4752 /* Don't generate any opcodes, just record the details for later. */
4753 unwind.frame_size += offset;
4754 unwind.pending_offset += offset;
4755
4756 demand_empty_rest_of_line ();
4757 }
4758
4759 /* Parse an unwind_setfp directive. */
4760
4761 static void
4762 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4763 {
4764 int sp_reg;
4765 int fp_reg;
4766 int offset;
4767
4768 if (!unwind.proc_start)
4769 as_bad (MISSING_FNSTART);
4770
4771 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4772 if (skip_past_comma (&input_line_pointer) == FAIL)
4773 sp_reg = FAIL;
4774 else
4775 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4776
4777 if (fp_reg == FAIL || sp_reg == FAIL)
4778 {
4779 as_bad (_("expected <reg>, <reg>"));
4780 ignore_rest_of_line ();
4781 return;
4782 }
4783
4784 /* Optional constant. */
4785 if (skip_past_comma (&input_line_pointer) != FAIL)
4786 {
4787 if (immediate_for_directive (&offset) == FAIL)
4788 return;
4789 }
4790 else
4791 offset = 0;
4792
4793 demand_empty_rest_of_line ();
4794
4795 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4796 {
4797 as_bad (_("register must be either sp or set by a previous"
4798 "unwind_movsp directive"));
4799 return;
4800 }
4801
4802 /* Don't generate any opcodes, just record the information for later. */
4803 unwind.fp_reg = fp_reg;
4804 unwind.fp_used = 1;
4805 if (sp_reg == REG_SP)
4806 unwind.fp_offset = unwind.frame_size - offset;
4807 else
4808 unwind.fp_offset -= offset;
4809 }
4810
4811 /* Parse an unwind_raw directive. */
4812
4813 static void
4814 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4815 {
4816 expressionS exp;
4817 /* This is an arbitrary limit. */
4818 unsigned char op[16];
4819 int count;
4820
4821 if (!unwind.proc_start)
4822 as_bad (MISSING_FNSTART);
4823
4824 expression (&exp);
4825 if (exp.X_op == O_constant
4826 && skip_past_comma (&input_line_pointer) != FAIL)
4827 {
4828 unwind.frame_size += exp.X_add_number;
4829 expression (&exp);
4830 }
4831 else
4832 exp.X_op = O_illegal;
4833
4834 if (exp.X_op != O_constant)
4835 {
4836 as_bad (_("expected <offset>, <opcode>"));
4837 ignore_rest_of_line ();
4838 return;
4839 }
4840
4841 count = 0;
4842
4843 /* Parse the opcode. */
4844 for (;;)
4845 {
4846 if (count >= 16)
4847 {
4848 as_bad (_("unwind opcode too long"));
4849 ignore_rest_of_line ();
4850 }
4851 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4852 {
4853 as_bad (_("invalid unwind opcode"));
4854 ignore_rest_of_line ();
4855 return;
4856 }
4857 op[count++] = exp.X_add_number;
4858
4859 /* Parse the next byte. */
4860 if (skip_past_comma (&input_line_pointer) == FAIL)
4861 break;
4862
4863 expression (&exp);
4864 }
4865
4866 /* Add the opcode bytes in reverse order. */
4867 while (count--)
4868 add_unwind_opcode (op[count], 1);
4869
4870 demand_empty_rest_of_line ();
4871 }
4872
4873
4874 /* Parse a .eabi_attribute directive. */
4875
4876 static void
4877 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4878 {
4879 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4880
4881 if (tag >= 0 && tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4882 attributes_set_explicitly[tag] = 1;
4883 }
4884
4885 /* Emit a tls fix for the symbol. */
4886
4887 static void
4888 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4889 {
4890 char *p;
4891 expressionS exp;
4892 #ifdef md_flush_pending_output
4893 md_flush_pending_output ();
4894 #endif
4895
4896 #ifdef md_cons_align
4897 md_cons_align (4);
4898 #endif
4899
4900 /* Since we're just labelling the code, there's no need to define a
4901 mapping symbol. */
4902 expression (&exp);
4903 p = obstack_next_free (&frchain_now->frch_obstack);
4904 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4905 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4906 : BFD_RELOC_ARM_TLS_DESCSEQ);
4907 }
4908 #endif /* OBJ_ELF */
4909
4910 static void s_arm_arch (int);
4911 static void s_arm_object_arch (int);
4912 static void s_arm_cpu (int);
4913 static void s_arm_fpu (int);
4914 static void s_arm_arch_extension (int);
4915
4916 #ifdef TE_PE
4917
4918 static void
4919 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4920 {
4921 expressionS exp;
4922
4923 do
4924 {
4925 expression (&exp);
4926 if (exp.X_op == O_symbol)
4927 exp.X_op = O_secrel;
4928
4929 emit_expr (&exp, 4);
4930 }
4931 while (*input_line_pointer++ == ',');
4932
4933 input_line_pointer--;
4934 demand_empty_rest_of_line ();
4935 }
4936 #endif /* TE_PE */
4937
4938 int
4939 arm_is_largest_exponent_ok (int precision)
4940 {
4941 /* precision == 1 ensures that this will only return
4942 true for 16 bit floats. */
4943 return (precision == 1) && (fp16_format == ARM_FP16_FORMAT_ALTERNATIVE);
4944 }
4945
4946 static void
4947 set_fp16_format (int dummy ATTRIBUTE_UNUSED)
4948 {
4949 char saved_char;
4950 char* name;
4951 enum fp_16bit_format new_format;
4952
4953 new_format = ARM_FP16_FORMAT_DEFAULT;
4954
4955 name = input_line_pointer;
4956 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
4957 input_line_pointer++;
4958
4959 saved_char = *input_line_pointer;
4960 *input_line_pointer = 0;
4961
4962 if (strcasecmp (name, "ieee") == 0)
4963 new_format = ARM_FP16_FORMAT_IEEE;
4964 else if (strcasecmp (name, "alternative") == 0)
4965 new_format = ARM_FP16_FORMAT_ALTERNATIVE;
4966 else
4967 {
4968 as_bad (_("unrecognised float16 format \"%s\""), name);
4969 goto cleanup;
4970 }
4971
4972 /* Only set fp16_format if it is still the default (aka not already
4973 been set yet). */
4974 if (fp16_format == ARM_FP16_FORMAT_DEFAULT)
4975 fp16_format = new_format;
4976 else
4977 {
4978 if (new_format != fp16_format)
4979 as_warn (_("float16 format cannot be set more than once, ignoring."));
4980 }
4981
4982 cleanup:
4983 *input_line_pointer = saved_char;
4984 ignore_rest_of_line ();
4985 }
4986
4987 /* This table describes all the machine specific pseudo-ops the assembler
4988 has to support. The fields are:
4989 pseudo-op name without dot
4990 function to call to execute this pseudo-op
4991 Integer arg to pass to the function. */
4992
4993 const pseudo_typeS md_pseudo_table[] =
4994 {
4995 /* Never called because '.req' does not start a line. */
4996 { "req", s_req, 0 },
4997 /* Following two are likewise never called. */
4998 { "dn", s_dn, 0 },
4999 { "qn", s_qn, 0 },
5000 { "unreq", s_unreq, 0 },
5001 { "bss", s_bss, 0 },
5002 { "align", s_align_ptwo, 2 },
5003 { "arm", s_arm, 0 },
5004 { "thumb", s_thumb, 0 },
5005 { "code", s_code, 0 },
5006 { "force_thumb", s_force_thumb, 0 },
5007 { "thumb_func", s_thumb_func, 0 },
5008 { "thumb_set", s_thumb_set, 0 },
5009 { "even", s_even, 0 },
5010 { "ltorg", s_ltorg, 0 },
5011 { "pool", s_ltorg, 0 },
5012 { "syntax", s_syntax, 0 },
5013 { "cpu", s_arm_cpu, 0 },
5014 { "arch", s_arm_arch, 0 },
5015 { "object_arch", s_arm_object_arch, 0 },
5016 { "fpu", s_arm_fpu, 0 },
5017 { "arch_extension", s_arm_arch_extension, 0 },
5018 #ifdef OBJ_ELF
5019 { "word", s_arm_elf_cons, 4 },
5020 { "long", s_arm_elf_cons, 4 },
5021 { "inst.n", s_arm_elf_inst, 2 },
5022 { "inst.w", s_arm_elf_inst, 4 },
5023 { "inst", s_arm_elf_inst, 0 },
5024 { "rel31", s_arm_rel31, 0 },
5025 { "fnstart", s_arm_unwind_fnstart, 0 },
5026 { "fnend", s_arm_unwind_fnend, 0 },
5027 { "cantunwind", s_arm_unwind_cantunwind, 0 },
5028 { "personality", s_arm_unwind_personality, 0 },
5029 { "personalityindex", s_arm_unwind_personalityindex, 0 },
5030 { "handlerdata", s_arm_unwind_handlerdata, 0 },
5031 { "save", s_arm_unwind_save, 0 },
5032 { "vsave", s_arm_unwind_save, 1 },
5033 { "movsp", s_arm_unwind_movsp, 0 },
5034 { "pad", s_arm_unwind_pad, 0 },
5035 { "setfp", s_arm_unwind_setfp, 0 },
5036 { "unwind_raw", s_arm_unwind_raw, 0 },
5037 { "eabi_attribute", s_arm_eabi_attribute, 0 },
5038 { "tlsdescseq", s_arm_tls_descseq, 0 },
5039 #else
5040 { "word", cons, 4},
5041
5042 /* These are used for dwarf. */
5043 {"2byte", cons, 2},
5044 {"4byte", cons, 4},
5045 {"8byte", cons, 8},
5046 /* These are used for dwarf2. */
5047 { "file", dwarf2_directive_file, 0 },
5048 { "loc", dwarf2_directive_loc, 0 },
5049 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
5050 #endif
5051 { "extend", float_cons, 'x' },
5052 { "ldouble", float_cons, 'x' },
5053 { "packed", float_cons, 'p' },
5054 #ifdef TE_PE
5055 {"secrel32", pe_directive_secrel, 0},
5056 #endif
5057
5058 /* These are for compatibility with CodeComposer Studio. */
5059 {"ref", s_ccs_ref, 0},
5060 {"def", s_ccs_def, 0},
5061 {"asmfunc", s_ccs_asmfunc, 0},
5062 {"endasmfunc", s_ccs_endasmfunc, 0},
5063
5064 {"float16", float_cons, 'h' },
5065 {"float16_format", set_fp16_format, 0 },
5066
5067 { 0, 0, 0 }
5068 };
5069
5070 /* Parser functions used exclusively in instruction operands. */
5071
5072 /* Generic immediate-value read function for use in insn parsing.
5073 STR points to the beginning of the immediate (the leading #);
5074 VAL receives the value; if the value is outside [MIN, MAX]
5075 issue an error. PREFIX_OPT is true if the immediate prefix is
5076 optional. */
5077
5078 static int
5079 parse_immediate (char **str, int *val, int min, int max,
5080 bfd_boolean prefix_opt)
5081 {
5082 expressionS exp;
5083
5084 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
5085 if (exp.X_op != O_constant)
5086 {
5087 inst.error = _("constant expression required");
5088 return FAIL;
5089 }
5090
5091 if (exp.X_add_number < min || exp.X_add_number > max)
5092 {
5093 inst.error = _("immediate value out of range");
5094 return FAIL;
5095 }
5096
5097 *val = exp.X_add_number;
5098 return SUCCESS;
5099 }
5100
5101 /* Less-generic immediate-value read function with the possibility of loading a
5102 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5103 instructions. Puts the result directly in inst.operands[i]. */
5104
5105 static int
5106 parse_big_immediate (char **str, int i, expressionS *in_exp,
5107 bfd_boolean allow_symbol_p)
5108 {
5109 expressionS exp;
5110 expressionS *exp_p = in_exp ? in_exp : &exp;
5111 char *ptr = *str;
5112
5113 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
5114
5115 if (exp_p->X_op == O_constant)
5116 {
5117 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
5118 /* If we're on a 64-bit host, then a 64-bit number can be returned using
5119 O_constant. We have to be careful not to break compilation for
5120 32-bit X_add_number, though. */
5121 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
5122 {
5123 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
5124 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
5125 & 0xffffffff);
5126 inst.operands[i].regisimm = 1;
5127 }
5128 }
5129 else if (exp_p->X_op == O_big
5130 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
5131 {
5132 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
5133
5134 /* Bignums have their least significant bits in
5135 generic_bignum[0]. Make sure we put 32 bits in imm and
5136 32 bits in reg, in a (hopefully) portable way. */
5137 gas_assert (parts != 0);
5138
5139 /* Make sure that the number is not too big.
5140 PR 11972: Bignums can now be sign-extended to the
5141 size of a .octa so check that the out of range bits
5142 are all zero or all one. */
5143 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
5144 {
5145 LITTLENUM_TYPE m = -1;
5146
5147 if (generic_bignum[parts * 2] != 0
5148 && generic_bignum[parts * 2] != m)
5149 return FAIL;
5150
5151 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
5152 if (generic_bignum[j] != generic_bignum[j-1])
5153 return FAIL;
5154 }
5155
5156 inst.operands[i].imm = 0;
5157 for (j = 0; j < parts; j++, idx++)
5158 inst.operands[i].imm |= generic_bignum[idx]
5159 << (LITTLENUM_NUMBER_OF_BITS * j);
5160 inst.operands[i].reg = 0;
5161 for (j = 0; j < parts; j++, idx++)
5162 inst.operands[i].reg |= generic_bignum[idx]
5163 << (LITTLENUM_NUMBER_OF_BITS * j);
5164 inst.operands[i].regisimm = 1;
5165 }
5166 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
5167 return FAIL;
5168
5169 *str = ptr;
5170
5171 return SUCCESS;
5172 }
5173
5174 /* Returns the pseudo-register number of an FPA immediate constant,
5175 or FAIL if there isn't a valid constant here. */
5176
5177 static int
5178 parse_fpa_immediate (char ** str)
5179 {
5180 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5181 char * save_in;
5182 expressionS exp;
5183 int i;
5184 int j;
5185
5186 /* First try and match exact strings, this is to guarantee
5187 that some formats will work even for cross assembly. */
5188
5189 for (i = 0; fp_const[i]; i++)
5190 {
5191 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
5192 {
5193 char *start = *str;
5194
5195 *str += strlen (fp_const[i]);
5196 if (is_end_of_line[(unsigned char) **str])
5197 return i + 8;
5198 *str = start;
5199 }
5200 }
5201
5202 /* Just because we didn't get a match doesn't mean that the constant
5203 isn't valid, just that it is in a format that we don't
5204 automatically recognize. Try parsing it with the standard
5205 expression routines. */
5206
5207 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
5208
5209 /* Look for a raw floating point number. */
5210 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
5211 && is_end_of_line[(unsigned char) *save_in])
5212 {
5213 for (i = 0; i < NUM_FLOAT_VALS; i++)
5214 {
5215 for (j = 0; j < MAX_LITTLENUMS; j++)
5216 {
5217 if (words[j] != fp_values[i][j])
5218 break;
5219 }
5220
5221 if (j == MAX_LITTLENUMS)
5222 {
5223 *str = save_in;
5224 return i + 8;
5225 }
5226 }
5227 }
5228
5229 /* Try and parse a more complex expression, this will probably fail
5230 unless the code uses a floating point prefix (eg "0f"). */
5231 save_in = input_line_pointer;
5232 input_line_pointer = *str;
5233 if (expression (&exp) == absolute_section
5234 && exp.X_op == O_big
5235 && exp.X_add_number < 0)
5236 {
5237 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
5238 Ditto for 15. */
5239 #define X_PRECISION 5
5240 #define E_PRECISION 15L
5241 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
5242 {
5243 for (i = 0; i < NUM_FLOAT_VALS; i++)
5244 {
5245 for (j = 0; j < MAX_LITTLENUMS; j++)
5246 {
5247 if (words[j] != fp_values[i][j])
5248 break;
5249 }
5250
5251 if (j == MAX_LITTLENUMS)
5252 {
5253 *str = input_line_pointer;
5254 input_line_pointer = save_in;
5255 return i + 8;
5256 }
5257 }
5258 }
5259 }
5260
5261 *str = input_line_pointer;
5262 input_line_pointer = save_in;
5263 inst.error = _("invalid FPA immediate expression");
5264 return FAIL;
5265 }
5266
5267 /* Returns 1 if a number has "quarter-precision" float format
5268 0baBbbbbbc defgh000 00000000 00000000. */
5269
5270 static int
5271 is_quarter_float (unsigned imm)
5272 {
5273 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5274 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5275 }
5276
5277
5278 /* Detect the presence of a floating point or integer zero constant,
5279 i.e. #0.0 or #0. */
5280
5281 static bfd_boolean
5282 parse_ifimm_zero (char **in)
5283 {
5284 int error_code;
5285
5286 if (!is_immediate_prefix (**in))
5287 {
5288 /* In unified syntax, all prefixes are optional. */
5289 if (!unified_syntax)
5290 return FALSE;
5291 }
5292 else
5293 ++*in;
5294
5295 /* Accept #0x0 as a synonym for #0. */
5296 if (strncmp (*in, "0x", 2) == 0)
5297 {
5298 int val;
5299 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5300 return FALSE;
5301 return TRUE;
5302 }
5303
5304 error_code = atof_generic (in, ".", EXP_CHARS,
5305 &generic_floating_point_number);
5306
5307 if (!error_code
5308 && generic_floating_point_number.sign == '+'
5309 && (generic_floating_point_number.low
5310 > generic_floating_point_number.leader))
5311 return TRUE;
5312
5313 return FALSE;
5314 }
5315
5316 /* Parse an 8-bit "quarter-precision" floating point number of the form:
5317 0baBbbbbbc defgh000 00000000 00000000.
5318 The zero and minus-zero cases need special handling, since they can't be
5319 encoded in the "quarter-precision" float format, but can nonetheless be
5320 loaded as integer constants. */
5321
5322 static unsigned
5323 parse_qfloat_immediate (char **ccp, int *immed)
5324 {
5325 char *str = *ccp;
5326 char *fpnum;
5327 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5328 int found_fpchar = 0;
5329
5330 skip_past_char (&str, '#');
5331
5332 /* We must not accidentally parse an integer as a floating-point number. Make
5333 sure that the value we parse is not an integer by checking for special
5334 characters '.' or 'e'.
5335 FIXME: This is a horrible hack, but doing better is tricky because type
5336 information isn't in a very usable state at parse time. */
5337 fpnum = str;
5338 skip_whitespace (fpnum);
5339
5340 if (strncmp (fpnum, "0x", 2) == 0)
5341 return FAIL;
5342 else
5343 {
5344 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
5345 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5346 {
5347 found_fpchar = 1;
5348 break;
5349 }
5350
5351 if (!found_fpchar)
5352 return FAIL;
5353 }
5354
5355 if ((str = atof_ieee (str, 's', words)) != NULL)
5356 {
5357 unsigned fpword = 0;
5358 int i;
5359
5360 /* Our FP word must be 32 bits (single-precision FP). */
5361 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
5362 {
5363 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5364 fpword |= words[i];
5365 }
5366
5367 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5368 *immed = fpword;
5369 else
5370 return FAIL;
5371
5372 *ccp = str;
5373
5374 return SUCCESS;
5375 }
5376
5377 return FAIL;
5378 }
5379
5380 /* Shift operands. */
5381 enum shift_kind
5382 {
5383 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX, SHIFT_UXTW
5384 };
5385
5386 struct asm_shift_name
5387 {
5388 const char *name;
5389 enum shift_kind kind;
5390 };
5391
5392 /* Third argument to parse_shift. */
5393 enum parse_shift_mode
5394 {
5395 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5396 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5397 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5398 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5399 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5400 SHIFT_UXTW_IMMEDIATE /* Shift must be UXTW immediate. */
5401 };
5402
5403 /* Parse a <shift> specifier on an ARM data processing instruction.
5404 This has three forms:
5405
5406 (LSL|LSR|ASL|ASR|ROR) Rs
5407 (LSL|LSR|ASL|ASR|ROR) #imm
5408 RRX
5409
5410 Note that ASL is assimilated to LSL in the instruction encoding, and
5411 RRX to ROR #0 (which cannot be written as such). */
5412
5413 static int
5414 parse_shift (char **str, int i, enum parse_shift_mode mode)
5415 {
5416 const struct asm_shift_name *shift_name;
5417 enum shift_kind shift;
5418 char *s = *str;
5419 char *p = s;
5420 int reg;
5421
5422 for (p = *str; ISALPHA (*p); p++)
5423 ;
5424
5425 if (p == *str)
5426 {
5427 inst.error = _("shift expression expected");
5428 return FAIL;
5429 }
5430
5431 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
5432 p - *str);
5433
5434 if (shift_name == NULL)
5435 {
5436 inst.error = _("shift expression expected");
5437 return FAIL;
5438 }
5439
5440 shift = shift_name->kind;
5441
5442 switch (mode)
5443 {
5444 case NO_SHIFT_RESTRICT:
5445 case SHIFT_IMMEDIATE:
5446 if (shift == SHIFT_UXTW)
5447 {
5448 inst.error = _("'UXTW' not allowed here");
5449 return FAIL;
5450 }
5451 break;
5452
5453 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5454 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5455 {
5456 inst.error = _("'LSL' or 'ASR' required");
5457 return FAIL;
5458 }
5459 break;
5460
5461 case SHIFT_LSL_IMMEDIATE:
5462 if (shift != SHIFT_LSL)
5463 {
5464 inst.error = _("'LSL' required");
5465 return FAIL;
5466 }
5467 break;
5468
5469 case SHIFT_ASR_IMMEDIATE:
5470 if (shift != SHIFT_ASR)
5471 {
5472 inst.error = _("'ASR' required");
5473 return FAIL;
5474 }
5475 break;
5476 case SHIFT_UXTW_IMMEDIATE:
5477 if (shift != SHIFT_UXTW)
5478 {
5479 inst.error = _("'UXTW' required");
5480 return FAIL;
5481 }
5482 break;
5483
5484 default: abort ();
5485 }
5486
5487 if (shift != SHIFT_RRX)
5488 {
5489 /* Whitespace can appear here if the next thing is a bare digit. */
5490 skip_whitespace (p);
5491
5492 if (mode == NO_SHIFT_RESTRICT
5493 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5494 {
5495 inst.operands[i].imm = reg;
5496 inst.operands[i].immisreg = 1;
5497 }
5498 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5499 return FAIL;
5500 }
5501 inst.operands[i].shift_kind = shift;
5502 inst.operands[i].shifted = 1;
5503 *str = p;
5504 return SUCCESS;
5505 }
5506
5507 /* Parse a <shifter_operand> for an ARM data processing instruction:
5508
5509 #<immediate>
5510 #<immediate>, <rotate>
5511 <Rm>
5512 <Rm>, <shift>
5513
5514 where <shift> is defined by parse_shift above, and <rotate> is a
5515 multiple of 2 between 0 and 30. Validation of immediate operands
5516 is deferred to md_apply_fix. */
5517
5518 static int
5519 parse_shifter_operand (char **str, int i)
5520 {
5521 int value;
5522 expressionS exp;
5523
5524 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5525 {
5526 inst.operands[i].reg = value;
5527 inst.operands[i].isreg = 1;
5528
5529 /* parse_shift will override this if appropriate */
5530 inst.relocs[0].exp.X_op = O_constant;
5531 inst.relocs[0].exp.X_add_number = 0;
5532
5533 if (skip_past_comma (str) == FAIL)
5534 return SUCCESS;
5535
5536 /* Shift operation on register. */
5537 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5538 }
5539
5540 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
5541 return FAIL;
5542
5543 if (skip_past_comma (str) == SUCCESS)
5544 {
5545 /* #x, y -- ie explicit rotation by Y. */
5546 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5547 return FAIL;
5548
5549 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
5550 {
5551 inst.error = _("constant expression expected");
5552 return FAIL;
5553 }
5554
5555 value = exp.X_add_number;
5556 if (value < 0 || value > 30 || value % 2 != 0)
5557 {
5558 inst.error = _("invalid rotation");
5559 return FAIL;
5560 }
5561 if (inst.relocs[0].exp.X_add_number < 0
5562 || inst.relocs[0].exp.X_add_number > 255)
5563 {
5564 inst.error = _("invalid constant");
5565 return FAIL;
5566 }
5567
5568 /* Encode as specified. */
5569 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
5570 return SUCCESS;
5571 }
5572
5573 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5574 inst.relocs[0].pc_rel = 0;
5575 return SUCCESS;
5576 }
5577
5578 /* Group relocation information. Each entry in the table contains the
5579 textual name of the relocation as may appear in assembler source
5580 and must end with a colon.
5581 Along with this textual name are the relocation codes to be used if
5582 the corresponding instruction is an ALU instruction (ADD or SUB only),
5583 an LDR, an LDRS, or an LDC. */
5584
5585 struct group_reloc_table_entry
5586 {
5587 const char *name;
5588 int alu_code;
5589 int ldr_code;
5590 int ldrs_code;
5591 int ldc_code;
5592 };
5593
5594 typedef enum
5595 {
5596 /* Varieties of non-ALU group relocation. */
5597
5598 GROUP_LDR,
5599 GROUP_LDRS,
5600 GROUP_LDC,
5601 GROUP_MVE
5602 } group_reloc_type;
5603
5604 static struct group_reloc_table_entry group_reloc_table[] =
5605 { /* Program counter relative: */
5606 { "pc_g0_nc",
5607 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5608 0, /* LDR */
5609 0, /* LDRS */
5610 0 }, /* LDC */
5611 { "pc_g0",
5612 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5613 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5614 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5615 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5616 { "pc_g1_nc",
5617 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5618 0, /* LDR */
5619 0, /* LDRS */
5620 0 }, /* LDC */
5621 { "pc_g1",
5622 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5623 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5624 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5625 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5626 { "pc_g2",
5627 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5628 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5629 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5630 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5631 /* Section base relative */
5632 { "sb_g0_nc",
5633 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5634 0, /* LDR */
5635 0, /* LDRS */
5636 0 }, /* LDC */
5637 { "sb_g0",
5638 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5639 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5640 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5641 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5642 { "sb_g1_nc",
5643 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5644 0, /* LDR */
5645 0, /* LDRS */
5646 0 }, /* LDC */
5647 { "sb_g1",
5648 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5649 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5650 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5651 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5652 { "sb_g2",
5653 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5654 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5655 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5656 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5657 /* Absolute thumb alu relocations. */
5658 { "lower0_7",
5659 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5660 0, /* LDR. */
5661 0, /* LDRS. */
5662 0 }, /* LDC. */
5663 { "lower8_15",
5664 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5665 0, /* LDR. */
5666 0, /* LDRS. */
5667 0 }, /* LDC. */
5668 { "upper0_7",
5669 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5670 0, /* LDR. */
5671 0, /* LDRS. */
5672 0 }, /* LDC. */
5673 { "upper8_15",
5674 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5675 0, /* LDR. */
5676 0, /* LDRS. */
5677 0 } }; /* LDC. */
5678
5679 /* Given the address of a pointer pointing to the textual name of a group
5680 relocation as may appear in assembler source, attempt to find its details
5681 in group_reloc_table. The pointer will be updated to the character after
5682 the trailing colon. On failure, FAIL will be returned; SUCCESS
5683 otherwise. On success, *entry will be updated to point at the relevant
5684 group_reloc_table entry. */
5685
5686 static int
5687 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5688 {
5689 unsigned int i;
5690 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5691 {
5692 int length = strlen (group_reloc_table[i].name);
5693
5694 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5695 && (*str)[length] == ':')
5696 {
5697 *out = &group_reloc_table[i];
5698 *str += (length + 1);
5699 return SUCCESS;
5700 }
5701 }
5702
5703 return FAIL;
5704 }
5705
5706 /* Parse a <shifter_operand> for an ARM data processing instruction
5707 (as for parse_shifter_operand) where group relocations are allowed:
5708
5709 #<immediate>
5710 #<immediate>, <rotate>
5711 #:<group_reloc>:<expression>
5712 <Rm>
5713 <Rm>, <shift>
5714
5715 where <group_reloc> is one of the strings defined in group_reloc_table.
5716 The hashes are optional.
5717
5718 Everything else is as for parse_shifter_operand. */
5719
5720 static parse_operand_result
5721 parse_shifter_operand_group_reloc (char **str, int i)
5722 {
5723 /* Determine if we have the sequence of characters #: or just :
5724 coming next. If we do, then we check for a group relocation.
5725 If we don't, punt the whole lot to parse_shifter_operand. */
5726
5727 if (((*str)[0] == '#' && (*str)[1] == ':')
5728 || (*str)[0] == ':')
5729 {
5730 struct group_reloc_table_entry *entry;
5731
5732 if ((*str)[0] == '#')
5733 (*str) += 2;
5734 else
5735 (*str)++;
5736
5737 /* Try to parse a group relocation. Anything else is an error. */
5738 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5739 {
5740 inst.error = _("unknown group relocation");
5741 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5742 }
5743
5744 /* We now have the group relocation table entry corresponding to
5745 the name in the assembler source. Next, we parse the expression. */
5746 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
5747 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5748
5749 /* Record the relocation type (always the ALU variant here). */
5750 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5751 gas_assert (inst.relocs[0].type != 0);
5752
5753 return PARSE_OPERAND_SUCCESS;
5754 }
5755 else
5756 return parse_shifter_operand (str, i) == SUCCESS
5757 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5758
5759 /* Never reached. */
5760 }
5761
5762 /* Parse a Neon alignment expression. Information is written to
5763 inst.operands[i]. We assume the initial ':' has been skipped.
5764
5765 align .imm = align << 8, .immisalign=1, .preind=0 */
5766 static parse_operand_result
5767 parse_neon_alignment (char **str, int i)
5768 {
5769 char *p = *str;
5770 expressionS exp;
5771
5772 my_get_expression (&exp, &p, GE_NO_PREFIX);
5773
5774 if (exp.X_op != O_constant)
5775 {
5776 inst.error = _("alignment must be constant");
5777 return PARSE_OPERAND_FAIL;
5778 }
5779
5780 inst.operands[i].imm = exp.X_add_number << 8;
5781 inst.operands[i].immisalign = 1;
5782 /* Alignments are not pre-indexes. */
5783 inst.operands[i].preind = 0;
5784
5785 *str = p;
5786 return PARSE_OPERAND_SUCCESS;
5787 }
5788
5789 /* Parse all forms of an ARM address expression. Information is written
5790 to inst.operands[i] and/or inst.relocs[0].
5791
5792 Preindexed addressing (.preind=1):
5793
5794 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
5795 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5796 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5797 .shift_kind=shift .relocs[0].exp=shift_imm
5798
5799 These three may have a trailing ! which causes .writeback to be set also.
5800
5801 Postindexed addressing (.postind=1, .writeback=1):
5802
5803 [Rn], #offset .reg=Rn .relocs[0].exp=offset
5804 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5805 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5806 .shift_kind=shift .relocs[0].exp=shift_imm
5807
5808 Unindexed addressing (.preind=0, .postind=0):
5809
5810 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5811
5812 Other:
5813
5814 [Rn]{!} shorthand for [Rn,#0]{!}
5815 =immediate .isreg=0 .relocs[0].exp=immediate
5816 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
5817
5818 It is the caller's responsibility to check for addressing modes not
5819 supported by the instruction, and to set inst.relocs[0].type. */
5820
5821 static parse_operand_result
5822 parse_address_main (char **str, int i, int group_relocations,
5823 group_reloc_type group_type)
5824 {
5825 char *p = *str;
5826 int reg;
5827
5828 if (skip_past_char (&p, '[') == FAIL)
5829 {
5830 if (skip_past_char (&p, '=') == FAIL)
5831 {
5832 /* Bare address - translate to PC-relative offset. */
5833 inst.relocs[0].pc_rel = 1;
5834 inst.operands[i].reg = REG_PC;
5835 inst.operands[i].isreg = 1;
5836 inst.operands[i].preind = 1;
5837
5838 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
5839 return PARSE_OPERAND_FAIL;
5840 }
5841 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
5842 /*allow_symbol_p=*/TRUE))
5843 return PARSE_OPERAND_FAIL;
5844
5845 *str = p;
5846 return PARSE_OPERAND_SUCCESS;
5847 }
5848
5849 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5850 skip_whitespace (p);
5851
5852 if (group_type == GROUP_MVE)
5853 {
5854 enum arm_reg_type rtype = REG_TYPE_MQ;
5855 struct neon_type_el et;
5856 if ((reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5857 {
5858 inst.operands[i].isquad = 1;
5859 }
5860 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5861 {
5862 inst.error = BAD_ADDR_MODE;
5863 return PARSE_OPERAND_FAIL;
5864 }
5865 }
5866 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5867 {
5868 if (group_type == GROUP_MVE)
5869 inst.error = BAD_ADDR_MODE;
5870 else
5871 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5872 return PARSE_OPERAND_FAIL;
5873 }
5874 inst.operands[i].reg = reg;
5875 inst.operands[i].isreg = 1;
5876
5877 if (skip_past_comma (&p) == SUCCESS)
5878 {
5879 inst.operands[i].preind = 1;
5880
5881 if (*p == '+') p++;
5882 else if (*p == '-') p++, inst.operands[i].negative = 1;
5883
5884 enum arm_reg_type rtype = REG_TYPE_MQ;
5885 struct neon_type_el et;
5886 if (group_type == GROUP_MVE
5887 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
5888 {
5889 inst.operands[i].immisreg = 2;
5890 inst.operands[i].imm = reg;
5891
5892 if (skip_past_comma (&p) == SUCCESS)
5893 {
5894 if (parse_shift (&p, i, SHIFT_UXTW_IMMEDIATE) == SUCCESS)
5895 {
5896 inst.operands[i].imm |= inst.relocs[0].exp.X_add_number << 5;
5897 inst.relocs[0].exp.X_add_number = 0;
5898 }
5899 else
5900 return PARSE_OPERAND_FAIL;
5901 }
5902 }
5903 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5904 {
5905 inst.operands[i].imm = reg;
5906 inst.operands[i].immisreg = 1;
5907
5908 if (skip_past_comma (&p) == SUCCESS)
5909 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5910 return PARSE_OPERAND_FAIL;
5911 }
5912 else if (skip_past_char (&p, ':') == SUCCESS)
5913 {
5914 /* FIXME: '@' should be used here, but it's filtered out by generic
5915 code before we get to see it here. This may be subject to
5916 change. */
5917 parse_operand_result result = parse_neon_alignment (&p, i);
5918
5919 if (result != PARSE_OPERAND_SUCCESS)
5920 return result;
5921 }
5922 else
5923 {
5924 if (inst.operands[i].negative)
5925 {
5926 inst.operands[i].negative = 0;
5927 p--;
5928 }
5929
5930 if (group_relocations
5931 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5932 {
5933 struct group_reloc_table_entry *entry;
5934
5935 /* Skip over the #: or : sequence. */
5936 if (*p == '#')
5937 p += 2;
5938 else
5939 p++;
5940
5941 /* Try to parse a group relocation. Anything else is an
5942 error. */
5943 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5944 {
5945 inst.error = _("unknown group relocation");
5946 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5947 }
5948
5949 /* We now have the group relocation table entry corresponding to
5950 the name in the assembler source. Next, we parse the
5951 expression. */
5952 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
5953 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5954
5955 /* Record the relocation type. */
5956 switch (group_type)
5957 {
5958 case GROUP_LDR:
5959 inst.relocs[0].type
5960 = (bfd_reloc_code_real_type) entry->ldr_code;
5961 break;
5962
5963 case GROUP_LDRS:
5964 inst.relocs[0].type
5965 = (bfd_reloc_code_real_type) entry->ldrs_code;
5966 break;
5967
5968 case GROUP_LDC:
5969 inst.relocs[0].type
5970 = (bfd_reloc_code_real_type) entry->ldc_code;
5971 break;
5972
5973 default:
5974 gas_assert (0);
5975 }
5976
5977 if (inst.relocs[0].type == 0)
5978 {
5979 inst.error = _("this group relocation is not allowed on this instruction");
5980 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5981 }
5982 }
5983 else
5984 {
5985 char *q = p;
5986
5987 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5988 return PARSE_OPERAND_FAIL;
5989 /* If the offset is 0, find out if it's a +0 or -0. */
5990 if (inst.relocs[0].exp.X_op == O_constant
5991 && inst.relocs[0].exp.X_add_number == 0)
5992 {
5993 skip_whitespace (q);
5994 if (*q == '#')
5995 {
5996 q++;
5997 skip_whitespace (q);
5998 }
5999 if (*q == '-')
6000 inst.operands[i].negative = 1;
6001 }
6002 }
6003 }
6004 }
6005 else if (skip_past_char (&p, ':') == SUCCESS)
6006 {
6007 /* FIXME: '@' should be used here, but it's filtered out by generic code
6008 before we get to see it here. This may be subject to change. */
6009 parse_operand_result result = parse_neon_alignment (&p, i);
6010
6011 if (result != PARSE_OPERAND_SUCCESS)
6012 return result;
6013 }
6014
6015 if (skip_past_char (&p, ']') == FAIL)
6016 {
6017 inst.error = _("']' expected");
6018 return PARSE_OPERAND_FAIL;
6019 }
6020
6021 if (skip_past_char (&p, '!') == SUCCESS)
6022 inst.operands[i].writeback = 1;
6023
6024 else if (skip_past_comma (&p) == SUCCESS)
6025 {
6026 if (skip_past_char (&p, '{') == SUCCESS)
6027 {
6028 /* [Rn], {expr} - unindexed, with option */
6029 if (parse_immediate (&p, &inst.operands[i].imm,
6030 0, 255, TRUE) == FAIL)
6031 return PARSE_OPERAND_FAIL;
6032
6033 if (skip_past_char (&p, '}') == FAIL)
6034 {
6035 inst.error = _("'}' expected at end of 'option' field");
6036 return PARSE_OPERAND_FAIL;
6037 }
6038 if (inst.operands[i].preind)
6039 {
6040 inst.error = _("cannot combine index with option");
6041 return PARSE_OPERAND_FAIL;
6042 }
6043 *str = p;
6044 return PARSE_OPERAND_SUCCESS;
6045 }
6046 else
6047 {
6048 inst.operands[i].postind = 1;
6049 inst.operands[i].writeback = 1;
6050
6051 if (inst.operands[i].preind)
6052 {
6053 inst.error = _("cannot combine pre- and post-indexing");
6054 return PARSE_OPERAND_FAIL;
6055 }
6056
6057 if (*p == '+') p++;
6058 else if (*p == '-') p++, inst.operands[i].negative = 1;
6059
6060 enum arm_reg_type rtype = REG_TYPE_MQ;
6061 struct neon_type_el et;
6062 if (group_type == GROUP_MVE
6063 && (reg = arm_typed_reg_parse (&p, rtype, &rtype, &et)) != FAIL)
6064 {
6065 inst.operands[i].immisreg = 2;
6066 inst.operands[i].imm = reg;
6067 }
6068 else if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
6069 {
6070 /* We might be using the immediate for alignment already. If we
6071 are, OR the register number into the low-order bits. */
6072 if (inst.operands[i].immisalign)
6073 inst.operands[i].imm |= reg;
6074 else
6075 inst.operands[i].imm = reg;
6076 inst.operands[i].immisreg = 1;
6077
6078 if (skip_past_comma (&p) == SUCCESS)
6079 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
6080 return PARSE_OPERAND_FAIL;
6081 }
6082 else
6083 {
6084 char *q = p;
6085
6086 if (inst.operands[i].negative)
6087 {
6088 inst.operands[i].negative = 0;
6089 p--;
6090 }
6091 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
6092 return PARSE_OPERAND_FAIL;
6093 /* If the offset is 0, find out if it's a +0 or -0. */
6094 if (inst.relocs[0].exp.X_op == O_constant
6095 && inst.relocs[0].exp.X_add_number == 0)
6096 {
6097 skip_whitespace (q);
6098 if (*q == '#')
6099 {
6100 q++;
6101 skip_whitespace (q);
6102 }
6103 if (*q == '-')
6104 inst.operands[i].negative = 1;
6105 }
6106 }
6107 }
6108 }
6109
6110 /* If at this point neither .preind nor .postind is set, we have a
6111 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
6112 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
6113 {
6114 inst.operands[i].preind = 1;
6115 inst.relocs[0].exp.X_op = O_constant;
6116 inst.relocs[0].exp.X_add_number = 0;
6117 }
6118 *str = p;
6119 return PARSE_OPERAND_SUCCESS;
6120 }
6121
6122 static int
6123 parse_address (char **str, int i)
6124 {
6125 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
6126 ? SUCCESS : FAIL;
6127 }
6128
6129 static parse_operand_result
6130 parse_address_group_reloc (char **str, int i, group_reloc_type type)
6131 {
6132 return parse_address_main (str, i, 1, type);
6133 }
6134
6135 /* Parse an operand for a MOVW or MOVT instruction. */
6136 static int
6137 parse_half (char **str)
6138 {
6139 char * p;
6140
6141 p = *str;
6142 skip_past_char (&p, '#');
6143 if (strncasecmp (p, ":lower16:", 9) == 0)
6144 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
6145 else if (strncasecmp (p, ":upper16:", 9) == 0)
6146 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
6147
6148 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
6149 {
6150 p += 9;
6151 skip_whitespace (p);
6152 }
6153
6154 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
6155 return FAIL;
6156
6157 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
6158 {
6159 if (inst.relocs[0].exp.X_op != O_constant)
6160 {
6161 inst.error = _("constant expression expected");
6162 return FAIL;
6163 }
6164 if (inst.relocs[0].exp.X_add_number < 0
6165 || inst.relocs[0].exp.X_add_number > 0xffff)
6166 {
6167 inst.error = _("immediate value out of range");
6168 return FAIL;
6169 }
6170 }
6171 *str = p;
6172 return SUCCESS;
6173 }
6174
6175 /* Miscellaneous. */
6176
6177 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
6178 or a bitmask suitable to be or-ed into the ARM msr instruction. */
6179 static int
6180 parse_psr (char **str, bfd_boolean lhs)
6181 {
6182 char *p;
6183 unsigned long psr_field;
6184 const struct asm_psr *psr;
6185 char *start;
6186 bfd_boolean is_apsr = FALSE;
6187 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
6188
6189 /* PR gas/12698: If the user has specified -march=all then m_profile will
6190 be TRUE, but we want to ignore it in this case as we are building for any
6191 CPU type, including non-m variants. */
6192 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
6193 m_profile = FALSE;
6194
6195 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
6196 feature for ease of use and backwards compatibility. */
6197 p = *str;
6198 if (strncasecmp (p, "SPSR", 4) == 0)
6199 {
6200 if (m_profile)
6201 goto unsupported_psr;
6202
6203 psr_field = SPSR_BIT;
6204 }
6205 else if (strncasecmp (p, "CPSR", 4) == 0)
6206 {
6207 if (m_profile)
6208 goto unsupported_psr;
6209
6210 psr_field = 0;
6211 }
6212 else if (strncasecmp (p, "APSR", 4) == 0)
6213 {
6214 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
6215 and ARMv7-R architecture CPUs. */
6216 is_apsr = TRUE;
6217 psr_field = 0;
6218 }
6219 else if (m_profile)
6220 {
6221 start = p;
6222 do
6223 p++;
6224 while (ISALNUM (*p) || *p == '_');
6225
6226 if (strncasecmp (start, "iapsr", 5) == 0
6227 || strncasecmp (start, "eapsr", 5) == 0
6228 || strncasecmp (start, "xpsr", 4) == 0
6229 || strncasecmp (start, "psr", 3) == 0)
6230 p = start + strcspn (start, "rR") + 1;
6231
6232 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
6233 p - start);
6234
6235 if (!psr)
6236 return FAIL;
6237
6238 /* If APSR is being written, a bitfield may be specified. Note that
6239 APSR itself is handled above. */
6240 if (psr->field <= 3)
6241 {
6242 psr_field = psr->field;
6243 is_apsr = TRUE;
6244 goto check_suffix;
6245 }
6246
6247 *str = p;
6248 /* M-profile MSR instructions have the mask field set to "10", except
6249 *PSR variants which modify APSR, which may use a different mask (and
6250 have been handled already). Do that by setting the PSR_f field
6251 here. */
6252 return psr->field | (lhs ? PSR_f : 0);
6253 }
6254 else
6255 goto unsupported_psr;
6256
6257 p += 4;
6258 check_suffix:
6259 if (*p == '_')
6260 {
6261 /* A suffix follows. */
6262 p++;
6263 start = p;
6264
6265 do
6266 p++;
6267 while (ISALNUM (*p) || *p == '_');
6268
6269 if (is_apsr)
6270 {
6271 /* APSR uses a notation for bits, rather than fields. */
6272 unsigned int nzcvq_bits = 0;
6273 unsigned int g_bit = 0;
6274 char *bit;
6275
6276 for (bit = start; bit != p; bit++)
6277 {
6278 switch (TOLOWER (*bit))
6279 {
6280 case 'n':
6281 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
6282 break;
6283
6284 case 'z':
6285 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
6286 break;
6287
6288 case 'c':
6289 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
6290 break;
6291
6292 case 'v':
6293 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
6294 break;
6295
6296 case 'q':
6297 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
6298 break;
6299
6300 case 'g':
6301 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
6302 break;
6303
6304 default:
6305 inst.error = _("unexpected bit specified after APSR");
6306 return FAIL;
6307 }
6308 }
6309
6310 if (nzcvq_bits == 0x1f)
6311 psr_field |= PSR_f;
6312
6313 if (g_bit == 0x1)
6314 {
6315 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
6316 {
6317 inst.error = _("selected processor does not "
6318 "support DSP extension");
6319 return FAIL;
6320 }
6321
6322 psr_field |= PSR_s;
6323 }
6324
6325 if ((nzcvq_bits & 0x20) != 0
6326 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6327 || (g_bit & 0x2) != 0)
6328 {
6329 inst.error = _("bad bitmask specified after APSR");
6330 return FAIL;
6331 }
6332 }
6333 else
6334 {
6335 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
6336 p - start);
6337 if (!psr)
6338 goto error;
6339
6340 psr_field |= psr->field;
6341 }
6342 }
6343 else
6344 {
6345 if (ISALNUM (*p))
6346 goto error; /* Garbage after "[CS]PSR". */
6347
6348 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
6349 is deprecated, but allow it anyway. */
6350 if (is_apsr && lhs)
6351 {
6352 psr_field |= PSR_f;
6353 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6354 "deprecated"));
6355 }
6356 else if (!m_profile)
6357 /* These bits are never right for M-profile devices: don't set them
6358 (only code paths which read/write APSR reach here). */
6359 psr_field |= (PSR_c | PSR_f);
6360 }
6361 *str = p;
6362 return psr_field;
6363
6364 unsupported_psr:
6365 inst.error = _("selected processor does not support requested special "
6366 "purpose register");
6367 return FAIL;
6368
6369 error:
6370 inst.error = _("flag for {c}psr instruction expected");
6371 return FAIL;
6372 }
6373
6374 static int
6375 parse_sys_vldr_vstr (char **str)
6376 {
6377 unsigned i;
6378 int val = FAIL;
6379 struct {
6380 const char *name;
6381 int regl;
6382 int regh;
6383 } sysregs[] = {
6384 {"FPSCR", 0x1, 0x0},
6385 {"FPSCR_nzcvqc", 0x2, 0x0},
6386 {"VPR", 0x4, 0x1},
6387 {"P0", 0x5, 0x1},
6388 {"FPCXTNS", 0x6, 0x1},
6389 {"FPCXTS", 0x7, 0x1}
6390 };
6391 char *op_end = strchr (*str, ',');
6392 size_t op_strlen = op_end - *str;
6393
6394 for (i = 0; i < sizeof (sysregs) / sizeof (sysregs[0]); i++)
6395 {
6396 if (!strncmp (*str, sysregs[i].name, op_strlen))
6397 {
6398 val = sysregs[i].regl | (sysregs[i].regh << 3);
6399 *str = op_end;
6400 break;
6401 }
6402 }
6403
6404 return val;
6405 }
6406
6407 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6408 value suitable for splatting into the AIF field of the instruction. */
6409
6410 static int
6411 parse_cps_flags (char **str)
6412 {
6413 int val = 0;
6414 int saw_a_flag = 0;
6415 char *s = *str;
6416
6417 for (;;)
6418 switch (*s++)
6419 {
6420 case '\0': case ',':
6421 goto done;
6422
6423 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6424 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6425 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
6426
6427 default:
6428 inst.error = _("unrecognized CPS flag");
6429 return FAIL;
6430 }
6431
6432 done:
6433 if (saw_a_flag == 0)
6434 {
6435 inst.error = _("missing CPS flags");
6436 return FAIL;
6437 }
6438
6439 *str = s - 1;
6440 return val;
6441 }
6442
6443 /* Parse an endian specifier ("BE" or "LE", case insensitive);
6444 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
6445
6446 static int
6447 parse_endian_specifier (char **str)
6448 {
6449 int little_endian;
6450 char *s = *str;
6451
6452 if (strncasecmp (s, "BE", 2))
6453 little_endian = 0;
6454 else if (strncasecmp (s, "LE", 2))
6455 little_endian = 1;
6456 else
6457 {
6458 inst.error = _("valid endian specifiers are be or le");
6459 return FAIL;
6460 }
6461
6462 if (ISALNUM (s[2]) || s[2] == '_')
6463 {
6464 inst.error = _("valid endian specifiers are be or le");
6465 return FAIL;
6466 }
6467
6468 *str = s + 2;
6469 return little_endian;
6470 }
6471
6472 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6473 value suitable for poking into the rotate field of an sxt or sxta
6474 instruction, or FAIL on error. */
6475
6476 static int
6477 parse_ror (char **str)
6478 {
6479 int rot;
6480 char *s = *str;
6481
6482 if (strncasecmp (s, "ROR", 3) == 0)
6483 s += 3;
6484 else
6485 {
6486 inst.error = _("missing rotation field after comma");
6487 return FAIL;
6488 }
6489
6490 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6491 return FAIL;
6492
6493 switch (rot)
6494 {
6495 case 0: *str = s; return 0x0;
6496 case 8: *str = s; return 0x1;
6497 case 16: *str = s; return 0x2;
6498 case 24: *str = s; return 0x3;
6499
6500 default:
6501 inst.error = _("rotation can only be 0, 8, 16, or 24");
6502 return FAIL;
6503 }
6504 }
6505
6506 /* Parse a conditional code (from conds[] below). The value returned is in the
6507 range 0 .. 14, or FAIL. */
6508 static int
6509 parse_cond (char **str)
6510 {
6511 char *q;
6512 const struct asm_cond *c;
6513 int n;
6514 /* Condition codes are always 2 characters, so matching up to
6515 3 characters is sufficient. */
6516 char cond[3];
6517
6518 q = *str;
6519 n = 0;
6520 while (ISALPHA (*q) && n < 3)
6521 {
6522 cond[n] = TOLOWER (*q);
6523 q++;
6524 n++;
6525 }
6526
6527 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
6528 if (!c)
6529 {
6530 inst.error = _("condition required");
6531 return FAIL;
6532 }
6533
6534 *str = q;
6535 return c->value;
6536 }
6537
6538 /* Parse an option for a barrier instruction. Returns the encoding for the
6539 option, or FAIL. */
6540 static int
6541 parse_barrier (char **str)
6542 {
6543 char *p, *q;
6544 const struct asm_barrier_opt *o;
6545
6546 p = q = *str;
6547 while (ISALPHA (*q))
6548 q++;
6549
6550 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
6551 q - p);
6552 if (!o)
6553 return FAIL;
6554
6555 if (!mark_feature_used (&o->arch))
6556 return FAIL;
6557
6558 *str = q;
6559 return o->value;
6560 }
6561
6562 /* Parse the operands of a table branch instruction. Similar to a memory
6563 operand. */
6564 static int
6565 parse_tb (char **str)
6566 {
6567 char * p = *str;
6568 int reg;
6569
6570 if (skip_past_char (&p, '[') == FAIL)
6571 {
6572 inst.error = _("'[' expected");
6573 return FAIL;
6574 }
6575
6576 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6577 {
6578 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6579 return FAIL;
6580 }
6581 inst.operands[0].reg = reg;
6582
6583 if (skip_past_comma (&p) == FAIL)
6584 {
6585 inst.error = _("',' expected");
6586 return FAIL;
6587 }
6588
6589 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6590 {
6591 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6592 return FAIL;
6593 }
6594 inst.operands[0].imm = reg;
6595
6596 if (skip_past_comma (&p) == SUCCESS)
6597 {
6598 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6599 return FAIL;
6600 if (inst.relocs[0].exp.X_add_number != 1)
6601 {
6602 inst.error = _("invalid shift");
6603 return FAIL;
6604 }
6605 inst.operands[0].shifted = 1;
6606 }
6607
6608 if (skip_past_char (&p, ']') == FAIL)
6609 {
6610 inst.error = _("']' expected");
6611 return FAIL;
6612 }
6613 *str = p;
6614 return SUCCESS;
6615 }
6616
6617 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6618 information on the types the operands can take and how they are encoded.
6619 Up to four operands may be read; this function handles setting the
6620 ".present" field for each read operand itself.
6621 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6622 else returns FAIL. */
6623
6624 static int
6625 parse_neon_mov (char **str, int *which_operand)
6626 {
6627 int i = *which_operand, val;
6628 enum arm_reg_type rtype;
6629 char *ptr = *str;
6630 struct neon_type_el optype;
6631
6632 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6633 {
6634 /* Cases 17 or 19. */
6635 inst.operands[i].reg = val;
6636 inst.operands[i].isvec = 1;
6637 inst.operands[i].isscalar = 2;
6638 inst.operands[i].vectype = optype;
6639 inst.operands[i++].present = 1;
6640
6641 if (skip_past_comma (&ptr) == FAIL)
6642 goto wanted_comma;
6643
6644 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6645 {
6646 /* Case 17: VMOV<c>.<dt> <Qd[idx]>, <Rt> */
6647 inst.operands[i].reg = val;
6648 inst.operands[i].isreg = 1;
6649 inst.operands[i].present = 1;
6650 }
6651 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6652 {
6653 /* Case 19: VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2> */
6654 inst.operands[i].reg = val;
6655 inst.operands[i].isvec = 1;
6656 inst.operands[i].isscalar = 2;
6657 inst.operands[i].vectype = optype;
6658 inst.operands[i++].present = 1;
6659
6660 if (skip_past_comma (&ptr) == FAIL)
6661 goto wanted_comma;
6662
6663 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6664 goto wanted_arm;
6665
6666 inst.operands[i].reg = val;
6667 inst.operands[i].isreg = 1;
6668 inst.operands[i++].present = 1;
6669
6670 if (skip_past_comma (&ptr) == FAIL)
6671 goto wanted_comma;
6672
6673 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6674 goto wanted_arm;
6675
6676 inst.operands[i].reg = val;
6677 inst.operands[i].isreg = 1;
6678 inst.operands[i].present = 1;
6679 }
6680 else
6681 {
6682 first_error (_("expected ARM or MVE vector register"));
6683 return FAIL;
6684 }
6685 }
6686 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6687 {
6688 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6689 inst.operands[i].reg = val;
6690 inst.operands[i].isscalar = 1;
6691 inst.operands[i].vectype = optype;
6692 inst.operands[i++].present = 1;
6693
6694 if (skip_past_comma (&ptr) == FAIL)
6695 goto wanted_comma;
6696
6697 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6698 goto wanted_arm;
6699
6700 inst.operands[i].reg = val;
6701 inst.operands[i].isreg = 1;
6702 inst.operands[i].present = 1;
6703 }
6704 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6705 != FAIL)
6706 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype, &optype))
6707 != FAIL))
6708 {
6709 /* Cases 0, 1, 2, 3, 5 (D only). */
6710 if (skip_past_comma (&ptr) == FAIL)
6711 goto wanted_comma;
6712
6713 inst.operands[i].reg = val;
6714 inst.operands[i].isreg = 1;
6715 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6716 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6717 inst.operands[i].isvec = 1;
6718 inst.operands[i].vectype = optype;
6719 inst.operands[i++].present = 1;
6720
6721 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6722 {
6723 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6724 Case 13: VMOV <Sd>, <Rm> */
6725 inst.operands[i].reg = val;
6726 inst.operands[i].isreg = 1;
6727 inst.operands[i].present = 1;
6728
6729 if (rtype == REG_TYPE_NQ)
6730 {
6731 first_error (_("can't use Neon quad register here"));
6732 return FAIL;
6733 }
6734 else if (rtype != REG_TYPE_VFS)
6735 {
6736 i++;
6737 if (skip_past_comma (&ptr) == FAIL)
6738 goto wanted_comma;
6739 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6740 goto wanted_arm;
6741 inst.operands[i].reg = val;
6742 inst.operands[i].isreg = 1;
6743 inst.operands[i].present = 1;
6744 }
6745 }
6746 else if (((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6747 &optype)) != FAIL)
6748 || ((val = arm_typed_reg_parse (&ptr, REG_TYPE_MQ, &rtype,
6749 &optype)) != FAIL))
6750 {
6751 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6752 Case 1: VMOV<c><q> <Dd>, <Dm>
6753 Case 8: VMOV.F32 <Sd>, <Sm>
6754 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6755
6756 inst.operands[i].reg = val;
6757 inst.operands[i].isreg = 1;
6758 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6759 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6760 inst.operands[i].isvec = 1;
6761 inst.operands[i].vectype = optype;
6762 inst.operands[i].present = 1;
6763
6764 if (skip_past_comma (&ptr) == SUCCESS)
6765 {
6766 /* Case 15. */
6767 i++;
6768
6769 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6770 goto wanted_arm;
6771
6772 inst.operands[i].reg = val;
6773 inst.operands[i].isreg = 1;
6774 inst.operands[i++].present = 1;
6775
6776 if (skip_past_comma (&ptr) == FAIL)
6777 goto wanted_comma;
6778
6779 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6780 goto wanted_arm;
6781
6782 inst.operands[i].reg = val;
6783 inst.operands[i].isreg = 1;
6784 inst.operands[i].present = 1;
6785 }
6786 }
6787 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6788 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6789 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6790 Case 10: VMOV.F32 <Sd>, #<imm>
6791 Case 11: VMOV.F64 <Dd>, #<imm> */
6792 inst.operands[i].immisfloat = 1;
6793 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6794 == SUCCESS)
6795 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6796 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6797 ;
6798 else
6799 {
6800 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6801 return FAIL;
6802 }
6803 }
6804 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6805 {
6806 /* Cases 6, 7, 16, 18. */
6807 inst.operands[i].reg = val;
6808 inst.operands[i].isreg = 1;
6809 inst.operands[i++].present = 1;
6810
6811 if (skip_past_comma (&ptr) == FAIL)
6812 goto wanted_comma;
6813
6814 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ)) != FAIL)
6815 {
6816 /* Case 18: VMOV<c>.<dt> <Rt>, <Qn[idx]> */
6817 inst.operands[i].reg = val;
6818 inst.operands[i].isscalar = 2;
6819 inst.operands[i].present = 1;
6820 inst.operands[i].vectype = optype;
6821 }
6822 else if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_VFD)) != FAIL)
6823 {
6824 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6825 inst.operands[i].reg = val;
6826 inst.operands[i].isscalar = 1;
6827 inst.operands[i].present = 1;
6828 inst.operands[i].vectype = optype;
6829 }
6830 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6831 {
6832 inst.operands[i].reg = val;
6833 inst.operands[i].isreg = 1;
6834 inst.operands[i++].present = 1;
6835
6836 if (skip_past_comma (&ptr) == FAIL)
6837 goto wanted_comma;
6838
6839 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6840 != FAIL)
6841 {
6842 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6843
6844 inst.operands[i].reg = val;
6845 inst.operands[i].isreg = 1;
6846 inst.operands[i].isvec = 1;
6847 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6848 inst.operands[i].vectype = optype;
6849 inst.operands[i].present = 1;
6850
6851 if (rtype == REG_TYPE_VFS)
6852 {
6853 /* Case 14. */
6854 i++;
6855 if (skip_past_comma (&ptr) == FAIL)
6856 goto wanted_comma;
6857 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6858 &optype)) == FAIL)
6859 {
6860 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6861 return FAIL;
6862 }
6863 inst.operands[i].reg = val;
6864 inst.operands[i].isreg = 1;
6865 inst.operands[i].isvec = 1;
6866 inst.operands[i].issingle = 1;
6867 inst.operands[i].vectype = optype;
6868 inst.operands[i].present = 1;
6869 }
6870 }
6871 else
6872 {
6873 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6874 != FAIL)
6875 {
6876 /* Case 16: VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]> */
6877 inst.operands[i].reg = val;
6878 inst.operands[i].isvec = 1;
6879 inst.operands[i].isscalar = 2;
6880 inst.operands[i].vectype = optype;
6881 inst.operands[i++].present = 1;
6882
6883 if (skip_past_comma (&ptr) == FAIL)
6884 goto wanted_comma;
6885
6886 if ((val = parse_scalar (&ptr, 8, &optype, REG_TYPE_MQ))
6887 == FAIL)
6888 {
6889 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
6890 return FAIL;
6891 }
6892 inst.operands[i].reg = val;
6893 inst.operands[i].isvec = 1;
6894 inst.operands[i].isscalar = 2;
6895 inst.operands[i].vectype = optype;
6896 inst.operands[i].present = 1;
6897 }
6898 else
6899 {
6900 first_error (_("VFP single, double or MVE vector register"
6901 " expected"));
6902 return FAIL;
6903 }
6904 }
6905 }
6906 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6907 != FAIL)
6908 {
6909 /* Case 13. */
6910 inst.operands[i].reg = val;
6911 inst.operands[i].isreg = 1;
6912 inst.operands[i].isvec = 1;
6913 inst.operands[i].issingle = 1;
6914 inst.operands[i].vectype = optype;
6915 inst.operands[i].present = 1;
6916 }
6917 }
6918 else
6919 {
6920 first_error (_("parse error"));
6921 return FAIL;
6922 }
6923
6924 /* Successfully parsed the operands. Update args. */
6925 *which_operand = i;
6926 *str = ptr;
6927 return SUCCESS;
6928
6929 wanted_comma:
6930 first_error (_("expected comma"));
6931 return FAIL;
6932
6933 wanted_arm:
6934 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6935 return FAIL;
6936 }
6937
6938 /* Use this macro when the operand constraints are different
6939 for ARM and THUMB (e.g. ldrd). */
6940 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6941 ((arm_operand) | ((thumb_operand) << 16))
6942
6943 /* Matcher codes for parse_operands. */
6944 enum operand_parse_code
6945 {
6946 OP_stop, /* end of line */
6947
6948 OP_RR, /* ARM register */
6949 OP_RRnpc, /* ARM register, not r15 */
6950 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6951 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6952 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6953 optional trailing ! */
6954 OP_RRw, /* ARM register, not r15, optional trailing ! */
6955 OP_RCP, /* Coprocessor number */
6956 OP_RCN, /* Coprocessor register */
6957 OP_RF, /* FPA register */
6958 OP_RVS, /* VFP single precision register */
6959 OP_RVD, /* VFP double precision register (0..15) */
6960 OP_RND, /* Neon double precision register (0..31) */
6961 OP_RNDMQ, /* Neon double precision (0..31) or MVE vector register. */
6962 OP_RNDMQR, /* Neon double precision (0..31), MVE vector or ARM register.
6963 */
6964 OP_RNQ, /* Neon quad precision register */
6965 OP_RNQMQ, /* Neon quad or MVE vector register. */
6966 OP_RVSD, /* VFP single or double precision register */
6967 OP_RVSD_COND, /* VFP single, double precision register or condition code. */
6968 OP_RVSDMQ, /* VFP single, double precision or MVE vector register. */
6969 OP_RNSD, /* Neon single or double precision register */
6970 OP_RNDQ, /* Neon double or quad precision register */
6971 OP_RNDQMQ, /* Neon double, quad or MVE vector register. */
6972 OP_RNDQMQR, /* Neon double, quad, MVE vector or ARM register. */
6973 OP_RNSDQ, /* Neon single, double or quad precision register */
6974 OP_RNSC, /* Neon scalar D[X] */
6975 OP_RVC, /* VFP control register */
6976 OP_RMF, /* Maverick F register */
6977 OP_RMD, /* Maverick D register */
6978 OP_RMFX, /* Maverick FX register */
6979 OP_RMDX, /* Maverick DX register */
6980 OP_RMAX, /* Maverick AX register */
6981 OP_RMDS, /* Maverick DSPSC register */
6982 OP_RIWR, /* iWMMXt wR register */
6983 OP_RIWC, /* iWMMXt wC register */
6984 OP_RIWG, /* iWMMXt wCG register */
6985 OP_RXA, /* XScale accumulator register */
6986
6987 OP_RNSDQMQ, /* Neon single, double or quad register or MVE vector register
6988 */
6989 OP_RNSDQMQR, /* Neon single, double or quad register, MVE vector register or
6990 GPR (no SP/SP) */
6991 OP_RMQ, /* MVE vector register. */
6992 OP_RMQRZ, /* MVE vector or ARM register including ZR. */
6993 OP_RMQRR, /* MVE vector or ARM register. */
6994
6995 /* New operands for Armv8.1-M Mainline. */
6996 OP_LR, /* ARM LR register */
6997 OP_RRe, /* ARM register, only even numbered. */
6998 OP_RRo, /* ARM register, only odd numbered, not r13 or r15. */
6999 OP_RRnpcsp_I32, /* ARM register (no BadReg) or literal 1 .. 32 */
7000 OP_RR_ZR, /* ARM register or ZR but no PC */
7001
7002 OP_REGLST, /* ARM register list */
7003 OP_CLRMLST, /* CLRM register list */
7004 OP_VRSLST, /* VFP single-precision register list */
7005 OP_VRDLST, /* VFP double-precision register list */
7006 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
7007 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
7008 OP_NSTRLST, /* Neon element/structure list */
7009 OP_VRSDVLST, /* VFP single or double-precision register list and VPR */
7010 OP_MSTRLST2, /* MVE vector list with two elements. */
7011 OP_MSTRLST4, /* MVE vector list with four elements. */
7012
7013 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
7014 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
7015 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
7016 OP_RSVDMQ_FI0, /* VFP S, D, MVE vector register or floating point immediate
7017 zero. */
7018 OP_RR_RNSC, /* ARM reg or Neon scalar. */
7019 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
7020 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
7021 OP_RNSDQ_RNSC_MQ, /* Vector S, D or Q reg, Neon scalar or MVE vector register.
7022 */
7023 OP_RNSDQ_RNSC_MQ_RR, /* Vector S, D or Q reg, or MVE vector reg , or Neon
7024 scalar, or ARM register. */
7025 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
7026 OP_RNDQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, or ARM register. */
7027 OP_RNDQMQ_RNSC_RR, /* Neon D or Q reg, Neon scalar, MVE vector or ARM
7028 register. */
7029 OP_RNDQMQ_RNSC, /* Neon D, Q or MVE vector reg, or Neon scalar. */
7030 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
7031 OP_VMOV, /* Neon VMOV operands. */
7032 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
7033 /* Neon D, Q or MVE vector register, or big immediate for logic and VMVN. */
7034 OP_RNDQMQ_Ibig,
7035 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
7036 OP_RNDQMQ_I63b_RR, /* Neon D or Q reg, immediate for shift, MVE vector or
7037 ARM register. */
7038 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
7039 OP_VLDR, /* VLDR operand. */
7040
7041 OP_I0, /* immediate zero */
7042 OP_I7, /* immediate value 0 .. 7 */
7043 OP_I15, /* 0 .. 15 */
7044 OP_I16, /* 1 .. 16 */
7045 OP_I16z, /* 0 .. 16 */
7046 OP_I31, /* 0 .. 31 */
7047 OP_I31w, /* 0 .. 31, optional trailing ! */
7048 OP_I32, /* 1 .. 32 */
7049 OP_I32z, /* 0 .. 32 */
7050 OP_I48_I64, /* 48 or 64 */
7051 OP_I63, /* 0 .. 63 */
7052 OP_I63s, /* -64 .. 63 */
7053 OP_I64, /* 1 .. 64 */
7054 OP_I64z, /* 0 .. 64 */
7055 OP_I255, /* 0 .. 255 */
7056
7057 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
7058 OP_I7b, /* 0 .. 7 */
7059 OP_I15b, /* 0 .. 15 */
7060 OP_I31b, /* 0 .. 31 */
7061
7062 OP_SH, /* shifter operand */
7063 OP_SHG, /* shifter operand with possible group relocation */
7064 OP_ADDR, /* Memory address expression (any mode) */
7065 OP_ADDRMVE, /* Memory address expression for MVE's VSTR/VLDR. */
7066 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
7067 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
7068 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
7069 OP_EXP, /* arbitrary expression */
7070 OP_EXPi, /* same, with optional immediate prefix */
7071 OP_EXPr, /* same, with optional relocation suffix */
7072 OP_EXPs, /* same, with optional non-first operand relocation suffix */
7073 OP_HALF, /* 0 .. 65535 or low/high reloc. */
7074 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
7075 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
7076
7077 OP_CPSF, /* CPS flags */
7078 OP_ENDI, /* Endianness specifier */
7079 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
7080 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
7081 OP_COND, /* conditional code */
7082 OP_TB, /* Table branch. */
7083
7084 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
7085
7086 OP_RRnpc_I0, /* ARM register or literal 0 */
7087 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
7088 OP_RR_EXi, /* ARM register or expression with imm prefix */
7089 OP_RF_IF, /* FPA register or immediate */
7090 OP_RIWR_RIWC, /* iWMMXt R or C reg */
7091 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
7092
7093 /* Optional operands. */
7094 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
7095 OP_oI31b, /* 0 .. 31 */
7096 OP_oI32b, /* 1 .. 32 */
7097 OP_oI32z, /* 0 .. 32 */
7098 OP_oIffffb, /* 0 .. 65535 */
7099 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
7100
7101 OP_oRR, /* ARM register */
7102 OP_oLR, /* ARM LR register */
7103 OP_oRRnpc, /* ARM register, not the PC */
7104 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
7105 OP_oRRw, /* ARM register, not r15, optional trailing ! */
7106 OP_oRND, /* Optional Neon double precision register */
7107 OP_oRNQ, /* Optional Neon quad precision register */
7108 OP_oRNDQMQ, /* Optional Neon double, quad or MVE vector register. */
7109 OP_oRNDQ, /* Optional Neon double or quad precision register */
7110 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
7111 OP_oRNSDQMQ, /* Optional single, double or quad register or MVE vector
7112 register. */
7113 OP_oSHll, /* LSL immediate */
7114 OP_oSHar, /* ASR immediate */
7115 OP_oSHllar, /* LSL or ASR immediate */
7116 OP_oROR, /* ROR 0/8/16/24 */
7117 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
7118
7119 OP_oRMQRZ, /* optional MVE vector or ARM register including ZR. */
7120
7121 /* Some pre-defined mixed (ARM/THUMB) operands. */
7122 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
7123 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
7124 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
7125
7126 OP_FIRST_OPTIONAL = OP_oI7b
7127 };
7128
7129 /* Generic instruction operand parser. This does no encoding and no
7130 semantic validation; it merely squirrels values away in the inst
7131 structure. Returns SUCCESS or FAIL depending on whether the
7132 specified grammar matched. */
7133 static int
7134 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
7135 {
7136 unsigned const int *upat = pattern;
7137 char *backtrack_pos = 0;
7138 const char *backtrack_error = 0;
7139 int i, val = 0, backtrack_index = 0;
7140 enum arm_reg_type rtype;
7141 parse_operand_result result;
7142 unsigned int op_parse_code;
7143 bfd_boolean partial_match;
7144
7145 #define po_char_or_fail(chr) \
7146 do \
7147 { \
7148 if (skip_past_char (&str, chr) == FAIL) \
7149 goto bad_args; \
7150 } \
7151 while (0)
7152
7153 #define po_reg_or_fail(regtype) \
7154 do \
7155 { \
7156 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7157 & inst.operands[i].vectype); \
7158 if (val == FAIL) \
7159 { \
7160 first_error (_(reg_expected_msgs[regtype])); \
7161 goto failure; \
7162 } \
7163 inst.operands[i].reg = val; \
7164 inst.operands[i].isreg = 1; \
7165 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7166 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7167 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7168 || rtype == REG_TYPE_VFD \
7169 || rtype == REG_TYPE_NQ); \
7170 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7171 } \
7172 while (0)
7173
7174 #define po_reg_or_goto(regtype, label) \
7175 do \
7176 { \
7177 val = arm_typed_reg_parse (& str, regtype, & rtype, \
7178 & inst.operands[i].vectype); \
7179 if (val == FAIL) \
7180 goto label; \
7181 \
7182 inst.operands[i].reg = val; \
7183 inst.operands[i].isreg = 1; \
7184 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
7185 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
7186 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
7187 || rtype == REG_TYPE_VFD \
7188 || rtype == REG_TYPE_NQ); \
7189 inst.operands[i].iszr = (rtype == REG_TYPE_ZR); \
7190 } \
7191 while (0)
7192
7193 #define po_imm_or_fail(min, max, popt) \
7194 do \
7195 { \
7196 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
7197 goto failure; \
7198 inst.operands[i].imm = val; \
7199 } \
7200 while (0)
7201
7202 #define po_imm1_or_imm2_or_fail(imm1, imm2, popt) \
7203 do \
7204 { \
7205 expressionS exp; \
7206 my_get_expression (&exp, &str, popt); \
7207 if (exp.X_op != O_constant) \
7208 { \
7209 inst.error = _("constant expression required"); \
7210 goto failure; \
7211 } \
7212 if (exp.X_add_number != imm1 && exp.X_add_number != imm2) \
7213 { \
7214 inst.error = _("immediate value 48 or 64 expected"); \
7215 goto failure; \
7216 } \
7217 inst.operands[i].imm = exp.X_add_number; \
7218 } \
7219 while (0)
7220
7221 #define po_scalar_or_goto(elsz, label, reg_type) \
7222 do \
7223 { \
7224 val = parse_scalar (& str, elsz, & inst.operands[i].vectype, \
7225 reg_type); \
7226 if (val == FAIL) \
7227 goto label; \
7228 inst.operands[i].reg = val; \
7229 inst.operands[i].isscalar = 1; \
7230 } \
7231 while (0)
7232
7233 #define po_misc_or_fail(expr) \
7234 do \
7235 { \
7236 if (expr) \
7237 goto failure; \
7238 } \
7239 while (0)
7240
7241 #define po_misc_or_fail_no_backtrack(expr) \
7242 do \
7243 { \
7244 result = expr; \
7245 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
7246 backtrack_pos = 0; \
7247 if (result != PARSE_OPERAND_SUCCESS) \
7248 goto failure; \
7249 } \
7250 while (0)
7251
7252 #define po_barrier_or_imm(str) \
7253 do \
7254 { \
7255 val = parse_barrier (&str); \
7256 if (val == FAIL && ! ISALPHA (*str)) \
7257 goto immediate; \
7258 if (val == FAIL \
7259 /* ISB can only take SY as an option. */ \
7260 || ((inst.instruction & 0xf0) == 0x60 \
7261 && val != 0xf)) \
7262 { \
7263 inst.error = _("invalid barrier type"); \
7264 backtrack_pos = 0; \
7265 goto failure; \
7266 } \
7267 } \
7268 while (0)
7269
7270 skip_whitespace (str);
7271
7272 for (i = 0; upat[i] != OP_stop; i++)
7273 {
7274 op_parse_code = upat[i];
7275 if (op_parse_code >= 1<<16)
7276 op_parse_code = thumb ? (op_parse_code >> 16)
7277 : (op_parse_code & ((1<<16)-1));
7278
7279 if (op_parse_code >= OP_FIRST_OPTIONAL)
7280 {
7281 /* Remember where we are in case we need to backtrack. */
7282 backtrack_pos = str;
7283 backtrack_error = inst.error;
7284 backtrack_index = i;
7285 }
7286
7287 if (i > 0 && (i > 1 || inst.operands[0].present))
7288 po_char_or_fail (',');
7289
7290 switch (op_parse_code)
7291 {
7292 /* Registers */
7293 case OP_oRRnpc:
7294 case OP_oRRnpcsp:
7295 case OP_RRnpc:
7296 case OP_RRnpcsp:
7297 case OP_oRR:
7298 case OP_RRe:
7299 case OP_RRo:
7300 case OP_LR:
7301 case OP_oLR:
7302 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
7303 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
7304 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
7305 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
7306 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
7307 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
7308 case OP_oRND:
7309 case OP_RNDMQR:
7310 po_reg_or_goto (REG_TYPE_RN, try_rndmq);
7311 break;
7312 try_rndmq:
7313 case OP_RNDMQ:
7314 po_reg_or_goto (REG_TYPE_MQ, try_rnd);
7315 break;
7316 try_rnd:
7317 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
7318 case OP_RVC:
7319 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
7320 break;
7321 /* Also accept generic coprocessor regs for unknown registers. */
7322 coproc_reg:
7323 po_reg_or_goto (REG_TYPE_CN, vpr_po);
7324 break;
7325 /* Also accept P0 or p0 for VPR.P0. Since P0 is already an
7326 existing register with a value of 0, this seems like the
7327 best way to parse P0. */
7328 vpr_po:
7329 if (strncasecmp (str, "P0", 2) == 0)
7330 {
7331 str += 2;
7332 inst.operands[i].isreg = 1;
7333 inst.operands[i].reg = 13;
7334 }
7335 else
7336 goto failure;
7337 break;
7338 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
7339 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
7340 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
7341 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
7342 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
7343 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
7344 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
7345 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
7346 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
7347 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
7348 case OP_oRNQ:
7349 case OP_RNQMQ:
7350 po_reg_or_goto (REG_TYPE_MQ, try_nq);
7351 break;
7352 try_nq:
7353 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
7354 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
7355 case OP_RNDQMQR:
7356 po_reg_or_goto (REG_TYPE_RN, try_rndqmq);
7357 break;
7358 try_rndqmq:
7359 case OP_oRNDQMQ:
7360 case OP_RNDQMQ:
7361 po_reg_or_goto (REG_TYPE_MQ, try_rndq);
7362 break;
7363 try_rndq:
7364 case OP_oRNDQ:
7365 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
7366 case OP_RVSDMQ:
7367 po_reg_or_goto (REG_TYPE_MQ, try_rvsd);
7368 break;
7369 try_rvsd:
7370 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
7371 case OP_RVSD_COND:
7372 po_reg_or_goto (REG_TYPE_VFSD, try_cond);
7373 break;
7374 case OP_oRNSDQ:
7375 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
7376 case OP_RNSDQMQR:
7377 po_reg_or_goto (REG_TYPE_RN, try_mq);
7378 break;
7379 try_mq:
7380 case OP_oRNSDQMQ:
7381 case OP_RNSDQMQ:
7382 po_reg_or_goto (REG_TYPE_MQ, try_nsdq2);
7383 break;
7384 try_nsdq2:
7385 po_reg_or_fail (REG_TYPE_NSDQ);
7386 inst.error = 0;
7387 break;
7388 case OP_RMQRR:
7389 po_reg_or_goto (REG_TYPE_RN, try_rmq);
7390 break;
7391 try_rmq:
7392 case OP_RMQ:
7393 po_reg_or_fail (REG_TYPE_MQ);
7394 break;
7395 /* Neon scalar. Using an element size of 8 means that some invalid
7396 scalars are accepted here, so deal with those in later code. */
7397 case OP_RNSC: po_scalar_or_goto (8, failure, REG_TYPE_VFD); break;
7398
7399 case OP_RNDQ_I0:
7400 {
7401 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
7402 break;
7403 try_imm0:
7404 po_imm_or_fail (0, 0, TRUE);
7405 }
7406 break;
7407
7408 case OP_RVSD_I0:
7409 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
7410 break;
7411
7412 case OP_RSVDMQ_FI0:
7413 po_reg_or_goto (REG_TYPE_MQ, try_rsvd_fi0);
7414 break;
7415 try_rsvd_fi0:
7416 case OP_RSVD_FI0:
7417 {
7418 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
7419 break;
7420 try_ifimm0:
7421 if (parse_ifimm_zero (&str))
7422 inst.operands[i].imm = 0;
7423 else
7424 {
7425 inst.error
7426 = _("only floating point zero is allowed as immediate value");
7427 goto failure;
7428 }
7429 }
7430 break;
7431
7432 case OP_RR_RNSC:
7433 {
7434 po_scalar_or_goto (8, try_rr, REG_TYPE_VFD);
7435 break;
7436 try_rr:
7437 po_reg_or_fail (REG_TYPE_RN);
7438 }
7439 break;
7440
7441 case OP_RNSDQ_RNSC_MQ_RR:
7442 po_reg_or_goto (REG_TYPE_RN, try_rnsdq_rnsc_mq);
7443 break;
7444 try_rnsdq_rnsc_mq:
7445 case OP_RNSDQ_RNSC_MQ:
7446 po_reg_or_goto (REG_TYPE_MQ, try_rnsdq_rnsc);
7447 break;
7448 try_rnsdq_rnsc:
7449 case OP_RNSDQ_RNSC:
7450 {
7451 po_scalar_or_goto (8, try_nsdq, REG_TYPE_VFD);
7452 inst.error = 0;
7453 break;
7454 try_nsdq:
7455 po_reg_or_fail (REG_TYPE_NSDQ);
7456 inst.error = 0;
7457 }
7458 break;
7459
7460 case OP_RNSD_RNSC:
7461 {
7462 po_scalar_or_goto (8, try_s_scalar, REG_TYPE_VFD);
7463 break;
7464 try_s_scalar:
7465 po_scalar_or_goto (4, try_nsd, REG_TYPE_VFS);
7466 break;
7467 try_nsd:
7468 po_reg_or_fail (REG_TYPE_NSD);
7469 }
7470 break;
7471
7472 case OP_RNDQMQ_RNSC_RR:
7473 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc_rr);
7474 break;
7475 try_rndq_rnsc_rr:
7476 case OP_RNDQ_RNSC_RR:
7477 po_reg_or_goto (REG_TYPE_RN, try_rndq_rnsc);
7478 break;
7479 case OP_RNDQMQ_RNSC:
7480 po_reg_or_goto (REG_TYPE_MQ, try_rndq_rnsc);
7481 break;
7482 try_rndq_rnsc:
7483 case OP_RNDQ_RNSC:
7484 {
7485 po_scalar_or_goto (8, try_ndq, REG_TYPE_VFD);
7486 break;
7487 try_ndq:
7488 po_reg_or_fail (REG_TYPE_NDQ);
7489 }
7490 break;
7491
7492 case OP_RND_RNSC:
7493 {
7494 po_scalar_or_goto (8, try_vfd, REG_TYPE_VFD);
7495 break;
7496 try_vfd:
7497 po_reg_or_fail (REG_TYPE_VFD);
7498 }
7499 break;
7500
7501 case OP_VMOV:
7502 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
7503 not careful then bad things might happen. */
7504 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
7505 break;
7506
7507 case OP_RNDQMQ_Ibig:
7508 po_reg_or_goto (REG_TYPE_MQ, try_rndq_ibig);
7509 break;
7510 try_rndq_ibig:
7511 case OP_RNDQ_Ibig:
7512 {
7513 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
7514 break;
7515 try_immbig:
7516 /* There's a possibility of getting a 64-bit immediate here, so
7517 we need special handling. */
7518 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
7519 == FAIL)
7520 {
7521 inst.error = _("immediate value is out of range");
7522 goto failure;
7523 }
7524 }
7525 break;
7526
7527 case OP_RNDQMQ_I63b_RR:
7528 po_reg_or_goto (REG_TYPE_MQ, try_rndq_i63b_rr);
7529 break;
7530 try_rndq_i63b_rr:
7531 po_reg_or_goto (REG_TYPE_RN, try_rndq_i63b);
7532 break;
7533 try_rndq_i63b:
7534 case OP_RNDQ_I63b:
7535 {
7536 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
7537 break;
7538 try_shimm:
7539 po_imm_or_fail (0, 63, TRUE);
7540 }
7541 break;
7542
7543 case OP_RRnpcb:
7544 po_char_or_fail ('[');
7545 po_reg_or_fail (REG_TYPE_RN);
7546 po_char_or_fail (']');
7547 break;
7548
7549 case OP_RRnpctw:
7550 case OP_RRw:
7551 case OP_oRRw:
7552 po_reg_or_fail (REG_TYPE_RN);
7553 if (skip_past_char (&str, '!') == SUCCESS)
7554 inst.operands[i].writeback = 1;
7555 break;
7556
7557 /* Immediates */
7558 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
7559 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
7560 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
7561 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
7562 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
7563 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
7564 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
7565 case OP_I48_I64: po_imm1_or_imm2_or_fail (48, 64, FALSE); break;
7566 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
7567 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
7568 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
7569 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
7570 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
7571
7572 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
7573 case OP_oI7b:
7574 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
7575 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
7576 case OP_oI31b:
7577 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
7578 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
7579 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
7580 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
7581
7582 /* Immediate variants */
7583 case OP_oI255c:
7584 po_char_or_fail ('{');
7585 po_imm_or_fail (0, 255, TRUE);
7586 po_char_or_fail ('}');
7587 break;
7588
7589 case OP_I31w:
7590 /* The expression parser chokes on a trailing !, so we have
7591 to find it first and zap it. */
7592 {
7593 char *s = str;
7594 while (*s && *s != ',')
7595 s++;
7596 if (s[-1] == '!')
7597 {
7598 s[-1] = '\0';
7599 inst.operands[i].writeback = 1;
7600 }
7601 po_imm_or_fail (0, 31, TRUE);
7602 if (str == s - 1)
7603 str = s;
7604 }
7605 break;
7606
7607 /* Expressions */
7608 case OP_EXPi: EXPi:
7609 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7610 GE_OPT_PREFIX));
7611 break;
7612
7613 case OP_EXP:
7614 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7615 GE_NO_PREFIX));
7616 break;
7617
7618 case OP_EXPr: EXPr:
7619 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7620 GE_NO_PREFIX));
7621 if (inst.relocs[0].exp.X_op == O_symbol)
7622 {
7623 val = parse_reloc (&str);
7624 if (val == -1)
7625 {
7626 inst.error = _("unrecognized relocation suffix");
7627 goto failure;
7628 }
7629 else if (val != BFD_RELOC_UNUSED)
7630 {
7631 inst.operands[i].imm = val;
7632 inst.operands[i].hasreloc = 1;
7633 }
7634 }
7635 break;
7636
7637 case OP_EXPs:
7638 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7639 GE_NO_PREFIX));
7640 if (inst.relocs[i].exp.X_op == O_symbol)
7641 {
7642 inst.operands[i].hasreloc = 1;
7643 }
7644 else if (inst.relocs[i].exp.X_op == O_constant)
7645 {
7646 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7647 inst.operands[i].hasreloc = 0;
7648 }
7649 break;
7650
7651 /* Operand for MOVW or MOVT. */
7652 case OP_HALF:
7653 po_misc_or_fail (parse_half (&str));
7654 break;
7655
7656 /* Register or expression. */
7657 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7658 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
7659
7660 /* Register or immediate. */
7661 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7662 I0: po_imm_or_fail (0, 0, FALSE); break;
7663
7664 case OP_RRnpcsp_I32: po_reg_or_goto (REG_TYPE_RN, I32); break;
7665 I32: po_imm_or_fail (1, 32, FALSE); break;
7666
7667 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7668 IF:
7669 if (!is_immediate_prefix (*str))
7670 goto bad_args;
7671 str++;
7672 val = parse_fpa_immediate (&str);
7673 if (val == FAIL)
7674 goto failure;
7675 /* FPA immediates are encoded as registers 8-15.
7676 parse_fpa_immediate has already applied the offset. */
7677 inst.operands[i].reg = val;
7678 inst.operands[i].isreg = 1;
7679 break;
7680
7681 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7682 I32z: po_imm_or_fail (0, 32, FALSE); break;
7683
7684 /* Two kinds of register. */
7685 case OP_RIWR_RIWC:
7686 {
7687 struct reg_entry *rege = arm_reg_parse_multi (&str);
7688 if (!rege
7689 || (rege->type != REG_TYPE_MMXWR
7690 && rege->type != REG_TYPE_MMXWC
7691 && rege->type != REG_TYPE_MMXWCG))
7692 {
7693 inst.error = _("iWMMXt data or control register expected");
7694 goto failure;
7695 }
7696 inst.operands[i].reg = rege->number;
7697 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7698 }
7699 break;
7700
7701 case OP_RIWC_RIWG:
7702 {
7703 struct reg_entry *rege = arm_reg_parse_multi (&str);
7704 if (!rege
7705 || (rege->type != REG_TYPE_MMXWC
7706 && rege->type != REG_TYPE_MMXWCG))
7707 {
7708 inst.error = _("iWMMXt control register expected");
7709 goto failure;
7710 }
7711 inst.operands[i].reg = rege->number;
7712 inst.operands[i].isreg = 1;
7713 }
7714 break;
7715
7716 /* Misc */
7717 case OP_CPSF: val = parse_cps_flags (&str); break;
7718 case OP_ENDI: val = parse_endian_specifier (&str); break;
7719 case OP_oROR: val = parse_ror (&str); break;
7720 try_cond:
7721 case OP_COND: val = parse_cond (&str); break;
7722 case OP_oBARRIER_I15:
7723 po_barrier_or_imm (str); break;
7724 immediate:
7725 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
7726 goto failure;
7727 break;
7728
7729 case OP_wPSR:
7730 case OP_rPSR:
7731 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7732 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7733 {
7734 inst.error = _("Banked registers are not available with this "
7735 "architecture.");
7736 goto failure;
7737 }
7738 break;
7739 try_psr:
7740 val = parse_psr (&str, op_parse_code == OP_wPSR);
7741 break;
7742
7743 case OP_VLDR:
7744 po_reg_or_goto (REG_TYPE_VFSD, try_sysreg);
7745 break;
7746 try_sysreg:
7747 val = parse_sys_vldr_vstr (&str);
7748 break;
7749
7750 case OP_APSR_RR:
7751 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7752 break;
7753 try_apsr:
7754 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7755 instruction). */
7756 if (strncasecmp (str, "APSR_", 5) == 0)
7757 {
7758 unsigned found = 0;
7759 str += 5;
7760 while (found < 15)
7761 switch (*str++)
7762 {
7763 case 'c': found = (found & 1) ? 16 : found | 1; break;
7764 case 'n': found = (found & 2) ? 16 : found | 2; break;
7765 case 'z': found = (found & 4) ? 16 : found | 4; break;
7766 case 'v': found = (found & 8) ? 16 : found | 8; break;
7767 default: found = 16;
7768 }
7769 if (found != 15)
7770 goto failure;
7771 inst.operands[i].isvec = 1;
7772 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7773 inst.operands[i].reg = REG_PC;
7774 }
7775 else
7776 goto failure;
7777 break;
7778
7779 case OP_TB:
7780 po_misc_or_fail (parse_tb (&str));
7781 break;
7782
7783 /* Register lists. */
7784 case OP_REGLST:
7785 val = parse_reg_list (&str, REGLIST_RN);
7786 if (*str == '^')
7787 {
7788 inst.operands[i].writeback = 1;
7789 str++;
7790 }
7791 break;
7792
7793 case OP_CLRMLST:
7794 val = parse_reg_list (&str, REGLIST_CLRM);
7795 break;
7796
7797 case OP_VRSLST:
7798 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S,
7799 &partial_match);
7800 break;
7801
7802 case OP_VRDLST:
7803 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D,
7804 &partial_match);
7805 break;
7806
7807 case OP_VRSDLST:
7808 /* Allow Q registers too. */
7809 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7810 REGLIST_NEON_D, &partial_match);
7811 if (val == FAIL)
7812 {
7813 inst.error = NULL;
7814 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7815 REGLIST_VFP_S, &partial_match);
7816 inst.operands[i].issingle = 1;
7817 }
7818 break;
7819
7820 case OP_VRSDVLST:
7821 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7822 REGLIST_VFP_D_VPR, &partial_match);
7823 if (val == FAIL && !partial_match)
7824 {
7825 inst.error = NULL;
7826 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7827 REGLIST_VFP_S_VPR, &partial_match);
7828 inst.operands[i].issingle = 1;
7829 }
7830 break;
7831
7832 case OP_NRDLST:
7833 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7834 REGLIST_NEON_D, &partial_match);
7835 break;
7836
7837 case OP_MSTRLST4:
7838 case OP_MSTRLST2:
7839 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7840 1, &inst.operands[i].vectype);
7841 if (val != (((op_parse_code == OP_MSTRLST2) ? 3 : 7) << 5 | 0xe))
7842 goto failure;
7843 break;
7844 case OP_NSTRLST:
7845 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7846 0, &inst.operands[i].vectype);
7847 break;
7848
7849 /* Addressing modes */
7850 case OP_ADDRMVE:
7851 po_misc_or_fail (parse_address_group_reloc (&str, i, GROUP_MVE));
7852 break;
7853
7854 case OP_ADDR:
7855 po_misc_or_fail (parse_address (&str, i));
7856 break;
7857
7858 case OP_ADDRGLDR:
7859 po_misc_or_fail_no_backtrack (
7860 parse_address_group_reloc (&str, i, GROUP_LDR));
7861 break;
7862
7863 case OP_ADDRGLDRS:
7864 po_misc_or_fail_no_backtrack (
7865 parse_address_group_reloc (&str, i, GROUP_LDRS));
7866 break;
7867
7868 case OP_ADDRGLDC:
7869 po_misc_or_fail_no_backtrack (
7870 parse_address_group_reloc (&str, i, GROUP_LDC));
7871 break;
7872
7873 case OP_SH:
7874 po_misc_or_fail (parse_shifter_operand (&str, i));
7875 break;
7876
7877 case OP_SHG:
7878 po_misc_or_fail_no_backtrack (
7879 parse_shifter_operand_group_reloc (&str, i));
7880 break;
7881
7882 case OP_oSHll:
7883 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7884 break;
7885
7886 case OP_oSHar:
7887 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7888 break;
7889
7890 case OP_oSHllar:
7891 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7892 break;
7893
7894 case OP_RMQRZ:
7895 case OP_oRMQRZ:
7896 po_reg_or_goto (REG_TYPE_MQ, try_rr_zr);
7897 break;
7898
7899 case OP_RR_ZR:
7900 try_rr_zr:
7901 po_reg_or_goto (REG_TYPE_RN, ZR);
7902 break;
7903 ZR:
7904 po_reg_or_fail (REG_TYPE_ZR);
7905 break;
7906
7907 default:
7908 as_fatal (_("unhandled operand code %d"), op_parse_code);
7909 }
7910
7911 /* Various value-based sanity checks and shared operations. We
7912 do not signal immediate failures for the register constraints;
7913 this allows a syntax error to take precedence. */
7914 switch (op_parse_code)
7915 {
7916 case OP_oRRnpc:
7917 case OP_RRnpc:
7918 case OP_RRnpcb:
7919 case OP_RRw:
7920 case OP_oRRw:
7921 case OP_RRnpc_I0:
7922 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7923 inst.error = BAD_PC;
7924 break;
7925
7926 case OP_oRRnpcsp:
7927 case OP_RRnpcsp:
7928 case OP_RRnpcsp_I32:
7929 if (inst.operands[i].isreg)
7930 {
7931 if (inst.operands[i].reg == REG_PC)
7932 inst.error = BAD_PC;
7933 else if (inst.operands[i].reg == REG_SP
7934 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7935 relaxed since ARMv8-A. */
7936 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7937 {
7938 gas_assert (thumb);
7939 inst.error = BAD_SP;
7940 }
7941 }
7942 break;
7943
7944 case OP_RRnpctw:
7945 if (inst.operands[i].isreg
7946 && inst.operands[i].reg == REG_PC
7947 && (inst.operands[i].writeback || thumb))
7948 inst.error = BAD_PC;
7949 break;
7950
7951 case OP_RVSD_COND:
7952 case OP_VLDR:
7953 if (inst.operands[i].isreg)
7954 break;
7955 /* fall through. */
7956
7957 case OP_CPSF:
7958 case OP_ENDI:
7959 case OP_oROR:
7960 case OP_wPSR:
7961 case OP_rPSR:
7962 case OP_COND:
7963 case OP_oBARRIER_I15:
7964 case OP_REGLST:
7965 case OP_CLRMLST:
7966 case OP_VRSLST:
7967 case OP_VRDLST:
7968 case OP_VRSDLST:
7969 case OP_VRSDVLST:
7970 case OP_NRDLST:
7971 case OP_NSTRLST:
7972 case OP_MSTRLST2:
7973 case OP_MSTRLST4:
7974 if (val == FAIL)
7975 goto failure;
7976 inst.operands[i].imm = val;
7977 break;
7978
7979 case OP_LR:
7980 case OP_oLR:
7981 if (inst.operands[i].reg != REG_LR)
7982 inst.error = _("operand must be LR register");
7983 break;
7984
7985 case OP_RMQRZ:
7986 case OP_oRMQRZ:
7987 case OP_RR_ZR:
7988 if (!inst.operands[i].iszr && inst.operands[i].reg == REG_PC)
7989 inst.error = BAD_PC;
7990 break;
7991
7992 case OP_RRe:
7993 if (inst.operands[i].isreg
7994 && (inst.operands[i].reg & 0x00000001) != 0)
7995 inst.error = BAD_ODD;
7996 break;
7997
7998 case OP_RRo:
7999 if (inst.operands[i].isreg)
8000 {
8001 if ((inst.operands[i].reg & 0x00000001) != 1)
8002 inst.error = BAD_EVEN;
8003 else if (inst.operands[i].reg == REG_SP)
8004 as_tsktsk (MVE_BAD_SP);
8005 else if (inst.operands[i].reg == REG_PC)
8006 inst.error = BAD_PC;
8007 }
8008 break;
8009
8010 default:
8011 break;
8012 }
8013
8014 /* If we get here, this operand was successfully parsed. */
8015 inst.operands[i].present = 1;
8016 continue;
8017
8018 bad_args:
8019 inst.error = BAD_ARGS;
8020
8021 failure:
8022 if (!backtrack_pos)
8023 {
8024 /* The parse routine should already have set inst.error, but set a
8025 default here just in case. */
8026 if (!inst.error)
8027 inst.error = BAD_SYNTAX;
8028 return FAIL;
8029 }
8030
8031 /* Do not backtrack over a trailing optional argument that
8032 absorbed some text. We will only fail again, with the
8033 'garbage following instruction' error message, which is
8034 probably less helpful than the current one. */
8035 if (backtrack_index == i && backtrack_pos != str
8036 && upat[i+1] == OP_stop)
8037 {
8038 if (!inst.error)
8039 inst.error = BAD_SYNTAX;
8040 return FAIL;
8041 }
8042
8043 /* Try again, skipping the optional argument at backtrack_pos. */
8044 str = backtrack_pos;
8045 inst.error = backtrack_error;
8046 inst.operands[backtrack_index].present = 0;
8047 i = backtrack_index;
8048 backtrack_pos = 0;
8049 }
8050
8051 /* Check that we have parsed all the arguments. */
8052 if (*str != '\0' && !inst.error)
8053 inst.error = _("garbage following instruction");
8054
8055 return inst.error ? FAIL : SUCCESS;
8056 }
8057
8058 #undef po_char_or_fail
8059 #undef po_reg_or_fail
8060 #undef po_reg_or_goto
8061 #undef po_imm_or_fail
8062 #undef po_scalar_or_fail
8063 #undef po_barrier_or_imm
8064
8065 /* Shorthand macro for instruction encoding functions issuing errors. */
8066 #define constraint(expr, err) \
8067 do \
8068 { \
8069 if (expr) \
8070 { \
8071 inst.error = err; \
8072 return; \
8073 } \
8074 } \
8075 while (0)
8076
8077 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
8078 instructions are unpredictable if these registers are used. This
8079 is the BadReg predicate in ARM's Thumb-2 documentation.
8080
8081 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
8082 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
8083 #define reject_bad_reg(reg) \
8084 do \
8085 if (reg == REG_PC) \
8086 { \
8087 inst.error = BAD_PC; \
8088 return; \
8089 } \
8090 else if (reg == REG_SP \
8091 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
8092 { \
8093 inst.error = BAD_SP; \
8094 return; \
8095 } \
8096 while (0)
8097
8098 /* If REG is R13 (the stack pointer), warn that its use is
8099 deprecated. */
8100 #define warn_deprecated_sp(reg) \
8101 do \
8102 if (warn_on_deprecated && reg == REG_SP) \
8103 as_tsktsk (_("use of r13 is deprecated")); \
8104 while (0)
8105
8106 /* Functions for operand encoding. ARM, then Thumb. */
8107
8108 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
8109
8110 /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
8111
8112 The only binary encoding difference is the Coprocessor number. Coprocessor
8113 9 is used for half-precision calculations or conversions. The format of the
8114 instruction is the same as the equivalent Coprocessor 10 instruction that
8115 exists for Single-Precision operation. */
8116
8117 static void
8118 do_scalar_fp16_v82_encode (void)
8119 {
8120 if (inst.cond < COND_ALWAYS)
8121 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
8122 " the behaviour is UNPREDICTABLE"));
8123 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
8124 _(BAD_FP16));
8125
8126 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
8127 mark_feature_used (&arm_ext_fp16);
8128 }
8129
8130 /* If VAL can be encoded in the immediate field of an ARM instruction,
8131 return the encoded form. Otherwise, return FAIL. */
8132
8133 static unsigned int
8134 encode_arm_immediate (unsigned int val)
8135 {
8136 unsigned int a, i;
8137
8138 if (val <= 0xff)
8139 return val;
8140
8141 for (i = 2; i < 32; i += 2)
8142 if ((a = rotate_left (val, i)) <= 0xff)
8143 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
8144
8145 return FAIL;
8146 }
8147
8148 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
8149 return the encoded form. Otherwise, return FAIL. */
8150 static unsigned int
8151 encode_thumb32_immediate (unsigned int val)
8152 {
8153 unsigned int a, i;
8154
8155 if (val <= 0xff)
8156 return val;
8157
8158 for (i = 1; i <= 24; i++)
8159 {
8160 a = val >> i;
8161 if ((val & ~(0xff << i)) == 0)
8162 return ((val >> i) & 0x7f) | ((32 - i) << 7);
8163 }
8164
8165 a = val & 0xff;
8166 if (val == ((a << 16) | a))
8167 return 0x100 | a;
8168 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
8169 return 0x300 | a;
8170
8171 a = val & 0xff00;
8172 if (val == ((a << 16) | a))
8173 return 0x200 | (a >> 8);
8174
8175 return FAIL;
8176 }
8177 /* Encode a VFP SP or DP register number into inst.instruction. */
8178
8179 static void
8180 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
8181 {
8182 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
8183 && reg > 15)
8184 {
8185 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
8186 {
8187 if (thumb_mode)
8188 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
8189 fpu_vfp_ext_d32);
8190 else
8191 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
8192 fpu_vfp_ext_d32);
8193 }
8194 else
8195 {
8196 first_error (_("D register out of range for selected VFP version"));
8197 return;
8198 }
8199 }
8200
8201 switch (pos)
8202 {
8203 case VFP_REG_Sd:
8204 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
8205 break;
8206
8207 case VFP_REG_Sn:
8208 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
8209 break;
8210
8211 case VFP_REG_Sm:
8212 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
8213 break;
8214
8215 case VFP_REG_Dd:
8216 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
8217 break;
8218
8219 case VFP_REG_Dn:
8220 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
8221 break;
8222
8223 case VFP_REG_Dm:
8224 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
8225 break;
8226
8227 default:
8228 abort ();
8229 }
8230 }
8231
8232 /* Encode a <shift> in an ARM-format instruction. The immediate,
8233 if any, is handled by md_apply_fix. */
8234 static void
8235 encode_arm_shift (int i)
8236 {
8237 /* register-shifted register. */
8238 if (inst.operands[i].immisreg)
8239 {
8240 int op_index;
8241 for (op_index = 0; op_index <= i; ++op_index)
8242 {
8243 /* Check the operand only when it's presented. In pre-UAL syntax,
8244 if the destination register is the same as the first operand, two
8245 register form of the instruction can be used. */
8246 if (inst.operands[op_index].present && inst.operands[op_index].isreg
8247 && inst.operands[op_index].reg == REG_PC)
8248 as_warn (UNPRED_REG ("r15"));
8249 }
8250
8251 if (inst.operands[i].imm == REG_PC)
8252 as_warn (UNPRED_REG ("r15"));
8253 }
8254
8255 if (inst.operands[i].shift_kind == SHIFT_RRX)
8256 inst.instruction |= SHIFT_ROR << 5;
8257 else
8258 {
8259 inst.instruction |= inst.operands[i].shift_kind << 5;
8260 if (inst.operands[i].immisreg)
8261 {
8262 inst.instruction |= SHIFT_BY_REG;
8263 inst.instruction |= inst.operands[i].imm << 8;
8264 }
8265 else
8266 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8267 }
8268 }
8269
8270 static void
8271 encode_arm_shifter_operand (int i)
8272 {
8273 if (inst.operands[i].isreg)
8274 {
8275 inst.instruction |= inst.operands[i].reg;
8276 encode_arm_shift (i);
8277 }
8278 else
8279 {
8280 inst.instruction |= INST_IMMEDIATE;
8281 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
8282 inst.instruction |= inst.operands[i].imm;
8283 }
8284 }
8285
8286 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
8287 static void
8288 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
8289 {
8290 /* PR 14260:
8291 Generate an error if the operand is not a register. */
8292 constraint (!inst.operands[i].isreg,
8293 _("Instruction does not support =N addresses"));
8294
8295 inst.instruction |= inst.operands[i].reg << 16;
8296
8297 if (inst.operands[i].preind)
8298 {
8299 if (is_t)
8300 {
8301 inst.error = _("instruction does not accept preindexed addressing");
8302 return;
8303 }
8304 inst.instruction |= PRE_INDEX;
8305 if (inst.operands[i].writeback)
8306 inst.instruction |= WRITE_BACK;
8307
8308 }
8309 else if (inst.operands[i].postind)
8310 {
8311 gas_assert (inst.operands[i].writeback);
8312 if (is_t)
8313 inst.instruction |= WRITE_BACK;
8314 }
8315 else /* unindexed - only for coprocessor */
8316 {
8317 inst.error = _("instruction does not accept unindexed addressing");
8318 return;
8319 }
8320
8321 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
8322 && (((inst.instruction & 0x000f0000) >> 16)
8323 == ((inst.instruction & 0x0000f000) >> 12)))
8324 as_warn ((inst.instruction & LOAD_BIT)
8325 ? _("destination register same as write-back base")
8326 : _("source register same as write-back base"));
8327 }
8328
8329 /* inst.operands[i] was set up by parse_address. Encode it into an
8330 ARM-format mode 2 load or store instruction. If is_t is true,
8331 reject forms that cannot be used with a T instruction (i.e. not
8332 post-indexed). */
8333 static void
8334 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
8335 {
8336 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8337
8338 encode_arm_addr_mode_common (i, is_t);
8339
8340 if (inst.operands[i].immisreg)
8341 {
8342 constraint ((inst.operands[i].imm == REG_PC
8343 || (is_pc && inst.operands[i].writeback)),
8344 BAD_PC_ADDRESSING);
8345 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
8346 inst.instruction |= inst.operands[i].imm;
8347 if (!inst.operands[i].negative)
8348 inst.instruction |= INDEX_UP;
8349 if (inst.operands[i].shifted)
8350 {
8351 if (inst.operands[i].shift_kind == SHIFT_RRX)
8352 inst.instruction |= SHIFT_ROR << 5;
8353 else
8354 {
8355 inst.instruction |= inst.operands[i].shift_kind << 5;
8356 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
8357 }
8358 }
8359 }
8360 else /* immediate offset in inst.relocs[0] */
8361 {
8362 if (is_pc && !inst.relocs[0].pc_rel)
8363 {
8364 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
8365
8366 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
8367 cannot use PC in addressing.
8368 PC cannot be used in writeback addressing, either. */
8369 constraint ((is_t || inst.operands[i].writeback),
8370 BAD_PC_ADDRESSING);
8371
8372 /* Use of PC in str is deprecated for ARMv7. */
8373 if (warn_on_deprecated
8374 && !is_load
8375 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
8376 as_tsktsk (_("use of PC in this instruction is deprecated"));
8377 }
8378
8379 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8380 {
8381 /* Prefer + for zero encoded value. */
8382 if (!inst.operands[i].negative)
8383 inst.instruction |= INDEX_UP;
8384 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
8385 }
8386 }
8387 }
8388
8389 /* inst.operands[i] was set up by parse_address. Encode it into an
8390 ARM-format mode 3 load or store instruction. Reject forms that
8391 cannot be used with such instructions. If is_t is true, reject
8392 forms that cannot be used with a T instruction (i.e. not
8393 post-indexed). */
8394 static void
8395 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
8396 {
8397 if (inst.operands[i].immisreg && inst.operands[i].shifted)
8398 {
8399 inst.error = _("instruction does not accept scaled register index");
8400 return;
8401 }
8402
8403 encode_arm_addr_mode_common (i, is_t);
8404
8405 if (inst.operands[i].immisreg)
8406 {
8407 constraint ((inst.operands[i].imm == REG_PC
8408 || (is_t && inst.operands[i].reg == REG_PC)),
8409 BAD_PC_ADDRESSING);
8410 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
8411 BAD_PC_WRITEBACK);
8412 inst.instruction |= inst.operands[i].imm;
8413 if (!inst.operands[i].negative)
8414 inst.instruction |= INDEX_UP;
8415 }
8416 else /* immediate offset in inst.relocs[0] */
8417 {
8418 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
8419 && inst.operands[i].writeback),
8420 BAD_PC_WRITEBACK);
8421 inst.instruction |= HWOFFSET_IMM;
8422 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
8423 {
8424 /* Prefer + for zero encoded value. */
8425 if (!inst.operands[i].negative)
8426 inst.instruction |= INDEX_UP;
8427
8428 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
8429 }
8430 }
8431 }
8432
8433 /* Write immediate bits [7:0] to the following locations:
8434
8435 |28/24|23 19|18 16|15 4|3 0|
8436 | 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|
8437
8438 This function is used by VMOV/VMVN/VORR/VBIC. */
8439
8440 static void
8441 neon_write_immbits (unsigned immbits)
8442 {
8443 inst.instruction |= immbits & 0xf;
8444 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
8445 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
8446 }
8447
8448 /* Invert low-order SIZE bits of XHI:XLO. */
8449
8450 static void
8451 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
8452 {
8453 unsigned immlo = xlo ? *xlo : 0;
8454 unsigned immhi = xhi ? *xhi : 0;
8455
8456 switch (size)
8457 {
8458 case 8:
8459 immlo = (~immlo) & 0xff;
8460 break;
8461
8462 case 16:
8463 immlo = (~immlo) & 0xffff;
8464 break;
8465
8466 case 64:
8467 immhi = (~immhi) & 0xffffffff;
8468 /* fall through. */
8469
8470 case 32:
8471 immlo = (~immlo) & 0xffffffff;
8472 break;
8473
8474 default:
8475 abort ();
8476 }
8477
8478 if (xlo)
8479 *xlo = immlo;
8480
8481 if (xhi)
8482 *xhi = immhi;
8483 }
8484
8485 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
8486 A, B, C, D. */
8487
8488 static int
8489 neon_bits_same_in_bytes (unsigned imm)
8490 {
8491 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
8492 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
8493 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
8494 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
8495 }
8496
8497 /* For immediate of above form, return 0bABCD. */
8498
8499 static unsigned
8500 neon_squash_bits (unsigned imm)
8501 {
8502 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
8503 | ((imm & 0x01000000) >> 21);
8504 }
8505
8506 /* Compress quarter-float representation to 0b...000 abcdefgh. */
8507
8508 static unsigned
8509 neon_qfloat_bits (unsigned imm)
8510 {
8511 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
8512 }
8513
8514 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
8515 the instruction. *OP is passed as the initial value of the op field, and
8516 may be set to a different value depending on the constant (i.e.
8517 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
8518 MVN). If the immediate looks like a repeated pattern then also
8519 try smaller element sizes. */
8520
8521 static int
8522 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
8523 unsigned *immbits, int *op, int size,
8524 enum neon_el_type type)
8525 {
8526 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
8527 float. */
8528 if (type == NT_float && !float_p)
8529 return FAIL;
8530
8531 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
8532 {
8533 if (size != 32 || *op == 1)
8534 return FAIL;
8535 *immbits = neon_qfloat_bits (immlo);
8536 return 0xf;
8537 }
8538
8539 if (size == 64)
8540 {
8541 if (neon_bits_same_in_bytes (immhi)
8542 && neon_bits_same_in_bytes (immlo))
8543 {
8544 if (*op == 1)
8545 return FAIL;
8546 *immbits = (neon_squash_bits (immhi) << 4)
8547 | neon_squash_bits (immlo);
8548 *op = 1;
8549 return 0xe;
8550 }
8551
8552 if (immhi != immlo)
8553 return FAIL;
8554 }
8555
8556 if (size >= 32)
8557 {
8558 if (immlo == (immlo & 0x000000ff))
8559 {
8560 *immbits = immlo;
8561 return 0x0;
8562 }
8563 else if (immlo == (immlo & 0x0000ff00))
8564 {
8565 *immbits = immlo >> 8;
8566 return 0x2;
8567 }
8568 else if (immlo == (immlo & 0x00ff0000))
8569 {
8570 *immbits = immlo >> 16;
8571 return 0x4;
8572 }
8573 else if (immlo == (immlo & 0xff000000))
8574 {
8575 *immbits = immlo >> 24;
8576 return 0x6;
8577 }
8578 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
8579 {
8580 *immbits = (immlo >> 8) & 0xff;
8581 return 0xc;
8582 }
8583 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
8584 {
8585 *immbits = (immlo >> 16) & 0xff;
8586 return 0xd;
8587 }
8588
8589 if ((immlo & 0xffff) != (immlo >> 16))
8590 return FAIL;
8591 immlo &= 0xffff;
8592 }
8593
8594 if (size >= 16)
8595 {
8596 if (immlo == (immlo & 0x000000ff))
8597 {
8598 *immbits = immlo;
8599 return 0x8;
8600 }
8601 else if (immlo == (immlo & 0x0000ff00))
8602 {
8603 *immbits = immlo >> 8;
8604 return 0xa;
8605 }
8606
8607 if ((immlo & 0xff) != (immlo >> 8))
8608 return FAIL;
8609 immlo &= 0xff;
8610 }
8611
8612 if (immlo == (immlo & 0x000000ff))
8613 {
8614 /* Don't allow MVN with 8-bit immediate. */
8615 if (*op == 1)
8616 return FAIL;
8617 *immbits = immlo;
8618 return 0xe;
8619 }
8620
8621 return FAIL;
8622 }
8623
8624 #if defined BFD_HOST_64_BIT
8625 /* Returns TRUE if double precision value V may be cast
8626 to single precision without loss of accuracy. */
8627
8628 static bfd_boolean
8629 is_double_a_single (bfd_int64_t v)
8630 {
8631 int exp = (int)((v >> 52) & 0x7FF);
8632 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
8633
8634 return (exp == 0 || exp == 0x7FF
8635 || (exp >= 1023 - 126 && exp <= 1023 + 127))
8636 && (mantissa & 0x1FFFFFFFl) == 0;
8637 }
8638
8639 /* Returns a double precision value casted to single precision
8640 (ignoring the least significant bits in exponent and mantissa). */
8641
8642 static int
8643 double_to_single (bfd_int64_t v)
8644 {
8645 int sign = (int) ((v >> 63) & 1l);
8646 int exp = (int) ((v >> 52) & 0x7FF);
8647 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
8648
8649 if (exp == 0x7FF)
8650 exp = 0xFF;
8651 else
8652 {
8653 exp = exp - 1023 + 127;
8654 if (exp >= 0xFF)
8655 {
8656 /* Infinity. */
8657 exp = 0x7F;
8658 mantissa = 0;
8659 }
8660 else if (exp < 0)
8661 {
8662 /* No denormalized numbers. */
8663 exp = 0;
8664 mantissa = 0;
8665 }
8666 }
8667 mantissa >>= 29;
8668 return (sign << 31) | (exp << 23) | mantissa;
8669 }
8670 #endif /* BFD_HOST_64_BIT */
8671
8672 enum lit_type
8673 {
8674 CONST_THUMB,
8675 CONST_ARM,
8676 CONST_VEC
8677 };
8678
8679 static void do_vfp_nsyn_opcode (const char *);
8680
8681 /* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
8682 Determine whether it can be performed with a move instruction; if
8683 it can, convert inst.instruction to that move instruction and
8684 return TRUE; if it can't, convert inst.instruction to a literal-pool
8685 load and return FALSE. If this is not a valid thing to do in the
8686 current context, set inst.error and return TRUE.
8687
8688 inst.operands[i] describes the destination register. */
8689
8690 static bfd_boolean
8691 move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
8692 {
8693 unsigned long tbit;
8694 bfd_boolean thumb_p = (t == CONST_THUMB);
8695 bfd_boolean arm_p = (t == CONST_ARM);
8696
8697 if (thumb_p)
8698 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
8699 else
8700 tbit = LOAD_BIT;
8701
8702 if ((inst.instruction & tbit) == 0)
8703 {
8704 inst.error = _("invalid pseudo operation");
8705 return TRUE;
8706 }
8707
8708 if (inst.relocs[0].exp.X_op != O_constant
8709 && inst.relocs[0].exp.X_op != O_symbol
8710 && inst.relocs[0].exp.X_op != O_big)
8711 {
8712 inst.error = _("constant expression expected");
8713 return TRUE;
8714 }
8715
8716 if (inst.relocs[0].exp.X_op == O_constant
8717 || inst.relocs[0].exp.X_op == O_big)
8718 {
8719 #if defined BFD_HOST_64_BIT
8720 bfd_int64_t v;
8721 #else
8722 offsetT v;
8723 #endif
8724 if (inst.relocs[0].exp.X_op == O_big)
8725 {
8726 LITTLENUM_TYPE w[X_PRECISION];
8727 LITTLENUM_TYPE * l;
8728
8729 if (inst.relocs[0].exp.X_add_number == -1)
8730 {
8731 gen_to_words (w, X_PRECISION, E_PRECISION);
8732 l = w;
8733 /* FIXME: Should we check words w[2..5] ? */
8734 }
8735 else
8736 l = generic_bignum;
8737
8738 #if defined BFD_HOST_64_BIT
8739 v =
8740 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8741 << LITTLENUM_NUMBER_OF_BITS)
8742 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8743 << LITTLENUM_NUMBER_OF_BITS)
8744 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8745 << LITTLENUM_NUMBER_OF_BITS)
8746 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8747 #else
8748 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8749 | (l[0] & LITTLENUM_MASK);
8750 #endif
8751 }
8752 else
8753 v = inst.relocs[0].exp.X_add_number;
8754
8755 if (!inst.operands[i].issingle)
8756 {
8757 if (thumb_p)
8758 {
8759 /* LDR should not use lead in a flag-setting instruction being
8760 chosen so we do not check whether movs can be used. */
8761
8762 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
8763 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8764 && inst.operands[i].reg != 13
8765 && inst.operands[i].reg != 15)
8766 {
8767 /* Check if on thumb2 it can be done with a mov.w, mvn or
8768 movw instruction. */
8769 unsigned int newimm;
8770 bfd_boolean isNegated;
8771
8772 newimm = encode_thumb32_immediate (v);
8773 if (newimm != (unsigned int) FAIL)
8774 isNegated = FALSE;
8775 else
8776 {
8777 newimm = encode_thumb32_immediate (~v);
8778 if (newimm != (unsigned int) FAIL)
8779 isNegated = TRUE;
8780 }
8781
8782 /* The number can be loaded with a mov.w or mvn
8783 instruction. */
8784 if (newimm != (unsigned int) FAIL
8785 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
8786 {
8787 inst.instruction = (0xf04f0000 /* MOV.W. */
8788 | (inst.operands[i].reg << 8));
8789 /* Change to MOVN. */
8790 inst.instruction |= (isNegated ? 0x200000 : 0);
8791 inst.instruction |= (newimm & 0x800) << 15;
8792 inst.instruction |= (newimm & 0x700) << 4;
8793 inst.instruction |= (newimm & 0x0ff);
8794 return TRUE;
8795 }
8796 /* The number can be loaded with a movw instruction. */
8797 else if ((v & ~0xFFFF) == 0
8798 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8799 {
8800 int imm = v & 0xFFFF;
8801
8802 inst.instruction = 0xf2400000; /* MOVW. */
8803 inst.instruction |= (inst.operands[i].reg << 8);
8804 inst.instruction |= (imm & 0xf000) << 4;
8805 inst.instruction |= (imm & 0x0800) << 15;
8806 inst.instruction |= (imm & 0x0700) << 4;
8807 inst.instruction |= (imm & 0x00ff);
8808 /* In case this replacement is being done on Armv8-M
8809 Baseline we need to make sure to disable the
8810 instruction size check, as otherwise GAS will reject
8811 the use of this T32 instruction. */
8812 inst.size_req = 0;
8813 return TRUE;
8814 }
8815 }
8816 }
8817 else if (arm_p)
8818 {
8819 int value = encode_arm_immediate (v);
8820
8821 if (value != FAIL)
8822 {
8823 /* This can be done with a mov instruction. */
8824 inst.instruction &= LITERAL_MASK;
8825 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8826 inst.instruction |= value & 0xfff;
8827 return TRUE;
8828 }
8829
8830 value = encode_arm_immediate (~ v);
8831 if (value != FAIL)
8832 {
8833 /* This can be done with a mvn instruction. */
8834 inst.instruction &= LITERAL_MASK;
8835 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8836 inst.instruction |= value & 0xfff;
8837 return TRUE;
8838 }
8839 }
8840 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8841 {
8842 int op = 0;
8843 unsigned immbits = 0;
8844 unsigned immlo = inst.operands[1].imm;
8845 unsigned immhi = inst.operands[1].regisimm
8846 ? inst.operands[1].reg
8847 : inst.relocs[0].exp.X_unsigned
8848 ? 0
8849 : ((bfd_int64_t)((int) immlo)) >> 32;
8850 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8851 &op, 64, NT_invtype);
8852
8853 if (cmode == FAIL)
8854 {
8855 neon_invert_size (&immlo, &immhi, 64);
8856 op = !op;
8857 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8858 &op, 64, NT_invtype);
8859 }
8860
8861 if (cmode != FAIL)
8862 {
8863 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8864 | (1 << 23)
8865 | (cmode << 8)
8866 | (op << 5)
8867 | (1 << 4);
8868
8869 /* Fill other bits in vmov encoding for both thumb and arm. */
8870 if (thumb_mode)
8871 inst.instruction |= (0x7U << 29) | (0xF << 24);
8872 else
8873 inst.instruction |= (0xFU << 28) | (0x1 << 25);
8874 neon_write_immbits (immbits);
8875 return TRUE;
8876 }
8877 }
8878 }
8879
8880 if (t == CONST_VEC)
8881 {
8882 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8883 if (inst.operands[i].issingle
8884 && is_quarter_float (inst.operands[1].imm)
8885 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8886 {
8887 inst.operands[1].imm =
8888 neon_qfloat_bits (v);
8889 do_vfp_nsyn_opcode ("fconsts");
8890 return TRUE;
8891 }
8892
8893 /* If our host does not support a 64-bit type then we cannot perform
8894 the following optimization. This mean that there will be a
8895 discrepancy between the output produced by an assembler built for
8896 a 32-bit-only host and the output produced from a 64-bit host, but
8897 this cannot be helped. */
8898 #if defined BFD_HOST_64_BIT
8899 else if (!inst.operands[1].issingle
8900 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8901 {
8902 if (is_double_a_single (v)
8903 && is_quarter_float (double_to_single (v)))
8904 {
8905 inst.operands[1].imm =
8906 neon_qfloat_bits (double_to_single (v));
8907 do_vfp_nsyn_opcode ("fconstd");
8908 return TRUE;
8909 }
8910 }
8911 #endif
8912 }
8913 }
8914
8915 if (add_to_lit_pool ((!inst.operands[i].isvec
8916 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8917 return TRUE;
8918
8919 inst.operands[1].reg = REG_PC;
8920 inst.operands[1].isreg = 1;
8921 inst.operands[1].preind = 1;
8922 inst.relocs[0].pc_rel = 1;
8923 inst.relocs[0].type = (thumb_p
8924 ? BFD_RELOC_ARM_THUMB_OFFSET
8925 : (mode_3
8926 ? BFD_RELOC_ARM_HWLITERAL
8927 : BFD_RELOC_ARM_LITERAL));
8928 return FALSE;
8929 }
8930
8931 /* inst.operands[i] was set up by parse_address. Encode it into an
8932 ARM-format instruction. Reject all forms which cannot be encoded
8933 into a coprocessor load/store instruction. If wb_ok is false,
8934 reject use of writeback; if unind_ok is false, reject use of
8935 unindexed addressing. If reloc_override is not 0, use it instead
8936 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8937 (in which case it is preserved). */
8938
8939 static int
8940 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8941 {
8942 if (!inst.operands[i].isreg)
8943 {
8944 /* PR 18256 */
8945 if (! inst.operands[0].isvec)
8946 {
8947 inst.error = _("invalid co-processor operand");
8948 return FAIL;
8949 }
8950 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8951 return SUCCESS;
8952 }
8953
8954 inst.instruction |= inst.operands[i].reg << 16;
8955
8956 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8957
8958 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8959 {
8960 gas_assert (!inst.operands[i].writeback);
8961 if (!unind_ok)
8962 {
8963 inst.error = _("instruction does not support unindexed addressing");
8964 return FAIL;
8965 }
8966 inst.instruction |= inst.operands[i].imm;
8967 inst.instruction |= INDEX_UP;
8968 return SUCCESS;
8969 }
8970
8971 if (inst.operands[i].preind)
8972 inst.instruction |= PRE_INDEX;
8973
8974 if (inst.operands[i].writeback)
8975 {
8976 if (inst.operands[i].reg == REG_PC)
8977 {
8978 inst.error = _("pc may not be used with write-back");
8979 return FAIL;
8980 }
8981 if (!wb_ok)
8982 {
8983 inst.error = _("instruction does not support writeback");
8984 return FAIL;
8985 }
8986 inst.instruction |= WRITE_BACK;
8987 }
8988
8989 if (reloc_override)
8990 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
8991 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
8992 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
8993 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
8994 {
8995 if (thumb_mode)
8996 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8997 else
8998 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
8999 }
9000
9001 /* Prefer + for zero encoded value. */
9002 if (!inst.operands[i].negative)
9003 inst.instruction |= INDEX_UP;
9004
9005 return SUCCESS;
9006 }
9007
9008 /* Functions for instruction encoding, sorted by sub-architecture.
9009 First some generics; their names are taken from the conventional
9010 bit positions for register arguments in ARM format instructions. */
9011
9012 static void
9013 do_noargs (void)
9014 {
9015 }
9016
9017 static void
9018 do_rd (void)
9019 {
9020 inst.instruction |= inst.operands[0].reg << 12;
9021 }
9022
9023 static void
9024 do_rn (void)
9025 {
9026 inst.instruction |= inst.operands[0].reg << 16;
9027 }
9028
9029 static void
9030 do_rd_rm (void)
9031 {
9032 inst.instruction |= inst.operands[0].reg << 12;
9033 inst.instruction |= inst.operands[1].reg;
9034 }
9035
9036 static void
9037 do_rm_rn (void)
9038 {
9039 inst.instruction |= inst.operands[0].reg;
9040 inst.instruction |= inst.operands[1].reg << 16;
9041 }
9042
9043 static void
9044 do_rd_rn (void)
9045 {
9046 inst.instruction |= inst.operands[0].reg << 12;
9047 inst.instruction |= inst.operands[1].reg << 16;
9048 }
9049
9050 static void
9051 do_rn_rd (void)
9052 {
9053 inst.instruction |= inst.operands[0].reg << 16;
9054 inst.instruction |= inst.operands[1].reg << 12;
9055 }
9056
9057 static void
9058 do_tt (void)
9059 {
9060 inst.instruction |= inst.operands[0].reg << 8;
9061 inst.instruction |= inst.operands[1].reg << 16;
9062 }
9063
9064 static bfd_boolean
9065 check_obsolete (const arm_feature_set *feature, const char *msg)
9066 {
9067 if (ARM_CPU_IS_ANY (cpu_variant))
9068 {
9069 as_tsktsk ("%s", msg);
9070 return TRUE;
9071 }
9072 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
9073 {
9074 as_bad ("%s", msg);
9075 return TRUE;
9076 }
9077
9078 return FALSE;
9079 }
9080
9081 static void
9082 do_rd_rm_rn (void)
9083 {
9084 unsigned Rn = inst.operands[2].reg;
9085 /* Enforce restrictions on SWP instruction. */
9086 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
9087 {
9088 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
9089 _("Rn must not overlap other operands"));
9090
9091 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
9092 */
9093 if (!check_obsolete (&arm_ext_v8,
9094 _("swp{b} use is obsoleted for ARMv8 and later"))
9095 && warn_on_deprecated
9096 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
9097 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
9098 }
9099
9100 inst.instruction |= inst.operands[0].reg << 12;
9101 inst.instruction |= inst.operands[1].reg;
9102 inst.instruction |= Rn << 16;
9103 }
9104
9105 static void
9106 do_rd_rn_rm (void)
9107 {
9108 inst.instruction |= inst.operands[0].reg << 12;
9109 inst.instruction |= inst.operands[1].reg << 16;
9110 inst.instruction |= inst.operands[2].reg;
9111 }
9112
9113 static void
9114 do_rm_rd_rn (void)
9115 {
9116 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
9117 constraint (((inst.relocs[0].exp.X_op != O_constant
9118 && inst.relocs[0].exp.X_op != O_illegal)
9119 || inst.relocs[0].exp.X_add_number != 0),
9120 BAD_ADDR_MODE);
9121 inst.instruction |= inst.operands[0].reg;
9122 inst.instruction |= inst.operands[1].reg << 12;
9123 inst.instruction |= inst.operands[2].reg << 16;
9124 }
9125
9126 static void
9127 do_imm0 (void)
9128 {
9129 inst.instruction |= inst.operands[0].imm;
9130 }
9131
9132 static void
9133 do_rd_cpaddr (void)
9134 {
9135 inst.instruction |= inst.operands[0].reg << 12;
9136 encode_arm_cp_address (1, TRUE, TRUE, 0);
9137 }
9138
9139 /* ARM instructions, in alphabetical order by function name (except
9140 that wrapper functions appear immediately after the function they
9141 wrap). */
9142
9143 /* This is a pseudo-op of the form "adr rd, label" to be converted
9144 into a relative address of the form "add rd, pc, #label-.-8". */
9145
9146 static void
9147 do_adr (void)
9148 {
9149 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9150
9151 /* Frag hacking will turn this into a sub instruction if the offset turns
9152 out to be negative. */
9153 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9154 inst.relocs[0].pc_rel = 1;
9155 inst.relocs[0].exp.X_add_number -= 8;
9156
9157 if (support_interwork
9158 && inst.relocs[0].exp.X_op == O_symbol
9159 && inst.relocs[0].exp.X_add_symbol != NULL
9160 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9161 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9162 inst.relocs[0].exp.X_add_number |= 1;
9163 }
9164
9165 /* This is a pseudo-op of the form "adrl rd, label" to be converted
9166 into a relative address of the form:
9167 add rd, pc, #low(label-.-8)"
9168 add rd, rd, #high(label-.-8)" */
9169
9170 static void
9171 do_adrl (void)
9172 {
9173 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
9174
9175 /* Frag hacking will turn this into a sub instruction if the offset turns
9176 out to be negative. */
9177 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
9178 inst.relocs[0].pc_rel = 1;
9179 inst.size = INSN_SIZE * 2;
9180 inst.relocs[0].exp.X_add_number -= 8;
9181
9182 if (support_interwork
9183 && inst.relocs[0].exp.X_op == O_symbol
9184 && inst.relocs[0].exp.X_add_symbol != NULL
9185 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
9186 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
9187 inst.relocs[0].exp.X_add_number |= 1;
9188 }
9189
9190 static void
9191 do_arit (void)
9192 {
9193 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9194 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9195 THUMB1_RELOC_ONLY);
9196 if (!inst.operands[1].present)
9197 inst.operands[1].reg = inst.operands[0].reg;
9198 inst.instruction |= inst.operands[0].reg << 12;
9199 inst.instruction |= inst.operands[1].reg << 16;
9200 encode_arm_shifter_operand (2);
9201 }
9202
9203 static void
9204 do_barrier (void)
9205 {
9206 if (inst.operands[0].present)
9207 inst.instruction |= inst.operands[0].imm;
9208 else
9209 inst.instruction |= 0xf;
9210 }
9211
9212 static void
9213 do_bfc (void)
9214 {
9215 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9216 constraint (msb > 32, _("bit-field extends past end of register"));
9217 /* The instruction encoding stores the LSB and MSB,
9218 not the LSB and width. */
9219 inst.instruction |= inst.operands[0].reg << 12;
9220 inst.instruction |= inst.operands[1].imm << 7;
9221 inst.instruction |= (msb - 1) << 16;
9222 }
9223
9224 static void
9225 do_bfi (void)
9226 {
9227 unsigned int msb;
9228
9229 /* #0 in second position is alternative syntax for bfc, which is
9230 the same instruction but with REG_PC in the Rm field. */
9231 if (!inst.operands[1].isreg)
9232 inst.operands[1].reg = REG_PC;
9233
9234 msb = inst.operands[2].imm + inst.operands[3].imm;
9235 constraint (msb > 32, _("bit-field extends past end of register"));
9236 /* The instruction encoding stores the LSB and MSB,
9237 not the LSB and width. */
9238 inst.instruction |= inst.operands[0].reg << 12;
9239 inst.instruction |= inst.operands[1].reg;
9240 inst.instruction |= inst.operands[2].imm << 7;
9241 inst.instruction |= (msb - 1) << 16;
9242 }
9243
9244 static void
9245 do_bfx (void)
9246 {
9247 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9248 _("bit-field extends past end of register"));
9249 inst.instruction |= inst.operands[0].reg << 12;
9250 inst.instruction |= inst.operands[1].reg;
9251 inst.instruction |= inst.operands[2].imm << 7;
9252 inst.instruction |= (inst.operands[3].imm - 1) << 16;
9253 }
9254
9255 /* ARM V5 breakpoint instruction (argument parse)
9256 BKPT <16 bit unsigned immediate>
9257 Instruction is not conditional.
9258 The bit pattern given in insns[] has the COND_ALWAYS condition,
9259 and it is an error if the caller tried to override that. */
9260
9261 static void
9262 do_bkpt (void)
9263 {
9264 /* Top 12 of 16 bits to bits 19:8. */
9265 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
9266
9267 /* Bottom 4 of 16 bits to bits 3:0. */
9268 inst.instruction |= inst.operands[0].imm & 0xf;
9269 }
9270
9271 static void
9272 encode_branch (int default_reloc)
9273 {
9274 if (inst.operands[0].hasreloc)
9275 {
9276 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
9277 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
9278 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
9279 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
9280 ? BFD_RELOC_ARM_PLT32
9281 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
9282 }
9283 else
9284 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
9285 inst.relocs[0].pc_rel = 1;
9286 }
9287
9288 static void
9289 do_branch (void)
9290 {
9291 #ifdef OBJ_ELF
9292 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9293 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9294 else
9295 #endif
9296 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9297 }
9298
9299 static void
9300 do_bl (void)
9301 {
9302 #ifdef OBJ_ELF
9303 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9304 {
9305 if (inst.cond == COND_ALWAYS)
9306 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
9307 else
9308 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
9309 }
9310 else
9311 #endif
9312 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
9313 }
9314
9315 /* ARM V5 branch-link-exchange instruction (argument parse)
9316 BLX <target_addr> ie BLX(1)
9317 BLX{<condition>} <Rm> ie BLX(2)
9318 Unfortunately, there are two different opcodes for this mnemonic.
9319 So, the insns[].value is not used, and the code here zaps values
9320 into inst.instruction.
9321 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
9322
9323 static void
9324 do_blx (void)
9325 {
9326 if (inst.operands[0].isreg)
9327 {
9328 /* Arg is a register; the opcode provided by insns[] is correct.
9329 It is not illegal to do "blx pc", just useless. */
9330 if (inst.operands[0].reg == REG_PC)
9331 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
9332
9333 inst.instruction |= inst.operands[0].reg;
9334 }
9335 else
9336 {
9337 /* Arg is an address; this instruction cannot be executed
9338 conditionally, and the opcode must be adjusted.
9339 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
9340 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
9341 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9342 inst.instruction = 0xfa000000;
9343 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
9344 }
9345 }
9346
9347 static void
9348 do_bx (void)
9349 {
9350 bfd_boolean want_reloc;
9351
9352 if (inst.operands[0].reg == REG_PC)
9353 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
9354
9355 inst.instruction |= inst.operands[0].reg;
9356 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
9357 it is for ARMv4t or earlier. */
9358 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
9359 if (!ARM_FEATURE_ZERO (selected_object_arch)
9360 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
9361 want_reloc = TRUE;
9362
9363 #ifdef OBJ_ELF
9364 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
9365 #endif
9366 want_reloc = FALSE;
9367
9368 if (want_reloc)
9369 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
9370 }
9371
9372
9373 /* ARM v5TEJ. Jump to Jazelle code. */
9374
9375 static void
9376 do_bxj (void)
9377 {
9378 if (inst.operands[0].reg == REG_PC)
9379 as_tsktsk (_("use of r15 in bxj is not really useful"));
9380
9381 inst.instruction |= inst.operands[0].reg;
9382 }
9383
9384 /* Co-processor data operation:
9385 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
9386 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
9387 static void
9388 do_cdp (void)
9389 {
9390 inst.instruction |= inst.operands[0].reg << 8;
9391 inst.instruction |= inst.operands[1].imm << 20;
9392 inst.instruction |= inst.operands[2].reg << 12;
9393 inst.instruction |= inst.operands[3].reg << 16;
9394 inst.instruction |= inst.operands[4].reg;
9395 inst.instruction |= inst.operands[5].imm << 5;
9396 }
9397
9398 static void
9399 do_cmp (void)
9400 {
9401 inst.instruction |= inst.operands[0].reg << 16;
9402 encode_arm_shifter_operand (1);
9403 }
9404
9405 /* Transfer between coprocessor and ARM registers.
9406 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
9407 MRC2
9408 MCR{cond}
9409 MCR2
9410
9411 No special properties. */
9412
9413 struct deprecated_coproc_regs_s
9414 {
9415 unsigned cp;
9416 int opc1;
9417 unsigned crn;
9418 unsigned crm;
9419 int opc2;
9420 arm_feature_set deprecated;
9421 arm_feature_set obsoleted;
9422 const char *dep_msg;
9423 const char *obs_msg;
9424 };
9425
9426 #define DEPR_ACCESS_V8 \
9427 N_("This coprocessor register access is deprecated in ARMv8")
9428
9429 /* Table of all deprecated coprocessor registers. */
9430 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
9431 {
9432 {15, 0, 7, 10, 5, /* CP15DMB. */
9433 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9434 DEPR_ACCESS_V8, NULL},
9435 {15, 0, 7, 10, 4, /* CP15DSB. */
9436 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9437 DEPR_ACCESS_V8, NULL},
9438 {15, 0, 7, 5, 4, /* CP15ISB. */
9439 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9440 DEPR_ACCESS_V8, NULL},
9441 {14, 6, 1, 0, 0, /* TEEHBR. */
9442 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9443 DEPR_ACCESS_V8, NULL},
9444 {14, 6, 0, 0, 0, /* TEECR. */
9445 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
9446 DEPR_ACCESS_V8, NULL},
9447 };
9448
9449 #undef DEPR_ACCESS_V8
9450
9451 static const size_t deprecated_coproc_reg_count =
9452 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
9453
9454 static void
9455 do_co_reg (void)
9456 {
9457 unsigned Rd;
9458 size_t i;
9459
9460 Rd = inst.operands[2].reg;
9461 if (thumb_mode)
9462 {
9463 if (inst.instruction == 0xee000010
9464 || inst.instruction == 0xfe000010)
9465 /* MCR, MCR2 */
9466 reject_bad_reg (Rd);
9467 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9468 /* MRC, MRC2 */
9469 constraint (Rd == REG_SP, BAD_SP);
9470 }
9471 else
9472 {
9473 /* MCR */
9474 if (inst.instruction == 0xe000010)
9475 constraint (Rd == REG_PC, BAD_PC);
9476 }
9477
9478 for (i = 0; i < deprecated_coproc_reg_count; ++i)
9479 {
9480 const struct deprecated_coproc_regs_s *r =
9481 deprecated_coproc_regs + i;
9482
9483 if (inst.operands[0].reg == r->cp
9484 && inst.operands[1].imm == r->opc1
9485 && inst.operands[3].reg == r->crn
9486 && inst.operands[4].reg == r->crm
9487 && inst.operands[5].imm == r->opc2)
9488 {
9489 if (! ARM_CPU_IS_ANY (cpu_variant)
9490 && warn_on_deprecated
9491 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
9492 as_tsktsk ("%s", r->dep_msg);
9493 }
9494 }
9495
9496 inst.instruction |= inst.operands[0].reg << 8;
9497 inst.instruction |= inst.operands[1].imm << 21;
9498 inst.instruction |= Rd << 12;
9499 inst.instruction |= inst.operands[3].reg << 16;
9500 inst.instruction |= inst.operands[4].reg;
9501 inst.instruction |= inst.operands[5].imm << 5;
9502 }
9503
9504 /* Transfer between coprocessor register and pair of ARM registers.
9505 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
9506 MCRR2
9507 MRRC{cond}
9508 MRRC2
9509
9510 Two XScale instructions are special cases of these:
9511
9512 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
9513 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
9514
9515 Result unpredictable if Rd or Rn is R15. */
9516
9517 static void
9518 do_co_reg2c (void)
9519 {
9520 unsigned Rd, Rn;
9521
9522 Rd = inst.operands[2].reg;
9523 Rn = inst.operands[3].reg;
9524
9525 if (thumb_mode)
9526 {
9527 reject_bad_reg (Rd);
9528 reject_bad_reg (Rn);
9529 }
9530 else
9531 {
9532 constraint (Rd == REG_PC, BAD_PC);
9533 constraint (Rn == REG_PC, BAD_PC);
9534 }
9535
9536 /* Only check the MRRC{2} variants. */
9537 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
9538 {
9539 /* If Rd == Rn, error that the operation is
9540 unpredictable (example MRRC p3,#1,r1,r1,c4). */
9541 constraint (Rd == Rn, BAD_OVERLAP);
9542 }
9543
9544 inst.instruction |= inst.operands[0].reg << 8;
9545 inst.instruction |= inst.operands[1].imm << 4;
9546 inst.instruction |= Rd << 12;
9547 inst.instruction |= Rn << 16;
9548 inst.instruction |= inst.operands[4].reg;
9549 }
9550
9551 static void
9552 do_cpsi (void)
9553 {
9554 inst.instruction |= inst.operands[0].imm << 6;
9555 if (inst.operands[1].present)
9556 {
9557 inst.instruction |= CPSI_MMOD;
9558 inst.instruction |= inst.operands[1].imm;
9559 }
9560 }
9561
9562 static void
9563 do_dbg (void)
9564 {
9565 inst.instruction |= inst.operands[0].imm;
9566 }
9567
9568 static void
9569 do_div (void)
9570 {
9571 unsigned Rd, Rn, Rm;
9572
9573 Rd = inst.operands[0].reg;
9574 Rn = (inst.operands[1].present
9575 ? inst.operands[1].reg : Rd);
9576 Rm = inst.operands[2].reg;
9577
9578 constraint ((Rd == REG_PC), BAD_PC);
9579 constraint ((Rn == REG_PC), BAD_PC);
9580 constraint ((Rm == REG_PC), BAD_PC);
9581
9582 inst.instruction |= Rd << 16;
9583 inst.instruction |= Rn << 0;
9584 inst.instruction |= Rm << 8;
9585 }
9586
9587 static void
9588 do_it (void)
9589 {
9590 /* There is no IT instruction in ARM mode. We
9591 process it to do the validation as if in
9592 thumb mode, just in case the code gets
9593 assembled for thumb using the unified syntax. */
9594
9595 inst.size = 0;
9596 if (unified_syntax)
9597 {
9598 set_pred_insn_type (IT_INSN);
9599 now_pred.mask = (inst.instruction & 0xf) | 0x10;
9600 now_pred.cc = inst.operands[0].imm;
9601 }
9602 }
9603
9604 /* If there is only one register in the register list,
9605 then return its register number. Otherwise return -1. */
9606 static int
9607 only_one_reg_in_list (int range)
9608 {
9609 int i = ffs (range) - 1;
9610 return (i > 15 || range != (1 << i)) ? -1 : i;
9611 }
9612
9613 static void
9614 encode_ldmstm(int from_push_pop_mnem)
9615 {
9616 int base_reg = inst.operands[0].reg;
9617 int range = inst.operands[1].imm;
9618 int one_reg;
9619
9620 inst.instruction |= base_reg << 16;
9621 inst.instruction |= range;
9622
9623 if (inst.operands[1].writeback)
9624 inst.instruction |= LDM_TYPE_2_OR_3;
9625
9626 if (inst.operands[0].writeback)
9627 {
9628 inst.instruction |= WRITE_BACK;
9629 /* Check for unpredictable uses of writeback. */
9630 if (inst.instruction & LOAD_BIT)
9631 {
9632 /* Not allowed in LDM type 2. */
9633 if ((inst.instruction & LDM_TYPE_2_OR_3)
9634 && ((range & (1 << REG_PC)) == 0))
9635 as_warn (_("writeback of base register is UNPREDICTABLE"));
9636 /* Only allowed if base reg not in list for other types. */
9637 else if (range & (1 << base_reg))
9638 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
9639 }
9640 else /* STM. */
9641 {
9642 /* Not allowed for type 2. */
9643 if (inst.instruction & LDM_TYPE_2_OR_3)
9644 as_warn (_("writeback of base register is UNPREDICTABLE"));
9645 /* Only allowed if base reg not in list, or first in list. */
9646 else if ((range & (1 << base_reg))
9647 && (range & ((1 << base_reg) - 1)))
9648 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
9649 }
9650 }
9651
9652 /* If PUSH/POP has only one register, then use the A2 encoding. */
9653 one_reg = only_one_reg_in_list (range);
9654 if (from_push_pop_mnem && one_reg >= 0)
9655 {
9656 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
9657
9658 if (is_push && one_reg == 13 /* SP */)
9659 /* PR 22483: The A2 encoding cannot be used when
9660 pushing the stack pointer as this is UNPREDICTABLE. */
9661 return;
9662
9663 inst.instruction &= A_COND_MASK;
9664 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
9665 inst.instruction |= one_reg << 12;
9666 }
9667 }
9668
9669 static void
9670 do_ldmstm (void)
9671 {
9672 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
9673 }
9674
9675 /* ARMv5TE load-consecutive (argument parse)
9676 Mode is like LDRH.
9677
9678 LDRccD R, mode
9679 STRccD R, mode. */
9680
9681 static void
9682 do_ldrd (void)
9683 {
9684 constraint (inst.operands[0].reg % 2 != 0,
9685 _("first transfer register must be even"));
9686 constraint (inst.operands[1].present
9687 && inst.operands[1].reg != inst.operands[0].reg + 1,
9688 _("can only transfer two consecutive registers"));
9689 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9690 constraint (!inst.operands[2].isreg, _("'[' expected"));
9691
9692 if (!inst.operands[1].present)
9693 inst.operands[1].reg = inst.operands[0].reg + 1;
9694
9695 /* encode_arm_addr_mode_3 will diagnose overlap between the base
9696 register and the first register written; we have to diagnose
9697 overlap between the base and the second register written here. */
9698
9699 if (inst.operands[2].reg == inst.operands[1].reg
9700 && (inst.operands[2].writeback || inst.operands[2].postind))
9701 as_warn (_("base register written back, and overlaps "
9702 "second transfer register"));
9703
9704 if (!(inst.instruction & V4_STR_BIT))
9705 {
9706 /* For an index-register load, the index register must not overlap the
9707 destination (even if not write-back). */
9708 if (inst.operands[2].immisreg
9709 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9710 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9711 as_warn (_("index register overlaps transfer register"));
9712 }
9713 inst.instruction |= inst.operands[0].reg << 12;
9714 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
9715 }
9716
9717 static void
9718 do_ldrex (void)
9719 {
9720 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9721 || inst.operands[1].postind || inst.operands[1].writeback
9722 || inst.operands[1].immisreg || inst.operands[1].shifted
9723 || inst.operands[1].negative
9724 /* This can arise if the programmer has written
9725 strex rN, rM, foo
9726 or if they have mistakenly used a register name as the last
9727 operand, eg:
9728 strex rN, rM, rX
9729 It is very difficult to distinguish between these two cases
9730 because "rX" might actually be a label. ie the register
9731 name has been occluded by a symbol of the same name. So we
9732 just generate a general 'bad addressing mode' type error
9733 message and leave it up to the programmer to discover the
9734 true cause and fix their mistake. */
9735 || (inst.operands[1].reg == REG_PC),
9736 BAD_ADDR_MODE);
9737
9738 constraint (inst.relocs[0].exp.X_op != O_constant
9739 || inst.relocs[0].exp.X_add_number != 0,
9740 _("offset must be zero in ARM encoding"));
9741
9742 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9743
9744 inst.instruction |= inst.operands[0].reg << 12;
9745 inst.instruction |= inst.operands[1].reg << 16;
9746 inst.relocs[0].type = BFD_RELOC_UNUSED;
9747 }
9748
9749 static void
9750 do_ldrexd (void)
9751 {
9752 constraint (inst.operands[0].reg % 2 != 0,
9753 _("even register required"));
9754 constraint (inst.operands[1].present
9755 && inst.operands[1].reg != inst.operands[0].reg + 1,
9756 _("can only load two consecutive registers"));
9757 /* If op 1 were present and equal to PC, this function wouldn't
9758 have been called in the first place. */
9759 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9760
9761 inst.instruction |= inst.operands[0].reg << 12;
9762 inst.instruction |= inst.operands[2].reg << 16;
9763 }
9764
9765 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9766 which is not a multiple of four is UNPREDICTABLE. */
9767 static void
9768 check_ldr_r15_aligned (void)
9769 {
9770 constraint (!(inst.operands[1].immisreg)
9771 && (inst.operands[0].reg == REG_PC
9772 && inst.operands[1].reg == REG_PC
9773 && (inst.relocs[0].exp.X_add_number & 0x3)),
9774 _("ldr to register 15 must be 4-byte aligned"));
9775 }
9776
9777 static void
9778 do_ldst (void)
9779 {
9780 inst.instruction |= inst.operands[0].reg << 12;
9781 if (!inst.operands[1].isreg)
9782 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
9783 return;
9784 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
9785 check_ldr_r15_aligned ();
9786 }
9787
9788 static void
9789 do_ldstt (void)
9790 {
9791 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9792 reject [Rn,...]. */
9793 if (inst.operands[1].preind)
9794 {
9795 constraint (inst.relocs[0].exp.X_op != O_constant
9796 || inst.relocs[0].exp.X_add_number != 0,
9797 _("this instruction requires a post-indexed address"));
9798
9799 inst.operands[1].preind = 0;
9800 inst.operands[1].postind = 1;
9801 inst.operands[1].writeback = 1;
9802 }
9803 inst.instruction |= inst.operands[0].reg << 12;
9804 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9805 }
9806
9807 /* Halfword and signed-byte load/store operations. */
9808
9809 static void
9810 do_ldstv4 (void)
9811 {
9812 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9813 inst.instruction |= inst.operands[0].reg << 12;
9814 if (!inst.operands[1].isreg)
9815 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
9816 return;
9817 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
9818 }
9819
9820 static void
9821 do_ldsttv4 (void)
9822 {
9823 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9824 reject [Rn,...]. */
9825 if (inst.operands[1].preind)
9826 {
9827 constraint (inst.relocs[0].exp.X_op != O_constant
9828 || inst.relocs[0].exp.X_add_number != 0,
9829 _("this instruction requires a post-indexed address"));
9830
9831 inst.operands[1].preind = 0;
9832 inst.operands[1].postind = 1;
9833 inst.operands[1].writeback = 1;
9834 }
9835 inst.instruction |= inst.operands[0].reg << 12;
9836 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9837 }
9838
9839 /* Co-processor register load/store.
9840 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9841 static void
9842 do_lstc (void)
9843 {
9844 inst.instruction |= inst.operands[0].reg << 8;
9845 inst.instruction |= inst.operands[1].reg << 12;
9846 encode_arm_cp_address (2, TRUE, TRUE, 0);
9847 }
9848
9849 static void
9850 do_mlas (void)
9851 {
9852 /* This restriction does not apply to mls (nor to mla in v6 or later). */
9853 if (inst.operands[0].reg == inst.operands[1].reg
9854 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
9855 && !(inst.instruction & 0x00400000))
9856 as_tsktsk (_("Rd and Rm should be different in mla"));
9857
9858 inst.instruction |= inst.operands[0].reg << 16;
9859 inst.instruction |= inst.operands[1].reg;
9860 inst.instruction |= inst.operands[2].reg << 8;
9861 inst.instruction |= inst.operands[3].reg << 12;
9862 }
9863
9864 static void
9865 do_mov (void)
9866 {
9867 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9868 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9869 THUMB1_RELOC_ONLY);
9870 inst.instruction |= inst.operands[0].reg << 12;
9871 encode_arm_shifter_operand (1);
9872 }
9873
9874 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9875 static void
9876 do_mov16 (void)
9877 {
9878 bfd_vma imm;
9879 bfd_boolean top;
9880
9881 top = (inst.instruction & 0x00400000) != 0;
9882 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
9883 _(":lower16: not allowed in this instruction"));
9884 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
9885 _(":upper16: not allowed in this instruction"));
9886 inst.instruction |= inst.operands[0].reg << 12;
9887 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
9888 {
9889 imm = inst.relocs[0].exp.X_add_number;
9890 /* The value is in two pieces: 0:11, 16:19. */
9891 inst.instruction |= (imm & 0x00000fff);
9892 inst.instruction |= (imm & 0x0000f000) << 4;
9893 }
9894 }
9895
9896 static int
9897 do_vfp_nsyn_mrs (void)
9898 {
9899 if (inst.operands[0].isvec)
9900 {
9901 if (inst.operands[1].reg != 1)
9902 first_error (_("operand 1 must be FPSCR"));
9903 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9904 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9905 do_vfp_nsyn_opcode ("fmstat");
9906 }
9907 else if (inst.operands[1].isvec)
9908 do_vfp_nsyn_opcode ("fmrx");
9909 else
9910 return FAIL;
9911
9912 return SUCCESS;
9913 }
9914
9915 static int
9916 do_vfp_nsyn_msr (void)
9917 {
9918 if (inst.operands[0].isvec)
9919 do_vfp_nsyn_opcode ("fmxr");
9920 else
9921 return FAIL;
9922
9923 return SUCCESS;
9924 }
9925
9926 static void
9927 do_vmrs (void)
9928 {
9929 unsigned Rt = inst.operands[0].reg;
9930
9931 if (thumb_mode && Rt == REG_SP)
9932 {
9933 inst.error = BAD_SP;
9934 return;
9935 }
9936
9937 switch (inst.operands[1].reg)
9938 {
9939 /* MVFR2 is only valid for Armv8-A. */
9940 case 5:
9941 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9942 _(BAD_FPU));
9943 break;
9944
9945 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
9946 case 1: /* fpscr. */
9947 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9948 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9949 _(BAD_FPU));
9950 break;
9951
9952 case 14: /* fpcxt_ns. */
9953 case 15: /* fpcxt_s. */
9954 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
9955 _("selected processor does not support instruction"));
9956 break;
9957
9958 case 2: /* fpscr_nzcvqc. */
9959 case 12: /* vpr. */
9960 case 13: /* p0. */
9961 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
9962 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
9963 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
9964 _("selected processor does not support instruction"));
9965 if (inst.operands[0].reg != 2
9966 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
9967 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
9968 break;
9969
9970 default:
9971 break;
9972 }
9973
9974 /* APSR_ sets isvec. All other refs to PC are illegal. */
9975 if (!inst.operands[0].isvec && Rt == REG_PC)
9976 {
9977 inst.error = BAD_PC;
9978 return;
9979 }
9980
9981 /* If we get through parsing the register name, we just insert the number
9982 generated into the instruction without further validation. */
9983 inst.instruction |= (inst.operands[1].reg << 16);
9984 inst.instruction |= (Rt << 12);
9985 }
9986
9987 static void
9988 do_vmsr (void)
9989 {
9990 unsigned Rt = inst.operands[1].reg;
9991
9992 if (thumb_mode)
9993 reject_bad_reg (Rt);
9994 else if (Rt == REG_PC)
9995 {
9996 inst.error = BAD_PC;
9997 return;
9998 }
9999
10000 switch (inst.operands[0].reg)
10001 {
10002 /* MVFR2 is only valid for Armv8-A. */
10003 case 5:
10004 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
10005 _(BAD_FPU));
10006 break;
10007
10008 /* Check for new Armv8.1-M Mainline changes to <spec_reg>. */
10009 case 1: /* fpcr. */
10010 constraint (!(ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10011 || ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10012 _(BAD_FPU));
10013 break;
10014
10015 case 14: /* fpcxt_ns. */
10016 case 15: /* fpcxt_s. */
10017 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main),
10018 _("selected processor does not support instruction"));
10019 break;
10020
10021 case 2: /* fpscr_nzcvqc. */
10022 case 12: /* vpr. */
10023 case 13: /* p0. */
10024 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_1m_main)
10025 || (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
10026 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)),
10027 _("selected processor does not support instruction"));
10028 if (inst.operands[0].reg != 2
10029 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
10030 as_warn (_("accessing MVE system register without MVE is UNPREDICTABLE"));
10031 break;
10032
10033 default:
10034 break;
10035 }
10036
10037 /* If we get through parsing the register name, we just insert the number
10038 generated into the instruction without further validation. */
10039 inst.instruction |= (inst.operands[0].reg << 16);
10040 inst.instruction |= (Rt << 12);
10041 }
10042
10043 static void
10044 do_mrs (void)
10045 {
10046 unsigned br;
10047
10048 if (do_vfp_nsyn_mrs () == SUCCESS)
10049 return;
10050
10051 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10052 inst.instruction |= inst.operands[0].reg << 12;
10053
10054 if (inst.operands[1].isreg)
10055 {
10056 br = inst.operands[1].reg;
10057 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
10058 as_bad (_("bad register for mrs"));
10059 }
10060 else
10061 {
10062 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10063 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
10064 != (PSR_c|PSR_f),
10065 _("'APSR', 'CPSR' or 'SPSR' expected"));
10066 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
10067 }
10068
10069 inst.instruction |= br;
10070 }
10071
10072 /* Two possible forms:
10073 "{C|S}PSR_<field>, Rm",
10074 "{C|S}PSR_f, #expression". */
10075
10076 static void
10077 do_msr (void)
10078 {
10079 if (do_vfp_nsyn_msr () == SUCCESS)
10080 return;
10081
10082 inst.instruction |= inst.operands[0].imm;
10083 if (inst.operands[1].isreg)
10084 inst.instruction |= inst.operands[1].reg;
10085 else
10086 {
10087 inst.instruction |= INST_IMMEDIATE;
10088 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
10089 inst.relocs[0].pc_rel = 0;
10090 }
10091 }
10092
10093 static void
10094 do_mul (void)
10095 {
10096 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
10097
10098 if (!inst.operands[2].present)
10099 inst.operands[2].reg = inst.operands[0].reg;
10100 inst.instruction |= inst.operands[0].reg << 16;
10101 inst.instruction |= inst.operands[1].reg;
10102 inst.instruction |= inst.operands[2].reg << 8;
10103
10104 if (inst.operands[0].reg == inst.operands[1].reg
10105 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10106 as_tsktsk (_("Rd and Rm should be different in mul"));
10107 }
10108
10109 /* Long Multiply Parser
10110 UMULL RdLo, RdHi, Rm, Rs
10111 SMULL RdLo, RdHi, Rm, Rs
10112 UMLAL RdLo, RdHi, Rm, Rs
10113 SMLAL RdLo, RdHi, Rm, Rs. */
10114
10115 static void
10116 do_mull (void)
10117 {
10118 inst.instruction |= inst.operands[0].reg << 12;
10119 inst.instruction |= inst.operands[1].reg << 16;
10120 inst.instruction |= inst.operands[2].reg;
10121 inst.instruction |= inst.operands[3].reg << 8;
10122
10123 /* rdhi and rdlo must be different. */
10124 if (inst.operands[0].reg == inst.operands[1].reg)
10125 as_tsktsk (_("rdhi and rdlo must be different"));
10126
10127 /* rdhi, rdlo and rm must all be different before armv6. */
10128 if ((inst.operands[0].reg == inst.operands[2].reg
10129 || inst.operands[1].reg == inst.operands[2].reg)
10130 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
10131 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
10132 }
10133
10134 static void
10135 do_nop (void)
10136 {
10137 if (inst.operands[0].present
10138 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
10139 {
10140 /* Architectural NOP hints are CPSR sets with no bits selected. */
10141 inst.instruction &= 0xf0000000;
10142 inst.instruction |= 0x0320f000;
10143 if (inst.operands[0].present)
10144 inst.instruction |= inst.operands[0].imm;
10145 }
10146 }
10147
10148 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
10149 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
10150 Condition defaults to COND_ALWAYS.
10151 Error if Rd, Rn or Rm are R15. */
10152
10153 static void
10154 do_pkhbt (void)
10155 {
10156 inst.instruction |= inst.operands[0].reg << 12;
10157 inst.instruction |= inst.operands[1].reg << 16;
10158 inst.instruction |= inst.operands[2].reg;
10159 if (inst.operands[3].present)
10160 encode_arm_shift (3);
10161 }
10162
10163 /* ARM V6 PKHTB (Argument Parse). */
10164
10165 static void
10166 do_pkhtb (void)
10167 {
10168 if (!inst.operands[3].present)
10169 {
10170 /* If the shift specifier is omitted, turn the instruction
10171 into pkhbt rd, rm, rn. */
10172 inst.instruction &= 0xfff00010;
10173 inst.instruction |= inst.operands[0].reg << 12;
10174 inst.instruction |= inst.operands[1].reg;
10175 inst.instruction |= inst.operands[2].reg << 16;
10176 }
10177 else
10178 {
10179 inst.instruction |= inst.operands[0].reg << 12;
10180 inst.instruction |= inst.operands[1].reg << 16;
10181 inst.instruction |= inst.operands[2].reg;
10182 encode_arm_shift (3);
10183 }
10184 }
10185
10186 /* ARMv5TE: Preload-Cache
10187 MP Extensions: Preload for write
10188
10189 PLD(W) <addr_mode>
10190
10191 Syntactically, like LDR with B=1, W=0, L=1. */
10192
10193 static void
10194 do_pld (void)
10195 {
10196 constraint (!inst.operands[0].isreg,
10197 _("'[' expected after PLD mnemonic"));
10198 constraint (inst.operands[0].postind,
10199 _("post-indexed expression used in preload instruction"));
10200 constraint (inst.operands[0].writeback,
10201 _("writeback used in preload instruction"));
10202 constraint (!inst.operands[0].preind,
10203 _("unindexed addressing used in preload instruction"));
10204 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10205 }
10206
10207 /* ARMv7: PLI <addr_mode> */
10208 static void
10209 do_pli (void)
10210 {
10211 constraint (!inst.operands[0].isreg,
10212 _("'[' expected after PLI mnemonic"));
10213 constraint (inst.operands[0].postind,
10214 _("post-indexed expression used in preload instruction"));
10215 constraint (inst.operands[0].writeback,
10216 _("writeback used in preload instruction"));
10217 constraint (!inst.operands[0].preind,
10218 _("unindexed addressing used in preload instruction"));
10219 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
10220 inst.instruction &= ~PRE_INDEX;
10221 }
10222
10223 static void
10224 do_push_pop (void)
10225 {
10226 constraint (inst.operands[0].writeback,
10227 _("push/pop do not support {reglist}^"));
10228 inst.operands[1] = inst.operands[0];
10229 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
10230 inst.operands[0].isreg = 1;
10231 inst.operands[0].writeback = 1;
10232 inst.operands[0].reg = REG_SP;
10233 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
10234 }
10235
10236 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
10237 word at the specified address and the following word
10238 respectively.
10239 Unconditionally executed.
10240 Error if Rn is R15. */
10241
10242 static void
10243 do_rfe (void)
10244 {
10245 inst.instruction |= inst.operands[0].reg << 16;
10246 if (inst.operands[0].writeback)
10247 inst.instruction |= WRITE_BACK;
10248 }
10249
10250 /* ARM V6 ssat (argument parse). */
10251
10252 static void
10253 do_ssat (void)
10254 {
10255 inst.instruction |= inst.operands[0].reg << 12;
10256 inst.instruction |= (inst.operands[1].imm - 1) << 16;
10257 inst.instruction |= inst.operands[2].reg;
10258
10259 if (inst.operands[3].present)
10260 encode_arm_shift (3);
10261 }
10262
10263 /* ARM V6 usat (argument parse). */
10264
10265 static void
10266 do_usat (void)
10267 {
10268 inst.instruction |= inst.operands[0].reg << 12;
10269 inst.instruction |= inst.operands[1].imm << 16;
10270 inst.instruction |= inst.operands[2].reg;
10271
10272 if (inst.operands[3].present)
10273 encode_arm_shift (3);
10274 }
10275
10276 /* ARM V6 ssat16 (argument parse). */
10277
10278 static void
10279 do_ssat16 (void)
10280 {
10281 inst.instruction |= inst.operands[0].reg << 12;
10282 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
10283 inst.instruction |= inst.operands[2].reg;
10284 }
10285
10286 static void
10287 do_usat16 (void)
10288 {
10289 inst.instruction |= inst.operands[0].reg << 12;
10290 inst.instruction |= inst.operands[1].imm << 16;
10291 inst.instruction |= inst.operands[2].reg;
10292 }
10293
10294 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
10295 preserving the other bits.
10296
10297 setend <endian_specifier>, where <endian_specifier> is either
10298 BE or LE. */
10299
10300 static void
10301 do_setend (void)
10302 {
10303 if (warn_on_deprecated
10304 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10305 as_tsktsk (_("setend use is deprecated for ARMv8"));
10306
10307 if (inst.operands[0].imm)
10308 inst.instruction |= 0x200;
10309 }
10310
10311 static void
10312 do_shift (void)
10313 {
10314 unsigned int Rm = (inst.operands[1].present
10315 ? inst.operands[1].reg
10316 : inst.operands[0].reg);
10317
10318 inst.instruction |= inst.operands[0].reg << 12;
10319 inst.instruction |= Rm;
10320 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
10321 {
10322 inst.instruction |= inst.operands[2].reg << 8;
10323 inst.instruction |= SHIFT_BY_REG;
10324 /* PR 12854: Error on extraneous shifts. */
10325 constraint (inst.operands[2].shifted,
10326 _("extraneous shift as part of operand to shift insn"));
10327 }
10328 else
10329 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
10330 }
10331
10332 static void
10333 do_smc (void)
10334 {
10335 unsigned int value = inst.relocs[0].exp.X_add_number;
10336 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
10337
10338 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
10339 inst.relocs[0].pc_rel = 0;
10340 }
10341
10342 static void
10343 do_hvc (void)
10344 {
10345 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
10346 inst.relocs[0].pc_rel = 0;
10347 }
10348
10349 static void
10350 do_swi (void)
10351 {
10352 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
10353 inst.relocs[0].pc_rel = 0;
10354 }
10355
10356 static void
10357 do_setpan (void)
10358 {
10359 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10360 _("selected processor does not support SETPAN instruction"));
10361
10362 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
10363 }
10364
10365 static void
10366 do_t_setpan (void)
10367 {
10368 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
10369 _("selected processor does not support SETPAN instruction"));
10370
10371 inst.instruction |= (inst.operands[0].imm << 3);
10372 }
10373
10374 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
10375 SMLAxy{cond} Rd,Rm,Rs,Rn
10376 SMLAWy{cond} Rd,Rm,Rs,Rn
10377 Error if any register is R15. */
10378
10379 static void
10380 do_smla (void)
10381 {
10382 inst.instruction |= inst.operands[0].reg << 16;
10383 inst.instruction |= inst.operands[1].reg;
10384 inst.instruction |= inst.operands[2].reg << 8;
10385 inst.instruction |= inst.operands[3].reg << 12;
10386 }
10387
10388 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
10389 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
10390 Error if any register is R15.
10391 Warning if Rdlo == Rdhi. */
10392
10393 static void
10394 do_smlal (void)
10395 {
10396 inst.instruction |= inst.operands[0].reg << 12;
10397 inst.instruction |= inst.operands[1].reg << 16;
10398 inst.instruction |= inst.operands[2].reg;
10399 inst.instruction |= inst.operands[3].reg << 8;
10400
10401 if (inst.operands[0].reg == inst.operands[1].reg)
10402 as_tsktsk (_("rdhi and rdlo must be different"));
10403 }
10404
10405 /* ARM V5E (El Segundo) signed-multiply (argument parse)
10406 SMULxy{cond} Rd,Rm,Rs
10407 Error if any register is R15. */
10408
10409 static void
10410 do_smul (void)
10411 {
10412 inst.instruction |= inst.operands[0].reg << 16;
10413 inst.instruction |= inst.operands[1].reg;
10414 inst.instruction |= inst.operands[2].reg << 8;
10415 }
10416
10417 /* ARM V6 srs (argument parse). The variable fields in the encoding are
10418 the same for both ARM and Thumb-2. */
10419
10420 static void
10421 do_srs (void)
10422 {
10423 int reg;
10424
10425 if (inst.operands[0].present)
10426 {
10427 reg = inst.operands[0].reg;
10428 constraint (reg != REG_SP, _("SRS base register must be r13"));
10429 }
10430 else
10431 reg = REG_SP;
10432
10433 inst.instruction |= reg << 16;
10434 inst.instruction |= inst.operands[1].imm;
10435 if (inst.operands[0].writeback || inst.operands[1].writeback)
10436 inst.instruction |= WRITE_BACK;
10437 }
10438
10439 /* ARM V6 strex (argument parse). */
10440
10441 static void
10442 do_strex (void)
10443 {
10444 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10445 || inst.operands[2].postind || inst.operands[2].writeback
10446 || inst.operands[2].immisreg || inst.operands[2].shifted
10447 || inst.operands[2].negative
10448 /* See comment in do_ldrex(). */
10449 || (inst.operands[2].reg == REG_PC),
10450 BAD_ADDR_MODE);
10451
10452 constraint (inst.operands[0].reg == inst.operands[1].reg
10453 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10454
10455 constraint (inst.relocs[0].exp.X_op != O_constant
10456 || inst.relocs[0].exp.X_add_number != 0,
10457 _("offset must be zero in ARM encoding"));
10458
10459 inst.instruction |= inst.operands[0].reg << 12;
10460 inst.instruction |= inst.operands[1].reg;
10461 inst.instruction |= inst.operands[2].reg << 16;
10462 inst.relocs[0].type = BFD_RELOC_UNUSED;
10463 }
10464
10465 static void
10466 do_t_strexbh (void)
10467 {
10468 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10469 || inst.operands[2].postind || inst.operands[2].writeback
10470 || inst.operands[2].immisreg || inst.operands[2].shifted
10471 || inst.operands[2].negative,
10472 BAD_ADDR_MODE);
10473
10474 constraint (inst.operands[0].reg == inst.operands[1].reg
10475 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10476
10477 do_rm_rd_rn ();
10478 }
10479
10480 static void
10481 do_strexd (void)
10482 {
10483 constraint (inst.operands[1].reg % 2 != 0,
10484 _("even register required"));
10485 constraint (inst.operands[2].present
10486 && inst.operands[2].reg != inst.operands[1].reg + 1,
10487 _("can only store two consecutive registers"));
10488 /* If op 2 were present and equal to PC, this function wouldn't
10489 have been called in the first place. */
10490 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
10491
10492 constraint (inst.operands[0].reg == inst.operands[1].reg
10493 || inst.operands[0].reg == inst.operands[1].reg + 1
10494 || inst.operands[0].reg == inst.operands[3].reg,
10495 BAD_OVERLAP);
10496
10497 inst.instruction |= inst.operands[0].reg << 12;
10498 inst.instruction |= inst.operands[1].reg;
10499 inst.instruction |= inst.operands[3].reg << 16;
10500 }
10501
10502 /* ARM V8 STRL. */
10503 static void
10504 do_stlex (void)
10505 {
10506 constraint (inst.operands[0].reg == inst.operands[1].reg
10507 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10508
10509 do_rd_rm_rn ();
10510 }
10511
10512 static void
10513 do_t_stlex (void)
10514 {
10515 constraint (inst.operands[0].reg == inst.operands[1].reg
10516 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
10517
10518 do_rm_rd_rn ();
10519 }
10520
10521 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
10522 extends it to 32-bits, and adds the result to a value in another
10523 register. You can specify a rotation by 0, 8, 16, or 24 bits
10524 before extracting the 16-bit value.
10525 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
10526 Condition defaults to COND_ALWAYS.
10527 Error if any register uses R15. */
10528
10529 static void
10530 do_sxtah (void)
10531 {
10532 inst.instruction |= inst.operands[0].reg << 12;
10533 inst.instruction |= inst.operands[1].reg << 16;
10534 inst.instruction |= inst.operands[2].reg;
10535 inst.instruction |= inst.operands[3].imm << 10;
10536 }
10537
10538 /* ARM V6 SXTH.
10539
10540 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
10541 Condition defaults to COND_ALWAYS.
10542 Error if any register uses R15. */
10543
10544 static void
10545 do_sxth (void)
10546 {
10547 inst.instruction |= inst.operands[0].reg << 12;
10548 inst.instruction |= inst.operands[1].reg;
10549 inst.instruction |= inst.operands[2].imm << 10;
10550 }
10551 \f
10552 /* VFP instructions. In a logical order: SP variant first, monad
10553 before dyad, arithmetic then move then load/store. */
10554
10555 static void
10556 do_vfp_sp_monadic (void)
10557 {
10558 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10559 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10560 _(BAD_FPU));
10561
10562 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10563 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10564 }
10565
10566 static void
10567 do_vfp_sp_dyadic (void)
10568 {
10569 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10570 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10571 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10572 }
10573
10574 static void
10575 do_vfp_sp_compare_z (void)
10576 {
10577 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10578 }
10579
10580 static void
10581 do_vfp_dp_sp_cvt (void)
10582 {
10583 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10584 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
10585 }
10586
10587 static void
10588 do_vfp_sp_dp_cvt (void)
10589 {
10590 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10591 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10592 }
10593
10594 static void
10595 do_vfp_reg_from_sp (void)
10596 {
10597 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10598 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10599 _(BAD_FPU));
10600
10601 inst.instruction |= inst.operands[0].reg << 12;
10602 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
10603 }
10604
10605 static void
10606 do_vfp_reg2_from_sp2 (void)
10607 {
10608 constraint (inst.operands[2].imm != 2,
10609 _("only two consecutive VFP SP registers allowed here"));
10610 inst.instruction |= inst.operands[0].reg << 12;
10611 inst.instruction |= inst.operands[1].reg << 16;
10612 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
10613 }
10614
10615 static void
10616 do_vfp_sp_from_reg (void)
10617 {
10618 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
10619 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10620 _(BAD_FPU));
10621
10622 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
10623 inst.instruction |= inst.operands[1].reg << 12;
10624 }
10625
10626 static void
10627 do_vfp_sp2_from_reg2 (void)
10628 {
10629 constraint (inst.operands[0].imm != 2,
10630 _("only two consecutive VFP SP registers allowed here"));
10631 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
10632 inst.instruction |= inst.operands[1].reg << 12;
10633 inst.instruction |= inst.operands[2].reg << 16;
10634 }
10635
10636 static void
10637 do_vfp_sp_ldst (void)
10638 {
10639 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10640 encode_arm_cp_address (1, FALSE, TRUE, 0);
10641 }
10642
10643 static void
10644 do_vfp_dp_ldst (void)
10645 {
10646 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10647 encode_arm_cp_address (1, FALSE, TRUE, 0);
10648 }
10649
10650
10651 static void
10652 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
10653 {
10654 if (inst.operands[0].writeback)
10655 inst.instruction |= WRITE_BACK;
10656 else
10657 constraint (ldstm_type != VFP_LDSTMIA,
10658 _("this addressing mode requires base-register writeback"));
10659 inst.instruction |= inst.operands[0].reg << 16;
10660 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
10661 inst.instruction |= inst.operands[1].imm;
10662 }
10663
10664 static void
10665 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
10666 {
10667 int count;
10668
10669 if (inst.operands[0].writeback)
10670 inst.instruction |= WRITE_BACK;
10671 else
10672 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
10673 _("this addressing mode requires base-register writeback"));
10674
10675 inst.instruction |= inst.operands[0].reg << 16;
10676 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10677
10678 count = inst.operands[1].imm << 1;
10679 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
10680 count += 1;
10681
10682 inst.instruction |= count;
10683 }
10684
10685 static void
10686 do_vfp_sp_ldstmia (void)
10687 {
10688 vfp_sp_ldstm (VFP_LDSTMIA);
10689 }
10690
10691 static void
10692 do_vfp_sp_ldstmdb (void)
10693 {
10694 vfp_sp_ldstm (VFP_LDSTMDB);
10695 }
10696
10697 static void
10698 do_vfp_dp_ldstmia (void)
10699 {
10700 vfp_dp_ldstm (VFP_LDSTMIA);
10701 }
10702
10703 static void
10704 do_vfp_dp_ldstmdb (void)
10705 {
10706 vfp_dp_ldstm (VFP_LDSTMDB);
10707 }
10708
10709 static void
10710 do_vfp_xp_ldstmia (void)
10711 {
10712 vfp_dp_ldstm (VFP_LDSTMIAX);
10713 }
10714
10715 static void
10716 do_vfp_xp_ldstmdb (void)
10717 {
10718 vfp_dp_ldstm (VFP_LDSTMDBX);
10719 }
10720
10721 static void
10722 do_vfp_dp_rd_rm (void)
10723 {
10724 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
10725 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10726 _(BAD_FPU));
10727
10728 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10729 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
10730 }
10731
10732 static void
10733 do_vfp_dp_rn_rd (void)
10734 {
10735 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
10736 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10737 }
10738
10739 static void
10740 do_vfp_dp_rd_rn (void)
10741 {
10742 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10743 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10744 }
10745
10746 static void
10747 do_vfp_dp_rd_rn_rm (void)
10748 {
10749 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10750 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10751 _(BAD_FPU));
10752
10753 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10754 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
10755 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
10756 }
10757
10758 static void
10759 do_vfp_dp_rd (void)
10760 {
10761 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10762 }
10763
10764 static void
10765 do_vfp_dp_rm_rd_rn (void)
10766 {
10767 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
10768 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
10769 _(BAD_FPU));
10770
10771 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
10772 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
10773 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
10774 }
10775
10776 /* VFPv3 instructions. */
10777 static void
10778 do_vfp_sp_const (void)
10779 {
10780 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10781 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10782 inst.instruction |= (inst.operands[1].imm & 0x0f);
10783 }
10784
10785 static void
10786 do_vfp_dp_const (void)
10787 {
10788 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10789 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
10790 inst.instruction |= (inst.operands[1].imm & 0x0f);
10791 }
10792
10793 static void
10794 vfp_conv (int srcsize)
10795 {
10796 int immbits = srcsize - inst.operands[1].imm;
10797
10798 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10799 {
10800 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
10801 i.e. immbits must be in range 0 - 16. */
10802 inst.error = _("immediate value out of range, expected range [0, 16]");
10803 return;
10804 }
10805 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
10806 {
10807 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
10808 i.e. immbits must be in range 0 - 31. */
10809 inst.error = _("immediate value out of range, expected range [1, 32]");
10810 return;
10811 }
10812
10813 inst.instruction |= (immbits & 1) << 5;
10814 inst.instruction |= (immbits >> 1);
10815 }
10816
10817 static void
10818 do_vfp_sp_conv_16 (void)
10819 {
10820 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10821 vfp_conv (16);
10822 }
10823
10824 static void
10825 do_vfp_dp_conv_16 (void)
10826 {
10827 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10828 vfp_conv (16);
10829 }
10830
10831 static void
10832 do_vfp_sp_conv_32 (void)
10833 {
10834 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10835 vfp_conv (32);
10836 }
10837
10838 static void
10839 do_vfp_dp_conv_32 (void)
10840 {
10841 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10842 vfp_conv (32);
10843 }
10844 \f
10845 /* FPA instructions. Also in a logical order. */
10846
10847 static void
10848 do_fpa_cmp (void)
10849 {
10850 inst.instruction |= inst.operands[0].reg << 16;
10851 inst.instruction |= inst.operands[1].reg;
10852 }
10853
10854 static void
10855 do_fpa_ldmstm (void)
10856 {
10857 inst.instruction |= inst.operands[0].reg << 12;
10858 switch (inst.operands[1].imm)
10859 {
10860 case 1: inst.instruction |= CP_T_X; break;
10861 case 2: inst.instruction |= CP_T_Y; break;
10862 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10863 case 4: break;
10864 default: abort ();
10865 }
10866
10867 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10868 {
10869 /* The instruction specified "ea" or "fd", so we can only accept
10870 [Rn]{!}. The instruction does not really support stacking or
10871 unstacking, so we have to emulate these by setting appropriate
10872 bits and offsets. */
10873 constraint (inst.relocs[0].exp.X_op != O_constant
10874 || inst.relocs[0].exp.X_add_number != 0,
10875 _("this instruction does not support indexing"));
10876
10877 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10878 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
10879
10880 if (!(inst.instruction & INDEX_UP))
10881 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
10882
10883 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10884 {
10885 inst.operands[2].preind = 0;
10886 inst.operands[2].postind = 1;
10887 }
10888 }
10889
10890 encode_arm_cp_address (2, TRUE, TRUE, 0);
10891 }
10892 \f
10893 /* iWMMXt instructions: strictly in alphabetical order. */
10894
10895 static void
10896 do_iwmmxt_tandorc (void)
10897 {
10898 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10899 }
10900
10901 static void
10902 do_iwmmxt_textrc (void)
10903 {
10904 inst.instruction |= inst.operands[0].reg << 12;
10905 inst.instruction |= inst.operands[1].imm;
10906 }
10907
10908 static void
10909 do_iwmmxt_textrm (void)
10910 {
10911 inst.instruction |= inst.operands[0].reg << 12;
10912 inst.instruction |= inst.operands[1].reg << 16;
10913 inst.instruction |= inst.operands[2].imm;
10914 }
10915
10916 static void
10917 do_iwmmxt_tinsr (void)
10918 {
10919 inst.instruction |= inst.operands[0].reg << 16;
10920 inst.instruction |= inst.operands[1].reg << 12;
10921 inst.instruction |= inst.operands[2].imm;
10922 }
10923
10924 static void
10925 do_iwmmxt_tmia (void)
10926 {
10927 inst.instruction |= inst.operands[0].reg << 5;
10928 inst.instruction |= inst.operands[1].reg;
10929 inst.instruction |= inst.operands[2].reg << 12;
10930 }
10931
10932 static void
10933 do_iwmmxt_waligni (void)
10934 {
10935 inst.instruction |= inst.operands[0].reg << 12;
10936 inst.instruction |= inst.operands[1].reg << 16;
10937 inst.instruction |= inst.operands[2].reg;
10938 inst.instruction |= inst.operands[3].imm << 20;
10939 }
10940
10941 static void
10942 do_iwmmxt_wmerge (void)
10943 {
10944 inst.instruction |= inst.operands[0].reg << 12;
10945 inst.instruction |= inst.operands[1].reg << 16;
10946 inst.instruction |= inst.operands[2].reg;
10947 inst.instruction |= inst.operands[3].imm << 21;
10948 }
10949
10950 static void
10951 do_iwmmxt_wmov (void)
10952 {
10953 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10954 inst.instruction |= inst.operands[0].reg << 12;
10955 inst.instruction |= inst.operands[1].reg << 16;
10956 inst.instruction |= inst.operands[1].reg;
10957 }
10958
10959 static void
10960 do_iwmmxt_wldstbh (void)
10961 {
10962 int reloc;
10963 inst.instruction |= inst.operands[0].reg << 12;
10964 if (thumb_mode)
10965 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10966 else
10967 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10968 encode_arm_cp_address (1, TRUE, FALSE, reloc);
10969 }
10970
10971 static void
10972 do_iwmmxt_wldstw (void)
10973 {
10974 /* RIWR_RIWC clears .isreg for a control register. */
10975 if (!inst.operands[0].isreg)
10976 {
10977 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10978 inst.instruction |= 0xf0000000;
10979 }
10980
10981 inst.instruction |= inst.operands[0].reg << 12;
10982 encode_arm_cp_address (1, TRUE, TRUE, 0);
10983 }
10984
10985 static void
10986 do_iwmmxt_wldstd (void)
10987 {
10988 inst.instruction |= inst.operands[0].reg << 12;
10989 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10990 && inst.operands[1].immisreg)
10991 {
10992 inst.instruction &= ~0x1a000ff;
10993 inst.instruction |= (0xfU << 28);
10994 if (inst.operands[1].preind)
10995 inst.instruction |= PRE_INDEX;
10996 if (!inst.operands[1].negative)
10997 inst.instruction |= INDEX_UP;
10998 if (inst.operands[1].writeback)
10999 inst.instruction |= WRITE_BACK;
11000 inst.instruction |= inst.operands[1].reg << 16;
11001 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11002 inst.instruction |= inst.operands[1].imm;
11003 }
11004 else
11005 encode_arm_cp_address (1, TRUE, FALSE, 0);
11006 }
11007
11008 static void
11009 do_iwmmxt_wshufh (void)
11010 {
11011 inst.instruction |= inst.operands[0].reg << 12;
11012 inst.instruction |= inst.operands[1].reg << 16;
11013 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
11014 inst.instruction |= (inst.operands[2].imm & 0x0f);
11015 }
11016
11017 static void
11018 do_iwmmxt_wzero (void)
11019 {
11020 /* WZERO reg is an alias for WANDN reg, reg, reg. */
11021 inst.instruction |= inst.operands[0].reg;
11022 inst.instruction |= inst.operands[0].reg << 12;
11023 inst.instruction |= inst.operands[0].reg << 16;
11024 }
11025
11026 static void
11027 do_iwmmxt_wrwrwr_or_imm5 (void)
11028 {
11029 if (inst.operands[2].isreg)
11030 do_rd_rn_rm ();
11031 else {
11032 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
11033 _("immediate operand requires iWMMXt2"));
11034 do_rd_rn ();
11035 if (inst.operands[2].imm == 0)
11036 {
11037 switch ((inst.instruction >> 20) & 0xf)
11038 {
11039 case 4:
11040 case 5:
11041 case 6:
11042 case 7:
11043 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
11044 inst.operands[2].imm = 16;
11045 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
11046 break;
11047 case 8:
11048 case 9:
11049 case 10:
11050 case 11:
11051 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
11052 inst.operands[2].imm = 32;
11053 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
11054 break;
11055 case 12:
11056 case 13:
11057 case 14:
11058 case 15:
11059 {
11060 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
11061 unsigned long wrn;
11062 wrn = (inst.instruction >> 16) & 0xf;
11063 inst.instruction &= 0xff0fff0f;
11064 inst.instruction |= wrn;
11065 /* Bail out here; the instruction is now assembled. */
11066 return;
11067 }
11068 }
11069 }
11070 /* Map 32 -> 0, etc. */
11071 inst.operands[2].imm &= 0x1f;
11072 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
11073 }
11074 }
11075 \f
11076 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
11077 operations first, then control, shift, and load/store. */
11078
11079 /* Insns like "foo X,Y,Z". */
11080
11081 static void
11082 do_mav_triple (void)
11083 {
11084 inst.instruction |= inst.operands[0].reg << 16;
11085 inst.instruction |= inst.operands[1].reg;
11086 inst.instruction |= inst.operands[2].reg << 12;
11087 }
11088
11089 /* Insns like "foo W,X,Y,Z".
11090 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
11091
11092 static void
11093 do_mav_quad (void)
11094 {
11095 inst.instruction |= inst.operands[0].reg << 5;
11096 inst.instruction |= inst.operands[1].reg << 12;
11097 inst.instruction |= inst.operands[2].reg << 16;
11098 inst.instruction |= inst.operands[3].reg;
11099 }
11100
11101 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
11102 static void
11103 do_mav_dspsc (void)
11104 {
11105 inst.instruction |= inst.operands[1].reg << 12;
11106 }
11107
11108 /* Maverick shift immediate instructions.
11109 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
11110 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
11111
11112 static void
11113 do_mav_shift (void)
11114 {
11115 int imm = inst.operands[2].imm;
11116
11117 inst.instruction |= inst.operands[0].reg << 12;
11118 inst.instruction |= inst.operands[1].reg << 16;
11119
11120 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
11121 Bits 5-7 of the insn should have bits 4-6 of the immediate.
11122 Bit 4 should be 0. */
11123 imm = (imm & 0xf) | ((imm & 0x70) << 1);
11124
11125 inst.instruction |= imm;
11126 }
11127 \f
11128 /* XScale instructions. Also sorted arithmetic before move. */
11129
11130 /* Xscale multiply-accumulate (argument parse)
11131 MIAcc acc0,Rm,Rs
11132 MIAPHcc acc0,Rm,Rs
11133 MIAxycc acc0,Rm,Rs. */
11134
11135 static void
11136 do_xsc_mia (void)
11137 {
11138 inst.instruction |= inst.operands[1].reg;
11139 inst.instruction |= inst.operands[2].reg << 12;
11140 }
11141
11142 /* Xscale move-accumulator-register (argument parse)
11143
11144 MARcc acc0,RdLo,RdHi. */
11145
11146 static void
11147 do_xsc_mar (void)
11148 {
11149 inst.instruction |= inst.operands[1].reg << 12;
11150 inst.instruction |= inst.operands[2].reg << 16;
11151 }
11152
11153 /* Xscale move-register-accumulator (argument parse)
11154
11155 MRAcc RdLo,RdHi,acc0. */
11156
11157 static void
11158 do_xsc_mra (void)
11159 {
11160 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
11161 inst.instruction |= inst.operands[0].reg << 12;
11162 inst.instruction |= inst.operands[1].reg << 16;
11163 }
11164 \f
11165 /* Encoding functions relevant only to Thumb. */
11166
11167 /* inst.operands[i] is a shifted-register operand; encode
11168 it into inst.instruction in the format used by Thumb32. */
11169
11170 static void
11171 encode_thumb32_shifted_operand (int i)
11172 {
11173 unsigned int value = inst.relocs[0].exp.X_add_number;
11174 unsigned int shift = inst.operands[i].shift_kind;
11175
11176 constraint (inst.operands[i].immisreg,
11177 _("shift by register not allowed in thumb mode"));
11178 inst.instruction |= inst.operands[i].reg;
11179 if (shift == SHIFT_RRX)
11180 inst.instruction |= SHIFT_ROR << 4;
11181 else
11182 {
11183 constraint (inst.relocs[0].exp.X_op != O_constant,
11184 _("expression too complex"));
11185
11186 constraint (value > 32
11187 || (value == 32 && (shift == SHIFT_LSL
11188 || shift == SHIFT_ROR)),
11189 _("shift expression is too large"));
11190
11191 if (value == 0)
11192 shift = SHIFT_LSL;
11193 else if (value == 32)
11194 value = 0;
11195
11196 inst.instruction |= shift << 4;
11197 inst.instruction |= (value & 0x1c) << 10;
11198 inst.instruction |= (value & 0x03) << 6;
11199 }
11200 }
11201
11202
11203 /* inst.operands[i] was set up by parse_address. Encode it into a
11204 Thumb32 format load or store instruction. Reject forms that cannot
11205 be used with such instructions. If is_t is true, reject forms that
11206 cannot be used with a T instruction; if is_d is true, reject forms
11207 that cannot be used with a D instruction. If it is a store insn,
11208 reject PC in Rn. */
11209
11210 static void
11211 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
11212 {
11213 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
11214
11215 constraint (!inst.operands[i].isreg,
11216 _("Instruction does not support =N addresses"));
11217
11218 inst.instruction |= inst.operands[i].reg << 16;
11219 if (inst.operands[i].immisreg)
11220 {
11221 constraint (is_pc, BAD_PC_ADDRESSING);
11222 constraint (is_t || is_d, _("cannot use register index with this instruction"));
11223 constraint (inst.operands[i].negative,
11224 _("Thumb does not support negative register indexing"));
11225 constraint (inst.operands[i].postind,
11226 _("Thumb does not support register post-indexing"));
11227 constraint (inst.operands[i].writeback,
11228 _("Thumb does not support register indexing with writeback"));
11229 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
11230 _("Thumb supports only LSL in shifted register indexing"));
11231
11232 inst.instruction |= inst.operands[i].imm;
11233 if (inst.operands[i].shifted)
11234 {
11235 constraint (inst.relocs[0].exp.X_op != O_constant,
11236 _("expression too complex"));
11237 constraint (inst.relocs[0].exp.X_add_number < 0
11238 || inst.relocs[0].exp.X_add_number > 3,
11239 _("shift out of range"));
11240 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
11241 }
11242 inst.relocs[0].type = BFD_RELOC_UNUSED;
11243 }
11244 else if (inst.operands[i].preind)
11245 {
11246 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
11247 constraint (is_t && inst.operands[i].writeback,
11248 _("cannot use writeback with this instruction"));
11249 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
11250 BAD_PC_ADDRESSING);
11251
11252 if (is_d)
11253 {
11254 inst.instruction |= 0x01000000;
11255 if (inst.operands[i].writeback)
11256 inst.instruction |= 0x00200000;
11257 }
11258 else
11259 {
11260 inst.instruction |= 0x00000c00;
11261 if (inst.operands[i].writeback)
11262 inst.instruction |= 0x00000100;
11263 }
11264 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11265 }
11266 else if (inst.operands[i].postind)
11267 {
11268 gas_assert (inst.operands[i].writeback);
11269 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
11270 constraint (is_t, _("cannot use post-indexing with this instruction"));
11271
11272 if (is_d)
11273 inst.instruction |= 0x00200000;
11274 else
11275 inst.instruction |= 0x00000900;
11276 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
11277 }
11278 else /* unindexed - only for coprocessor */
11279 inst.error = _("instruction does not accept unindexed addressing");
11280 }
11281
11282 /* Table of Thumb instructions which exist in 16- and/or 32-bit
11283 encodings (the latter only in post-V6T2 cores). The index is the
11284 value used in the insns table below. When there is more than one
11285 possible 16-bit encoding for the instruction, this table always
11286 holds variant (1).
11287 Also contains several pseudo-instructions used during relaxation. */
11288 #define T16_32_TAB \
11289 X(_adc, 4140, eb400000), \
11290 X(_adcs, 4140, eb500000), \
11291 X(_add, 1c00, eb000000), \
11292 X(_adds, 1c00, eb100000), \
11293 X(_addi, 0000, f1000000), \
11294 X(_addis, 0000, f1100000), \
11295 X(_add_pc,000f, f20f0000), \
11296 X(_add_sp,000d, f10d0000), \
11297 X(_adr, 000f, f20f0000), \
11298 X(_and, 4000, ea000000), \
11299 X(_ands, 4000, ea100000), \
11300 X(_asr, 1000, fa40f000), \
11301 X(_asrs, 1000, fa50f000), \
11302 X(_b, e000, f000b000), \
11303 X(_bcond, d000, f0008000), \
11304 X(_bf, 0000, f040e001), \
11305 X(_bfcsel,0000, f000e001), \
11306 X(_bfx, 0000, f060e001), \
11307 X(_bfl, 0000, f000c001), \
11308 X(_bflx, 0000, f070e001), \
11309 X(_bic, 4380, ea200000), \
11310 X(_bics, 4380, ea300000), \
11311 X(_cinc, 0000, ea509000), \
11312 X(_cinv, 0000, ea50a000), \
11313 X(_cmn, 42c0, eb100f00), \
11314 X(_cmp, 2800, ebb00f00), \
11315 X(_cneg, 0000, ea50b000), \
11316 X(_cpsie, b660, f3af8400), \
11317 X(_cpsid, b670, f3af8600), \
11318 X(_cpy, 4600, ea4f0000), \
11319 X(_csel, 0000, ea508000), \
11320 X(_cset, 0000, ea5f900f), \
11321 X(_csetm, 0000, ea5fa00f), \
11322 X(_csinc, 0000, ea509000), \
11323 X(_csinv, 0000, ea50a000), \
11324 X(_csneg, 0000, ea50b000), \
11325 X(_dec_sp,80dd, f1ad0d00), \
11326 X(_dls, 0000, f040e001), \
11327 X(_dlstp, 0000, f000e001), \
11328 X(_eor, 4040, ea800000), \
11329 X(_eors, 4040, ea900000), \
11330 X(_inc_sp,00dd, f10d0d00), \
11331 X(_lctp, 0000, f00fe001), \
11332 X(_ldmia, c800, e8900000), \
11333 X(_ldr, 6800, f8500000), \
11334 X(_ldrb, 7800, f8100000), \
11335 X(_ldrh, 8800, f8300000), \
11336 X(_ldrsb, 5600, f9100000), \
11337 X(_ldrsh, 5e00, f9300000), \
11338 X(_ldr_pc,4800, f85f0000), \
11339 X(_ldr_pc2,4800, f85f0000), \
11340 X(_ldr_sp,9800, f85d0000), \
11341 X(_le, 0000, f00fc001), \
11342 X(_letp, 0000, f01fc001), \
11343 X(_lsl, 0000, fa00f000), \
11344 X(_lsls, 0000, fa10f000), \
11345 X(_lsr, 0800, fa20f000), \
11346 X(_lsrs, 0800, fa30f000), \
11347 X(_mov, 2000, ea4f0000), \
11348 X(_movs, 2000, ea5f0000), \
11349 X(_mul, 4340, fb00f000), \
11350 X(_muls, 4340, ffffffff), /* no 32b muls */ \
11351 X(_mvn, 43c0, ea6f0000), \
11352 X(_mvns, 43c0, ea7f0000), \
11353 X(_neg, 4240, f1c00000), /* rsb #0 */ \
11354 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
11355 X(_orr, 4300, ea400000), \
11356 X(_orrs, 4300, ea500000), \
11357 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
11358 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
11359 X(_rev, ba00, fa90f080), \
11360 X(_rev16, ba40, fa90f090), \
11361 X(_revsh, bac0, fa90f0b0), \
11362 X(_ror, 41c0, fa60f000), \
11363 X(_rors, 41c0, fa70f000), \
11364 X(_sbc, 4180, eb600000), \
11365 X(_sbcs, 4180, eb700000), \
11366 X(_stmia, c000, e8800000), \
11367 X(_str, 6000, f8400000), \
11368 X(_strb, 7000, f8000000), \
11369 X(_strh, 8000, f8200000), \
11370 X(_str_sp,9000, f84d0000), \
11371 X(_sub, 1e00, eba00000), \
11372 X(_subs, 1e00, ebb00000), \
11373 X(_subi, 8000, f1a00000), \
11374 X(_subis, 8000, f1b00000), \
11375 X(_sxtb, b240, fa4ff080), \
11376 X(_sxth, b200, fa0ff080), \
11377 X(_tst, 4200, ea100f00), \
11378 X(_uxtb, b2c0, fa5ff080), \
11379 X(_uxth, b280, fa1ff080), \
11380 X(_nop, bf00, f3af8000), \
11381 X(_yield, bf10, f3af8001), \
11382 X(_wfe, bf20, f3af8002), \
11383 X(_wfi, bf30, f3af8003), \
11384 X(_wls, 0000, f040c001), \
11385 X(_wlstp, 0000, f000c001), \
11386 X(_sev, bf40, f3af8004), \
11387 X(_sevl, bf50, f3af8005), \
11388 X(_udf, de00, f7f0a000)
11389
11390 /* To catch errors in encoding functions, the codes are all offset by
11391 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
11392 as 16-bit instructions. */
11393 #define X(a,b,c) T_MNEM##a
11394 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
11395 #undef X
11396
11397 #define X(a,b,c) 0x##b
11398 static const unsigned short thumb_op16[] = { T16_32_TAB };
11399 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
11400 #undef X
11401
11402 #define X(a,b,c) 0x##c
11403 static const unsigned int thumb_op32[] = { T16_32_TAB };
11404 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
11405 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
11406 #undef X
11407 #undef T16_32_TAB
11408
11409 /* Thumb instruction encoders, in alphabetical order. */
11410
11411 /* ADDW or SUBW. */
11412
11413 static void
11414 do_t_add_sub_w (void)
11415 {
11416 int Rd, Rn;
11417
11418 Rd = inst.operands[0].reg;
11419 Rn = inst.operands[1].reg;
11420
11421 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
11422 is the SP-{plus,minus}-immediate form of the instruction. */
11423 if (Rn == REG_SP)
11424 constraint (Rd == REG_PC, BAD_PC);
11425 else
11426 reject_bad_reg (Rd);
11427
11428 inst.instruction |= (Rn << 16) | (Rd << 8);
11429 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11430 }
11431
11432 /* Parse an add or subtract instruction. We get here with inst.instruction
11433 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
11434
11435 static void
11436 do_t_add_sub (void)
11437 {
11438 int Rd, Rs, Rn;
11439
11440 Rd = inst.operands[0].reg;
11441 Rs = (inst.operands[1].present
11442 ? inst.operands[1].reg /* Rd, Rs, foo */
11443 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11444
11445 if (Rd == REG_PC)
11446 set_pred_insn_type_last ();
11447
11448 if (unified_syntax)
11449 {
11450 bfd_boolean flags;
11451 bfd_boolean narrow;
11452 int opcode;
11453
11454 flags = (inst.instruction == T_MNEM_adds
11455 || inst.instruction == T_MNEM_subs);
11456 if (flags)
11457 narrow = !in_pred_block ();
11458 else
11459 narrow = in_pred_block ();
11460 if (!inst.operands[2].isreg)
11461 {
11462 int add;
11463
11464 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11465 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11466
11467 add = (inst.instruction == T_MNEM_add
11468 || inst.instruction == T_MNEM_adds);
11469 opcode = 0;
11470 if (inst.size_req != 4)
11471 {
11472 /* Attempt to use a narrow opcode, with relaxation if
11473 appropriate. */
11474 if (Rd == REG_SP && Rs == REG_SP && !flags)
11475 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
11476 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
11477 opcode = T_MNEM_add_sp;
11478 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
11479 opcode = T_MNEM_add_pc;
11480 else if (Rd <= 7 && Rs <= 7 && narrow)
11481 {
11482 if (flags)
11483 opcode = add ? T_MNEM_addis : T_MNEM_subis;
11484 else
11485 opcode = add ? T_MNEM_addi : T_MNEM_subi;
11486 }
11487 if (opcode)
11488 {
11489 inst.instruction = THUMB_OP16(opcode);
11490 inst.instruction |= (Rd << 4) | Rs;
11491 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
11492 || (inst.relocs[0].type
11493 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
11494 {
11495 if (inst.size_req == 2)
11496 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11497 else
11498 inst.relax = opcode;
11499 }
11500 }
11501 else
11502 constraint (inst.size_req == 2, BAD_HIREG);
11503 }
11504 if (inst.size_req == 4
11505 || (inst.size_req != 2 && !opcode))
11506 {
11507 constraint ((inst.relocs[0].type
11508 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
11509 && (inst.relocs[0].type
11510 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
11511 THUMB1_RELOC_ONLY);
11512 if (Rd == REG_PC)
11513 {
11514 constraint (add, BAD_PC);
11515 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
11516 _("only SUBS PC, LR, #const allowed"));
11517 constraint (inst.relocs[0].exp.X_op != O_constant,
11518 _("expression too complex"));
11519 constraint (inst.relocs[0].exp.X_add_number < 0
11520 || inst.relocs[0].exp.X_add_number > 0xff,
11521 _("immediate value out of range"));
11522 inst.instruction = T2_SUBS_PC_LR
11523 | inst.relocs[0].exp.X_add_number;
11524 inst.relocs[0].type = BFD_RELOC_UNUSED;
11525 return;
11526 }
11527 else if (Rs == REG_PC)
11528 {
11529 /* Always use addw/subw. */
11530 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
11531 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
11532 }
11533 else
11534 {
11535 inst.instruction = THUMB_OP32 (inst.instruction);
11536 inst.instruction = (inst.instruction & 0xe1ffffff)
11537 | 0x10000000;
11538 if (flags)
11539 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11540 else
11541 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
11542 }
11543 inst.instruction |= Rd << 8;
11544 inst.instruction |= Rs << 16;
11545 }
11546 }
11547 else
11548 {
11549 unsigned int value = inst.relocs[0].exp.X_add_number;
11550 unsigned int shift = inst.operands[2].shift_kind;
11551
11552 Rn = inst.operands[2].reg;
11553 /* See if we can do this with a 16-bit instruction. */
11554 if (!inst.operands[2].shifted && inst.size_req != 4)
11555 {
11556 if (Rd > 7 || Rs > 7 || Rn > 7)
11557 narrow = FALSE;
11558
11559 if (narrow)
11560 {
11561 inst.instruction = ((inst.instruction == T_MNEM_adds
11562 || inst.instruction == T_MNEM_add)
11563 ? T_OPCODE_ADD_R3
11564 : T_OPCODE_SUB_R3);
11565 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11566 return;
11567 }
11568
11569 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
11570 {
11571 /* Thumb-1 cores (except v6-M) require at least one high
11572 register in a narrow non flag setting add. */
11573 if (Rd > 7 || Rn > 7
11574 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
11575 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
11576 {
11577 if (Rd == Rn)
11578 {
11579 Rn = Rs;
11580 Rs = Rd;
11581 }
11582 inst.instruction = T_OPCODE_ADD_HI;
11583 inst.instruction |= (Rd & 8) << 4;
11584 inst.instruction |= (Rd & 7);
11585 inst.instruction |= Rn << 3;
11586 return;
11587 }
11588 }
11589 }
11590
11591 constraint (Rd == REG_PC, BAD_PC);
11592 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
11593 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
11594 constraint (Rs == REG_PC, BAD_PC);
11595 reject_bad_reg (Rn);
11596
11597 /* If we get here, it can't be done in 16 bits. */
11598 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
11599 _("shift must be constant"));
11600 inst.instruction = THUMB_OP32 (inst.instruction);
11601 inst.instruction |= Rd << 8;
11602 inst.instruction |= Rs << 16;
11603 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
11604 _("shift value over 3 not allowed in thumb mode"));
11605 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
11606 _("only LSL shift allowed in thumb mode"));
11607 encode_thumb32_shifted_operand (2);
11608 }
11609 }
11610 else
11611 {
11612 constraint (inst.instruction == T_MNEM_adds
11613 || inst.instruction == T_MNEM_subs,
11614 BAD_THUMB32);
11615
11616 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
11617 {
11618 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
11619 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
11620 BAD_HIREG);
11621
11622 inst.instruction = (inst.instruction == T_MNEM_add
11623 ? 0x0000 : 0x8000);
11624 inst.instruction |= (Rd << 4) | Rs;
11625 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11626 return;
11627 }
11628
11629 Rn = inst.operands[2].reg;
11630 constraint (inst.operands[2].shifted, _("unshifted register required"));
11631
11632 /* We now have Rd, Rs, and Rn set to registers. */
11633 if (Rd > 7 || Rs > 7 || Rn > 7)
11634 {
11635 /* Can't do this for SUB. */
11636 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
11637 inst.instruction = T_OPCODE_ADD_HI;
11638 inst.instruction |= (Rd & 8) << 4;
11639 inst.instruction |= (Rd & 7);
11640 if (Rs == Rd)
11641 inst.instruction |= Rn << 3;
11642 else if (Rn == Rd)
11643 inst.instruction |= Rs << 3;
11644 else
11645 constraint (1, _("dest must overlap one source register"));
11646 }
11647 else
11648 {
11649 inst.instruction = (inst.instruction == T_MNEM_add
11650 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
11651 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
11652 }
11653 }
11654 }
11655
11656 static void
11657 do_t_adr (void)
11658 {
11659 unsigned Rd;
11660
11661 Rd = inst.operands[0].reg;
11662 reject_bad_reg (Rd);
11663
11664 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
11665 {
11666 /* Defer to section relaxation. */
11667 inst.relax = inst.instruction;
11668 inst.instruction = THUMB_OP16 (inst.instruction);
11669 inst.instruction |= Rd << 4;
11670 }
11671 else if (unified_syntax && inst.size_req != 2)
11672 {
11673 /* Generate a 32-bit opcode. */
11674 inst.instruction = THUMB_OP32 (inst.instruction);
11675 inst.instruction |= Rd << 8;
11676 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
11677 inst.relocs[0].pc_rel = 1;
11678 }
11679 else
11680 {
11681 /* Generate a 16-bit opcode. */
11682 inst.instruction = THUMB_OP16 (inst.instruction);
11683 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
11684 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
11685 inst.relocs[0].pc_rel = 1;
11686 inst.instruction |= Rd << 4;
11687 }
11688
11689 if (inst.relocs[0].exp.X_op == O_symbol
11690 && inst.relocs[0].exp.X_add_symbol != NULL
11691 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11692 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11693 inst.relocs[0].exp.X_add_number += 1;
11694 }
11695
11696 /* Arithmetic instructions for which there is just one 16-bit
11697 instruction encoding, and it allows only two low registers.
11698 For maximal compatibility with ARM syntax, we allow three register
11699 operands even when Thumb-32 instructions are not available, as long
11700 as the first two are identical. For instance, both "sbc r0,r1" and
11701 "sbc r0,r0,r1" are allowed. */
11702 static void
11703 do_t_arit3 (void)
11704 {
11705 int Rd, Rs, Rn;
11706
11707 Rd = inst.operands[0].reg;
11708 Rs = (inst.operands[1].present
11709 ? inst.operands[1].reg /* Rd, Rs, foo */
11710 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11711 Rn = inst.operands[2].reg;
11712
11713 reject_bad_reg (Rd);
11714 reject_bad_reg (Rs);
11715 if (inst.operands[2].isreg)
11716 reject_bad_reg (Rn);
11717
11718 if (unified_syntax)
11719 {
11720 if (!inst.operands[2].isreg)
11721 {
11722 /* For an immediate, we always generate a 32-bit opcode;
11723 section relaxation will shrink it later if possible. */
11724 inst.instruction = THUMB_OP32 (inst.instruction);
11725 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11726 inst.instruction |= Rd << 8;
11727 inst.instruction |= Rs << 16;
11728 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11729 }
11730 else
11731 {
11732 bfd_boolean narrow;
11733
11734 /* See if we can do this with a 16-bit instruction. */
11735 if (THUMB_SETS_FLAGS (inst.instruction))
11736 narrow = !in_pred_block ();
11737 else
11738 narrow = in_pred_block ();
11739
11740 if (Rd > 7 || Rn > 7 || Rs > 7)
11741 narrow = FALSE;
11742 if (inst.operands[2].shifted)
11743 narrow = FALSE;
11744 if (inst.size_req == 4)
11745 narrow = FALSE;
11746
11747 if (narrow
11748 && Rd == Rs)
11749 {
11750 inst.instruction = THUMB_OP16 (inst.instruction);
11751 inst.instruction |= Rd;
11752 inst.instruction |= Rn << 3;
11753 return;
11754 }
11755
11756 /* If we get here, it can't be done in 16 bits. */
11757 constraint (inst.operands[2].shifted
11758 && inst.operands[2].immisreg,
11759 _("shift must be constant"));
11760 inst.instruction = THUMB_OP32 (inst.instruction);
11761 inst.instruction |= Rd << 8;
11762 inst.instruction |= Rs << 16;
11763 encode_thumb32_shifted_operand (2);
11764 }
11765 }
11766 else
11767 {
11768 /* On its face this is a lie - the instruction does set the
11769 flags. However, the only supported mnemonic in this mode
11770 says it doesn't. */
11771 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11772
11773 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11774 _("unshifted register required"));
11775 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11776 constraint (Rd != Rs,
11777 _("dest and source1 must be the same register"));
11778
11779 inst.instruction = THUMB_OP16 (inst.instruction);
11780 inst.instruction |= Rd;
11781 inst.instruction |= Rn << 3;
11782 }
11783 }
11784
11785 /* Similarly, but for instructions where the arithmetic operation is
11786 commutative, so we can allow either of them to be different from
11787 the destination operand in a 16-bit instruction. For instance, all
11788 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
11789 accepted. */
11790 static void
11791 do_t_arit3c (void)
11792 {
11793 int Rd, Rs, Rn;
11794
11795 Rd = inst.operands[0].reg;
11796 Rs = (inst.operands[1].present
11797 ? inst.operands[1].reg /* Rd, Rs, foo */
11798 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11799 Rn = inst.operands[2].reg;
11800
11801 reject_bad_reg (Rd);
11802 reject_bad_reg (Rs);
11803 if (inst.operands[2].isreg)
11804 reject_bad_reg (Rn);
11805
11806 if (unified_syntax)
11807 {
11808 if (!inst.operands[2].isreg)
11809 {
11810 /* For an immediate, we always generate a 32-bit opcode;
11811 section relaxation will shrink it later if possible. */
11812 inst.instruction = THUMB_OP32 (inst.instruction);
11813 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11814 inst.instruction |= Rd << 8;
11815 inst.instruction |= Rs << 16;
11816 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11817 }
11818 else
11819 {
11820 bfd_boolean narrow;
11821
11822 /* See if we can do this with a 16-bit instruction. */
11823 if (THUMB_SETS_FLAGS (inst.instruction))
11824 narrow = !in_pred_block ();
11825 else
11826 narrow = in_pred_block ();
11827
11828 if (Rd > 7 || Rn > 7 || Rs > 7)
11829 narrow = FALSE;
11830 if (inst.operands[2].shifted)
11831 narrow = FALSE;
11832 if (inst.size_req == 4)
11833 narrow = FALSE;
11834
11835 if (narrow)
11836 {
11837 if (Rd == Rs)
11838 {
11839 inst.instruction = THUMB_OP16 (inst.instruction);
11840 inst.instruction |= Rd;
11841 inst.instruction |= Rn << 3;
11842 return;
11843 }
11844 if (Rd == Rn)
11845 {
11846 inst.instruction = THUMB_OP16 (inst.instruction);
11847 inst.instruction |= Rd;
11848 inst.instruction |= Rs << 3;
11849 return;
11850 }
11851 }
11852
11853 /* If we get here, it can't be done in 16 bits. */
11854 constraint (inst.operands[2].shifted
11855 && inst.operands[2].immisreg,
11856 _("shift must be constant"));
11857 inst.instruction = THUMB_OP32 (inst.instruction);
11858 inst.instruction |= Rd << 8;
11859 inst.instruction |= Rs << 16;
11860 encode_thumb32_shifted_operand (2);
11861 }
11862 }
11863 else
11864 {
11865 /* On its face this is a lie - the instruction does set the
11866 flags. However, the only supported mnemonic in this mode
11867 says it doesn't. */
11868 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11869
11870 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11871 _("unshifted register required"));
11872 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11873
11874 inst.instruction = THUMB_OP16 (inst.instruction);
11875 inst.instruction |= Rd;
11876
11877 if (Rd == Rs)
11878 inst.instruction |= Rn << 3;
11879 else if (Rd == Rn)
11880 inst.instruction |= Rs << 3;
11881 else
11882 constraint (1, _("dest must overlap one source register"));
11883 }
11884 }
11885
11886 static void
11887 do_t_bfc (void)
11888 {
11889 unsigned Rd;
11890 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11891 constraint (msb > 32, _("bit-field extends past end of register"));
11892 /* The instruction encoding stores the LSB and MSB,
11893 not the LSB and width. */
11894 Rd = inst.operands[0].reg;
11895 reject_bad_reg (Rd);
11896 inst.instruction |= Rd << 8;
11897 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11898 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11899 inst.instruction |= msb - 1;
11900 }
11901
11902 static void
11903 do_t_bfi (void)
11904 {
11905 int Rd, Rn;
11906 unsigned int msb;
11907
11908 Rd = inst.operands[0].reg;
11909 reject_bad_reg (Rd);
11910
11911 /* #0 in second position is alternative syntax for bfc, which is
11912 the same instruction but with REG_PC in the Rm field. */
11913 if (!inst.operands[1].isreg)
11914 Rn = REG_PC;
11915 else
11916 {
11917 Rn = inst.operands[1].reg;
11918 reject_bad_reg (Rn);
11919 }
11920
11921 msb = inst.operands[2].imm + inst.operands[3].imm;
11922 constraint (msb > 32, _("bit-field extends past end of register"));
11923 /* The instruction encoding stores the LSB and MSB,
11924 not the LSB and width. */
11925 inst.instruction |= Rd << 8;
11926 inst.instruction |= Rn << 16;
11927 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11928 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11929 inst.instruction |= msb - 1;
11930 }
11931
11932 static void
11933 do_t_bfx (void)
11934 {
11935 unsigned Rd, Rn;
11936
11937 Rd = inst.operands[0].reg;
11938 Rn = inst.operands[1].reg;
11939
11940 reject_bad_reg (Rd);
11941 reject_bad_reg (Rn);
11942
11943 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11944 _("bit-field extends past end of register"));
11945 inst.instruction |= Rd << 8;
11946 inst.instruction |= Rn << 16;
11947 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11948 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11949 inst.instruction |= inst.operands[3].imm - 1;
11950 }
11951
11952 /* ARM V5 Thumb BLX (argument parse)
11953 BLX <target_addr> which is BLX(1)
11954 BLX <Rm> which is BLX(2)
11955 Unfortunately, there are two different opcodes for this mnemonic.
11956 So, the insns[].value is not used, and the code here zaps values
11957 into inst.instruction.
11958
11959 ??? How to take advantage of the additional two bits of displacement
11960 available in Thumb32 mode? Need new relocation? */
11961
11962 static void
11963 do_t_blx (void)
11964 {
11965 set_pred_insn_type_last ();
11966
11967 if (inst.operands[0].isreg)
11968 {
11969 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11970 /* We have a register, so this is BLX(2). */
11971 inst.instruction |= inst.operands[0].reg << 3;
11972 }
11973 else
11974 {
11975 /* No register. This must be BLX(1). */
11976 inst.instruction = 0xf000e800;
11977 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
11978 }
11979 }
11980
11981 static void
11982 do_t_branch (void)
11983 {
11984 int opcode;
11985 int cond;
11986 bfd_reloc_code_real_type reloc;
11987
11988 cond = inst.cond;
11989 set_pred_insn_type (IF_INSIDE_IT_LAST_INSN);
11990
11991 if (in_pred_block ())
11992 {
11993 /* Conditional branches inside IT blocks are encoded as unconditional
11994 branches. */
11995 cond = COND_ALWAYS;
11996 }
11997 else
11998 cond = inst.cond;
11999
12000 if (cond != COND_ALWAYS)
12001 opcode = T_MNEM_bcond;
12002 else
12003 opcode = inst.instruction;
12004
12005 if (unified_syntax
12006 && (inst.size_req == 4
12007 || (inst.size_req != 2
12008 && (inst.operands[0].hasreloc
12009 || inst.relocs[0].exp.X_op == O_constant))))
12010 {
12011 inst.instruction = THUMB_OP32(opcode);
12012 if (cond == COND_ALWAYS)
12013 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
12014 else
12015 {
12016 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
12017 _("selected architecture does not support "
12018 "wide conditional branch instruction"));
12019
12020 gas_assert (cond != 0xF);
12021 inst.instruction |= cond << 22;
12022 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
12023 }
12024 }
12025 else
12026 {
12027 inst.instruction = THUMB_OP16(opcode);
12028 if (cond == COND_ALWAYS)
12029 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
12030 else
12031 {
12032 inst.instruction |= cond << 8;
12033 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
12034 }
12035 /* Allow section relaxation. */
12036 if (unified_syntax && inst.size_req != 2)
12037 inst.relax = opcode;
12038 }
12039 inst.relocs[0].type = reloc;
12040 inst.relocs[0].pc_rel = 1;
12041 }
12042
12043 /* Actually do the work for Thumb state bkpt and hlt. The only difference
12044 between the two is the maximum immediate allowed - which is passed in
12045 RANGE. */
12046 static void
12047 do_t_bkpt_hlt1 (int range)
12048 {
12049 constraint (inst.cond != COND_ALWAYS,
12050 _("instruction is always unconditional"));
12051 if (inst.operands[0].present)
12052 {
12053 constraint (inst.operands[0].imm > range,
12054 _("immediate value out of range"));
12055 inst.instruction |= inst.operands[0].imm;
12056 }
12057
12058 set_pred_insn_type (NEUTRAL_IT_INSN);
12059 }
12060
12061 static void
12062 do_t_hlt (void)
12063 {
12064 do_t_bkpt_hlt1 (63);
12065 }
12066
12067 static void
12068 do_t_bkpt (void)
12069 {
12070 do_t_bkpt_hlt1 (255);
12071 }
12072
12073 static void
12074 do_t_branch23 (void)
12075 {
12076 set_pred_insn_type_last ();
12077 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
12078
12079 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
12080 this file. We used to simply ignore the PLT reloc type here --
12081 the branch encoding is now needed to deal with TLSCALL relocs.
12082 So if we see a PLT reloc now, put it back to how it used to be to
12083 keep the preexisting behaviour. */
12084 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
12085 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
12086
12087 #if defined(OBJ_COFF)
12088 /* If the destination of the branch is a defined symbol which does not have
12089 the THUMB_FUNC attribute, then we must be calling a function which has
12090 the (interfacearm) attribute. We look for the Thumb entry point to that
12091 function and change the branch to refer to that function instead. */
12092 if ( inst.relocs[0].exp.X_op == O_symbol
12093 && inst.relocs[0].exp.X_add_symbol != NULL
12094 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
12095 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
12096 inst.relocs[0].exp.X_add_symbol
12097 = find_real_start (inst.relocs[0].exp.X_add_symbol);
12098 #endif
12099 }
12100
12101 static void
12102 do_t_bx (void)
12103 {
12104 set_pred_insn_type_last ();
12105 inst.instruction |= inst.operands[0].reg << 3;
12106 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
12107 should cause the alignment to be checked once it is known. This is
12108 because BX PC only works if the instruction is word aligned. */
12109 }
12110
12111 static void
12112 do_t_bxj (void)
12113 {
12114 int Rm;
12115
12116 set_pred_insn_type_last ();
12117 Rm = inst.operands[0].reg;
12118 reject_bad_reg (Rm);
12119 inst.instruction |= Rm << 16;
12120 }
12121
12122 static void
12123 do_t_clz (void)
12124 {
12125 unsigned Rd;
12126 unsigned Rm;
12127
12128 Rd = inst.operands[0].reg;
12129 Rm = inst.operands[1].reg;
12130
12131 reject_bad_reg (Rd);
12132 reject_bad_reg (Rm);
12133
12134 inst.instruction |= Rd << 8;
12135 inst.instruction |= Rm << 16;
12136 inst.instruction |= Rm;
12137 }
12138
12139 /* For the Armv8.1-M conditional instructions. */
12140 static void
12141 do_t_cond (void)
12142 {
12143 unsigned Rd, Rn, Rm;
12144 signed int cond;
12145
12146 constraint (inst.cond != COND_ALWAYS, BAD_COND);
12147
12148 Rd = inst.operands[0].reg;
12149 switch (inst.instruction)
12150 {
12151 case T_MNEM_csinc:
12152 case T_MNEM_csinv:
12153 case T_MNEM_csneg:
12154 case T_MNEM_csel:
12155 Rn = inst.operands[1].reg;
12156 Rm = inst.operands[2].reg;
12157 cond = inst.operands[3].imm;
12158 constraint (Rn == REG_SP, BAD_SP);
12159 constraint (Rm == REG_SP, BAD_SP);
12160 break;
12161
12162 case T_MNEM_cinc:
12163 case T_MNEM_cinv:
12164 case T_MNEM_cneg:
12165 Rn = inst.operands[1].reg;
12166 cond = inst.operands[2].imm;
12167 /* Invert the last bit to invert the cond. */
12168 cond = TOGGLE_BIT (cond, 0);
12169 constraint (Rn == REG_SP, BAD_SP);
12170 Rm = Rn;
12171 break;
12172
12173 case T_MNEM_csetm:
12174 case T_MNEM_cset:
12175 cond = inst.operands[1].imm;
12176 /* Invert the last bit to invert the cond. */
12177 cond = TOGGLE_BIT (cond, 0);
12178 Rn = REG_PC;
12179 Rm = REG_PC;
12180 break;
12181
12182 default: abort ();
12183 }
12184
12185 set_pred_insn_type (OUTSIDE_PRED_INSN);
12186 inst.instruction = THUMB_OP32 (inst.instruction);
12187 inst.instruction |= Rd << 8;
12188 inst.instruction |= Rn << 16;
12189 inst.instruction |= Rm;
12190 inst.instruction |= cond << 4;
12191 }
12192
12193 static void
12194 do_t_csdb (void)
12195 {
12196 set_pred_insn_type (OUTSIDE_PRED_INSN);
12197 }
12198
12199 static void
12200 do_t_cps (void)
12201 {
12202 set_pred_insn_type (OUTSIDE_PRED_INSN);
12203 inst.instruction |= inst.operands[0].imm;
12204 }
12205
12206 static void
12207 do_t_cpsi (void)
12208 {
12209 set_pred_insn_type (OUTSIDE_PRED_INSN);
12210 if (unified_syntax
12211 && (inst.operands[1].present || inst.size_req == 4)
12212 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
12213 {
12214 unsigned int imod = (inst.instruction & 0x0030) >> 4;
12215 inst.instruction = 0xf3af8000;
12216 inst.instruction |= imod << 9;
12217 inst.instruction |= inst.operands[0].imm << 5;
12218 if (inst.operands[1].present)
12219 inst.instruction |= 0x100 | inst.operands[1].imm;
12220 }
12221 else
12222 {
12223 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
12224 && (inst.operands[0].imm & 4),
12225 _("selected processor does not support 'A' form "
12226 "of this instruction"));
12227 constraint (inst.operands[1].present || inst.size_req == 4,
12228 _("Thumb does not support the 2-argument "
12229 "form of this instruction"));
12230 inst.instruction |= inst.operands[0].imm;
12231 }
12232 }
12233
12234 /* THUMB CPY instruction (argument parse). */
12235
12236 static void
12237 do_t_cpy (void)
12238 {
12239 if (inst.size_req == 4)
12240 {
12241 inst.instruction = THUMB_OP32 (T_MNEM_mov);
12242 inst.instruction |= inst.operands[0].reg << 8;
12243 inst.instruction |= inst.operands[1].reg;
12244 }
12245 else
12246 {
12247 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
12248 inst.instruction |= (inst.operands[0].reg & 0x7);
12249 inst.instruction |= inst.operands[1].reg << 3;
12250 }
12251 }
12252
12253 static void
12254 do_t_cbz (void)
12255 {
12256 set_pred_insn_type (OUTSIDE_PRED_INSN);
12257 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12258 inst.instruction |= inst.operands[0].reg;
12259 inst.relocs[0].pc_rel = 1;
12260 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
12261 }
12262
12263 static void
12264 do_t_dbg (void)
12265 {
12266 inst.instruction |= inst.operands[0].imm;
12267 }
12268
12269 static void
12270 do_t_div (void)
12271 {
12272 unsigned Rd, Rn, Rm;
12273
12274 Rd = inst.operands[0].reg;
12275 Rn = (inst.operands[1].present
12276 ? inst.operands[1].reg : Rd);
12277 Rm = inst.operands[2].reg;
12278
12279 reject_bad_reg (Rd);
12280 reject_bad_reg (Rn);
12281 reject_bad_reg (Rm);
12282
12283 inst.instruction |= Rd << 8;
12284 inst.instruction |= Rn << 16;
12285 inst.instruction |= Rm;
12286 }
12287
12288 static void
12289 do_t_hint (void)
12290 {
12291 if (unified_syntax && inst.size_req == 4)
12292 inst.instruction = THUMB_OP32 (inst.instruction);
12293 else
12294 inst.instruction = THUMB_OP16 (inst.instruction);
12295 }
12296
12297 static void
12298 do_t_it (void)
12299 {
12300 unsigned int cond = inst.operands[0].imm;
12301
12302 set_pred_insn_type (IT_INSN);
12303 now_pred.mask = (inst.instruction & 0xf) | 0x10;
12304 now_pred.cc = cond;
12305 now_pred.warn_deprecated = FALSE;
12306 now_pred.type = SCALAR_PRED;
12307
12308 /* If the condition is a negative condition, invert the mask. */
12309 if ((cond & 0x1) == 0x0)
12310 {
12311 unsigned int mask = inst.instruction & 0x000f;
12312
12313 if ((mask & 0x7) == 0)
12314 {
12315 /* No conversion needed. */
12316 now_pred.block_length = 1;
12317 }
12318 else if ((mask & 0x3) == 0)
12319 {
12320 mask ^= 0x8;
12321 now_pred.block_length = 2;
12322 }
12323 else if ((mask & 0x1) == 0)
12324 {
12325 mask ^= 0xC;
12326 now_pred.block_length = 3;
12327 }
12328 else
12329 {
12330 mask ^= 0xE;
12331 now_pred.block_length = 4;
12332 }
12333
12334 inst.instruction &= 0xfff0;
12335 inst.instruction |= mask;
12336 }
12337
12338 inst.instruction |= cond << 4;
12339 }
12340
12341 /* Helper function used for both push/pop and ldm/stm. */
12342 static void
12343 encode_thumb2_multi (bfd_boolean do_io, int base, unsigned mask,
12344 bfd_boolean writeback)
12345 {
12346 bfd_boolean load, store;
12347
12348 gas_assert (base != -1 || !do_io);
12349 load = do_io && ((inst.instruction & (1 << 20)) != 0);
12350 store = do_io && !load;
12351
12352 if (mask & (1 << 13))
12353 inst.error = _("SP not allowed in register list");
12354
12355 if (do_io && (mask & (1 << base)) != 0
12356 && writeback)
12357 inst.error = _("having the base register in the register list when "
12358 "using write back is UNPREDICTABLE");
12359
12360 if (load)
12361 {
12362 if (mask & (1 << 15))
12363 {
12364 if (mask & (1 << 14))
12365 inst.error = _("LR and PC should not both be in register list");
12366 else
12367 set_pred_insn_type_last ();
12368 }
12369 }
12370 else if (store)
12371 {
12372 if (mask & (1 << 15))
12373 inst.error = _("PC not allowed in register list");
12374 }
12375
12376 if (do_io && ((mask & (mask - 1)) == 0))
12377 {
12378 /* Single register transfers implemented as str/ldr. */
12379 if (writeback)
12380 {
12381 if (inst.instruction & (1 << 23))
12382 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
12383 else
12384 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
12385 }
12386 else
12387 {
12388 if (inst.instruction & (1 << 23))
12389 inst.instruction = 0x00800000; /* ia -> [base] */
12390 else
12391 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
12392 }
12393
12394 inst.instruction |= 0xf8400000;
12395 if (load)
12396 inst.instruction |= 0x00100000;
12397
12398 mask = ffs (mask) - 1;
12399 mask <<= 12;
12400 }
12401 else if (writeback)
12402 inst.instruction |= WRITE_BACK;
12403
12404 inst.instruction |= mask;
12405 if (do_io)
12406 inst.instruction |= base << 16;
12407 }
12408
12409 static void
12410 do_t_ldmstm (void)
12411 {
12412 /* This really doesn't seem worth it. */
12413 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
12414 _("expression too complex"));
12415 constraint (inst.operands[1].writeback,
12416 _("Thumb load/store multiple does not support {reglist}^"));
12417
12418 if (unified_syntax)
12419 {
12420 bfd_boolean narrow;
12421 unsigned mask;
12422
12423 narrow = FALSE;
12424 /* See if we can use a 16-bit instruction. */
12425 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
12426 && inst.size_req != 4
12427 && !(inst.operands[1].imm & ~0xff))
12428 {
12429 mask = 1 << inst.operands[0].reg;
12430
12431 if (inst.operands[0].reg <= 7)
12432 {
12433 if (inst.instruction == T_MNEM_stmia
12434 ? inst.operands[0].writeback
12435 : (inst.operands[0].writeback
12436 == !(inst.operands[1].imm & mask)))
12437 {
12438 if (inst.instruction == T_MNEM_stmia
12439 && (inst.operands[1].imm & mask)
12440 && (inst.operands[1].imm & (mask - 1)))
12441 as_warn (_("value stored for r%d is UNKNOWN"),
12442 inst.operands[0].reg);
12443
12444 inst.instruction = THUMB_OP16 (inst.instruction);
12445 inst.instruction |= inst.operands[0].reg << 8;
12446 inst.instruction |= inst.operands[1].imm;
12447 narrow = TRUE;
12448 }
12449 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12450 {
12451 /* This means 1 register in reg list one of 3 situations:
12452 1. Instruction is stmia, but without writeback.
12453 2. lmdia without writeback, but with Rn not in
12454 reglist.
12455 3. ldmia with writeback, but with Rn in reglist.
12456 Case 3 is UNPREDICTABLE behaviour, so we handle
12457 case 1 and 2 which can be converted into a 16-bit
12458 str or ldr. The SP cases are handled below. */
12459 unsigned long opcode;
12460 /* First, record an error for Case 3. */
12461 if (inst.operands[1].imm & mask
12462 && inst.operands[0].writeback)
12463 inst.error =
12464 _("having the base register in the register list when "
12465 "using write back is UNPREDICTABLE");
12466
12467 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
12468 : T_MNEM_ldr);
12469 inst.instruction = THUMB_OP16 (opcode);
12470 inst.instruction |= inst.operands[0].reg << 3;
12471 inst.instruction |= (ffs (inst.operands[1].imm)-1);
12472 narrow = TRUE;
12473 }
12474 }
12475 else if (inst.operands[0] .reg == REG_SP)
12476 {
12477 if (inst.operands[0].writeback)
12478 {
12479 inst.instruction =
12480 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12481 ? T_MNEM_push : T_MNEM_pop);
12482 inst.instruction |= inst.operands[1].imm;
12483 narrow = TRUE;
12484 }
12485 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
12486 {
12487 inst.instruction =
12488 THUMB_OP16 (inst.instruction == T_MNEM_stmia
12489 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
12490 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
12491 narrow = TRUE;
12492 }
12493 }
12494 }
12495
12496 if (!narrow)
12497 {
12498 if (inst.instruction < 0xffff)
12499 inst.instruction = THUMB_OP32 (inst.instruction);
12500
12501 encode_thumb2_multi (TRUE /* do_io */, inst.operands[0].reg,
12502 inst.operands[1].imm,
12503 inst.operands[0].writeback);
12504 }
12505 }
12506 else
12507 {
12508 constraint (inst.operands[0].reg > 7
12509 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
12510 constraint (inst.instruction != T_MNEM_ldmia
12511 && inst.instruction != T_MNEM_stmia,
12512 _("Thumb-2 instruction only valid in unified syntax"));
12513 if (inst.instruction == T_MNEM_stmia)
12514 {
12515 if (!inst.operands[0].writeback)
12516 as_warn (_("this instruction will write back the base register"));
12517 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
12518 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
12519 as_warn (_("value stored for r%d is UNKNOWN"),
12520 inst.operands[0].reg);
12521 }
12522 else
12523 {
12524 if (!inst.operands[0].writeback
12525 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
12526 as_warn (_("this instruction will write back the base register"));
12527 else if (inst.operands[0].writeback
12528 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
12529 as_warn (_("this instruction will not write back the base register"));
12530 }
12531
12532 inst.instruction = THUMB_OP16 (inst.instruction);
12533 inst.instruction |= inst.operands[0].reg << 8;
12534 inst.instruction |= inst.operands[1].imm;
12535 }
12536 }
12537
12538 static void
12539 do_t_ldrex (void)
12540 {
12541 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
12542 || inst.operands[1].postind || inst.operands[1].writeback
12543 || inst.operands[1].immisreg || inst.operands[1].shifted
12544 || inst.operands[1].negative,
12545 BAD_ADDR_MODE);
12546
12547 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
12548
12549 inst.instruction |= inst.operands[0].reg << 12;
12550 inst.instruction |= inst.operands[1].reg << 16;
12551 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
12552 }
12553
12554 static void
12555 do_t_ldrexd (void)
12556 {
12557 if (!inst.operands[1].present)
12558 {
12559 constraint (inst.operands[0].reg == REG_LR,
12560 _("r14 not allowed as first register "
12561 "when second register is omitted"));
12562 inst.operands[1].reg = inst.operands[0].reg + 1;
12563 }
12564 constraint (inst.operands[0].reg == inst.operands[1].reg,
12565 BAD_OVERLAP);
12566
12567 inst.instruction |= inst.operands[0].reg << 12;
12568 inst.instruction |= inst.operands[1].reg << 8;
12569 inst.instruction |= inst.operands[2].reg << 16;
12570 }
12571
12572 static void
12573 do_t_ldst (void)
12574 {
12575 unsigned long opcode;
12576 int Rn;
12577
12578 if (inst.operands[0].isreg
12579 && !inst.operands[0].preind
12580 && inst.operands[0].reg == REG_PC)
12581 set_pred_insn_type_last ();
12582
12583 opcode = inst.instruction;
12584 if (unified_syntax)
12585 {
12586 if (!inst.operands[1].isreg)
12587 {
12588 if (opcode <= 0xffff)
12589 inst.instruction = THUMB_OP32 (opcode);
12590 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
12591 return;
12592 }
12593 if (inst.operands[1].isreg
12594 && !inst.operands[1].writeback
12595 && !inst.operands[1].shifted && !inst.operands[1].postind
12596 && !inst.operands[1].negative && inst.operands[0].reg <= 7
12597 && opcode <= 0xffff
12598 && inst.size_req != 4)
12599 {
12600 /* Insn may have a 16-bit form. */
12601 Rn = inst.operands[1].reg;
12602 if (inst.operands[1].immisreg)
12603 {
12604 inst.instruction = THUMB_OP16 (opcode);
12605 /* [Rn, Rik] */
12606 if (Rn <= 7 && inst.operands[1].imm <= 7)
12607 goto op16;
12608 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
12609 reject_bad_reg (inst.operands[1].imm);
12610 }
12611 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
12612 && opcode != T_MNEM_ldrsb)
12613 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
12614 || (Rn == REG_SP && opcode == T_MNEM_str))
12615 {
12616 /* [Rn, #const] */
12617 if (Rn > 7)
12618 {
12619 if (Rn == REG_PC)
12620 {
12621 if (inst.relocs[0].pc_rel)
12622 opcode = T_MNEM_ldr_pc2;
12623 else
12624 opcode = T_MNEM_ldr_pc;
12625 }
12626 else
12627 {
12628 if (opcode == T_MNEM_ldr)
12629 opcode = T_MNEM_ldr_sp;
12630 else
12631 opcode = T_MNEM_str_sp;
12632 }
12633 inst.instruction = inst.operands[0].reg << 8;
12634 }
12635 else
12636 {
12637 inst.instruction = inst.operands[0].reg;
12638 inst.instruction |= inst.operands[1].reg << 3;
12639 }
12640 inst.instruction |= THUMB_OP16 (opcode);
12641 if (inst.size_req == 2)
12642 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12643 else
12644 inst.relax = opcode;
12645 return;
12646 }
12647 }
12648 /* Definitely a 32-bit variant. */
12649
12650 /* Warning for Erratum 752419. */
12651 if (opcode == T_MNEM_ldr
12652 && inst.operands[0].reg == REG_SP
12653 && inst.operands[1].writeback == 1
12654 && !inst.operands[1].immisreg)
12655 {
12656 if (no_cpu_selected ()
12657 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
12658 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
12659 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
12660 as_warn (_("This instruction may be unpredictable "
12661 "if executed on M-profile cores "
12662 "with interrupts enabled."));
12663 }
12664
12665 /* Do some validations regarding addressing modes. */
12666 if (inst.operands[1].immisreg)
12667 reject_bad_reg (inst.operands[1].imm);
12668
12669 constraint (inst.operands[1].writeback == 1
12670 && inst.operands[0].reg == inst.operands[1].reg,
12671 BAD_OVERLAP);
12672
12673 inst.instruction = THUMB_OP32 (opcode);
12674 inst.instruction |= inst.operands[0].reg << 12;
12675 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
12676 check_ldr_r15_aligned ();
12677 return;
12678 }
12679
12680 constraint (inst.operands[0].reg > 7, BAD_HIREG);
12681
12682 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
12683 {
12684 /* Only [Rn,Rm] is acceptable. */
12685 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
12686 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
12687 || inst.operands[1].postind || inst.operands[1].shifted
12688 || inst.operands[1].negative,
12689 _("Thumb does not support this addressing mode"));
12690 inst.instruction = THUMB_OP16 (inst.instruction);
12691 goto op16;
12692 }
12693
12694 inst.instruction = THUMB_OP16 (inst.instruction);
12695 if (!inst.operands[1].isreg)
12696 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
12697 return;
12698
12699 constraint (!inst.operands[1].preind
12700 || inst.operands[1].shifted
12701 || inst.operands[1].writeback,
12702 _("Thumb does not support this addressing mode"));
12703 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
12704 {
12705 constraint (inst.instruction & 0x0600,
12706 _("byte or halfword not valid for base register"));
12707 constraint (inst.operands[1].reg == REG_PC
12708 && !(inst.instruction & THUMB_LOAD_BIT),
12709 _("r15 based store not allowed"));
12710 constraint (inst.operands[1].immisreg,
12711 _("invalid base register for register offset"));
12712
12713 if (inst.operands[1].reg == REG_PC)
12714 inst.instruction = T_OPCODE_LDR_PC;
12715 else if (inst.instruction & THUMB_LOAD_BIT)
12716 inst.instruction = T_OPCODE_LDR_SP;
12717 else
12718 inst.instruction = T_OPCODE_STR_SP;
12719
12720 inst.instruction |= inst.operands[0].reg << 8;
12721 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12722 return;
12723 }
12724
12725 constraint (inst.operands[1].reg > 7, BAD_HIREG);
12726 if (!inst.operands[1].immisreg)
12727 {
12728 /* Immediate offset. */
12729 inst.instruction |= inst.operands[0].reg;
12730 inst.instruction |= inst.operands[1].reg << 3;
12731 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
12732 return;
12733 }
12734
12735 /* Register offset. */
12736 constraint (inst.operands[1].imm > 7, BAD_HIREG);
12737 constraint (inst.operands[1].negative,
12738 _("Thumb does not support this addressing mode"));
12739
12740 op16:
12741 switch (inst.instruction)
12742 {
12743 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
12744 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
12745 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
12746 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
12747 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
12748 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
12749 case 0x5600 /* ldrsb */:
12750 case 0x5e00 /* ldrsh */: break;
12751 default: abort ();
12752 }
12753
12754 inst.instruction |= inst.operands[0].reg;
12755 inst.instruction |= inst.operands[1].reg << 3;
12756 inst.instruction |= inst.operands[1].imm << 6;
12757 }
12758
12759 static void
12760 do_t_ldstd (void)
12761 {
12762 if (!inst.operands[1].present)
12763 {
12764 inst.operands[1].reg = inst.operands[0].reg + 1;
12765 constraint (inst.operands[0].reg == REG_LR,
12766 _("r14 not allowed here"));
12767 constraint (inst.operands[0].reg == REG_R12,
12768 _("r12 not allowed here"));
12769 }
12770
12771 if (inst.operands[2].writeback
12772 && (inst.operands[0].reg == inst.operands[2].reg
12773 || inst.operands[1].reg == inst.operands[2].reg))
12774 as_warn (_("base register written back, and overlaps "
12775 "one of transfer registers"));
12776
12777 inst.instruction |= inst.operands[0].reg << 12;
12778 inst.instruction |= inst.operands[1].reg << 8;
12779 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
12780 }
12781
12782 static void
12783 do_t_ldstt (void)
12784 {
12785 inst.instruction |= inst.operands[0].reg << 12;
12786 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
12787 }
12788
12789 static void
12790 do_t_mla (void)
12791 {
12792 unsigned Rd, Rn, Rm, Ra;
12793
12794 Rd = inst.operands[0].reg;
12795 Rn = inst.operands[1].reg;
12796 Rm = inst.operands[2].reg;
12797 Ra = inst.operands[3].reg;
12798
12799 reject_bad_reg (Rd);
12800 reject_bad_reg (Rn);
12801 reject_bad_reg (Rm);
12802 reject_bad_reg (Ra);
12803
12804 inst.instruction |= Rd << 8;
12805 inst.instruction |= Rn << 16;
12806 inst.instruction |= Rm;
12807 inst.instruction |= Ra << 12;
12808 }
12809
12810 static void
12811 do_t_mlal (void)
12812 {
12813 unsigned RdLo, RdHi, Rn, Rm;
12814
12815 RdLo = inst.operands[0].reg;
12816 RdHi = inst.operands[1].reg;
12817 Rn = inst.operands[2].reg;
12818 Rm = inst.operands[3].reg;
12819
12820 reject_bad_reg (RdLo);
12821 reject_bad_reg (RdHi);
12822 reject_bad_reg (Rn);
12823 reject_bad_reg (Rm);
12824
12825 inst.instruction |= RdLo << 12;
12826 inst.instruction |= RdHi << 8;
12827 inst.instruction |= Rn << 16;
12828 inst.instruction |= Rm;
12829 }
12830
12831 static void
12832 do_t_mov_cmp (void)
12833 {
12834 unsigned Rn, Rm;
12835
12836 Rn = inst.operands[0].reg;
12837 Rm = inst.operands[1].reg;
12838
12839 if (Rn == REG_PC)
12840 set_pred_insn_type_last ();
12841
12842 if (unified_syntax)
12843 {
12844 int r0off = (inst.instruction == T_MNEM_mov
12845 || inst.instruction == T_MNEM_movs) ? 8 : 16;
12846 unsigned long opcode;
12847 bfd_boolean narrow;
12848 bfd_boolean low_regs;
12849
12850 low_regs = (Rn <= 7 && Rm <= 7);
12851 opcode = inst.instruction;
12852 if (in_pred_block ())
12853 narrow = opcode != T_MNEM_movs;
12854 else
12855 narrow = opcode != T_MNEM_movs || low_regs;
12856 if (inst.size_req == 4
12857 || inst.operands[1].shifted)
12858 narrow = FALSE;
12859
12860 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
12861 if (opcode == T_MNEM_movs && inst.operands[1].isreg
12862 && !inst.operands[1].shifted
12863 && Rn == REG_PC
12864 && Rm == REG_LR)
12865 {
12866 inst.instruction = T2_SUBS_PC_LR;
12867 return;
12868 }
12869
12870 if (opcode == T_MNEM_cmp)
12871 {
12872 constraint (Rn == REG_PC, BAD_PC);
12873 if (narrow)
12874 {
12875 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
12876 but valid. */
12877 warn_deprecated_sp (Rm);
12878 /* R15 was documented as a valid choice for Rm in ARMv6,
12879 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12880 tools reject R15, so we do too. */
12881 constraint (Rm == REG_PC, BAD_PC);
12882 }
12883 else
12884 reject_bad_reg (Rm);
12885 }
12886 else if (opcode == T_MNEM_mov
12887 || opcode == T_MNEM_movs)
12888 {
12889 if (inst.operands[1].isreg)
12890 {
12891 if (opcode == T_MNEM_movs)
12892 {
12893 reject_bad_reg (Rn);
12894 reject_bad_reg (Rm);
12895 }
12896 else if (narrow)
12897 {
12898 /* This is mov.n. */
12899 if ((Rn == REG_SP || Rn == REG_PC)
12900 && (Rm == REG_SP || Rm == REG_PC))
12901 {
12902 as_tsktsk (_("Use of r%u as a source register is "
12903 "deprecated when r%u is the destination "
12904 "register."), Rm, Rn);
12905 }
12906 }
12907 else
12908 {
12909 /* This is mov.w. */
12910 constraint (Rn == REG_PC, BAD_PC);
12911 constraint (Rm == REG_PC, BAD_PC);
12912 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12913 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
12914 }
12915 }
12916 else
12917 reject_bad_reg (Rn);
12918 }
12919
12920 if (!inst.operands[1].isreg)
12921 {
12922 /* Immediate operand. */
12923 if (!in_pred_block () && opcode == T_MNEM_mov)
12924 narrow = 0;
12925 if (low_regs && narrow)
12926 {
12927 inst.instruction = THUMB_OP16 (opcode);
12928 inst.instruction |= Rn << 8;
12929 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12930 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
12931 {
12932 if (inst.size_req == 2)
12933 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
12934 else
12935 inst.relax = opcode;
12936 }
12937 }
12938 else
12939 {
12940 constraint ((inst.relocs[0].type
12941 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12942 && (inst.relocs[0].type
12943 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
12944 THUMB1_RELOC_ONLY);
12945
12946 inst.instruction = THUMB_OP32 (inst.instruction);
12947 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12948 inst.instruction |= Rn << r0off;
12949 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12950 }
12951 }
12952 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12953 && (inst.instruction == T_MNEM_mov
12954 || inst.instruction == T_MNEM_movs))
12955 {
12956 /* Register shifts are encoded as separate shift instructions. */
12957 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12958
12959 if (in_pred_block ())
12960 narrow = !flags;
12961 else
12962 narrow = flags;
12963
12964 if (inst.size_req == 4)
12965 narrow = FALSE;
12966
12967 if (!low_regs || inst.operands[1].imm > 7)
12968 narrow = FALSE;
12969
12970 if (Rn != Rm)
12971 narrow = FALSE;
12972
12973 switch (inst.operands[1].shift_kind)
12974 {
12975 case SHIFT_LSL:
12976 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12977 break;
12978 case SHIFT_ASR:
12979 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12980 break;
12981 case SHIFT_LSR:
12982 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12983 break;
12984 case SHIFT_ROR:
12985 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12986 break;
12987 default:
12988 abort ();
12989 }
12990
12991 inst.instruction = opcode;
12992 if (narrow)
12993 {
12994 inst.instruction |= Rn;
12995 inst.instruction |= inst.operands[1].imm << 3;
12996 }
12997 else
12998 {
12999 if (flags)
13000 inst.instruction |= CONDS_BIT;
13001
13002 inst.instruction |= Rn << 8;
13003 inst.instruction |= Rm << 16;
13004 inst.instruction |= inst.operands[1].imm;
13005 }
13006 }
13007 else if (!narrow)
13008 {
13009 /* Some mov with immediate shift have narrow variants.
13010 Register shifts are handled above. */
13011 if (low_regs && inst.operands[1].shifted
13012 && (inst.instruction == T_MNEM_mov
13013 || inst.instruction == T_MNEM_movs))
13014 {
13015 if (in_pred_block ())
13016 narrow = (inst.instruction == T_MNEM_mov);
13017 else
13018 narrow = (inst.instruction == T_MNEM_movs);
13019 }
13020
13021 if (narrow)
13022 {
13023 switch (inst.operands[1].shift_kind)
13024 {
13025 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13026 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13027 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13028 default: narrow = FALSE; break;
13029 }
13030 }
13031
13032 if (narrow)
13033 {
13034 inst.instruction |= Rn;
13035 inst.instruction |= Rm << 3;
13036 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13037 }
13038 else
13039 {
13040 inst.instruction = THUMB_OP32 (inst.instruction);
13041 inst.instruction |= Rn << r0off;
13042 encode_thumb32_shifted_operand (1);
13043 }
13044 }
13045 else
13046 switch (inst.instruction)
13047 {
13048 case T_MNEM_mov:
13049 /* In v4t or v5t a move of two lowregs produces unpredictable
13050 results. Don't allow this. */
13051 if (low_regs)
13052 {
13053 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
13054 "MOV Rd, Rs with two low registers is not "
13055 "permitted on this architecture");
13056 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13057 arm_ext_v6);
13058 }
13059
13060 inst.instruction = T_OPCODE_MOV_HR;
13061 inst.instruction |= (Rn & 0x8) << 4;
13062 inst.instruction |= (Rn & 0x7);
13063 inst.instruction |= Rm << 3;
13064 break;
13065
13066 case T_MNEM_movs:
13067 /* We know we have low registers at this point.
13068 Generate LSLS Rd, Rs, #0. */
13069 inst.instruction = T_OPCODE_LSL_I;
13070 inst.instruction |= Rn;
13071 inst.instruction |= Rm << 3;
13072 break;
13073
13074 case T_MNEM_cmp:
13075 if (low_regs)
13076 {
13077 inst.instruction = T_OPCODE_CMP_LR;
13078 inst.instruction |= Rn;
13079 inst.instruction |= Rm << 3;
13080 }
13081 else
13082 {
13083 inst.instruction = T_OPCODE_CMP_HR;
13084 inst.instruction |= (Rn & 0x8) << 4;
13085 inst.instruction |= (Rn & 0x7);
13086 inst.instruction |= Rm << 3;
13087 }
13088 break;
13089 }
13090 return;
13091 }
13092
13093 inst.instruction = THUMB_OP16 (inst.instruction);
13094
13095 /* PR 10443: Do not silently ignore shifted operands. */
13096 constraint (inst.operands[1].shifted,
13097 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
13098
13099 if (inst.operands[1].isreg)
13100 {
13101 if (Rn < 8 && Rm < 8)
13102 {
13103 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
13104 since a MOV instruction produces unpredictable results. */
13105 if (inst.instruction == T_OPCODE_MOV_I8)
13106 inst.instruction = T_OPCODE_ADD_I3;
13107 else
13108 inst.instruction = T_OPCODE_CMP_LR;
13109
13110 inst.instruction |= Rn;
13111 inst.instruction |= Rm << 3;
13112 }
13113 else
13114 {
13115 if (inst.instruction == T_OPCODE_MOV_I8)
13116 inst.instruction = T_OPCODE_MOV_HR;
13117 else
13118 inst.instruction = T_OPCODE_CMP_HR;
13119 do_t_cpy ();
13120 }
13121 }
13122 else
13123 {
13124 constraint (Rn > 7,
13125 _("only lo regs allowed with immediate"));
13126 inst.instruction |= Rn << 8;
13127 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
13128 }
13129 }
13130
13131 static void
13132 do_t_mov16 (void)
13133 {
13134 unsigned Rd;
13135 bfd_vma imm;
13136 bfd_boolean top;
13137
13138 top = (inst.instruction & 0x00800000) != 0;
13139 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
13140 {
13141 constraint (top, _(":lower16: not allowed in this instruction"));
13142 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
13143 }
13144 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
13145 {
13146 constraint (!top, _(":upper16: not allowed in this instruction"));
13147 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
13148 }
13149
13150 Rd = inst.operands[0].reg;
13151 reject_bad_reg (Rd);
13152
13153 inst.instruction |= Rd << 8;
13154 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
13155 {
13156 imm = inst.relocs[0].exp.X_add_number;
13157 inst.instruction |= (imm & 0xf000) << 4;
13158 inst.instruction |= (imm & 0x0800) << 15;
13159 inst.instruction |= (imm & 0x0700) << 4;
13160 inst.instruction |= (imm & 0x00ff);
13161 }
13162 }
13163
13164 static void
13165 do_t_mvn_tst (void)
13166 {
13167 unsigned Rn, Rm;
13168
13169 Rn = inst.operands[0].reg;
13170 Rm = inst.operands[1].reg;
13171
13172 if (inst.instruction == T_MNEM_cmp
13173 || inst.instruction == T_MNEM_cmn)
13174 constraint (Rn == REG_PC, BAD_PC);
13175 else
13176 reject_bad_reg (Rn);
13177 reject_bad_reg (Rm);
13178
13179 if (unified_syntax)
13180 {
13181 int r0off = (inst.instruction == T_MNEM_mvn
13182 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
13183 bfd_boolean narrow;
13184
13185 if (inst.size_req == 4
13186 || inst.instruction > 0xffff
13187 || inst.operands[1].shifted
13188 || Rn > 7 || Rm > 7)
13189 narrow = FALSE;
13190 else if (inst.instruction == T_MNEM_cmn
13191 || inst.instruction == T_MNEM_tst)
13192 narrow = TRUE;
13193 else if (THUMB_SETS_FLAGS (inst.instruction))
13194 narrow = !in_pred_block ();
13195 else
13196 narrow = in_pred_block ();
13197
13198 if (!inst.operands[1].isreg)
13199 {
13200 /* For an immediate, we always generate a 32-bit opcode;
13201 section relaxation will shrink it later if possible. */
13202 if (inst.instruction < 0xffff)
13203 inst.instruction = THUMB_OP32 (inst.instruction);
13204 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13205 inst.instruction |= Rn << r0off;
13206 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13207 }
13208 else
13209 {
13210 /* See if we can do this with a 16-bit instruction. */
13211 if (narrow)
13212 {
13213 inst.instruction = THUMB_OP16 (inst.instruction);
13214 inst.instruction |= Rn;
13215 inst.instruction |= Rm << 3;
13216 }
13217 else
13218 {
13219 constraint (inst.operands[1].shifted
13220 && inst.operands[1].immisreg,
13221 _("shift must be constant"));
13222 if (inst.instruction < 0xffff)
13223 inst.instruction = THUMB_OP32 (inst.instruction);
13224 inst.instruction |= Rn << r0off;
13225 encode_thumb32_shifted_operand (1);
13226 }
13227 }
13228 }
13229 else
13230 {
13231 constraint (inst.instruction > 0xffff
13232 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
13233 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
13234 _("unshifted register required"));
13235 constraint (Rn > 7 || Rm > 7,
13236 BAD_HIREG);
13237
13238 inst.instruction = THUMB_OP16 (inst.instruction);
13239 inst.instruction |= Rn;
13240 inst.instruction |= Rm << 3;
13241 }
13242 }
13243
13244 static void
13245 do_t_mrs (void)
13246 {
13247 unsigned Rd;
13248
13249 if (do_vfp_nsyn_mrs () == SUCCESS)
13250 return;
13251
13252 Rd = inst.operands[0].reg;
13253 reject_bad_reg (Rd);
13254 inst.instruction |= Rd << 8;
13255
13256 if (inst.operands[1].isreg)
13257 {
13258 unsigned br = inst.operands[1].reg;
13259 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
13260 as_bad (_("bad register for mrs"));
13261
13262 inst.instruction |= br & (0xf << 16);
13263 inst.instruction |= (br & 0x300) >> 4;
13264 inst.instruction |= (br & SPSR_BIT) >> 2;
13265 }
13266 else
13267 {
13268 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13269
13270 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13271 {
13272 /* PR gas/12698: The constraint is only applied for m_profile.
13273 If the user has specified -march=all, we want to ignore it as
13274 we are building for any CPU type, including non-m variants. */
13275 bfd_boolean m_profile =
13276 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13277 constraint ((flags != 0) && m_profile, _("selected processor does "
13278 "not support requested special purpose register"));
13279 }
13280 else
13281 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
13282 devices). */
13283 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
13284 _("'APSR', 'CPSR' or 'SPSR' expected"));
13285
13286 inst.instruction |= (flags & SPSR_BIT) >> 2;
13287 inst.instruction |= inst.operands[1].imm & 0xff;
13288 inst.instruction |= 0xf0000;
13289 }
13290 }
13291
13292 static void
13293 do_t_msr (void)
13294 {
13295 int flags;
13296 unsigned Rn;
13297
13298 if (do_vfp_nsyn_msr () == SUCCESS)
13299 return;
13300
13301 constraint (!inst.operands[1].isreg,
13302 _("Thumb encoding does not support an immediate here"));
13303
13304 if (inst.operands[0].isreg)
13305 flags = (int)(inst.operands[0].reg);
13306 else
13307 flags = inst.operands[0].imm;
13308
13309 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
13310 {
13311 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
13312
13313 /* PR gas/12698: The constraint is only applied for m_profile.
13314 If the user has specified -march=all, we want to ignore it as
13315 we are building for any CPU type, including non-m variants. */
13316 bfd_boolean m_profile =
13317 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
13318 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13319 && (bits & ~(PSR_s | PSR_f)) != 0)
13320 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
13321 && bits != PSR_f)) && m_profile,
13322 _("selected processor does not support requested special "
13323 "purpose register"));
13324 }
13325 else
13326 constraint ((flags & 0xff) != 0, _("selected processor does not support "
13327 "requested special purpose register"));
13328
13329 Rn = inst.operands[1].reg;
13330 reject_bad_reg (Rn);
13331
13332 inst.instruction |= (flags & SPSR_BIT) >> 2;
13333 inst.instruction |= (flags & 0xf0000) >> 8;
13334 inst.instruction |= (flags & 0x300) >> 4;
13335 inst.instruction |= (flags & 0xff);
13336 inst.instruction |= Rn << 16;
13337 }
13338
13339 static void
13340 do_t_mul (void)
13341 {
13342 bfd_boolean narrow;
13343 unsigned Rd, Rn, Rm;
13344
13345 if (!inst.operands[2].present)
13346 inst.operands[2].reg = inst.operands[0].reg;
13347
13348 Rd = inst.operands[0].reg;
13349 Rn = inst.operands[1].reg;
13350 Rm = inst.operands[2].reg;
13351
13352 if (unified_syntax)
13353 {
13354 if (inst.size_req == 4
13355 || (Rd != Rn
13356 && Rd != Rm)
13357 || Rn > 7
13358 || Rm > 7)
13359 narrow = FALSE;
13360 else if (inst.instruction == T_MNEM_muls)
13361 narrow = !in_pred_block ();
13362 else
13363 narrow = in_pred_block ();
13364 }
13365 else
13366 {
13367 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
13368 constraint (Rn > 7 || Rm > 7,
13369 BAD_HIREG);
13370 narrow = TRUE;
13371 }
13372
13373 if (narrow)
13374 {
13375 /* 16-bit MULS/Conditional MUL. */
13376 inst.instruction = THUMB_OP16 (inst.instruction);
13377 inst.instruction |= Rd;
13378
13379 if (Rd == Rn)
13380 inst.instruction |= Rm << 3;
13381 else if (Rd == Rm)
13382 inst.instruction |= Rn << 3;
13383 else
13384 constraint (1, _("dest must overlap one source register"));
13385 }
13386 else
13387 {
13388 constraint (inst.instruction != T_MNEM_mul,
13389 _("Thumb-2 MUL must not set flags"));
13390 /* 32-bit MUL. */
13391 inst.instruction = THUMB_OP32 (inst.instruction);
13392 inst.instruction |= Rd << 8;
13393 inst.instruction |= Rn << 16;
13394 inst.instruction |= Rm << 0;
13395
13396 reject_bad_reg (Rd);
13397 reject_bad_reg (Rn);
13398 reject_bad_reg (Rm);
13399 }
13400 }
13401
13402 static void
13403 do_t_mull (void)
13404 {
13405 unsigned RdLo, RdHi, Rn, Rm;
13406
13407 RdLo = inst.operands[0].reg;
13408 RdHi = inst.operands[1].reg;
13409 Rn = inst.operands[2].reg;
13410 Rm = inst.operands[3].reg;
13411
13412 reject_bad_reg (RdLo);
13413 reject_bad_reg (RdHi);
13414 reject_bad_reg (Rn);
13415 reject_bad_reg (Rm);
13416
13417 inst.instruction |= RdLo << 12;
13418 inst.instruction |= RdHi << 8;
13419 inst.instruction |= Rn << 16;
13420 inst.instruction |= Rm;
13421
13422 if (RdLo == RdHi)
13423 as_tsktsk (_("rdhi and rdlo must be different"));
13424 }
13425
13426 static void
13427 do_t_nop (void)
13428 {
13429 set_pred_insn_type (NEUTRAL_IT_INSN);
13430
13431 if (unified_syntax)
13432 {
13433 if (inst.size_req == 4 || inst.operands[0].imm > 15)
13434 {
13435 inst.instruction = THUMB_OP32 (inst.instruction);
13436 inst.instruction |= inst.operands[0].imm;
13437 }
13438 else
13439 {
13440 /* PR9722: Check for Thumb2 availability before
13441 generating a thumb2 nop instruction. */
13442 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
13443 {
13444 inst.instruction = THUMB_OP16 (inst.instruction);
13445 inst.instruction |= inst.operands[0].imm << 4;
13446 }
13447 else
13448 inst.instruction = 0x46c0;
13449 }
13450 }
13451 else
13452 {
13453 constraint (inst.operands[0].present,
13454 _("Thumb does not support NOP with hints"));
13455 inst.instruction = 0x46c0;
13456 }
13457 }
13458
13459 static void
13460 do_t_neg (void)
13461 {
13462 if (unified_syntax)
13463 {
13464 bfd_boolean narrow;
13465
13466 if (THUMB_SETS_FLAGS (inst.instruction))
13467 narrow = !in_pred_block ();
13468 else
13469 narrow = in_pred_block ();
13470 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13471 narrow = FALSE;
13472 if (inst.size_req == 4)
13473 narrow = FALSE;
13474
13475 if (!narrow)
13476 {
13477 inst.instruction = THUMB_OP32 (inst.instruction);
13478 inst.instruction |= inst.operands[0].reg << 8;
13479 inst.instruction |= inst.operands[1].reg << 16;
13480 }
13481 else
13482 {
13483 inst.instruction = THUMB_OP16 (inst.instruction);
13484 inst.instruction |= inst.operands[0].reg;
13485 inst.instruction |= inst.operands[1].reg << 3;
13486 }
13487 }
13488 else
13489 {
13490 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
13491 BAD_HIREG);
13492 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13493
13494 inst.instruction = THUMB_OP16 (inst.instruction);
13495 inst.instruction |= inst.operands[0].reg;
13496 inst.instruction |= inst.operands[1].reg << 3;
13497 }
13498 }
13499
13500 static void
13501 do_t_orn (void)
13502 {
13503 unsigned Rd, Rn;
13504
13505 Rd = inst.operands[0].reg;
13506 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
13507
13508 reject_bad_reg (Rd);
13509 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
13510 reject_bad_reg (Rn);
13511
13512 inst.instruction |= Rd << 8;
13513 inst.instruction |= Rn << 16;
13514
13515 if (!inst.operands[2].isreg)
13516 {
13517 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13518 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13519 }
13520 else
13521 {
13522 unsigned Rm;
13523
13524 Rm = inst.operands[2].reg;
13525 reject_bad_reg (Rm);
13526
13527 constraint (inst.operands[2].shifted
13528 && inst.operands[2].immisreg,
13529 _("shift must be constant"));
13530 encode_thumb32_shifted_operand (2);
13531 }
13532 }
13533
13534 static void
13535 do_t_pkhbt (void)
13536 {
13537 unsigned Rd, Rn, Rm;
13538
13539 Rd = inst.operands[0].reg;
13540 Rn = inst.operands[1].reg;
13541 Rm = inst.operands[2].reg;
13542
13543 reject_bad_reg (Rd);
13544 reject_bad_reg (Rn);
13545 reject_bad_reg (Rm);
13546
13547 inst.instruction |= Rd << 8;
13548 inst.instruction |= Rn << 16;
13549 inst.instruction |= Rm;
13550 if (inst.operands[3].present)
13551 {
13552 unsigned int val = inst.relocs[0].exp.X_add_number;
13553 constraint (inst.relocs[0].exp.X_op != O_constant,
13554 _("expression too complex"));
13555 inst.instruction |= (val & 0x1c) << 10;
13556 inst.instruction |= (val & 0x03) << 6;
13557 }
13558 }
13559
13560 static void
13561 do_t_pkhtb (void)
13562 {
13563 if (!inst.operands[3].present)
13564 {
13565 unsigned Rtmp;
13566
13567 inst.instruction &= ~0x00000020;
13568
13569 /* PR 10168. Swap the Rm and Rn registers. */
13570 Rtmp = inst.operands[1].reg;
13571 inst.operands[1].reg = inst.operands[2].reg;
13572 inst.operands[2].reg = Rtmp;
13573 }
13574 do_t_pkhbt ();
13575 }
13576
13577 static void
13578 do_t_pld (void)
13579 {
13580 if (inst.operands[0].immisreg)
13581 reject_bad_reg (inst.operands[0].imm);
13582
13583 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
13584 }
13585
13586 static void
13587 do_t_push_pop (void)
13588 {
13589 unsigned mask;
13590
13591 constraint (inst.operands[0].writeback,
13592 _("push/pop do not support {reglist}^"));
13593 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
13594 _("expression too complex"));
13595
13596 mask = inst.operands[0].imm;
13597 if (inst.size_req != 4 && (mask & ~0xff) == 0)
13598 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
13599 else if (inst.size_req != 4
13600 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
13601 ? REG_LR : REG_PC)))
13602 {
13603 inst.instruction = THUMB_OP16 (inst.instruction);
13604 inst.instruction |= THUMB_PP_PC_LR;
13605 inst.instruction |= mask & 0xff;
13606 }
13607 else if (unified_syntax)
13608 {
13609 inst.instruction = THUMB_OP32 (inst.instruction);
13610 encode_thumb2_multi (TRUE /* do_io */, 13, mask, TRUE);
13611 }
13612 else
13613 {
13614 inst.error = _("invalid register list to push/pop instruction");
13615 return;
13616 }
13617 }
13618
13619 static void
13620 do_t_clrm (void)
13621 {
13622 if (unified_syntax)
13623 encode_thumb2_multi (FALSE /* do_io */, -1, inst.operands[0].imm, FALSE);
13624 else
13625 {
13626 inst.error = _("invalid register list to push/pop instruction");
13627 return;
13628 }
13629 }
13630
13631 static void
13632 do_t_vscclrm (void)
13633 {
13634 if (inst.operands[0].issingle)
13635 {
13636 inst.instruction |= (inst.operands[0].reg & 0x1) << 22;
13637 inst.instruction |= (inst.operands[0].reg & 0x1e) << 11;
13638 inst.instruction |= inst.operands[0].imm;
13639 }
13640 else
13641 {
13642 inst.instruction |= (inst.operands[0].reg & 0x10) << 18;
13643 inst.instruction |= (inst.operands[0].reg & 0xf) << 12;
13644 inst.instruction |= 1 << 8;
13645 inst.instruction |= inst.operands[0].imm << 1;
13646 }
13647 }
13648
13649 static void
13650 do_t_rbit (void)
13651 {
13652 unsigned Rd, Rm;
13653
13654 Rd = inst.operands[0].reg;
13655 Rm = inst.operands[1].reg;
13656
13657 reject_bad_reg (Rd);
13658 reject_bad_reg (Rm);
13659
13660 inst.instruction |= Rd << 8;
13661 inst.instruction |= Rm << 16;
13662 inst.instruction |= Rm;
13663 }
13664
13665 static void
13666 do_t_rev (void)
13667 {
13668 unsigned Rd, Rm;
13669
13670 Rd = inst.operands[0].reg;
13671 Rm = inst.operands[1].reg;
13672
13673 reject_bad_reg (Rd);
13674 reject_bad_reg (Rm);
13675
13676 if (Rd <= 7 && Rm <= 7
13677 && inst.size_req != 4)
13678 {
13679 inst.instruction = THUMB_OP16 (inst.instruction);
13680 inst.instruction |= Rd;
13681 inst.instruction |= Rm << 3;
13682 }
13683 else if (unified_syntax)
13684 {
13685 inst.instruction = THUMB_OP32 (inst.instruction);
13686 inst.instruction |= Rd << 8;
13687 inst.instruction |= Rm << 16;
13688 inst.instruction |= Rm;
13689 }
13690 else
13691 inst.error = BAD_HIREG;
13692 }
13693
13694 static void
13695 do_t_rrx (void)
13696 {
13697 unsigned Rd, Rm;
13698
13699 Rd = inst.operands[0].reg;
13700 Rm = inst.operands[1].reg;
13701
13702 reject_bad_reg (Rd);
13703 reject_bad_reg (Rm);
13704
13705 inst.instruction |= Rd << 8;
13706 inst.instruction |= Rm;
13707 }
13708
13709 static void
13710 do_t_rsb (void)
13711 {
13712 unsigned Rd, Rs;
13713
13714 Rd = inst.operands[0].reg;
13715 Rs = (inst.operands[1].present
13716 ? inst.operands[1].reg /* Rd, Rs, foo */
13717 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
13718
13719 reject_bad_reg (Rd);
13720 reject_bad_reg (Rs);
13721 if (inst.operands[2].isreg)
13722 reject_bad_reg (inst.operands[2].reg);
13723
13724 inst.instruction |= Rd << 8;
13725 inst.instruction |= Rs << 16;
13726 if (!inst.operands[2].isreg)
13727 {
13728 bfd_boolean narrow;
13729
13730 if ((inst.instruction & 0x00100000) != 0)
13731 narrow = !in_pred_block ();
13732 else
13733 narrow = in_pred_block ();
13734
13735 if (Rd > 7 || Rs > 7)
13736 narrow = FALSE;
13737
13738 if (inst.size_req == 4 || !unified_syntax)
13739 narrow = FALSE;
13740
13741 if (inst.relocs[0].exp.X_op != O_constant
13742 || inst.relocs[0].exp.X_add_number != 0)
13743 narrow = FALSE;
13744
13745 /* Turn rsb #0 into 16-bit neg. We should probably do this via
13746 relaxation, but it doesn't seem worth the hassle. */
13747 if (narrow)
13748 {
13749 inst.relocs[0].type = BFD_RELOC_UNUSED;
13750 inst.instruction = THUMB_OP16 (T_MNEM_negs);
13751 inst.instruction |= Rs << 3;
13752 inst.instruction |= Rd;
13753 }
13754 else
13755 {
13756 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
13757 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
13758 }
13759 }
13760 else
13761 encode_thumb32_shifted_operand (2);
13762 }
13763
13764 static void
13765 do_t_setend (void)
13766 {
13767 if (warn_on_deprecated
13768 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13769 as_tsktsk (_("setend use is deprecated for ARMv8"));
13770
13771 set_pred_insn_type (OUTSIDE_PRED_INSN);
13772 if (inst.operands[0].imm)
13773 inst.instruction |= 0x8;
13774 }
13775
13776 static void
13777 do_t_shift (void)
13778 {
13779 if (!inst.operands[1].present)
13780 inst.operands[1].reg = inst.operands[0].reg;
13781
13782 if (unified_syntax)
13783 {
13784 bfd_boolean narrow;
13785 int shift_kind;
13786
13787 switch (inst.instruction)
13788 {
13789 case T_MNEM_asr:
13790 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
13791 case T_MNEM_lsl:
13792 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
13793 case T_MNEM_lsr:
13794 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
13795 case T_MNEM_ror:
13796 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
13797 default: abort ();
13798 }
13799
13800 if (THUMB_SETS_FLAGS (inst.instruction))
13801 narrow = !in_pred_block ();
13802 else
13803 narrow = in_pred_block ();
13804 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
13805 narrow = FALSE;
13806 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
13807 narrow = FALSE;
13808 if (inst.operands[2].isreg
13809 && (inst.operands[1].reg != inst.operands[0].reg
13810 || inst.operands[2].reg > 7))
13811 narrow = FALSE;
13812 if (inst.size_req == 4)
13813 narrow = FALSE;
13814
13815 reject_bad_reg (inst.operands[0].reg);
13816 reject_bad_reg (inst.operands[1].reg);
13817
13818 if (!narrow)
13819 {
13820 if (inst.operands[2].isreg)
13821 {
13822 reject_bad_reg (inst.operands[2].reg);
13823 inst.instruction = THUMB_OP32 (inst.instruction);
13824 inst.instruction |= inst.operands[0].reg << 8;
13825 inst.instruction |= inst.operands[1].reg << 16;
13826 inst.instruction |= inst.operands[2].reg;
13827
13828 /* PR 12854: Error on extraneous shifts. */
13829 constraint (inst.operands[2].shifted,
13830 _("extraneous shift as part of operand to shift insn"));
13831 }
13832 else
13833 {
13834 inst.operands[1].shifted = 1;
13835 inst.operands[1].shift_kind = shift_kind;
13836 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
13837 ? T_MNEM_movs : T_MNEM_mov);
13838 inst.instruction |= inst.operands[0].reg << 8;
13839 encode_thumb32_shifted_operand (1);
13840 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
13841 inst.relocs[0].type = BFD_RELOC_UNUSED;
13842 }
13843 }
13844 else
13845 {
13846 if (inst.operands[2].isreg)
13847 {
13848 switch (shift_kind)
13849 {
13850 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
13851 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
13852 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
13853 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
13854 default: abort ();
13855 }
13856
13857 inst.instruction |= inst.operands[0].reg;
13858 inst.instruction |= inst.operands[2].reg << 3;
13859
13860 /* PR 12854: Error on extraneous shifts. */
13861 constraint (inst.operands[2].shifted,
13862 _("extraneous shift as part of operand to shift insn"));
13863 }
13864 else
13865 {
13866 switch (shift_kind)
13867 {
13868 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
13869 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
13870 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
13871 default: abort ();
13872 }
13873 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13874 inst.instruction |= inst.operands[0].reg;
13875 inst.instruction |= inst.operands[1].reg << 3;
13876 }
13877 }
13878 }
13879 else
13880 {
13881 constraint (inst.operands[0].reg > 7
13882 || inst.operands[1].reg > 7, BAD_HIREG);
13883 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
13884
13885 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
13886 {
13887 constraint (inst.operands[2].reg > 7, BAD_HIREG);
13888 constraint (inst.operands[0].reg != inst.operands[1].reg,
13889 _("source1 and dest must be same register"));
13890
13891 switch (inst.instruction)
13892 {
13893 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
13894 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
13895 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
13896 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
13897 default: abort ();
13898 }
13899
13900 inst.instruction |= inst.operands[0].reg;
13901 inst.instruction |= inst.operands[2].reg << 3;
13902
13903 /* PR 12854: Error on extraneous shifts. */
13904 constraint (inst.operands[2].shifted,
13905 _("extraneous shift as part of operand to shift insn"));
13906 }
13907 else
13908 {
13909 switch (inst.instruction)
13910 {
13911 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13912 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13913 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13914 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13915 default: abort ();
13916 }
13917 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13918 inst.instruction |= inst.operands[0].reg;
13919 inst.instruction |= inst.operands[1].reg << 3;
13920 }
13921 }
13922 }
13923
13924 static void
13925 do_t_simd (void)
13926 {
13927 unsigned Rd, Rn, Rm;
13928
13929 Rd = inst.operands[0].reg;
13930 Rn = inst.operands[1].reg;
13931 Rm = inst.operands[2].reg;
13932
13933 reject_bad_reg (Rd);
13934 reject_bad_reg (Rn);
13935 reject_bad_reg (Rm);
13936
13937 inst.instruction |= Rd << 8;
13938 inst.instruction |= Rn << 16;
13939 inst.instruction |= Rm;
13940 }
13941
13942 static void
13943 do_t_simd2 (void)
13944 {
13945 unsigned Rd, Rn, Rm;
13946
13947 Rd = inst.operands[0].reg;
13948 Rm = inst.operands[1].reg;
13949 Rn = inst.operands[2].reg;
13950
13951 reject_bad_reg (Rd);
13952 reject_bad_reg (Rn);
13953 reject_bad_reg (Rm);
13954
13955 inst.instruction |= Rd << 8;
13956 inst.instruction |= Rn << 16;
13957 inst.instruction |= Rm;
13958 }
13959
13960 static void
13961 do_t_smc (void)
13962 {
13963 unsigned int value = inst.relocs[0].exp.X_add_number;
13964 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13965 _("SMC is not permitted on this architecture"));
13966 constraint (inst.relocs[0].exp.X_op != O_constant,
13967 _("expression too complex"));
13968 constraint (value > 0xf, _("immediate too large (bigger than 0xF)"));
13969
13970 inst.relocs[0].type = BFD_RELOC_UNUSED;
13971 inst.instruction |= (value & 0x000f) << 16;
13972
13973 /* PR gas/15623: SMC instructions must be last in an IT block. */
13974 set_pred_insn_type_last ();
13975 }
13976
13977 static void
13978 do_t_hvc (void)
13979 {
13980 unsigned int value = inst.relocs[0].exp.X_add_number;
13981
13982 inst.relocs[0].type = BFD_RELOC_UNUSED;
13983 inst.instruction |= (value & 0x0fff);
13984 inst.instruction |= (value & 0xf000) << 4;
13985 }
13986
13987 static void
13988 do_t_ssat_usat (int bias)
13989 {
13990 unsigned Rd, Rn;
13991
13992 Rd = inst.operands[0].reg;
13993 Rn = inst.operands[2].reg;
13994
13995 reject_bad_reg (Rd);
13996 reject_bad_reg (Rn);
13997
13998 inst.instruction |= Rd << 8;
13999 inst.instruction |= inst.operands[1].imm - bias;
14000 inst.instruction |= Rn << 16;
14001
14002 if (inst.operands[3].present)
14003 {
14004 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
14005
14006 inst.relocs[0].type = BFD_RELOC_UNUSED;
14007
14008 constraint (inst.relocs[0].exp.X_op != O_constant,
14009 _("expression too complex"));
14010
14011 if (shift_amount != 0)
14012 {
14013 constraint (shift_amount > 31,
14014 _("shift expression is too large"));
14015
14016 if (inst.operands[3].shift_kind == SHIFT_ASR)
14017 inst.instruction |= 0x00200000; /* sh bit. */
14018
14019 inst.instruction |= (shift_amount & 0x1c) << 10;
14020 inst.instruction |= (shift_amount & 0x03) << 6;
14021 }
14022 }
14023 }
14024
14025 static void
14026 do_t_ssat (void)
14027 {
14028 do_t_ssat_usat (1);
14029 }
14030
14031 static void
14032 do_t_ssat16 (void)
14033 {
14034 unsigned Rd, Rn;
14035
14036 Rd = inst.operands[0].reg;
14037 Rn = inst.operands[2].reg;
14038
14039 reject_bad_reg (Rd);
14040 reject_bad_reg (Rn);
14041
14042 inst.instruction |= Rd << 8;
14043 inst.instruction |= inst.operands[1].imm - 1;
14044 inst.instruction |= Rn << 16;
14045 }
14046
14047 static void
14048 do_t_strex (void)
14049 {
14050 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
14051 || inst.operands[2].postind || inst.operands[2].writeback
14052 || inst.operands[2].immisreg || inst.operands[2].shifted
14053 || inst.operands[2].negative,
14054 BAD_ADDR_MODE);
14055
14056 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
14057
14058 inst.instruction |= inst.operands[0].reg << 8;
14059 inst.instruction |= inst.operands[1].reg << 12;
14060 inst.instruction |= inst.operands[2].reg << 16;
14061 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
14062 }
14063
14064 static void
14065 do_t_strexd (void)
14066 {
14067 if (!inst.operands[2].present)
14068 inst.operands[2].reg = inst.operands[1].reg + 1;
14069
14070 constraint (inst.operands[0].reg == inst.operands[1].reg
14071 || inst.operands[0].reg == inst.operands[2].reg
14072 || inst.operands[0].reg == inst.operands[3].reg,
14073 BAD_OVERLAP);
14074
14075 inst.instruction |= inst.operands[0].reg;
14076 inst.instruction |= inst.operands[1].reg << 12;
14077 inst.instruction |= inst.operands[2].reg << 8;
14078 inst.instruction |= inst.operands[3].reg << 16;
14079 }
14080
14081 static void
14082 do_t_sxtah (void)
14083 {
14084 unsigned Rd, Rn, Rm;
14085
14086 Rd = inst.operands[0].reg;
14087 Rn = inst.operands[1].reg;
14088 Rm = inst.operands[2].reg;
14089
14090 reject_bad_reg (Rd);
14091 reject_bad_reg (Rn);
14092 reject_bad_reg (Rm);
14093
14094 inst.instruction |= Rd << 8;
14095 inst.instruction |= Rn << 16;
14096 inst.instruction |= Rm;
14097 inst.instruction |= inst.operands[3].imm << 4;
14098 }
14099
14100 static void
14101 do_t_sxth (void)
14102 {
14103 unsigned Rd, Rm;
14104
14105 Rd = inst.operands[0].reg;
14106 Rm = inst.operands[1].reg;
14107
14108 reject_bad_reg (Rd);
14109 reject_bad_reg (Rm);
14110
14111 if (inst.instruction <= 0xffff
14112 && inst.size_req != 4
14113 && Rd <= 7 && Rm <= 7
14114 && (!inst.operands[2].present || inst.operands[2].imm == 0))
14115 {
14116 inst.instruction = THUMB_OP16 (inst.instruction);
14117 inst.instruction |= Rd;
14118 inst.instruction |= Rm << 3;
14119 }
14120 else if (unified_syntax)
14121 {
14122 if (inst.instruction <= 0xffff)
14123 inst.instruction = THUMB_OP32 (inst.instruction);
14124 inst.instruction |= Rd << 8;
14125 inst.instruction |= Rm;
14126 inst.instruction |= inst.operands[2].imm << 4;
14127 }
14128 else
14129 {
14130 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
14131 _("Thumb encoding does not support rotation"));
14132 constraint (1, BAD_HIREG);
14133 }
14134 }
14135
14136 static void
14137 do_t_swi (void)
14138 {
14139 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
14140 }
14141
14142 static void
14143 do_t_tb (void)
14144 {
14145 unsigned Rn, Rm;
14146 int half;
14147
14148 half = (inst.instruction & 0x10) != 0;
14149 set_pred_insn_type_last ();
14150 constraint (inst.operands[0].immisreg,
14151 _("instruction requires register index"));
14152
14153 Rn = inst.operands[0].reg;
14154 Rm = inst.operands[0].imm;
14155
14156 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
14157 constraint (Rn == REG_SP, BAD_SP);
14158 reject_bad_reg (Rm);
14159
14160 constraint (!half && inst.operands[0].shifted,
14161 _("instruction does not allow shifted index"));
14162 inst.instruction |= (Rn << 16) | Rm;
14163 }
14164
14165 static void
14166 do_t_udf (void)
14167 {
14168 if (!inst.operands[0].present)
14169 inst.operands[0].imm = 0;
14170
14171 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
14172 {
14173 constraint (inst.size_req == 2,
14174 _("immediate value out of range"));
14175 inst.instruction = THUMB_OP32 (inst.instruction);
14176 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
14177 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
14178 }
14179 else
14180 {
14181 inst.instruction = THUMB_OP16 (inst.instruction);
14182 inst.instruction |= inst.operands[0].imm;
14183 }
14184
14185 set_pred_insn_type (NEUTRAL_IT_INSN);
14186 }
14187
14188
14189 static void
14190 do_t_usat (void)
14191 {
14192 do_t_ssat_usat (0);
14193 }
14194
14195 static void
14196 do_t_usat16 (void)
14197 {
14198 unsigned Rd, Rn;
14199
14200 Rd = inst.operands[0].reg;
14201 Rn = inst.operands[2].reg;
14202
14203 reject_bad_reg (Rd);
14204 reject_bad_reg (Rn);
14205
14206 inst.instruction |= Rd << 8;
14207 inst.instruction |= inst.operands[1].imm;
14208 inst.instruction |= Rn << 16;
14209 }
14210
14211 /* Checking the range of the branch offset (VAL) with NBITS bits
14212 and IS_SIGNED signedness. Also checks the LSB to be 0. */
14213 static int
14214 v8_1_branch_value_check (int val, int nbits, int is_signed)
14215 {
14216 gas_assert (nbits > 0 && nbits <= 32);
14217 if (is_signed)
14218 {
14219 int cmp = (1 << (nbits - 1));
14220 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
14221 return FAIL;
14222 }
14223 else
14224 {
14225 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
14226 return FAIL;
14227 }
14228 return SUCCESS;
14229 }
14230
14231 /* For branches in Armv8.1-M Mainline. */
14232 static void
14233 do_t_branch_future (void)
14234 {
14235 unsigned long insn = inst.instruction;
14236
14237 inst.instruction = THUMB_OP32 (inst.instruction);
14238 if (inst.operands[0].hasreloc == 0)
14239 {
14240 if (v8_1_branch_value_check (inst.operands[0].imm, 5, FALSE) == FAIL)
14241 as_bad (BAD_BRANCH_OFF);
14242
14243 inst.instruction |= ((inst.operands[0].imm & 0x1f) >> 1) << 23;
14244 }
14245 else
14246 {
14247 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH5;
14248 inst.relocs[0].pc_rel = 1;
14249 }
14250
14251 switch (insn)
14252 {
14253 case T_MNEM_bf:
14254 if (inst.operands[1].hasreloc == 0)
14255 {
14256 int val = inst.operands[1].imm;
14257 if (v8_1_branch_value_check (inst.operands[1].imm, 17, TRUE) == FAIL)
14258 as_bad (BAD_BRANCH_OFF);
14259
14260 int immA = (val & 0x0001f000) >> 12;
14261 int immB = (val & 0x00000ffc) >> 2;
14262 int immC = (val & 0x00000002) >> 1;
14263 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14264 }
14265 else
14266 {
14267 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF17;
14268 inst.relocs[1].pc_rel = 1;
14269 }
14270 break;
14271
14272 case T_MNEM_bfl:
14273 if (inst.operands[1].hasreloc == 0)
14274 {
14275 int val = inst.operands[1].imm;
14276 if (v8_1_branch_value_check (inst.operands[1].imm, 19, TRUE) == FAIL)
14277 as_bad (BAD_BRANCH_OFF);
14278
14279 int immA = (val & 0x0007f000) >> 12;
14280 int immB = (val & 0x00000ffc) >> 2;
14281 int immC = (val & 0x00000002) >> 1;
14282 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14283 }
14284 else
14285 {
14286 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF19;
14287 inst.relocs[1].pc_rel = 1;
14288 }
14289 break;
14290
14291 case T_MNEM_bfcsel:
14292 /* Operand 1. */
14293 if (inst.operands[1].hasreloc == 0)
14294 {
14295 int val = inst.operands[1].imm;
14296 int immA = (val & 0x00001000) >> 12;
14297 int immB = (val & 0x00000ffc) >> 2;
14298 int immC = (val & 0x00000002) >> 1;
14299 inst.instruction |= (immA << 16) | (immB << 1) | (immC << 11);
14300 }
14301 else
14302 {
14303 inst.relocs[1].type = BFD_RELOC_ARM_THUMB_BF13;
14304 inst.relocs[1].pc_rel = 1;
14305 }
14306
14307 /* Operand 2. */
14308 if (inst.operands[2].hasreloc == 0)
14309 {
14310 constraint ((inst.operands[0].hasreloc != 0), BAD_ARGS);
14311 int val2 = inst.operands[2].imm;
14312 int val0 = inst.operands[0].imm & 0x1f;
14313 int diff = val2 - val0;
14314 if (diff == 4)
14315 inst.instruction |= 1 << 17; /* T bit. */
14316 else if (diff != 2)
14317 as_bad (_("out of range label-relative fixup value"));
14318 }
14319 else
14320 {
14321 constraint ((inst.operands[0].hasreloc == 0), BAD_ARGS);
14322 inst.relocs[2].type = BFD_RELOC_THUMB_PCREL_BFCSEL;
14323 inst.relocs[2].pc_rel = 1;
14324 }
14325
14326 /* Operand 3. */
14327 constraint (inst.cond != COND_ALWAYS, BAD_COND);
14328 inst.instruction |= (inst.operands[3].imm & 0xf) << 18;
14329 break;
14330
14331 case T_MNEM_bfx:
14332 case T_MNEM_bflx:
14333 inst.instruction |= inst.operands[1].reg << 16;
14334 break;
14335
14336 default: abort ();
14337 }
14338 }
14339
14340 /* Helper function for do_t_loloop to handle relocations. */
14341 static void
14342 v8_1_loop_reloc (int is_le)
14343 {
14344 if (inst.relocs[0].exp.X_op == O_constant)
14345 {
14346 int value = inst.relocs[0].exp.X_add_number;
14347 value = (is_le) ? -value : value;
14348
14349 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
14350 as_bad (BAD_BRANCH_OFF);
14351
14352 int imml, immh;
14353
14354 immh = (value & 0x00000ffc) >> 2;
14355 imml = (value & 0x00000002) >> 1;
14356
14357 inst.instruction |= (imml << 11) | (immh << 1);
14358 }
14359 else
14360 {
14361 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_LOOP12;
14362 inst.relocs[0].pc_rel = 1;
14363 }
14364 }
14365
14366 /* For shifts with four operands in MVE. */
14367 static void
14368 do_mve_scalar_shift1 (void)
14369 {
14370 unsigned int value = inst.operands[2].imm;
14371
14372 inst.instruction |= inst.operands[0].reg << 16;
14373 inst.instruction |= inst.operands[1].reg << 8;
14374
14375 /* Setting the bit for saturation. */
14376 inst.instruction |= ((value == 64) ? 0: 1) << 7;
14377
14378 /* Assuming Rm is already checked not to be 11x1. */
14379 constraint (inst.operands[3].reg == inst.operands[0].reg, BAD_OVERLAP);
14380 constraint (inst.operands[3].reg == inst.operands[1].reg, BAD_OVERLAP);
14381 inst.instruction |= inst.operands[3].reg << 12;
14382 }
14383
14384 /* For shifts in MVE. */
14385 static void
14386 do_mve_scalar_shift (void)
14387 {
14388 if (!inst.operands[2].present)
14389 {
14390 inst.operands[2] = inst.operands[1];
14391 inst.operands[1].reg = 0xf;
14392 }
14393
14394 inst.instruction |= inst.operands[0].reg << 16;
14395 inst.instruction |= inst.operands[1].reg << 8;
14396
14397 if (inst.operands[2].isreg)
14398 {
14399 /* Assuming Rm is already checked not to be 11x1. */
14400 constraint (inst.operands[2].reg == inst.operands[0].reg, BAD_OVERLAP);
14401 constraint (inst.operands[2].reg == inst.operands[1].reg, BAD_OVERLAP);
14402 inst.instruction |= inst.operands[2].reg << 12;
14403 }
14404 else
14405 {
14406 /* Assuming imm is already checked as [1,32]. */
14407 unsigned int value = inst.operands[2].imm;
14408 inst.instruction |= (value & 0x1c) << 10;
14409 inst.instruction |= (value & 0x03) << 6;
14410 /* Change last 4 bits from 0xd to 0xf. */
14411 inst.instruction |= 0x2;
14412 }
14413 }
14414
14415 /* MVE instruction encoder helpers. */
14416 #define M_MNEM_vabav 0xee800f01
14417 #define M_MNEM_vmladav 0xeef00e00
14418 #define M_MNEM_vmladava 0xeef00e20
14419 #define M_MNEM_vmladavx 0xeef01e00
14420 #define M_MNEM_vmladavax 0xeef01e20
14421 #define M_MNEM_vmlsdav 0xeef00e01
14422 #define M_MNEM_vmlsdava 0xeef00e21
14423 #define M_MNEM_vmlsdavx 0xeef01e01
14424 #define M_MNEM_vmlsdavax 0xeef01e21
14425 #define M_MNEM_vmullt 0xee011e00
14426 #define M_MNEM_vmullb 0xee010e00
14427 #define M_MNEM_vctp 0xf000e801
14428 #define M_MNEM_vst20 0xfc801e00
14429 #define M_MNEM_vst21 0xfc801e20
14430 #define M_MNEM_vst40 0xfc801e01
14431 #define M_MNEM_vst41 0xfc801e21
14432 #define M_MNEM_vst42 0xfc801e41
14433 #define M_MNEM_vst43 0xfc801e61
14434 #define M_MNEM_vld20 0xfc901e00
14435 #define M_MNEM_vld21 0xfc901e20
14436 #define M_MNEM_vld40 0xfc901e01
14437 #define M_MNEM_vld41 0xfc901e21
14438 #define M_MNEM_vld42 0xfc901e41
14439 #define M_MNEM_vld43 0xfc901e61
14440 #define M_MNEM_vstrb 0xec000e00
14441 #define M_MNEM_vstrh 0xec000e10
14442 #define M_MNEM_vstrw 0xec000e40
14443 #define M_MNEM_vstrd 0xec000e50
14444 #define M_MNEM_vldrb 0xec100e00
14445 #define M_MNEM_vldrh 0xec100e10
14446 #define M_MNEM_vldrw 0xec100e40
14447 #define M_MNEM_vldrd 0xec100e50
14448 #define M_MNEM_vmovlt 0xeea01f40
14449 #define M_MNEM_vmovlb 0xeea00f40
14450 #define M_MNEM_vmovnt 0xfe311e81
14451 #define M_MNEM_vmovnb 0xfe310e81
14452 #define M_MNEM_vadc 0xee300f00
14453 #define M_MNEM_vadci 0xee301f00
14454 #define M_MNEM_vbrsr 0xfe011e60
14455 #define M_MNEM_vaddlv 0xee890f00
14456 #define M_MNEM_vaddlva 0xee890f20
14457 #define M_MNEM_vaddv 0xeef10f00
14458 #define M_MNEM_vaddva 0xeef10f20
14459 #define M_MNEM_vddup 0xee011f6e
14460 #define M_MNEM_vdwdup 0xee011f60
14461 #define M_MNEM_vidup 0xee010f6e
14462 #define M_MNEM_viwdup 0xee010f60
14463 #define M_MNEM_vmaxv 0xeee20f00
14464 #define M_MNEM_vmaxav 0xeee00f00
14465 #define M_MNEM_vminv 0xeee20f80
14466 #define M_MNEM_vminav 0xeee00f80
14467 #define M_MNEM_vmlaldav 0xee800e00
14468 #define M_MNEM_vmlaldava 0xee800e20
14469 #define M_MNEM_vmlaldavx 0xee801e00
14470 #define M_MNEM_vmlaldavax 0xee801e20
14471 #define M_MNEM_vmlsldav 0xee800e01
14472 #define M_MNEM_vmlsldava 0xee800e21
14473 #define M_MNEM_vmlsldavx 0xee801e01
14474 #define M_MNEM_vmlsldavax 0xee801e21
14475 #define M_MNEM_vrmlaldavhx 0xee801f00
14476 #define M_MNEM_vrmlaldavhax 0xee801f20
14477 #define M_MNEM_vrmlsldavh 0xfe800e01
14478 #define M_MNEM_vrmlsldavha 0xfe800e21
14479 #define M_MNEM_vrmlsldavhx 0xfe801e01
14480 #define M_MNEM_vrmlsldavhax 0xfe801e21
14481 #define M_MNEM_vqmovnt 0xee331e01
14482 #define M_MNEM_vqmovnb 0xee330e01
14483 #define M_MNEM_vqmovunt 0xee311e81
14484 #define M_MNEM_vqmovunb 0xee310e81
14485 #define M_MNEM_vshrnt 0xee801fc1
14486 #define M_MNEM_vshrnb 0xee800fc1
14487 #define M_MNEM_vrshrnt 0xfe801fc1
14488 #define M_MNEM_vqshrnt 0xee801f40
14489 #define M_MNEM_vqshrnb 0xee800f40
14490 #define M_MNEM_vqshrunt 0xee801fc0
14491 #define M_MNEM_vqshrunb 0xee800fc0
14492 #define M_MNEM_vrshrnb 0xfe800fc1
14493 #define M_MNEM_vqrshrnt 0xee801f41
14494 #define M_MNEM_vqrshrnb 0xee800f41
14495 #define M_MNEM_vqrshrunt 0xfe801fc0
14496 #define M_MNEM_vqrshrunb 0xfe800fc0
14497
14498 /* Neon instruction encoder helpers. */
14499
14500 /* Encodings for the different types for various Neon opcodes. */
14501
14502 /* An "invalid" code for the following tables. */
14503 #define N_INV -1u
14504
14505 struct neon_tab_entry
14506 {
14507 unsigned integer;
14508 unsigned float_or_poly;
14509 unsigned scalar_or_imm;
14510 };
14511
14512 /* Map overloaded Neon opcodes to their respective encodings. */
14513 #define NEON_ENC_TAB \
14514 X(vabd, 0x0000700, 0x1200d00, N_INV), \
14515 X(vabdl, 0x0800700, N_INV, N_INV), \
14516 X(vmax, 0x0000600, 0x0000f00, N_INV), \
14517 X(vmin, 0x0000610, 0x0200f00, N_INV), \
14518 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
14519 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
14520 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
14521 X(vadd, 0x0000800, 0x0000d00, N_INV), \
14522 X(vaddl, 0x0800000, N_INV, N_INV), \
14523 X(vsub, 0x1000800, 0x0200d00, N_INV), \
14524 X(vsubl, 0x0800200, N_INV, N_INV), \
14525 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
14526 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
14527 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
14528 /* Register variants of the following two instructions are encoded as
14529 vcge / vcgt with the operands reversed. */ \
14530 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
14531 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
14532 X(vfma, N_INV, 0x0000c10, N_INV), \
14533 X(vfms, N_INV, 0x0200c10, N_INV), \
14534 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
14535 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
14536 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
14537 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
14538 X(vmlal, 0x0800800, N_INV, 0x0800240), \
14539 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
14540 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
14541 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
14542 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
14543 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
14544 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
14545 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
14546 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
14547 X(vshl, 0x0000400, N_INV, 0x0800510), \
14548 X(vqshl, 0x0000410, N_INV, 0x0800710), \
14549 X(vand, 0x0000110, N_INV, 0x0800030), \
14550 X(vbic, 0x0100110, N_INV, 0x0800030), \
14551 X(veor, 0x1000110, N_INV, N_INV), \
14552 X(vorn, 0x0300110, N_INV, 0x0800010), \
14553 X(vorr, 0x0200110, N_INV, 0x0800010), \
14554 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
14555 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
14556 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
14557 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
14558 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
14559 X(vst1, 0x0000000, 0x0800000, N_INV), \
14560 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
14561 X(vst2, 0x0000100, 0x0800100, N_INV), \
14562 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
14563 X(vst3, 0x0000200, 0x0800200, N_INV), \
14564 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
14565 X(vst4, 0x0000300, 0x0800300, N_INV), \
14566 X(vmovn, 0x1b20200, N_INV, N_INV), \
14567 X(vtrn, 0x1b20080, N_INV, N_INV), \
14568 X(vqmovn, 0x1b20200, N_INV, N_INV), \
14569 X(vqmovun, 0x1b20240, N_INV, N_INV), \
14570 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
14571 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
14572 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
14573 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
14574 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
14575 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
14576 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
14577 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
14578 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
14579 X(vseleq, 0xe000a00, N_INV, N_INV), \
14580 X(vselvs, 0xe100a00, N_INV, N_INV), \
14581 X(vselge, 0xe200a00, N_INV, N_INV), \
14582 X(vselgt, 0xe300a00, N_INV, N_INV), \
14583 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
14584 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
14585 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
14586 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
14587 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
14588 X(aes, 0x3b00300, N_INV, N_INV), \
14589 X(sha3op, 0x2000c00, N_INV, N_INV), \
14590 X(sha1h, 0x3b902c0, N_INV, N_INV), \
14591 X(sha2op, 0x3ba0380, N_INV, N_INV)
14592
14593 enum neon_opc
14594 {
14595 #define X(OPC,I,F,S) N_MNEM_##OPC
14596 NEON_ENC_TAB
14597 #undef X
14598 };
14599
14600 static const struct neon_tab_entry neon_enc_tab[] =
14601 {
14602 #define X(OPC,I,F,S) { (I), (F), (S) }
14603 NEON_ENC_TAB
14604 #undef X
14605 };
14606
14607 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
14608 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14609 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14610 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14611 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14612 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14613 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14614 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
14615 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
14616 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
14617 #define NEON_ENC_SINGLE_(X) \
14618 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
14619 #define NEON_ENC_DOUBLE_(X) \
14620 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
14621 #define NEON_ENC_FPV8_(X) \
14622 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
14623
14624 #define NEON_ENCODE(type, inst) \
14625 do \
14626 { \
14627 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
14628 inst.is_neon = 1; \
14629 } \
14630 while (0)
14631
14632 #define check_neon_suffixes \
14633 do \
14634 { \
14635 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
14636 { \
14637 as_bad (_("invalid neon suffix for non neon instruction")); \
14638 return; \
14639 } \
14640 } \
14641 while (0)
14642
14643 /* Define shapes for instruction operands. The following mnemonic characters
14644 are used in this table:
14645
14646 F - VFP S<n> register
14647 D - Neon D<n> register
14648 Q - Neon Q<n> register
14649 I - Immediate
14650 S - Scalar
14651 R - ARM register
14652 L - D<n> register list
14653
14654 This table is used to generate various data:
14655 - enumerations of the form NS_DDR to be used as arguments to
14656 neon_select_shape.
14657 - a table classifying shapes into single, double, quad, mixed.
14658 - a table used to drive neon_select_shape. */
14659
14660 #define NEON_SHAPE_DEF \
14661 X(4, (R, R, Q, Q), QUAD), \
14662 X(4, (Q, R, R, I), QUAD), \
14663 X(4, (R, R, S, S), QUAD), \
14664 X(4, (S, S, R, R), QUAD), \
14665 X(3, (Q, R, I), QUAD), \
14666 X(3, (I, Q, Q), QUAD), \
14667 X(3, (I, Q, R), QUAD), \
14668 X(3, (R, Q, Q), QUAD), \
14669 X(3, (D, D, D), DOUBLE), \
14670 X(3, (Q, Q, Q), QUAD), \
14671 X(3, (D, D, I), DOUBLE), \
14672 X(3, (Q, Q, I), QUAD), \
14673 X(3, (D, D, S), DOUBLE), \
14674 X(3, (Q, Q, S), QUAD), \
14675 X(3, (Q, Q, R), QUAD), \
14676 X(3, (R, R, Q), QUAD), \
14677 X(2, (R, Q), QUAD), \
14678 X(2, (D, D), DOUBLE), \
14679 X(2, (Q, Q), QUAD), \
14680 X(2, (D, S), DOUBLE), \
14681 X(2, (Q, S), QUAD), \
14682 X(2, (D, R), DOUBLE), \
14683 X(2, (Q, R), QUAD), \
14684 X(2, (D, I), DOUBLE), \
14685 X(2, (Q, I), QUAD), \
14686 X(3, (D, L, D), DOUBLE), \
14687 X(2, (D, Q), MIXED), \
14688 X(2, (Q, D), MIXED), \
14689 X(3, (D, Q, I), MIXED), \
14690 X(3, (Q, D, I), MIXED), \
14691 X(3, (Q, D, D), MIXED), \
14692 X(3, (D, Q, Q), MIXED), \
14693 X(3, (Q, Q, D), MIXED), \
14694 X(3, (Q, D, S), MIXED), \
14695 X(3, (D, Q, S), MIXED), \
14696 X(4, (D, D, D, I), DOUBLE), \
14697 X(4, (Q, Q, Q, I), QUAD), \
14698 X(4, (D, D, S, I), DOUBLE), \
14699 X(4, (Q, Q, S, I), QUAD), \
14700 X(2, (F, F), SINGLE), \
14701 X(3, (F, F, F), SINGLE), \
14702 X(2, (F, I), SINGLE), \
14703 X(2, (F, D), MIXED), \
14704 X(2, (D, F), MIXED), \
14705 X(3, (F, F, I), MIXED), \
14706 X(4, (R, R, F, F), SINGLE), \
14707 X(4, (F, F, R, R), SINGLE), \
14708 X(3, (D, R, R), DOUBLE), \
14709 X(3, (R, R, D), DOUBLE), \
14710 X(2, (S, R), SINGLE), \
14711 X(2, (R, S), SINGLE), \
14712 X(2, (F, R), SINGLE), \
14713 X(2, (R, F), SINGLE), \
14714 /* Used for MVE tail predicated loop instructions. */\
14715 X(2, (R, R), QUAD), \
14716 /* Half float shape supported so far. */\
14717 X (2, (H, D), MIXED), \
14718 X (2, (D, H), MIXED), \
14719 X (2, (H, F), MIXED), \
14720 X (2, (F, H), MIXED), \
14721 X (2, (H, H), HALF), \
14722 X (2, (H, R), HALF), \
14723 X (2, (R, H), HALF), \
14724 X (2, (H, I), HALF), \
14725 X (3, (H, H, H), HALF), \
14726 X (3, (H, F, I), MIXED), \
14727 X (3, (F, H, I), MIXED), \
14728 X (3, (D, H, H), MIXED), \
14729 X (3, (D, H, S), MIXED)
14730
14731 #define S2(A,B) NS_##A##B
14732 #define S3(A,B,C) NS_##A##B##C
14733 #define S4(A,B,C,D) NS_##A##B##C##D
14734
14735 #define X(N, L, C) S##N L
14736
14737 enum neon_shape
14738 {
14739 NEON_SHAPE_DEF,
14740 NS_NULL
14741 };
14742
14743 #undef X
14744 #undef S2
14745 #undef S3
14746 #undef S4
14747
14748 enum neon_shape_class
14749 {
14750 SC_HALF,
14751 SC_SINGLE,
14752 SC_DOUBLE,
14753 SC_QUAD,
14754 SC_MIXED
14755 };
14756
14757 #define X(N, L, C) SC_##C
14758
14759 static enum neon_shape_class neon_shape_class[] =
14760 {
14761 NEON_SHAPE_DEF
14762 };
14763
14764 #undef X
14765
14766 enum neon_shape_el
14767 {
14768 SE_H,
14769 SE_F,
14770 SE_D,
14771 SE_Q,
14772 SE_I,
14773 SE_S,
14774 SE_R,
14775 SE_L
14776 };
14777
14778 /* Register widths of above. */
14779 static unsigned neon_shape_el_size[] =
14780 {
14781 16,
14782 32,
14783 64,
14784 128,
14785 0,
14786 32,
14787 32,
14788 0
14789 };
14790
14791 struct neon_shape_info
14792 {
14793 unsigned els;
14794 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
14795 };
14796
14797 #define S2(A,B) { SE_##A, SE_##B }
14798 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
14799 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
14800
14801 #define X(N, L, C) { N, S##N L }
14802
14803 static struct neon_shape_info neon_shape_tab[] =
14804 {
14805 NEON_SHAPE_DEF
14806 };
14807
14808 #undef X
14809 #undef S2
14810 #undef S3
14811 #undef S4
14812
14813 /* Bit masks used in type checking given instructions.
14814 'N_EQK' means the type must be the same as (or based on in some way) the key
14815 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
14816 set, various other bits can be set as well in order to modify the meaning of
14817 the type constraint. */
14818
14819 enum neon_type_mask
14820 {
14821 N_S8 = 0x0000001,
14822 N_S16 = 0x0000002,
14823 N_S32 = 0x0000004,
14824 N_S64 = 0x0000008,
14825 N_U8 = 0x0000010,
14826 N_U16 = 0x0000020,
14827 N_U32 = 0x0000040,
14828 N_U64 = 0x0000080,
14829 N_I8 = 0x0000100,
14830 N_I16 = 0x0000200,
14831 N_I32 = 0x0000400,
14832 N_I64 = 0x0000800,
14833 N_8 = 0x0001000,
14834 N_16 = 0x0002000,
14835 N_32 = 0x0004000,
14836 N_64 = 0x0008000,
14837 N_P8 = 0x0010000,
14838 N_P16 = 0x0020000,
14839 N_F16 = 0x0040000,
14840 N_F32 = 0x0080000,
14841 N_F64 = 0x0100000,
14842 N_P64 = 0x0200000,
14843 N_KEY = 0x1000000, /* Key element (main type specifier). */
14844 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
14845 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
14846 N_UNT = 0x8000000, /* Must be explicitly untyped. */
14847 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
14848 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
14849 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
14850 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
14851 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
14852 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
14853 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
14854 N_UTYP = 0,
14855 N_MAX_NONSPECIAL = N_P64
14856 };
14857
14858 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
14859
14860 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
14861 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14862 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
14863 #define N_S_32 (N_S8 | N_S16 | N_S32)
14864 #define N_F_16_32 (N_F16 | N_F32)
14865 #define N_SUF_32 (N_SU_32 | N_F_16_32)
14866 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
14867 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
14868 #define N_F_ALL (N_F16 | N_F32 | N_F64)
14869 #define N_I_MVE (N_I8 | N_I16 | N_I32)
14870 #define N_F_MVE (N_F16 | N_F32)
14871 #define N_SU_MVE (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
14872
14873 /* Pass this as the first type argument to neon_check_type to ignore types
14874 altogether. */
14875 #define N_IGNORE_TYPE (N_KEY | N_EQK)
14876
14877 /* Select a "shape" for the current instruction (describing register types or
14878 sizes) from a list of alternatives. Return NS_NULL if the current instruction
14879 doesn't fit. For non-polymorphic shapes, checking is usually done as a
14880 function of operand parsing, so this function doesn't need to be called.
14881 Shapes should be listed in order of decreasing length. */
14882
14883 static enum neon_shape
14884 neon_select_shape (enum neon_shape shape, ...)
14885 {
14886 va_list ap;
14887 enum neon_shape first_shape = shape;
14888
14889 /* Fix missing optional operands. FIXME: we don't know at this point how
14890 many arguments we should have, so this makes the assumption that we have
14891 > 1. This is true of all current Neon opcodes, I think, but may not be
14892 true in the future. */
14893 if (!inst.operands[1].present)
14894 inst.operands[1] = inst.operands[0];
14895
14896 va_start (ap, shape);
14897
14898 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
14899 {
14900 unsigned j;
14901 int matches = 1;
14902
14903 for (j = 0; j < neon_shape_tab[shape].els; j++)
14904 {
14905 if (!inst.operands[j].present)
14906 {
14907 matches = 0;
14908 break;
14909 }
14910
14911 switch (neon_shape_tab[shape].el[j])
14912 {
14913 /* If a .f16, .16, .u16, .s16 type specifier is given over
14914 a VFP single precision register operand, it's essentially
14915 means only half of the register is used.
14916
14917 If the type specifier is given after the mnemonics, the
14918 information is stored in inst.vectype. If the type specifier
14919 is given after register operand, the information is stored
14920 in inst.operands[].vectype.
14921
14922 When there is only one type specifier, and all the register
14923 operands are the same type of hardware register, the type
14924 specifier applies to all register operands.
14925
14926 If no type specifier is given, the shape is inferred from
14927 operand information.
14928
14929 for example:
14930 vadd.f16 s0, s1, s2: NS_HHH
14931 vabs.f16 s0, s1: NS_HH
14932 vmov.f16 s0, r1: NS_HR
14933 vmov.f16 r0, s1: NS_RH
14934 vcvt.f16 r0, s1: NS_RH
14935 vcvt.f16.s32 s2, s2, #29: NS_HFI
14936 vcvt.f16.s32 s2, s2: NS_HF
14937 */
14938 case SE_H:
14939 if (!(inst.operands[j].isreg
14940 && inst.operands[j].isvec
14941 && inst.operands[j].issingle
14942 && !inst.operands[j].isquad
14943 && ((inst.vectype.elems == 1
14944 && inst.vectype.el[0].size == 16)
14945 || (inst.vectype.elems > 1
14946 && inst.vectype.el[j].size == 16)
14947 || (inst.vectype.elems == 0
14948 && inst.operands[j].vectype.type != NT_invtype
14949 && inst.operands[j].vectype.size == 16))))
14950 matches = 0;
14951 break;
14952
14953 case SE_F:
14954 if (!(inst.operands[j].isreg
14955 && inst.operands[j].isvec
14956 && inst.operands[j].issingle
14957 && !inst.operands[j].isquad
14958 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
14959 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
14960 || (inst.vectype.elems == 0
14961 && (inst.operands[j].vectype.size == 32
14962 || inst.operands[j].vectype.type == NT_invtype)))))
14963 matches = 0;
14964 break;
14965
14966 case SE_D:
14967 if (!(inst.operands[j].isreg
14968 && inst.operands[j].isvec
14969 && !inst.operands[j].isquad
14970 && !inst.operands[j].issingle))
14971 matches = 0;
14972 break;
14973
14974 case SE_R:
14975 if (!(inst.operands[j].isreg
14976 && !inst.operands[j].isvec))
14977 matches = 0;
14978 break;
14979
14980 case SE_Q:
14981 if (!(inst.operands[j].isreg
14982 && inst.operands[j].isvec
14983 && inst.operands[j].isquad
14984 && !inst.operands[j].issingle))
14985 matches = 0;
14986 break;
14987
14988 case SE_I:
14989 if (!(!inst.operands[j].isreg
14990 && !inst.operands[j].isscalar))
14991 matches = 0;
14992 break;
14993
14994 case SE_S:
14995 if (!(!inst.operands[j].isreg
14996 && inst.operands[j].isscalar))
14997 matches = 0;
14998 break;
14999
15000 case SE_L:
15001 break;
15002 }
15003 if (!matches)
15004 break;
15005 }
15006 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
15007 /* We've matched all the entries in the shape table, and we don't
15008 have any left over operands which have not been matched. */
15009 break;
15010 }
15011
15012 va_end (ap);
15013
15014 if (shape == NS_NULL && first_shape != NS_NULL)
15015 first_error (_("invalid instruction shape"));
15016
15017 return shape;
15018 }
15019
15020 /* True if SHAPE is predominantly a quadword operation (most of the time, this
15021 means the Q bit should be set). */
15022
15023 static int
15024 neon_quad (enum neon_shape shape)
15025 {
15026 return neon_shape_class[shape] == SC_QUAD;
15027 }
15028
15029 static void
15030 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
15031 unsigned *g_size)
15032 {
15033 /* Allow modification to be made to types which are constrained to be
15034 based on the key element, based on bits set alongside N_EQK. */
15035 if ((typebits & N_EQK) != 0)
15036 {
15037 if ((typebits & N_HLF) != 0)
15038 *g_size /= 2;
15039 else if ((typebits & N_DBL) != 0)
15040 *g_size *= 2;
15041 if ((typebits & N_SGN) != 0)
15042 *g_type = NT_signed;
15043 else if ((typebits & N_UNS) != 0)
15044 *g_type = NT_unsigned;
15045 else if ((typebits & N_INT) != 0)
15046 *g_type = NT_integer;
15047 else if ((typebits & N_FLT) != 0)
15048 *g_type = NT_float;
15049 else if ((typebits & N_SIZ) != 0)
15050 *g_type = NT_untyped;
15051 }
15052 }
15053
15054 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
15055 operand type, i.e. the single type specified in a Neon instruction when it
15056 is the only one given. */
15057
15058 static struct neon_type_el
15059 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
15060 {
15061 struct neon_type_el dest = *key;
15062
15063 gas_assert ((thisarg & N_EQK) != 0);
15064
15065 neon_modify_type_size (thisarg, &dest.type, &dest.size);
15066
15067 return dest;
15068 }
15069
15070 /* Convert Neon type and size into compact bitmask representation. */
15071
15072 static enum neon_type_mask
15073 type_chk_of_el_type (enum neon_el_type type, unsigned size)
15074 {
15075 switch (type)
15076 {
15077 case NT_untyped:
15078 switch (size)
15079 {
15080 case 8: return N_8;
15081 case 16: return N_16;
15082 case 32: return N_32;
15083 case 64: return N_64;
15084 default: ;
15085 }
15086 break;
15087
15088 case NT_integer:
15089 switch (size)
15090 {
15091 case 8: return N_I8;
15092 case 16: return N_I16;
15093 case 32: return N_I32;
15094 case 64: return N_I64;
15095 default: ;
15096 }
15097 break;
15098
15099 case NT_float:
15100 switch (size)
15101 {
15102 case 16: return N_F16;
15103 case 32: return N_F32;
15104 case 64: return N_F64;
15105 default: ;
15106 }
15107 break;
15108
15109 case NT_poly:
15110 switch (size)
15111 {
15112 case 8: return N_P8;
15113 case 16: return N_P16;
15114 case 64: return N_P64;
15115 default: ;
15116 }
15117 break;
15118
15119 case NT_signed:
15120 switch (size)
15121 {
15122 case 8: return N_S8;
15123 case 16: return N_S16;
15124 case 32: return N_S32;
15125 case 64: return N_S64;
15126 default: ;
15127 }
15128 break;
15129
15130 case NT_unsigned:
15131 switch (size)
15132 {
15133 case 8: return N_U8;
15134 case 16: return N_U16;
15135 case 32: return N_U32;
15136 case 64: return N_U64;
15137 default: ;
15138 }
15139 break;
15140
15141 default: ;
15142 }
15143
15144 return N_UTYP;
15145 }
15146
15147 /* Convert compact Neon bitmask type representation to a type and size. Only
15148 handles the case where a single bit is set in the mask. */
15149
15150 static int
15151 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
15152 enum neon_type_mask mask)
15153 {
15154 if ((mask & N_EQK) != 0)
15155 return FAIL;
15156
15157 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
15158 *size = 8;
15159 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
15160 *size = 16;
15161 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
15162 *size = 32;
15163 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
15164 *size = 64;
15165 else
15166 return FAIL;
15167
15168 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
15169 *type = NT_signed;
15170 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
15171 *type = NT_unsigned;
15172 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
15173 *type = NT_integer;
15174 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
15175 *type = NT_untyped;
15176 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
15177 *type = NT_poly;
15178 else if ((mask & (N_F_ALL)) != 0)
15179 *type = NT_float;
15180 else
15181 return FAIL;
15182
15183 return SUCCESS;
15184 }
15185
15186 /* Modify a bitmask of allowed types. This is only needed for type
15187 relaxation. */
15188
15189 static unsigned
15190 modify_types_allowed (unsigned allowed, unsigned mods)
15191 {
15192 unsigned size;
15193 enum neon_el_type type;
15194 unsigned destmask;
15195 int i;
15196
15197 destmask = 0;
15198
15199 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
15200 {
15201 if (el_type_of_type_chk (&type, &size,
15202 (enum neon_type_mask) (allowed & i)) == SUCCESS)
15203 {
15204 neon_modify_type_size (mods, &type, &size);
15205 destmask |= type_chk_of_el_type (type, size);
15206 }
15207 }
15208
15209 return destmask;
15210 }
15211
15212 /* Check type and return type classification.
15213 The manual states (paraphrase): If one datatype is given, it indicates the
15214 type given in:
15215 - the second operand, if there is one
15216 - the operand, if there is no second operand
15217 - the result, if there are no operands.
15218 This isn't quite good enough though, so we use a concept of a "key" datatype
15219 which is set on a per-instruction basis, which is the one which matters when
15220 only one data type is written.
15221 Note: this function has side-effects (e.g. filling in missing operands). All
15222 Neon instructions should call it before performing bit encoding. */
15223
15224 static struct neon_type_el
15225 neon_check_type (unsigned els, enum neon_shape ns, ...)
15226 {
15227 va_list ap;
15228 unsigned i, pass, key_el = 0;
15229 unsigned types[NEON_MAX_TYPE_ELS];
15230 enum neon_el_type k_type = NT_invtype;
15231 unsigned k_size = -1u;
15232 struct neon_type_el badtype = {NT_invtype, -1};
15233 unsigned key_allowed = 0;
15234
15235 /* Optional registers in Neon instructions are always (not) in operand 1.
15236 Fill in the missing operand here, if it was omitted. */
15237 if (els > 1 && !inst.operands[1].present)
15238 inst.operands[1] = inst.operands[0];
15239
15240 /* Suck up all the varargs. */
15241 va_start (ap, ns);
15242 for (i = 0; i < els; i++)
15243 {
15244 unsigned thisarg = va_arg (ap, unsigned);
15245 if (thisarg == N_IGNORE_TYPE)
15246 {
15247 va_end (ap);
15248 return badtype;
15249 }
15250 types[i] = thisarg;
15251 if ((thisarg & N_KEY) != 0)
15252 key_el = i;
15253 }
15254 va_end (ap);
15255
15256 if (inst.vectype.elems > 0)
15257 for (i = 0; i < els; i++)
15258 if (inst.operands[i].vectype.type != NT_invtype)
15259 {
15260 first_error (_("types specified in both the mnemonic and operands"));
15261 return badtype;
15262 }
15263
15264 /* Duplicate inst.vectype elements here as necessary.
15265 FIXME: No idea if this is exactly the same as the ARM assembler,
15266 particularly when an insn takes one register and one non-register
15267 operand. */
15268 if (inst.vectype.elems == 1 && els > 1)
15269 {
15270 unsigned j;
15271 inst.vectype.elems = els;
15272 inst.vectype.el[key_el] = inst.vectype.el[0];
15273 for (j = 0; j < els; j++)
15274 if (j != key_el)
15275 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15276 types[j]);
15277 }
15278 else if (inst.vectype.elems == 0 && els > 0)
15279 {
15280 unsigned j;
15281 /* No types were given after the mnemonic, so look for types specified
15282 after each operand. We allow some flexibility here; as long as the
15283 "key" operand has a type, we can infer the others. */
15284 for (j = 0; j < els; j++)
15285 if (inst.operands[j].vectype.type != NT_invtype)
15286 inst.vectype.el[j] = inst.operands[j].vectype;
15287
15288 if (inst.operands[key_el].vectype.type != NT_invtype)
15289 {
15290 for (j = 0; j < els; j++)
15291 if (inst.operands[j].vectype.type == NT_invtype)
15292 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
15293 types[j]);
15294 }
15295 else
15296 {
15297 first_error (_("operand types can't be inferred"));
15298 return badtype;
15299 }
15300 }
15301 else if (inst.vectype.elems != els)
15302 {
15303 first_error (_("type specifier has the wrong number of parts"));
15304 return badtype;
15305 }
15306
15307 for (pass = 0; pass < 2; pass++)
15308 {
15309 for (i = 0; i < els; i++)
15310 {
15311 unsigned thisarg = types[i];
15312 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
15313 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
15314 enum neon_el_type g_type = inst.vectype.el[i].type;
15315 unsigned g_size = inst.vectype.el[i].size;
15316
15317 /* Decay more-specific signed & unsigned types to sign-insensitive
15318 integer types if sign-specific variants are unavailable. */
15319 if ((g_type == NT_signed || g_type == NT_unsigned)
15320 && (types_allowed & N_SU_ALL) == 0)
15321 g_type = NT_integer;
15322
15323 /* If only untyped args are allowed, decay any more specific types to
15324 them. Some instructions only care about signs for some element
15325 sizes, so handle that properly. */
15326 if (((types_allowed & N_UNT) == 0)
15327 && ((g_size == 8 && (types_allowed & N_8) != 0)
15328 || (g_size == 16 && (types_allowed & N_16) != 0)
15329 || (g_size == 32 && (types_allowed & N_32) != 0)
15330 || (g_size == 64 && (types_allowed & N_64) != 0)))
15331 g_type = NT_untyped;
15332
15333 if (pass == 0)
15334 {
15335 if ((thisarg & N_KEY) != 0)
15336 {
15337 k_type = g_type;
15338 k_size = g_size;
15339 key_allowed = thisarg & ~N_KEY;
15340
15341 /* Check architecture constraint on FP16 extension. */
15342 if (k_size == 16
15343 && k_type == NT_float
15344 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15345 {
15346 inst.error = _(BAD_FP16);
15347 return badtype;
15348 }
15349 }
15350 }
15351 else
15352 {
15353 if ((thisarg & N_VFP) != 0)
15354 {
15355 enum neon_shape_el regshape;
15356 unsigned regwidth, match;
15357
15358 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
15359 if (ns == NS_NULL)
15360 {
15361 first_error (_("invalid instruction shape"));
15362 return badtype;
15363 }
15364 regshape = neon_shape_tab[ns].el[i];
15365 regwidth = neon_shape_el_size[regshape];
15366
15367 /* In VFP mode, operands must match register widths. If we
15368 have a key operand, use its width, else use the width of
15369 the current operand. */
15370 if (k_size != -1u)
15371 match = k_size;
15372 else
15373 match = g_size;
15374
15375 /* FP16 will use a single precision register. */
15376 if (regwidth == 32 && match == 16)
15377 {
15378 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
15379 match = regwidth;
15380 else
15381 {
15382 inst.error = _(BAD_FP16);
15383 return badtype;
15384 }
15385 }
15386
15387 if (regwidth != match)
15388 {
15389 first_error (_("operand size must match register width"));
15390 return badtype;
15391 }
15392 }
15393
15394 if ((thisarg & N_EQK) == 0)
15395 {
15396 unsigned given_type = type_chk_of_el_type (g_type, g_size);
15397
15398 if ((given_type & types_allowed) == 0)
15399 {
15400 first_error (BAD_SIMD_TYPE);
15401 return badtype;
15402 }
15403 }
15404 else
15405 {
15406 enum neon_el_type mod_k_type = k_type;
15407 unsigned mod_k_size = k_size;
15408 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
15409 if (g_type != mod_k_type || g_size != mod_k_size)
15410 {
15411 first_error (_("inconsistent types in Neon instruction"));
15412 return badtype;
15413 }
15414 }
15415 }
15416 }
15417 }
15418
15419 return inst.vectype.el[key_el];
15420 }
15421
15422 /* Neon-style VFP instruction forwarding. */
15423
15424 /* Thumb VFP instructions have 0xE in the condition field. */
15425
15426 static void
15427 do_vfp_cond_or_thumb (void)
15428 {
15429 inst.is_neon = 1;
15430
15431 if (thumb_mode)
15432 inst.instruction |= 0xe0000000;
15433 else
15434 inst.instruction |= inst.cond << 28;
15435 }
15436
15437 /* Look up and encode a simple mnemonic, for use as a helper function for the
15438 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
15439 etc. It is assumed that operand parsing has already been done, and that the
15440 operands are in the form expected by the given opcode (this isn't necessarily
15441 the same as the form in which they were parsed, hence some massaging must
15442 take place before this function is called).
15443 Checks current arch version against that in the looked-up opcode. */
15444
15445 static void
15446 do_vfp_nsyn_opcode (const char *opname)
15447 {
15448 const struct asm_opcode *opcode;
15449
15450 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
15451
15452 if (!opcode)
15453 abort ();
15454
15455 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
15456 thumb_mode ? *opcode->tvariant : *opcode->avariant),
15457 _(BAD_FPU));
15458
15459 inst.is_neon = 1;
15460
15461 if (thumb_mode)
15462 {
15463 inst.instruction = opcode->tvalue;
15464 opcode->tencode ();
15465 }
15466 else
15467 {
15468 inst.instruction = (inst.cond << 28) | opcode->avalue;
15469 opcode->aencode ();
15470 }
15471 }
15472
15473 static void
15474 do_vfp_nsyn_add_sub (enum neon_shape rs)
15475 {
15476 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
15477
15478 if (rs == NS_FFF || rs == NS_HHH)
15479 {
15480 if (is_add)
15481 do_vfp_nsyn_opcode ("fadds");
15482 else
15483 do_vfp_nsyn_opcode ("fsubs");
15484
15485 /* ARMv8.2 fp16 instruction. */
15486 if (rs == NS_HHH)
15487 do_scalar_fp16_v82_encode ();
15488 }
15489 else
15490 {
15491 if (is_add)
15492 do_vfp_nsyn_opcode ("faddd");
15493 else
15494 do_vfp_nsyn_opcode ("fsubd");
15495 }
15496 }
15497
15498 /* Check operand types to see if this is a VFP instruction, and if so call
15499 PFN (). */
15500
15501 static int
15502 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
15503 {
15504 enum neon_shape rs;
15505 struct neon_type_el et;
15506
15507 switch (args)
15508 {
15509 case 2:
15510 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15511 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15512 break;
15513
15514 case 3:
15515 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15516 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15517 N_F_ALL | N_KEY | N_VFP);
15518 break;
15519
15520 default:
15521 abort ();
15522 }
15523
15524 if (et.type != NT_invtype)
15525 {
15526 pfn (rs);
15527 return SUCCESS;
15528 }
15529
15530 inst.error = NULL;
15531 return FAIL;
15532 }
15533
15534 static void
15535 do_vfp_nsyn_mla_mls (enum neon_shape rs)
15536 {
15537 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
15538
15539 if (rs == NS_FFF || rs == NS_HHH)
15540 {
15541 if (is_mla)
15542 do_vfp_nsyn_opcode ("fmacs");
15543 else
15544 do_vfp_nsyn_opcode ("fnmacs");
15545
15546 /* ARMv8.2 fp16 instruction. */
15547 if (rs == NS_HHH)
15548 do_scalar_fp16_v82_encode ();
15549 }
15550 else
15551 {
15552 if (is_mla)
15553 do_vfp_nsyn_opcode ("fmacd");
15554 else
15555 do_vfp_nsyn_opcode ("fnmacd");
15556 }
15557 }
15558
15559 static void
15560 do_vfp_nsyn_fma_fms (enum neon_shape rs)
15561 {
15562 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
15563
15564 if (rs == NS_FFF || rs == NS_HHH)
15565 {
15566 if (is_fma)
15567 do_vfp_nsyn_opcode ("ffmas");
15568 else
15569 do_vfp_nsyn_opcode ("ffnmas");
15570
15571 /* ARMv8.2 fp16 instruction. */
15572 if (rs == NS_HHH)
15573 do_scalar_fp16_v82_encode ();
15574 }
15575 else
15576 {
15577 if (is_fma)
15578 do_vfp_nsyn_opcode ("ffmad");
15579 else
15580 do_vfp_nsyn_opcode ("ffnmad");
15581 }
15582 }
15583
15584 static void
15585 do_vfp_nsyn_mul (enum neon_shape rs)
15586 {
15587 if (rs == NS_FFF || rs == NS_HHH)
15588 {
15589 do_vfp_nsyn_opcode ("fmuls");
15590
15591 /* ARMv8.2 fp16 instruction. */
15592 if (rs == NS_HHH)
15593 do_scalar_fp16_v82_encode ();
15594 }
15595 else
15596 do_vfp_nsyn_opcode ("fmuld");
15597 }
15598
15599 static void
15600 do_vfp_nsyn_abs_neg (enum neon_shape rs)
15601 {
15602 int is_neg = (inst.instruction & 0x80) != 0;
15603 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
15604
15605 if (rs == NS_FF || rs == NS_HH)
15606 {
15607 if (is_neg)
15608 do_vfp_nsyn_opcode ("fnegs");
15609 else
15610 do_vfp_nsyn_opcode ("fabss");
15611
15612 /* ARMv8.2 fp16 instruction. */
15613 if (rs == NS_HH)
15614 do_scalar_fp16_v82_encode ();
15615 }
15616 else
15617 {
15618 if (is_neg)
15619 do_vfp_nsyn_opcode ("fnegd");
15620 else
15621 do_vfp_nsyn_opcode ("fabsd");
15622 }
15623 }
15624
15625 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
15626 insns belong to Neon, and are handled elsewhere. */
15627
15628 static void
15629 do_vfp_nsyn_ldm_stm (int is_dbmode)
15630 {
15631 int is_ldm = (inst.instruction & (1 << 20)) != 0;
15632 if (is_ldm)
15633 {
15634 if (is_dbmode)
15635 do_vfp_nsyn_opcode ("fldmdbs");
15636 else
15637 do_vfp_nsyn_opcode ("fldmias");
15638 }
15639 else
15640 {
15641 if (is_dbmode)
15642 do_vfp_nsyn_opcode ("fstmdbs");
15643 else
15644 do_vfp_nsyn_opcode ("fstmias");
15645 }
15646 }
15647
15648 static void
15649 do_vfp_nsyn_sqrt (void)
15650 {
15651 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
15652 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
15653
15654 if (rs == NS_FF || rs == NS_HH)
15655 {
15656 do_vfp_nsyn_opcode ("fsqrts");
15657
15658 /* ARMv8.2 fp16 instruction. */
15659 if (rs == NS_HH)
15660 do_scalar_fp16_v82_encode ();
15661 }
15662 else
15663 do_vfp_nsyn_opcode ("fsqrtd");
15664 }
15665
15666 static void
15667 do_vfp_nsyn_div (void)
15668 {
15669 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15670 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15671 N_F_ALL | N_KEY | N_VFP);
15672
15673 if (rs == NS_FFF || rs == NS_HHH)
15674 {
15675 do_vfp_nsyn_opcode ("fdivs");
15676
15677 /* ARMv8.2 fp16 instruction. */
15678 if (rs == NS_HHH)
15679 do_scalar_fp16_v82_encode ();
15680 }
15681 else
15682 do_vfp_nsyn_opcode ("fdivd");
15683 }
15684
15685 static void
15686 do_vfp_nsyn_nmul (void)
15687 {
15688 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
15689 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
15690 N_F_ALL | N_KEY | N_VFP);
15691
15692 if (rs == NS_FFF || rs == NS_HHH)
15693 {
15694 NEON_ENCODE (SINGLE, inst);
15695 do_vfp_sp_dyadic ();
15696
15697 /* ARMv8.2 fp16 instruction. */
15698 if (rs == NS_HHH)
15699 do_scalar_fp16_v82_encode ();
15700 }
15701 else
15702 {
15703 NEON_ENCODE (DOUBLE, inst);
15704 do_vfp_dp_rd_rn_rm ();
15705 }
15706 do_vfp_cond_or_thumb ();
15707
15708 }
15709
15710 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
15711 (0, 1, 2, 3). */
15712
15713 static unsigned
15714 neon_logbits (unsigned x)
15715 {
15716 return ffs (x) - 4;
15717 }
15718
15719 #define LOW4(R) ((R) & 0xf)
15720 #define HI1(R) (((R) >> 4) & 1)
15721
15722 static unsigned
15723 mve_get_vcmp_vpt_cond (struct neon_type_el et)
15724 {
15725 switch (et.type)
15726 {
15727 default:
15728 first_error (BAD_EL_TYPE);
15729 return 0;
15730 case NT_float:
15731 switch (inst.operands[0].imm)
15732 {
15733 default:
15734 first_error (_("invalid condition"));
15735 return 0;
15736 case 0x0:
15737 /* eq. */
15738 return 0;
15739 case 0x1:
15740 /* ne. */
15741 return 1;
15742 case 0xa:
15743 /* ge/ */
15744 return 4;
15745 case 0xb:
15746 /* lt. */
15747 return 5;
15748 case 0xc:
15749 /* gt. */
15750 return 6;
15751 case 0xd:
15752 /* le. */
15753 return 7;
15754 }
15755 case NT_integer:
15756 /* only accept eq and ne. */
15757 if (inst.operands[0].imm > 1)
15758 {
15759 first_error (_("invalid condition"));
15760 return 0;
15761 }
15762 return inst.operands[0].imm;
15763 case NT_unsigned:
15764 if (inst.operands[0].imm == 0x2)
15765 return 2;
15766 else if (inst.operands[0].imm == 0x8)
15767 return 3;
15768 else
15769 {
15770 first_error (_("invalid condition"));
15771 return 0;
15772 }
15773 case NT_signed:
15774 switch (inst.operands[0].imm)
15775 {
15776 default:
15777 first_error (_("invalid condition"));
15778 return 0;
15779 case 0xa:
15780 /* ge. */
15781 return 4;
15782 case 0xb:
15783 /* lt. */
15784 return 5;
15785 case 0xc:
15786 /* gt. */
15787 return 6;
15788 case 0xd:
15789 /* le. */
15790 return 7;
15791 }
15792 }
15793 /* Should be unreachable. */
15794 abort ();
15795 }
15796
15797 /* For VCTP (create vector tail predicate) in MVE. */
15798 static void
15799 do_mve_vctp (void)
15800 {
15801 int dt = 0;
15802 unsigned size = 0x0;
15803
15804 if (inst.cond > COND_ALWAYS)
15805 inst.pred_insn_type = INSIDE_VPT_INSN;
15806 else
15807 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15808
15809 /* This is a typical MVE instruction which has no type but have size 8, 16,
15810 32 and 64. For instructions with no type, inst.vectype.el[j].type is set
15811 to NT_untyped and size is updated in inst.vectype.el[j].size. */
15812 if ((inst.operands[0].present) && (inst.vectype.el[0].type == NT_untyped))
15813 dt = inst.vectype.el[0].size;
15814
15815 /* Setting this does not indicate an actual NEON instruction, but only
15816 indicates that the mnemonic accepts neon-style type suffixes. */
15817 inst.is_neon = 1;
15818
15819 switch (dt)
15820 {
15821 case 8:
15822 break;
15823 case 16:
15824 size = 0x1; break;
15825 case 32:
15826 size = 0x2; break;
15827 case 64:
15828 size = 0x3; break;
15829 default:
15830 first_error (_("Type is not allowed for this instruction"));
15831 }
15832 inst.instruction |= size << 20;
15833 inst.instruction |= inst.operands[0].reg << 16;
15834 }
15835
15836 static void
15837 do_mve_vpt (void)
15838 {
15839 /* We are dealing with a vector predicated block. */
15840 if (inst.operands[0].present)
15841 {
15842 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15843 struct neon_type_el et
15844 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15845 N_EQK);
15846
15847 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15848
15849 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15850
15851 if (et.type == NT_invtype)
15852 return;
15853
15854 if (et.type == NT_float)
15855 {
15856 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15857 BAD_FPU);
15858 constraint (et.size != 16 && et.size != 32, BAD_EL_TYPE);
15859 inst.instruction |= (et.size == 16) << 28;
15860 inst.instruction |= 0x3 << 20;
15861 }
15862 else
15863 {
15864 constraint (et.size != 8 && et.size != 16 && et.size != 32,
15865 BAD_EL_TYPE);
15866 inst.instruction |= 1 << 28;
15867 inst.instruction |= neon_logbits (et.size) << 20;
15868 }
15869
15870 if (inst.operands[2].isquad)
15871 {
15872 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15873 inst.instruction |= LOW4 (inst.operands[2].reg);
15874 inst.instruction |= (fcond & 0x2) >> 1;
15875 }
15876 else
15877 {
15878 if (inst.operands[2].reg == REG_SP)
15879 as_tsktsk (MVE_BAD_SP);
15880 inst.instruction |= 1 << 6;
15881 inst.instruction |= (fcond & 0x2) << 4;
15882 inst.instruction |= inst.operands[2].reg;
15883 }
15884 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15885 inst.instruction |= (fcond & 0x4) << 10;
15886 inst.instruction |= (fcond & 0x1) << 7;
15887
15888 }
15889 set_pred_insn_type (VPT_INSN);
15890 now_pred.cc = 0;
15891 now_pred.mask = ((inst.instruction & 0x00400000) >> 19)
15892 | ((inst.instruction & 0xe000) >> 13);
15893 now_pred.warn_deprecated = FALSE;
15894 now_pred.type = VECTOR_PRED;
15895 inst.is_neon = 1;
15896 }
15897
15898 static void
15899 do_mve_vcmp (void)
15900 {
15901 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
15902 if (!inst.operands[1].isreg || !inst.operands[1].isquad)
15903 first_error (_(reg_expected_msgs[REG_TYPE_MQ]));
15904 if (!inst.operands[2].present)
15905 first_error (_("MVE vector or ARM register expected"));
15906 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
15907
15908 /* Deal with 'else' conditional MVE's vcmp, it will be parsed as vcmpe. */
15909 if ((inst.instruction & 0xffffffff) == N_MNEM_vcmpe
15910 && inst.operands[1].isquad)
15911 {
15912 inst.instruction = N_MNEM_vcmp;
15913 inst.cond = 0x10;
15914 }
15915
15916 if (inst.cond > COND_ALWAYS)
15917 inst.pred_insn_type = INSIDE_VPT_INSN;
15918 else
15919 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15920
15921 enum neon_shape rs = neon_select_shape (NS_IQQ, NS_IQR, NS_NULL);
15922 struct neon_type_el et
15923 = neon_check_type (3, rs, N_EQK, N_KEY | N_F_MVE | N_I_MVE | N_SU_32,
15924 N_EQK);
15925
15926 constraint (rs == NS_IQR && inst.operands[2].reg == REG_PC
15927 && !inst.operands[2].iszr, BAD_PC);
15928
15929 unsigned fcond = mve_get_vcmp_vpt_cond (et);
15930
15931 inst.instruction = 0xee010f00;
15932 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15933 inst.instruction |= (fcond & 0x4) << 10;
15934 inst.instruction |= (fcond & 0x1) << 7;
15935 if (et.type == NT_float)
15936 {
15937 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
15938 BAD_FPU);
15939 inst.instruction |= (et.size == 16) << 28;
15940 inst.instruction |= 0x3 << 20;
15941 }
15942 else
15943 {
15944 inst.instruction |= 1 << 28;
15945 inst.instruction |= neon_logbits (et.size) << 20;
15946 }
15947 if (inst.operands[2].isquad)
15948 {
15949 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15950 inst.instruction |= (fcond & 0x2) >> 1;
15951 inst.instruction |= LOW4 (inst.operands[2].reg);
15952 }
15953 else
15954 {
15955 if (inst.operands[2].reg == REG_SP)
15956 as_tsktsk (MVE_BAD_SP);
15957 inst.instruction |= 1 << 6;
15958 inst.instruction |= (fcond & 0x2) << 4;
15959 inst.instruction |= inst.operands[2].reg;
15960 }
15961
15962 inst.is_neon = 1;
15963 return;
15964 }
15965
15966 static void
15967 do_mve_vmaxa_vmina (void)
15968 {
15969 if (inst.cond > COND_ALWAYS)
15970 inst.pred_insn_type = INSIDE_VPT_INSN;
15971 else
15972 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15973
15974 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
15975 struct neon_type_el et
15976 = neon_check_type (2, rs, N_EQK, N_KEY | N_S8 | N_S16 | N_S32);
15977
15978 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15979 inst.instruction |= neon_logbits (et.size) << 18;
15980 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15981 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15982 inst.instruction |= LOW4 (inst.operands[1].reg);
15983 inst.is_neon = 1;
15984 }
15985
15986 static void
15987 do_mve_vfmas (void)
15988 {
15989 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
15990 struct neon_type_el et
15991 = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK, N_EQK);
15992
15993 if (inst.cond > COND_ALWAYS)
15994 inst.pred_insn_type = INSIDE_VPT_INSN;
15995 else
15996 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
15997
15998 if (inst.operands[2].reg == REG_SP)
15999 as_tsktsk (MVE_BAD_SP);
16000 else if (inst.operands[2].reg == REG_PC)
16001 as_tsktsk (MVE_BAD_PC);
16002
16003 inst.instruction |= (et.size == 16) << 28;
16004 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16005 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16006 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16007 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16008 inst.instruction |= inst.operands[2].reg;
16009 inst.is_neon = 1;
16010 }
16011
16012 static void
16013 do_mve_viddup (void)
16014 {
16015 if (inst.cond > COND_ALWAYS)
16016 inst.pred_insn_type = INSIDE_VPT_INSN;
16017 else
16018 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16019
16020 unsigned imm = inst.relocs[0].exp.X_add_number;
16021 constraint (imm != 1 && imm != 2 && imm != 4 && imm != 8,
16022 _("immediate must be either 1, 2, 4 or 8"));
16023
16024 enum neon_shape rs;
16025 struct neon_type_el et;
16026 unsigned Rm;
16027 if (inst.instruction == M_MNEM_vddup || inst.instruction == M_MNEM_vidup)
16028 {
16029 rs = neon_select_shape (NS_QRI, NS_NULL);
16030 et = neon_check_type (2, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK);
16031 Rm = 7;
16032 }
16033 else
16034 {
16035 constraint ((inst.operands[2].reg % 2) != 1, BAD_EVEN);
16036 if (inst.operands[2].reg == REG_SP)
16037 as_tsktsk (MVE_BAD_SP);
16038 else if (inst.operands[2].reg == REG_PC)
16039 first_error (BAD_PC);
16040
16041 rs = neon_select_shape (NS_QRRI, NS_NULL);
16042 et = neon_check_type (3, rs, N_KEY | N_U8 | N_U16 | N_U32, N_EQK, N_EQK);
16043 Rm = inst.operands[2].reg >> 1;
16044 }
16045 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16046 inst.instruction |= neon_logbits (et.size) << 20;
16047 inst.instruction |= inst.operands[1].reg << 16;
16048 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16049 inst.instruction |= (imm > 2) << 7;
16050 inst.instruction |= Rm << 1;
16051 inst.instruction |= (imm == 2 || imm == 8);
16052 inst.is_neon = 1;
16053 }
16054
16055 static void
16056 do_mve_vmlas (void)
16057 {
16058 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
16059 struct neon_type_el et
16060 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16061
16062 if (inst.operands[2].reg == REG_PC)
16063 as_tsktsk (MVE_BAD_PC);
16064 else if (inst.operands[2].reg == REG_SP)
16065 as_tsktsk (MVE_BAD_SP);
16066
16067 if (inst.cond > COND_ALWAYS)
16068 inst.pred_insn_type = INSIDE_VPT_INSN;
16069 else
16070 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16071
16072 inst.instruction |= (et.type == NT_unsigned) << 28;
16073 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16074 inst.instruction |= neon_logbits (et.size) << 20;
16075 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16076 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16077 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16078 inst.instruction |= inst.operands[2].reg;
16079 inst.is_neon = 1;
16080 }
16081
16082 static void
16083 do_mve_vshll (void)
16084 {
16085 struct neon_type_el et
16086 = neon_check_type (2, NS_QQI, N_EQK, N_S8 | N_U8 | N_S16 | N_U16 | N_KEY);
16087
16088 if (inst.cond > COND_ALWAYS)
16089 inst.pred_insn_type = INSIDE_VPT_INSN;
16090 else
16091 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16092
16093 int imm = inst.operands[2].imm;
16094 constraint (imm < 1 || (unsigned)imm > et.size,
16095 _("immediate value out of range"));
16096
16097 if ((unsigned)imm == et.size)
16098 {
16099 inst.instruction |= neon_logbits (et.size) << 18;
16100 inst.instruction |= 0x110001;
16101 }
16102 else
16103 {
16104 inst.instruction |= (et.size + imm) << 16;
16105 inst.instruction |= 0x800140;
16106 }
16107
16108 inst.instruction |= (et.type == NT_unsigned) << 28;
16109 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16110 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16111 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16112 inst.instruction |= LOW4 (inst.operands[1].reg);
16113 inst.is_neon = 1;
16114 }
16115
16116 static void
16117 do_mve_vshlc (void)
16118 {
16119 if (inst.cond > COND_ALWAYS)
16120 inst.pred_insn_type = INSIDE_VPT_INSN;
16121 else
16122 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16123
16124 if (inst.operands[1].reg == REG_PC)
16125 as_tsktsk (MVE_BAD_PC);
16126 else if (inst.operands[1].reg == REG_SP)
16127 as_tsktsk (MVE_BAD_SP);
16128
16129 int imm = inst.operands[2].imm;
16130 constraint (imm < 1 || imm > 32, _("immediate value out of range"));
16131
16132 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16133 inst.instruction |= (imm & 0x1f) << 16;
16134 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16135 inst.instruction |= inst.operands[1].reg;
16136 inst.is_neon = 1;
16137 }
16138
16139 static void
16140 do_mve_vshrn (void)
16141 {
16142 unsigned types;
16143 switch (inst.instruction)
16144 {
16145 case M_MNEM_vshrnt:
16146 case M_MNEM_vshrnb:
16147 case M_MNEM_vrshrnt:
16148 case M_MNEM_vrshrnb:
16149 types = N_I16 | N_I32;
16150 break;
16151 case M_MNEM_vqshrnt:
16152 case M_MNEM_vqshrnb:
16153 case M_MNEM_vqrshrnt:
16154 case M_MNEM_vqrshrnb:
16155 types = N_U16 | N_U32 | N_S16 | N_S32;
16156 break;
16157 case M_MNEM_vqshrunt:
16158 case M_MNEM_vqshrunb:
16159 case M_MNEM_vqrshrunt:
16160 case M_MNEM_vqrshrunb:
16161 types = N_S16 | N_S32;
16162 break;
16163 default:
16164 abort ();
16165 }
16166
16167 struct neon_type_el et = neon_check_type (2, NS_QQI, N_EQK, types | N_KEY);
16168
16169 if (inst.cond > COND_ALWAYS)
16170 inst.pred_insn_type = INSIDE_VPT_INSN;
16171 else
16172 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16173
16174 unsigned Qd = inst.operands[0].reg;
16175 unsigned Qm = inst.operands[1].reg;
16176 unsigned imm = inst.operands[2].imm;
16177 constraint (imm < 1 || ((unsigned) imm) > (et.size / 2),
16178 et.size == 16
16179 ? _("immediate operand expected in the range [1,8]")
16180 : _("immediate operand expected in the range [1,16]"));
16181
16182 inst.instruction |= (et.type == NT_unsigned) << 28;
16183 inst.instruction |= HI1 (Qd) << 22;
16184 inst.instruction |= (et.size - imm) << 16;
16185 inst.instruction |= LOW4 (Qd) << 12;
16186 inst.instruction |= HI1 (Qm) << 5;
16187 inst.instruction |= LOW4 (Qm);
16188 inst.is_neon = 1;
16189 }
16190
16191 static void
16192 do_mve_vqmovn (void)
16193 {
16194 struct neon_type_el et;
16195 if (inst.instruction == M_MNEM_vqmovnt
16196 || inst.instruction == M_MNEM_vqmovnb)
16197 et = neon_check_type (2, NS_QQ, N_EQK,
16198 N_U16 | N_U32 | N_S16 | N_S32 | N_KEY);
16199 else
16200 et = neon_check_type (2, NS_QQ, N_EQK, N_S16 | N_S32 | N_KEY);
16201
16202 if (inst.cond > COND_ALWAYS)
16203 inst.pred_insn_type = INSIDE_VPT_INSN;
16204 else
16205 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16206
16207 inst.instruction |= (et.type == NT_unsigned) << 28;
16208 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16209 inst.instruction |= (et.size == 32) << 18;
16210 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16211 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16212 inst.instruction |= LOW4 (inst.operands[1].reg);
16213 inst.is_neon = 1;
16214 }
16215
16216 static void
16217 do_mve_vpsel (void)
16218 {
16219 neon_select_shape (NS_QQQ, NS_NULL);
16220
16221 if (inst.cond > COND_ALWAYS)
16222 inst.pred_insn_type = INSIDE_VPT_INSN;
16223 else
16224 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16225
16226 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16227 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16228 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16229 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16230 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16231 inst.instruction |= LOW4 (inst.operands[2].reg);
16232 inst.is_neon = 1;
16233 }
16234
16235 static void
16236 do_mve_vpnot (void)
16237 {
16238 if (inst.cond > COND_ALWAYS)
16239 inst.pred_insn_type = INSIDE_VPT_INSN;
16240 else
16241 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16242 }
16243
16244 static void
16245 do_mve_vmaxnma_vminnma (void)
16246 {
16247 enum neon_shape rs = neon_select_shape (NS_QQ, NS_NULL);
16248 struct neon_type_el et
16249 = neon_check_type (2, rs, N_EQK, N_F_MVE | 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 inst.instruction |= (et.size == 16) << 28;
16257 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16258 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16259 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16260 inst.instruction |= LOW4 (inst.operands[1].reg);
16261 inst.is_neon = 1;
16262 }
16263
16264 static void
16265 do_mve_vcmul (void)
16266 {
16267 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
16268 struct neon_type_el et
16269 = neon_check_type (3, rs, N_EQK, N_EQK, N_F_MVE | N_KEY);
16270
16271 if (inst.cond > COND_ALWAYS)
16272 inst.pred_insn_type = INSIDE_VPT_INSN;
16273 else
16274 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16275
16276 unsigned rot = inst.relocs[0].exp.X_add_number;
16277 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
16278 _("immediate out of range"));
16279
16280 if (et.size == 32 && (inst.operands[0].reg == inst.operands[1].reg
16281 || inst.operands[0].reg == inst.operands[2].reg))
16282 as_tsktsk (BAD_MVE_SRCDEST);
16283
16284 inst.instruction |= (et.size == 32) << 28;
16285 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16286 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16287 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16288 inst.instruction |= (rot > 90) << 12;
16289 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16290 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16291 inst.instruction |= LOW4 (inst.operands[2].reg);
16292 inst.instruction |= (rot == 90 || rot == 270);
16293 inst.is_neon = 1;
16294 }
16295
16296 /* To handle the Low Overhead Loop instructions
16297 in Armv8.1-M Mainline and MVE. */
16298 static void
16299 do_t_loloop (void)
16300 {
16301 unsigned long insn = inst.instruction;
16302
16303 inst.instruction = THUMB_OP32 (inst.instruction);
16304
16305 if (insn == T_MNEM_lctp)
16306 return;
16307
16308 set_pred_insn_type (MVE_OUTSIDE_PRED_INSN);
16309
16310 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16311 {
16312 struct neon_type_el et
16313 = neon_check_type (2, NS_RR, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16314 inst.instruction |= neon_logbits (et.size) << 20;
16315 inst.is_neon = 1;
16316 }
16317
16318 switch (insn)
16319 {
16320 case T_MNEM_letp:
16321 constraint (!inst.operands[0].present,
16322 _("expected LR"));
16323 /* fall through. */
16324 case T_MNEM_le:
16325 /* le <label>. */
16326 if (!inst.operands[0].present)
16327 inst.instruction |= 1 << 21;
16328
16329 v8_1_loop_reloc (TRUE);
16330 break;
16331
16332 case T_MNEM_wls:
16333 case T_MNEM_wlstp:
16334 v8_1_loop_reloc (FALSE);
16335 /* fall through. */
16336 case T_MNEM_dlstp:
16337 case T_MNEM_dls:
16338 constraint (inst.operands[1].isreg != 1, BAD_ARGS);
16339
16340 if (insn == T_MNEM_wlstp || insn == T_MNEM_dlstp)
16341 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
16342 else if (inst.operands[1].reg == REG_PC)
16343 as_tsktsk (MVE_BAD_PC);
16344 if (inst.operands[1].reg == REG_SP)
16345 as_tsktsk (MVE_BAD_SP);
16346
16347 inst.instruction |= (inst.operands[1].reg << 16);
16348 break;
16349
16350 default:
16351 abort ();
16352 }
16353 }
16354
16355
16356 static void
16357 do_vfp_nsyn_cmp (void)
16358 {
16359 enum neon_shape rs;
16360 if (!inst.operands[0].isreg)
16361 {
16362 do_mve_vcmp ();
16363 return;
16364 }
16365 else
16366 {
16367 constraint (inst.operands[2].present, BAD_SYNTAX);
16368 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd),
16369 BAD_FPU);
16370 }
16371
16372 if (inst.operands[1].isreg)
16373 {
16374 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
16375 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
16376
16377 if (rs == NS_FF || rs == NS_HH)
16378 {
16379 NEON_ENCODE (SINGLE, inst);
16380 do_vfp_sp_monadic ();
16381 }
16382 else
16383 {
16384 NEON_ENCODE (DOUBLE, inst);
16385 do_vfp_dp_rd_rm ();
16386 }
16387 }
16388 else
16389 {
16390 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
16391 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
16392
16393 switch (inst.instruction & 0x0fffffff)
16394 {
16395 case N_MNEM_vcmp:
16396 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
16397 break;
16398 case N_MNEM_vcmpe:
16399 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
16400 break;
16401 default:
16402 abort ();
16403 }
16404
16405 if (rs == NS_FI || rs == NS_HI)
16406 {
16407 NEON_ENCODE (SINGLE, inst);
16408 do_vfp_sp_compare_z ();
16409 }
16410 else
16411 {
16412 NEON_ENCODE (DOUBLE, inst);
16413 do_vfp_dp_rd ();
16414 }
16415 }
16416 do_vfp_cond_or_thumb ();
16417
16418 /* ARMv8.2 fp16 instruction. */
16419 if (rs == NS_HI || rs == NS_HH)
16420 do_scalar_fp16_v82_encode ();
16421 }
16422
16423 static void
16424 nsyn_insert_sp (void)
16425 {
16426 inst.operands[1] = inst.operands[0];
16427 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
16428 inst.operands[0].reg = REG_SP;
16429 inst.operands[0].isreg = 1;
16430 inst.operands[0].writeback = 1;
16431 inst.operands[0].present = 1;
16432 }
16433
16434 static void
16435 do_vfp_nsyn_push (void)
16436 {
16437 nsyn_insert_sp ();
16438
16439 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
16440 _("register list must contain at least 1 and at most 16 "
16441 "registers"));
16442
16443 if (inst.operands[1].issingle)
16444 do_vfp_nsyn_opcode ("fstmdbs");
16445 else
16446 do_vfp_nsyn_opcode ("fstmdbd");
16447 }
16448
16449 static void
16450 do_vfp_nsyn_pop (void)
16451 {
16452 nsyn_insert_sp ();
16453
16454 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
16455 _("register list must contain at least 1 and at most 16 "
16456 "registers"));
16457
16458 if (inst.operands[1].issingle)
16459 do_vfp_nsyn_opcode ("fldmias");
16460 else
16461 do_vfp_nsyn_opcode ("fldmiad");
16462 }
16463
16464 /* Fix up Neon data-processing instructions, ORing in the correct bits for
16465 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
16466
16467 static void
16468 neon_dp_fixup (struct arm_it* insn)
16469 {
16470 unsigned int i = insn->instruction;
16471 insn->is_neon = 1;
16472
16473 if (thumb_mode)
16474 {
16475 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
16476 if (i & (1 << 24))
16477 i |= 1 << 28;
16478
16479 i &= ~(1 << 24);
16480
16481 i |= 0xef000000;
16482 }
16483 else
16484 i |= 0xf2000000;
16485
16486 insn->instruction = i;
16487 }
16488
16489 static void
16490 mve_encode_qqr (int size, int U, int fp)
16491 {
16492 if (inst.operands[2].reg == REG_SP)
16493 as_tsktsk (MVE_BAD_SP);
16494 else if (inst.operands[2].reg == REG_PC)
16495 as_tsktsk (MVE_BAD_PC);
16496
16497 if (fp)
16498 {
16499 /* vadd. */
16500 if (((unsigned)inst.instruction) == 0xd00)
16501 inst.instruction = 0xee300f40;
16502 /* vsub. */
16503 else if (((unsigned)inst.instruction) == 0x200d00)
16504 inst.instruction = 0xee301f40;
16505 /* vmul. */
16506 else if (((unsigned)inst.instruction) == 0x1000d10)
16507 inst.instruction = 0xee310e60;
16508
16509 /* Setting size which is 1 for F16 and 0 for F32. */
16510 inst.instruction |= (size == 16) << 28;
16511 }
16512 else
16513 {
16514 /* vadd. */
16515 if (((unsigned)inst.instruction) == 0x800)
16516 inst.instruction = 0xee010f40;
16517 /* vsub. */
16518 else if (((unsigned)inst.instruction) == 0x1000800)
16519 inst.instruction = 0xee011f40;
16520 /* vhadd. */
16521 else if (((unsigned)inst.instruction) == 0)
16522 inst.instruction = 0xee000f40;
16523 /* vhsub. */
16524 else if (((unsigned)inst.instruction) == 0x200)
16525 inst.instruction = 0xee001f40;
16526 /* vmla. */
16527 else if (((unsigned)inst.instruction) == 0x900)
16528 inst.instruction = 0xee010e40;
16529 /* vmul. */
16530 else if (((unsigned)inst.instruction) == 0x910)
16531 inst.instruction = 0xee011e60;
16532 /* vqadd. */
16533 else if (((unsigned)inst.instruction) == 0x10)
16534 inst.instruction = 0xee000f60;
16535 /* vqsub. */
16536 else if (((unsigned)inst.instruction) == 0x210)
16537 inst.instruction = 0xee001f60;
16538 /* vqrdmlah. */
16539 else if (((unsigned)inst.instruction) == 0x3000b10)
16540 inst.instruction = 0xee000e40;
16541 /* vqdmulh. */
16542 else if (((unsigned)inst.instruction) == 0x0000b00)
16543 inst.instruction = 0xee010e60;
16544 /* vqrdmulh. */
16545 else if (((unsigned)inst.instruction) == 0x1000b00)
16546 inst.instruction = 0xfe010e60;
16547
16548 /* Set U-bit. */
16549 inst.instruction |= U << 28;
16550
16551 /* Setting bits for size. */
16552 inst.instruction |= neon_logbits (size) << 20;
16553 }
16554 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16555 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16556 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16557 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16558 inst.instruction |= inst.operands[2].reg;
16559 inst.is_neon = 1;
16560 }
16561
16562 static void
16563 mve_encode_rqq (unsigned bit28, unsigned size)
16564 {
16565 inst.instruction |= bit28 << 28;
16566 inst.instruction |= neon_logbits (size) << 20;
16567 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16568 inst.instruction |= inst.operands[0].reg << 12;
16569 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16570 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16571 inst.instruction |= LOW4 (inst.operands[2].reg);
16572 inst.is_neon = 1;
16573 }
16574
16575 static void
16576 mve_encode_qqq (int ubit, int size)
16577 {
16578
16579 inst.instruction |= (ubit != 0) << 28;
16580 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16581 inst.instruction |= neon_logbits (size) << 20;
16582 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16583 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16584 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16585 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16586 inst.instruction |= LOW4 (inst.operands[2].reg);
16587
16588 inst.is_neon = 1;
16589 }
16590
16591 static void
16592 mve_encode_rq (unsigned bit28, unsigned size)
16593 {
16594 inst.instruction |= bit28 << 28;
16595 inst.instruction |= neon_logbits (size) << 18;
16596 inst.instruction |= inst.operands[0].reg << 12;
16597 inst.instruction |= LOW4 (inst.operands[1].reg);
16598 inst.is_neon = 1;
16599 }
16600
16601 static void
16602 mve_encode_rrqq (unsigned U, unsigned size)
16603 {
16604 constraint (inst.operands[3].reg > 14, MVE_BAD_QREG);
16605
16606 inst.instruction |= U << 28;
16607 inst.instruction |= (inst.operands[1].reg >> 1) << 20;
16608 inst.instruction |= LOW4 (inst.operands[2].reg) << 16;
16609 inst.instruction |= (size == 32) << 16;
16610 inst.instruction |= inst.operands[0].reg << 12;
16611 inst.instruction |= HI1 (inst.operands[2].reg) << 7;
16612 inst.instruction |= inst.operands[3].reg;
16613 inst.is_neon = 1;
16614 }
16615
16616 /* Encode insns with bit pattern:
16617
16618 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16619 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
16620
16621 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
16622 different meaning for some instruction. */
16623
16624 static void
16625 neon_three_same (int isquad, int ubit, int size)
16626 {
16627 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16628 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16629 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16630 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16631 inst.instruction |= LOW4 (inst.operands[2].reg);
16632 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16633 inst.instruction |= (isquad != 0) << 6;
16634 inst.instruction |= (ubit != 0) << 24;
16635 if (size != -1)
16636 inst.instruction |= neon_logbits (size) << 20;
16637
16638 neon_dp_fixup (&inst);
16639 }
16640
16641 /* Encode instructions of the form:
16642
16643 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
16644 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
16645
16646 Don't write size if SIZE == -1. */
16647
16648 static void
16649 neon_two_same (int qbit, int ubit, int size)
16650 {
16651 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16652 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16653 inst.instruction |= LOW4 (inst.operands[1].reg);
16654 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16655 inst.instruction |= (qbit != 0) << 6;
16656 inst.instruction |= (ubit != 0) << 24;
16657
16658 if (size != -1)
16659 inst.instruction |= neon_logbits (size) << 18;
16660
16661 neon_dp_fixup (&inst);
16662 }
16663
16664 enum vfp_or_neon_is_neon_bits
16665 {
16666 NEON_CHECK_CC = 1,
16667 NEON_CHECK_ARCH = 2,
16668 NEON_CHECK_ARCH8 = 4
16669 };
16670
16671 /* Call this function if an instruction which may have belonged to the VFP or
16672 Neon instruction sets, but turned out to be a Neon instruction (due to the
16673 operand types involved, etc.). We have to check and/or fix-up a couple of
16674 things:
16675
16676 - Make sure the user hasn't attempted to make a Neon instruction
16677 conditional.
16678 - Alter the value in the condition code field if necessary.
16679 - Make sure that the arch supports Neon instructions.
16680
16681 Which of these operations take place depends on bits from enum
16682 vfp_or_neon_is_neon_bits.
16683
16684 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
16685 current instruction's condition is COND_ALWAYS, the condition field is
16686 changed to inst.uncond_value. This is necessary because instructions shared
16687 between VFP and Neon may be conditional for the VFP variants only, and the
16688 unconditional Neon version must have, e.g., 0xF in the condition field. */
16689
16690 static int
16691 vfp_or_neon_is_neon (unsigned check)
16692 {
16693 /* Conditions are always legal in Thumb mode (IT blocks). */
16694 if (!thumb_mode && (check & NEON_CHECK_CC))
16695 {
16696 if (inst.cond != COND_ALWAYS)
16697 {
16698 first_error (_(BAD_COND));
16699 return FAIL;
16700 }
16701 if (inst.uncond_value != -1)
16702 inst.instruction |= inst.uncond_value << 28;
16703 }
16704
16705
16706 if (((check & NEON_CHECK_ARCH) && !mark_feature_used (&fpu_neon_ext_v1))
16707 || ((check & NEON_CHECK_ARCH8)
16708 && !mark_feature_used (&fpu_neon_ext_armv8)))
16709 {
16710 first_error (_(BAD_FPU));
16711 return FAIL;
16712 }
16713
16714 return SUCCESS;
16715 }
16716
16717
16718 /* Return TRUE if the SIMD instruction is available for the current
16719 cpu_variant. FP is set to TRUE if this is a SIMD floating-point
16720 instruction. CHECK contains th. CHECK contains the set of bits to pass to
16721 vfp_or_neon_is_neon for the NEON specific checks. */
16722
16723 static bfd_boolean
16724 check_simd_pred_availability (int fp, unsigned check)
16725 {
16726 if (inst.cond > COND_ALWAYS)
16727 {
16728 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16729 {
16730 inst.error = BAD_FPU;
16731 return FALSE;
16732 }
16733 inst.pred_insn_type = INSIDE_VPT_INSN;
16734 }
16735 else if (inst.cond < COND_ALWAYS)
16736 {
16737 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16738 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16739 else if (vfp_or_neon_is_neon (check) == FAIL)
16740 return FALSE;
16741 }
16742 else
16743 {
16744 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fp ? mve_fp_ext : mve_ext)
16745 && vfp_or_neon_is_neon (check) == FAIL)
16746 return FALSE;
16747
16748 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16749 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
16750 }
16751 return TRUE;
16752 }
16753
16754 /* Neon instruction encoders, in approximate order of appearance. */
16755
16756 static void
16757 do_neon_dyadic_i_su (void)
16758 {
16759 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
16760 return;
16761
16762 enum neon_shape rs;
16763 struct neon_type_el et;
16764 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16765 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16766 else
16767 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16768
16769 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_32 | N_KEY);
16770
16771
16772 if (rs != NS_QQR)
16773 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16774 else
16775 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16776 }
16777
16778 static void
16779 do_neon_dyadic_i64_su (void)
16780 {
16781 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
16782 return;
16783 enum neon_shape rs;
16784 struct neon_type_el et;
16785 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16786 {
16787 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16788 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16789 }
16790 else
16791 {
16792 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16793 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16794 }
16795 if (rs == NS_QQR)
16796 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
16797 else
16798 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16799 }
16800
16801 static void
16802 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
16803 unsigned immbits)
16804 {
16805 unsigned size = et.size >> 3;
16806 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16807 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16808 inst.instruction |= LOW4 (inst.operands[1].reg);
16809 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16810 inst.instruction |= (isquad != 0) << 6;
16811 inst.instruction |= immbits << 16;
16812 inst.instruction |= (size >> 3) << 7;
16813 inst.instruction |= (size & 0x7) << 19;
16814 if (write_ubit)
16815 inst.instruction |= (uval != 0) << 24;
16816
16817 neon_dp_fixup (&inst);
16818 }
16819
16820 static void
16821 do_neon_shl (void)
16822 {
16823 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
16824 return;
16825
16826 if (!inst.operands[2].isreg)
16827 {
16828 enum neon_shape rs;
16829 struct neon_type_el et;
16830 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16831 {
16832 rs = neon_select_shape (NS_QQI, NS_NULL);
16833 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_MVE);
16834 }
16835 else
16836 {
16837 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16838 et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
16839 }
16840 int imm = inst.operands[2].imm;
16841
16842 constraint (imm < 0 || (unsigned)imm >= et.size,
16843 _("immediate out of range for shift"));
16844 NEON_ENCODE (IMMED, inst);
16845 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
16846 }
16847 else
16848 {
16849 enum neon_shape rs;
16850 struct neon_type_el et;
16851 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16852 {
16853 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16854 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16855 }
16856 else
16857 {
16858 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16859 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16860 }
16861
16862
16863 if (rs == NS_QQR)
16864 {
16865 constraint (inst.operands[0].reg != inst.operands[1].reg,
16866 _("invalid instruction shape"));
16867 if (inst.operands[2].reg == REG_SP)
16868 as_tsktsk (MVE_BAD_SP);
16869 else if (inst.operands[2].reg == REG_PC)
16870 as_tsktsk (MVE_BAD_PC);
16871
16872 inst.instruction = 0xee311e60;
16873 inst.instruction |= (et.type == NT_unsigned) << 28;
16874 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16875 inst.instruction |= neon_logbits (et.size) << 18;
16876 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16877 inst.instruction |= inst.operands[2].reg;
16878 inst.is_neon = 1;
16879 }
16880 else
16881 {
16882 unsigned int tmp;
16883
16884 /* VSHL/VQSHL 3-register variants have syntax such as:
16885 vshl.xx Dd, Dm, Dn
16886 whereas other 3-register operations encoded by neon_three_same have
16887 syntax like:
16888 vadd.xx Dd, Dn, Dm
16889 (i.e. with Dn & Dm reversed). Swap operands[1].reg and
16890 operands[2].reg here. */
16891 tmp = inst.operands[2].reg;
16892 inst.operands[2].reg = inst.operands[1].reg;
16893 inst.operands[1].reg = tmp;
16894 NEON_ENCODE (INTEGER, inst);
16895 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16896 }
16897 }
16898 }
16899
16900 static void
16901 do_neon_qshl (void)
16902 {
16903 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
16904 return;
16905
16906 if (!inst.operands[2].isreg)
16907 {
16908 enum neon_shape rs;
16909 struct neon_type_el et;
16910 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16911 {
16912 rs = neon_select_shape (NS_QQI, NS_NULL);
16913 et = neon_check_type (2, rs, N_EQK, N_KEY | N_SU_MVE);
16914 }
16915 else
16916 {
16917 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16918 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16919 }
16920 int imm = inst.operands[2].imm;
16921
16922 constraint (imm < 0 || (unsigned)imm >= et.size,
16923 _("immediate out of range for shift"));
16924 NEON_ENCODE (IMMED, inst);
16925 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
16926 }
16927 else
16928 {
16929 enum neon_shape rs;
16930 struct neon_type_el et;
16931
16932 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16933 {
16934 rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
16935 et = neon_check_type (3, rs, N_EQK, N_SU_MVE | N_KEY, N_EQK | N_EQK);
16936 }
16937 else
16938 {
16939 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16940 et = neon_check_type (3, rs, N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
16941 }
16942
16943 if (rs == NS_QQR)
16944 {
16945 constraint (inst.operands[0].reg != inst.operands[1].reg,
16946 _("invalid instruction shape"));
16947 if (inst.operands[2].reg == REG_SP)
16948 as_tsktsk (MVE_BAD_SP);
16949 else if (inst.operands[2].reg == REG_PC)
16950 as_tsktsk (MVE_BAD_PC);
16951
16952 inst.instruction = 0xee311ee0;
16953 inst.instruction |= (et.type == NT_unsigned) << 28;
16954 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16955 inst.instruction |= neon_logbits (et.size) << 18;
16956 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16957 inst.instruction |= inst.operands[2].reg;
16958 inst.is_neon = 1;
16959 }
16960 else
16961 {
16962 unsigned int tmp;
16963
16964 /* See note in do_neon_shl. */
16965 tmp = inst.operands[2].reg;
16966 inst.operands[2].reg = inst.operands[1].reg;
16967 inst.operands[1].reg = tmp;
16968 NEON_ENCODE (INTEGER, inst);
16969 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
16970 }
16971 }
16972 }
16973
16974 static void
16975 do_neon_rshl (void)
16976 {
16977 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
16978 return;
16979
16980 enum neon_shape rs;
16981 struct neon_type_el et;
16982 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
16983 {
16984 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
16985 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
16986 }
16987 else
16988 {
16989 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
16990 et = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_ALL | N_KEY);
16991 }
16992
16993 unsigned int tmp;
16994
16995 if (rs == NS_QQR)
16996 {
16997 if (inst.operands[2].reg == REG_PC)
16998 as_tsktsk (MVE_BAD_PC);
16999 else if (inst.operands[2].reg == REG_SP)
17000 as_tsktsk (MVE_BAD_SP);
17001
17002 constraint (inst.operands[0].reg != inst.operands[1].reg,
17003 _("invalid instruction shape"));
17004
17005 if (inst.instruction == 0x0000510)
17006 /* We are dealing with vqrshl. */
17007 inst.instruction = 0xee331ee0;
17008 else
17009 /* We are dealing with vrshl. */
17010 inst.instruction = 0xee331e60;
17011
17012 inst.instruction |= (et.type == NT_unsigned) << 28;
17013 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17014 inst.instruction |= neon_logbits (et.size) << 18;
17015 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17016 inst.instruction |= inst.operands[2].reg;
17017 inst.is_neon = 1;
17018 }
17019 else
17020 {
17021 tmp = inst.operands[2].reg;
17022 inst.operands[2].reg = inst.operands[1].reg;
17023 inst.operands[1].reg = tmp;
17024 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
17025 }
17026 }
17027
17028 static int
17029 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
17030 {
17031 /* Handle .I8 pseudo-instructions. */
17032 if (size == 8)
17033 {
17034 /* Unfortunately, this will make everything apart from zero out-of-range.
17035 FIXME is this the intended semantics? There doesn't seem much point in
17036 accepting .I8 if so. */
17037 immediate |= immediate << 8;
17038 size = 16;
17039 }
17040
17041 if (size >= 32)
17042 {
17043 if (immediate == (immediate & 0x000000ff))
17044 {
17045 *immbits = immediate;
17046 return 0x1;
17047 }
17048 else if (immediate == (immediate & 0x0000ff00))
17049 {
17050 *immbits = immediate >> 8;
17051 return 0x3;
17052 }
17053 else if (immediate == (immediate & 0x00ff0000))
17054 {
17055 *immbits = immediate >> 16;
17056 return 0x5;
17057 }
17058 else if (immediate == (immediate & 0xff000000))
17059 {
17060 *immbits = immediate >> 24;
17061 return 0x7;
17062 }
17063 if ((immediate & 0xffff) != (immediate >> 16))
17064 goto bad_immediate;
17065 immediate &= 0xffff;
17066 }
17067
17068 if (immediate == (immediate & 0x000000ff))
17069 {
17070 *immbits = immediate;
17071 return 0x9;
17072 }
17073 else if (immediate == (immediate & 0x0000ff00))
17074 {
17075 *immbits = immediate >> 8;
17076 return 0xb;
17077 }
17078
17079 bad_immediate:
17080 first_error (_("immediate value out of range"));
17081 return FAIL;
17082 }
17083
17084 static void
17085 do_neon_logic (void)
17086 {
17087 if (inst.operands[2].present && inst.operands[2].isreg)
17088 {
17089 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17090 if (rs == NS_QQQ
17091 && !check_simd_pred_availability (FALSE,
17092 NEON_CHECK_ARCH | NEON_CHECK_CC))
17093 return;
17094 else if (rs != NS_QQQ
17095 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17096 first_error (BAD_FPU);
17097
17098 neon_check_type (3, rs, N_IGNORE_TYPE);
17099 /* U bit and size field were set as part of the bitmask. */
17100 NEON_ENCODE (INTEGER, inst);
17101 neon_three_same (neon_quad (rs), 0, -1);
17102 }
17103 else
17104 {
17105 const int three_ops_form = (inst.operands[2].present
17106 && !inst.operands[2].isreg);
17107 const int immoperand = (three_ops_form ? 2 : 1);
17108 enum neon_shape rs = (three_ops_form
17109 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
17110 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
17111 /* Because neon_select_shape makes the second operand a copy of the first
17112 if the second operand is not present. */
17113 if (rs == NS_QQI
17114 && !check_simd_pred_availability (FALSE,
17115 NEON_CHECK_ARCH | NEON_CHECK_CC))
17116 return;
17117 else if (rs != NS_QQI
17118 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
17119 first_error (BAD_FPU);
17120
17121 struct neon_type_el et;
17122 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17123 et = neon_check_type (2, rs, N_I32 | N_I16 | N_KEY, N_EQK);
17124 else
17125 et = neon_check_type (2, rs, N_I8 | N_I16 | N_I32 | N_I64 | N_F32
17126 | N_KEY, N_EQK);
17127
17128 if (et.type == NT_invtype)
17129 return;
17130 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
17131 unsigned immbits;
17132 int cmode;
17133
17134
17135 if (three_ops_form)
17136 constraint (inst.operands[0].reg != inst.operands[1].reg,
17137 _("first and second operands shall be the same register"));
17138
17139 NEON_ENCODE (IMMED, inst);
17140
17141 immbits = inst.operands[immoperand].imm;
17142 if (et.size == 64)
17143 {
17144 /* .i64 is a pseudo-op, so the immediate must be a repeating
17145 pattern. */
17146 if (immbits != (inst.operands[immoperand].regisimm ?
17147 inst.operands[immoperand].reg : 0))
17148 {
17149 /* Set immbits to an invalid constant. */
17150 immbits = 0xdeadbeef;
17151 }
17152 }
17153
17154 switch (opcode)
17155 {
17156 case N_MNEM_vbic:
17157 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17158 break;
17159
17160 case N_MNEM_vorr:
17161 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17162 break;
17163
17164 case N_MNEM_vand:
17165 /* Pseudo-instruction for VBIC. */
17166 neon_invert_size (&immbits, 0, et.size);
17167 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17168 break;
17169
17170 case N_MNEM_vorn:
17171 /* Pseudo-instruction for VORR. */
17172 neon_invert_size (&immbits, 0, et.size);
17173 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
17174 break;
17175
17176 default:
17177 abort ();
17178 }
17179
17180 if (cmode == FAIL)
17181 return;
17182
17183 inst.instruction |= neon_quad (rs) << 6;
17184 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17185 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17186 inst.instruction |= cmode << 8;
17187 neon_write_immbits (immbits);
17188
17189 neon_dp_fixup (&inst);
17190 }
17191 }
17192
17193 static void
17194 do_neon_bitfield (void)
17195 {
17196 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17197 neon_check_type (3, rs, N_IGNORE_TYPE);
17198 neon_three_same (neon_quad (rs), 0, -1);
17199 }
17200
17201 static void
17202 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
17203 unsigned destbits)
17204 {
17205 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17206 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
17207 types | N_KEY);
17208 if (et.type == NT_float)
17209 {
17210 NEON_ENCODE (FLOAT, inst);
17211 if (rs == NS_QQR)
17212 mve_encode_qqr (et.size, 0, 1);
17213 else
17214 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
17215 }
17216 else
17217 {
17218 NEON_ENCODE (INTEGER, inst);
17219 if (rs == NS_QQR)
17220 mve_encode_qqr (et.size, et.type == ubit_meaning, 0);
17221 else
17222 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
17223 }
17224 }
17225
17226
17227 static void
17228 do_neon_dyadic_if_su_d (void)
17229 {
17230 /* This version only allow D registers, but that constraint is enforced during
17231 operand parsing so we don't need to do anything extra here. */
17232 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17233 }
17234
17235 static void
17236 do_neon_dyadic_if_i_d (void)
17237 {
17238 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17239 affected if we specify unsigned args. */
17240 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17241 }
17242
17243 static void
17244 do_mve_vstr_vldr_QI (int size, int elsize, int load)
17245 {
17246 constraint (size < 32, BAD_ADDR_MODE);
17247 constraint (size != elsize, BAD_EL_TYPE);
17248 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17249 constraint (!inst.operands[1].preind, BAD_ADDR_MODE);
17250 constraint (load && inst.operands[0].reg == inst.operands[1].reg,
17251 _("destination register and offset register may not be the"
17252 " same"));
17253
17254 int imm = inst.relocs[0].exp.X_add_number;
17255 int add = 1;
17256 if (imm < 0)
17257 {
17258 add = 0;
17259 imm = -imm;
17260 }
17261 constraint ((imm % (size / 8) != 0)
17262 || imm > (0x7f << neon_logbits (size)),
17263 (size == 32) ? _("immediate must be a multiple of 4 in the"
17264 " range of +/-[0,508]")
17265 : _("immediate must be a multiple of 8 in the"
17266 " range of +/-[0,1016]"));
17267 inst.instruction |= 0x11 << 24;
17268 inst.instruction |= add << 23;
17269 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17270 inst.instruction |= inst.operands[1].writeback << 21;
17271 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17272 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17273 inst.instruction |= 1 << 12;
17274 inst.instruction |= (size == 64) << 8;
17275 inst.instruction &= 0xffffff00;
17276 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17277 inst.instruction |= imm >> neon_logbits (size);
17278 }
17279
17280 static void
17281 do_mve_vstr_vldr_RQ (int size, int elsize, int load)
17282 {
17283 unsigned os = inst.operands[1].imm >> 5;
17284 constraint (os != 0 && size == 8,
17285 _("can not shift offsets when accessing less than half-word"));
17286 constraint (os && os != neon_logbits (size),
17287 _("shift immediate must be 1, 2 or 3 for half-word, word"
17288 " or double-word accesses respectively"));
17289 if (inst.operands[1].reg == REG_PC)
17290 as_tsktsk (MVE_BAD_PC);
17291
17292 switch (size)
17293 {
17294 case 8:
17295 constraint (elsize >= 64, BAD_EL_TYPE);
17296 break;
17297 case 16:
17298 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17299 break;
17300 case 32:
17301 case 64:
17302 constraint (elsize != size, BAD_EL_TYPE);
17303 break;
17304 default:
17305 break;
17306 }
17307 constraint (inst.operands[1].writeback || !inst.operands[1].preind,
17308 BAD_ADDR_MODE);
17309 if (load)
17310 {
17311 constraint (inst.operands[0].reg == (inst.operands[1].imm & 0x1f),
17312 _("destination register and offset register may not be"
17313 " the same"));
17314 constraint (size == elsize && inst.vectype.el[0].type != NT_unsigned,
17315 BAD_EL_TYPE);
17316 constraint (inst.vectype.el[0].type != NT_unsigned
17317 && inst.vectype.el[0].type != NT_signed, BAD_EL_TYPE);
17318 inst.instruction |= (inst.vectype.el[0].type == NT_unsigned) << 28;
17319 }
17320 else
17321 {
17322 constraint (inst.vectype.el[0].type != NT_untyped, BAD_EL_TYPE);
17323 }
17324
17325 inst.instruction |= 1 << 23;
17326 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17327 inst.instruction |= inst.operands[1].reg << 16;
17328 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17329 inst.instruction |= neon_logbits (elsize) << 7;
17330 inst.instruction |= HI1 (inst.operands[1].imm) << 5;
17331 inst.instruction |= LOW4 (inst.operands[1].imm);
17332 inst.instruction |= !!os;
17333 }
17334
17335 static void
17336 do_mve_vstr_vldr_RI (int size, int elsize, int load)
17337 {
17338 enum neon_el_type type = inst.vectype.el[0].type;
17339
17340 constraint (size >= 64, BAD_ADDR_MODE);
17341 switch (size)
17342 {
17343 case 16:
17344 constraint (elsize < 16 || elsize >= 64, BAD_EL_TYPE);
17345 break;
17346 case 32:
17347 constraint (elsize != size, BAD_EL_TYPE);
17348 break;
17349 default:
17350 break;
17351 }
17352 if (load)
17353 {
17354 constraint (elsize != size && type != NT_unsigned
17355 && type != NT_signed, BAD_EL_TYPE);
17356 }
17357 else
17358 {
17359 constraint (elsize != size && type != NT_untyped, BAD_EL_TYPE);
17360 }
17361
17362 int imm = inst.relocs[0].exp.X_add_number;
17363 int add = 1;
17364 if (imm < 0)
17365 {
17366 add = 0;
17367 imm = -imm;
17368 }
17369
17370 if ((imm % (size / 8) != 0) || imm > (0x7f << neon_logbits (size)))
17371 {
17372 switch (size)
17373 {
17374 case 8:
17375 constraint (1, _("immediate must be in the range of +/-[0,127]"));
17376 break;
17377 case 16:
17378 constraint (1, _("immediate must be a multiple of 2 in the"
17379 " range of +/-[0,254]"));
17380 break;
17381 case 32:
17382 constraint (1, _("immediate must be a multiple of 4 in the"
17383 " range of +/-[0,508]"));
17384 break;
17385 }
17386 }
17387
17388 if (size != elsize)
17389 {
17390 constraint (inst.operands[1].reg > 7, BAD_HIREG);
17391 constraint (inst.operands[0].reg > 14,
17392 _("MVE vector register in the range [Q0..Q7] expected"));
17393 inst.instruction |= (load && type == NT_unsigned) << 28;
17394 inst.instruction |= (size == 16) << 19;
17395 inst.instruction |= neon_logbits (elsize) << 7;
17396 }
17397 else
17398 {
17399 if (inst.operands[1].reg == REG_PC)
17400 as_tsktsk (MVE_BAD_PC);
17401 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17402 as_tsktsk (MVE_BAD_SP);
17403 inst.instruction |= 1 << 12;
17404 inst.instruction |= neon_logbits (size) << 7;
17405 }
17406 inst.instruction |= inst.operands[1].preind << 24;
17407 inst.instruction |= add << 23;
17408 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17409 inst.instruction |= inst.operands[1].writeback << 21;
17410 inst.instruction |= inst.operands[1].reg << 16;
17411 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17412 inst.instruction &= 0xffffff80;
17413 inst.instruction |= imm >> neon_logbits (size);
17414
17415 }
17416
17417 static void
17418 do_mve_vstr_vldr (void)
17419 {
17420 unsigned size;
17421 int load = 0;
17422
17423 if (inst.cond > COND_ALWAYS)
17424 inst.pred_insn_type = INSIDE_VPT_INSN;
17425 else
17426 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17427
17428 switch (inst.instruction)
17429 {
17430 default:
17431 gas_assert (0);
17432 break;
17433 case M_MNEM_vldrb:
17434 load = 1;
17435 /* fall through. */
17436 case M_MNEM_vstrb:
17437 size = 8;
17438 break;
17439 case M_MNEM_vldrh:
17440 load = 1;
17441 /* fall through. */
17442 case M_MNEM_vstrh:
17443 size = 16;
17444 break;
17445 case M_MNEM_vldrw:
17446 load = 1;
17447 /* fall through. */
17448 case M_MNEM_vstrw:
17449 size = 32;
17450 break;
17451 case M_MNEM_vldrd:
17452 load = 1;
17453 /* fall through. */
17454 case M_MNEM_vstrd:
17455 size = 64;
17456 break;
17457 }
17458 unsigned elsize = inst.vectype.el[0].size;
17459
17460 if (inst.operands[1].isquad)
17461 {
17462 /* We are dealing with [Q, imm]{!} cases. */
17463 do_mve_vstr_vldr_QI (size, elsize, load);
17464 }
17465 else
17466 {
17467 if (inst.operands[1].immisreg == 2)
17468 {
17469 /* We are dealing with [R, Q, {UXTW #os}] cases. */
17470 do_mve_vstr_vldr_RQ (size, elsize, load);
17471 }
17472 else if (!inst.operands[1].immisreg)
17473 {
17474 /* We are dealing with [R, Imm]{!}/[R], Imm cases. */
17475 do_mve_vstr_vldr_RI (size, elsize, load);
17476 }
17477 else
17478 constraint (1, BAD_ADDR_MODE);
17479 }
17480
17481 inst.is_neon = 1;
17482 }
17483
17484 static void
17485 do_mve_vst_vld (void)
17486 {
17487 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17488 return;
17489
17490 constraint (!inst.operands[1].preind || inst.relocs[0].exp.X_add_symbol != 0
17491 || inst.relocs[0].exp.X_add_number != 0
17492 || inst.operands[1].immisreg != 0,
17493 BAD_ADDR_MODE);
17494 constraint (inst.vectype.el[0].size > 32, BAD_EL_TYPE);
17495 if (inst.operands[1].reg == REG_PC)
17496 as_tsktsk (MVE_BAD_PC);
17497 else if (inst.operands[1].reg == REG_SP && inst.operands[1].writeback)
17498 as_tsktsk (MVE_BAD_SP);
17499
17500
17501 /* These instructions are one of the "exceptions" mentioned in
17502 handle_pred_state. They are MVE instructions that are not VPT compatible
17503 and do not accept a VPT code, thus appending such a code is a syntax
17504 error. */
17505 if (inst.cond > COND_ALWAYS)
17506 first_error (BAD_SYNTAX);
17507 /* If we append a scalar condition code we can set this to
17508 MVE_OUTSIDE_PRED_INSN as it will also lead to a syntax error. */
17509 else if (inst.cond < COND_ALWAYS)
17510 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17511 else
17512 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
17513
17514 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17515 inst.instruction |= inst.operands[1].writeback << 21;
17516 inst.instruction |= inst.operands[1].reg << 16;
17517 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17518 inst.instruction |= neon_logbits (inst.vectype.el[0].size) << 7;
17519 inst.is_neon = 1;
17520 }
17521
17522 static void
17523 do_mve_vaddlv (void)
17524 {
17525 enum neon_shape rs = neon_select_shape (NS_RRQ, NS_NULL);
17526 struct neon_type_el et
17527 = neon_check_type (3, rs, N_EQK, N_EQK, N_S32 | N_U32 | N_KEY);
17528
17529 if (et.type == NT_invtype)
17530 first_error (BAD_EL_TYPE);
17531
17532 if (inst.cond > COND_ALWAYS)
17533 inst.pred_insn_type = INSIDE_VPT_INSN;
17534 else
17535 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17536
17537 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17538
17539 inst.instruction |= (et.type == NT_unsigned) << 28;
17540 inst.instruction |= inst.operands[1].reg << 19;
17541 inst.instruction |= inst.operands[0].reg << 12;
17542 inst.instruction |= inst.operands[2].reg;
17543 inst.is_neon = 1;
17544 }
17545
17546 static void
17547 do_neon_dyadic_if_su (void)
17548 {
17549 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17550 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
17551 N_SUF_32 | N_KEY);
17552
17553 constraint ((inst.instruction == ((unsigned) N_MNEM_vmax)
17554 || inst.instruction == ((unsigned) N_MNEM_vmin))
17555 && et.type == NT_float
17556 && !ARM_CPU_HAS_FEATURE (cpu_variant,fpu_neon_ext_v1), BAD_FPU);
17557
17558 if (!check_simd_pred_availability (et.type == NT_float,
17559 NEON_CHECK_ARCH | NEON_CHECK_CC))
17560 return;
17561
17562 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
17563 }
17564
17565 static void
17566 do_neon_addsub_if_i (void)
17567 {
17568 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1xd)
17569 && try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
17570 return;
17571
17572 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_QQR, NS_NULL);
17573 struct neon_type_el et = neon_check_type (3, rs, N_EQK,
17574 N_EQK, N_IF_32 | N_I64 | N_KEY);
17575
17576 constraint (rs == NS_QQR && et.size == 64, BAD_FPU);
17577 /* If we are parsing Q registers and the element types match MVE, which NEON
17578 also supports, then we must check whether this is an instruction that can
17579 be used by both MVE/NEON. This distinction can be made based on whether
17580 they are predicated or not. */
17581 if ((rs == NS_QQQ || rs == NS_QQR) && et.size != 64)
17582 {
17583 if (!check_simd_pred_availability (et.type == NT_float,
17584 NEON_CHECK_ARCH | NEON_CHECK_CC))
17585 return;
17586 }
17587 else
17588 {
17589 /* If they are either in a D register or are using an unsupported. */
17590 if (rs != NS_QQR
17591 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
17592 return;
17593 }
17594
17595 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17596 affected if we specify unsigned args. */
17597 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
17598 }
17599
17600 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
17601 result to be:
17602 V<op> A,B (A is operand 0, B is operand 2)
17603 to mean:
17604 V<op> A,B,A
17605 not:
17606 V<op> A,B,B
17607 so handle that case specially. */
17608
17609 static void
17610 neon_exchange_operands (void)
17611 {
17612 if (inst.operands[1].present)
17613 {
17614 void *scratch = xmalloc (sizeof (inst.operands[0]));
17615
17616 /* Swap operands[1] and operands[2]. */
17617 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
17618 inst.operands[1] = inst.operands[2];
17619 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
17620 free (scratch);
17621 }
17622 else
17623 {
17624 inst.operands[1] = inst.operands[2];
17625 inst.operands[2] = inst.operands[0];
17626 }
17627 }
17628
17629 static void
17630 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
17631 {
17632 if (inst.operands[2].isreg)
17633 {
17634 if (invert)
17635 neon_exchange_operands ();
17636 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
17637 }
17638 else
17639 {
17640 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
17641 struct neon_type_el et = neon_check_type (2, rs,
17642 N_EQK | N_SIZ, immtypes | N_KEY);
17643
17644 NEON_ENCODE (IMMED, inst);
17645 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17646 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17647 inst.instruction |= LOW4 (inst.operands[1].reg);
17648 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17649 inst.instruction |= neon_quad (rs) << 6;
17650 inst.instruction |= (et.type == NT_float) << 10;
17651 inst.instruction |= neon_logbits (et.size) << 18;
17652
17653 neon_dp_fixup (&inst);
17654 }
17655 }
17656
17657 static void
17658 do_neon_cmp (void)
17659 {
17660 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
17661 }
17662
17663 static void
17664 do_neon_cmp_inv (void)
17665 {
17666 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
17667 }
17668
17669 static void
17670 do_neon_ceq (void)
17671 {
17672 neon_compare (N_IF_32, N_IF_32, FALSE);
17673 }
17674
17675 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
17676 scalars, which are encoded in 5 bits, M : Rm.
17677 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
17678 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
17679 index in M.
17680
17681 Dot Product instructions are similar to multiply instructions except elsize
17682 should always be 32.
17683
17684 This function translates SCALAR, which is GAS's internal encoding of indexed
17685 scalar register, to raw encoding. There is also register and index range
17686 check based on ELSIZE. */
17687
17688 static unsigned
17689 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
17690 {
17691 unsigned regno = NEON_SCALAR_REG (scalar);
17692 unsigned elno = NEON_SCALAR_INDEX (scalar);
17693
17694 switch (elsize)
17695 {
17696 case 16:
17697 if (regno > 7 || elno > 3)
17698 goto bad_scalar;
17699 return regno | (elno << 3);
17700
17701 case 32:
17702 if (regno > 15 || elno > 1)
17703 goto bad_scalar;
17704 return regno | (elno << 4);
17705
17706 default:
17707 bad_scalar:
17708 first_error (_("scalar out of range for multiply instruction"));
17709 }
17710
17711 return 0;
17712 }
17713
17714 /* Encode multiply / multiply-accumulate scalar instructions. */
17715
17716 static void
17717 neon_mul_mac (struct neon_type_el et, int ubit)
17718 {
17719 unsigned scalar;
17720
17721 /* Give a more helpful error message if we have an invalid type. */
17722 if (et.type == NT_invtype)
17723 return;
17724
17725 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
17726 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17727 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17728 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17729 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17730 inst.instruction |= LOW4 (scalar);
17731 inst.instruction |= HI1 (scalar) << 5;
17732 inst.instruction |= (et.type == NT_float) << 8;
17733 inst.instruction |= neon_logbits (et.size) << 20;
17734 inst.instruction |= (ubit != 0) << 24;
17735
17736 neon_dp_fixup (&inst);
17737 }
17738
17739 static void
17740 do_neon_mac_maybe_scalar (void)
17741 {
17742 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
17743 return;
17744
17745 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
17746 return;
17747
17748 if (inst.operands[2].isscalar)
17749 {
17750 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17751 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17752 struct neon_type_el et = neon_check_type (3, rs,
17753 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
17754 NEON_ENCODE (SCALAR, inst);
17755 neon_mul_mac (et, neon_quad (rs));
17756 }
17757 else if (!inst.operands[2].isvec)
17758 {
17759 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17760
17761 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
17762 neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
17763
17764 neon_dyadic_misc (NT_unsigned, N_SU_MVE, 0);
17765 }
17766 else
17767 {
17768 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17769 /* The "untyped" case can't happen. Do this to stop the "U" bit being
17770 affected if we specify unsigned args. */
17771 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17772 }
17773 }
17774
17775 static void
17776 do_neon_fmac (void)
17777 {
17778 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_fma)
17779 && try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
17780 return;
17781
17782 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH))
17783 return;
17784
17785 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
17786 {
17787 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17788 struct neon_type_el et = neon_check_type (3, rs, N_F_MVE | N_KEY, N_EQK,
17789 N_EQK);
17790
17791 if (rs == NS_QQR)
17792 {
17793 if (inst.operands[2].reg == REG_SP)
17794 as_tsktsk (MVE_BAD_SP);
17795 else if (inst.operands[2].reg == REG_PC)
17796 as_tsktsk (MVE_BAD_PC);
17797
17798 inst.instruction = 0xee310e40;
17799 inst.instruction |= (et.size == 16) << 28;
17800 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17801 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17802 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17803 inst.instruction |= HI1 (inst.operands[1].reg) << 6;
17804 inst.instruction |= inst.operands[2].reg;
17805 inst.is_neon = 1;
17806 return;
17807 }
17808 }
17809 else
17810 {
17811 constraint (!inst.operands[2].isvec, BAD_FPU);
17812 }
17813
17814 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
17815 }
17816
17817 static void
17818 do_neon_tst (void)
17819 {
17820 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17821 struct neon_type_el et = neon_check_type (3, rs,
17822 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
17823 neon_three_same (neon_quad (rs), 0, et.size);
17824 }
17825
17826 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
17827 same types as the MAC equivalents. The polynomial type for this instruction
17828 is encoded the same as the integer type. */
17829
17830 static void
17831 do_neon_mul (void)
17832 {
17833 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
17834 return;
17835
17836 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
17837 return;
17838
17839 if (inst.operands[2].isscalar)
17840 {
17841 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17842 do_neon_mac_maybe_scalar ();
17843 }
17844 else
17845 {
17846 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17847 {
17848 enum neon_shape rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17849 struct neon_type_el et
17850 = neon_check_type (3, rs, N_EQK, N_EQK, N_I_MVE | N_F_MVE | N_KEY);
17851 if (et.type == NT_float)
17852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext),
17853 BAD_FPU);
17854
17855 neon_dyadic_misc (NT_float, N_I_MVE | N_F_MVE, 0);
17856 }
17857 else
17858 {
17859 constraint (!inst.operands[2].isvec, BAD_FPU);
17860 neon_dyadic_misc (NT_poly,
17861 N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
17862 }
17863 }
17864 }
17865
17866 static void
17867 do_neon_qdmulh (void)
17868 {
17869 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
17870 return;
17871
17872 if (inst.operands[2].isscalar)
17873 {
17874 constraint (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
17875 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17876 struct neon_type_el et = neon_check_type (3, rs,
17877 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17878 NEON_ENCODE (SCALAR, inst);
17879 neon_mul_mac (et, neon_quad (rs));
17880 }
17881 else
17882 {
17883 enum neon_shape rs;
17884 struct neon_type_el et;
17885 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
17886 {
17887 rs = neon_select_shape (NS_QQR, NS_QQQ, NS_NULL);
17888 et = neon_check_type (3, rs,
17889 N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17890 }
17891 else
17892 {
17893 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17894 et = neon_check_type (3, rs,
17895 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17896 }
17897
17898 NEON_ENCODE (INTEGER, inst);
17899 if (rs == NS_QQR)
17900 mve_encode_qqr (et.size, 0, 0);
17901 else
17902 /* The U bit (rounding) comes from bit mask. */
17903 neon_three_same (neon_quad (rs), 0, et.size);
17904 }
17905 }
17906
17907 static void
17908 do_mve_vaddv (void)
17909 {
17910 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
17911 struct neon_type_el et
17912 = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
17913
17914 if (et.type == NT_invtype)
17915 first_error (BAD_EL_TYPE);
17916
17917 if (inst.cond > COND_ALWAYS)
17918 inst.pred_insn_type = INSIDE_VPT_INSN;
17919 else
17920 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17921
17922 constraint (inst.operands[1].reg > 14, MVE_BAD_QREG);
17923
17924 mve_encode_rq (et.type == NT_unsigned, et.size);
17925 }
17926
17927 static void
17928 do_mve_vhcadd (void)
17929 {
17930 enum neon_shape rs = neon_select_shape (NS_QQQI, NS_NULL);
17931 struct neon_type_el et
17932 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
17933
17934 if (inst.cond > COND_ALWAYS)
17935 inst.pred_insn_type = INSIDE_VPT_INSN;
17936 else
17937 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17938
17939 unsigned rot = inst.relocs[0].exp.X_add_number;
17940 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17941
17942 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
17943 as_tsktsk (_("Warning: 32-bit element size and same first and third "
17944 "operand makes instruction UNPREDICTABLE"));
17945
17946 mve_encode_qqq (0, et.size);
17947 inst.instruction |= (rot == 270) << 12;
17948 inst.is_neon = 1;
17949 }
17950
17951 static void
17952 do_mve_vqdmull (void)
17953 {
17954 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_QQR, NS_NULL);
17955 struct neon_type_el et
17956 = neon_check_type (3, rs, N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
17957
17958 if (et.size == 32
17959 && (inst.operands[0].reg == inst.operands[1].reg
17960 || (rs == NS_QQQ && inst.operands[0].reg == inst.operands[2].reg)))
17961 as_tsktsk (BAD_MVE_SRCDEST);
17962
17963 if (inst.cond > COND_ALWAYS)
17964 inst.pred_insn_type = INSIDE_VPT_INSN;
17965 else
17966 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17967
17968 if (rs == NS_QQQ)
17969 {
17970 mve_encode_qqq (et.size == 32, 64);
17971 inst.instruction |= 1;
17972 }
17973 else
17974 {
17975 mve_encode_qqr (64, et.size == 32, 0);
17976 inst.instruction |= 0x3 << 5;
17977 }
17978 }
17979
17980 static void
17981 do_mve_vadc (void)
17982 {
17983 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
17984 struct neon_type_el et
17985 = neon_check_type (3, rs, N_KEY | N_I32, N_EQK, N_EQK);
17986
17987 if (et.type == NT_invtype)
17988 first_error (BAD_EL_TYPE);
17989
17990 if (inst.cond > COND_ALWAYS)
17991 inst.pred_insn_type = INSIDE_VPT_INSN;
17992 else
17993 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
17994
17995 mve_encode_qqq (0, 64);
17996 }
17997
17998 static void
17999 do_mve_vbrsr (void)
18000 {
18001 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18002 struct neon_type_el et
18003 = neon_check_type (3, rs, N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18004
18005 if (inst.cond > COND_ALWAYS)
18006 inst.pred_insn_type = INSIDE_VPT_INSN;
18007 else
18008 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18009
18010 mve_encode_qqr (et.size, 0, 0);
18011 }
18012
18013 static void
18014 do_mve_vsbc (void)
18015 {
18016 neon_check_type (3, NS_QQQ, N_EQK, N_EQK, N_I32 | N_KEY);
18017
18018 if (inst.cond > COND_ALWAYS)
18019 inst.pred_insn_type = INSIDE_VPT_INSN;
18020 else
18021 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18022
18023 mve_encode_qqq (1, 64);
18024 }
18025
18026 static void
18027 do_mve_vmulh (void)
18028 {
18029 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18030 struct neon_type_el et
18031 = neon_check_type (3, rs, N_EQK, N_EQK, N_SU_MVE | N_KEY);
18032
18033 if (inst.cond > COND_ALWAYS)
18034 inst.pred_insn_type = INSIDE_VPT_INSN;
18035 else
18036 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18037
18038 mve_encode_qqq (et.type == NT_unsigned, et.size);
18039 }
18040
18041 static void
18042 do_mve_vqdmlah (void)
18043 {
18044 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18045 struct neon_type_el et
18046 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18047
18048 if (inst.cond > COND_ALWAYS)
18049 inst.pred_insn_type = INSIDE_VPT_INSN;
18050 else
18051 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18052
18053 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18054 }
18055
18056 static void
18057 do_mve_vqdmladh (void)
18058 {
18059 enum neon_shape rs = neon_select_shape (NS_QQQ, NS_NULL);
18060 struct neon_type_el et
18061 = neon_check_type (3, rs, N_EQK, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18062
18063 if (inst.cond > COND_ALWAYS)
18064 inst.pred_insn_type = INSIDE_VPT_INSN;
18065 else
18066 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18067
18068 mve_encode_qqq (0, et.size);
18069 }
18070
18071
18072 static void
18073 do_mve_vmull (void)
18074 {
18075
18076 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_DDS,
18077 NS_QQS, NS_QQQ, NS_QQR, NS_NULL);
18078 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
18079 && inst.cond == COND_ALWAYS
18080 && ((unsigned)inst.instruction) == M_MNEM_vmullt)
18081 {
18082 if (rs == NS_QQQ)
18083 {
18084
18085 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18086 N_SUF_32 | N_F64 | N_P8
18087 | N_P16 | N_I_MVE | N_KEY);
18088 if (((et.type == NT_poly) && et.size == 8
18089 && ARM_CPU_IS_ANY (cpu_variant))
18090 || (et.type == NT_integer) || (et.type == NT_float))
18091 goto neon_vmul;
18092 }
18093 else
18094 goto neon_vmul;
18095 }
18096
18097 constraint (rs != NS_QQQ, BAD_FPU);
18098 struct neon_type_el et = neon_check_type (3, rs, N_EQK , N_EQK,
18099 N_SU_32 | N_P8 | N_P16 | N_KEY);
18100
18101 /* We are dealing with MVE's vmullt. */
18102 if (et.size == 32
18103 && (inst.operands[0].reg == inst.operands[1].reg
18104 || inst.operands[0].reg == inst.operands[2].reg))
18105 as_tsktsk (BAD_MVE_SRCDEST);
18106
18107 if (inst.cond > COND_ALWAYS)
18108 inst.pred_insn_type = INSIDE_VPT_INSN;
18109 else
18110 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18111
18112 if (et.type == NT_poly)
18113 mve_encode_qqq (neon_logbits (et.size), 64);
18114 else
18115 mve_encode_qqq (et.type == NT_unsigned, et.size);
18116
18117 return;
18118
18119 neon_vmul:
18120 inst.instruction = N_MNEM_vmul;
18121 inst.cond = 0xb;
18122 if (thumb_mode)
18123 inst.pred_insn_type = INSIDE_IT_INSN;
18124 do_neon_mul ();
18125 }
18126
18127 static void
18128 do_mve_vabav (void)
18129 {
18130 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18131
18132 if (rs == NS_NULL)
18133 return;
18134
18135 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18136 return;
18137
18138 struct neon_type_el et = neon_check_type (2, NS_NULL, N_EQK, N_KEY | N_S8
18139 | N_S16 | N_S32 | N_U8 | N_U16
18140 | N_U32);
18141
18142 if (inst.cond > COND_ALWAYS)
18143 inst.pred_insn_type = INSIDE_VPT_INSN;
18144 else
18145 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18146
18147 mve_encode_rqq (et.type == NT_unsigned, et.size);
18148 }
18149
18150 static void
18151 do_mve_vmladav (void)
18152 {
18153 enum neon_shape rs = neon_select_shape (NS_RQQ, NS_NULL);
18154 struct neon_type_el et = neon_check_type (3, rs,
18155 N_EQK, N_EQK, N_SU_MVE | N_KEY);
18156
18157 if (et.type == NT_unsigned
18158 && (inst.instruction == M_MNEM_vmladavx
18159 || inst.instruction == M_MNEM_vmladavax
18160 || inst.instruction == M_MNEM_vmlsdav
18161 || inst.instruction == M_MNEM_vmlsdava
18162 || inst.instruction == M_MNEM_vmlsdavx
18163 || inst.instruction == M_MNEM_vmlsdavax))
18164 first_error (BAD_SIMD_TYPE);
18165
18166 constraint (inst.operands[2].reg > 14,
18167 _("MVE vector register in the range [Q0..Q7] expected"));
18168
18169 if (inst.cond > COND_ALWAYS)
18170 inst.pred_insn_type = INSIDE_VPT_INSN;
18171 else
18172 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18173
18174 if (inst.instruction == M_MNEM_vmlsdav
18175 || inst.instruction == M_MNEM_vmlsdava
18176 || inst.instruction == M_MNEM_vmlsdavx
18177 || inst.instruction == M_MNEM_vmlsdavax)
18178 inst.instruction |= (et.size == 8) << 28;
18179 else
18180 inst.instruction |= (et.size == 8) << 8;
18181
18182 mve_encode_rqq (et.type == NT_unsigned, 64);
18183 inst.instruction |= (et.size == 32) << 16;
18184 }
18185
18186 static void
18187 do_mve_vmlaldav (void)
18188 {
18189 enum neon_shape rs = neon_select_shape (NS_RRQQ, NS_NULL);
18190 struct neon_type_el et
18191 = neon_check_type (4, rs, N_EQK, N_EQK, N_EQK,
18192 N_S16 | N_S32 | N_U16 | N_U32 | N_KEY);
18193
18194 if (et.type == NT_unsigned
18195 && (inst.instruction == M_MNEM_vmlsldav
18196 || inst.instruction == M_MNEM_vmlsldava
18197 || inst.instruction == M_MNEM_vmlsldavx
18198 || inst.instruction == M_MNEM_vmlsldavax))
18199 first_error (BAD_SIMD_TYPE);
18200
18201 if (inst.cond > COND_ALWAYS)
18202 inst.pred_insn_type = INSIDE_VPT_INSN;
18203 else
18204 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18205
18206 mve_encode_rrqq (et.type == NT_unsigned, et.size);
18207 }
18208
18209 static void
18210 do_mve_vrmlaldavh (void)
18211 {
18212 struct neon_type_el et;
18213 if (inst.instruction == M_MNEM_vrmlsldavh
18214 || inst.instruction == M_MNEM_vrmlsldavha
18215 || inst.instruction == M_MNEM_vrmlsldavhx
18216 || inst.instruction == M_MNEM_vrmlsldavhax)
18217 {
18218 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18219 if (inst.operands[1].reg == REG_SP)
18220 as_tsktsk (MVE_BAD_SP);
18221 }
18222 else
18223 {
18224 if (inst.instruction == M_MNEM_vrmlaldavhx
18225 || inst.instruction == M_MNEM_vrmlaldavhax)
18226 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK, N_S32 | N_KEY);
18227 else
18228 et = neon_check_type (4, NS_RRQQ, N_EQK, N_EQK, N_EQK,
18229 N_U32 | N_S32 | N_KEY);
18230 /* vrmlaldavh's encoding with SP as the second, odd, GPR operand may alias
18231 with vmax/min instructions, making the use of SP in assembly really
18232 nonsensical, so instead of issuing a warning like we do for other uses
18233 of SP for the odd register operand we error out. */
18234 constraint (inst.operands[1].reg == REG_SP, BAD_SP);
18235 }
18236
18237 /* Make sure we still check the second operand is an odd one and that PC is
18238 disallowed. This because we are parsing for any GPR operand, to be able
18239 to distinguish between giving a warning or an error for SP as described
18240 above. */
18241 constraint ((inst.operands[1].reg % 2) != 1, BAD_EVEN);
18242 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
18243
18244 if (inst.cond > COND_ALWAYS)
18245 inst.pred_insn_type = INSIDE_VPT_INSN;
18246 else
18247 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18248
18249 mve_encode_rrqq (et.type == NT_unsigned, 0);
18250 }
18251
18252
18253 static void
18254 do_mve_vmaxnmv (void)
18255 {
18256 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18257 struct neon_type_el et
18258 = neon_check_type (2, rs, N_EQK, N_F_MVE | N_KEY);
18259
18260 if (inst.cond > COND_ALWAYS)
18261 inst.pred_insn_type = INSIDE_VPT_INSN;
18262 else
18263 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18264
18265 if (inst.operands[0].reg == REG_SP)
18266 as_tsktsk (MVE_BAD_SP);
18267 else if (inst.operands[0].reg == REG_PC)
18268 as_tsktsk (MVE_BAD_PC);
18269
18270 mve_encode_rq (et.size == 16, 64);
18271 }
18272
18273 static void
18274 do_mve_vmaxv (void)
18275 {
18276 enum neon_shape rs = neon_select_shape (NS_RQ, NS_NULL);
18277 struct neon_type_el et;
18278
18279 if (inst.instruction == M_MNEM_vmaxv || inst.instruction == M_MNEM_vminv)
18280 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
18281 else
18282 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18283
18284 if (inst.cond > COND_ALWAYS)
18285 inst.pred_insn_type = INSIDE_VPT_INSN;
18286 else
18287 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
18288
18289 if (inst.operands[0].reg == REG_SP)
18290 as_tsktsk (MVE_BAD_SP);
18291 else if (inst.operands[0].reg == REG_PC)
18292 as_tsktsk (MVE_BAD_PC);
18293
18294 mve_encode_rq (et.type == NT_unsigned, et.size);
18295 }
18296
18297
18298 static void
18299 do_neon_qrdmlah (void)
18300 {
18301 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18302 return;
18303 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18304 {
18305 /* Check we're on the correct architecture. */
18306 if (!mark_feature_used (&fpu_neon_ext_armv8))
18307 inst.error
18308 = _("instruction form not available on this architecture.");
18309 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
18310 {
18311 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
18312 record_feature_use (&fpu_neon_ext_v8_1);
18313 }
18314 if (inst.operands[2].isscalar)
18315 {
18316 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
18317 struct neon_type_el et = neon_check_type (3, rs,
18318 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18319 NEON_ENCODE (SCALAR, inst);
18320 neon_mul_mac (et, neon_quad (rs));
18321 }
18322 else
18323 {
18324 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18325 struct neon_type_el et = neon_check_type (3, rs,
18326 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
18327 NEON_ENCODE (INTEGER, inst);
18328 /* The U bit (rounding) comes from bit mask. */
18329 neon_three_same (neon_quad (rs), 0, et.size);
18330 }
18331 }
18332 else
18333 {
18334 enum neon_shape rs = neon_select_shape (NS_QQR, NS_NULL);
18335 struct neon_type_el et
18336 = neon_check_type (3, rs, N_EQK, N_EQK, N_S_32 | N_KEY);
18337
18338 NEON_ENCODE (INTEGER, inst);
18339 mve_encode_qqr (et.size, et.type == NT_unsigned, 0);
18340 }
18341 }
18342
18343 static void
18344 do_neon_fcmp_absolute (void)
18345 {
18346 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18347 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18348 N_F_16_32 | N_KEY);
18349 /* Size field comes from bit mask. */
18350 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
18351 }
18352
18353 static void
18354 do_neon_fcmp_absolute_inv (void)
18355 {
18356 neon_exchange_operands ();
18357 do_neon_fcmp_absolute ();
18358 }
18359
18360 static void
18361 do_neon_step (void)
18362 {
18363 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
18364 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
18365 N_F_16_32 | N_KEY);
18366 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
18367 }
18368
18369 static void
18370 do_neon_abs_neg (void)
18371 {
18372 enum neon_shape rs;
18373 struct neon_type_el et;
18374
18375 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
18376 return;
18377
18378 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
18379 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
18380
18381 if (!check_simd_pred_availability (et.type == NT_float,
18382 NEON_CHECK_ARCH | NEON_CHECK_CC))
18383 return;
18384
18385 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18386 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18387 inst.instruction |= LOW4 (inst.operands[1].reg);
18388 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18389 inst.instruction |= neon_quad (rs) << 6;
18390 inst.instruction |= (et.type == NT_float) << 10;
18391 inst.instruction |= neon_logbits (et.size) << 18;
18392
18393 neon_dp_fixup (&inst);
18394 }
18395
18396 static void
18397 do_neon_sli (void)
18398 {
18399 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18400 return;
18401
18402 enum neon_shape rs;
18403 struct neon_type_el et;
18404 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18405 {
18406 rs = neon_select_shape (NS_QQI, NS_NULL);
18407 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18408 }
18409 else
18410 {
18411 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18412 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18413 }
18414
18415
18416 int imm = inst.operands[2].imm;
18417 constraint (imm < 0 || (unsigned)imm >= et.size,
18418 _("immediate out of range for insert"));
18419 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
18420 }
18421
18422 static void
18423 do_neon_sri (void)
18424 {
18425 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18426 return;
18427
18428 enum neon_shape rs;
18429 struct neon_type_el et;
18430 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18431 {
18432 rs = neon_select_shape (NS_QQI, NS_NULL);
18433 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_KEY);
18434 }
18435 else
18436 {
18437 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18438 et = neon_check_type (2, rs, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
18439 }
18440
18441 int imm = inst.operands[2].imm;
18442 constraint (imm < 1 || (unsigned)imm > et.size,
18443 _("immediate out of range for insert"));
18444 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
18445 }
18446
18447 static void
18448 do_neon_qshlu_imm (void)
18449 {
18450 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
18451 return;
18452
18453 enum neon_shape rs;
18454 struct neon_type_el et;
18455 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
18456 {
18457 rs = neon_select_shape (NS_QQI, NS_NULL);
18458 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
18459 }
18460 else
18461 {
18462 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
18463 et = neon_check_type (2, rs, N_EQK | N_UNS,
18464 N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
18465 }
18466
18467 int imm = inst.operands[2].imm;
18468 constraint (imm < 0 || (unsigned)imm >= et.size,
18469 _("immediate out of range for shift"));
18470 /* Only encodes the 'U present' variant of the instruction.
18471 In this case, signed types have OP (bit 8) set to 0.
18472 Unsigned types have OP set to 1. */
18473 inst.instruction |= (et.type == NT_unsigned) << 8;
18474 /* The rest of the bits are the same as other immediate shifts. */
18475 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
18476 }
18477
18478 static void
18479 do_neon_qmovn (void)
18480 {
18481 struct neon_type_el et = neon_check_type (2, NS_DQ,
18482 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18483 /* Saturating move where operands can be signed or unsigned, and the
18484 destination has the same signedness. */
18485 NEON_ENCODE (INTEGER, inst);
18486 if (et.type == NT_unsigned)
18487 inst.instruction |= 0xc0;
18488 else
18489 inst.instruction |= 0x80;
18490 neon_two_same (0, 1, et.size / 2);
18491 }
18492
18493 static void
18494 do_neon_qmovun (void)
18495 {
18496 struct neon_type_el et = neon_check_type (2, NS_DQ,
18497 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18498 /* Saturating move with unsigned results. Operands must be signed. */
18499 NEON_ENCODE (INTEGER, inst);
18500 neon_two_same (0, 1, et.size / 2);
18501 }
18502
18503 static void
18504 do_neon_rshift_sat_narrow (void)
18505 {
18506 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18507 or unsigned. If operands are unsigned, results must also be unsigned. */
18508 struct neon_type_el et = neon_check_type (2, NS_DQI,
18509 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
18510 int imm = inst.operands[2].imm;
18511 /* This gets the bounds check, size encoding and immediate bits calculation
18512 right. */
18513 et.size /= 2;
18514
18515 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
18516 VQMOVN.I<size> <Dd>, <Qm>. */
18517 if (imm == 0)
18518 {
18519 inst.operands[2].present = 0;
18520 inst.instruction = N_MNEM_vqmovn;
18521 do_neon_qmovn ();
18522 return;
18523 }
18524
18525 constraint (imm < 1 || (unsigned)imm > et.size,
18526 _("immediate out of range"));
18527 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
18528 }
18529
18530 static void
18531 do_neon_rshift_sat_narrow_u (void)
18532 {
18533 /* FIXME: Types for narrowing. If operands are signed, results can be signed
18534 or unsigned. If operands are unsigned, results must also be unsigned. */
18535 struct neon_type_el et = neon_check_type (2, NS_DQI,
18536 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
18537 int imm = inst.operands[2].imm;
18538 /* This gets the bounds check, size encoding and immediate bits calculation
18539 right. */
18540 et.size /= 2;
18541
18542 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
18543 VQMOVUN.I<size> <Dd>, <Qm>. */
18544 if (imm == 0)
18545 {
18546 inst.operands[2].present = 0;
18547 inst.instruction = N_MNEM_vqmovun;
18548 do_neon_qmovun ();
18549 return;
18550 }
18551
18552 constraint (imm < 1 || (unsigned)imm > et.size,
18553 _("immediate out of range"));
18554 /* FIXME: The manual is kind of unclear about what value U should have in
18555 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
18556 must be 1. */
18557 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
18558 }
18559
18560 static void
18561 do_neon_movn (void)
18562 {
18563 struct neon_type_el et = neon_check_type (2, NS_DQ,
18564 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18565 NEON_ENCODE (INTEGER, inst);
18566 neon_two_same (0, 1, et.size / 2);
18567 }
18568
18569 static void
18570 do_neon_rshift_narrow (void)
18571 {
18572 struct neon_type_el et = neon_check_type (2, NS_DQI,
18573 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
18574 int imm = inst.operands[2].imm;
18575 /* This gets the bounds check, size encoding and immediate bits calculation
18576 right. */
18577 et.size /= 2;
18578
18579 /* If immediate is zero then we are a pseudo-instruction for
18580 VMOVN.I<size> <Dd>, <Qm> */
18581 if (imm == 0)
18582 {
18583 inst.operands[2].present = 0;
18584 inst.instruction = N_MNEM_vmovn;
18585 do_neon_movn ();
18586 return;
18587 }
18588
18589 constraint (imm < 1 || (unsigned)imm > et.size,
18590 _("immediate out of range for narrowing operation"));
18591 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
18592 }
18593
18594 static void
18595 do_neon_shll (void)
18596 {
18597 /* FIXME: Type checking when lengthening. */
18598 struct neon_type_el et = neon_check_type (2, NS_QDI,
18599 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
18600 unsigned imm = inst.operands[2].imm;
18601
18602 if (imm == et.size)
18603 {
18604 /* Maximum shift variant. */
18605 NEON_ENCODE (INTEGER, inst);
18606 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18607 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18608 inst.instruction |= LOW4 (inst.operands[1].reg);
18609 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18610 inst.instruction |= neon_logbits (et.size) << 18;
18611
18612 neon_dp_fixup (&inst);
18613 }
18614 else
18615 {
18616 /* A more-specific type check for non-max versions. */
18617 et = neon_check_type (2, NS_QDI,
18618 N_EQK | N_DBL, N_SU_32 | N_KEY);
18619 NEON_ENCODE (IMMED, inst);
18620 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
18621 }
18622 }
18623
18624 /* Check the various types for the VCVT instruction, and return which version
18625 the current instruction is. */
18626
18627 #define CVT_FLAVOUR_VAR \
18628 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
18629 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
18630 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
18631 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
18632 /* Half-precision conversions. */ \
18633 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18634 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
18635 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
18636 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
18637 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
18638 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
18639 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
18640 Compared with single/double precision variants, only the co-processor \
18641 field is different, so the encoding flow is reused here. */ \
18642 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
18643 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
18644 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
18645 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
18646 /* VFP instructions. */ \
18647 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
18648 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
18649 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
18650 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
18651 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
18652 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
18653 /* VFP instructions with bitshift. */ \
18654 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
18655 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
18656 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
18657 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
18658 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
18659 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
18660 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
18661 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
18662
18663 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
18664 neon_cvt_flavour_##C,
18665
18666 /* The different types of conversions we can do. */
18667 enum neon_cvt_flavour
18668 {
18669 CVT_FLAVOUR_VAR
18670 neon_cvt_flavour_invalid,
18671 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
18672 };
18673
18674 #undef CVT_VAR
18675
18676 static enum neon_cvt_flavour
18677 get_neon_cvt_flavour (enum neon_shape rs)
18678 {
18679 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
18680 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
18681 if (et.type != NT_invtype) \
18682 { \
18683 inst.error = NULL; \
18684 return (neon_cvt_flavour_##C); \
18685 }
18686
18687 struct neon_type_el et;
18688 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
18689 || rs == NS_FF) ? N_VFP : 0;
18690 /* The instruction versions which take an immediate take one register
18691 argument, which is extended to the width of the full register. Thus the
18692 "source" and "destination" registers must have the same width. Hack that
18693 here by making the size equal to the key (wider, in this case) operand. */
18694 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
18695
18696 CVT_FLAVOUR_VAR;
18697
18698 return neon_cvt_flavour_invalid;
18699 #undef CVT_VAR
18700 }
18701
18702 enum neon_cvt_mode
18703 {
18704 neon_cvt_mode_a,
18705 neon_cvt_mode_n,
18706 neon_cvt_mode_p,
18707 neon_cvt_mode_m,
18708 neon_cvt_mode_z,
18709 neon_cvt_mode_x,
18710 neon_cvt_mode_r
18711 };
18712
18713 /* Neon-syntax VFP conversions. */
18714
18715 static void
18716 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
18717 {
18718 const char *opname = 0;
18719
18720 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
18721 || rs == NS_FHI || rs == NS_HFI)
18722 {
18723 /* Conversions with immediate bitshift. */
18724 const char *enc[] =
18725 {
18726 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
18727 CVT_FLAVOUR_VAR
18728 NULL
18729 #undef CVT_VAR
18730 };
18731
18732 if (flavour < (int) ARRAY_SIZE (enc))
18733 {
18734 opname = enc[flavour];
18735 constraint (inst.operands[0].reg != inst.operands[1].reg,
18736 _("operands 0 and 1 must be the same register"));
18737 inst.operands[1] = inst.operands[2];
18738 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
18739 }
18740 }
18741 else
18742 {
18743 /* Conversions without bitshift. */
18744 const char *enc[] =
18745 {
18746 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
18747 CVT_FLAVOUR_VAR
18748 NULL
18749 #undef CVT_VAR
18750 };
18751
18752 if (flavour < (int) ARRAY_SIZE (enc))
18753 opname = enc[flavour];
18754 }
18755
18756 if (opname)
18757 do_vfp_nsyn_opcode (opname);
18758
18759 /* ARMv8.2 fp16 VCVT instruction. */
18760 if (flavour == neon_cvt_flavour_s32_f16
18761 || flavour == neon_cvt_flavour_u32_f16
18762 || flavour == neon_cvt_flavour_f16_u32
18763 || flavour == neon_cvt_flavour_f16_s32)
18764 do_scalar_fp16_v82_encode ();
18765 }
18766
18767 static void
18768 do_vfp_nsyn_cvtz (void)
18769 {
18770 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
18771 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
18772 const char *enc[] =
18773 {
18774 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
18775 CVT_FLAVOUR_VAR
18776 NULL
18777 #undef CVT_VAR
18778 };
18779
18780 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
18781 do_vfp_nsyn_opcode (enc[flavour]);
18782 }
18783
18784 static void
18785 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
18786 enum neon_cvt_mode mode)
18787 {
18788 int sz, op;
18789 int rm;
18790
18791 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
18792 D register operands. */
18793 if (flavour == neon_cvt_flavour_s32_f64
18794 || flavour == neon_cvt_flavour_u32_f64)
18795 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
18796 _(BAD_FPU));
18797
18798 if (flavour == neon_cvt_flavour_s32_f16
18799 || flavour == neon_cvt_flavour_u32_f16)
18800 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
18801 _(BAD_FP16));
18802
18803 set_pred_insn_type (OUTSIDE_PRED_INSN);
18804
18805 switch (flavour)
18806 {
18807 case neon_cvt_flavour_s32_f64:
18808 sz = 1;
18809 op = 1;
18810 break;
18811 case neon_cvt_flavour_s32_f32:
18812 sz = 0;
18813 op = 1;
18814 break;
18815 case neon_cvt_flavour_s32_f16:
18816 sz = 0;
18817 op = 1;
18818 break;
18819 case neon_cvt_flavour_u32_f64:
18820 sz = 1;
18821 op = 0;
18822 break;
18823 case neon_cvt_flavour_u32_f32:
18824 sz = 0;
18825 op = 0;
18826 break;
18827 case neon_cvt_flavour_u32_f16:
18828 sz = 0;
18829 op = 0;
18830 break;
18831 default:
18832 first_error (_("invalid instruction shape"));
18833 return;
18834 }
18835
18836 switch (mode)
18837 {
18838 case neon_cvt_mode_a: rm = 0; break;
18839 case neon_cvt_mode_n: rm = 1; break;
18840 case neon_cvt_mode_p: rm = 2; break;
18841 case neon_cvt_mode_m: rm = 3; break;
18842 default: first_error (_("invalid rounding mode")); return;
18843 }
18844
18845 NEON_ENCODE (FPV8, inst);
18846 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
18847 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
18848 inst.instruction |= sz << 8;
18849
18850 /* ARMv8.2 fp16 VCVT instruction. */
18851 if (flavour == neon_cvt_flavour_s32_f16
18852 ||flavour == neon_cvt_flavour_u32_f16)
18853 do_scalar_fp16_v82_encode ();
18854 inst.instruction |= op << 7;
18855 inst.instruction |= rm << 16;
18856 inst.instruction |= 0xf0000000;
18857 inst.is_neon = TRUE;
18858 }
18859
18860 static void
18861 do_neon_cvt_1 (enum neon_cvt_mode mode)
18862 {
18863 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
18864 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
18865 NS_FH, NS_HF, NS_FHI, NS_HFI,
18866 NS_NULL);
18867 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
18868
18869 if (flavour == neon_cvt_flavour_invalid)
18870 return;
18871
18872 /* PR11109: Handle round-to-zero for VCVT conversions. */
18873 if (mode == neon_cvt_mode_z
18874 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
18875 && (flavour == neon_cvt_flavour_s16_f16
18876 || flavour == neon_cvt_flavour_u16_f16
18877 || flavour == neon_cvt_flavour_s32_f32
18878 || flavour == neon_cvt_flavour_u32_f32
18879 || flavour == neon_cvt_flavour_s32_f64
18880 || flavour == neon_cvt_flavour_u32_f64)
18881 && (rs == NS_FD || rs == NS_FF))
18882 {
18883 do_vfp_nsyn_cvtz ();
18884 return;
18885 }
18886
18887 /* ARMv8.2 fp16 VCVT conversions. */
18888 if (mode == neon_cvt_mode_z
18889 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
18890 && (flavour == neon_cvt_flavour_s32_f16
18891 || flavour == neon_cvt_flavour_u32_f16)
18892 && (rs == NS_FH))
18893 {
18894 do_vfp_nsyn_cvtz ();
18895 do_scalar_fp16_v82_encode ();
18896 return;
18897 }
18898
18899 /* VFP rather than Neon conversions. */
18900 if (flavour >= neon_cvt_flavour_first_fp)
18901 {
18902 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
18903 do_vfp_nsyn_cvt (rs, flavour);
18904 else
18905 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
18906
18907 return;
18908 }
18909
18910 switch (rs)
18911 {
18912 case NS_QQI:
18913 if (mode == neon_cvt_mode_z
18914 && (flavour == neon_cvt_flavour_f16_s16
18915 || flavour == neon_cvt_flavour_f16_u16
18916 || flavour == neon_cvt_flavour_s16_f16
18917 || flavour == neon_cvt_flavour_u16_f16
18918 || flavour == neon_cvt_flavour_f32_u32
18919 || flavour == neon_cvt_flavour_f32_s32
18920 || flavour == neon_cvt_flavour_s32_f32
18921 || flavour == neon_cvt_flavour_u32_f32))
18922 {
18923 if (!check_simd_pred_availability (TRUE,
18924 NEON_CHECK_CC | NEON_CHECK_ARCH))
18925 return;
18926 }
18927 else if (mode == neon_cvt_mode_n)
18928 {
18929 /* We are dealing with vcvt with the 'ne' condition. */
18930 inst.cond = 0x1;
18931 inst.instruction = N_MNEM_vcvt;
18932 do_neon_cvt_1 (neon_cvt_mode_z);
18933 return;
18934 }
18935 /* fall through. */
18936 case NS_DDI:
18937 {
18938 unsigned immbits;
18939 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
18940 0x0000100, 0x1000100, 0x0, 0x1000000};
18941
18942 if ((rs != NS_QQI || !ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18943 && vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
18944 return;
18945
18946 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
18947 {
18948 constraint (inst.operands[2].present && inst.operands[2].imm == 0,
18949 _("immediate value out of range"));
18950 switch (flavour)
18951 {
18952 case neon_cvt_flavour_f16_s16:
18953 case neon_cvt_flavour_f16_u16:
18954 case neon_cvt_flavour_s16_f16:
18955 case neon_cvt_flavour_u16_f16:
18956 constraint (inst.operands[2].imm > 16,
18957 _("immediate value out of range"));
18958 break;
18959 case neon_cvt_flavour_f32_u32:
18960 case neon_cvt_flavour_f32_s32:
18961 case neon_cvt_flavour_s32_f32:
18962 case neon_cvt_flavour_u32_f32:
18963 constraint (inst.operands[2].imm > 32,
18964 _("immediate value out of range"));
18965 break;
18966 default:
18967 inst.error = BAD_FPU;
18968 return;
18969 }
18970 }
18971
18972 /* Fixed-point conversion with #0 immediate is encoded as an
18973 integer conversion. */
18974 if (inst.operands[2].present && inst.operands[2].imm == 0)
18975 goto int_encode;
18976 NEON_ENCODE (IMMED, inst);
18977 if (flavour != neon_cvt_flavour_invalid)
18978 inst.instruction |= enctab[flavour];
18979 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
18980 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
18981 inst.instruction |= LOW4 (inst.operands[1].reg);
18982 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
18983 inst.instruction |= neon_quad (rs) << 6;
18984 inst.instruction |= 1 << 21;
18985 if (flavour < neon_cvt_flavour_s16_f16)
18986 {
18987 inst.instruction |= 1 << 21;
18988 immbits = 32 - inst.operands[2].imm;
18989 inst.instruction |= immbits << 16;
18990 }
18991 else
18992 {
18993 inst.instruction |= 3 << 20;
18994 immbits = 16 - inst.operands[2].imm;
18995 inst.instruction |= immbits << 16;
18996 inst.instruction &= ~(1 << 9);
18997 }
18998
18999 neon_dp_fixup (&inst);
19000 }
19001 break;
19002
19003 case NS_QQ:
19004 if ((mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
19005 || mode == neon_cvt_mode_m || mode == neon_cvt_mode_p)
19006 && (flavour == neon_cvt_flavour_s16_f16
19007 || flavour == neon_cvt_flavour_u16_f16
19008 || flavour == neon_cvt_flavour_s32_f32
19009 || flavour == neon_cvt_flavour_u32_f32))
19010 {
19011 if (!check_simd_pred_availability (TRUE,
19012 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19013 return;
19014 }
19015 else if (mode == neon_cvt_mode_z
19016 && (flavour == neon_cvt_flavour_f16_s16
19017 || flavour == neon_cvt_flavour_f16_u16
19018 || flavour == neon_cvt_flavour_s16_f16
19019 || flavour == neon_cvt_flavour_u16_f16
19020 || flavour == neon_cvt_flavour_f32_u32
19021 || flavour == neon_cvt_flavour_f32_s32
19022 || flavour == neon_cvt_flavour_s32_f32
19023 || flavour == neon_cvt_flavour_u32_f32))
19024 {
19025 if (!check_simd_pred_availability (TRUE,
19026 NEON_CHECK_CC | NEON_CHECK_ARCH))
19027 return;
19028 }
19029 /* fall through. */
19030 case NS_DD:
19031 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
19032 {
19033
19034 NEON_ENCODE (FLOAT, inst);
19035 if (!check_simd_pred_availability (TRUE,
19036 NEON_CHECK_CC | NEON_CHECK_ARCH8))
19037 return;
19038
19039 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19040 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19041 inst.instruction |= LOW4 (inst.operands[1].reg);
19042 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19043 inst.instruction |= neon_quad (rs) << 6;
19044 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
19045 || flavour == neon_cvt_flavour_u32_f32) << 7;
19046 inst.instruction |= mode << 8;
19047 if (flavour == neon_cvt_flavour_u16_f16
19048 || flavour == neon_cvt_flavour_s16_f16)
19049 /* Mask off the original size bits and reencode them. */
19050 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
19051
19052 if (thumb_mode)
19053 inst.instruction |= 0xfc000000;
19054 else
19055 inst.instruction |= 0xf0000000;
19056 }
19057 else
19058 {
19059 int_encode:
19060 {
19061 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
19062 0x100, 0x180, 0x0, 0x080};
19063
19064 NEON_ENCODE (INTEGER, inst);
19065
19066 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
19067 {
19068 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19069 return;
19070 }
19071
19072 if (flavour != neon_cvt_flavour_invalid)
19073 inst.instruction |= enctab[flavour];
19074
19075 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19076 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19077 inst.instruction |= LOW4 (inst.operands[1].reg);
19078 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19079 inst.instruction |= neon_quad (rs) << 6;
19080 if (flavour >= neon_cvt_flavour_s16_f16
19081 && flavour <= neon_cvt_flavour_f16_u16)
19082 /* Half precision. */
19083 inst.instruction |= 1 << 18;
19084 else
19085 inst.instruction |= 2 << 18;
19086
19087 neon_dp_fixup (&inst);
19088 }
19089 }
19090 break;
19091
19092 /* Half-precision conversions for Advanced SIMD -- neon. */
19093 case NS_QD:
19094 case NS_DQ:
19095 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
19096 return;
19097
19098 if ((rs == NS_DQ)
19099 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
19100 {
19101 as_bad (_("operand size must match register width"));
19102 break;
19103 }
19104
19105 if ((rs == NS_QD)
19106 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
19107 {
19108 as_bad (_("operand size must match register width"));
19109 break;
19110 }
19111
19112 if (rs == NS_DQ)
19113 inst.instruction = 0x3b60600;
19114 else
19115 inst.instruction = 0x3b60700;
19116
19117 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19118 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19119 inst.instruction |= LOW4 (inst.operands[1].reg);
19120 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19121 neon_dp_fixup (&inst);
19122 break;
19123
19124 default:
19125 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
19126 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
19127 do_vfp_nsyn_cvt (rs, flavour);
19128 else
19129 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
19130 }
19131 }
19132
19133 static void
19134 do_neon_cvtr (void)
19135 {
19136 do_neon_cvt_1 (neon_cvt_mode_x);
19137 }
19138
19139 static void
19140 do_neon_cvt (void)
19141 {
19142 do_neon_cvt_1 (neon_cvt_mode_z);
19143 }
19144
19145 static void
19146 do_neon_cvta (void)
19147 {
19148 do_neon_cvt_1 (neon_cvt_mode_a);
19149 }
19150
19151 static void
19152 do_neon_cvtn (void)
19153 {
19154 do_neon_cvt_1 (neon_cvt_mode_n);
19155 }
19156
19157 static void
19158 do_neon_cvtp (void)
19159 {
19160 do_neon_cvt_1 (neon_cvt_mode_p);
19161 }
19162
19163 static void
19164 do_neon_cvtm (void)
19165 {
19166 do_neon_cvt_1 (neon_cvt_mode_m);
19167 }
19168
19169 static void
19170 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
19171 {
19172 if (is_double)
19173 mark_feature_used (&fpu_vfp_ext_armv8);
19174
19175 encode_arm_vfp_reg (inst.operands[0].reg,
19176 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
19177 encode_arm_vfp_reg (inst.operands[1].reg,
19178 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
19179 inst.instruction |= to ? 0x10000 : 0;
19180 inst.instruction |= t ? 0x80 : 0;
19181 inst.instruction |= is_double ? 0x100 : 0;
19182 do_vfp_cond_or_thumb ();
19183 }
19184
19185 static void
19186 do_neon_cvttb_1 (bfd_boolean t)
19187 {
19188 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
19189 NS_DF, NS_DH, NS_QQ, NS_QQI, NS_NULL);
19190
19191 if (rs == NS_NULL)
19192 return;
19193 else if (rs == NS_QQ || rs == NS_QQI)
19194 {
19195 int single_to_half = 0;
19196 if (!check_simd_pred_availability (TRUE, NEON_CHECK_ARCH))
19197 return;
19198
19199 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
19200
19201 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19202 && (flavour == neon_cvt_flavour_u16_f16
19203 || flavour == neon_cvt_flavour_s16_f16
19204 || flavour == neon_cvt_flavour_f16_s16
19205 || flavour == neon_cvt_flavour_f16_u16
19206 || flavour == neon_cvt_flavour_u32_f32
19207 || flavour == neon_cvt_flavour_s32_f32
19208 || flavour == neon_cvt_flavour_f32_s32
19209 || flavour == neon_cvt_flavour_f32_u32))
19210 {
19211 inst.cond = 0xf;
19212 inst.instruction = N_MNEM_vcvt;
19213 set_pred_insn_type (INSIDE_VPT_INSN);
19214 do_neon_cvt_1 (neon_cvt_mode_z);
19215 return;
19216 }
19217 else if (rs == NS_QQ && flavour == neon_cvt_flavour_f32_f16)
19218 single_to_half = 1;
19219 else if (rs == NS_QQ && flavour != neon_cvt_flavour_f16_f32)
19220 {
19221 first_error (BAD_FPU);
19222 return;
19223 }
19224
19225 inst.instruction = 0xee3f0e01;
19226 inst.instruction |= single_to_half << 28;
19227 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19228 inst.instruction |= LOW4 (inst.operands[0].reg) << 13;
19229 inst.instruction |= t << 12;
19230 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19231 inst.instruction |= LOW4 (inst.operands[1].reg) << 1;
19232 inst.is_neon = 1;
19233 }
19234 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
19235 {
19236 inst.error = NULL;
19237 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
19238 }
19239 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
19240 {
19241 inst.error = NULL;
19242 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
19243 }
19244 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
19245 {
19246 /* The VCVTB and VCVTT instructions with D-register operands
19247 don't work for SP only targets. */
19248 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19249 _(BAD_FPU));
19250
19251 inst.error = NULL;
19252 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
19253 }
19254 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
19255 {
19256 /* The VCVTB and VCVTT instructions with D-register operands
19257 don't work for SP only targets. */
19258 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
19259 _(BAD_FPU));
19260
19261 inst.error = NULL;
19262 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
19263 }
19264 else
19265 return;
19266 }
19267
19268 static void
19269 do_neon_cvtb (void)
19270 {
19271 do_neon_cvttb_1 (FALSE);
19272 }
19273
19274
19275 static void
19276 do_neon_cvtt (void)
19277 {
19278 do_neon_cvttb_1 (TRUE);
19279 }
19280
19281 static void
19282 neon_move_immediate (void)
19283 {
19284 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
19285 struct neon_type_el et = neon_check_type (2, rs,
19286 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
19287 unsigned immlo, immhi = 0, immbits;
19288 int op, cmode, float_p;
19289
19290 constraint (et.type == NT_invtype,
19291 _("operand size must be specified for immediate VMOV"));
19292
19293 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
19294 op = (inst.instruction & (1 << 5)) != 0;
19295
19296 immlo = inst.operands[1].imm;
19297 if (inst.operands[1].regisimm)
19298 immhi = inst.operands[1].reg;
19299
19300 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
19301 _("immediate has bits set outside the operand size"));
19302
19303 float_p = inst.operands[1].immisfloat;
19304
19305 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
19306 et.size, et.type)) == FAIL)
19307 {
19308 /* Invert relevant bits only. */
19309 neon_invert_size (&immlo, &immhi, et.size);
19310 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
19311 with one or the other; those cases are caught by
19312 neon_cmode_for_move_imm. */
19313 op = !op;
19314 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
19315 &op, et.size, et.type)) == FAIL)
19316 {
19317 first_error (_("immediate out of range"));
19318 return;
19319 }
19320 }
19321
19322 inst.instruction &= ~(1 << 5);
19323 inst.instruction |= op << 5;
19324
19325 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19326 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19327 inst.instruction |= neon_quad (rs) << 6;
19328 inst.instruction |= cmode << 8;
19329
19330 neon_write_immbits (immbits);
19331 }
19332
19333 static void
19334 do_neon_mvn (void)
19335 {
19336 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
19337 return;
19338
19339 if (inst.operands[1].isreg)
19340 {
19341 enum neon_shape rs;
19342 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19343 rs = neon_select_shape (NS_QQ, NS_NULL);
19344 else
19345 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19346
19347 NEON_ENCODE (INTEGER, inst);
19348 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19349 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19350 inst.instruction |= LOW4 (inst.operands[1].reg);
19351 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19352 inst.instruction |= neon_quad (rs) << 6;
19353 }
19354 else
19355 {
19356 NEON_ENCODE (IMMED, inst);
19357 neon_move_immediate ();
19358 }
19359
19360 neon_dp_fixup (&inst);
19361
19362 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19363 {
19364 constraint (!inst.operands[1].isreg && !inst.operands[0].isquad, BAD_FPU);
19365 constraint ((inst.instruction & 0xd00) == 0xd00,
19366 _("immediate value out of range"));
19367 }
19368 }
19369
19370 /* Encode instructions of form:
19371
19372 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
19373 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
19374
19375 static void
19376 neon_mixed_length (struct neon_type_el et, unsigned size)
19377 {
19378 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19379 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19380 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19381 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19382 inst.instruction |= LOW4 (inst.operands[2].reg);
19383 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19384 inst.instruction |= (et.type == NT_unsigned) << 24;
19385 inst.instruction |= neon_logbits (size) << 20;
19386
19387 neon_dp_fixup (&inst);
19388 }
19389
19390 static void
19391 do_neon_dyadic_long (void)
19392 {
19393 enum neon_shape rs = neon_select_shape (NS_QDD, NS_QQQ, NS_QQR, NS_NULL);
19394 if (rs == NS_QDD)
19395 {
19396 if (vfp_or_neon_is_neon (NEON_CHECK_ARCH | NEON_CHECK_CC) == FAIL)
19397 return;
19398
19399 NEON_ENCODE (INTEGER, inst);
19400 /* FIXME: Type checking for lengthening op. */
19401 struct neon_type_el et = neon_check_type (3, NS_QDD,
19402 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
19403 neon_mixed_length (et, et.size);
19404 }
19405 else if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19406 && (inst.cond == 0xf || inst.cond == 0x10))
19407 {
19408 /* If parsing for MVE, vaddl/vsubl/vabdl{e,t} can only be vadd/vsub/vabd
19409 in an IT block with le/lt conditions. */
19410
19411 if (inst.cond == 0xf)
19412 inst.cond = 0xb;
19413 else if (inst.cond == 0x10)
19414 inst.cond = 0xd;
19415
19416 inst.pred_insn_type = INSIDE_IT_INSN;
19417
19418 if (inst.instruction == N_MNEM_vaddl)
19419 {
19420 inst.instruction = N_MNEM_vadd;
19421 do_neon_addsub_if_i ();
19422 }
19423 else if (inst.instruction == N_MNEM_vsubl)
19424 {
19425 inst.instruction = N_MNEM_vsub;
19426 do_neon_addsub_if_i ();
19427 }
19428 else if (inst.instruction == N_MNEM_vabdl)
19429 {
19430 inst.instruction = N_MNEM_vabd;
19431 do_neon_dyadic_if_su ();
19432 }
19433 }
19434 else
19435 first_error (BAD_FPU);
19436 }
19437
19438 static void
19439 do_neon_abal (void)
19440 {
19441 struct neon_type_el et = neon_check_type (3, NS_QDD,
19442 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
19443 neon_mixed_length (et, et.size);
19444 }
19445
19446 static void
19447 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
19448 {
19449 if (inst.operands[2].isscalar)
19450 {
19451 struct neon_type_el et = neon_check_type (3, NS_QDS,
19452 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
19453 NEON_ENCODE (SCALAR, inst);
19454 neon_mul_mac (et, et.type == NT_unsigned);
19455 }
19456 else
19457 {
19458 struct neon_type_el et = neon_check_type (3, NS_QDD,
19459 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
19460 NEON_ENCODE (INTEGER, inst);
19461 neon_mixed_length (et, et.size);
19462 }
19463 }
19464
19465 static void
19466 do_neon_mac_maybe_scalar_long (void)
19467 {
19468 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
19469 }
19470
19471 /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
19472 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
19473
19474 static unsigned
19475 neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
19476 {
19477 unsigned regno = NEON_SCALAR_REG (scalar);
19478 unsigned elno = NEON_SCALAR_INDEX (scalar);
19479
19480 if (quad_p)
19481 {
19482 if (regno > 7 || elno > 3)
19483 goto bad_scalar;
19484
19485 return ((regno & 0x7)
19486 | ((elno & 0x1) << 3)
19487 | (((elno >> 1) & 0x1) << 5));
19488 }
19489 else
19490 {
19491 if (regno > 15 || elno > 1)
19492 goto bad_scalar;
19493
19494 return (((regno & 0x1) << 5)
19495 | ((regno >> 1) & 0x7)
19496 | ((elno & 0x1) << 3));
19497 }
19498
19499 bad_scalar:
19500 first_error (_("scalar out of range for multiply instruction"));
19501 return 0;
19502 }
19503
19504 static void
19505 do_neon_fmac_maybe_scalar_long (int subtype)
19506 {
19507 enum neon_shape rs;
19508 int high8;
19509 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
19510 field (bits[21:20]) has different meaning. For scalar index variant, it's
19511 used to differentiate add and subtract, otherwise it's with fixed value
19512 0x2. */
19513 int size = -1;
19514
19515 if (inst.cond != COND_ALWAYS)
19516 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
19517 "behaviour is UNPREDICTABLE"));
19518
19519 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
19520 _(BAD_FP16));
19521
19522 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
19523 _(BAD_FPU));
19524
19525 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
19526 be a scalar index register. */
19527 if (inst.operands[2].isscalar)
19528 {
19529 high8 = 0xfe000000;
19530 if (subtype)
19531 size = 16;
19532 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
19533 }
19534 else
19535 {
19536 high8 = 0xfc000000;
19537 size = 32;
19538 if (subtype)
19539 inst.instruction |= (0x1 << 23);
19540 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
19541 }
19542
19543 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
19544
19545 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
19546 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
19547 so we simply pass -1 as size. */
19548 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
19549 neon_three_same (quad_p, 0, size);
19550
19551 /* Undo neon_dp_fixup. Redo the high eight bits. */
19552 inst.instruction &= 0x00ffffff;
19553 inst.instruction |= high8;
19554
19555 #define LOW1(R) ((R) & 0x1)
19556 #define HI4(R) (((R) >> 1) & 0xf)
19557 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
19558 whether the instruction is in Q form and whether Vm is a scalar indexed
19559 operand. */
19560 if (inst.operands[2].isscalar)
19561 {
19562 unsigned rm
19563 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
19564 inst.instruction &= 0xffffffd0;
19565 inst.instruction |= rm;
19566
19567 if (!quad_p)
19568 {
19569 /* Redo Rn as well. */
19570 inst.instruction &= 0xfff0ff7f;
19571 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19572 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19573 }
19574 }
19575 else if (!quad_p)
19576 {
19577 /* Redo Rn and Rm. */
19578 inst.instruction &= 0xfff0ff50;
19579 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
19580 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
19581 inst.instruction |= HI4 (inst.operands[2].reg);
19582 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
19583 }
19584 }
19585
19586 static void
19587 do_neon_vfmal (void)
19588 {
19589 return do_neon_fmac_maybe_scalar_long (0);
19590 }
19591
19592 static void
19593 do_neon_vfmsl (void)
19594 {
19595 return do_neon_fmac_maybe_scalar_long (1);
19596 }
19597
19598 static void
19599 do_neon_dyadic_wide (void)
19600 {
19601 struct neon_type_el et = neon_check_type (3, NS_QQD,
19602 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
19603 neon_mixed_length (et, et.size);
19604 }
19605
19606 static void
19607 do_neon_dyadic_narrow (void)
19608 {
19609 struct neon_type_el et = neon_check_type (3, NS_QDD,
19610 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
19611 /* Operand sign is unimportant, and the U bit is part of the opcode,
19612 so force the operand type to integer. */
19613 et.type = NT_integer;
19614 neon_mixed_length (et, et.size / 2);
19615 }
19616
19617 static void
19618 do_neon_mul_sat_scalar_long (void)
19619 {
19620 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
19621 }
19622
19623 static void
19624 do_neon_vmull (void)
19625 {
19626 if (inst.operands[2].isscalar)
19627 do_neon_mac_maybe_scalar_long ();
19628 else
19629 {
19630 struct neon_type_el et = neon_check_type (3, NS_QDD,
19631 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
19632
19633 if (et.type == NT_poly)
19634 NEON_ENCODE (POLY, inst);
19635 else
19636 NEON_ENCODE (INTEGER, inst);
19637
19638 /* For polynomial encoding the U bit must be zero, and the size must
19639 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
19640 obviously, as 0b10). */
19641 if (et.size == 64)
19642 {
19643 /* Check we're on the correct architecture. */
19644 if (!mark_feature_used (&fpu_crypto_ext_armv8))
19645 inst.error =
19646 _("Instruction form not available on this architecture.");
19647
19648 et.size = 32;
19649 }
19650
19651 neon_mixed_length (et, et.size);
19652 }
19653 }
19654
19655 static void
19656 do_neon_ext (void)
19657 {
19658 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
19659 struct neon_type_el et = neon_check_type (3, rs,
19660 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
19661 unsigned imm = (inst.operands[3].imm * et.size) / 8;
19662
19663 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
19664 _("shift out of range"));
19665 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19666 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19667 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19668 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19669 inst.instruction |= LOW4 (inst.operands[2].reg);
19670 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
19671 inst.instruction |= neon_quad (rs) << 6;
19672 inst.instruction |= imm << 8;
19673
19674 neon_dp_fixup (&inst);
19675 }
19676
19677 static void
19678 do_neon_rev (void)
19679 {
19680 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
19681 return;
19682
19683 enum neon_shape rs;
19684 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19685 rs = neon_select_shape (NS_QQ, NS_NULL);
19686 else
19687 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
19688
19689 struct neon_type_el et = neon_check_type (2, rs,
19690 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19691
19692 unsigned op = (inst.instruction >> 7) & 3;
19693 /* N (width of reversed regions) is encoded as part of the bitmask. We
19694 extract it here to check the elements to be reversed are smaller.
19695 Otherwise we'd get a reserved instruction. */
19696 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
19697
19698 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext) && elsize == 64
19699 && inst.operands[0].reg == inst.operands[1].reg)
19700 as_tsktsk (_("Warning: 64-bit element size and same destination and source"
19701 " operands makes instruction UNPREDICTABLE"));
19702
19703 gas_assert (elsize != 0);
19704 constraint (et.size >= elsize,
19705 _("elements must be smaller than reversal region"));
19706 neon_two_same (neon_quad (rs), 1, et.size);
19707 }
19708
19709 static void
19710 do_neon_dup (void)
19711 {
19712 if (inst.operands[1].isscalar)
19713 {
19714 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19715 BAD_FPU);
19716 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
19717 struct neon_type_el et = neon_check_type (2, rs,
19718 N_EQK, N_8 | N_16 | N_32 | N_KEY);
19719 unsigned sizebits = et.size >> 3;
19720 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
19721 int logsize = neon_logbits (et.size);
19722 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
19723
19724 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
19725 return;
19726
19727 NEON_ENCODE (SCALAR, inst);
19728 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19729 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19730 inst.instruction |= LOW4 (dm);
19731 inst.instruction |= HI1 (dm) << 5;
19732 inst.instruction |= neon_quad (rs) << 6;
19733 inst.instruction |= x << 17;
19734 inst.instruction |= sizebits << 16;
19735
19736 neon_dp_fixup (&inst);
19737 }
19738 else
19739 {
19740 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
19741 struct neon_type_el et = neon_check_type (2, rs,
19742 N_8 | N_16 | N_32 | N_KEY, N_EQK);
19743 if (rs == NS_QR)
19744 {
19745 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH))
19746 return;
19747 }
19748 else
19749 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1),
19750 BAD_FPU);
19751
19752 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19753 {
19754 if (inst.operands[1].reg == REG_SP)
19755 as_tsktsk (MVE_BAD_SP);
19756 else if (inst.operands[1].reg == REG_PC)
19757 as_tsktsk (MVE_BAD_PC);
19758 }
19759
19760 /* Duplicate ARM register to lanes of vector. */
19761 NEON_ENCODE (ARMREG, inst);
19762 switch (et.size)
19763 {
19764 case 8: inst.instruction |= 0x400000; break;
19765 case 16: inst.instruction |= 0x000020; break;
19766 case 32: inst.instruction |= 0x000000; break;
19767 default: break;
19768 }
19769 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
19770 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
19771 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
19772 inst.instruction |= neon_quad (rs) << 21;
19773 /* The encoding for this instruction is identical for the ARM and Thumb
19774 variants, except for the condition field. */
19775 do_vfp_cond_or_thumb ();
19776 }
19777 }
19778
19779 static void
19780 do_mve_mov (int toQ)
19781 {
19782 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19783 return;
19784 if (inst.cond > COND_ALWAYS)
19785 inst.pred_insn_type = MVE_UNPREDICABLE_INSN;
19786
19787 unsigned Rt = 0, Rt2 = 1, Q0 = 2, Q1 = 3;
19788 if (toQ)
19789 {
19790 Q0 = 0;
19791 Q1 = 1;
19792 Rt = 2;
19793 Rt2 = 3;
19794 }
19795
19796 constraint (inst.operands[Q0].reg != inst.operands[Q1].reg + 2,
19797 _("Index one must be [2,3] and index two must be two less than"
19798 " index one."));
19799 constraint (inst.operands[Rt].reg == inst.operands[Rt2].reg,
19800 _("General purpose registers may not be the same"));
19801 constraint (inst.operands[Rt].reg == REG_SP
19802 || inst.operands[Rt2].reg == REG_SP,
19803 BAD_SP);
19804 constraint (inst.operands[Rt].reg == REG_PC
19805 || inst.operands[Rt2].reg == REG_PC,
19806 BAD_PC);
19807
19808 inst.instruction = 0xec000f00;
19809 inst.instruction |= HI1 (inst.operands[Q1].reg / 32) << 23;
19810 inst.instruction |= !!toQ << 20;
19811 inst.instruction |= inst.operands[Rt2].reg << 16;
19812 inst.instruction |= LOW4 (inst.operands[Q1].reg / 32) << 13;
19813 inst.instruction |= (inst.operands[Q1].reg % 4) << 4;
19814 inst.instruction |= inst.operands[Rt].reg;
19815 }
19816
19817 static void
19818 do_mve_movn (void)
19819 {
19820 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19821 return;
19822
19823 if (inst.cond > COND_ALWAYS)
19824 inst.pred_insn_type = INSIDE_VPT_INSN;
19825 else
19826 inst.pred_insn_type = MVE_OUTSIDE_PRED_INSN;
19827
19828 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_I16 | N_I32
19829 | N_KEY);
19830
19831 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19832 inst.instruction |= (neon_logbits (et.size) - 1) << 18;
19833 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19834 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19835 inst.instruction |= LOW4 (inst.operands[1].reg);
19836 inst.is_neon = 1;
19837
19838 }
19839
19840 /* VMOV has particularly many variations. It can be one of:
19841 0. VMOV<c><q> <Qd>, <Qm>
19842 1. VMOV<c><q> <Dd>, <Dm>
19843 (Register operations, which are VORR with Rm = Rn.)
19844 2. VMOV<c><q>.<dt> <Qd>, #<imm>
19845 3. VMOV<c><q>.<dt> <Dd>, #<imm>
19846 (Immediate loads.)
19847 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
19848 (ARM register to scalar.)
19849 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
19850 (Two ARM registers to vector.)
19851 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
19852 (Scalar to ARM register.)
19853 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
19854 (Vector to two ARM registers.)
19855 8. VMOV.F32 <Sd>, <Sm>
19856 9. VMOV.F64 <Dd>, <Dm>
19857 (VFP register moves.)
19858 10. VMOV.F32 <Sd>, #imm
19859 11. VMOV.F64 <Dd>, #imm
19860 (VFP float immediate load.)
19861 12. VMOV <Rd>, <Sm>
19862 (VFP single to ARM reg.)
19863 13. VMOV <Sd>, <Rm>
19864 (ARM reg to VFP single.)
19865 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
19866 (Two ARM regs to two VFP singles.)
19867 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
19868 (Two VFP singles to two ARM regs.)
19869 16. VMOV<c> <Rt>, <Rt2>, <Qd[idx]>, <Qd[idx2]>
19870 17. VMOV<c> <Qd[idx]>, <Qd[idx2]>, <Rt>, <Rt2>
19871 18. VMOV<c>.<dt> <Rt>, <Qn[idx]>
19872 19. VMOV<c>.<dt> <Qd[idx]>, <Rt>
19873
19874 These cases can be disambiguated using neon_select_shape, except cases 1/9
19875 and 3/11 which depend on the operand type too.
19876
19877 All the encoded bits are hardcoded by this function.
19878
19879 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
19880 Cases 5, 7 may be used with VFPv2 and above.
19881
19882 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
19883 can specify a type where it doesn't make sense to, and is ignored). */
19884
19885 static void
19886 do_neon_mov (void)
19887 {
19888 enum neon_shape rs = neon_select_shape (NS_RRSS, NS_SSRR, NS_RRFF, NS_FFRR,
19889 NS_DRR, NS_RRD, NS_QQ, NS_DD, NS_QI,
19890 NS_DI, NS_SR, NS_RS, NS_FF, NS_FI,
19891 NS_RF, NS_FR, NS_HR, NS_RH, NS_HI,
19892 NS_NULL);
19893 struct neon_type_el et;
19894 const char *ldconst = 0;
19895
19896 switch (rs)
19897 {
19898 case NS_DD: /* case 1/9. */
19899 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
19900 /* It is not an error here if no type is given. */
19901 inst.error = NULL;
19902
19903 /* In MVE we interpret the following instructions as same, so ignoring
19904 the following type (float) and size (64) checks.
19905 a: VMOV<c><q> <Dd>, <Dm>
19906 b: VMOV<c><q>.F64 <Dd>, <Dm>. */
19907 if ((et.type == NT_float && et.size == 64)
19908 || (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)))
19909 {
19910 do_vfp_nsyn_opcode ("fcpyd");
19911 break;
19912 }
19913 /* fall through. */
19914
19915 case NS_QQ: /* case 0/1. */
19916 {
19917 if (!check_simd_pred_availability (FALSE,
19918 NEON_CHECK_CC | NEON_CHECK_ARCH))
19919 return;
19920 /* The architecture manual I have doesn't explicitly state which
19921 value the U bit should have for register->register moves, but
19922 the equivalent VORR instruction has U = 0, so do that. */
19923 inst.instruction = 0x0200110;
19924 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
19925 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
19926 inst.instruction |= LOW4 (inst.operands[1].reg);
19927 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
19928 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
19929 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
19930 inst.instruction |= neon_quad (rs) << 6;
19931
19932 neon_dp_fixup (&inst);
19933 }
19934 break;
19935
19936 case NS_DI: /* case 3/11. */
19937 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
19938 inst.error = NULL;
19939 if (et.type == NT_float && et.size == 64)
19940 {
19941 /* case 11 (fconstd). */
19942 ldconst = "fconstd";
19943 goto encode_fconstd;
19944 }
19945 /* fall through. */
19946
19947 case NS_QI: /* case 2/3. */
19948 if (!check_simd_pred_availability (FALSE,
19949 NEON_CHECK_CC | NEON_CHECK_ARCH))
19950 return;
19951 inst.instruction = 0x0800010;
19952 neon_move_immediate ();
19953 neon_dp_fixup (&inst);
19954 break;
19955
19956 case NS_SR: /* case 4. */
19957 {
19958 unsigned bcdebits = 0;
19959 int logsize;
19960 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
19961 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
19962
19963 /* .<size> is optional here, defaulting to .32. */
19964 if (inst.vectype.elems == 0
19965 && inst.operands[0].vectype.type == NT_invtype
19966 && inst.operands[1].vectype.type == NT_invtype)
19967 {
19968 inst.vectype.el[0].type = NT_untyped;
19969 inst.vectype.el[0].size = 32;
19970 inst.vectype.elems = 1;
19971 }
19972
19973 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
19974 logsize = neon_logbits (et.size);
19975
19976 if (et.size != 32)
19977 {
19978 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
19979 && vfp_or_neon_is_neon (NEON_CHECK_ARCH) == FAIL)
19980 return;
19981 }
19982 else
19983 {
19984 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
19985 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
19986 _(BAD_FPU));
19987 }
19988
19989 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
19990 {
19991 if (inst.operands[1].reg == REG_SP)
19992 as_tsktsk (MVE_BAD_SP);
19993 else if (inst.operands[1].reg == REG_PC)
19994 as_tsktsk (MVE_BAD_PC);
19995 }
19996 unsigned size = inst.operands[0].isscalar == 1 ? 64 : 128;
19997
19998 constraint (et.type == NT_invtype, _("bad type for scalar"));
19999 constraint (x >= size / et.size, _("scalar index out of range"));
20000
20001
20002 switch (et.size)
20003 {
20004 case 8: bcdebits = 0x8; break;
20005 case 16: bcdebits = 0x1; break;
20006 case 32: bcdebits = 0x0; break;
20007 default: ;
20008 }
20009
20010 bcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20011
20012 inst.instruction = 0xe000b10;
20013 do_vfp_cond_or_thumb ();
20014 inst.instruction |= LOW4 (dn) << 16;
20015 inst.instruction |= HI1 (dn) << 7;
20016 inst.instruction |= inst.operands[1].reg << 12;
20017 inst.instruction |= (bcdebits & 3) << 5;
20018 inst.instruction |= ((bcdebits >> 2) & 3) << 21;
20019 inst.instruction |= (x >> (3-logsize)) << 16;
20020 }
20021 break;
20022
20023 case NS_DRR: /* case 5 (fmdrr). */
20024 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20025 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20026 _(BAD_FPU));
20027
20028 inst.instruction = 0xc400b10;
20029 do_vfp_cond_or_thumb ();
20030 inst.instruction |= LOW4 (inst.operands[0].reg);
20031 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
20032 inst.instruction |= inst.operands[1].reg << 12;
20033 inst.instruction |= inst.operands[2].reg << 16;
20034 break;
20035
20036 case NS_RS: /* case 6. */
20037 {
20038 unsigned logsize;
20039 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
20040 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
20041 unsigned abcdebits = 0;
20042
20043 /* .<dt> is optional here, defaulting to .32. */
20044 if (inst.vectype.elems == 0
20045 && inst.operands[0].vectype.type == NT_invtype
20046 && inst.operands[1].vectype.type == NT_invtype)
20047 {
20048 inst.vectype.el[0].type = NT_untyped;
20049 inst.vectype.el[0].size = 32;
20050 inst.vectype.elems = 1;
20051 }
20052
20053 et = neon_check_type (2, NS_NULL,
20054 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
20055 logsize = neon_logbits (et.size);
20056
20057 if (et.size != 32)
20058 {
20059 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
20060 && vfp_or_neon_is_neon (NEON_CHECK_CC
20061 | NEON_CHECK_ARCH) == FAIL)
20062 return;
20063 }
20064 else
20065 {
20066 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1)
20067 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20068 _(BAD_FPU));
20069 }
20070
20071 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20072 {
20073 if (inst.operands[0].reg == REG_SP)
20074 as_tsktsk (MVE_BAD_SP);
20075 else if (inst.operands[0].reg == REG_PC)
20076 as_tsktsk (MVE_BAD_PC);
20077 }
20078
20079 unsigned size = inst.operands[1].isscalar == 1 ? 64 : 128;
20080
20081 constraint (et.type == NT_invtype, _("bad type for scalar"));
20082 constraint (x >= size / et.size, _("scalar index out of range"));
20083
20084 switch (et.size)
20085 {
20086 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
20087 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
20088 case 32: abcdebits = 0x00; break;
20089 default: ;
20090 }
20091
20092 abcdebits |= (x & ((1 << (3-logsize)) - 1)) << logsize;
20093 inst.instruction = 0xe100b10;
20094 do_vfp_cond_or_thumb ();
20095 inst.instruction |= LOW4 (dn) << 16;
20096 inst.instruction |= HI1 (dn) << 7;
20097 inst.instruction |= inst.operands[0].reg << 12;
20098 inst.instruction |= (abcdebits & 3) << 5;
20099 inst.instruction |= (abcdebits >> 2) << 21;
20100 inst.instruction |= (x >> (3-logsize)) << 16;
20101 }
20102 break;
20103
20104 case NS_RRD: /* case 7 (fmrrd). */
20105 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20106 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20107 _(BAD_FPU));
20108
20109 inst.instruction = 0xc500b10;
20110 do_vfp_cond_or_thumb ();
20111 inst.instruction |= inst.operands[0].reg << 12;
20112 inst.instruction |= inst.operands[1].reg << 16;
20113 inst.instruction |= LOW4 (inst.operands[2].reg);
20114 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20115 break;
20116
20117 case NS_FF: /* case 8 (fcpys). */
20118 do_vfp_nsyn_opcode ("fcpys");
20119 break;
20120
20121 case NS_HI:
20122 case NS_FI: /* case 10 (fconsts). */
20123 ldconst = "fconsts";
20124 encode_fconstd:
20125 if (!inst.operands[1].immisfloat)
20126 {
20127 unsigned new_imm;
20128 /* Immediate has to fit in 8 bits so float is enough. */
20129 float imm = (float) inst.operands[1].imm;
20130 memcpy (&new_imm, &imm, sizeof (float));
20131 /* But the assembly may have been written to provide an integer
20132 bit pattern that equates to a float, so check that the
20133 conversion has worked. */
20134 if (is_quarter_float (new_imm))
20135 {
20136 if (is_quarter_float (inst.operands[1].imm))
20137 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
20138
20139 inst.operands[1].imm = new_imm;
20140 inst.operands[1].immisfloat = 1;
20141 }
20142 }
20143
20144 if (is_quarter_float (inst.operands[1].imm))
20145 {
20146 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
20147 do_vfp_nsyn_opcode (ldconst);
20148
20149 /* ARMv8.2 fp16 vmov.f16 instruction. */
20150 if (rs == NS_HI)
20151 do_scalar_fp16_v82_encode ();
20152 }
20153 else
20154 first_error (_("immediate out of range"));
20155 break;
20156
20157 case NS_RH:
20158 case NS_RF: /* case 12 (fmrs). */
20159 do_vfp_nsyn_opcode ("fmrs");
20160 /* ARMv8.2 fp16 vmov.f16 instruction. */
20161 if (rs == NS_RH)
20162 do_scalar_fp16_v82_encode ();
20163 break;
20164
20165 case NS_HR:
20166 case NS_FR: /* case 13 (fmsr). */
20167 do_vfp_nsyn_opcode ("fmsr");
20168 /* ARMv8.2 fp16 vmov.f16 instruction. */
20169 if (rs == NS_HR)
20170 do_scalar_fp16_v82_encode ();
20171 break;
20172
20173 case NS_RRSS:
20174 do_mve_mov (0);
20175 break;
20176 case NS_SSRR:
20177 do_mve_mov (1);
20178 break;
20179
20180 /* The encoders for the fmrrs and fmsrr instructions expect three operands
20181 (one of which is a list), but we have parsed four. Do some fiddling to
20182 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
20183 expect. */
20184 case NS_RRFF: /* case 14 (fmrrs). */
20185 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20186 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20187 _(BAD_FPU));
20188 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
20189 _("VFP registers must be adjacent"));
20190 inst.operands[2].imm = 2;
20191 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20192 do_vfp_nsyn_opcode ("fmrrs");
20193 break;
20194
20195 case NS_FFRR: /* case 15 (fmsrr). */
20196 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2)
20197 && !ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext),
20198 _(BAD_FPU));
20199 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
20200 _("VFP registers must be adjacent"));
20201 inst.operands[1] = inst.operands[2];
20202 inst.operands[2] = inst.operands[3];
20203 inst.operands[0].imm = 2;
20204 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
20205 do_vfp_nsyn_opcode ("fmsrr");
20206 break;
20207
20208 case NS_NULL:
20209 /* neon_select_shape has determined that the instruction
20210 shape is wrong and has already set the error message. */
20211 break;
20212
20213 default:
20214 abort ();
20215 }
20216 }
20217
20218 static void
20219 do_mve_movl (void)
20220 {
20221 if (!(inst.operands[0].present && inst.operands[0].isquad
20222 && inst.operands[1].present && inst.operands[1].isquad
20223 && !inst.operands[2].present))
20224 {
20225 inst.instruction = 0;
20226 inst.cond = 0xb;
20227 if (thumb_mode)
20228 set_pred_insn_type (INSIDE_IT_INSN);
20229 do_neon_mov ();
20230 return;
20231 }
20232
20233 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20234 return;
20235
20236 if (inst.cond != COND_ALWAYS)
20237 inst.pred_insn_type = INSIDE_VPT_INSN;
20238
20239 struct neon_type_el et = neon_check_type (2, NS_QQ, N_EQK, N_S8 | N_U8
20240 | N_S16 | N_U16 | N_KEY);
20241
20242 inst.instruction |= (et.type == NT_unsigned) << 28;
20243 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20244 inst.instruction |= (neon_logbits (et.size) + 1) << 19;
20245 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20246 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
20247 inst.instruction |= LOW4 (inst.operands[1].reg);
20248 inst.is_neon = 1;
20249 }
20250
20251 static void
20252 do_neon_rshift_round_imm (void)
20253 {
20254 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20255 return;
20256
20257 enum neon_shape rs;
20258 struct neon_type_el et;
20259
20260 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20261 {
20262 rs = neon_select_shape (NS_QQI, NS_NULL);
20263 et = neon_check_type (2, rs, N_EQK, N_SU_MVE | N_KEY);
20264 }
20265 else
20266 {
20267 rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
20268 et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
20269 }
20270 int imm = inst.operands[2].imm;
20271
20272 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
20273 if (imm == 0)
20274 {
20275 inst.operands[2].present = 0;
20276 do_neon_mov ();
20277 return;
20278 }
20279
20280 constraint (imm < 1 || (unsigned)imm > et.size,
20281 _("immediate out of range for shift"));
20282 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
20283 et.size - imm);
20284 }
20285
20286 static void
20287 do_neon_movhf (void)
20288 {
20289 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
20290 constraint (rs != NS_HH, _("invalid suffix"));
20291
20292 if (inst.cond != COND_ALWAYS)
20293 {
20294 if (thumb_mode)
20295 {
20296 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
20297 " the behaviour is UNPREDICTABLE"));
20298 }
20299 else
20300 {
20301 inst.error = BAD_COND;
20302 return;
20303 }
20304 }
20305
20306 do_vfp_sp_monadic ();
20307
20308 inst.is_neon = 1;
20309 inst.instruction |= 0xf0000000;
20310 }
20311
20312 static void
20313 do_neon_movl (void)
20314 {
20315 struct neon_type_el et = neon_check_type (2, NS_QD,
20316 N_EQK | N_DBL, N_SU_32 | N_KEY);
20317 unsigned sizebits = et.size >> 3;
20318 inst.instruction |= sizebits << 19;
20319 neon_two_same (0, et.type == NT_unsigned, -1);
20320 }
20321
20322 static void
20323 do_neon_trn (void)
20324 {
20325 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20326 struct neon_type_el et = neon_check_type (2, rs,
20327 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20328 NEON_ENCODE (INTEGER, inst);
20329 neon_two_same (neon_quad (rs), 1, et.size);
20330 }
20331
20332 static void
20333 do_neon_zip_uzp (void)
20334 {
20335 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20336 struct neon_type_el et = neon_check_type (2, rs,
20337 N_EQK, N_8 | N_16 | N_32 | N_KEY);
20338 if (rs == NS_DD && et.size == 32)
20339 {
20340 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
20341 inst.instruction = N_MNEM_vtrn;
20342 do_neon_trn ();
20343 return;
20344 }
20345 neon_two_same (neon_quad (rs), 1, et.size);
20346 }
20347
20348 static void
20349 do_neon_sat_abs_neg (void)
20350 {
20351 if (!check_simd_pred_availability (FALSE, NEON_CHECK_CC | NEON_CHECK_ARCH))
20352 return;
20353
20354 enum neon_shape rs;
20355 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20356 rs = neon_select_shape (NS_QQ, NS_NULL);
20357 else
20358 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20359 struct neon_type_el et = neon_check_type (2, rs,
20360 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20361 neon_two_same (neon_quad (rs), 1, et.size);
20362 }
20363
20364 static void
20365 do_neon_pair_long (void)
20366 {
20367 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20368 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
20369 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
20370 inst.instruction |= (et.type == NT_unsigned) << 7;
20371 neon_two_same (neon_quad (rs), 1, et.size);
20372 }
20373
20374 static void
20375 do_neon_recip_est (void)
20376 {
20377 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20378 struct neon_type_el et = neon_check_type (2, rs,
20379 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
20380 inst.instruction |= (et.type == NT_float) << 8;
20381 neon_two_same (neon_quad (rs), 1, et.size);
20382 }
20383
20384 static void
20385 do_neon_cls (void)
20386 {
20387 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20388 return;
20389
20390 enum neon_shape rs;
20391 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20392 rs = neon_select_shape (NS_QQ, NS_NULL);
20393 else
20394 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20395
20396 struct neon_type_el et = neon_check_type (2, rs,
20397 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
20398 neon_two_same (neon_quad (rs), 1, et.size);
20399 }
20400
20401 static void
20402 do_neon_clz (void)
20403 {
20404 if (!check_simd_pred_availability (FALSE, NEON_CHECK_ARCH | NEON_CHECK_CC))
20405 return;
20406
20407 enum neon_shape rs;
20408 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20409 rs = neon_select_shape (NS_QQ, NS_NULL);
20410 else
20411 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20412
20413 struct neon_type_el et = neon_check_type (2, rs,
20414 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
20415 neon_two_same (neon_quad (rs), 1, et.size);
20416 }
20417
20418 static void
20419 do_neon_cnt (void)
20420 {
20421 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20422 struct neon_type_el et = neon_check_type (2, rs,
20423 N_EQK | N_INT, N_8 | N_KEY);
20424 neon_two_same (neon_quad (rs), 1, et.size);
20425 }
20426
20427 static void
20428 do_neon_swp (void)
20429 {
20430 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
20431 neon_two_same (neon_quad (rs), 1, -1);
20432 }
20433
20434 static void
20435 do_neon_tbl_tbx (void)
20436 {
20437 unsigned listlenbits;
20438 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
20439
20440 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
20441 {
20442 first_error (_("bad list length for table lookup"));
20443 return;
20444 }
20445
20446 listlenbits = inst.operands[1].imm - 1;
20447 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20448 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20449 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
20450 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
20451 inst.instruction |= LOW4 (inst.operands[2].reg);
20452 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
20453 inst.instruction |= listlenbits << 8;
20454
20455 neon_dp_fixup (&inst);
20456 }
20457
20458 static void
20459 do_neon_ldm_stm (void)
20460 {
20461 /* P, U and L bits are part of bitmask. */
20462 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
20463 unsigned offsetbits = inst.operands[1].imm * 2;
20464
20465 if (inst.operands[1].issingle)
20466 {
20467 do_vfp_nsyn_ldm_stm (is_dbmode);
20468 return;
20469 }
20470
20471 constraint (is_dbmode && !inst.operands[0].writeback,
20472 _("writeback (!) must be used for VLDMDB and VSTMDB"));
20473
20474 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
20475 _("register list must contain at least 1 and at most 16 "
20476 "registers"));
20477
20478 inst.instruction |= inst.operands[0].reg << 16;
20479 inst.instruction |= inst.operands[0].writeback << 21;
20480 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
20481 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
20482
20483 inst.instruction |= offsetbits;
20484
20485 do_vfp_cond_or_thumb ();
20486 }
20487
20488 static void
20489 do_neon_ldr_str (void)
20490 {
20491 int is_ldr = (inst.instruction & (1 << 20)) != 0;
20492
20493 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
20494 And is UNPREDICTABLE in thumb mode. */
20495 if (!is_ldr
20496 && inst.operands[1].reg == REG_PC
20497 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
20498 {
20499 if (thumb_mode)
20500 inst.error = _("Use of PC here is UNPREDICTABLE");
20501 else if (warn_on_deprecated)
20502 as_tsktsk (_("Use of PC here is deprecated"));
20503 }
20504
20505 if (inst.operands[0].issingle)
20506 {
20507 if (is_ldr)
20508 do_vfp_nsyn_opcode ("flds");
20509 else
20510 do_vfp_nsyn_opcode ("fsts");
20511
20512 /* ARMv8.2 vldr.16/vstr.16 instruction. */
20513 if (inst.vectype.el[0].size == 16)
20514 do_scalar_fp16_v82_encode ();
20515 }
20516 else
20517 {
20518 if (is_ldr)
20519 do_vfp_nsyn_opcode ("fldd");
20520 else
20521 do_vfp_nsyn_opcode ("fstd");
20522 }
20523 }
20524
20525 static void
20526 do_t_vldr_vstr_sysreg (void)
20527 {
20528 int fp_vldr_bitno = 20, sysreg_vldr_bitno = 20;
20529 bfd_boolean is_vldr = ((inst.instruction & (1 << fp_vldr_bitno)) != 0);
20530
20531 /* Use of PC is UNPREDICTABLE. */
20532 if (inst.operands[1].reg == REG_PC)
20533 inst.error = _("Use of PC here is UNPREDICTABLE");
20534
20535 if (inst.operands[1].immisreg)
20536 inst.error = _("instruction does not accept register index");
20537
20538 if (!inst.operands[1].isreg)
20539 inst.error = _("instruction does not accept PC-relative addressing");
20540
20541 if (abs (inst.operands[1].imm) >= (1 << 7))
20542 inst.error = _("immediate value out of range");
20543
20544 inst.instruction = 0xec000f80;
20545 if (is_vldr)
20546 inst.instruction |= 1 << sysreg_vldr_bitno;
20547 encode_arm_cp_address (1, TRUE, FALSE, BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM);
20548 inst.instruction |= (inst.operands[0].imm & 0x7) << 13;
20549 inst.instruction |= (inst.operands[0].imm & 0x8) << 19;
20550 }
20551
20552 static void
20553 do_vldr_vstr (void)
20554 {
20555 bfd_boolean sysreg_op = !inst.operands[0].isreg;
20556
20557 /* VLDR/VSTR (System Register). */
20558 if (sysreg_op)
20559 {
20560 if (!mark_feature_used (&arm_ext_v8_1m_main))
20561 as_bad (_("Instruction not permitted on this architecture"));
20562
20563 do_t_vldr_vstr_sysreg ();
20564 }
20565 /* VLDR/VSTR. */
20566 else
20567 {
20568 if (!mark_feature_used (&fpu_vfp_ext_v1xd))
20569 as_bad (_("Instruction not permitted on this architecture"));
20570 do_neon_ldr_str ();
20571 }
20572 }
20573
20574 /* "interleave" version also handles non-interleaving register VLD1/VST1
20575 instructions. */
20576
20577 static void
20578 do_neon_ld_st_interleave (void)
20579 {
20580 struct neon_type_el et = neon_check_type (1, NS_NULL,
20581 N_8 | N_16 | N_32 | N_64);
20582 unsigned alignbits = 0;
20583 unsigned idx;
20584 /* The bits in this table go:
20585 0: register stride of one (0) or two (1)
20586 1,2: register list length, minus one (1, 2, 3, 4).
20587 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
20588 We use -1 for invalid entries. */
20589 const int typetable[] =
20590 {
20591 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
20592 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
20593 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
20594 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
20595 };
20596 int typebits;
20597
20598 if (et.type == NT_invtype)
20599 return;
20600
20601 if (inst.operands[1].immisalign)
20602 switch (inst.operands[1].imm >> 8)
20603 {
20604 case 64: alignbits = 1; break;
20605 case 128:
20606 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
20607 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20608 goto bad_alignment;
20609 alignbits = 2;
20610 break;
20611 case 256:
20612 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
20613 goto bad_alignment;
20614 alignbits = 3;
20615 break;
20616 default:
20617 bad_alignment:
20618 first_error (_("bad alignment"));
20619 return;
20620 }
20621
20622 inst.instruction |= alignbits << 4;
20623 inst.instruction |= neon_logbits (et.size) << 6;
20624
20625 /* Bits [4:6] of the immediate in a list specifier encode register stride
20626 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
20627 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
20628 up the right value for "type" in a table based on this value and the given
20629 list style, then stick it back. */
20630 idx = ((inst.operands[0].imm >> 4) & 7)
20631 | (((inst.instruction >> 8) & 3) << 3);
20632
20633 typebits = typetable[idx];
20634
20635 constraint (typebits == -1, _("bad list type for instruction"));
20636 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
20637 BAD_EL_TYPE);
20638
20639 inst.instruction &= ~0xf00;
20640 inst.instruction |= typebits << 8;
20641 }
20642
20643 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
20644 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
20645 otherwise. The variable arguments are a list of pairs of legal (size, align)
20646 values, terminated with -1. */
20647
20648 static int
20649 neon_alignment_bit (int size, int align, int *do_alignment, ...)
20650 {
20651 va_list ap;
20652 int result = FAIL, thissize, thisalign;
20653
20654 if (!inst.operands[1].immisalign)
20655 {
20656 *do_alignment = 0;
20657 return SUCCESS;
20658 }
20659
20660 va_start (ap, do_alignment);
20661
20662 do
20663 {
20664 thissize = va_arg (ap, int);
20665 if (thissize == -1)
20666 break;
20667 thisalign = va_arg (ap, int);
20668
20669 if (size == thissize && align == thisalign)
20670 result = SUCCESS;
20671 }
20672 while (result != SUCCESS);
20673
20674 va_end (ap);
20675
20676 if (result == SUCCESS)
20677 *do_alignment = 1;
20678 else
20679 first_error (_("unsupported alignment for instruction"));
20680
20681 return result;
20682 }
20683
20684 static void
20685 do_neon_ld_st_lane (void)
20686 {
20687 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
20688 int align_good, do_alignment = 0;
20689 int logsize = neon_logbits (et.size);
20690 int align = inst.operands[1].imm >> 8;
20691 int n = (inst.instruction >> 8) & 3;
20692 int max_el = 64 / et.size;
20693
20694 if (et.type == NT_invtype)
20695 return;
20696
20697 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
20698 _("bad list length"));
20699 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
20700 _("scalar index out of range"));
20701 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
20702 && et.size == 8,
20703 _("stride of 2 unavailable when element size is 8"));
20704
20705 switch (n)
20706 {
20707 case 0: /* VLD1 / VST1. */
20708 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
20709 32, 32, -1);
20710 if (align_good == FAIL)
20711 return;
20712 if (do_alignment)
20713 {
20714 unsigned alignbits = 0;
20715 switch (et.size)
20716 {
20717 case 16: alignbits = 0x1; break;
20718 case 32: alignbits = 0x3; break;
20719 default: ;
20720 }
20721 inst.instruction |= alignbits << 4;
20722 }
20723 break;
20724
20725 case 1: /* VLD2 / VST2. */
20726 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
20727 16, 32, 32, 64, -1);
20728 if (align_good == FAIL)
20729 return;
20730 if (do_alignment)
20731 inst.instruction |= 1 << 4;
20732 break;
20733
20734 case 2: /* VLD3 / VST3. */
20735 constraint (inst.operands[1].immisalign,
20736 _("can't use alignment with this instruction"));
20737 break;
20738
20739 case 3: /* VLD4 / VST4. */
20740 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
20741 16, 64, 32, 64, 32, 128, -1);
20742 if (align_good == FAIL)
20743 return;
20744 if (do_alignment)
20745 {
20746 unsigned alignbits = 0;
20747 switch (et.size)
20748 {
20749 case 8: alignbits = 0x1; break;
20750 case 16: alignbits = 0x1; break;
20751 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
20752 default: ;
20753 }
20754 inst.instruction |= alignbits << 4;
20755 }
20756 break;
20757
20758 default: ;
20759 }
20760
20761 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
20762 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20763 inst.instruction |= 1 << (4 + logsize);
20764
20765 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
20766 inst.instruction |= logsize << 10;
20767 }
20768
20769 /* Encode single n-element structure to all lanes VLD<n> instructions. */
20770
20771 static void
20772 do_neon_ld_dup (void)
20773 {
20774 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
20775 int align_good, do_alignment = 0;
20776
20777 if (et.type == NT_invtype)
20778 return;
20779
20780 switch ((inst.instruction >> 8) & 3)
20781 {
20782 case 0: /* VLD1. */
20783 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
20784 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
20785 &do_alignment, 16, 16, 32, 32, -1);
20786 if (align_good == FAIL)
20787 return;
20788 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
20789 {
20790 case 1: break;
20791 case 2: inst.instruction |= 1 << 5; break;
20792 default: first_error (_("bad list length")); return;
20793 }
20794 inst.instruction |= neon_logbits (et.size) << 6;
20795 break;
20796
20797 case 1: /* VLD2. */
20798 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
20799 &do_alignment, 8, 16, 16, 32, 32, 64,
20800 -1);
20801 if (align_good == FAIL)
20802 return;
20803 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
20804 _("bad list length"));
20805 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20806 inst.instruction |= 1 << 5;
20807 inst.instruction |= neon_logbits (et.size) << 6;
20808 break;
20809
20810 case 2: /* VLD3. */
20811 constraint (inst.operands[1].immisalign,
20812 _("can't use alignment with this instruction"));
20813 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
20814 _("bad list length"));
20815 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20816 inst.instruction |= 1 << 5;
20817 inst.instruction |= neon_logbits (et.size) << 6;
20818 break;
20819
20820 case 3: /* VLD4. */
20821 {
20822 int align = inst.operands[1].imm >> 8;
20823 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
20824 16, 64, 32, 64, 32, 128, -1);
20825 if (align_good == FAIL)
20826 return;
20827 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
20828 _("bad list length"));
20829 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
20830 inst.instruction |= 1 << 5;
20831 if (et.size == 32 && align == 128)
20832 inst.instruction |= 0x3 << 6;
20833 else
20834 inst.instruction |= neon_logbits (et.size) << 6;
20835 }
20836 break;
20837
20838 default: ;
20839 }
20840
20841 inst.instruction |= do_alignment << 4;
20842 }
20843
20844 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
20845 apart from bits [11:4]. */
20846
20847 static void
20848 do_neon_ldx_stx (void)
20849 {
20850 if (inst.operands[1].isreg)
20851 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
20852
20853 switch (NEON_LANE (inst.operands[0].imm))
20854 {
20855 case NEON_INTERLEAVE_LANES:
20856 NEON_ENCODE (INTERLV, inst);
20857 do_neon_ld_st_interleave ();
20858 break;
20859
20860 case NEON_ALL_LANES:
20861 NEON_ENCODE (DUP, inst);
20862 if (inst.instruction == N_INV)
20863 {
20864 first_error ("only loads support such operands");
20865 break;
20866 }
20867 do_neon_ld_dup ();
20868 break;
20869
20870 default:
20871 NEON_ENCODE (LANE, inst);
20872 do_neon_ld_st_lane ();
20873 }
20874
20875 /* L bit comes from bit mask. */
20876 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
20877 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
20878 inst.instruction |= inst.operands[1].reg << 16;
20879
20880 if (inst.operands[1].postind)
20881 {
20882 int postreg = inst.operands[1].imm & 0xf;
20883 constraint (!inst.operands[1].immisreg,
20884 _("post-index must be a register"));
20885 constraint (postreg == 0xd || postreg == 0xf,
20886 _("bad register for post-index"));
20887 inst.instruction |= postreg;
20888 }
20889 else
20890 {
20891 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
20892 constraint (inst.relocs[0].exp.X_op != O_constant
20893 || inst.relocs[0].exp.X_add_number != 0,
20894 BAD_ADDR_MODE);
20895
20896 if (inst.operands[1].writeback)
20897 {
20898 inst.instruction |= 0xd;
20899 }
20900 else
20901 inst.instruction |= 0xf;
20902 }
20903
20904 if (thumb_mode)
20905 inst.instruction |= 0xf9000000;
20906 else
20907 inst.instruction |= 0xf4000000;
20908 }
20909
20910 /* FP v8. */
20911 static void
20912 do_vfp_nsyn_fpv8 (enum neon_shape rs)
20913 {
20914 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
20915 D register operands. */
20916 if (neon_shape_class[rs] == SC_DOUBLE)
20917 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
20918 _(BAD_FPU));
20919
20920 NEON_ENCODE (FPV8, inst);
20921
20922 if (rs == NS_FFF || rs == NS_HHH)
20923 {
20924 do_vfp_sp_dyadic ();
20925
20926 /* ARMv8.2 fp16 instruction. */
20927 if (rs == NS_HHH)
20928 do_scalar_fp16_v82_encode ();
20929 }
20930 else
20931 do_vfp_dp_rd_rn_rm ();
20932
20933 if (rs == NS_DDD)
20934 inst.instruction |= 0x100;
20935
20936 inst.instruction |= 0xf0000000;
20937 }
20938
20939 static void
20940 do_vsel (void)
20941 {
20942 set_pred_insn_type (OUTSIDE_PRED_INSN);
20943
20944 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
20945 first_error (_("invalid instruction shape"));
20946 }
20947
20948 static void
20949 do_vmaxnm (void)
20950 {
20951 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
20952 set_pred_insn_type (OUTSIDE_PRED_INSN);
20953
20954 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
20955 return;
20956
20957 if (!check_simd_pred_availability (TRUE, NEON_CHECK_CC | NEON_CHECK_ARCH8))
20958 return;
20959
20960 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
20961 }
20962
20963 static void
20964 do_vrint_1 (enum neon_cvt_mode mode)
20965 {
20966 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
20967 struct neon_type_el et;
20968
20969 if (rs == NS_NULL)
20970 return;
20971
20972 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
20973 D register operands. */
20974 if (neon_shape_class[rs] == SC_DOUBLE)
20975 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
20976 _(BAD_FPU));
20977
20978 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
20979 | N_VFP);
20980 if (et.type != NT_invtype)
20981 {
20982 /* VFP encodings. */
20983 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
20984 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
20985 set_pred_insn_type (OUTSIDE_PRED_INSN);
20986
20987 NEON_ENCODE (FPV8, inst);
20988 if (rs == NS_FF || rs == NS_HH)
20989 do_vfp_sp_monadic ();
20990 else
20991 do_vfp_dp_rd_rm ();
20992
20993 switch (mode)
20994 {
20995 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
20996 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
20997 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
20998 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
20999 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
21000 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
21001 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
21002 default: abort ();
21003 }
21004
21005 inst.instruction |= (rs == NS_DD) << 8;
21006 do_vfp_cond_or_thumb ();
21007
21008 /* ARMv8.2 fp16 vrint instruction. */
21009 if (rs == NS_HH)
21010 do_scalar_fp16_v82_encode ();
21011 }
21012 else
21013 {
21014 /* Neon encodings (or something broken...). */
21015 inst.error = NULL;
21016 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
21017
21018 if (et.type == NT_invtype)
21019 return;
21020
21021 if (!check_simd_pred_availability (TRUE,
21022 NEON_CHECK_CC | NEON_CHECK_ARCH8))
21023 return;
21024
21025 NEON_ENCODE (FLOAT, inst);
21026
21027 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21028 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21029 inst.instruction |= LOW4 (inst.operands[1].reg);
21030 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21031 inst.instruction |= neon_quad (rs) << 6;
21032 /* Mask off the original size bits and reencode them. */
21033 inst.instruction = ((inst.instruction & 0xfff3ffff)
21034 | neon_logbits (et.size) << 18);
21035
21036 switch (mode)
21037 {
21038 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
21039 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
21040 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
21041 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
21042 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
21043 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
21044 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
21045 default: abort ();
21046 }
21047
21048 if (thumb_mode)
21049 inst.instruction |= 0xfc000000;
21050 else
21051 inst.instruction |= 0xf0000000;
21052 }
21053 }
21054
21055 static void
21056 do_vrintx (void)
21057 {
21058 do_vrint_1 (neon_cvt_mode_x);
21059 }
21060
21061 static void
21062 do_vrintz (void)
21063 {
21064 do_vrint_1 (neon_cvt_mode_z);
21065 }
21066
21067 static void
21068 do_vrintr (void)
21069 {
21070 do_vrint_1 (neon_cvt_mode_r);
21071 }
21072
21073 static void
21074 do_vrinta (void)
21075 {
21076 do_vrint_1 (neon_cvt_mode_a);
21077 }
21078
21079 static void
21080 do_vrintn (void)
21081 {
21082 do_vrint_1 (neon_cvt_mode_n);
21083 }
21084
21085 static void
21086 do_vrintp (void)
21087 {
21088 do_vrint_1 (neon_cvt_mode_p);
21089 }
21090
21091 static void
21092 do_vrintm (void)
21093 {
21094 do_vrint_1 (neon_cvt_mode_m);
21095 }
21096
21097 static unsigned
21098 neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
21099 {
21100 unsigned regno = NEON_SCALAR_REG (opnd);
21101 unsigned elno = NEON_SCALAR_INDEX (opnd);
21102
21103 if (elsize == 16 && elno < 2 && regno < 16)
21104 return regno | (elno << 4);
21105 else if (elsize == 32 && elno == 0)
21106 return regno;
21107
21108 first_error (_("scalar out of range"));
21109 return 0;
21110 }
21111
21112 static void
21113 do_vcmla (void)
21114 {
21115 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext)
21116 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21117 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21118 constraint (inst.relocs[0].exp.X_op != O_constant,
21119 _("expression too complex"));
21120 unsigned rot = inst.relocs[0].exp.X_add_number;
21121 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
21122 _("immediate out of range"));
21123 rot /= 90;
21124
21125 if (!check_simd_pred_availability (TRUE,
21126 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21127 return;
21128
21129 if (inst.operands[2].isscalar)
21130 {
21131 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21132 first_error (_("invalid instruction shape"));
21133 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
21134 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21135 N_KEY | N_F16 | N_F32).size;
21136 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
21137 inst.is_neon = 1;
21138 inst.instruction = 0xfe000800;
21139 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21140 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21141 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21142 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21143 inst.instruction |= LOW4 (m);
21144 inst.instruction |= HI1 (m) << 5;
21145 inst.instruction |= neon_quad (rs) << 6;
21146 inst.instruction |= rot << 20;
21147 inst.instruction |= (size == 32) << 23;
21148 }
21149 else
21150 {
21151 enum neon_shape rs;
21152 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext))
21153 rs = neon_select_shape (NS_QQQI, NS_NULL);
21154 else
21155 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21156
21157 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
21158 N_KEY | N_F16 | N_F32).size;
21159 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_fp_ext) && size == 32
21160 && (inst.operands[0].reg == inst.operands[1].reg
21161 || inst.operands[0].reg == inst.operands[2].reg))
21162 as_tsktsk (BAD_MVE_SRCDEST);
21163
21164 neon_three_same (neon_quad (rs), 0, -1);
21165 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21166 inst.instruction |= 0xfc200800;
21167 inst.instruction |= rot << 23;
21168 inst.instruction |= (size == 32) << 20;
21169 }
21170 }
21171
21172 static void
21173 do_vcadd (void)
21174 {
21175 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext)
21176 && (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8)
21177 || !mark_feature_used (&arm_ext_v8_3)), (BAD_FPU));
21178 constraint (inst.relocs[0].exp.X_op != O_constant,
21179 _("expression too complex"));
21180
21181 unsigned rot = inst.relocs[0].exp.X_add_number;
21182 constraint (rot != 90 && rot != 270, _("immediate out of range"));
21183 enum neon_shape rs;
21184 struct neon_type_el et;
21185 if (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21186 {
21187 rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
21188 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32);
21189 }
21190 else
21191 {
21192 rs = neon_select_shape (NS_QQQI, NS_NULL);
21193 et = neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16 | N_F32 | N_I8
21194 | N_I16 | N_I32);
21195 if (et.size == 32 && inst.operands[0].reg == inst.operands[2].reg)
21196 as_tsktsk (_("Warning: 32-bit element size and same first and third "
21197 "operand makes instruction UNPREDICTABLE"));
21198 }
21199
21200 if (et.type == NT_invtype)
21201 return;
21202
21203 if (!check_simd_pred_availability (et.type == NT_float,
21204 NEON_CHECK_ARCH8 | NEON_CHECK_CC))
21205 return;
21206
21207 if (et.type == NT_float)
21208 {
21209 neon_three_same (neon_quad (rs), 0, -1);
21210 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
21211 inst.instruction |= 0xfc800800;
21212 inst.instruction |= (rot == 270) << 24;
21213 inst.instruction |= (et.size == 32) << 20;
21214 }
21215 else
21216 {
21217 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext), BAD_FPU);
21218 inst.instruction = 0xfe000f00;
21219 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21220 inst.instruction |= neon_logbits (et.size) << 20;
21221 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
21222 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21223 inst.instruction |= (rot == 270) << 12;
21224 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
21225 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
21226 inst.instruction |= LOW4 (inst.operands[2].reg);
21227 inst.is_neon = 1;
21228 }
21229 }
21230
21231 /* Dot Product instructions encoding support. */
21232
21233 static void
21234 do_neon_dotproduct (int unsigned_p)
21235 {
21236 enum neon_shape rs;
21237 unsigned scalar_oprd2 = 0;
21238 int high8;
21239
21240 if (inst.cond != COND_ALWAYS)
21241 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
21242 "is UNPREDICTABLE"));
21243
21244 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
21245 _(BAD_FPU));
21246
21247 /* Dot Product instructions are in three-same D/Q register format or the third
21248 operand can be a scalar index register. */
21249 if (inst.operands[2].isscalar)
21250 {
21251 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
21252 high8 = 0xfe000000;
21253 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
21254 }
21255 else
21256 {
21257 high8 = 0xfc000000;
21258 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
21259 }
21260
21261 if (unsigned_p)
21262 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
21263 else
21264 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
21265
21266 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
21267 Product instruction, so we pass 0 as the "ubit" parameter. And the
21268 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
21269 neon_three_same (neon_quad (rs), 0, 32);
21270
21271 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
21272 different NEON three-same encoding. */
21273 inst.instruction &= 0x00ffffff;
21274 inst.instruction |= high8;
21275 /* Encode 'U' bit which indicates signedness. */
21276 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
21277 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
21278 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
21279 the instruction encoding. */
21280 if (inst.operands[2].isscalar)
21281 {
21282 inst.instruction &= 0xffffffd0;
21283 inst.instruction |= LOW4 (scalar_oprd2);
21284 inst.instruction |= HI1 (scalar_oprd2) << 5;
21285 }
21286 }
21287
21288 /* Dot Product instructions for signed integer. */
21289
21290 static void
21291 do_neon_dotproduct_s (void)
21292 {
21293 return do_neon_dotproduct (0);
21294 }
21295
21296 /* Dot Product instructions for unsigned integer. */
21297
21298 static void
21299 do_neon_dotproduct_u (void)
21300 {
21301 return do_neon_dotproduct (1);
21302 }
21303
21304 /* Crypto v1 instructions. */
21305 static void
21306 do_crypto_2op_1 (unsigned elttype, int op)
21307 {
21308 set_pred_insn_type (OUTSIDE_PRED_INSN);
21309
21310 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
21311 == NT_invtype)
21312 return;
21313
21314 inst.error = NULL;
21315
21316 NEON_ENCODE (INTEGER, inst);
21317 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
21318 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
21319 inst.instruction |= LOW4 (inst.operands[1].reg);
21320 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
21321 if (op != -1)
21322 inst.instruction |= op << 6;
21323
21324 if (thumb_mode)
21325 inst.instruction |= 0xfc000000;
21326 else
21327 inst.instruction |= 0xf0000000;
21328 }
21329
21330 static void
21331 do_crypto_3op_1 (int u, int op)
21332 {
21333 set_pred_insn_type (OUTSIDE_PRED_INSN);
21334
21335 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
21336 N_32 | N_UNT | N_KEY).type == NT_invtype)
21337 return;
21338
21339 inst.error = NULL;
21340
21341 NEON_ENCODE (INTEGER, inst);
21342 neon_three_same (1, u, 8 << op);
21343 }
21344
21345 static void
21346 do_aese (void)
21347 {
21348 do_crypto_2op_1 (N_8, 0);
21349 }
21350
21351 static void
21352 do_aesd (void)
21353 {
21354 do_crypto_2op_1 (N_8, 1);
21355 }
21356
21357 static void
21358 do_aesmc (void)
21359 {
21360 do_crypto_2op_1 (N_8, 2);
21361 }
21362
21363 static void
21364 do_aesimc (void)
21365 {
21366 do_crypto_2op_1 (N_8, 3);
21367 }
21368
21369 static void
21370 do_sha1c (void)
21371 {
21372 do_crypto_3op_1 (0, 0);
21373 }
21374
21375 static void
21376 do_sha1p (void)
21377 {
21378 do_crypto_3op_1 (0, 1);
21379 }
21380
21381 static void
21382 do_sha1m (void)
21383 {
21384 do_crypto_3op_1 (0, 2);
21385 }
21386
21387 static void
21388 do_sha1su0 (void)
21389 {
21390 do_crypto_3op_1 (0, 3);
21391 }
21392
21393 static void
21394 do_sha256h (void)
21395 {
21396 do_crypto_3op_1 (1, 0);
21397 }
21398
21399 static void
21400 do_sha256h2 (void)
21401 {
21402 do_crypto_3op_1 (1, 1);
21403 }
21404
21405 static void
21406 do_sha256su1 (void)
21407 {
21408 do_crypto_3op_1 (1, 2);
21409 }
21410
21411 static void
21412 do_sha1h (void)
21413 {
21414 do_crypto_2op_1 (N_32, -1);
21415 }
21416
21417 static void
21418 do_sha1su1 (void)
21419 {
21420 do_crypto_2op_1 (N_32, 0);
21421 }
21422
21423 static void
21424 do_sha256su0 (void)
21425 {
21426 do_crypto_2op_1 (N_32, 1);
21427 }
21428
21429 static void
21430 do_crc32_1 (unsigned int poly, unsigned int sz)
21431 {
21432 unsigned int Rd = inst.operands[0].reg;
21433 unsigned int Rn = inst.operands[1].reg;
21434 unsigned int Rm = inst.operands[2].reg;
21435
21436 set_pred_insn_type (OUTSIDE_PRED_INSN);
21437 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
21438 inst.instruction |= LOW4 (Rn) << 16;
21439 inst.instruction |= LOW4 (Rm);
21440 inst.instruction |= sz << (thumb_mode ? 4 : 21);
21441 inst.instruction |= poly << (thumb_mode ? 20 : 9);
21442
21443 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
21444 as_warn (UNPRED_REG ("r15"));
21445 }
21446
21447 static void
21448 do_crc32b (void)
21449 {
21450 do_crc32_1 (0, 0);
21451 }
21452
21453 static void
21454 do_crc32h (void)
21455 {
21456 do_crc32_1 (0, 1);
21457 }
21458
21459 static void
21460 do_crc32w (void)
21461 {
21462 do_crc32_1 (0, 2);
21463 }
21464
21465 static void
21466 do_crc32cb (void)
21467 {
21468 do_crc32_1 (1, 0);
21469 }
21470
21471 static void
21472 do_crc32ch (void)
21473 {
21474 do_crc32_1 (1, 1);
21475 }
21476
21477 static void
21478 do_crc32cw (void)
21479 {
21480 do_crc32_1 (1, 2);
21481 }
21482
21483 static void
21484 do_vjcvt (void)
21485 {
21486 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
21487 _(BAD_FPU));
21488 neon_check_type (2, NS_FD, N_S32, N_F64);
21489 do_vfp_sp_dp_cvt ();
21490 do_vfp_cond_or_thumb ();
21491 }
21492
21493 \f
21494 /* Overall per-instruction processing. */
21495
21496 /* We need to be able to fix up arbitrary expressions in some statements.
21497 This is so that we can handle symbols that are an arbitrary distance from
21498 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
21499 which returns part of an address in a form which will be valid for
21500 a data instruction. We do this by pushing the expression into a symbol
21501 in the expr_section, and creating a fix for that. */
21502
21503 static void
21504 fix_new_arm (fragS * frag,
21505 int where,
21506 short int size,
21507 expressionS * exp,
21508 int pc_rel,
21509 int reloc)
21510 {
21511 fixS * new_fix;
21512
21513 switch (exp->X_op)
21514 {
21515 case O_constant:
21516 if (pc_rel)
21517 {
21518 /* Create an absolute valued symbol, so we have something to
21519 refer to in the object file. Unfortunately for us, gas's
21520 generic expression parsing will already have folded out
21521 any use of .set foo/.type foo %function that may have
21522 been used to set type information of the target location,
21523 that's being specified symbolically. We have to presume
21524 the user knows what they are doing. */
21525 char name[16 + 8];
21526 symbolS *symbol;
21527
21528 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
21529
21530 symbol = symbol_find_or_make (name);
21531 S_SET_SEGMENT (symbol, absolute_section);
21532 symbol_set_frag (symbol, &zero_address_frag);
21533 S_SET_VALUE (symbol, exp->X_add_number);
21534 exp->X_op = O_symbol;
21535 exp->X_add_symbol = symbol;
21536 exp->X_add_number = 0;
21537 }
21538 /* FALLTHROUGH */
21539 case O_symbol:
21540 case O_add:
21541 case O_subtract:
21542 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
21543 (enum bfd_reloc_code_real) reloc);
21544 break;
21545
21546 default:
21547 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
21548 pc_rel, (enum bfd_reloc_code_real) reloc);
21549 break;
21550 }
21551
21552 /* Mark whether the fix is to a THUMB instruction, or an ARM
21553 instruction. */
21554 new_fix->tc_fix_data = thumb_mode;
21555 }
21556
21557 /* Create a frg for an instruction requiring relaxation. */
21558 static void
21559 output_relax_insn (void)
21560 {
21561 char * to;
21562 symbolS *sym;
21563 int offset;
21564
21565 /* The size of the instruction is unknown, so tie the debug info to the
21566 start of the instruction. */
21567 dwarf2_emit_insn (0);
21568
21569 switch (inst.relocs[0].exp.X_op)
21570 {
21571 case O_symbol:
21572 sym = inst.relocs[0].exp.X_add_symbol;
21573 offset = inst.relocs[0].exp.X_add_number;
21574 break;
21575 case O_constant:
21576 sym = NULL;
21577 offset = inst.relocs[0].exp.X_add_number;
21578 break;
21579 default:
21580 sym = make_expr_symbol (&inst.relocs[0].exp);
21581 offset = 0;
21582 break;
21583 }
21584 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
21585 inst.relax, sym, offset, NULL/*offset, opcode*/);
21586 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
21587 }
21588
21589 /* Write a 32-bit thumb instruction to buf. */
21590 static void
21591 put_thumb32_insn (char * buf, unsigned long insn)
21592 {
21593 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
21594 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
21595 }
21596
21597 static void
21598 output_inst (const char * str)
21599 {
21600 char * to = NULL;
21601
21602 if (inst.error)
21603 {
21604 as_bad ("%s -- `%s'", inst.error, str);
21605 return;
21606 }
21607 if (inst.relax)
21608 {
21609 output_relax_insn ();
21610 return;
21611 }
21612 if (inst.size == 0)
21613 return;
21614
21615 to = frag_more (inst.size);
21616 /* PR 9814: Record the thumb mode into the current frag so that we know
21617 what type of NOP padding to use, if necessary. We override any previous
21618 setting so that if the mode has changed then the NOPS that we use will
21619 match the encoding of the last instruction in the frag. */
21620 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
21621
21622 if (thumb_mode && (inst.size > THUMB_SIZE))
21623 {
21624 gas_assert (inst.size == (2 * THUMB_SIZE));
21625 put_thumb32_insn (to, inst.instruction);
21626 }
21627 else if (inst.size > INSN_SIZE)
21628 {
21629 gas_assert (inst.size == (2 * INSN_SIZE));
21630 md_number_to_chars (to, inst.instruction, INSN_SIZE);
21631 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
21632 }
21633 else
21634 md_number_to_chars (to, inst.instruction, inst.size);
21635
21636 int r;
21637 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
21638 {
21639 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
21640 fix_new_arm (frag_now, to - frag_now->fr_literal,
21641 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
21642 inst.relocs[r].type);
21643 }
21644
21645 dwarf2_emit_insn (inst.size);
21646 }
21647
21648 static char *
21649 output_it_inst (int cond, int mask, char * to)
21650 {
21651 unsigned long instruction = 0xbf00;
21652
21653 mask &= 0xf;
21654 instruction |= mask;
21655 instruction |= cond << 4;
21656
21657 if (to == NULL)
21658 {
21659 to = frag_more (2);
21660 #ifdef OBJ_ELF
21661 dwarf2_emit_insn (2);
21662 #endif
21663 }
21664
21665 md_number_to_chars (to, instruction, 2);
21666
21667 return to;
21668 }
21669
21670 /* Tag values used in struct asm_opcode's tag field. */
21671 enum opcode_tag
21672 {
21673 OT_unconditional, /* Instruction cannot be conditionalized.
21674 The ARM condition field is still 0xE. */
21675 OT_unconditionalF, /* Instruction cannot be conditionalized
21676 and carries 0xF in its ARM condition field. */
21677 OT_csuffix, /* Instruction takes a conditional suffix. */
21678 OT_csuffixF, /* Some forms of the instruction take a scalar
21679 conditional suffix, others place 0xF where the
21680 condition field would be, others take a vector
21681 conditional suffix. */
21682 OT_cinfix3, /* Instruction takes a conditional infix,
21683 beginning at character index 3. (In
21684 unified mode, it becomes a suffix.) */
21685 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
21686 tsts, cmps, cmns, and teqs. */
21687 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
21688 character index 3, even in unified mode. Used for
21689 legacy instructions where suffix and infix forms
21690 may be ambiguous. */
21691 OT_csuf_or_in3, /* Instruction takes either a conditional
21692 suffix or an infix at character index 3. */
21693 OT_odd_infix_unc, /* This is the unconditional variant of an
21694 instruction that takes a conditional infix
21695 at an unusual position. In unified mode,
21696 this variant will accept a suffix. */
21697 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
21698 are the conditional variants of instructions that
21699 take conditional infixes in unusual positions.
21700 The infix appears at character index
21701 (tag - OT_odd_infix_0). These are not accepted
21702 in unified mode. */
21703 };
21704
21705 /* Subroutine of md_assemble, responsible for looking up the primary
21706 opcode from the mnemonic the user wrote. STR points to the
21707 beginning of the mnemonic.
21708
21709 This is not simply a hash table lookup, because of conditional
21710 variants. Most instructions have conditional variants, which are
21711 expressed with a _conditional affix_ to the mnemonic. If we were
21712 to encode each conditional variant as a literal string in the opcode
21713 table, it would have approximately 20,000 entries.
21714
21715 Most mnemonics take this affix as a suffix, and in unified syntax,
21716 'most' is upgraded to 'all'. However, in the divided syntax, some
21717 instructions take the affix as an infix, notably the s-variants of
21718 the arithmetic instructions. Of those instructions, all but six
21719 have the infix appear after the third character of the mnemonic.
21720
21721 Accordingly, the algorithm for looking up primary opcodes given
21722 an identifier is:
21723
21724 1. Look up the identifier in the opcode table.
21725 If we find a match, go to step U.
21726
21727 2. Look up the last two characters of the identifier in the
21728 conditions table. If we find a match, look up the first N-2
21729 characters of the identifier in the opcode table. If we
21730 find a match, go to step CE.
21731
21732 3. Look up the fourth and fifth characters of the identifier in
21733 the conditions table. If we find a match, extract those
21734 characters from the identifier, and look up the remaining
21735 characters in the opcode table. If we find a match, go
21736 to step CM.
21737
21738 4. Fail.
21739
21740 U. Examine the tag field of the opcode structure, in case this is
21741 one of the six instructions with its conditional infix in an
21742 unusual place. If it is, the tag tells us where to find the
21743 infix; look it up in the conditions table and set inst.cond
21744 accordingly. Otherwise, this is an unconditional instruction.
21745 Again set inst.cond accordingly. Return the opcode structure.
21746
21747 CE. Examine the tag field to make sure this is an instruction that
21748 should receive a conditional suffix. If it is not, fail.
21749 Otherwise, set inst.cond from the suffix we already looked up,
21750 and return the opcode structure.
21751
21752 CM. Examine the tag field to make sure this is an instruction that
21753 should receive a conditional infix after the third character.
21754 If it is not, fail. Otherwise, undo the edits to the current
21755 line of input and proceed as for case CE. */
21756
21757 static const struct asm_opcode *
21758 opcode_lookup (char **str)
21759 {
21760 char *end, *base;
21761 char *affix;
21762 const struct asm_opcode *opcode;
21763 const struct asm_cond *cond;
21764 char save[2];
21765
21766 /* Scan up to the end of the mnemonic, which must end in white space,
21767 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
21768 for (base = end = *str; *end != '\0'; end++)
21769 if (*end == ' ' || *end == '.')
21770 break;
21771
21772 if (end == base)
21773 return NULL;
21774
21775 /* Handle a possible width suffix and/or Neon type suffix. */
21776 if (end[0] == '.')
21777 {
21778 int offset = 2;
21779
21780 /* The .w and .n suffixes are only valid if the unified syntax is in
21781 use. */
21782 if (unified_syntax && end[1] == 'w')
21783 inst.size_req = 4;
21784 else if (unified_syntax && end[1] == 'n')
21785 inst.size_req = 2;
21786 else
21787 offset = 0;
21788
21789 inst.vectype.elems = 0;
21790
21791 *str = end + offset;
21792
21793 if (end[offset] == '.')
21794 {
21795 /* See if we have a Neon type suffix (possible in either unified or
21796 non-unified ARM syntax mode). */
21797 if (parse_neon_type (&inst.vectype, str) == FAIL)
21798 return NULL;
21799 }
21800 else if (end[offset] != '\0' && end[offset] != ' ')
21801 return NULL;
21802 }
21803 else
21804 *str = end;
21805
21806 /* Look for unaffixed or special-case affixed mnemonic. */
21807 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
21808 end - base);
21809 if (opcode)
21810 {
21811 /* step U */
21812 if (opcode->tag < OT_odd_infix_0)
21813 {
21814 inst.cond = COND_ALWAYS;
21815 return opcode;
21816 }
21817
21818 if (warn_on_deprecated && unified_syntax)
21819 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
21820 affix = base + (opcode->tag - OT_odd_infix_0);
21821 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
21822 gas_assert (cond);
21823
21824 inst.cond = cond->value;
21825 return opcode;
21826 }
21827 if (ARM_CPU_HAS_FEATURE (cpu_variant, mve_ext))
21828 {
21829 /* Cannot have a conditional suffix on a mnemonic of less than a character.
21830 */
21831 if (end - base < 2)
21832 return NULL;
21833 affix = end - 1;
21834 cond = (const struct asm_cond *) hash_find_n (arm_vcond_hsh, affix, 1);
21835 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
21836 affix - base);
21837 /* If this opcode can not be vector predicated then don't accept it with a
21838 vector predication code. */
21839 if (opcode && !opcode->mayBeVecPred)
21840 opcode = NULL;
21841 }
21842 if (!opcode || !cond)
21843 {
21844 /* Cannot have a conditional suffix on a mnemonic of less than two
21845 characters. */
21846 if (end - base < 3)
21847 return NULL;
21848
21849 /* Look for suffixed mnemonic. */
21850 affix = end - 2;
21851 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
21852 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
21853 affix - base);
21854 }
21855
21856 if (opcode && cond)
21857 {
21858 /* step CE */
21859 switch (opcode->tag)
21860 {
21861 case OT_cinfix3_legacy:
21862 /* Ignore conditional suffixes matched on infix only mnemonics. */
21863 break;
21864
21865 case OT_cinfix3:
21866 case OT_cinfix3_deprecated:
21867 case OT_odd_infix_unc:
21868 if (!unified_syntax)
21869 return NULL;
21870 /* Fall through. */
21871
21872 case OT_csuffix:
21873 case OT_csuffixF:
21874 case OT_csuf_or_in3:
21875 inst.cond = cond->value;
21876 return opcode;
21877
21878 case OT_unconditional:
21879 case OT_unconditionalF:
21880 if (thumb_mode)
21881 inst.cond = cond->value;
21882 else
21883 {
21884 /* Delayed diagnostic. */
21885 inst.error = BAD_COND;
21886 inst.cond = COND_ALWAYS;
21887 }
21888 return opcode;
21889
21890 default:
21891 return NULL;
21892 }
21893 }
21894
21895 /* Cannot have a usual-position infix on a mnemonic of less than
21896 six characters (five would be a suffix). */
21897 if (end - base < 6)
21898 return NULL;
21899
21900 /* Look for infixed mnemonic in the usual position. */
21901 affix = base + 3;
21902 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
21903 if (!cond)
21904 return NULL;
21905
21906 memcpy (save, affix, 2);
21907 memmove (affix, affix + 2, (end - affix) - 2);
21908 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
21909 (end - base) - 2);
21910 memmove (affix + 2, affix, (end - affix) - 2);
21911 memcpy (affix, save, 2);
21912
21913 if (opcode
21914 && (opcode->tag == OT_cinfix3
21915 || opcode->tag == OT_cinfix3_deprecated
21916 || opcode->tag == OT_csuf_or_in3
21917 || opcode->tag == OT_cinfix3_legacy))
21918 {
21919 /* Step CM. */
21920 if (warn_on_deprecated && unified_syntax
21921 && (opcode->tag == OT_cinfix3
21922 || opcode->tag == OT_cinfix3_deprecated))
21923 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
21924
21925 inst.cond = cond->value;
21926 return opcode;
21927 }
21928
21929 return NULL;
21930 }
21931
21932 /* This function generates an initial IT instruction, leaving its block
21933 virtually open for the new instructions. Eventually,
21934 the mask will be updated by now_pred_add_mask () each time
21935 a new instruction needs to be included in the IT block.
21936 Finally, the block is closed with close_automatic_it_block ().
21937 The block closure can be requested either from md_assemble (),
21938 a tencode (), or due to a label hook. */
21939
21940 static void
21941 new_automatic_it_block (int cond)
21942 {
21943 now_pred.state = AUTOMATIC_PRED_BLOCK;
21944 now_pred.mask = 0x18;
21945 now_pred.cc = cond;
21946 now_pred.block_length = 1;
21947 mapping_state (MAP_THUMB);
21948 now_pred.insn = output_it_inst (cond, now_pred.mask, NULL);
21949 now_pred.warn_deprecated = FALSE;
21950 now_pred.insn_cond = TRUE;
21951 }
21952
21953 /* Close an automatic IT block.
21954 See comments in new_automatic_it_block (). */
21955
21956 static void
21957 close_automatic_it_block (void)
21958 {
21959 now_pred.mask = 0x10;
21960 now_pred.block_length = 0;
21961 }
21962
21963 /* Update the mask of the current automatically-generated IT
21964 instruction. See comments in new_automatic_it_block (). */
21965
21966 static void
21967 now_pred_add_mask (int cond)
21968 {
21969 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
21970 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
21971 | ((bitvalue) << (nbit)))
21972 const int resulting_bit = (cond & 1);
21973
21974 now_pred.mask &= 0xf;
21975 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
21976 resulting_bit,
21977 (5 - now_pred.block_length));
21978 now_pred.mask = SET_BIT_VALUE (now_pred.mask,
21979 1,
21980 ((5 - now_pred.block_length) - 1));
21981 output_it_inst (now_pred.cc, now_pred.mask, now_pred.insn);
21982
21983 #undef CLEAR_BIT
21984 #undef SET_BIT_VALUE
21985 }
21986
21987 /* The IT blocks handling machinery is accessed through the these functions:
21988 it_fsm_pre_encode () from md_assemble ()
21989 set_pred_insn_type () optional, from the tencode functions
21990 set_pred_insn_type_last () ditto
21991 in_pred_block () ditto
21992 it_fsm_post_encode () from md_assemble ()
21993 force_automatic_it_block_close () from label handling functions
21994
21995 Rationale:
21996 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
21997 initializing the IT insn type with a generic initial value depending
21998 on the inst.condition.
21999 2) During the tencode function, two things may happen:
22000 a) The tencode function overrides the IT insn type by
22001 calling either set_pred_insn_type (type) or
22002 set_pred_insn_type_last ().
22003 b) The tencode function queries the IT block state by
22004 calling in_pred_block () (i.e. to determine narrow/not narrow mode).
22005
22006 Both set_pred_insn_type and in_pred_block run the internal FSM state
22007 handling function (handle_pred_state), because: a) setting the IT insn
22008 type may incur in an invalid state (exiting the function),
22009 and b) querying the state requires the FSM to be updated.
22010 Specifically we want to avoid creating an IT block for conditional
22011 branches, so it_fsm_pre_encode is actually a guess and we can't
22012 determine whether an IT block is required until the tencode () routine
22013 has decided what type of instruction this actually it.
22014 Because of this, if set_pred_insn_type and in_pred_block have to be
22015 used, set_pred_insn_type has to be called first.
22016
22017 set_pred_insn_type_last () is a wrapper of set_pred_insn_type (type),
22018 that determines the insn IT type depending on the inst.cond code.
22019 When a tencode () routine encodes an instruction that can be
22020 either outside an IT block, or, in the case of being inside, has to be
22021 the last one, set_pred_insn_type_last () will determine the proper
22022 IT instruction type based on the inst.cond code. Otherwise,
22023 set_pred_insn_type can be called for overriding that logic or
22024 for covering other cases.
22025
22026 Calling handle_pred_state () may not transition the IT block state to
22027 OUTSIDE_PRED_BLOCK immediately, since the (current) state could be
22028 still queried. Instead, if the FSM determines that the state should
22029 be transitioned to OUTSIDE_PRED_BLOCK, a flag is marked to be closed
22030 after the tencode () function: that's what it_fsm_post_encode () does.
22031
22032 Since in_pred_block () calls the state handling function to get an
22033 updated state, an error may occur (due to invalid insns combination).
22034 In that case, inst.error is set.
22035 Therefore, inst.error has to be checked after the execution of
22036 the tencode () routine.
22037
22038 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
22039 any pending state change (if any) that didn't take place in
22040 handle_pred_state () as explained above. */
22041
22042 static void
22043 it_fsm_pre_encode (void)
22044 {
22045 if (inst.cond != COND_ALWAYS)
22046 inst.pred_insn_type = INSIDE_IT_INSN;
22047 else
22048 inst.pred_insn_type = OUTSIDE_PRED_INSN;
22049
22050 now_pred.state_handled = 0;
22051 }
22052
22053 /* IT state FSM handling function. */
22054 /* MVE instructions and non-MVE instructions are handled differently because of
22055 the introduction of VPT blocks.
22056 Specifications say that any non-MVE instruction inside a VPT block is
22057 UNPREDICTABLE, with the exception of the BKPT instruction. Whereas most MVE
22058 instructions are deemed to be UNPREDICTABLE if inside an IT block. For the
22059 few exceptions we have MVE_UNPREDICABLE_INSN.
22060 The error messages provided depending on the different combinations possible
22061 are described in the cases below:
22062 For 'most' MVE instructions:
22063 1) In an IT block, with an IT code: syntax error
22064 2) In an IT block, with a VPT code: error: must be in a VPT block
22065 3) In an IT block, with no code: warning: UNPREDICTABLE
22066 4) In a VPT block, with an IT code: syntax error
22067 5) In a VPT block, with a VPT code: OK!
22068 6) In a VPT block, with no code: error: missing code
22069 7) Outside a pred block, with an IT code: error: syntax error
22070 8) Outside a pred block, with a VPT code: error: should be in a VPT block
22071 9) Outside a pred block, with no code: OK!
22072 For non-MVE instructions:
22073 10) In an IT block, with an IT code: OK!
22074 11) In an IT block, with a VPT code: syntax error
22075 12) In an IT block, with no code: error: missing code
22076 13) In a VPT block, with an IT code: error: should be in an IT block
22077 14) In a VPT block, with a VPT code: syntax error
22078 15) In a VPT block, with no code: UNPREDICTABLE
22079 16) Outside a pred block, with an IT code: error: should be in an IT block
22080 17) Outside a pred block, with a VPT code: syntax error
22081 18) Outside a pred block, with no code: OK!
22082 */
22083
22084
22085 static int
22086 handle_pred_state (void)
22087 {
22088 now_pred.state_handled = 1;
22089 now_pred.insn_cond = FALSE;
22090
22091 switch (now_pred.state)
22092 {
22093 case OUTSIDE_PRED_BLOCK:
22094 switch (inst.pred_insn_type)
22095 {
22096 case MVE_UNPREDICABLE_INSN:
22097 case MVE_OUTSIDE_PRED_INSN:
22098 if (inst.cond < COND_ALWAYS)
22099 {
22100 /* Case 7: Outside a pred block, with an IT code: error: syntax
22101 error. */
22102 inst.error = BAD_SYNTAX;
22103 return FAIL;
22104 }
22105 /* Case 9: Outside a pred block, with no code: OK! */
22106 break;
22107 case OUTSIDE_PRED_INSN:
22108 if (inst.cond > COND_ALWAYS)
22109 {
22110 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22111 */
22112 inst.error = BAD_SYNTAX;
22113 return FAIL;
22114 }
22115 /* Case 18: Outside a pred block, with no code: OK! */
22116 break;
22117
22118 case INSIDE_VPT_INSN:
22119 /* Case 8: Outside a pred block, with a VPT code: error: should be in
22120 a VPT block. */
22121 inst.error = BAD_OUT_VPT;
22122 return FAIL;
22123
22124 case INSIDE_IT_INSN:
22125 case INSIDE_IT_LAST_INSN:
22126 if (inst.cond < COND_ALWAYS)
22127 {
22128 /* Case 16: Outside a pred block, with an IT code: error: should
22129 be in an IT block. */
22130 if (thumb_mode == 0)
22131 {
22132 if (unified_syntax
22133 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
22134 as_tsktsk (_("Warning: conditional outside an IT block"\
22135 " for Thumb."));
22136 }
22137 else
22138 {
22139 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
22140 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
22141 {
22142 /* Automatically generate the IT instruction. */
22143 new_automatic_it_block (inst.cond);
22144 if (inst.pred_insn_type == INSIDE_IT_LAST_INSN)
22145 close_automatic_it_block ();
22146 }
22147 else
22148 {
22149 inst.error = BAD_OUT_IT;
22150 return FAIL;
22151 }
22152 }
22153 break;
22154 }
22155 else if (inst.cond > COND_ALWAYS)
22156 {
22157 /* Case 17: Outside a pred block, with a VPT code: syntax error.
22158 */
22159 inst.error = BAD_SYNTAX;
22160 return FAIL;
22161 }
22162 else
22163 gas_assert (0);
22164 case IF_INSIDE_IT_LAST_INSN:
22165 case NEUTRAL_IT_INSN:
22166 break;
22167
22168 case VPT_INSN:
22169 if (inst.cond != COND_ALWAYS)
22170 first_error (BAD_SYNTAX);
22171 now_pred.state = MANUAL_PRED_BLOCK;
22172 now_pred.block_length = 0;
22173 now_pred.type = VECTOR_PRED;
22174 now_pred.cc = 0;
22175 break;
22176 case IT_INSN:
22177 now_pred.state = MANUAL_PRED_BLOCK;
22178 now_pred.block_length = 0;
22179 now_pred.type = SCALAR_PRED;
22180 break;
22181 }
22182 break;
22183
22184 case AUTOMATIC_PRED_BLOCK:
22185 /* Three things may happen now:
22186 a) We should increment current it block size;
22187 b) We should close current it block (closing insn or 4 insns);
22188 c) We should close current it block and start a new one (due
22189 to incompatible conditions or
22190 4 insns-length block reached). */
22191
22192 switch (inst.pred_insn_type)
22193 {
22194 case INSIDE_VPT_INSN:
22195 case VPT_INSN:
22196 case MVE_UNPREDICABLE_INSN:
22197 case MVE_OUTSIDE_PRED_INSN:
22198 gas_assert (0);
22199 case OUTSIDE_PRED_INSN:
22200 /* The closure of the block shall happen immediately,
22201 so any in_pred_block () call reports the block as closed. */
22202 force_automatic_it_block_close ();
22203 break;
22204
22205 case INSIDE_IT_INSN:
22206 case INSIDE_IT_LAST_INSN:
22207 case IF_INSIDE_IT_LAST_INSN:
22208 now_pred.block_length++;
22209
22210 if (now_pred.block_length > 4
22211 || !now_pred_compatible (inst.cond))
22212 {
22213 force_automatic_it_block_close ();
22214 if (inst.pred_insn_type != IF_INSIDE_IT_LAST_INSN)
22215 new_automatic_it_block (inst.cond);
22216 }
22217 else
22218 {
22219 now_pred.insn_cond = TRUE;
22220 now_pred_add_mask (inst.cond);
22221 }
22222
22223 if (now_pred.state == AUTOMATIC_PRED_BLOCK
22224 && (inst.pred_insn_type == INSIDE_IT_LAST_INSN
22225 || inst.pred_insn_type == IF_INSIDE_IT_LAST_INSN))
22226 close_automatic_it_block ();
22227 break;
22228
22229 case NEUTRAL_IT_INSN:
22230 now_pred.block_length++;
22231 now_pred.insn_cond = TRUE;
22232
22233 if (now_pred.block_length > 4)
22234 force_automatic_it_block_close ();
22235 else
22236 now_pred_add_mask (now_pred.cc & 1);
22237 break;
22238
22239 case IT_INSN:
22240 close_automatic_it_block ();
22241 now_pred.state = MANUAL_PRED_BLOCK;
22242 break;
22243 }
22244 break;
22245
22246 case MANUAL_PRED_BLOCK:
22247 {
22248 int cond, is_last;
22249 if (now_pred.type == SCALAR_PRED)
22250 {
22251 /* Check conditional suffixes. */
22252 cond = now_pred.cc ^ ((now_pred.mask >> 4) & 1) ^ 1;
22253 now_pred.mask <<= 1;
22254 now_pred.mask &= 0x1f;
22255 is_last = (now_pred.mask == 0x10);
22256 }
22257 else
22258 {
22259 now_pred.cc ^= (now_pred.mask >> 4);
22260 cond = now_pred.cc + 0xf;
22261 now_pred.mask <<= 1;
22262 now_pred.mask &= 0x1f;
22263 is_last = now_pred.mask == 0x10;
22264 }
22265 now_pred.insn_cond = TRUE;
22266
22267 switch (inst.pred_insn_type)
22268 {
22269 case OUTSIDE_PRED_INSN:
22270 if (now_pred.type == SCALAR_PRED)
22271 {
22272 if (inst.cond == COND_ALWAYS)
22273 {
22274 /* Case 12: In an IT block, with no code: error: missing
22275 code. */
22276 inst.error = BAD_NOT_IT;
22277 return FAIL;
22278 }
22279 else if (inst.cond > COND_ALWAYS)
22280 {
22281 /* Case 11: In an IT block, with a VPT code: syntax error.
22282 */
22283 inst.error = BAD_SYNTAX;
22284 return FAIL;
22285 }
22286 else if (thumb_mode)
22287 {
22288 /* This is for some special cases where a non-MVE
22289 instruction is not allowed in an IT block, such as cbz,
22290 but are put into one with a condition code.
22291 You could argue this should be a syntax error, but we
22292 gave the 'not allowed in IT block' diagnostic in the
22293 past so we will keep doing so. */
22294 inst.error = BAD_NOT_IT;
22295 return FAIL;
22296 }
22297 break;
22298 }
22299 else
22300 {
22301 /* Case 15: In a VPT block, with no code: UNPREDICTABLE. */
22302 as_tsktsk (MVE_NOT_VPT);
22303 return SUCCESS;
22304 }
22305 case MVE_OUTSIDE_PRED_INSN:
22306 if (now_pred.type == SCALAR_PRED)
22307 {
22308 if (inst.cond == COND_ALWAYS)
22309 {
22310 /* Case 3: In an IT block, with no code: warning:
22311 UNPREDICTABLE. */
22312 as_tsktsk (MVE_NOT_IT);
22313 return SUCCESS;
22314 }
22315 else if (inst.cond < COND_ALWAYS)
22316 {
22317 /* Case 1: In an IT block, with an IT code: syntax error.
22318 */
22319 inst.error = BAD_SYNTAX;
22320 return FAIL;
22321 }
22322 else
22323 gas_assert (0);
22324 }
22325 else
22326 {
22327 if (inst.cond < COND_ALWAYS)
22328 {
22329 /* Case 4: In a VPT block, with an IT code: syntax error.
22330 */
22331 inst.error = BAD_SYNTAX;
22332 return FAIL;
22333 }
22334 else if (inst.cond == COND_ALWAYS)
22335 {
22336 /* Case 6: In a VPT block, with no code: error: missing
22337 code. */
22338 inst.error = BAD_NOT_VPT;
22339 return FAIL;
22340 }
22341 else
22342 {
22343 gas_assert (0);
22344 }
22345 }
22346 case MVE_UNPREDICABLE_INSN:
22347 as_tsktsk (now_pred.type == SCALAR_PRED ? MVE_NOT_IT : MVE_NOT_VPT);
22348 return SUCCESS;
22349 case INSIDE_IT_INSN:
22350 if (inst.cond > COND_ALWAYS)
22351 {
22352 /* Case 11: In an IT block, with a VPT code: syntax error. */
22353 /* Case 14: In a VPT block, with a VPT code: syntax error. */
22354 inst.error = BAD_SYNTAX;
22355 return FAIL;
22356 }
22357 else if (now_pred.type == SCALAR_PRED)
22358 {
22359 /* Case 10: In an IT block, with an IT code: OK! */
22360 if (cond != inst.cond)
22361 {
22362 inst.error = now_pred.type == SCALAR_PRED ? BAD_IT_COND :
22363 BAD_VPT_COND;
22364 return FAIL;
22365 }
22366 }
22367 else
22368 {
22369 /* Case 13: In a VPT block, with an IT code: error: should be
22370 in an IT block. */
22371 inst.error = BAD_OUT_IT;
22372 return FAIL;
22373 }
22374 break;
22375
22376 case INSIDE_VPT_INSN:
22377 if (now_pred.type == SCALAR_PRED)
22378 {
22379 /* Case 2: In an IT block, with a VPT code: error: must be in a
22380 VPT block. */
22381 inst.error = BAD_OUT_VPT;
22382 return FAIL;
22383 }
22384 /* Case 5: In a VPT block, with a VPT code: OK! */
22385 else if (cond != inst.cond)
22386 {
22387 inst.error = BAD_VPT_COND;
22388 return FAIL;
22389 }
22390 break;
22391 case INSIDE_IT_LAST_INSN:
22392 case IF_INSIDE_IT_LAST_INSN:
22393 if (now_pred.type == VECTOR_PRED || inst.cond > COND_ALWAYS)
22394 {
22395 /* Case 4: In a VPT block, with an IT code: syntax error. */
22396 /* Case 11: In an IT block, with a VPT code: syntax error. */
22397 inst.error = BAD_SYNTAX;
22398 return FAIL;
22399 }
22400 else if (cond != inst.cond)
22401 {
22402 inst.error = BAD_IT_COND;
22403 return FAIL;
22404 }
22405 if (!is_last)
22406 {
22407 inst.error = BAD_BRANCH;
22408 return FAIL;
22409 }
22410 break;
22411
22412 case NEUTRAL_IT_INSN:
22413 /* The BKPT instruction is unconditional even in a IT or VPT
22414 block. */
22415 break;
22416
22417 case IT_INSN:
22418 if (now_pred.type == SCALAR_PRED)
22419 {
22420 inst.error = BAD_IT_IT;
22421 return FAIL;
22422 }
22423 /* fall through. */
22424 case VPT_INSN:
22425 if (inst.cond == COND_ALWAYS)
22426 {
22427 /* Executing a VPT/VPST instruction inside an IT block or a
22428 VPT/VPST/IT instruction inside a VPT block is UNPREDICTABLE.
22429 */
22430 if (now_pred.type == SCALAR_PRED)
22431 as_tsktsk (MVE_NOT_IT);
22432 else
22433 as_tsktsk (MVE_NOT_VPT);
22434 return SUCCESS;
22435 }
22436 else
22437 {
22438 /* VPT/VPST do not accept condition codes. */
22439 inst.error = BAD_SYNTAX;
22440 return FAIL;
22441 }
22442 }
22443 }
22444 break;
22445 }
22446
22447 return SUCCESS;
22448 }
22449
22450 struct depr_insn_mask
22451 {
22452 unsigned long pattern;
22453 unsigned long mask;
22454 const char* description;
22455 };
22456
22457 /* List of 16-bit instruction patterns deprecated in an IT block in
22458 ARMv8. */
22459 static const struct depr_insn_mask depr_it_insns[] = {
22460 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
22461 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
22462 { 0xa000, 0xb800, N_("ADR") },
22463 { 0x4800, 0xf800, N_("Literal loads") },
22464 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
22465 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
22466 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
22467 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
22468 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
22469 { 0, 0, NULL }
22470 };
22471
22472 static void
22473 it_fsm_post_encode (void)
22474 {
22475 int is_last;
22476
22477 if (!now_pred.state_handled)
22478 handle_pred_state ();
22479
22480 if (now_pred.insn_cond
22481 && !now_pred.warn_deprecated
22482 && warn_on_deprecated
22483 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
22484 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
22485 {
22486 if (inst.instruction >= 0x10000)
22487 {
22488 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
22489 "performance deprecated in ARMv8-A and ARMv8-R"));
22490 now_pred.warn_deprecated = TRUE;
22491 }
22492 else
22493 {
22494 const struct depr_insn_mask *p = depr_it_insns;
22495
22496 while (p->mask != 0)
22497 {
22498 if ((inst.instruction & p->mask) == p->pattern)
22499 {
22500 as_tsktsk (_("IT blocks containing 16-bit Thumb "
22501 "instructions of the following class are "
22502 "performance deprecated in ARMv8-A and "
22503 "ARMv8-R: %s"), p->description);
22504 now_pred.warn_deprecated = TRUE;
22505 break;
22506 }
22507
22508 ++p;
22509 }
22510 }
22511
22512 if (now_pred.block_length > 1)
22513 {
22514 as_tsktsk (_("IT blocks containing more than one conditional "
22515 "instruction are performance deprecated in ARMv8-A and "
22516 "ARMv8-R"));
22517 now_pred.warn_deprecated = TRUE;
22518 }
22519 }
22520
22521 is_last = (now_pred.mask == 0x10);
22522 if (is_last)
22523 {
22524 now_pred.state = OUTSIDE_PRED_BLOCK;
22525 now_pred.mask = 0;
22526 }
22527 }
22528
22529 static void
22530 force_automatic_it_block_close (void)
22531 {
22532 if (now_pred.state == AUTOMATIC_PRED_BLOCK)
22533 {
22534 close_automatic_it_block ();
22535 now_pred.state = OUTSIDE_PRED_BLOCK;
22536 now_pred.mask = 0;
22537 }
22538 }
22539
22540 static int
22541 in_pred_block (void)
22542 {
22543 if (!now_pred.state_handled)
22544 handle_pred_state ();
22545
22546 return now_pred.state != OUTSIDE_PRED_BLOCK;
22547 }
22548
22549 /* Whether OPCODE only has T32 encoding. Since this function is only used by
22550 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
22551 here, hence the "known" in the function name. */
22552
22553 static bfd_boolean
22554 known_t32_only_insn (const struct asm_opcode *opcode)
22555 {
22556 /* Original Thumb-1 wide instruction. */
22557 if (opcode->tencode == do_t_blx
22558 || opcode->tencode == do_t_branch23
22559 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
22560 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
22561 return TRUE;
22562
22563 /* Wide-only instruction added to ARMv8-M Baseline. */
22564 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
22565 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
22566 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
22567 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
22568 return TRUE;
22569
22570 return FALSE;
22571 }
22572
22573 /* Whether wide instruction variant can be used if available for a valid OPCODE
22574 in ARCH. */
22575
22576 static bfd_boolean
22577 t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
22578 {
22579 if (known_t32_only_insn (opcode))
22580 return TRUE;
22581
22582 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
22583 of variant T3 of B.W is checked in do_t_branch. */
22584 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
22585 && opcode->tencode == do_t_branch)
22586 return TRUE;
22587
22588 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
22589 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
22590 && opcode->tencode == do_t_mov_cmp
22591 /* Make sure CMP instruction is not affected. */
22592 && opcode->aencode == do_mov)
22593 return TRUE;
22594
22595 /* Wide instruction variants of all instructions with narrow *and* wide
22596 variants become available with ARMv6t2. Other opcodes are either
22597 narrow-only or wide-only and are thus available if OPCODE is valid. */
22598 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
22599 return TRUE;
22600
22601 /* OPCODE with narrow only instruction variant or wide variant not
22602 available. */
22603 return FALSE;
22604 }
22605
22606 void
22607 md_assemble (char *str)
22608 {
22609 char *p = str;
22610 const struct asm_opcode * opcode;
22611
22612 /* Align the previous label if needed. */
22613 if (last_label_seen != NULL)
22614 {
22615 symbol_set_frag (last_label_seen, frag_now);
22616 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
22617 S_SET_SEGMENT (last_label_seen, now_seg);
22618 }
22619
22620 memset (&inst, '\0', sizeof (inst));
22621 int r;
22622 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
22623 inst.relocs[r].type = BFD_RELOC_UNUSED;
22624
22625 opcode = opcode_lookup (&p);
22626 if (!opcode)
22627 {
22628 /* It wasn't an instruction, but it might be a register alias of
22629 the form alias .req reg, or a Neon .dn/.qn directive. */
22630 if (! create_register_alias (str, p)
22631 && ! create_neon_reg_alias (str, p))
22632 as_bad (_("bad instruction `%s'"), str);
22633
22634 return;
22635 }
22636
22637 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
22638 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
22639
22640 /* The value which unconditional instructions should have in place of the
22641 condition field. */
22642 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
22643
22644 if (thumb_mode)
22645 {
22646 arm_feature_set variant;
22647
22648 variant = cpu_variant;
22649 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
22650 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
22651 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
22652 /* Check that this instruction is supported for this CPU. */
22653 if (!opcode->tvariant
22654 || (thumb_mode == 1
22655 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
22656 {
22657 if (opcode->tencode == do_t_swi)
22658 as_bad (_("SVC is not permitted on this architecture"));
22659 else
22660 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
22661 return;
22662 }
22663 if (inst.cond != COND_ALWAYS && !unified_syntax
22664 && opcode->tencode != do_t_branch)
22665 {
22666 as_bad (_("Thumb does not support conditional execution"));
22667 return;
22668 }
22669
22670 /* Two things are addressed here:
22671 1) Implicit require narrow instructions on Thumb-1.
22672 This avoids relaxation accidentally introducing Thumb-2
22673 instructions.
22674 2) Reject wide instructions in non Thumb-2 cores.
22675
22676 Only instructions with narrow and wide variants need to be handled
22677 but selecting all non wide-only instructions is easier. */
22678 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
22679 && !t32_insn_ok (variant, opcode))
22680 {
22681 if (inst.size_req == 0)
22682 inst.size_req = 2;
22683 else if (inst.size_req == 4)
22684 {
22685 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
22686 as_bad (_("selected processor does not support 32bit wide "
22687 "variant of instruction `%s'"), str);
22688 else
22689 as_bad (_("selected processor does not support `%s' in "
22690 "Thumb-2 mode"), str);
22691 return;
22692 }
22693 }
22694
22695 inst.instruction = opcode->tvalue;
22696
22697 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
22698 {
22699 /* Prepare the pred_insn_type for those encodings that don't set
22700 it. */
22701 it_fsm_pre_encode ();
22702
22703 opcode->tencode ();
22704
22705 it_fsm_post_encode ();
22706 }
22707
22708 if (!(inst.error || inst.relax))
22709 {
22710 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
22711 inst.size = (inst.instruction > 0xffff ? 4 : 2);
22712 if (inst.size_req && inst.size_req != inst.size)
22713 {
22714 as_bad (_("cannot honor width suffix -- `%s'"), str);
22715 return;
22716 }
22717 }
22718
22719 /* Something has gone badly wrong if we try to relax a fixed size
22720 instruction. */
22721 gas_assert (inst.size_req == 0 || !inst.relax);
22722
22723 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
22724 *opcode->tvariant);
22725 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
22726 set those bits when Thumb-2 32-bit instructions are seen. The impact
22727 of relaxable instructions will be considered later after we finish all
22728 relaxation. */
22729 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
22730 variant = arm_arch_none;
22731 else
22732 variant = cpu_variant;
22733 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
22734 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
22735 arm_ext_v6t2);
22736
22737 check_neon_suffixes;
22738
22739 if (!inst.error)
22740 {
22741 mapping_state (MAP_THUMB);
22742 }
22743 }
22744 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22745 {
22746 bfd_boolean is_bx;
22747
22748 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
22749 is_bx = (opcode->aencode == do_bx);
22750
22751 /* Check that this instruction is supported for this CPU. */
22752 if (!(is_bx && fix_v4bx)
22753 && !(opcode->avariant &&
22754 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
22755 {
22756 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
22757 return;
22758 }
22759 if (inst.size_req)
22760 {
22761 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
22762 return;
22763 }
22764
22765 inst.instruction = opcode->avalue;
22766 if (opcode->tag == OT_unconditionalF)
22767 inst.instruction |= 0xFU << 28;
22768 else
22769 inst.instruction |= inst.cond << 28;
22770 inst.size = INSN_SIZE;
22771 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
22772 {
22773 it_fsm_pre_encode ();
22774 opcode->aencode ();
22775 it_fsm_post_encode ();
22776 }
22777 /* Arm mode bx is marked as both v4T and v5 because it's still required
22778 on a hypothetical non-thumb v5 core. */
22779 if (is_bx)
22780 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
22781 else
22782 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
22783 *opcode->avariant);
22784
22785 check_neon_suffixes;
22786
22787 if (!inst.error)
22788 {
22789 mapping_state (MAP_ARM);
22790 }
22791 }
22792 else
22793 {
22794 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
22795 "-- `%s'"), str);
22796 return;
22797 }
22798 output_inst (str);
22799 }
22800
22801 static void
22802 check_pred_blocks_finished (void)
22803 {
22804 #ifdef OBJ_ELF
22805 asection *sect;
22806
22807 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
22808 if (seg_info (sect)->tc_segment_info_data.current_pred.state
22809 == MANUAL_PRED_BLOCK)
22810 {
22811 if (now_pred.type == SCALAR_PRED)
22812 as_warn (_("section '%s' finished with an open IT block."),
22813 sect->name);
22814 else
22815 as_warn (_("section '%s' finished with an open VPT/VPST block."),
22816 sect->name);
22817 }
22818 #else
22819 if (now_pred.state == MANUAL_PRED_BLOCK)
22820 {
22821 if (now_pred.type == SCALAR_PRED)
22822 as_warn (_("file finished with an open IT block."));
22823 else
22824 as_warn (_("file finished with an open VPT/VPST block."));
22825 }
22826 #endif
22827 }
22828
22829 /* Various frobbings of labels and their addresses. */
22830
22831 void
22832 arm_start_line_hook (void)
22833 {
22834 last_label_seen = NULL;
22835 }
22836
22837 void
22838 arm_frob_label (symbolS * sym)
22839 {
22840 last_label_seen = sym;
22841
22842 ARM_SET_THUMB (sym, thumb_mode);
22843
22844 #if defined OBJ_COFF || defined OBJ_ELF
22845 ARM_SET_INTERWORK (sym, support_interwork);
22846 #endif
22847
22848 force_automatic_it_block_close ();
22849
22850 /* Note - do not allow local symbols (.Lxxx) to be labelled
22851 as Thumb functions. This is because these labels, whilst
22852 they exist inside Thumb code, are not the entry points for
22853 possible ARM->Thumb calls. Also, these labels can be used
22854 as part of a computed goto or switch statement. eg gcc
22855 can generate code that looks like this:
22856
22857 ldr r2, [pc, .Laaa]
22858 lsl r3, r3, #2
22859 ldr r2, [r3, r2]
22860 mov pc, r2
22861
22862 .Lbbb: .word .Lxxx
22863 .Lccc: .word .Lyyy
22864 ..etc...
22865 .Laaa: .word Lbbb
22866
22867 The first instruction loads the address of the jump table.
22868 The second instruction converts a table index into a byte offset.
22869 The third instruction gets the jump address out of the table.
22870 The fourth instruction performs the jump.
22871
22872 If the address stored at .Laaa is that of a symbol which has the
22873 Thumb_Func bit set, then the linker will arrange for this address
22874 to have the bottom bit set, which in turn would mean that the
22875 address computation performed by the third instruction would end
22876 up with the bottom bit set. Since the ARM is capable of unaligned
22877 word loads, the instruction would then load the incorrect address
22878 out of the jump table, and chaos would ensue. */
22879 if (label_is_thumb_function_name
22880 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
22881 && (bfd_section_flags (now_seg) & SEC_CODE) != 0)
22882 {
22883 /* When the address of a Thumb function is taken the bottom
22884 bit of that address should be set. This will allow
22885 interworking between Arm and Thumb functions to work
22886 correctly. */
22887
22888 THUMB_SET_FUNC (sym, 1);
22889
22890 label_is_thumb_function_name = FALSE;
22891 }
22892
22893 dwarf2_emit_label (sym);
22894 }
22895
22896 bfd_boolean
22897 arm_data_in_code (void)
22898 {
22899 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
22900 {
22901 *input_line_pointer = '/';
22902 input_line_pointer += 5;
22903 *input_line_pointer = 0;
22904 return TRUE;
22905 }
22906
22907 return FALSE;
22908 }
22909
22910 char *
22911 arm_canonicalize_symbol_name (char * name)
22912 {
22913 int len;
22914
22915 if (thumb_mode && (len = strlen (name)) > 5
22916 && streq (name + len - 5, "/data"))
22917 *(name + len - 5) = 0;
22918
22919 return name;
22920 }
22921 \f
22922 /* Table of all register names defined by default. The user can
22923 define additional names with .req. Note that all register names
22924 should appear in both upper and lowercase variants. Some registers
22925 also have mixed-case names. */
22926
22927 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
22928 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
22929 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
22930 #define REGSET(p,t) \
22931 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
22932 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
22933 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
22934 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
22935 #define REGSETH(p,t) \
22936 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
22937 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
22938 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
22939 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
22940 #define REGSET2(p,t) \
22941 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
22942 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
22943 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
22944 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
22945 #define SPLRBANK(base,bank,t) \
22946 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
22947 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
22948 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
22949 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
22950 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
22951 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
22952
22953 static const struct reg_entry reg_names[] =
22954 {
22955 /* ARM integer registers. */
22956 REGSET(r, RN), REGSET(R, RN),
22957
22958 /* ATPCS synonyms. */
22959 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
22960 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
22961 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
22962
22963 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
22964 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
22965 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
22966
22967 /* Well-known aliases. */
22968 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
22969 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
22970
22971 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
22972 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
22973
22974 /* Defining the new Zero register from ARMv8.1-M. */
22975 REGDEF(zr,15,ZR),
22976 REGDEF(ZR,15,ZR),
22977
22978 /* Coprocessor numbers. */
22979 REGSET(p, CP), REGSET(P, CP),
22980
22981 /* Coprocessor register numbers. The "cr" variants are for backward
22982 compatibility. */
22983 REGSET(c, CN), REGSET(C, CN),
22984 REGSET(cr, CN), REGSET(CR, CN),
22985
22986 /* ARM banked registers. */
22987 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
22988 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
22989 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
22990 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
22991 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
22992 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
22993 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
22994
22995 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
22996 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
22997 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
22998 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
22999 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
23000 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
23001 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
23002 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
23003
23004 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
23005 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
23006 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
23007 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
23008 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
23009 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
23010 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
23011 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
23012 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
23013
23014 /* FPA registers. */
23015 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
23016 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
23017
23018 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
23019 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
23020
23021 /* VFP SP registers. */
23022 REGSET(s,VFS), REGSET(S,VFS),
23023 REGSETH(s,VFS), REGSETH(S,VFS),
23024
23025 /* VFP DP Registers. */
23026 REGSET(d,VFD), REGSET(D,VFD),
23027 /* Extra Neon DP registers. */
23028 REGSETH(d,VFD), REGSETH(D,VFD),
23029
23030 /* Neon QP registers. */
23031 REGSET2(q,NQ), REGSET2(Q,NQ),
23032
23033 /* VFP control registers. */
23034 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
23035 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
23036 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
23037 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
23038 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
23039 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
23040 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
23041 REGDEF(fpscr_nzcvqc,2,VFC), REGDEF(FPSCR_nzcvqc,2,VFC),
23042 REGDEF(vpr,12,VFC), REGDEF(VPR,12,VFC),
23043 REGDEF(fpcxt_ns,14,VFC), REGDEF(FPCXT_NS,14,VFC),
23044 REGDEF(fpcxt_s,15,VFC), REGDEF(FPCXT_S,15,VFC),
23045
23046 /* Maverick DSP coprocessor registers. */
23047 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
23048 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
23049
23050 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
23051 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
23052 REGDEF(dspsc,0,DSPSC),
23053
23054 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
23055 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
23056 REGDEF(DSPSC,0,DSPSC),
23057
23058 /* iWMMXt data registers - p0, c0-15. */
23059 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
23060
23061 /* iWMMXt control registers - p1, c0-3. */
23062 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
23063 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
23064 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
23065 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
23066
23067 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
23068 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
23069 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
23070 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
23071 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
23072
23073 /* XScale accumulator registers. */
23074 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
23075 };
23076 #undef REGDEF
23077 #undef REGNUM
23078 #undef REGSET
23079
23080 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
23081 within psr_required_here. */
23082 static const struct asm_psr psrs[] =
23083 {
23084 /* Backward compatibility notation. Note that "all" is no longer
23085 truly all possible PSR bits. */
23086 {"all", PSR_c | PSR_f},
23087 {"flg", PSR_f},
23088 {"ctl", PSR_c},
23089
23090 /* Individual flags. */
23091 {"f", PSR_f},
23092 {"c", PSR_c},
23093 {"x", PSR_x},
23094 {"s", PSR_s},
23095
23096 /* Combinations of flags. */
23097 {"fs", PSR_f | PSR_s},
23098 {"fx", PSR_f | PSR_x},
23099 {"fc", PSR_f | PSR_c},
23100 {"sf", PSR_s | PSR_f},
23101 {"sx", PSR_s | PSR_x},
23102 {"sc", PSR_s | PSR_c},
23103 {"xf", PSR_x | PSR_f},
23104 {"xs", PSR_x | PSR_s},
23105 {"xc", PSR_x | PSR_c},
23106 {"cf", PSR_c | PSR_f},
23107 {"cs", PSR_c | PSR_s},
23108 {"cx", PSR_c | PSR_x},
23109 {"fsx", PSR_f | PSR_s | PSR_x},
23110 {"fsc", PSR_f | PSR_s | PSR_c},
23111 {"fxs", PSR_f | PSR_x | PSR_s},
23112 {"fxc", PSR_f | PSR_x | PSR_c},
23113 {"fcs", PSR_f | PSR_c | PSR_s},
23114 {"fcx", PSR_f | PSR_c | PSR_x},
23115 {"sfx", PSR_s | PSR_f | PSR_x},
23116 {"sfc", PSR_s | PSR_f | PSR_c},
23117 {"sxf", PSR_s | PSR_x | PSR_f},
23118 {"sxc", PSR_s | PSR_x | PSR_c},
23119 {"scf", PSR_s | PSR_c | PSR_f},
23120 {"scx", PSR_s | PSR_c | PSR_x},
23121 {"xfs", PSR_x | PSR_f | PSR_s},
23122 {"xfc", PSR_x | PSR_f | PSR_c},
23123 {"xsf", PSR_x | PSR_s | PSR_f},
23124 {"xsc", PSR_x | PSR_s | PSR_c},
23125 {"xcf", PSR_x | PSR_c | PSR_f},
23126 {"xcs", PSR_x | PSR_c | PSR_s},
23127 {"cfs", PSR_c | PSR_f | PSR_s},
23128 {"cfx", PSR_c | PSR_f | PSR_x},
23129 {"csf", PSR_c | PSR_s | PSR_f},
23130 {"csx", PSR_c | PSR_s | PSR_x},
23131 {"cxf", PSR_c | PSR_x | PSR_f},
23132 {"cxs", PSR_c | PSR_x | PSR_s},
23133 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
23134 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
23135 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
23136 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
23137 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
23138 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
23139 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
23140 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
23141 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
23142 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
23143 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
23144 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
23145 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
23146 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
23147 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
23148 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
23149 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
23150 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
23151 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
23152 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
23153 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
23154 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
23155 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
23156 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
23157 };
23158
23159 /* Table of V7M psr names. */
23160 static const struct asm_psr v7m_psrs[] =
23161 {
23162 {"apsr", 0x0 }, {"APSR", 0x0 },
23163 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
23164 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
23165 {"psr", 0x3 }, {"PSR", 0x3 },
23166 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
23167 {"ipsr", 0x5 }, {"IPSR", 0x5 },
23168 {"epsr", 0x6 }, {"EPSR", 0x6 },
23169 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
23170 {"msp", 0x8 }, {"MSP", 0x8 },
23171 {"psp", 0x9 }, {"PSP", 0x9 },
23172 {"msplim", 0xa }, {"MSPLIM", 0xa },
23173 {"psplim", 0xb }, {"PSPLIM", 0xb },
23174 {"primask", 0x10}, {"PRIMASK", 0x10},
23175 {"basepri", 0x11}, {"BASEPRI", 0x11},
23176 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
23177 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
23178 {"control", 0x14}, {"CONTROL", 0x14},
23179 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
23180 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
23181 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
23182 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
23183 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
23184 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
23185 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
23186 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
23187 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
23188 };
23189
23190 /* Table of all shift-in-operand names. */
23191 static const struct asm_shift_name shift_names [] =
23192 {
23193 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
23194 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
23195 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
23196 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
23197 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
23198 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX },
23199 { "uxtw", SHIFT_UXTW}, { "UXTW", SHIFT_UXTW}
23200 };
23201
23202 /* Table of all explicit relocation names. */
23203 #ifdef OBJ_ELF
23204 static struct reloc_entry reloc_names[] =
23205 {
23206 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
23207 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
23208 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
23209 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
23210 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
23211 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
23212 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
23213 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
23214 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
23215 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
23216 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
23217 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
23218 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
23219 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
23220 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
23221 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
23222 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
23223 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
23224 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
23225 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
23226 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23227 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
23228 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
23229 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
23230 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
23231 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
23232 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
23233 };
23234 #endif
23235
23236 /* Table of all conditional affixes. */
23237 static const struct asm_cond conds[] =
23238 {
23239 {"eq", 0x0},
23240 {"ne", 0x1},
23241 {"cs", 0x2}, {"hs", 0x2},
23242 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
23243 {"mi", 0x4},
23244 {"pl", 0x5},
23245 {"vs", 0x6},
23246 {"vc", 0x7},
23247 {"hi", 0x8},
23248 {"ls", 0x9},
23249 {"ge", 0xa},
23250 {"lt", 0xb},
23251 {"gt", 0xc},
23252 {"le", 0xd},
23253 {"al", 0xe}
23254 };
23255 static const struct asm_cond vconds[] =
23256 {
23257 {"t", 0xf},
23258 {"e", 0x10}
23259 };
23260
23261 #define UL_BARRIER(L,U,CODE,FEAT) \
23262 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
23263 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
23264
23265 static struct asm_barrier_opt barrier_opt_names[] =
23266 {
23267 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
23268 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
23269 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
23270 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
23271 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
23272 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
23273 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
23274 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
23275 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
23276 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
23277 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
23278 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
23279 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
23280 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
23281 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
23282 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
23283 };
23284
23285 #undef UL_BARRIER
23286
23287 /* Table of ARM-format instructions. */
23288
23289 /* Macros for gluing together operand strings. N.B. In all cases
23290 other than OPS0, the trailing OP_stop comes from default
23291 zero-initialization of the unspecified elements of the array. */
23292 #define OPS0() { OP_stop, }
23293 #define OPS1(a) { OP_##a, }
23294 #define OPS2(a,b) { OP_##a,OP_##b, }
23295 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
23296 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
23297 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
23298 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
23299
23300 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
23301 This is useful when mixing operands for ARM and THUMB, i.e. using the
23302 MIX_ARM_THUMB_OPERANDS macro.
23303 In order to use these macros, prefix the number of operands with _
23304 e.g. _3. */
23305 #define OPS_1(a) { a, }
23306 #define OPS_2(a,b) { a,b, }
23307 #define OPS_3(a,b,c) { a,b,c, }
23308 #define OPS_4(a,b,c,d) { a,b,c,d, }
23309 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
23310 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
23311
23312 /* These macros abstract out the exact format of the mnemonic table and
23313 save some repeated characters. */
23314
23315 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
23316 #define TxCE(mnem, op, top, nops, ops, ae, te) \
23317 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
23318 THUMB_VARIANT, do_##ae, do_##te, 0 }
23319
23320 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
23321 a T_MNEM_xyz enumerator. */
23322 #define TCE(mnem, aop, top, nops, ops, ae, te) \
23323 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
23324 #define tCE(mnem, aop, top, nops, ops, ae, te) \
23325 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
23326
23327 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
23328 infix after the third character. */
23329 #define TxC3(mnem, op, top, nops, ops, ae, te) \
23330 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
23331 THUMB_VARIANT, do_##ae, do_##te, 0 }
23332 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
23333 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
23334 THUMB_VARIANT, do_##ae, do_##te, 0 }
23335 #define TC3(mnem, aop, top, nops, ops, ae, te) \
23336 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
23337 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
23338 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
23339 #define tC3(mnem, aop, top, nops, ops, ae, te) \
23340 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
23341 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
23342 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
23343
23344 /* Mnemonic that cannot be conditionalized. The ARM condition-code
23345 field is still 0xE. Many of the Thumb variants can be executed
23346 conditionally, so this is checked separately. */
23347 #define TUE(mnem, op, top, nops, ops, ae, te) \
23348 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
23349 THUMB_VARIANT, do_##ae, do_##te, 0 }
23350
23351 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
23352 Used by mnemonics that have very minimal differences in the encoding for
23353 ARM and Thumb variants and can be handled in a common function. */
23354 #define TUEc(mnem, op, top, nops, ops, en) \
23355 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
23356 THUMB_VARIANT, do_##en, do_##en, 0 }
23357
23358 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
23359 condition code field. */
23360 #define TUF(mnem, op, top, nops, ops, ae, te) \
23361 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
23362 THUMB_VARIANT, do_##ae, do_##te, 0 }
23363
23364 /* ARM-only variants of all the above. */
23365 #define CE(mnem, op, nops, ops, ae) \
23366 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
23367
23368 #define C3(mnem, op, nops, ops, ae) \
23369 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
23370
23371 /* Thumb-only variants of TCE and TUE. */
23372 #define ToC(mnem, top, nops, ops, te) \
23373 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
23374 do_##te, 0 }
23375
23376 #define ToU(mnem, top, nops, ops, te) \
23377 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
23378 NULL, do_##te, 0 }
23379
23380 /* T_MNEM_xyz enumerator variants of ToC. */
23381 #define toC(mnem, top, nops, ops, te) \
23382 { mnem, OPS##nops ops, OT_csuffix, 0x0, T_MNEM##top, 0, THUMB_VARIANT, NULL, \
23383 do_##te, 0 }
23384
23385 /* T_MNEM_xyz enumerator variants of ToU. */
23386 #define toU(mnem, top, nops, ops, te) \
23387 { mnem, OPS##nops ops, OT_unconditional, 0x0, T_MNEM##top, 0, THUMB_VARIANT, \
23388 NULL, do_##te, 0 }
23389
23390 /* Legacy mnemonics that always have conditional infix after the third
23391 character. */
23392 #define CL(mnem, op, nops, ops, ae) \
23393 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
23394 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
23395
23396 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
23397 #define cCE(mnem, op, nops, ops, ae) \
23398 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
23399
23400 /* mov instructions that are shared between coprocessor and MVE. */
23401 #define mcCE(mnem, op, nops, ops, ae) \
23402 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##ae, 0 }
23403
23404 /* Legacy coprocessor instructions where conditional infix and conditional
23405 suffix are ambiguous. For consistency this includes all FPA instructions,
23406 not just the potentially ambiguous ones. */
23407 #define cCL(mnem, op, nops, ops, ae) \
23408 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
23409 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
23410
23411 /* Coprocessor, takes either a suffix or a position-3 infix
23412 (for an FPA corner case). */
23413 #define C3E(mnem, op, nops, ops, ae) \
23414 { mnem, OPS##nops ops, OT_csuf_or_in3, \
23415 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae, 0 }
23416
23417 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
23418 { m1 #m2 m3, OPS##nops ops, \
23419 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
23420 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
23421
23422 #define CM(m1, m2, op, nops, ops, ae) \
23423 xCM_ (m1, , m2, op, nops, ops, ae), \
23424 xCM_ (m1, eq, m2, op, nops, ops, ae), \
23425 xCM_ (m1, ne, m2, op, nops, ops, ae), \
23426 xCM_ (m1, cs, m2, op, nops, ops, ae), \
23427 xCM_ (m1, hs, m2, op, nops, ops, ae), \
23428 xCM_ (m1, cc, m2, op, nops, ops, ae), \
23429 xCM_ (m1, ul, m2, op, nops, ops, ae), \
23430 xCM_ (m1, lo, m2, op, nops, ops, ae), \
23431 xCM_ (m1, mi, m2, op, nops, ops, ae), \
23432 xCM_ (m1, pl, m2, op, nops, ops, ae), \
23433 xCM_ (m1, vs, m2, op, nops, ops, ae), \
23434 xCM_ (m1, vc, m2, op, nops, ops, ae), \
23435 xCM_ (m1, hi, m2, op, nops, ops, ae), \
23436 xCM_ (m1, ls, m2, op, nops, ops, ae), \
23437 xCM_ (m1, ge, m2, op, nops, ops, ae), \
23438 xCM_ (m1, lt, m2, op, nops, ops, ae), \
23439 xCM_ (m1, gt, m2, op, nops, ops, ae), \
23440 xCM_ (m1, le, m2, op, nops, ops, ae), \
23441 xCM_ (m1, al, m2, op, nops, ops, ae)
23442
23443 #define UE(mnem, op, nops, ops, ae) \
23444 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
23445
23446 #define UF(mnem, op, nops, ops, ae) \
23447 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL, 0 }
23448
23449 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
23450 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
23451 use the same encoding function for each. */
23452 #define NUF(mnem, op, nops, ops, enc) \
23453 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
23454 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
23455
23456 /* Neon data processing, version which indirects through neon_enc_tab for
23457 the various overloaded versions of opcodes. */
23458 #define nUF(mnem, op, nops, ops, enc) \
23459 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
23460 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 0 }
23461
23462 /* Neon insn with conditional suffix for the ARM version, non-overloaded
23463 version. */
23464 #define NCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
23465 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
23466 THUMB_VARIANT, do_##enc, do_##enc, mve_p }
23467
23468 #define NCE(mnem, op, nops, ops, enc) \
23469 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
23470
23471 #define NCEF(mnem, op, nops, ops, enc) \
23472 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
23473
23474 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
23475 #define nCE_tag(mnem, op, nops, ops, enc, tag, mve_p) \
23476 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
23477 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, mve_p }
23478
23479 #define nCE(mnem, op, nops, ops, enc) \
23480 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 0)
23481
23482 #define nCEF(mnem, op, nops, ops, enc) \
23483 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 0)
23484
23485 /* */
23486 #define mCEF(mnem, op, nops, ops, enc) \
23487 { #mnem, OPS##nops ops, OT_csuffixF, M_MNEM##op, M_MNEM##op, \
23488 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23489
23490
23491 /* nCEF but for MVE predicated instructions. */
23492 #define mnCEF(mnem, op, nops, ops, enc) \
23493 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
23494
23495 /* nCE but for MVE predicated instructions. */
23496 #define mnCE(mnem, op, nops, ops, enc) \
23497 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
23498
23499 /* NUF but for potentially MVE predicated instructions. */
23500 #define MNUF(mnem, op, nops, ops, enc) \
23501 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
23502 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23503
23504 /* nUF but for potentially MVE predicated instructions. */
23505 #define mnUF(mnem, op, nops, ops, enc) \
23506 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
23507 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc, 1 }
23508
23509 /* ToC but for potentially MVE predicated instructions. */
23510 #define mToC(mnem, top, nops, ops, te) \
23511 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
23512 do_##te, 1 }
23513
23514 /* NCE but for MVE predicated instructions. */
23515 #define MNCE(mnem, op, nops, ops, enc) \
23516 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix, 1)
23517
23518 /* NCEF but for MVE predicated instructions. */
23519 #define MNCEF(mnem, op, nops, ops, enc) \
23520 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF, 1)
23521 #define do_0 0
23522
23523 static const struct asm_opcode insns[] =
23524 {
23525 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
23526 #define THUMB_VARIANT & arm_ext_v4t
23527 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
23528 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
23529 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
23530 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
23531 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
23532 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
23533 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
23534 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
23535 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
23536 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
23537 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
23538 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
23539 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
23540 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
23541 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
23542 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
23543
23544 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
23545 for setting PSR flag bits. They are obsolete in V6 and do not
23546 have Thumb equivalents. */
23547 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
23548 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
23549 CL("tstp", 110f000, 2, (RR, SH), cmp),
23550 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
23551 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
23552 CL("cmpp", 150f000, 2, (RR, SH), cmp),
23553 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
23554 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
23555 CL("cmnp", 170f000, 2, (RR, SH), cmp),
23556
23557 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
23558 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
23559 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
23560 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
23561
23562 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
23563 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
23564 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
23565 OP_RRnpc),
23566 OP_ADDRGLDR),ldst, t_ldst),
23567 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
23568
23569 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23570 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23571 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23572 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23573 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23574 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23575
23576 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
23577 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
23578
23579 /* Pseudo ops. */
23580 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
23581 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
23582 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
23583 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
23584
23585 /* Thumb-compatibility pseudo ops. */
23586 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
23587 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
23588 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
23589 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
23590 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
23591 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
23592 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
23593 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
23594 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
23595 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
23596 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
23597 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
23598
23599 /* These may simplify to neg. */
23600 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
23601 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
23602
23603 #undef THUMB_VARIANT
23604 #define THUMB_VARIANT & arm_ext_os
23605
23606 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
23607 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
23608
23609 #undef THUMB_VARIANT
23610 #define THUMB_VARIANT & arm_ext_v6
23611
23612 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
23613
23614 /* V1 instructions with no Thumb analogue prior to V6T2. */
23615 #undef THUMB_VARIANT
23616 #define THUMB_VARIANT & arm_ext_v6t2
23617
23618 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
23619 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
23620 CL("teqp", 130f000, 2, (RR, SH), cmp),
23621
23622 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
23623 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
23624 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
23625 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
23626
23627 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23628 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23629
23630 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23631 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
23632
23633 /* V1 instructions with no Thumb analogue at all. */
23634 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
23635 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
23636
23637 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
23638 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
23639 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
23640 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
23641 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
23642 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
23643 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
23644 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
23645
23646 #undef ARM_VARIANT
23647 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
23648 #undef THUMB_VARIANT
23649 #define THUMB_VARIANT & arm_ext_v4t
23650
23651 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
23652 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
23653
23654 #undef THUMB_VARIANT
23655 #define THUMB_VARIANT & arm_ext_v6t2
23656
23657 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
23658 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
23659
23660 /* Generic coprocessor instructions. */
23661 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
23662 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23663 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23664 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23665 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23666 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
23667 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
23668
23669 #undef ARM_VARIANT
23670 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
23671
23672 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
23673 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
23674
23675 #undef ARM_VARIANT
23676 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
23677 #undef THUMB_VARIANT
23678 #define THUMB_VARIANT & arm_ext_msr
23679
23680 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
23681 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
23682
23683 #undef ARM_VARIANT
23684 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
23685 #undef THUMB_VARIANT
23686 #define THUMB_VARIANT & arm_ext_v6t2
23687
23688 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23689 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23690 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23691 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23692 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23693 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23694 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
23695 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
23696
23697 #undef ARM_VARIANT
23698 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
23699 #undef THUMB_VARIANT
23700 #define THUMB_VARIANT & arm_ext_v4t
23701
23702 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23703 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23704 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23705 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23706 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23707 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
23708
23709 #undef ARM_VARIANT
23710 #define ARM_VARIANT & arm_ext_v4t_5
23711
23712 /* ARM Architecture 4T. */
23713 /* Note: bx (and blx) are required on V5, even if the processor does
23714 not support Thumb. */
23715 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
23716
23717 #undef ARM_VARIANT
23718 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
23719 #undef THUMB_VARIANT
23720 #define THUMB_VARIANT & arm_ext_v5t
23721
23722 /* Note: blx has 2 variants; the .value coded here is for
23723 BLX(2). Only this variant has conditional execution. */
23724 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
23725 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
23726
23727 #undef THUMB_VARIANT
23728 #define THUMB_VARIANT & arm_ext_v6t2
23729
23730 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
23731 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23732 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23733 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23734 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
23735 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
23736 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
23737 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
23738
23739 #undef ARM_VARIANT
23740 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
23741 #undef THUMB_VARIANT
23742 #define THUMB_VARIANT & arm_ext_v5exp
23743
23744 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23745 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23746 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23747 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23748
23749 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23750 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
23751
23752 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23753 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23754 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23755 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
23756
23757 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23758 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23759 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23760 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23761
23762 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23763 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23764
23765 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23766 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23767 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23768 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
23769
23770 #undef ARM_VARIANT
23771 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
23772 #undef THUMB_VARIANT
23773 #define THUMB_VARIANT & arm_ext_v6t2
23774
23775 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
23776 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
23777 ldrd, t_ldstd),
23778 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
23779 ADDRGLDRS), ldrd, t_ldstd),
23780
23781 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
23782 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
23783
23784 #undef ARM_VARIANT
23785 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
23786
23787 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
23788
23789 #undef ARM_VARIANT
23790 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
23791 #undef THUMB_VARIANT
23792 #define THUMB_VARIANT & arm_ext_v6
23793
23794 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
23795 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
23796 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23797 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23798 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
23799 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23800 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23801 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23802 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23803 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
23804
23805 #undef THUMB_VARIANT
23806 #define THUMB_VARIANT & arm_ext_v6t2_v8m
23807
23808 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
23809 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
23810 strex, t_strex),
23811 #undef THUMB_VARIANT
23812 #define THUMB_VARIANT & arm_ext_v6t2
23813
23814 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
23815 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
23816
23817 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
23818 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
23819
23820 /* ARM V6 not included in V7M. */
23821 #undef THUMB_VARIANT
23822 #define THUMB_VARIANT & arm_ext_v6_notm
23823 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
23824 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
23825 UF(rfeib, 9900a00, 1, (RRw), rfe),
23826 UF(rfeda, 8100a00, 1, (RRw), rfe),
23827 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
23828 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
23829 UF(rfefa, 8100a00, 1, (RRw), rfe),
23830 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
23831 UF(rfeed, 9900a00, 1, (RRw), rfe),
23832 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
23833 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
23834 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
23835 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
23836 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
23837 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
23838 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
23839 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
23840 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
23841 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
23842
23843 /* ARM V6 not included in V7M (eg. integer SIMD). */
23844 #undef THUMB_VARIANT
23845 #define THUMB_VARIANT & arm_ext_v6_dsp
23846 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
23847 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
23848 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23849 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23850 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23851 /* Old name for QASX. */
23852 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23853 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23854 /* Old name for QSAX. */
23855 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23856 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23857 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23858 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23859 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23860 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23861 /* Old name for SASX. */
23862 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23863 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23864 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23865 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23866 /* Old name for SHASX. */
23867 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23868 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23869 /* Old name for SHSAX. */
23870 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23871 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23872 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23873 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23874 /* Old name for SSAX. */
23875 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23876 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23877 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23878 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23879 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23880 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23881 /* Old name for UASX. */
23882 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23883 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23884 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23885 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23886 /* Old name for UHASX. */
23887 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23888 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23889 /* Old name for UHSAX. */
23890 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23891 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23892 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23893 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23894 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23895 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23896 /* Old name for UQASX. */
23897 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23898 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23899 /* Old name for UQSAX. */
23900 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23901 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23902 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23903 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23904 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23905 /* Old name for USAX. */
23906 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23907 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23908 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23909 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23910 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23911 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23912 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23913 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23914 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
23915 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
23916 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
23917 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23918 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23919 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23920 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23921 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23922 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23923 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23924 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
23925 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23926 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23927 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23928 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23929 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23930 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23931 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23932 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23933 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23934 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23935 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
23936 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
23937 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
23938 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
23939 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
23940
23941 #undef ARM_VARIANT
23942 #define ARM_VARIANT & arm_ext_v6k_v6t2
23943 #undef THUMB_VARIANT
23944 #define THUMB_VARIANT & arm_ext_v6k_v6t2
23945
23946 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
23947 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
23948 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
23949 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
23950
23951 #undef THUMB_VARIANT
23952 #define THUMB_VARIANT & arm_ext_v6_notm
23953 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
23954 ldrexd, t_ldrexd),
23955 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
23956 RRnpcb), strexd, t_strexd),
23957
23958 #undef THUMB_VARIANT
23959 #define THUMB_VARIANT & arm_ext_v6t2_v8m
23960 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
23961 rd_rn, rd_rn),
23962 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
23963 rd_rn, rd_rn),
23964 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
23965 strex, t_strexbh),
23966 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
23967 strex, t_strexbh),
23968 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
23969
23970 #undef ARM_VARIANT
23971 #define ARM_VARIANT & arm_ext_sec
23972 #undef THUMB_VARIANT
23973 #define THUMB_VARIANT & arm_ext_sec
23974
23975 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
23976
23977 #undef ARM_VARIANT
23978 #define ARM_VARIANT & arm_ext_virt
23979 #undef THUMB_VARIANT
23980 #define THUMB_VARIANT & arm_ext_virt
23981
23982 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
23983 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
23984
23985 #undef ARM_VARIANT
23986 #define ARM_VARIANT & arm_ext_pan
23987 #undef THUMB_VARIANT
23988 #define THUMB_VARIANT & arm_ext_pan
23989
23990 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
23991
23992 #undef ARM_VARIANT
23993 #define ARM_VARIANT & arm_ext_v6t2
23994 #undef THUMB_VARIANT
23995 #define THUMB_VARIANT & arm_ext_v6t2
23996
23997 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
23998 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
23999 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24000 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
24001
24002 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
24003 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
24004
24005 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24006 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24007 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24008 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
24009
24010 #undef ARM_VARIANT
24011 #define ARM_VARIANT & arm_ext_v3
24012 #undef THUMB_VARIANT
24013 #define THUMB_VARIANT & arm_ext_v6t2
24014
24015 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
24016 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
24017 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
24018
24019 #undef ARM_VARIANT
24020 #define ARM_VARIANT & arm_ext_v6t2
24021 #undef THUMB_VARIANT
24022 #define THUMB_VARIANT & arm_ext_v6t2_v8m
24023 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
24024 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
24025
24026 /* Thumb-only instructions. */
24027 #undef ARM_VARIANT
24028 #define ARM_VARIANT NULL
24029 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
24030 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
24031
24032 /* ARM does not really have an IT instruction, so always allow it.
24033 The opcode is copied from Thumb in order to allow warnings in
24034 -mimplicit-it=[never | arm] modes. */
24035 #undef ARM_VARIANT
24036 #define ARM_VARIANT & arm_ext_v1
24037 #undef THUMB_VARIANT
24038 #define THUMB_VARIANT & arm_ext_v6t2
24039
24040 TUE("it", bf08, bf08, 1, (COND), it, t_it),
24041 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
24042 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
24043 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
24044 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
24045 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
24046 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
24047 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
24048 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
24049 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
24050 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
24051 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
24052 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
24053 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
24054 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
24055 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
24056 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
24057 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
24058
24059 /* Thumb2 only instructions. */
24060 #undef ARM_VARIANT
24061 #define ARM_VARIANT NULL
24062
24063 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24064 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
24065 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
24066 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
24067 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
24068 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
24069
24070 /* Hardware division instructions. */
24071 #undef ARM_VARIANT
24072 #define ARM_VARIANT & arm_ext_adiv
24073 #undef THUMB_VARIANT
24074 #define THUMB_VARIANT & arm_ext_div
24075
24076 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
24077 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
24078
24079 /* ARM V6M/V7 instructions. */
24080 #undef ARM_VARIANT
24081 #define ARM_VARIANT & arm_ext_barrier
24082 #undef THUMB_VARIANT
24083 #define THUMB_VARIANT & arm_ext_barrier
24084
24085 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
24086 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
24087 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
24088
24089 /* ARM V7 instructions. */
24090 #undef ARM_VARIANT
24091 #define ARM_VARIANT & arm_ext_v7
24092 #undef THUMB_VARIANT
24093 #define THUMB_VARIANT & arm_ext_v7
24094
24095 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
24096 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
24097
24098 #undef ARM_VARIANT
24099 #define ARM_VARIANT & arm_ext_mp
24100 #undef THUMB_VARIANT
24101 #define THUMB_VARIANT & arm_ext_mp
24102
24103 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
24104
24105 /* AArchv8 instructions. */
24106 #undef ARM_VARIANT
24107 #define ARM_VARIANT & arm_ext_v8
24108
24109 /* Instructions shared between armv8-a and armv8-m. */
24110 #undef THUMB_VARIANT
24111 #define THUMB_VARIANT & arm_ext_atomics
24112
24113 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24114 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24115 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24116 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24117 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24118 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
24119 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24120 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
24121 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
24122 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
24123 stlex, t_stlex),
24124 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
24125 stlex, t_stlex),
24126 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
24127 stlex, t_stlex),
24128 #undef THUMB_VARIANT
24129 #define THUMB_VARIANT & arm_ext_v8
24130
24131 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
24132 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
24133 ldrexd, t_ldrexd),
24134 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
24135 strexd, t_strexd),
24136
24137 /* Defined in V8 but is in undefined encoding space for earlier
24138 architectures. However earlier architectures are required to treat
24139 this instuction as a semihosting trap as well. Hence while not explicitly
24140 defined as such, it is in fact correct to define the instruction for all
24141 architectures. */
24142 #undef THUMB_VARIANT
24143 #define THUMB_VARIANT & arm_ext_v1
24144 #undef ARM_VARIANT
24145 #define ARM_VARIANT & arm_ext_v1
24146 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
24147
24148 /* ARMv8 T32 only. */
24149 #undef ARM_VARIANT
24150 #define ARM_VARIANT NULL
24151 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
24152 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
24153 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
24154
24155 /* FP for ARMv8. */
24156 #undef ARM_VARIANT
24157 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
24158 #undef THUMB_VARIANT
24159 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
24160
24161 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
24162 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
24163 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
24164 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
24165 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
24166 mnCE(vrintz, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintz),
24167 mnCE(vrintx, _vrintr, 2, (RNSDQMQ, oRNSDQMQ), vrintx),
24168 mnUF(vrinta, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrinta),
24169 mnUF(vrintn, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintn),
24170 mnUF(vrintp, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintp),
24171 mnUF(vrintm, _vrinta, 2, (RNSDQMQ, oRNSDQMQ), vrintm),
24172
24173 /* Crypto v1 extensions. */
24174 #undef ARM_VARIANT
24175 #define ARM_VARIANT & fpu_crypto_ext_armv8
24176 #undef THUMB_VARIANT
24177 #define THUMB_VARIANT & fpu_crypto_ext_armv8
24178
24179 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
24180 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
24181 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
24182 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
24183 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
24184 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
24185 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
24186 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
24187 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
24188 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
24189 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
24190 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
24191 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
24192 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
24193
24194 #undef ARM_VARIANT
24195 #define ARM_VARIANT & crc_ext_armv8
24196 #undef THUMB_VARIANT
24197 #define THUMB_VARIANT & crc_ext_armv8
24198 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
24199 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
24200 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
24201 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
24202 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
24203 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
24204
24205 /* ARMv8.2 RAS extension. */
24206 #undef ARM_VARIANT
24207 #define ARM_VARIANT & arm_ext_ras
24208 #undef THUMB_VARIANT
24209 #define THUMB_VARIANT & arm_ext_ras
24210 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
24211
24212 #undef ARM_VARIANT
24213 #define ARM_VARIANT & arm_ext_v8_3
24214 #undef THUMB_VARIANT
24215 #define THUMB_VARIANT & arm_ext_v8_3
24216 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
24217
24218 #undef ARM_VARIANT
24219 #define ARM_VARIANT & fpu_neon_ext_dotprod
24220 #undef THUMB_VARIANT
24221 #define THUMB_VARIANT & fpu_neon_ext_dotprod
24222 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
24223 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
24224
24225 #undef ARM_VARIANT
24226 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
24227 #undef THUMB_VARIANT
24228 #define THUMB_VARIANT NULL
24229
24230 cCE("wfs", e200110, 1, (RR), rd),
24231 cCE("rfs", e300110, 1, (RR), rd),
24232 cCE("wfc", e400110, 1, (RR), rd),
24233 cCE("rfc", e500110, 1, (RR), rd),
24234
24235 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
24236 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
24237 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
24238 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
24239
24240 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
24241 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
24242 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
24243 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
24244
24245 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
24246 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
24247 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
24248 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
24249 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
24250 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
24251 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
24252 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
24253 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
24254 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
24255 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
24256 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
24257
24258 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
24259 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
24260 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
24261 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
24262 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
24263 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
24264 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
24265 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
24266 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
24267 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
24268 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
24269 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
24270
24271 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
24272 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
24273 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
24274 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
24275 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
24276 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
24277 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
24278 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
24279 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
24280 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
24281 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
24282 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
24283
24284 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
24285 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
24286 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
24287 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
24288 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
24289 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
24290 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
24291 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
24292 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
24293 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
24294 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
24295 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
24296
24297 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
24298 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
24299 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
24300 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
24301 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
24302 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
24303 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
24304 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
24305 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
24306 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
24307 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
24308 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
24309
24310 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
24311 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
24312 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
24313 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
24314 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
24315 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
24316 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
24317 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
24318 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
24319 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
24320 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
24321 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
24322
24323 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
24324 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
24325 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
24326 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
24327 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
24328 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
24329 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
24330 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
24331 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
24332 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
24333 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
24334 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
24335
24336 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
24337 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
24338 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
24339 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
24340 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
24341 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
24342 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
24343 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
24344 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
24345 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
24346 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
24347 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
24348
24349 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
24350 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
24351 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
24352 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
24353 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
24354 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
24355 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
24356 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
24357 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
24358 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
24359 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
24360 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
24361
24362 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
24363 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
24364 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
24365 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
24366 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
24367 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
24368 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
24369 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
24370 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
24371 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
24372 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
24373 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
24374
24375 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
24376 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
24377 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
24378 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
24379 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
24380 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
24381 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
24382 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
24383 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
24384 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
24385 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
24386 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
24387
24388 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
24389 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
24390 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
24391 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
24392 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
24393 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
24394 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
24395 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
24396 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
24397 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
24398 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
24399 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
24400
24401 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
24402 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
24403 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
24404 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
24405 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
24406 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
24407 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
24408 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
24409 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
24410 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
24411 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
24412 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
24413
24414 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
24415 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
24416 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
24417 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
24418 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
24419 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
24420 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
24421 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
24422 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
24423 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
24424 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
24425 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
24426
24427 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
24428 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
24429 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
24430 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
24431 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
24432 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
24433 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
24434 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
24435 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
24436 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
24437 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
24438 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
24439
24440 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
24441 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
24442 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
24443 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
24444 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
24445 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
24446 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
24447 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
24448 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
24449 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
24450 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
24451 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
24452
24453 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
24454 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
24455 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
24456 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
24457 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
24458 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24459 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24460 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24461 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
24462 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
24463 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
24464 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
24465
24466 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
24467 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
24468 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
24469 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
24470 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
24471 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24472 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24473 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24474 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
24475 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
24476 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
24477 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
24478
24479 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
24480 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
24481 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
24482 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
24483 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
24484 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24485 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24486 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24487 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
24488 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
24489 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
24490 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
24491
24492 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
24493 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
24494 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
24495 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
24496 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
24497 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24498 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24499 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24500 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
24501 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
24502 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
24503 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
24504
24505 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
24506 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
24507 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
24508 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
24509 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
24510 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24511 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24512 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24513 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
24514 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
24515 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
24516 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
24517
24518 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
24519 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
24520 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
24521 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
24522 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
24523 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24524 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24525 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24526 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
24527 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
24528 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
24529 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
24530
24531 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
24532 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
24533 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
24534 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
24535 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
24536 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24537 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24538 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24539 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
24540 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
24541 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
24542 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
24543
24544 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
24545 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
24546 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
24547 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
24548 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
24549 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24550 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24551 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24552 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
24553 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
24554 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
24555 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
24556
24557 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
24558 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
24559 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
24560 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
24561 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
24562 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24563 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24564 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24565 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
24566 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
24567 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
24568 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
24569
24570 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
24571 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
24572 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
24573 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
24574 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
24575 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24576 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24577 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24578 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
24579 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
24580 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
24581 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
24582
24583 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24584 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24585 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24586 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24587 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24588 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24589 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24590 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24591 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24592 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24593 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24594 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24595
24596 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24597 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24598 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24599 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24600 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24601 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24602 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24603 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24604 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24605 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24606 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24607 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24608
24609 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
24610 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
24611 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
24612 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
24613 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
24614 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
24615 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
24616 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
24617 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
24618 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
24619 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
24620 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
24621
24622 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
24623 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
24624 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
24625 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
24626
24627 cCL("flts", e000110, 2, (RF, RR), rn_rd),
24628 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
24629 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
24630 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
24631 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
24632 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
24633 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
24634 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
24635 cCL("flte", e080110, 2, (RF, RR), rn_rd),
24636 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
24637 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
24638 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
24639
24640 /* The implementation of the FIX instruction is broken on some
24641 assemblers, in that it accepts a precision specifier as well as a
24642 rounding specifier, despite the fact that this is meaningless.
24643 To be more compatible, we accept it as well, though of course it
24644 does not set any bits. */
24645 cCE("fix", e100110, 2, (RR, RF), rd_rm),
24646 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
24647 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
24648 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
24649 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
24650 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
24651 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
24652 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
24653 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
24654 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
24655 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
24656 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
24657 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
24658
24659 /* Instructions that were new with the real FPA, call them V2. */
24660 #undef ARM_VARIANT
24661 #define ARM_VARIANT & fpu_fpa_ext_v2
24662
24663 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24664 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24665 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24666 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24667 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24668 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
24669
24670 #undef ARM_VARIANT
24671 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
24672 #undef THUMB_VARIANT
24673 #define THUMB_VARIANT & arm_ext_v6t2
24674 mcCE(vmrs, ef00a10, 2, (APSR_RR, RVC), vmrs),
24675 mcCE(vmsr, ee00a10, 2, (RVC, RR), vmsr),
24676 #undef THUMB_VARIANT
24677
24678 /* Moves and type conversions. */
24679 cCE("fmstat", ef1fa10, 0, (), noargs),
24680 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
24681 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
24682 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
24683 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
24684 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
24685 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
24686 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
24687 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
24688
24689 /* Memory operations. */
24690 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
24691 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
24692 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24693 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24694 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24695 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24696 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24697 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24698 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24699 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24700 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24701 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
24702 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24703 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
24704 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24705 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
24706 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24707 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
24708
24709 /* Monadic operations. */
24710 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
24711 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
24712 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
24713
24714 /* Dyadic operations. */
24715 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24716 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24717 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24718 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24719 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24720 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24721 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24722 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24723 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
24724
24725 /* Comparisons. */
24726 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
24727 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
24728 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
24729 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
24730
24731 /* Double precision load/store are still present on single precision
24732 implementations. */
24733 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
24734 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
24735 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24736 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24737 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24738 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24739 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24740 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
24741 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24742 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
24743
24744 #undef ARM_VARIANT
24745 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
24746
24747 /* Moves and type conversions. */
24748 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
24749 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24750 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
24751 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
24752 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
24753 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
24754 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
24755 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
24756 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
24757 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24758 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
24759 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
24760
24761 /* Monadic operations. */
24762 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24763 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
24764 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24765
24766 /* Dyadic operations. */
24767 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24768 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24769 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24770 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24771 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24772 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24773 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24774 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24775 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
24776
24777 /* Comparisons. */
24778 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
24779 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
24780 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
24781 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
24782
24783 /* Instructions which may belong to either the Neon or VFP instruction sets.
24784 Individual encoder functions perform additional architecture checks. */
24785 #undef ARM_VARIANT
24786 #define ARM_VARIANT & fpu_vfp_ext_v1xd
24787 #undef THUMB_VARIANT
24788 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
24789
24790 /* These mnemonics are unique to VFP. */
24791 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
24792 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
24793 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24794 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24795 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
24796 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
24797 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
24798 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
24799
24800 /* Mnemonics shared by Neon and VFP. */
24801 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
24802
24803 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24804 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24805 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24806 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24807 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24808 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
24809
24810 mnCEF(vcvt, _vcvt, 3, (RNSDQMQ, RNSDQMQ, oI32z), neon_cvt),
24811 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
24812 MNCEF(vcvtb, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtb),
24813 MNCEF(vcvtt, eb20a40, 3, (RVSDMQ, RVSDMQ, oI32b), neon_cvtt),
24814
24815
24816 /* NOTE: All VMOV encoding is special-cased! */
24817 NCE(vmovq, 0, 1, (VMOV), neon_mov),
24818
24819 #undef THUMB_VARIANT
24820 /* Could be either VLDR/VSTR or VLDR/VSTR (system register) which are guarded
24821 by different feature bits. Since we are setting the Thumb guard, we can
24822 require Thumb-1 which makes it a nop guard and set the right feature bit in
24823 do_vldr_vstr (). */
24824 #define THUMB_VARIANT & arm_ext_v4t
24825 NCE(vldr, d100b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
24826 NCE(vstr, d000b00, 2, (VLDR, ADDRGLDC), vldr_vstr),
24827
24828 #undef ARM_VARIANT
24829 #define ARM_VARIANT & arm_ext_fp16
24830 #undef THUMB_VARIANT
24831 #define THUMB_VARIANT & arm_ext_fp16
24832 /* New instructions added from v8.2, allowing the extraction and insertion of
24833 the upper 16 bits of a 32-bit vector register. */
24834 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
24835 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
24836
24837 /* New backported fma/fms instructions optional in v8.2. */
24838 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
24839 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
24840
24841 #undef THUMB_VARIANT
24842 #define THUMB_VARIANT & fpu_neon_ext_v1
24843 #undef ARM_VARIANT
24844 #define ARM_VARIANT & fpu_neon_ext_v1
24845
24846 /* Data processing with three registers of the same length. */
24847 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
24848 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
24849 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
24850 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
24851 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
24852 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
24853 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
24854 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
24855 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
24856 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
24857 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
24858 /* If not immediate, fall back to neon_dyadic_i64_su.
24859 shl should accept I8 I16 I32 I64,
24860 qshl should accept S8 S16 S32 S64 U8 U16 U32 U64. */
24861 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl),
24862 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl),
24863 /* Logic ops, types optional & ignored. */
24864 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
24865 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
24866 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
24867 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
24868 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
24869 /* Bitfield ops, untyped. */
24870 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24871 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
24872 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24873 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
24874 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
24875 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
24876 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
24877 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
24878 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
24879 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
24880 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
24881 back to neon_dyadic_if_su. */
24882 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
24883 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
24884 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
24885 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
24886 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
24887 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
24888 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
24889 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
24890 /* Comparison. Type I8 I16 I32 F32. */
24891 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
24892 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
24893 /* As above, D registers only. */
24894 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
24895 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
24896 /* Int and float variants, signedness unimportant. */
24897 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
24898 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
24899 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
24900 /* Add/sub take types I8 I16 I32 I64 F32. */
24901 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
24902 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
24903 /* vtst takes sizes 8, 16, 32. */
24904 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
24905 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
24906 /* VMUL takes I8 I16 I32 F32 P8. */
24907 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
24908 /* VQD{R}MULH takes S16 S32. */
24909 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
24910 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
24911 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
24912 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
24913 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
24914 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
24915 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
24916 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
24917 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
24918 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
24919 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
24920 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
24921 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
24922 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
24923 /* ARM v8.1 extension. */
24924 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
24925 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
24926 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
24927
24928 /* Two address, int/float. Types S8 S16 S32 F32. */
24929 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
24930 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
24931
24932 /* Data processing with two registers and a shift amount. */
24933 /* Right shifts, and variants with rounding.
24934 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
24935 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
24936 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
24937 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
24938 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
24939 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
24940 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
24941 /* Shift and insert. Sizes accepted 8 16 32 64. */
24942 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
24943 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
24944 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
24945 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
24946 /* Right shift immediate, saturating & narrowing, with rounding variants.
24947 Types accepted S16 S32 S64 U16 U32 U64. */
24948 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
24949 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
24950 /* As above, unsigned. Types accepted S16 S32 S64. */
24951 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
24952 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
24953 /* Right shift narrowing. Types accepted I16 I32 I64. */
24954 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
24955 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
24956 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
24957 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
24958 /* CVT with optional immediate for fixed-point variant. */
24959 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
24960
24961 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
24962
24963 /* Data processing, three registers of different lengths. */
24964 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
24965 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
24966 /* If not scalar, fall back to neon_dyadic_long.
24967 Vector types as above, scalar types S16 S32 U16 U32. */
24968 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
24969 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
24970 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
24971 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
24972 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
24973 /* Dyadic, narrowing insns. Types I16 I32 I64. */
24974 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24975 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24976 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24977 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
24978 /* Saturating doubling multiplies. Types S16 S32. */
24979 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
24980 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
24981 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
24982 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
24983 S16 S32 U16 U32. */
24984 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
24985
24986 /* Extract. Size 8. */
24987 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
24988 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
24989
24990 /* Two registers, miscellaneous. */
24991 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
24992 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
24993 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
24994 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
24995 /* Vector replicate. Sizes 8 16 32. */
24996 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
24997 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
24998 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
24999 /* VMOVN. Types I16 I32 I64. */
25000 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
25001 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
25002 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
25003 /* VQMOVUN. Types S16 S32 S64. */
25004 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
25005 /* VZIP / VUZP. Sizes 8 16 32. */
25006 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
25007 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
25008 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
25009 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
25010 /* VQABS / VQNEG. Types S8 S16 S32. */
25011 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
25012 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
25013 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
25014 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
25015 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
25016 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
25017 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
25018 /* Reciprocal estimates. Types U32 F16 F32. */
25019 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
25020 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
25021 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
25022 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
25023 /* VCLS. Types S8 S16 S32. */
25024 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
25025 /* VCLZ. Types I8 I16 I32. */
25026 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
25027 /* VCNT. Size 8. */
25028 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
25029 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
25030 /* Two address, untyped. */
25031 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
25032 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
25033 /* VTRN. Sizes 8 16 32. */
25034 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
25035 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
25036
25037 /* Table lookup. Size 8. */
25038 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25039 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
25040
25041 #undef THUMB_VARIANT
25042 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
25043 #undef ARM_VARIANT
25044 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
25045
25046 /* Neon element/structure load/store. */
25047 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25048 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
25049 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25050 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
25051 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25052 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
25053 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25054 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
25055
25056 #undef THUMB_VARIANT
25057 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
25058 #undef ARM_VARIANT
25059 #define ARM_VARIANT & fpu_vfp_ext_v3xd
25060 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
25061 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25062 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25063 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25064 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25065 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25066 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25067 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
25068 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
25069
25070 #undef THUMB_VARIANT
25071 #define THUMB_VARIANT & fpu_vfp_ext_v3
25072 #undef ARM_VARIANT
25073 #define ARM_VARIANT & fpu_vfp_ext_v3
25074
25075 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
25076 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25077 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25078 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25079 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25080 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25081 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25082 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
25083 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
25084
25085 #undef ARM_VARIANT
25086 #define ARM_VARIANT & fpu_vfp_ext_fma
25087 #undef THUMB_VARIANT
25088 #define THUMB_VARIANT & fpu_vfp_ext_fma
25089 /* Mnemonics shared by Neon, VFP and MVE. These are included in the
25090 VFP FMA variant; NEON and VFP FMA always includes the NEON
25091 FMA instructions. */
25092 mnCEF(vfma, _vfma, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_fmac),
25093 mnCEF(vfms, _vfms, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), neon_fmac),
25094
25095 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
25096 the v form should always be used. */
25097 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25098 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
25099 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25100 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
25101 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25102 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
25103
25104 #undef THUMB_VARIANT
25105 #undef ARM_VARIANT
25106 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
25107
25108 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25109 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25110 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25111 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25112 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25113 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
25114 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
25115 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
25116
25117 #undef ARM_VARIANT
25118 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
25119
25120 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
25121 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
25122 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
25123 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
25124 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
25125 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
25126 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
25127 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
25128 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
25129 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25130 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25131 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
25132 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25133 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25134 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
25135 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25136 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25137 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
25138 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
25139 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
25140 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25141 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25142 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25143 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25144 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25145 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
25146 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
25147 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
25148 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
25149 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
25150 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
25151 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
25152 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
25153 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
25154 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
25155 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
25156 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
25157 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25158 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25159 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25160 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25161 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25162 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25163 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25164 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25165 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25166 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
25167 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25168 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25169 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25170 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25171 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25172 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25173 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25174 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25175 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25176 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25177 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25178 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25179 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25180 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25181 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25182 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25183 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25184 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25185 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25186 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25187 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25188 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25189 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25190 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25191 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25192 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25193 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25194 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25195 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25196 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25197 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25198 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25199 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25200 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25201 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25202 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25203 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25204 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25205 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25206 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25207 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25208 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
25209 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25210 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25211 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25212 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25213 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25214 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25215 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25216 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25217 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25218 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25219 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25220 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25221 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25222 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25223 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25224 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25225 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25226 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25227 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25228 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25229 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25230 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
25231 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25232 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25233 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25234 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25235 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25236 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25237 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25238 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25239 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25240 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25241 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25242 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25243 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25244 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25245 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25246 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25247 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
25248 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
25249 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25250 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
25251 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
25252 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
25253 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25254 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25255 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25256 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25257 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25258 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25259 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25260 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25261 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25262 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
25263 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
25264 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
25265 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
25266 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
25267 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
25268 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25269 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25270 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25271 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
25272 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
25273 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
25274 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
25275 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
25276 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
25277 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25278 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25279 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25280 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25281 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
25282
25283 #undef ARM_VARIANT
25284 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
25285
25286 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
25287 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
25288 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
25289 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
25290 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
25291 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
25292 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25293 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25294 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25295 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25296 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25297 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25298 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25299 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25300 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25301 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25302 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25303 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25304 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25305 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25306 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
25307 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25308 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25309 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25310 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25311 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25312 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25313 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25314 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25315 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25316 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25317 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25318 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25319 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25320 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25321 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25322 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25323 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25324 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25325 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25326 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25327 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25328 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25329 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25330 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25331 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25332 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25333 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25334 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25335 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25336 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25337 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25338 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25339 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25340 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25341 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25342 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
25343
25344 #undef ARM_VARIANT
25345 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
25346
25347 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
25348 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
25349 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
25350 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
25351 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
25352 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
25353 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
25354 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
25355 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
25356 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
25357 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
25358 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
25359 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
25360 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
25361 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
25362 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
25363 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
25364 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
25365 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
25366 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
25367 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
25368 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
25369 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
25370 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
25371 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
25372 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
25373 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
25374 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
25375 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
25376 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
25377 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
25378 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
25379 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
25380 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
25381 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
25382 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
25383 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
25384 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
25385 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
25386 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
25387 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
25388 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
25389 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
25390 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
25391 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
25392 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
25393 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
25394 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
25395 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
25396 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
25397 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
25398 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
25399 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
25400 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
25401 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
25402 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
25403 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
25404 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
25405 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
25406 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
25407 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
25408 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
25409 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
25410 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
25411 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25412 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25413 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25414 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25415 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25416 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
25417 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25418 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
25419 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
25420 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
25421 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
25422 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
25423
25424 /* ARMv8.5-A instructions. */
25425 #undef ARM_VARIANT
25426 #define ARM_VARIANT & arm_ext_sb
25427 #undef THUMB_VARIANT
25428 #define THUMB_VARIANT & arm_ext_sb
25429 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
25430
25431 #undef ARM_VARIANT
25432 #define ARM_VARIANT & arm_ext_predres
25433 #undef THUMB_VARIANT
25434 #define THUMB_VARIANT & arm_ext_predres
25435 CE("cfprctx", e070f93, 1, (RRnpc), rd),
25436 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
25437 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
25438
25439 /* ARMv8-M instructions. */
25440 #undef ARM_VARIANT
25441 #define ARM_VARIANT NULL
25442 #undef THUMB_VARIANT
25443 #define THUMB_VARIANT & arm_ext_v8m
25444 ToU("sg", e97fe97f, 0, (), noargs),
25445 ToC("blxns", 4784, 1, (RRnpc), t_blx),
25446 ToC("bxns", 4704, 1, (RRnpc), t_bx),
25447 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
25448 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
25449 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
25450 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
25451
25452 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
25453 instructions behave as nop if no VFP is present. */
25454 #undef THUMB_VARIANT
25455 #define THUMB_VARIANT & arm_ext_v8m_main
25456 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
25457 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
25458
25459 /* Armv8.1-M Mainline instructions. */
25460 #undef THUMB_VARIANT
25461 #define THUMB_VARIANT & arm_ext_v8_1m_main
25462 toU("cinc", _cinc, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25463 toU("cinv", _cinv, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25464 toU("cneg", _cneg, 3, (RRnpcsp, RR_ZR, COND), t_cond),
25465 toU("csel", _csel, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25466 toU("csetm", _csetm, 2, (RRnpcsp, COND), t_cond),
25467 toU("cset", _cset, 2, (RRnpcsp, COND), t_cond),
25468 toU("csinc", _csinc, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25469 toU("csinv", _csinv, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25470 toU("csneg", _csneg, 4, (RRnpcsp, RR_ZR, RR_ZR, COND), t_cond),
25471
25472 toC("bf", _bf, 2, (EXPs, EXPs), t_branch_future),
25473 toU("bfcsel", _bfcsel, 4, (EXPs, EXPs, EXPs, COND), t_branch_future),
25474 toC("bfx", _bfx, 2, (EXPs, RRnpcsp), t_branch_future),
25475 toC("bfl", _bfl, 2, (EXPs, EXPs), t_branch_future),
25476 toC("bflx", _bflx, 2, (EXPs, RRnpcsp), t_branch_future),
25477
25478 toU("dls", _dls, 2, (LR, RRnpcsp), t_loloop),
25479 toU("wls", _wls, 3, (LR, RRnpcsp, EXP), t_loloop),
25480 toU("le", _le, 2, (oLR, EXP), t_loloop),
25481
25482 ToC("clrm", e89f0000, 1, (CLRMLST), t_clrm),
25483 ToC("vscclrm", ec9f0a00, 1, (VRSDVLST), t_vscclrm),
25484
25485 #undef THUMB_VARIANT
25486 #define THUMB_VARIANT & mve_ext
25487 ToC("lsll", ea50010d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
25488 ToC("lsrl", ea50011f, 3, (RRe, RRo, I32), mve_scalar_shift),
25489 ToC("asrl", ea50012d, 3, (RRe, RRo, RRnpcsp_I32), mve_scalar_shift),
25490 ToC("uqrshll", ea51010d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
25491 ToC("sqrshrl", ea51012d, 4, (RRe, RRo, I48_I64, RRnpcsp), mve_scalar_shift1),
25492 ToC("uqshll", ea51010f, 3, (RRe, RRo, I32), mve_scalar_shift),
25493 ToC("urshrl", ea51011f, 3, (RRe, RRo, I32), mve_scalar_shift),
25494 ToC("srshrl", ea51012f, 3, (RRe, RRo, I32), mve_scalar_shift),
25495 ToC("sqshll", ea51013f, 3, (RRe, RRo, I32), mve_scalar_shift),
25496 ToC("uqrshl", ea500f0d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
25497 ToC("sqrshr", ea500f2d, 2, (RRnpcsp, RRnpcsp), mve_scalar_shift),
25498 ToC("uqshl", ea500f0f, 2, (RRnpcsp, I32), mve_scalar_shift),
25499 ToC("urshr", ea500f1f, 2, (RRnpcsp, I32), mve_scalar_shift),
25500 ToC("srshr", ea500f2f, 2, (RRnpcsp, I32), mve_scalar_shift),
25501 ToC("sqshl", ea500f3f, 2, (RRnpcsp, I32), mve_scalar_shift),
25502
25503 ToC("vpt", ee410f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25504 ToC("vptt", ee018f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25505 ToC("vpte", ee418f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25506 ToC("vpttt", ee014f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25507 ToC("vptte", ee01cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25508 ToC("vptet", ee41cf00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25509 ToC("vptee", ee414f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25510 ToC("vptttt", ee012f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25511 ToC("vpttte", ee016f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25512 ToC("vpttet", ee01ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25513 ToC("vpttee", ee01af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25514 ToC("vptett", ee41af00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25515 ToC("vptete", ee41ef00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25516 ToC("vpteet", ee416f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25517 ToC("vpteee", ee412f00, 3, (COND, RMQ, RMQRZ), mve_vpt),
25518
25519 ToC("vpst", fe710f4d, 0, (), mve_vpt),
25520 ToC("vpstt", fe318f4d, 0, (), mve_vpt),
25521 ToC("vpste", fe718f4d, 0, (), mve_vpt),
25522 ToC("vpsttt", fe314f4d, 0, (), mve_vpt),
25523 ToC("vpstte", fe31cf4d, 0, (), mve_vpt),
25524 ToC("vpstet", fe71cf4d, 0, (), mve_vpt),
25525 ToC("vpstee", fe714f4d, 0, (), mve_vpt),
25526 ToC("vpstttt", fe312f4d, 0, (), mve_vpt),
25527 ToC("vpsttte", fe316f4d, 0, (), mve_vpt),
25528 ToC("vpsttet", fe31ef4d, 0, (), mve_vpt),
25529 ToC("vpsttee", fe31af4d, 0, (), mve_vpt),
25530 ToC("vpstett", fe71af4d, 0, (), mve_vpt),
25531 ToC("vpstete", fe71ef4d, 0, (), mve_vpt),
25532 ToC("vpsteet", fe716f4d, 0, (), mve_vpt),
25533 ToC("vpsteee", fe712f4d, 0, (), mve_vpt),
25534
25535 /* MVE and MVE FP only. */
25536 mToC("vhcadd", ee000f00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vhcadd),
25537 mCEF(vctp, _vctp, 1, (RRnpc), mve_vctp),
25538 mCEF(vadc, _vadc, 3, (RMQ, RMQ, RMQ), mve_vadc),
25539 mCEF(vadci, _vadci, 3, (RMQ, RMQ, RMQ), mve_vadc),
25540 mToC("vsbc", fe300f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
25541 mToC("vsbci", fe301f00, 3, (RMQ, RMQ, RMQ), mve_vsbc),
25542 mCEF(vmullb, _vmullb, 3, (RMQ, RMQ, RMQ), mve_vmull),
25543 mCEF(vabav, _vabav, 3, (RRnpcsp, RMQ, RMQ), mve_vabav),
25544 mCEF(vmladav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25545 mCEF(vmladava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25546 mCEF(vmladavx, _vmladavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
25547 mCEF(vmladavax, _vmladavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
25548 mCEF(vmlav, _vmladav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25549 mCEF(vmlava, _vmladava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25550 mCEF(vmlsdav, _vmlsdav, 3, (RRe, RMQ, RMQ), mve_vmladav),
25551 mCEF(vmlsdava, _vmlsdava, 3, (RRe, RMQ, RMQ), mve_vmladav),
25552 mCEF(vmlsdavx, _vmlsdavx, 3, (RRe, RMQ, RMQ), mve_vmladav),
25553 mCEF(vmlsdavax, _vmlsdavax, 3, (RRe, RMQ, RMQ), mve_vmladav),
25554
25555 mCEF(vst20, _vst20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25556 mCEF(vst21, _vst21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25557 mCEF(vst40, _vst40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25558 mCEF(vst41, _vst41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25559 mCEF(vst42, _vst42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25560 mCEF(vst43, _vst43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25561 mCEF(vld20, _vld20, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25562 mCEF(vld21, _vld21, 2, (MSTRLST2, ADDRMVE), mve_vst_vld),
25563 mCEF(vld40, _vld40, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25564 mCEF(vld41, _vld41, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25565 mCEF(vld42, _vld42, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25566 mCEF(vld43, _vld43, 2, (MSTRLST4, ADDRMVE), mve_vst_vld),
25567 mCEF(vstrb, _vstrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25568 mCEF(vstrh, _vstrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25569 mCEF(vstrw, _vstrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25570 mCEF(vstrd, _vstrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25571 mCEF(vldrb, _vldrb, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25572 mCEF(vldrh, _vldrh, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25573 mCEF(vldrw, _vldrw, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25574 mCEF(vldrd, _vldrd, 2, (RMQ, ADDRMVE), mve_vstr_vldr),
25575
25576 mCEF(vmovnt, _vmovnt, 2, (RMQ, RMQ), mve_movn),
25577 mCEF(vmovnb, _vmovnb, 2, (RMQ, RMQ), mve_movn),
25578 mCEF(vbrsr, _vbrsr, 3, (RMQ, RMQ, RR), mve_vbrsr),
25579 mCEF(vaddlv, _vaddlv, 3, (RRe, RRo, RMQ), mve_vaddlv),
25580 mCEF(vaddlva, _vaddlva, 3, (RRe, RRo, RMQ), mve_vaddlv),
25581 mCEF(vaddv, _vaddv, 2, (RRe, RMQ), mve_vaddv),
25582 mCEF(vaddva, _vaddva, 2, (RRe, RMQ), mve_vaddv),
25583 mCEF(vddup, _vddup, 3, (RMQ, RRe, EXPi), mve_viddup),
25584 mCEF(vdwdup, _vdwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
25585 mCEF(vidup, _vidup, 3, (RMQ, RRe, EXPi), mve_viddup),
25586 mCEF(viwdup, _viwdup, 4, (RMQ, RRe, RR, EXPi), mve_viddup),
25587 mToC("vmaxa", ee330e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
25588 mToC("vmina", ee331e81, 2, (RMQ, RMQ), mve_vmaxa_vmina),
25589 mCEF(vmaxv, _vmaxv, 2, (RR, RMQ), mve_vmaxv),
25590 mCEF(vmaxav, _vmaxav, 2, (RR, RMQ), mve_vmaxv),
25591 mCEF(vminv, _vminv, 2, (RR, RMQ), mve_vmaxv),
25592 mCEF(vminav, _vminav, 2, (RR, RMQ), mve_vmaxv),
25593
25594 mCEF(vmlaldav, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25595 mCEF(vmlaldava, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25596 mCEF(vmlaldavx, _vmlaldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25597 mCEF(vmlaldavax, _vmlaldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25598 mCEF(vmlalv, _vmlaldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25599 mCEF(vmlalva, _vmlaldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25600 mCEF(vmlsldav, _vmlsldav, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25601 mCEF(vmlsldava, _vmlsldava, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25602 mCEF(vmlsldavx, _vmlsldavx, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25603 mCEF(vmlsldavax, _vmlsldavax, 4, (RRe, RRo, RMQ, RMQ), mve_vmlaldav),
25604 mToC("vrmlaldavh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25605 mToC("vrmlaldavha",ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25606 mCEF(vrmlaldavhx, _vrmlaldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25607 mCEF(vrmlaldavhax, _vrmlaldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25608 mToC("vrmlalvh", ee800f00, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25609 mToC("vrmlalvha", ee800f20, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25610 mCEF(vrmlsldavh, _vrmlsldavh, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25611 mCEF(vrmlsldavha, _vrmlsldavha, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25612 mCEF(vrmlsldavhx, _vrmlsldavhx, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25613 mCEF(vrmlsldavhax, _vrmlsldavhax, 4, (RRe, RR, RMQ, RMQ), mve_vrmlaldavh),
25614
25615 mToC("vmlas", ee011e40, 3, (RMQ, RMQ, RR), mve_vmlas),
25616 mToC("vmulh", ee010e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
25617 mToC("vrmulh", ee011e01, 3, (RMQ, RMQ, RMQ), mve_vmulh),
25618 mToC("vpnot", fe310f4d, 0, (), mve_vpnot),
25619 mToC("vpsel", fe310f01, 3, (RMQ, RMQ, RMQ), mve_vpsel),
25620
25621 mToC("vqdmladh", ee000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25622 mToC("vqdmladhx", ee001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25623 mToC("vqrdmladh", ee000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25624 mToC("vqrdmladhx",ee001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25625 mToC("vqdmlsdh", fe000e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25626 mToC("vqdmlsdhx", fe001e00, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25627 mToC("vqrdmlsdh", fe000e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25628 mToC("vqrdmlsdhx",fe001e01, 3, (RMQ, RMQ, RMQ), mve_vqdmladh),
25629 mToC("vqdmlah", ee000e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25630 mToC("vqdmlash", ee001e60, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25631 mToC("vqrdmlash", ee001e40, 3, (RMQ, RMQ, RR), mve_vqdmlah),
25632 mToC("vqdmullt", ee301f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
25633 mToC("vqdmullb", ee300f00, 3, (RMQ, RMQ, RMQRR), mve_vqdmull),
25634 mCEF(vqmovnt, _vqmovnt, 2, (RMQ, RMQ), mve_vqmovn),
25635 mCEF(vqmovnb, _vqmovnb, 2, (RMQ, RMQ), mve_vqmovn),
25636 mCEF(vqmovunt, _vqmovunt, 2, (RMQ, RMQ), mve_vqmovn),
25637 mCEF(vqmovunb, _vqmovunb, 2, (RMQ, RMQ), mve_vqmovn),
25638
25639 mCEF(vshrnt, _vshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25640 mCEF(vshrnb, _vshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25641 mCEF(vrshrnt, _vrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25642 mCEF(vrshrnb, _vrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25643 mCEF(vqshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25644 mCEF(vqshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25645 mCEF(vqshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25646 mCEF(vqshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25647 mCEF(vqrshrnt, _vqrshrnt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25648 mCEF(vqrshrnb, _vqrshrnb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25649 mCEF(vqrshrunt, _vqrshrunt, 3, (RMQ, RMQ, I32z), mve_vshrn),
25650 mCEF(vqrshrunb, _vqrshrunb, 3, (RMQ, RMQ, I32z), mve_vshrn),
25651
25652 mToC("vshlc", eea00fc0, 3, (RMQ, RR, I32z), mve_vshlc),
25653 mToC("vshllt", ee201e00, 3, (RMQ, RMQ, I32), mve_vshll),
25654 mToC("vshllb", ee200e00, 3, (RMQ, RMQ, I32), mve_vshll),
25655
25656 toU("dlstp", _dlstp, 2, (LR, RR), t_loloop),
25657 toU("wlstp", _wlstp, 3, (LR, RR, EXP), t_loloop),
25658 toU("letp", _letp, 2, (LR, EXP), t_loloop),
25659 toU("lctp", _lctp, 0, (), t_loloop),
25660
25661 #undef THUMB_VARIANT
25662 #define THUMB_VARIANT & mve_fp_ext
25663 mToC("vcmul", ee300e00, 4, (RMQ, RMQ, RMQ, EXPi), mve_vcmul),
25664 mToC("vfmas", ee311e40, 3, (RMQ, RMQ, RR), mve_vfmas),
25665 mToC("vmaxnma", ee3f0e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
25666 mToC("vminnma", ee3f1e81, 2, (RMQ, RMQ), mve_vmaxnma_vminnma),
25667 mToC("vmaxnmv", eeee0f00, 2, (RR, RMQ), mve_vmaxnmv),
25668 mToC("vmaxnmav",eeec0f00, 2, (RR, RMQ), mve_vmaxnmv),
25669 mToC("vminnmv", eeee0f80, 2, (RR, RMQ), mve_vmaxnmv),
25670 mToC("vminnmav",eeec0f80, 2, (RR, RMQ), mve_vmaxnmv),
25671
25672 #undef ARM_VARIANT
25673 #define ARM_VARIANT & fpu_vfp_ext_v1
25674 #undef THUMB_VARIANT
25675 #define THUMB_VARIANT & arm_ext_v6t2
25676 mnCEF(vmla, _vmla, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mac_maybe_scalar),
25677 mnCEF(vmul, _vmul, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ_RR), neon_mul),
25678
25679 mcCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
25680
25681 #undef ARM_VARIANT
25682 #define ARM_VARIANT & fpu_vfp_ext_v1xd
25683
25684 MNCE(vmov, 0, 1, (VMOV), neon_mov),
25685 mcCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
25686 mcCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
25687 mcCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
25688
25689 mCEF(vmullt, _vmullt, 3, (RNSDQMQ, oRNSDQMQ, RNSDQ_RNSC_MQ), mve_vmull),
25690 mnCEF(vadd, _vadd, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
25691 mnCEF(vsub, _vsub, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQR), neon_addsub_if_i),
25692
25693 MNCEF(vabs, 1b10300, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
25694 MNCEF(vneg, 1b10380, 2, (RNSDQMQ, RNSDQMQ), neon_abs_neg),
25695
25696 mCEF(vmovlt, _vmovlt, 1, (VMOV), mve_movl),
25697 mCEF(vmovlb, _vmovlb, 1, (VMOV), mve_movl),
25698
25699 mnCE(vcmp, _vcmp, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
25700 mnCE(vcmpe, _vcmpe, 3, (RVSD_COND, RSVDMQ_FI0, oRMQRZ), vfp_nsyn_cmp),
25701
25702 #undef ARM_VARIANT
25703 #define ARM_VARIANT & fpu_vfp_ext_v2
25704
25705 mcCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
25706 mcCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
25707 mcCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
25708 mcCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
25709
25710 #undef ARM_VARIANT
25711 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
25712 mnUF(vcvta, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvta),
25713 mnUF(vcvtp, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtp),
25714 mnUF(vcvtn, _vcvta, 3, (RNSDQMQ, oRNSDQMQ, oI32z), neon_cvtn),
25715 mnUF(vcvtm, _vcvta, 2, (RNSDQMQ, oRNSDQMQ), neon_cvtm),
25716 mnUF(vmaxnm, _vmaxnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
25717 mnUF(vminnm, _vminnm, 3, (RNSDQMQ, oRNSDQMQ, RNSDQMQ), vmaxnm),
25718
25719 #undef ARM_VARIANT
25720 #define ARM_VARIANT & fpu_neon_ext_v1
25721 mnUF(vabd, _vabd, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
25722 mnUF(vabdl, _vabdl, 3, (RNQMQ, RNDMQ, RNDMQ), neon_dyadic_long),
25723 mnUF(vaddl, _vaddl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
25724 mnUF(vsubl, _vsubl, 3, (RNQMQ, RNDMQ, RNDMQR), neon_dyadic_long),
25725 mnUF(vand, _vand, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25726 mnUF(vbic, _vbic, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25727 mnUF(vorr, _vorr, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25728 mnUF(vorn, _vorn, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_Ibig), neon_logic),
25729 mnUF(veor, _veor, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_logic),
25730 MNUF(vcls, 1b00400, 2, (RNDQMQ, RNDQMQ), neon_cls),
25731 MNUF(vclz, 1b00480, 2, (RNDQMQ, RNDQMQ), neon_clz),
25732 mnCE(vdup, _vdup, 2, (RNDQMQ, RR_RNSC), neon_dup),
25733 MNUF(vhadd, 00000000, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
25734 MNUF(vrhadd, 00000100, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_i_su),
25735 MNUF(vhsub, 00000200, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i_su),
25736 mnUF(vmin, _vmin, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
25737 mnUF(vmax, _vmax, 3, (RNDQMQ, oRNDQMQ, RNDQMQ), neon_dyadic_if_su),
25738 MNUF(vqadd, 0000010, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
25739 MNUF(vqsub, 0000210, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_dyadic_i64_su),
25740 mnUF(vmvn, _vmvn, 2, (RNDQMQ, RNDQMQ_Ibig), neon_mvn),
25741 MNUF(vqabs, 1b00700, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
25742 MNUF(vqneg, 1b00780, 2, (RNDQMQ, RNDQMQ), neon_sat_abs_neg),
25743 mnUF(vqrdmlah, _vqrdmlah,3, (RNDQMQ, oRNDQMQ, RNDQ_RNSC_RR), neon_qrdmlah),
25744 mnUF(vqdmulh, _vqdmulh, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
25745 mnUF(vqrdmulh, _vqrdmulh,3, (RNDQMQ, oRNDQMQ, RNDQMQ_RNSC_RR), neon_qdmulh),
25746 MNUF(vqrshl, 0000510, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
25747 MNUF(vrshl, 0000500, 3, (RNDQMQ, oRNDQMQ, RNDQMQR), neon_rshl),
25748 MNUF(vshr, 0800010, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
25749 MNUF(vrshr, 0800210, 3, (RNDQMQ, oRNDQMQ, I64z), neon_rshift_round_imm),
25750 MNUF(vsli, 1800510, 3, (RNDQMQ, oRNDQMQ, I63), neon_sli),
25751 MNUF(vsri, 1800410, 3, (RNDQMQ, oRNDQMQ, I64z), neon_sri),
25752 MNUF(vrev64, 1b00000, 2, (RNDQMQ, RNDQMQ), neon_rev),
25753 MNUF(vrev32, 1b00080, 2, (RNDQMQ, RNDQMQ), neon_rev),
25754 MNUF(vrev16, 1b00100, 2, (RNDQMQ, RNDQMQ), neon_rev),
25755 mnUF(vshl, _vshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_shl),
25756 mnUF(vqshl, _vqshl, 3, (RNDQMQ, oRNDQMQ, RNDQMQ_I63b_RR), neon_qshl),
25757 MNUF(vqshlu, 1800610, 3, (RNDQMQ, oRNDQMQ, I63), neon_qshlu_imm),
25758
25759 #undef ARM_VARIANT
25760 #define ARM_VARIANT & arm_ext_v8_3
25761 #undef THUMB_VARIANT
25762 #define THUMB_VARIANT & arm_ext_v6t2_v8m
25763 MNUF (vcadd, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ, EXPi), vcadd),
25764 MNUF (vcmla, 0, 4, (RNDQMQ, RNDQMQ, RNDQMQ_RNSC, EXPi), vcmla),
25765 };
25766 #undef ARM_VARIANT
25767 #undef THUMB_VARIANT
25768 #undef TCE
25769 #undef TUE
25770 #undef TUF
25771 #undef TCC
25772 #undef cCE
25773 #undef cCL
25774 #undef C3E
25775 #undef C3
25776 #undef CE
25777 #undef CM
25778 #undef CL
25779 #undef UE
25780 #undef UF
25781 #undef UT
25782 #undef NUF
25783 #undef nUF
25784 #undef NCE
25785 #undef nCE
25786 #undef OPS0
25787 #undef OPS1
25788 #undef OPS2
25789 #undef OPS3
25790 #undef OPS4
25791 #undef OPS5
25792 #undef OPS6
25793 #undef do_0
25794 #undef ToC
25795 #undef toC
25796 #undef ToU
25797 #undef toU
25798 \f
25799 /* MD interface: bits in the object file. */
25800
25801 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
25802 for use in the a.out file, and stores them in the array pointed to by buf.
25803 This knows about the endian-ness of the target machine and does
25804 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
25805 2 (short) and 4 (long) Floating numbers are put out as a series of
25806 LITTLENUMS (shorts, here at least). */
25807
25808 void
25809 md_number_to_chars (char * buf, valueT val, int n)
25810 {
25811 if (target_big_endian)
25812 number_to_chars_bigendian (buf, val, n);
25813 else
25814 number_to_chars_littleendian (buf, val, n);
25815 }
25816
25817 static valueT
25818 md_chars_to_number (char * buf, int n)
25819 {
25820 valueT result = 0;
25821 unsigned char * where = (unsigned char *) buf;
25822
25823 if (target_big_endian)
25824 {
25825 while (n--)
25826 {
25827 result <<= 8;
25828 result |= (*where++ & 255);
25829 }
25830 }
25831 else
25832 {
25833 while (n--)
25834 {
25835 result <<= 8;
25836 result |= (where[n] & 255);
25837 }
25838 }
25839
25840 return result;
25841 }
25842
25843 /* MD interface: Sections. */
25844
25845 /* Calculate the maximum variable size (i.e., excluding fr_fix)
25846 that an rs_machine_dependent frag may reach. */
25847
25848 unsigned int
25849 arm_frag_max_var (fragS *fragp)
25850 {
25851 /* We only use rs_machine_dependent for variable-size Thumb instructions,
25852 which are either THUMB_SIZE (2) or INSN_SIZE (4).
25853
25854 Note that we generate relaxable instructions even for cases that don't
25855 really need it, like an immediate that's a trivial constant. So we're
25856 overestimating the instruction size for some of those cases. Rather
25857 than putting more intelligence here, it would probably be better to
25858 avoid generating a relaxation frag in the first place when it can be
25859 determined up front that a short instruction will suffice. */
25860
25861 gas_assert (fragp->fr_type == rs_machine_dependent);
25862 return INSN_SIZE;
25863 }
25864
25865 /* Estimate the size of a frag before relaxing. Assume everything fits in
25866 2 bytes. */
25867
25868 int
25869 md_estimate_size_before_relax (fragS * fragp,
25870 segT segtype ATTRIBUTE_UNUSED)
25871 {
25872 fragp->fr_var = 2;
25873 return 2;
25874 }
25875
25876 /* Convert a machine dependent frag. */
25877
25878 void
25879 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
25880 {
25881 unsigned long insn;
25882 unsigned long old_op;
25883 char *buf;
25884 expressionS exp;
25885 fixS *fixp;
25886 int reloc_type;
25887 int pc_rel;
25888 int opcode;
25889
25890 buf = fragp->fr_literal + fragp->fr_fix;
25891
25892 old_op = bfd_get_16(abfd, buf);
25893 if (fragp->fr_symbol)
25894 {
25895 exp.X_op = O_symbol;
25896 exp.X_add_symbol = fragp->fr_symbol;
25897 }
25898 else
25899 {
25900 exp.X_op = O_constant;
25901 }
25902 exp.X_add_number = fragp->fr_offset;
25903 opcode = fragp->fr_subtype;
25904 switch (opcode)
25905 {
25906 case T_MNEM_ldr_pc:
25907 case T_MNEM_ldr_pc2:
25908 case T_MNEM_ldr_sp:
25909 case T_MNEM_str_sp:
25910 case T_MNEM_ldr:
25911 case T_MNEM_ldrb:
25912 case T_MNEM_ldrh:
25913 case T_MNEM_str:
25914 case T_MNEM_strb:
25915 case T_MNEM_strh:
25916 if (fragp->fr_var == 4)
25917 {
25918 insn = THUMB_OP32 (opcode);
25919 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
25920 {
25921 insn |= (old_op & 0x700) << 4;
25922 }
25923 else
25924 {
25925 insn |= (old_op & 7) << 12;
25926 insn |= (old_op & 0x38) << 13;
25927 }
25928 insn |= 0x00000c00;
25929 put_thumb32_insn (buf, insn);
25930 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
25931 }
25932 else
25933 {
25934 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
25935 }
25936 pc_rel = (opcode == T_MNEM_ldr_pc2);
25937 break;
25938 case T_MNEM_adr:
25939 if (fragp->fr_var == 4)
25940 {
25941 insn = THUMB_OP32 (opcode);
25942 insn |= (old_op & 0xf0) << 4;
25943 put_thumb32_insn (buf, insn);
25944 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
25945 }
25946 else
25947 {
25948 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
25949 exp.X_add_number -= 4;
25950 }
25951 pc_rel = 1;
25952 break;
25953 case T_MNEM_mov:
25954 case T_MNEM_movs:
25955 case T_MNEM_cmp:
25956 case T_MNEM_cmn:
25957 if (fragp->fr_var == 4)
25958 {
25959 int r0off = (opcode == T_MNEM_mov
25960 || opcode == T_MNEM_movs) ? 0 : 8;
25961 insn = THUMB_OP32 (opcode);
25962 insn = (insn & 0xe1ffffff) | 0x10000000;
25963 insn |= (old_op & 0x700) << r0off;
25964 put_thumb32_insn (buf, insn);
25965 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
25966 }
25967 else
25968 {
25969 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
25970 }
25971 pc_rel = 0;
25972 break;
25973 case T_MNEM_b:
25974 if (fragp->fr_var == 4)
25975 {
25976 insn = THUMB_OP32(opcode);
25977 put_thumb32_insn (buf, insn);
25978 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
25979 }
25980 else
25981 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
25982 pc_rel = 1;
25983 break;
25984 case T_MNEM_bcond:
25985 if (fragp->fr_var == 4)
25986 {
25987 insn = THUMB_OP32(opcode);
25988 insn |= (old_op & 0xf00) << 14;
25989 put_thumb32_insn (buf, insn);
25990 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
25991 }
25992 else
25993 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
25994 pc_rel = 1;
25995 break;
25996 case T_MNEM_add_sp:
25997 case T_MNEM_add_pc:
25998 case T_MNEM_inc_sp:
25999 case T_MNEM_dec_sp:
26000 if (fragp->fr_var == 4)
26001 {
26002 /* ??? Choose between add and addw. */
26003 insn = THUMB_OP32 (opcode);
26004 insn |= (old_op & 0xf0) << 4;
26005 put_thumb32_insn (buf, insn);
26006 if (opcode == T_MNEM_add_pc)
26007 reloc_type = BFD_RELOC_ARM_T32_IMM12;
26008 else
26009 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26010 }
26011 else
26012 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26013 pc_rel = 0;
26014 break;
26015
26016 case T_MNEM_addi:
26017 case T_MNEM_addis:
26018 case T_MNEM_subi:
26019 case T_MNEM_subis:
26020 if (fragp->fr_var == 4)
26021 {
26022 insn = THUMB_OP32 (opcode);
26023 insn |= (old_op & 0xf0) << 4;
26024 insn |= (old_op & 0xf) << 16;
26025 put_thumb32_insn (buf, insn);
26026 if (insn & (1 << 20))
26027 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
26028 else
26029 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
26030 }
26031 else
26032 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
26033 pc_rel = 0;
26034 break;
26035 default:
26036 abort ();
26037 }
26038 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
26039 (enum bfd_reloc_code_real) reloc_type);
26040 fixp->fx_file = fragp->fr_file;
26041 fixp->fx_line = fragp->fr_line;
26042 fragp->fr_fix += fragp->fr_var;
26043
26044 /* Set whether we use thumb-2 ISA based on final relaxation results. */
26045 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
26046 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
26047 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
26048 }
26049
26050 /* Return the size of a relaxable immediate operand instruction.
26051 SHIFT and SIZE specify the form of the allowable immediate. */
26052 static int
26053 relax_immediate (fragS *fragp, int size, int shift)
26054 {
26055 offsetT offset;
26056 offsetT mask;
26057 offsetT low;
26058
26059 /* ??? Should be able to do better than this. */
26060 if (fragp->fr_symbol)
26061 return 4;
26062
26063 low = (1 << shift) - 1;
26064 mask = (1 << (shift + size)) - (1 << shift);
26065 offset = fragp->fr_offset;
26066 /* Force misaligned offsets to 32-bit variant. */
26067 if (offset & low)
26068 return 4;
26069 if (offset & ~mask)
26070 return 4;
26071 return 2;
26072 }
26073
26074 /* Get the address of a symbol during relaxation. */
26075 static addressT
26076 relaxed_symbol_addr (fragS *fragp, long stretch)
26077 {
26078 fragS *sym_frag;
26079 addressT addr;
26080 symbolS *sym;
26081
26082 sym = fragp->fr_symbol;
26083 sym_frag = symbol_get_frag (sym);
26084 know (S_GET_SEGMENT (sym) != absolute_section
26085 || sym_frag == &zero_address_frag);
26086 addr = S_GET_VALUE (sym) + fragp->fr_offset;
26087
26088 /* If frag has yet to be reached on this pass, assume it will
26089 move by STRETCH just as we did. If this is not so, it will
26090 be because some frag between grows, and that will force
26091 another pass. */
26092
26093 if (stretch != 0
26094 && sym_frag->relax_marker != fragp->relax_marker)
26095 {
26096 fragS *f;
26097
26098 /* Adjust stretch for any alignment frag. Note that if have
26099 been expanding the earlier code, the symbol may be
26100 defined in what appears to be an earlier frag. FIXME:
26101 This doesn't handle the fr_subtype field, which specifies
26102 a maximum number of bytes to skip when doing an
26103 alignment. */
26104 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
26105 {
26106 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
26107 {
26108 if (stretch < 0)
26109 stretch = - ((- stretch)
26110 & ~ ((1 << (int) f->fr_offset) - 1));
26111 else
26112 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
26113 if (stretch == 0)
26114 break;
26115 }
26116 }
26117 if (f != NULL)
26118 addr += stretch;
26119 }
26120
26121 return addr;
26122 }
26123
26124 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
26125 load. */
26126 static int
26127 relax_adr (fragS *fragp, asection *sec, long stretch)
26128 {
26129 addressT addr;
26130 offsetT val;
26131
26132 /* Assume worst case for symbols not known to be in the same section. */
26133 if (fragp->fr_symbol == NULL
26134 || !S_IS_DEFINED (fragp->fr_symbol)
26135 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26136 || S_IS_WEAK (fragp->fr_symbol))
26137 return 4;
26138
26139 val = relaxed_symbol_addr (fragp, stretch);
26140 addr = fragp->fr_address + fragp->fr_fix;
26141 addr = (addr + 4) & ~3;
26142 /* Force misaligned targets to 32-bit variant. */
26143 if (val & 3)
26144 return 4;
26145 val -= addr;
26146 if (val < 0 || val > 1020)
26147 return 4;
26148 return 2;
26149 }
26150
26151 /* Return the size of a relaxable add/sub immediate instruction. */
26152 static int
26153 relax_addsub (fragS *fragp, asection *sec)
26154 {
26155 char *buf;
26156 int op;
26157
26158 buf = fragp->fr_literal + fragp->fr_fix;
26159 op = bfd_get_16(sec->owner, buf);
26160 if ((op & 0xf) == ((op >> 4) & 0xf))
26161 return relax_immediate (fragp, 8, 0);
26162 else
26163 return relax_immediate (fragp, 3, 0);
26164 }
26165
26166 /* Return TRUE iff the definition of symbol S could be pre-empted
26167 (overridden) at link or load time. */
26168 static bfd_boolean
26169 symbol_preemptible (symbolS *s)
26170 {
26171 /* Weak symbols can always be pre-empted. */
26172 if (S_IS_WEAK (s))
26173 return TRUE;
26174
26175 /* Non-global symbols cannot be pre-empted. */
26176 if (! S_IS_EXTERNAL (s))
26177 return FALSE;
26178
26179 #ifdef OBJ_ELF
26180 /* In ELF, a global symbol can be marked protected, or private. In that
26181 case it can't be pre-empted (other definitions in the same link unit
26182 would violate the ODR). */
26183 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
26184 return FALSE;
26185 #endif
26186
26187 /* Other global symbols might be pre-empted. */
26188 return TRUE;
26189 }
26190
26191 /* Return the size of a relaxable branch instruction. BITS is the
26192 size of the offset field in the narrow instruction. */
26193
26194 static int
26195 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
26196 {
26197 addressT addr;
26198 offsetT val;
26199 offsetT limit;
26200
26201 /* Assume worst case for symbols not known to be in the same section. */
26202 if (!S_IS_DEFINED (fragp->fr_symbol)
26203 || sec != S_GET_SEGMENT (fragp->fr_symbol)
26204 || S_IS_WEAK (fragp->fr_symbol))
26205 return 4;
26206
26207 #ifdef OBJ_ELF
26208 /* A branch to a function in ARM state will require interworking. */
26209 if (S_IS_DEFINED (fragp->fr_symbol)
26210 && ARM_IS_FUNC (fragp->fr_symbol))
26211 return 4;
26212 #endif
26213
26214 if (symbol_preemptible (fragp->fr_symbol))
26215 return 4;
26216
26217 val = relaxed_symbol_addr (fragp, stretch);
26218 addr = fragp->fr_address + fragp->fr_fix + 4;
26219 val -= addr;
26220
26221 /* Offset is a signed value *2 */
26222 limit = 1 << bits;
26223 if (val >= limit || val < -limit)
26224 return 4;
26225 return 2;
26226 }
26227
26228
26229 /* Relax a machine dependent frag. This returns the amount by which
26230 the current size of the frag should change. */
26231
26232 int
26233 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
26234 {
26235 int oldsize;
26236 int newsize;
26237
26238 oldsize = fragp->fr_var;
26239 switch (fragp->fr_subtype)
26240 {
26241 case T_MNEM_ldr_pc2:
26242 newsize = relax_adr (fragp, sec, stretch);
26243 break;
26244 case T_MNEM_ldr_pc:
26245 case T_MNEM_ldr_sp:
26246 case T_MNEM_str_sp:
26247 newsize = relax_immediate (fragp, 8, 2);
26248 break;
26249 case T_MNEM_ldr:
26250 case T_MNEM_str:
26251 newsize = relax_immediate (fragp, 5, 2);
26252 break;
26253 case T_MNEM_ldrh:
26254 case T_MNEM_strh:
26255 newsize = relax_immediate (fragp, 5, 1);
26256 break;
26257 case T_MNEM_ldrb:
26258 case T_MNEM_strb:
26259 newsize = relax_immediate (fragp, 5, 0);
26260 break;
26261 case T_MNEM_adr:
26262 newsize = relax_adr (fragp, sec, stretch);
26263 break;
26264 case T_MNEM_mov:
26265 case T_MNEM_movs:
26266 case T_MNEM_cmp:
26267 case T_MNEM_cmn:
26268 newsize = relax_immediate (fragp, 8, 0);
26269 break;
26270 case T_MNEM_b:
26271 newsize = relax_branch (fragp, sec, 11, stretch);
26272 break;
26273 case T_MNEM_bcond:
26274 newsize = relax_branch (fragp, sec, 8, stretch);
26275 break;
26276 case T_MNEM_add_sp:
26277 case T_MNEM_add_pc:
26278 newsize = relax_immediate (fragp, 8, 2);
26279 break;
26280 case T_MNEM_inc_sp:
26281 case T_MNEM_dec_sp:
26282 newsize = relax_immediate (fragp, 7, 2);
26283 break;
26284 case T_MNEM_addi:
26285 case T_MNEM_addis:
26286 case T_MNEM_subi:
26287 case T_MNEM_subis:
26288 newsize = relax_addsub (fragp, sec);
26289 break;
26290 default:
26291 abort ();
26292 }
26293
26294 fragp->fr_var = newsize;
26295 /* Freeze wide instructions that are at or before the same location as
26296 in the previous pass. This avoids infinite loops.
26297 Don't freeze them unconditionally because targets may be artificially
26298 misaligned by the expansion of preceding frags. */
26299 if (stretch <= 0 && newsize > 2)
26300 {
26301 md_convert_frag (sec->owner, sec, fragp);
26302 frag_wane (fragp);
26303 }
26304
26305 return newsize - oldsize;
26306 }
26307
26308 /* Round up a section size to the appropriate boundary. */
26309
26310 valueT
26311 md_section_align (segT segment ATTRIBUTE_UNUSED,
26312 valueT size)
26313 {
26314 return size;
26315 }
26316
26317 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
26318 of an rs_align_code fragment. */
26319
26320 void
26321 arm_handle_align (fragS * fragP)
26322 {
26323 static unsigned char const arm_noop[2][2][4] =
26324 {
26325 { /* ARMv1 */
26326 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
26327 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
26328 },
26329 { /* ARMv6k */
26330 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
26331 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
26332 },
26333 };
26334 static unsigned char const thumb_noop[2][2][2] =
26335 {
26336 { /* Thumb-1 */
26337 {0xc0, 0x46}, /* LE */
26338 {0x46, 0xc0}, /* BE */
26339 },
26340 { /* Thumb-2 */
26341 {0x00, 0xbf}, /* LE */
26342 {0xbf, 0x00} /* BE */
26343 }
26344 };
26345 static unsigned char const wide_thumb_noop[2][4] =
26346 { /* Wide Thumb-2 */
26347 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
26348 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
26349 };
26350
26351 unsigned bytes, fix, noop_size;
26352 char * p;
26353 const unsigned char * noop;
26354 const unsigned char *narrow_noop = NULL;
26355 #ifdef OBJ_ELF
26356 enum mstate state;
26357 #endif
26358
26359 if (fragP->fr_type != rs_align_code)
26360 return;
26361
26362 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
26363 p = fragP->fr_literal + fragP->fr_fix;
26364 fix = 0;
26365
26366 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
26367 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
26368
26369 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
26370
26371 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
26372 {
26373 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
26374 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
26375 {
26376 narrow_noop = thumb_noop[1][target_big_endian];
26377 noop = wide_thumb_noop[target_big_endian];
26378 }
26379 else
26380 noop = thumb_noop[0][target_big_endian];
26381 noop_size = 2;
26382 #ifdef OBJ_ELF
26383 state = MAP_THUMB;
26384 #endif
26385 }
26386 else
26387 {
26388 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
26389 ? selected_cpu : arm_arch_none,
26390 arm_ext_v6k) != 0]
26391 [target_big_endian];
26392 noop_size = 4;
26393 #ifdef OBJ_ELF
26394 state = MAP_ARM;
26395 #endif
26396 }
26397
26398 fragP->fr_var = noop_size;
26399
26400 if (bytes & (noop_size - 1))
26401 {
26402 fix = bytes & (noop_size - 1);
26403 #ifdef OBJ_ELF
26404 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
26405 #endif
26406 memset (p, 0, fix);
26407 p += fix;
26408 bytes -= fix;
26409 }
26410
26411 if (narrow_noop)
26412 {
26413 if (bytes & noop_size)
26414 {
26415 /* Insert a narrow noop. */
26416 memcpy (p, narrow_noop, noop_size);
26417 p += noop_size;
26418 bytes -= noop_size;
26419 fix += noop_size;
26420 }
26421
26422 /* Use wide noops for the remainder */
26423 noop_size = 4;
26424 }
26425
26426 while (bytes >= noop_size)
26427 {
26428 memcpy (p, noop, noop_size);
26429 p += noop_size;
26430 bytes -= noop_size;
26431 fix += noop_size;
26432 }
26433
26434 fragP->fr_fix += fix;
26435 }
26436
26437 /* Called from md_do_align. Used to create an alignment
26438 frag in a code section. */
26439
26440 void
26441 arm_frag_align_code (int n, int max)
26442 {
26443 char * p;
26444
26445 /* We assume that there will never be a requirement
26446 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
26447 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
26448 {
26449 char err_msg[128];
26450
26451 sprintf (err_msg,
26452 _("alignments greater than %d bytes not supported in .text sections."),
26453 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
26454 as_fatal ("%s", err_msg);
26455 }
26456
26457 p = frag_var (rs_align_code,
26458 MAX_MEM_FOR_RS_ALIGN_CODE,
26459 1,
26460 (relax_substateT) max,
26461 (symbolS *) NULL,
26462 (offsetT) n,
26463 (char *) NULL);
26464 *p = 0;
26465 }
26466
26467 /* Perform target specific initialisation of a frag.
26468 Note - despite the name this initialisation is not done when the frag
26469 is created, but only when its type is assigned. A frag can be created
26470 and used a long time before its type is set, so beware of assuming that
26471 this initialisation is performed first. */
26472
26473 #ifndef OBJ_ELF
26474 void
26475 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
26476 {
26477 /* Record whether this frag is in an ARM or a THUMB area. */
26478 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
26479 }
26480
26481 #else /* OBJ_ELF is defined. */
26482 void
26483 arm_init_frag (fragS * fragP, int max_chars)
26484 {
26485 bfd_boolean frag_thumb_mode;
26486
26487 /* If the current ARM vs THUMB mode has not already
26488 been recorded into this frag then do so now. */
26489 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
26490 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
26491
26492 /* PR 21809: Do not set a mapping state for debug sections
26493 - it just confuses other tools. */
26494 if (bfd_section_flags (now_seg) & SEC_DEBUGGING)
26495 return;
26496
26497 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
26498
26499 /* Record a mapping symbol for alignment frags. We will delete this
26500 later if the alignment ends up empty. */
26501 switch (fragP->fr_type)
26502 {
26503 case rs_align:
26504 case rs_align_test:
26505 case rs_fill:
26506 mapping_state_2 (MAP_DATA, max_chars);
26507 break;
26508 case rs_align_code:
26509 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
26510 break;
26511 default:
26512 break;
26513 }
26514 }
26515
26516 /* When we change sections we need to issue a new mapping symbol. */
26517
26518 void
26519 arm_elf_change_section (void)
26520 {
26521 /* Link an unlinked unwind index table section to the .text section. */
26522 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
26523 && elf_linked_to_section (now_seg) == NULL)
26524 elf_linked_to_section (now_seg) = text_section;
26525 }
26526
26527 int
26528 arm_elf_section_type (const char * str, size_t len)
26529 {
26530 if (len == 5 && strncmp (str, "exidx", 5) == 0)
26531 return SHT_ARM_EXIDX;
26532
26533 return -1;
26534 }
26535 \f
26536 /* Code to deal with unwinding tables. */
26537
26538 static void add_unwind_adjustsp (offsetT);
26539
26540 /* Generate any deferred unwind frame offset. */
26541
26542 static void
26543 flush_pending_unwind (void)
26544 {
26545 offsetT offset;
26546
26547 offset = unwind.pending_offset;
26548 unwind.pending_offset = 0;
26549 if (offset != 0)
26550 add_unwind_adjustsp (offset);
26551 }
26552
26553 /* Add an opcode to this list for this function. Two-byte opcodes should
26554 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
26555 order. */
26556
26557 static void
26558 add_unwind_opcode (valueT op, int length)
26559 {
26560 /* Add any deferred stack adjustment. */
26561 if (unwind.pending_offset)
26562 flush_pending_unwind ();
26563
26564 unwind.sp_restored = 0;
26565
26566 if (unwind.opcode_count + length > unwind.opcode_alloc)
26567 {
26568 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
26569 if (unwind.opcodes)
26570 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
26571 unwind.opcode_alloc);
26572 else
26573 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
26574 }
26575 while (length > 0)
26576 {
26577 length--;
26578 unwind.opcodes[unwind.opcode_count] = op & 0xff;
26579 op >>= 8;
26580 unwind.opcode_count++;
26581 }
26582 }
26583
26584 /* Add unwind opcodes to adjust the stack pointer. */
26585
26586 static void
26587 add_unwind_adjustsp (offsetT offset)
26588 {
26589 valueT op;
26590
26591 if (offset > 0x200)
26592 {
26593 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
26594 char bytes[5];
26595 int n;
26596 valueT o;
26597
26598 /* Long form: 0xb2, uleb128. */
26599 /* This might not fit in a word so add the individual bytes,
26600 remembering the list is built in reverse order. */
26601 o = (valueT) ((offset - 0x204) >> 2);
26602 if (o == 0)
26603 add_unwind_opcode (0, 1);
26604
26605 /* Calculate the uleb128 encoding of the offset. */
26606 n = 0;
26607 while (o)
26608 {
26609 bytes[n] = o & 0x7f;
26610 o >>= 7;
26611 if (o)
26612 bytes[n] |= 0x80;
26613 n++;
26614 }
26615 /* Add the insn. */
26616 for (; n; n--)
26617 add_unwind_opcode (bytes[n - 1], 1);
26618 add_unwind_opcode (0xb2, 1);
26619 }
26620 else if (offset > 0x100)
26621 {
26622 /* Two short opcodes. */
26623 add_unwind_opcode (0x3f, 1);
26624 op = (offset - 0x104) >> 2;
26625 add_unwind_opcode (op, 1);
26626 }
26627 else if (offset > 0)
26628 {
26629 /* Short opcode. */
26630 op = (offset - 4) >> 2;
26631 add_unwind_opcode (op, 1);
26632 }
26633 else if (offset < 0)
26634 {
26635 offset = -offset;
26636 while (offset > 0x100)
26637 {
26638 add_unwind_opcode (0x7f, 1);
26639 offset -= 0x100;
26640 }
26641 op = ((offset - 4) >> 2) | 0x40;
26642 add_unwind_opcode (op, 1);
26643 }
26644 }
26645
26646 /* Finish the list of unwind opcodes for this function. */
26647
26648 static void
26649 finish_unwind_opcodes (void)
26650 {
26651 valueT op;
26652
26653 if (unwind.fp_used)
26654 {
26655 /* Adjust sp as necessary. */
26656 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
26657 flush_pending_unwind ();
26658
26659 /* After restoring sp from the frame pointer. */
26660 op = 0x90 | unwind.fp_reg;
26661 add_unwind_opcode (op, 1);
26662 }
26663 else
26664 flush_pending_unwind ();
26665 }
26666
26667
26668 /* Start an exception table entry. If idx is nonzero this is an index table
26669 entry. */
26670
26671 static void
26672 start_unwind_section (const segT text_seg, int idx)
26673 {
26674 const char * text_name;
26675 const char * prefix;
26676 const char * prefix_once;
26677 const char * group_name;
26678 char * sec_name;
26679 int type;
26680 int flags;
26681 int linkonce;
26682
26683 if (idx)
26684 {
26685 prefix = ELF_STRING_ARM_unwind;
26686 prefix_once = ELF_STRING_ARM_unwind_once;
26687 type = SHT_ARM_EXIDX;
26688 }
26689 else
26690 {
26691 prefix = ELF_STRING_ARM_unwind_info;
26692 prefix_once = ELF_STRING_ARM_unwind_info_once;
26693 type = SHT_PROGBITS;
26694 }
26695
26696 text_name = segment_name (text_seg);
26697 if (streq (text_name, ".text"))
26698 text_name = "";
26699
26700 if (strncmp (text_name, ".gnu.linkonce.t.",
26701 strlen (".gnu.linkonce.t.")) == 0)
26702 {
26703 prefix = prefix_once;
26704 text_name += strlen (".gnu.linkonce.t.");
26705 }
26706
26707 sec_name = concat (prefix, text_name, (char *) NULL);
26708
26709 flags = SHF_ALLOC;
26710 linkonce = 0;
26711 group_name = 0;
26712
26713 /* Handle COMDAT group. */
26714 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
26715 {
26716 group_name = elf_group_name (text_seg);
26717 if (group_name == NULL)
26718 {
26719 as_bad (_("Group section `%s' has no group signature"),
26720 segment_name (text_seg));
26721 ignore_rest_of_line ();
26722 return;
26723 }
26724 flags |= SHF_GROUP;
26725 linkonce = 1;
26726 }
26727
26728 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
26729 linkonce, 0);
26730
26731 /* Set the section link for index tables. */
26732 if (idx)
26733 elf_linked_to_section (now_seg) = text_seg;
26734 }
26735
26736
26737 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
26738 personality routine data. Returns zero, or the index table value for
26739 an inline entry. */
26740
26741 static valueT
26742 create_unwind_entry (int have_data)
26743 {
26744 int size;
26745 addressT where;
26746 char *ptr;
26747 /* The current word of data. */
26748 valueT data;
26749 /* The number of bytes left in this word. */
26750 int n;
26751
26752 finish_unwind_opcodes ();
26753
26754 /* Remember the current text section. */
26755 unwind.saved_seg = now_seg;
26756 unwind.saved_subseg = now_subseg;
26757
26758 start_unwind_section (now_seg, 0);
26759
26760 if (unwind.personality_routine == NULL)
26761 {
26762 if (unwind.personality_index == -2)
26763 {
26764 if (have_data)
26765 as_bad (_("handlerdata in cantunwind frame"));
26766 return 1; /* EXIDX_CANTUNWIND. */
26767 }
26768
26769 /* Use a default personality routine if none is specified. */
26770 if (unwind.personality_index == -1)
26771 {
26772 if (unwind.opcode_count > 3)
26773 unwind.personality_index = 1;
26774 else
26775 unwind.personality_index = 0;
26776 }
26777
26778 /* Space for the personality routine entry. */
26779 if (unwind.personality_index == 0)
26780 {
26781 if (unwind.opcode_count > 3)
26782 as_bad (_("too many unwind opcodes for personality routine 0"));
26783
26784 if (!have_data)
26785 {
26786 /* All the data is inline in the index table. */
26787 data = 0x80;
26788 n = 3;
26789 while (unwind.opcode_count > 0)
26790 {
26791 unwind.opcode_count--;
26792 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
26793 n--;
26794 }
26795
26796 /* Pad with "finish" opcodes. */
26797 while (n--)
26798 data = (data << 8) | 0xb0;
26799
26800 return data;
26801 }
26802 size = 0;
26803 }
26804 else
26805 /* We get two opcodes "free" in the first word. */
26806 size = unwind.opcode_count - 2;
26807 }
26808 else
26809 {
26810 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
26811 if (unwind.personality_index != -1)
26812 {
26813 as_bad (_("attempt to recreate an unwind entry"));
26814 return 1;
26815 }
26816
26817 /* An extra byte is required for the opcode count. */
26818 size = unwind.opcode_count + 1;
26819 }
26820
26821 size = (size + 3) >> 2;
26822 if (size > 0xff)
26823 as_bad (_("too many unwind opcodes"));
26824
26825 frag_align (2, 0, 0);
26826 record_alignment (now_seg, 2);
26827 unwind.table_entry = expr_build_dot ();
26828
26829 /* Allocate the table entry. */
26830 ptr = frag_more ((size << 2) + 4);
26831 /* PR 13449: Zero the table entries in case some of them are not used. */
26832 memset (ptr, 0, (size << 2) + 4);
26833 where = frag_now_fix () - ((size << 2) + 4);
26834
26835 switch (unwind.personality_index)
26836 {
26837 case -1:
26838 /* ??? Should this be a PLT generating relocation? */
26839 /* Custom personality routine. */
26840 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
26841 BFD_RELOC_ARM_PREL31);
26842
26843 where += 4;
26844 ptr += 4;
26845
26846 /* Set the first byte to the number of additional words. */
26847 data = size > 0 ? size - 1 : 0;
26848 n = 3;
26849 break;
26850
26851 /* ABI defined personality routines. */
26852 case 0:
26853 /* Three opcodes bytes are packed into the first word. */
26854 data = 0x80;
26855 n = 3;
26856 break;
26857
26858 case 1:
26859 case 2:
26860 /* The size and first two opcode bytes go in the first word. */
26861 data = ((0x80 + unwind.personality_index) << 8) | size;
26862 n = 2;
26863 break;
26864
26865 default:
26866 /* Should never happen. */
26867 abort ();
26868 }
26869
26870 /* Pack the opcodes into words (MSB first), reversing the list at the same
26871 time. */
26872 while (unwind.opcode_count > 0)
26873 {
26874 if (n == 0)
26875 {
26876 md_number_to_chars (ptr, data, 4);
26877 ptr += 4;
26878 n = 4;
26879 data = 0;
26880 }
26881 unwind.opcode_count--;
26882 n--;
26883 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
26884 }
26885
26886 /* Finish off the last word. */
26887 if (n < 4)
26888 {
26889 /* Pad with "finish" opcodes. */
26890 while (n--)
26891 data = (data << 8) | 0xb0;
26892
26893 md_number_to_chars (ptr, data, 4);
26894 }
26895
26896 if (!have_data)
26897 {
26898 /* Add an empty descriptor if there is no user-specified data. */
26899 ptr = frag_more (4);
26900 md_number_to_chars (ptr, 0, 4);
26901 }
26902
26903 return 0;
26904 }
26905
26906
26907 /* Initialize the DWARF-2 unwind information for this procedure. */
26908
26909 void
26910 tc_arm_frame_initial_instructions (void)
26911 {
26912 cfi_add_CFA_def_cfa (REG_SP, 0);
26913 }
26914 #endif /* OBJ_ELF */
26915
26916 /* Convert REGNAME to a DWARF-2 register number. */
26917
26918 int
26919 tc_arm_regname_to_dw2regnum (char *regname)
26920 {
26921 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
26922 if (reg != FAIL)
26923 return reg;
26924
26925 /* PR 16694: Allow VFP registers as well. */
26926 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
26927 if (reg != FAIL)
26928 return 64 + reg;
26929
26930 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
26931 if (reg != FAIL)
26932 return reg + 256;
26933
26934 return FAIL;
26935 }
26936
26937 #ifdef TE_PE
26938 void
26939 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
26940 {
26941 expressionS exp;
26942
26943 exp.X_op = O_secrel;
26944 exp.X_add_symbol = symbol;
26945 exp.X_add_number = 0;
26946 emit_expr (&exp, size);
26947 }
26948 #endif
26949
26950 /* MD interface: Symbol and relocation handling. */
26951
26952 /* Return the address within the segment that a PC-relative fixup is
26953 relative to. For ARM, PC-relative fixups applied to instructions
26954 are generally relative to the location of the fixup plus 8 bytes.
26955 Thumb branches are offset by 4, and Thumb loads relative to PC
26956 require special handling. */
26957
26958 long
26959 md_pcrel_from_section (fixS * fixP, segT seg)
26960 {
26961 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
26962
26963 /* If this is pc-relative and we are going to emit a relocation
26964 then we just want to put out any pipeline compensation that the linker
26965 will need. Otherwise we want to use the calculated base.
26966 For WinCE we skip the bias for externals as well, since this
26967 is how the MS ARM-CE assembler behaves and we want to be compatible. */
26968 if (fixP->fx_pcrel
26969 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
26970 || (arm_force_relocation (fixP)
26971 #ifdef TE_WINCE
26972 && !S_IS_EXTERNAL (fixP->fx_addsy)
26973 #endif
26974 )))
26975 base = 0;
26976
26977
26978 switch (fixP->fx_r_type)
26979 {
26980 /* PC relative addressing on the Thumb is slightly odd as the
26981 bottom two bits of the PC are forced to zero for the
26982 calculation. This happens *after* application of the
26983 pipeline offset. However, Thumb adrl already adjusts for
26984 this, so we need not do it again. */
26985 case BFD_RELOC_ARM_THUMB_ADD:
26986 return base & ~3;
26987
26988 case BFD_RELOC_ARM_THUMB_OFFSET:
26989 case BFD_RELOC_ARM_T32_OFFSET_IMM:
26990 case BFD_RELOC_ARM_T32_ADD_PC12:
26991 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
26992 return (base + 4) & ~3;
26993
26994 /* Thumb branches are simply offset by +4. */
26995 case BFD_RELOC_THUMB_PCREL_BRANCH5:
26996 case BFD_RELOC_THUMB_PCREL_BRANCH7:
26997 case BFD_RELOC_THUMB_PCREL_BRANCH9:
26998 case BFD_RELOC_THUMB_PCREL_BRANCH12:
26999 case BFD_RELOC_THUMB_PCREL_BRANCH20:
27000 case BFD_RELOC_THUMB_PCREL_BRANCH25:
27001 case BFD_RELOC_THUMB_PCREL_BFCSEL:
27002 case BFD_RELOC_ARM_THUMB_BF17:
27003 case BFD_RELOC_ARM_THUMB_BF19:
27004 case BFD_RELOC_ARM_THUMB_BF13:
27005 case BFD_RELOC_ARM_THUMB_LOOP12:
27006 return base + 4;
27007
27008 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27009 if (fixP->fx_addsy
27010 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27011 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27012 && ARM_IS_FUNC (fixP->fx_addsy)
27013 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27014 base = fixP->fx_where + fixP->fx_frag->fr_address;
27015 return base + 4;
27016
27017 /* BLX is like branches above, but forces the low two bits of PC to
27018 zero. */
27019 case BFD_RELOC_THUMB_PCREL_BLX:
27020 if (fixP->fx_addsy
27021 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27022 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27023 && THUMB_IS_FUNC (fixP->fx_addsy)
27024 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27025 base = fixP->fx_where + fixP->fx_frag->fr_address;
27026 return (base + 4) & ~3;
27027
27028 /* ARM mode branches are offset by +8. However, the Windows CE
27029 loader expects the relocation not to take this into account. */
27030 case BFD_RELOC_ARM_PCREL_BLX:
27031 if (fixP->fx_addsy
27032 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27033 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27034 && ARM_IS_FUNC (fixP->fx_addsy)
27035 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27036 base = fixP->fx_where + fixP->fx_frag->fr_address;
27037 return base + 8;
27038
27039 case BFD_RELOC_ARM_PCREL_CALL:
27040 if (fixP->fx_addsy
27041 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27042 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27043 && THUMB_IS_FUNC (fixP->fx_addsy)
27044 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
27045 base = fixP->fx_where + fixP->fx_frag->fr_address;
27046 return base + 8;
27047
27048 case BFD_RELOC_ARM_PCREL_BRANCH:
27049 case BFD_RELOC_ARM_PCREL_JUMP:
27050 case BFD_RELOC_ARM_PLT32:
27051 #ifdef TE_WINCE
27052 /* When handling fixups immediately, because we have already
27053 discovered the value of a symbol, or the address of the frag involved
27054 we must account for the offset by +8, as the OS loader will never see the reloc.
27055 see fixup_segment() in write.c
27056 The S_IS_EXTERNAL test handles the case of global symbols.
27057 Those need the calculated base, not just the pipe compensation the linker will need. */
27058 if (fixP->fx_pcrel
27059 && fixP->fx_addsy != NULL
27060 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27061 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
27062 return base + 8;
27063 return base;
27064 #else
27065 return base + 8;
27066 #endif
27067
27068
27069 /* ARM mode loads relative to PC are also offset by +8. Unlike
27070 branches, the Windows CE loader *does* expect the relocation
27071 to take this into account. */
27072 case BFD_RELOC_ARM_OFFSET_IMM:
27073 case BFD_RELOC_ARM_OFFSET_IMM8:
27074 case BFD_RELOC_ARM_HWLITERAL:
27075 case BFD_RELOC_ARM_LITERAL:
27076 case BFD_RELOC_ARM_CP_OFF_IMM:
27077 return base + 8;
27078
27079
27080 /* Other PC-relative relocations are un-offset. */
27081 default:
27082 return base;
27083 }
27084 }
27085
27086 static bfd_boolean flag_warn_syms = TRUE;
27087
27088 bfd_boolean
27089 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
27090 {
27091 /* PR 18347 - Warn if the user attempts to create a symbol with the same
27092 name as an ARM instruction. Whilst strictly speaking it is allowed, it
27093 does mean that the resulting code might be very confusing to the reader.
27094 Also this warning can be triggered if the user omits an operand before
27095 an immediate address, eg:
27096
27097 LDR =foo
27098
27099 GAS treats this as an assignment of the value of the symbol foo to a
27100 symbol LDR, and so (without this code) it will not issue any kind of
27101 warning or error message.
27102
27103 Note - ARM instructions are case-insensitive but the strings in the hash
27104 table are all stored in lower case, so we must first ensure that name is
27105 lower case too. */
27106 if (flag_warn_syms && arm_ops_hsh)
27107 {
27108 char * nbuf = strdup (name);
27109 char * p;
27110
27111 for (p = nbuf; *p; p++)
27112 *p = TOLOWER (*p);
27113 if (hash_find (arm_ops_hsh, nbuf) != NULL)
27114 {
27115 static struct hash_control * already_warned = NULL;
27116
27117 if (already_warned == NULL)
27118 already_warned = hash_new ();
27119 /* Only warn about the symbol once. To keep the code
27120 simple we let hash_insert do the lookup for us. */
27121 if (hash_insert (already_warned, nbuf, NULL) == NULL)
27122 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
27123 }
27124 else
27125 free (nbuf);
27126 }
27127
27128 return FALSE;
27129 }
27130
27131 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
27132 Otherwise we have no need to default values of symbols. */
27133
27134 symbolS *
27135 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
27136 {
27137 #ifdef OBJ_ELF
27138 if (name[0] == '_' && name[1] == 'G'
27139 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
27140 {
27141 if (!GOT_symbol)
27142 {
27143 if (symbol_find (name))
27144 as_bad (_("GOT already in the symbol table"));
27145
27146 GOT_symbol = symbol_new (name, undefined_section,
27147 (valueT) 0, & zero_address_frag);
27148 }
27149
27150 return GOT_symbol;
27151 }
27152 #endif
27153
27154 return NULL;
27155 }
27156
27157 /* Subroutine of md_apply_fix. Check to see if an immediate can be
27158 computed as two separate immediate values, added together. We
27159 already know that this value cannot be computed by just one ARM
27160 instruction. */
27161
27162 static unsigned int
27163 validate_immediate_twopart (unsigned int val,
27164 unsigned int * highpart)
27165 {
27166 unsigned int a;
27167 unsigned int i;
27168
27169 for (i = 0; i < 32; i += 2)
27170 if (((a = rotate_left (val, i)) & 0xff) != 0)
27171 {
27172 if (a & 0xff00)
27173 {
27174 if (a & ~ 0xffff)
27175 continue;
27176 * highpart = (a >> 8) | ((i + 24) << 7);
27177 }
27178 else if (a & 0xff0000)
27179 {
27180 if (a & 0xff000000)
27181 continue;
27182 * highpart = (a >> 16) | ((i + 16) << 7);
27183 }
27184 else
27185 {
27186 gas_assert (a & 0xff000000);
27187 * highpart = (a >> 24) | ((i + 8) << 7);
27188 }
27189
27190 return (a & 0xff) | (i << 7);
27191 }
27192
27193 return FAIL;
27194 }
27195
27196 static int
27197 validate_offset_imm (unsigned int val, int hwse)
27198 {
27199 if ((hwse && val > 255) || val > 4095)
27200 return FAIL;
27201 return val;
27202 }
27203
27204 /* Subroutine of md_apply_fix. Do those data_ops which can take a
27205 negative immediate constant by altering the instruction. A bit of
27206 a hack really.
27207 MOV <-> MVN
27208 AND <-> BIC
27209 ADC <-> SBC
27210 by inverting the second operand, and
27211 ADD <-> SUB
27212 CMP <-> CMN
27213 by negating the second operand. */
27214
27215 static int
27216 negate_data_op (unsigned long * instruction,
27217 unsigned long value)
27218 {
27219 int op, new_inst;
27220 unsigned long negated, inverted;
27221
27222 negated = encode_arm_immediate (-value);
27223 inverted = encode_arm_immediate (~value);
27224
27225 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
27226 switch (op)
27227 {
27228 /* First negates. */
27229 case OPCODE_SUB: /* ADD <-> SUB */
27230 new_inst = OPCODE_ADD;
27231 value = negated;
27232 break;
27233
27234 case OPCODE_ADD:
27235 new_inst = OPCODE_SUB;
27236 value = negated;
27237 break;
27238
27239 case OPCODE_CMP: /* CMP <-> CMN */
27240 new_inst = OPCODE_CMN;
27241 value = negated;
27242 break;
27243
27244 case OPCODE_CMN:
27245 new_inst = OPCODE_CMP;
27246 value = negated;
27247 break;
27248
27249 /* Now Inverted ops. */
27250 case OPCODE_MOV: /* MOV <-> MVN */
27251 new_inst = OPCODE_MVN;
27252 value = inverted;
27253 break;
27254
27255 case OPCODE_MVN:
27256 new_inst = OPCODE_MOV;
27257 value = inverted;
27258 break;
27259
27260 case OPCODE_AND: /* AND <-> BIC */
27261 new_inst = OPCODE_BIC;
27262 value = inverted;
27263 break;
27264
27265 case OPCODE_BIC:
27266 new_inst = OPCODE_AND;
27267 value = inverted;
27268 break;
27269
27270 case OPCODE_ADC: /* ADC <-> SBC */
27271 new_inst = OPCODE_SBC;
27272 value = inverted;
27273 break;
27274
27275 case OPCODE_SBC:
27276 new_inst = OPCODE_ADC;
27277 value = inverted;
27278 break;
27279
27280 /* We cannot do anything. */
27281 default:
27282 return FAIL;
27283 }
27284
27285 if (value == (unsigned) FAIL)
27286 return FAIL;
27287
27288 *instruction &= OPCODE_MASK;
27289 *instruction |= new_inst << DATA_OP_SHIFT;
27290 return value;
27291 }
27292
27293 /* Like negate_data_op, but for Thumb-2. */
27294
27295 static unsigned int
27296 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
27297 {
27298 int op, new_inst;
27299 int rd;
27300 unsigned int negated, inverted;
27301
27302 negated = encode_thumb32_immediate (-value);
27303 inverted = encode_thumb32_immediate (~value);
27304
27305 rd = (*instruction >> 8) & 0xf;
27306 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
27307 switch (op)
27308 {
27309 /* ADD <-> SUB. Includes CMP <-> CMN. */
27310 case T2_OPCODE_SUB:
27311 new_inst = T2_OPCODE_ADD;
27312 value = negated;
27313 break;
27314
27315 case T2_OPCODE_ADD:
27316 new_inst = T2_OPCODE_SUB;
27317 value = negated;
27318 break;
27319
27320 /* ORR <-> ORN. Includes MOV <-> MVN. */
27321 case T2_OPCODE_ORR:
27322 new_inst = T2_OPCODE_ORN;
27323 value = inverted;
27324 break;
27325
27326 case T2_OPCODE_ORN:
27327 new_inst = T2_OPCODE_ORR;
27328 value = inverted;
27329 break;
27330
27331 /* AND <-> BIC. TST has no inverted equivalent. */
27332 case T2_OPCODE_AND:
27333 new_inst = T2_OPCODE_BIC;
27334 if (rd == 15)
27335 value = FAIL;
27336 else
27337 value = inverted;
27338 break;
27339
27340 case T2_OPCODE_BIC:
27341 new_inst = T2_OPCODE_AND;
27342 value = inverted;
27343 break;
27344
27345 /* ADC <-> SBC */
27346 case T2_OPCODE_ADC:
27347 new_inst = T2_OPCODE_SBC;
27348 value = inverted;
27349 break;
27350
27351 case T2_OPCODE_SBC:
27352 new_inst = T2_OPCODE_ADC;
27353 value = inverted;
27354 break;
27355
27356 /* We cannot do anything. */
27357 default:
27358 return FAIL;
27359 }
27360
27361 if (value == (unsigned int)FAIL)
27362 return FAIL;
27363
27364 *instruction &= T2_OPCODE_MASK;
27365 *instruction |= new_inst << T2_DATA_OP_SHIFT;
27366 return value;
27367 }
27368
27369 /* Read a 32-bit thumb instruction from buf. */
27370
27371 static unsigned long
27372 get_thumb32_insn (char * buf)
27373 {
27374 unsigned long insn;
27375 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
27376 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27377
27378 return insn;
27379 }
27380
27381 /* We usually want to set the low bit on the address of thumb function
27382 symbols. In particular .word foo - . should have the low bit set.
27383 Generic code tries to fold the difference of two symbols to
27384 a constant. Prevent this and force a relocation when the first symbols
27385 is a thumb function. */
27386
27387 bfd_boolean
27388 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
27389 {
27390 if (op == O_subtract
27391 && l->X_op == O_symbol
27392 && r->X_op == O_symbol
27393 && THUMB_IS_FUNC (l->X_add_symbol))
27394 {
27395 l->X_op = O_subtract;
27396 l->X_op_symbol = r->X_add_symbol;
27397 l->X_add_number -= r->X_add_number;
27398 return TRUE;
27399 }
27400
27401 /* Process as normal. */
27402 return FALSE;
27403 }
27404
27405 /* Encode Thumb2 unconditional branches and calls. The encoding
27406 for the 2 are identical for the immediate values. */
27407
27408 static void
27409 encode_thumb2_b_bl_offset (char * buf, offsetT value)
27410 {
27411 #define T2I1I2MASK ((1 << 13) | (1 << 11))
27412 offsetT newval;
27413 offsetT newval2;
27414 addressT S, I1, I2, lo, hi;
27415
27416 S = (value >> 24) & 0x01;
27417 I1 = (value >> 23) & 0x01;
27418 I2 = (value >> 22) & 0x01;
27419 hi = (value >> 12) & 0x3ff;
27420 lo = (value >> 1) & 0x7ff;
27421 newval = md_chars_to_number (buf, THUMB_SIZE);
27422 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
27423 newval |= (S << 10) | hi;
27424 newval2 &= ~T2I1I2MASK;
27425 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
27426 md_number_to_chars (buf, newval, THUMB_SIZE);
27427 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
27428 }
27429
27430 void
27431 md_apply_fix (fixS * fixP,
27432 valueT * valP,
27433 segT seg)
27434 {
27435 offsetT value = * valP;
27436 offsetT newval;
27437 unsigned int newimm;
27438 unsigned long temp;
27439 int sign;
27440 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
27441
27442 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
27443
27444 /* Note whether this will delete the relocation. */
27445
27446 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
27447 fixP->fx_done = 1;
27448
27449 /* On a 64-bit host, silently truncate 'value' to 32 bits for
27450 consistency with the behaviour on 32-bit hosts. Remember value
27451 for emit_reloc. */
27452 value &= 0xffffffff;
27453 value ^= 0x80000000;
27454 value -= 0x80000000;
27455
27456 *valP = value;
27457 fixP->fx_addnumber = value;
27458
27459 /* Same treatment for fixP->fx_offset. */
27460 fixP->fx_offset &= 0xffffffff;
27461 fixP->fx_offset ^= 0x80000000;
27462 fixP->fx_offset -= 0x80000000;
27463
27464 switch (fixP->fx_r_type)
27465 {
27466 case BFD_RELOC_NONE:
27467 /* This will need to go in the object file. */
27468 fixP->fx_done = 0;
27469 break;
27470
27471 case BFD_RELOC_ARM_IMMEDIATE:
27472 /* We claim that this fixup has been processed here,
27473 even if in fact we generate an error because we do
27474 not have a reloc for it, so tc_gen_reloc will reject it. */
27475 fixP->fx_done = 1;
27476
27477 if (fixP->fx_addsy)
27478 {
27479 const char *msg = 0;
27480
27481 if (! S_IS_DEFINED (fixP->fx_addsy))
27482 msg = _("undefined symbol %s used as an immediate value");
27483 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
27484 msg = _("symbol %s is in a different section");
27485 else if (S_IS_WEAK (fixP->fx_addsy))
27486 msg = _("symbol %s is weak and may be overridden later");
27487
27488 if (msg)
27489 {
27490 as_bad_where (fixP->fx_file, fixP->fx_line,
27491 msg, S_GET_NAME (fixP->fx_addsy));
27492 break;
27493 }
27494 }
27495
27496 temp = md_chars_to_number (buf, INSN_SIZE);
27497
27498 /* If the offset is negative, we should use encoding A2 for ADR. */
27499 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
27500 newimm = negate_data_op (&temp, value);
27501 else
27502 {
27503 newimm = encode_arm_immediate (value);
27504
27505 /* If the instruction will fail, see if we can fix things up by
27506 changing the opcode. */
27507 if (newimm == (unsigned int) FAIL)
27508 newimm = negate_data_op (&temp, value);
27509 /* MOV accepts both ARM modified immediate (A1 encoding) and
27510 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
27511 When disassembling, MOV is preferred when there is no encoding
27512 overlap. */
27513 if (newimm == (unsigned int) FAIL
27514 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
27515 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
27516 && !((temp >> SBIT_SHIFT) & 0x1)
27517 && value >= 0 && value <= 0xffff)
27518 {
27519 /* Clear bits[23:20] to change encoding from A1 to A2. */
27520 temp &= 0xff0fffff;
27521 /* Encoding high 4bits imm. Code below will encode the remaining
27522 low 12bits. */
27523 temp |= (value & 0x0000f000) << 4;
27524 newimm = value & 0x00000fff;
27525 }
27526 }
27527
27528 if (newimm == (unsigned int) FAIL)
27529 {
27530 as_bad_where (fixP->fx_file, fixP->fx_line,
27531 _("invalid constant (%lx) after fixup"),
27532 (unsigned long) value);
27533 break;
27534 }
27535
27536 newimm |= (temp & 0xfffff000);
27537 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
27538 break;
27539
27540 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
27541 {
27542 unsigned int highpart = 0;
27543 unsigned int newinsn = 0xe1a00000; /* nop. */
27544
27545 if (fixP->fx_addsy)
27546 {
27547 const char *msg = 0;
27548
27549 if (! S_IS_DEFINED (fixP->fx_addsy))
27550 msg = _("undefined symbol %s used as an immediate value");
27551 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
27552 msg = _("symbol %s is in a different section");
27553 else if (S_IS_WEAK (fixP->fx_addsy))
27554 msg = _("symbol %s is weak and may be overridden later");
27555
27556 if (msg)
27557 {
27558 as_bad_where (fixP->fx_file, fixP->fx_line,
27559 msg, S_GET_NAME (fixP->fx_addsy));
27560 break;
27561 }
27562 }
27563
27564 newimm = encode_arm_immediate (value);
27565 temp = md_chars_to_number (buf, INSN_SIZE);
27566
27567 /* If the instruction will fail, see if we can fix things up by
27568 changing the opcode. */
27569 if (newimm == (unsigned int) FAIL
27570 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
27571 {
27572 /* No ? OK - try using two ADD instructions to generate
27573 the value. */
27574 newimm = validate_immediate_twopart (value, & highpart);
27575
27576 /* Yes - then make sure that the second instruction is
27577 also an add. */
27578 if (newimm != (unsigned int) FAIL)
27579 newinsn = temp;
27580 /* Still No ? Try using a negated value. */
27581 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
27582 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
27583 /* Otherwise - give up. */
27584 else
27585 {
27586 as_bad_where (fixP->fx_file, fixP->fx_line,
27587 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
27588 (long) value);
27589 break;
27590 }
27591
27592 /* Replace the first operand in the 2nd instruction (which
27593 is the PC) with the destination register. We have
27594 already added in the PC in the first instruction and we
27595 do not want to do it again. */
27596 newinsn &= ~ 0xf0000;
27597 newinsn |= ((newinsn & 0x0f000) << 4);
27598 }
27599
27600 newimm |= (temp & 0xfffff000);
27601 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
27602
27603 highpart |= (newinsn & 0xfffff000);
27604 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
27605 }
27606 break;
27607
27608 case BFD_RELOC_ARM_OFFSET_IMM:
27609 if (!fixP->fx_done && seg->use_rela_p)
27610 value = 0;
27611 /* Fall through. */
27612
27613 case BFD_RELOC_ARM_LITERAL:
27614 sign = value > 0;
27615
27616 if (value < 0)
27617 value = - value;
27618
27619 if (validate_offset_imm (value, 0) == FAIL)
27620 {
27621 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
27622 as_bad_where (fixP->fx_file, fixP->fx_line,
27623 _("invalid literal constant: pool needs to be closer"));
27624 else
27625 as_bad_where (fixP->fx_file, fixP->fx_line,
27626 _("bad immediate value for offset (%ld)"),
27627 (long) value);
27628 break;
27629 }
27630
27631 newval = md_chars_to_number (buf, INSN_SIZE);
27632 if (value == 0)
27633 newval &= 0xfffff000;
27634 else
27635 {
27636 newval &= 0xff7ff000;
27637 newval |= value | (sign ? INDEX_UP : 0);
27638 }
27639 md_number_to_chars (buf, newval, INSN_SIZE);
27640 break;
27641
27642 case BFD_RELOC_ARM_OFFSET_IMM8:
27643 case BFD_RELOC_ARM_HWLITERAL:
27644 sign = value > 0;
27645
27646 if (value < 0)
27647 value = - value;
27648
27649 if (validate_offset_imm (value, 1) == FAIL)
27650 {
27651 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
27652 as_bad_where (fixP->fx_file, fixP->fx_line,
27653 _("invalid literal constant: pool needs to be closer"));
27654 else
27655 as_bad_where (fixP->fx_file, fixP->fx_line,
27656 _("bad immediate value for 8-bit offset (%ld)"),
27657 (long) value);
27658 break;
27659 }
27660
27661 newval = md_chars_to_number (buf, INSN_SIZE);
27662 if (value == 0)
27663 newval &= 0xfffff0f0;
27664 else
27665 {
27666 newval &= 0xff7ff0f0;
27667 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
27668 }
27669 md_number_to_chars (buf, newval, INSN_SIZE);
27670 break;
27671
27672 case BFD_RELOC_ARM_T32_OFFSET_U8:
27673 if (value < 0 || value > 1020 || value % 4 != 0)
27674 as_bad_where (fixP->fx_file, fixP->fx_line,
27675 _("bad immediate value for offset (%ld)"), (long) value);
27676 value /= 4;
27677
27678 newval = md_chars_to_number (buf+2, THUMB_SIZE);
27679 newval |= value;
27680 md_number_to_chars (buf+2, newval, THUMB_SIZE);
27681 break;
27682
27683 case BFD_RELOC_ARM_T32_OFFSET_IMM:
27684 /* This is a complicated relocation used for all varieties of Thumb32
27685 load/store instruction with immediate offset:
27686
27687 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
27688 *4, optional writeback(W)
27689 (doubleword load/store)
27690
27691 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
27692 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
27693 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
27694 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
27695 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
27696
27697 Uppercase letters indicate bits that are already encoded at
27698 this point. Lowercase letters are our problem. For the
27699 second block of instructions, the secondary opcode nybble
27700 (bits 8..11) is present, and bit 23 is zero, even if this is
27701 a PC-relative operation. */
27702 newval = md_chars_to_number (buf, THUMB_SIZE);
27703 newval <<= 16;
27704 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
27705
27706 if ((newval & 0xf0000000) == 0xe0000000)
27707 {
27708 /* Doubleword load/store: 8-bit offset, scaled by 4. */
27709 if (value >= 0)
27710 newval |= (1 << 23);
27711 else
27712 value = -value;
27713 if (value % 4 != 0)
27714 {
27715 as_bad_where (fixP->fx_file, fixP->fx_line,
27716 _("offset not a multiple of 4"));
27717 break;
27718 }
27719 value /= 4;
27720 if (value > 0xff)
27721 {
27722 as_bad_where (fixP->fx_file, fixP->fx_line,
27723 _("offset out of range"));
27724 break;
27725 }
27726 newval &= ~0xff;
27727 }
27728 else if ((newval & 0x000f0000) == 0x000f0000)
27729 {
27730 /* PC-relative, 12-bit offset. */
27731 if (value >= 0)
27732 newval |= (1 << 23);
27733 else
27734 value = -value;
27735 if (value > 0xfff)
27736 {
27737 as_bad_where (fixP->fx_file, fixP->fx_line,
27738 _("offset out of range"));
27739 break;
27740 }
27741 newval &= ~0xfff;
27742 }
27743 else if ((newval & 0x00000100) == 0x00000100)
27744 {
27745 /* Writeback: 8-bit, +/- offset. */
27746 if (value >= 0)
27747 newval |= (1 << 9);
27748 else
27749 value = -value;
27750 if (value > 0xff)
27751 {
27752 as_bad_where (fixP->fx_file, fixP->fx_line,
27753 _("offset out of range"));
27754 break;
27755 }
27756 newval &= ~0xff;
27757 }
27758 else if ((newval & 0x00000f00) == 0x00000e00)
27759 {
27760 /* T-instruction: positive 8-bit offset. */
27761 if (value < 0 || value > 0xff)
27762 {
27763 as_bad_where (fixP->fx_file, fixP->fx_line,
27764 _("offset out of range"));
27765 break;
27766 }
27767 newval &= ~0xff;
27768 newval |= value;
27769 }
27770 else
27771 {
27772 /* Positive 12-bit or negative 8-bit offset. */
27773 int limit;
27774 if (value >= 0)
27775 {
27776 newval |= (1 << 23);
27777 limit = 0xfff;
27778 }
27779 else
27780 {
27781 value = -value;
27782 limit = 0xff;
27783 }
27784 if (value > limit)
27785 {
27786 as_bad_where (fixP->fx_file, fixP->fx_line,
27787 _("offset out of range"));
27788 break;
27789 }
27790 newval &= ~limit;
27791 }
27792
27793 newval |= value;
27794 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
27795 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
27796 break;
27797
27798 case BFD_RELOC_ARM_SHIFT_IMM:
27799 newval = md_chars_to_number (buf, INSN_SIZE);
27800 if (((unsigned long) value) > 32
27801 || (value == 32
27802 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
27803 {
27804 as_bad_where (fixP->fx_file, fixP->fx_line,
27805 _("shift expression is too large"));
27806 break;
27807 }
27808
27809 if (value == 0)
27810 /* Shifts of zero must be done as lsl. */
27811 newval &= ~0x60;
27812 else if (value == 32)
27813 value = 0;
27814 newval &= 0xfffff07f;
27815 newval |= (value & 0x1f) << 7;
27816 md_number_to_chars (buf, newval, INSN_SIZE);
27817 break;
27818
27819 case BFD_RELOC_ARM_T32_IMMEDIATE:
27820 case BFD_RELOC_ARM_T32_ADD_IMM:
27821 case BFD_RELOC_ARM_T32_IMM12:
27822 case BFD_RELOC_ARM_T32_ADD_PC12:
27823 /* We claim that this fixup has been processed here,
27824 even if in fact we generate an error because we do
27825 not have a reloc for it, so tc_gen_reloc will reject it. */
27826 fixP->fx_done = 1;
27827
27828 if (fixP->fx_addsy
27829 && ! S_IS_DEFINED (fixP->fx_addsy))
27830 {
27831 as_bad_where (fixP->fx_file, fixP->fx_line,
27832 _("undefined symbol %s used as an immediate value"),
27833 S_GET_NAME (fixP->fx_addsy));
27834 break;
27835 }
27836
27837 newval = md_chars_to_number (buf, THUMB_SIZE);
27838 newval <<= 16;
27839 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
27840
27841 newimm = FAIL;
27842 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
27843 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
27844 Thumb2 modified immediate encoding (T2). */
27845 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
27846 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
27847 {
27848 newimm = encode_thumb32_immediate (value);
27849 if (newimm == (unsigned int) FAIL)
27850 newimm = thumb32_negate_data_op (&newval, value);
27851 }
27852 if (newimm == (unsigned int) FAIL)
27853 {
27854 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
27855 {
27856 /* Turn add/sum into addw/subw. */
27857 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
27858 newval = (newval & 0xfeffffff) | 0x02000000;
27859 /* No flat 12-bit imm encoding for addsw/subsw. */
27860 if ((newval & 0x00100000) == 0)
27861 {
27862 /* 12 bit immediate for addw/subw. */
27863 if (value < 0)
27864 {
27865 value = -value;
27866 newval ^= 0x00a00000;
27867 }
27868 if (value > 0xfff)
27869 newimm = (unsigned int) FAIL;
27870 else
27871 newimm = value;
27872 }
27873 }
27874 else
27875 {
27876 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
27877 UINT16 (T3 encoding), MOVW only accepts UINT16. When
27878 disassembling, MOV is preferred when there is no encoding
27879 overlap. */
27880 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
27881 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
27882 but with the Rn field [19:16] set to 1111. */
27883 && (((newval >> 16) & 0xf) == 0xf)
27884 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
27885 && !((newval >> T2_SBIT_SHIFT) & 0x1)
27886 && value >= 0 && value <= 0xffff)
27887 {
27888 /* Toggle bit[25] to change encoding from T2 to T3. */
27889 newval ^= 1 << 25;
27890 /* Clear bits[19:16]. */
27891 newval &= 0xfff0ffff;
27892 /* Encoding high 4bits imm. Code below will encode the
27893 remaining low 12bits. */
27894 newval |= (value & 0x0000f000) << 4;
27895 newimm = value & 0x00000fff;
27896 }
27897 }
27898 }
27899
27900 if (newimm == (unsigned int)FAIL)
27901 {
27902 as_bad_where (fixP->fx_file, fixP->fx_line,
27903 _("invalid constant (%lx) after fixup"),
27904 (unsigned long) value);
27905 break;
27906 }
27907
27908 newval |= (newimm & 0x800) << 15;
27909 newval |= (newimm & 0x700) << 4;
27910 newval |= (newimm & 0x0ff);
27911
27912 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
27913 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
27914 break;
27915
27916 case BFD_RELOC_ARM_SMC:
27917 if (((unsigned long) value) > 0xf)
27918 as_bad_where (fixP->fx_file, fixP->fx_line,
27919 _("invalid smc expression"));
27920
27921 newval = md_chars_to_number (buf, INSN_SIZE);
27922 newval |= (value & 0xf);
27923 md_number_to_chars (buf, newval, INSN_SIZE);
27924 break;
27925
27926 case BFD_RELOC_ARM_HVC:
27927 if (((unsigned long) value) > 0xffff)
27928 as_bad_where (fixP->fx_file, fixP->fx_line,
27929 _("invalid hvc expression"));
27930 newval = md_chars_to_number (buf, INSN_SIZE);
27931 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
27932 md_number_to_chars (buf, newval, INSN_SIZE);
27933 break;
27934
27935 case BFD_RELOC_ARM_SWI:
27936 if (fixP->tc_fix_data != 0)
27937 {
27938 if (((unsigned long) value) > 0xff)
27939 as_bad_where (fixP->fx_file, fixP->fx_line,
27940 _("invalid swi expression"));
27941 newval = md_chars_to_number (buf, THUMB_SIZE);
27942 newval |= value;
27943 md_number_to_chars (buf, newval, THUMB_SIZE);
27944 }
27945 else
27946 {
27947 if (((unsigned long) value) > 0x00ffffff)
27948 as_bad_where (fixP->fx_file, fixP->fx_line,
27949 _("invalid swi expression"));
27950 newval = md_chars_to_number (buf, INSN_SIZE);
27951 newval |= value;
27952 md_number_to_chars (buf, newval, INSN_SIZE);
27953 }
27954 break;
27955
27956 case BFD_RELOC_ARM_MULTI:
27957 if (((unsigned long) value) > 0xffff)
27958 as_bad_where (fixP->fx_file, fixP->fx_line,
27959 _("invalid expression in load/store multiple"));
27960 newval = value | md_chars_to_number (buf, INSN_SIZE);
27961 md_number_to_chars (buf, newval, INSN_SIZE);
27962 break;
27963
27964 #ifdef OBJ_ELF
27965 case BFD_RELOC_ARM_PCREL_CALL:
27966
27967 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27968 && fixP->fx_addsy
27969 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27970 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27971 && THUMB_IS_FUNC (fixP->fx_addsy))
27972 /* Flip the bl to blx. This is a simple flip
27973 bit here because we generate PCREL_CALL for
27974 unconditional bls. */
27975 {
27976 newval = md_chars_to_number (buf, INSN_SIZE);
27977 newval = newval | 0x10000000;
27978 md_number_to_chars (buf, newval, INSN_SIZE);
27979 temp = 1;
27980 fixP->fx_done = 1;
27981 }
27982 else
27983 temp = 3;
27984 goto arm_branch_common;
27985
27986 case BFD_RELOC_ARM_PCREL_JUMP:
27987 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27988 && fixP->fx_addsy
27989 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
27990 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
27991 && THUMB_IS_FUNC (fixP->fx_addsy))
27992 {
27993 /* This would map to a bl<cond>, b<cond>,
27994 b<always> to a Thumb function. We
27995 need to force a relocation for this particular
27996 case. */
27997 newval = md_chars_to_number (buf, INSN_SIZE);
27998 fixP->fx_done = 0;
27999 }
28000 /* Fall through. */
28001
28002 case BFD_RELOC_ARM_PLT32:
28003 #endif
28004 case BFD_RELOC_ARM_PCREL_BRANCH:
28005 temp = 3;
28006 goto arm_branch_common;
28007
28008 case BFD_RELOC_ARM_PCREL_BLX:
28009
28010 temp = 1;
28011 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28012 && fixP->fx_addsy
28013 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28014 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28015 && ARM_IS_FUNC (fixP->fx_addsy))
28016 {
28017 /* Flip the blx to a bl and warn. */
28018 const char *name = S_GET_NAME (fixP->fx_addsy);
28019 newval = 0xeb000000;
28020 as_warn_where (fixP->fx_file, fixP->fx_line,
28021 _("blx to '%s' an ARM ISA state function changed to bl"),
28022 name);
28023 md_number_to_chars (buf, newval, INSN_SIZE);
28024 temp = 3;
28025 fixP->fx_done = 1;
28026 }
28027
28028 #ifdef OBJ_ELF
28029 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
28030 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
28031 #endif
28032
28033 arm_branch_common:
28034 /* We are going to store value (shifted right by two) in the
28035 instruction, in a 24 bit, signed field. Bits 26 through 32 either
28036 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
28037 also be clear. */
28038 if (value & temp)
28039 as_bad_where (fixP->fx_file, fixP->fx_line,
28040 _("misaligned branch destination"));
28041 if ((value & (offsetT)0xfe000000) != (offsetT)0
28042 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
28043 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28044
28045 if (fixP->fx_done || !seg->use_rela_p)
28046 {
28047 newval = md_chars_to_number (buf, INSN_SIZE);
28048 newval |= (value >> 2) & 0x00ffffff;
28049 /* Set the H bit on BLX instructions. */
28050 if (temp == 1)
28051 {
28052 if (value & 2)
28053 newval |= 0x01000000;
28054 else
28055 newval &= ~0x01000000;
28056 }
28057 md_number_to_chars (buf, newval, INSN_SIZE);
28058 }
28059 break;
28060
28061 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
28062 /* CBZ can only branch forward. */
28063
28064 /* Attempts to use CBZ to branch to the next instruction
28065 (which, strictly speaking, are prohibited) will be turned into
28066 no-ops.
28067
28068 FIXME: It may be better to remove the instruction completely and
28069 perform relaxation. */
28070 if (value == -2)
28071 {
28072 newval = md_chars_to_number (buf, THUMB_SIZE);
28073 newval = 0xbf00; /* NOP encoding T1 */
28074 md_number_to_chars (buf, newval, THUMB_SIZE);
28075 }
28076 else
28077 {
28078 if (value & ~0x7e)
28079 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28080
28081 if (fixP->fx_done || !seg->use_rela_p)
28082 {
28083 newval = md_chars_to_number (buf, THUMB_SIZE);
28084 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
28085 md_number_to_chars (buf, newval, THUMB_SIZE);
28086 }
28087 }
28088 break;
28089
28090 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
28091 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
28092 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28093
28094 if (fixP->fx_done || !seg->use_rela_p)
28095 {
28096 newval = md_chars_to_number (buf, THUMB_SIZE);
28097 newval |= (value & 0x1ff) >> 1;
28098 md_number_to_chars (buf, newval, THUMB_SIZE);
28099 }
28100 break;
28101
28102 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
28103 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
28104 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28105
28106 if (fixP->fx_done || !seg->use_rela_p)
28107 {
28108 newval = md_chars_to_number (buf, THUMB_SIZE);
28109 newval |= (value & 0xfff) >> 1;
28110 md_number_to_chars (buf, newval, THUMB_SIZE);
28111 }
28112 break;
28113
28114 case BFD_RELOC_THUMB_PCREL_BRANCH20:
28115 if (fixP->fx_addsy
28116 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28117 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28118 && ARM_IS_FUNC (fixP->fx_addsy)
28119 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28120 {
28121 /* Force a relocation for a branch 20 bits wide. */
28122 fixP->fx_done = 0;
28123 }
28124 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
28125 as_bad_where (fixP->fx_file, fixP->fx_line,
28126 _("conditional branch out of range"));
28127
28128 if (fixP->fx_done || !seg->use_rela_p)
28129 {
28130 offsetT newval2;
28131 addressT S, J1, J2, lo, hi;
28132
28133 S = (value & 0x00100000) >> 20;
28134 J2 = (value & 0x00080000) >> 19;
28135 J1 = (value & 0x00040000) >> 18;
28136 hi = (value & 0x0003f000) >> 12;
28137 lo = (value & 0x00000ffe) >> 1;
28138
28139 newval = md_chars_to_number (buf, THUMB_SIZE);
28140 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28141 newval |= (S << 10) | hi;
28142 newval2 |= (J1 << 13) | (J2 << 11) | lo;
28143 md_number_to_chars (buf, newval, THUMB_SIZE);
28144 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28145 }
28146 break;
28147
28148 case BFD_RELOC_THUMB_PCREL_BLX:
28149 /* If there is a blx from a thumb state function to
28150 another thumb function flip this to a bl and warn
28151 about it. */
28152
28153 if (fixP->fx_addsy
28154 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28155 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28156 && THUMB_IS_FUNC (fixP->fx_addsy))
28157 {
28158 const char *name = S_GET_NAME (fixP->fx_addsy);
28159 as_warn_where (fixP->fx_file, fixP->fx_line,
28160 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
28161 name);
28162 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28163 newval = newval | 0x1000;
28164 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28165 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28166 fixP->fx_done = 1;
28167 }
28168
28169
28170 goto thumb_bl_common;
28171
28172 case BFD_RELOC_THUMB_PCREL_BRANCH23:
28173 /* A bl from Thumb state ISA to an internal ARM state function
28174 is converted to a blx. */
28175 if (fixP->fx_addsy
28176 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28177 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28178 && ARM_IS_FUNC (fixP->fx_addsy)
28179 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
28180 {
28181 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28182 newval = newval & ~0x1000;
28183 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
28184 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
28185 fixP->fx_done = 1;
28186 }
28187
28188 thumb_bl_common:
28189
28190 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28191 /* For a BLX instruction, make sure that the relocation is rounded up
28192 to a word boundary. This follows the semantics of the instruction
28193 which specifies that bit 1 of the target address will come from bit
28194 1 of the base address. */
28195 value = (value + 3) & ~ 3;
28196
28197 #ifdef OBJ_ELF
28198 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
28199 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
28200 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
28201 #endif
28202
28203 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
28204 {
28205 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
28206 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28207 else if ((value & ~0x1ffffff)
28208 && ((value & ~0x1ffffff) != ~0x1ffffff))
28209 as_bad_where (fixP->fx_file, fixP->fx_line,
28210 _("Thumb2 branch out of range"));
28211 }
28212
28213 if (fixP->fx_done || !seg->use_rela_p)
28214 encode_thumb2_b_bl_offset (buf, value);
28215
28216 break;
28217
28218 case BFD_RELOC_THUMB_PCREL_BRANCH25:
28219 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
28220 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
28221
28222 if (fixP->fx_done || !seg->use_rela_p)
28223 encode_thumb2_b_bl_offset (buf, value);
28224
28225 break;
28226
28227 case BFD_RELOC_8:
28228 if (fixP->fx_done || !seg->use_rela_p)
28229 *buf = value;
28230 break;
28231
28232 case BFD_RELOC_16:
28233 if (fixP->fx_done || !seg->use_rela_p)
28234 md_number_to_chars (buf, value, 2);
28235 break;
28236
28237 #ifdef OBJ_ELF
28238 case BFD_RELOC_ARM_TLS_CALL:
28239 case BFD_RELOC_ARM_THM_TLS_CALL:
28240 case BFD_RELOC_ARM_TLS_DESCSEQ:
28241 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
28242 case BFD_RELOC_ARM_TLS_GOTDESC:
28243 case BFD_RELOC_ARM_TLS_GD32:
28244 case BFD_RELOC_ARM_TLS_LE32:
28245 case BFD_RELOC_ARM_TLS_IE32:
28246 case BFD_RELOC_ARM_TLS_LDM32:
28247 case BFD_RELOC_ARM_TLS_LDO32:
28248 S_SET_THREAD_LOCAL (fixP->fx_addsy);
28249 break;
28250
28251 /* Same handling as above, but with the arm_fdpic guard. */
28252 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
28253 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
28254 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
28255 if (arm_fdpic)
28256 {
28257 S_SET_THREAD_LOCAL (fixP->fx_addsy);
28258 }
28259 else
28260 {
28261 as_bad_where (fixP->fx_file, fixP->fx_line,
28262 _("Relocation supported only in FDPIC mode"));
28263 }
28264 break;
28265
28266 case BFD_RELOC_ARM_GOT32:
28267 case BFD_RELOC_ARM_GOTOFF:
28268 break;
28269
28270 case BFD_RELOC_ARM_GOT_PREL:
28271 if (fixP->fx_done || !seg->use_rela_p)
28272 md_number_to_chars (buf, value, 4);
28273 break;
28274
28275 case BFD_RELOC_ARM_TARGET2:
28276 /* TARGET2 is not partial-inplace, so we need to write the
28277 addend here for REL targets, because it won't be written out
28278 during reloc processing later. */
28279 if (fixP->fx_done || !seg->use_rela_p)
28280 md_number_to_chars (buf, fixP->fx_offset, 4);
28281 break;
28282
28283 /* Relocations for FDPIC. */
28284 case BFD_RELOC_ARM_GOTFUNCDESC:
28285 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
28286 case BFD_RELOC_ARM_FUNCDESC:
28287 if (arm_fdpic)
28288 {
28289 if (fixP->fx_done || !seg->use_rela_p)
28290 md_number_to_chars (buf, 0, 4);
28291 }
28292 else
28293 {
28294 as_bad_where (fixP->fx_file, fixP->fx_line,
28295 _("Relocation supported only in FDPIC mode"));
28296 }
28297 break;
28298 #endif
28299
28300 case BFD_RELOC_RVA:
28301 case BFD_RELOC_32:
28302 case BFD_RELOC_ARM_TARGET1:
28303 case BFD_RELOC_ARM_ROSEGREL32:
28304 case BFD_RELOC_ARM_SBREL32:
28305 case BFD_RELOC_32_PCREL:
28306 #ifdef TE_PE
28307 case BFD_RELOC_32_SECREL:
28308 #endif
28309 if (fixP->fx_done || !seg->use_rela_p)
28310 #ifdef TE_WINCE
28311 /* For WinCE we only do this for pcrel fixups. */
28312 if (fixP->fx_done || fixP->fx_pcrel)
28313 #endif
28314 md_number_to_chars (buf, value, 4);
28315 break;
28316
28317 #ifdef OBJ_ELF
28318 case BFD_RELOC_ARM_PREL31:
28319 if (fixP->fx_done || !seg->use_rela_p)
28320 {
28321 newval = md_chars_to_number (buf, 4) & 0x80000000;
28322 if ((value ^ (value >> 1)) & 0x40000000)
28323 {
28324 as_bad_where (fixP->fx_file, fixP->fx_line,
28325 _("rel31 relocation overflow"));
28326 }
28327 newval |= value & 0x7fffffff;
28328 md_number_to_chars (buf, newval, 4);
28329 }
28330 break;
28331 #endif
28332
28333 case BFD_RELOC_ARM_CP_OFF_IMM:
28334 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
28335 case BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM:
28336 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
28337 newval = md_chars_to_number (buf, INSN_SIZE);
28338 else
28339 newval = get_thumb32_insn (buf);
28340 if ((newval & 0x0f200f00) == 0x0d000900)
28341 {
28342 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
28343 has permitted values that are multiples of 2, in the range 0
28344 to 510. */
28345 if (value < -510 || value > 510 || (value & 1))
28346 as_bad_where (fixP->fx_file, fixP->fx_line,
28347 _("co-processor offset out of range"));
28348 }
28349 else if ((newval & 0xfe001f80) == 0xec000f80)
28350 {
28351 if (value < -511 || value > 512 || (value & 3))
28352 as_bad_where (fixP->fx_file, fixP->fx_line,
28353 _("co-processor offset out of range"));
28354 }
28355 else if (value < -1023 || value > 1023 || (value & 3))
28356 as_bad_where (fixP->fx_file, fixP->fx_line,
28357 _("co-processor offset out of range"));
28358 cp_off_common:
28359 sign = value > 0;
28360 if (value < 0)
28361 value = -value;
28362 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
28363 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
28364 newval = md_chars_to_number (buf, INSN_SIZE);
28365 else
28366 newval = get_thumb32_insn (buf);
28367 if (value == 0)
28368 {
28369 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
28370 newval &= 0xffffff80;
28371 else
28372 newval &= 0xffffff00;
28373 }
28374 else
28375 {
28376 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_VLDR_VSTR_OFF_IMM)
28377 newval &= 0xff7fff80;
28378 else
28379 newval &= 0xff7fff00;
28380 if ((newval & 0x0f200f00) == 0x0d000900)
28381 {
28382 /* This is a fp16 vstr/vldr.
28383
28384 It requires the immediate offset in the instruction is shifted
28385 left by 1 to be a half-word offset.
28386
28387 Here, left shift by 1 first, and later right shift by 2
28388 should get the right offset. */
28389 value <<= 1;
28390 }
28391 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
28392 }
28393 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
28394 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
28395 md_number_to_chars (buf, newval, INSN_SIZE);
28396 else
28397 put_thumb32_insn (buf, newval);
28398 break;
28399
28400 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
28401 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
28402 if (value < -255 || value > 255)
28403 as_bad_where (fixP->fx_file, fixP->fx_line,
28404 _("co-processor offset out of range"));
28405 value *= 4;
28406 goto cp_off_common;
28407
28408 case BFD_RELOC_ARM_THUMB_OFFSET:
28409 newval = md_chars_to_number (buf, THUMB_SIZE);
28410 /* Exactly what ranges, and where the offset is inserted depends
28411 on the type of instruction, we can establish this from the
28412 top 4 bits. */
28413 switch (newval >> 12)
28414 {
28415 case 4: /* PC load. */
28416 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
28417 forced to zero for these loads; md_pcrel_from has already
28418 compensated for this. */
28419 if (value & 3)
28420 as_bad_where (fixP->fx_file, fixP->fx_line,
28421 _("invalid offset, target not word aligned (0x%08lX)"),
28422 (((unsigned long) fixP->fx_frag->fr_address
28423 + (unsigned long) fixP->fx_where) & ~3)
28424 + (unsigned long) value);
28425
28426 if (value & ~0x3fc)
28427 as_bad_where (fixP->fx_file, fixP->fx_line,
28428 _("invalid offset, value too big (0x%08lX)"),
28429 (long) value);
28430
28431 newval |= value >> 2;
28432 break;
28433
28434 case 9: /* SP load/store. */
28435 if (value & ~0x3fc)
28436 as_bad_where (fixP->fx_file, fixP->fx_line,
28437 _("invalid offset, value too big (0x%08lX)"),
28438 (long) value);
28439 newval |= value >> 2;
28440 break;
28441
28442 case 6: /* Word load/store. */
28443 if (value & ~0x7c)
28444 as_bad_where (fixP->fx_file, fixP->fx_line,
28445 _("invalid offset, value too big (0x%08lX)"),
28446 (long) value);
28447 newval |= value << 4; /* 6 - 2. */
28448 break;
28449
28450 case 7: /* Byte load/store. */
28451 if (value & ~0x1f)
28452 as_bad_where (fixP->fx_file, fixP->fx_line,
28453 _("invalid offset, value too big (0x%08lX)"),
28454 (long) value);
28455 newval |= value << 6;
28456 break;
28457
28458 case 8: /* Halfword load/store. */
28459 if (value & ~0x3e)
28460 as_bad_where (fixP->fx_file, fixP->fx_line,
28461 _("invalid offset, value too big (0x%08lX)"),
28462 (long) value);
28463 newval |= value << 5; /* 6 - 1. */
28464 break;
28465
28466 default:
28467 as_bad_where (fixP->fx_file, fixP->fx_line,
28468 "Unable to process relocation for thumb opcode: %lx",
28469 (unsigned long) newval);
28470 break;
28471 }
28472 md_number_to_chars (buf, newval, THUMB_SIZE);
28473 break;
28474
28475 case BFD_RELOC_ARM_THUMB_ADD:
28476 /* This is a complicated relocation, since we use it for all of
28477 the following immediate relocations:
28478
28479 3bit ADD/SUB
28480 8bit ADD/SUB
28481 9bit ADD/SUB SP word-aligned
28482 10bit ADD PC/SP word-aligned
28483
28484 The type of instruction being processed is encoded in the
28485 instruction field:
28486
28487 0x8000 SUB
28488 0x00F0 Rd
28489 0x000F Rs
28490 */
28491 newval = md_chars_to_number (buf, THUMB_SIZE);
28492 {
28493 int rd = (newval >> 4) & 0xf;
28494 int rs = newval & 0xf;
28495 int subtract = !!(newval & 0x8000);
28496
28497 /* Check for HI regs, only very restricted cases allowed:
28498 Adjusting SP, and using PC or SP to get an address. */
28499 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
28500 || (rs > 7 && rs != REG_SP && rs != REG_PC))
28501 as_bad_where (fixP->fx_file, fixP->fx_line,
28502 _("invalid Hi register with immediate"));
28503
28504 /* If value is negative, choose the opposite instruction. */
28505 if (value < 0)
28506 {
28507 value = -value;
28508 subtract = !subtract;
28509 if (value < 0)
28510 as_bad_where (fixP->fx_file, fixP->fx_line,
28511 _("immediate value out of range"));
28512 }
28513
28514 if (rd == REG_SP)
28515 {
28516 if (value & ~0x1fc)
28517 as_bad_where (fixP->fx_file, fixP->fx_line,
28518 _("invalid immediate for stack address calculation"));
28519 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
28520 newval |= value >> 2;
28521 }
28522 else if (rs == REG_PC || rs == REG_SP)
28523 {
28524 /* PR gas/18541. If the addition is for a defined symbol
28525 within range of an ADR instruction then accept it. */
28526 if (subtract
28527 && value == 4
28528 && fixP->fx_addsy != NULL)
28529 {
28530 subtract = 0;
28531
28532 if (! S_IS_DEFINED (fixP->fx_addsy)
28533 || S_GET_SEGMENT (fixP->fx_addsy) != seg
28534 || S_IS_WEAK (fixP->fx_addsy))
28535 {
28536 as_bad_where (fixP->fx_file, fixP->fx_line,
28537 _("address calculation needs a strongly defined nearby symbol"));
28538 }
28539 else
28540 {
28541 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
28542
28543 /* Round up to the next 4-byte boundary. */
28544 if (v & 3)
28545 v = (v + 3) & ~ 3;
28546 else
28547 v += 4;
28548 v = S_GET_VALUE (fixP->fx_addsy) - v;
28549
28550 if (v & ~0x3fc)
28551 {
28552 as_bad_where (fixP->fx_file, fixP->fx_line,
28553 _("symbol too far away"));
28554 }
28555 else
28556 {
28557 fixP->fx_done = 1;
28558 value = v;
28559 }
28560 }
28561 }
28562
28563 if (subtract || value & ~0x3fc)
28564 as_bad_where (fixP->fx_file, fixP->fx_line,
28565 _("invalid immediate for address calculation (value = 0x%08lX)"),
28566 (unsigned long) (subtract ? - value : value));
28567 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
28568 newval |= rd << 8;
28569 newval |= value >> 2;
28570 }
28571 else if (rs == rd)
28572 {
28573 if (value & ~0xff)
28574 as_bad_where (fixP->fx_file, fixP->fx_line,
28575 _("immediate value out of range"));
28576 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
28577 newval |= (rd << 8) | value;
28578 }
28579 else
28580 {
28581 if (value & ~0x7)
28582 as_bad_where (fixP->fx_file, fixP->fx_line,
28583 _("immediate value out of range"));
28584 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
28585 newval |= rd | (rs << 3) | (value << 6);
28586 }
28587 }
28588 md_number_to_chars (buf, newval, THUMB_SIZE);
28589 break;
28590
28591 case BFD_RELOC_ARM_THUMB_IMM:
28592 newval = md_chars_to_number (buf, THUMB_SIZE);
28593 if (value < 0 || value > 255)
28594 as_bad_where (fixP->fx_file, fixP->fx_line,
28595 _("invalid immediate: %ld is out of range"),
28596 (long) value);
28597 newval |= value;
28598 md_number_to_chars (buf, newval, THUMB_SIZE);
28599 break;
28600
28601 case BFD_RELOC_ARM_THUMB_SHIFT:
28602 /* 5bit shift value (0..32). LSL cannot take 32. */
28603 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
28604 temp = newval & 0xf800;
28605 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
28606 as_bad_where (fixP->fx_file, fixP->fx_line,
28607 _("invalid shift value: %ld"), (long) value);
28608 /* Shifts of zero must be encoded as LSL. */
28609 if (value == 0)
28610 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
28611 /* Shifts of 32 are encoded as zero. */
28612 else if (value == 32)
28613 value = 0;
28614 newval |= value << 6;
28615 md_number_to_chars (buf, newval, THUMB_SIZE);
28616 break;
28617
28618 case BFD_RELOC_VTABLE_INHERIT:
28619 case BFD_RELOC_VTABLE_ENTRY:
28620 fixP->fx_done = 0;
28621 return;
28622
28623 case BFD_RELOC_ARM_MOVW:
28624 case BFD_RELOC_ARM_MOVT:
28625 case BFD_RELOC_ARM_THUMB_MOVW:
28626 case BFD_RELOC_ARM_THUMB_MOVT:
28627 if (fixP->fx_done || !seg->use_rela_p)
28628 {
28629 /* REL format relocations are limited to a 16-bit addend. */
28630 if (!fixP->fx_done)
28631 {
28632 if (value < -0x8000 || value > 0x7fff)
28633 as_bad_where (fixP->fx_file, fixP->fx_line,
28634 _("offset out of range"));
28635 }
28636 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
28637 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
28638 {
28639 value >>= 16;
28640 }
28641
28642 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
28643 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
28644 {
28645 newval = get_thumb32_insn (buf);
28646 newval &= 0xfbf08f00;
28647 newval |= (value & 0xf000) << 4;
28648 newval |= (value & 0x0800) << 15;
28649 newval |= (value & 0x0700) << 4;
28650 newval |= (value & 0x00ff);
28651 put_thumb32_insn (buf, newval);
28652 }
28653 else
28654 {
28655 newval = md_chars_to_number (buf, 4);
28656 newval &= 0xfff0f000;
28657 newval |= value & 0x0fff;
28658 newval |= (value & 0xf000) << 4;
28659 md_number_to_chars (buf, newval, 4);
28660 }
28661 }
28662 return;
28663
28664 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
28665 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
28666 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
28667 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
28668 gas_assert (!fixP->fx_done);
28669 {
28670 bfd_vma insn;
28671 bfd_boolean is_mov;
28672 bfd_vma encoded_addend = value;
28673
28674 /* Check that addend can be encoded in instruction. */
28675 if (!seg->use_rela_p && (value < 0 || value > 255))
28676 as_bad_where (fixP->fx_file, fixP->fx_line,
28677 _("the offset 0x%08lX is not representable"),
28678 (unsigned long) encoded_addend);
28679
28680 /* Extract the instruction. */
28681 insn = md_chars_to_number (buf, THUMB_SIZE);
28682 is_mov = (insn & 0xf800) == 0x2000;
28683
28684 /* Encode insn. */
28685 if (is_mov)
28686 {
28687 if (!seg->use_rela_p)
28688 insn |= encoded_addend;
28689 }
28690 else
28691 {
28692 int rd, rs;
28693
28694 /* Extract the instruction. */
28695 /* Encoding is the following
28696 0x8000 SUB
28697 0x00F0 Rd
28698 0x000F Rs
28699 */
28700 /* The following conditions must be true :
28701 - ADD
28702 - Rd == Rs
28703 - Rd <= 7
28704 */
28705 rd = (insn >> 4) & 0xf;
28706 rs = insn & 0xf;
28707 if ((insn & 0x8000) || (rd != rs) || rd > 7)
28708 as_bad_where (fixP->fx_file, fixP->fx_line,
28709 _("Unable to process relocation for thumb opcode: %lx"),
28710 (unsigned long) insn);
28711
28712 /* Encode as ADD immediate8 thumb 1 code. */
28713 insn = 0x3000 | (rd << 8);
28714
28715 /* Place the encoded addend into the first 8 bits of the
28716 instruction. */
28717 if (!seg->use_rela_p)
28718 insn |= encoded_addend;
28719 }
28720
28721 /* Update the instruction. */
28722 md_number_to_chars (buf, insn, THUMB_SIZE);
28723 }
28724 break;
28725
28726 case BFD_RELOC_ARM_ALU_PC_G0_NC:
28727 case BFD_RELOC_ARM_ALU_PC_G0:
28728 case BFD_RELOC_ARM_ALU_PC_G1_NC:
28729 case BFD_RELOC_ARM_ALU_PC_G1:
28730 case BFD_RELOC_ARM_ALU_PC_G2:
28731 case BFD_RELOC_ARM_ALU_SB_G0_NC:
28732 case BFD_RELOC_ARM_ALU_SB_G0:
28733 case BFD_RELOC_ARM_ALU_SB_G1_NC:
28734 case BFD_RELOC_ARM_ALU_SB_G1:
28735 case BFD_RELOC_ARM_ALU_SB_G2:
28736 gas_assert (!fixP->fx_done);
28737 if (!seg->use_rela_p)
28738 {
28739 bfd_vma insn;
28740 bfd_vma encoded_addend;
28741 bfd_vma addend_abs = llabs (value);
28742
28743 /* Check that the absolute value of the addend can be
28744 expressed as an 8-bit constant plus a rotation. */
28745 encoded_addend = encode_arm_immediate (addend_abs);
28746 if (encoded_addend == (unsigned int) FAIL)
28747 as_bad_where (fixP->fx_file, fixP->fx_line,
28748 _("the offset 0x%08lX is not representable"),
28749 (unsigned long) addend_abs);
28750
28751 /* Extract the instruction. */
28752 insn = md_chars_to_number (buf, INSN_SIZE);
28753
28754 /* If the addend is positive, use an ADD instruction.
28755 Otherwise use a SUB. Take care not to destroy the S bit. */
28756 insn &= 0xff1fffff;
28757 if (value < 0)
28758 insn |= 1 << 22;
28759 else
28760 insn |= 1 << 23;
28761
28762 /* Place the encoded addend into the first 12 bits of the
28763 instruction. */
28764 insn &= 0xfffff000;
28765 insn |= encoded_addend;
28766
28767 /* Update the instruction. */
28768 md_number_to_chars (buf, insn, INSN_SIZE);
28769 }
28770 break;
28771
28772 case BFD_RELOC_ARM_LDR_PC_G0:
28773 case BFD_RELOC_ARM_LDR_PC_G1:
28774 case BFD_RELOC_ARM_LDR_PC_G2:
28775 case BFD_RELOC_ARM_LDR_SB_G0:
28776 case BFD_RELOC_ARM_LDR_SB_G1:
28777 case BFD_RELOC_ARM_LDR_SB_G2:
28778 gas_assert (!fixP->fx_done);
28779 if (!seg->use_rela_p)
28780 {
28781 bfd_vma insn;
28782 bfd_vma addend_abs = llabs (value);
28783
28784 /* Check that the absolute value of the addend can be
28785 encoded in 12 bits. */
28786 if (addend_abs >= 0x1000)
28787 as_bad_where (fixP->fx_file, fixP->fx_line,
28788 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
28789 (unsigned long) addend_abs);
28790
28791 /* Extract the instruction. */
28792 insn = md_chars_to_number (buf, INSN_SIZE);
28793
28794 /* If the addend is negative, clear bit 23 of the instruction.
28795 Otherwise set it. */
28796 if (value < 0)
28797 insn &= ~(1 << 23);
28798 else
28799 insn |= 1 << 23;
28800
28801 /* Place the absolute value of the addend into the first 12 bits
28802 of the instruction. */
28803 insn &= 0xfffff000;
28804 insn |= addend_abs;
28805
28806 /* Update the instruction. */
28807 md_number_to_chars (buf, insn, INSN_SIZE);
28808 }
28809 break;
28810
28811 case BFD_RELOC_ARM_LDRS_PC_G0:
28812 case BFD_RELOC_ARM_LDRS_PC_G1:
28813 case BFD_RELOC_ARM_LDRS_PC_G2:
28814 case BFD_RELOC_ARM_LDRS_SB_G0:
28815 case BFD_RELOC_ARM_LDRS_SB_G1:
28816 case BFD_RELOC_ARM_LDRS_SB_G2:
28817 gas_assert (!fixP->fx_done);
28818 if (!seg->use_rela_p)
28819 {
28820 bfd_vma insn;
28821 bfd_vma addend_abs = llabs (value);
28822
28823 /* Check that the absolute value of the addend can be
28824 encoded in 8 bits. */
28825 if (addend_abs >= 0x100)
28826 as_bad_where (fixP->fx_file, fixP->fx_line,
28827 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
28828 (unsigned long) addend_abs);
28829
28830 /* Extract the instruction. */
28831 insn = md_chars_to_number (buf, INSN_SIZE);
28832
28833 /* If the addend is negative, clear bit 23 of the instruction.
28834 Otherwise set it. */
28835 if (value < 0)
28836 insn &= ~(1 << 23);
28837 else
28838 insn |= 1 << 23;
28839
28840 /* Place the first four bits of the absolute value of the addend
28841 into the first 4 bits of the instruction, and the remaining
28842 four into bits 8 .. 11. */
28843 insn &= 0xfffff0f0;
28844 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
28845
28846 /* Update the instruction. */
28847 md_number_to_chars (buf, insn, INSN_SIZE);
28848 }
28849 break;
28850
28851 case BFD_RELOC_ARM_LDC_PC_G0:
28852 case BFD_RELOC_ARM_LDC_PC_G1:
28853 case BFD_RELOC_ARM_LDC_PC_G2:
28854 case BFD_RELOC_ARM_LDC_SB_G0:
28855 case BFD_RELOC_ARM_LDC_SB_G1:
28856 case BFD_RELOC_ARM_LDC_SB_G2:
28857 gas_assert (!fixP->fx_done);
28858 if (!seg->use_rela_p)
28859 {
28860 bfd_vma insn;
28861 bfd_vma addend_abs = llabs (value);
28862
28863 /* Check that the absolute value of the addend is a multiple of
28864 four and, when divided by four, fits in 8 bits. */
28865 if (addend_abs & 0x3)
28866 as_bad_where (fixP->fx_file, fixP->fx_line,
28867 _("bad offset 0x%08lX (must be word-aligned)"),
28868 (unsigned long) addend_abs);
28869
28870 if ((addend_abs >> 2) > 0xff)
28871 as_bad_where (fixP->fx_file, fixP->fx_line,
28872 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
28873 (unsigned long) addend_abs);
28874
28875 /* Extract the instruction. */
28876 insn = md_chars_to_number (buf, INSN_SIZE);
28877
28878 /* If the addend is negative, clear bit 23 of the instruction.
28879 Otherwise set it. */
28880 if (value < 0)
28881 insn &= ~(1 << 23);
28882 else
28883 insn |= 1 << 23;
28884
28885 /* Place the addend (divided by four) into the first eight
28886 bits of the instruction. */
28887 insn &= 0xfffffff0;
28888 insn |= addend_abs >> 2;
28889
28890 /* Update the instruction. */
28891 md_number_to_chars (buf, insn, INSN_SIZE);
28892 }
28893 break;
28894
28895 case BFD_RELOC_THUMB_PCREL_BRANCH5:
28896 if (fixP->fx_addsy
28897 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28898 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28899 && ARM_IS_FUNC (fixP->fx_addsy)
28900 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28901 {
28902 /* Force a relocation for a branch 5 bits wide. */
28903 fixP->fx_done = 0;
28904 }
28905 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
28906 as_bad_where (fixP->fx_file, fixP->fx_line,
28907 BAD_BRANCH_OFF);
28908
28909 if (fixP->fx_done || !seg->use_rela_p)
28910 {
28911 addressT boff = value >> 1;
28912
28913 newval = md_chars_to_number (buf, THUMB_SIZE);
28914 newval |= (boff << 7);
28915 md_number_to_chars (buf, newval, THUMB_SIZE);
28916 }
28917 break;
28918
28919 case BFD_RELOC_THUMB_PCREL_BFCSEL:
28920 if (fixP->fx_addsy
28921 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28922 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28923 && ARM_IS_FUNC (fixP->fx_addsy)
28924 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28925 {
28926 fixP->fx_done = 0;
28927 }
28928 if ((value & ~0x7f) && ((value & ~0x3f) != ~0x3f))
28929 as_bad_where (fixP->fx_file, fixP->fx_line,
28930 _("branch out of range"));
28931
28932 if (fixP->fx_done || !seg->use_rela_p)
28933 {
28934 newval = md_chars_to_number (buf, THUMB_SIZE);
28935
28936 addressT boff = ((newval & 0x0780) >> 7) << 1;
28937 addressT diff = value - boff;
28938
28939 if (diff == 4)
28940 {
28941 newval |= 1 << 1; /* T bit. */
28942 }
28943 else if (diff != 2)
28944 {
28945 as_bad_where (fixP->fx_file, fixP->fx_line,
28946 _("out of range label-relative fixup value"));
28947 }
28948 md_number_to_chars (buf, newval, THUMB_SIZE);
28949 }
28950 break;
28951
28952 case BFD_RELOC_ARM_THUMB_BF17:
28953 if (fixP->fx_addsy
28954 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28955 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28956 && ARM_IS_FUNC (fixP->fx_addsy)
28957 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28958 {
28959 /* Force a relocation for a branch 17 bits wide. */
28960 fixP->fx_done = 0;
28961 }
28962
28963 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
28964 as_bad_where (fixP->fx_file, fixP->fx_line,
28965 BAD_BRANCH_OFF);
28966
28967 if (fixP->fx_done || !seg->use_rela_p)
28968 {
28969 offsetT newval2;
28970 addressT immA, immB, immC;
28971
28972 immA = (value & 0x0001f000) >> 12;
28973 immB = (value & 0x00000ffc) >> 2;
28974 immC = (value & 0x00000002) >> 1;
28975
28976 newval = md_chars_to_number (buf, THUMB_SIZE);
28977 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
28978 newval |= immA;
28979 newval2 |= (immC << 11) | (immB << 1);
28980 md_number_to_chars (buf, newval, THUMB_SIZE);
28981 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
28982 }
28983 break;
28984
28985 case BFD_RELOC_ARM_THUMB_BF19:
28986 if (fixP->fx_addsy
28987 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
28988 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
28989 && ARM_IS_FUNC (fixP->fx_addsy)
28990 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
28991 {
28992 /* Force a relocation for a branch 19 bits wide. */
28993 fixP->fx_done = 0;
28994 }
28995
28996 if (v8_1_branch_value_check (value, 19, TRUE) == FAIL)
28997 as_bad_where (fixP->fx_file, fixP->fx_line,
28998 BAD_BRANCH_OFF);
28999
29000 if (fixP->fx_done || !seg->use_rela_p)
29001 {
29002 offsetT newval2;
29003 addressT immA, immB, immC;
29004
29005 immA = (value & 0x0007f000) >> 12;
29006 immB = (value & 0x00000ffc) >> 2;
29007 immC = (value & 0x00000002) >> 1;
29008
29009 newval = md_chars_to_number (buf, THUMB_SIZE);
29010 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29011 newval |= immA;
29012 newval2 |= (immC << 11) | (immB << 1);
29013 md_number_to_chars (buf, newval, THUMB_SIZE);
29014 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29015 }
29016 break;
29017
29018 case BFD_RELOC_ARM_THUMB_BF13:
29019 if (fixP->fx_addsy
29020 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29021 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29022 && ARM_IS_FUNC (fixP->fx_addsy)
29023 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29024 {
29025 /* Force a relocation for a branch 13 bits wide. */
29026 fixP->fx_done = 0;
29027 }
29028
29029 if (v8_1_branch_value_check (value, 13, TRUE) == FAIL)
29030 as_bad_where (fixP->fx_file, fixP->fx_line,
29031 BAD_BRANCH_OFF);
29032
29033 if (fixP->fx_done || !seg->use_rela_p)
29034 {
29035 offsetT newval2;
29036 addressT immA, immB, immC;
29037
29038 immA = (value & 0x00001000) >> 12;
29039 immB = (value & 0x00000ffc) >> 2;
29040 immC = (value & 0x00000002) >> 1;
29041
29042 newval = md_chars_to_number (buf, THUMB_SIZE);
29043 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29044 newval |= immA;
29045 newval2 |= (immC << 11) | (immB << 1);
29046 md_number_to_chars (buf, newval, THUMB_SIZE);
29047 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
29048 }
29049 break;
29050
29051 case BFD_RELOC_ARM_THUMB_LOOP12:
29052 if (fixP->fx_addsy
29053 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
29054 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
29055 && ARM_IS_FUNC (fixP->fx_addsy)
29056 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
29057 {
29058 /* Force a relocation for a branch 12 bits wide. */
29059 fixP->fx_done = 0;
29060 }
29061
29062 bfd_vma insn = get_thumb32_insn (buf);
29063 /* le lr, <label>, le <label> or letp lr, <label> */
29064 if (((insn & 0xffffffff) == 0xf00fc001)
29065 || ((insn & 0xffffffff) == 0xf02fc001)
29066 || ((insn & 0xffffffff) == 0xf01fc001))
29067 value = -value;
29068
29069 if (v8_1_branch_value_check (value, 12, FALSE) == FAIL)
29070 as_bad_where (fixP->fx_file, fixP->fx_line,
29071 BAD_BRANCH_OFF);
29072 if (fixP->fx_done || !seg->use_rela_p)
29073 {
29074 addressT imml, immh;
29075
29076 immh = (value & 0x00000ffc) >> 2;
29077 imml = (value & 0x00000002) >> 1;
29078
29079 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
29080 newval |= (imml << 11) | (immh << 1);
29081 md_number_to_chars (buf + THUMB_SIZE, newval, THUMB_SIZE);
29082 }
29083 break;
29084
29085 case BFD_RELOC_ARM_V4BX:
29086 /* This will need to go in the object file. */
29087 fixP->fx_done = 0;
29088 break;
29089
29090 case BFD_RELOC_UNUSED:
29091 default:
29092 as_bad_where (fixP->fx_file, fixP->fx_line,
29093 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
29094 }
29095 }
29096
29097 /* Translate internal representation of relocation info to BFD target
29098 format. */
29099
29100 arelent *
29101 tc_gen_reloc (asection *section, fixS *fixp)
29102 {
29103 arelent * reloc;
29104 bfd_reloc_code_real_type code;
29105
29106 reloc = XNEW (arelent);
29107
29108 reloc->sym_ptr_ptr = XNEW (asymbol *);
29109 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
29110 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
29111
29112 if (fixp->fx_pcrel)
29113 {
29114 if (section->use_rela_p)
29115 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
29116 else
29117 fixp->fx_offset = reloc->address;
29118 }
29119 reloc->addend = fixp->fx_offset;
29120
29121 switch (fixp->fx_r_type)
29122 {
29123 case BFD_RELOC_8:
29124 if (fixp->fx_pcrel)
29125 {
29126 code = BFD_RELOC_8_PCREL;
29127 break;
29128 }
29129 /* Fall through. */
29130
29131 case BFD_RELOC_16:
29132 if (fixp->fx_pcrel)
29133 {
29134 code = BFD_RELOC_16_PCREL;
29135 break;
29136 }
29137 /* Fall through. */
29138
29139 case BFD_RELOC_32:
29140 if (fixp->fx_pcrel)
29141 {
29142 code = BFD_RELOC_32_PCREL;
29143 break;
29144 }
29145 /* Fall through. */
29146
29147 case BFD_RELOC_ARM_MOVW:
29148 if (fixp->fx_pcrel)
29149 {
29150 code = BFD_RELOC_ARM_MOVW_PCREL;
29151 break;
29152 }
29153 /* Fall through. */
29154
29155 case BFD_RELOC_ARM_MOVT:
29156 if (fixp->fx_pcrel)
29157 {
29158 code = BFD_RELOC_ARM_MOVT_PCREL;
29159 break;
29160 }
29161 /* Fall through. */
29162
29163 case BFD_RELOC_ARM_THUMB_MOVW:
29164 if (fixp->fx_pcrel)
29165 {
29166 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
29167 break;
29168 }
29169 /* Fall through. */
29170
29171 case BFD_RELOC_ARM_THUMB_MOVT:
29172 if (fixp->fx_pcrel)
29173 {
29174 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
29175 break;
29176 }
29177 /* Fall through. */
29178
29179 case BFD_RELOC_NONE:
29180 case BFD_RELOC_ARM_PCREL_BRANCH:
29181 case BFD_RELOC_ARM_PCREL_BLX:
29182 case BFD_RELOC_RVA:
29183 case BFD_RELOC_THUMB_PCREL_BRANCH7:
29184 case BFD_RELOC_THUMB_PCREL_BRANCH9:
29185 case BFD_RELOC_THUMB_PCREL_BRANCH12:
29186 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29187 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29188 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29189 case BFD_RELOC_VTABLE_ENTRY:
29190 case BFD_RELOC_VTABLE_INHERIT:
29191 #ifdef TE_PE
29192 case BFD_RELOC_32_SECREL:
29193 #endif
29194 code = fixp->fx_r_type;
29195 break;
29196
29197 case BFD_RELOC_THUMB_PCREL_BLX:
29198 #ifdef OBJ_ELF
29199 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
29200 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
29201 else
29202 #endif
29203 code = BFD_RELOC_THUMB_PCREL_BLX;
29204 break;
29205
29206 case BFD_RELOC_ARM_LITERAL:
29207 case BFD_RELOC_ARM_HWLITERAL:
29208 /* If this is called then the a literal has
29209 been referenced across a section boundary. */
29210 as_bad_where (fixp->fx_file, fixp->fx_line,
29211 _("literal referenced across section boundary"));
29212 return NULL;
29213
29214 #ifdef OBJ_ELF
29215 case BFD_RELOC_ARM_TLS_CALL:
29216 case BFD_RELOC_ARM_THM_TLS_CALL:
29217 case BFD_RELOC_ARM_TLS_DESCSEQ:
29218 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
29219 case BFD_RELOC_ARM_GOT32:
29220 case BFD_RELOC_ARM_GOTOFF:
29221 case BFD_RELOC_ARM_GOT_PREL:
29222 case BFD_RELOC_ARM_PLT32:
29223 case BFD_RELOC_ARM_TARGET1:
29224 case BFD_RELOC_ARM_ROSEGREL32:
29225 case BFD_RELOC_ARM_SBREL32:
29226 case BFD_RELOC_ARM_PREL31:
29227 case BFD_RELOC_ARM_TARGET2:
29228 case BFD_RELOC_ARM_TLS_LDO32:
29229 case BFD_RELOC_ARM_PCREL_CALL:
29230 case BFD_RELOC_ARM_PCREL_JUMP:
29231 case BFD_RELOC_ARM_ALU_PC_G0_NC:
29232 case BFD_RELOC_ARM_ALU_PC_G0:
29233 case BFD_RELOC_ARM_ALU_PC_G1_NC:
29234 case BFD_RELOC_ARM_ALU_PC_G1:
29235 case BFD_RELOC_ARM_ALU_PC_G2:
29236 case BFD_RELOC_ARM_LDR_PC_G0:
29237 case BFD_RELOC_ARM_LDR_PC_G1:
29238 case BFD_RELOC_ARM_LDR_PC_G2:
29239 case BFD_RELOC_ARM_LDRS_PC_G0:
29240 case BFD_RELOC_ARM_LDRS_PC_G1:
29241 case BFD_RELOC_ARM_LDRS_PC_G2:
29242 case BFD_RELOC_ARM_LDC_PC_G0:
29243 case BFD_RELOC_ARM_LDC_PC_G1:
29244 case BFD_RELOC_ARM_LDC_PC_G2:
29245 case BFD_RELOC_ARM_ALU_SB_G0_NC:
29246 case BFD_RELOC_ARM_ALU_SB_G0:
29247 case BFD_RELOC_ARM_ALU_SB_G1_NC:
29248 case BFD_RELOC_ARM_ALU_SB_G1:
29249 case BFD_RELOC_ARM_ALU_SB_G2:
29250 case BFD_RELOC_ARM_LDR_SB_G0:
29251 case BFD_RELOC_ARM_LDR_SB_G1:
29252 case BFD_RELOC_ARM_LDR_SB_G2:
29253 case BFD_RELOC_ARM_LDRS_SB_G0:
29254 case BFD_RELOC_ARM_LDRS_SB_G1:
29255 case BFD_RELOC_ARM_LDRS_SB_G2:
29256 case BFD_RELOC_ARM_LDC_SB_G0:
29257 case BFD_RELOC_ARM_LDC_SB_G1:
29258 case BFD_RELOC_ARM_LDC_SB_G2:
29259 case BFD_RELOC_ARM_V4BX:
29260 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
29261 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
29262 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
29263 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
29264 case BFD_RELOC_ARM_GOTFUNCDESC:
29265 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
29266 case BFD_RELOC_ARM_FUNCDESC:
29267 case BFD_RELOC_ARM_THUMB_BF17:
29268 case BFD_RELOC_ARM_THUMB_BF19:
29269 case BFD_RELOC_ARM_THUMB_BF13:
29270 code = fixp->fx_r_type;
29271 break;
29272
29273 case BFD_RELOC_ARM_TLS_GOTDESC:
29274 case BFD_RELOC_ARM_TLS_GD32:
29275 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
29276 case BFD_RELOC_ARM_TLS_LE32:
29277 case BFD_RELOC_ARM_TLS_IE32:
29278 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
29279 case BFD_RELOC_ARM_TLS_LDM32:
29280 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
29281 /* BFD will include the symbol's address in the addend.
29282 But we don't want that, so subtract it out again here. */
29283 if (!S_IS_COMMON (fixp->fx_addsy))
29284 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
29285 code = fixp->fx_r_type;
29286 break;
29287 #endif
29288
29289 case BFD_RELOC_ARM_IMMEDIATE:
29290 as_bad_where (fixp->fx_file, fixp->fx_line,
29291 _("internal relocation (type: IMMEDIATE) not fixed up"));
29292 return NULL;
29293
29294 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
29295 as_bad_where (fixp->fx_file, fixp->fx_line,
29296 _("ADRL used for a symbol not defined in the same file"));
29297 return NULL;
29298
29299 case BFD_RELOC_THUMB_PCREL_BRANCH5:
29300 case BFD_RELOC_THUMB_PCREL_BFCSEL:
29301 case BFD_RELOC_ARM_THUMB_LOOP12:
29302 as_bad_where (fixp->fx_file, fixp->fx_line,
29303 _("%s used for a symbol not defined in the same file"),
29304 bfd_get_reloc_code_name (fixp->fx_r_type));
29305 return NULL;
29306
29307 case BFD_RELOC_ARM_OFFSET_IMM:
29308 if (section->use_rela_p)
29309 {
29310 code = fixp->fx_r_type;
29311 break;
29312 }
29313
29314 if (fixp->fx_addsy != NULL
29315 && !S_IS_DEFINED (fixp->fx_addsy)
29316 && S_IS_LOCAL (fixp->fx_addsy))
29317 {
29318 as_bad_where (fixp->fx_file, fixp->fx_line,
29319 _("undefined local label `%s'"),
29320 S_GET_NAME (fixp->fx_addsy));
29321 return NULL;
29322 }
29323
29324 as_bad_where (fixp->fx_file, fixp->fx_line,
29325 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
29326 return NULL;
29327
29328 default:
29329 {
29330 const char * type;
29331
29332 switch (fixp->fx_r_type)
29333 {
29334 case BFD_RELOC_NONE: type = "NONE"; break;
29335 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
29336 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
29337 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
29338 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
29339 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
29340 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
29341 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
29342 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
29343 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
29344 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
29345 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
29346 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
29347 default: type = _("<unknown>"); break;
29348 }
29349 as_bad_where (fixp->fx_file, fixp->fx_line,
29350 _("cannot represent %s relocation in this object file format"),
29351 type);
29352 return NULL;
29353 }
29354 }
29355
29356 #ifdef OBJ_ELF
29357 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
29358 && GOT_symbol
29359 && fixp->fx_addsy == GOT_symbol)
29360 {
29361 code = BFD_RELOC_ARM_GOTPC;
29362 reloc->addend = fixp->fx_offset = reloc->address;
29363 }
29364 #endif
29365
29366 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
29367
29368 if (reloc->howto == NULL)
29369 {
29370 as_bad_where (fixp->fx_file, fixp->fx_line,
29371 _("cannot represent %s relocation in this object file format"),
29372 bfd_get_reloc_code_name (code));
29373 return NULL;
29374 }
29375
29376 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
29377 vtable entry to be used in the relocation's section offset. */
29378 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
29379 reloc->address = fixp->fx_offset;
29380
29381 return reloc;
29382 }
29383
29384 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
29385
29386 void
29387 cons_fix_new_arm (fragS * frag,
29388 int where,
29389 int size,
29390 expressionS * exp,
29391 bfd_reloc_code_real_type reloc)
29392 {
29393 int pcrel = 0;
29394
29395 /* Pick a reloc.
29396 FIXME: @@ Should look at CPU word size. */
29397 switch (size)
29398 {
29399 case 1:
29400 reloc = BFD_RELOC_8;
29401 break;
29402 case 2:
29403 reloc = BFD_RELOC_16;
29404 break;
29405 case 4:
29406 default:
29407 reloc = BFD_RELOC_32;
29408 break;
29409 case 8:
29410 reloc = BFD_RELOC_64;
29411 break;
29412 }
29413
29414 #ifdef TE_PE
29415 if (exp->X_op == O_secrel)
29416 {
29417 exp->X_op = O_symbol;
29418 reloc = BFD_RELOC_32_SECREL;
29419 }
29420 #endif
29421
29422 fix_new_exp (frag, where, size, exp, pcrel, reloc);
29423 }
29424
29425 #if defined (OBJ_COFF)
29426 void
29427 arm_validate_fix (fixS * fixP)
29428 {
29429 /* If the destination of the branch is a defined symbol which does not have
29430 the THUMB_FUNC attribute, then we must be calling a function which has
29431 the (interfacearm) attribute. We look for the Thumb entry point to that
29432 function and change the branch to refer to that function instead. */
29433 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
29434 && fixP->fx_addsy != NULL
29435 && S_IS_DEFINED (fixP->fx_addsy)
29436 && ! THUMB_IS_FUNC (fixP->fx_addsy))
29437 {
29438 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
29439 }
29440 }
29441 #endif
29442
29443
29444 int
29445 arm_force_relocation (struct fix * fixp)
29446 {
29447 #if defined (OBJ_COFF) && defined (TE_PE)
29448 if (fixp->fx_r_type == BFD_RELOC_RVA)
29449 return 1;
29450 #endif
29451
29452 /* In case we have a call or a branch to a function in ARM ISA mode from
29453 a thumb function or vice-versa force the relocation. These relocations
29454 are cleared off for some cores that might have blx and simple transformations
29455 are possible. */
29456
29457 #ifdef OBJ_ELF
29458 switch (fixp->fx_r_type)
29459 {
29460 case BFD_RELOC_ARM_PCREL_JUMP:
29461 case BFD_RELOC_ARM_PCREL_CALL:
29462 case BFD_RELOC_THUMB_PCREL_BLX:
29463 if (THUMB_IS_FUNC (fixp->fx_addsy))
29464 return 1;
29465 break;
29466
29467 case BFD_RELOC_ARM_PCREL_BLX:
29468 case BFD_RELOC_THUMB_PCREL_BRANCH25:
29469 case BFD_RELOC_THUMB_PCREL_BRANCH20:
29470 case BFD_RELOC_THUMB_PCREL_BRANCH23:
29471 if (ARM_IS_FUNC (fixp->fx_addsy))
29472 return 1;
29473 break;
29474
29475 default:
29476 break;
29477 }
29478 #endif
29479
29480 /* Resolve these relocations even if the symbol is extern or weak.
29481 Technically this is probably wrong due to symbol preemption.
29482 In practice these relocations do not have enough range to be useful
29483 at dynamic link time, and some code (e.g. in the Linux kernel)
29484 expects these references to be resolved. */
29485 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
29486 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
29487 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
29488 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
29489 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
29490 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
29491 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
29492 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
29493 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
29494 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
29495 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
29496 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
29497 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
29498 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
29499 return 0;
29500
29501 /* Always leave these relocations for the linker. */
29502 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
29503 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
29504 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
29505 return 1;
29506
29507 /* Always generate relocations against function symbols. */
29508 if (fixp->fx_r_type == BFD_RELOC_32
29509 && fixp->fx_addsy
29510 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
29511 return 1;
29512
29513 return generic_force_reloc (fixp);
29514 }
29515
29516 #if defined (OBJ_ELF) || defined (OBJ_COFF)
29517 /* Relocations against function names must be left unadjusted,
29518 so that the linker can use this information to generate interworking
29519 stubs. The MIPS version of this function
29520 also prevents relocations that are mips-16 specific, but I do not
29521 know why it does this.
29522
29523 FIXME:
29524 There is one other problem that ought to be addressed here, but
29525 which currently is not: Taking the address of a label (rather
29526 than a function) and then later jumping to that address. Such
29527 addresses also ought to have their bottom bit set (assuming that
29528 they reside in Thumb code), but at the moment they will not. */
29529
29530 bfd_boolean
29531 arm_fix_adjustable (fixS * fixP)
29532 {
29533 if (fixP->fx_addsy == NULL)
29534 return 1;
29535
29536 /* Preserve relocations against symbols with function type. */
29537 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
29538 return FALSE;
29539
29540 if (THUMB_IS_FUNC (fixP->fx_addsy)
29541 && fixP->fx_subsy == NULL)
29542 return FALSE;
29543
29544 /* We need the symbol name for the VTABLE entries. */
29545 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
29546 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
29547 return FALSE;
29548
29549 /* Don't allow symbols to be discarded on GOT related relocs. */
29550 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
29551 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
29552 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
29553 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
29554 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
29555 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
29556 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
29557 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
29558 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
29559 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
29560 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
29561 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
29562 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
29563 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
29564 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
29565 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
29566 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
29567 return FALSE;
29568
29569 /* Similarly for group relocations. */
29570 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
29571 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
29572 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
29573 return FALSE;
29574
29575 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
29576 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
29577 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
29578 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
29579 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
29580 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
29581 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
29582 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
29583 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
29584 return FALSE;
29585
29586 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
29587 offsets, so keep these symbols. */
29588 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
29589 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
29590 return FALSE;
29591
29592 return TRUE;
29593 }
29594 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
29595
29596 #ifdef OBJ_ELF
29597 const char *
29598 elf32_arm_target_format (void)
29599 {
29600 #ifdef TE_SYMBIAN
29601 return (target_big_endian
29602 ? "elf32-bigarm-symbian"
29603 : "elf32-littlearm-symbian");
29604 #elif defined (TE_VXWORKS)
29605 return (target_big_endian
29606 ? "elf32-bigarm-vxworks"
29607 : "elf32-littlearm-vxworks");
29608 #elif defined (TE_NACL)
29609 return (target_big_endian
29610 ? "elf32-bigarm-nacl"
29611 : "elf32-littlearm-nacl");
29612 #else
29613 if (arm_fdpic)
29614 {
29615 if (target_big_endian)
29616 return "elf32-bigarm-fdpic";
29617 else
29618 return "elf32-littlearm-fdpic";
29619 }
29620 else
29621 {
29622 if (target_big_endian)
29623 return "elf32-bigarm";
29624 else
29625 return "elf32-littlearm";
29626 }
29627 #endif
29628 }
29629
29630 void
29631 armelf_frob_symbol (symbolS * symp,
29632 int * puntp)
29633 {
29634 elf_frob_symbol (symp, puntp);
29635 }
29636 #endif
29637
29638 /* MD interface: Finalization. */
29639
29640 void
29641 arm_cleanup (void)
29642 {
29643 literal_pool * pool;
29644
29645 /* Ensure that all the predication blocks are properly closed. */
29646 check_pred_blocks_finished ();
29647
29648 for (pool = list_of_pools; pool; pool = pool->next)
29649 {
29650 /* Put it at the end of the relevant section. */
29651 subseg_set (pool->section, pool->sub_section);
29652 #ifdef OBJ_ELF
29653 arm_elf_change_section ();
29654 #endif
29655 s_ltorg (0);
29656 }
29657 }
29658
29659 #ifdef OBJ_ELF
29660 /* Remove any excess mapping symbols generated for alignment frags in
29661 SEC. We may have created a mapping symbol before a zero byte
29662 alignment; remove it if there's a mapping symbol after the
29663 alignment. */
29664 static void
29665 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
29666 void *dummy ATTRIBUTE_UNUSED)
29667 {
29668 segment_info_type *seginfo = seg_info (sec);
29669 fragS *fragp;
29670
29671 if (seginfo == NULL || seginfo->frchainP == NULL)
29672 return;
29673
29674 for (fragp = seginfo->frchainP->frch_root;
29675 fragp != NULL;
29676 fragp = fragp->fr_next)
29677 {
29678 symbolS *sym = fragp->tc_frag_data.last_map;
29679 fragS *next = fragp->fr_next;
29680
29681 /* Variable-sized frags have been converted to fixed size by
29682 this point. But if this was variable-sized to start with,
29683 there will be a fixed-size frag after it. So don't handle
29684 next == NULL. */
29685 if (sym == NULL || next == NULL)
29686 continue;
29687
29688 if (S_GET_VALUE (sym) < next->fr_address)
29689 /* Not at the end of this frag. */
29690 continue;
29691 know (S_GET_VALUE (sym) == next->fr_address);
29692
29693 do
29694 {
29695 if (next->tc_frag_data.first_map != NULL)
29696 {
29697 /* Next frag starts with a mapping symbol. Discard this
29698 one. */
29699 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
29700 break;
29701 }
29702
29703 if (next->fr_next == NULL)
29704 {
29705 /* This mapping symbol is at the end of the section. Discard
29706 it. */
29707 know (next->fr_fix == 0 && next->fr_var == 0);
29708 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
29709 break;
29710 }
29711
29712 /* As long as we have empty frags without any mapping symbols,
29713 keep looking. */
29714 /* If the next frag is non-empty and does not start with a
29715 mapping symbol, then this mapping symbol is required. */
29716 if (next->fr_address != next->fr_next->fr_address)
29717 break;
29718
29719 next = next->fr_next;
29720 }
29721 while (next != NULL);
29722 }
29723 }
29724 #endif
29725
29726 /* Adjust the symbol table. This marks Thumb symbols as distinct from
29727 ARM ones. */
29728
29729 void
29730 arm_adjust_symtab (void)
29731 {
29732 #ifdef OBJ_COFF
29733 symbolS * sym;
29734
29735 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
29736 {
29737 if (ARM_IS_THUMB (sym))
29738 {
29739 if (THUMB_IS_FUNC (sym))
29740 {
29741 /* Mark the symbol as a Thumb function. */
29742 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
29743 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
29744 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
29745
29746 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
29747 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
29748 else
29749 as_bad (_("%s: unexpected function type: %d"),
29750 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
29751 }
29752 else switch (S_GET_STORAGE_CLASS (sym))
29753 {
29754 case C_EXT:
29755 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
29756 break;
29757 case C_STAT:
29758 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
29759 break;
29760 case C_LABEL:
29761 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
29762 break;
29763 default:
29764 /* Do nothing. */
29765 break;
29766 }
29767 }
29768
29769 if (ARM_IS_INTERWORK (sym))
29770 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
29771 }
29772 #endif
29773 #ifdef OBJ_ELF
29774 symbolS * sym;
29775 char bind;
29776
29777 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
29778 {
29779 if (ARM_IS_THUMB (sym))
29780 {
29781 elf_symbol_type * elf_sym;
29782
29783 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
29784 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
29785
29786 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
29787 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
29788 {
29789 /* If it's a .thumb_func, declare it as so,
29790 otherwise tag label as .code 16. */
29791 if (THUMB_IS_FUNC (sym))
29792 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
29793 ST_BRANCH_TO_THUMB);
29794 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
29795 elf_sym->internal_elf_sym.st_info =
29796 ELF_ST_INFO (bind, STT_ARM_16BIT);
29797 }
29798 }
29799 }
29800
29801 /* Remove any overlapping mapping symbols generated by alignment frags. */
29802 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
29803 /* Now do generic ELF adjustments. */
29804 elf_adjust_symtab ();
29805 #endif
29806 }
29807
29808 /* MD interface: Initialization. */
29809
29810 static void
29811 set_constant_flonums (void)
29812 {
29813 int i;
29814
29815 for (i = 0; i < NUM_FLOAT_VALS; i++)
29816 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
29817 abort ();
29818 }
29819
29820 /* Auto-select Thumb mode if it's the only available instruction set for the
29821 given architecture. */
29822
29823 static void
29824 autoselect_thumb_from_cpu_variant (void)
29825 {
29826 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
29827 opcode_select (16);
29828 }
29829
29830 void
29831 md_begin (void)
29832 {
29833 unsigned mach;
29834 unsigned int i;
29835
29836 if ( (arm_ops_hsh = hash_new ()) == NULL
29837 || (arm_cond_hsh = hash_new ()) == NULL
29838 || (arm_vcond_hsh = hash_new ()) == NULL
29839 || (arm_shift_hsh = hash_new ()) == NULL
29840 || (arm_psr_hsh = hash_new ()) == NULL
29841 || (arm_v7m_psr_hsh = hash_new ()) == NULL
29842 || (arm_reg_hsh = hash_new ()) == NULL
29843 || (arm_reloc_hsh = hash_new ()) == NULL
29844 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
29845 as_fatal (_("virtual memory exhausted"));
29846
29847 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
29848 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
29849 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
29850 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
29851 for (i = 0; i < sizeof (vconds) / sizeof (struct asm_cond); i++)
29852 hash_insert (arm_vcond_hsh, vconds[i].template_name, (void *) (vconds + i));
29853 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
29854 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
29855 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
29856 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
29857 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
29858 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
29859 (void *) (v7m_psrs + i));
29860 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
29861 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
29862 for (i = 0;
29863 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
29864 i++)
29865 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
29866 (void *) (barrier_opt_names + i));
29867 #ifdef OBJ_ELF
29868 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
29869 {
29870 struct reloc_entry * entry = reloc_names + i;
29871
29872 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
29873 /* This makes encode_branch() use the EABI versions of this relocation. */
29874 entry->reloc = BFD_RELOC_UNUSED;
29875
29876 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
29877 }
29878 #endif
29879
29880 set_constant_flonums ();
29881
29882 /* Set the cpu variant based on the command-line options. We prefer
29883 -mcpu= over -march= if both are set (as for GCC); and we prefer
29884 -mfpu= over any other way of setting the floating point unit.
29885 Use of legacy options with new options are faulted. */
29886 if (legacy_cpu)
29887 {
29888 if (mcpu_cpu_opt || march_cpu_opt)
29889 as_bad (_("use of old and new-style options to set CPU type"));
29890
29891 selected_arch = *legacy_cpu;
29892 }
29893 else if (mcpu_cpu_opt)
29894 {
29895 selected_arch = *mcpu_cpu_opt;
29896 selected_ext = *mcpu_ext_opt;
29897 }
29898 else if (march_cpu_opt)
29899 {
29900 selected_arch = *march_cpu_opt;
29901 selected_ext = *march_ext_opt;
29902 }
29903 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
29904
29905 if (legacy_fpu)
29906 {
29907 if (mfpu_opt)
29908 as_bad (_("use of old and new-style options to set FPU type"));
29909
29910 selected_fpu = *legacy_fpu;
29911 }
29912 else if (mfpu_opt)
29913 selected_fpu = *mfpu_opt;
29914 else
29915 {
29916 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
29917 || defined (TE_NetBSD) || defined (TE_VXWORKS))
29918 /* Some environments specify a default FPU. If they don't, infer it
29919 from the processor. */
29920 if (mcpu_fpu_opt)
29921 selected_fpu = *mcpu_fpu_opt;
29922 else if (march_fpu_opt)
29923 selected_fpu = *march_fpu_opt;
29924 #else
29925 selected_fpu = fpu_default;
29926 #endif
29927 }
29928
29929 if (ARM_FEATURE_ZERO (selected_fpu))
29930 {
29931 if (!no_cpu_selected ())
29932 selected_fpu = fpu_default;
29933 else
29934 selected_fpu = fpu_arch_fpa;
29935 }
29936
29937 #ifdef CPU_DEFAULT
29938 if (ARM_FEATURE_ZERO (selected_arch))
29939 {
29940 selected_arch = cpu_default;
29941 selected_cpu = selected_arch;
29942 }
29943 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
29944 #else
29945 /* Autodection of feature mode: allow all features in cpu_variant but leave
29946 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
29947 after all instruction have been processed and we can decide what CPU
29948 should be selected. */
29949 if (ARM_FEATURE_ZERO (selected_arch))
29950 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
29951 else
29952 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
29953 #endif
29954
29955 autoselect_thumb_from_cpu_variant ();
29956
29957 arm_arch_used = thumb_arch_used = arm_arch_none;
29958
29959 #if defined OBJ_COFF || defined OBJ_ELF
29960 {
29961 unsigned int flags = 0;
29962
29963 #if defined OBJ_ELF
29964 flags = meabi_flags;
29965
29966 switch (meabi_flags)
29967 {
29968 case EF_ARM_EABI_UNKNOWN:
29969 #endif
29970 /* Set the flags in the private structure. */
29971 if (uses_apcs_26) flags |= F_APCS26;
29972 if (support_interwork) flags |= F_INTERWORK;
29973 if (uses_apcs_float) flags |= F_APCS_FLOAT;
29974 if (pic_code) flags |= F_PIC;
29975 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
29976 flags |= F_SOFT_FLOAT;
29977
29978 switch (mfloat_abi_opt)
29979 {
29980 case ARM_FLOAT_ABI_SOFT:
29981 case ARM_FLOAT_ABI_SOFTFP:
29982 flags |= F_SOFT_FLOAT;
29983 break;
29984
29985 case ARM_FLOAT_ABI_HARD:
29986 if (flags & F_SOFT_FLOAT)
29987 as_bad (_("hard-float conflicts with specified fpu"));
29988 break;
29989 }
29990
29991 /* Using pure-endian doubles (even if soft-float). */
29992 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
29993 flags |= F_VFP_FLOAT;
29994
29995 #if defined OBJ_ELF
29996 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
29997 flags |= EF_ARM_MAVERICK_FLOAT;
29998 break;
29999
30000 case EF_ARM_EABI_VER4:
30001 case EF_ARM_EABI_VER5:
30002 /* No additional flags to set. */
30003 break;
30004
30005 default:
30006 abort ();
30007 }
30008 #endif
30009 bfd_set_private_flags (stdoutput, flags);
30010
30011 /* We have run out flags in the COFF header to encode the
30012 status of ATPCS support, so instead we create a dummy,
30013 empty, debug section called .arm.atpcs. */
30014 if (atpcs)
30015 {
30016 asection * sec;
30017
30018 sec = bfd_make_section (stdoutput, ".arm.atpcs");
30019
30020 if (sec != NULL)
30021 {
30022 bfd_set_section_flags (sec, SEC_READONLY | SEC_DEBUGGING);
30023 bfd_set_section_size (sec, 0);
30024 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
30025 }
30026 }
30027 }
30028 #endif
30029
30030 /* Record the CPU type as well. */
30031 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
30032 mach = bfd_mach_arm_iWMMXt2;
30033 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
30034 mach = bfd_mach_arm_iWMMXt;
30035 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
30036 mach = bfd_mach_arm_XScale;
30037 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
30038 mach = bfd_mach_arm_ep9312;
30039 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
30040 mach = bfd_mach_arm_5TE;
30041 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
30042 {
30043 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30044 mach = bfd_mach_arm_5T;
30045 else
30046 mach = bfd_mach_arm_5;
30047 }
30048 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
30049 {
30050 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
30051 mach = bfd_mach_arm_4T;
30052 else
30053 mach = bfd_mach_arm_4;
30054 }
30055 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
30056 mach = bfd_mach_arm_3M;
30057 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
30058 mach = bfd_mach_arm_3;
30059 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
30060 mach = bfd_mach_arm_2a;
30061 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
30062 mach = bfd_mach_arm_2;
30063 else
30064 mach = bfd_mach_arm_unknown;
30065
30066 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
30067 }
30068
30069 /* Command line processing. */
30070
30071 /* md_parse_option
30072 Invocation line includes a switch not recognized by the base assembler.
30073 See if it's a processor-specific option.
30074
30075 This routine is somewhat complicated by the need for backwards
30076 compatibility (since older releases of gcc can't be changed).
30077 The new options try to make the interface as compatible as
30078 possible with GCC.
30079
30080 New options (supported) are:
30081
30082 -mcpu=<cpu name> Assemble for selected processor
30083 -march=<architecture name> Assemble for selected architecture
30084 -mfpu=<fpu architecture> Assemble for selected FPU.
30085 -EB/-mbig-endian Big-endian
30086 -EL/-mlittle-endian Little-endian
30087 -k Generate PIC code
30088 -mthumb Start in Thumb mode
30089 -mthumb-interwork Code supports ARM/Thumb interworking
30090
30091 -m[no-]warn-deprecated Warn about deprecated features
30092 -m[no-]warn-syms Warn when symbols match instructions
30093
30094 For now we will also provide support for:
30095
30096 -mapcs-32 32-bit Program counter
30097 -mapcs-26 26-bit Program counter
30098 -macps-float Floats passed in FP registers
30099 -mapcs-reentrant Reentrant code
30100 -matpcs
30101 (sometime these will probably be replaced with -mapcs=<list of options>
30102 and -matpcs=<list of options>)
30103
30104 The remaining options are only supported for back-wards compatibility.
30105 Cpu variants, the arm part is optional:
30106 -m[arm]1 Currently not supported.
30107 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
30108 -m[arm]3 Arm 3 processor
30109 -m[arm]6[xx], Arm 6 processors
30110 -m[arm]7[xx][t][[d]m] Arm 7 processors
30111 -m[arm]8[10] Arm 8 processors
30112 -m[arm]9[20][tdmi] Arm 9 processors
30113 -mstrongarm[110[0]] StrongARM processors
30114 -mxscale XScale processors
30115 -m[arm]v[2345[t[e]]] Arm architectures
30116 -mall All (except the ARM1)
30117 FP variants:
30118 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
30119 -mfpe-old (No float load/store multiples)
30120 -mvfpxd VFP Single precision
30121 -mvfp All VFP
30122 -mno-fpu Disable all floating point instructions
30123
30124 The following CPU names are recognized:
30125 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
30126 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
30127 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
30128 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
30129 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
30130 arm10t arm10e, arm1020t, arm1020e, arm10200e,
30131 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
30132
30133 */
30134
30135 const char * md_shortopts = "m:k";
30136
30137 #ifdef ARM_BI_ENDIAN
30138 #define OPTION_EB (OPTION_MD_BASE + 0)
30139 #define OPTION_EL (OPTION_MD_BASE + 1)
30140 #else
30141 #if TARGET_BYTES_BIG_ENDIAN
30142 #define OPTION_EB (OPTION_MD_BASE + 0)
30143 #else
30144 #define OPTION_EL (OPTION_MD_BASE + 1)
30145 #endif
30146 #endif
30147 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
30148 #define OPTION_FDPIC (OPTION_MD_BASE + 3)
30149
30150 struct option md_longopts[] =
30151 {
30152 #ifdef OPTION_EB
30153 {"EB", no_argument, NULL, OPTION_EB},
30154 #endif
30155 #ifdef OPTION_EL
30156 {"EL", no_argument, NULL, OPTION_EL},
30157 #endif
30158 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
30159 #ifdef OBJ_ELF
30160 {"fdpic", no_argument, NULL, OPTION_FDPIC},
30161 #endif
30162 {NULL, no_argument, NULL, 0}
30163 };
30164
30165 size_t md_longopts_size = sizeof (md_longopts);
30166
30167 struct arm_option_table
30168 {
30169 const char * option; /* Option name to match. */
30170 const char * help; /* Help information. */
30171 int * var; /* Variable to change. */
30172 int value; /* What to change it to. */
30173 const char * deprecated; /* If non-null, print this message. */
30174 };
30175
30176 struct arm_option_table arm_opts[] =
30177 {
30178 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
30179 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
30180 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
30181 &support_interwork, 1, NULL},
30182 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
30183 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
30184 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
30185 1, NULL},
30186 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
30187 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
30188 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
30189 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
30190 NULL},
30191
30192 /* These are recognized by the assembler, but have no affect on code. */
30193 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
30194 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
30195
30196 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
30197 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
30198 &warn_on_deprecated, 0, NULL},
30199 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
30200 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
30201 {NULL, NULL, NULL, 0, NULL}
30202 };
30203
30204 struct arm_legacy_option_table
30205 {
30206 const char * option; /* Option name to match. */
30207 const arm_feature_set ** var; /* Variable to change. */
30208 const arm_feature_set value; /* What to change it to. */
30209 const char * deprecated; /* If non-null, print this message. */
30210 };
30211
30212 const struct arm_legacy_option_table arm_legacy_opts[] =
30213 {
30214 /* DON'T add any new processors to this list -- we want the whole list
30215 to go away... Add them to the processors table instead. */
30216 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30217 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
30218 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30219 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
30220 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30221 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
30222 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30223 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
30224 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30225 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
30226 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30227 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
30228 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30229 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
30230 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30231 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
30232 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30233 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
30234 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30235 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
30236 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30237 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
30238 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30239 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
30240 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30241 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
30242 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30243 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
30244 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30245 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
30246 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30247 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
30248 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30249 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
30250 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30251 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
30252 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30253 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
30254 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30255 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
30256 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30257 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
30258 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30259 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
30260 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30261 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
30262 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30263 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30264 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30265 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
30266 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30267 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
30268 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30269 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
30270 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30271 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
30272 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30273 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
30274 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30275 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
30276 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30277 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
30278 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30279 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
30280 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30281 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
30282 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30283 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
30284 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
30285 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
30286 N_("use -mcpu=strongarm110")},
30287 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
30288 N_("use -mcpu=strongarm1100")},
30289 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
30290 N_("use -mcpu=strongarm1110")},
30291 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
30292 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
30293 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
30294
30295 /* Architecture variants -- don't add any more to this list either. */
30296 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30297 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
30298 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30299 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
30300 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30301 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
30302 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30303 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
30304 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30305 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
30306 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30307 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
30308 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30309 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
30310 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30311 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
30312 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
30313 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
30314
30315 /* Floating point variants -- don't add any more to this list either. */
30316 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
30317 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
30318 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
30319 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
30320 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
30321
30322 {NULL, NULL, ARM_ARCH_NONE, NULL}
30323 };
30324
30325 struct arm_cpu_option_table
30326 {
30327 const char * name;
30328 size_t name_len;
30329 const arm_feature_set value;
30330 const arm_feature_set ext;
30331 /* For some CPUs we assume an FPU unless the user explicitly sets
30332 -mfpu=... */
30333 const arm_feature_set default_fpu;
30334 /* The canonical name of the CPU, or NULL to use NAME converted to upper
30335 case. */
30336 const char * canonical_name;
30337 };
30338
30339 /* This list should, at a minimum, contain all the cpu names
30340 recognized by GCC. */
30341 #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
30342
30343 static const struct arm_cpu_option_table arm_cpus[] =
30344 {
30345 ARM_CPU_OPT ("all", NULL, ARM_ANY,
30346 ARM_ARCH_NONE,
30347 FPU_ARCH_FPA),
30348 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
30349 ARM_ARCH_NONE,
30350 FPU_ARCH_FPA),
30351 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
30352 ARM_ARCH_NONE,
30353 FPU_ARCH_FPA),
30354 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
30355 ARM_ARCH_NONE,
30356 FPU_ARCH_FPA),
30357 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
30358 ARM_ARCH_NONE,
30359 FPU_ARCH_FPA),
30360 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
30361 ARM_ARCH_NONE,
30362 FPU_ARCH_FPA),
30363 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
30364 ARM_ARCH_NONE,
30365 FPU_ARCH_FPA),
30366 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
30367 ARM_ARCH_NONE,
30368 FPU_ARCH_FPA),
30369 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
30370 ARM_ARCH_NONE,
30371 FPU_ARCH_FPA),
30372 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
30373 ARM_ARCH_NONE,
30374 FPU_ARCH_FPA),
30375 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
30376 ARM_ARCH_NONE,
30377 FPU_ARCH_FPA),
30378 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
30379 ARM_ARCH_NONE,
30380 FPU_ARCH_FPA),
30381 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
30382 ARM_ARCH_NONE,
30383 FPU_ARCH_FPA),
30384 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
30385 ARM_ARCH_NONE,
30386 FPU_ARCH_FPA),
30387 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
30388 ARM_ARCH_NONE,
30389 FPU_ARCH_FPA),
30390 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
30391 ARM_ARCH_NONE,
30392 FPU_ARCH_FPA),
30393 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
30394 ARM_ARCH_NONE,
30395 FPU_ARCH_FPA),
30396 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
30397 ARM_ARCH_NONE,
30398 FPU_ARCH_FPA),
30399 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
30400 ARM_ARCH_NONE,
30401 FPU_ARCH_FPA),
30402 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
30403 ARM_ARCH_NONE,
30404 FPU_ARCH_FPA),
30405 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
30406 ARM_ARCH_NONE,
30407 FPU_ARCH_FPA),
30408 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
30409 ARM_ARCH_NONE,
30410 FPU_ARCH_FPA),
30411 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
30412 ARM_ARCH_NONE,
30413 FPU_ARCH_FPA),
30414 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
30415 ARM_ARCH_NONE,
30416 FPU_ARCH_FPA),
30417 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
30418 ARM_ARCH_NONE,
30419 FPU_ARCH_FPA),
30420 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
30421 ARM_ARCH_NONE,
30422 FPU_ARCH_FPA),
30423 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
30424 ARM_ARCH_NONE,
30425 FPU_ARCH_FPA),
30426 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
30427 ARM_ARCH_NONE,
30428 FPU_ARCH_FPA),
30429 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
30430 ARM_ARCH_NONE,
30431 FPU_ARCH_FPA),
30432 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
30433 ARM_ARCH_NONE,
30434 FPU_ARCH_FPA),
30435 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
30436 ARM_ARCH_NONE,
30437 FPU_ARCH_FPA),
30438 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
30439 ARM_ARCH_NONE,
30440 FPU_ARCH_FPA),
30441 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
30442 ARM_ARCH_NONE,
30443 FPU_ARCH_FPA),
30444 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
30445 ARM_ARCH_NONE,
30446 FPU_ARCH_FPA),
30447 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
30448 ARM_ARCH_NONE,
30449 FPU_ARCH_FPA),
30450 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
30451 ARM_ARCH_NONE,
30452 FPU_ARCH_FPA),
30453 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
30454 ARM_ARCH_NONE,
30455 FPU_ARCH_FPA),
30456 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
30457 ARM_ARCH_NONE,
30458 FPU_ARCH_FPA),
30459 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
30460 ARM_ARCH_NONE,
30461 FPU_ARCH_FPA),
30462 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
30463 ARM_ARCH_NONE,
30464 FPU_ARCH_FPA),
30465 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
30466 ARM_ARCH_NONE,
30467 FPU_ARCH_FPA),
30468 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
30469 ARM_ARCH_NONE,
30470 FPU_ARCH_FPA),
30471 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
30472 ARM_ARCH_NONE,
30473 FPU_ARCH_FPA),
30474 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
30475 ARM_ARCH_NONE,
30476 FPU_ARCH_FPA),
30477 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
30478 ARM_ARCH_NONE,
30479 FPU_ARCH_FPA),
30480 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
30481 ARM_ARCH_NONE,
30482 FPU_ARCH_FPA),
30483
30484 /* For V5 or later processors we default to using VFP; but the user
30485 should really set the FPU type explicitly. */
30486 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
30487 ARM_ARCH_NONE,
30488 FPU_ARCH_VFP_V2),
30489 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
30490 ARM_ARCH_NONE,
30491 FPU_ARCH_VFP_V2),
30492 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
30493 ARM_ARCH_NONE,
30494 FPU_ARCH_VFP_V2),
30495 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
30496 ARM_ARCH_NONE,
30497 FPU_ARCH_VFP_V2),
30498 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
30499 ARM_ARCH_NONE,
30500 FPU_ARCH_VFP_V2),
30501 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
30502 ARM_ARCH_NONE,
30503 FPU_ARCH_VFP_V2),
30504 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
30505 ARM_ARCH_NONE,
30506 FPU_ARCH_VFP_V2),
30507 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
30508 ARM_ARCH_NONE,
30509 FPU_ARCH_VFP_V2),
30510 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
30511 ARM_ARCH_NONE,
30512 FPU_ARCH_VFP_V2),
30513 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
30514 ARM_ARCH_NONE,
30515 FPU_ARCH_VFP_V2),
30516 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
30517 ARM_ARCH_NONE,
30518 FPU_ARCH_VFP_V2),
30519 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
30520 ARM_ARCH_NONE,
30521 FPU_ARCH_VFP_V2),
30522 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
30523 ARM_ARCH_NONE,
30524 FPU_ARCH_VFP_V1),
30525 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
30526 ARM_ARCH_NONE,
30527 FPU_ARCH_VFP_V1),
30528 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
30529 ARM_ARCH_NONE,
30530 FPU_ARCH_VFP_V2),
30531 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
30532 ARM_ARCH_NONE,
30533 FPU_ARCH_VFP_V2),
30534 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
30535 ARM_ARCH_NONE,
30536 FPU_ARCH_VFP_V1),
30537 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
30538 ARM_ARCH_NONE,
30539 FPU_ARCH_VFP_V2),
30540 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
30541 ARM_ARCH_NONE,
30542 FPU_ARCH_VFP_V2),
30543 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
30544 ARM_ARCH_NONE,
30545 FPU_ARCH_VFP_V2),
30546 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
30547 ARM_ARCH_NONE,
30548 FPU_ARCH_VFP_V2),
30549 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
30550 ARM_ARCH_NONE,
30551 FPU_ARCH_VFP_V2),
30552 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
30553 ARM_ARCH_NONE,
30554 FPU_ARCH_VFP_V2),
30555 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
30556 ARM_ARCH_NONE,
30557 FPU_ARCH_VFP_V2),
30558 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
30559 ARM_ARCH_NONE,
30560 FPU_ARCH_VFP_V2),
30561 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
30562 ARM_ARCH_NONE,
30563 FPU_ARCH_VFP_V2),
30564 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
30565 ARM_ARCH_NONE,
30566 FPU_NONE),
30567 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
30568 ARM_ARCH_NONE,
30569 FPU_NONE),
30570 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
30571 ARM_ARCH_NONE,
30572 FPU_ARCH_VFP_V2),
30573 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
30574 ARM_ARCH_NONE,
30575 FPU_ARCH_VFP_V2),
30576 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
30577 ARM_ARCH_NONE,
30578 FPU_ARCH_VFP_V2),
30579 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
30580 ARM_ARCH_NONE,
30581 FPU_NONE),
30582 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
30583 ARM_ARCH_NONE,
30584 FPU_NONE),
30585 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
30586 ARM_ARCH_NONE,
30587 FPU_ARCH_VFP_V2),
30588 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
30589 ARM_ARCH_NONE,
30590 FPU_NONE),
30591 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
30592 ARM_ARCH_NONE,
30593 FPU_ARCH_VFP_V2),
30594 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
30595 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30596 FPU_NONE),
30597 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
30598 ARM_ARCH_NONE,
30599 FPU_ARCH_NEON_VFP_V4),
30600 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
30601 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
30602 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
30603 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
30604 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30605 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
30606 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
30607 ARM_ARCH_NONE,
30608 FPU_ARCH_NEON_VFP_V4),
30609 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
30610 ARM_ARCH_NONE,
30611 FPU_ARCH_NEON_VFP_V4),
30612 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
30613 ARM_ARCH_NONE,
30614 FPU_ARCH_NEON_VFP_V4),
30615 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
30616 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30617 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30618 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
30619 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30620 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30621 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
30622 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30623 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30624 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
30625 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30626 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30627 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
30628 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30629 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30630 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
30631 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30632 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30633 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
30634 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30635 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30636 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
30637 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30638 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30639 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
30640 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30641 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30642 ARM_CPU_OPT ("cortex-a76ae", "Cortex-A76AE", ARM_ARCH_V8_2A,
30643 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30644 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30645 ARM_CPU_OPT ("cortex-a77", "Cortex-A77", ARM_ARCH_V8_2A,
30646 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30647 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30648 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
30649 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30650 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30651 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
30652 ARM_ARCH_NONE,
30653 FPU_NONE),
30654 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
30655 ARM_ARCH_NONE,
30656 FPU_ARCH_VFP_V3D16),
30657 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
30658 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30659 FPU_NONE),
30660 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
30661 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30662 FPU_ARCH_VFP_V3D16),
30663 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
30664 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
30665 FPU_ARCH_VFP_V3D16),
30666 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
30667 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30668 FPU_ARCH_NEON_VFP_ARMV8),
30669 ARM_CPU_OPT ("cortex-m35p", "Cortex-M35P", ARM_ARCH_V8M_MAIN,
30670 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30671 FPU_NONE),
30672 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
30673 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30674 FPU_NONE),
30675 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
30676 ARM_ARCH_NONE,
30677 FPU_NONE),
30678 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
30679 ARM_ARCH_NONE,
30680 FPU_NONE),
30681 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
30682 ARM_ARCH_NONE,
30683 FPU_NONE),
30684 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
30685 ARM_ARCH_NONE,
30686 FPU_NONE),
30687 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
30688 ARM_ARCH_NONE,
30689 FPU_NONE),
30690 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
30691 ARM_ARCH_NONE,
30692 FPU_NONE),
30693 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
30694 ARM_ARCH_NONE,
30695 FPU_NONE),
30696 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
30697 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30698 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30699 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
30700 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
30701 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
30702 /* ??? XSCALE is really an architecture. */
30703 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
30704 ARM_ARCH_NONE,
30705 FPU_ARCH_VFP_V2),
30706
30707 /* ??? iwmmxt is not a processor. */
30708 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
30709 ARM_ARCH_NONE,
30710 FPU_ARCH_VFP_V2),
30711 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
30712 ARM_ARCH_NONE,
30713 FPU_ARCH_VFP_V2),
30714 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
30715 ARM_ARCH_NONE,
30716 FPU_ARCH_VFP_V2),
30717
30718 /* Maverick. */
30719 ARM_CPU_OPT ("ep9312", "ARM920T",
30720 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
30721 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
30722
30723 /* Marvell processors. */
30724 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
30725 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30726 FPU_ARCH_VFP_V3D16),
30727 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
30728 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
30729 FPU_ARCH_NEON_VFP_V4),
30730
30731 /* APM X-Gene family. */
30732 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
30733 ARM_ARCH_NONE,
30734 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30735 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
30736 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
30737 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
30738
30739 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
30740 };
30741 #undef ARM_CPU_OPT
30742
30743 struct arm_ext_table
30744 {
30745 const char * name;
30746 size_t name_len;
30747 const arm_feature_set merge;
30748 const arm_feature_set clear;
30749 };
30750
30751 struct arm_arch_option_table
30752 {
30753 const char * name;
30754 size_t name_len;
30755 const arm_feature_set value;
30756 const arm_feature_set default_fpu;
30757 const struct arm_ext_table * ext_table;
30758 };
30759
30760 /* Used to add support for +E and +noE extension. */
30761 #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
30762 /* Used to add support for a +E extension. */
30763 #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
30764 /* Used to add support for a +noE extension. */
30765 #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
30766
30767 #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
30768 ~0 & ~FPU_ENDIAN_PURE)
30769
30770 static const struct arm_ext_table armv5te_ext_table[] =
30771 {
30772 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
30773 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30774 };
30775
30776 static const struct arm_ext_table armv7_ext_table[] =
30777 {
30778 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30779 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30780 };
30781
30782 static const struct arm_ext_table armv7ve_ext_table[] =
30783 {
30784 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
30785 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
30786 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
30787 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30788 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
30789 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
30790 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
30791
30792 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
30793 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
30794
30795 /* Aliases for +simd. */
30796 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
30797
30798 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30799 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30800 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
30801
30802 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30803 };
30804
30805 static const struct arm_ext_table armv7a_ext_table[] =
30806 {
30807 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30808 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
30809 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
30810 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30811 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
30812 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
30813 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
30814
30815 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
30816 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
30817
30818 /* Aliases for +simd. */
30819 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30820 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
30821
30822 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
30823 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
30824
30825 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
30826 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
30827 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30828 };
30829
30830 static const struct arm_ext_table armv7r_ext_table[] =
30831 {
30832 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
30833 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
30834 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
30835 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
30836 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
30837 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
30838 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
30839 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
30840 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30841 };
30842
30843 static const struct arm_ext_table armv7em_ext_table[] =
30844 {
30845 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
30846 /* Alias for +fp, used to be known as fpv4-sp-d16. */
30847 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
30848 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
30849 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
30850 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
30851 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30852 };
30853
30854 static const struct arm_ext_table armv8a_ext_table[] =
30855 {
30856 ARM_ADD ("crc", ARCH_CRC_ARMV8),
30857 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
30858 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
30859 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30860
30861 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30862 should use the +simd option to turn on FP. */
30863 ARM_REMOVE ("fp", ALL_FP),
30864 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30865 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30866 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30867 };
30868
30869
30870 static const struct arm_ext_table armv81a_ext_table[] =
30871 {
30872 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
30873 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
30874 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30875
30876 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30877 should use the +simd option to turn on FP. */
30878 ARM_REMOVE ("fp", ALL_FP),
30879 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30880 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30881 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30882 };
30883
30884 static const struct arm_ext_table armv82a_ext_table[] =
30885 {
30886 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
30887 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
30888 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
30889 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
30890 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30891 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30892
30893 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30894 should use the +simd option to turn on FP. */
30895 ARM_REMOVE ("fp", ALL_FP),
30896 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30897 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30898 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30899 };
30900
30901 static const struct arm_ext_table armv84a_ext_table[] =
30902 {
30903 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30904 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
30905 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
30906 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30907
30908 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30909 should use the +simd option to turn on FP. */
30910 ARM_REMOVE ("fp", ALL_FP),
30911 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
30912 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
30913 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30914 };
30915
30916 static const struct arm_ext_table armv85a_ext_table[] =
30917 {
30918 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
30919 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
30920 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
30921 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30922
30923 /* Armv8-a does not allow an FP implementation without SIMD, so the user
30924 should use the +simd option to turn on FP. */
30925 ARM_REMOVE ("fp", ALL_FP),
30926 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30927 };
30928
30929 static const struct arm_ext_table armv8m_main_ext_table[] =
30930 {
30931 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30932 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
30933 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
30934 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
30935 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30936 };
30937
30938 static const struct arm_ext_table armv8_1m_main_ext_table[] =
30939 {
30940 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
30941 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
30942 ARM_EXT ("fp",
30943 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30944 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
30945 ALL_FP),
30946 ARM_ADD ("fp.dp",
30947 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30948 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
30949 ARM_EXT ("mve", ARM_FEATURE_COPROC (FPU_MVE),
30950 ARM_FEATURE_COPROC (FPU_MVE | FPU_MVE_FP)),
30951 ARM_ADD ("mve.fp",
30952 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
30953 FPU_MVE | FPU_MVE_FP | FPU_VFP_V5_SP_D16 |
30954 FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
30955 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30956 };
30957
30958 static const struct arm_ext_table armv8r_ext_table[] =
30959 {
30960 ARM_ADD ("crc", ARCH_CRC_ARMV8),
30961 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
30962 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
30963 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
30964 ARM_REMOVE ("fp", ALL_FP),
30965 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
30966 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
30967 };
30968
30969 /* This list should, at a minimum, contain all the architecture names
30970 recognized by GCC. */
30971 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
30972 #define ARM_ARCH_OPT2(N, V, DF, ext) \
30973 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
30974
30975 static const struct arm_arch_option_table arm_archs[] =
30976 {
30977 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
30978 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
30979 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
30980 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
30981 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
30982 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
30983 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
30984 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
30985 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
30986 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
30987 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
30988 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
30989 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
30990 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
30991 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
30992 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
30993 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
30994 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
30995 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
30996 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
30997 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
30998 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
30999 kept to preserve existing behaviour. */
31000 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31001 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
31002 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
31003 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
31004 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
31005 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
31006 kept to preserve existing behaviour. */
31007 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31008 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
31009 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
31010 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
31011 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
31012 /* The official spelling of the ARMv7 profile variants is the dashed form.
31013 Accept the non-dashed form for compatibility with old toolchains. */
31014 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31015 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
31016 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
31017 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
31018 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
31019 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
31020 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
31021 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
31022 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
31023 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
31024 armv8m_main),
31025 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
31026 armv8_1m_main),
31027 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
31028 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
31029 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
31030 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
31031 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
31032 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
31033 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
31034 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
31035 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
31036 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
31037 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
31038 };
31039 #undef ARM_ARCH_OPT
31040
31041 /* ISA extensions in the co-processor and main instruction set space. */
31042
31043 struct arm_option_extension_value_table
31044 {
31045 const char * name;
31046 size_t name_len;
31047 const arm_feature_set merge_value;
31048 const arm_feature_set clear_value;
31049 /* List of architectures for which an extension is available. ARM_ARCH_NONE
31050 indicates that an extension is available for all architectures while
31051 ARM_ANY marks an empty entry. */
31052 const arm_feature_set allowed_archs[2];
31053 };
31054
31055 /* The following table must be in alphabetical order with a NULL last entry. */
31056
31057 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
31058 #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
31059
31060 /* DEPRECATED: Refrain from using this table to add any new extensions, instead
31061 use the context sensitive approach using arm_ext_table's. */
31062 static const struct arm_option_extension_value_table arm_extensions[] =
31063 {
31064 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
31065 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31066 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
31067 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
31068 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31069 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
31070 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
31071 ARM_ARCH_V8_2A),
31072 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31073 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
31074 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
31075 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
31076 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31077 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31078 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
31079 ARM_ARCH_V8_2A),
31080 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31081 | ARM_EXT2_FP16_FML),
31082 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
31083 | ARM_EXT2_FP16_FML),
31084 ARM_ARCH_V8_2A),
31085 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31086 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
31087 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
31088 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
31089 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
31090 Thumb divide instruction. Due to this having the same name as the
31091 previous entry, this will be ignored when doing command-line parsing and
31092 only considered by build attribute selection code. */
31093 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
31094 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
31095 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
31096 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
31097 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
31098 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
31099 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
31100 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
31101 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
31102 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
31103 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
31104 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
31105 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
31106 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
31107 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
31108 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
31109 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
31110 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
31111 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
31112 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
31113 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
31114 ARM_ARCH_V8A),
31115 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
31116 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
31117 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
31118 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
31119 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
31120 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
31121 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
31122 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
31123 ARM_ARCH_V8A),
31124 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31125 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
31126 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
31127 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
31128 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
31129 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
31130 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
31131 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
31132 | ARM_EXT_DIV),
31133 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
31134 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
31135 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
31136 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
31137 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
31138 };
31139 #undef ARM_EXT_OPT
31140
31141 /* ISA floating-point and Advanced SIMD extensions. */
31142 struct arm_option_fpu_value_table
31143 {
31144 const char * name;
31145 const arm_feature_set value;
31146 };
31147
31148 /* This list should, at a minimum, contain all the fpu names
31149 recognized by GCC. */
31150 static const struct arm_option_fpu_value_table arm_fpus[] =
31151 {
31152 {"softfpa", FPU_NONE},
31153 {"fpe", FPU_ARCH_FPE},
31154 {"fpe2", FPU_ARCH_FPE},
31155 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
31156 {"fpa", FPU_ARCH_FPA},
31157 {"fpa10", FPU_ARCH_FPA},
31158 {"fpa11", FPU_ARCH_FPA},
31159 {"arm7500fe", FPU_ARCH_FPA},
31160 {"softvfp", FPU_ARCH_VFP},
31161 {"softvfp+vfp", FPU_ARCH_VFP_V2},
31162 {"vfp", FPU_ARCH_VFP_V2},
31163 {"vfp9", FPU_ARCH_VFP_V2},
31164 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
31165 {"vfp10", FPU_ARCH_VFP_V2},
31166 {"vfp10-r0", FPU_ARCH_VFP_V1},
31167 {"vfpxd", FPU_ARCH_VFP_V1xD},
31168 {"vfpv2", FPU_ARCH_VFP_V2},
31169 {"vfpv3", FPU_ARCH_VFP_V3},
31170 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
31171 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
31172 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
31173 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
31174 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
31175 {"arm1020t", FPU_ARCH_VFP_V1},
31176 {"arm1020e", FPU_ARCH_VFP_V2},
31177 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
31178 {"arm1136jf-s", FPU_ARCH_VFP_V2},
31179 {"maverick", FPU_ARCH_MAVERICK},
31180 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
31181 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
31182 {"neon-fp16", FPU_ARCH_NEON_FP16},
31183 {"vfpv4", FPU_ARCH_VFP_V4},
31184 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
31185 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
31186 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
31187 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
31188 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
31189 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
31190 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
31191 {"crypto-neon-fp-armv8",
31192 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
31193 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
31194 {"crypto-neon-fp-armv8.1",
31195 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
31196 {NULL, ARM_ARCH_NONE}
31197 };
31198
31199 struct arm_option_value_table
31200 {
31201 const char *name;
31202 long value;
31203 };
31204
31205 static const struct arm_option_value_table arm_float_abis[] =
31206 {
31207 {"hard", ARM_FLOAT_ABI_HARD},
31208 {"softfp", ARM_FLOAT_ABI_SOFTFP},
31209 {"soft", ARM_FLOAT_ABI_SOFT},
31210 {NULL, 0}
31211 };
31212
31213 #ifdef OBJ_ELF
31214 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
31215 static const struct arm_option_value_table arm_eabis[] =
31216 {
31217 {"gnu", EF_ARM_EABI_UNKNOWN},
31218 {"4", EF_ARM_EABI_VER4},
31219 {"5", EF_ARM_EABI_VER5},
31220 {NULL, 0}
31221 };
31222 #endif
31223
31224 struct arm_long_option_table
31225 {
31226 const char * option; /* Substring to match. */
31227 const char * help; /* Help information. */
31228 int (* func) (const char * subopt); /* Function to decode sub-option. */
31229 const char * deprecated; /* If non-null, print this message. */
31230 };
31231
31232 static bfd_boolean
31233 arm_parse_extension (const char *str, const arm_feature_set *opt_set,
31234 arm_feature_set *ext_set,
31235 const struct arm_ext_table *ext_table)
31236 {
31237 /* We insist on extensions being specified in alphabetical order, and with
31238 extensions being added before being removed. We achieve this by having
31239 the global ARM_EXTENSIONS table in alphabetical order, and using the
31240 ADDING_VALUE variable to indicate whether we are adding an extension (1)
31241 or removing it (0) and only allowing it to change in the order
31242 -1 -> 1 -> 0. */
31243 const struct arm_option_extension_value_table * opt = NULL;
31244 const arm_feature_set arm_any = ARM_ANY;
31245 int adding_value = -1;
31246
31247 while (str != NULL && *str != 0)
31248 {
31249 const char *ext;
31250 size_t len;
31251
31252 if (*str != '+')
31253 {
31254 as_bad (_("invalid architectural extension"));
31255 return FALSE;
31256 }
31257
31258 str++;
31259 ext = strchr (str, '+');
31260
31261 if (ext != NULL)
31262 len = ext - str;
31263 else
31264 len = strlen (str);
31265
31266 if (len >= 2 && strncmp (str, "no", 2) == 0)
31267 {
31268 if (adding_value != 0)
31269 {
31270 adding_value = 0;
31271 opt = arm_extensions;
31272 }
31273
31274 len -= 2;
31275 str += 2;
31276 }
31277 else if (len > 0)
31278 {
31279 if (adding_value == -1)
31280 {
31281 adding_value = 1;
31282 opt = arm_extensions;
31283 }
31284 else if (adding_value != 1)
31285 {
31286 as_bad (_("must specify extensions to add before specifying "
31287 "those to remove"));
31288 return FALSE;
31289 }
31290 }
31291
31292 if (len == 0)
31293 {
31294 as_bad (_("missing architectural extension"));
31295 return FALSE;
31296 }
31297
31298 gas_assert (adding_value != -1);
31299 gas_assert (opt != NULL);
31300
31301 if (ext_table != NULL)
31302 {
31303 const struct arm_ext_table * ext_opt = ext_table;
31304 bfd_boolean found = FALSE;
31305 for (; ext_opt->name != NULL; ext_opt++)
31306 if (ext_opt->name_len == len
31307 && strncmp (ext_opt->name, str, len) == 0)
31308 {
31309 if (adding_value)
31310 {
31311 if (ARM_FEATURE_ZERO (ext_opt->merge))
31312 /* TODO: Option not supported. When we remove the
31313 legacy table this case should error out. */
31314 continue;
31315
31316 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
31317 }
31318 else
31319 {
31320 if (ARM_FEATURE_ZERO (ext_opt->clear))
31321 /* TODO: Option not supported. When we remove the
31322 legacy table this case should error out. */
31323 continue;
31324 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
31325 }
31326 found = TRUE;
31327 break;
31328 }
31329 if (found)
31330 {
31331 str = ext;
31332 continue;
31333 }
31334 }
31335
31336 /* Scan over the options table trying to find an exact match. */
31337 for (; opt->name != NULL; opt++)
31338 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
31339 {
31340 int i, nb_allowed_archs =
31341 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
31342 /* Check we can apply the extension to this architecture. */
31343 for (i = 0; i < nb_allowed_archs; i++)
31344 {
31345 /* Empty entry. */
31346 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
31347 continue;
31348 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
31349 break;
31350 }
31351 if (i == nb_allowed_archs)
31352 {
31353 as_bad (_("extension does not apply to the base architecture"));
31354 return FALSE;
31355 }
31356
31357 /* Add or remove the extension. */
31358 if (adding_value)
31359 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
31360 else
31361 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
31362
31363 /* Allowing Thumb division instructions for ARMv7 in autodetection
31364 rely on this break so that duplicate extensions (extensions
31365 with the same name as a previous extension in the list) are not
31366 considered for command-line parsing. */
31367 break;
31368 }
31369
31370 if (opt->name == NULL)
31371 {
31372 /* Did we fail to find an extension because it wasn't specified in
31373 alphabetical order, or because it does not exist? */
31374
31375 for (opt = arm_extensions; opt->name != NULL; opt++)
31376 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
31377 break;
31378
31379 if (opt->name == NULL)
31380 as_bad (_("unknown architectural extension `%s'"), str);
31381 else
31382 as_bad (_("architectural extensions must be specified in "
31383 "alphabetical order"));
31384
31385 return FALSE;
31386 }
31387 else
31388 {
31389 /* We should skip the extension we've just matched the next time
31390 round. */
31391 opt++;
31392 }
31393
31394 str = ext;
31395 };
31396
31397 return TRUE;
31398 }
31399
31400 static bfd_boolean
31401 arm_parse_fp16_opt (const char *str)
31402 {
31403 if (strcasecmp (str, "ieee") == 0)
31404 fp16_format = ARM_FP16_FORMAT_IEEE;
31405 else if (strcasecmp (str, "alternative") == 0)
31406 fp16_format = ARM_FP16_FORMAT_ALTERNATIVE;
31407 else
31408 {
31409 as_bad (_("unrecognised float16 format \"%s\""), str);
31410 return FALSE;
31411 }
31412
31413 return TRUE;
31414 }
31415
31416 static bfd_boolean
31417 arm_parse_cpu (const char *str)
31418 {
31419 const struct arm_cpu_option_table *opt;
31420 const char *ext = strchr (str, '+');
31421 size_t len;
31422
31423 if (ext != NULL)
31424 len = ext - str;
31425 else
31426 len = strlen (str);
31427
31428 if (len == 0)
31429 {
31430 as_bad (_("missing cpu name `%s'"), str);
31431 return FALSE;
31432 }
31433
31434 for (opt = arm_cpus; opt->name != NULL; opt++)
31435 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
31436 {
31437 mcpu_cpu_opt = &opt->value;
31438 if (mcpu_ext_opt == NULL)
31439 mcpu_ext_opt = XNEW (arm_feature_set);
31440 *mcpu_ext_opt = opt->ext;
31441 mcpu_fpu_opt = &opt->default_fpu;
31442 if (opt->canonical_name)
31443 {
31444 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
31445 strcpy (selected_cpu_name, opt->canonical_name);
31446 }
31447 else
31448 {
31449 size_t i;
31450
31451 if (len >= sizeof selected_cpu_name)
31452 len = (sizeof selected_cpu_name) - 1;
31453
31454 for (i = 0; i < len; i++)
31455 selected_cpu_name[i] = TOUPPER (opt->name[i]);
31456 selected_cpu_name[i] = 0;
31457 }
31458
31459 if (ext != NULL)
31460 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
31461
31462 return TRUE;
31463 }
31464
31465 as_bad (_("unknown cpu `%s'"), str);
31466 return FALSE;
31467 }
31468
31469 static bfd_boolean
31470 arm_parse_arch (const char *str)
31471 {
31472 const struct arm_arch_option_table *opt;
31473 const char *ext = strchr (str, '+');
31474 size_t len;
31475
31476 if (ext != NULL)
31477 len = ext - str;
31478 else
31479 len = strlen (str);
31480
31481 if (len == 0)
31482 {
31483 as_bad (_("missing architecture name `%s'"), str);
31484 return FALSE;
31485 }
31486
31487 for (opt = arm_archs; opt->name != NULL; opt++)
31488 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
31489 {
31490 march_cpu_opt = &opt->value;
31491 if (march_ext_opt == NULL)
31492 march_ext_opt = XNEW (arm_feature_set);
31493 *march_ext_opt = arm_arch_none;
31494 march_fpu_opt = &opt->default_fpu;
31495 strcpy (selected_cpu_name, opt->name);
31496
31497 if (ext != NULL)
31498 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
31499 opt->ext_table);
31500
31501 return TRUE;
31502 }
31503
31504 as_bad (_("unknown architecture `%s'\n"), str);
31505 return FALSE;
31506 }
31507
31508 static bfd_boolean
31509 arm_parse_fpu (const char * str)
31510 {
31511 const struct arm_option_fpu_value_table * opt;
31512
31513 for (opt = arm_fpus; opt->name != NULL; opt++)
31514 if (streq (opt->name, str))
31515 {
31516 mfpu_opt = &opt->value;
31517 return TRUE;
31518 }
31519
31520 as_bad (_("unknown floating point format `%s'\n"), str);
31521 return FALSE;
31522 }
31523
31524 static bfd_boolean
31525 arm_parse_float_abi (const char * str)
31526 {
31527 const struct arm_option_value_table * opt;
31528
31529 for (opt = arm_float_abis; opt->name != NULL; opt++)
31530 if (streq (opt->name, str))
31531 {
31532 mfloat_abi_opt = opt->value;
31533 return TRUE;
31534 }
31535
31536 as_bad (_("unknown floating point abi `%s'\n"), str);
31537 return FALSE;
31538 }
31539
31540 #ifdef OBJ_ELF
31541 static bfd_boolean
31542 arm_parse_eabi (const char * str)
31543 {
31544 const struct arm_option_value_table *opt;
31545
31546 for (opt = arm_eabis; opt->name != NULL; opt++)
31547 if (streq (opt->name, str))
31548 {
31549 meabi_flags = opt->value;
31550 return TRUE;
31551 }
31552 as_bad (_("unknown EABI `%s'\n"), str);
31553 return FALSE;
31554 }
31555 #endif
31556
31557 static bfd_boolean
31558 arm_parse_it_mode (const char * str)
31559 {
31560 bfd_boolean ret = TRUE;
31561
31562 if (streq ("arm", str))
31563 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
31564 else if (streq ("thumb", str))
31565 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
31566 else if (streq ("always", str))
31567 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
31568 else if (streq ("never", str))
31569 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
31570 else
31571 {
31572 as_bad (_("unknown implicit IT mode `%s', should be "\
31573 "arm, thumb, always, or never."), str);
31574 ret = FALSE;
31575 }
31576
31577 return ret;
31578 }
31579
31580 static bfd_boolean
31581 arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
31582 {
31583 codecomposer_syntax = TRUE;
31584 arm_comment_chars[0] = ';';
31585 arm_line_separator_chars[0] = 0;
31586 return TRUE;
31587 }
31588
31589 struct arm_long_option_table arm_long_opts[] =
31590 {
31591 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
31592 arm_parse_cpu, NULL},
31593 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
31594 arm_parse_arch, NULL},
31595 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
31596 arm_parse_fpu, NULL},
31597 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
31598 arm_parse_float_abi, NULL},
31599 #ifdef OBJ_ELF
31600 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
31601 arm_parse_eabi, NULL},
31602 #endif
31603 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
31604 arm_parse_it_mode, NULL},
31605 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
31606 arm_ccs_mode, NULL},
31607 {"mfp16-format=",
31608 N_("[ieee|alternative]\n\
31609 set the encoding for half precision floating point "
31610 "numbers to IEEE\n\
31611 or Arm alternative format."),
31612 arm_parse_fp16_opt, NULL },
31613 {NULL, NULL, 0, NULL}
31614 };
31615
31616 int
31617 md_parse_option (int c, const char * arg)
31618 {
31619 struct arm_option_table *opt;
31620 const struct arm_legacy_option_table *fopt;
31621 struct arm_long_option_table *lopt;
31622
31623 switch (c)
31624 {
31625 #ifdef OPTION_EB
31626 case OPTION_EB:
31627 target_big_endian = 1;
31628 break;
31629 #endif
31630
31631 #ifdef OPTION_EL
31632 case OPTION_EL:
31633 target_big_endian = 0;
31634 break;
31635 #endif
31636
31637 case OPTION_FIX_V4BX:
31638 fix_v4bx = TRUE;
31639 break;
31640
31641 #ifdef OBJ_ELF
31642 case OPTION_FDPIC:
31643 arm_fdpic = TRUE;
31644 break;
31645 #endif /* OBJ_ELF */
31646
31647 case 'a':
31648 /* Listing option. Just ignore these, we don't support additional
31649 ones. */
31650 return 0;
31651
31652 default:
31653 for (opt = arm_opts; opt->option != NULL; opt++)
31654 {
31655 if (c == opt->option[0]
31656 && ((arg == NULL && opt->option[1] == 0)
31657 || streq (arg, opt->option + 1)))
31658 {
31659 /* If the option is deprecated, tell the user. */
31660 if (warn_on_deprecated && opt->deprecated != NULL)
31661 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
31662 arg ? arg : "", _(opt->deprecated));
31663
31664 if (opt->var != NULL)
31665 *opt->var = opt->value;
31666
31667 return 1;
31668 }
31669 }
31670
31671 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
31672 {
31673 if (c == fopt->option[0]
31674 && ((arg == NULL && fopt->option[1] == 0)
31675 || streq (arg, fopt->option + 1)))
31676 {
31677 /* If the option is deprecated, tell the user. */
31678 if (warn_on_deprecated && fopt->deprecated != NULL)
31679 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
31680 arg ? arg : "", _(fopt->deprecated));
31681
31682 if (fopt->var != NULL)
31683 *fopt->var = &fopt->value;
31684
31685 return 1;
31686 }
31687 }
31688
31689 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
31690 {
31691 /* These options are expected to have an argument. */
31692 if (c == lopt->option[0]
31693 && arg != NULL
31694 && strncmp (arg, lopt->option + 1,
31695 strlen (lopt->option + 1)) == 0)
31696 {
31697 /* If the option is deprecated, tell the user. */
31698 if (warn_on_deprecated && lopt->deprecated != NULL)
31699 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
31700 _(lopt->deprecated));
31701
31702 /* Call the sup-option parser. */
31703 return lopt->func (arg + strlen (lopt->option) - 1);
31704 }
31705 }
31706
31707 return 0;
31708 }
31709
31710 return 1;
31711 }
31712
31713 void
31714 md_show_usage (FILE * fp)
31715 {
31716 struct arm_option_table *opt;
31717 struct arm_long_option_table *lopt;
31718
31719 fprintf (fp, _(" ARM-specific assembler options:\n"));
31720
31721 for (opt = arm_opts; opt->option != NULL; opt++)
31722 if (opt->help != NULL)
31723 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
31724
31725 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
31726 if (lopt->help != NULL)
31727 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
31728
31729 #ifdef OPTION_EB
31730 fprintf (fp, _("\
31731 -EB assemble code for a big-endian cpu\n"));
31732 #endif
31733
31734 #ifdef OPTION_EL
31735 fprintf (fp, _("\
31736 -EL assemble code for a little-endian cpu\n"));
31737 #endif
31738
31739 fprintf (fp, _("\
31740 --fix-v4bx Allow BX in ARMv4 code\n"));
31741
31742 #ifdef OBJ_ELF
31743 fprintf (fp, _("\
31744 --fdpic generate an FDPIC object file\n"));
31745 #endif /* OBJ_ELF */
31746 }
31747
31748 #ifdef OBJ_ELF
31749
31750 typedef struct
31751 {
31752 int val;
31753 arm_feature_set flags;
31754 } cpu_arch_ver_table;
31755
31756 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
31757 chronologically for architectures, with an exception for ARMv6-M and
31758 ARMv6S-M due to legacy reasons. No new architecture should have a
31759 special case. This allows for build attribute selection results to be
31760 stable when new architectures are added. */
31761 static const cpu_arch_ver_table cpu_arch_ver[] =
31762 {
31763 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
31764 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
31765 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
31766 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
31767 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
31768 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
31769 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
31770 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
31771 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
31772 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
31773 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
31774 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
31775 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
31776 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
31777 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
31778 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
31779 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
31780 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
31781 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
31782 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
31783 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
31784 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
31785 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
31786 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
31787
31788 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
31789 always selected build attributes to match those of ARMv6-M
31790 (resp. ARMv6S-M). However, due to these architectures being a strict
31791 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
31792 would be selected when fully respecting chronology of architectures.
31793 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
31794 move them before ARMv7 architectures. */
31795 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
31796 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
31797
31798 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
31799 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
31800 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
31801 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
31802 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
31803 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
31804 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
31805 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
31806 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
31807 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
31808 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
31809 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
31810 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
31811 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
31812 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
31813 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
31814 {-1, ARM_ARCH_NONE}
31815 };
31816
31817 /* Set an attribute if it has not already been set by the user. */
31818
31819 static void
31820 aeabi_set_attribute_int (int tag, int value)
31821 {
31822 if (tag < 1
31823 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
31824 || !attributes_set_explicitly[tag])
31825 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
31826 }
31827
31828 static void
31829 aeabi_set_attribute_string (int tag, const char *value)
31830 {
31831 if (tag < 1
31832 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
31833 || !attributes_set_explicitly[tag])
31834 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
31835 }
31836
31837 /* Return whether features in the *NEEDED feature set are available via
31838 extensions for the architecture whose feature set is *ARCH_FSET. */
31839
31840 static bfd_boolean
31841 have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
31842 const arm_feature_set *needed)
31843 {
31844 int i, nb_allowed_archs;
31845 arm_feature_set ext_fset;
31846 const struct arm_option_extension_value_table *opt;
31847
31848 ext_fset = arm_arch_none;
31849 for (opt = arm_extensions; opt->name != NULL; opt++)
31850 {
31851 /* Extension does not provide any feature we need. */
31852 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
31853 continue;
31854
31855 nb_allowed_archs =
31856 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
31857 for (i = 0; i < nb_allowed_archs; i++)
31858 {
31859 /* Empty entry. */
31860 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
31861 break;
31862
31863 /* Extension is available, add it. */
31864 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
31865 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
31866 }
31867 }
31868
31869 /* Can we enable all features in *needed? */
31870 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
31871 }
31872
31873 /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
31874 a given architecture feature set *ARCH_EXT_FSET including extension feature
31875 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
31876 - if true, check for an exact match of the architecture modulo extensions;
31877 - otherwise, select build attribute value of the first superset
31878 architecture released so that results remains stable when new architectures
31879 are added.
31880 For -march/-mcpu=all the build attribute value of the most featureful
31881 architecture is returned. Tag_CPU_arch_profile result is returned in
31882 PROFILE. */
31883
31884 static int
31885 get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
31886 const arm_feature_set *ext_fset,
31887 char *profile, int exact_match)
31888 {
31889 arm_feature_set arch_fset;
31890 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
31891
31892 /* Select most featureful architecture with all its extensions if building
31893 for -march=all as the feature sets used to set build attributes. */
31894 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
31895 {
31896 /* Force revisiting of decision for each new architecture. */
31897 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
31898 *profile = 'A';
31899 return TAG_CPU_ARCH_V8;
31900 }
31901
31902 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
31903
31904 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
31905 {
31906 arm_feature_set known_arch_fset;
31907
31908 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
31909 if (exact_match)
31910 {
31911 /* Base architecture match user-specified architecture and
31912 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
31913 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
31914 {
31915 p_ver_ret = p_ver;
31916 goto found;
31917 }
31918 /* Base architecture match user-specified architecture only
31919 (eg. ARMv6-M in the same case as above). Record it in case we
31920 find a match with above condition. */
31921 else if (p_ver_ret == NULL
31922 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
31923 p_ver_ret = p_ver;
31924 }
31925 else
31926 {
31927
31928 /* Architecture has all features wanted. */
31929 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
31930 {
31931 arm_feature_set added_fset;
31932
31933 /* Compute features added by this architecture over the one
31934 recorded in p_ver_ret. */
31935 if (p_ver_ret != NULL)
31936 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
31937 p_ver_ret->flags);
31938 /* First architecture that match incl. with extensions, or the
31939 only difference in features over the recorded match is
31940 features that were optional and are now mandatory. */
31941 if (p_ver_ret == NULL
31942 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
31943 {
31944 p_ver_ret = p_ver;
31945 goto found;
31946 }
31947 }
31948 else if (p_ver_ret == NULL)
31949 {
31950 arm_feature_set needed_ext_fset;
31951
31952 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
31953
31954 /* Architecture has all features needed when using some
31955 extensions. Record it and continue searching in case there
31956 exist an architecture providing all needed features without
31957 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
31958 OS extension). */
31959 if (have_ext_for_needed_feat_p (&known_arch_fset,
31960 &needed_ext_fset))
31961 p_ver_ret = p_ver;
31962 }
31963 }
31964 }
31965
31966 if (p_ver_ret == NULL)
31967 return -1;
31968
31969 found:
31970 /* Tag_CPU_arch_profile. */
31971 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
31972 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
31973 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
31974 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
31975 *profile = 'A';
31976 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
31977 *profile = 'R';
31978 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
31979 *profile = 'M';
31980 else
31981 *profile = '\0';
31982 return p_ver_ret->val;
31983 }
31984
31985 /* Set the public EABI object attributes. */
31986
31987 static void
31988 aeabi_set_public_attributes (void)
31989 {
31990 char profile = '\0';
31991 int arch = -1;
31992 int virt_sec = 0;
31993 int fp16_optional = 0;
31994 int skip_exact_match = 0;
31995 arm_feature_set flags, flags_arch, flags_ext;
31996
31997 /* Autodetection mode, choose the architecture based the instructions
31998 actually used. */
31999 if (no_cpu_selected ())
32000 {
32001 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
32002
32003 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
32004 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
32005
32006 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
32007 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
32008
32009 /* Code run during relaxation relies on selected_cpu being set. */
32010 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32011 flags_ext = arm_arch_none;
32012 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
32013 selected_ext = flags_ext;
32014 selected_cpu = flags;
32015 }
32016 /* Otherwise, choose the architecture based on the capabilities of the
32017 requested cpu. */
32018 else
32019 {
32020 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
32021 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
32022 flags_ext = selected_ext;
32023 flags = selected_cpu;
32024 }
32025 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
32026
32027 /* Allow the user to override the reported architecture. */
32028 if (!ARM_FEATURE_ZERO (selected_object_arch))
32029 {
32030 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
32031 flags_ext = arm_arch_none;
32032 }
32033 else
32034 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
32035
32036 /* When this function is run again after relaxation has happened there is no
32037 way to determine whether an architecture or CPU was specified by the user:
32038 - selected_cpu is set above for relaxation to work;
32039 - march_cpu_opt is not set if only -mcpu or .cpu is used;
32040 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
32041 Therefore, if not in -march=all case we first try an exact match and fall
32042 back to autodetection. */
32043 if (!skip_exact_match)
32044 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
32045 if (arch == -1)
32046 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
32047 if (arch == -1)
32048 as_bad (_("no architecture contains all the instructions used\n"));
32049
32050 /* Tag_CPU_name. */
32051 if (selected_cpu_name[0])
32052 {
32053 char *q;
32054
32055 q = selected_cpu_name;
32056 if (strncmp (q, "armv", 4) == 0)
32057 {
32058 int i;
32059
32060 q += 4;
32061 for (i = 0; q[i]; i++)
32062 q[i] = TOUPPER (q[i]);
32063 }
32064 aeabi_set_attribute_string (Tag_CPU_name, q);
32065 }
32066
32067 /* Tag_CPU_arch. */
32068 aeabi_set_attribute_int (Tag_CPU_arch, arch);
32069
32070 /* Tag_CPU_arch_profile. */
32071 if (profile != '\0')
32072 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
32073
32074 /* Tag_DSP_extension. */
32075 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
32076 aeabi_set_attribute_int (Tag_DSP_extension, 1);
32077
32078 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
32079 /* Tag_ARM_ISA_use. */
32080 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
32081 || ARM_FEATURE_ZERO (flags_arch))
32082 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
32083
32084 /* Tag_THUMB_ISA_use. */
32085 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
32086 || ARM_FEATURE_ZERO (flags_arch))
32087 {
32088 int thumb_isa_use;
32089
32090 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
32091 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
32092 thumb_isa_use = 3;
32093 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
32094 thumb_isa_use = 2;
32095 else
32096 thumb_isa_use = 1;
32097 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
32098 }
32099
32100 /* Tag_VFP_arch. */
32101 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
32102 aeabi_set_attribute_int (Tag_VFP_arch,
32103 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
32104 ? 7 : 8);
32105 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
32106 aeabi_set_attribute_int (Tag_VFP_arch,
32107 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
32108 ? 5 : 6);
32109 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
32110 {
32111 fp16_optional = 1;
32112 aeabi_set_attribute_int (Tag_VFP_arch, 3);
32113 }
32114 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
32115 {
32116 aeabi_set_attribute_int (Tag_VFP_arch, 4);
32117 fp16_optional = 1;
32118 }
32119 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
32120 aeabi_set_attribute_int (Tag_VFP_arch, 2);
32121 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
32122 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
32123 aeabi_set_attribute_int (Tag_VFP_arch, 1);
32124
32125 /* Tag_ABI_HardFP_use. */
32126 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
32127 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
32128 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
32129
32130 /* Tag_WMMX_arch. */
32131 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
32132 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
32133 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
32134 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
32135
32136 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
32137 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
32138 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
32139 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
32140 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
32141 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
32142 {
32143 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
32144 {
32145 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
32146 }
32147 else
32148 {
32149 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
32150 fp16_optional = 1;
32151 }
32152 }
32153
32154 if (ARM_CPU_HAS_FEATURE (flags, mve_fp_ext))
32155 aeabi_set_attribute_int (Tag_MVE_arch, 2);
32156 else if (ARM_CPU_HAS_FEATURE (flags, mve_ext))
32157 aeabi_set_attribute_int (Tag_MVE_arch, 1);
32158
32159 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
32160 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
32161 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
32162
32163 /* Tag_DIV_use.
32164
32165 We set Tag_DIV_use to two when integer divide instructions have been used
32166 in ARM state, or when Thumb integer divide instructions have been used,
32167 but we have no architecture profile set, nor have we any ARM instructions.
32168
32169 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
32170 by the base architecture.
32171
32172 For new architectures we will have to check these tests. */
32173 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
32174 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
32175 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
32176 aeabi_set_attribute_int (Tag_DIV_use, 0);
32177 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
32178 || (profile == '\0'
32179 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
32180 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
32181 aeabi_set_attribute_int (Tag_DIV_use, 2);
32182
32183 /* Tag_MP_extension_use. */
32184 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
32185 aeabi_set_attribute_int (Tag_MPextension_use, 1);
32186
32187 /* Tag Virtualization_use. */
32188 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
32189 virt_sec |= 1;
32190 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
32191 virt_sec |= 2;
32192 if (virt_sec != 0)
32193 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
32194
32195 if (fp16_format != ARM_FP16_FORMAT_DEFAULT)
32196 aeabi_set_attribute_int (Tag_ABI_FP_16bit_format, fp16_format);
32197 }
32198
32199 /* Post relaxation hook. Recompute ARM attributes now that relaxation is
32200 finished and free extension feature bits which will not be used anymore. */
32201
32202 void
32203 arm_md_post_relax (void)
32204 {
32205 aeabi_set_public_attributes ();
32206 XDELETE (mcpu_ext_opt);
32207 mcpu_ext_opt = NULL;
32208 XDELETE (march_ext_opt);
32209 march_ext_opt = NULL;
32210 }
32211
32212 /* Add the default contents for the .ARM.attributes section. */
32213
32214 void
32215 arm_md_end (void)
32216 {
32217 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
32218 return;
32219
32220 aeabi_set_public_attributes ();
32221 }
32222 #endif /* OBJ_ELF */
32223
32224 /* Parse a .cpu directive. */
32225
32226 static void
32227 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
32228 {
32229 const struct arm_cpu_option_table *opt;
32230 char *name;
32231 char saved_char;
32232
32233 name = input_line_pointer;
32234 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
32235 input_line_pointer++;
32236 saved_char = *input_line_pointer;
32237 *input_line_pointer = 0;
32238
32239 /* Skip the first "all" entry. */
32240 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
32241 if (streq (opt->name, name))
32242 {
32243 selected_arch = opt->value;
32244 selected_ext = opt->ext;
32245 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
32246 if (opt->canonical_name)
32247 strcpy (selected_cpu_name, opt->canonical_name);
32248 else
32249 {
32250 int i;
32251 for (i = 0; opt->name[i]; i++)
32252 selected_cpu_name[i] = TOUPPER (opt->name[i]);
32253
32254 selected_cpu_name[i] = 0;
32255 }
32256 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32257
32258 *input_line_pointer = saved_char;
32259 demand_empty_rest_of_line ();
32260 return;
32261 }
32262 as_bad (_("unknown cpu `%s'"), name);
32263 *input_line_pointer = saved_char;
32264 ignore_rest_of_line ();
32265 }
32266
32267 /* Parse a .arch directive. */
32268
32269 static void
32270 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
32271 {
32272 const struct arm_arch_option_table *opt;
32273 char saved_char;
32274 char *name;
32275
32276 name = input_line_pointer;
32277 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
32278 input_line_pointer++;
32279 saved_char = *input_line_pointer;
32280 *input_line_pointer = 0;
32281
32282 /* Skip the first "all" entry. */
32283 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32284 if (streq (opt->name, name))
32285 {
32286 selected_arch = opt->value;
32287 selected_ext = arm_arch_none;
32288 selected_cpu = selected_arch;
32289 strcpy (selected_cpu_name, opt->name);
32290 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32291 *input_line_pointer = saved_char;
32292 demand_empty_rest_of_line ();
32293 return;
32294 }
32295
32296 as_bad (_("unknown architecture `%s'\n"), name);
32297 *input_line_pointer = saved_char;
32298 ignore_rest_of_line ();
32299 }
32300
32301 /* Parse a .object_arch directive. */
32302
32303 static void
32304 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
32305 {
32306 const struct arm_arch_option_table *opt;
32307 char saved_char;
32308 char *name;
32309
32310 name = input_line_pointer;
32311 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
32312 input_line_pointer++;
32313 saved_char = *input_line_pointer;
32314 *input_line_pointer = 0;
32315
32316 /* Skip the first "all" entry. */
32317 for (opt = arm_archs + 1; opt->name != NULL; opt++)
32318 if (streq (opt->name, name))
32319 {
32320 selected_object_arch = opt->value;
32321 *input_line_pointer = saved_char;
32322 demand_empty_rest_of_line ();
32323 return;
32324 }
32325
32326 as_bad (_("unknown architecture `%s'\n"), name);
32327 *input_line_pointer = saved_char;
32328 ignore_rest_of_line ();
32329 }
32330
32331 /* Parse a .arch_extension directive. */
32332
32333 static void
32334 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
32335 {
32336 const struct arm_option_extension_value_table *opt;
32337 char saved_char;
32338 char *name;
32339 int adding_value = 1;
32340
32341 name = input_line_pointer;
32342 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
32343 input_line_pointer++;
32344 saved_char = *input_line_pointer;
32345 *input_line_pointer = 0;
32346
32347 if (strlen (name) >= 2
32348 && strncmp (name, "no", 2) == 0)
32349 {
32350 adding_value = 0;
32351 name += 2;
32352 }
32353
32354 for (opt = arm_extensions; opt->name != NULL; opt++)
32355 if (streq (opt->name, name))
32356 {
32357 int i, nb_allowed_archs =
32358 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
32359 for (i = 0; i < nb_allowed_archs; i++)
32360 {
32361 /* Empty entry. */
32362 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
32363 continue;
32364 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
32365 break;
32366 }
32367
32368 if (i == nb_allowed_archs)
32369 {
32370 as_bad (_("architectural extension `%s' is not allowed for the "
32371 "current base architecture"), name);
32372 break;
32373 }
32374
32375 if (adding_value)
32376 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
32377 opt->merge_value);
32378 else
32379 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
32380
32381 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
32382 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32383 *input_line_pointer = saved_char;
32384 demand_empty_rest_of_line ();
32385 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
32386 on this return so that duplicate extensions (extensions with the
32387 same name as a previous extension in the list) are not considered
32388 for command-line parsing. */
32389 return;
32390 }
32391
32392 if (opt->name == NULL)
32393 as_bad (_("unknown architecture extension `%s'\n"), name);
32394
32395 *input_line_pointer = saved_char;
32396 ignore_rest_of_line ();
32397 }
32398
32399 /* Parse a .fpu directive. */
32400
32401 static void
32402 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
32403 {
32404 const struct arm_option_fpu_value_table *opt;
32405 char saved_char;
32406 char *name;
32407
32408 name = input_line_pointer;
32409 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
32410 input_line_pointer++;
32411 saved_char = *input_line_pointer;
32412 *input_line_pointer = 0;
32413
32414 for (opt = arm_fpus; opt->name != NULL; opt++)
32415 if (streq (opt->name, name))
32416 {
32417 selected_fpu = opt->value;
32418 #ifndef CPU_DEFAULT
32419 if (no_cpu_selected ())
32420 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
32421 else
32422 #endif
32423 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
32424 *input_line_pointer = saved_char;
32425 demand_empty_rest_of_line ();
32426 return;
32427 }
32428
32429 as_bad (_("unknown floating point format `%s'\n"), name);
32430 *input_line_pointer = saved_char;
32431 ignore_rest_of_line ();
32432 }
32433
32434 /* Copy symbol information. */
32435
32436 void
32437 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
32438 {
32439 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
32440 }
32441
32442 #ifdef OBJ_ELF
32443 /* Given a symbolic attribute NAME, return the proper integer value.
32444 Returns -1 if the attribute is not known. */
32445
32446 int
32447 arm_convert_symbolic_attribute (const char *name)
32448 {
32449 static const struct
32450 {
32451 const char * name;
32452 const int tag;
32453 }
32454 attribute_table[] =
32455 {
32456 /* When you modify this table you should
32457 also modify the list in doc/c-arm.texi. */
32458 #define T(tag) {#tag, tag}
32459 T (Tag_CPU_raw_name),
32460 T (Tag_CPU_name),
32461 T (Tag_CPU_arch),
32462 T (Tag_CPU_arch_profile),
32463 T (Tag_ARM_ISA_use),
32464 T (Tag_THUMB_ISA_use),
32465 T (Tag_FP_arch),
32466 T (Tag_VFP_arch),
32467 T (Tag_WMMX_arch),
32468 T (Tag_Advanced_SIMD_arch),
32469 T (Tag_PCS_config),
32470 T (Tag_ABI_PCS_R9_use),
32471 T (Tag_ABI_PCS_RW_data),
32472 T (Tag_ABI_PCS_RO_data),
32473 T (Tag_ABI_PCS_GOT_use),
32474 T (Tag_ABI_PCS_wchar_t),
32475 T (Tag_ABI_FP_rounding),
32476 T (Tag_ABI_FP_denormal),
32477 T (Tag_ABI_FP_exceptions),
32478 T (Tag_ABI_FP_user_exceptions),
32479 T (Tag_ABI_FP_number_model),
32480 T (Tag_ABI_align_needed),
32481 T (Tag_ABI_align8_needed),
32482 T (Tag_ABI_align_preserved),
32483 T (Tag_ABI_align8_preserved),
32484 T (Tag_ABI_enum_size),
32485 T (Tag_ABI_HardFP_use),
32486 T (Tag_ABI_VFP_args),
32487 T (Tag_ABI_WMMX_args),
32488 T (Tag_ABI_optimization_goals),
32489 T (Tag_ABI_FP_optimization_goals),
32490 T (Tag_compatibility),
32491 T (Tag_CPU_unaligned_access),
32492 T (Tag_FP_HP_extension),
32493 T (Tag_VFP_HP_extension),
32494 T (Tag_ABI_FP_16bit_format),
32495 T (Tag_MPextension_use),
32496 T (Tag_DIV_use),
32497 T (Tag_nodefaults),
32498 T (Tag_also_compatible_with),
32499 T (Tag_conformance),
32500 T (Tag_T2EE_use),
32501 T (Tag_Virtualization_use),
32502 T (Tag_DSP_extension),
32503 T (Tag_MVE_arch),
32504 /* We deliberately do not include Tag_MPextension_use_legacy. */
32505 #undef T
32506 };
32507 unsigned int i;
32508
32509 if (name == NULL)
32510 return -1;
32511
32512 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
32513 if (streq (name, attribute_table[i].name))
32514 return attribute_table[i].tag;
32515
32516 return -1;
32517 }
32518
32519 /* Apply sym value for relocations only in the case that they are for
32520 local symbols in the same segment as the fixup and you have the
32521 respective architectural feature for blx and simple switches. */
32522
32523 int
32524 arm_apply_sym_value (struct fix * fixP, segT this_seg)
32525 {
32526 if (fixP->fx_addsy
32527 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
32528 /* PR 17444: If the local symbol is in a different section then a reloc
32529 will always be generated for it, so applying the symbol value now
32530 will result in a double offset being stored in the relocation. */
32531 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
32532 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
32533 {
32534 switch (fixP->fx_r_type)
32535 {
32536 case BFD_RELOC_ARM_PCREL_BLX:
32537 case BFD_RELOC_THUMB_PCREL_BRANCH23:
32538 if (ARM_IS_FUNC (fixP->fx_addsy))
32539 return 1;
32540 break;
32541
32542 case BFD_RELOC_ARM_PCREL_CALL:
32543 case BFD_RELOC_THUMB_PCREL_BLX:
32544 if (THUMB_IS_FUNC (fixP->fx_addsy))
32545 return 1;
32546 break;
32547
32548 default:
32549 break;
32550 }
32551
32552 }
32553 return 0;
32554 }
32555 #endif /* OBJ_ELF */
This page took 0.732584 seconds and 4 git commands to generate.