]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/config/tc-arm.c
[binutils, ARM, 5/16] BF insns infrastructure with new global reloc R_ARM_THM_BF16
[thirdparty/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 #ifdef OBJ_ELF
306 static const arm_feature_set fpu_vfp_fp16 =
307 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
308 static const arm_feature_set fpu_neon_ext_fma =
309 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
310 #endif
311 static const arm_feature_set fpu_vfp_ext_fma =
312 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
313 static const arm_feature_set fpu_vfp_ext_armv8 =
314 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
315 static const arm_feature_set fpu_vfp_ext_armv8xd =
316 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
317 static const arm_feature_set fpu_neon_ext_armv8 =
318 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
319 static const arm_feature_set fpu_crypto_ext_armv8 =
320 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
321 static const arm_feature_set crc_ext_armv8 =
322 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
323 static const arm_feature_set fpu_neon_ext_v8_1 =
324 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
325 static const arm_feature_set fpu_neon_ext_dotprod =
326 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
327
328 static int mfloat_abi_opt = -1;
329 /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
330 directive. */
331 static arm_feature_set selected_arch = ARM_ARCH_NONE;
332 /* Extension feature bits selected by the last -mcpu/-march or .arch_extension
333 directive. */
334 static arm_feature_set selected_ext = ARM_ARCH_NONE;
335 /* Feature bits selected by the last -mcpu/-march or by the combination of the
336 last .cpu/.arch directive .arch_extension directives since that
337 directive. */
338 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
339 /* FPU feature bits selected by the last -mfpu or .fpu directive. */
340 static arm_feature_set selected_fpu = FPU_NONE;
341 /* Feature bits selected by the last .object_arch directive. */
342 static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
343 /* Must be long enough to hold any of the names in arm_cpus. */
344 static char selected_cpu_name[20];
345
346 extern FLONUM_TYPE generic_floating_point_number;
347
348 /* Return if no cpu was selected on command-line. */
349 static bfd_boolean
350 no_cpu_selected (void)
351 {
352 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
353 }
354
355 #ifdef OBJ_ELF
356 # ifdef EABI_DEFAULT
357 static int meabi_flags = EABI_DEFAULT;
358 # else
359 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
360 # endif
361
362 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
363
364 bfd_boolean
365 arm_is_eabi (void)
366 {
367 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
368 }
369 #endif
370
371 #ifdef OBJ_ELF
372 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
373 symbolS * GOT_symbol;
374 #endif
375
376 /* 0: assemble for ARM,
377 1: assemble for Thumb,
378 2: assemble for Thumb even though target CPU does not support thumb
379 instructions. */
380 static int thumb_mode = 0;
381 /* A value distinct from the possible values for thumb_mode that we
382 can use to record whether thumb_mode has been copied into the
383 tc_frag_data field of a frag. */
384 #define MODE_RECORDED (1 << 4)
385
386 /* Specifies the intrinsic IT insn behavior mode. */
387 enum implicit_it_mode
388 {
389 IMPLICIT_IT_MODE_NEVER = 0x00,
390 IMPLICIT_IT_MODE_ARM = 0x01,
391 IMPLICIT_IT_MODE_THUMB = 0x02,
392 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
393 };
394 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
395
396 /* If unified_syntax is true, we are processing the new unified
397 ARM/Thumb syntax. Important differences from the old ARM mode:
398
399 - Immediate operands do not require a # prefix.
400 - Conditional affixes always appear at the end of the
401 instruction. (For backward compatibility, those instructions
402 that formerly had them in the middle, continue to accept them
403 there.)
404 - The IT instruction may appear, and if it does is validated
405 against subsequent conditional affixes. It does not generate
406 machine code.
407
408 Important differences from the old Thumb mode:
409
410 - Immediate operands do not require a # prefix.
411 - Most of the V6T2 instructions are only available in unified mode.
412 - The .N and .W suffixes are recognized and honored (it is an error
413 if they cannot be honored).
414 - All instructions set the flags if and only if they have an 's' affix.
415 - Conditional affixes may be used. They are validated against
416 preceding IT instructions. Unlike ARM mode, you cannot use a
417 conditional affix except in the scope of an IT instruction. */
418
419 static bfd_boolean unified_syntax = FALSE;
420
421 /* An immediate operand can start with #, and ld*, st*, pld operands
422 can contain [ and ]. We need to tell APP not to elide whitespace
423 before a [, which can appear as the first operand for pld.
424 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
425 const char arm_symbol_chars[] = "#[]{}";
426
427 enum neon_el_type
428 {
429 NT_invtype,
430 NT_untyped,
431 NT_integer,
432 NT_float,
433 NT_poly,
434 NT_signed,
435 NT_unsigned
436 };
437
438 struct neon_type_el
439 {
440 enum neon_el_type type;
441 unsigned size;
442 };
443
444 #define NEON_MAX_TYPE_ELS 4
445
446 struct neon_type
447 {
448 struct neon_type_el el[NEON_MAX_TYPE_ELS];
449 unsigned elems;
450 };
451
452 enum it_instruction_type
453 {
454 OUTSIDE_IT_INSN,
455 INSIDE_IT_INSN,
456 INSIDE_IT_LAST_INSN,
457 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
458 if inside, should be the last one. */
459 NEUTRAL_IT_INSN, /* This could be either inside or outside,
460 i.e. BKPT and NOP. */
461 IT_INSN /* The IT insn has been parsed. */
462 };
463
464 /* The maximum number of operands we need. */
465 #define ARM_IT_MAX_OPERANDS 6
466 #define ARM_IT_MAX_RELOCS 3
467
468 struct arm_it
469 {
470 const char * error;
471 unsigned long instruction;
472 int size;
473 int size_req;
474 int cond;
475 /* "uncond_value" is set to the value in place of the conditional field in
476 unconditional versions of the instruction, or -1 if nothing is
477 appropriate. */
478 int uncond_value;
479 struct neon_type vectype;
480 /* This does not indicate an actual NEON instruction, only that
481 the mnemonic accepts neon-style type suffixes. */
482 int is_neon;
483 /* Set to the opcode if the instruction needs relaxation.
484 Zero if the instruction is not relaxed. */
485 unsigned long relax;
486 struct
487 {
488 bfd_reloc_code_real_type type;
489 expressionS exp;
490 int pc_rel;
491 } relocs[ARM_IT_MAX_RELOCS];
492
493 enum it_instruction_type it_insn_type;
494
495 struct
496 {
497 unsigned reg;
498 signed int imm;
499 struct neon_type_el vectype;
500 unsigned present : 1; /* Operand present. */
501 unsigned isreg : 1; /* Operand was a register. */
502 unsigned immisreg : 1; /* .imm field is a second register. */
503 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
504 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
505 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
506 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
507 instructions. This allows us to disambiguate ARM <-> vector insns. */
508 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
509 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
510 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
511 unsigned issingle : 1; /* Operand is VFP single-precision register. */
512 unsigned hasreloc : 1; /* Operand has relocation suffix. */
513 unsigned writeback : 1; /* Operand has trailing ! */
514 unsigned preind : 1; /* Preindexed address. */
515 unsigned postind : 1; /* Postindexed address. */
516 unsigned negative : 1; /* Index register was negated. */
517 unsigned shifted : 1; /* Shift applied to operation. */
518 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
519 } operands[ARM_IT_MAX_OPERANDS];
520 };
521
522 static struct arm_it inst;
523
524 #define NUM_FLOAT_VALS 8
525
526 const char * fp_const[] =
527 {
528 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
529 };
530
531 /* Number of littlenums required to hold an extended precision number. */
532 #define MAX_LITTLENUMS 6
533
534 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
535
536 #define FAIL (-1)
537 #define SUCCESS (0)
538
539 #define SUFF_S 1
540 #define SUFF_D 2
541 #define SUFF_E 3
542 #define SUFF_P 4
543
544 #define CP_T_X 0x00008000
545 #define CP_T_Y 0x00400000
546
547 #define CONDS_BIT 0x00100000
548 #define LOAD_BIT 0x00100000
549
550 #define DOUBLE_LOAD_FLAG 0x00000001
551
552 struct asm_cond
553 {
554 const char * template_name;
555 unsigned long value;
556 };
557
558 #define COND_ALWAYS 0xE
559
560 struct asm_psr
561 {
562 const char * template_name;
563 unsigned long field;
564 };
565
566 struct asm_barrier_opt
567 {
568 const char * template_name;
569 unsigned long value;
570 const arm_feature_set arch;
571 };
572
573 /* The bit that distinguishes CPSR and SPSR. */
574 #define SPSR_BIT (1 << 22)
575
576 /* The individual PSR flag bits. */
577 #define PSR_c (1 << 16)
578 #define PSR_x (1 << 17)
579 #define PSR_s (1 << 18)
580 #define PSR_f (1 << 19)
581
582 struct reloc_entry
583 {
584 const char * name;
585 bfd_reloc_code_real_type reloc;
586 };
587
588 enum vfp_reg_pos
589 {
590 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
591 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
592 };
593
594 enum vfp_ldstm_type
595 {
596 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
597 };
598
599 /* Bits for DEFINED field in neon_typed_alias. */
600 #define NTA_HASTYPE 1
601 #define NTA_HASINDEX 2
602
603 struct neon_typed_alias
604 {
605 unsigned char defined;
606 unsigned char index;
607 struct neon_type_el eltype;
608 };
609
610 /* ARM register categories. This includes coprocessor numbers and various
611 architecture extensions' registers. Each entry should have an error message
612 in reg_expected_msgs below. */
613 enum arm_reg_type
614 {
615 REG_TYPE_RN,
616 REG_TYPE_CP,
617 REG_TYPE_CN,
618 REG_TYPE_FN,
619 REG_TYPE_VFS,
620 REG_TYPE_VFD,
621 REG_TYPE_NQ,
622 REG_TYPE_VFSD,
623 REG_TYPE_NDQ,
624 REG_TYPE_NSD,
625 REG_TYPE_NSDQ,
626 REG_TYPE_VFC,
627 REG_TYPE_MVF,
628 REG_TYPE_MVD,
629 REG_TYPE_MVFX,
630 REG_TYPE_MVDX,
631 REG_TYPE_MVAX,
632 REG_TYPE_DSPSC,
633 REG_TYPE_MMXWR,
634 REG_TYPE_MMXWC,
635 REG_TYPE_MMXWCG,
636 REG_TYPE_XSCALE,
637 REG_TYPE_RNB
638 };
639
640 /* Structure for a hash table entry for a register.
641 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
642 information which states whether a vector type or index is specified (for a
643 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
644 struct reg_entry
645 {
646 const char * name;
647 unsigned int number;
648 unsigned char type;
649 unsigned char builtin;
650 struct neon_typed_alias * neon;
651 };
652
653 /* Diagnostics used when we don't get a register of the expected type. */
654 const char * const reg_expected_msgs[] =
655 {
656 [REG_TYPE_RN] = N_("ARM register expected"),
657 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
658 [REG_TYPE_CN] = N_("co-processor register expected"),
659 [REG_TYPE_FN] = N_("FPA register expected"),
660 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
661 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
662 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
663 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
664 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
665 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
666 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
667 " expected"),
668 [REG_TYPE_VFC] = N_("VFP system register expected"),
669 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
670 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
671 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
672 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
673 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
674 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
675 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
676 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
677 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
678 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
679 [REG_TYPE_RNB] = N_("")
680 };
681
682 /* Some well known registers that we refer to directly elsewhere. */
683 #define REG_R12 12
684 #define REG_SP 13
685 #define REG_LR 14
686 #define REG_PC 15
687
688 /* ARM instructions take 4bytes in the object file, Thumb instructions
689 take 2: */
690 #define INSN_SIZE 4
691
692 struct asm_opcode
693 {
694 /* Basic string to match. */
695 const char * template_name;
696
697 /* Parameters to instruction. */
698 unsigned int operands[8];
699
700 /* Conditional tag - see opcode_lookup. */
701 unsigned int tag : 4;
702
703 /* Basic instruction code. */
704 unsigned int avalue : 28;
705
706 /* Thumb-format instruction code. */
707 unsigned int tvalue;
708
709 /* Which architecture variant provides this instruction. */
710 const arm_feature_set * avariant;
711 const arm_feature_set * tvariant;
712
713 /* Function to call to encode instruction in ARM format. */
714 void (* aencode) (void);
715
716 /* Function to call to encode instruction in Thumb format. */
717 void (* tencode) (void);
718 };
719
720 /* Defines for various bits that we will want to toggle. */
721 #define INST_IMMEDIATE 0x02000000
722 #define OFFSET_REG 0x02000000
723 #define HWOFFSET_IMM 0x00400000
724 #define SHIFT_BY_REG 0x00000010
725 #define PRE_INDEX 0x01000000
726 #define INDEX_UP 0x00800000
727 #define WRITE_BACK 0x00200000
728 #define LDM_TYPE_2_OR_3 0x00400000
729 #define CPSI_MMOD 0x00020000
730
731 #define LITERAL_MASK 0xf000f000
732 #define OPCODE_MASK 0xfe1fffff
733 #define V4_STR_BIT 0x00000020
734 #define VLDR_VMOV_SAME 0x0040f000
735
736 #define T2_SUBS_PC_LR 0xf3de8f00
737
738 #define DATA_OP_SHIFT 21
739 #define SBIT_SHIFT 20
740
741 #define T2_OPCODE_MASK 0xfe1fffff
742 #define T2_DATA_OP_SHIFT 21
743 #define T2_SBIT_SHIFT 20
744
745 #define A_COND_MASK 0xf0000000
746 #define A_PUSH_POP_OP_MASK 0x0fff0000
747
748 /* Opcodes for pushing/poping registers to/from the stack. */
749 #define A1_OPCODE_PUSH 0x092d0000
750 #define A2_OPCODE_PUSH 0x052d0004
751 #define A2_OPCODE_POP 0x049d0004
752
753 /* Codes to distinguish the arithmetic instructions. */
754 #define OPCODE_AND 0
755 #define OPCODE_EOR 1
756 #define OPCODE_SUB 2
757 #define OPCODE_RSB 3
758 #define OPCODE_ADD 4
759 #define OPCODE_ADC 5
760 #define OPCODE_SBC 6
761 #define OPCODE_RSC 7
762 #define OPCODE_TST 8
763 #define OPCODE_TEQ 9
764 #define OPCODE_CMP 10
765 #define OPCODE_CMN 11
766 #define OPCODE_ORR 12
767 #define OPCODE_MOV 13
768 #define OPCODE_BIC 14
769 #define OPCODE_MVN 15
770
771 #define T2_OPCODE_AND 0
772 #define T2_OPCODE_BIC 1
773 #define T2_OPCODE_ORR 2
774 #define T2_OPCODE_ORN 3
775 #define T2_OPCODE_EOR 4
776 #define T2_OPCODE_ADD 8
777 #define T2_OPCODE_ADC 10
778 #define T2_OPCODE_SBC 11
779 #define T2_OPCODE_SUB 13
780 #define T2_OPCODE_RSB 14
781
782 #define T_OPCODE_MUL 0x4340
783 #define T_OPCODE_TST 0x4200
784 #define T_OPCODE_CMN 0x42c0
785 #define T_OPCODE_NEG 0x4240
786 #define T_OPCODE_MVN 0x43c0
787
788 #define T_OPCODE_ADD_R3 0x1800
789 #define T_OPCODE_SUB_R3 0x1a00
790 #define T_OPCODE_ADD_HI 0x4400
791 #define T_OPCODE_ADD_ST 0xb000
792 #define T_OPCODE_SUB_ST 0xb080
793 #define T_OPCODE_ADD_SP 0xa800
794 #define T_OPCODE_ADD_PC 0xa000
795 #define T_OPCODE_ADD_I8 0x3000
796 #define T_OPCODE_SUB_I8 0x3800
797 #define T_OPCODE_ADD_I3 0x1c00
798 #define T_OPCODE_SUB_I3 0x1e00
799
800 #define T_OPCODE_ASR_R 0x4100
801 #define T_OPCODE_LSL_R 0x4080
802 #define T_OPCODE_LSR_R 0x40c0
803 #define T_OPCODE_ROR_R 0x41c0
804 #define T_OPCODE_ASR_I 0x1000
805 #define T_OPCODE_LSL_I 0x0000
806 #define T_OPCODE_LSR_I 0x0800
807
808 #define T_OPCODE_MOV_I8 0x2000
809 #define T_OPCODE_CMP_I8 0x2800
810 #define T_OPCODE_CMP_LR 0x4280
811 #define T_OPCODE_MOV_HR 0x4600
812 #define T_OPCODE_CMP_HR 0x4500
813
814 #define T_OPCODE_LDR_PC 0x4800
815 #define T_OPCODE_LDR_SP 0x9800
816 #define T_OPCODE_STR_SP 0x9000
817 #define T_OPCODE_LDR_IW 0x6800
818 #define T_OPCODE_STR_IW 0x6000
819 #define T_OPCODE_LDR_IH 0x8800
820 #define T_OPCODE_STR_IH 0x8000
821 #define T_OPCODE_LDR_IB 0x7800
822 #define T_OPCODE_STR_IB 0x7000
823 #define T_OPCODE_LDR_RW 0x5800
824 #define T_OPCODE_STR_RW 0x5000
825 #define T_OPCODE_LDR_RH 0x5a00
826 #define T_OPCODE_STR_RH 0x5200
827 #define T_OPCODE_LDR_RB 0x5c00
828 #define T_OPCODE_STR_RB 0x5400
829
830 #define T_OPCODE_PUSH 0xb400
831 #define T_OPCODE_POP 0xbc00
832
833 #define T_OPCODE_BRANCH 0xe000
834
835 #define THUMB_SIZE 2 /* Size of thumb instruction. */
836 #define THUMB_PP_PC_LR 0x0100
837 #define THUMB_LOAD_BIT 0x0800
838 #define THUMB2_LOAD_BIT 0x00100000
839
840 #define BAD_ARGS _("bad arguments to instruction")
841 #define BAD_SP _("r13 not allowed here")
842 #define BAD_PC _("r15 not allowed here")
843 #define BAD_COND _("instruction cannot be conditional")
844 #define BAD_OVERLAP _("registers may not be the same")
845 #define BAD_HIREG _("lo register required")
846 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
847 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
848 #define BAD_BRANCH _("branch must be last instruction in IT block")
849 #define BAD_BRANCH_OFF _("branch out of range or not a multiple of 2")
850 #define BAD_NOT_IT _("instruction not allowed in IT block")
851 #define BAD_FPU _("selected FPU does not support instruction")
852 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
853 #define BAD_IT_COND _("incorrect condition in IT block")
854 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
855 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
856 #define BAD_PC_ADDRESSING \
857 _("cannot use register index with PC-relative addressing")
858 #define BAD_PC_WRITEBACK \
859 _("cannot use writeback with PC-relative addressing")
860 #define BAD_RANGE _("branch out of range")
861 #define BAD_FP16 _("selected processor does not support fp16 instruction")
862 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
863 #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
864
865 static struct hash_control * arm_ops_hsh;
866 static struct hash_control * arm_cond_hsh;
867 static struct hash_control * arm_shift_hsh;
868 static struct hash_control * arm_psr_hsh;
869 static struct hash_control * arm_v7m_psr_hsh;
870 static struct hash_control * arm_reg_hsh;
871 static struct hash_control * arm_reloc_hsh;
872 static struct hash_control * arm_barrier_opt_hsh;
873
874 /* Stuff needed to resolve the label ambiguity
875 As:
876 ...
877 label: <insn>
878 may differ from:
879 ...
880 label:
881 <insn> */
882
883 symbolS * last_label_seen;
884 static int label_is_thumb_function_name = FALSE;
885
886 /* Literal pool structure. Held on a per-section
887 and per-sub-section basis. */
888
889 #define MAX_LITERAL_POOL_SIZE 1024
890 typedef struct literal_pool
891 {
892 expressionS literals [MAX_LITERAL_POOL_SIZE];
893 unsigned int next_free_entry;
894 unsigned int id;
895 symbolS * symbol;
896 segT section;
897 subsegT sub_section;
898 #ifdef OBJ_ELF
899 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
900 #endif
901 struct literal_pool * next;
902 unsigned int alignment;
903 } literal_pool;
904
905 /* Pointer to a linked list of literal pools. */
906 literal_pool * list_of_pools = NULL;
907
908 typedef enum asmfunc_states
909 {
910 OUTSIDE_ASMFUNC,
911 WAITING_ASMFUNC_NAME,
912 WAITING_ENDASMFUNC
913 } asmfunc_states;
914
915 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
916
917 #ifdef OBJ_ELF
918 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
919 #else
920 static struct current_it now_it;
921 #endif
922
923 static inline int
924 now_it_compatible (int cond)
925 {
926 return (cond & ~1) == (now_it.cc & ~1);
927 }
928
929 static inline int
930 conditional_insn (void)
931 {
932 return inst.cond != COND_ALWAYS;
933 }
934
935 static int in_it_block (void);
936
937 static int handle_it_state (void);
938
939 static void force_automatic_it_block_close (void);
940
941 static void it_fsm_post_encode (void);
942
943 #define set_it_insn_type(type) \
944 do \
945 { \
946 inst.it_insn_type = type; \
947 if (handle_it_state () == FAIL) \
948 return; \
949 } \
950 while (0)
951
952 #define set_it_insn_type_nonvoid(type, failret) \
953 do \
954 { \
955 inst.it_insn_type = type; \
956 if (handle_it_state () == FAIL) \
957 return failret; \
958 } \
959 while(0)
960
961 #define set_it_insn_type_last() \
962 do \
963 { \
964 if (inst.cond == COND_ALWAYS) \
965 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
966 else \
967 set_it_insn_type (INSIDE_IT_LAST_INSN); \
968 } \
969 while (0)
970
971 /* Pure syntax. */
972
973 /* This array holds the chars that always start a comment. If the
974 pre-processor is disabled, these aren't very useful. */
975 char arm_comment_chars[] = "@";
976
977 /* This array holds the chars that only start a comment at the beginning of
978 a line. If the line seems to have the form '# 123 filename'
979 .line and .file directives will appear in the pre-processed output. */
980 /* Note that input_file.c hand checks for '#' at the beginning of the
981 first line of the input file. This is because the compiler outputs
982 #NO_APP at the beginning of its output. */
983 /* Also note that comments like this one will always work. */
984 const char line_comment_chars[] = "#";
985
986 char arm_line_separator_chars[] = ";";
987
988 /* Chars that can be used to separate mant
989 from exp in floating point numbers. */
990 const char EXP_CHARS[] = "eE";
991
992 /* Chars that mean this number is a floating point constant. */
993 /* As in 0f12.456 */
994 /* or 0d1.2345e12 */
995
996 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
997
998 /* Prefix characters that indicate the start of an immediate
999 value. */
1000 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
1001
1002 /* Separator character handling. */
1003
1004 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
1005
1006 static inline int
1007 skip_past_char (char ** str, char c)
1008 {
1009 /* PR gas/14987: Allow for whitespace before the expected character. */
1010 skip_whitespace (*str);
1011
1012 if (**str == c)
1013 {
1014 (*str)++;
1015 return SUCCESS;
1016 }
1017 else
1018 return FAIL;
1019 }
1020
1021 #define skip_past_comma(str) skip_past_char (str, ',')
1022
1023 /* Arithmetic expressions (possibly involving symbols). */
1024
1025 /* Return TRUE if anything in the expression is a bignum. */
1026
1027 static bfd_boolean
1028 walk_no_bignums (symbolS * sp)
1029 {
1030 if (symbol_get_value_expression (sp)->X_op == O_big)
1031 return TRUE;
1032
1033 if (symbol_get_value_expression (sp)->X_add_symbol)
1034 {
1035 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1036 || (symbol_get_value_expression (sp)->X_op_symbol
1037 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
1038 }
1039
1040 return FALSE;
1041 }
1042
1043 static bfd_boolean in_my_get_expression = FALSE;
1044
1045 /* Third argument to my_get_expression. */
1046 #define GE_NO_PREFIX 0
1047 #define GE_IMM_PREFIX 1
1048 #define GE_OPT_PREFIX 2
1049 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1050 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1051 #define GE_OPT_PREFIX_BIG 3
1052
1053 static int
1054 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
1055 {
1056 char * save_in;
1057
1058 /* In unified syntax, all prefixes are optional. */
1059 if (unified_syntax)
1060 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
1061 : GE_OPT_PREFIX;
1062
1063 switch (prefix_mode)
1064 {
1065 case GE_NO_PREFIX: break;
1066 case GE_IMM_PREFIX:
1067 if (!is_immediate_prefix (**str))
1068 {
1069 inst.error = _("immediate expression requires a # prefix");
1070 return FAIL;
1071 }
1072 (*str)++;
1073 break;
1074 case GE_OPT_PREFIX:
1075 case GE_OPT_PREFIX_BIG:
1076 if (is_immediate_prefix (**str))
1077 (*str)++;
1078 break;
1079 default:
1080 abort ();
1081 }
1082
1083 memset (ep, 0, sizeof (expressionS));
1084
1085 save_in = input_line_pointer;
1086 input_line_pointer = *str;
1087 in_my_get_expression = TRUE;
1088 expression (ep);
1089 in_my_get_expression = FALSE;
1090
1091 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1092 {
1093 /* We found a bad or missing expression in md_operand(). */
1094 *str = input_line_pointer;
1095 input_line_pointer = save_in;
1096 if (inst.error == NULL)
1097 inst.error = (ep->X_op == O_absent
1098 ? _("missing expression") :_("bad expression"));
1099 return 1;
1100 }
1101
1102 /* Get rid of any bignums now, so that we don't generate an error for which
1103 we can't establish a line number later on. Big numbers are never valid
1104 in instructions, which is where this routine is always called. */
1105 if (prefix_mode != GE_OPT_PREFIX_BIG
1106 && (ep->X_op == O_big
1107 || (ep->X_add_symbol
1108 && (walk_no_bignums (ep->X_add_symbol)
1109 || (ep->X_op_symbol
1110 && walk_no_bignums (ep->X_op_symbol))))))
1111 {
1112 inst.error = _("invalid constant");
1113 *str = input_line_pointer;
1114 input_line_pointer = save_in;
1115 return 1;
1116 }
1117
1118 *str = input_line_pointer;
1119 input_line_pointer = save_in;
1120 return SUCCESS;
1121 }
1122
1123 /* Turn a string in input_line_pointer into a floating point constant
1124 of type TYPE, and store the appropriate bytes in *LITP. The number
1125 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1126 returned, or NULL on OK.
1127
1128 Note that fp constants aren't represent in the normal way on the ARM.
1129 In big endian mode, things are as expected. However, in little endian
1130 mode fp constants are big-endian word-wise, and little-endian byte-wise
1131 within the words. For example, (double) 1.1 in big endian mode is
1132 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1133 the byte sequence 99 99 f1 3f 9a 99 99 99.
1134
1135 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1136
1137 const char *
1138 md_atof (int type, char * litP, int * sizeP)
1139 {
1140 int prec;
1141 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1142 char *t;
1143 int i;
1144
1145 switch (type)
1146 {
1147 case 'f':
1148 case 'F':
1149 case 's':
1150 case 'S':
1151 prec = 2;
1152 break;
1153
1154 case 'd':
1155 case 'D':
1156 case 'r':
1157 case 'R':
1158 prec = 4;
1159 break;
1160
1161 case 'x':
1162 case 'X':
1163 prec = 5;
1164 break;
1165
1166 case 'p':
1167 case 'P':
1168 prec = 5;
1169 break;
1170
1171 default:
1172 *sizeP = 0;
1173 return _("Unrecognized or unsupported floating point constant");
1174 }
1175
1176 t = atof_ieee (input_line_pointer, type, words);
1177 if (t)
1178 input_line_pointer = t;
1179 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1180
1181 if (target_big_endian)
1182 {
1183 for (i = 0; i < prec; i++)
1184 {
1185 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1186 litP += sizeof (LITTLENUM_TYPE);
1187 }
1188 }
1189 else
1190 {
1191 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1192 for (i = prec - 1; i >= 0; i--)
1193 {
1194 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1195 litP += sizeof (LITTLENUM_TYPE);
1196 }
1197 else
1198 /* For a 4 byte float the order of elements in `words' is 1 0.
1199 For an 8 byte float the order is 1 0 3 2. */
1200 for (i = 0; i < prec; i += 2)
1201 {
1202 md_number_to_chars (litP, (valueT) words[i + 1],
1203 sizeof (LITTLENUM_TYPE));
1204 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1205 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1206 litP += 2 * sizeof (LITTLENUM_TYPE);
1207 }
1208 }
1209
1210 return NULL;
1211 }
1212
1213 /* We handle all bad expressions here, so that we can report the faulty
1214 instruction in the error message. */
1215
1216 void
1217 md_operand (expressionS * exp)
1218 {
1219 if (in_my_get_expression)
1220 exp->X_op = O_illegal;
1221 }
1222
1223 /* Immediate values. */
1224
1225 #ifdef OBJ_ELF
1226 /* Generic immediate-value read function for use in directives.
1227 Accepts anything that 'expression' can fold to a constant.
1228 *val receives the number. */
1229
1230 static int
1231 immediate_for_directive (int *val)
1232 {
1233 expressionS exp;
1234 exp.X_op = O_illegal;
1235
1236 if (is_immediate_prefix (*input_line_pointer))
1237 {
1238 input_line_pointer++;
1239 expression (&exp);
1240 }
1241
1242 if (exp.X_op != O_constant)
1243 {
1244 as_bad (_("expected #constant"));
1245 ignore_rest_of_line ();
1246 return FAIL;
1247 }
1248 *val = exp.X_add_number;
1249 return SUCCESS;
1250 }
1251 #endif
1252
1253 /* Register parsing. */
1254
1255 /* Generic register parser. CCP points to what should be the
1256 beginning of a register name. If it is indeed a valid register
1257 name, advance CCP over it and return the reg_entry structure;
1258 otherwise return NULL. Does not issue diagnostics. */
1259
1260 static struct reg_entry *
1261 arm_reg_parse_multi (char **ccp)
1262 {
1263 char *start = *ccp;
1264 char *p;
1265 struct reg_entry *reg;
1266
1267 skip_whitespace (start);
1268
1269 #ifdef REGISTER_PREFIX
1270 if (*start != REGISTER_PREFIX)
1271 return NULL;
1272 start++;
1273 #endif
1274 #ifdef OPTIONAL_REGISTER_PREFIX
1275 if (*start == OPTIONAL_REGISTER_PREFIX)
1276 start++;
1277 #endif
1278
1279 p = start;
1280 if (!ISALPHA (*p) || !is_name_beginner (*p))
1281 return NULL;
1282
1283 do
1284 p++;
1285 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1286
1287 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1288
1289 if (!reg)
1290 return NULL;
1291
1292 *ccp = p;
1293 return reg;
1294 }
1295
1296 static int
1297 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1298 enum arm_reg_type type)
1299 {
1300 /* Alternative syntaxes are accepted for a few register classes. */
1301 switch (type)
1302 {
1303 case REG_TYPE_MVF:
1304 case REG_TYPE_MVD:
1305 case REG_TYPE_MVFX:
1306 case REG_TYPE_MVDX:
1307 /* Generic coprocessor register names are allowed for these. */
1308 if (reg && reg->type == REG_TYPE_CN)
1309 return reg->number;
1310 break;
1311
1312 case REG_TYPE_CP:
1313 /* For backward compatibility, a bare number is valid here. */
1314 {
1315 unsigned long processor = strtoul (start, ccp, 10);
1316 if (*ccp != start && processor <= 15)
1317 return processor;
1318 }
1319 /* Fall through. */
1320
1321 case REG_TYPE_MMXWC:
1322 /* WC includes WCG. ??? I'm not sure this is true for all
1323 instructions that take WC registers. */
1324 if (reg && reg->type == REG_TYPE_MMXWCG)
1325 return reg->number;
1326 break;
1327
1328 default:
1329 break;
1330 }
1331
1332 return FAIL;
1333 }
1334
1335 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1336 return value is the register number or FAIL. */
1337
1338 static int
1339 arm_reg_parse (char **ccp, enum arm_reg_type type)
1340 {
1341 char *start = *ccp;
1342 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1343 int ret;
1344
1345 /* Do not allow a scalar (reg+index) to parse as a register. */
1346 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1347 return FAIL;
1348
1349 if (reg && reg->type == type)
1350 return reg->number;
1351
1352 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1353 return ret;
1354
1355 *ccp = start;
1356 return FAIL;
1357 }
1358
1359 /* Parse a Neon type specifier. *STR should point at the leading '.'
1360 character. Does no verification at this stage that the type fits the opcode
1361 properly. E.g.,
1362
1363 .i32.i32.s16
1364 .s32.f32
1365 .u16
1366
1367 Can all be legally parsed by this function.
1368
1369 Fills in neon_type struct pointer with parsed information, and updates STR
1370 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1371 type, FAIL if not. */
1372
1373 static int
1374 parse_neon_type (struct neon_type *type, char **str)
1375 {
1376 char *ptr = *str;
1377
1378 if (type)
1379 type->elems = 0;
1380
1381 while (type->elems < NEON_MAX_TYPE_ELS)
1382 {
1383 enum neon_el_type thistype = NT_untyped;
1384 unsigned thissize = -1u;
1385
1386 if (*ptr != '.')
1387 break;
1388
1389 ptr++;
1390
1391 /* Just a size without an explicit type. */
1392 if (ISDIGIT (*ptr))
1393 goto parsesize;
1394
1395 switch (TOLOWER (*ptr))
1396 {
1397 case 'i': thistype = NT_integer; break;
1398 case 'f': thistype = NT_float; break;
1399 case 'p': thistype = NT_poly; break;
1400 case 's': thistype = NT_signed; break;
1401 case 'u': thistype = NT_unsigned; break;
1402 case 'd':
1403 thistype = NT_float;
1404 thissize = 64;
1405 ptr++;
1406 goto done;
1407 default:
1408 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1409 return FAIL;
1410 }
1411
1412 ptr++;
1413
1414 /* .f is an abbreviation for .f32. */
1415 if (thistype == NT_float && !ISDIGIT (*ptr))
1416 thissize = 32;
1417 else
1418 {
1419 parsesize:
1420 thissize = strtoul (ptr, &ptr, 10);
1421
1422 if (thissize != 8 && thissize != 16 && thissize != 32
1423 && thissize != 64)
1424 {
1425 as_bad (_("bad size %d in type specifier"), thissize);
1426 return FAIL;
1427 }
1428 }
1429
1430 done:
1431 if (type)
1432 {
1433 type->el[type->elems].type = thistype;
1434 type->el[type->elems].size = thissize;
1435 type->elems++;
1436 }
1437 }
1438
1439 /* Empty/missing type is not a successful parse. */
1440 if (type->elems == 0)
1441 return FAIL;
1442
1443 *str = ptr;
1444
1445 return SUCCESS;
1446 }
1447
1448 /* Errors may be set multiple times during parsing or bit encoding
1449 (particularly in the Neon bits), but usually the earliest error which is set
1450 will be the most meaningful. Avoid overwriting it with later (cascading)
1451 errors by calling this function. */
1452
1453 static void
1454 first_error (const char *err)
1455 {
1456 if (!inst.error)
1457 inst.error = err;
1458 }
1459
1460 /* Parse a single type, e.g. ".s32", leading period included. */
1461 static int
1462 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1463 {
1464 char *str = *ccp;
1465 struct neon_type optype;
1466
1467 if (*str == '.')
1468 {
1469 if (parse_neon_type (&optype, &str) == SUCCESS)
1470 {
1471 if (optype.elems == 1)
1472 *vectype = optype.el[0];
1473 else
1474 {
1475 first_error (_("only one type should be specified for operand"));
1476 return FAIL;
1477 }
1478 }
1479 else
1480 {
1481 first_error (_("vector type expected"));
1482 return FAIL;
1483 }
1484 }
1485 else
1486 return FAIL;
1487
1488 *ccp = str;
1489
1490 return SUCCESS;
1491 }
1492
1493 /* Special meanings for indices (which have a range of 0-7), which will fit into
1494 a 4-bit integer. */
1495
1496 #define NEON_ALL_LANES 15
1497 #define NEON_INTERLEAVE_LANES 14
1498
1499 /* Parse either a register or a scalar, with an optional type. Return the
1500 register number, and optionally fill in the actual type of the register
1501 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1502 type/index information in *TYPEINFO. */
1503
1504 static int
1505 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1506 enum arm_reg_type *rtype,
1507 struct neon_typed_alias *typeinfo)
1508 {
1509 char *str = *ccp;
1510 struct reg_entry *reg = arm_reg_parse_multi (&str);
1511 struct neon_typed_alias atype;
1512 struct neon_type_el parsetype;
1513
1514 atype.defined = 0;
1515 atype.index = -1;
1516 atype.eltype.type = NT_invtype;
1517 atype.eltype.size = -1;
1518
1519 /* Try alternate syntax for some types of register. Note these are mutually
1520 exclusive with the Neon syntax extensions. */
1521 if (reg == NULL)
1522 {
1523 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1524 if (altreg != FAIL)
1525 *ccp = str;
1526 if (typeinfo)
1527 *typeinfo = atype;
1528 return altreg;
1529 }
1530
1531 /* Undo polymorphism when a set of register types may be accepted. */
1532 if ((type == REG_TYPE_NDQ
1533 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1534 || (type == REG_TYPE_VFSD
1535 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1536 || (type == REG_TYPE_NSDQ
1537 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1538 || reg->type == REG_TYPE_NQ))
1539 || (type == REG_TYPE_NSD
1540 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1541 || (type == REG_TYPE_MMXWC
1542 && (reg->type == REG_TYPE_MMXWCG)))
1543 type = (enum arm_reg_type) reg->type;
1544
1545 if (type != reg->type)
1546 return FAIL;
1547
1548 if (reg->neon)
1549 atype = *reg->neon;
1550
1551 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1552 {
1553 if ((atype.defined & NTA_HASTYPE) != 0)
1554 {
1555 first_error (_("can't redefine type for operand"));
1556 return FAIL;
1557 }
1558 atype.defined |= NTA_HASTYPE;
1559 atype.eltype = parsetype;
1560 }
1561
1562 if (skip_past_char (&str, '[') == SUCCESS)
1563 {
1564 if (type != REG_TYPE_VFD
1565 && !(type == REG_TYPE_VFS
1566 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
1567 {
1568 first_error (_("only D registers may be indexed"));
1569 return FAIL;
1570 }
1571
1572 if ((atype.defined & NTA_HASINDEX) != 0)
1573 {
1574 first_error (_("can't change index for operand"));
1575 return FAIL;
1576 }
1577
1578 atype.defined |= NTA_HASINDEX;
1579
1580 if (skip_past_char (&str, ']') == SUCCESS)
1581 atype.index = NEON_ALL_LANES;
1582 else
1583 {
1584 expressionS exp;
1585
1586 my_get_expression (&exp, &str, GE_NO_PREFIX);
1587
1588 if (exp.X_op != O_constant)
1589 {
1590 first_error (_("constant expression required"));
1591 return FAIL;
1592 }
1593
1594 if (skip_past_char (&str, ']') == FAIL)
1595 return FAIL;
1596
1597 atype.index = exp.X_add_number;
1598 }
1599 }
1600
1601 if (typeinfo)
1602 *typeinfo = atype;
1603
1604 if (rtype)
1605 *rtype = type;
1606
1607 *ccp = str;
1608
1609 return reg->number;
1610 }
1611
1612 /* Like arm_reg_parse, but allow allow the following extra features:
1613 - If RTYPE is non-zero, return the (possibly restricted) type of the
1614 register (e.g. Neon double or quad reg when either has been requested).
1615 - If this is a Neon vector type with additional type information, fill
1616 in the struct pointed to by VECTYPE (if non-NULL).
1617 This function will fault on encountering a scalar. */
1618
1619 static int
1620 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1621 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1622 {
1623 struct neon_typed_alias atype;
1624 char *str = *ccp;
1625 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1626
1627 if (reg == FAIL)
1628 return FAIL;
1629
1630 /* Do not allow regname(... to parse as a register. */
1631 if (*str == '(')
1632 return FAIL;
1633
1634 /* Do not allow a scalar (reg+index) to parse as a register. */
1635 if ((atype.defined & NTA_HASINDEX) != 0)
1636 {
1637 first_error (_("register operand expected, but got scalar"));
1638 return FAIL;
1639 }
1640
1641 if (vectype)
1642 *vectype = atype.eltype;
1643
1644 *ccp = str;
1645
1646 return reg;
1647 }
1648
1649 #define NEON_SCALAR_REG(X) ((X) >> 4)
1650 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1651
1652 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1653 have enough information to be able to do a good job bounds-checking. So, we
1654 just do easy checks here, and do further checks later. */
1655
1656 static int
1657 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1658 {
1659 int reg;
1660 char *str = *ccp;
1661 struct neon_typed_alias atype;
1662 enum arm_reg_type reg_type = REG_TYPE_VFD;
1663
1664 if (elsize == 4)
1665 reg_type = REG_TYPE_VFS;
1666
1667 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
1668
1669 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1670 return FAIL;
1671
1672 if (atype.index == NEON_ALL_LANES)
1673 {
1674 first_error (_("scalar must have an index"));
1675 return FAIL;
1676 }
1677 else if (atype.index >= 64 / elsize)
1678 {
1679 first_error (_("scalar index out of range"));
1680 return FAIL;
1681 }
1682
1683 if (type)
1684 *type = atype.eltype;
1685
1686 *ccp = str;
1687
1688 return reg * 16 + atype.index;
1689 }
1690
1691 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1692
1693 static long
1694 parse_reg_list (char ** strp)
1695 {
1696 char * str = * strp;
1697 long range = 0;
1698 int another_range;
1699
1700 /* We come back here if we get ranges concatenated by '+' or '|'. */
1701 do
1702 {
1703 skip_whitespace (str);
1704
1705 another_range = 0;
1706
1707 if (*str == '{')
1708 {
1709 int in_range = 0;
1710 int cur_reg = -1;
1711
1712 str++;
1713 do
1714 {
1715 int reg;
1716
1717 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1718 {
1719 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1720 return FAIL;
1721 }
1722
1723 if (in_range)
1724 {
1725 int i;
1726
1727 if (reg <= cur_reg)
1728 {
1729 first_error (_("bad range in register list"));
1730 return FAIL;
1731 }
1732
1733 for (i = cur_reg + 1; i < reg; i++)
1734 {
1735 if (range & (1 << i))
1736 as_tsktsk
1737 (_("Warning: duplicated register (r%d) in register list"),
1738 i);
1739 else
1740 range |= 1 << i;
1741 }
1742 in_range = 0;
1743 }
1744
1745 if (range & (1 << reg))
1746 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1747 reg);
1748 else if (reg <= cur_reg)
1749 as_tsktsk (_("Warning: register range not in ascending order"));
1750
1751 range |= 1 << reg;
1752 cur_reg = reg;
1753 }
1754 while (skip_past_comma (&str) != FAIL
1755 || (in_range = 1, *str++ == '-'));
1756 str--;
1757
1758 if (skip_past_char (&str, '}') == FAIL)
1759 {
1760 first_error (_("missing `}'"));
1761 return FAIL;
1762 }
1763 }
1764 else
1765 {
1766 expressionS exp;
1767
1768 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1769 return FAIL;
1770
1771 if (exp.X_op == O_constant)
1772 {
1773 if (exp.X_add_number
1774 != (exp.X_add_number & 0x0000ffff))
1775 {
1776 inst.error = _("invalid register mask");
1777 return FAIL;
1778 }
1779
1780 if ((range & exp.X_add_number) != 0)
1781 {
1782 int regno = range & exp.X_add_number;
1783
1784 regno &= -regno;
1785 regno = (1 << regno) - 1;
1786 as_tsktsk
1787 (_("Warning: duplicated register (r%d) in register list"),
1788 regno);
1789 }
1790
1791 range |= exp.X_add_number;
1792 }
1793 else
1794 {
1795 if (inst.relocs[0].type != 0)
1796 {
1797 inst.error = _("expression too complex");
1798 return FAIL;
1799 }
1800
1801 memcpy (&inst.relocs[0].exp, &exp, sizeof (expressionS));
1802 inst.relocs[0].type = BFD_RELOC_ARM_MULTI;
1803 inst.relocs[0].pc_rel = 0;
1804 }
1805 }
1806
1807 if (*str == '|' || *str == '+')
1808 {
1809 str++;
1810 another_range = 1;
1811 }
1812 }
1813 while (another_range);
1814
1815 *strp = str;
1816 return range;
1817 }
1818
1819 /* Types of registers in a list. */
1820
1821 enum reg_list_els
1822 {
1823 REGLIST_VFP_S,
1824 REGLIST_VFP_D,
1825 REGLIST_NEON_D
1826 };
1827
1828 /* Parse a VFP register list. If the string is invalid return FAIL.
1829 Otherwise return the number of registers, and set PBASE to the first
1830 register. Parses registers of type ETYPE.
1831 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1832 - Q registers can be used to specify pairs of D registers
1833 - { } can be omitted from around a singleton register list
1834 FIXME: This is not implemented, as it would require backtracking in
1835 some cases, e.g.:
1836 vtbl.8 d3,d4,d5
1837 This could be done (the meaning isn't really ambiguous), but doesn't
1838 fit in well with the current parsing framework.
1839 - 32 D registers may be used (also true for VFPv3).
1840 FIXME: Types are ignored in these register lists, which is probably a
1841 bug. */
1842
1843 static int
1844 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1845 {
1846 char *str = *ccp;
1847 int base_reg;
1848 int new_base;
1849 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1850 int max_regs = 0;
1851 int count = 0;
1852 int warned = 0;
1853 unsigned long mask = 0;
1854 int i;
1855
1856 if (skip_past_char (&str, '{') == FAIL)
1857 {
1858 inst.error = _("expecting {");
1859 return FAIL;
1860 }
1861
1862 switch (etype)
1863 {
1864 case REGLIST_VFP_S:
1865 regtype = REG_TYPE_VFS;
1866 max_regs = 32;
1867 break;
1868
1869 case REGLIST_VFP_D:
1870 regtype = REG_TYPE_VFD;
1871 break;
1872
1873 case REGLIST_NEON_D:
1874 regtype = REG_TYPE_NDQ;
1875 break;
1876 }
1877
1878 if (etype != REGLIST_VFP_S)
1879 {
1880 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1881 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1882 {
1883 max_regs = 32;
1884 if (thumb_mode)
1885 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1886 fpu_vfp_ext_d32);
1887 else
1888 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1889 fpu_vfp_ext_d32);
1890 }
1891 else
1892 max_regs = 16;
1893 }
1894
1895 base_reg = max_regs;
1896
1897 do
1898 {
1899 int setmask = 1, addregs = 1;
1900
1901 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1902
1903 if (new_base == FAIL)
1904 {
1905 first_error (_(reg_expected_msgs[regtype]));
1906 return FAIL;
1907 }
1908
1909 if (new_base >= max_regs)
1910 {
1911 first_error (_("register out of range in list"));
1912 return FAIL;
1913 }
1914
1915 /* Note: a value of 2 * n is returned for the register Q<n>. */
1916 if (regtype == REG_TYPE_NQ)
1917 {
1918 setmask = 3;
1919 addregs = 2;
1920 }
1921
1922 if (new_base < base_reg)
1923 base_reg = new_base;
1924
1925 if (mask & (setmask << new_base))
1926 {
1927 first_error (_("invalid register list"));
1928 return FAIL;
1929 }
1930
1931 if ((mask >> new_base) != 0 && ! warned)
1932 {
1933 as_tsktsk (_("register list not in ascending order"));
1934 warned = 1;
1935 }
1936
1937 mask |= setmask << new_base;
1938 count += addregs;
1939
1940 if (*str == '-') /* We have the start of a range expression */
1941 {
1942 int high_range;
1943
1944 str++;
1945
1946 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1947 == FAIL)
1948 {
1949 inst.error = gettext (reg_expected_msgs[regtype]);
1950 return FAIL;
1951 }
1952
1953 if (high_range >= max_regs)
1954 {
1955 first_error (_("register out of range in list"));
1956 return FAIL;
1957 }
1958
1959 if (regtype == REG_TYPE_NQ)
1960 high_range = high_range + 1;
1961
1962 if (high_range <= new_base)
1963 {
1964 inst.error = _("register range not in ascending order");
1965 return FAIL;
1966 }
1967
1968 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1969 {
1970 if (mask & (setmask << new_base))
1971 {
1972 inst.error = _("invalid register list");
1973 return FAIL;
1974 }
1975
1976 mask |= setmask << new_base;
1977 count += addregs;
1978 }
1979 }
1980 }
1981 while (skip_past_comma (&str) != FAIL);
1982
1983 str++;
1984
1985 /* Sanity check -- should have raised a parse error above. */
1986 if (count == 0 || count > max_regs)
1987 abort ();
1988
1989 *pbase = base_reg;
1990
1991 /* Final test -- the registers must be consecutive. */
1992 mask >>= base_reg;
1993 for (i = 0; i < count; i++)
1994 {
1995 if ((mask & (1u << i)) == 0)
1996 {
1997 inst.error = _("non-contiguous register range");
1998 return FAIL;
1999 }
2000 }
2001
2002 *ccp = str;
2003
2004 return count;
2005 }
2006
2007 /* True if two alias types are the same. */
2008
2009 static bfd_boolean
2010 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2011 {
2012 if (!a && !b)
2013 return TRUE;
2014
2015 if (!a || !b)
2016 return FALSE;
2017
2018 if (a->defined != b->defined)
2019 return FALSE;
2020
2021 if ((a->defined & NTA_HASTYPE) != 0
2022 && (a->eltype.type != b->eltype.type
2023 || a->eltype.size != b->eltype.size))
2024 return FALSE;
2025
2026 if ((a->defined & NTA_HASINDEX) != 0
2027 && (a->index != b->index))
2028 return FALSE;
2029
2030 return TRUE;
2031 }
2032
2033 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2034 The base register is put in *PBASE.
2035 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
2036 the return value.
2037 The register stride (minus one) is put in bit 4 of the return value.
2038 Bits [6:5] encode the list length (minus one).
2039 The type of the list elements is put in *ELTYPE, if non-NULL. */
2040
2041 #define NEON_LANE(X) ((X) & 0xf)
2042 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
2043 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2044
2045 static int
2046 parse_neon_el_struct_list (char **str, unsigned *pbase,
2047 struct neon_type_el *eltype)
2048 {
2049 char *ptr = *str;
2050 int base_reg = -1;
2051 int reg_incr = -1;
2052 int count = 0;
2053 int lane = -1;
2054 int leading_brace = 0;
2055 enum arm_reg_type rtype = REG_TYPE_NDQ;
2056 const char *const incr_error = _("register stride must be 1 or 2");
2057 const char *const type_error = _("mismatched element/structure types in list");
2058 struct neon_typed_alias firsttype;
2059 firsttype.defined = 0;
2060 firsttype.eltype.type = NT_invtype;
2061 firsttype.eltype.size = -1;
2062 firsttype.index = -1;
2063
2064 if (skip_past_char (&ptr, '{') == SUCCESS)
2065 leading_brace = 1;
2066
2067 do
2068 {
2069 struct neon_typed_alias atype;
2070 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2071
2072 if (getreg == FAIL)
2073 {
2074 first_error (_(reg_expected_msgs[rtype]));
2075 return FAIL;
2076 }
2077
2078 if (base_reg == -1)
2079 {
2080 base_reg = getreg;
2081 if (rtype == REG_TYPE_NQ)
2082 {
2083 reg_incr = 1;
2084 }
2085 firsttype = atype;
2086 }
2087 else if (reg_incr == -1)
2088 {
2089 reg_incr = getreg - base_reg;
2090 if (reg_incr < 1 || reg_incr > 2)
2091 {
2092 first_error (_(incr_error));
2093 return FAIL;
2094 }
2095 }
2096 else if (getreg != base_reg + reg_incr * count)
2097 {
2098 first_error (_(incr_error));
2099 return FAIL;
2100 }
2101
2102 if (! neon_alias_types_same (&atype, &firsttype))
2103 {
2104 first_error (_(type_error));
2105 return FAIL;
2106 }
2107
2108 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2109 modes. */
2110 if (ptr[0] == '-')
2111 {
2112 struct neon_typed_alias htype;
2113 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2114 if (lane == -1)
2115 lane = NEON_INTERLEAVE_LANES;
2116 else if (lane != NEON_INTERLEAVE_LANES)
2117 {
2118 first_error (_(type_error));
2119 return FAIL;
2120 }
2121 if (reg_incr == -1)
2122 reg_incr = 1;
2123 else if (reg_incr != 1)
2124 {
2125 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2126 return FAIL;
2127 }
2128 ptr++;
2129 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2130 if (hireg == FAIL)
2131 {
2132 first_error (_(reg_expected_msgs[rtype]));
2133 return FAIL;
2134 }
2135 if (! neon_alias_types_same (&htype, &firsttype))
2136 {
2137 first_error (_(type_error));
2138 return FAIL;
2139 }
2140 count += hireg + dregs - getreg;
2141 continue;
2142 }
2143
2144 /* If we're using Q registers, we can't use [] or [n] syntax. */
2145 if (rtype == REG_TYPE_NQ)
2146 {
2147 count += 2;
2148 continue;
2149 }
2150
2151 if ((atype.defined & NTA_HASINDEX) != 0)
2152 {
2153 if (lane == -1)
2154 lane = atype.index;
2155 else if (lane != atype.index)
2156 {
2157 first_error (_(type_error));
2158 return FAIL;
2159 }
2160 }
2161 else if (lane == -1)
2162 lane = NEON_INTERLEAVE_LANES;
2163 else if (lane != NEON_INTERLEAVE_LANES)
2164 {
2165 first_error (_(type_error));
2166 return FAIL;
2167 }
2168 count++;
2169 }
2170 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2171
2172 /* No lane set by [x]. We must be interleaving structures. */
2173 if (lane == -1)
2174 lane = NEON_INTERLEAVE_LANES;
2175
2176 /* Sanity check. */
2177 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2178 || (count > 1 && reg_incr == -1))
2179 {
2180 first_error (_("error parsing element/structure list"));
2181 return FAIL;
2182 }
2183
2184 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2185 {
2186 first_error (_("expected }"));
2187 return FAIL;
2188 }
2189
2190 if (reg_incr == -1)
2191 reg_incr = 1;
2192
2193 if (eltype)
2194 *eltype = firsttype.eltype;
2195
2196 *pbase = base_reg;
2197 *str = ptr;
2198
2199 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2200 }
2201
2202 /* Parse an explicit relocation suffix on an expression. This is
2203 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2204 arm_reloc_hsh contains no entries, so this function can only
2205 succeed if there is no () after the word. Returns -1 on error,
2206 BFD_RELOC_UNUSED if there wasn't any suffix. */
2207
2208 static int
2209 parse_reloc (char **str)
2210 {
2211 struct reloc_entry *r;
2212 char *p, *q;
2213
2214 if (**str != '(')
2215 return BFD_RELOC_UNUSED;
2216
2217 p = *str + 1;
2218 q = p;
2219
2220 while (*q && *q != ')' && *q != ',')
2221 q++;
2222 if (*q != ')')
2223 return -1;
2224
2225 if ((r = (struct reloc_entry *)
2226 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2227 return -1;
2228
2229 *str = q + 1;
2230 return r->reloc;
2231 }
2232
2233 /* Directives: register aliases. */
2234
2235 static struct reg_entry *
2236 insert_reg_alias (char *str, unsigned number, int type)
2237 {
2238 struct reg_entry *new_reg;
2239 const char *name;
2240
2241 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2242 {
2243 if (new_reg->builtin)
2244 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2245
2246 /* Only warn about a redefinition if it's not defined as the
2247 same register. */
2248 else if (new_reg->number != number || new_reg->type != type)
2249 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2250
2251 return NULL;
2252 }
2253
2254 name = xstrdup (str);
2255 new_reg = XNEW (struct reg_entry);
2256
2257 new_reg->name = name;
2258 new_reg->number = number;
2259 new_reg->type = type;
2260 new_reg->builtin = FALSE;
2261 new_reg->neon = NULL;
2262
2263 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2264 abort ();
2265
2266 return new_reg;
2267 }
2268
2269 static void
2270 insert_neon_reg_alias (char *str, int number, int type,
2271 struct neon_typed_alias *atype)
2272 {
2273 struct reg_entry *reg = insert_reg_alias (str, number, type);
2274
2275 if (!reg)
2276 {
2277 first_error (_("attempt to redefine typed alias"));
2278 return;
2279 }
2280
2281 if (atype)
2282 {
2283 reg->neon = XNEW (struct neon_typed_alias);
2284 *reg->neon = *atype;
2285 }
2286 }
2287
2288 /* Look for the .req directive. This is of the form:
2289
2290 new_register_name .req existing_register_name
2291
2292 If we find one, or if it looks sufficiently like one that we want to
2293 handle any error here, return TRUE. Otherwise return FALSE. */
2294
2295 static bfd_boolean
2296 create_register_alias (char * newname, char *p)
2297 {
2298 struct reg_entry *old;
2299 char *oldname, *nbuf;
2300 size_t nlen;
2301
2302 /* The input scrubber ensures that whitespace after the mnemonic is
2303 collapsed to single spaces. */
2304 oldname = p;
2305 if (strncmp (oldname, " .req ", 6) != 0)
2306 return FALSE;
2307
2308 oldname += 6;
2309 if (*oldname == '\0')
2310 return FALSE;
2311
2312 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2313 if (!old)
2314 {
2315 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2316 return TRUE;
2317 }
2318
2319 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2320 the desired alias name, and p points to its end. If not, then
2321 the desired alias name is in the global original_case_string. */
2322 #ifdef TC_CASE_SENSITIVE
2323 nlen = p - newname;
2324 #else
2325 newname = original_case_string;
2326 nlen = strlen (newname);
2327 #endif
2328
2329 nbuf = xmemdup0 (newname, nlen);
2330
2331 /* Create aliases under the new name as stated; an all-lowercase
2332 version of the new name; and an all-uppercase version of the new
2333 name. */
2334 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2335 {
2336 for (p = nbuf; *p; p++)
2337 *p = TOUPPER (*p);
2338
2339 if (strncmp (nbuf, newname, nlen))
2340 {
2341 /* If this attempt to create an additional alias fails, do not bother
2342 trying to create the all-lower case alias. We will fail and issue
2343 a second, duplicate error message. This situation arises when the
2344 programmer does something like:
2345 foo .req r0
2346 Foo .req r1
2347 The second .req creates the "Foo" alias but then fails to create
2348 the artificial FOO alias because it has already been created by the
2349 first .req. */
2350 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2351 {
2352 free (nbuf);
2353 return TRUE;
2354 }
2355 }
2356
2357 for (p = nbuf; *p; p++)
2358 *p = TOLOWER (*p);
2359
2360 if (strncmp (nbuf, newname, nlen))
2361 insert_reg_alias (nbuf, old->number, old->type);
2362 }
2363
2364 free (nbuf);
2365 return TRUE;
2366 }
2367
2368 /* Create a Neon typed/indexed register alias using directives, e.g.:
2369 X .dn d5.s32[1]
2370 Y .qn 6.s16
2371 Z .dn d7
2372 T .dn Z[0]
2373 These typed registers can be used instead of the types specified after the
2374 Neon mnemonic, so long as all operands given have types. Types can also be
2375 specified directly, e.g.:
2376 vadd d0.s32, d1.s32, d2.s32 */
2377
2378 static bfd_boolean
2379 create_neon_reg_alias (char *newname, char *p)
2380 {
2381 enum arm_reg_type basetype;
2382 struct reg_entry *basereg;
2383 struct reg_entry mybasereg;
2384 struct neon_type ntype;
2385 struct neon_typed_alias typeinfo;
2386 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2387 int namelen;
2388
2389 typeinfo.defined = 0;
2390 typeinfo.eltype.type = NT_invtype;
2391 typeinfo.eltype.size = -1;
2392 typeinfo.index = -1;
2393
2394 nameend = p;
2395
2396 if (strncmp (p, " .dn ", 5) == 0)
2397 basetype = REG_TYPE_VFD;
2398 else if (strncmp (p, " .qn ", 5) == 0)
2399 basetype = REG_TYPE_NQ;
2400 else
2401 return FALSE;
2402
2403 p += 5;
2404
2405 if (*p == '\0')
2406 return FALSE;
2407
2408 basereg = arm_reg_parse_multi (&p);
2409
2410 if (basereg && basereg->type != basetype)
2411 {
2412 as_bad (_("bad type for register"));
2413 return FALSE;
2414 }
2415
2416 if (basereg == NULL)
2417 {
2418 expressionS exp;
2419 /* Try parsing as an integer. */
2420 my_get_expression (&exp, &p, GE_NO_PREFIX);
2421 if (exp.X_op != O_constant)
2422 {
2423 as_bad (_("expression must be constant"));
2424 return FALSE;
2425 }
2426 basereg = &mybasereg;
2427 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2428 : exp.X_add_number;
2429 basereg->neon = 0;
2430 }
2431
2432 if (basereg->neon)
2433 typeinfo = *basereg->neon;
2434
2435 if (parse_neon_type (&ntype, &p) == SUCCESS)
2436 {
2437 /* We got a type. */
2438 if (typeinfo.defined & NTA_HASTYPE)
2439 {
2440 as_bad (_("can't redefine the type of a register alias"));
2441 return FALSE;
2442 }
2443
2444 typeinfo.defined |= NTA_HASTYPE;
2445 if (ntype.elems != 1)
2446 {
2447 as_bad (_("you must specify a single type only"));
2448 return FALSE;
2449 }
2450 typeinfo.eltype = ntype.el[0];
2451 }
2452
2453 if (skip_past_char (&p, '[') == SUCCESS)
2454 {
2455 expressionS exp;
2456 /* We got a scalar index. */
2457
2458 if (typeinfo.defined & NTA_HASINDEX)
2459 {
2460 as_bad (_("can't redefine the index of a scalar alias"));
2461 return FALSE;
2462 }
2463
2464 my_get_expression (&exp, &p, GE_NO_PREFIX);
2465
2466 if (exp.X_op != O_constant)
2467 {
2468 as_bad (_("scalar index must be constant"));
2469 return FALSE;
2470 }
2471
2472 typeinfo.defined |= NTA_HASINDEX;
2473 typeinfo.index = exp.X_add_number;
2474
2475 if (skip_past_char (&p, ']') == FAIL)
2476 {
2477 as_bad (_("expecting ]"));
2478 return FALSE;
2479 }
2480 }
2481
2482 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2483 the desired alias name, and p points to its end. If not, then
2484 the desired alias name is in the global original_case_string. */
2485 #ifdef TC_CASE_SENSITIVE
2486 namelen = nameend - newname;
2487 #else
2488 newname = original_case_string;
2489 namelen = strlen (newname);
2490 #endif
2491
2492 namebuf = xmemdup0 (newname, namelen);
2493
2494 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2495 typeinfo.defined != 0 ? &typeinfo : NULL);
2496
2497 /* Insert name in all uppercase. */
2498 for (p = namebuf; *p; p++)
2499 *p = TOUPPER (*p);
2500
2501 if (strncmp (namebuf, newname, namelen))
2502 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2503 typeinfo.defined != 0 ? &typeinfo : NULL);
2504
2505 /* Insert name in all lowercase. */
2506 for (p = namebuf; *p; p++)
2507 *p = TOLOWER (*p);
2508
2509 if (strncmp (namebuf, newname, namelen))
2510 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2511 typeinfo.defined != 0 ? &typeinfo : NULL);
2512
2513 free (namebuf);
2514 return TRUE;
2515 }
2516
2517 /* Should never be called, as .req goes between the alias and the
2518 register name, not at the beginning of the line. */
2519
2520 static void
2521 s_req (int a ATTRIBUTE_UNUSED)
2522 {
2523 as_bad (_("invalid syntax for .req directive"));
2524 }
2525
2526 static void
2527 s_dn (int a ATTRIBUTE_UNUSED)
2528 {
2529 as_bad (_("invalid syntax for .dn directive"));
2530 }
2531
2532 static void
2533 s_qn (int a ATTRIBUTE_UNUSED)
2534 {
2535 as_bad (_("invalid syntax for .qn directive"));
2536 }
2537
2538 /* The .unreq directive deletes an alias which was previously defined
2539 by .req. For example:
2540
2541 my_alias .req r11
2542 .unreq my_alias */
2543
2544 static void
2545 s_unreq (int a ATTRIBUTE_UNUSED)
2546 {
2547 char * name;
2548 char saved_char;
2549
2550 name = input_line_pointer;
2551
2552 while (*input_line_pointer != 0
2553 && *input_line_pointer != ' '
2554 && *input_line_pointer != '\n')
2555 ++input_line_pointer;
2556
2557 saved_char = *input_line_pointer;
2558 *input_line_pointer = 0;
2559
2560 if (!*name)
2561 as_bad (_("invalid syntax for .unreq directive"));
2562 else
2563 {
2564 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2565 name);
2566
2567 if (!reg)
2568 as_bad (_("unknown register alias '%s'"), name);
2569 else if (reg->builtin)
2570 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2571 name);
2572 else
2573 {
2574 char * p;
2575 char * nbuf;
2576
2577 hash_delete (arm_reg_hsh, name, FALSE);
2578 free ((char *) reg->name);
2579 if (reg->neon)
2580 free (reg->neon);
2581 free (reg);
2582
2583 /* Also locate the all upper case and all lower case versions.
2584 Do not complain if we cannot find one or the other as it
2585 was probably deleted above. */
2586
2587 nbuf = strdup (name);
2588 for (p = nbuf; *p; p++)
2589 *p = TOUPPER (*p);
2590 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2591 if (reg)
2592 {
2593 hash_delete (arm_reg_hsh, nbuf, FALSE);
2594 free ((char *) reg->name);
2595 if (reg->neon)
2596 free (reg->neon);
2597 free (reg);
2598 }
2599
2600 for (p = nbuf; *p; p++)
2601 *p = TOLOWER (*p);
2602 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2603 if (reg)
2604 {
2605 hash_delete (arm_reg_hsh, nbuf, FALSE);
2606 free ((char *) reg->name);
2607 if (reg->neon)
2608 free (reg->neon);
2609 free (reg);
2610 }
2611
2612 free (nbuf);
2613 }
2614 }
2615
2616 *input_line_pointer = saved_char;
2617 demand_empty_rest_of_line ();
2618 }
2619
2620 /* Directives: Instruction set selection. */
2621
2622 #ifdef OBJ_ELF
2623 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2624 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2625 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2626 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2627
2628 /* Create a new mapping symbol for the transition to STATE. */
2629
2630 static void
2631 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2632 {
2633 symbolS * symbolP;
2634 const char * symname;
2635 int type;
2636
2637 switch (state)
2638 {
2639 case MAP_DATA:
2640 symname = "$d";
2641 type = BSF_NO_FLAGS;
2642 break;
2643 case MAP_ARM:
2644 symname = "$a";
2645 type = BSF_NO_FLAGS;
2646 break;
2647 case MAP_THUMB:
2648 symname = "$t";
2649 type = BSF_NO_FLAGS;
2650 break;
2651 default:
2652 abort ();
2653 }
2654
2655 symbolP = symbol_new (symname, now_seg, value, frag);
2656 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2657
2658 switch (state)
2659 {
2660 case MAP_ARM:
2661 THUMB_SET_FUNC (symbolP, 0);
2662 ARM_SET_THUMB (symbolP, 0);
2663 ARM_SET_INTERWORK (symbolP, support_interwork);
2664 break;
2665
2666 case MAP_THUMB:
2667 THUMB_SET_FUNC (symbolP, 1);
2668 ARM_SET_THUMB (symbolP, 1);
2669 ARM_SET_INTERWORK (symbolP, support_interwork);
2670 break;
2671
2672 case MAP_DATA:
2673 default:
2674 break;
2675 }
2676
2677 /* Save the mapping symbols for future reference. Also check that
2678 we do not place two mapping symbols at the same offset within a
2679 frag. We'll handle overlap between frags in
2680 check_mapping_symbols.
2681
2682 If .fill or other data filling directive generates zero sized data,
2683 the mapping symbol for the following code will have the same value
2684 as the one generated for the data filling directive. In this case,
2685 we replace the old symbol with the new one at the same address. */
2686 if (value == 0)
2687 {
2688 if (frag->tc_frag_data.first_map != NULL)
2689 {
2690 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2691 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2692 }
2693 frag->tc_frag_data.first_map = symbolP;
2694 }
2695 if (frag->tc_frag_data.last_map != NULL)
2696 {
2697 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2698 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2699 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2700 }
2701 frag->tc_frag_data.last_map = symbolP;
2702 }
2703
2704 /* We must sometimes convert a region marked as code to data during
2705 code alignment, if an odd number of bytes have to be padded. The
2706 code mapping symbol is pushed to an aligned address. */
2707
2708 static void
2709 insert_data_mapping_symbol (enum mstate state,
2710 valueT value, fragS *frag, offsetT bytes)
2711 {
2712 /* If there was already a mapping symbol, remove it. */
2713 if (frag->tc_frag_data.last_map != NULL
2714 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2715 {
2716 symbolS *symp = frag->tc_frag_data.last_map;
2717
2718 if (value == 0)
2719 {
2720 know (frag->tc_frag_data.first_map == symp);
2721 frag->tc_frag_data.first_map = NULL;
2722 }
2723 frag->tc_frag_data.last_map = NULL;
2724 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2725 }
2726
2727 make_mapping_symbol (MAP_DATA, value, frag);
2728 make_mapping_symbol (state, value + bytes, frag);
2729 }
2730
2731 static void mapping_state_2 (enum mstate state, int max_chars);
2732
2733 /* Set the mapping state to STATE. Only call this when about to
2734 emit some STATE bytes to the file. */
2735
2736 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2737 void
2738 mapping_state (enum mstate state)
2739 {
2740 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2741
2742 if (mapstate == state)
2743 /* The mapping symbol has already been emitted.
2744 There is nothing else to do. */
2745 return;
2746
2747 if (state == MAP_ARM || state == MAP_THUMB)
2748 /* PR gas/12931
2749 All ARM instructions require 4-byte alignment.
2750 (Almost) all Thumb instructions require 2-byte alignment.
2751
2752 When emitting instructions into any section, mark the section
2753 appropriately.
2754
2755 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2756 but themselves require 2-byte alignment; this applies to some
2757 PC- relative forms. However, these cases will involve implicit
2758 literal pool generation or an explicit .align >=2, both of
2759 which will cause the section to me marked with sufficient
2760 alignment. Thus, we don't handle those cases here. */
2761 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2762
2763 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2764 /* This case will be evaluated later. */
2765 return;
2766
2767 mapping_state_2 (state, 0);
2768 }
2769
2770 /* Same as mapping_state, but MAX_CHARS bytes have already been
2771 allocated. Put the mapping symbol that far back. */
2772
2773 static void
2774 mapping_state_2 (enum mstate state, int max_chars)
2775 {
2776 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2777
2778 if (!SEG_NORMAL (now_seg))
2779 return;
2780
2781 if (mapstate == state)
2782 /* The mapping symbol has already been emitted.
2783 There is nothing else to do. */
2784 return;
2785
2786 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2787 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2788 {
2789 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2790 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2791
2792 if (add_symbol)
2793 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2794 }
2795
2796 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2797 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2798 }
2799 #undef TRANSITION
2800 #else
2801 #define mapping_state(x) ((void)0)
2802 #define mapping_state_2(x, y) ((void)0)
2803 #endif
2804
2805 /* Find the real, Thumb encoded start of a Thumb function. */
2806
2807 #ifdef OBJ_COFF
2808 static symbolS *
2809 find_real_start (symbolS * symbolP)
2810 {
2811 char * real_start;
2812 const char * name = S_GET_NAME (symbolP);
2813 symbolS * new_target;
2814
2815 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2816 #define STUB_NAME ".real_start_of"
2817
2818 if (name == NULL)
2819 abort ();
2820
2821 /* The compiler may generate BL instructions to local labels because
2822 it needs to perform a branch to a far away location. These labels
2823 do not have a corresponding ".real_start_of" label. We check
2824 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2825 the ".real_start_of" convention for nonlocal branches. */
2826 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2827 return symbolP;
2828
2829 real_start = concat (STUB_NAME, name, NULL);
2830 new_target = symbol_find (real_start);
2831 free (real_start);
2832
2833 if (new_target == NULL)
2834 {
2835 as_warn (_("Failed to find real start of function: %s\n"), name);
2836 new_target = symbolP;
2837 }
2838
2839 return new_target;
2840 }
2841 #endif
2842
2843 static void
2844 opcode_select (int width)
2845 {
2846 switch (width)
2847 {
2848 case 16:
2849 if (! thumb_mode)
2850 {
2851 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2852 as_bad (_("selected processor does not support THUMB opcodes"));
2853
2854 thumb_mode = 1;
2855 /* No need to force the alignment, since we will have been
2856 coming from ARM mode, which is word-aligned. */
2857 record_alignment (now_seg, 1);
2858 }
2859 break;
2860
2861 case 32:
2862 if (thumb_mode)
2863 {
2864 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2865 as_bad (_("selected processor does not support ARM opcodes"));
2866
2867 thumb_mode = 0;
2868
2869 if (!need_pass_2)
2870 frag_align (2, 0, 0);
2871
2872 record_alignment (now_seg, 1);
2873 }
2874 break;
2875
2876 default:
2877 as_bad (_("invalid instruction size selected (%d)"), width);
2878 }
2879 }
2880
2881 static void
2882 s_arm (int ignore ATTRIBUTE_UNUSED)
2883 {
2884 opcode_select (32);
2885 demand_empty_rest_of_line ();
2886 }
2887
2888 static void
2889 s_thumb (int ignore ATTRIBUTE_UNUSED)
2890 {
2891 opcode_select (16);
2892 demand_empty_rest_of_line ();
2893 }
2894
2895 static void
2896 s_code (int unused ATTRIBUTE_UNUSED)
2897 {
2898 int temp;
2899
2900 temp = get_absolute_expression ();
2901 switch (temp)
2902 {
2903 case 16:
2904 case 32:
2905 opcode_select (temp);
2906 break;
2907
2908 default:
2909 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2910 }
2911 }
2912
2913 static void
2914 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2915 {
2916 /* If we are not already in thumb mode go into it, EVEN if
2917 the target processor does not support thumb instructions.
2918 This is used by gcc/config/arm/lib1funcs.asm for example
2919 to compile interworking support functions even if the
2920 target processor should not support interworking. */
2921 if (! thumb_mode)
2922 {
2923 thumb_mode = 2;
2924 record_alignment (now_seg, 1);
2925 }
2926
2927 demand_empty_rest_of_line ();
2928 }
2929
2930 static void
2931 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2932 {
2933 s_thumb (0);
2934
2935 /* The following label is the name/address of the start of a Thumb function.
2936 We need to know this for the interworking support. */
2937 label_is_thumb_function_name = TRUE;
2938 }
2939
2940 /* Perform a .set directive, but also mark the alias as
2941 being a thumb function. */
2942
2943 static void
2944 s_thumb_set (int equiv)
2945 {
2946 /* XXX the following is a duplicate of the code for s_set() in read.c
2947 We cannot just call that code as we need to get at the symbol that
2948 is created. */
2949 char * name;
2950 char delim;
2951 char * end_name;
2952 symbolS * symbolP;
2953
2954 /* Especial apologies for the random logic:
2955 This just grew, and could be parsed much more simply!
2956 Dean - in haste. */
2957 delim = get_symbol_name (& name);
2958 end_name = input_line_pointer;
2959 (void) restore_line_pointer (delim);
2960
2961 if (*input_line_pointer != ',')
2962 {
2963 *end_name = 0;
2964 as_bad (_("expected comma after name \"%s\""), name);
2965 *end_name = delim;
2966 ignore_rest_of_line ();
2967 return;
2968 }
2969
2970 input_line_pointer++;
2971 *end_name = 0;
2972
2973 if (name[0] == '.' && name[1] == '\0')
2974 {
2975 /* XXX - this should not happen to .thumb_set. */
2976 abort ();
2977 }
2978
2979 if ((symbolP = symbol_find (name)) == NULL
2980 && (symbolP = md_undefined_symbol (name)) == NULL)
2981 {
2982 #ifndef NO_LISTING
2983 /* When doing symbol listings, play games with dummy fragments living
2984 outside the normal fragment chain to record the file and line info
2985 for this symbol. */
2986 if (listing & LISTING_SYMBOLS)
2987 {
2988 extern struct list_info_struct * listing_tail;
2989 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2990
2991 memset (dummy_frag, 0, sizeof (fragS));
2992 dummy_frag->fr_type = rs_fill;
2993 dummy_frag->line = listing_tail;
2994 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2995 dummy_frag->fr_symbol = symbolP;
2996 }
2997 else
2998 #endif
2999 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
3000
3001 #ifdef OBJ_COFF
3002 /* "set" symbols are local unless otherwise specified. */
3003 SF_SET_LOCAL (symbolP);
3004 #endif /* OBJ_COFF */
3005 } /* Make a new symbol. */
3006
3007 symbol_table_insert (symbolP);
3008
3009 * end_name = delim;
3010
3011 if (equiv
3012 && S_IS_DEFINED (symbolP)
3013 && S_GET_SEGMENT (symbolP) != reg_section)
3014 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3015
3016 pseudo_set (symbolP);
3017
3018 demand_empty_rest_of_line ();
3019
3020 /* XXX Now we come to the Thumb specific bit of code. */
3021
3022 THUMB_SET_FUNC (symbolP, 1);
3023 ARM_SET_THUMB (symbolP, 1);
3024 #if defined OBJ_ELF || defined OBJ_COFF
3025 ARM_SET_INTERWORK (symbolP, support_interwork);
3026 #endif
3027 }
3028
3029 /* Directives: Mode selection. */
3030
3031 /* .syntax [unified|divided] - choose the new unified syntax
3032 (same for Arm and Thumb encoding, modulo slight differences in what
3033 can be represented) or the old divergent syntax for each mode. */
3034 static void
3035 s_syntax (int unused ATTRIBUTE_UNUSED)
3036 {
3037 char *name, delim;
3038
3039 delim = get_symbol_name (& name);
3040
3041 if (!strcasecmp (name, "unified"))
3042 unified_syntax = TRUE;
3043 else if (!strcasecmp (name, "divided"))
3044 unified_syntax = FALSE;
3045 else
3046 {
3047 as_bad (_("unrecognized syntax mode \"%s\""), name);
3048 return;
3049 }
3050 (void) restore_line_pointer (delim);
3051 demand_empty_rest_of_line ();
3052 }
3053
3054 /* Directives: sectioning and alignment. */
3055
3056 static void
3057 s_bss (int ignore ATTRIBUTE_UNUSED)
3058 {
3059 /* We don't support putting frags in the BSS segment, we fake it by
3060 marking in_bss, then looking at s_skip for clues. */
3061 subseg_set (bss_section, 0);
3062 demand_empty_rest_of_line ();
3063
3064 #ifdef md_elf_section_change_hook
3065 md_elf_section_change_hook ();
3066 #endif
3067 }
3068
3069 static void
3070 s_even (int ignore ATTRIBUTE_UNUSED)
3071 {
3072 /* Never make frag if expect extra pass. */
3073 if (!need_pass_2)
3074 frag_align (1, 0, 0);
3075
3076 record_alignment (now_seg, 1);
3077
3078 demand_empty_rest_of_line ();
3079 }
3080
3081 /* Directives: CodeComposer Studio. */
3082
3083 /* .ref (for CodeComposer Studio syntax only). */
3084 static void
3085 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3086 {
3087 if (codecomposer_syntax)
3088 ignore_rest_of_line ();
3089 else
3090 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3091 }
3092
3093 /* If name is not NULL, then it is used for marking the beginning of a
3094 function, whereas if it is NULL then it means the function end. */
3095 static void
3096 asmfunc_debug (const char * name)
3097 {
3098 static const char * last_name = NULL;
3099
3100 if (name != NULL)
3101 {
3102 gas_assert (last_name == NULL);
3103 last_name = name;
3104
3105 if (debug_type == DEBUG_STABS)
3106 stabs_generate_asm_func (name, name);
3107 }
3108 else
3109 {
3110 gas_assert (last_name != NULL);
3111
3112 if (debug_type == DEBUG_STABS)
3113 stabs_generate_asm_endfunc (last_name, last_name);
3114
3115 last_name = NULL;
3116 }
3117 }
3118
3119 static void
3120 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3121 {
3122 if (codecomposer_syntax)
3123 {
3124 switch (asmfunc_state)
3125 {
3126 case OUTSIDE_ASMFUNC:
3127 asmfunc_state = WAITING_ASMFUNC_NAME;
3128 break;
3129
3130 case WAITING_ASMFUNC_NAME:
3131 as_bad (_(".asmfunc repeated."));
3132 break;
3133
3134 case WAITING_ENDASMFUNC:
3135 as_bad (_(".asmfunc without function."));
3136 break;
3137 }
3138 demand_empty_rest_of_line ();
3139 }
3140 else
3141 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3142 }
3143
3144 static void
3145 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3146 {
3147 if (codecomposer_syntax)
3148 {
3149 switch (asmfunc_state)
3150 {
3151 case OUTSIDE_ASMFUNC:
3152 as_bad (_(".endasmfunc without a .asmfunc."));
3153 break;
3154
3155 case WAITING_ASMFUNC_NAME:
3156 as_bad (_(".endasmfunc without function."));
3157 break;
3158
3159 case WAITING_ENDASMFUNC:
3160 asmfunc_state = OUTSIDE_ASMFUNC;
3161 asmfunc_debug (NULL);
3162 break;
3163 }
3164 demand_empty_rest_of_line ();
3165 }
3166 else
3167 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3168 }
3169
3170 static void
3171 s_ccs_def (int name)
3172 {
3173 if (codecomposer_syntax)
3174 s_globl (name);
3175 else
3176 as_bad (_(".def pseudo-op only available with -mccs flag."));
3177 }
3178
3179 /* Directives: Literal pools. */
3180
3181 static literal_pool *
3182 find_literal_pool (void)
3183 {
3184 literal_pool * pool;
3185
3186 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3187 {
3188 if (pool->section == now_seg
3189 && pool->sub_section == now_subseg)
3190 break;
3191 }
3192
3193 return pool;
3194 }
3195
3196 static literal_pool *
3197 find_or_make_literal_pool (void)
3198 {
3199 /* Next literal pool ID number. */
3200 static unsigned int latest_pool_num = 1;
3201 literal_pool * pool;
3202
3203 pool = find_literal_pool ();
3204
3205 if (pool == NULL)
3206 {
3207 /* Create a new pool. */
3208 pool = XNEW (literal_pool);
3209 if (! pool)
3210 return NULL;
3211
3212 pool->next_free_entry = 0;
3213 pool->section = now_seg;
3214 pool->sub_section = now_subseg;
3215 pool->next = list_of_pools;
3216 pool->symbol = NULL;
3217 pool->alignment = 2;
3218
3219 /* Add it to the list. */
3220 list_of_pools = pool;
3221 }
3222
3223 /* New pools, and emptied pools, will have a NULL symbol. */
3224 if (pool->symbol == NULL)
3225 {
3226 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3227 (valueT) 0, &zero_address_frag);
3228 pool->id = latest_pool_num ++;
3229 }
3230
3231 /* Done. */
3232 return pool;
3233 }
3234
3235 /* Add the literal in the global 'inst'
3236 structure to the relevant literal pool. */
3237
3238 static int
3239 add_to_lit_pool (unsigned int nbytes)
3240 {
3241 #define PADDING_SLOT 0x1
3242 #define LIT_ENTRY_SIZE_MASK 0xFF
3243 literal_pool * pool;
3244 unsigned int entry, pool_size = 0;
3245 bfd_boolean padding_slot_p = FALSE;
3246 unsigned imm1 = 0;
3247 unsigned imm2 = 0;
3248
3249 if (nbytes == 8)
3250 {
3251 imm1 = inst.operands[1].imm;
3252 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3253 : inst.relocs[0].exp.X_unsigned ? 0
3254 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
3255 if (target_big_endian)
3256 {
3257 imm1 = imm2;
3258 imm2 = inst.operands[1].imm;
3259 }
3260 }
3261
3262 pool = find_or_make_literal_pool ();
3263
3264 /* Check if this literal value is already in the pool. */
3265 for (entry = 0; entry < pool->next_free_entry; entry ++)
3266 {
3267 if (nbytes == 4)
3268 {
3269 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3270 && (inst.relocs[0].exp.X_op == O_constant)
3271 && (pool->literals[entry].X_add_number
3272 == inst.relocs[0].exp.X_add_number)
3273 && (pool->literals[entry].X_md == nbytes)
3274 && (pool->literals[entry].X_unsigned
3275 == inst.relocs[0].exp.X_unsigned))
3276 break;
3277
3278 if ((pool->literals[entry].X_op == inst.relocs[0].exp.X_op)
3279 && (inst.relocs[0].exp.X_op == O_symbol)
3280 && (pool->literals[entry].X_add_number
3281 == inst.relocs[0].exp.X_add_number)
3282 && (pool->literals[entry].X_add_symbol
3283 == inst.relocs[0].exp.X_add_symbol)
3284 && (pool->literals[entry].X_op_symbol
3285 == inst.relocs[0].exp.X_op_symbol)
3286 && (pool->literals[entry].X_md == nbytes))
3287 break;
3288 }
3289 else if ((nbytes == 8)
3290 && !(pool_size & 0x7)
3291 && ((entry + 1) != pool->next_free_entry)
3292 && (pool->literals[entry].X_op == O_constant)
3293 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3294 && (pool->literals[entry].X_unsigned
3295 == inst.relocs[0].exp.X_unsigned)
3296 && (pool->literals[entry + 1].X_op == O_constant)
3297 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3298 && (pool->literals[entry + 1].X_unsigned
3299 == inst.relocs[0].exp.X_unsigned))
3300 break;
3301
3302 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3303 if (padding_slot_p && (nbytes == 4))
3304 break;
3305
3306 pool_size += 4;
3307 }
3308
3309 /* Do we need to create a new entry? */
3310 if (entry == pool->next_free_entry)
3311 {
3312 if (entry >= MAX_LITERAL_POOL_SIZE)
3313 {
3314 inst.error = _("literal pool overflow");
3315 return FAIL;
3316 }
3317
3318 if (nbytes == 8)
3319 {
3320 /* For 8-byte entries, we align to an 8-byte boundary,
3321 and split it into two 4-byte entries, because on 32-bit
3322 host, 8-byte constants are treated as big num, thus
3323 saved in "generic_bignum" which will be overwritten
3324 by later assignments.
3325
3326 We also need to make sure there is enough space for
3327 the split.
3328
3329 We also check to make sure the literal operand is a
3330 constant number. */
3331 if (!(inst.relocs[0].exp.X_op == O_constant
3332 || inst.relocs[0].exp.X_op == O_big))
3333 {
3334 inst.error = _("invalid type for literal pool");
3335 return FAIL;
3336 }
3337 else if (pool_size & 0x7)
3338 {
3339 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3340 {
3341 inst.error = _("literal pool overflow");
3342 return FAIL;
3343 }
3344
3345 pool->literals[entry] = inst.relocs[0].exp;
3346 pool->literals[entry].X_op = O_constant;
3347 pool->literals[entry].X_add_number = 0;
3348 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3349 pool->next_free_entry += 1;
3350 pool_size += 4;
3351 }
3352 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3353 {
3354 inst.error = _("literal pool overflow");
3355 return FAIL;
3356 }
3357
3358 pool->literals[entry] = inst.relocs[0].exp;
3359 pool->literals[entry].X_op = O_constant;
3360 pool->literals[entry].X_add_number = imm1;
3361 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3362 pool->literals[entry++].X_md = 4;
3363 pool->literals[entry] = inst.relocs[0].exp;
3364 pool->literals[entry].X_op = O_constant;
3365 pool->literals[entry].X_add_number = imm2;
3366 pool->literals[entry].X_unsigned = inst.relocs[0].exp.X_unsigned;
3367 pool->literals[entry].X_md = 4;
3368 pool->alignment = 3;
3369 pool->next_free_entry += 1;
3370 }
3371 else
3372 {
3373 pool->literals[entry] = inst.relocs[0].exp;
3374 pool->literals[entry].X_md = 4;
3375 }
3376
3377 #ifdef OBJ_ELF
3378 /* PR ld/12974: Record the location of the first source line to reference
3379 this entry in the literal pool. If it turns out during linking that the
3380 symbol does not exist we will be able to give an accurate line number for
3381 the (first use of the) missing reference. */
3382 if (debug_type == DEBUG_DWARF2)
3383 dwarf2_where (pool->locs + entry);
3384 #endif
3385 pool->next_free_entry += 1;
3386 }
3387 else if (padding_slot_p)
3388 {
3389 pool->literals[entry] = inst.relocs[0].exp;
3390 pool->literals[entry].X_md = nbytes;
3391 }
3392
3393 inst.relocs[0].exp.X_op = O_symbol;
3394 inst.relocs[0].exp.X_add_number = pool_size;
3395 inst.relocs[0].exp.X_add_symbol = pool->symbol;
3396
3397 return SUCCESS;
3398 }
3399
3400 bfd_boolean
3401 tc_start_label_without_colon (void)
3402 {
3403 bfd_boolean ret = TRUE;
3404
3405 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3406 {
3407 const char *label = input_line_pointer;
3408
3409 while (!is_end_of_line[(int) label[-1]])
3410 --label;
3411
3412 if (*label == '.')
3413 {
3414 as_bad (_("Invalid label '%s'"), label);
3415 ret = FALSE;
3416 }
3417
3418 asmfunc_debug (label);
3419
3420 asmfunc_state = WAITING_ENDASMFUNC;
3421 }
3422
3423 return ret;
3424 }
3425
3426 /* Can't use symbol_new here, so have to create a symbol and then at
3427 a later date assign it a value. That's what these functions do. */
3428
3429 static void
3430 symbol_locate (symbolS * symbolP,
3431 const char * name, /* It is copied, the caller can modify. */
3432 segT segment, /* Segment identifier (SEG_<something>). */
3433 valueT valu, /* Symbol value. */
3434 fragS * frag) /* Associated fragment. */
3435 {
3436 size_t name_length;
3437 char * preserved_copy_of_name;
3438
3439 name_length = strlen (name) + 1; /* +1 for \0. */
3440 obstack_grow (&notes, name, name_length);
3441 preserved_copy_of_name = (char *) obstack_finish (&notes);
3442
3443 #ifdef tc_canonicalize_symbol_name
3444 preserved_copy_of_name =
3445 tc_canonicalize_symbol_name (preserved_copy_of_name);
3446 #endif
3447
3448 S_SET_NAME (symbolP, preserved_copy_of_name);
3449
3450 S_SET_SEGMENT (symbolP, segment);
3451 S_SET_VALUE (symbolP, valu);
3452 symbol_clear_list_pointers (symbolP);
3453
3454 symbol_set_frag (symbolP, frag);
3455
3456 /* Link to end of symbol chain. */
3457 {
3458 extern int symbol_table_frozen;
3459
3460 if (symbol_table_frozen)
3461 abort ();
3462 }
3463
3464 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3465
3466 obj_symbol_new_hook (symbolP);
3467
3468 #ifdef tc_symbol_new_hook
3469 tc_symbol_new_hook (symbolP);
3470 #endif
3471
3472 #ifdef DEBUG_SYMS
3473 verify_symbol_chain (symbol_rootP, symbol_lastP);
3474 #endif /* DEBUG_SYMS */
3475 }
3476
3477 static void
3478 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3479 {
3480 unsigned int entry;
3481 literal_pool * pool;
3482 char sym_name[20];
3483
3484 pool = find_literal_pool ();
3485 if (pool == NULL
3486 || pool->symbol == NULL
3487 || pool->next_free_entry == 0)
3488 return;
3489
3490 /* Align pool as you have word accesses.
3491 Only make a frag if we have to. */
3492 if (!need_pass_2)
3493 frag_align (pool->alignment, 0, 0);
3494
3495 record_alignment (now_seg, 2);
3496
3497 #ifdef OBJ_ELF
3498 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3499 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3500 #endif
3501 sprintf (sym_name, "$$lit_\002%x", pool->id);
3502
3503 symbol_locate (pool->symbol, sym_name, now_seg,
3504 (valueT) frag_now_fix (), frag_now);
3505 symbol_table_insert (pool->symbol);
3506
3507 ARM_SET_THUMB (pool->symbol, thumb_mode);
3508
3509 #if defined OBJ_COFF || defined OBJ_ELF
3510 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3511 #endif
3512
3513 for (entry = 0; entry < pool->next_free_entry; entry ++)
3514 {
3515 #ifdef OBJ_ELF
3516 if (debug_type == DEBUG_DWARF2)
3517 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3518 #endif
3519 /* First output the expression in the instruction to the pool. */
3520 emit_expr (&(pool->literals[entry]),
3521 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3522 }
3523
3524 /* Mark the pool as empty. */
3525 pool->next_free_entry = 0;
3526 pool->symbol = NULL;
3527 }
3528
3529 #ifdef OBJ_ELF
3530 /* Forward declarations for functions below, in the MD interface
3531 section. */
3532 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3533 static valueT create_unwind_entry (int);
3534 static void start_unwind_section (const segT, int);
3535 static void add_unwind_opcode (valueT, int);
3536 static void flush_pending_unwind (void);
3537
3538 /* Directives: Data. */
3539
3540 static void
3541 s_arm_elf_cons (int nbytes)
3542 {
3543 expressionS exp;
3544
3545 #ifdef md_flush_pending_output
3546 md_flush_pending_output ();
3547 #endif
3548
3549 if (is_it_end_of_statement ())
3550 {
3551 demand_empty_rest_of_line ();
3552 return;
3553 }
3554
3555 #ifdef md_cons_align
3556 md_cons_align (nbytes);
3557 #endif
3558
3559 mapping_state (MAP_DATA);
3560 do
3561 {
3562 int reloc;
3563 char *base = input_line_pointer;
3564
3565 expression (& exp);
3566
3567 if (exp.X_op != O_symbol)
3568 emit_expr (&exp, (unsigned int) nbytes);
3569 else
3570 {
3571 char *before_reloc = input_line_pointer;
3572 reloc = parse_reloc (&input_line_pointer);
3573 if (reloc == -1)
3574 {
3575 as_bad (_("unrecognized relocation suffix"));
3576 ignore_rest_of_line ();
3577 return;
3578 }
3579 else if (reloc == BFD_RELOC_UNUSED)
3580 emit_expr (&exp, (unsigned int) nbytes);
3581 else
3582 {
3583 reloc_howto_type *howto = (reloc_howto_type *)
3584 bfd_reloc_type_lookup (stdoutput,
3585 (bfd_reloc_code_real_type) reloc);
3586 int size = bfd_get_reloc_size (howto);
3587
3588 if (reloc == BFD_RELOC_ARM_PLT32)
3589 {
3590 as_bad (_("(plt) is only valid on branch targets"));
3591 reloc = BFD_RELOC_UNUSED;
3592 size = 0;
3593 }
3594
3595 if (size > nbytes)
3596 as_bad (ngettext ("%s relocations do not fit in %d byte",
3597 "%s relocations do not fit in %d bytes",
3598 nbytes),
3599 howto->name, nbytes);
3600 else
3601 {
3602 /* We've parsed an expression stopping at O_symbol.
3603 But there may be more expression left now that we
3604 have parsed the relocation marker. Parse it again.
3605 XXX Surely there is a cleaner way to do this. */
3606 char *p = input_line_pointer;
3607 int offset;
3608 char *save_buf = XNEWVEC (char, input_line_pointer - base);
3609
3610 memcpy (save_buf, base, input_line_pointer - base);
3611 memmove (base + (input_line_pointer - before_reloc),
3612 base, before_reloc - base);
3613
3614 input_line_pointer = base + (input_line_pointer-before_reloc);
3615 expression (&exp);
3616 memcpy (base, save_buf, p - base);
3617
3618 offset = nbytes - size;
3619 p = frag_more (nbytes);
3620 memset (p, 0, nbytes);
3621 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3622 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3623 free (save_buf);
3624 }
3625 }
3626 }
3627 }
3628 while (*input_line_pointer++ == ',');
3629
3630 /* Put terminator back into stream. */
3631 input_line_pointer --;
3632 demand_empty_rest_of_line ();
3633 }
3634
3635 /* Emit an expression containing a 32-bit thumb instruction.
3636 Implementation based on put_thumb32_insn. */
3637
3638 static void
3639 emit_thumb32_expr (expressionS * exp)
3640 {
3641 expressionS exp_high = *exp;
3642
3643 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3644 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3645 exp->X_add_number &= 0xffff;
3646 emit_expr (exp, (unsigned int) THUMB_SIZE);
3647 }
3648
3649 /* Guess the instruction size based on the opcode. */
3650
3651 static int
3652 thumb_insn_size (int opcode)
3653 {
3654 if ((unsigned int) opcode < 0xe800u)
3655 return 2;
3656 else if ((unsigned int) opcode >= 0xe8000000u)
3657 return 4;
3658 else
3659 return 0;
3660 }
3661
3662 static bfd_boolean
3663 emit_insn (expressionS *exp, int nbytes)
3664 {
3665 int size = 0;
3666
3667 if (exp->X_op == O_constant)
3668 {
3669 size = nbytes;
3670
3671 if (size == 0)
3672 size = thumb_insn_size (exp->X_add_number);
3673
3674 if (size != 0)
3675 {
3676 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3677 {
3678 as_bad (_(".inst.n operand too big. "\
3679 "Use .inst.w instead"));
3680 size = 0;
3681 }
3682 else
3683 {
3684 if (now_it.state == AUTOMATIC_IT_BLOCK)
3685 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3686 else
3687 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3688
3689 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3690 emit_thumb32_expr (exp);
3691 else
3692 emit_expr (exp, (unsigned int) size);
3693
3694 it_fsm_post_encode ();
3695 }
3696 }
3697 else
3698 as_bad (_("cannot determine Thumb instruction size. " \
3699 "Use .inst.n/.inst.w instead"));
3700 }
3701 else
3702 as_bad (_("constant expression required"));
3703
3704 return (size != 0);
3705 }
3706
3707 /* Like s_arm_elf_cons but do not use md_cons_align and
3708 set the mapping state to MAP_ARM/MAP_THUMB. */
3709
3710 static void
3711 s_arm_elf_inst (int nbytes)
3712 {
3713 if (is_it_end_of_statement ())
3714 {
3715 demand_empty_rest_of_line ();
3716 return;
3717 }
3718
3719 /* Calling mapping_state () here will not change ARM/THUMB,
3720 but will ensure not to be in DATA state. */
3721
3722 if (thumb_mode)
3723 mapping_state (MAP_THUMB);
3724 else
3725 {
3726 if (nbytes != 0)
3727 {
3728 as_bad (_("width suffixes are invalid in ARM mode"));
3729 ignore_rest_of_line ();
3730 return;
3731 }
3732
3733 nbytes = 4;
3734
3735 mapping_state (MAP_ARM);
3736 }
3737
3738 do
3739 {
3740 expressionS exp;
3741
3742 expression (& exp);
3743
3744 if (! emit_insn (& exp, nbytes))
3745 {
3746 ignore_rest_of_line ();
3747 return;
3748 }
3749 }
3750 while (*input_line_pointer++ == ',');
3751
3752 /* Put terminator back into stream. */
3753 input_line_pointer --;
3754 demand_empty_rest_of_line ();
3755 }
3756
3757 /* Parse a .rel31 directive. */
3758
3759 static void
3760 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3761 {
3762 expressionS exp;
3763 char *p;
3764 valueT highbit;
3765
3766 highbit = 0;
3767 if (*input_line_pointer == '1')
3768 highbit = 0x80000000;
3769 else if (*input_line_pointer != '0')
3770 as_bad (_("expected 0 or 1"));
3771
3772 input_line_pointer++;
3773 if (*input_line_pointer != ',')
3774 as_bad (_("missing comma"));
3775 input_line_pointer++;
3776
3777 #ifdef md_flush_pending_output
3778 md_flush_pending_output ();
3779 #endif
3780
3781 #ifdef md_cons_align
3782 md_cons_align (4);
3783 #endif
3784
3785 mapping_state (MAP_DATA);
3786
3787 expression (&exp);
3788
3789 p = frag_more (4);
3790 md_number_to_chars (p, highbit, 4);
3791 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3792 BFD_RELOC_ARM_PREL31);
3793
3794 demand_empty_rest_of_line ();
3795 }
3796
3797 /* Directives: AEABI stack-unwind tables. */
3798
3799 /* Parse an unwind_fnstart directive. Simply records the current location. */
3800
3801 static void
3802 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3803 {
3804 demand_empty_rest_of_line ();
3805 if (unwind.proc_start)
3806 {
3807 as_bad (_("duplicate .fnstart directive"));
3808 return;
3809 }
3810
3811 /* Mark the start of the function. */
3812 unwind.proc_start = expr_build_dot ();
3813
3814 /* Reset the rest of the unwind info. */
3815 unwind.opcode_count = 0;
3816 unwind.table_entry = NULL;
3817 unwind.personality_routine = NULL;
3818 unwind.personality_index = -1;
3819 unwind.frame_size = 0;
3820 unwind.fp_offset = 0;
3821 unwind.fp_reg = REG_SP;
3822 unwind.fp_used = 0;
3823 unwind.sp_restored = 0;
3824 }
3825
3826
3827 /* Parse a handlerdata directive. Creates the exception handling table entry
3828 for the function. */
3829
3830 static void
3831 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3832 {
3833 demand_empty_rest_of_line ();
3834 if (!unwind.proc_start)
3835 as_bad (MISSING_FNSTART);
3836
3837 if (unwind.table_entry)
3838 as_bad (_("duplicate .handlerdata directive"));
3839
3840 create_unwind_entry (1);
3841 }
3842
3843 /* Parse an unwind_fnend directive. Generates the index table entry. */
3844
3845 static void
3846 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3847 {
3848 long where;
3849 char *ptr;
3850 valueT val;
3851 unsigned int marked_pr_dependency;
3852
3853 demand_empty_rest_of_line ();
3854
3855 if (!unwind.proc_start)
3856 {
3857 as_bad (_(".fnend directive without .fnstart"));
3858 return;
3859 }
3860
3861 /* Add eh table entry. */
3862 if (unwind.table_entry == NULL)
3863 val = create_unwind_entry (0);
3864 else
3865 val = 0;
3866
3867 /* Add index table entry. This is two words. */
3868 start_unwind_section (unwind.saved_seg, 1);
3869 frag_align (2, 0, 0);
3870 record_alignment (now_seg, 2);
3871
3872 ptr = frag_more (8);
3873 memset (ptr, 0, 8);
3874 where = frag_now_fix () - 8;
3875
3876 /* Self relative offset of the function start. */
3877 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3878 BFD_RELOC_ARM_PREL31);
3879
3880 /* Indicate dependency on EHABI-defined personality routines to the
3881 linker, if it hasn't been done already. */
3882 marked_pr_dependency
3883 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3884 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3885 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3886 {
3887 static const char *const name[] =
3888 {
3889 "__aeabi_unwind_cpp_pr0",
3890 "__aeabi_unwind_cpp_pr1",
3891 "__aeabi_unwind_cpp_pr2"
3892 };
3893 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3894 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3895 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3896 |= 1 << unwind.personality_index;
3897 }
3898
3899 if (val)
3900 /* Inline exception table entry. */
3901 md_number_to_chars (ptr + 4, val, 4);
3902 else
3903 /* Self relative offset of the table entry. */
3904 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3905 BFD_RELOC_ARM_PREL31);
3906
3907 /* Restore the original section. */
3908 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3909
3910 unwind.proc_start = NULL;
3911 }
3912
3913
3914 /* Parse an unwind_cantunwind directive. */
3915
3916 static void
3917 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3918 {
3919 demand_empty_rest_of_line ();
3920 if (!unwind.proc_start)
3921 as_bad (MISSING_FNSTART);
3922
3923 if (unwind.personality_routine || unwind.personality_index != -1)
3924 as_bad (_("personality routine specified for cantunwind frame"));
3925
3926 unwind.personality_index = -2;
3927 }
3928
3929
3930 /* Parse a personalityindex directive. */
3931
3932 static void
3933 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3934 {
3935 expressionS exp;
3936
3937 if (!unwind.proc_start)
3938 as_bad (MISSING_FNSTART);
3939
3940 if (unwind.personality_routine || unwind.personality_index != -1)
3941 as_bad (_("duplicate .personalityindex directive"));
3942
3943 expression (&exp);
3944
3945 if (exp.X_op != O_constant
3946 || exp.X_add_number < 0 || exp.X_add_number > 15)
3947 {
3948 as_bad (_("bad personality routine number"));
3949 ignore_rest_of_line ();
3950 return;
3951 }
3952
3953 unwind.personality_index = exp.X_add_number;
3954
3955 demand_empty_rest_of_line ();
3956 }
3957
3958
3959 /* Parse a personality directive. */
3960
3961 static void
3962 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3963 {
3964 char *name, *p, c;
3965
3966 if (!unwind.proc_start)
3967 as_bad (MISSING_FNSTART);
3968
3969 if (unwind.personality_routine || unwind.personality_index != -1)
3970 as_bad (_("duplicate .personality directive"));
3971
3972 c = get_symbol_name (& name);
3973 p = input_line_pointer;
3974 if (c == '"')
3975 ++ input_line_pointer;
3976 unwind.personality_routine = symbol_find_or_make (name);
3977 *p = c;
3978 demand_empty_rest_of_line ();
3979 }
3980
3981
3982 /* Parse a directive saving core registers. */
3983
3984 static void
3985 s_arm_unwind_save_core (void)
3986 {
3987 valueT op;
3988 long range;
3989 int n;
3990
3991 range = parse_reg_list (&input_line_pointer);
3992 if (range == FAIL)
3993 {
3994 as_bad (_("expected register list"));
3995 ignore_rest_of_line ();
3996 return;
3997 }
3998
3999 demand_empty_rest_of_line ();
4000
4001 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
4002 into .unwind_save {..., sp...}. We aren't bothered about the value of
4003 ip because it is clobbered by calls. */
4004 if (unwind.sp_restored && unwind.fp_reg == 12
4005 && (range & 0x3000) == 0x1000)
4006 {
4007 unwind.opcode_count--;
4008 unwind.sp_restored = 0;
4009 range = (range | 0x2000) & ~0x1000;
4010 unwind.pending_offset = 0;
4011 }
4012
4013 /* Pop r4-r15. */
4014 if (range & 0xfff0)
4015 {
4016 /* See if we can use the short opcodes. These pop a block of up to 8
4017 registers starting with r4, plus maybe r14. */
4018 for (n = 0; n < 8; n++)
4019 {
4020 /* Break at the first non-saved register. */
4021 if ((range & (1 << (n + 4))) == 0)
4022 break;
4023 }
4024 /* See if there are any other bits set. */
4025 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4026 {
4027 /* Use the long form. */
4028 op = 0x8000 | ((range >> 4) & 0xfff);
4029 add_unwind_opcode (op, 2);
4030 }
4031 else
4032 {
4033 /* Use the short form. */
4034 if (range & 0x4000)
4035 op = 0xa8; /* Pop r14. */
4036 else
4037 op = 0xa0; /* Do not pop r14. */
4038 op |= (n - 1);
4039 add_unwind_opcode (op, 1);
4040 }
4041 }
4042
4043 /* Pop r0-r3. */
4044 if (range & 0xf)
4045 {
4046 op = 0xb100 | (range & 0xf);
4047 add_unwind_opcode (op, 2);
4048 }
4049
4050 /* Record the number of bytes pushed. */
4051 for (n = 0; n < 16; n++)
4052 {
4053 if (range & (1 << n))
4054 unwind.frame_size += 4;
4055 }
4056 }
4057
4058
4059 /* Parse a directive saving FPA registers. */
4060
4061 static void
4062 s_arm_unwind_save_fpa (int reg)
4063 {
4064 expressionS exp;
4065 int num_regs;
4066 valueT op;
4067
4068 /* Get Number of registers to transfer. */
4069 if (skip_past_comma (&input_line_pointer) != FAIL)
4070 expression (&exp);
4071 else
4072 exp.X_op = O_illegal;
4073
4074 if (exp.X_op != O_constant)
4075 {
4076 as_bad (_("expected , <constant>"));
4077 ignore_rest_of_line ();
4078 return;
4079 }
4080
4081 num_regs = exp.X_add_number;
4082
4083 if (num_regs < 1 || num_regs > 4)
4084 {
4085 as_bad (_("number of registers must be in the range [1:4]"));
4086 ignore_rest_of_line ();
4087 return;
4088 }
4089
4090 demand_empty_rest_of_line ();
4091
4092 if (reg == 4)
4093 {
4094 /* Short form. */
4095 op = 0xb4 | (num_regs - 1);
4096 add_unwind_opcode (op, 1);
4097 }
4098 else
4099 {
4100 /* Long form. */
4101 op = 0xc800 | (reg << 4) | (num_regs - 1);
4102 add_unwind_opcode (op, 2);
4103 }
4104 unwind.frame_size += num_regs * 12;
4105 }
4106
4107
4108 /* Parse a directive saving VFP registers for ARMv6 and above. */
4109
4110 static void
4111 s_arm_unwind_save_vfp_armv6 (void)
4112 {
4113 int count;
4114 unsigned int start;
4115 valueT op;
4116 int num_vfpv3_regs = 0;
4117 int num_regs_below_16;
4118
4119 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4120 if (count == FAIL)
4121 {
4122 as_bad (_("expected register list"));
4123 ignore_rest_of_line ();
4124 return;
4125 }
4126
4127 demand_empty_rest_of_line ();
4128
4129 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4130 than FSTMX/FLDMX-style ones). */
4131
4132 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4133 if (start >= 16)
4134 num_vfpv3_regs = count;
4135 else if (start + count > 16)
4136 num_vfpv3_regs = start + count - 16;
4137
4138 if (num_vfpv3_regs > 0)
4139 {
4140 int start_offset = start > 16 ? start - 16 : 0;
4141 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4142 add_unwind_opcode (op, 2);
4143 }
4144
4145 /* Generate opcode for registers numbered in the range 0 .. 15. */
4146 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4147 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4148 if (num_regs_below_16 > 0)
4149 {
4150 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4151 add_unwind_opcode (op, 2);
4152 }
4153
4154 unwind.frame_size += count * 8;
4155 }
4156
4157
4158 /* Parse a directive saving VFP registers for pre-ARMv6. */
4159
4160 static void
4161 s_arm_unwind_save_vfp (void)
4162 {
4163 int count;
4164 unsigned int reg;
4165 valueT op;
4166
4167 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
4168 if (count == FAIL)
4169 {
4170 as_bad (_("expected register list"));
4171 ignore_rest_of_line ();
4172 return;
4173 }
4174
4175 demand_empty_rest_of_line ();
4176
4177 if (reg == 8)
4178 {
4179 /* Short form. */
4180 op = 0xb8 | (count - 1);
4181 add_unwind_opcode (op, 1);
4182 }
4183 else
4184 {
4185 /* Long form. */
4186 op = 0xb300 | (reg << 4) | (count - 1);
4187 add_unwind_opcode (op, 2);
4188 }
4189 unwind.frame_size += count * 8 + 4;
4190 }
4191
4192
4193 /* Parse a directive saving iWMMXt data registers. */
4194
4195 static void
4196 s_arm_unwind_save_mmxwr (void)
4197 {
4198 int reg;
4199 int hi_reg;
4200 int i;
4201 unsigned mask = 0;
4202 valueT op;
4203
4204 if (*input_line_pointer == '{')
4205 input_line_pointer++;
4206
4207 do
4208 {
4209 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4210
4211 if (reg == FAIL)
4212 {
4213 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4214 goto error;
4215 }
4216
4217 if (mask >> reg)
4218 as_tsktsk (_("register list not in ascending order"));
4219 mask |= 1 << reg;
4220
4221 if (*input_line_pointer == '-')
4222 {
4223 input_line_pointer++;
4224 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4225 if (hi_reg == FAIL)
4226 {
4227 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4228 goto error;
4229 }
4230 else if (reg >= hi_reg)
4231 {
4232 as_bad (_("bad register range"));
4233 goto error;
4234 }
4235 for (; reg < hi_reg; reg++)
4236 mask |= 1 << reg;
4237 }
4238 }
4239 while (skip_past_comma (&input_line_pointer) != FAIL);
4240
4241 skip_past_char (&input_line_pointer, '}');
4242
4243 demand_empty_rest_of_line ();
4244
4245 /* Generate any deferred opcodes because we're going to be looking at
4246 the list. */
4247 flush_pending_unwind ();
4248
4249 for (i = 0; i < 16; i++)
4250 {
4251 if (mask & (1 << i))
4252 unwind.frame_size += 8;
4253 }
4254
4255 /* Attempt to combine with a previous opcode. We do this because gcc
4256 likes to output separate unwind directives for a single block of
4257 registers. */
4258 if (unwind.opcode_count > 0)
4259 {
4260 i = unwind.opcodes[unwind.opcode_count - 1];
4261 if ((i & 0xf8) == 0xc0)
4262 {
4263 i &= 7;
4264 /* Only merge if the blocks are contiguous. */
4265 if (i < 6)
4266 {
4267 if ((mask & 0xfe00) == (1 << 9))
4268 {
4269 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4270 unwind.opcode_count--;
4271 }
4272 }
4273 else if (i == 6 && unwind.opcode_count >= 2)
4274 {
4275 i = unwind.opcodes[unwind.opcode_count - 2];
4276 reg = i >> 4;
4277 i &= 0xf;
4278
4279 op = 0xffff << (reg - 1);
4280 if (reg > 0
4281 && ((mask & op) == (1u << (reg - 1))))
4282 {
4283 op = (1 << (reg + i + 1)) - 1;
4284 op &= ~((1 << reg) - 1);
4285 mask |= op;
4286 unwind.opcode_count -= 2;
4287 }
4288 }
4289 }
4290 }
4291
4292 hi_reg = 15;
4293 /* We want to generate opcodes in the order the registers have been
4294 saved, ie. descending order. */
4295 for (reg = 15; reg >= -1; reg--)
4296 {
4297 /* Save registers in blocks. */
4298 if (reg < 0
4299 || !(mask & (1 << reg)))
4300 {
4301 /* We found an unsaved reg. Generate opcodes to save the
4302 preceding block. */
4303 if (reg != hi_reg)
4304 {
4305 if (reg == 9)
4306 {
4307 /* Short form. */
4308 op = 0xc0 | (hi_reg - 10);
4309 add_unwind_opcode (op, 1);
4310 }
4311 else
4312 {
4313 /* Long form. */
4314 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4315 add_unwind_opcode (op, 2);
4316 }
4317 }
4318 hi_reg = reg - 1;
4319 }
4320 }
4321
4322 return;
4323 error:
4324 ignore_rest_of_line ();
4325 }
4326
4327 static void
4328 s_arm_unwind_save_mmxwcg (void)
4329 {
4330 int reg;
4331 int hi_reg;
4332 unsigned mask = 0;
4333 valueT op;
4334
4335 if (*input_line_pointer == '{')
4336 input_line_pointer++;
4337
4338 skip_whitespace (input_line_pointer);
4339
4340 do
4341 {
4342 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4343
4344 if (reg == FAIL)
4345 {
4346 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4347 goto error;
4348 }
4349
4350 reg -= 8;
4351 if (mask >> reg)
4352 as_tsktsk (_("register list not in ascending order"));
4353 mask |= 1 << reg;
4354
4355 if (*input_line_pointer == '-')
4356 {
4357 input_line_pointer++;
4358 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4359 if (hi_reg == FAIL)
4360 {
4361 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4362 goto error;
4363 }
4364 else if (reg >= hi_reg)
4365 {
4366 as_bad (_("bad register range"));
4367 goto error;
4368 }
4369 for (; reg < hi_reg; reg++)
4370 mask |= 1 << reg;
4371 }
4372 }
4373 while (skip_past_comma (&input_line_pointer) != FAIL);
4374
4375 skip_past_char (&input_line_pointer, '}');
4376
4377 demand_empty_rest_of_line ();
4378
4379 /* Generate any deferred opcodes because we're going to be looking at
4380 the list. */
4381 flush_pending_unwind ();
4382
4383 for (reg = 0; reg < 16; reg++)
4384 {
4385 if (mask & (1 << reg))
4386 unwind.frame_size += 4;
4387 }
4388 op = 0xc700 | mask;
4389 add_unwind_opcode (op, 2);
4390 return;
4391 error:
4392 ignore_rest_of_line ();
4393 }
4394
4395
4396 /* Parse an unwind_save directive.
4397 If the argument is non-zero, this is a .vsave directive. */
4398
4399 static void
4400 s_arm_unwind_save (int arch_v6)
4401 {
4402 char *peek;
4403 struct reg_entry *reg;
4404 bfd_boolean had_brace = FALSE;
4405
4406 if (!unwind.proc_start)
4407 as_bad (MISSING_FNSTART);
4408
4409 /* Figure out what sort of save we have. */
4410 peek = input_line_pointer;
4411
4412 if (*peek == '{')
4413 {
4414 had_brace = TRUE;
4415 peek++;
4416 }
4417
4418 reg = arm_reg_parse_multi (&peek);
4419
4420 if (!reg)
4421 {
4422 as_bad (_("register expected"));
4423 ignore_rest_of_line ();
4424 return;
4425 }
4426
4427 switch (reg->type)
4428 {
4429 case REG_TYPE_FN:
4430 if (had_brace)
4431 {
4432 as_bad (_("FPA .unwind_save does not take a register list"));
4433 ignore_rest_of_line ();
4434 return;
4435 }
4436 input_line_pointer = peek;
4437 s_arm_unwind_save_fpa (reg->number);
4438 return;
4439
4440 case REG_TYPE_RN:
4441 s_arm_unwind_save_core ();
4442 return;
4443
4444 case REG_TYPE_VFD:
4445 if (arch_v6)
4446 s_arm_unwind_save_vfp_armv6 ();
4447 else
4448 s_arm_unwind_save_vfp ();
4449 return;
4450
4451 case REG_TYPE_MMXWR:
4452 s_arm_unwind_save_mmxwr ();
4453 return;
4454
4455 case REG_TYPE_MMXWCG:
4456 s_arm_unwind_save_mmxwcg ();
4457 return;
4458
4459 default:
4460 as_bad (_(".unwind_save does not support this kind of register"));
4461 ignore_rest_of_line ();
4462 }
4463 }
4464
4465
4466 /* Parse an unwind_movsp directive. */
4467
4468 static void
4469 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4470 {
4471 int reg;
4472 valueT op;
4473 int offset;
4474
4475 if (!unwind.proc_start)
4476 as_bad (MISSING_FNSTART);
4477
4478 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4479 if (reg == FAIL)
4480 {
4481 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4482 ignore_rest_of_line ();
4483 return;
4484 }
4485
4486 /* Optional constant. */
4487 if (skip_past_comma (&input_line_pointer) != FAIL)
4488 {
4489 if (immediate_for_directive (&offset) == FAIL)
4490 return;
4491 }
4492 else
4493 offset = 0;
4494
4495 demand_empty_rest_of_line ();
4496
4497 if (reg == REG_SP || reg == REG_PC)
4498 {
4499 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4500 return;
4501 }
4502
4503 if (unwind.fp_reg != REG_SP)
4504 as_bad (_("unexpected .unwind_movsp directive"));
4505
4506 /* Generate opcode to restore the value. */
4507 op = 0x90 | reg;
4508 add_unwind_opcode (op, 1);
4509
4510 /* Record the information for later. */
4511 unwind.fp_reg = reg;
4512 unwind.fp_offset = unwind.frame_size - offset;
4513 unwind.sp_restored = 1;
4514 }
4515
4516 /* Parse an unwind_pad directive. */
4517
4518 static void
4519 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4520 {
4521 int offset;
4522
4523 if (!unwind.proc_start)
4524 as_bad (MISSING_FNSTART);
4525
4526 if (immediate_for_directive (&offset) == FAIL)
4527 return;
4528
4529 if (offset & 3)
4530 {
4531 as_bad (_("stack increment must be multiple of 4"));
4532 ignore_rest_of_line ();
4533 return;
4534 }
4535
4536 /* Don't generate any opcodes, just record the details for later. */
4537 unwind.frame_size += offset;
4538 unwind.pending_offset += offset;
4539
4540 demand_empty_rest_of_line ();
4541 }
4542
4543 /* Parse an unwind_setfp directive. */
4544
4545 static void
4546 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4547 {
4548 int sp_reg;
4549 int fp_reg;
4550 int offset;
4551
4552 if (!unwind.proc_start)
4553 as_bad (MISSING_FNSTART);
4554
4555 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4556 if (skip_past_comma (&input_line_pointer) == FAIL)
4557 sp_reg = FAIL;
4558 else
4559 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4560
4561 if (fp_reg == FAIL || sp_reg == FAIL)
4562 {
4563 as_bad (_("expected <reg>, <reg>"));
4564 ignore_rest_of_line ();
4565 return;
4566 }
4567
4568 /* Optional constant. */
4569 if (skip_past_comma (&input_line_pointer) != FAIL)
4570 {
4571 if (immediate_for_directive (&offset) == FAIL)
4572 return;
4573 }
4574 else
4575 offset = 0;
4576
4577 demand_empty_rest_of_line ();
4578
4579 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4580 {
4581 as_bad (_("register must be either sp or set by a previous"
4582 "unwind_movsp directive"));
4583 return;
4584 }
4585
4586 /* Don't generate any opcodes, just record the information for later. */
4587 unwind.fp_reg = fp_reg;
4588 unwind.fp_used = 1;
4589 if (sp_reg == REG_SP)
4590 unwind.fp_offset = unwind.frame_size - offset;
4591 else
4592 unwind.fp_offset -= offset;
4593 }
4594
4595 /* Parse an unwind_raw directive. */
4596
4597 static void
4598 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4599 {
4600 expressionS exp;
4601 /* This is an arbitrary limit. */
4602 unsigned char op[16];
4603 int count;
4604
4605 if (!unwind.proc_start)
4606 as_bad (MISSING_FNSTART);
4607
4608 expression (&exp);
4609 if (exp.X_op == O_constant
4610 && skip_past_comma (&input_line_pointer) != FAIL)
4611 {
4612 unwind.frame_size += exp.X_add_number;
4613 expression (&exp);
4614 }
4615 else
4616 exp.X_op = O_illegal;
4617
4618 if (exp.X_op != O_constant)
4619 {
4620 as_bad (_("expected <offset>, <opcode>"));
4621 ignore_rest_of_line ();
4622 return;
4623 }
4624
4625 count = 0;
4626
4627 /* Parse the opcode. */
4628 for (;;)
4629 {
4630 if (count >= 16)
4631 {
4632 as_bad (_("unwind opcode too long"));
4633 ignore_rest_of_line ();
4634 }
4635 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4636 {
4637 as_bad (_("invalid unwind opcode"));
4638 ignore_rest_of_line ();
4639 return;
4640 }
4641 op[count++] = exp.X_add_number;
4642
4643 /* Parse the next byte. */
4644 if (skip_past_comma (&input_line_pointer) == FAIL)
4645 break;
4646
4647 expression (&exp);
4648 }
4649
4650 /* Add the opcode bytes in reverse order. */
4651 while (count--)
4652 add_unwind_opcode (op[count], 1);
4653
4654 demand_empty_rest_of_line ();
4655 }
4656
4657
4658 /* Parse a .eabi_attribute directive. */
4659
4660 static void
4661 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4662 {
4663 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4664
4665 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4666 attributes_set_explicitly[tag] = 1;
4667 }
4668
4669 /* Emit a tls fix for the symbol. */
4670
4671 static void
4672 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4673 {
4674 char *p;
4675 expressionS exp;
4676 #ifdef md_flush_pending_output
4677 md_flush_pending_output ();
4678 #endif
4679
4680 #ifdef md_cons_align
4681 md_cons_align (4);
4682 #endif
4683
4684 /* Since we're just labelling the code, there's no need to define a
4685 mapping symbol. */
4686 expression (&exp);
4687 p = obstack_next_free (&frchain_now->frch_obstack);
4688 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4689 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4690 : BFD_RELOC_ARM_TLS_DESCSEQ);
4691 }
4692 #endif /* OBJ_ELF */
4693
4694 static void s_arm_arch (int);
4695 static void s_arm_object_arch (int);
4696 static void s_arm_cpu (int);
4697 static void s_arm_fpu (int);
4698 static void s_arm_arch_extension (int);
4699
4700 #ifdef TE_PE
4701
4702 static void
4703 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4704 {
4705 expressionS exp;
4706
4707 do
4708 {
4709 expression (&exp);
4710 if (exp.X_op == O_symbol)
4711 exp.X_op = O_secrel;
4712
4713 emit_expr (&exp, 4);
4714 }
4715 while (*input_line_pointer++ == ',');
4716
4717 input_line_pointer--;
4718 demand_empty_rest_of_line ();
4719 }
4720 #endif /* TE_PE */
4721
4722 /* This table describes all the machine specific pseudo-ops the assembler
4723 has to support. The fields are:
4724 pseudo-op name without dot
4725 function to call to execute this pseudo-op
4726 Integer arg to pass to the function. */
4727
4728 const pseudo_typeS md_pseudo_table[] =
4729 {
4730 /* Never called because '.req' does not start a line. */
4731 { "req", s_req, 0 },
4732 /* Following two are likewise never called. */
4733 { "dn", s_dn, 0 },
4734 { "qn", s_qn, 0 },
4735 { "unreq", s_unreq, 0 },
4736 { "bss", s_bss, 0 },
4737 { "align", s_align_ptwo, 2 },
4738 { "arm", s_arm, 0 },
4739 { "thumb", s_thumb, 0 },
4740 { "code", s_code, 0 },
4741 { "force_thumb", s_force_thumb, 0 },
4742 { "thumb_func", s_thumb_func, 0 },
4743 { "thumb_set", s_thumb_set, 0 },
4744 { "even", s_even, 0 },
4745 { "ltorg", s_ltorg, 0 },
4746 { "pool", s_ltorg, 0 },
4747 { "syntax", s_syntax, 0 },
4748 { "cpu", s_arm_cpu, 0 },
4749 { "arch", s_arm_arch, 0 },
4750 { "object_arch", s_arm_object_arch, 0 },
4751 { "fpu", s_arm_fpu, 0 },
4752 { "arch_extension", s_arm_arch_extension, 0 },
4753 #ifdef OBJ_ELF
4754 { "word", s_arm_elf_cons, 4 },
4755 { "long", s_arm_elf_cons, 4 },
4756 { "inst.n", s_arm_elf_inst, 2 },
4757 { "inst.w", s_arm_elf_inst, 4 },
4758 { "inst", s_arm_elf_inst, 0 },
4759 { "rel31", s_arm_rel31, 0 },
4760 { "fnstart", s_arm_unwind_fnstart, 0 },
4761 { "fnend", s_arm_unwind_fnend, 0 },
4762 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4763 { "personality", s_arm_unwind_personality, 0 },
4764 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4765 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4766 { "save", s_arm_unwind_save, 0 },
4767 { "vsave", s_arm_unwind_save, 1 },
4768 { "movsp", s_arm_unwind_movsp, 0 },
4769 { "pad", s_arm_unwind_pad, 0 },
4770 { "setfp", s_arm_unwind_setfp, 0 },
4771 { "unwind_raw", s_arm_unwind_raw, 0 },
4772 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4773 { "tlsdescseq", s_arm_tls_descseq, 0 },
4774 #else
4775 { "word", cons, 4},
4776
4777 /* These are used for dwarf. */
4778 {"2byte", cons, 2},
4779 {"4byte", cons, 4},
4780 {"8byte", cons, 8},
4781 /* These are used for dwarf2. */
4782 { "file", dwarf2_directive_file, 0 },
4783 { "loc", dwarf2_directive_loc, 0 },
4784 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4785 #endif
4786 { "extend", float_cons, 'x' },
4787 { "ldouble", float_cons, 'x' },
4788 { "packed", float_cons, 'p' },
4789 #ifdef TE_PE
4790 {"secrel32", pe_directive_secrel, 0},
4791 #endif
4792
4793 /* These are for compatibility with CodeComposer Studio. */
4794 {"ref", s_ccs_ref, 0},
4795 {"def", s_ccs_def, 0},
4796 {"asmfunc", s_ccs_asmfunc, 0},
4797 {"endasmfunc", s_ccs_endasmfunc, 0},
4798
4799 { 0, 0, 0 }
4800 };
4801 \f
4802 /* Parser functions used exclusively in instruction operands. */
4803
4804 /* Generic immediate-value read function for use in insn parsing.
4805 STR points to the beginning of the immediate (the leading #);
4806 VAL receives the value; if the value is outside [MIN, MAX]
4807 issue an error. PREFIX_OPT is true if the immediate prefix is
4808 optional. */
4809
4810 static int
4811 parse_immediate (char **str, int *val, int min, int max,
4812 bfd_boolean prefix_opt)
4813 {
4814 expressionS exp;
4815
4816 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4817 if (exp.X_op != O_constant)
4818 {
4819 inst.error = _("constant expression required");
4820 return FAIL;
4821 }
4822
4823 if (exp.X_add_number < min || exp.X_add_number > max)
4824 {
4825 inst.error = _("immediate value out of range");
4826 return FAIL;
4827 }
4828
4829 *val = exp.X_add_number;
4830 return SUCCESS;
4831 }
4832
4833 /* Less-generic immediate-value read function with the possibility of loading a
4834 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4835 instructions. Puts the result directly in inst.operands[i]. */
4836
4837 static int
4838 parse_big_immediate (char **str, int i, expressionS *in_exp,
4839 bfd_boolean allow_symbol_p)
4840 {
4841 expressionS exp;
4842 expressionS *exp_p = in_exp ? in_exp : &exp;
4843 char *ptr = *str;
4844
4845 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
4846
4847 if (exp_p->X_op == O_constant)
4848 {
4849 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
4850 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4851 O_constant. We have to be careful not to break compilation for
4852 32-bit X_add_number, though. */
4853 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
4854 {
4855 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4856 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4857 & 0xffffffff);
4858 inst.operands[i].regisimm = 1;
4859 }
4860 }
4861 else if (exp_p->X_op == O_big
4862 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
4863 {
4864 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4865
4866 /* Bignums have their least significant bits in
4867 generic_bignum[0]. Make sure we put 32 bits in imm and
4868 32 bits in reg, in a (hopefully) portable way. */
4869 gas_assert (parts != 0);
4870
4871 /* Make sure that the number is not too big.
4872 PR 11972: Bignums can now be sign-extended to the
4873 size of a .octa so check that the out of range bits
4874 are all zero or all one. */
4875 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
4876 {
4877 LITTLENUM_TYPE m = -1;
4878
4879 if (generic_bignum[parts * 2] != 0
4880 && generic_bignum[parts * 2] != m)
4881 return FAIL;
4882
4883 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
4884 if (generic_bignum[j] != generic_bignum[j-1])
4885 return FAIL;
4886 }
4887
4888 inst.operands[i].imm = 0;
4889 for (j = 0; j < parts; j++, idx++)
4890 inst.operands[i].imm |= generic_bignum[idx]
4891 << (LITTLENUM_NUMBER_OF_BITS * j);
4892 inst.operands[i].reg = 0;
4893 for (j = 0; j < parts; j++, idx++)
4894 inst.operands[i].reg |= generic_bignum[idx]
4895 << (LITTLENUM_NUMBER_OF_BITS * j);
4896 inst.operands[i].regisimm = 1;
4897 }
4898 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
4899 return FAIL;
4900
4901 *str = ptr;
4902
4903 return SUCCESS;
4904 }
4905
4906 /* Returns the pseudo-register number of an FPA immediate constant,
4907 or FAIL if there isn't a valid constant here. */
4908
4909 static int
4910 parse_fpa_immediate (char ** str)
4911 {
4912 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4913 char * save_in;
4914 expressionS exp;
4915 int i;
4916 int j;
4917
4918 /* First try and match exact strings, this is to guarantee
4919 that some formats will work even for cross assembly. */
4920
4921 for (i = 0; fp_const[i]; i++)
4922 {
4923 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4924 {
4925 char *start = *str;
4926
4927 *str += strlen (fp_const[i]);
4928 if (is_end_of_line[(unsigned char) **str])
4929 return i + 8;
4930 *str = start;
4931 }
4932 }
4933
4934 /* Just because we didn't get a match doesn't mean that the constant
4935 isn't valid, just that it is in a format that we don't
4936 automatically recognize. Try parsing it with the standard
4937 expression routines. */
4938
4939 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4940
4941 /* Look for a raw floating point number. */
4942 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4943 && is_end_of_line[(unsigned char) *save_in])
4944 {
4945 for (i = 0; i < NUM_FLOAT_VALS; i++)
4946 {
4947 for (j = 0; j < MAX_LITTLENUMS; j++)
4948 {
4949 if (words[j] != fp_values[i][j])
4950 break;
4951 }
4952
4953 if (j == MAX_LITTLENUMS)
4954 {
4955 *str = save_in;
4956 return i + 8;
4957 }
4958 }
4959 }
4960
4961 /* Try and parse a more complex expression, this will probably fail
4962 unless the code uses a floating point prefix (eg "0f"). */
4963 save_in = input_line_pointer;
4964 input_line_pointer = *str;
4965 if (expression (&exp) == absolute_section
4966 && exp.X_op == O_big
4967 && exp.X_add_number < 0)
4968 {
4969 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4970 Ditto for 15. */
4971 #define X_PRECISION 5
4972 #define E_PRECISION 15L
4973 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
4974 {
4975 for (i = 0; i < NUM_FLOAT_VALS; i++)
4976 {
4977 for (j = 0; j < MAX_LITTLENUMS; j++)
4978 {
4979 if (words[j] != fp_values[i][j])
4980 break;
4981 }
4982
4983 if (j == MAX_LITTLENUMS)
4984 {
4985 *str = input_line_pointer;
4986 input_line_pointer = save_in;
4987 return i + 8;
4988 }
4989 }
4990 }
4991 }
4992
4993 *str = input_line_pointer;
4994 input_line_pointer = save_in;
4995 inst.error = _("invalid FPA immediate expression");
4996 return FAIL;
4997 }
4998
4999 /* Returns 1 if a number has "quarter-precision" float format
5000 0baBbbbbbc defgh000 00000000 00000000. */
5001
5002 static int
5003 is_quarter_float (unsigned imm)
5004 {
5005 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
5006 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
5007 }
5008
5009
5010 /* Detect the presence of a floating point or integer zero constant,
5011 i.e. #0.0 or #0. */
5012
5013 static bfd_boolean
5014 parse_ifimm_zero (char **in)
5015 {
5016 int error_code;
5017
5018 if (!is_immediate_prefix (**in))
5019 {
5020 /* In unified syntax, all prefixes are optional. */
5021 if (!unified_syntax)
5022 return FALSE;
5023 }
5024 else
5025 ++*in;
5026
5027 /* Accept #0x0 as a synonym for #0. */
5028 if (strncmp (*in, "0x", 2) == 0)
5029 {
5030 int val;
5031 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5032 return FALSE;
5033 return TRUE;
5034 }
5035
5036 error_code = atof_generic (in, ".", EXP_CHARS,
5037 &generic_floating_point_number);
5038
5039 if (!error_code
5040 && generic_floating_point_number.sign == '+'
5041 && (generic_floating_point_number.low
5042 > generic_floating_point_number.leader))
5043 return TRUE;
5044
5045 return FALSE;
5046 }
5047
5048 /* Parse an 8-bit "quarter-precision" floating point number of the form:
5049 0baBbbbbbc defgh000 00000000 00000000.
5050 The zero and minus-zero cases need special handling, since they can't be
5051 encoded in the "quarter-precision" float format, but can nonetheless be
5052 loaded as integer constants. */
5053
5054 static unsigned
5055 parse_qfloat_immediate (char **ccp, int *immed)
5056 {
5057 char *str = *ccp;
5058 char *fpnum;
5059 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5060 int found_fpchar = 0;
5061
5062 skip_past_char (&str, '#');
5063
5064 /* We must not accidentally parse an integer as a floating-point number. Make
5065 sure that the value we parse is not an integer by checking for special
5066 characters '.' or 'e'.
5067 FIXME: This is a horrible hack, but doing better is tricky because type
5068 information isn't in a very usable state at parse time. */
5069 fpnum = str;
5070 skip_whitespace (fpnum);
5071
5072 if (strncmp (fpnum, "0x", 2) == 0)
5073 return FAIL;
5074 else
5075 {
5076 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
5077 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5078 {
5079 found_fpchar = 1;
5080 break;
5081 }
5082
5083 if (!found_fpchar)
5084 return FAIL;
5085 }
5086
5087 if ((str = atof_ieee (str, 's', words)) != NULL)
5088 {
5089 unsigned fpword = 0;
5090 int i;
5091
5092 /* Our FP word must be 32 bits (single-precision FP). */
5093 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
5094 {
5095 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5096 fpword |= words[i];
5097 }
5098
5099 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5100 *immed = fpword;
5101 else
5102 return FAIL;
5103
5104 *ccp = str;
5105
5106 return SUCCESS;
5107 }
5108
5109 return FAIL;
5110 }
5111
5112 /* Shift operands. */
5113 enum shift_kind
5114 {
5115 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5116 };
5117
5118 struct asm_shift_name
5119 {
5120 const char *name;
5121 enum shift_kind kind;
5122 };
5123
5124 /* Third argument to parse_shift. */
5125 enum parse_shift_mode
5126 {
5127 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5128 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5129 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5130 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5131 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5132 };
5133
5134 /* Parse a <shift> specifier on an ARM data processing instruction.
5135 This has three forms:
5136
5137 (LSL|LSR|ASL|ASR|ROR) Rs
5138 (LSL|LSR|ASL|ASR|ROR) #imm
5139 RRX
5140
5141 Note that ASL is assimilated to LSL in the instruction encoding, and
5142 RRX to ROR #0 (which cannot be written as such). */
5143
5144 static int
5145 parse_shift (char **str, int i, enum parse_shift_mode mode)
5146 {
5147 const struct asm_shift_name *shift_name;
5148 enum shift_kind shift;
5149 char *s = *str;
5150 char *p = s;
5151 int reg;
5152
5153 for (p = *str; ISALPHA (*p); p++)
5154 ;
5155
5156 if (p == *str)
5157 {
5158 inst.error = _("shift expression expected");
5159 return FAIL;
5160 }
5161
5162 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
5163 p - *str);
5164
5165 if (shift_name == NULL)
5166 {
5167 inst.error = _("shift expression expected");
5168 return FAIL;
5169 }
5170
5171 shift = shift_name->kind;
5172
5173 switch (mode)
5174 {
5175 case NO_SHIFT_RESTRICT:
5176 case SHIFT_IMMEDIATE: break;
5177
5178 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5179 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5180 {
5181 inst.error = _("'LSL' or 'ASR' required");
5182 return FAIL;
5183 }
5184 break;
5185
5186 case SHIFT_LSL_IMMEDIATE:
5187 if (shift != SHIFT_LSL)
5188 {
5189 inst.error = _("'LSL' required");
5190 return FAIL;
5191 }
5192 break;
5193
5194 case SHIFT_ASR_IMMEDIATE:
5195 if (shift != SHIFT_ASR)
5196 {
5197 inst.error = _("'ASR' required");
5198 return FAIL;
5199 }
5200 break;
5201
5202 default: abort ();
5203 }
5204
5205 if (shift != SHIFT_RRX)
5206 {
5207 /* Whitespace can appear here if the next thing is a bare digit. */
5208 skip_whitespace (p);
5209
5210 if (mode == NO_SHIFT_RESTRICT
5211 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5212 {
5213 inst.operands[i].imm = reg;
5214 inst.operands[i].immisreg = 1;
5215 }
5216 else if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5217 return FAIL;
5218 }
5219 inst.operands[i].shift_kind = shift;
5220 inst.operands[i].shifted = 1;
5221 *str = p;
5222 return SUCCESS;
5223 }
5224
5225 /* Parse a <shifter_operand> for an ARM data processing instruction:
5226
5227 #<immediate>
5228 #<immediate>, <rotate>
5229 <Rm>
5230 <Rm>, <shift>
5231
5232 where <shift> is defined by parse_shift above, and <rotate> is a
5233 multiple of 2 between 0 and 30. Validation of immediate operands
5234 is deferred to md_apply_fix. */
5235
5236 static int
5237 parse_shifter_operand (char **str, int i)
5238 {
5239 int value;
5240 expressionS exp;
5241
5242 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5243 {
5244 inst.operands[i].reg = value;
5245 inst.operands[i].isreg = 1;
5246
5247 /* parse_shift will override this if appropriate */
5248 inst.relocs[0].exp.X_op = O_constant;
5249 inst.relocs[0].exp.X_add_number = 0;
5250
5251 if (skip_past_comma (str) == FAIL)
5252 return SUCCESS;
5253
5254 /* Shift operation on register. */
5255 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5256 }
5257
5258 if (my_get_expression (&inst.relocs[0].exp, str, GE_IMM_PREFIX))
5259 return FAIL;
5260
5261 if (skip_past_comma (str) == SUCCESS)
5262 {
5263 /* #x, y -- ie explicit rotation by Y. */
5264 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5265 return FAIL;
5266
5267 if (exp.X_op != O_constant || inst.relocs[0].exp.X_op != O_constant)
5268 {
5269 inst.error = _("constant expression expected");
5270 return FAIL;
5271 }
5272
5273 value = exp.X_add_number;
5274 if (value < 0 || value > 30 || value % 2 != 0)
5275 {
5276 inst.error = _("invalid rotation");
5277 return FAIL;
5278 }
5279 if (inst.relocs[0].exp.X_add_number < 0
5280 || inst.relocs[0].exp.X_add_number > 255)
5281 {
5282 inst.error = _("invalid constant");
5283 return FAIL;
5284 }
5285
5286 /* Encode as specified. */
5287 inst.operands[i].imm = inst.relocs[0].exp.X_add_number | value << 7;
5288 return SUCCESS;
5289 }
5290
5291 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
5292 inst.relocs[0].pc_rel = 0;
5293 return SUCCESS;
5294 }
5295
5296 /* Group relocation information. Each entry in the table contains the
5297 textual name of the relocation as may appear in assembler source
5298 and must end with a colon.
5299 Along with this textual name are the relocation codes to be used if
5300 the corresponding instruction is an ALU instruction (ADD or SUB only),
5301 an LDR, an LDRS, or an LDC. */
5302
5303 struct group_reloc_table_entry
5304 {
5305 const char *name;
5306 int alu_code;
5307 int ldr_code;
5308 int ldrs_code;
5309 int ldc_code;
5310 };
5311
5312 typedef enum
5313 {
5314 /* Varieties of non-ALU group relocation. */
5315
5316 GROUP_LDR,
5317 GROUP_LDRS,
5318 GROUP_LDC
5319 } group_reloc_type;
5320
5321 static struct group_reloc_table_entry group_reloc_table[] =
5322 { /* Program counter relative: */
5323 { "pc_g0_nc",
5324 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5325 0, /* LDR */
5326 0, /* LDRS */
5327 0 }, /* LDC */
5328 { "pc_g0",
5329 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5330 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5331 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5332 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5333 { "pc_g1_nc",
5334 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5335 0, /* LDR */
5336 0, /* LDRS */
5337 0 }, /* LDC */
5338 { "pc_g1",
5339 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5340 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5341 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5342 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5343 { "pc_g2",
5344 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5345 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5346 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5347 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5348 /* Section base relative */
5349 { "sb_g0_nc",
5350 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5351 0, /* LDR */
5352 0, /* LDRS */
5353 0 }, /* LDC */
5354 { "sb_g0",
5355 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5356 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5357 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5358 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5359 { "sb_g1_nc",
5360 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5361 0, /* LDR */
5362 0, /* LDRS */
5363 0 }, /* LDC */
5364 { "sb_g1",
5365 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5366 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5367 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5368 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5369 { "sb_g2",
5370 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5371 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5372 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5373 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5374 /* Absolute thumb alu relocations. */
5375 { "lower0_7",
5376 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5377 0, /* LDR. */
5378 0, /* LDRS. */
5379 0 }, /* LDC. */
5380 { "lower8_15",
5381 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5382 0, /* LDR. */
5383 0, /* LDRS. */
5384 0 }, /* LDC. */
5385 { "upper0_7",
5386 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5387 0, /* LDR. */
5388 0, /* LDRS. */
5389 0 }, /* LDC. */
5390 { "upper8_15",
5391 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5392 0, /* LDR. */
5393 0, /* LDRS. */
5394 0 } }; /* LDC. */
5395
5396 /* Given the address of a pointer pointing to the textual name of a group
5397 relocation as may appear in assembler source, attempt to find its details
5398 in group_reloc_table. The pointer will be updated to the character after
5399 the trailing colon. On failure, FAIL will be returned; SUCCESS
5400 otherwise. On success, *entry will be updated to point at the relevant
5401 group_reloc_table entry. */
5402
5403 static int
5404 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5405 {
5406 unsigned int i;
5407 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5408 {
5409 int length = strlen (group_reloc_table[i].name);
5410
5411 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5412 && (*str)[length] == ':')
5413 {
5414 *out = &group_reloc_table[i];
5415 *str += (length + 1);
5416 return SUCCESS;
5417 }
5418 }
5419
5420 return FAIL;
5421 }
5422
5423 /* Parse a <shifter_operand> for an ARM data processing instruction
5424 (as for parse_shifter_operand) where group relocations are allowed:
5425
5426 #<immediate>
5427 #<immediate>, <rotate>
5428 #:<group_reloc>:<expression>
5429 <Rm>
5430 <Rm>, <shift>
5431
5432 where <group_reloc> is one of the strings defined in group_reloc_table.
5433 The hashes are optional.
5434
5435 Everything else is as for parse_shifter_operand. */
5436
5437 static parse_operand_result
5438 parse_shifter_operand_group_reloc (char **str, int i)
5439 {
5440 /* Determine if we have the sequence of characters #: or just :
5441 coming next. If we do, then we check for a group relocation.
5442 If we don't, punt the whole lot to parse_shifter_operand. */
5443
5444 if (((*str)[0] == '#' && (*str)[1] == ':')
5445 || (*str)[0] == ':')
5446 {
5447 struct group_reloc_table_entry *entry;
5448
5449 if ((*str)[0] == '#')
5450 (*str) += 2;
5451 else
5452 (*str)++;
5453
5454 /* Try to parse a group relocation. Anything else is an error. */
5455 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5456 {
5457 inst.error = _("unknown group relocation");
5458 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5459 }
5460
5461 /* We now have the group relocation table entry corresponding to
5462 the name in the assembler source. Next, we parse the expression. */
5463 if (my_get_expression (&inst.relocs[0].exp, str, GE_NO_PREFIX))
5464 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5465
5466 /* Record the relocation type (always the ALU variant here). */
5467 inst.relocs[0].type = (bfd_reloc_code_real_type) entry->alu_code;
5468 gas_assert (inst.relocs[0].type != 0);
5469
5470 return PARSE_OPERAND_SUCCESS;
5471 }
5472 else
5473 return parse_shifter_operand (str, i) == SUCCESS
5474 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5475
5476 /* Never reached. */
5477 }
5478
5479 /* Parse a Neon alignment expression. Information is written to
5480 inst.operands[i]. We assume the initial ':' has been skipped.
5481
5482 align .imm = align << 8, .immisalign=1, .preind=0 */
5483 static parse_operand_result
5484 parse_neon_alignment (char **str, int i)
5485 {
5486 char *p = *str;
5487 expressionS exp;
5488
5489 my_get_expression (&exp, &p, GE_NO_PREFIX);
5490
5491 if (exp.X_op != O_constant)
5492 {
5493 inst.error = _("alignment must be constant");
5494 return PARSE_OPERAND_FAIL;
5495 }
5496
5497 inst.operands[i].imm = exp.X_add_number << 8;
5498 inst.operands[i].immisalign = 1;
5499 /* Alignments are not pre-indexes. */
5500 inst.operands[i].preind = 0;
5501
5502 *str = p;
5503 return PARSE_OPERAND_SUCCESS;
5504 }
5505
5506 /* Parse all forms of an ARM address expression. Information is written
5507 to inst.operands[i] and/or inst.relocs[0].
5508
5509 Preindexed addressing (.preind=1):
5510
5511 [Rn, #offset] .reg=Rn .relocs[0].exp=offset
5512 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5513 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5514 .shift_kind=shift .relocs[0].exp=shift_imm
5515
5516 These three may have a trailing ! which causes .writeback to be set also.
5517
5518 Postindexed addressing (.postind=1, .writeback=1):
5519
5520 [Rn], #offset .reg=Rn .relocs[0].exp=offset
5521 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5522 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5523 .shift_kind=shift .relocs[0].exp=shift_imm
5524
5525 Unindexed addressing (.preind=0, .postind=0):
5526
5527 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5528
5529 Other:
5530
5531 [Rn]{!} shorthand for [Rn,#0]{!}
5532 =immediate .isreg=0 .relocs[0].exp=immediate
5533 label .reg=PC .relocs[0].pc_rel=1 .relocs[0].exp=label
5534
5535 It is the caller's responsibility to check for addressing modes not
5536 supported by the instruction, and to set inst.relocs[0].type. */
5537
5538 static parse_operand_result
5539 parse_address_main (char **str, int i, int group_relocations,
5540 group_reloc_type group_type)
5541 {
5542 char *p = *str;
5543 int reg;
5544
5545 if (skip_past_char (&p, '[') == FAIL)
5546 {
5547 if (skip_past_char (&p, '=') == FAIL)
5548 {
5549 /* Bare address - translate to PC-relative offset. */
5550 inst.relocs[0].pc_rel = 1;
5551 inst.operands[i].reg = REG_PC;
5552 inst.operands[i].isreg = 1;
5553 inst.operands[i].preind = 1;
5554
5555 if (my_get_expression (&inst.relocs[0].exp, &p, GE_OPT_PREFIX_BIG))
5556 return PARSE_OPERAND_FAIL;
5557 }
5558 else if (parse_big_immediate (&p, i, &inst.relocs[0].exp,
5559 /*allow_symbol_p=*/TRUE))
5560 return PARSE_OPERAND_FAIL;
5561
5562 *str = p;
5563 return PARSE_OPERAND_SUCCESS;
5564 }
5565
5566 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5567 skip_whitespace (p);
5568
5569 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5570 {
5571 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5572 return PARSE_OPERAND_FAIL;
5573 }
5574 inst.operands[i].reg = reg;
5575 inst.operands[i].isreg = 1;
5576
5577 if (skip_past_comma (&p) == SUCCESS)
5578 {
5579 inst.operands[i].preind = 1;
5580
5581 if (*p == '+') p++;
5582 else if (*p == '-') p++, inst.operands[i].negative = 1;
5583
5584 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5585 {
5586 inst.operands[i].imm = reg;
5587 inst.operands[i].immisreg = 1;
5588
5589 if (skip_past_comma (&p) == SUCCESS)
5590 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5591 return PARSE_OPERAND_FAIL;
5592 }
5593 else if (skip_past_char (&p, ':') == SUCCESS)
5594 {
5595 /* FIXME: '@' should be used here, but it's filtered out by generic
5596 code before we get to see it here. This may be subject to
5597 change. */
5598 parse_operand_result result = parse_neon_alignment (&p, i);
5599
5600 if (result != PARSE_OPERAND_SUCCESS)
5601 return result;
5602 }
5603 else
5604 {
5605 if (inst.operands[i].negative)
5606 {
5607 inst.operands[i].negative = 0;
5608 p--;
5609 }
5610
5611 if (group_relocations
5612 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5613 {
5614 struct group_reloc_table_entry *entry;
5615
5616 /* Skip over the #: or : sequence. */
5617 if (*p == '#')
5618 p += 2;
5619 else
5620 p++;
5621
5622 /* Try to parse a group relocation. Anything else is an
5623 error. */
5624 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5625 {
5626 inst.error = _("unknown group relocation");
5627 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5628 }
5629
5630 /* We now have the group relocation table entry corresponding to
5631 the name in the assembler source. Next, we parse the
5632 expression. */
5633 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
5634 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5635
5636 /* Record the relocation type. */
5637 switch (group_type)
5638 {
5639 case GROUP_LDR:
5640 inst.relocs[0].type
5641 = (bfd_reloc_code_real_type) entry->ldr_code;
5642 break;
5643
5644 case GROUP_LDRS:
5645 inst.relocs[0].type
5646 = (bfd_reloc_code_real_type) entry->ldrs_code;
5647 break;
5648
5649 case GROUP_LDC:
5650 inst.relocs[0].type
5651 = (bfd_reloc_code_real_type) entry->ldc_code;
5652 break;
5653
5654 default:
5655 gas_assert (0);
5656 }
5657
5658 if (inst.relocs[0].type == 0)
5659 {
5660 inst.error = _("this group relocation is not allowed on this instruction");
5661 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5662 }
5663 }
5664 else
5665 {
5666 char *q = p;
5667
5668 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5669 return PARSE_OPERAND_FAIL;
5670 /* If the offset is 0, find out if it's a +0 or -0. */
5671 if (inst.relocs[0].exp.X_op == O_constant
5672 && inst.relocs[0].exp.X_add_number == 0)
5673 {
5674 skip_whitespace (q);
5675 if (*q == '#')
5676 {
5677 q++;
5678 skip_whitespace (q);
5679 }
5680 if (*q == '-')
5681 inst.operands[i].negative = 1;
5682 }
5683 }
5684 }
5685 }
5686 else if (skip_past_char (&p, ':') == SUCCESS)
5687 {
5688 /* FIXME: '@' should be used here, but it's filtered out by generic code
5689 before we get to see it here. This may be subject to change. */
5690 parse_operand_result result = parse_neon_alignment (&p, i);
5691
5692 if (result != PARSE_OPERAND_SUCCESS)
5693 return result;
5694 }
5695
5696 if (skip_past_char (&p, ']') == FAIL)
5697 {
5698 inst.error = _("']' expected");
5699 return PARSE_OPERAND_FAIL;
5700 }
5701
5702 if (skip_past_char (&p, '!') == SUCCESS)
5703 inst.operands[i].writeback = 1;
5704
5705 else if (skip_past_comma (&p) == SUCCESS)
5706 {
5707 if (skip_past_char (&p, '{') == SUCCESS)
5708 {
5709 /* [Rn], {expr} - unindexed, with option */
5710 if (parse_immediate (&p, &inst.operands[i].imm,
5711 0, 255, TRUE) == FAIL)
5712 return PARSE_OPERAND_FAIL;
5713
5714 if (skip_past_char (&p, '}') == FAIL)
5715 {
5716 inst.error = _("'}' expected at end of 'option' field");
5717 return PARSE_OPERAND_FAIL;
5718 }
5719 if (inst.operands[i].preind)
5720 {
5721 inst.error = _("cannot combine index with option");
5722 return PARSE_OPERAND_FAIL;
5723 }
5724 *str = p;
5725 return PARSE_OPERAND_SUCCESS;
5726 }
5727 else
5728 {
5729 inst.operands[i].postind = 1;
5730 inst.operands[i].writeback = 1;
5731
5732 if (inst.operands[i].preind)
5733 {
5734 inst.error = _("cannot combine pre- and post-indexing");
5735 return PARSE_OPERAND_FAIL;
5736 }
5737
5738 if (*p == '+') p++;
5739 else if (*p == '-') p++, inst.operands[i].negative = 1;
5740
5741 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5742 {
5743 /* We might be using the immediate for alignment already. If we
5744 are, OR the register number into the low-order bits. */
5745 if (inst.operands[i].immisalign)
5746 inst.operands[i].imm |= reg;
5747 else
5748 inst.operands[i].imm = reg;
5749 inst.operands[i].immisreg = 1;
5750
5751 if (skip_past_comma (&p) == SUCCESS)
5752 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5753 return PARSE_OPERAND_FAIL;
5754 }
5755 else
5756 {
5757 char *q = p;
5758
5759 if (inst.operands[i].negative)
5760 {
5761 inst.operands[i].negative = 0;
5762 p--;
5763 }
5764 if (my_get_expression (&inst.relocs[0].exp, &p, GE_IMM_PREFIX))
5765 return PARSE_OPERAND_FAIL;
5766 /* If the offset is 0, find out if it's a +0 or -0. */
5767 if (inst.relocs[0].exp.X_op == O_constant
5768 && inst.relocs[0].exp.X_add_number == 0)
5769 {
5770 skip_whitespace (q);
5771 if (*q == '#')
5772 {
5773 q++;
5774 skip_whitespace (q);
5775 }
5776 if (*q == '-')
5777 inst.operands[i].negative = 1;
5778 }
5779 }
5780 }
5781 }
5782
5783 /* If at this point neither .preind nor .postind is set, we have a
5784 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5785 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5786 {
5787 inst.operands[i].preind = 1;
5788 inst.relocs[0].exp.X_op = O_constant;
5789 inst.relocs[0].exp.X_add_number = 0;
5790 }
5791 *str = p;
5792 return PARSE_OPERAND_SUCCESS;
5793 }
5794
5795 static int
5796 parse_address (char **str, int i)
5797 {
5798 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5799 ? SUCCESS : FAIL;
5800 }
5801
5802 static parse_operand_result
5803 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5804 {
5805 return parse_address_main (str, i, 1, type);
5806 }
5807
5808 /* Parse an operand for a MOVW or MOVT instruction. */
5809 static int
5810 parse_half (char **str)
5811 {
5812 char * p;
5813
5814 p = *str;
5815 skip_past_char (&p, '#');
5816 if (strncasecmp (p, ":lower16:", 9) == 0)
5817 inst.relocs[0].type = BFD_RELOC_ARM_MOVW;
5818 else if (strncasecmp (p, ":upper16:", 9) == 0)
5819 inst.relocs[0].type = BFD_RELOC_ARM_MOVT;
5820
5821 if (inst.relocs[0].type != BFD_RELOC_UNUSED)
5822 {
5823 p += 9;
5824 skip_whitespace (p);
5825 }
5826
5827 if (my_get_expression (&inst.relocs[0].exp, &p, GE_NO_PREFIX))
5828 return FAIL;
5829
5830 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
5831 {
5832 if (inst.relocs[0].exp.X_op != O_constant)
5833 {
5834 inst.error = _("constant expression expected");
5835 return FAIL;
5836 }
5837 if (inst.relocs[0].exp.X_add_number < 0
5838 || inst.relocs[0].exp.X_add_number > 0xffff)
5839 {
5840 inst.error = _("immediate value out of range");
5841 return FAIL;
5842 }
5843 }
5844 *str = p;
5845 return SUCCESS;
5846 }
5847
5848 /* Miscellaneous. */
5849
5850 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5851 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5852 static int
5853 parse_psr (char **str, bfd_boolean lhs)
5854 {
5855 char *p;
5856 unsigned long psr_field;
5857 const struct asm_psr *psr;
5858 char *start;
5859 bfd_boolean is_apsr = FALSE;
5860 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
5861
5862 /* PR gas/12698: If the user has specified -march=all then m_profile will
5863 be TRUE, but we want to ignore it in this case as we are building for any
5864 CPU type, including non-m variants. */
5865 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
5866 m_profile = FALSE;
5867
5868 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5869 feature for ease of use and backwards compatibility. */
5870 p = *str;
5871 if (strncasecmp (p, "SPSR", 4) == 0)
5872 {
5873 if (m_profile)
5874 goto unsupported_psr;
5875
5876 psr_field = SPSR_BIT;
5877 }
5878 else if (strncasecmp (p, "CPSR", 4) == 0)
5879 {
5880 if (m_profile)
5881 goto unsupported_psr;
5882
5883 psr_field = 0;
5884 }
5885 else if (strncasecmp (p, "APSR", 4) == 0)
5886 {
5887 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5888 and ARMv7-R architecture CPUs. */
5889 is_apsr = TRUE;
5890 psr_field = 0;
5891 }
5892 else if (m_profile)
5893 {
5894 start = p;
5895 do
5896 p++;
5897 while (ISALNUM (*p) || *p == '_');
5898
5899 if (strncasecmp (start, "iapsr", 5) == 0
5900 || strncasecmp (start, "eapsr", 5) == 0
5901 || strncasecmp (start, "xpsr", 4) == 0
5902 || strncasecmp (start, "psr", 3) == 0)
5903 p = start + strcspn (start, "rR") + 1;
5904
5905 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5906 p - start);
5907
5908 if (!psr)
5909 return FAIL;
5910
5911 /* If APSR is being written, a bitfield may be specified. Note that
5912 APSR itself is handled above. */
5913 if (psr->field <= 3)
5914 {
5915 psr_field = psr->field;
5916 is_apsr = TRUE;
5917 goto check_suffix;
5918 }
5919
5920 *str = p;
5921 /* M-profile MSR instructions have the mask field set to "10", except
5922 *PSR variants which modify APSR, which may use a different mask (and
5923 have been handled already). Do that by setting the PSR_f field
5924 here. */
5925 return psr->field | (lhs ? PSR_f : 0);
5926 }
5927 else
5928 goto unsupported_psr;
5929
5930 p += 4;
5931 check_suffix:
5932 if (*p == '_')
5933 {
5934 /* A suffix follows. */
5935 p++;
5936 start = p;
5937
5938 do
5939 p++;
5940 while (ISALNUM (*p) || *p == '_');
5941
5942 if (is_apsr)
5943 {
5944 /* APSR uses a notation for bits, rather than fields. */
5945 unsigned int nzcvq_bits = 0;
5946 unsigned int g_bit = 0;
5947 char *bit;
5948
5949 for (bit = start; bit != p; bit++)
5950 {
5951 switch (TOLOWER (*bit))
5952 {
5953 case 'n':
5954 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5955 break;
5956
5957 case 'z':
5958 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5959 break;
5960
5961 case 'c':
5962 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5963 break;
5964
5965 case 'v':
5966 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5967 break;
5968
5969 case 'q':
5970 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5971 break;
5972
5973 case 'g':
5974 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5975 break;
5976
5977 default:
5978 inst.error = _("unexpected bit specified after APSR");
5979 return FAIL;
5980 }
5981 }
5982
5983 if (nzcvq_bits == 0x1f)
5984 psr_field |= PSR_f;
5985
5986 if (g_bit == 0x1)
5987 {
5988 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5989 {
5990 inst.error = _("selected processor does not "
5991 "support DSP extension");
5992 return FAIL;
5993 }
5994
5995 psr_field |= PSR_s;
5996 }
5997
5998 if ((nzcvq_bits & 0x20) != 0
5999 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
6000 || (g_bit & 0x2) != 0)
6001 {
6002 inst.error = _("bad bitmask specified after APSR");
6003 return FAIL;
6004 }
6005 }
6006 else
6007 {
6008 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
6009 p - start);
6010 if (!psr)
6011 goto error;
6012
6013 psr_field |= psr->field;
6014 }
6015 }
6016 else
6017 {
6018 if (ISALNUM (*p))
6019 goto error; /* Garbage after "[CS]PSR". */
6020
6021 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
6022 is deprecated, but allow it anyway. */
6023 if (is_apsr && lhs)
6024 {
6025 psr_field |= PSR_f;
6026 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6027 "deprecated"));
6028 }
6029 else if (!m_profile)
6030 /* These bits are never right for M-profile devices: don't set them
6031 (only code paths which read/write APSR reach here). */
6032 psr_field |= (PSR_c | PSR_f);
6033 }
6034 *str = p;
6035 return psr_field;
6036
6037 unsupported_psr:
6038 inst.error = _("selected processor does not support requested special "
6039 "purpose register");
6040 return FAIL;
6041
6042 error:
6043 inst.error = _("flag for {c}psr instruction expected");
6044 return FAIL;
6045 }
6046
6047 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6048 value suitable for splatting into the AIF field of the instruction. */
6049
6050 static int
6051 parse_cps_flags (char **str)
6052 {
6053 int val = 0;
6054 int saw_a_flag = 0;
6055 char *s = *str;
6056
6057 for (;;)
6058 switch (*s++)
6059 {
6060 case '\0': case ',':
6061 goto done;
6062
6063 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6064 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6065 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
6066
6067 default:
6068 inst.error = _("unrecognized CPS flag");
6069 return FAIL;
6070 }
6071
6072 done:
6073 if (saw_a_flag == 0)
6074 {
6075 inst.error = _("missing CPS flags");
6076 return FAIL;
6077 }
6078
6079 *str = s - 1;
6080 return val;
6081 }
6082
6083 /* Parse an endian specifier ("BE" or "LE", case insensitive);
6084 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
6085
6086 static int
6087 parse_endian_specifier (char **str)
6088 {
6089 int little_endian;
6090 char *s = *str;
6091
6092 if (strncasecmp (s, "BE", 2))
6093 little_endian = 0;
6094 else if (strncasecmp (s, "LE", 2))
6095 little_endian = 1;
6096 else
6097 {
6098 inst.error = _("valid endian specifiers are be or le");
6099 return FAIL;
6100 }
6101
6102 if (ISALNUM (s[2]) || s[2] == '_')
6103 {
6104 inst.error = _("valid endian specifiers are be or le");
6105 return FAIL;
6106 }
6107
6108 *str = s + 2;
6109 return little_endian;
6110 }
6111
6112 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6113 value suitable for poking into the rotate field of an sxt or sxta
6114 instruction, or FAIL on error. */
6115
6116 static int
6117 parse_ror (char **str)
6118 {
6119 int rot;
6120 char *s = *str;
6121
6122 if (strncasecmp (s, "ROR", 3) == 0)
6123 s += 3;
6124 else
6125 {
6126 inst.error = _("missing rotation field after comma");
6127 return FAIL;
6128 }
6129
6130 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6131 return FAIL;
6132
6133 switch (rot)
6134 {
6135 case 0: *str = s; return 0x0;
6136 case 8: *str = s; return 0x1;
6137 case 16: *str = s; return 0x2;
6138 case 24: *str = s; return 0x3;
6139
6140 default:
6141 inst.error = _("rotation can only be 0, 8, 16, or 24");
6142 return FAIL;
6143 }
6144 }
6145
6146 /* Parse a conditional code (from conds[] below). The value returned is in the
6147 range 0 .. 14, or FAIL. */
6148 static int
6149 parse_cond (char **str)
6150 {
6151 char *q;
6152 const struct asm_cond *c;
6153 int n;
6154 /* Condition codes are always 2 characters, so matching up to
6155 3 characters is sufficient. */
6156 char cond[3];
6157
6158 q = *str;
6159 n = 0;
6160 while (ISALPHA (*q) && n < 3)
6161 {
6162 cond[n] = TOLOWER (*q);
6163 q++;
6164 n++;
6165 }
6166
6167 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
6168 if (!c)
6169 {
6170 inst.error = _("condition required");
6171 return FAIL;
6172 }
6173
6174 *str = q;
6175 return c->value;
6176 }
6177
6178 /* Record a use of the given feature. */
6179 static void
6180 record_feature_use (const arm_feature_set *feature)
6181 {
6182 if (thumb_mode)
6183 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6184 else
6185 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6186 }
6187
6188 /* If the given feature is currently allowed, mark it as used and return TRUE.
6189 Return FALSE otherwise. */
6190 static bfd_boolean
6191 mark_feature_used (const arm_feature_set *feature)
6192 {
6193 /* Ensure the option is currently allowed. */
6194 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6195 return FALSE;
6196
6197 /* Add the appropriate architecture feature for the barrier option used. */
6198 record_feature_use (feature);
6199
6200 return TRUE;
6201 }
6202
6203 /* Parse an option for a barrier instruction. Returns the encoding for the
6204 option, or FAIL. */
6205 static int
6206 parse_barrier (char **str)
6207 {
6208 char *p, *q;
6209 const struct asm_barrier_opt *o;
6210
6211 p = q = *str;
6212 while (ISALPHA (*q))
6213 q++;
6214
6215 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
6216 q - p);
6217 if (!o)
6218 return FAIL;
6219
6220 if (!mark_feature_used (&o->arch))
6221 return FAIL;
6222
6223 *str = q;
6224 return o->value;
6225 }
6226
6227 /* Parse the operands of a table branch instruction. Similar to a memory
6228 operand. */
6229 static int
6230 parse_tb (char **str)
6231 {
6232 char * p = *str;
6233 int reg;
6234
6235 if (skip_past_char (&p, '[') == FAIL)
6236 {
6237 inst.error = _("'[' expected");
6238 return FAIL;
6239 }
6240
6241 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6242 {
6243 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6244 return FAIL;
6245 }
6246 inst.operands[0].reg = reg;
6247
6248 if (skip_past_comma (&p) == FAIL)
6249 {
6250 inst.error = _("',' expected");
6251 return FAIL;
6252 }
6253
6254 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6255 {
6256 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6257 return FAIL;
6258 }
6259 inst.operands[0].imm = reg;
6260
6261 if (skip_past_comma (&p) == SUCCESS)
6262 {
6263 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6264 return FAIL;
6265 if (inst.relocs[0].exp.X_add_number != 1)
6266 {
6267 inst.error = _("invalid shift");
6268 return FAIL;
6269 }
6270 inst.operands[0].shifted = 1;
6271 }
6272
6273 if (skip_past_char (&p, ']') == FAIL)
6274 {
6275 inst.error = _("']' expected");
6276 return FAIL;
6277 }
6278 *str = p;
6279 return SUCCESS;
6280 }
6281
6282 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6283 information on the types the operands can take and how they are encoded.
6284 Up to four operands may be read; this function handles setting the
6285 ".present" field for each read operand itself.
6286 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6287 else returns FAIL. */
6288
6289 static int
6290 parse_neon_mov (char **str, int *which_operand)
6291 {
6292 int i = *which_operand, val;
6293 enum arm_reg_type rtype;
6294 char *ptr = *str;
6295 struct neon_type_el optype;
6296
6297 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6298 {
6299 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6300 inst.operands[i].reg = val;
6301 inst.operands[i].isscalar = 1;
6302 inst.operands[i].vectype = optype;
6303 inst.operands[i++].present = 1;
6304
6305 if (skip_past_comma (&ptr) == FAIL)
6306 goto wanted_comma;
6307
6308 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6309 goto wanted_arm;
6310
6311 inst.operands[i].reg = val;
6312 inst.operands[i].isreg = 1;
6313 inst.operands[i].present = 1;
6314 }
6315 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6316 != FAIL)
6317 {
6318 /* Cases 0, 1, 2, 3, 5 (D only). */
6319 if (skip_past_comma (&ptr) == FAIL)
6320 goto wanted_comma;
6321
6322 inst.operands[i].reg = val;
6323 inst.operands[i].isreg = 1;
6324 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6325 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6326 inst.operands[i].isvec = 1;
6327 inst.operands[i].vectype = optype;
6328 inst.operands[i++].present = 1;
6329
6330 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6331 {
6332 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6333 Case 13: VMOV <Sd>, <Rm> */
6334 inst.operands[i].reg = val;
6335 inst.operands[i].isreg = 1;
6336 inst.operands[i].present = 1;
6337
6338 if (rtype == REG_TYPE_NQ)
6339 {
6340 first_error (_("can't use Neon quad register here"));
6341 return FAIL;
6342 }
6343 else if (rtype != REG_TYPE_VFS)
6344 {
6345 i++;
6346 if (skip_past_comma (&ptr) == FAIL)
6347 goto wanted_comma;
6348 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6349 goto wanted_arm;
6350 inst.operands[i].reg = val;
6351 inst.operands[i].isreg = 1;
6352 inst.operands[i].present = 1;
6353 }
6354 }
6355 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6356 &optype)) != FAIL)
6357 {
6358 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6359 Case 1: VMOV<c><q> <Dd>, <Dm>
6360 Case 8: VMOV.F32 <Sd>, <Sm>
6361 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6362
6363 inst.operands[i].reg = val;
6364 inst.operands[i].isreg = 1;
6365 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6366 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6367 inst.operands[i].isvec = 1;
6368 inst.operands[i].vectype = optype;
6369 inst.operands[i].present = 1;
6370
6371 if (skip_past_comma (&ptr) == SUCCESS)
6372 {
6373 /* Case 15. */
6374 i++;
6375
6376 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6377 goto wanted_arm;
6378
6379 inst.operands[i].reg = val;
6380 inst.operands[i].isreg = 1;
6381 inst.operands[i++].present = 1;
6382
6383 if (skip_past_comma (&ptr) == FAIL)
6384 goto wanted_comma;
6385
6386 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6387 goto wanted_arm;
6388
6389 inst.operands[i].reg = val;
6390 inst.operands[i].isreg = 1;
6391 inst.operands[i].present = 1;
6392 }
6393 }
6394 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6395 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6396 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6397 Case 10: VMOV.F32 <Sd>, #<imm>
6398 Case 11: VMOV.F64 <Dd>, #<imm> */
6399 inst.operands[i].immisfloat = 1;
6400 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6401 == SUCCESS)
6402 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6403 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6404 ;
6405 else
6406 {
6407 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6408 return FAIL;
6409 }
6410 }
6411 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6412 {
6413 /* Cases 6, 7. */
6414 inst.operands[i].reg = val;
6415 inst.operands[i].isreg = 1;
6416 inst.operands[i++].present = 1;
6417
6418 if (skip_past_comma (&ptr) == FAIL)
6419 goto wanted_comma;
6420
6421 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6422 {
6423 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6424 inst.operands[i].reg = val;
6425 inst.operands[i].isscalar = 1;
6426 inst.operands[i].present = 1;
6427 inst.operands[i].vectype = optype;
6428 }
6429 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6430 {
6431 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6432 inst.operands[i].reg = val;
6433 inst.operands[i].isreg = 1;
6434 inst.operands[i++].present = 1;
6435
6436 if (skip_past_comma (&ptr) == FAIL)
6437 goto wanted_comma;
6438
6439 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6440 == FAIL)
6441 {
6442 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6443 return FAIL;
6444 }
6445
6446 inst.operands[i].reg = val;
6447 inst.operands[i].isreg = 1;
6448 inst.operands[i].isvec = 1;
6449 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6450 inst.operands[i].vectype = optype;
6451 inst.operands[i].present = 1;
6452
6453 if (rtype == REG_TYPE_VFS)
6454 {
6455 /* Case 14. */
6456 i++;
6457 if (skip_past_comma (&ptr) == FAIL)
6458 goto wanted_comma;
6459 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6460 &optype)) == FAIL)
6461 {
6462 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6463 return FAIL;
6464 }
6465 inst.operands[i].reg = val;
6466 inst.operands[i].isreg = 1;
6467 inst.operands[i].isvec = 1;
6468 inst.operands[i].issingle = 1;
6469 inst.operands[i].vectype = optype;
6470 inst.operands[i].present = 1;
6471 }
6472 }
6473 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6474 != FAIL)
6475 {
6476 /* Case 13. */
6477 inst.operands[i].reg = val;
6478 inst.operands[i].isreg = 1;
6479 inst.operands[i].isvec = 1;
6480 inst.operands[i].issingle = 1;
6481 inst.operands[i].vectype = optype;
6482 inst.operands[i].present = 1;
6483 }
6484 }
6485 else
6486 {
6487 first_error (_("parse error"));
6488 return FAIL;
6489 }
6490
6491 /* Successfully parsed the operands. Update args. */
6492 *which_operand = i;
6493 *str = ptr;
6494 return SUCCESS;
6495
6496 wanted_comma:
6497 first_error (_("expected comma"));
6498 return FAIL;
6499
6500 wanted_arm:
6501 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6502 return FAIL;
6503 }
6504
6505 /* Use this macro when the operand constraints are different
6506 for ARM and THUMB (e.g. ldrd). */
6507 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6508 ((arm_operand) | ((thumb_operand) << 16))
6509
6510 /* Matcher codes for parse_operands. */
6511 enum operand_parse_code
6512 {
6513 OP_stop, /* end of line */
6514
6515 OP_RR, /* ARM register */
6516 OP_RRnpc, /* ARM register, not r15 */
6517 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6518 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6519 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6520 optional trailing ! */
6521 OP_RRw, /* ARM register, not r15, optional trailing ! */
6522 OP_RCP, /* Coprocessor number */
6523 OP_RCN, /* Coprocessor register */
6524 OP_RF, /* FPA register */
6525 OP_RVS, /* VFP single precision register */
6526 OP_RVD, /* VFP double precision register (0..15) */
6527 OP_RND, /* Neon double precision register (0..31) */
6528 OP_RNQ, /* Neon quad precision register */
6529 OP_RVSD, /* VFP single or double precision register */
6530 OP_RNSD, /* Neon single or double precision register */
6531 OP_RNDQ, /* Neon double or quad precision register */
6532 OP_RNSDQ, /* Neon single, double or quad precision register */
6533 OP_RNSC, /* Neon scalar D[X] */
6534 OP_RVC, /* VFP control register */
6535 OP_RMF, /* Maverick F register */
6536 OP_RMD, /* Maverick D register */
6537 OP_RMFX, /* Maverick FX register */
6538 OP_RMDX, /* Maverick DX register */
6539 OP_RMAX, /* Maverick AX register */
6540 OP_RMDS, /* Maverick DSPSC register */
6541 OP_RIWR, /* iWMMXt wR register */
6542 OP_RIWC, /* iWMMXt wC register */
6543 OP_RIWG, /* iWMMXt wCG register */
6544 OP_RXA, /* XScale accumulator register */
6545
6546 OP_REGLST, /* ARM register list */
6547 OP_VRSLST, /* VFP single-precision register list */
6548 OP_VRDLST, /* VFP double-precision register list */
6549 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6550 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6551 OP_NSTRLST, /* Neon element/structure list */
6552
6553 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6554 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6555 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
6556 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6557 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
6558 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6559 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6560 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6561 OP_VMOV, /* Neon VMOV operands. */
6562 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6563 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6564 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6565
6566 OP_I0, /* immediate zero */
6567 OP_I7, /* immediate value 0 .. 7 */
6568 OP_I15, /* 0 .. 15 */
6569 OP_I16, /* 1 .. 16 */
6570 OP_I16z, /* 0 .. 16 */
6571 OP_I31, /* 0 .. 31 */
6572 OP_I31w, /* 0 .. 31, optional trailing ! */
6573 OP_I32, /* 1 .. 32 */
6574 OP_I32z, /* 0 .. 32 */
6575 OP_I63, /* 0 .. 63 */
6576 OP_I63s, /* -64 .. 63 */
6577 OP_I64, /* 1 .. 64 */
6578 OP_I64z, /* 0 .. 64 */
6579 OP_I255, /* 0 .. 255 */
6580
6581 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6582 OP_I7b, /* 0 .. 7 */
6583 OP_I15b, /* 0 .. 15 */
6584 OP_I31b, /* 0 .. 31 */
6585
6586 OP_SH, /* shifter operand */
6587 OP_SHG, /* shifter operand with possible group relocation */
6588 OP_ADDR, /* Memory address expression (any mode) */
6589 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6590 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6591 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6592 OP_EXP, /* arbitrary expression */
6593 OP_EXPi, /* same, with optional immediate prefix */
6594 OP_EXPr, /* same, with optional relocation suffix */
6595 OP_EXPs, /* same, with optional non-first operand relocation suffix */
6596 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6597 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6598 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
6599
6600 OP_CPSF, /* CPS flags */
6601 OP_ENDI, /* Endianness specifier */
6602 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6603 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6604 OP_COND, /* conditional code */
6605 OP_TB, /* Table branch. */
6606
6607 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6608
6609 OP_RRnpc_I0, /* ARM register or literal 0 */
6610 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
6611 OP_RR_EXi, /* ARM register or expression with imm prefix */
6612 OP_RF_IF, /* FPA register or immediate */
6613 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6614 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6615
6616 /* Optional operands. */
6617 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6618 OP_oI31b, /* 0 .. 31 */
6619 OP_oI32b, /* 1 .. 32 */
6620 OP_oI32z, /* 0 .. 32 */
6621 OP_oIffffb, /* 0 .. 65535 */
6622 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6623
6624 OP_oRR, /* ARM register */
6625 OP_oRRnpc, /* ARM register, not the PC */
6626 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6627 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6628 OP_oRND, /* Optional Neon double precision register */
6629 OP_oRNQ, /* Optional Neon quad precision register */
6630 OP_oRNDQ, /* Optional Neon double or quad precision register */
6631 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6632 OP_oSHll, /* LSL immediate */
6633 OP_oSHar, /* ASR immediate */
6634 OP_oSHllar, /* LSL or ASR immediate */
6635 OP_oROR, /* ROR 0/8/16/24 */
6636 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6637
6638 /* Some pre-defined mixed (ARM/THUMB) operands. */
6639 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6640 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6641 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6642
6643 OP_FIRST_OPTIONAL = OP_oI7b
6644 };
6645
6646 /* Generic instruction operand parser. This does no encoding and no
6647 semantic validation; it merely squirrels values away in the inst
6648 structure. Returns SUCCESS or FAIL depending on whether the
6649 specified grammar matched. */
6650 static int
6651 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6652 {
6653 unsigned const int *upat = pattern;
6654 char *backtrack_pos = 0;
6655 const char *backtrack_error = 0;
6656 int i, val = 0, backtrack_index = 0;
6657 enum arm_reg_type rtype;
6658 parse_operand_result result;
6659 unsigned int op_parse_code;
6660
6661 #define po_char_or_fail(chr) \
6662 do \
6663 { \
6664 if (skip_past_char (&str, chr) == FAIL) \
6665 goto bad_args; \
6666 } \
6667 while (0)
6668
6669 #define po_reg_or_fail(regtype) \
6670 do \
6671 { \
6672 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6673 & inst.operands[i].vectype); \
6674 if (val == FAIL) \
6675 { \
6676 first_error (_(reg_expected_msgs[regtype])); \
6677 goto failure; \
6678 } \
6679 inst.operands[i].reg = val; \
6680 inst.operands[i].isreg = 1; \
6681 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6682 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6683 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6684 || rtype == REG_TYPE_VFD \
6685 || rtype == REG_TYPE_NQ); \
6686 } \
6687 while (0)
6688
6689 #define po_reg_or_goto(regtype, label) \
6690 do \
6691 { \
6692 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6693 & inst.operands[i].vectype); \
6694 if (val == FAIL) \
6695 goto label; \
6696 \
6697 inst.operands[i].reg = val; \
6698 inst.operands[i].isreg = 1; \
6699 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6700 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6701 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6702 || rtype == REG_TYPE_VFD \
6703 || rtype == REG_TYPE_NQ); \
6704 } \
6705 while (0)
6706
6707 #define po_imm_or_fail(min, max, popt) \
6708 do \
6709 { \
6710 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6711 goto failure; \
6712 inst.operands[i].imm = val; \
6713 } \
6714 while (0)
6715
6716 #define po_scalar_or_goto(elsz, label) \
6717 do \
6718 { \
6719 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6720 if (val == FAIL) \
6721 goto label; \
6722 inst.operands[i].reg = val; \
6723 inst.operands[i].isscalar = 1; \
6724 } \
6725 while (0)
6726
6727 #define po_misc_or_fail(expr) \
6728 do \
6729 { \
6730 if (expr) \
6731 goto failure; \
6732 } \
6733 while (0)
6734
6735 #define po_misc_or_fail_no_backtrack(expr) \
6736 do \
6737 { \
6738 result = expr; \
6739 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6740 backtrack_pos = 0; \
6741 if (result != PARSE_OPERAND_SUCCESS) \
6742 goto failure; \
6743 } \
6744 while (0)
6745
6746 #define po_barrier_or_imm(str) \
6747 do \
6748 { \
6749 val = parse_barrier (&str); \
6750 if (val == FAIL && ! ISALPHA (*str)) \
6751 goto immediate; \
6752 if (val == FAIL \
6753 /* ISB can only take SY as an option. */ \
6754 || ((inst.instruction & 0xf0) == 0x60 \
6755 && val != 0xf)) \
6756 { \
6757 inst.error = _("invalid barrier type"); \
6758 backtrack_pos = 0; \
6759 goto failure; \
6760 } \
6761 } \
6762 while (0)
6763
6764 skip_whitespace (str);
6765
6766 for (i = 0; upat[i] != OP_stop; i++)
6767 {
6768 op_parse_code = upat[i];
6769 if (op_parse_code >= 1<<16)
6770 op_parse_code = thumb ? (op_parse_code >> 16)
6771 : (op_parse_code & ((1<<16)-1));
6772
6773 if (op_parse_code >= OP_FIRST_OPTIONAL)
6774 {
6775 /* Remember where we are in case we need to backtrack. */
6776 gas_assert (!backtrack_pos);
6777 backtrack_pos = str;
6778 backtrack_error = inst.error;
6779 backtrack_index = i;
6780 }
6781
6782 if (i > 0 && (i > 1 || inst.operands[0].present))
6783 po_char_or_fail (',');
6784
6785 switch (op_parse_code)
6786 {
6787 /* Registers */
6788 case OP_oRRnpc:
6789 case OP_oRRnpcsp:
6790 case OP_RRnpc:
6791 case OP_RRnpcsp:
6792 case OP_oRR:
6793 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6794 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6795 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6796 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6797 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6798 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6799 case OP_oRND:
6800 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6801 case OP_RVC:
6802 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6803 break;
6804 /* Also accept generic coprocessor regs for unknown registers. */
6805 coproc_reg:
6806 po_reg_or_fail (REG_TYPE_CN);
6807 break;
6808 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6809 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6810 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6811 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6812 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6813 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6814 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6815 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6816 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6817 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6818 case OP_oRNQ:
6819 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6820 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
6821 case OP_oRNDQ:
6822 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6823 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6824 case OP_oRNSDQ:
6825 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6826
6827 /* Neon scalar. Using an element size of 8 means that some invalid
6828 scalars are accepted here, so deal with those in later code. */
6829 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6830
6831 case OP_RNDQ_I0:
6832 {
6833 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6834 break;
6835 try_imm0:
6836 po_imm_or_fail (0, 0, TRUE);
6837 }
6838 break;
6839
6840 case OP_RVSD_I0:
6841 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6842 break;
6843
6844 case OP_RSVD_FI0:
6845 {
6846 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6847 break;
6848 try_ifimm0:
6849 if (parse_ifimm_zero (&str))
6850 inst.operands[i].imm = 0;
6851 else
6852 {
6853 inst.error
6854 = _("only floating point zero is allowed as immediate value");
6855 goto failure;
6856 }
6857 }
6858 break;
6859
6860 case OP_RR_RNSC:
6861 {
6862 po_scalar_or_goto (8, try_rr);
6863 break;
6864 try_rr:
6865 po_reg_or_fail (REG_TYPE_RN);
6866 }
6867 break;
6868
6869 case OP_RNSDQ_RNSC:
6870 {
6871 po_scalar_or_goto (8, try_nsdq);
6872 break;
6873 try_nsdq:
6874 po_reg_or_fail (REG_TYPE_NSDQ);
6875 }
6876 break;
6877
6878 case OP_RNSD_RNSC:
6879 {
6880 po_scalar_or_goto (8, try_s_scalar);
6881 break;
6882 try_s_scalar:
6883 po_scalar_or_goto (4, try_nsd);
6884 break;
6885 try_nsd:
6886 po_reg_or_fail (REG_TYPE_NSD);
6887 }
6888 break;
6889
6890 case OP_RNDQ_RNSC:
6891 {
6892 po_scalar_or_goto (8, try_ndq);
6893 break;
6894 try_ndq:
6895 po_reg_or_fail (REG_TYPE_NDQ);
6896 }
6897 break;
6898
6899 case OP_RND_RNSC:
6900 {
6901 po_scalar_or_goto (8, try_vfd);
6902 break;
6903 try_vfd:
6904 po_reg_or_fail (REG_TYPE_VFD);
6905 }
6906 break;
6907
6908 case OP_VMOV:
6909 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6910 not careful then bad things might happen. */
6911 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6912 break;
6913
6914 case OP_RNDQ_Ibig:
6915 {
6916 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6917 break;
6918 try_immbig:
6919 /* There's a possibility of getting a 64-bit immediate here, so
6920 we need special handling. */
6921 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6922 == FAIL)
6923 {
6924 inst.error = _("immediate value is out of range");
6925 goto failure;
6926 }
6927 }
6928 break;
6929
6930 case OP_RNDQ_I63b:
6931 {
6932 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6933 break;
6934 try_shimm:
6935 po_imm_or_fail (0, 63, TRUE);
6936 }
6937 break;
6938
6939 case OP_RRnpcb:
6940 po_char_or_fail ('[');
6941 po_reg_or_fail (REG_TYPE_RN);
6942 po_char_or_fail (']');
6943 break;
6944
6945 case OP_RRnpctw:
6946 case OP_RRw:
6947 case OP_oRRw:
6948 po_reg_or_fail (REG_TYPE_RN);
6949 if (skip_past_char (&str, '!') == SUCCESS)
6950 inst.operands[i].writeback = 1;
6951 break;
6952
6953 /* Immediates */
6954 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6955 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6956 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6957 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6958 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6959 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6960 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6961 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6962 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6963 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6964 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6965 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6966
6967 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6968 case OP_oI7b:
6969 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6970 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6971 case OP_oI31b:
6972 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6973 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6974 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
6975 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6976
6977 /* Immediate variants */
6978 case OP_oI255c:
6979 po_char_or_fail ('{');
6980 po_imm_or_fail (0, 255, TRUE);
6981 po_char_or_fail ('}');
6982 break;
6983
6984 case OP_I31w:
6985 /* The expression parser chokes on a trailing !, so we have
6986 to find it first and zap it. */
6987 {
6988 char *s = str;
6989 while (*s && *s != ',')
6990 s++;
6991 if (s[-1] == '!')
6992 {
6993 s[-1] = '\0';
6994 inst.operands[i].writeback = 1;
6995 }
6996 po_imm_or_fail (0, 31, TRUE);
6997 if (str == s - 1)
6998 str = s;
6999 }
7000 break;
7001
7002 /* Expressions */
7003 case OP_EXPi: EXPi:
7004 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7005 GE_OPT_PREFIX));
7006 break;
7007
7008 case OP_EXP:
7009 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7010 GE_NO_PREFIX));
7011 break;
7012
7013 case OP_EXPr: EXPr:
7014 po_misc_or_fail (my_get_expression (&inst.relocs[0].exp, &str,
7015 GE_NO_PREFIX));
7016 if (inst.relocs[0].exp.X_op == O_symbol)
7017 {
7018 val = parse_reloc (&str);
7019 if (val == -1)
7020 {
7021 inst.error = _("unrecognized relocation suffix");
7022 goto failure;
7023 }
7024 else if (val != BFD_RELOC_UNUSED)
7025 {
7026 inst.operands[i].imm = val;
7027 inst.operands[i].hasreloc = 1;
7028 }
7029 }
7030 break;
7031
7032 case OP_EXPs:
7033 po_misc_or_fail (my_get_expression (&inst.relocs[i].exp, &str,
7034 GE_NO_PREFIX));
7035 if (inst.relocs[i].exp.X_op == O_symbol)
7036 {
7037 inst.operands[i].hasreloc = 1;
7038 }
7039 else if (inst.relocs[i].exp.X_op == O_constant)
7040 {
7041 inst.operands[i].imm = inst.relocs[i].exp.X_add_number;
7042 inst.operands[i].hasreloc = 0;
7043 }
7044 break;
7045
7046 /* Operand for MOVW or MOVT. */
7047 case OP_HALF:
7048 po_misc_or_fail (parse_half (&str));
7049 break;
7050
7051 /* Register or expression. */
7052 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7053 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
7054
7055 /* Register or immediate. */
7056 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7057 I0: po_imm_or_fail (0, 0, FALSE); break;
7058
7059 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7060 IF:
7061 if (!is_immediate_prefix (*str))
7062 goto bad_args;
7063 str++;
7064 val = parse_fpa_immediate (&str);
7065 if (val == FAIL)
7066 goto failure;
7067 /* FPA immediates are encoded as registers 8-15.
7068 parse_fpa_immediate has already applied the offset. */
7069 inst.operands[i].reg = val;
7070 inst.operands[i].isreg = 1;
7071 break;
7072
7073 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7074 I32z: po_imm_or_fail (0, 32, FALSE); break;
7075
7076 /* Two kinds of register. */
7077 case OP_RIWR_RIWC:
7078 {
7079 struct reg_entry *rege = arm_reg_parse_multi (&str);
7080 if (!rege
7081 || (rege->type != REG_TYPE_MMXWR
7082 && rege->type != REG_TYPE_MMXWC
7083 && rege->type != REG_TYPE_MMXWCG))
7084 {
7085 inst.error = _("iWMMXt data or control register expected");
7086 goto failure;
7087 }
7088 inst.operands[i].reg = rege->number;
7089 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7090 }
7091 break;
7092
7093 case OP_RIWC_RIWG:
7094 {
7095 struct reg_entry *rege = arm_reg_parse_multi (&str);
7096 if (!rege
7097 || (rege->type != REG_TYPE_MMXWC
7098 && rege->type != REG_TYPE_MMXWCG))
7099 {
7100 inst.error = _("iWMMXt control register expected");
7101 goto failure;
7102 }
7103 inst.operands[i].reg = rege->number;
7104 inst.operands[i].isreg = 1;
7105 }
7106 break;
7107
7108 /* Misc */
7109 case OP_CPSF: val = parse_cps_flags (&str); break;
7110 case OP_ENDI: val = parse_endian_specifier (&str); break;
7111 case OP_oROR: val = parse_ror (&str); break;
7112 case OP_COND: val = parse_cond (&str); break;
7113 case OP_oBARRIER_I15:
7114 po_barrier_or_imm (str); break;
7115 immediate:
7116 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
7117 goto failure;
7118 break;
7119
7120 case OP_wPSR:
7121 case OP_rPSR:
7122 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7123 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7124 {
7125 inst.error = _("Banked registers are not available with this "
7126 "architecture.");
7127 goto failure;
7128 }
7129 break;
7130 try_psr:
7131 val = parse_psr (&str, op_parse_code == OP_wPSR);
7132 break;
7133
7134 case OP_APSR_RR:
7135 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7136 break;
7137 try_apsr:
7138 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7139 instruction). */
7140 if (strncasecmp (str, "APSR_", 5) == 0)
7141 {
7142 unsigned found = 0;
7143 str += 5;
7144 while (found < 15)
7145 switch (*str++)
7146 {
7147 case 'c': found = (found & 1) ? 16 : found | 1; break;
7148 case 'n': found = (found & 2) ? 16 : found | 2; break;
7149 case 'z': found = (found & 4) ? 16 : found | 4; break;
7150 case 'v': found = (found & 8) ? 16 : found | 8; break;
7151 default: found = 16;
7152 }
7153 if (found != 15)
7154 goto failure;
7155 inst.operands[i].isvec = 1;
7156 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7157 inst.operands[i].reg = REG_PC;
7158 }
7159 else
7160 goto failure;
7161 break;
7162
7163 case OP_TB:
7164 po_misc_or_fail (parse_tb (&str));
7165 break;
7166
7167 /* Register lists. */
7168 case OP_REGLST:
7169 val = parse_reg_list (&str);
7170 if (*str == '^')
7171 {
7172 inst.operands[i].writeback = 1;
7173 str++;
7174 }
7175 break;
7176
7177 case OP_VRSLST:
7178 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
7179 break;
7180
7181 case OP_VRDLST:
7182 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
7183 break;
7184
7185 case OP_VRSDLST:
7186 /* Allow Q registers too. */
7187 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7188 REGLIST_NEON_D);
7189 if (val == FAIL)
7190 {
7191 inst.error = NULL;
7192 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7193 REGLIST_VFP_S);
7194 inst.operands[i].issingle = 1;
7195 }
7196 break;
7197
7198 case OP_NRDLST:
7199 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7200 REGLIST_NEON_D);
7201 break;
7202
7203 case OP_NSTRLST:
7204 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7205 &inst.operands[i].vectype);
7206 break;
7207
7208 /* Addressing modes */
7209 case OP_ADDR:
7210 po_misc_or_fail (parse_address (&str, i));
7211 break;
7212
7213 case OP_ADDRGLDR:
7214 po_misc_or_fail_no_backtrack (
7215 parse_address_group_reloc (&str, i, GROUP_LDR));
7216 break;
7217
7218 case OP_ADDRGLDRS:
7219 po_misc_or_fail_no_backtrack (
7220 parse_address_group_reloc (&str, i, GROUP_LDRS));
7221 break;
7222
7223 case OP_ADDRGLDC:
7224 po_misc_or_fail_no_backtrack (
7225 parse_address_group_reloc (&str, i, GROUP_LDC));
7226 break;
7227
7228 case OP_SH:
7229 po_misc_or_fail (parse_shifter_operand (&str, i));
7230 break;
7231
7232 case OP_SHG:
7233 po_misc_or_fail_no_backtrack (
7234 parse_shifter_operand_group_reloc (&str, i));
7235 break;
7236
7237 case OP_oSHll:
7238 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7239 break;
7240
7241 case OP_oSHar:
7242 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7243 break;
7244
7245 case OP_oSHllar:
7246 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7247 break;
7248
7249 default:
7250 as_fatal (_("unhandled operand code %d"), op_parse_code);
7251 }
7252
7253 /* Various value-based sanity checks and shared operations. We
7254 do not signal immediate failures for the register constraints;
7255 this allows a syntax error to take precedence. */
7256 switch (op_parse_code)
7257 {
7258 case OP_oRRnpc:
7259 case OP_RRnpc:
7260 case OP_RRnpcb:
7261 case OP_RRw:
7262 case OP_oRRw:
7263 case OP_RRnpc_I0:
7264 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7265 inst.error = BAD_PC;
7266 break;
7267
7268 case OP_oRRnpcsp:
7269 case OP_RRnpcsp:
7270 if (inst.operands[i].isreg)
7271 {
7272 if (inst.operands[i].reg == REG_PC)
7273 inst.error = BAD_PC;
7274 else if (inst.operands[i].reg == REG_SP
7275 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7276 relaxed since ARMv8-A. */
7277 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7278 {
7279 gas_assert (thumb);
7280 inst.error = BAD_SP;
7281 }
7282 }
7283 break;
7284
7285 case OP_RRnpctw:
7286 if (inst.operands[i].isreg
7287 && inst.operands[i].reg == REG_PC
7288 && (inst.operands[i].writeback || thumb))
7289 inst.error = BAD_PC;
7290 break;
7291
7292 case OP_CPSF:
7293 case OP_ENDI:
7294 case OP_oROR:
7295 case OP_wPSR:
7296 case OP_rPSR:
7297 case OP_COND:
7298 case OP_oBARRIER_I15:
7299 case OP_REGLST:
7300 case OP_VRSLST:
7301 case OP_VRDLST:
7302 case OP_VRSDLST:
7303 case OP_NRDLST:
7304 case OP_NSTRLST:
7305 if (val == FAIL)
7306 goto failure;
7307 inst.operands[i].imm = val;
7308 break;
7309
7310 default:
7311 break;
7312 }
7313
7314 /* If we get here, this operand was successfully parsed. */
7315 inst.operands[i].present = 1;
7316 continue;
7317
7318 bad_args:
7319 inst.error = BAD_ARGS;
7320
7321 failure:
7322 if (!backtrack_pos)
7323 {
7324 /* The parse routine should already have set inst.error, but set a
7325 default here just in case. */
7326 if (!inst.error)
7327 inst.error = _("syntax error");
7328 return FAIL;
7329 }
7330
7331 /* Do not backtrack over a trailing optional argument that
7332 absorbed some text. We will only fail again, with the
7333 'garbage following instruction' error message, which is
7334 probably less helpful than the current one. */
7335 if (backtrack_index == i && backtrack_pos != str
7336 && upat[i+1] == OP_stop)
7337 {
7338 if (!inst.error)
7339 inst.error = _("syntax error");
7340 return FAIL;
7341 }
7342
7343 /* Try again, skipping the optional argument at backtrack_pos. */
7344 str = backtrack_pos;
7345 inst.error = backtrack_error;
7346 inst.operands[backtrack_index].present = 0;
7347 i = backtrack_index;
7348 backtrack_pos = 0;
7349 }
7350
7351 /* Check that we have parsed all the arguments. */
7352 if (*str != '\0' && !inst.error)
7353 inst.error = _("garbage following instruction");
7354
7355 return inst.error ? FAIL : SUCCESS;
7356 }
7357
7358 #undef po_char_or_fail
7359 #undef po_reg_or_fail
7360 #undef po_reg_or_goto
7361 #undef po_imm_or_fail
7362 #undef po_scalar_or_fail
7363 #undef po_barrier_or_imm
7364
7365 /* Shorthand macro for instruction encoding functions issuing errors. */
7366 #define constraint(expr, err) \
7367 do \
7368 { \
7369 if (expr) \
7370 { \
7371 inst.error = err; \
7372 return; \
7373 } \
7374 } \
7375 while (0)
7376
7377 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7378 instructions are unpredictable if these registers are used. This
7379 is the BadReg predicate in ARM's Thumb-2 documentation.
7380
7381 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7382 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7383 #define reject_bad_reg(reg) \
7384 do \
7385 if (reg == REG_PC) \
7386 { \
7387 inst.error = BAD_PC; \
7388 return; \
7389 } \
7390 else if (reg == REG_SP \
7391 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7392 { \
7393 inst.error = BAD_SP; \
7394 return; \
7395 } \
7396 while (0)
7397
7398 /* If REG is R13 (the stack pointer), warn that its use is
7399 deprecated. */
7400 #define warn_deprecated_sp(reg) \
7401 do \
7402 if (warn_on_deprecated && reg == REG_SP) \
7403 as_tsktsk (_("use of r13 is deprecated")); \
7404 while (0)
7405
7406 /* Functions for operand encoding. ARM, then Thumb. */
7407
7408 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
7409
7410 /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7411
7412 The only binary encoding difference is the Coprocessor number. Coprocessor
7413 9 is used for half-precision calculations or conversions. The format of the
7414 instruction is the same as the equivalent Coprocessor 10 instruction that
7415 exists for Single-Precision operation. */
7416
7417 static void
7418 do_scalar_fp16_v82_encode (void)
7419 {
7420 if (inst.cond != COND_ALWAYS)
7421 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7422 " the behaviour is UNPREDICTABLE"));
7423 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7424 _(BAD_FP16));
7425
7426 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7427 mark_feature_used (&arm_ext_fp16);
7428 }
7429
7430 /* If VAL can be encoded in the immediate field of an ARM instruction,
7431 return the encoded form. Otherwise, return FAIL. */
7432
7433 static unsigned int
7434 encode_arm_immediate (unsigned int val)
7435 {
7436 unsigned int a, i;
7437
7438 if (val <= 0xff)
7439 return val;
7440
7441 for (i = 2; i < 32; i += 2)
7442 if ((a = rotate_left (val, i)) <= 0xff)
7443 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7444
7445 return FAIL;
7446 }
7447
7448 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7449 return the encoded form. Otherwise, return FAIL. */
7450 static unsigned int
7451 encode_thumb32_immediate (unsigned int val)
7452 {
7453 unsigned int a, i;
7454
7455 if (val <= 0xff)
7456 return val;
7457
7458 for (i = 1; i <= 24; i++)
7459 {
7460 a = val >> i;
7461 if ((val & ~(0xff << i)) == 0)
7462 return ((val >> i) & 0x7f) | ((32 - i) << 7);
7463 }
7464
7465 a = val & 0xff;
7466 if (val == ((a << 16) | a))
7467 return 0x100 | a;
7468 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7469 return 0x300 | a;
7470
7471 a = val & 0xff00;
7472 if (val == ((a << 16) | a))
7473 return 0x200 | (a >> 8);
7474
7475 return FAIL;
7476 }
7477 /* Encode a VFP SP or DP register number into inst.instruction. */
7478
7479 static void
7480 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7481 {
7482 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7483 && reg > 15)
7484 {
7485 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
7486 {
7487 if (thumb_mode)
7488 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7489 fpu_vfp_ext_d32);
7490 else
7491 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7492 fpu_vfp_ext_d32);
7493 }
7494 else
7495 {
7496 first_error (_("D register out of range for selected VFP version"));
7497 return;
7498 }
7499 }
7500
7501 switch (pos)
7502 {
7503 case VFP_REG_Sd:
7504 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7505 break;
7506
7507 case VFP_REG_Sn:
7508 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7509 break;
7510
7511 case VFP_REG_Sm:
7512 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7513 break;
7514
7515 case VFP_REG_Dd:
7516 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7517 break;
7518
7519 case VFP_REG_Dn:
7520 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7521 break;
7522
7523 case VFP_REG_Dm:
7524 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7525 break;
7526
7527 default:
7528 abort ();
7529 }
7530 }
7531
7532 /* Encode a <shift> in an ARM-format instruction. The immediate,
7533 if any, is handled by md_apply_fix. */
7534 static void
7535 encode_arm_shift (int i)
7536 {
7537 /* register-shifted register. */
7538 if (inst.operands[i].immisreg)
7539 {
7540 int op_index;
7541 for (op_index = 0; op_index <= i; ++op_index)
7542 {
7543 /* Check the operand only when it's presented. In pre-UAL syntax,
7544 if the destination register is the same as the first operand, two
7545 register form of the instruction can be used. */
7546 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7547 && inst.operands[op_index].reg == REG_PC)
7548 as_warn (UNPRED_REG ("r15"));
7549 }
7550
7551 if (inst.operands[i].imm == REG_PC)
7552 as_warn (UNPRED_REG ("r15"));
7553 }
7554
7555 if (inst.operands[i].shift_kind == SHIFT_RRX)
7556 inst.instruction |= SHIFT_ROR << 5;
7557 else
7558 {
7559 inst.instruction |= inst.operands[i].shift_kind << 5;
7560 if (inst.operands[i].immisreg)
7561 {
7562 inst.instruction |= SHIFT_BY_REG;
7563 inst.instruction |= inst.operands[i].imm << 8;
7564 }
7565 else
7566 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
7567 }
7568 }
7569
7570 static void
7571 encode_arm_shifter_operand (int i)
7572 {
7573 if (inst.operands[i].isreg)
7574 {
7575 inst.instruction |= inst.operands[i].reg;
7576 encode_arm_shift (i);
7577 }
7578 else
7579 {
7580 inst.instruction |= INST_IMMEDIATE;
7581 if (inst.relocs[0].type != BFD_RELOC_ARM_IMMEDIATE)
7582 inst.instruction |= inst.operands[i].imm;
7583 }
7584 }
7585
7586 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7587 static void
7588 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7589 {
7590 /* PR 14260:
7591 Generate an error if the operand is not a register. */
7592 constraint (!inst.operands[i].isreg,
7593 _("Instruction does not support =N addresses"));
7594
7595 inst.instruction |= inst.operands[i].reg << 16;
7596
7597 if (inst.operands[i].preind)
7598 {
7599 if (is_t)
7600 {
7601 inst.error = _("instruction does not accept preindexed addressing");
7602 return;
7603 }
7604 inst.instruction |= PRE_INDEX;
7605 if (inst.operands[i].writeback)
7606 inst.instruction |= WRITE_BACK;
7607
7608 }
7609 else if (inst.operands[i].postind)
7610 {
7611 gas_assert (inst.operands[i].writeback);
7612 if (is_t)
7613 inst.instruction |= WRITE_BACK;
7614 }
7615 else /* unindexed - only for coprocessor */
7616 {
7617 inst.error = _("instruction does not accept unindexed addressing");
7618 return;
7619 }
7620
7621 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7622 && (((inst.instruction & 0x000f0000) >> 16)
7623 == ((inst.instruction & 0x0000f000) >> 12)))
7624 as_warn ((inst.instruction & LOAD_BIT)
7625 ? _("destination register same as write-back base")
7626 : _("source register same as write-back base"));
7627 }
7628
7629 /* inst.operands[i] was set up by parse_address. Encode it into an
7630 ARM-format mode 2 load or store instruction. If is_t is true,
7631 reject forms that cannot be used with a T instruction (i.e. not
7632 post-indexed). */
7633 static void
7634 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7635 {
7636 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7637
7638 encode_arm_addr_mode_common (i, is_t);
7639
7640 if (inst.operands[i].immisreg)
7641 {
7642 constraint ((inst.operands[i].imm == REG_PC
7643 || (is_pc && inst.operands[i].writeback)),
7644 BAD_PC_ADDRESSING);
7645 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7646 inst.instruction |= inst.operands[i].imm;
7647 if (!inst.operands[i].negative)
7648 inst.instruction |= INDEX_UP;
7649 if (inst.operands[i].shifted)
7650 {
7651 if (inst.operands[i].shift_kind == SHIFT_RRX)
7652 inst.instruction |= SHIFT_ROR << 5;
7653 else
7654 {
7655 inst.instruction |= inst.operands[i].shift_kind << 5;
7656 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
7657 }
7658 }
7659 }
7660 else /* immediate offset in inst.relocs[0] */
7661 {
7662 if (is_pc && !inst.relocs[0].pc_rel)
7663 {
7664 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7665
7666 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7667 cannot use PC in addressing.
7668 PC cannot be used in writeback addressing, either. */
7669 constraint ((is_t || inst.operands[i].writeback),
7670 BAD_PC_ADDRESSING);
7671
7672 /* Use of PC in str is deprecated for ARMv7. */
7673 if (warn_on_deprecated
7674 && !is_load
7675 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7676 as_tsktsk (_("use of PC in this instruction is deprecated"));
7677 }
7678
7679 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
7680 {
7681 /* Prefer + for zero encoded value. */
7682 if (!inst.operands[i].negative)
7683 inst.instruction |= INDEX_UP;
7684 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM;
7685 }
7686 }
7687 }
7688
7689 /* inst.operands[i] was set up by parse_address. Encode it into an
7690 ARM-format mode 3 load or store instruction. Reject forms that
7691 cannot be used with such instructions. If is_t is true, reject
7692 forms that cannot be used with a T instruction (i.e. not
7693 post-indexed). */
7694 static void
7695 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7696 {
7697 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7698 {
7699 inst.error = _("instruction does not accept scaled register index");
7700 return;
7701 }
7702
7703 encode_arm_addr_mode_common (i, is_t);
7704
7705 if (inst.operands[i].immisreg)
7706 {
7707 constraint ((inst.operands[i].imm == REG_PC
7708 || (is_t && inst.operands[i].reg == REG_PC)),
7709 BAD_PC_ADDRESSING);
7710 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7711 BAD_PC_WRITEBACK);
7712 inst.instruction |= inst.operands[i].imm;
7713 if (!inst.operands[i].negative)
7714 inst.instruction |= INDEX_UP;
7715 }
7716 else /* immediate offset in inst.relocs[0] */
7717 {
7718 constraint ((inst.operands[i].reg == REG_PC && !inst.relocs[0].pc_rel
7719 && inst.operands[i].writeback),
7720 BAD_PC_WRITEBACK);
7721 inst.instruction |= HWOFFSET_IMM;
7722 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
7723 {
7724 /* Prefer + for zero encoded value. */
7725 if (!inst.operands[i].negative)
7726 inst.instruction |= INDEX_UP;
7727
7728 inst.relocs[0].type = BFD_RELOC_ARM_OFFSET_IMM8;
7729 }
7730 }
7731 }
7732
7733 /* Write immediate bits [7:0] to the following locations:
7734
7735 |28/24|23 19|18 16|15 4|3 0|
7736 | 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|
7737
7738 This function is used by VMOV/VMVN/VORR/VBIC. */
7739
7740 static void
7741 neon_write_immbits (unsigned immbits)
7742 {
7743 inst.instruction |= immbits & 0xf;
7744 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7745 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7746 }
7747
7748 /* Invert low-order SIZE bits of XHI:XLO. */
7749
7750 static void
7751 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7752 {
7753 unsigned immlo = xlo ? *xlo : 0;
7754 unsigned immhi = xhi ? *xhi : 0;
7755
7756 switch (size)
7757 {
7758 case 8:
7759 immlo = (~immlo) & 0xff;
7760 break;
7761
7762 case 16:
7763 immlo = (~immlo) & 0xffff;
7764 break;
7765
7766 case 64:
7767 immhi = (~immhi) & 0xffffffff;
7768 /* fall through. */
7769
7770 case 32:
7771 immlo = (~immlo) & 0xffffffff;
7772 break;
7773
7774 default:
7775 abort ();
7776 }
7777
7778 if (xlo)
7779 *xlo = immlo;
7780
7781 if (xhi)
7782 *xhi = immhi;
7783 }
7784
7785 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7786 A, B, C, D. */
7787
7788 static int
7789 neon_bits_same_in_bytes (unsigned imm)
7790 {
7791 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7792 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7793 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7794 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7795 }
7796
7797 /* For immediate of above form, return 0bABCD. */
7798
7799 static unsigned
7800 neon_squash_bits (unsigned imm)
7801 {
7802 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7803 | ((imm & 0x01000000) >> 21);
7804 }
7805
7806 /* Compress quarter-float representation to 0b...000 abcdefgh. */
7807
7808 static unsigned
7809 neon_qfloat_bits (unsigned imm)
7810 {
7811 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7812 }
7813
7814 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7815 the instruction. *OP is passed as the initial value of the op field, and
7816 may be set to a different value depending on the constant (i.e.
7817 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7818 MVN). If the immediate looks like a repeated pattern then also
7819 try smaller element sizes. */
7820
7821 static int
7822 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7823 unsigned *immbits, int *op, int size,
7824 enum neon_el_type type)
7825 {
7826 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7827 float. */
7828 if (type == NT_float && !float_p)
7829 return FAIL;
7830
7831 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
7832 {
7833 if (size != 32 || *op == 1)
7834 return FAIL;
7835 *immbits = neon_qfloat_bits (immlo);
7836 return 0xf;
7837 }
7838
7839 if (size == 64)
7840 {
7841 if (neon_bits_same_in_bytes (immhi)
7842 && neon_bits_same_in_bytes (immlo))
7843 {
7844 if (*op == 1)
7845 return FAIL;
7846 *immbits = (neon_squash_bits (immhi) << 4)
7847 | neon_squash_bits (immlo);
7848 *op = 1;
7849 return 0xe;
7850 }
7851
7852 if (immhi != immlo)
7853 return FAIL;
7854 }
7855
7856 if (size >= 32)
7857 {
7858 if (immlo == (immlo & 0x000000ff))
7859 {
7860 *immbits = immlo;
7861 return 0x0;
7862 }
7863 else if (immlo == (immlo & 0x0000ff00))
7864 {
7865 *immbits = immlo >> 8;
7866 return 0x2;
7867 }
7868 else if (immlo == (immlo & 0x00ff0000))
7869 {
7870 *immbits = immlo >> 16;
7871 return 0x4;
7872 }
7873 else if (immlo == (immlo & 0xff000000))
7874 {
7875 *immbits = immlo >> 24;
7876 return 0x6;
7877 }
7878 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7879 {
7880 *immbits = (immlo >> 8) & 0xff;
7881 return 0xc;
7882 }
7883 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7884 {
7885 *immbits = (immlo >> 16) & 0xff;
7886 return 0xd;
7887 }
7888
7889 if ((immlo & 0xffff) != (immlo >> 16))
7890 return FAIL;
7891 immlo &= 0xffff;
7892 }
7893
7894 if (size >= 16)
7895 {
7896 if (immlo == (immlo & 0x000000ff))
7897 {
7898 *immbits = immlo;
7899 return 0x8;
7900 }
7901 else if (immlo == (immlo & 0x0000ff00))
7902 {
7903 *immbits = immlo >> 8;
7904 return 0xa;
7905 }
7906
7907 if ((immlo & 0xff) != (immlo >> 8))
7908 return FAIL;
7909 immlo &= 0xff;
7910 }
7911
7912 if (immlo == (immlo & 0x000000ff))
7913 {
7914 /* Don't allow MVN with 8-bit immediate. */
7915 if (*op == 1)
7916 return FAIL;
7917 *immbits = immlo;
7918 return 0xe;
7919 }
7920
7921 return FAIL;
7922 }
7923
7924 #if defined BFD_HOST_64_BIT
7925 /* Returns TRUE if double precision value V may be cast
7926 to single precision without loss of accuracy. */
7927
7928 static bfd_boolean
7929 is_double_a_single (bfd_int64_t v)
7930 {
7931 int exp = (int)((v >> 52) & 0x7FF);
7932 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
7933
7934 return (exp == 0 || exp == 0x7FF
7935 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7936 && (mantissa & 0x1FFFFFFFl) == 0;
7937 }
7938
7939 /* Returns a double precision value casted to single precision
7940 (ignoring the least significant bits in exponent and mantissa). */
7941
7942 static int
7943 double_to_single (bfd_int64_t v)
7944 {
7945 int sign = (int) ((v >> 63) & 1l);
7946 int exp = (int) ((v >> 52) & 0x7FF);
7947 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
7948
7949 if (exp == 0x7FF)
7950 exp = 0xFF;
7951 else
7952 {
7953 exp = exp - 1023 + 127;
7954 if (exp >= 0xFF)
7955 {
7956 /* Infinity. */
7957 exp = 0x7F;
7958 mantissa = 0;
7959 }
7960 else if (exp < 0)
7961 {
7962 /* No denormalized numbers. */
7963 exp = 0;
7964 mantissa = 0;
7965 }
7966 }
7967 mantissa >>= 29;
7968 return (sign << 31) | (exp << 23) | mantissa;
7969 }
7970 #endif /* BFD_HOST_64_BIT */
7971
7972 enum lit_type
7973 {
7974 CONST_THUMB,
7975 CONST_ARM,
7976 CONST_VEC
7977 };
7978
7979 static void do_vfp_nsyn_opcode (const char *);
7980
7981 /* inst.relocs[0].exp describes an "=expr" load pseudo-operation.
7982 Determine whether it can be performed with a move instruction; if
7983 it can, convert inst.instruction to that move instruction and
7984 return TRUE; if it can't, convert inst.instruction to a literal-pool
7985 load and return FALSE. If this is not a valid thing to do in the
7986 current context, set inst.error and return TRUE.
7987
7988 inst.operands[i] describes the destination register. */
7989
7990 static bfd_boolean
7991 move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
7992 {
7993 unsigned long tbit;
7994 bfd_boolean thumb_p = (t == CONST_THUMB);
7995 bfd_boolean arm_p = (t == CONST_ARM);
7996
7997 if (thumb_p)
7998 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7999 else
8000 tbit = LOAD_BIT;
8001
8002 if ((inst.instruction & tbit) == 0)
8003 {
8004 inst.error = _("invalid pseudo operation");
8005 return TRUE;
8006 }
8007
8008 if (inst.relocs[0].exp.X_op != O_constant
8009 && inst.relocs[0].exp.X_op != O_symbol
8010 && inst.relocs[0].exp.X_op != O_big)
8011 {
8012 inst.error = _("constant expression expected");
8013 return TRUE;
8014 }
8015
8016 if (inst.relocs[0].exp.X_op == O_constant
8017 || inst.relocs[0].exp.X_op == O_big)
8018 {
8019 #if defined BFD_HOST_64_BIT
8020 bfd_int64_t v;
8021 #else
8022 offsetT v;
8023 #endif
8024 if (inst.relocs[0].exp.X_op == O_big)
8025 {
8026 LITTLENUM_TYPE w[X_PRECISION];
8027 LITTLENUM_TYPE * l;
8028
8029 if (inst.relocs[0].exp.X_add_number == -1)
8030 {
8031 gen_to_words (w, X_PRECISION, E_PRECISION);
8032 l = w;
8033 /* FIXME: Should we check words w[2..5] ? */
8034 }
8035 else
8036 l = generic_bignum;
8037
8038 #if defined BFD_HOST_64_BIT
8039 v =
8040 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8041 << LITTLENUM_NUMBER_OF_BITS)
8042 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8043 << LITTLENUM_NUMBER_OF_BITS)
8044 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8045 << LITTLENUM_NUMBER_OF_BITS)
8046 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8047 #else
8048 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8049 | (l[0] & LITTLENUM_MASK);
8050 #endif
8051 }
8052 else
8053 v = inst.relocs[0].exp.X_add_number;
8054
8055 if (!inst.operands[i].issingle)
8056 {
8057 if (thumb_p)
8058 {
8059 /* LDR should not use lead in a flag-setting instruction being
8060 chosen so we do not check whether movs can be used. */
8061
8062 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
8063 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8064 && inst.operands[i].reg != 13
8065 && inst.operands[i].reg != 15)
8066 {
8067 /* Check if on thumb2 it can be done with a mov.w, mvn or
8068 movw instruction. */
8069 unsigned int newimm;
8070 bfd_boolean isNegated;
8071
8072 newimm = encode_thumb32_immediate (v);
8073 if (newimm != (unsigned int) FAIL)
8074 isNegated = FALSE;
8075 else
8076 {
8077 newimm = encode_thumb32_immediate (~v);
8078 if (newimm != (unsigned int) FAIL)
8079 isNegated = TRUE;
8080 }
8081
8082 /* The number can be loaded with a mov.w or mvn
8083 instruction. */
8084 if (newimm != (unsigned int) FAIL
8085 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
8086 {
8087 inst.instruction = (0xf04f0000 /* MOV.W. */
8088 | (inst.operands[i].reg << 8));
8089 /* Change to MOVN. */
8090 inst.instruction |= (isNegated ? 0x200000 : 0);
8091 inst.instruction |= (newimm & 0x800) << 15;
8092 inst.instruction |= (newimm & 0x700) << 4;
8093 inst.instruction |= (newimm & 0x0ff);
8094 return TRUE;
8095 }
8096 /* The number can be loaded with a movw instruction. */
8097 else if ((v & ~0xFFFF) == 0
8098 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8099 {
8100 int imm = v & 0xFFFF;
8101
8102 inst.instruction = 0xf2400000; /* MOVW. */
8103 inst.instruction |= (inst.operands[i].reg << 8);
8104 inst.instruction |= (imm & 0xf000) << 4;
8105 inst.instruction |= (imm & 0x0800) << 15;
8106 inst.instruction |= (imm & 0x0700) << 4;
8107 inst.instruction |= (imm & 0x00ff);
8108 return TRUE;
8109 }
8110 }
8111 }
8112 else if (arm_p)
8113 {
8114 int value = encode_arm_immediate (v);
8115
8116 if (value != FAIL)
8117 {
8118 /* This can be done with a mov instruction. */
8119 inst.instruction &= LITERAL_MASK;
8120 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8121 inst.instruction |= value & 0xfff;
8122 return TRUE;
8123 }
8124
8125 value = encode_arm_immediate (~ v);
8126 if (value != FAIL)
8127 {
8128 /* This can be done with a mvn instruction. */
8129 inst.instruction &= LITERAL_MASK;
8130 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8131 inst.instruction |= value & 0xfff;
8132 return TRUE;
8133 }
8134 }
8135 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8136 {
8137 int op = 0;
8138 unsigned immbits = 0;
8139 unsigned immlo = inst.operands[1].imm;
8140 unsigned immhi = inst.operands[1].regisimm
8141 ? inst.operands[1].reg
8142 : inst.relocs[0].exp.X_unsigned
8143 ? 0
8144 : ((bfd_int64_t)((int) immlo)) >> 32;
8145 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8146 &op, 64, NT_invtype);
8147
8148 if (cmode == FAIL)
8149 {
8150 neon_invert_size (&immlo, &immhi, 64);
8151 op = !op;
8152 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8153 &op, 64, NT_invtype);
8154 }
8155
8156 if (cmode != FAIL)
8157 {
8158 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8159 | (1 << 23)
8160 | (cmode << 8)
8161 | (op << 5)
8162 | (1 << 4);
8163
8164 /* Fill other bits in vmov encoding for both thumb and arm. */
8165 if (thumb_mode)
8166 inst.instruction |= (0x7U << 29) | (0xF << 24);
8167 else
8168 inst.instruction |= (0xFU << 28) | (0x1 << 25);
8169 neon_write_immbits (immbits);
8170 return TRUE;
8171 }
8172 }
8173 }
8174
8175 if (t == CONST_VEC)
8176 {
8177 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8178 if (inst.operands[i].issingle
8179 && is_quarter_float (inst.operands[1].imm)
8180 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8181 {
8182 inst.operands[1].imm =
8183 neon_qfloat_bits (v);
8184 do_vfp_nsyn_opcode ("fconsts");
8185 return TRUE;
8186 }
8187
8188 /* If our host does not support a 64-bit type then we cannot perform
8189 the following optimization. This mean that there will be a
8190 discrepancy between the output produced by an assembler built for
8191 a 32-bit-only host and the output produced from a 64-bit host, but
8192 this cannot be helped. */
8193 #if defined BFD_HOST_64_BIT
8194 else if (!inst.operands[1].issingle
8195 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8196 {
8197 if (is_double_a_single (v)
8198 && is_quarter_float (double_to_single (v)))
8199 {
8200 inst.operands[1].imm =
8201 neon_qfloat_bits (double_to_single (v));
8202 do_vfp_nsyn_opcode ("fconstd");
8203 return TRUE;
8204 }
8205 }
8206 #endif
8207 }
8208 }
8209
8210 if (add_to_lit_pool ((!inst.operands[i].isvec
8211 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8212 return TRUE;
8213
8214 inst.operands[1].reg = REG_PC;
8215 inst.operands[1].isreg = 1;
8216 inst.operands[1].preind = 1;
8217 inst.relocs[0].pc_rel = 1;
8218 inst.relocs[0].type = (thumb_p
8219 ? BFD_RELOC_ARM_THUMB_OFFSET
8220 : (mode_3
8221 ? BFD_RELOC_ARM_HWLITERAL
8222 : BFD_RELOC_ARM_LITERAL));
8223 return FALSE;
8224 }
8225
8226 /* inst.operands[i] was set up by parse_address. Encode it into an
8227 ARM-format instruction. Reject all forms which cannot be encoded
8228 into a coprocessor load/store instruction. If wb_ok is false,
8229 reject use of writeback; if unind_ok is false, reject use of
8230 unindexed addressing. If reloc_override is not 0, use it instead
8231 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8232 (in which case it is preserved). */
8233
8234 static int
8235 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8236 {
8237 if (!inst.operands[i].isreg)
8238 {
8239 /* PR 18256 */
8240 if (! inst.operands[0].isvec)
8241 {
8242 inst.error = _("invalid co-processor operand");
8243 return FAIL;
8244 }
8245 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8246 return SUCCESS;
8247 }
8248
8249 inst.instruction |= inst.operands[i].reg << 16;
8250
8251 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8252
8253 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8254 {
8255 gas_assert (!inst.operands[i].writeback);
8256 if (!unind_ok)
8257 {
8258 inst.error = _("instruction does not support unindexed addressing");
8259 return FAIL;
8260 }
8261 inst.instruction |= inst.operands[i].imm;
8262 inst.instruction |= INDEX_UP;
8263 return SUCCESS;
8264 }
8265
8266 if (inst.operands[i].preind)
8267 inst.instruction |= PRE_INDEX;
8268
8269 if (inst.operands[i].writeback)
8270 {
8271 if (inst.operands[i].reg == REG_PC)
8272 {
8273 inst.error = _("pc may not be used with write-back");
8274 return FAIL;
8275 }
8276 if (!wb_ok)
8277 {
8278 inst.error = _("instruction does not support writeback");
8279 return FAIL;
8280 }
8281 inst.instruction |= WRITE_BACK;
8282 }
8283
8284 if (reloc_override)
8285 inst.relocs[0].type = (bfd_reloc_code_real_type) reloc_override;
8286 else if ((inst.relocs[0].type < BFD_RELOC_ARM_ALU_PC_G0_NC
8287 || inst.relocs[0].type > BFD_RELOC_ARM_LDC_SB_G2)
8288 && inst.relocs[0].type != BFD_RELOC_ARM_LDR_PC_G0)
8289 {
8290 if (thumb_mode)
8291 inst.relocs[0].type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8292 else
8293 inst.relocs[0].type = BFD_RELOC_ARM_CP_OFF_IMM;
8294 }
8295
8296 /* Prefer + for zero encoded value. */
8297 if (!inst.operands[i].negative)
8298 inst.instruction |= INDEX_UP;
8299
8300 return SUCCESS;
8301 }
8302
8303 /* Functions for instruction encoding, sorted by sub-architecture.
8304 First some generics; their names are taken from the conventional
8305 bit positions for register arguments in ARM format instructions. */
8306
8307 static void
8308 do_noargs (void)
8309 {
8310 }
8311
8312 static void
8313 do_rd (void)
8314 {
8315 inst.instruction |= inst.operands[0].reg << 12;
8316 }
8317
8318 static void
8319 do_rn (void)
8320 {
8321 inst.instruction |= inst.operands[0].reg << 16;
8322 }
8323
8324 static void
8325 do_rd_rm (void)
8326 {
8327 inst.instruction |= inst.operands[0].reg << 12;
8328 inst.instruction |= inst.operands[1].reg;
8329 }
8330
8331 static void
8332 do_rm_rn (void)
8333 {
8334 inst.instruction |= inst.operands[0].reg;
8335 inst.instruction |= inst.operands[1].reg << 16;
8336 }
8337
8338 static void
8339 do_rd_rn (void)
8340 {
8341 inst.instruction |= inst.operands[0].reg << 12;
8342 inst.instruction |= inst.operands[1].reg << 16;
8343 }
8344
8345 static void
8346 do_rn_rd (void)
8347 {
8348 inst.instruction |= inst.operands[0].reg << 16;
8349 inst.instruction |= inst.operands[1].reg << 12;
8350 }
8351
8352 static void
8353 do_tt (void)
8354 {
8355 inst.instruction |= inst.operands[0].reg << 8;
8356 inst.instruction |= inst.operands[1].reg << 16;
8357 }
8358
8359 static bfd_boolean
8360 check_obsolete (const arm_feature_set *feature, const char *msg)
8361 {
8362 if (ARM_CPU_IS_ANY (cpu_variant))
8363 {
8364 as_tsktsk ("%s", msg);
8365 return TRUE;
8366 }
8367 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8368 {
8369 as_bad ("%s", msg);
8370 return TRUE;
8371 }
8372
8373 return FALSE;
8374 }
8375
8376 static void
8377 do_rd_rm_rn (void)
8378 {
8379 unsigned Rn = inst.operands[2].reg;
8380 /* Enforce restrictions on SWP instruction. */
8381 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
8382 {
8383 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8384 _("Rn must not overlap other operands"));
8385
8386 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8387 */
8388 if (!check_obsolete (&arm_ext_v8,
8389 _("swp{b} use is obsoleted for ARMv8 and later"))
8390 && warn_on_deprecated
8391 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
8392 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
8393 }
8394
8395 inst.instruction |= inst.operands[0].reg << 12;
8396 inst.instruction |= inst.operands[1].reg;
8397 inst.instruction |= Rn << 16;
8398 }
8399
8400 static void
8401 do_rd_rn_rm (void)
8402 {
8403 inst.instruction |= inst.operands[0].reg << 12;
8404 inst.instruction |= inst.operands[1].reg << 16;
8405 inst.instruction |= inst.operands[2].reg;
8406 }
8407
8408 static void
8409 do_rm_rd_rn (void)
8410 {
8411 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8412 constraint (((inst.relocs[0].exp.X_op != O_constant
8413 && inst.relocs[0].exp.X_op != O_illegal)
8414 || inst.relocs[0].exp.X_add_number != 0),
8415 BAD_ADDR_MODE);
8416 inst.instruction |= inst.operands[0].reg;
8417 inst.instruction |= inst.operands[1].reg << 12;
8418 inst.instruction |= inst.operands[2].reg << 16;
8419 }
8420
8421 static void
8422 do_imm0 (void)
8423 {
8424 inst.instruction |= inst.operands[0].imm;
8425 }
8426
8427 static void
8428 do_rd_cpaddr (void)
8429 {
8430 inst.instruction |= inst.operands[0].reg << 12;
8431 encode_arm_cp_address (1, TRUE, TRUE, 0);
8432 }
8433
8434 /* ARM instructions, in alphabetical order by function name (except
8435 that wrapper functions appear immediately after the function they
8436 wrap). */
8437
8438 /* This is a pseudo-op of the form "adr rd, label" to be converted
8439 into a relative address of the form "add rd, pc, #label-.-8". */
8440
8441 static void
8442 do_adr (void)
8443 {
8444 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
8445
8446 /* Frag hacking will turn this into a sub instruction if the offset turns
8447 out to be negative. */
8448 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
8449 inst.relocs[0].pc_rel = 1;
8450 inst.relocs[0].exp.X_add_number -= 8;
8451
8452 if (support_interwork
8453 && inst.relocs[0].exp.X_op == O_symbol
8454 && inst.relocs[0].exp.X_add_symbol != NULL
8455 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8456 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8457 inst.relocs[0].exp.X_add_number |= 1;
8458 }
8459
8460 /* This is a pseudo-op of the form "adrl rd, label" to be converted
8461 into a relative address of the form:
8462 add rd, pc, #low(label-.-8)"
8463 add rd, rd, #high(label-.-8)" */
8464
8465 static void
8466 do_adrl (void)
8467 {
8468 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
8469
8470 /* Frag hacking will turn this into a sub instruction if the offset turns
8471 out to be negative. */
8472 inst.relocs[0].type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
8473 inst.relocs[0].pc_rel = 1;
8474 inst.size = INSN_SIZE * 2;
8475 inst.relocs[0].exp.X_add_number -= 8;
8476
8477 if (support_interwork
8478 && inst.relocs[0].exp.X_op == O_symbol
8479 && inst.relocs[0].exp.X_add_symbol != NULL
8480 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
8481 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
8482 inst.relocs[0].exp.X_add_number |= 1;
8483 }
8484
8485 static void
8486 do_arit (void)
8487 {
8488 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8489 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8490 THUMB1_RELOC_ONLY);
8491 if (!inst.operands[1].present)
8492 inst.operands[1].reg = inst.operands[0].reg;
8493 inst.instruction |= inst.operands[0].reg << 12;
8494 inst.instruction |= inst.operands[1].reg << 16;
8495 encode_arm_shifter_operand (2);
8496 }
8497
8498 static void
8499 do_barrier (void)
8500 {
8501 if (inst.operands[0].present)
8502 inst.instruction |= inst.operands[0].imm;
8503 else
8504 inst.instruction |= 0xf;
8505 }
8506
8507 static void
8508 do_bfc (void)
8509 {
8510 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8511 constraint (msb > 32, _("bit-field extends past end of register"));
8512 /* The instruction encoding stores the LSB and MSB,
8513 not the LSB and width. */
8514 inst.instruction |= inst.operands[0].reg << 12;
8515 inst.instruction |= inst.operands[1].imm << 7;
8516 inst.instruction |= (msb - 1) << 16;
8517 }
8518
8519 static void
8520 do_bfi (void)
8521 {
8522 unsigned int msb;
8523
8524 /* #0 in second position is alternative syntax for bfc, which is
8525 the same instruction but with REG_PC in the Rm field. */
8526 if (!inst.operands[1].isreg)
8527 inst.operands[1].reg = REG_PC;
8528
8529 msb = inst.operands[2].imm + inst.operands[3].imm;
8530 constraint (msb > 32, _("bit-field extends past end of register"));
8531 /* The instruction encoding stores the LSB and MSB,
8532 not the LSB and width. */
8533 inst.instruction |= inst.operands[0].reg << 12;
8534 inst.instruction |= inst.operands[1].reg;
8535 inst.instruction |= inst.operands[2].imm << 7;
8536 inst.instruction |= (msb - 1) << 16;
8537 }
8538
8539 static void
8540 do_bfx (void)
8541 {
8542 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8543 _("bit-field extends past end of register"));
8544 inst.instruction |= inst.operands[0].reg << 12;
8545 inst.instruction |= inst.operands[1].reg;
8546 inst.instruction |= inst.operands[2].imm << 7;
8547 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8548 }
8549
8550 /* ARM V5 breakpoint instruction (argument parse)
8551 BKPT <16 bit unsigned immediate>
8552 Instruction is not conditional.
8553 The bit pattern given in insns[] has the COND_ALWAYS condition,
8554 and it is an error if the caller tried to override that. */
8555
8556 static void
8557 do_bkpt (void)
8558 {
8559 /* Top 12 of 16 bits to bits 19:8. */
8560 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
8561
8562 /* Bottom 4 of 16 bits to bits 3:0. */
8563 inst.instruction |= inst.operands[0].imm & 0xf;
8564 }
8565
8566 static void
8567 encode_branch (int default_reloc)
8568 {
8569 if (inst.operands[0].hasreloc)
8570 {
8571 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8572 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8573 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8574 inst.relocs[0].type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8575 ? BFD_RELOC_ARM_PLT32
8576 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
8577 }
8578 else
8579 inst.relocs[0].type = (bfd_reloc_code_real_type) default_reloc;
8580 inst.relocs[0].pc_rel = 1;
8581 }
8582
8583 static void
8584 do_branch (void)
8585 {
8586 #ifdef OBJ_ELF
8587 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8588 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8589 else
8590 #endif
8591 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8592 }
8593
8594 static void
8595 do_bl (void)
8596 {
8597 #ifdef OBJ_ELF
8598 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8599 {
8600 if (inst.cond == COND_ALWAYS)
8601 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8602 else
8603 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8604 }
8605 else
8606 #endif
8607 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8608 }
8609
8610 /* ARM V5 branch-link-exchange instruction (argument parse)
8611 BLX <target_addr> ie BLX(1)
8612 BLX{<condition>} <Rm> ie BLX(2)
8613 Unfortunately, there are two different opcodes for this mnemonic.
8614 So, the insns[].value is not used, and the code here zaps values
8615 into inst.instruction.
8616 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
8617
8618 static void
8619 do_blx (void)
8620 {
8621 if (inst.operands[0].isreg)
8622 {
8623 /* Arg is a register; the opcode provided by insns[] is correct.
8624 It is not illegal to do "blx pc", just useless. */
8625 if (inst.operands[0].reg == REG_PC)
8626 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
8627
8628 inst.instruction |= inst.operands[0].reg;
8629 }
8630 else
8631 {
8632 /* Arg is an address; this instruction cannot be executed
8633 conditionally, and the opcode must be adjusted.
8634 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8635 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
8636 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8637 inst.instruction = 0xfa000000;
8638 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
8639 }
8640 }
8641
8642 static void
8643 do_bx (void)
8644 {
8645 bfd_boolean want_reloc;
8646
8647 if (inst.operands[0].reg == REG_PC)
8648 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
8649
8650 inst.instruction |= inst.operands[0].reg;
8651 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8652 it is for ARMv4t or earlier. */
8653 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8654 if (!ARM_FEATURE_ZERO (selected_object_arch)
8655 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
8656 want_reloc = TRUE;
8657
8658 #ifdef OBJ_ELF
8659 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
8660 #endif
8661 want_reloc = FALSE;
8662
8663 if (want_reloc)
8664 inst.relocs[0].type = BFD_RELOC_ARM_V4BX;
8665 }
8666
8667
8668 /* ARM v5TEJ. Jump to Jazelle code. */
8669
8670 static void
8671 do_bxj (void)
8672 {
8673 if (inst.operands[0].reg == REG_PC)
8674 as_tsktsk (_("use of r15 in bxj is not really useful"));
8675
8676 inst.instruction |= inst.operands[0].reg;
8677 }
8678
8679 /* Co-processor data operation:
8680 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8681 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8682 static void
8683 do_cdp (void)
8684 {
8685 inst.instruction |= inst.operands[0].reg << 8;
8686 inst.instruction |= inst.operands[1].imm << 20;
8687 inst.instruction |= inst.operands[2].reg << 12;
8688 inst.instruction |= inst.operands[3].reg << 16;
8689 inst.instruction |= inst.operands[4].reg;
8690 inst.instruction |= inst.operands[5].imm << 5;
8691 }
8692
8693 static void
8694 do_cmp (void)
8695 {
8696 inst.instruction |= inst.operands[0].reg << 16;
8697 encode_arm_shifter_operand (1);
8698 }
8699
8700 /* Transfer between coprocessor and ARM registers.
8701 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8702 MRC2
8703 MCR{cond}
8704 MCR2
8705
8706 No special properties. */
8707
8708 struct deprecated_coproc_regs_s
8709 {
8710 unsigned cp;
8711 int opc1;
8712 unsigned crn;
8713 unsigned crm;
8714 int opc2;
8715 arm_feature_set deprecated;
8716 arm_feature_set obsoleted;
8717 const char *dep_msg;
8718 const char *obs_msg;
8719 };
8720
8721 #define DEPR_ACCESS_V8 \
8722 N_("This coprocessor register access is deprecated in ARMv8")
8723
8724 /* Table of all deprecated coprocessor registers. */
8725 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8726 {
8727 {15, 0, 7, 10, 5, /* CP15DMB. */
8728 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8729 DEPR_ACCESS_V8, NULL},
8730 {15, 0, 7, 10, 4, /* CP15DSB. */
8731 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8732 DEPR_ACCESS_V8, NULL},
8733 {15, 0, 7, 5, 4, /* CP15ISB. */
8734 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8735 DEPR_ACCESS_V8, NULL},
8736 {14, 6, 1, 0, 0, /* TEEHBR. */
8737 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8738 DEPR_ACCESS_V8, NULL},
8739 {14, 6, 0, 0, 0, /* TEECR. */
8740 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8741 DEPR_ACCESS_V8, NULL},
8742 };
8743
8744 #undef DEPR_ACCESS_V8
8745
8746 static const size_t deprecated_coproc_reg_count =
8747 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8748
8749 static void
8750 do_co_reg (void)
8751 {
8752 unsigned Rd;
8753 size_t i;
8754
8755 Rd = inst.operands[2].reg;
8756 if (thumb_mode)
8757 {
8758 if (inst.instruction == 0xee000010
8759 || inst.instruction == 0xfe000010)
8760 /* MCR, MCR2 */
8761 reject_bad_reg (Rd);
8762 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8763 /* MRC, MRC2 */
8764 constraint (Rd == REG_SP, BAD_SP);
8765 }
8766 else
8767 {
8768 /* MCR */
8769 if (inst.instruction == 0xe000010)
8770 constraint (Rd == REG_PC, BAD_PC);
8771 }
8772
8773 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8774 {
8775 const struct deprecated_coproc_regs_s *r =
8776 deprecated_coproc_regs + i;
8777
8778 if (inst.operands[0].reg == r->cp
8779 && inst.operands[1].imm == r->opc1
8780 && inst.operands[3].reg == r->crn
8781 && inst.operands[4].reg == r->crm
8782 && inst.operands[5].imm == r->opc2)
8783 {
8784 if (! ARM_CPU_IS_ANY (cpu_variant)
8785 && warn_on_deprecated
8786 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
8787 as_tsktsk ("%s", r->dep_msg);
8788 }
8789 }
8790
8791 inst.instruction |= inst.operands[0].reg << 8;
8792 inst.instruction |= inst.operands[1].imm << 21;
8793 inst.instruction |= Rd << 12;
8794 inst.instruction |= inst.operands[3].reg << 16;
8795 inst.instruction |= inst.operands[4].reg;
8796 inst.instruction |= inst.operands[5].imm << 5;
8797 }
8798
8799 /* Transfer between coprocessor register and pair of ARM registers.
8800 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8801 MCRR2
8802 MRRC{cond}
8803 MRRC2
8804
8805 Two XScale instructions are special cases of these:
8806
8807 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8808 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
8809
8810 Result unpredictable if Rd or Rn is R15. */
8811
8812 static void
8813 do_co_reg2c (void)
8814 {
8815 unsigned Rd, Rn;
8816
8817 Rd = inst.operands[2].reg;
8818 Rn = inst.operands[3].reg;
8819
8820 if (thumb_mode)
8821 {
8822 reject_bad_reg (Rd);
8823 reject_bad_reg (Rn);
8824 }
8825 else
8826 {
8827 constraint (Rd == REG_PC, BAD_PC);
8828 constraint (Rn == REG_PC, BAD_PC);
8829 }
8830
8831 /* Only check the MRRC{2} variants. */
8832 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8833 {
8834 /* If Rd == Rn, error that the operation is
8835 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8836 constraint (Rd == Rn, BAD_OVERLAP);
8837 }
8838
8839 inst.instruction |= inst.operands[0].reg << 8;
8840 inst.instruction |= inst.operands[1].imm << 4;
8841 inst.instruction |= Rd << 12;
8842 inst.instruction |= Rn << 16;
8843 inst.instruction |= inst.operands[4].reg;
8844 }
8845
8846 static void
8847 do_cpsi (void)
8848 {
8849 inst.instruction |= inst.operands[0].imm << 6;
8850 if (inst.operands[1].present)
8851 {
8852 inst.instruction |= CPSI_MMOD;
8853 inst.instruction |= inst.operands[1].imm;
8854 }
8855 }
8856
8857 static void
8858 do_dbg (void)
8859 {
8860 inst.instruction |= inst.operands[0].imm;
8861 }
8862
8863 static void
8864 do_div (void)
8865 {
8866 unsigned Rd, Rn, Rm;
8867
8868 Rd = inst.operands[0].reg;
8869 Rn = (inst.operands[1].present
8870 ? inst.operands[1].reg : Rd);
8871 Rm = inst.operands[2].reg;
8872
8873 constraint ((Rd == REG_PC), BAD_PC);
8874 constraint ((Rn == REG_PC), BAD_PC);
8875 constraint ((Rm == REG_PC), BAD_PC);
8876
8877 inst.instruction |= Rd << 16;
8878 inst.instruction |= Rn << 0;
8879 inst.instruction |= Rm << 8;
8880 }
8881
8882 static void
8883 do_it (void)
8884 {
8885 /* There is no IT instruction in ARM mode. We
8886 process it to do the validation as if in
8887 thumb mode, just in case the code gets
8888 assembled for thumb using the unified syntax. */
8889
8890 inst.size = 0;
8891 if (unified_syntax)
8892 {
8893 set_it_insn_type (IT_INSN);
8894 now_it.mask = (inst.instruction & 0xf) | 0x10;
8895 now_it.cc = inst.operands[0].imm;
8896 }
8897 }
8898
8899 /* If there is only one register in the register list,
8900 then return its register number. Otherwise return -1. */
8901 static int
8902 only_one_reg_in_list (int range)
8903 {
8904 int i = ffs (range) - 1;
8905 return (i > 15 || range != (1 << i)) ? -1 : i;
8906 }
8907
8908 static void
8909 encode_ldmstm(int from_push_pop_mnem)
8910 {
8911 int base_reg = inst.operands[0].reg;
8912 int range = inst.operands[1].imm;
8913 int one_reg;
8914
8915 inst.instruction |= base_reg << 16;
8916 inst.instruction |= range;
8917
8918 if (inst.operands[1].writeback)
8919 inst.instruction |= LDM_TYPE_2_OR_3;
8920
8921 if (inst.operands[0].writeback)
8922 {
8923 inst.instruction |= WRITE_BACK;
8924 /* Check for unpredictable uses of writeback. */
8925 if (inst.instruction & LOAD_BIT)
8926 {
8927 /* Not allowed in LDM type 2. */
8928 if ((inst.instruction & LDM_TYPE_2_OR_3)
8929 && ((range & (1 << REG_PC)) == 0))
8930 as_warn (_("writeback of base register is UNPREDICTABLE"));
8931 /* Only allowed if base reg not in list for other types. */
8932 else if (range & (1 << base_reg))
8933 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8934 }
8935 else /* STM. */
8936 {
8937 /* Not allowed for type 2. */
8938 if (inst.instruction & LDM_TYPE_2_OR_3)
8939 as_warn (_("writeback of base register is UNPREDICTABLE"));
8940 /* Only allowed if base reg not in list, or first in list. */
8941 else if ((range & (1 << base_reg))
8942 && (range & ((1 << base_reg) - 1)))
8943 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
8944 }
8945 }
8946
8947 /* If PUSH/POP has only one register, then use the A2 encoding. */
8948 one_reg = only_one_reg_in_list (range);
8949 if (from_push_pop_mnem && one_reg >= 0)
8950 {
8951 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8952
8953 if (is_push && one_reg == 13 /* SP */)
8954 /* PR 22483: The A2 encoding cannot be used when
8955 pushing the stack pointer as this is UNPREDICTABLE. */
8956 return;
8957
8958 inst.instruction &= A_COND_MASK;
8959 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8960 inst.instruction |= one_reg << 12;
8961 }
8962 }
8963
8964 static void
8965 do_ldmstm (void)
8966 {
8967 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
8968 }
8969
8970 /* ARMv5TE load-consecutive (argument parse)
8971 Mode is like LDRH.
8972
8973 LDRccD R, mode
8974 STRccD R, mode. */
8975
8976 static void
8977 do_ldrd (void)
8978 {
8979 constraint (inst.operands[0].reg % 2 != 0,
8980 _("first transfer register must be even"));
8981 constraint (inst.operands[1].present
8982 && inst.operands[1].reg != inst.operands[0].reg + 1,
8983 _("can only transfer two consecutive registers"));
8984 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8985 constraint (!inst.operands[2].isreg, _("'[' expected"));
8986
8987 if (!inst.operands[1].present)
8988 inst.operands[1].reg = inst.operands[0].reg + 1;
8989
8990 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8991 register and the first register written; we have to diagnose
8992 overlap between the base and the second register written here. */
8993
8994 if (inst.operands[2].reg == inst.operands[1].reg
8995 && (inst.operands[2].writeback || inst.operands[2].postind))
8996 as_warn (_("base register written back, and overlaps "
8997 "second transfer register"));
8998
8999 if (!(inst.instruction & V4_STR_BIT))
9000 {
9001 /* For an index-register load, the index register must not overlap the
9002 destination (even if not write-back). */
9003 if (inst.operands[2].immisreg
9004 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
9005 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
9006 as_warn (_("index register overlaps transfer register"));
9007 }
9008 inst.instruction |= inst.operands[0].reg << 12;
9009 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
9010 }
9011
9012 static void
9013 do_ldrex (void)
9014 {
9015 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9016 || inst.operands[1].postind || inst.operands[1].writeback
9017 || inst.operands[1].immisreg || inst.operands[1].shifted
9018 || inst.operands[1].negative
9019 /* This can arise if the programmer has written
9020 strex rN, rM, foo
9021 or if they have mistakenly used a register name as the last
9022 operand, eg:
9023 strex rN, rM, rX
9024 It is very difficult to distinguish between these two cases
9025 because "rX" might actually be a label. ie the register
9026 name has been occluded by a symbol of the same name. So we
9027 just generate a general 'bad addressing mode' type error
9028 message and leave it up to the programmer to discover the
9029 true cause and fix their mistake. */
9030 || (inst.operands[1].reg == REG_PC),
9031 BAD_ADDR_MODE);
9032
9033 constraint (inst.relocs[0].exp.X_op != O_constant
9034 || inst.relocs[0].exp.X_add_number != 0,
9035 _("offset must be zero in ARM encoding"));
9036
9037 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9038
9039 inst.instruction |= inst.operands[0].reg << 12;
9040 inst.instruction |= inst.operands[1].reg << 16;
9041 inst.relocs[0].type = BFD_RELOC_UNUSED;
9042 }
9043
9044 static void
9045 do_ldrexd (void)
9046 {
9047 constraint (inst.operands[0].reg % 2 != 0,
9048 _("even register required"));
9049 constraint (inst.operands[1].present
9050 && inst.operands[1].reg != inst.operands[0].reg + 1,
9051 _("can only load two consecutive registers"));
9052 /* If op 1 were present and equal to PC, this function wouldn't
9053 have been called in the first place. */
9054 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9055
9056 inst.instruction |= inst.operands[0].reg << 12;
9057 inst.instruction |= inst.operands[2].reg << 16;
9058 }
9059
9060 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9061 which is not a multiple of four is UNPREDICTABLE. */
9062 static void
9063 check_ldr_r15_aligned (void)
9064 {
9065 constraint (!(inst.operands[1].immisreg)
9066 && (inst.operands[0].reg == REG_PC
9067 && inst.operands[1].reg == REG_PC
9068 && (inst.relocs[0].exp.X_add_number & 0x3)),
9069 _("ldr to register 15 must be 4-byte aligned"));
9070 }
9071
9072 static void
9073 do_ldst (void)
9074 {
9075 inst.instruction |= inst.operands[0].reg << 12;
9076 if (!inst.operands[1].isreg)
9077 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
9078 return;
9079 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
9080 check_ldr_r15_aligned ();
9081 }
9082
9083 static void
9084 do_ldstt (void)
9085 {
9086 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9087 reject [Rn,...]. */
9088 if (inst.operands[1].preind)
9089 {
9090 constraint (inst.relocs[0].exp.X_op != O_constant
9091 || inst.relocs[0].exp.X_add_number != 0,
9092 _("this instruction requires a post-indexed address"));
9093
9094 inst.operands[1].preind = 0;
9095 inst.operands[1].postind = 1;
9096 inst.operands[1].writeback = 1;
9097 }
9098 inst.instruction |= inst.operands[0].reg << 12;
9099 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9100 }
9101
9102 /* Halfword and signed-byte load/store operations. */
9103
9104 static void
9105 do_ldstv4 (void)
9106 {
9107 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9108 inst.instruction |= inst.operands[0].reg << 12;
9109 if (!inst.operands[1].isreg)
9110 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
9111 return;
9112 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
9113 }
9114
9115 static void
9116 do_ldsttv4 (void)
9117 {
9118 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9119 reject [Rn,...]. */
9120 if (inst.operands[1].preind)
9121 {
9122 constraint (inst.relocs[0].exp.X_op != O_constant
9123 || inst.relocs[0].exp.X_add_number != 0,
9124 _("this instruction requires a post-indexed address"));
9125
9126 inst.operands[1].preind = 0;
9127 inst.operands[1].postind = 1;
9128 inst.operands[1].writeback = 1;
9129 }
9130 inst.instruction |= inst.operands[0].reg << 12;
9131 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
9132 }
9133
9134 /* Co-processor register load/store.
9135 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9136 static void
9137 do_lstc (void)
9138 {
9139 inst.instruction |= inst.operands[0].reg << 8;
9140 inst.instruction |= inst.operands[1].reg << 12;
9141 encode_arm_cp_address (2, TRUE, TRUE, 0);
9142 }
9143
9144 static void
9145 do_mlas (void)
9146 {
9147 /* This restriction does not apply to mls (nor to mla in v6 or later). */
9148 if (inst.operands[0].reg == inst.operands[1].reg
9149 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
9150 && !(inst.instruction & 0x00400000))
9151 as_tsktsk (_("Rd and Rm should be different in mla"));
9152
9153 inst.instruction |= inst.operands[0].reg << 16;
9154 inst.instruction |= inst.operands[1].reg;
9155 inst.instruction |= inst.operands[2].reg << 8;
9156 inst.instruction |= inst.operands[3].reg << 12;
9157 }
9158
9159 static void
9160 do_mov (void)
9161 {
9162 constraint (inst.relocs[0].type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9163 && inst.relocs[0].type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9164 THUMB1_RELOC_ONLY);
9165 inst.instruction |= inst.operands[0].reg << 12;
9166 encode_arm_shifter_operand (1);
9167 }
9168
9169 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9170 static void
9171 do_mov16 (void)
9172 {
9173 bfd_vma imm;
9174 bfd_boolean top;
9175
9176 top = (inst.instruction & 0x00400000) != 0;
9177 constraint (top && inst.relocs[0].type == BFD_RELOC_ARM_MOVW,
9178 _(":lower16: not allowed in this instruction"));
9179 constraint (!top && inst.relocs[0].type == BFD_RELOC_ARM_MOVT,
9180 _(":upper16: not allowed in this instruction"));
9181 inst.instruction |= inst.operands[0].reg << 12;
9182 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
9183 {
9184 imm = inst.relocs[0].exp.X_add_number;
9185 /* The value is in two pieces: 0:11, 16:19. */
9186 inst.instruction |= (imm & 0x00000fff);
9187 inst.instruction |= (imm & 0x0000f000) << 4;
9188 }
9189 }
9190
9191 static int
9192 do_vfp_nsyn_mrs (void)
9193 {
9194 if (inst.operands[0].isvec)
9195 {
9196 if (inst.operands[1].reg != 1)
9197 first_error (_("operand 1 must be FPSCR"));
9198 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9199 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9200 do_vfp_nsyn_opcode ("fmstat");
9201 }
9202 else if (inst.operands[1].isvec)
9203 do_vfp_nsyn_opcode ("fmrx");
9204 else
9205 return FAIL;
9206
9207 return SUCCESS;
9208 }
9209
9210 static int
9211 do_vfp_nsyn_msr (void)
9212 {
9213 if (inst.operands[0].isvec)
9214 do_vfp_nsyn_opcode ("fmxr");
9215 else
9216 return FAIL;
9217
9218 return SUCCESS;
9219 }
9220
9221 static void
9222 do_vmrs (void)
9223 {
9224 unsigned Rt = inst.operands[0].reg;
9225
9226 if (thumb_mode && Rt == REG_SP)
9227 {
9228 inst.error = BAD_SP;
9229 return;
9230 }
9231
9232 /* MVFR2 is only valid at ARMv8-A. */
9233 if (inst.operands[1].reg == 5)
9234 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9235 _(BAD_FPU));
9236
9237 /* APSR_ sets isvec. All other refs to PC are illegal. */
9238 if (!inst.operands[0].isvec && Rt == REG_PC)
9239 {
9240 inst.error = BAD_PC;
9241 return;
9242 }
9243
9244 /* If we get through parsing the register name, we just insert the number
9245 generated into the instruction without further validation. */
9246 inst.instruction |= (inst.operands[1].reg << 16);
9247 inst.instruction |= (Rt << 12);
9248 }
9249
9250 static void
9251 do_vmsr (void)
9252 {
9253 unsigned Rt = inst.operands[1].reg;
9254
9255 if (thumb_mode)
9256 reject_bad_reg (Rt);
9257 else if (Rt == REG_PC)
9258 {
9259 inst.error = BAD_PC;
9260 return;
9261 }
9262
9263 /* MVFR2 is only valid for ARMv8-A. */
9264 if (inst.operands[0].reg == 5)
9265 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9266 _(BAD_FPU));
9267
9268 /* If we get through parsing the register name, we just insert the number
9269 generated into the instruction without further validation. */
9270 inst.instruction |= (inst.operands[0].reg << 16);
9271 inst.instruction |= (Rt << 12);
9272 }
9273
9274 static void
9275 do_mrs (void)
9276 {
9277 unsigned br;
9278
9279 if (do_vfp_nsyn_mrs () == SUCCESS)
9280 return;
9281
9282 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9283 inst.instruction |= inst.operands[0].reg << 12;
9284
9285 if (inst.operands[1].isreg)
9286 {
9287 br = inst.operands[1].reg;
9288 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
9289 as_bad (_("bad register for mrs"));
9290 }
9291 else
9292 {
9293 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9294 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9295 != (PSR_c|PSR_f),
9296 _("'APSR', 'CPSR' or 'SPSR' expected"));
9297 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9298 }
9299
9300 inst.instruction |= br;
9301 }
9302
9303 /* Two possible forms:
9304 "{C|S}PSR_<field>, Rm",
9305 "{C|S}PSR_f, #expression". */
9306
9307 static void
9308 do_msr (void)
9309 {
9310 if (do_vfp_nsyn_msr () == SUCCESS)
9311 return;
9312
9313 inst.instruction |= inst.operands[0].imm;
9314 if (inst.operands[1].isreg)
9315 inst.instruction |= inst.operands[1].reg;
9316 else
9317 {
9318 inst.instruction |= INST_IMMEDIATE;
9319 inst.relocs[0].type = BFD_RELOC_ARM_IMMEDIATE;
9320 inst.relocs[0].pc_rel = 0;
9321 }
9322 }
9323
9324 static void
9325 do_mul (void)
9326 {
9327 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9328
9329 if (!inst.operands[2].present)
9330 inst.operands[2].reg = inst.operands[0].reg;
9331 inst.instruction |= inst.operands[0].reg << 16;
9332 inst.instruction |= inst.operands[1].reg;
9333 inst.instruction |= inst.operands[2].reg << 8;
9334
9335 if (inst.operands[0].reg == inst.operands[1].reg
9336 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9337 as_tsktsk (_("Rd and Rm should be different in mul"));
9338 }
9339
9340 /* Long Multiply Parser
9341 UMULL RdLo, RdHi, Rm, Rs
9342 SMULL RdLo, RdHi, Rm, Rs
9343 UMLAL RdLo, RdHi, Rm, Rs
9344 SMLAL RdLo, RdHi, Rm, Rs. */
9345
9346 static void
9347 do_mull (void)
9348 {
9349 inst.instruction |= inst.operands[0].reg << 12;
9350 inst.instruction |= inst.operands[1].reg << 16;
9351 inst.instruction |= inst.operands[2].reg;
9352 inst.instruction |= inst.operands[3].reg << 8;
9353
9354 /* rdhi and rdlo must be different. */
9355 if (inst.operands[0].reg == inst.operands[1].reg)
9356 as_tsktsk (_("rdhi and rdlo must be different"));
9357
9358 /* rdhi, rdlo and rm must all be different before armv6. */
9359 if ((inst.operands[0].reg == inst.operands[2].reg
9360 || inst.operands[1].reg == inst.operands[2].reg)
9361 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9362 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9363 }
9364
9365 static void
9366 do_nop (void)
9367 {
9368 if (inst.operands[0].present
9369 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
9370 {
9371 /* Architectural NOP hints are CPSR sets with no bits selected. */
9372 inst.instruction &= 0xf0000000;
9373 inst.instruction |= 0x0320f000;
9374 if (inst.operands[0].present)
9375 inst.instruction |= inst.operands[0].imm;
9376 }
9377 }
9378
9379 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9380 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9381 Condition defaults to COND_ALWAYS.
9382 Error if Rd, Rn or Rm are R15. */
9383
9384 static void
9385 do_pkhbt (void)
9386 {
9387 inst.instruction |= inst.operands[0].reg << 12;
9388 inst.instruction |= inst.operands[1].reg << 16;
9389 inst.instruction |= inst.operands[2].reg;
9390 if (inst.operands[3].present)
9391 encode_arm_shift (3);
9392 }
9393
9394 /* ARM V6 PKHTB (Argument Parse). */
9395
9396 static void
9397 do_pkhtb (void)
9398 {
9399 if (!inst.operands[3].present)
9400 {
9401 /* If the shift specifier is omitted, turn the instruction
9402 into pkhbt rd, rm, rn. */
9403 inst.instruction &= 0xfff00010;
9404 inst.instruction |= inst.operands[0].reg << 12;
9405 inst.instruction |= inst.operands[1].reg;
9406 inst.instruction |= inst.operands[2].reg << 16;
9407 }
9408 else
9409 {
9410 inst.instruction |= inst.operands[0].reg << 12;
9411 inst.instruction |= inst.operands[1].reg << 16;
9412 inst.instruction |= inst.operands[2].reg;
9413 encode_arm_shift (3);
9414 }
9415 }
9416
9417 /* ARMv5TE: Preload-Cache
9418 MP Extensions: Preload for write
9419
9420 PLD(W) <addr_mode>
9421
9422 Syntactically, like LDR with B=1, W=0, L=1. */
9423
9424 static void
9425 do_pld (void)
9426 {
9427 constraint (!inst.operands[0].isreg,
9428 _("'[' expected after PLD mnemonic"));
9429 constraint (inst.operands[0].postind,
9430 _("post-indexed expression used in preload instruction"));
9431 constraint (inst.operands[0].writeback,
9432 _("writeback used in preload instruction"));
9433 constraint (!inst.operands[0].preind,
9434 _("unindexed addressing used in preload instruction"));
9435 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9436 }
9437
9438 /* ARMv7: PLI <addr_mode> */
9439 static void
9440 do_pli (void)
9441 {
9442 constraint (!inst.operands[0].isreg,
9443 _("'[' expected after PLI mnemonic"));
9444 constraint (inst.operands[0].postind,
9445 _("post-indexed expression used in preload instruction"));
9446 constraint (inst.operands[0].writeback,
9447 _("writeback used in preload instruction"));
9448 constraint (!inst.operands[0].preind,
9449 _("unindexed addressing used in preload instruction"));
9450 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9451 inst.instruction &= ~PRE_INDEX;
9452 }
9453
9454 static void
9455 do_push_pop (void)
9456 {
9457 constraint (inst.operands[0].writeback,
9458 _("push/pop do not support {reglist}^"));
9459 inst.operands[1] = inst.operands[0];
9460 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9461 inst.operands[0].isreg = 1;
9462 inst.operands[0].writeback = 1;
9463 inst.operands[0].reg = REG_SP;
9464 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
9465 }
9466
9467 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9468 word at the specified address and the following word
9469 respectively.
9470 Unconditionally executed.
9471 Error if Rn is R15. */
9472
9473 static void
9474 do_rfe (void)
9475 {
9476 inst.instruction |= inst.operands[0].reg << 16;
9477 if (inst.operands[0].writeback)
9478 inst.instruction |= WRITE_BACK;
9479 }
9480
9481 /* ARM V6 ssat (argument parse). */
9482
9483 static void
9484 do_ssat (void)
9485 {
9486 inst.instruction |= inst.operands[0].reg << 12;
9487 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9488 inst.instruction |= inst.operands[2].reg;
9489
9490 if (inst.operands[3].present)
9491 encode_arm_shift (3);
9492 }
9493
9494 /* ARM V6 usat (argument parse). */
9495
9496 static void
9497 do_usat (void)
9498 {
9499 inst.instruction |= inst.operands[0].reg << 12;
9500 inst.instruction |= inst.operands[1].imm << 16;
9501 inst.instruction |= inst.operands[2].reg;
9502
9503 if (inst.operands[3].present)
9504 encode_arm_shift (3);
9505 }
9506
9507 /* ARM V6 ssat16 (argument parse). */
9508
9509 static void
9510 do_ssat16 (void)
9511 {
9512 inst.instruction |= inst.operands[0].reg << 12;
9513 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9514 inst.instruction |= inst.operands[2].reg;
9515 }
9516
9517 static void
9518 do_usat16 (void)
9519 {
9520 inst.instruction |= inst.operands[0].reg << 12;
9521 inst.instruction |= inst.operands[1].imm << 16;
9522 inst.instruction |= inst.operands[2].reg;
9523 }
9524
9525 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9526 preserving the other bits.
9527
9528 setend <endian_specifier>, where <endian_specifier> is either
9529 BE or LE. */
9530
9531 static void
9532 do_setend (void)
9533 {
9534 if (warn_on_deprecated
9535 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9536 as_tsktsk (_("setend use is deprecated for ARMv8"));
9537
9538 if (inst.operands[0].imm)
9539 inst.instruction |= 0x200;
9540 }
9541
9542 static void
9543 do_shift (void)
9544 {
9545 unsigned int Rm = (inst.operands[1].present
9546 ? inst.operands[1].reg
9547 : inst.operands[0].reg);
9548
9549 inst.instruction |= inst.operands[0].reg << 12;
9550 inst.instruction |= Rm;
9551 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
9552 {
9553 inst.instruction |= inst.operands[2].reg << 8;
9554 inst.instruction |= SHIFT_BY_REG;
9555 /* PR 12854: Error on extraneous shifts. */
9556 constraint (inst.operands[2].shifted,
9557 _("extraneous shift as part of operand to shift insn"));
9558 }
9559 else
9560 inst.relocs[0].type = BFD_RELOC_ARM_SHIFT_IMM;
9561 }
9562
9563 static void
9564 do_smc (void)
9565 {
9566 inst.relocs[0].type = BFD_RELOC_ARM_SMC;
9567 inst.relocs[0].pc_rel = 0;
9568 }
9569
9570 static void
9571 do_hvc (void)
9572 {
9573 inst.relocs[0].type = BFD_RELOC_ARM_HVC;
9574 inst.relocs[0].pc_rel = 0;
9575 }
9576
9577 static void
9578 do_swi (void)
9579 {
9580 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
9581 inst.relocs[0].pc_rel = 0;
9582 }
9583
9584 static void
9585 do_setpan (void)
9586 {
9587 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9588 _("selected processor does not support SETPAN instruction"));
9589
9590 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9591 }
9592
9593 static void
9594 do_t_setpan (void)
9595 {
9596 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9597 _("selected processor does not support SETPAN instruction"));
9598
9599 inst.instruction |= (inst.operands[0].imm << 3);
9600 }
9601
9602 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9603 SMLAxy{cond} Rd,Rm,Rs,Rn
9604 SMLAWy{cond} Rd,Rm,Rs,Rn
9605 Error if any register is R15. */
9606
9607 static void
9608 do_smla (void)
9609 {
9610 inst.instruction |= inst.operands[0].reg << 16;
9611 inst.instruction |= inst.operands[1].reg;
9612 inst.instruction |= inst.operands[2].reg << 8;
9613 inst.instruction |= inst.operands[3].reg << 12;
9614 }
9615
9616 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9617 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9618 Error if any register is R15.
9619 Warning if Rdlo == Rdhi. */
9620
9621 static void
9622 do_smlal (void)
9623 {
9624 inst.instruction |= inst.operands[0].reg << 12;
9625 inst.instruction |= inst.operands[1].reg << 16;
9626 inst.instruction |= inst.operands[2].reg;
9627 inst.instruction |= inst.operands[3].reg << 8;
9628
9629 if (inst.operands[0].reg == inst.operands[1].reg)
9630 as_tsktsk (_("rdhi and rdlo must be different"));
9631 }
9632
9633 /* ARM V5E (El Segundo) signed-multiply (argument parse)
9634 SMULxy{cond} Rd,Rm,Rs
9635 Error if any register is R15. */
9636
9637 static void
9638 do_smul (void)
9639 {
9640 inst.instruction |= inst.operands[0].reg << 16;
9641 inst.instruction |= inst.operands[1].reg;
9642 inst.instruction |= inst.operands[2].reg << 8;
9643 }
9644
9645 /* ARM V6 srs (argument parse). The variable fields in the encoding are
9646 the same for both ARM and Thumb-2. */
9647
9648 static void
9649 do_srs (void)
9650 {
9651 int reg;
9652
9653 if (inst.operands[0].present)
9654 {
9655 reg = inst.operands[0].reg;
9656 constraint (reg != REG_SP, _("SRS base register must be r13"));
9657 }
9658 else
9659 reg = REG_SP;
9660
9661 inst.instruction |= reg << 16;
9662 inst.instruction |= inst.operands[1].imm;
9663 if (inst.operands[0].writeback || inst.operands[1].writeback)
9664 inst.instruction |= WRITE_BACK;
9665 }
9666
9667 /* ARM V6 strex (argument parse). */
9668
9669 static void
9670 do_strex (void)
9671 {
9672 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9673 || inst.operands[2].postind || inst.operands[2].writeback
9674 || inst.operands[2].immisreg || inst.operands[2].shifted
9675 || inst.operands[2].negative
9676 /* See comment in do_ldrex(). */
9677 || (inst.operands[2].reg == REG_PC),
9678 BAD_ADDR_MODE);
9679
9680 constraint (inst.operands[0].reg == inst.operands[1].reg
9681 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9682
9683 constraint (inst.relocs[0].exp.X_op != O_constant
9684 || inst.relocs[0].exp.X_add_number != 0,
9685 _("offset must be zero in ARM encoding"));
9686
9687 inst.instruction |= inst.operands[0].reg << 12;
9688 inst.instruction |= inst.operands[1].reg;
9689 inst.instruction |= inst.operands[2].reg << 16;
9690 inst.relocs[0].type = BFD_RELOC_UNUSED;
9691 }
9692
9693 static void
9694 do_t_strexbh (void)
9695 {
9696 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9697 || inst.operands[2].postind || inst.operands[2].writeback
9698 || inst.operands[2].immisreg || inst.operands[2].shifted
9699 || inst.operands[2].negative,
9700 BAD_ADDR_MODE);
9701
9702 constraint (inst.operands[0].reg == inst.operands[1].reg
9703 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9704
9705 do_rm_rd_rn ();
9706 }
9707
9708 static void
9709 do_strexd (void)
9710 {
9711 constraint (inst.operands[1].reg % 2 != 0,
9712 _("even register required"));
9713 constraint (inst.operands[2].present
9714 && inst.operands[2].reg != inst.operands[1].reg + 1,
9715 _("can only store two consecutive registers"));
9716 /* If op 2 were present and equal to PC, this function wouldn't
9717 have been called in the first place. */
9718 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
9719
9720 constraint (inst.operands[0].reg == inst.operands[1].reg
9721 || inst.operands[0].reg == inst.operands[1].reg + 1
9722 || inst.operands[0].reg == inst.operands[3].reg,
9723 BAD_OVERLAP);
9724
9725 inst.instruction |= inst.operands[0].reg << 12;
9726 inst.instruction |= inst.operands[1].reg;
9727 inst.instruction |= inst.operands[3].reg << 16;
9728 }
9729
9730 /* ARM V8 STRL. */
9731 static void
9732 do_stlex (void)
9733 {
9734 constraint (inst.operands[0].reg == inst.operands[1].reg
9735 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9736
9737 do_rd_rm_rn ();
9738 }
9739
9740 static void
9741 do_t_stlex (void)
9742 {
9743 constraint (inst.operands[0].reg == inst.operands[1].reg
9744 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9745
9746 do_rm_rd_rn ();
9747 }
9748
9749 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9750 extends it to 32-bits, and adds the result to a value in another
9751 register. You can specify a rotation by 0, 8, 16, or 24 bits
9752 before extracting the 16-bit value.
9753 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9754 Condition defaults to COND_ALWAYS.
9755 Error if any register uses R15. */
9756
9757 static void
9758 do_sxtah (void)
9759 {
9760 inst.instruction |= inst.operands[0].reg << 12;
9761 inst.instruction |= inst.operands[1].reg << 16;
9762 inst.instruction |= inst.operands[2].reg;
9763 inst.instruction |= inst.operands[3].imm << 10;
9764 }
9765
9766 /* ARM V6 SXTH.
9767
9768 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9769 Condition defaults to COND_ALWAYS.
9770 Error if any register uses R15. */
9771
9772 static void
9773 do_sxth (void)
9774 {
9775 inst.instruction |= inst.operands[0].reg << 12;
9776 inst.instruction |= inst.operands[1].reg;
9777 inst.instruction |= inst.operands[2].imm << 10;
9778 }
9779 \f
9780 /* VFP instructions. In a logical order: SP variant first, monad
9781 before dyad, arithmetic then move then load/store. */
9782
9783 static void
9784 do_vfp_sp_monadic (void)
9785 {
9786 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9787 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
9788 }
9789
9790 static void
9791 do_vfp_sp_dyadic (void)
9792 {
9793 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9794 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9795 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
9796 }
9797
9798 static void
9799 do_vfp_sp_compare_z (void)
9800 {
9801 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9802 }
9803
9804 static void
9805 do_vfp_dp_sp_cvt (void)
9806 {
9807 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9808 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
9809 }
9810
9811 static void
9812 do_vfp_sp_dp_cvt (void)
9813 {
9814 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9815 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9816 }
9817
9818 static void
9819 do_vfp_reg_from_sp (void)
9820 {
9821 inst.instruction |= inst.operands[0].reg << 12;
9822 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9823 }
9824
9825 static void
9826 do_vfp_reg2_from_sp2 (void)
9827 {
9828 constraint (inst.operands[2].imm != 2,
9829 _("only two consecutive VFP SP registers allowed here"));
9830 inst.instruction |= inst.operands[0].reg << 12;
9831 inst.instruction |= inst.operands[1].reg << 16;
9832 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
9833 }
9834
9835 static void
9836 do_vfp_sp_from_reg (void)
9837 {
9838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
9839 inst.instruction |= inst.operands[1].reg << 12;
9840 }
9841
9842 static void
9843 do_vfp_sp2_from_reg2 (void)
9844 {
9845 constraint (inst.operands[0].imm != 2,
9846 _("only two consecutive VFP SP registers allowed here"));
9847 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
9848 inst.instruction |= inst.operands[1].reg << 12;
9849 inst.instruction |= inst.operands[2].reg << 16;
9850 }
9851
9852 static void
9853 do_vfp_sp_ldst (void)
9854 {
9855 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9856 encode_arm_cp_address (1, FALSE, TRUE, 0);
9857 }
9858
9859 static void
9860 do_vfp_dp_ldst (void)
9861 {
9862 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9863 encode_arm_cp_address (1, FALSE, TRUE, 0);
9864 }
9865
9866
9867 static void
9868 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
9869 {
9870 if (inst.operands[0].writeback)
9871 inst.instruction |= WRITE_BACK;
9872 else
9873 constraint (ldstm_type != VFP_LDSTMIA,
9874 _("this addressing mode requires base-register writeback"));
9875 inst.instruction |= inst.operands[0].reg << 16;
9876 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
9877 inst.instruction |= inst.operands[1].imm;
9878 }
9879
9880 static void
9881 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
9882 {
9883 int count;
9884
9885 if (inst.operands[0].writeback)
9886 inst.instruction |= WRITE_BACK;
9887 else
9888 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9889 _("this addressing mode requires base-register writeback"));
9890
9891 inst.instruction |= inst.operands[0].reg << 16;
9892 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9893
9894 count = inst.operands[1].imm << 1;
9895 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9896 count += 1;
9897
9898 inst.instruction |= count;
9899 }
9900
9901 static void
9902 do_vfp_sp_ldstmia (void)
9903 {
9904 vfp_sp_ldstm (VFP_LDSTMIA);
9905 }
9906
9907 static void
9908 do_vfp_sp_ldstmdb (void)
9909 {
9910 vfp_sp_ldstm (VFP_LDSTMDB);
9911 }
9912
9913 static void
9914 do_vfp_dp_ldstmia (void)
9915 {
9916 vfp_dp_ldstm (VFP_LDSTMIA);
9917 }
9918
9919 static void
9920 do_vfp_dp_ldstmdb (void)
9921 {
9922 vfp_dp_ldstm (VFP_LDSTMDB);
9923 }
9924
9925 static void
9926 do_vfp_xp_ldstmia (void)
9927 {
9928 vfp_dp_ldstm (VFP_LDSTMIAX);
9929 }
9930
9931 static void
9932 do_vfp_xp_ldstmdb (void)
9933 {
9934 vfp_dp_ldstm (VFP_LDSTMDBX);
9935 }
9936
9937 static void
9938 do_vfp_dp_rd_rm (void)
9939 {
9940 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9941 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9942 }
9943
9944 static void
9945 do_vfp_dp_rn_rd (void)
9946 {
9947 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9948 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9949 }
9950
9951 static void
9952 do_vfp_dp_rd_rn (void)
9953 {
9954 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9955 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9956 }
9957
9958 static void
9959 do_vfp_dp_rd_rn_rm (void)
9960 {
9961 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9962 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9963 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9964 }
9965
9966 static void
9967 do_vfp_dp_rd (void)
9968 {
9969 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9970 }
9971
9972 static void
9973 do_vfp_dp_rm_rd_rn (void)
9974 {
9975 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9976 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9977 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9978 }
9979
9980 /* VFPv3 instructions. */
9981 static void
9982 do_vfp_sp_const (void)
9983 {
9984 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9985 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9986 inst.instruction |= (inst.operands[1].imm & 0x0f);
9987 }
9988
9989 static void
9990 do_vfp_dp_const (void)
9991 {
9992 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9993 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9994 inst.instruction |= (inst.operands[1].imm & 0x0f);
9995 }
9996
9997 static void
9998 vfp_conv (int srcsize)
9999 {
10000 int immbits = srcsize - inst.operands[1].imm;
10001
10002 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
10003 {
10004 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
10005 i.e. immbits must be in range 0 - 16. */
10006 inst.error = _("immediate value out of range, expected range [0, 16]");
10007 return;
10008 }
10009 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
10010 {
10011 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
10012 i.e. immbits must be in range 0 - 31. */
10013 inst.error = _("immediate value out of range, expected range [1, 32]");
10014 return;
10015 }
10016
10017 inst.instruction |= (immbits & 1) << 5;
10018 inst.instruction |= (immbits >> 1);
10019 }
10020
10021 static void
10022 do_vfp_sp_conv_16 (void)
10023 {
10024 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10025 vfp_conv (16);
10026 }
10027
10028 static void
10029 do_vfp_dp_conv_16 (void)
10030 {
10031 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10032 vfp_conv (16);
10033 }
10034
10035 static void
10036 do_vfp_sp_conv_32 (void)
10037 {
10038 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10039 vfp_conv (32);
10040 }
10041
10042 static void
10043 do_vfp_dp_conv_32 (void)
10044 {
10045 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10046 vfp_conv (32);
10047 }
10048 \f
10049 /* FPA instructions. Also in a logical order. */
10050
10051 static void
10052 do_fpa_cmp (void)
10053 {
10054 inst.instruction |= inst.operands[0].reg << 16;
10055 inst.instruction |= inst.operands[1].reg;
10056 }
10057
10058 static void
10059 do_fpa_ldmstm (void)
10060 {
10061 inst.instruction |= inst.operands[0].reg << 12;
10062 switch (inst.operands[1].imm)
10063 {
10064 case 1: inst.instruction |= CP_T_X; break;
10065 case 2: inst.instruction |= CP_T_Y; break;
10066 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10067 case 4: break;
10068 default: abort ();
10069 }
10070
10071 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10072 {
10073 /* The instruction specified "ea" or "fd", so we can only accept
10074 [Rn]{!}. The instruction does not really support stacking or
10075 unstacking, so we have to emulate these by setting appropriate
10076 bits and offsets. */
10077 constraint (inst.relocs[0].exp.X_op != O_constant
10078 || inst.relocs[0].exp.X_add_number != 0,
10079 _("this instruction does not support indexing"));
10080
10081 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10082 inst.relocs[0].exp.X_add_number = 12 * inst.operands[1].imm;
10083
10084 if (!(inst.instruction & INDEX_UP))
10085 inst.relocs[0].exp.X_add_number = -inst.relocs[0].exp.X_add_number;
10086
10087 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10088 {
10089 inst.operands[2].preind = 0;
10090 inst.operands[2].postind = 1;
10091 }
10092 }
10093
10094 encode_arm_cp_address (2, TRUE, TRUE, 0);
10095 }
10096 \f
10097 /* iWMMXt instructions: strictly in alphabetical order. */
10098
10099 static void
10100 do_iwmmxt_tandorc (void)
10101 {
10102 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10103 }
10104
10105 static void
10106 do_iwmmxt_textrc (void)
10107 {
10108 inst.instruction |= inst.operands[0].reg << 12;
10109 inst.instruction |= inst.operands[1].imm;
10110 }
10111
10112 static void
10113 do_iwmmxt_textrm (void)
10114 {
10115 inst.instruction |= inst.operands[0].reg << 12;
10116 inst.instruction |= inst.operands[1].reg << 16;
10117 inst.instruction |= inst.operands[2].imm;
10118 }
10119
10120 static void
10121 do_iwmmxt_tinsr (void)
10122 {
10123 inst.instruction |= inst.operands[0].reg << 16;
10124 inst.instruction |= inst.operands[1].reg << 12;
10125 inst.instruction |= inst.operands[2].imm;
10126 }
10127
10128 static void
10129 do_iwmmxt_tmia (void)
10130 {
10131 inst.instruction |= inst.operands[0].reg << 5;
10132 inst.instruction |= inst.operands[1].reg;
10133 inst.instruction |= inst.operands[2].reg << 12;
10134 }
10135
10136 static void
10137 do_iwmmxt_waligni (void)
10138 {
10139 inst.instruction |= inst.operands[0].reg << 12;
10140 inst.instruction |= inst.operands[1].reg << 16;
10141 inst.instruction |= inst.operands[2].reg;
10142 inst.instruction |= inst.operands[3].imm << 20;
10143 }
10144
10145 static void
10146 do_iwmmxt_wmerge (void)
10147 {
10148 inst.instruction |= inst.operands[0].reg << 12;
10149 inst.instruction |= inst.operands[1].reg << 16;
10150 inst.instruction |= inst.operands[2].reg;
10151 inst.instruction |= inst.operands[3].imm << 21;
10152 }
10153
10154 static void
10155 do_iwmmxt_wmov (void)
10156 {
10157 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10158 inst.instruction |= inst.operands[0].reg << 12;
10159 inst.instruction |= inst.operands[1].reg << 16;
10160 inst.instruction |= inst.operands[1].reg;
10161 }
10162
10163 static void
10164 do_iwmmxt_wldstbh (void)
10165 {
10166 int reloc;
10167 inst.instruction |= inst.operands[0].reg << 12;
10168 if (thumb_mode)
10169 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10170 else
10171 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10172 encode_arm_cp_address (1, TRUE, FALSE, reloc);
10173 }
10174
10175 static void
10176 do_iwmmxt_wldstw (void)
10177 {
10178 /* RIWR_RIWC clears .isreg for a control register. */
10179 if (!inst.operands[0].isreg)
10180 {
10181 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10182 inst.instruction |= 0xf0000000;
10183 }
10184
10185 inst.instruction |= inst.operands[0].reg << 12;
10186 encode_arm_cp_address (1, TRUE, TRUE, 0);
10187 }
10188
10189 static void
10190 do_iwmmxt_wldstd (void)
10191 {
10192 inst.instruction |= inst.operands[0].reg << 12;
10193 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10194 && inst.operands[1].immisreg)
10195 {
10196 inst.instruction &= ~0x1a000ff;
10197 inst.instruction |= (0xfU << 28);
10198 if (inst.operands[1].preind)
10199 inst.instruction |= PRE_INDEX;
10200 if (!inst.operands[1].negative)
10201 inst.instruction |= INDEX_UP;
10202 if (inst.operands[1].writeback)
10203 inst.instruction |= WRITE_BACK;
10204 inst.instruction |= inst.operands[1].reg << 16;
10205 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
10206 inst.instruction |= inst.operands[1].imm;
10207 }
10208 else
10209 encode_arm_cp_address (1, TRUE, FALSE, 0);
10210 }
10211
10212 static void
10213 do_iwmmxt_wshufh (void)
10214 {
10215 inst.instruction |= inst.operands[0].reg << 12;
10216 inst.instruction |= inst.operands[1].reg << 16;
10217 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10218 inst.instruction |= (inst.operands[2].imm & 0x0f);
10219 }
10220
10221 static void
10222 do_iwmmxt_wzero (void)
10223 {
10224 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10225 inst.instruction |= inst.operands[0].reg;
10226 inst.instruction |= inst.operands[0].reg << 12;
10227 inst.instruction |= inst.operands[0].reg << 16;
10228 }
10229
10230 static void
10231 do_iwmmxt_wrwrwr_or_imm5 (void)
10232 {
10233 if (inst.operands[2].isreg)
10234 do_rd_rn_rm ();
10235 else {
10236 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10237 _("immediate operand requires iWMMXt2"));
10238 do_rd_rn ();
10239 if (inst.operands[2].imm == 0)
10240 {
10241 switch ((inst.instruction >> 20) & 0xf)
10242 {
10243 case 4:
10244 case 5:
10245 case 6:
10246 case 7:
10247 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10248 inst.operands[2].imm = 16;
10249 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10250 break;
10251 case 8:
10252 case 9:
10253 case 10:
10254 case 11:
10255 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10256 inst.operands[2].imm = 32;
10257 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10258 break;
10259 case 12:
10260 case 13:
10261 case 14:
10262 case 15:
10263 {
10264 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10265 unsigned long wrn;
10266 wrn = (inst.instruction >> 16) & 0xf;
10267 inst.instruction &= 0xff0fff0f;
10268 inst.instruction |= wrn;
10269 /* Bail out here; the instruction is now assembled. */
10270 return;
10271 }
10272 }
10273 }
10274 /* Map 32 -> 0, etc. */
10275 inst.operands[2].imm &= 0x1f;
10276 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
10277 }
10278 }
10279 \f
10280 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10281 operations first, then control, shift, and load/store. */
10282
10283 /* Insns like "foo X,Y,Z". */
10284
10285 static void
10286 do_mav_triple (void)
10287 {
10288 inst.instruction |= inst.operands[0].reg << 16;
10289 inst.instruction |= inst.operands[1].reg;
10290 inst.instruction |= inst.operands[2].reg << 12;
10291 }
10292
10293 /* Insns like "foo W,X,Y,Z".
10294 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
10295
10296 static void
10297 do_mav_quad (void)
10298 {
10299 inst.instruction |= inst.operands[0].reg << 5;
10300 inst.instruction |= inst.operands[1].reg << 12;
10301 inst.instruction |= inst.operands[2].reg << 16;
10302 inst.instruction |= inst.operands[3].reg;
10303 }
10304
10305 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10306 static void
10307 do_mav_dspsc (void)
10308 {
10309 inst.instruction |= inst.operands[1].reg << 12;
10310 }
10311
10312 /* Maverick shift immediate instructions.
10313 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10314 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
10315
10316 static void
10317 do_mav_shift (void)
10318 {
10319 int imm = inst.operands[2].imm;
10320
10321 inst.instruction |= inst.operands[0].reg << 12;
10322 inst.instruction |= inst.operands[1].reg << 16;
10323
10324 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10325 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10326 Bit 4 should be 0. */
10327 imm = (imm & 0xf) | ((imm & 0x70) << 1);
10328
10329 inst.instruction |= imm;
10330 }
10331 \f
10332 /* XScale instructions. Also sorted arithmetic before move. */
10333
10334 /* Xscale multiply-accumulate (argument parse)
10335 MIAcc acc0,Rm,Rs
10336 MIAPHcc acc0,Rm,Rs
10337 MIAxycc acc0,Rm,Rs. */
10338
10339 static void
10340 do_xsc_mia (void)
10341 {
10342 inst.instruction |= inst.operands[1].reg;
10343 inst.instruction |= inst.operands[2].reg << 12;
10344 }
10345
10346 /* Xscale move-accumulator-register (argument parse)
10347
10348 MARcc acc0,RdLo,RdHi. */
10349
10350 static void
10351 do_xsc_mar (void)
10352 {
10353 inst.instruction |= inst.operands[1].reg << 12;
10354 inst.instruction |= inst.operands[2].reg << 16;
10355 }
10356
10357 /* Xscale move-register-accumulator (argument parse)
10358
10359 MRAcc RdLo,RdHi,acc0. */
10360
10361 static void
10362 do_xsc_mra (void)
10363 {
10364 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10365 inst.instruction |= inst.operands[0].reg << 12;
10366 inst.instruction |= inst.operands[1].reg << 16;
10367 }
10368 \f
10369 /* Encoding functions relevant only to Thumb. */
10370
10371 /* inst.operands[i] is a shifted-register operand; encode
10372 it into inst.instruction in the format used by Thumb32. */
10373
10374 static void
10375 encode_thumb32_shifted_operand (int i)
10376 {
10377 unsigned int value = inst.relocs[0].exp.X_add_number;
10378 unsigned int shift = inst.operands[i].shift_kind;
10379
10380 constraint (inst.operands[i].immisreg,
10381 _("shift by register not allowed in thumb mode"));
10382 inst.instruction |= inst.operands[i].reg;
10383 if (shift == SHIFT_RRX)
10384 inst.instruction |= SHIFT_ROR << 4;
10385 else
10386 {
10387 constraint (inst.relocs[0].exp.X_op != O_constant,
10388 _("expression too complex"));
10389
10390 constraint (value > 32
10391 || (value == 32 && (shift == SHIFT_LSL
10392 || shift == SHIFT_ROR)),
10393 _("shift expression is too large"));
10394
10395 if (value == 0)
10396 shift = SHIFT_LSL;
10397 else if (value == 32)
10398 value = 0;
10399
10400 inst.instruction |= shift << 4;
10401 inst.instruction |= (value & 0x1c) << 10;
10402 inst.instruction |= (value & 0x03) << 6;
10403 }
10404 }
10405
10406
10407 /* inst.operands[i] was set up by parse_address. Encode it into a
10408 Thumb32 format load or store instruction. Reject forms that cannot
10409 be used with such instructions. If is_t is true, reject forms that
10410 cannot be used with a T instruction; if is_d is true, reject forms
10411 that cannot be used with a D instruction. If it is a store insn,
10412 reject PC in Rn. */
10413
10414 static void
10415 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10416 {
10417 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
10418
10419 constraint (!inst.operands[i].isreg,
10420 _("Instruction does not support =N addresses"));
10421
10422 inst.instruction |= inst.operands[i].reg << 16;
10423 if (inst.operands[i].immisreg)
10424 {
10425 constraint (is_pc, BAD_PC_ADDRESSING);
10426 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10427 constraint (inst.operands[i].negative,
10428 _("Thumb does not support negative register indexing"));
10429 constraint (inst.operands[i].postind,
10430 _("Thumb does not support register post-indexing"));
10431 constraint (inst.operands[i].writeback,
10432 _("Thumb does not support register indexing with writeback"));
10433 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10434 _("Thumb supports only LSL in shifted register indexing"));
10435
10436 inst.instruction |= inst.operands[i].imm;
10437 if (inst.operands[i].shifted)
10438 {
10439 constraint (inst.relocs[0].exp.X_op != O_constant,
10440 _("expression too complex"));
10441 constraint (inst.relocs[0].exp.X_add_number < 0
10442 || inst.relocs[0].exp.X_add_number > 3,
10443 _("shift out of range"));
10444 inst.instruction |= inst.relocs[0].exp.X_add_number << 4;
10445 }
10446 inst.relocs[0].type = BFD_RELOC_UNUSED;
10447 }
10448 else if (inst.operands[i].preind)
10449 {
10450 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
10451 constraint (is_t && inst.operands[i].writeback,
10452 _("cannot use writeback with this instruction"));
10453 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10454 BAD_PC_ADDRESSING);
10455
10456 if (is_d)
10457 {
10458 inst.instruction |= 0x01000000;
10459 if (inst.operands[i].writeback)
10460 inst.instruction |= 0x00200000;
10461 }
10462 else
10463 {
10464 inst.instruction |= 0x00000c00;
10465 if (inst.operands[i].writeback)
10466 inst.instruction |= 0x00000100;
10467 }
10468 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10469 }
10470 else if (inst.operands[i].postind)
10471 {
10472 gas_assert (inst.operands[i].writeback);
10473 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10474 constraint (is_t, _("cannot use post-indexing with this instruction"));
10475
10476 if (is_d)
10477 inst.instruction |= 0x00200000;
10478 else
10479 inst.instruction |= 0x00000900;
10480 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10481 }
10482 else /* unindexed - only for coprocessor */
10483 inst.error = _("instruction does not accept unindexed addressing");
10484 }
10485
10486 /* Table of Thumb instructions which exist in both 16- and 32-bit
10487 encodings (the latter only in post-V6T2 cores). The index is the
10488 value used in the insns table below. When there is more than one
10489 possible 16-bit encoding for the instruction, this table always
10490 holds variant (1).
10491 Also contains several pseudo-instructions used during relaxation. */
10492 #define T16_32_TAB \
10493 X(_adc, 4140, eb400000), \
10494 X(_adcs, 4140, eb500000), \
10495 X(_add, 1c00, eb000000), \
10496 X(_adds, 1c00, eb100000), \
10497 X(_addi, 0000, f1000000), \
10498 X(_addis, 0000, f1100000), \
10499 X(_add_pc,000f, f20f0000), \
10500 X(_add_sp,000d, f10d0000), \
10501 X(_adr, 000f, f20f0000), \
10502 X(_and, 4000, ea000000), \
10503 X(_ands, 4000, ea100000), \
10504 X(_asr, 1000, fa40f000), \
10505 X(_asrs, 1000, fa50f000), \
10506 X(_b, e000, f000b000), \
10507 X(_bcond, d000, f0008000), \
10508 X(_bic, 4380, ea200000), \
10509 X(_bics, 4380, ea300000), \
10510 X(_cmn, 42c0, eb100f00), \
10511 X(_cmp, 2800, ebb00f00), \
10512 X(_cpsie, b660, f3af8400), \
10513 X(_cpsid, b670, f3af8600), \
10514 X(_cpy, 4600, ea4f0000), \
10515 X(_dec_sp,80dd, f1ad0d00), \
10516 X(_eor, 4040, ea800000), \
10517 X(_eors, 4040, ea900000), \
10518 X(_inc_sp,00dd, f10d0d00), \
10519 X(_ldmia, c800, e8900000), \
10520 X(_ldr, 6800, f8500000), \
10521 X(_ldrb, 7800, f8100000), \
10522 X(_ldrh, 8800, f8300000), \
10523 X(_ldrsb, 5600, f9100000), \
10524 X(_ldrsh, 5e00, f9300000), \
10525 X(_ldr_pc,4800, f85f0000), \
10526 X(_ldr_pc2,4800, f85f0000), \
10527 X(_ldr_sp,9800, f85d0000), \
10528 X(_lsl, 0000, fa00f000), \
10529 X(_lsls, 0000, fa10f000), \
10530 X(_lsr, 0800, fa20f000), \
10531 X(_lsrs, 0800, fa30f000), \
10532 X(_mov, 2000, ea4f0000), \
10533 X(_movs, 2000, ea5f0000), \
10534 X(_mul, 4340, fb00f000), \
10535 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10536 X(_mvn, 43c0, ea6f0000), \
10537 X(_mvns, 43c0, ea7f0000), \
10538 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10539 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10540 X(_orr, 4300, ea400000), \
10541 X(_orrs, 4300, ea500000), \
10542 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10543 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10544 X(_rev, ba00, fa90f080), \
10545 X(_rev16, ba40, fa90f090), \
10546 X(_revsh, bac0, fa90f0b0), \
10547 X(_ror, 41c0, fa60f000), \
10548 X(_rors, 41c0, fa70f000), \
10549 X(_sbc, 4180, eb600000), \
10550 X(_sbcs, 4180, eb700000), \
10551 X(_stmia, c000, e8800000), \
10552 X(_str, 6000, f8400000), \
10553 X(_strb, 7000, f8000000), \
10554 X(_strh, 8000, f8200000), \
10555 X(_str_sp,9000, f84d0000), \
10556 X(_sub, 1e00, eba00000), \
10557 X(_subs, 1e00, ebb00000), \
10558 X(_subi, 8000, f1a00000), \
10559 X(_subis, 8000, f1b00000), \
10560 X(_sxtb, b240, fa4ff080), \
10561 X(_sxth, b200, fa0ff080), \
10562 X(_tst, 4200, ea100f00), \
10563 X(_uxtb, b2c0, fa5ff080), \
10564 X(_uxth, b280, fa1ff080), \
10565 X(_nop, bf00, f3af8000), \
10566 X(_yield, bf10, f3af8001), \
10567 X(_wfe, bf20, f3af8002), \
10568 X(_wfi, bf30, f3af8003), \
10569 X(_sev, bf40, f3af8004), \
10570 X(_sevl, bf50, f3af8005), \
10571 X(_udf, de00, f7f0a000)
10572
10573 /* To catch errors in encoding functions, the codes are all offset by
10574 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10575 as 16-bit instructions. */
10576 #define X(a,b,c) T_MNEM##a
10577 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10578 #undef X
10579
10580 #define X(a,b,c) 0x##b
10581 static const unsigned short thumb_op16[] = { T16_32_TAB };
10582 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10583 #undef X
10584
10585 #define X(a,b,c) 0x##c
10586 static const unsigned int thumb_op32[] = { T16_32_TAB };
10587 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10588 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
10589 #undef X
10590 #undef T16_32_TAB
10591
10592 /* Thumb instruction encoders, in alphabetical order. */
10593
10594 /* ADDW or SUBW. */
10595
10596 static void
10597 do_t_add_sub_w (void)
10598 {
10599 int Rd, Rn;
10600
10601 Rd = inst.operands[0].reg;
10602 Rn = inst.operands[1].reg;
10603
10604 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10605 is the SP-{plus,minus}-immediate form of the instruction. */
10606 if (Rn == REG_SP)
10607 constraint (Rd == REG_PC, BAD_PC);
10608 else
10609 reject_bad_reg (Rd);
10610
10611 inst.instruction |= (Rn << 16) | (Rd << 8);
10612 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
10613 }
10614
10615 /* Parse an add or subtract instruction. We get here with inst.instruction
10616 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
10617
10618 static void
10619 do_t_add_sub (void)
10620 {
10621 int Rd, Rs, Rn;
10622
10623 Rd = inst.operands[0].reg;
10624 Rs = (inst.operands[1].present
10625 ? inst.operands[1].reg /* Rd, Rs, foo */
10626 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10627
10628 if (Rd == REG_PC)
10629 set_it_insn_type_last ();
10630
10631 if (unified_syntax)
10632 {
10633 bfd_boolean flags;
10634 bfd_boolean narrow;
10635 int opcode;
10636
10637 flags = (inst.instruction == T_MNEM_adds
10638 || inst.instruction == T_MNEM_subs);
10639 if (flags)
10640 narrow = !in_it_block ();
10641 else
10642 narrow = in_it_block ();
10643 if (!inst.operands[2].isreg)
10644 {
10645 int add;
10646
10647 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10648 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10649
10650 add = (inst.instruction == T_MNEM_add
10651 || inst.instruction == T_MNEM_adds);
10652 opcode = 0;
10653 if (inst.size_req != 4)
10654 {
10655 /* Attempt to use a narrow opcode, with relaxation if
10656 appropriate. */
10657 if (Rd == REG_SP && Rs == REG_SP && !flags)
10658 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10659 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10660 opcode = T_MNEM_add_sp;
10661 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10662 opcode = T_MNEM_add_pc;
10663 else if (Rd <= 7 && Rs <= 7 && narrow)
10664 {
10665 if (flags)
10666 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10667 else
10668 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10669 }
10670 if (opcode)
10671 {
10672 inst.instruction = THUMB_OP16(opcode);
10673 inst.instruction |= (Rd << 4) | Rs;
10674 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10675 || (inst.relocs[0].type
10676 > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC))
10677 {
10678 if (inst.size_req == 2)
10679 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
10680 else
10681 inst.relax = opcode;
10682 }
10683 }
10684 else
10685 constraint (inst.size_req == 2, BAD_HIREG);
10686 }
10687 if (inst.size_req == 4
10688 || (inst.size_req != 2 && !opcode))
10689 {
10690 constraint ((inst.relocs[0].type
10691 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
10692 && (inst.relocs[0].type
10693 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
10694 THUMB1_RELOC_ONLY);
10695 if (Rd == REG_PC)
10696 {
10697 constraint (add, BAD_PC);
10698 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10699 _("only SUBS PC, LR, #const allowed"));
10700 constraint (inst.relocs[0].exp.X_op != O_constant,
10701 _("expression too complex"));
10702 constraint (inst.relocs[0].exp.X_add_number < 0
10703 || inst.relocs[0].exp.X_add_number > 0xff,
10704 _("immediate value out of range"));
10705 inst.instruction = T2_SUBS_PC_LR
10706 | inst.relocs[0].exp.X_add_number;
10707 inst.relocs[0].type = BFD_RELOC_UNUSED;
10708 return;
10709 }
10710 else if (Rs == REG_PC)
10711 {
10712 /* Always use addw/subw. */
10713 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10714 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMM12;
10715 }
10716 else
10717 {
10718 inst.instruction = THUMB_OP32 (inst.instruction);
10719 inst.instruction = (inst.instruction & 0xe1ffffff)
10720 | 0x10000000;
10721 if (flags)
10722 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
10723 else
10724 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_IMM;
10725 }
10726 inst.instruction |= Rd << 8;
10727 inst.instruction |= Rs << 16;
10728 }
10729 }
10730 else
10731 {
10732 unsigned int value = inst.relocs[0].exp.X_add_number;
10733 unsigned int shift = inst.operands[2].shift_kind;
10734
10735 Rn = inst.operands[2].reg;
10736 /* See if we can do this with a 16-bit instruction. */
10737 if (!inst.operands[2].shifted && inst.size_req != 4)
10738 {
10739 if (Rd > 7 || Rs > 7 || Rn > 7)
10740 narrow = FALSE;
10741
10742 if (narrow)
10743 {
10744 inst.instruction = ((inst.instruction == T_MNEM_adds
10745 || inst.instruction == T_MNEM_add)
10746 ? T_OPCODE_ADD_R3
10747 : T_OPCODE_SUB_R3);
10748 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10749 return;
10750 }
10751
10752 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
10753 {
10754 /* Thumb-1 cores (except v6-M) require at least one high
10755 register in a narrow non flag setting add. */
10756 if (Rd > 7 || Rn > 7
10757 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10758 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
10759 {
10760 if (Rd == Rn)
10761 {
10762 Rn = Rs;
10763 Rs = Rd;
10764 }
10765 inst.instruction = T_OPCODE_ADD_HI;
10766 inst.instruction |= (Rd & 8) << 4;
10767 inst.instruction |= (Rd & 7);
10768 inst.instruction |= Rn << 3;
10769 return;
10770 }
10771 }
10772 }
10773
10774 constraint (Rd == REG_PC, BAD_PC);
10775 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10776 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10777 constraint (Rs == REG_PC, BAD_PC);
10778 reject_bad_reg (Rn);
10779
10780 /* If we get here, it can't be done in 16 bits. */
10781 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10782 _("shift must be constant"));
10783 inst.instruction = THUMB_OP32 (inst.instruction);
10784 inst.instruction |= Rd << 8;
10785 inst.instruction |= Rs << 16;
10786 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10787 _("shift value over 3 not allowed in thumb mode"));
10788 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10789 _("only LSL shift allowed in thumb mode"));
10790 encode_thumb32_shifted_operand (2);
10791 }
10792 }
10793 else
10794 {
10795 constraint (inst.instruction == T_MNEM_adds
10796 || inst.instruction == T_MNEM_subs,
10797 BAD_THUMB32);
10798
10799 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
10800 {
10801 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10802 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10803 BAD_HIREG);
10804
10805 inst.instruction = (inst.instruction == T_MNEM_add
10806 ? 0x0000 : 0x8000);
10807 inst.instruction |= (Rd << 4) | Rs;
10808 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
10809 return;
10810 }
10811
10812 Rn = inst.operands[2].reg;
10813 constraint (inst.operands[2].shifted, _("unshifted register required"));
10814
10815 /* We now have Rd, Rs, and Rn set to registers. */
10816 if (Rd > 7 || Rs > 7 || Rn > 7)
10817 {
10818 /* Can't do this for SUB. */
10819 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10820 inst.instruction = T_OPCODE_ADD_HI;
10821 inst.instruction |= (Rd & 8) << 4;
10822 inst.instruction |= (Rd & 7);
10823 if (Rs == Rd)
10824 inst.instruction |= Rn << 3;
10825 else if (Rn == Rd)
10826 inst.instruction |= Rs << 3;
10827 else
10828 constraint (1, _("dest must overlap one source register"));
10829 }
10830 else
10831 {
10832 inst.instruction = (inst.instruction == T_MNEM_add
10833 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10834 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10835 }
10836 }
10837 }
10838
10839 static void
10840 do_t_adr (void)
10841 {
10842 unsigned Rd;
10843
10844 Rd = inst.operands[0].reg;
10845 reject_bad_reg (Rd);
10846
10847 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
10848 {
10849 /* Defer to section relaxation. */
10850 inst.relax = inst.instruction;
10851 inst.instruction = THUMB_OP16 (inst.instruction);
10852 inst.instruction |= Rd << 4;
10853 }
10854 else if (unified_syntax && inst.size_req != 2)
10855 {
10856 /* Generate a 32-bit opcode. */
10857 inst.instruction = THUMB_OP32 (inst.instruction);
10858 inst.instruction |= Rd << 8;
10859 inst.relocs[0].type = BFD_RELOC_ARM_T32_ADD_PC12;
10860 inst.relocs[0].pc_rel = 1;
10861 }
10862 else
10863 {
10864 /* Generate a 16-bit opcode. */
10865 inst.instruction = THUMB_OP16 (inst.instruction);
10866 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_ADD;
10867 inst.relocs[0].exp.X_add_number -= 4; /* PC relative adjust. */
10868 inst.relocs[0].pc_rel = 1;
10869 inst.instruction |= Rd << 4;
10870 }
10871
10872 if (inst.relocs[0].exp.X_op == O_symbol
10873 && inst.relocs[0].exp.X_add_symbol != NULL
10874 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
10875 && THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
10876 inst.relocs[0].exp.X_add_number += 1;
10877 }
10878
10879 /* Arithmetic instructions for which there is just one 16-bit
10880 instruction encoding, and it allows only two low registers.
10881 For maximal compatibility with ARM syntax, we allow three register
10882 operands even when Thumb-32 instructions are not available, as long
10883 as the first two are identical. For instance, both "sbc r0,r1" and
10884 "sbc r0,r0,r1" are allowed. */
10885 static void
10886 do_t_arit3 (void)
10887 {
10888 int Rd, Rs, Rn;
10889
10890 Rd = inst.operands[0].reg;
10891 Rs = (inst.operands[1].present
10892 ? inst.operands[1].reg /* Rd, Rs, foo */
10893 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10894 Rn = inst.operands[2].reg;
10895
10896 reject_bad_reg (Rd);
10897 reject_bad_reg (Rs);
10898 if (inst.operands[2].isreg)
10899 reject_bad_reg (Rn);
10900
10901 if (unified_syntax)
10902 {
10903 if (!inst.operands[2].isreg)
10904 {
10905 /* For an immediate, we always generate a 32-bit opcode;
10906 section relaxation will shrink it later if possible. */
10907 inst.instruction = THUMB_OP32 (inst.instruction);
10908 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10909 inst.instruction |= Rd << 8;
10910 inst.instruction |= Rs << 16;
10911 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
10912 }
10913 else
10914 {
10915 bfd_boolean narrow;
10916
10917 /* See if we can do this with a 16-bit instruction. */
10918 if (THUMB_SETS_FLAGS (inst.instruction))
10919 narrow = !in_it_block ();
10920 else
10921 narrow = in_it_block ();
10922
10923 if (Rd > 7 || Rn > 7 || Rs > 7)
10924 narrow = FALSE;
10925 if (inst.operands[2].shifted)
10926 narrow = FALSE;
10927 if (inst.size_req == 4)
10928 narrow = FALSE;
10929
10930 if (narrow
10931 && Rd == Rs)
10932 {
10933 inst.instruction = THUMB_OP16 (inst.instruction);
10934 inst.instruction |= Rd;
10935 inst.instruction |= Rn << 3;
10936 return;
10937 }
10938
10939 /* If we get here, it can't be done in 16 bits. */
10940 constraint (inst.operands[2].shifted
10941 && inst.operands[2].immisreg,
10942 _("shift must be constant"));
10943 inst.instruction = THUMB_OP32 (inst.instruction);
10944 inst.instruction |= Rd << 8;
10945 inst.instruction |= Rs << 16;
10946 encode_thumb32_shifted_operand (2);
10947 }
10948 }
10949 else
10950 {
10951 /* On its face this is a lie - the instruction does set the
10952 flags. However, the only supported mnemonic in this mode
10953 says it doesn't. */
10954 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10955
10956 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10957 _("unshifted register required"));
10958 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10959 constraint (Rd != Rs,
10960 _("dest and source1 must be the same register"));
10961
10962 inst.instruction = THUMB_OP16 (inst.instruction);
10963 inst.instruction |= Rd;
10964 inst.instruction |= Rn << 3;
10965 }
10966 }
10967
10968 /* Similarly, but for instructions where the arithmetic operation is
10969 commutative, so we can allow either of them to be different from
10970 the destination operand in a 16-bit instruction. For instance, all
10971 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10972 accepted. */
10973 static void
10974 do_t_arit3c (void)
10975 {
10976 int Rd, Rs, Rn;
10977
10978 Rd = inst.operands[0].reg;
10979 Rs = (inst.operands[1].present
10980 ? inst.operands[1].reg /* Rd, Rs, foo */
10981 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10982 Rn = inst.operands[2].reg;
10983
10984 reject_bad_reg (Rd);
10985 reject_bad_reg (Rs);
10986 if (inst.operands[2].isreg)
10987 reject_bad_reg (Rn);
10988
10989 if (unified_syntax)
10990 {
10991 if (!inst.operands[2].isreg)
10992 {
10993 /* For an immediate, we always generate a 32-bit opcode;
10994 section relaxation will shrink it later if possible. */
10995 inst.instruction = THUMB_OP32 (inst.instruction);
10996 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10997 inst.instruction |= Rd << 8;
10998 inst.instruction |= Rs << 16;
10999 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
11000 }
11001 else
11002 {
11003 bfd_boolean narrow;
11004
11005 /* See if we can do this with a 16-bit instruction. */
11006 if (THUMB_SETS_FLAGS (inst.instruction))
11007 narrow = !in_it_block ();
11008 else
11009 narrow = in_it_block ();
11010
11011 if (Rd > 7 || Rn > 7 || Rs > 7)
11012 narrow = FALSE;
11013 if (inst.operands[2].shifted)
11014 narrow = FALSE;
11015 if (inst.size_req == 4)
11016 narrow = FALSE;
11017
11018 if (narrow)
11019 {
11020 if (Rd == Rs)
11021 {
11022 inst.instruction = THUMB_OP16 (inst.instruction);
11023 inst.instruction |= Rd;
11024 inst.instruction |= Rn << 3;
11025 return;
11026 }
11027 if (Rd == Rn)
11028 {
11029 inst.instruction = THUMB_OP16 (inst.instruction);
11030 inst.instruction |= Rd;
11031 inst.instruction |= Rs << 3;
11032 return;
11033 }
11034 }
11035
11036 /* If we get here, it can't be done in 16 bits. */
11037 constraint (inst.operands[2].shifted
11038 && inst.operands[2].immisreg,
11039 _("shift must be constant"));
11040 inst.instruction = THUMB_OP32 (inst.instruction);
11041 inst.instruction |= Rd << 8;
11042 inst.instruction |= Rs << 16;
11043 encode_thumb32_shifted_operand (2);
11044 }
11045 }
11046 else
11047 {
11048 /* On its face this is a lie - the instruction does set the
11049 flags. However, the only supported mnemonic in this mode
11050 says it doesn't. */
11051 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11052
11053 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11054 _("unshifted register required"));
11055 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11056
11057 inst.instruction = THUMB_OP16 (inst.instruction);
11058 inst.instruction |= Rd;
11059
11060 if (Rd == Rs)
11061 inst.instruction |= Rn << 3;
11062 else if (Rd == Rn)
11063 inst.instruction |= Rs << 3;
11064 else
11065 constraint (1, _("dest must overlap one source register"));
11066 }
11067 }
11068
11069 static void
11070 do_t_bfc (void)
11071 {
11072 unsigned Rd;
11073 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11074 constraint (msb > 32, _("bit-field extends past end of register"));
11075 /* The instruction encoding stores the LSB and MSB,
11076 not the LSB and width. */
11077 Rd = inst.operands[0].reg;
11078 reject_bad_reg (Rd);
11079 inst.instruction |= Rd << 8;
11080 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11081 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11082 inst.instruction |= msb - 1;
11083 }
11084
11085 static void
11086 do_t_bfi (void)
11087 {
11088 int Rd, Rn;
11089 unsigned int msb;
11090
11091 Rd = inst.operands[0].reg;
11092 reject_bad_reg (Rd);
11093
11094 /* #0 in second position is alternative syntax for bfc, which is
11095 the same instruction but with REG_PC in the Rm field. */
11096 if (!inst.operands[1].isreg)
11097 Rn = REG_PC;
11098 else
11099 {
11100 Rn = inst.operands[1].reg;
11101 reject_bad_reg (Rn);
11102 }
11103
11104 msb = inst.operands[2].imm + inst.operands[3].imm;
11105 constraint (msb > 32, _("bit-field extends past end of register"));
11106 /* The instruction encoding stores the LSB and MSB,
11107 not the LSB and width. */
11108 inst.instruction |= Rd << 8;
11109 inst.instruction |= Rn << 16;
11110 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11111 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11112 inst.instruction |= msb - 1;
11113 }
11114
11115 static void
11116 do_t_bfx (void)
11117 {
11118 unsigned Rd, Rn;
11119
11120 Rd = inst.operands[0].reg;
11121 Rn = inst.operands[1].reg;
11122
11123 reject_bad_reg (Rd);
11124 reject_bad_reg (Rn);
11125
11126 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11127 _("bit-field extends past end of register"));
11128 inst.instruction |= Rd << 8;
11129 inst.instruction |= Rn << 16;
11130 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11131 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11132 inst.instruction |= inst.operands[3].imm - 1;
11133 }
11134
11135 /* ARM V5 Thumb BLX (argument parse)
11136 BLX <target_addr> which is BLX(1)
11137 BLX <Rm> which is BLX(2)
11138 Unfortunately, there are two different opcodes for this mnemonic.
11139 So, the insns[].value is not used, and the code here zaps values
11140 into inst.instruction.
11141
11142 ??? How to take advantage of the additional two bits of displacement
11143 available in Thumb32 mode? Need new relocation? */
11144
11145 static void
11146 do_t_blx (void)
11147 {
11148 set_it_insn_type_last ();
11149
11150 if (inst.operands[0].isreg)
11151 {
11152 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11153 /* We have a register, so this is BLX(2). */
11154 inst.instruction |= inst.operands[0].reg << 3;
11155 }
11156 else
11157 {
11158 /* No register. This must be BLX(1). */
11159 inst.instruction = 0xf000e800;
11160 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
11161 }
11162 }
11163
11164 static void
11165 do_t_branch (void)
11166 {
11167 int opcode;
11168 int cond;
11169 bfd_reloc_code_real_type reloc;
11170
11171 cond = inst.cond;
11172 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11173
11174 if (in_it_block ())
11175 {
11176 /* Conditional branches inside IT blocks are encoded as unconditional
11177 branches. */
11178 cond = COND_ALWAYS;
11179 }
11180 else
11181 cond = inst.cond;
11182
11183 if (cond != COND_ALWAYS)
11184 opcode = T_MNEM_bcond;
11185 else
11186 opcode = inst.instruction;
11187
11188 if (unified_syntax
11189 && (inst.size_req == 4
11190 || (inst.size_req != 2
11191 && (inst.operands[0].hasreloc
11192 || inst.relocs[0].exp.X_op == O_constant))))
11193 {
11194 inst.instruction = THUMB_OP32(opcode);
11195 if (cond == COND_ALWAYS)
11196 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
11197 else
11198 {
11199 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11200 _("selected architecture does not support "
11201 "wide conditional branch instruction"));
11202
11203 gas_assert (cond != 0xF);
11204 inst.instruction |= cond << 22;
11205 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
11206 }
11207 }
11208 else
11209 {
11210 inst.instruction = THUMB_OP16(opcode);
11211 if (cond == COND_ALWAYS)
11212 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
11213 else
11214 {
11215 inst.instruction |= cond << 8;
11216 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
11217 }
11218 /* Allow section relaxation. */
11219 if (unified_syntax && inst.size_req != 2)
11220 inst.relax = opcode;
11221 }
11222 inst.relocs[0].type = reloc;
11223 inst.relocs[0].pc_rel = 1;
11224 }
11225
11226 /* Actually do the work for Thumb state bkpt and hlt. The only difference
11227 between the two is the maximum immediate allowed - which is passed in
11228 RANGE. */
11229 static void
11230 do_t_bkpt_hlt1 (int range)
11231 {
11232 constraint (inst.cond != COND_ALWAYS,
11233 _("instruction is always unconditional"));
11234 if (inst.operands[0].present)
11235 {
11236 constraint (inst.operands[0].imm > range,
11237 _("immediate value out of range"));
11238 inst.instruction |= inst.operands[0].imm;
11239 }
11240
11241 set_it_insn_type (NEUTRAL_IT_INSN);
11242 }
11243
11244 static void
11245 do_t_hlt (void)
11246 {
11247 do_t_bkpt_hlt1 (63);
11248 }
11249
11250 static void
11251 do_t_bkpt (void)
11252 {
11253 do_t_bkpt_hlt1 (255);
11254 }
11255
11256 static void
11257 do_t_branch23 (void)
11258 {
11259 set_it_insn_type_last ();
11260 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
11261
11262 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11263 this file. We used to simply ignore the PLT reloc type here --
11264 the branch encoding is now needed to deal with TLSCALL relocs.
11265 So if we see a PLT reloc now, put it back to how it used to be to
11266 keep the preexisting behaviour. */
11267 if (inst.relocs[0].type == BFD_RELOC_ARM_PLT32)
11268 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH23;
11269
11270 #if defined(OBJ_COFF)
11271 /* If the destination of the branch is a defined symbol which does not have
11272 the THUMB_FUNC attribute, then we must be calling a function which has
11273 the (interfacearm) attribute. We look for the Thumb entry point to that
11274 function and change the branch to refer to that function instead. */
11275 if ( inst.relocs[0].exp.X_op == O_symbol
11276 && inst.relocs[0].exp.X_add_symbol != NULL
11277 && S_IS_DEFINED (inst.relocs[0].exp.X_add_symbol)
11278 && ! THUMB_IS_FUNC (inst.relocs[0].exp.X_add_symbol))
11279 inst.relocs[0].exp.X_add_symbol
11280 = find_real_start (inst.relocs[0].exp.X_add_symbol);
11281 #endif
11282 }
11283
11284 static void
11285 do_t_bx (void)
11286 {
11287 set_it_insn_type_last ();
11288 inst.instruction |= inst.operands[0].reg << 3;
11289 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11290 should cause the alignment to be checked once it is known. This is
11291 because BX PC only works if the instruction is word aligned. */
11292 }
11293
11294 static void
11295 do_t_bxj (void)
11296 {
11297 int Rm;
11298
11299 set_it_insn_type_last ();
11300 Rm = inst.operands[0].reg;
11301 reject_bad_reg (Rm);
11302 inst.instruction |= Rm << 16;
11303 }
11304
11305 static void
11306 do_t_clz (void)
11307 {
11308 unsigned Rd;
11309 unsigned Rm;
11310
11311 Rd = inst.operands[0].reg;
11312 Rm = inst.operands[1].reg;
11313
11314 reject_bad_reg (Rd);
11315 reject_bad_reg (Rm);
11316
11317 inst.instruction |= Rd << 8;
11318 inst.instruction |= Rm << 16;
11319 inst.instruction |= Rm;
11320 }
11321
11322 static void
11323 do_t_csdb (void)
11324 {
11325 set_it_insn_type (OUTSIDE_IT_INSN);
11326 }
11327
11328 static void
11329 do_t_cps (void)
11330 {
11331 set_it_insn_type (OUTSIDE_IT_INSN);
11332 inst.instruction |= inst.operands[0].imm;
11333 }
11334
11335 static void
11336 do_t_cpsi (void)
11337 {
11338 set_it_insn_type (OUTSIDE_IT_INSN);
11339 if (unified_syntax
11340 && (inst.operands[1].present || inst.size_req == 4)
11341 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
11342 {
11343 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11344 inst.instruction = 0xf3af8000;
11345 inst.instruction |= imod << 9;
11346 inst.instruction |= inst.operands[0].imm << 5;
11347 if (inst.operands[1].present)
11348 inst.instruction |= 0x100 | inst.operands[1].imm;
11349 }
11350 else
11351 {
11352 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11353 && (inst.operands[0].imm & 4),
11354 _("selected processor does not support 'A' form "
11355 "of this instruction"));
11356 constraint (inst.operands[1].present || inst.size_req == 4,
11357 _("Thumb does not support the 2-argument "
11358 "form of this instruction"));
11359 inst.instruction |= inst.operands[0].imm;
11360 }
11361 }
11362
11363 /* THUMB CPY instruction (argument parse). */
11364
11365 static void
11366 do_t_cpy (void)
11367 {
11368 if (inst.size_req == 4)
11369 {
11370 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11371 inst.instruction |= inst.operands[0].reg << 8;
11372 inst.instruction |= inst.operands[1].reg;
11373 }
11374 else
11375 {
11376 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11377 inst.instruction |= (inst.operands[0].reg & 0x7);
11378 inst.instruction |= inst.operands[1].reg << 3;
11379 }
11380 }
11381
11382 static void
11383 do_t_cbz (void)
11384 {
11385 set_it_insn_type (OUTSIDE_IT_INSN);
11386 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11387 inst.instruction |= inst.operands[0].reg;
11388 inst.relocs[0].pc_rel = 1;
11389 inst.relocs[0].type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11390 }
11391
11392 static void
11393 do_t_dbg (void)
11394 {
11395 inst.instruction |= inst.operands[0].imm;
11396 }
11397
11398 static void
11399 do_t_div (void)
11400 {
11401 unsigned Rd, Rn, Rm;
11402
11403 Rd = inst.operands[0].reg;
11404 Rn = (inst.operands[1].present
11405 ? inst.operands[1].reg : Rd);
11406 Rm = inst.operands[2].reg;
11407
11408 reject_bad_reg (Rd);
11409 reject_bad_reg (Rn);
11410 reject_bad_reg (Rm);
11411
11412 inst.instruction |= Rd << 8;
11413 inst.instruction |= Rn << 16;
11414 inst.instruction |= Rm;
11415 }
11416
11417 static void
11418 do_t_hint (void)
11419 {
11420 if (unified_syntax && inst.size_req == 4)
11421 inst.instruction = THUMB_OP32 (inst.instruction);
11422 else
11423 inst.instruction = THUMB_OP16 (inst.instruction);
11424 }
11425
11426 static void
11427 do_t_it (void)
11428 {
11429 unsigned int cond = inst.operands[0].imm;
11430
11431 set_it_insn_type (IT_INSN);
11432 now_it.mask = (inst.instruction & 0xf) | 0x10;
11433 now_it.cc = cond;
11434 now_it.warn_deprecated = FALSE;
11435
11436 /* If the condition is a negative condition, invert the mask. */
11437 if ((cond & 0x1) == 0x0)
11438 {
11439 unsigned int mask = inst.instruction & 0x000f;
11440
11441 if ((mask & 0x7) == 0)
11442 {
11443 /* No conversion needed. */
11444 now_it.block_length = 1;
11445 }
11446 else if ((mask & 0x3) == 0)
11447 {
11448 mask ^= 0x8;
11449 now_it.block_length = 2;
11450 }
11451 else if ((mask & 0x1) == 0)
11452 {
11453 mask ^= 0xC;
11454 now_it.block_length = 3;
11455 }
11456 else
11457 {
11458 mask ^= 0xE;
11459 now_it.block_length = 4;
11460 }
11461
11462 inst.instruction &= 0xfff0;
11463 inst.instruction |= mask;
11464 }
11465
11466 inst.instruction |= cond << 4;
11467 }
11468
11469 /* Helper function used for both push/pop and ldm/stm. */
11470 static void
11471 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11472 {
11473 bfd_boolean load;
11474
11475 load = (inst.instruction & (1 << 20)) != 0;
11476
11477 if (mask & (1 << 13))
11478 inst.error = _("SP not allowed in register list");
11479
11480 if ((mask & (1 << base)) != 0
11481 && writeback)
11482 inst.error = _("having the base register in the register list when "
11483 "using write back is UNPREDICTABLE");
11484
11485 if (load)
11486 {
11487 if (mask & (1 << 15))
11488 {
11489 if (mask & (1 << 14))
11490 inst.error = _("LR and PC should not both be in register list");
11491 else
11492 set_it_insn_type_last ();
11493 }
11494 }
11495 else
11496 {
11497 if (mask & (1 << 15))
11498 inst.error = _("PC not allowed in register list");
11499 }
11500
11501 if ((mask & (mask - 1)) == 0)
11502 {
11503 /* Single register transfers implemented as str/ldr. */
11504 if (writeback)
11505 {
11506 if (inst.instruction & (1 << 23))
11507 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11508 else
11509 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11510 }
11511 else
11512 {
11513 if (inst.instruction & (1 << 23))
11514 inst.instruction = 0x00800000; /* ia -> [base] */
11515 else
11516 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11517 }
11518
11519 inst.instruction |= 0xf8400000;
11520 if (load)
11521 inst.instruction |= 0x00100000;
11522
11523 mask = ffs (mask) - 1;
11524 mask <<= 12;
11525 }
11526 else if (writeback)
11527 inst.instruction |= WRITE_BACK;
11528
11529 inst.instruction |= mask;
11530 inst.instruction |= base << 16;
11531 }
11532
11533 static void
11534 do_t_ldmstm (void)
11535 {
11536 /* This really doesn't seem worth it. */
11537 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
11538 _("expression too complex"));
11539 constraint (inst.operands[1].writeback,
11540 _("Thumb load/store multiple does not support {reglist}^"));
11541
11542 if (unified_syntax)
11543 {
11544 bfd_boolean narrow;
11545 unsigned mask;
11546
11547 narrow = FALSE;
11548 /* See if we can use a 16-bit instruction. */
11549 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11550 && inst.size_req != 4
11551 && !(inst.operands[1].imm & ~0xff))
11552 {
11553 mask = 1 << inst.operands[0].reg;
11554
11555 if (inst.operands[0].reg <= 7)
11556 {
11557 if (inst.instruction == T_MNEM_stmia
11558 ? inst.operands[0].writeback
11559 : (inst.operands[0].writeback
11560 == !(inst.operands[1].imm & mask)))
11561 {
11562 if (inst.instruction == T_MNEM_stmia
11563 && (inst.operands[1].imm & mask)
11564 && (inst.operands[1].imm & (mask - 1)))
11565 as_warn (_("value stored for r%d is UNKNOWN"),
11566 inst.operands[0].reg);
11567
11568 inst.instruction = THUMB_OP16 (inst.instruction);
11569 inst.instruction |= inst.operands[0].reg << 8;
11570 inst.instruction |= inst.operands[1].imm;
11571 narrow = TRUE;
11572 }
11573 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11574 {
11575 /* This means 1 register in reg list one of 3 situations:
11576 1. Instruction is stmia, but without writeback.
11577 2. lmdia without writeback, but with Rn not in
11578 reglist.
11579 3. ldmia with writeback, but with Rn in reglist.
11580 Case 3 is UNPREDICTABLE behaviour, so we handle
11581 case 1 and 2 which can be converted into a 16-bit
11582 str or ldr. The SP cases are handled below. */
11583 unsigned long opcode;
11584 /* First, record an error for Case 3. */
11585 if (inst.operands[1].imm & mask
11586 && inst.operands[0].writeback)
11587 inst.error =
11588 _("having the base register in the register list when "
11589 "using write back is UNPREDICTABLE");
11590
11591 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
11592 : T_MNEM_ldr);
11593 inst.instruction = THUMB_OP16 (opcode);
11594 inst.instruction |= inst.operands[0].reg << 3;
11595 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11596 narrow = TRUE;
11597 }
11598 }
11599 else if (inst.operands[0] .reg == REG_SP)
11600 {
11601 if (inst.operands[0].writeback)
11602 {
11603 inst.instruction =
11604 THUMB_OP16 (inst.instruction == T_MNEM_stmia
11605 ? T_MNEM_push : T_MNEM_pop);
11606 inst.instruction |= inst.operands[1].imm;
11607 narrow = TRUE;
11608 }
11609 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11610 {
11611 inst.instruction =
11612 THUMB_OP16 (inst.instruction == T_MNEM_stmia
11613 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
11614 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
11615 narrow = TRUE;
11616 }
11617 }
11618 }
11619
11620 if (!narrow)
11621 {
11622 if (inst.instruction < 0xffff)
11623 inst.instruction = THUMB_OP32 (inst.instruction);
11624
11625 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11626 inst.operands[0].writeback);
11627 }
11628 }
11629 else
11630 {
11631 constraint (inst.operands[0].reg > 7
11632 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
11633 constraint (inst.instruction != T_MNEM_ldmia
11634 && inst.instruction != T_MNEM_stmia,
11635 _("Thumb-2 instruction only valid in unified syntax"));
11636 if (inst.instruction == T_MNEM_stmia)
11637 {
11638 if (!inst.operands[0].writeback)
11639 as_warn (_("this instruction will write back the base register"));
11640 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11641 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
11642 as_warn (_("value stored for r%d is UNKNOWN"),
11643 inst.operands[0].reg);
11644 }
11645 else
11646 {
11647 if (!inst.operands[0].writeback
11648 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11649 as_warn (_("this instruction will write back the base register"));
11650 else if (inst.operands[0].writeback
11651 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11652 as_warn (_("this instruction will not write back the base register"));
11653 }
11654
11655 inst.instruction = THUMB_OP16 (inst.instruction);
11656 inst.instruction |= inst.operands[0].reg << 8;
11657 inst.instruction |= inst.operands[1].imm;
11658 }
11659 }
11660
11661 static void
11662 do_t_ldrex (void)
11663 {
11664 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11665 || inst.operands[1].postind || inst.operands[1].writeback
11666 || inst.operands[1].immisreg || inst.operands[1].shifted
11667 || inst.operands[1].negative,
11668 BAD_ADDR_MODE);
11669
11670 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11671
11672 inst.instruction |= inst.operands[0].reg << 12;
11673 inst.instruction |= inst.operands[1].reg << 16;
11674 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
11675 }
11676
11677 static void
11678 do_t_ldrexd (void)
11679 {
11680 if (!inst.operands[1].present)
11681 {
11682 constraint (inst.operands[0].reg == REG_LR,
11683 _("r14 not allowed as first register "
11684 "when second register is omitted"));
11685 inst.operands[1].reg = inst.operands[0].reg + 1;
11686 }
11687 constraint (inst.operands[0].reg == inst.operands[1].reg,
11688 BAD_OVERLAP);
11689
11690 inst.instruction |= inst.operands[0].reg << 12;
11691 inst.instruction |= inst.operands[1].reg << 8;
11692 inst.instruction |= inst.operands[2].reg << 16;
11693 }
11694
11695 static void
11696 do_t_ldst (void)
11697 {
11698 unsigned long opcode;
11699 int Rn;
11700
11701 if (inst.operands[0].isreg
11702 && !inst.operands[0].preind
11703 && inst.operands[0].reg == REG_PC)
11704 set_it_insn_type_last ();
11705
11706 opcode = inst.instruction;
11707 if (unified_syntax)
11708 {
11709 if (!inst.operands[1].isreg)
11710 {
11711 if (opcode <= 0xffff)
11712 inst.instruction = THUMB_OP32 (opcode);
11713 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
11714 return;
11715 }
11716 if (inst.operands[1].isreg
11717 && !inst.operands[1].writeback
11718 && !inst.operands[1].shifted && !inst.operands[1].postind
11719 && !inst.operands[1].negative && inst.operands[0].reg <= 7
11720 && opcode <= 0xffff
11721 && inst.size_req != 4)
11722 {
11723 /* Insn may have a 16-bit form. */
11724 Rn = inst.operands[1].reg;
11725 if (inst.operands[1].immisreg)
11726 {
11727 inst.instruction = THUMB_OP16 (opcode);
11728 /* [Rn, Rik] */
11729 if (Rn <= 7 && inst.operands[1].imm <= 7)
11730 goto op16;
11731 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11732 reject_bad_reg (inst.operands[1].imm);
11733 }
11734 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11735 && opcode != T_MNEM_ldrsb)
11736 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11737 || (Rn == REG_SP && opcode == T_MNEM_str))
11738 {
11739 /* [Rn, #const] */
11740 if (Rn > 7)
11741 {
11742 if (Rn == REG_PC)
11743 {
11744 if (inst.relocs[0].pc_rel)
11745 opcode = T_MNEM_ldr_pc2;
11746 else
11747 opcode = T_MNEM_ldr_pc;
11748 }
11749 else
11750 {
11751 if (opcode == T_MNEM_ldr)
11752 opcode = T_MNEM_ldr_sp;
11753 else
11754 opcode = T_MNEM_str_sp;
11755 }
11756 inst.instruction = inst.operands[0].reg << 8;
11757 }
11758 else
11759 {
11760 inst.instruction = inst.operands[0].reg;
11761 inst.instruction |= inst.operands[1].reg << 3;
11762 }
11763 inst.instruction |= THUMB_OP16 (opcode);
11764 if (inst.size_req == 2)
11765 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
11766 else
11767 inst.relax = opcode;
11768 return;
11769 }
11770 }
11771 /* Definitely a 32-bit variant. */
11772
11773 /* Warning for Erratum 752419. */
11774 if (opcode == T_MNEM_ldr
11775 && inst.operands[0].reg == REG_SP
11776 && inst.operands[1].writeback == 1
11777 && !inst.operands[1].immisreg)
11778 {
11779 if (no_cpu_selected ()
11780 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
11781 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11782 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
11783 as_warn (_("This instruction may be unpredictable "
11784 "if executed on M-profile cores "
11785 "with interrupts enabled."));
11786 }
11787
11788 /* Do some validations regarding addressing modes. */
11789 if (inst.operands[1].immisreg)
11790 reject_bad_reg (inst.operands[1].imm);
11791
11792 constraint (inst.operands[1].writeback == 1
11793 && inst.operands[0].reg == inst.operands[1].reg,
11794 BAD_OVERLAP);
11795
11796 inst.instruction = THUMB_OP32 (opcode);
11797 inst.instruction |= inst.operands[0].reg << 12;
11798 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
11799 check_ldr_r15_aligned ();
11800 return;
11801 }
11802
11803 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11804
11805 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
11806 {
11807 /* Only [Rn,Rm] is acceptable. */
11808 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11809 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11810 || inst.operands[1].postind || inst.operands[1].shifted
11811 || inst.operands[1].negative,
11812 _("Thumb does not support this addressing mode"));
11813 inst.instruction = THUMB_OP16 (inst.instruction);
11814 goto op16;
11815 }
11816
11817 inst.instruction = THUMB_OP16 (inst.instruction);
11818 if (!inst.operands[1].isreg)
11819 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
11820 return;
11821
11822 constraint (!inst.operands[1].preind
11823 || inst.operands[1].shifted
11824 || inst.operands[1].writeback,
11825 _("Thumb does not support this addressing mode"));
11826 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
11827 {
11828 constraint (inst.instruction & 0x0600,
11829 _("byte or halfword not valid for base register"));
11830 constraint (inst.operands[1].reg == REG_PC
11831 && !(inst.instruction & THUMB_LOAD_BIT),
11832 _("r15 based store not allowed"));
11833 constraint (inst.operands[1].immisreg,
11834 _("invalid base register for register offset"));
11835
11836 if (inst.operands[1].reg == REG_PC)
11837 inst.instruction = T_OPCODE_LDR_PC;
11838 else if (inst.instruction & THUMB_LOAD_BIT)
11839 inst.instruction = T_OPCODE_LDR_SP;
11840 else
11841 inst.instruction = T_OPCODE_STR_SP;
11842
11843 inst.instruction |= inst.operands[0].reg << 8;
11844 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
11845 return;
11846 }
11847
11848 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11849 if (!inst.operands[1].immisreg)
11850 {
11851 /* Immediate offset. */
11852 inst.instruction |= inst.operands[0].reg;
11853 inst.instruction |= inst.operands[1].reg << 3;
11854 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_OFFSET;
11855 return;
11856 }
11857
11858 /* Register offset. */
11859 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11860 constraint (inst.operands[1].negative,
11861 _("Thumb does not support this addressing mode"));
11862
11863 op16:
11864 switch (inst.instruction)
11865 {
11866 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11867 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11868 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11869 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11870 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11871 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11872 case 0x5600 /* ldrsb */:
11873 case 0x5e00 /* ldrsh */: break;
11874 default: abort ();
11875 }
11876
11877 inst.instruction |= inst.operands[0].reg;
11878 inst.instruction |= inst.operands[1].reg << 3;
11879 inst.instruction |= inst.operands[1].imm << 6;
11880 }
11881
11882 static void
11883 do_t_ldstd (void)
11884 {
11885 if (!inst.operands[1].present)
11886 {
11887 inst.operands[1].reg = inst.operands[0].reg + 1;
11888 constraint (inst.operands[0].reg == REG_LR,
11889 _("r14 not allowed here"));
11890 constraint (inst.operands[0].reg == REG_R12,
11891 _("r12 not allowed here"));
11892 }
11893
11894 if (inst.operands[2].writeback
11895 && (inst.operands[0].reg == inst.operands[2].reg
11896 || inst.operands[1].reg == inst.operands[2].reg))
11897 as_warn (_("base register written back, and overlaps "
11898 "one of transfer registers"));
11899
11900 inst.instruction |= inst.operands[0].reg << 12;
11901 inst.instruction |= inst.operands[1].reg << 8;
11902 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
11903 }
11904
11905 static void
11906 do_t_ldstt (void)
11907 {
11908 inst.instruction |= inst.operands[0].reg << 12;
11909 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11910 }
11911
11912 static void
11913 do_t_mla (void)
11914 {
11915 unsigned Rd, Rn, Rm, Ra;
11916
11917 Rd = inst.operands[0].reg;
11918 Rn = inst.operands[1].reg;
11919 Rm = inst.operands[2].reg;
11920 Ra = inst.operands[3].reg;
11921
11922 reject_bad_reg (Rd);
11923 reject_bad_reg (Rn);
11924 reject_bad_reg (Rm);
11925 reject_bad_reg (Ra);
11926
11927 inst.instruction |= Rd << 8;
11928 inst.instruction |= Rn << 16;
11929 inst.instruction |= Rm;
11930 inst.instruction |= Ra << 12;
11931 }
11932
11933 static void
11934 do_t_mlal (void)
11935 {
11936 unsigned RdLo, RdHi, Rn, Rm;
11937
11938 RdLo = inst.operands[0].reg;
11939 RdHi = inst.operands[1].reg;
11940 Rn = inst.operands[2].reg;
11941 Rm = inst.operands[3].reg;
11942
11943 reject_bad_reg (RdLo);
11944 reject_bad_reg (RdHi);
11945 reject_bad_reg (Rn);
11946 reject_bad_reg (Rm);
11947
11948 inst.instruction |= RdLo << 12;
11949 inst.instruction |= RdHi << 8;
11950 inst.instruction |= Rn << 16;
11951 inst.instruction |= Rm;
11952 }
11953
11954 static void
11955 do_t_mov_cmp (void)
11956 {
11957 unsigned Rn, Rm;
11958
11959 Rn = inst.operands[0].reg;
11960 Rm = inst.operands[1].reg;
11961
11962 if (Rn == REG_PC)
11963 set_it_insn_type_last ();
11964
11965 if (unified_syntax)
11966 {
11967 int r0off = (inst.instruction == T_MNEM_mov
11968 || inst.instruction == T_MNEM_movs) ? 8 : 16;
11969 unsigned long opcode;
11970 bfd_boolean narrow;
11971 bfd_boolean low_regs;
11972
11973 low_regs = (Rn <= 7 && Rm <= 7);
11974 opcode = inst.instruction;
11975 if (in_it_block ())
11976 narrow = opcode != T_MNEM_movs;
11977 else
11978 narrow = opcode != T_MNEM_movs || low_regs;
11979 if (inst.size_req == 4
11980 || inst.operands[1].shifted)
11981 narrow = FALSE;
11982
11983 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11984 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11985 && !inst.operands[1].shifted
11986 && Rn == REG_PC
11987 && Rm == REG_LR)
11988 {
11989 inst.instruction = T2_SUBS_PC_LR;
11990 return;
11991 }
11992
11993 if (opcode == T_MNEM_cmp)
11994 {
11995 constraint (Rn == REG_PC, BAD_PC);
11996 if (narrow)
11997 {
11998 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11999 but valid. */
12000 warn_deprecated_sp (Rm);
12001 /* R15 was documented as a valid choice for Rm in ARMv6,
12002 but as UNPREDICTABLE in ARMv7. ARM's proprietary
12003 tools reject R15, so we do too. */
12004 constraint (Rm == REG_PC, BAD_PC);
12005 }
12006 else
12007 reject_bad_reg (Rm);
12008 }
12009 else if (opcode == T_MNEM_mov
12010 || opcode == T_MNEM_movs)
12011 {
12012 if (inst.operands[1].isreg)
12013 {
12014 if (opcode == T_MNEM_movs)
12015 {
12016 reject_bad_reg (Rn);
12017 reject_bad_reg (Rm);
12018 }
12019 else if (narrow)
12020 {
12021 /* This is mov.n. */
12022 if ((Rn == REG_SP || Rn == REG_PC)
12023 && (Rm == REG_SP || Rm == REG_PC))
12024 {
12025 as_tsktsk (_("Use of r%u as a source register is "
12026 "deprecated when r%u is the destination "
12027 "register."), Rm, Rn);
12028 }
12029 }
12030 else
12031 {
12032 /* This is mov.w. */
12033 constraint (Rn == REG_PC, BAD_PC);
12034 constraint (Rm == REG_PC, BAD_PC);
12035 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12036 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
12037 }
12038 }
12039 else
12040 reject_bad_reg (Rn);
12041 }
12042
12043 if (!inst.operands[1].isreg)
12044 {
12045 /* Immediate operand. */
12046 if (!in_it_block () && opcode == T_MNEM_mov)
12047 narrow = 0;
12048 if (low_regs && narrow)
12049 {
12050 inst.instruction = THUMB_OP16 (opcode);
12051 inst.instruction |= Rn << 8;
12052 if (inst.relocs[0].type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12053 || inst.relocs[0].type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
12054 {
12055 if (inst.size_req == 2)
12056 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
12057 else
12058 inst.relax = opcode;
12059 }
12060 }
12061 else
12062 {
12063 constraint ((inst.relocs[0].type
12064 >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC)
12065 && (inst.relocs[0].type
12066 <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC) ,
12067 THUMB1_RELOC_ONLY);
12068
12069 inst.instruction = THUMB_OP32 (inst.instruction);
12070 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12071 inst.instruction |= Rn << r0off;
12072 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12073 }
12074 }
12075 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12076 && (inst.instruction == T_MNEM_mov
12077 || inst.instruction == T_MNEM_movs))
12078 {
12079 /* Register shifts are encoded as separate shift instructions. */
12080 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12081
12082 if (in_it_block ())
12083 narrow = !flags;
12084 else
12085 narrow = flags;
12086
12087 if (inst.size_req == 4)
12088 narrow = FALSE;
12089
12090 if (!low_regs || inst.operands[1].imm > 7)
12091 narrow = FALSE;
12092
12093 if (Rn != Rm)
12094 narrow = FALSE;
12095
12096 switch (inst.operands[1].shift_kind)
12097 {
12098 case SHIFT_LSL:
12099 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12100 break;
12101 case SHIFT_ASR:
12102 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12103 break;
12104 case SHIFT_LSR:
12105 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12106 break;
12107 case SHIFT_ROR:
12108 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12109 break;
12110 default:
12111 abort ();
12112 }
12113
12114 inst.instruction = opcode;
12115 if (narrow)
12116 {
12117 inst.instruction |= Rn;
12118 inst.instruction |= inst.operands[1].imm << 3;
12119 }
12120 else
12121 {
12122 if (flags)
12123 inst.instruction |= CONDS_BIT;
12124
12125 inst.instruction |= Rn << 8;
12126 inst.instruction |= Rm << 16;
12127 inst.instruction |= inst.operands[1].imm;
12128 }
12129 }
12130 else if (!narrow)
12131 {
12132 /* Some mov with immediate shift have narrow variants.
12133 Register shifts are handled above. */
12134 if (low_regs && inst.operands[1].shifted
12135 && (inst.instruction == T_MNEM_mov
12136 || inst.instruction == T_MNEM_movs))
12137 {
12138 if (in_it_block ())
12139 narrow = (inst.instruction == T_MNEM_mov);
12140 else
12141 narrow = (inst.instruction == T_MNEM_movs);
12142 }
12143
12144 if (narrow)
12145 {
12146 switch (inst.operands[1].shift_kind)
12147 {
12148 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12149 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12150 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12151 default: narrow = FALSE; break;
12152 }
12153 }
12154
12155 if (narrow)
12156 {
12157 inst.instruction |= Rn;
12158 inst.instruction |= Rm << 3;
12159 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
12160 }
12161 else
12162 {
12163 inst.instruction = THUMB_OP32 (inst.instruction);
12164 inst.instruction |= Rn << r0off;
12165 encode_thumb32_shifted_operand (1);
12166 }
12167 }
12168 else
12169 switch (inst.instruction)
12170 {
12171 case T_MNEM_mov:
12172 /* In v4t or v5t a move of two lowregs produces unpredictable
12173 results. Don't allow this. */
12174 if (low_regs)
12175 {
12176 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12177 "MOV Rd, Rs with two low registers is not "
12178 "permitted on this architecture");
12179 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
12180 arm_ext_v6);
12181 }
12182
12183 inst.instruction = T_OPCODE_MOV_HR;
12184 inst.instruction |= (Rn & 0x8) << 4;
12185 inst.instruction |= (Rn & 0x7);
12186 inst.instruction |= Rm << 3;
12187 break;
12188
12189 case T_MNEM_movs:
12190 /* We know we have low registers at this point.
12191 Generate LSLS Rd, Rs, #0. */
12192 inst.instruction = T_OPCODE_LSL_I;
12193 inst.instruction |= Rn;
12194 inst.instruction |= Rm << 3;
12195 break;
12196
12197 case T_MNEM_cmp:
12198 if (low_regs)
12199 {
12200 inst.instruction = T_OPCODE_CMP_LR;
12201 inst.instruction |= Rn;
12202 inst.instruction |= Rm << 3;
12203 }
12204 else
12205 {
12206 inst.instruction = T_OPCODE_CMP_HR;
12207 inst.instruction |= (Rn & 0x8) << 4;
12208 inst.instruction |= (Rn & 0x7);
12209 inst.instruction |= Rm << 3;
12210 }
12211 break;
12212 }
12213 return;
12214 }
12215
12216 inst.instruction = THUMB_OP16 (inst.instruction);
12217
12218 /* PR 10443: Do not silently ignore shifted operands. */
12219 constraint (inst.operands[1].shifted,
12220 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12221
12222 if (inst.operands[1].isreg)
12223 {
12224 if (Rn < 8 && Rm < 8)
12225 {
12226 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12227 since a MOV instruction produces unpredictable results. */
12228 if (inst.instruction == T_OPCODE_MOV_I8)
12229 inst.instruction = T_OPCODE_ADD_I3;
12230 else
12231 inst.instruction = T_OPCODE_CMP_LR;
12232
12233 inst.instruction |= Rn;
12234 inst.instruction |= Rm << 3;
12235 }
12236 else
12237 {
12238 if (inst.instruction == T_OPCODE_MOV_I8)
12239 inst.instruction = T_OPCODE_MOV_HR;
12240 else
12241 inst.instruction = T_OPCODE_CMP_HR;
12242 do_t_cpy ();
12243 }
12244 }
12245 else
12246 {
12247 constraint (Rn > 7,
12248 _("only lo regs allowed with immediate"));
12249 inst.instruction |= Rn << 8;
12250 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_IMM;
12251 }
12252 }
12253
12254 static void
12255 do_t_mov16 (void)
12256 {
12257 unsigned Rd;
12258 bfd_vma imm;
12259 bfd_boolean top;
12260
12261 top = (inst.instruction & 0x00800000) != 0;
12262 if (inst.relocs[0].type == BFD_RELOC_ARM_MOVW)
12263 {
12264 constraint (top, _(":lower16: not allowed in this instruction"));
12265 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVW;
12266 }
12267 else if (inst.relocs[0].type == BFD_RELOC_ARM_MOVT)
12268 {
12269 constraint (!top, _(":upper16: not allowed in this instruction"));
12270 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_MOVT;
12271 }
12272
12273 Rd = inst.operands[0].reg;
12274 reject_bad_reg (Rd);
12275
12276 inst.instruction |= Rd << 8;
12277 if (inst.relocs[0].type == BFD_RELOC_UNUSED)
12278 {
12279 imm = inst.relocs[0].exp.X_add_number;
12280 inst.instruction |= (imm & 0xf000) << 4;
12281 inst.instruction |= (imm & 0x0800) << 15;
12282 inst.instruction |= (imm & 0x0700) << 4;
12283 inst.instruction |= (imm & 0x00ff);
12284 }
12285 }
12286
12287 static void
12288 do_t_mvn_tst (void)
12289 {
12290 unsigned Rn, Rm;
12291
12292 Rn = inst.operands[0].reg;
12293 Rm = inst.operands[1].reg;
12294
12295 if (inst.instruction == T_MNEM_cmp
12296 || inst.instruction == T_MNEM_cmn)
12297 constraint (Rn == REG_PC, BAD_PC);
12298 else
12299 reject_bad_reg (Rn);
12300 reject_bad_reg (Rm);
12301
12302 if (unified_syntax)
12303 {
12304 int r0off = (inst.instruction == T_MNEM_mvn
12305 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
12306 bfd_boolean narrow;
12307
12308 if (inst.size_req == 4
12309 || inst.instruction > 0xffff
12310 || inst.operands[1].shifted
12311 || Rn > 7 || Rm > 7)
12312 narrow = FALSE;
12313 else if (inst.instruction == T_MNEM_cmn
12314 || inst.instruction == T_MNEM_tst)
12315 narrow = TRUE;
12316 else if (THUMB_SETS_FLAGS (inst.instruction))
12317 narrow = !in_it_block ();
12318 else
12319 narrow = in_it_block ();
12320
12321 if (!inst.operands[1].isreg)
12322 {
12323 /* For an immediate, we always generate a 32-bit opcode;
12324 section relaxation will shrink it later if possible. */
12325 if (inst.instruction < 0xffff)
12326 inst.instruction = THUMB_OP32 (inst.instruction);
12327 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12328 inst.instruction |= Rn << r0off;
12329 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12330 }
12331 else
12332 {
12333 /* See if we can do this with a 16-bit instruction. */
12334 if (narrow)
12335 {
12336 inst.instruction = THUMB_OP16 (inst.instruction);
12337 inst.instruction |= Rn;
12338 inst.instruction |= Rm << 3;
12339 }
12340 else
12341 {
12342 constraint (inst.operands[1].shifted
12343 && inst.operands[1].immisreg,
12344 _("shift must be constant"));
12345 if (inst.instruction < 0xffff)
12346 inst.instruction = THUMB_OP32 (inst.instruction);
12347 inst.instruction |= Rn << r0off;
12348 encode_thumb32_shifted_operand (1);
12349 }
12350 }
12351 }
12352 else
12353 {
12354 constraint (inst.instruction > 0xffff
12355 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12356 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12357 _("unshifted register required"));
12358 constraint (Rn > 7 || Rm > 7,
12359 BAD_HIREG);
12360
12361 inst.instruction = THUMB_OP16 (inst.instruction);
12362 inst.instruction |= Rn;
12363 inst.instruction |= Rm << 3;
12364 }
12365 }
12366
12367 static void
12368 do_t_mrs (void)
12369 {
12370 unsigned Rd;
12371
12372 if (do_vfp_nsyn_mrs () == SUCCESS)
12373 return;
12374
12375 Rd = inst.operands[0].reg;
12376 reject_bad_reg (Rd);
12377 inst.instruction |= Rd << 8;
12378
12379 if (inst.operands[1].isreg)
12380 {
12381 unsigned br = inst.operands[1].reg;
12382 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12383 as_bad (_("bad register for mrs"));
12384
12385 inst.instruction |= br & (0xf << 16);
12386 inst.instruction |= (br & 0x300) >> 4;
12387 inst.instruction |= (br & SPSR_BIT) >> 2;
12388 }
12389 else
12390 {
12391 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12392
12393 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
12394 {
12395 /* PR gas/12698: The constraint is only applied for m_profile.
12396 If the user has specified -march=all, we want to ignore it as
12397 we are building for any CPU type, including non-m variants. */
12398 bfd_boolean m_profile =
12399 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
12400 constraint ((flags != 0) && m_profile, _("selected processor does "
12401 "not support requested special purpose register"));
12402 }
12403 else
12404 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12405 devices). */
12406 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12407 _("'APSR', 'CPSR' or 'SPSR' expected"));
12408
12409 inst.instruction |= (flags & SPSR_BIT) >> 2;
12410 inst.instruction |= inst.operands[1].imm & 0xff;
12411 inst.instruction |= 0xf0000;
12412 }
12413 }
12414
12415 static void
12416 do_t_msr (void)
12417 {
12418 int flags;
12419 unsigned Rn;
12420
12421 if (do_vfp_nsyn_msr () == SUCCESS)
12422 return;
12423
12424 constraint (!inst.operands[1].isreg,
12425 _("Thumb encoding does not support an immediate here"));
12426
12427 if (inst.operands[0].isreg)
12428 flags = (int)(inst.operands[0].reg);
12429 else
12430 flags = inst.operands[0].imm;
12431
12432 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
12433 {
12434 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12435
12436 /* PR gas/12698: The constraint is only applied for m_profile.
12437 If the user has specified -march=all, we want to ignore it as
12438 we are building for any CPU type, including non-m variants. */
12439 bfd_boolean m_profile =
12440 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
12441 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12442 && (bits & ~(PSR_s | PSR_f)) != 0)
12443 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12444 && bits != PSR_f)) && m_profile,
12445 _("selected processor does not support requested special "
12446 "purpose register"));
12447 }
12448 else
12449 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12450 "requested special purpose register"));
12451
12452 Rn = inst.operands[1].reg;
12453 reject_bad_reg (Rn);
12454
12455 inst.instruction |= (flags & SPSR_BIT) >> 2;
12456 inst.instruction |= (flags & 0xf0000) >> 8;
12457 inst.instruction |= (flags & 0x300) >> 4;
12458 inst.instruction |= (flags & 0xff);
12459 inst.instruction |= Rn << 16;
12460 }
12461
12462 static void
12463 do_t_mul (void)
12464 {
12465 bfd_boolean narrow;
12466 unsigned Rd, Rn, Rm;
12467
12468 if (!inst.operands[2].present)
12469 inst.operands[2].reg = inst.operands[0].reg;
12470
12471 Rd = inst.operands[0].reg;
12472 Rn = inst.operands[1].reg;
12473 Rm = inst.operands[2].reg;
12474
12475 if (unified_syntax)
12476 {
12477 if (inst.size_req == 4
12478 || (Rd != Rn
12479 && Rd != Rm)
12480 || Rn > 7
12481 || Rm > 7)
12482 narrow = FALSE;
12483 else if (inst.instruction == T_MNEM_muls)
12484 narrow = !in_it_block ();
12485 else
12486 narrow = in_it_block ();
12487 }
12488 else
12489 {
12490 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
12491 constraint (Rn > 7 || Rm > 7,
12492 BAD_HIREG);
12493 narrow = TRUE;
12494 }
12495
12496 if (narrow)
12497 {
12498 /* 16-bit MULS/Conditional MUL. */
12499 inst.instruction = THUMB_OP16 (inst.instruction);
12500 inst.instruction |= Rd;
12501
12502 if (Rd == Rn)
12503 inst.instruction |= Rm << 3;
12504 else if (Rd == Rm)
12505 inst.instruction |= Rn << 3;
12506 else
12507 constraint (1, _("dest must overlap one source register"));
12508 }
12509 else
12510 {
12511 constraint (inst.instruction != T_MNEM_mul,
12512 _("Thumb-2 MUL must not set flags"));
12513 /* 32-bit MUL. */
12514 inst.instruction = THUMB_OP32 (inst.instruction);
12515 inst.instruction |= Rd << 8;
12516 inst.instruction |= Rn << 16;
12517 inst.instruction |= Rm << 0;
12518
12519 reject_bad_reg (Rd);
12520 reject_bad_reg (Rn);
12521 reject_bad_reg (Rm);
12522 }
12523 }
12524
12525 static void
12526 do_t_mull (void)
12527 {
12528 unsigned RdLo, RdHi, Rn, Rm;
12529
12530 RdLo = inst.operands[0].reg;
12531 RdHi = inst.operands[1].reg;
12532 Rn = inst.operands[2].reg;
12533 Rm = inst.operands[3].reg;
12534
12535 reject_bad_reg (RdLo);
12536 reject_bad_reg (RdHi);
12537 reject_bad_reg (Rn);
12538 reject_bad_reg (Rm);
12539
12540 inst.instruction |= RdLo << 12;
12541 inst.instruction |= RdHi << 8;
12542 inst.instruction |= Rn << 16;
12543 inst.instruction |= Rm;
12544
12545 if (RdLo == RdHi)
12546 as_tsktsk (_("rdhi and rdlo must be different"));
12547 }
12548
12549 static void
12550 do_t_nop (void)
12551 {
12552 set_it_insn_type (NEUTRAL_IT_INSN);
12553
12554 if (unified_syntax)
12555 {
12556 if (inst.size_req == 4 || inst.operands[0].imm > 15)
12557 {
12558 inst.instruction = THUMB_OP32 (inst.instruction);
12559 inst.instruction |= inst.operands[0].imm;
12560 }
12561 else
12562 {
12563 /* PR9722: Check for Thumb2 availability before
12564 generating a thumb2 nop instruction. */
12565 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
12566 {
12567 inst.instruction = THUMB_OP16 (inst.instruction);
12568 inst.instruction |= inst.operands[0].imm << 4;
12569 }
12570 else
12571 inst.instruction = 0x46c0;
12572 }
12573 }
12574 else
12575 {
12576 constraint (inst.operands[0].present,
12577 _("Thumb does not support NOP with hints"));
12578 inst.instruction = 0x46c0;
12579 }
12580 }
12581
12582 static void
12583 do_t_neg (void)
12584 {
12585 if (unified_syntax)
12586 {
12587 bfd_boolean narrow;
12588
12589 if (THUMB_SETS_FLAGS (inst.instruction))
12590 narrow = !in_it_block ();
12591 else
12592 narrow = in_it_block ();
12593 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12594 narrow = FALSE;
12595 if (inst.size_req == 4)
12596 narrow = FALSE;
12597
12598 if (!narrow)
12599 {
12600 inst.instruction = THUMB_OP32 (inst.instruction);
12601 inst.instruction |= inst.operands[0].reg << 8;
12602 inst.instruction |= inst.operands[1].reg << 16;
12603 }
12604 else
12605 {
12606 inst.instruction = THUMB_OP16 (inst.instruction);
12607 inst.instruction |= inst.operands[0].reg;
12608 inst.instruction |= inst.operands[1].reg << 3;
12609 }
12610 }
12611 else
12612 {
12613 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12614 BAD_HIREG);
12615 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12616
12617 inst.instruction = THUMB_OP16 (inst.instruction);
12618 inst.instruction |= inst.operands[0].reg;
12619 inst.instruction |= inst.operands[1].reg << 3;
12620 }
12621 }
12622
12623 static void
12624 do_t_orn (void)
12625 {
12626 unsigned Rd, Rn;
12627
12628 Rd = inst.operands[0].reg;
12629 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12630
12631 reject_bad_reg (Rd);
12632 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12633 reject_bad_reg (Rn);
12634
12635 inst.instruction |= Rd << 8;
12636 inst.instruction |= Rn << 16;
12637
12638 if (!inst.operands[2].isreg)
12639 {
12640 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12641 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12642 }
12643 else
12644 {
12645 unsigned Rm;
12646
12647 Rm = inst.operands[2].reg;
12648 reject_bad_reg (Rm);
12649
12650 constraint (inst.operands[2].shifted
12651 && inst.operands[2].immisreg,
12652 _("shift must be constant"));
12653 encode_thumb32_shifted_operand (2);
12654 }
12655 }
12656
12657 static void
12658 do_t_pkhbt (void)
12659 {
12660 unsigned Rd, Rn, Rm;
12661
12662 Rd = inst.operands[0].reg;
12663 Rn = inst.operands[1].reg;
12664 Rm = inst.operands[2].reg;
12665
12666 reject_bad_reg (Rd);
12667 reject_bad_reg (Rn);
12668 reject_bad_reg (Rm);
12669
12670 inst.instruction |= Rd << 8;
12671 inst.instruction |= Rn << 16;
12672 inst.instruction |= Rm;
12673 if (inst.operands[3].present)
12674 {
12675 unsigned int val = inst.relocs[0].exp.X_add_number;
12676 constraint (inst.relocs[0].exp.X_op != O_constant,
12677 _("expression too complex"));
12678 inst.instruction |= (val & 0x1c) << 10;
12679 inst.instruction |= (val & 0x03) << 6;
12680 }
12681 }
12682
12683 static void
12684 do_t_pkhtb (void)
12685 {
12686 if (!inst.operands[3].present)
12687 {
12688 unsigned Rtmp;
12689
12690 inst.instruction &= ~0x00000020;
12691
12692 /* PR 10168. Swap the Rm and Rn registers. */
12693 Rtmp = inst.operands[1].reg;
12694 inst.operands[1].reg = inst.operands[2].reg;
12695 inst.operands[2].reg = Rtmp;
12696 }
12697 do_t_pkhbt ();
12698 }
12699
12700 static void
12701 do_t_pld (void)
12702 {
12703 if (inst.operands[0].immisreg)
12704 reject_bad_reg (inst.operands[0].imm);
12705
12706 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12707 }
12708
12709 static void
12710 do_t_push_pop (void)
12711 {
12712 unsigned mask;
12713
12714 constraint (inst.operands[0].writeback,
12715 _("push/pop do not support {reglist}^"));
12716 constraint (inst.relocs[0].type != BFD_RELOC_UNUSED,
12717 _("expression too complex"));
12718
12719 mask = inst.operands[0].imm;
12720 if (inst.size_req != 4 && (mask & ~0xff) == 0)
12721 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
12722 else if (inst.size_req != 4
12723 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
12724 ? REG_LR : REG_PC)))
12725 {
12726 inst.instruction = THUMB_OP16 (inst.instruction);
12727 inst.instruction |= THUMB_PP_PC_LR;
12728 inst.instruction |= mask & 0xff;
12729 }
12730 else if (unified_syntax)
12731 {
12732 inst.instruction = THUMB_OP32 (inst.instruction);
12733 encode_thumb2_ldmstm (13, mask, TRUE);
12734 }
12735 else
12736 {
12737 inst.error = _("invalid register list to push/pop instruction");
12738 return;
12739 }
12740 }
12741
12742 static void
12743 do_t_rbit (void)
12744 {
12745 unsigned Rd, Rm;
12746
12747 Rd = inst.operands[0].reg;
12748 Rm = inst.operands[1].reg;
12749
12750 reject_bad_reg (Rd);
12751 reject_bad_reg (Rm);
12752
12753 inst.instruction |= Rd << 8;
12754 inst.instruction |= Rm << 16;
12755 inst.instruction |= Rm;
12756 }
12757
12758 static void
12759 do_t_rev (void)
12760 {
12761 unsigned Rd, Rm;
12762
12763 Rd = inst.operands[0].reg;
12764 Rm = inst.operands[1].reg;
12765
12766 reject_bad_reg (Rd);
12767 reject_bad_reg (Rm);
12768
12769 if (Rd <= 7 && Rm <= 7
12770 && inst.size_req != 4)
12771 {
12772 inst.instruction = THUMB_OP16 (inst.instruction);
12773 inst.instruction |= Rd;
12774 inst.instruction |= Rm << 3;
12775 }
12776 else if (unified_syntax)
12777 {
12778 inst.instruction = THUMB_OP32 (inst.instruction);
12779 inst.instruction |= Rd << 8;
12780 inst.instruction |= Rm << 16;
12781 inst.instruction |= Rm;
12782 }
12783 else
12784 inst.error = BAD_HIREG;
12785 }
12786
12787 static void
12788 do_t_rrx (void)
12789 {
12790 unsigned Rd, Rm;
12791
12792 Rd = inst.operands[0].reg;
12793 Rm = inst.operands[1].reg;
12794
12795 reject_bad_reg (Rd);
12796 reject_bad_reg (Rm);
12797
12798 inst.instruction |= Rd << 8;
12799 inst.instruction |= Rm;
12800 }
12801
12802 static void
12803 do_t_rsb (void)
12804 {
12805 unsigned Rd, Rs;
12806
12807 Rd = inst.operands[0].reg;
12808 Rs = (inst.operands[1].present
12809 ? inst.operands[1].reg /* Rd, Rs, foo */
12810 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
12811
12812 reject_bad_reg (Rd);
12813 reject_bad_reg (Rs);
12814 if (inst.operands[2].isreg)
12815 reject_bad_reg (inst.operands[2].reg);
12816
12817 inst.instruction |= Rd << 8;
12818 inst.instruction |= Rs << 16;
12819 if (!inst.operands[2].isreg)
12820 {
12821 bfd_boolean narrow;
12822
12823 if ((inst.instruction & 0x00100000) != 0)
12824 narrow = !in_it_block ();
12825 else
12826 narrow = in_it_block ();
12827
12828 if (Rd > 7 || Rs > 7)
12829 narrow = FALSE;
12830
12831 if (inst.size_req == 4 || !unified_syntax)
12832 narrow = FALSE;
12833
12834 if (inst.relocs[0].exp.X_op != O_constant
12835 || inst.relocs[0].exp.X_add_number != 0)
12836 narrow = FALSE;
12837
12838 /* Turn rsb #0 into 16-bit neg. We should probably do this via
12839 relaxation, but it doesn't seem worth the hassle. */
12840 if (narrow)
12841 {
12842 inst.relocs[0].type = BFD_RELOC_UNUSED;
12843 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12844 inst.instruction |= Rs << 3;
12845 inst.instruction |= Rd;
12846 }
12847 else
12848 {
12849 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12850 inst.relocs[0].type = BFD_RELOC_ARM_T32_IMMEDIATE;
12851 }
12852 }
12853 else
12854 encode_thumb32_shifted_operand (2);
12855 }
12856
12857 static void
12858 do_t_setend (void)
12859 {
12860 if (warn_on_deprecated
12861 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12862 as_tsktsk (_("setend use is deprecated for ARMv8"));
12863
12864 set_it_insn_type (OUTSIDE_IT_INSN);
12865 if (inst.operands[0].imm)
12866 inst.instruction |= 0x8;
12867 }
12868
12869 static void
12870 do_t_shift (void)
12871 {
12872 if (!inst.operands[1].present)
12873 inst.operands[1].reg = inst.operands[0].reg;
12874
12875 if (unified_syntax)
12876 {
12877 bfd_boolean narrow;
12878 int shift_kind;
12879
12880 switch (inst.instruction)
12881 {
12882 case T_MNEM_asr:
12883 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12884 case T_MNEM_lsl:
12885 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12886 case T_MNEM_lsr:
12887 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12888 case T_MNEM_ror:
12889 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12890 default: abort ();
12891 }
12892
12893 if (THUMB_SETS_FLAGS (inst.instruction))
12894 narrow = !in_it_block ();
12895 else
12896 narrow = in_it_block ();
12897 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12898 narrow = FALSE;
12899 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12900 narrow = FALSE;
12901 if (inst.operands[2].isreg
12902 && (inst.operands[1].reg != inst.operands[0].reg
12903 || inst.operands[2].reg > 7))
12904 narrow = FALSE;
12905 if (inst.size_req == 4)
12906 narrow = FALSE;
12907
12908 reject_bad_reg (inst.operands[0].reg);
12909 reject_bad_reg (inst.operands[1].reg);
12910
12911 if (!narrow)
12912 {
12913 if (inst.operands[2].isreg)
12914 {
12915 reject_bad_reg (inst.operands[2].reg);
12916 inst.instruction = THUMB_OP32 (inst.instruction);
12917 inst.instruction |= inst.operands[0].reg << 8;
12918 inst.instruction |= inst.operands[1].reg << 16;
12919 inst.instruction |= inst.operands[2].reg;
12920
12921 /* PR 12854: Error on extraneous shifts. */
12922 constraint (inst.operands[2].shifted,
12923 _("extraneous shift as part of operand to shift insn"));
12924 }
12925 else
12926 {
12927 inst.operands[1].shifted = 1;
12928 inst.operands[1].shift_kind = shift_kind;
12929 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12930 ? T_MNEM_movs : T_MNEM_mov);
12931 inst.instruction |= inst.operands[0].reg << 8;
12932 encode_thumb32_shifted_operand (1);
12933 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12934 inst.relocs[0].type = BFD_RELOC_UNUSED;
12935 }
12936 }
12937 else
12938 {
12939 if (inst.operands[2].isreg)
12940 {
12941 switch (shift_kind)
12942 {
12943 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12944 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12945 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12946 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
12947 default: abort ();
12948 }
12949
12950 inst.instruction |= inst.operands[0].reg;
12951 inst.instruction |= inst.operands[2].reg << 3;
12952
12953 /* PR 12854: Error on extraneous shifts. */
12954 constraint (inst.operands[2].shifted,
12955 _("extraneous shift as part of operand to shift insn"));
12956 }
12957 else
12958 {
12959 switch (shift_kind)
12960 {
12961 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12962 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12963 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12964 default: abort ();
12965 }
12966 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
12967 inst.instruction |= inst.operands[0].reg;
12968 inst.instruction |= inst.operands[1].reg << 3;
12969 }
12970 }
12971 }
12972 else
12973 {
12974 constraint (inst.operands[0].reg > 7
12975 || inst.operands[1].reg > 7, BAD_HIREG);
12976 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12977
12978 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12979 {
12980 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12981 constraint (inst.operands[0].reg != inst.operands[1].reg,
12982 _("source1 and dest must be same register"));
12983
12984 switch (inst.instruction)
12985 {
12986 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12987 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12988 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12989 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12990 default: abort ();
12991 }
12992
12993 inst.instruction |= inst.operands[0].reg;
12994 inst.instruction |= inst.operands[2].reg << 3;
12995
12996 /* PR 12854: Error on extraneous shifts. */
12997 constraint (inst.operands[2].shifted,
12998 _("extraneous shift as part of operand to shift insn"));
12999 }
13000 else
13001 {
13002 switch (inst.instruction)
13003 {
13004 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
13005 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
13006 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
13007 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
13008 default: abort ();
13009 }
13010 inst.relocs[0].type = BFD_RELOC_ARM_THUMB_SHIFT;
13011 inst.instruction |= inst.operands[0].reg;
13012 inst.instruction |= inst.operands[1].reg << 3;
13013 }
13014 }
13015 }
13016
13017 static void
13018 do_t_simd (void)
13019 {
13020 unsigned Rd, Rn, Rm;
13021
13022 Rd = inst.operands[0].reg;
13023 Rn = inst.operands[1].reg;
13024 Rm = inst.operands[2].reg;
13025
13026 reject_bad_reg (Rd);
13027 reject_bad_reg (Rn);
13028 reject_bad_reg (Rm);
13029
13030 inst.instruction |= Rd << 8;
13031 inst.instruction |= Rn << 16;
13032 inst.instruction |= Rm;
13033 }
13034
13035 static void
13036 do_t_simd2 (void)
13037 {
13038 unsigned Rd, Rn, Rm;
13039
13040 Rd = inst.operands[0].reg;
13041 Rm = inst.operands[1].reg;
13042 Rn = inst.operands[2].reg;
13043
13044 reject_bad_reg (Rd);
13045 reject_bad_reg (Rn);
13046 reject_bad_reg (Rm);
13047
13048 inst.instruction |= Rd << 8;
13049 inst.instruction |= Rn << 16;
13050 inst.instruction |= Rm;
13051 }
13052
13053 static void
13054 do_t_smc (void)
13055 {
13056 unsigned int value = inst.relocs[0].exp.X_add_number;
13057 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13058 _("SMC is not permitted on this architecture"));
13059 constraint (inst.relocs[0].exp.X_op != O_constant,
13060 _("expression too complex"));
13061 inst.relocs[0].type = BFD_RELOC_UNUSED;
13062 inst.instruction |= (value & 0xf000) >> 12;
13063 inst.instruction |= (value & 0x0ff0);
13064 inst.instruction |= (value & 0x000f) << 16;
13065 /* PR gas/15623: SMC instructions must be last in an IT block. */
13066 set_it_insn_type_last ();
13067 }
13068
13069 static void
13070 do_t_hvc (void)
13071 {
13072 unsigned int value = inst.relocs[0].exp.X_add_number;
13073
13074 inst.relocs[0].type = BFD_RELOC_UNUSED;
13075 inst.instruction |= (value & 0x0fff);
13076 inst.instruction |= (value & 0xf000) << 4;
13077 }
13078
13079 static void
13080 do_t_ssat_usat (int bias)
13081 {
13082 unsigned Rd, Rn;
13083
13084 Rd = inst.operands[0].reg;
13085 Rn = inst.operands[2].reg;
13086
13087 reject_bad_reg (Rd);
13088 reject_bad_reg (Rn);
13089
13090 inst.instruction |= Rd << 8;
13091 inst.instruction |= inst.operands[1].imm - bias;
13092 inst.instruction |= Rn << 16;
13093
13094 if (inst.operands[3].present)
13095 {
13096 offsetT shift_amount = inst.relocs[0].exp.X_add_number;
13097
13098 inst.relocs[0].type = BFD_RELOC_UNUSED;
13099
13100 constraint (inst.relocs[0].exp.X_op != O_constant,
13101 _("expression too complex"));
13102
13103 if (shift_amount != 0)
13104 {
13105 constraint (shift_amount > 31,
13106 _("shift expression is too large"));
13107
13108 if (inst.operands[3].shift_kind == SHIFT_ASR)
13109 inst.instruction |= 0x00200000; /* sh bit. */
13110
13111 inst.instruction |= (shift_amount & 0x1c) << 10;
13112 inst.instruction |= (shift_amount & 0x03) << 6;
13113 }
13114 }
13115 }
13116
13117 static void
13118 do_t_ssat (void)
13119 {
13120 do_t_ssat_usat (1);
13121 }
13122
13123 static void
13124 do_t_ssat16 (void)
13125 {
13126 unsigned Rd, Rn;
13127
13128 Rd = inst.operands[0].reg;
13129 Rn = inst.operands[2].reg;
13130
13131 reject_bad_reg (Rd);
13132 reject_bad_reg (Rn);
13133
13134 inst.instruction |= Rd << 8;
13135 inst.instruction |= inst.operands[1].imm - 1;
13136 inst.instruction |= Rn << 16;
13137 }
13138
13139 static void
13140 do_t_strex (void)
13141 {
13142 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13143 || inst.operands[2].postind || inst.operands[2].writeback
13144 || inst.operands[2].immisreg || inst.operands[2].shifted
13145 || inst.operands[2].negative,
13146 BAD_ADDR_MODE);
13147
13148 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13149
13150 inst.instruction |= inst.operands[0].reg << 8;
13151 inst.instruction |= inst.operands[1].reg << 12;
13152 inst.instruction |= inst.operands[2].reg << 16;
13153 inst.relocs[0].type = BFD_RELOC_ARM_T32_OFFSET_U8;
13154 }
13155
13156 static void
13157 do_t_strexd (void)
13158 {
13159 if (!inst.operands[2].present)
13160 inst.operands[2].reg = inst.operands[1].reg + 1;
13161
13162 constraint (inst.operands[0].reg == inst.operands[1].reg
13163 || inst.operands[0].reg == inst.operands[2].reg
13164 || inst.operands[0].reg == inst.operands[3].reg,
13165 BAD_OVERLAP);
13166
13167 inst.instruction |= inst.operands[0].reg;
13168 inst.instruction |= inst.operands[1].reg << 12;
13169 inst.instruction |= inst.operands[2].reg << 8;
13170 inst.instruction |= inst.operands[3].reg << 16;
13171 }
13172
13173 static void
13174 do_t_sxtah (void)
13175 {
13176 unsigned Rd, Rn, Rm;
13177
13178 Rd = inst.operands[0].reg;
13179 Rn = inst.operands[1].reg;
13180 Rm = inst.operands[2].reg;
13181
13182 reject_bad_reg (Rd);
13183 reject_bad_reg (Rn);
13184 reject_bad_reg (Rm);
13185
13186 inst.instruction |= Rd << 8;
13187 inst.instruction |= Rn << 16;
13188 inst.instruction |= Rm;
13189 inst.instruction |= inst.operands[3].imm << 4;
13190 }
13191
13192 static void
13193 do_t_sxth (void)
13194 {
13195 unsigned Rd, Rm;
13196
13197 Rd = inst.operands[0].reg;
13198 Rm = inst.operands[1].reg;
13199
13200 reject_bad_reg (Rd);
13201 reject_bad_reg (Rm);
13202
13203 if (inst.instruction <= 0xffff
13204 && inst.size_req != 4
13205 && Rd <= 7 && Rm <= 7
13206 && (!inst.operands[2].present || inst.operands[2].imm == 0))
13207 {
13208 inst.instruction = THUMB_OP16 (inst.instruction);
13209 inst.instruction |= Rd;
13210 inst.instruction |= Rm << 3;
13211 }
13212 else if (unified_syntax)
13213 {
13214 if (inst.instruction <= 0xffff)
13215 inst.instruction = THUMB_OP32 (inst.instruction);
13216 inst.instruction |= Rd << 8;
13217 inst.instruction |= Rm;
13218 inst.instruction |= inst.operands[2].imm << 4;
13219 }
13220 else
13221 {
13222 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13223 _("Thumb encoding does not support rotation"));
13224 constraint (1, BAD_HIREG);
13225 }
13226 }
13227
13228 static void
13229 do_t_swi (void)
13230 {
13231 inst.relocs[0].type = BFD_RELOC_ARM_SWI;
13232 }
13233
13234 static void
13235 do_t_tb (void)
13236 {
13237 unsigned Rn, Rm;
13238 int half;
13239
13240 half = (inst.instruction & 0x10) != 0;
13241 set_it_insn_type_last ();
13242 constraint (inst.operands[0].immisreg,
13243 _("instruction requires register index"));
13244
13245 Rn = inst.operands[0].reg;
13246 Rm = inst.operands[0].imm;
13247
13248 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13249 constraint (Rn == REG_SP, BAD_SP);
13250 reject_bad_reg (Rm);
13251
13252 constraint (!half && inst.operands[0].shifted,
13253 _("instruction does not allow shifted index"));
13254 inst.instruction |= (Rn << 16) | Rm;
13255 }
13256
13257 static void
13258 do_t_udf (void)
13259 {
13260 if (!inst.operands[0].present)
13261 inst.operands[0].imm = 0;
13262
13263 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13264 {
13265 constraint (inst.size_req == 2,
13266 _("immediate value out of range"));
13267 inst.instruction = THUMB_OP32 (inst.instruction);
13268 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13269 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13270 }
13271 else
13272 {
13273 inst.instruction = THUMB_OP16 (inst.instruction);
13274 inst.instruction |= inst.operands[0].imm;
13275 }
13276
13277 set_it_insn_type (NEUTRAL_IT_INSN);
13278 }
13279
13280
13281 static void
13282 do_t_usat (void)
13283 {
13284 do_t_ssat_usat (0);
13285 }
13286
13287 static void
13288 do_t_usat16 (void)
13289 {
13290 unsigned Rd, Rn;
13291
13292 Rd = inst.operands[0].reg;
13293 Rn = inst.operands[2].reg;
13294
13295 reject_bad_reg (Rd);
13296 reject_bad_reg (Rn);
13297
13298 inst.instruction |= Rd << 8;
13299 inst.instruction |= inst.operands[1].imm;
13300 inst.instruction |= Rn << 16;
13301 }
13302
13303 /* Checking the range of the branch offset (VAL) with NBITS bits
13304 and IS_SIGNED signedness. Also checks the LSB to be 0. */
13305 static int
13306 v8_1_branch_value_check (int val, int nbits, int is_signed)
13307 {
13308 gas_assert (nbits > 0 && nbits <= 32);
13309 if (is_signed)
13310 {
13311 int cmp = (1 << (nbits - 1));
13312 if ((val < -cmp) || (val >= cmp) || (val & 0x01))
13313 return FAIL;
13314 }
13315 else
13316 {
13317 if ((val <= 0) || (val >= (1 << nbits)) || (val & 0x1))
13318 return FAIL;
13319 }
13320 return SUCCESS;
13321 }
13322
13323 /* Neon instruction encoder helpers. */
13324
13325 /* Encodings for the different types for various Neon opcodes. */
13326
13327 /* An "invalid" code for the following tables. */
13328 #define N_INV -1u
13329
13330 struct neon_tab_entry
13331 {
13332 unsigned integer;
13333 unsigned float_or_poly;
13334 unsigned scalar_or_imm;
13335 };
13336
13337 /* Map overloaded Neon opcodes to their respective encodings. */
13338 #define NEON_ENC_TAB \
13339 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13340 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13341 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13342 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13343 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13344 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13345 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13346 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13347 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13348 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13349 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13350 /* Register variants of the following two instructions are encoded as
13351 vcge / vcgt with the operands reversed. */ \
13352 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13353 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
13354 X(vfma, N_INV, 0x0000c10, N_INV), \
13355 X(vfms, N_INV, 0x0200c10, N_INV), \
13356 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13357 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13358 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13359 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13360 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13361 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13362 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13363 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13364 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13365 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13366 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
13367 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13368 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
13369 X(vshl, 0x0000400, N_INV, 0x0800510), \
13370 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13371 X(vand, 0x0000110, N_INV, 0x0800030), \
13372 X(vbic, 0x0100110, N_INV, 0x0800030), \
13373 X(veor, 0x1000110, N_INV, N_INV), \
13374 X(vorn, 0x0300110, N_INV, 0x0800010), \
13375 X(vorr, 0x0200110, N_INV, 0x0800010), \
13376 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13377 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13378 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13379 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13380 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13381 X(vst1, 0x0000000, 0x0800000, N_INV), \
13382 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13383 X(vst2, 0x0000100, 0x0800100, N_INV), \
13384 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13385 X(vst3, 0x0000200, 0x0800200, N_INV), \
13386 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13387 X(vst4, 0x0000300, 0x0800300, N_INV), \
13388 X(vmovn, 0x1b20200, N_INV, N_INV), \
13389 X(vtrn, 0x1b20080, N_INV, N_INV), \
13390 X(vqmovn, 0x1b20200, N_INV, N_INV), \
13391 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13392 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
13393 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13394 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
13395 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13396 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
13397 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13398 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13399 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
13400 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13401 X(vseleq, 0xe000a00, N_INV, N_INV), \
13402 X(vselvs, 0xe100a00, N_INV, N_INV), \
13403 X(vselge, 0xe200a00, N_INV, N_INV), \
13404 X(vselgt, 0xe300a00, N_INV, N_INV), \
13405 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
13406 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
13407 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13408 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
13409 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
13410 X(aes, 0x3b00300, N_INV, N_INV), \
13411 X(sha3op, 0x2000c00, N_INV, N_INV), \
13412 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13413 X(sha2op, 0x3ba0380, N_INV, N_INV)
13414
13415 enum neon_opc
13416 {
13417 #define X(OPC,I,F,S) N_MNEM_##OPC
13418 NEON_ENC_TAB
13419 #undef X
13420 };
13421
13422 static const struct neon_tab_entry neon_enc_tab[] =
13423 {
13424 #define X(OPC,I,F,S) { (I), (F), (S) }
13425 NEON_ENC_TAB
13426 #undef X
13427 };
13428
13429 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
13430 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13431 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13432 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13433 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13434 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13435 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13436 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13437 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13438 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13439 #define NEON_ENC_SINGLE_(X) \
13440 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
13441 #define NEON_ENC_DOUBLE_(X) \
13442 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
13443 #define NEON_ENC_FPV8_(X) \
13444 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
13445
13446 #define NEON_ENCODE(type, inst) \
13447 do \
13448 { \
13449 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13450 inst.is_neon = 1; \
13451 } \
13452 while (0)
13453
13454 #define check_neon_suffixes \
13455 do \
13456 { \
13457 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13458 { \
13459 as_bad (_("invalid neon suffix for non neon instruction")); \
13460 return; \
13461 } \
13462 } \
13463 while (0)
13464
13465 /* Define shapes for instruction operands. The following mnemonic characters
13466 are used in this table:
13467
13468 F - VFP S<n> register
13469 D - Neon D<n> register
13470 Q - Neon Q<n> register
13471 I - Immediate
13472 S - Scalar
13473 R - ARM register
13474 L - D<n> register list
13475
13476 This table is used to generate various data:
13477 - enumerations of the form NS_DDR to be used as arguments to
13478 neon_select_shape.
13479 - a table classifying shapes into single, double, quad, mixed.
13480 - a table used to drive neon_select_shape. */
13481
13482 #define NEON_SHAPE_DEF \
13483 X(3, (D, D, D), DOUBLE), \
13484 X(3, (Q, Q, Q), QUAD), \
13485 X(3, (D, D, I), DOUBLE), \
13486 X(3, (Q, Q, I), QUAD), \
13487 X(3, (D, D, S), DOUBLE), \
13488 X(3, (Q, Q, S), QUAD), \
13489 X(2, (D, D), DOUBLE), \
13490 X(2, (Q, Q), QUAD), \
13491 X(2, (D, S), DOUBLE), \
13492 X(2, (Q, S), QUAD), \
13493 X(2, (D, R), DOUBLE), \
13494 X(2, (Q, R), QUAD), \
13495 X(2, (D, I), DOUBLE), \
13496 X(2, (Q, I), QUAD), \
13497 X(3, (D, L, D), DOUBLE), \
13498 X(2, (D, Q), MIXED), \
13499 X(2, (Q, D), MIXED), \
13500 X(3, (D, Q, I), MIXED), \
13501 X(3, (Q, D, I), MIXED), \
13502 X(3, (Q, D, D), MIXED), \
13503 X(3, (D, Q, Q), MIXED), \
13504 X(3, (Q, Q, D), MIXED), \
13505 X(3, (Q, D, S), MIXED), \
13506 X(3, (D, Q, S), MIXED), \
13507 X(4, (D, D, D, I), DOUBLE), \
13508 X(4, (Q, Q, Q, I), QUAD), \
13509 X(4, (D, D, S, I), DOUBLE), \
13510 X(4, (Q, Q, S, I), QUAD), \
13511 X(2, (F, F), SINGLE), \
13512 X(3, (F, F, F), SINGLE), \
13513 X(2, (F, I), SINGLE), \
13514 X(2, (F, D), MIXED), \
13515 X(2, (D, F), MIXED), \
13516 X(3, (F, F, I), MIXED), \
13517 X(4, (R, R, F, F), SINGLE), \
13518 X(4, (F, F, R, R), SINGLE), \
13519 X(3, (D, R, R), DOUBLE), \
13520 X(3, (R, R, D), DOUBLE), \
13521 X(2, (S, R), SINGLE), \
13522 X(2, (R, S), SINGLE), \
13523 X(2, (F, R), SINGLE), \
13524 X(2, (R, F), SINGLE), \
13525 /* Half float shape supported so far. */\
13526 X (2, (H, D), MIXED), \
13527 X (2, (D, H), MIXED), \
13528 X (2, (H, F), MIXED), \
13529 X (2, (F, H), MIXED), \
13530 X (2, (H, H), HALF), \
13531 X (2, (H, R), HALF), \
13532 X (2, (R, H), HALF), \
13533 X (2, (H, I), HALF), \
13534 X (3, (H, H, H), HALF), \
13535 X (3, (H, F, I), MIXED), \
13536 X (3, (F, H, I), MIXED), \
13537 X (3, (D, H, H), MIXED), \
13538 X (3, (D, H, S), MIXED)
13539
13540 #define S2(A,B) NS_##A##B
13541 #define S3(A,B,C) NS_##A##B##C
13542 #define S4(A,B,C,D) NS_##A##B##C##D
13543
13544 #define X(N, L, C) S##N L
13545
13546 enum neon_shape
13547 {
13548 NEON_SHAPE_DEF,
13549 NS_NULL
13550 };
13551
13552 #undef X
13553 #undef S2
13554 #undef S3
13555 #undef S4
13556
13557 enum neon_shape_class
13558 {
13559 SC_HALF,
13560 SC_SINGLE,
13561 SC_DOUBLE,
13562 SC_QUAD,
13563 SC_MIXED
13564 };
13565
13566 #define X(N, L, C) SC_##C
13567
13568 static enum neon_shape_class neon_shape_class[] =
13569 {
13570 NEON_SHAPE_DEF
13571 };
13572
13573 #undef X
13574
13575 enum neon_shape_el
13576 {
13577 SE_H,
13578 SE_F,
13579 SE_D,
13580 SE_Q,
13581 SE_I,
13582 SE_S,
13583 SE_R,
13584 SE_L
13585 };
13586
13587 /* Register widths of above. */
13588 static unsigned neon_shape_el_size[] =
13589 {
13590 16,
13591 32,
13592 64,
13593 128,
13594 0,
13595 32,
13596 32,
13597 0
13598 };
13599
13600 struct neon_shape_info
13601 {
13602 unsigned els;
13603 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13604 };
13605
13606 #define S2(A,B) { SE_##A, SE_##B }
13607 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13608 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13609
13610 #define X(N, L, C) { N, S##N L }
13611
13612 static struct neon_shape_info neon_shape_tab[] =
13613 {
13614 NEON_SHAPE_DEF
13615 };
13616
13617 #undef X
13618 #undef S2
13619 #undef S3
13620 #undef S4
13621
13622 /* Bit masks used in type checking given instructions.
13623 'N_EQK' means the type must be the same as (or based on in some way) the key
13624 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13625 set, various other bits can be set as well in order to modify the meaning of
13626 the type constraint. */
13627
13628 enum neon_type_mask
13629 {
13630 N_S8 = 0x0000001,
13631 N_S16 = 0x0000002,
13632 N_S32 = 0x0000004,
13633 N_S64 = 0x0000008,
13634 N_U8 = 0x0000010,
13635 N_U16 = 0x0000020,
13636 N_U32 = 0x0000040,
13637 N_U64 = 0x0000080,
13638 N_I8 = 0x0000100,
13639 N_I16 = 0x0000200,
13640 N_I32 = 0x0000400,
13641 N_I64 = 0x0000800,
13642 N_8 = 0x0001000,
13643 N_16 = 0x0002000,
13644 N_32 = 0x0004000,
13645 N_64 = 0x0008000,
13646 N_P8 = 0x0010000,
13647 N_P16 = 0x0020000,
13648 N_F16 = 0x0040000,
13649 N_F32 = 0x0080000,
13650 N_F64 = 0x0100000,
13651 N_P64 = 0x0200000,
13652 N_KEY = 0x1000000, /* Key element (main type specifier). */
13653 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
13654 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
13655 N_UNT = 0x8000000, /* Must be explicitly untyped. */
13656 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13657 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13658 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13659 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13660 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13661 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13662 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
13663 N_UTYP = 0,
13664 N_MAX_NONSPECIAL = N_P64
13665 };
13666
13667 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13668
13669 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13670 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13671 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13672 #define N_S_32 (N_S8 | N_S16 | N_S32)
13673 #define N_F_16_32 (N_F16 | N_F32)
13674 #define N_SUF_32 (N_SU_32 | N_F_16_32)
13675 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13676 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
13677 #define N_F_ALL (N_F16 | N_F32 | N_F64)
13678
13679 /* Pass this as the first type argument to neon_check_type to ignore types
13680 altogether. */
13681 #define N_IGNORE_TYPE (N_KEY | N_EQK)
13682
13683 /* Select a "shape" for the current instruction (describing register types or
13684 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13685 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13686 function of operand parsing, so this function doesn't need to be called.
13687 Shapes should be listed in order of decreasing length. */
13688
13689 static enum neon_shape
13690 neon_select_shape (enum neon_shape shape, ...)
13691 {
13692 va_list ap;
13693 enum neon_shape first_shape = shape;
13694
13695 /* Fix missing optional operands. FIXME: we don't know at this point how
13696 many arguments we should have, so this makes the assumption that we have
13697 > 1. This is true of all current Neon opcodes, I think, but may not be
13698 true in the future. */
13699 if (!inst.operands[1].present)
13700 inst.operands[1] = inst.operands[0];
13701
13702 va_start (ap, shape);
13703
13704 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
13705 {
13706 unsigned j;
13707 int matches = 1;
13708
13709 for (j = 0; j < neon_shape_tab[shape].els; j++)
13710 {
13711 if (!inst.operands[j].present)
13712 {
13713 matches = 0;
13714 break;
13715 }
13716
13717 switch (neon_shape_tab[shape].el[j])
13718 {
13719 /* If a .f16, .16, .u16, .s16 type specifier is given over
13720 a VFP single precision register operand, it's essentially
13721 means only half of the register is used.
13722
13723 If the type specifier is given after the mnemonics, the
13724 information is stored in inst.vectype. If the type specifier
13725 is given after register operand, the information is stored
13726 in inst.operands[].vectype.
13727
13728 When there is only one type specifier, and all the register
13729 operands are the same type of hardware register, the type
13730 specifier applies to all register operands.
13731
13732 If no type specifier is given, the shape is inferred from
13733 operand information.
13734
13735 for example:
13736 vadd.f16 s0, s1, s2: NS_HHH
13737 vabs.f16 s0, s1: NS_HH
13738 vmov.f16 s0, r1: NS_HR
13739 vmov.f16 r0, s1: NS_RH
13740 vcvt.f16 r0, s1: NS_RH
13741 vcvt.f16.s32 s2, s2, #29: NS_HFI
13742 vcvt.f16.s32 s2, s2: NS_HF
13743 */
13744 case SE_H:
13745 if (!(inst.operands[j].isreg
13746 && inst.operands[j].isvec
13747 && inst.operands[j].issingle
13748 && !inst.operands[j].isquad
13749 && ((inst.vectype.elems == 1
13750 && inst.vectype.el[0].size == 16)
13751 || (inst.vectype.elems > 1
13752 && inst.vectype.el[j].size == 16)
13753 || (inst.vectype.elems == 0
13754 && inst.operands[j].vectype.type != NT_invtype
13755 && inst.operands[j].vectype.size == 16))))
13756 matches = 0;
13757 break;
13758
13759 case SE_F:
13760 if (!(inst.operands[j].isreg
13761 && inst.operands[j].isvec
13762 && inst.operands[j].issingle
13763 && !inst.operands[j].isquad
13764 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13765 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13766 || (inst.vectype.elems == 0
13767 && (inst.operands[j].vectype.size == 32
13768 || inst.operands[j].vectype.type == NT_invtype)))))
13769 matches = 0;
13770 break;
13771
13772 case SE_D:
13773 if (!(inst.operands[j].isreg
13774 && inst.operands[j].isvec
13775 && !inst.operands[j].isquad
13776 && !inst.operands[j].issingle))
13777 matches = 0;
13778 break;
13779
13780 case SE_R:
13781 if (!(inst.operands[j].isreg
13782 && !inst.operands[j].isvec))
13783 matches = 0;
13784 break;
13785
13786 case SE_Q:
13787 if (!(inst.operands[j].isreg
13788 && inst.operands[j].isvec
13789 && inst.operands[j].isquad
13790 && !inst.operands[j].issingle))
13791 matches = 0;
13792 break;
13793
13794 case SE_I:
13795 if (!(!inst.operands[j].isreg
13796 && !inst.operands[j].isscalar))
13797 matches = 0;
13798 break;
13799
13800 case SE_S:
13801 if (!(!inst.operands[j].isreg
13802 && inst.operands[j].isscalar))
13803 matches = 0;
13804 break;
13805
13806 case SE_L:
13807 break;
13808 }
13809 if (!matches)
13810 break;
13811 }
13812 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13813 /* We've matched all the entries in the shape table, and we don't
13814 have any left over operands which have not been matched. */
13815 break;
13816 }
13817
13818 va_end (ap);
13819
13820 if (shape == NS_NULL && first_shape != NS_NULL)
13821 first_error (_("invalid instruction shape"));
13822
13823 return shape;
13824 }
13825
13826 /* True if SHAPE is predominantly a quadword operation (most of the time, this
13827 means the Q bit should be set). */
13828
13829 static int
13830 neon_quad (enum neon_shape shape)
13831 {
13832 return neon_shape_class[shape] == SC_QUAD;
13833 }
13834
13835 static void
13836 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
13837 unsigned *g_size)
13838 {
13839 /* Allow modification to be made to types which are constrained to be
13840 based on the key element, based on bits set alongside N_EQK. */
13841 if ((typebits & N_EQK) != 0)
13842 {
13843 if ((typebits & N_HLF) != 0)
13844 *g_size /= 2;
13845 else if ((typebits & N_DBL) != 0)
13846 *g_size *= 2;
13847 if ((typebits & N_SGN) != 0)
13848 *g_type = NT_signed;
13849 else if ((typebits & N_UNS) != 0)
13850 *g_type = NT_unsigned;
13851 else if ((typebits & N_INT) != 0)
13852 *g_type = NT_integer;
13853 else if ((typebits & N_FLT) != 0)
13854 *g_type = NT_float;
13855 else if ((typebits & N_SIZ) != 0)
13856 *g_type = NT_untyped;
13857 }
13858 }
13859
13860 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13861 operand type, i.e. the single type specified in a Neon instruction when it
13862 is the only one given. */
13863
13864 static struct neon_type_el
13865 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13866 {
13867 struct neon_type_el dest = *key;
13868
13869 gas_assert ((thisarg & N_EQK) != 0);
13870
13871 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13872
13873 return dest;
13874 }
13875
13876 /* Convert Neon type and size into compact bitmask representation. */
13877
13878 static enum neon_type_mask
13879 type_chk_of_el_type (enum neon_el_type type, unsigned size)
13880 {
13881 switch (type)
13882 {
13883 case NT_untyped:
13884 switch (size)
13885 {
13886 case 8: return N_8;
13887 case 16: return N_16;
13888 case 32: return N_32;
13889 case 64: return N_64;
13890 default: ;
13891 }
13892 break;
13893
13894 case NT_integer:
13895 switch (size)
13896 {
13897 case 8: return N_I8;
13898 case 16: return N_I16;
13899 case 32: return N_I32;
13900 case 64: return N_I64;
13901 default: ;
13902 }
13903 break;
13904
13905 case NT_float:
13906 switch (size)
13907 {
13908 case 16: return N_F16;
13909 case 32: return N_F32;
13910 case 64: return N_F64;
13911 default: ;
13912 }
13913 break;
13914
13915 case NT_poly:
13916 switch (size)
13917 {
13918 case 8: return N_P8;
13919 case 16: return N_P16;
13920 case 64: return N_P64;
13921 default: ;
13922 }
13923 break;
13924
13925 case NT_signed:
13926 switch (size)
13927 {
13928 case 8: return N_S8;
13929 case 16: return N_S16;
13930 case 32: return N_S32;
13931 case 64: return N_S64;
13932 default: ;
13933 }
13934 break;
13935
13936 case NT_unsigned:
13937 switch (size)
13938 {
13939 case 8: return N_U8;
13940 case 16: return N_U16;
13941 case 32: return N_U32;
13942 case 64: return N_U64;
13943 default: ;
13944 }
13945 break;
13946
13947 default: ;
13948 }
13949
13950 return N_UTYP;
13951 }
13952
13953 /* Convert compact Neon bitmask type representation to a type and size. Only
13954 handles the case where a single bit is set in the mask. */
13955
13956 static int
13957 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
13958 enum neon_type_mask mask)
13959 {
13960 if ((mask & N_EQK) != 0)
13961 return FAIL;
13962
13963 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13964 *size = 8;
13965 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
13966 *size = 16;
13967 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
13968 *size = 32;
13969 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
13970 *size = 64;
13971 else
13972 return FAIL;
13973
13974 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13975 *type = NT_signed;
13976 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
13977 *type = NT_unsigned;
13978 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
13979 *type = NT_integer;
13980 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
13981 *type = NT_untyped;
13982 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
13983 *type = NT_poly;
13984 else if ((mask & (N_F_ALL)) != 0)
13985 *type = NT_float;
13986 else
13987 return FAIL;
13988
13989 return SUCCESS;
13990 }
13991
13992 /* Modify a bitmask of allowed types. This is only needed for type
13993 relaxation. */
13994
13995 static unsigned
13996 modify_types_allowed (unsigned allowed, unsigned mods)
13997 {
13998 unsigned size;
13999 enum neon_el_type type;
14000 unsigned destmask;
14001 int i;
14002
14003 destmask = 0;
14004
14005 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
14006 {
14007 if (el_type_of_type_chk (&type, &size,
14008 (enum neon_type_mask) (allowed & i)) == SUCCESS)
14009 {
14010 neon_modify_type_size (mods, &type, &size);
14011 destmask |= type_chk_of_el_type (type, size);
14012 }
14013 }
14014
14015 return destmask;
14016 }
14017
14018 /* Check type and return type classification.
14019 The manual states (paraphrase): If one datatype is given, it indicates the
14020 type given in:
14021 - the second operand, if there is one
14022 - the operand, if there is no second operand
14023 - the result, if there are no operands.
14024 This isn't quite good enough though, so we use a concept of a "key" datatype
14025 which is set on a per-instruction basis, which is the one which matters when
14026 only one data type is written.
14027 Note: this function has side-effects (e.g. filling in missing operands). All
14028 Neon instructions should call it before performing bit encoding. */
14029
14030 static struct neon_type_el
14031 neon_check_type (unsigned els, enum neon_shape ns, ...)
14032 {
14033 va_list ap;
14034 unsigned i, pass, key_el = 0;
14035 unsigned types[NEON_MAX_TYPE_ELS];
14036 enum neon_el_type k_type = NT_invtype;
14037 unsigned k_size = -1u;
14038 struct neon_type_el badtype = {NT_invtype, -1};
14039 unsigned key_allowed = 0;
14040
14041 /* Optional registers in Neon instructions are always (not) in operand 1.
14042 Fill in the missing operand here, if it was omitted. */
14043 if (els > 1 && !inst.operands[1].present)
14044 inst.operands[1] = inst.operands[0];
14045
14046 /* Suck up all the varargs. */
14047 va_start (ap, ns);
14048 for (i = 0; i < els; i++)
14049 {
14050 unsigned thisarg = va_arg (ap, unsigned);
14051 if (thisarg == N_IGNORE_TYPE)
14052 {
14053 va_end (ap);
14054 return badtype;
14055 }
14056 types[i] = thisarg;
14057 if ((thisarg & N_KEY) != 0)
14058 key_el = i;
14059 }
14060 va_end (ap);
14061
14062 if (inst.vectype.elems > 0)
14063 for (i = 0; i < els; i++)
14064 if (inst.operands[i].vectype.type != NT_invtype)
14065 {
14066 first_error (_("types specified in both the mnemonic and operands"));
14067 return badtype;
14068 }
14069
14070 /* Duplicate inst.vectype elements here as necessary.
14071 FIXME: No idea if this is exactly the same as the ARM assembler,
14072 particularly when an insn takes one register and one non-register
14073 operand. */
14074 if (inst.vectype.elems == 1 && els > 1)
14075 {
14076 unsigned j;
14077 inst.vectype.elems = els;
14078 inst.vectype.el[key_el] = inst.vectype.el[0];
14079 for (j = 0; j < els; j++)
14080 if (j != key_el)
14081 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14082 types[j]);
14083 }
14084 else if (inst.vectype.elems == 0 && els > 0)
14085 {
14086 unsigned j;
14087 /* No types were given after the mnemonic, so look for types specified
14088 after each operand. We allow some flexibility here; as long as the
14089 "key" operand has a type, we can infer the others. */
14090 for (j = 0; j < els; j++)
14091 if (inst.operands[j].vectype.type != NT_invtype)
14092 inst.vectype.el[j] = inst.operands[j].vectype;
14093
14094 if (inst.operands[key_el].vectype.type != NT_invtype)
14095 {
14096 for (j = 0; j < els; j++)
14097 if (inst.operands[j].vectype.type == NT_invtype)
14098 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14099 types[j]);
14100 }
14101 else
14102 {
14103 first_error (_("operand types can't be inferred"));
14104 return badtype;
14105 }
14106 }
14107 else if (inst.vectype.elems != els)
14108 {
14109 first_error (_("type specifier has the wrong number of parts"));
14110 return badtype;
14111 }
14112
14113 for (pass = 0; pass < 2; pass++)
14114 {
14115 for (i = 0; i < els; i++)
14116 {
14117 unsigned thisarg = types[i];
14118 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14119 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14120 enum neon_el_type g_type = inst.vectype.el[i].type;
14121 unsigned g_size = inst.vectype.el[i].size;
14122
14123 /* Decay more-specific signed & unsigned types to sign-insensitive
14124 integer types if sign-specific variants are unavailable. */
14125 if ((g_type == NT_signed || g_type == NT_unsigned)
14126 && (types_allowed & N_SU_ALL) == 0)
14127 g_type = NT_integer;
14128
14129 /* If only untyped args are allowed, decay any more specific types to
14130 them. Some instructions only care about signs for some element
14131 sizes, so handle that properly. */
14132 if (((types_allowed & N_UNT) == 0)
14133 && ((g_size == 8 && (types_allowed & N_8) != 0)
14134 || (g_size == 16 && (types_allowed & N_16) != 0)
14135 || (g_size == 32 && (types_allowed & N_32) != 0)
14136 || (g_size == 64 && (types_allowed & N_64) != 0)))
14137 g_type = NT_untyped;
14138
14139 if (pass == 0)
14140 {
14141 if ((thisarg & N_KEY) != 0)
14142 {
14143 k_type = g_type;
14144 k_size = g_size;
14145 key_allowed = thisarg & ~N_KEY;
14146
14147 /* Check architecture constraint on FP16 extension. */
14148 if (k_size == 16
14149 && k_type == NT_float
14150 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14151 {
14152 inst.error = _(BAD_FP16);
14153 return badtype;
14154 }
14155 }
14156 }
14157 else
14158 {
14159 if ((thisarg & N_VFP) != 0)
14160 {
14161 enum neon_shape_el regshape;
14162 unsigned regwidth, match;
14163
14164 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14165 if (ns == NS_NULL)
14166 {
14167 first_error (_("invalid instruction shape"));
14168 return badtype;
14169 }
14170 regshape = neon_shape_tab[ns].el[i];
14171 regwidth = neon_shape_el_size[regshape];
14172
14173 /* In VFP mode, operands must match register widths. If we
14174 have a key operand, use its width, else use the width of
14175 the current operand. */
14176 if (k_size != -1u)
14177 match = k_size;
14178 else
14179 match = g_size;
14180
14181 /* FP16 will use a single precision register. */
14182 if (regwidth == 32 && match == 16)
14183 {
14184 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14185 match = regwidth;
14186 else
14187 {
14188 inst.error = _(BAD_FP16);
14189 return badtype;
14190 }
14191 }
14192
14193 if (regwidth != match)
14194 {
14195 first_error (_("operand size must match register width"));
14196 return badtype;
14197 }
14198 }
14199
14200 if ((thisarg & N_EQK) == 0)
14201 {
14202 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14203
14204 if ((given_type & types_allowed) == 0)
14205 {
14206 first_error (_("bad type in Neon instruction"));
14207 return badtype;
14208 }
14209 }
14210 else
14211 {
14212 enum neon_el_type mod_k_type = k_type;
14213 unsigned mod_k_size = k_size;
14214 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14215 if (g_type != mod_k_type || g_size != mod_k_size)
14216 {
14217 first_error (_("inconsistent types in Neon instruction"));
14218 return badtype;
14219 }
14220 }
14221 }
14222 }
14223 }
14224
14225 return inst.vectype.el[key_el];
14226 }
14227
14228 /* Neon-style VFP instruction forwarding. */
14229
14230 /* Thumb VFP instructions have 0xE in the condition field. */
14231
14232 static void
14233 do_vfp_cond_or_thumb (void)
14234 {
14235 inst.is_neon = 1;
14236
14237 if (thumb_mode)
14238 inst.instruction |= 0xe0000000;
14239 else
14240 inst.instruction |= inst.cond << 28;
14241 }
14242
14243 /* Look up and encode a simple mnemonic, for use as a helper function for the
14244 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14245 etc. It is assumed that operand parsing has already been done, and that the
14246 operands are in the form expected by the given opcode (this isn't necessarily
14247 the same as the form in which they were parsed, hence some massaging must
14248 take place before this function is called).
14249 Checks current arch version against that in the looked-up opcode. */
14250
14251 static void
14252 do_vfp_nsyn_opcode (const char *opname)
14253 {
14254 const struct asm_opcode *opcode;
14255
14256 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
14257
14258 if (!opcode)
14259 abort ();
14260
14261 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
14262 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14263 _(BAD_FPU));
14264
14265 inst.is_neon = 1;
14266
14267 if (thumb_mode)
14268 {
14269 inst.instruction = opcode->tvalue;
14270 opcode->tencode ();
14271 }
14272 else
14273 {
14274 inst.instruction = (inst.cond << 28) | opcode->avalue;
14275 opcode->aencode ();
14276 }
14277 }
14278
14279 static void
14280 do_vfp_nsyn_add_sub (enum neon_shape rs)
14281 {
14282 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14283
14284 if (rs == NS_FFF || rs == NS_HHH)
14285 {
14286 if (is_add)
14287 do_vfp_nsyn_opcode ("fadds");
14288 else
14289 do_vfp_nsyn_opcode ("fsubs");
14290
14291 /* ARMv8.2 fp16 instruction. */
14292 if (rs == NS_HHH)
14293 do_scalar_fp16_v82_encode ();
14294 }
14295 else
14296 {
14297 if (is_add)
14298 do_vfp_nsyn_opcode ("faddd");
14299 else
14300 do_vfp_nsyn_opcode ("fsubd");
14301 }
14302 }
14303
14304 /* Check operand types to see if this is a VFP instruction, and if so call
14305 PFN (). */
14306
14307 static int
14308 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14309 {
14310 enum neon_shape rs;
14311 struct neon_type_el et;
14312
14313 switch (args)
14314 {
14315 case 2:
14316 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14317 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
14318 break;
14319
14320 case 3:
14321 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14322 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14323 N_F_ALL | N_KEY | N_VFP);
14324 break;
14325
14326 default:
14327 abort ();
14328 }
14329
14330 if (et.type != NT_invtype)
14331 {
14332 pfn (rs);
14333 return SUCCESS;
14334 }
14335
14336 inst.error = NULL;
14337 return FAIL;
14338 }
14339
14340 static void
14341 do_vfp_nsyn_mla_mls (enum neon_shape rs)
14342 {
14343 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
14344
14345 if (rs == NS_FFF || rs == NS_HHH)
14346 {
14347 if (is_mla)
14348 do_vfp_nsyn_opcode ("fmacs");
14349 else
14350 do_vfp_nsyn_opcode ("fnmacs");
14351
14352 /* ARMv8.2 fp16 instruction. */
14353 if (rs == NS_HHH)
14354 do_scalar_fp16_v82_encode ();
14355 }
14356 else
14357 {
14358 if (is_mla)
14359 do_vfp_nsyn_opcode ("fmacd");
14360 else
14361 do_vfp_nsyn_opcode ("fnmacd");
14362 }
14363 }
14364
14365 static void
14366 do_vfp_nsyn_fma_fms (enum neon_shape rs)
14367 {
14368 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14369
14370 if (rs == NS_FFF || rs == NS_HHH)
14371 {
14372 if (is_fma)
14373 do_vfp_nsyn_opcode ("ffmas");
14374 else
14375 do_vfp_nsyn_opcode ("ffnmas");
14376
14377 /* ARMv8.2 fp16 instruction. */
14378 if (rs == NS_HHH)
14379 do_scalar_fp16_v82_encode ();
14380 }
14381 else
14382 {
14383 if (is_fma)
14384 do_vfp_nsyn_opcode ("ffmad");
14385 else
14386 do_vfp_nsyn_opcode ("ffnmad");
14387 }
14388 }
14389
14390 static void
14391 do_vfp_nsyn_mul (enum neon_shape rs)
14392 {
14393 if (rs == NS_FFF || rs == NS_HHH)
14394 {
14395 do_vfp_nsyn_opcode ("fmuls");
14396
14397 /* ARMv8.2 fp16 instruction. */
14398 if (rs == NS_HHH)
14399 do_scalar_fp16_v82_encode ();
14400 }
14401 else
14402 do_vfp_nsyn_opcode ("fmuld");
14403 }
14404
14405 static void
14406 do_vfp_nsyn_abs_neg (enum neon_shape rs)
14407 {
14408 int is_neg = (inst.instruction & 0x80) != 0;
14409 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
14410
14411 if (rs == NS_FF || rs == NS_HH)
14412 {
14413 if (is_neg)
14414 do_vfp_nsyn_opcode ("fnegs");
14415 else
14416 do_vfp_nsyn_opcode ("fabss");
14417
14418 /* ARMv8.2 fp16 instruction. */
14419 if (rs == NS_HH)
14420 do_scalar_fp16_v82_encode ();
14421 }
14422 else
14423 {
14424 if (is_neg)
14425 do_vfp_nsyn_opcode ("fnegd");
14426 else
14427 do_vfp_nsyn_opcode ("fabsd");
14428 }
14429 }
14430
14431 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14432 insns belong to Neon, and are handled elsewhere. */
14433
14434 static void
14435 do_vfp_nsyn_ldm_stm (int is_dbmode)
14436 {
14437 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14438 if (is_ldm)
14439 {
14440 if (is_dbmode)
14441 do_vfp_nsyn_opcode ("fldmdbs");
14442 else
14443 do_vfp_nsyn_opcode ("fldmias");
14444 }
14445 else
14446 {
14447 if (is_dbmode)
14448 do_vfp_nsyn_opcode ("fstmdbs");
14449 else
14450 do_vfp_nsyn_opcode ("fstmias");
14451 }
14452 }
14453
14454 static void
14455 do_vfp_nsyn_sqrt (void)
14456 {
14457 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14458 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
14459
14460 if (rs == NS_FF || rs == NS_HH)
14461 {
14462 do_vfp_nsyn_opcode ("fsqrts");
14463
14464 /* ARMv8.2 fp16 instruction. */
14465 if (rs == NS_HH)
14466 do_scalar_fp16_v82_encode ();
14467 }
14468 else
14469 do_vfp_nsyn_opcode ("fsqrtd");
14470 }
14471
14472 static void
14473 do_vfp_nsyn_div (void)
14474 {
14475 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14476 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14477 N_F_ALL | N_KEY | N_VFP);
14478
14479 if (rs == NS_FFF || rs == NS_HHH)
14480 {
14481 do_vfp_nsyn_opcode ("fdivs");
14482
14483 /* ARMv8.2 fp16 instruction. */
14484 if (rs == NS_HHH)
14485 do_scalar_fp16_v82_encode ();
14486 }
14487 else
14488 do_vfp_nsyn_opcode ("fdivd");
14489 }
14490
14491 static void
14492 do_vfp_nsyn_nmul (void)
14493 {
14494 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14495 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14496 N_F_ALL | N_KEY | N_VFP);
14497
14498 if (rs == NS_FFF || rs == NS_HHH)
14499 {
14500 NEON_ENCODE (SINGLE, inst);
14501 do_vfp_sp_dyadic ();
14502
14503 /* ARMv8.2 fp16 instruction. */
14504 if (rs == NS_HHH)
14505 do_scalar_fp16_v82_encode ();
14506 }
14507 else
14508 {
14509 NEON_ENCODE (DOUBLE, inst);
14510 do_vfp_dp_rd_rn_rm ();
14511 }
14512 do_vfp_cond_or_thumb ();
14513
14514 }
14515
14516 static void
14517 do_vfp_nsyn_cmp (void)
14518 {
14519 enum neon_shape rs;
14520 if (inst.operands[1].isreg)
14521 {
14522 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14523 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
14524
14525 if (rs == NS_FF || rs == NS_HH)
14526 {
14527 NEON_ENCODE (SINGLE, inst);
14528 do_vfp_sp_monadic ();
14529 }
14530 else
14531 {
14532 NEON_ENCODE (DOUBLE, inst);
14533 do_vfp_dp_rd_rm ();
14534 }
14535 }
14536 else
14537 {
14538 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14539 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
14540
14541 switch (inst.instruction & 0x0fffffff)
14542 {
14543 case N_MNEM_vcmp:
14544 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14545 break;
14546 case N_MNEM_vcmpe:
14547 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14548 break;
14549 default:
14550 abort ();
14551 }
14552
14553 if (rs == NS_FI || rs == NS_HI)
14554 {
14555 NEON_ENCODE (SINGLE, inst);
14556 do_vfp_sp_compare_z ();
14557 }
14558 else
14559 {
14560 NEON_ENCODE (DOUBLE, inst);
14561 do_vfp_dp_rd ();
14562 }
14563 }
14564 do_vfp_cond_or_thumb ();
14565
14566 /* ARMv8.2 fp16 instruction. */
14567 if (rs == NS_HI || rs == NS_HH)
14568 do_scalar_fp16_v82_encode ();
14569 }
14570
14571 static void
14572 nsyn_insert_sp (void)
14573 {
14574 inst.operands[1] = inst.operands[0];
14575 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
14576 inst.operands[0].reg = REG_SP;
14577 inst.operands[0].isreg = 1;
14578 inst.operands[0].writeback = 1;
14579 inst.operands[0].present = 1;
14580 }
14581
14582 static void
14583 do_vfp_nsyn_push (void)
14584 {
14585 nsyn_insert_sp ();
14586
14587 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14588 _("register list must contain at least 1 and at most 16 "
14589 "registers"));
14590
14591 if (inst.operands[1].issingle)
14592 do_vfp_nsyn_opcode ("fstmdbs");
14593 else
14594 do_vfp_nsyn_opcode ("fstmdbd");
14595 }
14596
14597 static void
14598 do_vfp_nsyn_pop (void)
14599 {
14600 nsyn_insert_sp ();
14601
14602 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14603 _("register list must contain at least 1 and at most 16 "
14604 "registers"));
14605
14606 if (inst.operands[1].issingle)
14607 do_vfp_nsyn_opcode ("fldmias");
14608 else
14609 do_vfp_nsyn_opcode ("fldmiad");
14610 }
14611
14612 /* Fix up Neon data-processing instructions, ORing in the correct bits for
14613 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14614
14615 static void
14616 neon_dp_fixup (struct arm_it* insn)
14617 {
14618 unsigned int i = insn->instruction;
14619 insn->is_neon = 1;
14620
14621 if (thumb_mode)
14622 {
14623 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14624 if (i & (1 << 24))
14625 i |= 1 << 28;
14626
14627 i &= ~(1 << 24);
14628
14629 i |= 0xef000000;
14630 }
14631 else
14632 i |= 0xf2000000;
14633
14634 insn->instruction = i;
14635 }
14636
14637 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14638 (0, 1, 2, 3). */
14639
14640 static unsigned
14641 neon_logbits (unsigned x)
14642 {
14643 return ffs (x) - 4;
14644 }
14645
14646 #define LOW4(R) ((R) & 0xf)
14647 #define HI1(R) (((R) >> 4) & 1)
14648
14649 /* Encode insns with bit pattern:
14650
14651 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14652 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
14653
14654 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14655 different meaning for some instruction. */
14656
14657 static void
14658 neon_three_same (int isquad, int ubit, int size)
14659 {
14660 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14661 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14662 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14663 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14664 inst.instruction |= LOW4 (inst.operands[2].reg);
14665 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14666 inst.instruction |= (isquad != 0) << 6;
14667 inst.instruction |= (ubit != 0) << 24;
14668 if (size != -1)
14669 inst.instruction |= neon_logbits (size) << 20;
14670
14671 neon_dp_fixup (&inst);
14672 }
14673
14674 /* Encode instructions of the form:
14675
14676 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14677 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
14678
14679 Don't write size if SIZE == -1. */
14680
14681 static void
14682 neon_two_same (int qbit, int ubit, int size)
14683 {
14684 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14685 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14686 inst.instruction |= LOW4 (inst.operands[1].reg);
14687 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14688 inst.instruction |= (qbit != 0) << 6;
14689 inst.instruction |= (ubit != 0) << 24;
14690
14691 if (size != -1)
14692 inst.instruction |= neon_logbits (size) << 18;
14693
14694 neon_dp_fixup (&inst);
14695 }
14696
14697 /* Neon instruction encoders, in approximate order of appearance. */
14698
14699 static void
14700 do_neon_dyadic_i_su (void)
14701 {
14702 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14703 struct neon_type_el et = neon_check_type (3, rs,
14704 N_EQK, N_EQK, N_SU_32 | N_KEY);
14705 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14706 }
14707
14708 static void
14709 do_neon_dyadic_i64_su (void)
14710 {
14711 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14712 struct neon_type_el et = neon_check_type (3, rs,
14713 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14714 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14715 }
14716
14717 static void
14718 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
14719 unsigned immbits)
14720 {
14721 unsigned size = et.size >> 3;
14722 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14723 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14724 inst.instruction |= LOW4 (inst.operands[1].reg);
14725 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14726 inst.instruction |= (isquad != 0) << 6;
14727 inst.instruction |= immbits << 16;
14728 inst.instruction |= (size >> 3) << 7;
14729 inst.instruction |= (size & 0x7) << 19;
14730 if (write_ubit)
14731 inst.instruction |= (uval != 0) << 24;
14732
14733 neon_dp_fixup (&inst);
14734 }
14735
14736 static void
14737 do_neon_shl_imm (void)
14738 {
14739 if (!inst.operands[2].isreg)
14740 {
14741 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14742 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
14743 int imm = inst.operands[2].imm;
14744
14745 constraint (imm < 0 || (unsigned)imm >= et.size,
14746 _("immediate out of range for shift"));
14747 NEON_ENCODE (IMMED, inst);
14748 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14749 }
14750 else
14751 {
14752 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14753 struct neon_type_el et = neon_check_type (3, rs,
14754 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
14755 unsigned int tmp;
14756
14757 /* VSHL/VQSHL 3-register variants have syntax such as:
14758 vshl.xx Dd, Dm, Dn
14759 whereas other 3-register operations encoded by neon_three_same have
14760 syntax like:
14761 vadd.xx Dd, Dn, Dm
14762 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14763 here. */
14764 tmp = inst.operands[2].reg;
14765 inst.operands[2].reg = inst.operands[1].reg;
14766 inst.operands[1].reg = tmp;
14767 NEON_ENCODE (INTEGER, inst);
14768 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14769 }
14770 }
14771
14772 static void
14773 do_neon_qshl_imm (void)
14774 {
14775 if (!inst.operands[2].isreg)
14776 {
14777 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14778 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14779 int imm = inst.operands[2].imm;
14780
14781 constraint (imm < 0 || (unsigned)imm >= et.size,
14782 _("immediate out of range for shift"));
14783 NEON_ENCODE (IMMED, inst);
14784 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
14785 }
14786 else
14787 {
14788 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14789 struct neon_type_el et = neon_check_type (3, rs,
14790 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
14791 unsigned int tmp;
14792
14793 /* See note in do_neon_shl_imm. */
14794 tmp = inst.operands[2].reg;
14795 inst.operands[2].reg = inst.operands[1].reg;
14796 inst.operands[1].reg = tmp;
14797 NEON_ENCODE (INTEGER, inst);
14798 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14799 }
14800 }
14801
14802 static void
14803 do_neon_rshl (void)
14804 {
14805 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14806 struct neon_type_el et = neon_check_type (3, rs,
14807 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14808 unsigned int tmp;
14809
14810 tmp = inst.operands[2].reg;
14811 inst.operands[2].reg = inst.operands[1].reg;
14812 inst.operands[1].reg = tmp;
14813 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14814 }
14815
14816 static int
14817 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14818 {
14819 /* Handle .I8 pseudo-instructions. */
14820 if (size == 8)
14821 {
14822 /* Unfortunately, this will make everything apart from zero out-of-range.
14823 FIXME is this the intended semantics? There doesn't seem much point in
14824 accepting .I8 if so. */
14825 immediate |= immediate << 8;
14826 size = 16;
14827 }
14828
14829 if (size >= 32)
14830 {
14831 if (immediate == (immediate & 0x000000ff))
14832 {
14833 *immbits = immediate;
14834 return 0x1;
14835 }
14836 else if (immediate == (immediate & 0x0000ff00))
14837 {
14838 *immbits = immediate >> 8;
14839 return 0x3;
14840 }
14841 else if (immediate == (immediate & 0x00ff0000))
14842 {
14843 *immbits = immediate >> 16;
14844 return 0x5;
14845 }
14846 else if (immediate == (immediate & 0xff000000))
14847 {
14848 *immbits = immediate >> 24;
14849 return 0x7;
14850 }
14851 if ((immediate & 0xffff) != (immediate >> 16))
14852 goto bad_immediate;
14853 immediate &= 0xffff;
14854 }
14855
14856 if (immediate == (immediate & 0x000000ff))
14857 {
14858 *immbits = immediate;
14859 return 0x9;
14860 }
14861 else if (immediate == (immediate & 0x0000ff00))
14862 {
14863 *immbits = immediate >> 8;
14864 return 0xb;
14865 }
14866
14867 bad_immediate:
14868 first_error (_("immediate value out of range"));
14869 return FAIL;
14870 }
14871
14872 static void
14873 do_neon_logic (void)
14874 {
14875 if (inst.operands[2].present && inst.operands[2].isreg)
14876 {
14877 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14878 neon_check_type (3, rs, N_IGNORE_TYPE);
14879 /* U bit and size field were set as part of the bitmask. */
14880 NEON_ENCODE (INTEGER, inst);
14881 neon_three_same (neon_quad (rs), 0, -1);
14882 }
14883 else
14884 {
14885 const int three_ops_form = (inst.operands[2].present
14886 && !inst.operands[2].isreg);
14887 const int immoperand = (three_ops_form ? 2 : 1);
14888 enum neon_shape rs = (three_ops_form
14889 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14890 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
14891 struct neon_type_el et = neon_check_type (2, rs,
14892 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14893 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
14894 unsigned immbits;
14895 int cmode;
14896
14897 if (et.type == NT_invtype)
14898 return;
14899
14900 if (three_ops_form)
14901 constraint (inst.operands[0].reg != inst.operands[1].reg,
14902 _("first and second operands shall be the same register"));
14903
14904 NEON_ENCODE (IMMED, inst);
14905
14906 immbits = inst.operands[immoperand].imm;
14907 if (et.size == 64)
14908 {
14909 /* .i64 is a pseudo-op, so the immediate must be a repeating
14910 pattern. */
14911 if (immbits != (inst.operands[immoperand].regisimm ?
14912 inst.operands[immoperand].reg : 0))
14913 {
14914 /* Set immbits to an invalid constant. */
14915 immbits = 0xdeadbeef;
14916 }
14917 }
14918
14919 switch (opcode)
14920 {
14921 case N_MNEM_vbic:
14922 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14923 break;
14924
14925 case N_MNEM_vorr:
14926 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14927 break;
14928
14929 case N_MNEM_vand:
14930 /* Pseudo-instruction for VBIC. */
14931 neon_invert_size (&immbits, 0, et.size);
14932 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14933 break;
14934
14935 case N_MNEM_vorn:
14936 /* Pseudo-instruction for VORR. */
14937 neon_invert_size (&immbits, 0, et.size);
14938 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14939 break;
14940
14941 default:
14942 abort ();
14943 }
14944
14945 if (cmode == FAIL)
14946 return;
14947
14948 inst.instruction |= neon_quad (rs) << 6;
14949 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14950 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14951 inst.instruction |= cmode << 8;
14952 neon_write_immbits (immbits);
14953
14954 neon_dp_fixup (&inst);
14955 }
14956 }
14957
14958 static void
14959 do_neon_bitfield (void)
14960 {
14961 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14962 neon_check_type (3, rs, N_IGNORE_TYPE);
14963 neon_three_same (neon_quad (rs), 0, -1);
14964 }
14965
14966 static void
14967 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
14968 unsigned destbits)
14969 {
14970 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14971 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
14972 types | N_KEY);
14973 if (et.type == NT_float)
14974 {
14975 NEON_ENCODE (FLOAT, inst);
14976 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
14977 }
14978 else
14979 {
14980 NEON_ENCODE (INTEGER, inst);
14981 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
14982 }
14983 }
14984
14985 static void
14986 do_neon_dyadic_if_su (void)
14987 {
14988 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
14989 }
14990
14991 static void
14992 do_neon_dyadic_if_su_d (void)
14993 {
14994 /* This version only allow D registers, but that constraint is enforced during
14995 operand parsing so we don't need to do anything extra here. */
14996 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
14997 }
14998
14999 static void
15000 do_neon_dyadic_if_i_d (void)
15001 {
15002 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15003 affected if we specify unsigned args. */
15004 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15005 }
15006
15007 enum vfp_or_neon_is_neon_bits
15008 {
15009 NEON_CHECK_CC = 1,
15010 NEON_CHECK_ARCH = 2,
15011 NEON_CHECK_ARCH8 = 4
15012 };
15013
15014 /* Call this function if an instruction which may have belonged to the VFP or
15015 Neon instruction sets, but turned out to be a Neon instruction (due to the
15016 operand types involved, etc.). We have to check and/or fix-up a couple of
15017 things:
15018
15019 - Make sure the user hasn't attempted to make a Neon instruction
15020 conditional.
15021 - Alter the value in the condition code field if necessary.
15022 - Make sure that the arch supports Neon instructions.
15023
15024 Which of these operations take place depends on bits from enum
15025 vfp_or_neon_is_neon_bits.
15026
15027 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
15028 current instruction's condition is COND_ALWAYS, the condition field is
15029 changed to inst.uncond_value. This is necessary because instructions shared
15030 between VFP and Neon may be conditional for the VFP variants only, and the
15031 unconditional Neon version must have, e.g., 0xF in the condition field. */
15032
15033 static int
15034 vfp_or_neon_is_neon (unsigned check)
15035 {
15036 /* Conditions are always legal in Thumb mode (IT blocks). */
15037 if (!thumb_mode && (check & NEON_CHECK_CC))
15038 {
15039 if (inst.cond != COND_ALWAYS)
15040 {
15041 first_error (_(BAD_COND));
15042 return FAIL;
15043 }
15044 if (inst.uncond_value != -1)
15045 inst.instruction |= inst.uncond_value << 28;
15046 }
15047
15048 if ((check & NEON_CHECK_ARCH)
15049 && !mark_feature_used (&fpu_neon_ext_v1))
15050 {
15051 first_error (_(BAD_FPU));
15052 return FAIL;
15053 }
15054
15055 if ((check & NEON_CHECK_ARCH8)
15056 && !mark_feature_used (&fpu_neon_ext_armv8))
15057 {
15058 first_error (_(BAD_FPU));
15059 return FAIL;
15060 }
15061
15062 return SUCCESS;
15063 }
15064
15065 static void
15066 do_neon_addsub_if_i (void)
15067 {
15068 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
15069 return;
15070
15071 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15072 return;
15073
15074 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15075 affected if we specify unsigned args. */
15076 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
15077 }
15078
15079 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15080 result to be:
15081 V<op> A,B (A is operand 0, B is operand 2)
15082 to mean:
15083 V<op> A,B,A
15084 not:
15085 V<op> A,B,B
15086 so handle that case specially. */
15087
15088 static void
15089 neon_exchange_operands (void)
15090 {
15091 if (inst.operands[1].present)
15092 {
15093 void *scratch = xmalloc (sizeof (inst.operands[0]));
15094
15095 /* Swap operands[1] and operands[2]. */
15096 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15097 inst.operands[1] = inst.operands[2];
15098 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
15099 free (scratch);
15100 }
15101 else
15102 {
15103 inst.operands[1] = inst.operands[2];
15104 inst.operands[2] = inst.operands[0];
15105 }
15106 }
15107
15108 static void
15109 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15110 {
15111 if (inst.operands[2].isreg)
15112 {
15113 if (invert)
15114 neon_exchange_operands ();
15115 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
15116 }
15117 else
15118 {
15119 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15120 struct neon_type_el et = neon_check_type (2, rs,
15121 N_EQK | N_SIZ, immtypes | N_KEY);
15122
15123 NEON_ENCODE (IMMED, inst);
15124 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15125 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15126 inst.instruction |= LOW4 (inst.operands[1].reg);
15127 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15128 inst.instruction |= neon_quad (rs) << 6;
15129 inst.instruction |= (et.type == NT_float) << 10;
15130 inst.instruction |= neon_logbits (et.size) << 18;
15131
15132 neon_dp_fixup (&inst);
15133 }
15134 }
15135
15136 static void
15137 do_neon_cmp (void)
15138 {
15139 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
15140 }
15141
15142 static void
15143 do_neon_cmp_inv (void)
15144 {
15145 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
15146 }
15147
15148 static void
15149 do_neon_ceq (void)
15150 {
15151 neon_compare (N_IF_32, N_IF_32, FALSE);
15152 }
15153
15154 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
15155 scalars, which are encoded in 5 bits, M : Rm.
15156 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15157 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
15158 index in M.
15159
15160 Dot Product instructions are similar to multiply instructions except elsize
15161 should always be 32.
15162
15163 This function translates SCALAR, which is GAS's internal encoding of indexed
15164 scalar register, to raw encoding. There is also register and index range
15165 check based on ELSIZE. */
15166
15167 static unsigned
15168 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15169 {
15170 unsigned regno = NEON_SCALAR_REG (scalar);
15171 unsigned elno = NEON_SCALAR_INDEX (scalar);
15172
15173 switch (elsize)
15174 {
15175 case 16:
15176 if (regno > 7 || elno > 3)
15177 goto bad_scalar;
15178 return regno | (elno << 3);
15179
15180 case 32:
15181 if (regno > 15 || elno > 1)
15182 goto bad_scalar;
15183 return regno | (elno << 4);
15184
15185 default:
15186 bad_scalar:
15187 first_error (_("scalar out of range for multiply instruction"));
15188 }
15189
15190 return 0;
15191 }
15192
15193 /* Encode multiply / multiply-accumulate scalar instructions. */
15194
15195 static void
15196 neon_mul_mac (struct neon_type_el et, int ubit)
15197 {
15198 unsigned scalar;
15199
15200 /* Give a more helpful error message if we have an invalid type. */
15201 if (et.type == NT_invtype)
15202 return;
15203
15204 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
15205 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15206 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15207 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15208 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15209 inst.instruction |= LOW4 (scalar);
15210 inst.instruction |= HI1 (scalar) << 5;
15211 inst.instruction |= (et.type == NT_float) << 8;
15212 inst.instruction |= neon_logbits (et.size) << 20;
15213 inst.instruction |= (ubit != 0) << 24;
15214
15215 neon_dp_fixup (&inst);
15216 }
15217
15218 static void
15219 do_neon_mac_maybe_scalar (void)
15220 {
15221 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15222 return;
15223
15224 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15225 return;
15226
15227 if (inst.operands[2].isscalar)
15228 {
15229 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15230 struct neon_type_el et = neon_check_type (3, rs,
15231 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
15232 NEON_ENCODE (SCALAR, inst);
15233 neon_mul_mac (et, neon_quad (rs));
15234 }
15235 else
15236 {
15237 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15238 affected if we specify unsigned args. */
15239 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15240 }
15241 }
15242
15243 static void
15244 do_neon_fmac (void)
15245 {
15246 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15247 return;
15248
15249 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15250 return;
15251
15252 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15253 }
15254
15255 static void
15256 do_neon_tst (void)
15257 {
15258 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15259 struct neon_type_el et = neon_check_type (3, rs,
15260 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
15261 neon_three_same (neon_quad (rs), 0, et.size);
15262 }
15263
15264 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
15265 same types as the MAC equivalents. The polynomial type for this instruction
15266 is encoded the same as the integer type. */
15267
15268 static void
15269 do_neon_mul (void)
15270 {
15271 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15272 return;
15273
15274 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15275 return;
15276
15277 if (inst.operands[2].isscalar)
15278 do_neon_mac_maybe_scalar ();
15279 else
15280 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
15281 }
15282
15283 static void
15284 do_neon_qdmulh (void)
15285 {
15286 if (inst.operands[2].isscalar)
15287 {
15288 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15289 struct neon_type_el et = neon_check_type (3, rs,
15290 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15291 NEON_ENCODE (SCALAR, inst);
15292 neon_mul_mac (et, neon_quad (rs));
15293 }
15294 else
15295 {
15296 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15297 struct neon_type_el et = neon_check_type (3, rs,
15298 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15299 NEON_ENCODE (INTEGER, inst);
15300 /* The U bit (rounding) comes from bit mask. */
15301 neon_three_same (neon_quad (rs), 0, et.size);
15302 }
15303 }
15304
15305 static void
15306 do_neon_qrdmlah (void)
15307 {
15308 /* Check we're on the correct architecture. */
15309 if (!mark_feature_used (&fpu_neon_ext_armv8))
15310 inst.error =
15311 _("instruction form not available on this architecture.");
15312 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15313 {
15314 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15315 record_feature_use (&fpu_neon_ext_v8_1);
15316 }
15317
15318 if (inst.operands[2].isscalar)
15319 {
15320 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15321 struct neon_type_el et = neon_check_type (3, rs,
15322 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15323 NEON_ENCODE (SCALAR, inst);
15324 neon_mul_mac (et, neon_quad (rs));
15325 }
15326 else
15327 {
15328 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15329 struct neon_type_el et = neon_check_type (3, rs,
15330 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15331 NEON_ENCODE (INTEGER, inst);
15332 /* The U bit (rounding) comes from bit mask. */
15333 neon_three_same (neon_quad (rs), 0, et.size);
15334 }
15335 }
15336
15337 static void
15338 do_neon_fcmp_absolute (void)
15339 {
15340 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15341 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15342 N_F_16_32 | N_KEY);
15343 /* Size field comes from bit mask. */
15344 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
15345 }
15346
15347 static void
15348 do_neon_fcmp_absolute_inv (void)
15349 {
15350 neon_exchange_operands ();
15351 do_neon_fcmp_absolute ();
15352 }
15353
15354 static void
15355 do_neon_step (void)
15356 {
15357 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15358 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15359 N_F_16_32 | N_KEY);
15360 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
15361 }
15362
15363 static void
15364 do_neon_abs_neg (void)
15365 {
15366 enum neon_shape rs;
15367 struct neon_type_el et;
15368
15369 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15370 return;
15371
15372 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15373 return;
15374
15375 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15376 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
15377
15378 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15379 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15380 inst.instruction |= LOW4 (inst.operands[1].reg);
15381 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15382 inst.instruction |= neon_quad (rs) << 6;
15383 inst.instruction |= (et.type == NT_float) << 10;
15384 inst.instruction |= neon_logbits (et.size) << 18;
15385
15386 neon_dp_fixup (&inst);
15387 }
15388
15389 static void
15390 do_neon_sli (void)
15391 {
15392 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15393 struct neon_type_el et = neon_check_type (2, rs,
15394 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15395 int imm = inst.operands[2].imm;
15396 constraint (imm < 0 || (unsigned)imm >= et.size,
15397 _("immediate out of range for insert"));
15398 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
15399 }
15400
15401 static void
15402 do_neon_sri (void)
15403 {
15404 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15405 struct neon_type_el et = neon_check_type (2, rs,
15406 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15407 int imm = inst.operands[2].imm;
15408 constraint (imm < 1 || (unsigned)imm > et.size,
15409 _("immediate out of range for insert"));
15410 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
15411 }
15412
15413 static void
15414 do_neon_qshlu_imm (void)
15415 {
15416 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15417 struct neon_type_el et = neon_check_type (2, rs,
15418 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15419 int imm = inst.operands[2].imm;
15420 constraint (imm < 0 || (unsigned)imm >= et.size,
15421 _("immediate out of range for shift"));
15422 /* Only encodes the 'U present' variant of the instruction.
15423 In this case, signed types have OP (bit 8) set to 0.
15424 Unsigned types have OP set to 1. */
15425 inst.instruction |= (et.type == NT_unsigned) << 8;
15426 /* The rest of the bits are the same as other immediate shifts. */
15427 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
15428 }
15429
15430 static void
15431 do_neon_qmovn (void)
15432 {
15433 struct neon_type_el et = neon_check_type (2, NS_DQ,
15434 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15435 /* Saturating move where operands can be signed or unsigned, and the
15436 destination has the same signedness. */
15437 NEON_ENCODE (INTEGER, inst);
15438 if (et.type == NT_unsigned)
15439 inst.instruction |= 0xc0;
15440 else
15441 inst.instruction |= 0x80;
15442 neon_two_same (0, 1, et.size / 2);
15443 }
15444
15445 static void
15446 do_neon_qmovun (void)
15447 {
15448 struct neon_type_el et = neon_check_type (2, NS_DQ,
15449 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15450 /* Saturating move with unsigned results. Operands must be signed. */
15451 NEON_ENCODE (INTEGER, inst);
15452 neon_two_same (0, 1, et.size / 2);
15453 }
15454
15455 static void
15456 do_neon_rshift_sat_narrow (void)
15457 {
15458 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15459 or unsigned. If operands are unsigned, results must also be unsigned. */
15460 struct neon_type_el et = neon_check_type (2, NS_DQI,
15461 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15462 int imm = inst.operands[2].imm;
15463 /* This gets the bounds check, size encoding and immediate bits calculation
15464 right. */
15465 et.size /= 2;
15466
15467 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15468 VQMOVN.I<size> <Dd>, <Qm>. */
15469 if (imm == 0)
15470 {
15471 inst.operands[2].present = 0;
15472 inst.instruction = N_MNEM_vqmovn;
15473 do_neon_qmovn ();
15474 return;
15475 }
15476
15477 constraint (imm < 1 || (unsigned)imm > et.size,
15478 _("immediate out of range"));
15479 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15480 }
15481
15482 static void
15483 do_neon_rshift_sat_narrow_u (void)
15484 {
15485 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15486 or unsigned. If operands are unsigned, results must also be unsigned. */
15487 struct neon_type_el et = neon_check_type (2, NS_DQI,
15488 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15489 int imm = inst.operands[2].imm;
15490 /* This gets the bounds check, size encoding and immediate bits calculation
15491 right. */
15492 et.size /= 2;
15493
15494 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15495 VQMOVUN.I<size> <Dd>, <Qm>. */
15496 if (imm == 0)
15497 {
15498 inst.operands[2].present = 0;
15499 inst.instruction = N_MNEM_vqmovun;
15500 do_neon_qmovun ();
15501 return;
15502 }
15503
15504 constraint (imm < 1 || (unsigned)imm > et.size,
15505 _("immediate out of range"));
15506 /* FIXME: The manual is kind of unclear about what value U should have in
15507 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15508 must be 1. */
15509 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15510 }
15511
15512 static void
15513 do_neon_movn (void)
15514 {
15515 struct neon_type_el et = neon_check_type (2, NS_DQ,
15516 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15517 NEON_ENCODE (INTEGER, inst);
15518 neon_two_same (0, 1, et.size / 2);
15519 }
15520
15521 static void
15522 do_neon_rshift_narrow (void)
15523 {
15524 struct neon_type_el et = neon_check_type (2, NS_DQI,
15525 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15526 int imm = inst.operands[2].imm;
15527 /* This gets the bounds check, size encoding and immediate bits calculation
15528 right. */
15529 et.size /= 2;
15530
15531 /* If immediate is zero then we are a pseudo-instruction for
15532 VMOVN.I<size> <Dd>, <Qm> */
15533 if (imm == 0)
15534 {
15535 inst.operands[2].present = 0;
15536 inst.instruction = N_MNEM_vmovn;
15537 do_neon_movn ();
15538 return;
15539 }
15540
15541 constraint (imm < 1 || (unsigned)imm > et.size,
15542 _("immediate out of range for narrowing operation"));
15543 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15544 }
15545
15546 static void
15547 do_neon_shll (void)
15548 {
15549 /* FIXME: Type checking when lengthening. */
15550 struct neon_type_el et = neon_check_type (2, NS_QDI,
15551 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15552 unsigned imm = inst.operands[2].imm;
15553
15554 if (imm == et.size)
15555 {
15556 /* Maximum shift variant. */
15557 NEON_ENCODE (INTEGER, inst);
15558 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15559 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15560 inst.instruction |= LOW4 (inst.operands[1].reg);
15561 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15562 inst.instruction |= neon_logbits (et.size) << 18;
15563
15564 neon_dp_fixup (&inst);
15565 }
15566 else
15567 {
15568 /* A more-specific type check for non-max versions. */
15569 et = neon_check_type (2, NS_QDI,
15570 N_EQK | N_DBL, N_SU_32 | N_KEY);
15571 NEON_ENCODE (IMMED, inst);
15572 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15573 }
15574 }
15575
15576 /* Check the various types for the VCVT instruction, and return which version
15577 the current instruction is. */
15578
15579 #define CVT_FLAVOUR_VAR \
15580 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15581 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15582 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15583 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15584 /* Half-precision conversions. */ \
15585 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15586 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15587 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15588 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
15589 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15590 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
15591 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15592 Compared with single/double precision variants, only the co-processor \
15593 field is different, so the encoding flow is reused here. */ \
15594 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15595 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15596 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15597 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
15598 /* VFP instructions. */ \
15599 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15600 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15601 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15602 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15603 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15604 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15605 /* VFP instructions with bitshift. */ \
15606 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15607 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15608 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15609 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15610 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15611 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15612 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15613 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15614
15615 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15616 neon_cvt_flavour_##C,
15617
15618 /* The different types of conversions we can do. */
15619 enum neon_cvt_flavour
15620 {
15621 CVT_FLAVOUR_VAR
15622 neon_cvt_flavour_invalid,
15623 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15624 };
15625
15626 #undef CVT_VAR
15627
15628 static enum neon_cvt_flavour
15629 get_neon_cvt_flavour (enum neon_shape rs)
15630 {
15631 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15632 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15633 if (et.type != NT_invtype) \
15634 { \
15635 inst.error = NULL; \
15636 return (neon_cvt_flavour_##C); \
15637 }
15638
15639 struct neon_type_el et;
15640 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
15641 || rs == NS_FF) ? N_VFP : 0;
15642 /* The instruction versions which take an immediate take one register
15643 argument, which is extended to the width of the full register. Thus the
15644 "source" and "destination" registers must have the same width. Hack that
15645 here by making the size equal to the key (wider, in this case) operand. */
15646 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
15647
15648 CVT_FLAVOUR_VAR;
15649
15650 return neon_cvt_flavour_invalid;
15651 #undef CVT_VAR
15652 }
15653
15654 enum neon_cvt_mode
15655 {
15656 neon_cvt_mode_a,
15657 neon_cvt_mode_n,
15658 neon_cvt_mode_p,
15659 neon_cvt_mode_m,
15660 neon_cvt_mode_z,
15661 neon_cvt_mode_x,
15662 neon_cvt_mode_r
15663 };
15664
15665 /* Neon-syntax VFP conversions. */
15666
15667 static void
15668 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
15669 {
15670 const char *opname = 0;
15671
15672 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15673 || rs == NS_FHI || rs == NS_HFI)
15674 {
15675 /* Conversions with immediate bitshift. */
15676 const char *enc[] =
15677 {
15678 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15679 CVT_FLAVOUR_VAR
15680 NULL
15681 #undef CVT_VAR
15682 };
15683
15684 if (flavour < (int) ARRAY_SIZE (enc))
15685 {
15686 opname = enc[flavour];
15687 constraint (inst.operands[0].reg != inst.operands[1].reg,
15688 _("operands 0 and 1 must be the same register"));
15689 inst.operands[1] = inst.operands[2];
15690 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15691 }
15692 }
15693 else
15694 {
15695 /* Conversions without bitshift. */
15696 const char *enc[] =
15697 {
15698 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15699 CVT_FLAVOUR_VAR
15700 NULL
15701 #undef CVT_VAR
15702 };
15703
15704 if (flavour < (int) ARRAY_SIZE (enc))
15705 opname = enc[flavour];
15706 }
15707
15708 if (opname)
15709 do_vfp_nsyn_opcode (opname);
15710
15711 /* ARMv8.2 fp16 VCVT instruction. */
15712 if (flavour == neon_cvt_flavour_s32_f16
15713 || flavour == neon_cvt_flavour_u32_f16
15714 || flavour == neon_cvt_flavour_f16_u32
15715 || flavour == neon_cvt_flavour_f16_s32)
15716 do_scalar_fp16_v82_encode ();
15717 }
15718
15719 static void
15720 do_vfp_nsyn_cvtz (void)
15721 {
15722 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
15723 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
15724 const char *enc[] =
15725 {
15726 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15727 CVT_FLAVOUR_VAR
15728 NULL
15729 #undef CVT_VAR
15730 };
15731
15732 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
15733 do_vfp_nsyn_opcode (enc[flavour]);
15734 }
15735
15736 static void
15737 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
15738 enum neon_cvt_mode mode)
15739 {
15740 int sz, op;
15741 int rm;
15742
15743 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15744 D register operands. */
15745 if (flavour == neon_cvt_flavour_s32_f64
15746 || flavour == neon_cvt_flavour_u32_f64)
15747 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15748 _(BAD_FPU));
15749
15750 if (flavour == neon_cvt_flavour_s32_f16
15751 || flavour == neon_cvt_flavour_u32_f16)
15752 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15753 _(BAD_FP16));
15754
15755 set_it_insn_type (OUTSIDE_IT_INSN);
15756
15757 switch (flavour)
15758 {
15759 case neon_cvt_flavour_s32_f64:
15760 sz = 1;
15761 op = 1;
15762 break;
15763 case neon_cvt_flavour_s32_f32:
15764 sz = 0;
15765 op = 1;
15766 break;
15767 case neon_cvt_flavour_s32_f16:
15768 sz = 0;
15769 op = 1;
15770 break;
15771 case neon_cvt_flavour_u32_f64:
15772 sz = 1;
15773 op = 0;
15774 break;
15775 case neon_cvt_flavour_u32_f32:
15776 sz = 0;
15777 op = 0;
15778 break;
15779 case neon_cvt_flavour_u32_f16:
15780 sz = 0;
15781 op = 0;
15782 break;
15783 default:
15784 first_error (_("invalid instruction shape"));
15785 return;
15786 }
15787
15788 switch (mode)
15789 {
15790 case neon_cvt_mode_a: rm = 0; break;
15791 case neon_cvt_mode_n: rm = 1; break;
15792 case neon_cvt_mode_p: rm = 2; break;
15793 case neon_cvt_mode_m: rm = 3; break;
15794 default: first_error (_("invalid rounding mode")); return;
15795 }
15796
15797 NEON_ENCODE (FPV8, inst);
15798 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15799 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15800 inst.instruction |= sz << 8;
15801
15802 /* ARMv8.2 fp16 VCVT instruction. */
15803 if (flavour == neon_cvt_flavour_s32_f16
15804 ||flavour == neon_cvt_flavour_u32_f16)
15805 do_scalar_fp16_v82_encode ();
15806 inst.instruction |= op << 7;
15807 inst.instruction |= rm << 16;
15808 inst.instruction |= 0xf0000000;
15809 inst.is_neon = TRUE;
15810 }
15811
15812 static void
15813 do_neon_cvt_1 (enum neon_cvt_mode mode)
15814 {
15815 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
15816 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15817 NS_FH, NS_HF, NS_FHI, NS_HFI,
15818 NS_NULL);
15819 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
15820
15821 if (flavour == neon_cvt_flavour_invalid)
15822 return;
15823
15824 /* PR11109: Handle round-to-zero for VCVT conversions. */
15825 if (mode == neon_cvt_mode_z
15826 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
15827 && (flavour == neon_cvt_flavour_s16_f16
15828 || flavour == neon_cvt_flavour_u16_f16
15829 || flavour == neon_cvt_flavour_s32_f32
15830 || flavour == neon_cvt_flavour_u32_f32
15831 || flavour == neon_cvt_flavour_s32_f64
15832 || flavour == neon_cvt_flavour_u32_f64)
15833 && (rs == NS_FD || rs == NS_FF))
15834 {
15835 do_vfp_nsyn_cvtz ();
15836 return;
15837 }
15838
15839 /* ARMv8.2 fp16 VCVT conversions. */
15840 if (mode == neon_cvt_mode_z
15841 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15842 && (flavour == neon_cvt_flavour_s32_f16
15843 || flavour == neon_cvt_flavour_u32_f16)
15844 && (rs == NS_FH))
15845 {
15846 do_vfp_nsyn_cvtz ();
15847 do_scalar_fp16_v82_encode ();
15848 return;
15849 }
15850
15851 /* VFP rather than Neon conversions. */
15852 if (flavour >= neon_cvt_flavour_first_fp)
15853 {
15854 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15855 do_vfp_nsyn_cvt (rs, flavour);
15856 else
15857 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15858
15859 return;
15860 }
15861
15862 switch (rs)
15863 {
15864 case NS_DDI:
15865 case NS_QQI:
15866 {
15867 unsigned immbits;
15868 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15869 0x0000100, 0x1000100, 0x0, 0x1000000};
15870
15871 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15872 return;
15873
15874 /* Fixed-point conversion with #0 immediate is encoded as an
15875 integer conversion. */
15876 if (inst.operands[2].present && inst.operands[2].imm == 0)
15877 goto int_encode;
15878 NEON_ENCODE (IMMED, inst);
15879 if (flavour != neon_cvt_flavour_invalid)
15880 inst.instruction |= enctab[flavour];
15881 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15882 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15883 inst.instruction |= LOW4 (inst.operands[1].reg);
15884 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15885 inst.instruction |= neon_quad (rs) << 6;
15886 inst.instruction |= 1 << 21;
15887 if (flavour < neon_cvt_flavour_s16_f16)
15888 {
15889 inst.instruction |= 1 << 21;
15890 immbits = 32 - inst.operands[2].imm;
15891 inst.instruction |= immbits << 16;
15892 }
15893 else
15894 {
15895 inst.instruction |= 3 << 20;
15896 immbits = 16 - inst.operands[2].imm;
15897 inst.instruction |= immbits << 16;
15898 inst.instruction &= ~(1 << 9);
15899 }
15900
15901 neon_dp_fixup (&inst);
15902 }
15903 break;
15904
15905 case NS_DD:
15906 case NS_QQ:
15907 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15908 {
15909 NEON_ENCODE (FLOAT, inst);
15910 set_it_insn_type (OUTSIDE_IT_INSN);
15911
15912 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15913 return;
15914
15915 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15916 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15917 inst.instruction |= LOW4 (inst.operands[1].reg);
15918 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15919 inst.instruction |= neon_quad (rs) << 6;
15920 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15921 || flavour == neon_cvt_flavour_u32_f32) << 7;
15922 inst.instruction |= mode << 8;
15923 if (flavour == neon_cvt_flavour_u16_f16
15924 || flavour == neon_cvt_flavour_s16_f16)
15925 /* Mask off the original size bits and reencode them. */
15926 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15927
15928 if (thumb_mode)
15929 inst.instruction |= 0xfc000000;
15930 else
15931 inst.instruction |= 0xf0000000;
15932 }
15933 else
15934 {
15935 int_encode:
15936 {
15937 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15938 0x100, 0x180, 0x0, 0x080};
15939
15940 NEON_ENCODE (INTEGER, inst);
15941
15942 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15943 return;
15944
15945 if (flavour != neon_cvt_flavour_invalid)
15946 inst.instruction |= enctab[flavour];
15947
15948 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15949 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15950 inst.instruction |= LOW4 (inst.operands[1].reg);
15951 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15952 inst.instruction |= neon_quad (rs) << 6;
15953 if (flavour >= neon_cvt_flavour_s16_f16
15954 && flavour <= neon_cvt_flavour_f16_u16)
15955 /* Half precision. */
15956 inst.instruction |= 1 << 18;
15957 else
15958 inst.instruction |= 2 << 18;
15959
15960 neon_dp_fixup (&inst);
15961 }
15962 }
15963 break;
15964
15965 /* Half-precision conversions for Advanced SIMD -- neon. */
15966 case NS_QD:
15967 case NS_DQ:
15968 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15969 return;
15970
15971 if ((rs == NS_DQ)
15972 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15973 {
15974 as_bad (_("operand size must match register width"));
15975 break;
15976 }
15977
15978 if ((rs == NS_QD)
15979 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15980 {
15981 as_bad (_("operand size must match register width"));
15982 break;
15983 }
15984
15985 if (rs == NS_DQ)
15986 inst.instruction = 0x3b60600;
15987 else
15988 inst.instruction = 0x3b60700;
15989
15990 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15991 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15992 inst.instruction |= LOW4 (inst.operands[1].reg);
15993 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15994 neon_dp_fixup (&inst);
15995 break;
15996
15997 default:
15998 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
15999 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
16000 do_vfp_nsyn_cvt (rs, flavour);
16001 else
16002 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
16003 }
16004 }
16005
16006 static void
16007 do_neon_cvtr (void)
16008 {
16009 do_neon_cvt_1 (neon_cvt_mode_x);
16010 }
16011
16012 static void
16013 do_neon_cvt (void)
16014 {
16015 do_neon_cvt_1 (neon_cvt_mode_z);
16016 }
16017
16018 static void
16019 do_neon_cvta (void)
16020 {
16021 do_neon_cvt_1 (neon_cvt_mode_a);
16022 }
16023
16024 static void
16025 do_neon_cvtn (void)
16026 {
16027 do_neon_cvt_1 (neon_cvt_mode_n);
16028 }
16029
16030 static void
16031 do_neon_cvtp (void)
16032 {
16033 do_neon_cvt_1 (neon_cvt_mode_p);
16034 }
16035
16036 static void
16037 do_neon_cvtm (void)
16038 {
16039 do_neon_cvt_1 (neon_cvt_mode_m);
16040 }
16041
16042 static void
16043 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
16044 {
16045 if (is_double)
16046 mark_feature_used (&fpu_vfp_ext_armv8);
16047
16048 encode_arm_vfp_reg (inst.operands[0].reg,
16049 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
16050 encode_arm_vfp_reg (inst.operands[1].reg,
16051 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
16052 inst.instruction |= to ? 0x10000 : 0;
16053 inst.instruction |= t ? 0x80 : 0;
16054 inst.instruction |= is_double ? 0x100 : 0;
16055 do_vfp_cond_or_thumb ();
16056 }
16057
16058 static void
16059 do_neon_cvttb_1 (bfd_boolean t)
16060 {
16061 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16062 NS_DF, NS_DH, NS_NULL);
16063
16064 if (rs == NS_NULL)
16065 return;
16066 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16067 {
16068 inst.error = NULL;
16069 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16070 }
16071 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16072 {
16073 inst.error = NULL;
16074 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16075 }
16076 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16077 {
16078 /* The VCVTB and VCVTT instructions with D-register operands
16079 don't work for SP only targets. */
16080 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16081 _(BAD_FPU));
16082
16083 inst.error = NULL;
16084 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16085 }
16086 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16087 {
16088 /* The VCVTB and VCVTT instructions with D-register operands
16089 don't work for SP only targets. */
16090 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16091 _(BAD_FPU));
16092
16093 inst.error = NULL;
16094 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16095 }
16096 else
16097 return;
16098 }
16099
16100 static void
16101 do_neon_cvtb (void)
16102 {
16103 do_neon_cvttb_1 (FALSE);
16104 }
16105
16106
16107 static void
16108 do_neon_cvtt (void)
16109 {
16110 do_neon_cvttb_1 (TRUE);
16111 }
16112
16113 static void
16114 neon_move_immediate (void)
16115 {
16116 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16117 struct neon_type_el et = neon_check_type (2, rs,
16118 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
16119 unsigned immlo, immhi = 0, immbits;
16120 int op, cmode, float_p;
16121
16122 constraint (et.type == NT_invtype,
16123 _("operand size must be specified for immediate VMOV"));
16124
16125 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16126 op = (inst.instruction & (1 << 5)) != 0;
16127
16128 immlo = inst.operands[1].imm;
16129 if (inst.operands[1].regisimm)
16130 immhi = inst.operands[1].reg;
16131
16132 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
16133 _("immediate has bits set outside the operand size"));
16134
16135 float_p = inst.operands[1].immisfloat;
16136
16137 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
16138 et.size, et.type)) == FAIL)
16139 {
16140 /* Invert relevant bits only. */
16141 neon_invert_size (&immlo, &immhi, et.size);
16142 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
16143 with one or the other; those cases are caught by
16144 neon_cmode_for_move_imm. */
16145 op = !op;
16146 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16147 &op, et.size, et.type)) == FAIL)
16148 {
16149 first_error (_("immediate out of range"));
16150 return;
16151 }
16152 }
16153
16154 inst.instruction &= ~(1 << 5);
16155 inst.instruction |= op << 5;
16156
16157 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16158 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16159 inst.instruction |= neon_quad (rs) << 6;
16160 inst.instruction |= cmode << 8;
16161
16162 neon_write_immbits (immbits);
16163 }
16164
16165 static void
16166 do_neon_mvn (void)
16167 {
16168 if (inst.operands[1].isreg)
16169 {
16170 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16171
16172 NEON_ENCODE (INTEGER, inst);
16173 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16174 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16175 inst.instruction |= LOW4 (inst.operands[1].reg);
16176 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16177 inst.instruction |= neon_quad (rs) << 6;
16178 }
16179 else
16180 {
16181 NEON_ENCODE (IMMED, inst);
16182 neon_move_immediate ();
16183 }
16184
16185 neon_dp_fixup (&inst);
16186 }
16187
16188 /* Encode instructions of form:
16189
16190 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16191 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
16192
16193 static void
16194 neon_mixed_length (struct neon_type_el et, unsigned size)
16195 {
16196 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16197 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16198 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16199 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16200 inst.instruction |= LOW4 (inst.operands[2].reg);
16201 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16202 inst.instruction |= (et.type == NT_unsigned) << 24;
16203 inst.instruction |= neon_logbits (size) << 20;
16204
16205 neon_dp_fixup (&inst);
16206 }
16207
16208 static void
16209 do_neon_dyadic_long (void)
16210 {
16211 /* FIXME: Type checking for lengthening op. */
16212 struct neon_type_el et = neon_check_type (3, NS_QDD,
16213 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16214 neon_mixed_length (et, et.size);
16215 }
16216
16217 static void
16218 do_neon_abal (void)
16219 {
16220 struct neon_type_el et = neon_check_type (3, NS_QDD,
16221 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16222 neon_mixed_length (et, et.size);
16223 }
16224
16225 static void
16226 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16227 {
16228 if (inst.operands[2].isscalar)
16229 {
16230 struct neon_type_el et = neon_check_type (3, NS_QDS,
16231 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
16232 NEON_ENCODE (SCALAR, inst);
16233 neon_mul_mac (et, et.type == NT_unsigned);
16234 }
16235 else
16236 {
16237 struct neon_type_el et = neon_check_type (3, NS_QDD,
16238 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
16239 NEON_ENCODE (INTEGER, inst);
16240 neon_mixed_length (et, et.size);
16241 }
16242 }
16243
16244 static void
16245 do_neon_mac_maybe_scalar_long (void)
16246 {
16247 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16248 }
16249
16250 /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16251 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16252
16253 static unsigned
16254 neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16255 {
16256 unsigned regno = NEON_SCALAR_REG (scalar);
16257 unsigned elno = NEON_SCALAR_INDEX (scalar);
16258
16259 if (quad_p)
16260 {
16261 if (regno > 7 || elno > 3)
16262 goto bad_scalar;
16263
16264 return ((regno & 0x7)
16265 | ((elno & 0x1) << 3)
16266 | (((elno >> 1) & 0x1) << 5));
16267 }
16268 else
16269 {
16270 if (regno > 15 || elno > 1)
16271 goto bad_scalar;
16272
16273 return (((regno & 0x1) << 5)
16274 | ((regno >> 1) & 0x7)
16275 | ((elno & 0x1) << 3));
16276 }
16277
16278 bad_scalar:
16279 first_error (_("scalar out of range for multiply instruction"));
16280 return 0;
16281 }
16282
16283 static void
16284 do_neon_fmac_maybe_scalar_long (int subtype)
16285 {
16286 enum neon_shape rs;
16287 int high8;
16288 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16289 field (bits[21:20]) has different meaning. For scalar index variant, it's
16290 used to differentiate add and subtract, otherwise it's with fixed value
16291 0x2. */
16292 int size = -1;
16293
16294 if (inst.cond != COND_ALWAYS)
16295 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16296 "behaviour is UNPREDICTABLE"));
16297
16298 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
16299 _(BAD_FP16));
16300
16301 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16302 _(BAD_FPU));
16303
16304 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16305 be a scalar index register. */
16306 if (inst.operands[2].isscalar)
16307 {
16308 high8 = 0xfe000000;
16309 if (subtype)
16310 size = 16;
16311 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16312 }
16313 else
16314 {
16315 high8 = 0xfc000000;
16316 size = 32;
16317 if (subtype)
16318 inst.instruction |= (0x1 << 23);
16319 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16320 }
16321
16322 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16323
16324 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16325 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16326 so we simply pass -1 as size. */
16327 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16328 neon_three_same (quad_p, 0, size);
16329
16330 /* Undo neon_dp_fixup. Redo the high eight bits. */
16331 inst.instruction &= 0x00ffffff;
16332 inst.instruction |= high8;
16333
16334 #define LOW1(R) ((R) & 0x1)
16335 #define HI4(R) (((R) >> 1) & 0xf)
16336 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16337 whether the instruction is in Q form and whether Vm is a scalar indexed
16338 operand. */
16339 if (inst.operands[2].isscalar)
16340 {
16341 unsigned rm
16342 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16343 inst.instruction &= 0xffffffd0;
16344 inst.instruction |= rm;
16345
16346 if (!quad_p)
16347 {
16348 /* Redo Rn as well. */
16349 inst.instruction &= 0xfff0ff7f;
16350 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16351 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16352 }
16353 }
16354 else if (!quad_p)
16355 {
16356 /* Redo Rn and Rm. */
16357 inst.instruction &= 0xfff0ff50;
16358 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16359 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16360 inst.instruction |= HI4 (inst.operands[2].reg);
16361 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16362 }
16363 }
16364
16365 static void
16366 do_neon_vfmal (void)
16367 {
16368 return do_neon_fmac_maybe_scalar_long (0);
16369 }
16370
16371 static void
16372 do_neon_vfmsl (void)
16373 {
16374 return do_neon_fmac_maybe_scalar_long (1);
16375 }
16376
16377 static void
16378 do_neon_dyadic_wide (void)
16379 {
16380 struct neon_type_el et = neon_check_type (3, NS_QQD,
16381 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16382 neon_mixed_length (et, et.size);
16383 }
16384
16385 static void
16386 do_neon_dyadic_narrow (void)
16387 {
16388 struct neon_type_el et = neon_check_type (3, NS_QDD,
16389 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
16390 /* Operand sign is unimportant, and the U bit is part of the opcode,
16391 so force the operand type to integer. */
16392 et.type = NT_integer;
16393 neon_mixed_length (et, et.size / 2);
16394 }
16395
16396 static void
16397 do_neon_mul_sat_scalar_long (void)
16398 {
16399 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16400 }
16401
16402 static void
16403 do_neon_vmull (void)
16404 {
16405 if (inst.operands[2].isscalar)
16406 do_neon_mac_maybe_scalar_long ();
16407 else
16408 {
16409 struct neon_type_el et = neon_check_type (3, NS_QDD,
16410 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
16411
16412 if (et.type == NT_poly)
16413 NEON_ENCODE (POLY, inst);
16414 else
16415 NEON_ENCODE (INTEGER, inst);
16416
16417 /* For polynomial encoding the U bit must be zero, and the size must
16418 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16419 obviously, as 0b10). */
16420 if (et.size == 64)
16421 {
16422 /* Check we're on the correct architecture. */
16423 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16424 inst.error =
16425 _("Instruction form not available on this architecture.");
16426
16427 et.size = 32;
16428 }
16429
16430 neon_mixed_length (et, et.size);
16431 }
16432 }
16433
16434 static void
16435 do_neon_ext (void)
16436 {
16437 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
16438 struct neon_type_el et = neon_check_type (3, rs,
16439 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16440 unsigned imm = (inst.operands[3].imm * et.size) / 8;
16441
16442 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16443 _("shift out of range"));
16444 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16445 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16446 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16447 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16448 inst.instruction |= LOW4 (inst.operands[2].reg);
16449 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16450 inst.instruction |= neon_quad (rs) << 6;
16451 inst.instruction |= imm << 8;
16452
16453 neon_dp_fixup (&inst);
16454 }
16455
16456 static void
16457 do_neon_rev (void)
16458 {
16459 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16460 struct neon_type_el et = neon_check_type (2, rs,
16461 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16462 unsigned op = (inst.instruction >> 7) & 3;
16463 /* N (width of reversed regions) is encoded as part of the bitmask. We
16464 extract it here to check the elements to be reversed are smaller.
16465 Otherwise we'd get a reserved instruction. */
16466 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
16467 gas_assert (elsize != 0);
16468 constraint (et.size >= elsize,
16469 _("elements must be smaller than reversal region"));
16470 neon_two_same (neon_quad (rs), 1, et.size);
16471 }
16472
16473 static void
16474 do_neon_dup (void)
16475 {
16476 if (inst.operands[1].isscalar)
16477 {
16478 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
16479 struct neon_type_el et = neon_check_type (2, rs,
16480 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16481 unsigned sizebits = et.size >> 3;
16482 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
16483 int logsize = neon_logbits (et.size);
16484 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
16485
16486 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
16487 return;
16488
16489 NEON_ENCODE (SCALAR, inst);
16490 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16491 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16492 inst.instruction |= LOW4 (dm);
16493 inst.instruction |= HI1 (dm) << 5;
16494 inst.instruction |= neon_quad (rs) << 6;
16495 inst.instruction |= x << 17;
16496 inst.instruction |= sizebits << 16;
16497
16498 neon_dp_fixup (&inst);
16499 }
16500 else
16501 {
16502 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16503 struct neon_type_el et = neon_check_type (2, rs,
16504 N_8 | N_16 | N_32 | N_KEY, N_EQK);
16505 /* Duplicate ARM register to lanes of vector. */
16506 NEON_ENCODE (ARMREG, inst);
16507 switch (et.size)
16508 {
16509 case 8: inst.instruction |= 0x400000; break;
16510 case 16: inst.instruction |= 0x000020; break;
16511 case 32: inst.instruction |= 0x000000; break;
16512 default: break;
16513 }
16514 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16515 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16516 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
16517 inst.instruction |= neon_quad (rs) << 21;
16518 /* The encoding for this instruction is identical for the ARM and Thumb
16519 variants, except for the condition field. */
16520 do_vfp_cond_or_thumb ();
16521 }
16522 }
16523
16524 /* VMOV has particularly many variations. It can be one of:
16525 0. VMOV<c><q> <Qd>, <Qm>
16526 1. VMOV<c><q> <Dd>, <Dm>
16527 (Register operations, which are VORR with Rm = Rn.)
16528 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16529 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16530 (Immediate loads.)
16531 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16532 (ARM register to scalar.)
16533 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16534 (Two ARM registers to vector.)
16535 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16536 (Scalar to ARM register.)
16537 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16538 (Vector to two ARM registers.)
16539 8. VMOV.F32 <Sd>, <Sm>
16540 9. VMOV.F64 <Dd>, <Dm>
16541 (VFP register moves.)
16542 10. VMOV.F32 <Sd>, #imm
16543 11. VMOV.F64 <Dd>, #imm
16544 (VFP float immediate load.)
16545 12. VMOV <Rd>, <Sm>
16546 (VFP single to ARM reg.)
16547 13. VMOV <Sd>, <Rm>
16548 (ARM reg to VFP single.)
16549 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16550 (Two ARM regs to two VFP singles.)
16551 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16552 (Two VFP singles to two ARM regs.)
16553
16554 These cases can be disambiguated using neon_select_shape, except cases 1/9
16555 and 3/11 which depend on the operand type too.
16556
16557 All the encoded bits are hardcoded by this function.
16558
16559 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16560 Cases 5, 7 may be used with VFPv2 and above.
16561
16562 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
16563 can specify a type where it doesn't make sense to, and is ignored). */
16564
16565 static void
16566 do_neon_mov (void)
16567 {
16568 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
16569 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16570 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16571 NS_HR, NS_RH, NS_HI, NS_NULL);
16572 struct neon_type_el et;
16573 const char *ldconst = 0;
16574
16575 switch (rs)
16576 {
16577 case NS_DD: /* case 1/9. */
16578 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16579 /* It is not an error here if no type is given. */
16580 inst.error = NULL;
16581 if (et.type == NT_float && et.size == 64)
16582 {
16583 do_vfp_nsyn_opcode ("fcpyd");
16584 break;
16585 }
16586 /* fall through. */
16587
16588 case NS_QQ: /* case 0/1. */
16589 {
16590 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16591 return;
16592 /* The architecture manual I have doesn't explicitly state which
16593 value the U bit should have for register->register moves, but
16594 the equivalent VORR instruction has U = 0, so do that. */
16595 inst.instruction = 0x0200110;
16596 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16597 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16598 inst.instruction |= LOW4 (inst.operands[1].reg);
16599 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16600 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16601 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16602 inst.instruction |= neon_quad (rs) << 6;
16603
16604 neon_dp_fixup (&inst);
16605 }
16606 break;
16607
16608 case NS_DI: /* case 3/11. */
16609 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16610 inst.error = NULL;
16611 if (et.type == NT_float && et.size == 64)
16612 {
16613 /* case 11 (fconstd). */
16614 ldconst = "fconstd";
16615 goto encode_fconstd;
16616 }
16617 /* fall through. */
16618
16619 case NS_QI: /* case 2/3. */
16620 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16621 return;
16622 inst.instruction = 0x0800010;
16623 neon_move_immediate ();
16624 neon_dp_fixup (&inst);
16625 break;
16626
16627 case NS_SR: /* case 4. */
16628 {
16629 unsigned bcdebits = 0;
16630 int logsize;
16631 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16632 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
16633
16634 /* .<size> is optional here, defaulting to .32. */
16635 if (inst.vectype.elems == 0
16636 && inst.operands[0].vectype.type == NT_invtype
16637 && inst.operands[1].vectype.type == NT_invtype)
16638 {
16639 inst.vectype.el[0].type = NT_untyped;
16640 inst.vectype.el[0].size = 32;
16641 inst.vectype.elems = 1;
16642 }
16643
16644 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16645 logsize = neon_logbits (et.size);
16646
16647 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16648 _(BAD_FPU));
16649 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16650 && et.size != 32, _(BAD_FPU));
16651 constraint (et.type == NT_invtype, _("bad type for scalar"));
16652 constraint (x >= 64 / et.size, _("scalar index out of range"));
16653
16654 switch (et.size)
16655 {
16656 case 8: bcdebits = 0x8; break;
16657 case 16: bcdebits = 0x1; break;
16658 case 32: bcdebits = 0x0; break;
16659 default: ;
16660 }
16661
16662 bcdebits |= x << logsize;
16663
16664 inst.instruction = 0xe000b10;
16665 do_vfp_cond_or_thumb ();
16666 inst.instruction |= LOW4 (dn) << 16;
16667 inst.instruction |= HI1 (dn) << 7;
16668 inst.instruction |= inst.operands[1].reg << 12;
16669 inst.instruction |= (bcdebits & 3) << 5;
16670 inst.instruction |= (bcdebits >> 2) << 21;
16671 }
16672 break;
16673
16674 case NS_DRR: /* case 5 (fmdrr). */
16675 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
16676 _(BAD_FPU));
16677
16678 inst.instruction = 0xc400b10;
16679 do_vfp_cond_or_thumb ();
16680 inst.instruction |= LOW4 (inst.operands[0].reg);
16681 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16682 inst.instruction |= inst.operands[1].reg << 12;
16683 inst.instruction |= inst.operands[2].reg << 16;
16684 break;
16685
16686 case NS_RS: /* case 6. */
16687 {
16688 unsigned logsize;
16689 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16690 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16691 unsigned abcdebits = 0;
16692
16693 /* .<dt> is optional here, defaulting to .32. */
16694 if (inst.vectype.elems == 0
16695 && inst.operands[0].vectype.type == NT_invtype
16696 && inst.operands[1].vectype.type == NT_invtype)
16697 {
16698 inst.vectype.el[0].type = NT_untyped;
16699 inst.vectype.el[0].size = 32;
16700 inst.vectype.elems = 1;
16701 }
16702
16703 et = neon_check_type (2, NS_NULL,
16704 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
16705 logsize = neon_logbits (et.size);
16706
16707 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16708 _(BAD_FPU));
16709 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16710 && et.size != 32, _(BAD_FPU));
16711 constraint (et.type == NT_invtype, _("bad type for scalar"));
16712 constraint (x >= 64 / et.size, _("scalar index out of range"));
16713
16714 switch (et.size)
16715 {
16716 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16717 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16718 case 32: abcdebits = 0x00; break;
16719 default: ;
16720 }
16721
16722 abcdebits |= x << logsize;
16723 inst.instruction = 0xe100b10;
16724 do_vfp_cond_or_thumb ();
16725 inst.instruction |= LOW4 (dn) << 16;
16726 inst.instruction |= HI1 (dn) << 7;
16727 inst.instruction |= inst.operands[0].reg << 12;
16728 inst.instruction |= (abcdebits & 3) << 5;
16729 inst.instruction |= (abcdebits >> 2) << 21;
16730 }
16731 break;
16732
16733 case NS_RRD: /* case 7 (fmrrd). */
16734 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
16735 _(BAD_FPU));
16736
16737 inst.instruction = 0xc500b10;
16738 do_vfp_cond_or_thumb ();
16739 inst.instruction |= inst.operands[0].reg << 12;
16740 inst.instruction |= inst.operands[1].reg << 16;
16741 inst.instruction |= LOW4 (inst.operands[2].reg);
16742 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16743 break;
16744
16745 case NS_FF: /* case 8 (fcpys). */
16746 do_vfp_nsyn_opcode ("fcpys");
16747 break;
16748
16749 case NS_HI:
16750 case NS_FI: /* case 10 (fconsts). */
16751 ldconst = "fconsts";
16752 encode_fconstd:
16753 if (!inst.operands[1].immisfloat)
16754 {
16755 unsigned new_imm;
16756 /* Immediate has to fit in 8 bits so float is enough. */
16757 float imm = (float) inst.operands[1].imm;
16758 memcpy (&new_imm, &imm, sizeof (float));
16759 /* But the assembly may have been written to provide an integer
16760 bit pattern that equates to a float, so check that the
16761 conversion has worked. */
16762 if (is_quarter_float (new_imm))
16763 {
16764 if (is_quarter_float (inst.operands[1].imm))
16765 as_warn (_("immediate constant is valid both as a bit-pattern and a floating point value (using the fp value)"));
16766
16767 inst.operands[1].imm = new_imm;
16768 inst.operands[1].immisfloat = 1;
16769 }
16770 }
16771
16772 if (is_quarter_float (inst.operands[1].imm))
16773 {
16774 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16775 do_vfp_nsyn_opcode (ldconst);
16776
16777 /* ARMv8.2 fp16 vmov.f16 instruction. */
16778 if (rs == NS_HI)
16779 do_scalar_fp16_v82_encode ();
16780 }
16781 else
16782 first_error (_("immediate out of range"));
16783 break;
16784
16785 case NS_RH:
16786 case NS_RF: /* case 12 (fmrs). */
16787 do_vfp_nsyn_opcode ("fmrs");
16788 /* ARMv8.2 fp16 vmov.f16 instruction. */
16789 if (rs == NS_RH)
16790 do_scalar_fp16_v82_encode ();
16791 break;
16792
16793 case NS_HR:
16794 case NS_FR: /* case 13 (fmsr). */
16795 do_vfp_nsyn_opcode ("fmsr");
16796 /* ARMv8.2 fp16 vmov.f16 instruction. */
16797 if (rs == NS_HR)
16798 do_scalar_fp16_v82_encode ();
16799 break;
16800
16801 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16802 (one of which is a list), but we have parsed four. Do some fiddling to
16803 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16804 expect. */
16805 case NS_RRFF: /* case 14 (fmrrs). */
16806 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
16807 _("VFP registers must be adjacent"));
16808 inst.operands[2].imm = 2;
16809 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16810 do_vfp_nsyn_opcode ("fmrrs");
16811 break;
16812
16813 case NS_FFRR: /* case 15 (fmsrr). */
16814 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
16815 _("VFP registers must be adjacent"));
16816 inst.operands[1] = inst.operands[2];
16817 inst.operands[2] = inst.operands[3];
16818 inst.operands[0].imm = 2;
16819 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16820 do_vfp_nsyn_opcode ("fmsrr");
16821 break;
16822
16823 case NS_NULL:
16824 /* neon_select_shape has determined that the instruction
16825 shape is wrong and has already set the error message. */
16826 break;
16827
16828 default:
16829 abort ();
16830 }
16831 }
16832
16833 static void
16834 do_neon_rshift_round_imm (void)
16835 {
16836 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16837 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16838 int imm = inst.operands[2].imm;
16839
16840 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16841 if (imm == 0)
16842 {
16843 inst.operands[2].present = 0;
16844 do_neon_mov ();
16845 return;
16846 }
16847
16848 constraint (imm < 1 || (unsigned)imm > et.size,
16849 _("immediate out of range for shift"));
16850 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
16851 et.size - imm);
16852 }
16853
16854 static void
16855 do_neon_movhf (void)
16856 {
16857 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16858 constraint (rs != NS_HH, _("invalid suffix"));
16859
16860 if (inst.cond != COND_ALWAYS)
16861 {
16862 if (thumb_mode)
16863 {
16864 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
16865 " the behaviour is UNPREDICTABLE"));
16866 }
16867 else
16868 {
16869 inst.error = BAD_COND;
16870 return;
16871 }
16872 }
16873
16874 do_vfp_sp_monadic ();
16875
16876 inst.is_neon = 1;
16877 inst.instruction |= 0xf0000000;
16878 }
16879
16880 static void
16881 do_neon_movl (void)
16882 {
16883 struct neon_type_el et = neon_check_type (2, NS_QD,
16884 N_EQK | N_DBL, N_SU_32 | N_KEY);
16885 unsigned sizebits = et.size >> 3;
16886 inst.instruction |= sizebits << 19;
16887 neon_two_same (0, et.type == NT_unsigned, -1);
16888 }
16889
16890 static void
16891 do_neon_trn (void)
16892 {
16893 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16894 struct neon_type_el et = neon_check_type (2, rs,
16895 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16896 NEON_ENCODE (INTEGER, inst);
16897 neon_two_same (neon_quad (rs), 1, et.size);
16898 }
16899
16900 static void
16901 do_neon_zip_uzp (void)
16902 {
16903 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16904 struct neon_type_el et = neon_check_type (2, rs,
16905 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16906 if (rs == NS_DD && et.size == 32)
16907 {
16908 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16909 inst.instruction = N_MNEM_vtrn;
16910 do_neon_trn ();
16911 return;
16912 }
16913 neon_two_same (neon_quad (rs), 1, et.size);
16914 }
16915
16916 static void
16917 do_neon_sat_abs_neg (void)
16918 {
16919 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16920 struct neon_type_el et = neon_check_type (2, rs,
16921 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
16922 neon_two_same (neon_quad (rs), 1, et.size);
16923 }
16924
16925 static void
16926 do_neon_pair_long (void)
16927 {
16928 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16929 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16930 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16931 inst.instruction |= (et.type == NT_unsigned) << 7;
16932 neon_two_same (neon_quad (rs), 1, et.size);
16933 }
16934
16935 static void
16936 do_neon_recip_est (void)
16937 {
16938 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16939 struct neon_type_el et = neon_check_type (2, rs,
16940 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
16941 inst.instruction |= (et.type == NT_float) << 8;
16942 neon_two_same (neon_quad (rs), 1, et.size);
16943 }
16944
16945 static void
16946 do_neon_cls (void)
16947 {
16948 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16949 struct neon_type_el et = neon_check_type (2, rs,
16950 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
16951 neon_two_same (neon_quad (rs), 1, et.size);
16952 }
16953
16954 static void
16955 do_neon_clz (void)
16956 {
16957 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16958 struct neon_type_el et = neon_check_type (2, rs,
16959 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
16960 neon_two_same (neon_quad (rs), 1, et.size);
16961 }
16962
16963 static void
16964 do_neon_cnt (void)
16965 {
16966 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16967 struct neon_type_el et = neon_check_type (2, rs,
16968 N_EQK | N_INT, N_8 | N_KEY);
16969 neon_two_same (neon_quad (rs), 1, et.size);
16970 }
16971
16972 static void
16973 do_neon_swp (void)
16974 {
16975 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16976 neon_two_same (neon_quad (rs), 1, -1);
16977 }
16978
16979 static void
16980 do_neon_tbl_tbx (void)
16981 {
16982 unsigned listlenbits;
16983 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
16984
16985 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16986 {
16987 first_error (_("bad list length for table lookup"));
16988 return;
16989 }
16990
16991 listlenbits = inst.operands[1].imm - 1;
16992 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16993 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16994 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16995 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16996 inst.instruction |= LOW4 (inst.operands[2].reg);
16997 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16998 inst.instruction |= listlenbits << 8;
16999
17000 neon_dp_fixup (&inst);
17001 }
17002
17003 static void
17004 do_neon_ldm_stm (void)
17005 {
17006 /* P, U and L bits are part of bitmask. */
17007 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
17008 unsigned offsetbits = inst.operands[1].imm * 2;
17009
17010 if (inst.operands[1].issingle)
17011 {
17012 do_vfp_nsyn_ldm_stm (is_dbmode);
17013 return;
17014 }
17015
17016 constraint (is_dbmode && !inst.operands[0].writeback,
17017 _("writeback (!) must be used for VLDMDB and VSTMDB"));
17018
17019 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
17020 _("register list must contain at least 1 and at most 16 "
17021 "registers"));
17022
17023 inst.instruction |= inst.operands[0].reg << 16;
17024 inst.instruction |= inst.operands[0].writeback << 21;
17025 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
17026 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
17027
17028 inst.instruction |= offsetbits;
17029
17030 do_vfp_cond_or_thumb ();
17031 }
17032
17033 static void
17034 do_neon_ldr_str (void)
17035 {
17036 int is_ldr = (inst.instruction & (1 << 20)) != 0;
17037
17038 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
17039 And is UNPREDICTABLE in thumb mode. */
17040 if (!is_ldr
17041 && inst.operands[1].reg == REG_PC
17042 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
17043 {
17044 if (thumb_mode)
17045 inst.error = _("Use of PC here is UNPREDICTABLE");
17046 else if (warn_on_deprecated)
17047 as_tsktsk (_("Use of PC here is deprecated"));
17048 }
17049
17050 if (inst.operands[0].issingle)
17051 {
17052 if (is_ldr)
17053 do_vfp_nsyn_opcode ("flds");
17054 else
17055 do_vfp_nsyn_opcode ("fsts");
17056
17057 /* ARMv8.2 vldr.16/vstr.16 instruction. */
17058 if (inst.vectype.el[0].size == 16)
17059 do_scalar_fp16_v82_encode ();
17060 }
17061 else
17062 {
17063 if (is_ldr)
17064 do_vfp_nsyn_opcode ("fldd");
17065 else
17066 do_vfp_nsyn_opcode ("fstd");
17067 }
17068 }
17069
17070 /* "interleave" version also handles non-interleaving register VLD1/VST1
17071 instructions. */
17072
17073 static void
17074 do_neon_ld_st_interleave (void)
17075 {
17076 struct neon_type_el et = neon_check_type (1, NS_NULL,
17077 N_8 | N_16 | N_32 | N_64);
17078 unsigned alignbits = 0;
17079 unsigned idx;
17080 /* The bits in this table go:
17081 0: register stride of one (0) or two (1)
17082 1,2: register list length, minus one (1, 2, 3, 4).
17083 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17084 We use -1 for invalid entries. */
17085 const int typetable[] =
17086 {
17087 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17088 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17089 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17090 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17091 };
17092 int typebits;
17093
17094 if (et.type == NT_invtype)
17095 return;
17096
17097 if (inst.operands[1].immisalign)
17098 switch (inst.operands[1].imm >> 8)
17099 {
17100 case 64: alignbits = 1; break;
17101 case 128:
17102 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
17103 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17104 goto bad_alignment;
17105 alignbits = 2;
17106 break;
17107 case 256:
17108 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17109 goto bad_alignment;
17110 alignbits = 3;
17111 break;
17112 default:
17113 bad_alignment:
17114 first_error (_("bad alignment"));
17115 return;
17116 }
17117
17118 inst.instruction |= alignbits << 4;
17119 inst.instruction |= neon_logbits (et.size) << 6;
17120
17121 /* Bits [4:6] of the immediate in a list specifier encode register stride
17122 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17123 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17124 up the right value for "type" in a table based on this value and the given
17125 list style, then stick it back. */
17126 idx = ((inst.operands[0].imm >> 4) & 7)
17127 | (((inst.instruction >> 8) & 3) << 3);
17128
17129 typebits = typetable[idx];
17130
17131 constraint (typebits == -1, _("bad list type for instruction"));
17132 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17133 _("bad element type for instruction"));
17134
17135 inst.instruction &= ~0xf00;
17136 inst.instruction |= typebits << 8;
17137 }
17138
17139 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17140 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17141 otherwise. The variable arguments are a list of pairs of legal (size, align)
17142 values, terminated with -1. */
17143
17144 static int
17145 neon_alignment_bit (int size, int align, int *do_alignment, ...)
17146 {
17147 va_list ap;
17148 int result = FAIL, thissize, thisalign;
17149
17150 if (!inst.operands[1].immisalign)
17151 {
17152 *do_alignment = 0;
17153 return SUCCESS;
17154 }
17155
17156 va_start (ap, do_alignment);
17157
17158 do
17159 {
17160 thissize = va_arg (ap, int);
17161 if (thissize == -1)
17162 break;
17163 thisalign = va_arg (ap, int);
17164
17165 if (size == thissize && align == thisalign)
17166 result = SUCCESS;
17167 }
17168 while (result != SUCCESS);
17169
17170 va_end (ap);
17171
17172 if (result == SUCCESS)
17173 *do_alignment = 1;
17174 else
17175 first_error (_("unsupported alignment for instruction"));
17176
17177 return result;
17178 }
17179
17180 static void
17181 do_neon_ld_st_lane (void)
17182 {
17183 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
17184 int align_good, do_alignment = 0;
17185 int logsize = neon_logbits (et.size);
17186 int align = inst.operands[1].imm >> 8;
17187 int n = (inst.instruction >> 8) & 3;
17188 int max_el = 64 / et.size;
17189
17190 if (et.type == NT_invtype)
17191 return;
17192
17193 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
17194 _("bad list length"));
17195 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
17196 _("scalar index out of range"));
17197 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
17198 && et.size == 8,
17199 _("stride of 2 unavailable when element size is 8"));
17200
17201 switch (n)
17202 {
17203 case 0: /* VLD1 / VST1. */
17204 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
17205 32, 32, -1);
17206 if (align_good == FAIL)
17207 return;
17208 if (do_alignment)
17209 {
17210 unsigned alignbits = 0;
17211 switch (et.size)
17212 {
17213 case 16: alignbits = 0x1; break;
17214 case 32: alignbits = 0x3; break;
17215 default: ;
17216 }
17217 inst.instruction |= alignbits << 4;
17218 }
17219 break;
17220
17221 case 1: /* VLD2 / VST2. */
17222 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17223 16, 32, 32, 64, -1);
17224 if (align_good == FAIL)
17225 return;
17226 if (do_alignment)
17227 inst.instruction |= 1 << 4;
17228 break;
17229
17230 case 2: /* VLD3 / VST3. */
17231 constraint (inst.operands[1].immisalign,
17232 _("can't use alignment with this instruction"));
17233 break;
17234
17235 case 3: /* VLD4 / VST4. */
17236 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
17237 16, 64, 32, 64, 32, 128, -1);
17238 if (align_good == FAIL)
17239 return;
17240 if (do_alignment)
17241 {
17242 unsigned alignbits = 0;
17243 switch (et.size)
17244 {
17245 case 8: alignbits = 0x1; break;
17246 case 16: alignbits = 0x1; break;
17247 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17248 default: ;
17249 }
17250 inst.instruction |= alignbits << 4;
17251 }
17252 break;
17253
17254 default: ;
17255 }
17256
17257 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17258 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17259 inst.instruction |= 1 << (4 + logsize);
17260
17261 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17262 inst.instruction |= logsize << 10;
17263 }
17264
17265 /* Encode single n-element structure to all lanes VLD<n> instructions. */
17266
17267 static void
17268 do_neon_ld_dup (void)
17269 {
17270 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
17271 int align_good, do_alignment = 0;
17272
17273 if (et.type == NT_invtype)
17274 return;
17275
17276 switch ((inst.instruction >> 8) & 3)
17277 {
17278 case 0: /* VLD1. */
17279 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
17280 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
17281 &do_alignment, 16, 16, 32, 32, -1);
17282 if (align_good == FAIL)
17283 return;
17284 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
17285 {
17286 case 1: break;
17287 case 2: inst.instruction |= 1 << 5; break;
17288 default: first_error (_("bad list length")); return;
17289 }
17290 inst.instruction |= neon_logbits (et.size) << 6;
17291 break;
17292
17293 case 1: /* VLD2. */
17294 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
17295 &do_alignment, 8, 16, 16, 32, 32, 64,
17296 -1);
17297 if (align_good == FAIL)
17298 return;
17299 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
17300 _("bad list length"));
17301 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17302 inst.instruction |= 1 << 5;
17303 inst.instruction |= neon_logbits (et.size) << 6;
17304 break;
17305
17306 case 2: /* VLD3. */
17307 constraint (inst.operands[1].immisalign,
17308 _("can't use alignment with this instruction"));
17309 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
17310 _("bad list length"));
17311 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17312 inst.instruction |= 1 << 5;
17313 inst.instruction |= neon_logbits (et.size) << 6;
17314 break;
17315
17316 case 3: /* VLD4. */
17317 {
17318 int align = inst.operands[1].imm >> 8;
17319 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
17320 16, 64, 32, 64, 32, 128, -1);
17321 if (align_good == FAIL)
17322 return;
17323 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17324 _("bad list length"));
17325 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17326 inst.instruction |= 1 << 5;
17327 if (et.size == 32 && align == 128)
17328 inst.instruction |= 0x3 << 6;
17329 else
17330 inst.instruction |= neon_logbits (et.size) << 6;
17331 }
17332 break;
17333
17334 default: ;
17335 }
17336
17337 inst.instruction |= do_alignment << 4;
17338 }
17339
17340 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17341 apart from bits [11:4]. */
17342
17343 static void
17344 do_neon_ldx_stx (void)
17345 {
17346 if (inst.operands[1].isreg)
17347 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17348
17349 switch (NEON_LANE (inst.operands[0].imm))
17350 {
17351 case NEON_INTERLEAVE_LANES:
17352 NEON_ENCODE (INTERLV, inst);
17353 do_neon_ld_st_interleave ();
17354 break;
17355
17356 case NEON_ALL_LANES:
17357 NEON_ENCODE (DUP, inst);
17358 if (inst.instruction == N_INV)
17359 {
17360 first_error ("only loads support such operands");
17361 break;
17362 }
17363 do_neon_ld_dup ();
17364 break;
17365
17366 default:
17367 NEON_ENCODE (LANE, inst);
17368 do_neon_ld_st_lane ();
17369 }
17370
17371 /* L bit comes from bit mask. */
17372 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17373 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17374 inst.instruction |= inst.operands[1].reg << 16;
17375
17376 if (inst.operands[1].postind)
17377 {
17378 int postreg = inst.operands[1].imm & 0xf;
17379 constraint (!inst.operands[1].immisreg,
17380 _("post-index must be a register"));
17381 constraint (postreg == 0xd || postreg == 0xf,
17382 _("bad register for post-index"));
17383 inst.instruction |= postreg;
17384 }
17385 else
17386 {
17387 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17388 constraint (inst.relocs[0].exp.X_op != O_constant
17389 || inst.relocs[0].exp.X_add_number != 0,
17390 BAD_ADDR_MODE);
17391
17392 if (inst.operands[1].writeback)
17393 {
17394 inst.instruction |= 0xd;
17395 }
17396 else
17397 inst.instruction |= 0xf;
17398 }
17399
17400 if (thumb_mode)
17401 inst.instruction |= 0xf9000000;
17402 else
17403 inst.instruction |= 0xf4000000;
17404 }
17405
17406 /* FP v8. */
17407 static void
17408 do_vfp_nsyn_fpv8 (enum neon_shape rs)
17409 {
17410 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17411 D register operands. */
17412 if (neon_shape_class[rs] == SC_DOUBLE)
17413 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17414 _(BAD_FPU));
17415
17416 NEON_ENCODE (FPV8, inst);
17417
17418 if (rs == NS_FFF || rs == NS_HHH)
17419 {
17420 do_vfp_sp_dyadic ();
17421
17422 /* ARMv8.2 fp16 instruction. */
17423 if (rs == NS_HHH)
17424 do_scalar_fp16_v82_encode ();
17425 }
17426 else
17427 do_vfp_dp_rd_rn_rm ();
17428
17429 if (rs == NS_DDD)
17430 inst.instruction |= 0x100;
17431
17432 inst.instruction |= 0xf0000000;
17433 }
17434
17435 static void
17436 do_vsel (void)
17437 {
17438 set_it_insn_type (OUTSIDE_IT_INSN);
17439
17440 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17441 first_error (_("invalid instruction shape"));
17442 }
17443
17444 static void
17445 do_vmaxnm (void)
17446 {
17447 set_it_insn_type (OUTSIDE_IT_INSN);
17448
17449 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17450 return;
17451
17452 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17453 return;
17454
17455 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
17456 }
17457
17458 static void
17459 do_vrint_1 (enum neon_cvt_mode mode)
17460 {
17461 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
17462 struct neon_type_el et;
17463
17464 if (rs == NS_NULL)
17465 return;
17466
17467 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17468 D register operands. */
17469 if (neon_shape_class[rs] == SC_DOUBLE)
17470 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17471 _(BAD_FPU));
17472
17473 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17474 | N_VFP);
17475 if (et.type != NT_invtype)
17476 {
17477 /* VFP encodings. */
17478 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17479 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17480 set_it_insn_type (OUTSIDE_IT_INSN);
17481
17482 NEON_ENCODE (FPV8, inst);
17483 if (rs == NS_FF || rs == NS_HH)
17484 do_vfp_sp_monadic ();
17485 else
17486 do_vfp_dp_rd_rm ();
17487
17488 switch (mode)
17489 {
17490 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17491 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17492 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17493 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17494 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17495 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17496 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17497 default: abort ();
17498 }
17499
17500 inst.instruction |= (rs == NS_DD) << 8;
17501 do_vfp_cond_or_thumb ();
17502
17503 /* ARMv8.2 fp16 vrint instruction. */
17504 if (rs == NS_HH)
17505 do_scalar_fp16_v82_encode ();
17506 }
17507 else
17508 {
17509 /* Neon encodings (or something broken...). */
17510 inst.error = NULL;
17511 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
17512
17513 if (et.type == NT_invtype)
17514 return;
17515
17516 set_it_insn_type (OUTSIDE_IT_INSN);
17517 NEON_ENCODE (FLOAT, inst);
17518
17519 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17520 return;
17521
17522 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17523 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17524 inst.instruction |= LOW4 (inst.operands[1].reg);
17525 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17526 inst.instruction |= neon_quad (rs) << 6;
17527 /* Mask off the original size bits and reencode them. */
17528 inst.instruction = ((inst.instruction & 0xfff3ffff)
17529 | neon_logbits (et.size) << 18);
17530
17531 switch (mode)
17532 {
17533 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17534 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17535 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17536 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17537 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17538 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17539 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17540 default: abort ();
17541 }
17542
17543 if (thumb_mode)
17544 inst.instruction |= 0xfc000000;
17545 else
17546 inst.instruction |= 0xf0000000;
17547 }
17548 }
17549
17550 static void
17551 do_vrintx (void)
17552 {
17553 do_vrint_1 (neon_cvt_mode_x);
17554 }
17555
17556 static void
17557 do_vrintz (void)
17558 {
17559 do_vrint_1 (neon_cvt_mode_z);
17560 }
17561
17562 static void
17563 do_vrintr (void)
17564 {
17565 do_vrint_1 (neon_cvt_mode_r);
17566 }
17567
17568 static void
17569 do_vrinta (void)
17570 {
17571 do_vrint_1 (neon_cvt_mode_a);
17572 }
17573
17574 static void
17575 do_vrintn (void)
17576 {
17577 do_vrint_1 (neon_cvt_mode_n);
17578 }
17579
17580 static void
17581 do_vrintp (void)
17582 {
17583 do_vrint_1 (neon_cvt_mode_p);
17584 }
17585
17586 static void
17587 do_vrintm (void)
17588 {
17589 do_vrint_1 (neon_cvt_mode_m);
17590 }
17591
17592 static unsigned
17593 neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17594 {
17595 unsigned regno = NEON_SCALAR_REG (opnd);
17596 unsigned elno = NEON_SCALAR_INDEX (opnd);
17597
17598 if (elsize == 16 && elno < 2 && regno < 16)
17599 return regno | (elno << 4);
17600 else if (elsize == 32 && elno == 0)
17601 return regno;
17602
17603 first_error (_("scalar out of range"));
17604 return 0;
17605 }
17606
17607 static void
17608 do_vcmla (void)
17609 {
17610 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17611 _(BAD_FPU));
17612 constraint (inst.relocs[0].exp.X_op != O_constant,
17613 _("expression too complex"));
17614 unsigned rot = inst.relocs[0].exp.X_add_number;
17615 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17616 _("immediate out of range"));
17617 rot /= 90;
17618 if (inst.operands[2].isscalar)
17619 {
17620 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17621 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17622 N_KEY | N_F16 | N_F32).size;
17623 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17624 inst.is_neon = 1;
17625 inst.instruction = 0xfe000800;
17626 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17627 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17628 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17629 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17630 inst.instruction |= LOW4 (m);
17631 inst.instruction |= HI1 (m) << 5;
17632 inst.instruction |= neon_quad (rs) << 6;
17633 inst.instruction |= rot << 20;
17634 inst.instruction |= (size == 32) << 23;
17635 }
17636 else
17637 {
17638 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17639 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17640 N_KEY | N_F16 | N_F32).size;
17641 neon_three_same (neon_quad (rs), 0, -1);
17642 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17643 inst.instruction |= 0xfc200800;
17644 inst.instruction |= rot << 23;
17645 inst.instruction |= (size == 32) << 20;
17646 }
17647 }
17648
17649 static void
17650 do_vcadd (void)
17651 {
17652 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17653 _(BAD_FPU));
17654 constraint (inst.relocs[0].exp.X_op != O_constant,
17655 _("expression too complex"));
17656 unsigned rot = inst.relocs[0].exp.X_add_number;
17657 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17658 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17659 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17660 N_KEY | N_F16 | N_F32).size;
17661 neon_three_same (neon_quad (rs), 0, -1);
17662 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17663 inst.instruction |= 0xfc800800;
17664 inst.instruction |= (rot == 270) << 24;
17665 inst.instruction |= (size == 32) << 20;
17666 }
17667
17668 /* Dot Product instructions encoding support. */
17669
17670 static void
17671 do_neon_dotproduct (int unsigned_p)
17672 {
17673 enum neon_shape rs;
17674 unsigned scalar_oprd2 = 0;
17675 int high8;
17676
17677 if (inst.cond != COND_ALWAYS)
17678 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17679 "is UNPREDICTABLE"));
17680
17681 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17682 _(BAD_FPU));
17683
17684 /* Dot Product instructions are in three-same D/Q register format or the third
17685 operand can be a scalar index register. */
17686 if (inst.operands[2].isscalar)
17687 {
17688 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17689 high8 = 0xfe000000;
17690 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17691 }
17692 else
17693 {
17694 high8 = 0xfc000000;
17695 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17696 }
17697
17698 if (unsigned_p)
17699 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17700 else
17701 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17702
17703 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17704 Product instruction, so we pass 0 as the "ubit" parameter. And the
17705 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17706 neon_three_same (neon_quad (rs), 0, 32);
17707
17708 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17709 different NEON three-same encoding. */
17710 inst.instruction &= 0x00ffffff;
17711 inst.instruction |= high8;
17712 /* Encode 'U' bit which indicates signedness. */
17713 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17714 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17715 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17716 the instruction encoding. */
17717 if (inst.operands[2].isscalar)
17718 {
17719 inst.instruction &= 0xffffffd0;
17720 inst.instruction |= LOW4 (scalar_oprd2);
17721 inst.instruction |= HI1 (scalar_oprd2) << 5;
17722 }
17723 }
17724
17725 /* Dot Product instructions for signed integer. */
17726
17727 static void
17728 do_neon_dotproduct_s (void)
17729 {
17730 return do_neon_dotproduct (0);
17731 }
17732
17733 /* Dot Product instructions for unsigned integer. */
17734
17735 static void
17736 do_neon_dotproduct_u (void)
17737 {
17738 return do_neon_dotproduct (1);
17739 }
17740
17741 /* Crypto v1 instructions. */
17742 static void
17743 do_crypto_2op_1 (unsigned elttype, int op)
17744 {
17745 set_it_insn_type (OUTSIDE_IT_INSN);
17746
17747 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17748 == NT_invtype)
17749 return;
17750
17751 inst.error = NULL;
17752
17753 NEON_ENCODE (INTEGER, inst);
17754 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17755 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17756 inst.instruction |= LOW4 (inst.operands[1].reg);
17757 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17758 if (op != -1)
17759 inst.instruction |= op << 6;
17760
17761 if (thumb_mode)
17762 inst.instruction |= 0xfc000000;
17763 else
17764 inst.instruction |= 0xf0000000;
17765 }
17766
17767 static void
17768 do_crypto_3op_1 (int u, int op)
17769 {
17770 set_it_insn_type (OUTSIDE_IT_INSN);
17771
17772 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17773 N_32 | N_UNT | N_KEY).type == NT_invtype)
17774 return;
17775
17776 inst.error = NULL;
17777
17778 NEON_ENCODE (INTEGER, inst);
17779 neon_three_same (1, u, 8 << op);
17780 }
17781
17782 static void
17783 do_aese (void)
17784 {
17785 do_crypto_2op_1 (N_8, 0);
17786 }
17787
17788 static void
17789 do_aesd (void)
17790 {
17791 do_crypto_2op_1 (N_8, 1);
17792 }
17793
17794 static void
17795 do_aesmc (void)
17796 {
17797 do_crypto_2op_1 (N_8, 2);
17798 }
17799
17800 static void
17801 do_aesimc (void)
17802 {
17803 do_crypto_2op_1 (N_8, 3);
17804 }
17805
17806 static void
17807 do_sha1c (void)
17808 {
17809 do_crypto_3op_1 (0, 0);
17810 }
17811
17812 static void
17813 do_sha1p (void)
17814 {
17815 do_crypto_3op_1 (0, 1);
17816 }
17817
17818 static void
17819 do_sha1m (void)
17820 {
17821 do_crypto_3op_1 (0, 2);
17822 }
17823
17824 static void
17825 do_sha1su0 (void)
17826 {
17827 do_crypto_3op_1 (0, 3);
17828 }
17829
17830 static void
17831 do_sha256h (void)
17832 {
17833 do_crypto_3op_1 (1, 0);
17834 }
17835
17836 static void
17837 do_sha256h2 (void)
17838 {
17839 do_crypto_3op_1 (1, 1);
17840 }
17841
17842 static void
17843 do_sha256su1 (void)
17844 {
17845 do_crypto_3op_1 (1, 2);
17846 }
17847
17848 static void
17849 do_sha1h (void)
17850 {
17851 do_crypto_2op_1 (N_32, -1);
17852 }
17853
17854 static void
17855 do_sha1su1 (void)
17856 {
17857 do_crypto_2op_1 (N_32, 0);
17858 }
17859
17860 static void
17861 do_sha256su0 (void)
17862 {
17863 do_crypto_2op_1 (N_32, 1);
17864 }
17865
17866 static void
17867 do_crc32_1 (unsigned int poly, unsigned int sz)
17868 {
17869 unsigned int Rd = inst.operands[0].reg;
17870 unsigned int Rn = inst.operands[1].reg;
17871 unsigned int Rm = inst.operands[2].reg;
17872
17873 set_it_insn_type (OUTSIDE_IT_INSN);
17874 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17875 inst.instruction |= LOW4 (Rn) << 16;
17876 inst.instruction |= LOW4 (Rm);
17877 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17878 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17879
17880 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17881 as_warn (UNPRED_REG ("r15"));
17882 }
17883
17884 static void
17885 do_crc32b (void)
17886 {
17887 do_crc32_1 (0, 0);
17888 }
17889
17890 static void
17891 do_crc32h (void)
17892 {
17893 do_crc32_1 (0, 1);
17894 }
17895
17896 static void
17897 do_crc32w (void)
17898 {
17899 do_crc32_1 (0, 2);
17900 }
17901
17902 static void
17903 do_crc32cb (void)
17904 {
17905 do_crc32_1 (1, 0);
17906 }
17907
17908 static void
17909 do_crc32ch (void)
17910 {
17911 do_crc32_1 (1, 1);
17912 }
17913
17914 static void
17915 do_crc32cw (void)
17916 {
17917 do_crc32_1 (1, 2);
17918 }
17919
17920 static void
17921 do_vjcvt (void)
17922 {
17923 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17924 _(BAD_FPU));
17925 neon_check_type (2, NS_FD, N_S32, N_F64);
17926 do_vfp_sp_dp_cvt ();
17927 do_vfp_cond_or_thumb ();
17928 }
17929
17930 \f
17931 /* Overall per-instruction processing. */
17932
17933 /* We need to be able to fix up arbitrary expressions in some statements.
17934 This is so that we can handle symbols that are an arbitrary distance from
17935 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17936 which returns part of an address in a form which will be valid for
17937 a data instruction. We do this by pushing the expression into a symbol
17938 in the expr_section, and creating a fix for that. */
17939
17940 static void
17941 fix_new_arm (fragS * frag,
17942 int where,
17943 short int size,
17944 expressionS * exp,
17945 int pc_rel,
17946 int reloc)
17947 {
17948 fixS * new_fix;
17949
17950 switch (exp->X_op)
17951 {
17952 case O_constant:
17953 if (pc_rel)
17954 {
17955 /* Create an absolute valued symbol, so we have something to
17956 refer to in the object file. Unfortunately for us, gas's
17957 generic expression parsing will already have folded out
17958 any use of .set foo/.type foo %function that may have
17959 been used to set type information of the target location,
17960 that's being specified symbolically. We have to presume
17961 the user knows what they are doing. */
17962 char name[16 + 8];
17963 symbolS *symbol;
17964
17965 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17966
17967 symbol = symbol_find_or_make (name);
17968 S_SET_SEGMENT (symbol, absolute_section);
17969 symbol_set_frag (symbol, &zero_address_frag);
17970 S_SET_VALUE (symbol, exp->X_add_number);
17971 exp->X_op = O_symbol;
17972 exp->X_add_symbol = symbol;
17973 exp->X_add_number = 0;
17974 }
17975 /* FALLTHROUGH */
17976 case O_symbol:
17977 case O_add:
17978 case O_subtract:
17979 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
17980 (enum bfd_reloc_code_real) reloc);
17981 break;
17982
17983 default:
17984 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
17985 pc_rel, (enum bfd_reloc_code_real) reloc);
17986 break;
17987 }
17988
17989 /* Mark whether the fix is to a THUMB instruction, or an ARM
17990 instruction. */
17991 new_fix->tc_fix_data = thumb_mode;
17992 }
17993
17994 /* Create a frg for an instruction requiring relaxation. */
17995 static void
17996 output_relax_insn (void)
17997 {
17998 char * to;
17999 symbolS *sym;
18000 int offset;
18001
18002 /* The size of the instruction is unknown, so tie the debug info to the
18003 start of the instruction. */
18004 dwarf2_emit_insn (0);
18005
18006 switch (inst.relocs[0].exp.X_op)
18007 {
18008 case O_symbol:
18009 sym = inst.relocs[0].exp.X_add_symbol;
18010 offset = inst.relocs[0].exp.X_add_number;
18011 break;
18012 case O_constant:
18013 sym = NULL;
18014 offset = inst.relocs[0].exp.X_add_number;
18015 break;
18016 default:
18017 sym = make_expr_symbol (&inst.relocs[0].exp);
18018 offset = 0;
18019 break;
18020 }
18021 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
18022 inst.relax, sym, offset, NULL/*offset, opcode*/);
18023 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
18024 }
18025
18026 /* Write a 32-bit thumb instruction to buf. */
18027 static void
18028 put_thumb32_insn (char * buf, unsigned long insn)
18029 {
18030 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
18031 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
18032 }
18033
18034 static void
18035 output_inst (const char * str)
18036 {
18037 char * to = NULL;
18038
18039 if (inst.error)
18040 {
18041 as_bad ("%s -- `%s'", inst.error, str);
18042 return;
18043 }
18044 if (inst.relax)
18045 {
18046 output_relax_insn ();
18047 return;
18048 }
18049 if (inst.size == 0)
18050 return;
18051
18052 to = frag_more (inst.size);
18053 /* PR 9814: Record the thumb mode into the current frag so that we know
18054 what type of NOP padding to use, if necessary. We override any previous
18055 setting so that if the mode has changed then the NOPS that we use will
18056 match the encoding of the last instruction in the frag. */
18057 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18058
18059 if (thumb_mode && (inst.size > THUMB_SIZE))
18060 {
18061 gas_assert (inst.size == (2 * THUMB_SIZE));
18062 put_thumb32_insn (to, inst.instruction);
18063 }
18064 else if (inst.size > INSN_SIZE)
18065 {
18066 gas_assert (inst.size == (2 * INSN_SIZE));
18067 md_number_to_chars (to, inst.instruction, INSN_SIZE);
18068 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
18069 }
18070 else
18071 md_number_to_chars (to, inst.instruction, inst.size);
18072
18073 int r;
18074 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18075 {
18076 if (inst.relocs[r].type != BFD_RELOC_UNUSED)
18077 fix_new_arm (frag_now, to - frag_now->fr_literal,
18078 inst.size, & inst.relocs[r].exp, inst.relocs[r].pc_rel,
18079 inst.relocs[r].type);
18080 }
18081
18082 dwarf2_emit_insn (inst.size);
18083 }
18084
18085 static char *
18086 output_it_inst (int cond, int mask, char * to)
18087 {
18088 unsigned long instruction = 0xbf00;
18089
18090 mask &= 0xf;
18091 instruction |= mask;
18092 instruction |= cond << 4;
18093
18094 if (to == NULL)
18095 {
18096 to = frag_more (2);
18097 #ifdef OBJ_ELF
18098 dwarf2_emit_insn (2);
18099 #endif
18100 }
18101
18102 md_number_to_chars (to, instruction, 2);
18103
18104 return to;
18105 }
18106
18107 /* Tag values used in struct asm_opcode's tag field. */
18108 enum opcode_tag
18109 {
18110 OT_unconditional, /* Instruction cannot be conditionalized.
18111 The ARM condition field is still 0xE. */
18112 OT_unconditionalF, /* Instruction cannot be conditionalized
18113 and carries 0xF in its ARM condition field. */
18114 OT_csuffix, /* Instruction takes a conditional suffix. */
18115 OT_csuffixF, /* Some forms of the instruction take a conditional
18116 suffix, others place 0xF where the condition field
18117 would be. */
18118 OT_cinfix3, /* Instruction takes a conditional infix,
18119 beginning at character index 3. (In
18120 unified mode, it becomes a suffix.) */
18121 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18122 tsts, cmps, cmns, and teqs. */
18123 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18124 character index 3, even in unified mode. Used for
18125 legacy instructions where suffix and infix forms
18126 may be ambiguous. */
18127 OT_csuf_or_in3, /* Instruction takes either a conditional
18128 suffix or an infix at character index 3. */
18129 OT_odd_infix_unc, /* This is the unconditional variant of an
18130 instruction that takes a conditional infix
18131 at an unusual position. In unified mode,
18132 this variant will accept a suffix. */
18133 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18134 are the conditional variants of instructions that
18135 take conditional infixes in unusual positions.
18136 The infix appears at character index
18137 (tag - OT_odd_infix_0). These are not accepted
18138 in unified mode. */
18139 };
18140
18141 /* Subroutine of md_assemble, responsible for looking up the primary
18142 opcode from the mnemonic the user wrote. STR points to the
18143 beginning of the mnemonic.
18144
18145 This is not simply a hash table lookup, because of conditional
18146 variants. Most instructions have conditional variants, which are
18147 expressed with a _conditional affix_ to the mnemonic. If we were
18148 to encode each conditional variant as a literal string in the opcode
18149 table, it would have approximately 20,000 entries.
18150
18151 Most mnemonics take this affix as a suffix, and in unified syntax,
18152 'most' is upgraded to 'all'. However, in the divided syntax, some
18153 instructions take the affix as an infix, notably the s-variants of
18154 the arithmetic instructions. Of those instructions, all but six
18155 have the infix appear after the third character of the mnemonic.
18156
18157 Accordingly, the algorithm for looking up primary opcodes given
18158 an identifier is:
18159
18160 1. Look up the identifier in the opcode table.
18161 If we find a match, go to step U.
18162
18163 2. Look up the last two characters of the identifier in the
18164 conditions table. If we find a match, look up the first N-2
18165 characters of the identifier in the opcode table. If we
18166 find a match, go to step CE.
18167
18168 3. Look up the fourth and fifth characters of the identifier in
18169 the conditions table. If we find a match, extract those
18170 characters from the identifier, and look up the remaining
18171 characters in the opcode table. If we find a match, go
18172 to step CM.
18173
18174 4. Fail.
18175
18176 U. Examine the tag field of the opcode structure, in case this is
18177 one of the six instructions with its conditional infix in an
18178 unusual place. If it is, the tag tells us where to find the
18179 infix; look it up in the conditions table and set inst.cond
18180 accordingly. Otherwise, this is an unconditional instruction.
18181 Again set inst.cond accordingly. Return the opcode structure.
18182
18183 CE. Examine the tag field to make sure this is an instruction that
18184 should receive a conditional suffix. If it is not, fail.
18185 Otherwise, set inst.cond from the suffix we already looked up,
18186 and return the opcode structure.
18187
18188 CM. Examine the tag field to make sure this is an instruction that
18189 should receive a conditional infix after the third character.
18190 If it is not, fail. Otherwise, undo the edits to the current
18191 line of input and proceed as for case CE. */
18192
18193 static const struct asm_opcode *
18194 opcode_lookup (char **str)
18195 {
18196 char *end, *base;
18197 char *affix;
18198 const struct asm_opcode *opcode;
18199 const struct asm_cond *cond;
18200 char save[2];
18201
18202 /* Scan up to the end of the mnemonic, which must end in white space,
18203 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
18204 for (base = end = *str; *end != '\0'; end++)
18205 if (*end == ' ' || *end == '.')
18206 break;
18207
18208 if (end == base)
18209 return NULL;
18210
18211 /* Handle a possible width suffix and/or Neon type suffix. */
18212 if (end[0] == '.')
18213 {
18214 int offset = 2;
18215
18216 /* The .w and .n suffixes are only valid if the unified syntax is in
18217 use. */
18218 if (unified_syntax && end[1] == 'w')
18219 inst.size_req = 4;
18220 else if (unified_syntax && end[1] == 'n')
18221 inst.size_req = 2;
18222 else
18223 offset = 0;
18224
18225 inst.vectype.elems = 0;
18226
18227 *str = end + offset;
18228
18229 if (end[offset] == '.')
18230 {
18231 /* See if we have a Neon type suffix (possible in either unified or
18232 non-unified ARM syntax mode). */
18233 if (parse_neon_type (&inst.vectype, str) == FAIL)
18234 return NULL;
18235 }
18236 else if (end[offset] != '\0' && end[offset] != ' ')
18237 return NULL;
18238 }
18239 else
18240 *str = end;
18241
18242 /* Look for unaffixed or special-case affixed mnemonic. */
18243 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18244 end - base);
18245 if (opcode)
18246 {
18247 /* step U */
18248 if (opcode->tag < OT_odd_infix_0)
18249 {
18250 inst.cond = COND_ALWAYS;
18251 return opcode;
18252 }
18253
18254 if (warn_on_deprecated && unified_syntax)
18255 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
18256 affix = base + (opcode->tag - OT_odd_infix_0);
18257 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18258 gas_assert (cond);
18259
18260 inst.cond = cond->value;
18261 return opcode;
18262 }
18263
18264 /* Cannot have a conditional suffix on a mnemonic of less than two
18265 characters. */
18266 if (end - base < 3)
18267 return NULL;
18268
18269 /* Look for suffixed mnemonic. */
18270 affix = end - 2;
18271 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18272 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18273 affix - base);
18274 if (opcode && cond)
18275 {
18276 /* step CE */
18277 switch (opcode->tag)
18278 {
18279 case OT_cinfix3_legacy:
18280 /* Ignore conditional suffixes matched on infix only mnemonics. */
18281 break;
18282
18283 case OT_cinfix3:
18284 case OT_cinfix3_deprecated:
18285 case OT_odd_infix_unc:
18286 if (!unified_syntax)
18287 return NULL;
18288 /* Fall through. */
18289
18290 case OT_csuffix:
18291 case OT_csuffixF:
18292 case OT_csuf_or_in3:
18293 inst.cond = cond->value;
18294 return opcode;
18295
18296 case OT_unconditional:
18297 case OT_unconditionalF:
18298 if (thumb_mode)
18299 inst.cond = cond->value;
18300 else
18301 {
18302 /* Delayed diagnostic. */
18303 inst.error = BAD_COND;
18304 inst.cond = COND_ALWAYS;
18305 }
18306 return opcode;
18307
18308 default:
18309 return NULL;
18310 }
18311 }
18312
18313 /* Cannot have a usual-position infix on a mnemonic of less than
18314 six characters (five would be a suffix). */
18315 if (end - base < 6)
18316 return NULL;
18317
18318 /* Look for infixed mnemonic in the usual position. */
18319 affix = base + 3;
18320 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18321 if (!cond)
18322 return NULL;
18323
18324 memcpy (save, affix, 2);
18325 memmove (affix, affix + 2, (end - affix) - 2);
18326 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18327 (end - base) - 2);
18328 memmove (affix + 2, affix, (end - affix) - 2);
18329 memcpy (affix, save, 2);
18330
18331 if (opcode
18332 && (opcode->tag == OT_cinfix3
18333 || opcode->tag == OT_cinfix3_deprecated
18334 || opcode->tag == OT_csuf_or_in3
18335 || opcode->tag == OT_cinfix3_legacy))
18336 {
18337 /* Step CM. */
18338 if (warn_on_deprecated && unified_syntax
18339 && (opcode->tag == OT_cinfix3
18340 || opcode->tag == OT_cinfix3_deprecated))
18341 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
18342
18343 inst.cond = cond->value;
18344 return opcode;
18345 }
18346
18347 return NULL;
18348 }
18349
18350 /* This function generates an initial IT instruction, leaving its block
18351 virtually open for the new instructions. Eventually,
18352 the mask will be updated by now_it_add_mask () each time
18353 a new instruction needs to be included in the IT block.
18354 Finally, the block is closed with close_automatic_it_block ().
18355 The block closure can be requested either from md_assemble (),
18356 a tencode (), or due to a label hook. */
18357
18358 static void
18359 new_automatic_it_block (int cond)
18360 {
18361 now_it.state = AUTOMATIC_IT_BLOCK;
18362 now_it.mask = 0x18;
18363 now_it.cc = cond;
18364 now_it.block_length = 1;
18365 mapping_state (MAP_THUMB);
18366 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
18367 now_it.warn_deprecated = FALSE;
18368 now_it.insn_cond = TRUE;
18369 }
18370
18371 /* Close an automatic IT block.
18372 See comments in new_automatic_it_block (). */
18373
18374 static void
18375 close_automatic_it_block (void)
18376 {
18377 now_it.mask = 0x10;
18378 now_it.block_length = 0;
18379 }
18380
18381 /* Update the mask of the current automatically-generated IT
18382 instruction. See comments in new_automatic_it_block (). */
18383
18384 static void
18385 now_it_add_mask (int cond)
18386 {
18387 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18388 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
18389 | ((bitvalue) << (nbit)))
18390 const int resulting_bit = (cond & 1);
18391
18392 now_it.mask &= 0xf;
18393 now_it.mask = SET_BIT_VALUE (now_it.mask,
18394 resulting_bit,
18395 (5 - now_it.block_length));
18396 now_it.mask = SET_BIT_VALUE (now_it.mask,
18397 1,
18398 ((5 - now_it.block_length) - 1) );
18399 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18400
18401 #undef CLEAR_BIT
18402 #undef SET_BIT_VALUE
18403 }
18404
18405 /* The IT blocks handling machinery is accessed through the these functions:
18406 it_fsm_pre_encode () from md_assemble ()
18407 set_it_insn_type () optional, from the tencode functions
18408 set_it_insn_type_last () ditto
18409 in_it_block () ditto
18410 it_fsm_post_encode () from md_assemble ()
18411 force_automatic_it_block_close () from label handling functions
18412
18413 Rationale:
18414 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
18415 initializing the IT insn type with a generic initial value depending
18416 on the inst.condition.
18417 2) During the tencode function, two things may happen:
18418 a) The tencode function overrides the IT insn type by
18419 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18420 b) The tencode function queries the IT block state by
18421 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18422
18423 Both set_it_insn_type and in_it_block run the internal FSM state
18424 handling function (handle_it_state), because: a) setting the IT insn
18425 type may incur in an invalid state (exiting the function),
18426 and b) querying the state requires the FSM to be updated.
18427 Specifically we want to avoid creating an IT block for conditional
18428 branches, so it_fsm_pre_encode is actually a guess and we can't
18429 determine whether an IT block is required until the tencode () routine
18430 has decided what type of instruction this actually it.
18431 Because of this, if set_it_insn_type and in_it_block have to be used,
18432 set_it_insn_type has to be called first.
18433
18434 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18435 determines the insn IT type depending on the inst.cond code.
18436 When a tencode () routine encodes an instruction that can be
18437 either outside an IT block, or, in the case of being inside, has to be
18438 the last one, set_it_insn_type_last () will determine the proper
18439 IT instruction type based on the inst.cond code. Otherwise,
18440 set_it_insn_type can be called for overriding that logic or
18441 for covering other cases.
18442
18443 Calling handle_it_state () may not transition the IT block state to
18444 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
18445 still queried. Instead, if the FSM determines that the state should
18446 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18447 after the tencode () function: that's what it_fsm_post_encode () does.
18448
18449 Since in_it_block () calls the state handling function to get an
18450 updated state, an error may occur (due to invalid insns combination).
18451 In that case, inst.error is set.
18452 Therefore, inst.error has to be checked after the execution of
18453 the tencode () routine.
18454
18455 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
18456 any pending state change (if any) that didn't take place in
18457 handle_it_state () as explained above. */
18458
18459 static void
18460 it_fsm_pre_encode (void)
18461 {
18462 if (inst.cond != COND_ALWAYS)
18463 inst.it_insn_type = INSIDE_IT_INSN;
18464 else
18465 inst.it_insn_type = OUTSIDE_IT_INSN;
18466
18467 now_it.state_handled = 0;
18468 }
18469
18470 /* IT state FSM handling function. */
18471
18472 static int
18473 handle_it_state (void)
18474 {
18475 now_it.state_handled = 1;
18476 now_it.insn_cond = FALSE;
18477
18478 switch (now_it.state)
18479 {
18480 case OUTSIDE_IT_BLOCK:
18481 switch (inst.it_insn_type)
18482 {
18483 case OUTSIDE_IT_INSN:
18484 break;
18485
18486 case INSIDE_IT_INSN:
18487 case INSIDE_IT_LAST_INSN:
18488 if (thumb_mode == 0)
18489 {
18490 if (unified_syntax
18491 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18492 as_tsktsk (_("Warning: conditional outside an IT block"\
18493 " for Thumb."));
18494 }
18495 else
18496 {
18497 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
18498 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
18499 {
18500 /* Automatically generate the IT instruction. */
18501 new_automatic_it_block (inst.cond);
18502 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18503 close_automatic_it_block ();
18504 }
18505 else
18506 {
18507 inst.error = BAD_OUT_IT;
18508 return FAIL;
18509 }
18510 }
18511 break;
18512
18513 case IF_INSIDE_IT_LAST_INSN:
18514 case NEUTRAL_IT_INSN:
18515 break;
18516
18517 case IT_INSN:
18518 now_it.state = MANUAL_IT_BLOCK;
18519 now_it.block_length = 0;
18520 break;
18521 }
18522 break;
18523
18524 case AUTOMATIC_IT_BLOCK:
18525 /* Three things may happen now:
18526 a) We should increment current it block size;
18527 b) We should close current it block (closing insn or 4 insns);
18528 c) We should close current it block and start a new one (due
18529 to incompatible conditions or
18530 4 insns-length block reached). */
18531
18532 switch (inst.it_insn_type)
18533 {
18534 case OUTSIDE_IT_INSN:
18535 /* The closure of the block shall happen immediately,
18536 so any in_it_block () call reports the block as closed. */
18537 force_automatic_it_block_close ();
18538 break;
18539
18540 case INSIDE_IT_INSN:
18541 case INSIDE_IT_LAST_INSN:
18542 case IF_INSIDE_IT_LAST_INSN:
18543 now_it.block_length++;
18544
18545 if (now_it.block_length > 4
18546 || !now_it_compatible (inst.cond))
18547 {
18548 force_automatic_it_block_close ();
18549 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18550 new_automatic_it_block (inst.cond);
18551 }
18552 else
18553 {
18554 now_it.insn_cond = TRUE;
18555 now_it_add_mask (inst.cond);
18556 }
18557
18558 if (now_it.state == AUTOMATIC_IT_BLOCK
18559 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18560 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18561 close_automatic_it_block ();
18562 break;
18563
18564 case NEUTRAL_IT_INSN:
18565 now_it.block_length++;
18566 now_it.insn_cond = TRUE;
18567
18568 if (now_it.block_length > 4)
18569 force_automatic_it_block_close ();
18570 else
18571 now_it_add_mask (now_it.cc & 1);
18572 break;
18573
18574 case IT_INSN:
18575 close_automatic_it_block ();
18576 now_it.state = MANUAL_IT_BLOCK;
18577 break;
18578 }
18579 break;
18580
18581 case MANUAL_IT_BLOCK:
18582 {
18583 /* Check conditional suffixes. */
18584 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18585 int is_last;
18586 now_it.mask <<= 1;
18587 now_it.mask &= 0x1f;
18588 is_last = (now_it.mask == 0x10);
18589 now_it.insn_cond = TRUE;
18590
18591 switch (inst.it_insn_type)
18592 {
18593 case OUTSIDE_IT_INSN:
18594 inst.error = BAD_NOT_IT;
18595 return FAIL;
18596
18597 case INSIDE_IT_INSN:
18598 if (cond != inst.cond)
18599 {
18600 inst.error = BAD_IT_COND;
18601 return FAIL;
18602 }
18603 break;
18604
18605 case INSIDE_IT_LAST_INSN:
18606 case IF_INSIDE_IT_LAST_INSN:
18607 if (cond != inst.cond)
18608 {
18609 inst.error = BAD_IT_COND;
18610 return FAIL;
18611 }
18612 if (!is_last)
18613 {
18614 inst.error = BAD_BRANCH;
18615 return FAIL;
18616 }
18617 break;
18618
18619 case NEUTRAL_IT_INSN:
18620 /* The BKPT instruction is unconditional even in an IT block. */
18621 break;
18622
18623 case IT_INSN:
18624 inst.error = BAD_IT_IT;
18625 return FAIL;
18626 }
18627 }
18628 break;
18629 }
18630
18631 return SUCCESS;
18632 }
18633
18634 struct depr_insn_mask
18635 {
18636 unsigned long pattern;
18637 unsigned long mask;
18638 const char* description;
18639 };
18640
18641 /* List of 16-bit instruction patterns deprecated in an IT block in
18642 ARMv8. */
18643 static const struct depr_insn_mask depr_it_insns[] = {
18644 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18645 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18646 { 0xa000, 0xb800, N_("ADR") },
18647 { 0x4800, 0xf800, N_("Literal loads") },
18648 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18649 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
18650 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18651 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18652 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
18653 { 0, 0, NULL }
18654 };
18655
18656 static void
18657 it_fsm_post_encode (void)
18658 {
18659 int is_last;
18660
18661 if (!now_it.state_handled)
18662 handle_it_state ();
18663
18664 if (now_it.insn_cond
18665 && !now_it.warn_deprecated
18666 && warn_on_deprecated
18667 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
18668 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
18669 {
18670 if (inst.instruction >= 0x10000)
18671 {
18672 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
18673 "performance deprecated in ARMv8-A and ARMv8-R"));
18674 now_it.warn_deprecated = TRUE;
18675 }
18676 else
18677 {
18678 const struct depr_insn_mask *p = depr_it_insns;
18679
18680 while (p->mask != 0)
18681 {
18682 if ((inst.instruction & p->mask) == p->pattern)
18683 {
18684 as_tsktsk (_("IT blocks containing 16-bit Thumb "
18685 "instructions of the following class are "
18686 "performance deprecated in ARMv8-A and "
18687 "ARMv8-R: %s"), p->description);
18688 now_it.warn_deprecated = TRUE;
18689 break;
18690 }
18691
18692 ++p;
18693 }
18694 }
18695
18696 if (now_it.block_length > 1)
18697 {
18698 as_tsktsk (_("IT blocks containing more than one conditional "
18699 "instruction are performance deprecated in ARMv8-A and "
18700 "ARMv8-R"));
18701 now_it.warn_deprecated = TRUE;
18702 }
18703 }
18704
18705 is_last = (now_it.mask == 0x10);
18706 if (is_last)
18707 {
18708 now_it.state = OUTSIDE_IT_BLOCK;
18709 now_it.mask = 0;
18710 }
18711 }
18712
18713 static void
18714 force_automatic_it_block_close (void)
18715 {
18716 if (now_it.state == AUTOMATIC_IT_BLOCK)
18717 {
18718 close_automatic_it_block ();
18719 now_it.state = OUTSIDE_IT_BLOCK;
18720 now_it.mask = 0;
18721 }
18722 }
18723
18724 static int
18725 in_it_block (void)
18726 {
18727 if (!now_it.state_handled)
18728 handle_it_state ();
18729
18730 return now_it.state != OUTSIDE_IT_BLOCK;
18731 }
18732
18733 /* Whether OPCODE only has T32 encoding. Since this function is only used by
18734 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18735 here, hence the "known" in the function name. */
18736
18737 static bfd_boolean
18738 known_t32_only_insn (const struct asm_opcode *opcode)
18739 {
18740 /* Original Thumb-1 wide instruction. */
18741 if (opcode->tencode == do_t_blx
18742 || opcode->tencode == do_t_branch23
18743 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18744 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18745 return TRUE;
18746
18747 /* Wide-only instruction added to ARMv8-M Baseline. */
18748 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
18749 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18750 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18751 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18752 return TRUE;
18753
18754 return FALSE;
18755 }
18756
18757 /* Whether wide instruction variant can be used if available for a valid OPCODE
18758 in ARCH. */
18759
18760 static bfd_boolean
18761 t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18762 {
18763 if (known_t32_only_insn (opcode))
18764 return TRUE;
18765
18766 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18767 of variant T3 of B.W is checked in do_t_branch. */
18768 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18769 && opcode->tencode == do_t_branch)
18770 return TRUE;
18771
18772 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18773 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18774 && opcode->tencode == do_t_mov_cmp
18775 /* Make sure CMP instruction is not affected. */
18776 && opcode->aencode == do_mov)
18777 return TRUE;
18778
18779 /* Wide instruction variants of all instructions with narrow *and* wide
18780 variants become available with ARMv6t2. Other opcodes are either
18781 narrow-only or wide-only and are thus available if OPCODE is valid. */
18782 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18783 return TRUE;
18784
18785 /* OPCODE with narrow only instruction variant or wide variant not
18786 available. */
18787 return FALSE;
18788 }
18789
18790 void
18791 md_assemble (char *str)
18792 {
18793 char *p = str;
18794 const struct asm_opcode * opcode;
18795
18796 /* Align the previous label if needed. */
18797 if (last_label_seen != NULL)
18798 {
18799 symbol_set_frag (last_label_seen, frag_now);
18800 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18801 S_SET_SEGMENT (last_label_seen, now_seg);
18802 }
18803
18804 memset (&inst, '\0', sizeof (inst));
18805 int r;
18806 for (r = 0; r < ARM_IT_MAX_RELOCS; r++)
18807 inst.relocs[r].type = BFD_RELOC_UNUSED;
18808
18809 opcode = opcode_lookup (&p);
18810 if (!opcode)
18811 {
18812 /* It wasn't an instruction, but it might be a register alias of
18813 the form alias .req reg, or a Neon .dn/.qn directive. */
18814 if (! create_register_alias (str, p)
18815 && ! create_neon_reg_alias (str, p))
18816 as_bad (_("bad instruction `%s'"), str);
18817
18818 return;
18819 }
18820
18821 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
18822 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
18823
18824 /* The value which unconditional instructions should have in place of the
18825 condition field. */
18826 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18827
18828 if (thumb_mode)
18829 {
18830 arm_feature_set variant;
18831
18832 variant = cpu_variant;
18833 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
18834 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18835 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
18836 /* Check that this instruction is supported for this CPU. */
18837 if (!opcode->tvariant
18838 || (thumb_mode == 1
18839 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
18840 {
18841 if (opcode->tencode == do_t_swi)
18842 as_bad (_("SVC is not permitted on this architecture"));
18843 else
18844 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
18845 return;
18846 }
18847 if (inst.cond != COND_ALWAYS && !unified_syntax
18848 && opcode->tencode != do_t_branch)
18849 {
18850 as_bad (_("Thumb does not support conditional execution"));
18851 return;
18852 }
18853
18854 /* Two things are addressed here:
18855 1) Implicit require narrow instructions on Thumb-1.
18856 This avoids relaxation accidentally introducing Thumb-2
18857 instructions.
18858 2) Reject wide instructions in non Thumb-2 cores.
18859
18860 Only instructions with narrow and wide variants need to be handled
18861 but selecting all non wide-only instructions is easier. */
18862 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
18863 && !t32_insn_ok (variant, opcode))
18864 {
18865 if (inst.size_req == 0)
18866 inst.size_req = 2;
18867 else if (inst.size_req == 4)
18868 {
18869 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18870 as_bad (_("selected processor does not support 32bit wide "
18871 "variant of instruction `%s'"), str);
18872 else
18873 as_bad (_("selected processor does not support `%s' in "
18874 "Thumb-2 mode"), str);
18875 return;
18876 }
18877 }
18878
18879 inst.instruction = opcode->tvalue;
18880
18881 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
18882 {
18883 /* Prepare the it_insn_type for those encodings that don't set
18884 it. */
18885 it_fsm_pre_encode ();
18886
18887 opcode->tencode ();
18888
18889 it_fsm_post_encode ();
18890 }
18891
18892 if (!(inst.error || inst.relax))
18893 {
18894 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
18895 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18896 if (inst.size_req && inst.size_req != inst.size)
18897 {
18898 as_bad (_("cannot honor width suffix -- `%s'"), str);
18899 return;
18900 }
18901 }
18902
18903 /* Something has gone badly wrong if we try to relax a fixed size
18904 instruction. */
18905 gas_assert (inst.size_req == 0 || !inst.relax);
18906
18907 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18908 *opcode->tvariant);
18909 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
18910 set those bits when Thumb-2 32-bit instructions are seen. The impact
18911 of relaxable instructions will be considered later after we finish all
18912 relaxation. */
18913 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18914 variant = arm_arch_none;
18915 else
18916 variant = cpu_variant;
18917 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
18918 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18919 arm_ext_v6t2);
18920
18921 check_neon_suffixes;
18922
18923 if (!inst.error)
18924 {
18925 mapping_state (MAP_THUMB);
18926 }
18927 }
18928 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
18929 {
18930 bfd_boolean is_bx;
18931
18932 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18933 is_bx = (opcode->aencode == do_bx);
18934
18935 /* Check that this instruction is supported for this CPU. */
18936 if (!(is_bx && fix_v4bx)
18937 && !(opcode->avariant &&
18938 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
18939 {
18940 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
18941 return;
18942 }
18943 if (inst.size_req)
18944 {
18945 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18946 return;
18947 }
18948
18949 inst.instruction = opcode->avalue;
18950 if (opcode->tag == OT_unconditionalF)
18951 inst.instruction |= 0xFU << 28;
18952 else
18953 inst.instruction |= inst.cond << 28;
18954 inst.size = INSN_SIZE;
18955 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
18956 {
18957 it_fsm_pre_encode ();
18958 opcode->aencode ();
18959 it_fsm_post_encode ();
18960 }
18961 /* Arm mode bx is marked as both v4T and v5 because it's still required
18962 on a hypothetical non-thumb v5 core. */
18963 if (is_bx)
18964 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
18965 else
18966 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18967 *opcode->avariant);
18968
18969 check_neon_suffixes;
18970
18971 if (!inst.error)
18972 {
18973 mapping_state (MAP_ARM);
18974 }
18975 }
18976 else
18977 {
18978 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18979 "-- `%s'"), str);
18980 return;
18981 }
18982 output_inst (str);
18983 }
18984
18985 static void
18986 check_it_blocks_finished (void)
18987 {
18988 #ifdef OBJ_ELF
18989 asection *sect;
18990
18991 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18992 if (seg_info (sect)->tc_segment_info_data.current_it.state
18993 == MANUAL_IT_BLOCK)
18994 {
18995 as_warn (_("section '%s' finished with an open IT block."),
18996 sect->name);
18997 }
18998 #else
18999 if (now_it.state == MANUAL_IT_BLOCK)
19000 as_warn (_("file finished with an open IT block."));
19001 #endif
19002 }
19003
19004 /* Various frobbings of labels and their addresses. */
19005
19006 void
19007 arm_start_line_hook (void)
19008 {
19009 last_label_seen = NULL;
19010 }
19011
19012 void
19013 arm_frob_label (symbolS * sym)
19014 {
19015 last_label_seen = sym;
19016
19017 ARM_SET_THUMB (sym, thumb_mode);
19018
19019 #if defined OBJ_COFF || defined OBJ_ELF
19020 ARM_SET_INTERWORK (sym, support_interwork);
19021 #endif
19022
19023 force_automatic_it_block_close ();
19024
19025 /* Note - do not allow local symbols (.Lxxx) to be labelled
19026 as Thumb functions. This is because these labels, whilst
19027 they exist inside Thumb code, are not the entry points for
19028 possible ARM->Thumb calls. Also, these labels can be used
19029 as part of a computed goto or switch statement. eg gcc
19030 can generate code that looks like this:
19031
19032 ldr r2, [pc, .Laaa]
19033 lsl r3, r3, #2
19034 ldr r2, [r3, r2]
19035 mov pc, r2
19036
19037 .Lbbb: .word .Lxxx
19038 .Lccc: .word .Lyyy
19039 ..etc...
19040 .Laaa: .word Lbbb
19041
19042 The first instruction loads the address of the jump table.
19043 The second instruction converts a table index into a byte offset.
19044 The third instruction gets the jump address out of the table.
19045 The fourth instruction performs the jump.
19046
19047 If the address stored at .Laaa is that of a symbol which has the
19048 Thumb_Func bit set, then the linker will arrange for this address
19049 to have the bottom bit set, which in turn would mean that the
19050 address computation performed by the third instruction would end
19051 up with the bottom bit set. Since the ARM is capable of unaligned
19052 word loads, the instruction would then load the incorrect address
19053 out of the jump table, and chaos would ensue. */
19054 if (label_is_thumb_function_name
19055 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
19056 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
19057 {
19058 /* When the address of a Thumb function is taken the bottom
19059 bit of that address should be set. This will allow
19060 interworking between Arm and Thumb functions to work
19061 correctly. */
19062
19063 THUMB_SET_FUNC (sym, 1);
19064
19065 label_is_thumb_function_name = FALSE;
19066 }
19067
19068 dwarf2_emit_label (sym);
19069 }
19070
19071 bfd_boolean
19072 arm_data_in_code (void)
19073 {
19074 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
19075 {
19076 *input_line_pointer = '/';
19077 input_line_pointer += 5;
19078 *input_line_pointer = 0;
19079 return TRUE;
19080 }
19081
19082 return FALSE;
19083 }
19084
19085 char *
19086 arm_canonicalize_symbol_name (char * name)
19087 {
19088 int len;
19089
19090 if (thumb_mode && (len = strlen (name)) > 5
19091 && streq (name + len - 5, "/data"))
19092 *(name + len - 5) = 0;
19093
19094 return name;
19095 }
19096 \f
19097 /* Table of all register names defined by default. The user can
19098 define additional names with .req. Note that all register names
19099 should appear in both upper and lowercase variants. Some registers
19100 also have mixed-case names. */
19101
19102 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
19103 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
19104 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
19105 #define REGSET(p,t) \
19106 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
19107 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
19108 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
19109 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
19110 #define REGSETH(p,t) \
19111 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
19112 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
19113 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
19114 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
19115 #define REGSET2(p,t) \
19116 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
19117 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
19118 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
19119 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
19120 #define SPLRBANK(base,bank,t) \
19121 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
19122 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
19123 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
19124 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
19125 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19126 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
19127
19128 static const struct reg_entry reg_names[] =
19129 {
19130 /* ARM integer registers. */
19131 REGSET(r, RN), REGSET(R, RN),
19132
19133 /* ATPCS synonyms. */
19134 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
19135 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
19136 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
19137
19138 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19139 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19140 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
19141
19142 /* Well-known aliases. */
19143 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19144 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19145
19146 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19147 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19148
19149 /* Coprocessor numbers. */
19150 REGSET(p, CP), REGSET(P, CP),
19151
19152 /* Coprocessor register numbers. The "cr" variants are for backward
19153 compatibility. */
19154 REGSET(c, CN), REGSET(C, CN),
19155 REGSET(cr, CN), REGSET(CR, CN),
19156
19157 /* ARM banked registers. */
19158 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19159 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19160 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19161 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19162 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19163 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19164 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19165
19166 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19167 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19168 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19169 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19170 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
19171 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
19172 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19173 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19174
19175 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19176 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19177 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19178 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19179 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19180 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19181 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
19182 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
19183 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19184
19185 /* FPA registers. */
19186 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19187 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19188
19189 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19190 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19191
19192 /* VFP SP registers. */
19193 REGSET(s,VFS), REGSET(S,VFS),
19194 REGSETH(s,VFS), REGSETH(S,VFS),
19195
19196 /* VFP DP Registers. */
19197 REGSET(d,VFD), REGSET(D,VFD),
19198 /* Extra Neon DP registers. */
19199 REGSETH(d,VFD), REGSETH(D,VFD),
19200
19201 /* Neon QP registers. */
19202 REGSET2(q,NQ), REGSET2(Q,NQ),
19203
19204 /* VFP control registers. */
19205 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19206 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
19207 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19208 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19209 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19210 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
19211 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
19212
19213 /* Maverick DSP coprocessor registers. */
19214 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19215 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
19216
19217 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
19218 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
19219 REGDEF(dspsc,0,DSPSC),
19220
19221 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19222 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19223 REGDEF(DSPSC,0,DSPSC),
19224
19225 /* iWMMXt data registers - p0, c0-15. */
19226 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19227
19228 /* iWMMXt control registers - p1, c0-3. */
19229 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19230 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19231 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19232 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19233
19234 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19235 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19236 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19237 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19238 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19239
19240 /* XScale accumulator registers. */
19241 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19242 };
19243 #undef REGDEF
19244 #undef REGNUM
19245 #undef REGSET
19246
19247 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19248 within psr_required_here. */
19249 static const struct asm_psr psrs[] =
19250 {
19251 /* Backward compatibility notation. Note that "all" is no longer
19252 truly all possible PSR bits. */
19253 {"all", PSR_c | PSR_f},
19254 {"flg", PSR_f},
19255 {"ctl", PSR_c},
19256
19257 /* Individual flags. */
19258 {"f", PSR_f},
19259 {"c", PSR_c},
19260 {"x", PSR_x},
19261 {"s", PSR_s},
19262
19263 /* Combinations of flags. */
19264 {"fs", PSR_f | PSR_s},
19265 {"fx", PSR_f | PSR_x},
19266 {"fc", PSR_f | PSR_c},
19267 {"sf", PSR_s | PSR_f},
19268 {"sx", PSR_s | PSR_x},
19269 {"sc", PSR_s | PSR_c},
19270 {"xf", PSR_x | PSR_f},
19271 {"xs", PSR_x | PSR_s},
19272 {"xc", PSR_x | PSR_c},
19273 {"cf", PSR_c | PSR_f},
19274 {"cs", PSR_c | PSR_s},
19275 {"cx", PSR_c | PSR_x},
19276 {"fsx", PSR_f | PSR_s | PSR_x},
19277 {"fsc", PSR_f | PSR_s | PSR_c},
19278 {"fxs", PSR_f | PSR_x | PSR_s},
19279 {"fxc", PSR_f | PSR_x | PSR_c},
19280 {"fcs", PSR_f | PSR_c | PSR_s},
19281 {"fcx", PSR_f | PSR_c | PSR_x},
19282 {"sfx", PSR_s | PSR_f | PSR_x},
19283 {"sfc", PSR_s | PSR_f | PSR_c},
19284 {"sxf", PSR_s | PSR_x | PSR_f},
19285 {"sxc", PSR_s | PSR_x | PSR_c},
19286 {"scf", PSR_s | PSR_c | PSR_f},
19287 {"scx", PSR_s | PSR_c | PSR_x},
19288 {"xfs", PSR_x | PSR_f | PSR_s},
19289 {"xfc", PSR_x | PSR_f | PSR_c},
19290 {"xsf", PSR_x | PSR_s | PSR_f},
19291 {"xsc", PSR_x | PSR_s | PSR_c},
19292 {"xcf", PSR_x | PSR_c | PSR_f},
19293 {"xcs", PSR_x | PSR_c | PSR_s},
19294 {"cfs", PSR_c | PSR_f | PSR_s},
19295 {"cfx", PSR_c | PSR_f | PSR_x},
19296 {"csf", PSR_c | PSR_s | PSR_f},
19297 {"csx", PSR_c | PSR_s | PSR_x},
19298 {"cxf", PSR_c | PSR_x | PSR_f},
19299 {"cxs", PSR_c | PSR_x | PSR_s},
19300 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19301 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19302 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19303 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19304 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19305 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19306 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19307 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19308 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19309 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19310 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19311 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19312 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19313 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19314 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19315 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19316 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19317 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19318 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19319 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19320 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19321 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19322 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19323 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19324 };
19325
19326 /* Table of V7M psr names. */
19327 static const struct asm_psr v7m_psrs[] =
19328 {
19329 {"apsr", 0x0 }, {"APSR", 0x0 },
19330 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19331 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19332 {"psr", 0x3 }, {"PSR", 0x3 },
19333 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19334 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19335 {"epsr", 0x6 }, {"EPSR", 0x6 },
19336 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19337 {"msp", 0x8 }, {"MSP", 0x8 },
19338 {"psp", 0x9 }, {"PSP", 0x9 },
19339 {"msplim", 0xa }, {"MSPLIM", 0xa },
19340 {"psplim", 0xb }, {"PSPLIM", 0xb },
19341 {"primask", 0x10}, {"PRIMASK", 0x10},
19342 {"basepri", 0x11}, {"BASEPRI", 0x11},
19343 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
19344 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19345 {"control", 0x14}, {"CONTROL", 0x14},
19346 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19347 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19348 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19349 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19350 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19351 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19352 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19353 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19354 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
19355 };
19356
19357 /* Table of all shift-in-operand names. */
19358 static const struct asm_shift_name shift_names [] =
19359 {
19360 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19361 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19362 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19363 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19364 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19365 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19366 };
19367
19368 /* Table of all explicit relocation names. */
19369 #ifdef OBJ_ELF
19370 static struct reloc_entry reloc_names[] =
19371 {
19372 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19373 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19374 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19375 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19376 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19377 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19378 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19379 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19380 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19381 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
19382 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
19383 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19384 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
19385 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
19386 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
19387 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
19388 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
19389 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
19390 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
19391 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
19392 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19393 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19394 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
19395 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
19396 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
19397 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
19398 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
19399 };
19400 #endif
19401
19402 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
19403 static const struct asm_cond conds[] =
19404 {
19405 {"eq", 0x0},
19406 {"ne", 0x1},
19407 {"cs", 0x2}, {"hs", 0x2},
19408 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19409 {"mi", 0x4},
19410 {"pl", 0x5},
19411 {"vs", 0x6},
19412 {"vc", 0x7},
19413 {"hi", 0x8},
19414 {"ls", 0x9},
19415 {"ge", 0xa},
19416 {"lt", 0xb},
19417 {"gt", 0xc},
19418 {"le", 0xd},
19419 {"al", 0xe}
19420 };
19421
19422 #define UL_BARRIER(L,U,CODE,FEAT) \
19423 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19424 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
19425
19426 static struct asm_barrier_opt barrier_opt_names[] =
19427 {
19428 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19429 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19430 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19431 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19432 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19433 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19434 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19435 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19436 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19437 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19438 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19439 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19440 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19441 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19442 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19443 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
19444 };
19445
19446 #undef UL_BARRIER
19447
19448 /* Table of ARM-format instructions. */
19449
19450 /* Macros for gluing together operand strings. N.B. In all cases
19451 other than OPS0, the trailing OP_stop comes from default
19452 zero-initialization of the unspecified elements of the array. */
19453 #define OPS0() { OP_stop, }
19454 #define OPS1(a) { OP_##a, }
19455 #define OPS2(a,b) { OP_##a,OP_##b, }
19456 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19457 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19458 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19459 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19460
19461 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19462 This is useful when mixing operands for ARM and THUMB, i.e. using the
19463 MIX_ARM_THUMB_OPERANDS macro.
19464 In order to use these macros, prefix the number of operands with _
19465 e.g. _3. */
19466 #define OPS_1(a) { a, }
19467 #define OPS_2(a,b) { a,b, }
19468 #define OPS_3(a,b,c) { a,b,c, }
19469 #define OPS_4(a,b,c,d) { a,b,c,d, }
19470 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19471 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19472
19473 /* These macros abstract out the exact format of the mnemonic table and
19474 save some repeated characters. */
19475
19476 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19477 #define TxCE(mnem, op, top, nops, ops, ae, te) \
19478 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
19479 THUMB_VARIANT, do_##ae, do_##te }
19480
19481 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19482 a T_MNEM_xyz enumerator. */
19483 #define TCE(mnem, aop, top, nops, ops, ae, te) \
19484 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
19485 #define tCE(mnem, aop, top, nops, ops, ae, te) \
19486 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
19487
19488 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19489 infix after the third character. */
19490 #define TxC3(mnem, op, top, nops, ops, ae, te) \
19491 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
19492 THUMB_VARIANT, do_##ae, do_##te }
19493 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
19494 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
19495 THUMB_VARIANT, do_##ae, do_##te }
19496 #define TC3(mnem, aop, top, nops, ops, ae, te) \
19497 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
19498 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
19499 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
19500 #define tC3(mnem, aop, top, nops, ops, ae, te) \
19501 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
19502 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
19503 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
19504
19505 /* Mnemonic that cannot be conditionalized. The ARM condition-code
19506 field is still 0xE. Many of the Thumb variants can be executed
19507 conditionally, so this is checked separately. */
19508 #define TUE(mnem, op, top, nops, ops, ae, te) \
19509 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19510 THUMB_VARIANT, do_##ae, do_##te }
19511
19512 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19513 Used by mnemonics that have very minimal differences in the encoding for
19514 ARM and Thumb variants and can be handled in a common function. */
19515 #define TUEc(mnem, op, top, nops, ops, en) \
19516 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19517 THUMB_VARIANT, do_##en, do_##en }
19518
19519 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19520 condition code field. */
19521 #define TUF(mnem, op, top, nops, ops, ae, te) \
19522 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
19523 THUMB_VARIANT, do_##ae, do_##te }
19524
19525 /* ARM-only variants of all the above. */
19526 #define CE(mnem, op, nops, ops, ae) \
19527 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19528
19529 #define C3(mnem, op, nops, ops, ae) \
19530 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19531
19532 /* Thumb-only variants of TCE and TUE. */
19533 #define ToC(mnem, top, nops, ops, te) \
19534 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
19535 do_##te }
19536
19537 #define ToU(mnem, top, nops, ops, te) \
19538 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
19539 NULL, do_##te }
19540
19541 /* Legacy mnemonics that always have conditional infix after the third
19542 character. */
19543 #define CL(mnem, op, nops, ops, ae) \
19544 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
19545 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19546
19547 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19548 #define cCE(mnem, op, nops, ops, ae) \
19549 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19550
19551 /* Legacy coprocessor instructions where conditional infix and conditional
19552 suffix are ambiguous. For consistency this includes all FPA instructions,
19553 not just the potentially ambiguous ones. */
19554 #define cCL(mnem, op, nops, ops, ae) \
19555 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
19556 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19557
19558 /* Coprocessor, takes either a suffix or a position-3 infix
19559 (for an FPA corner case). */
19560 #define C3E(mnem, op, nops, ops, ae) \
19561 { mnem, OPS##nops ops, OT_csuf_or_in3, \
19562 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19563
19564 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
19565 { m1 #m2 m3, OPS##nops ops, \
19566 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
19567 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19568
19569 #define CM(m1, m2, op, nops, ops, ae) \
19570 xCM_ (m1, , m2, op, nops, ops, ae), \
19571 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19572 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19573 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19574 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19575 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19576 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19577 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19578 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19579 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19580 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19581 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19582 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19583 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19584 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19585 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19586 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19587 xCM_ (m1, le, m2, op, nops, ops, ae), \
19588 xCM_ (m1, al, m2, op, nops, ops, ae)
19589
19590 #define UE(mnem, op, nops, ops, ae) \
19591 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19592
19593 #define UF(mnem, op, nops, ops, ae) \
19594 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19595
19596 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
19597 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19598 use the same encoding function for each. */
19599 #define NUF(mnem, op, nops, ops, enc) \
19600 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19601 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19602
19603 /* Neon data processing, version which indirects through neon_enc_tab for
19604 the various overloaded versions of opcodes. */
19605 #define nUF(mnem, op, nops, ops, enc) \
19606 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
19607 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19608
19609 /* Neon insn with conditional suffix for the ARM version, non-overloaded
19610 version. */
19611 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
19612 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
19613 THUMB_VARIANT, do_##enc, do_##enc }
19614
19615 #define NCE(mnem, op, nops, ops, enc) \
19616 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
19617
19618 #define NCEF(mnem, op, nops, ops, enc) \
19619 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
19620
19621 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
19622 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
19623 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
19624 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19625
19626 #define nCE(mnem, op, nops, ops, enc) \
19627 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
19628
19629 #define nCEF(mnem, op, nops, ops, enc) \
19630 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
19631
19632 #define do_0 0
19633
19634 static const struct asm_opcode insns[] =
19635 {
19636 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19637 #define THUMB_VARIANT & arm_ext_v4t
19638 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19639 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19640 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19641 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19642 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19643 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19644 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19645 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19646 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19647 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19648 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19649 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19650 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19651 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19652 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19653 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
19654
19655 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19656 for setting PSR flag bits. They are obsolete in V6 and do not
19657 have Thumb equivalents. */
19658 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19659 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19660 CL("tstp", 110f000, 2, (RR, SH), cmp),
19661 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19662 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19663 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19664 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19665 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19666 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19667
19668 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
19669 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
19670 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19671 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19672
19673 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
19674 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19675 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19676 OP_RRnpc),
19677 OP_ADDRGLDR),ldst, t_ldst),
19678 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19679
19680 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19681 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19682 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19683 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19684 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19685 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19686
19687 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19688 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
19689
19690 /* Pseudo ops. */
19691 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
19692 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
19693 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
19694 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
19695
19696 /* Thumb-compatibility pseudo ops. */
19697 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19698 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19699 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19700 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19701 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19702 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19703 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19704 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19705 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19706 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19707 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19708 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
19709
19710 /* These may simplify to neg. */
19711 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19712 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
19713
19714 #undef THUMB_VARIANT
19715 #define THUMB_VARIANT & arm_ext_os
19716
19717 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19718 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19719
19720 #undef THUMB_VARIANT
19721 #define THUMB_VARIANT & arm_ext_v6
19722
19723 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
19724
19725 /* V1 instructions with no Thumb analogue prior to V6T2. */
19726 #undef THUMB_VARIANT
19727 #define THUMB_VARIANT & arm_ext_v6t2
19728
19729 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19730 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19731 CL("teqp", 130f000, 2, (RR, SH), cmp),
19732
19733 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19734 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19735 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19736 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19737
19738 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19739 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19740
19741 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19742 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19743
19744 /* V1 instructions with no Thumb analogue at all. */
19745 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
19746 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19747
19748 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19749 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19750 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19751 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19752 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19753 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19754 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19755 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19756
19757 #undef ARM_VARIANT
19758 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19759 #undef THUMB_VARIANT
19760 #define THUMB_VARIANT & arm_ext_v4t
19761
19762 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19763 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19764
19765 #undef THUMB_VARIANT
19766 #define THUMB_VARIANT & arm_ext_v6t2
19767
19768 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
19769 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19770
19771 /* Generic coprocessor instructions. */
19772 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19773 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19774 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19775 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19776 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19777 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19778 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
19779
19780 #undef ARM_VARIANT
19781 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19782
19783 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19784 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19785
19786 #undef ARM_VARIANT
19787 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19788 #undef THUMB_VARIANT
19789 #define THUMB_VARIANT & arm_ext_msr
19790
19791 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19792 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
19793
19794 #undef ARM_VARIANT
19795 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19796 #undef THUMB_VARIANT
19797 #define THUMB_VARIANT & arm_ext_v6t2
19798
19799 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19800 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19801 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19802 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19803 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19804 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19805 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19806 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19807
19808 #undef ARM_VARIANT
19809 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19810 #undef THUMB_VARIANT
19811 #define THUMB_VARIANT & arm_ext_v4t
19812
19813 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19814 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19815 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19816 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19817 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19818 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19819
19820 #undef ARM_VARIANT
19821 #define ARM_VARIANT & arm_ext_v4t_5
19822
19823 /* ARM Architecture 4T. */
19824 /* Note: bx (and blx) are required on V5, even if the processor does
19825 not support Thumb. */
19826 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
19827
19828 #undef ARM_VARIANT
19829 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19830 #undef THUMB_VARIANT
19831 #define THUMB_VARIANT & arm_ext_v5t
19832
19833 /* Note: blx has 2 variants; the .value coded here is for
19834 BLX(2). Only this variant has conditional execution. */
19835 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19836 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
19837
19838 #undef THUMB_VARIANT
19839 #define THUMB_VARIANT & arm_ext_v6t2
19840
19841 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19842 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19843 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19844 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19845 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19846 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19847 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19848 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19849
19850 #undef ARM_VARIANT
19851 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19852 #undef THUMB_VARIANT
19853 #define THUMB_VARIANT & arm_ext_v5exp
19854
19855 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19856 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19857 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19858 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19859
19860 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19861 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19862
19863 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19864 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19865 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19866 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19867
19868 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19869 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19870 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19871 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19872
19873 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19874 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19875
19876 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19877 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19878 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19879 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19880
19881 #undef ARM_VARIANT
19882 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19883 #undef THUMB_VARIANT
19884 #define THUMB_VARIANT & arm_ext_v6t2
19885
19886 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
19887 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19888 ldrd, t_ldstd),
19889 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19890 ADDRGLDRS), ldrd, t_ldstd),
19891
19892 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19893 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19894
19895 #undef ARM_VARIANT
19896 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19897
19898 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
19899
19900 #undef ARM_VARIANT
19901 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19902 #undef THUMB_VARIANT
19903 #define THUMB_VARIANT & arm_ext_v6
19904
19905 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19906 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19907 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19908 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19909 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19910 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19911 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19912 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19913 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19914 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
19915
19916 #undef THUMB_VARIANT
19917 #define THUMB_VARIANT & arm_ext_v6t2_v8m
19918
19919 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19920 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19921 strex, t_strex),
19922 #undef THUMB_VARIANT
19923 #define THUMB_VARIANT & arm_ext_v6t2
19924
19925 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19926 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19927
19928 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19929 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
19930
19931 /* ARM V6 not included in V7M. */
19932 #undef THUMB_VARIANT
19933 #define THUMB_VARIANT & arm_ext_v6_notm
19934 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
19935 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
19936 UF(rfeib, 9900a00, 1, (RRw), rfe),
19937 UF(rfeda, 8100a00, 1, (RRw), rfe),
19938 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19939 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
19940 UF(rfefa, 8100a00, 1, (RRw), rfe),
19941 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19942 UF(rfeed, 9900a00, 1, (RRw), rfe),
19943 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19944 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19945 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19946 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
19947 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
19948 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
19949 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
19950 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
19951 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
19952 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
19953
19954 /* ARM V6 not included in V7M (eg. integer SIMD). */
19955 #undef THUMB_VARIANT
19956 #define THUMB_VARIANT & arm_ext_v6_dsp
19957 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19958 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19959 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19960 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19961 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19962 /* Old name for QASX. */
19963 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19964 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19965 /* Old name for QSAX. */
19966 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19967 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19968 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19969 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19970 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19971 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19972 /* Old name for SASX. */
19973 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19974 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19975 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19976 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19977 /* Old name for SHASX. */
19978 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19979 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19980 /* Old name for SHSAX. */
19981 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19982 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19983 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19984 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19985 /* Old name for SSAX. */
19986 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19987 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19988 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19989 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19990 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19991 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19992 /* Old name for UASX. */
19993 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19994 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19995 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19996 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19997 /* Old name for UHASX. */
19998 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19999 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20000 /* Old name for UHSAX. */
20001 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20002 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20003 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20004 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20005 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20006 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20007 /* Old name for UQASX. */
20008 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20009 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20010 /* Old name for UQSAX. */
20011 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20012 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20013 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20014 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20015 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20016 /* Old name for USAX. */
20017 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20018 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20019 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20020 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20021 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20022 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20023 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20024 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20025 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
20026 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
20027 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
20028 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20029 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20030 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20031 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20032 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20033 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20034 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20035 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
20036 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20037 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20038 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20039 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20040 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20041 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20042 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20043 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20044 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20045 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20046 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
20047 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
20048 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
20049 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
20050 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
20051
20052 #undef ARM_VARIANT
20053 #define ARM_VARIANT & arm_ext_v6k_v6t2
20054 #undef THUMB_VARIANT
20055 #define THUMB_VARIANT & arm_ext_v6k_v6t2
20056
20057 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
20058 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
20059 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
20060 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
20061
20062 #undef THUMB_VARIANT
20063 #define THUMB_VARIANT & arm_ext_v6_notm
20064 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
20065 ldrexd, t_ldrexd),
20066 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
20067 RRnpcb), strexd, t_strexd),
20068
20069 #undef THUMB_VARIANT
20070 #define THUMB_VARIANT & arm_ext_v6t2_v8m
20071 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
20072 rd_rn, rd_rn),
20073 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
20074 rd_rn, rd_rn),
20075 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
20076 strex, t_strexbh),
20077 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
20078 strex, t_strexbh),
20079 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
20080
20081 #undef ARM_VARIANT
20082 #define ARM_VARIANT & arm_ext_sec
20083 #undef THUMB_VARIANT
20084 #define THUMB_VARIANT & arm_ext_sec
20085
20086 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
20087
20088 #undef ARM_VARIANT
20089 #define ARM_VARIANT & arm_ext_virt
20090 #undef THUMB_VARIANT
20091 #define THUMB_VARIANT & arm_ext_virt
20092
20093 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
20094 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
20095
20096 #undef ARM_VARIANT
20097 #define ARM_VARIANT & arm_ext_pan
20098 #undef THUMB_VARIANT
20099 #define THUMB_VARIANT & arm_ext_pan
20100
20101 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
20102
20103 #undef ARM_VARIANT
20104 #define ARM_VARIANT & arm_ext_v6t2
20105 #undef THUMB_VARIANT
20106 #define THUMB_VARIANT & arm_ext_v6t2
20107
20108 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
20109 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
20110 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20111 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20112
20113 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
20114 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
20115
20116 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20117 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20118 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20119 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20120
20121 #undef ARM_VARIANT
20122 #define ARM_VARIANT & arm_ext_v3
20123 #undef THUMB_VARIANT
20124 #define THUMB_VARIANT & arm_ext_v6t2
20125
20126 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
20127 TUF("ssbb", 57ff040, f3bf8f40, 0, (), noargs, t_csdb),
20128 TUF("pssbb", 57ff044, f3bf8f44, 0, (), noargs, t_csdb),
20129
20130 #undef ARM_VARIANT
20131 #define ARM_VARIANT & arm_ext_v6t2
20132 #undef THUMB_VARIANT
20133 #define THUMB_VARIANT & arm_ext_v6t2_v8m
20134 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
20135 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
20136
20137 /* Thumb-only instructions. */
20138 #undef ARM_VARIANT
20139 #define ARM_VARIANT NULL
20140 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
20141 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
20142
20143 /* ARM does not really have an IT instruction, so always allow it.
20144 The opcode is copied from Thumb in order to allow warnings in
20145 -mimplicit-it=[never | arm] modes. */
20146 #undef ARM_VARIANT
20147 #define ARM_VARIANT & arm_ext_v1
20148 #undef THUMB_VARIANT
20149 #define THUMB_VARIANT & arm_ext_v6t2
20150
20151 TUE("it", bf08, bf08, 1, (COND), it, t_it),
20152 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
20153 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
20154 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20155 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20156 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20157 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20158 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20159 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20160 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20161 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20162 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20163 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20164 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20165 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
20166 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
20167 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20168 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
20169
20170 /* Thumb2 only instructions. */
20171 #undef ARM_VARIANT
20172 #define ARM_VARIANT NULL
20173
20174 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20175 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20176 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20177 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20178 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20179 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
20180
20181 /* Hardware division instructions. */
20182 #undef ARM_VARIANT
20183 #define ARM_VARIANT & arm_ext_adiv
20184 #undef THUMB_VARIANT
20185 #define THUMB_VARIANT & arm_ext_div
20186
20187 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20188 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
20189
20190 /* ARM V6M/V7 instructions. */
20191 #undef ARM_VARIANT
20192 #define ARM_VARIANT & arm_ext_barrier
20193 #undef THUMB_VARIANT
20194 #define THUMB_VARIANT & arm_ext_barrier
20195
20196 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20197 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20198 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
20199
20200 /* ARM V7 instructions. */
20201 #undef ARM_VARIANT
20202 #define ARM_VARIANT & arm_ext_v7
20203 #undef THUMB_VARIANT
20204 #define THUMB_VARIANT & arm_ext_v7
20205
20206 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20207 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
20208
20209 #undef ARM_VARIANT
20210 #define ARM_VARIANT & arm_ext_mp
20211 #undef THUMB_VARIANT
20212 #define THUMB_VARIANT & arm_ext_mp
20213
20214 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20215
20216 /* AArchv8 instructions. */
20217 #undef ARM_VARIANT
20218 #define ARM_VARIANT & arm_ext_v8
20219
20220 /* Instructions shared between armv8-a and armv8-m. */
20221 #undef THUMB_VARIANT
20222 #define THUMB_VARIANT & arm_ext_atomics
20223
20224 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20225 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20226 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20227 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20228 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20229 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20230 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20231 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20232 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20233 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20234 stlex, t_stlex),
20235 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20236 stlex, t_stlex),
20237 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20238 stlex, t_stlex),
20239 #undef THUMB_VARIANT
20240 #define THUMB_VARIANT & arm_ext_v8
20241
20242 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
20243 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20244 ldrexd, t_ldrexd),
20245 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20246 strexd, t_strexd),
20247
20248 /* Defined in V8 but is in undefined encoding space for earlier
20249 architectures. However earlier architectures are required to treat
20250 this instuction as a semihosting trap as well. Hence while not explicitly
20251 defined as such, it is in fact correct to define the instruction for all
20252 architectures. */
20253 #undef THUMB_VARIANT
20254 #define THUMB_VARIANT & arm_ext_v1
20255 #undef ARM_VARIANT
20256 #define ARM_VARIANT & arm_ext_v1
20257 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20258
20259 /* ARMv8 T32 only. */
20260 #undef ARM_VARIANT
20261 #define ARM_VARIANT NULL
20262 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20263 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20264 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20265
20266 /* FP for ARMv8. */
20267 #undef ARM_VARIANT
20268 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
20269 #undef THUMB_VARIANT
20270 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
20271
20272 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20273 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20274 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20275 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
20276 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20277 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20278 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20279 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20280 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20281 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
20282 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20283 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20284 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20285 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20286 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20287 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20288 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
20289
20290 /* Crypto v1 extensions. */
20291 #undef ARM_VARIANT
20292 #define ARM_VARIANT & fpu_crypto_ext_armv8
20293 #undef THUMB_VARIANT
20294 #define THUMB_VARIANT & fpu_crypto_ext_armv8
20295
20296 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20297 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20298 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20299 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
20300 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20301 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20302 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20303 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20304 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20305 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20306 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
20307 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20308 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20309 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
20310
20311 #undef ARM_VARIANT
20312 #define ARM_VARIANT & crc_ext_armv8
20313 #undef THUMB_VARIANT
20314 #define THUMB_VARIANT & crc_ext_armv8
20315 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20316 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20317 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20318 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20319 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20320 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20321
20322 /* ARMv8.2 RAS extension. */
20323 #undef ARM_VARIANT
20324 #define ARM_VARIANT & arm_ext_ras
20325 #undef THUMB_VARIANT
20326 #define THUMB_VARIANT & arm_ext_ras
20327 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20328
20329 #undef ARM_VARIANT
20330 #define ARM_VARIANT & arm_ext_v8_3
20331 #undef THUMB_VARIANT
20332 #define THUMB_VARIANT & arm_ext_v8_3
20333 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
20334 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20335 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
20336
20337 #undef ARM_VARIANT
20338 #define ARM_VARIANT & fpu_neon_ext_dotprod
20339 #undef THUMB_VARIANT
20340 #define THUMB_VARIANT & fpu_neon_ext_dotprod
20341 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20342 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20343
20344 #undef ARM_VARIANT
20345 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
20346 #undef THUMB_VARIANT
20347 #define THUMB_VARIANT NULL
20348
20349 cCE("wfs", e200110, 1, (RR), rd),
20350 cCE("rfs", e300110, 1, (RR), rd),
20351 cCE("wfc", e400110, 1, (RR), rd),
20352 cCE("rfc", e500110, 1, (RR), rd),
20353
20354 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20355 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20356 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20357 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20358
20359 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20360 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20361 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20362 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20363
20364 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20365 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20366 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20367 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20368 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20369 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20370 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20371 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20372 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20373 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20374 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20375 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20376
20377 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20378 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20379 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20380 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20381 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20382 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20383 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20384 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20385 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20386 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20387 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20388 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20389
20390 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20391 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20392 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20393 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20394 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20395 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20396 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20397 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20398 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20399 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20400 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20401 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20402
20403 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20404 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20405 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20406 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20407 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20408 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20409 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20410 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20411 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20412 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20413 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20414 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20415
20416 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20417 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20418 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20419 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20420 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20421 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20422 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20423 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20424 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20425 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20426 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20427 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20428
20429 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20430 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20431 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20432 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20433 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20434 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20435 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20436 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20437 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20438 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20439 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20440 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20441
20442 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20443 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20444 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20445 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20446 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20447 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20448 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20449 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20450 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20451 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20452 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20453 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20454
20455 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20456 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20457 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20458 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20459 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20460 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20461 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20462 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20463 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20464 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20465 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20466 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20467
20468 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20469 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20470 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20471 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20472 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20473 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20474 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20475 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20476 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20477 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20478 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20479 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20480
20481 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20482 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20483 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20484 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20485 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20486 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20487 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20488 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20489 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20490 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20491 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20492 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20493
20494 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20495 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20496 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20497 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20498 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20499 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20500 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20501 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20502 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20503 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20504 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20505 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20506
20507 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20508 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20509 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20510 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20511 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20512 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20513 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20514 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20515 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20516 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20517 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20518 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20519
20520 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20521 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20522 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20523 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20524 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20525 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20526 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20527 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20528 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20529 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20530 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20531 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20532
20533 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20534 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20535 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20536 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20537 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20538 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20539 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20540 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20541 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20542 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20543 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20544 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20545
20546 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20547 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20548 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20549 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20550 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20551 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20552 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20553 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20554 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20555 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20556 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20557 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20558
20559 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20560 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20561 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20562 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20563 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20564 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20565 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20566 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20567 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20568 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20569 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20570 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20571
20572 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20573 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20574 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20575 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20576 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20577 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20578 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20579 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20580 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20581 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20582 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20583 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20584
20585 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20586 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20587 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20588 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20589 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20590 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20591 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20592 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20593 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20594 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20595 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20596 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20597
20598 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20599 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20600 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20601 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20602 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20603 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20604 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20605 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20606 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20607 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20608 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20609 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20610
20611 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20612 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20613 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20614 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20615 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20616 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20617 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20618 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20619 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20620 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20621 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20622 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20623
20624 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20625 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20626 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20627 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20628 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20629 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20630 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20631 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20632 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20633 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20634 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20635 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20636
20637 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20638 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20639 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20640 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20641 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20642 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20643 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20644 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20645 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20646 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20647 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20648 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20649
20650 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20651 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20652 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20653 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20654 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20655 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20656 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20657 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20658 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20659 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20660 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20661 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20662
20663 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20664 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20665 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20666 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20667 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20668 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20669 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20670 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20671 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20672 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20673 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20674 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20675
20676 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20677 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20678 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20679 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20680 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20681 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20682 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20683 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20684 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20685 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20686 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20687 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20688
20689 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20690 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20691 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20692 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20693 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20694 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20695 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20696 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20697 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20698 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20699 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20700 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20701
20702 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20703 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20704 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20705 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20706 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20707 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20708 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20709 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20710 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20711 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20712 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20713 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20714
20715 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20716 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20717 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20718 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20719 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20720 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20721 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20722 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20723 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20724 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20725 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20726 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20727
20728 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20729 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20730 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20731 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20732 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20733 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20734 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20735 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20736 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20737 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20738 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20739 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20740
20741 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20742 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20743 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20744 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20745
20746 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20747 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20748 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20749 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20750 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20751 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20752 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20753 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20754 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20755 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20756 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20757 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
20758
20759 /* The implementation of the FIX instruction is broken on some
20760 assemblers, in that it accepts a precision specifier as well as a
20761 rounding specifier, despite the fact that this is meaningless.
20762 To be more compatible, we accept it as well, though of course it
20763 does not set any bits. */
20764 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20765 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20766 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20767 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20768 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20769 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20770 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20771 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20772 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20773 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20774 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20775 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20776 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
20777
20778 /* Instructions that were new with the real FPA, call them V2. */
20779 #undef ARM_VARIANT
20780 #define ARM_VARIANT & fpu_fpa_ext_v2
20781
20782 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20783 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20784 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20785 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20786 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20787 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20788
20789 #undef ARM_VARIANT
20790 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20791
20792 /* Moves and type conversions. */
20793 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20794 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20795 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20796 cCE("fmstat", ef1fa10, 0, (), noargs),
20797 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20798 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
20799 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20800 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20801 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20802 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20803 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20804 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20805 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20806 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
20807
20808 /* Memory operations. */
20809 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20810 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20811 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20812 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20813 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20814 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20815 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20816 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20817 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20818 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20819 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20820 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20821 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20822 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20823 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20824 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20825 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20826 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20827
20828 /* Monadic operations. */
20829 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20830 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20831 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
20832
20833 /* Dyadic operations. */
20834 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20835 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20836 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20837 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20838 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20839 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20840 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20841 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20842 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20843
20844 /* Comparisons. */
20845 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20846 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20847 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20848 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
20849
20850 /* Double precision load/store are still present on single precision
20851 implementations. */
20852 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20853 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20854 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20855 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20856 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20857 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20858 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20859 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20860 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20861 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20862
20863 #undef ARM_VARIANT
20864 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20865
20866 /* Moves and type conversions. */
20867 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20868 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20869 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20870 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20871 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20872 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20873 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20874 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20875 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20876 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20877 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20878 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20879 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20880
20881 /* Monadic operations. */
20882 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20883 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20884 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20885
20886 /* Dyadic operations. */
20887 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20888 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20889 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20890 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20891 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20892 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20893 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20894 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20895 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20896
20897 /* Comparisons. */
20898 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20899 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20900 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20901 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
20902
20903 #undef ARM_VARIANT
20904 #define ARM_VARIANT & fpu_vfp_ext_v2
20905
20906 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20907 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20908 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20909 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
20910
20911 /* Instructions which may belong to either the Neon or VFP instruction sets.
20912 Individual encoder functions perform additional architecture checks. */
20913 #undef ARM_VARIANT
20914 #define ARM_VARIANT & fpu_vfp_ext_v1xd
20915 #undef THUMB_VARIANT
20916 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
20917
20918 /* These mnemonics are unique to VFP. */
20919 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20920 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
20921 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20922 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20923 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20924 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20925 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20926 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20927 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20928 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20929
20930 /* Mnemonics shared by Neon and VFP. */
20931 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20932 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20933 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20934
20935 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20936 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20937
20938 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20939 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20940
20941 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20942 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20943 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20944 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20945 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20946 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20947 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20948 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20949
20950 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
20951 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
20952 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20953 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
20954
20955
20956 /* NOTE: All VMOV encoding is special-cased! */
20957 NCE(vmov, 0, 1, (VMOV), neon_mov),
20958 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20959
20960 #undef ARM_VARIANT
20961 #define ARM_VARIANT & arm_ext_fp16
20962 #undef THUMB_VARIANT
20963 #define THUMB_VARIANT & arm_ext_fp16
20964 /* New instructions added from v8.2, allowing the extraction and insertion of
20965 the upper 16 bits of a 32-bit vector register. */
20966 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20967 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20968
20969 /* New backported fma/fms instructions optional in v8.2. */
20970 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
20971 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
20972
20973 #undef THUMB_VARIANT
20974 #define THUMB_VARIANT & fpu_neon_ext_v1
20975 #undef ARM_VARIANT
20976 #define ARM_VARIANT & fpu_neon_ext_v1
20977
20978 /* Data processing with three registers of the same length. */
20979 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20980 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20981 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20982 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20983 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20984 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20985 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20986 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20987 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20988 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20989 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20990 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20991 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20992 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20993 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20994 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20995 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20996 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20997 /* If not immediate, fall back to neon_dyadic_i64_su.
20998 shl_imm should accept I8 I16 I32 I64,
20999 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21000 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
21001 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
21002 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
21003 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
21004 /* Logic ops, types optional & ignored. */
21005 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21006 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21007 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21008 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21009 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21010 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21011 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
21012 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
21013 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
21014 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
21015 /* Bitfield ops, untyped. */
21016 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21017 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21018 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21019 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21020 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
21021 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
21022 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
21023 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21024 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21025 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21026 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21027 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
21028 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
21029 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
21030 back to neon_dyadic_if_su. */
21031 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
21032 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
21033 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
21034 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
21035 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
21036 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
21037 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
21038 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
21039 /* Comparison. Type I8 I16 I32 F32. */
21040 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
21041 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
21042 /* As above, D registers only. */
21043 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
21044 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
21045 /* Int and float variants, signedness unimportant. */
21046 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
21047 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
21048 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
21049 /* Add/sub take types I8 I16 I32 I64 F32. */
21050 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
21051 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
21052 /* vtst takes sizes 8, 16, 32. */
21053 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
21054 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
21055 /* VMUL takes I8 I16 I32 F32 P8. */
21056 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
21057 /* VQD{R}MULH takes S16 S32. */
21058 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
21059 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21060 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
21061 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
21062 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
21063 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
21064 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
21065 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
21066 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
21067 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
21068 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
21069 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
21070 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
21071 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
21072 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
21073 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
21074 /* ARM v8.1 extension. */
21075 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
21076 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
21077 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
21078 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
21079
21080 /* Two address, int/float. Types S8 S16 S32 F32. */
21081 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
21082 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
21083
21084 /* Data processing with two registers and a shift amount. */
21085 /* Right shifts, and variants with rounding.
21086 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
21087 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21088 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21089 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21090 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21091 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21092 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21093 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21094 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21095 /* Shift and insert. Sizes accepted 8 16 32 64. */
21096 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
21097 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
21098 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
21099 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
21100 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
21101 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
21102 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
21103 /* Right shift immediate, saturating & narrowing, with rounding variants.
21104 Types accepted S16 S32 S64 U16 U32 U64. */
21105 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21106 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21107 /* As above, unsigned. Types accepted S16 S32 S64. */
21108 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21109 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21110 /* Right shift narrowing. Types accepted I16 I32 I64. */
21111 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21112 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21113 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21114 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
21115 /* CVT with optional immediate for fixed-point variant. */
21116 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
21117
21118 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
21119 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
21120
21121 /* Data processing, three registers of different lengths. */
21122 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
21123 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
21124 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
21125 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
21126 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
21127 /* If not scalar, fall back to neon_dyadic_long.
21128 Vector types as above, scalar types S16 S32 U16 U32. */
21129 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21130 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21131 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
21132 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21133 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21134 /* Dyadic, narrowing insns. Types I16 I32 I64. */
21135 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21136 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21137 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21138 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21139 /* Saturating doubling multiplies. Types S16 S32. */
21140 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21141 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21142 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21143 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
21144 S16 S32 U16 U32. */
21145 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
21146
21147 /* Extract. Size 8. */
21148 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
21149 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
21150
21151 /* Two registers, miscellaneous. */
21152 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
21153 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
21154 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
21155 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
21156 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
21157 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
21158 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
21159 /* Vector replicate. Sizes 8 16 32. */
21160 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
21161 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
21162 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
21163 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
21164 /* VMOVN. Types I16 I32 I64. */
21165 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
21166 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21167 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
21168 /* VQMOVUN. Types S16 S32 S64. */
21169 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
21170 /* VZIP / VUZP. Sizes 8 16 32. */
21171 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21172 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21173 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21174 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21175 /* VQABS / VQNEG. Types S8 S16 S32. */
21176 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21177 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21178 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21179 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21180 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21181 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21182 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21183 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21184 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
21185 /* Reciprocal estimates. Types U32 F16 F32. */
21186 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21187 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21188 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21189 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21190 /* VCLS. Types S8 S16 S32. */
21191 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21192 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21193 /* VCLZ. Types I8 I16 I32. */
21194 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21195 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21196 /* VCNT. Size 8. */
21197 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21198 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21199 /* Two address, untyped. */
21200 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21201 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21202 /* VTRN. Sizes 8 16 32. */
21203 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21204 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
21205
21206 /* Table lookup. Size 8. */
21207 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21208 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21209
21210 #undef THUMB_VARIANT
21211 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21212 #undef ARM_VARIANT
21213 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21214
21215 /* Neon element/structure load/store. */
21216 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21217 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21218 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21219 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21220 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21221 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21222 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21223 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21224
21225 #undef THUMB_VARIANT
21226 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
21227 #undef ARM_VARIANT
21228 #define ARM_VARIANT & fpu_vfp_ext_v3xd
21229 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21230 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21231 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21232 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21233 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21234 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21235 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21236 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21237 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21238
21239 #undef THUMB_VARIANT
21240 #define THUMB_VARIANT & fpu_vfp_ext_v3
21241 #undef ARM_VARIANT
21242 #define ARM_VARIANT & fpu_vfp_ext_v3
21243
21244 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21245 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21246 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21247 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21248 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21249 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21250 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21251 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21252 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21253
21254 #undef ARM_VARIANT
21255 #define ARM_VARIANT & fpu_vfp_ext_fma
21256 #undef THUMB_VARIANT
21257 #define THUMB_VARIANT & fpu_vfp_ext_fma
21258 /* Mnemonics shared by Neon and VFP. These are included in the
21259 VFP FMA variant; NEON and VFP FMA always includes the NEON
21260 FMA instructions. */
21261 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21262 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21263 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21264 the v form should always be used. */
21265 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21266 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21267 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21268 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21269 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21270 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21271
21272 #undef THUMB_VARIANT
21273 #undef ARM_VARIANT
21274 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21275
21276 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21277 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21278 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21279 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21280 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21281 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21282 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21283 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
21284
21285 #undef ARM_VARIANT
21286 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21287
21288 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21289 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21290 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21291 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21292 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21293 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21294 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21295 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21296 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
21297 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21298 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21299 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21300 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21301 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21302 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21303 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21304 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21305 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21306 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21307 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21308 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21309 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21310 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21311 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21312 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21313 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21314 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21315 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21316 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21317 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21318 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21319 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21320 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21321 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21322 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21323 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21324 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21325 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21326 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21327 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21328 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21329 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21330 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21331 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21332 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21333 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21334 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
21335 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21336 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21337 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21338 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21339 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21340 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21341 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21342 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21343 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21344 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21345 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21346 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21347 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21348 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21349 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21350 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21351 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21352 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21353 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21354 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21355 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21356 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21357 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21358 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21359 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21360 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21361 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21362 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21363 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21364 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21365 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21366 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21367 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21368 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21369 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21370 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21371 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21372 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21373 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21374 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21375 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21376 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21377 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21378 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21379 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21380 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21381 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21382 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21383 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21384 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21385 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21386 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21387 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21388 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21389 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21390 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21391 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21392 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21393 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21394 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21395 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21396 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21397 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21398 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21399 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21400 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21401 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21402 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21403 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21404 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21405 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21406 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21407 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21408 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21409 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21410 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21411 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21412 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21413 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21414 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21415 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21416 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21417 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21418 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21419 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21420 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21421 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21422 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21423 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21424 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21425 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21426 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21427 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21428 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21429 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21430 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21431 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21432 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21433 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21434 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21435 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21436 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21437 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21438 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21439 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21440 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21441 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21442 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21443 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21444 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21445 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21446 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21447 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21448 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21449 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
21450
21451 #undef ARM_VARIANT
21452 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21453
21454 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21455 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21456 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21457 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21458 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21459 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21460 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21461 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21462 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21463 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21464 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21465 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21466 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21467 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21468 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21469 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21470 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21471 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21472 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21473 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21474 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21475 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21476 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21477 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21478 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21479 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21480 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21481 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21482 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21483 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21484 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21485 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21486 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21487 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21488 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21489 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21490 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21491 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21492 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21493 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21494 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21495 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21496 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21497 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21498 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21499 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21500 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21501 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21502 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21503 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21504 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21505 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21506 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21507 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21508 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21509 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21510 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21511
21512 #undef ARM_VARIANT
21513 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21514
21515 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21516 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21517 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21518 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21519 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21520 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21521 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21522 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21523 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21524 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21525 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21526 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21527 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21528 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
21529 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21530 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21531 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21532 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21533 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21534 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21535 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21536 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21537 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21538 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21539 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21540 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21541 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21542 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
21543 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21544 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21545 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21546 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21547 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21548 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
21549 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21550 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21551 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21552 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21553 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21554 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21555 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21556 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
21557 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21558 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21559 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21560 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21561 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21562 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21563 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21564 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21565 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21566 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21567 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21568 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21569 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21570 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21571 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21572 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21573 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21574 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21575 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21576 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21577 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21578 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21579 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21580 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21581 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21582 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21583 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21584 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21585 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21586 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21587 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21588 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21589 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21590 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21591
21592 /* ARMv8.5-A instructions. */
21593 #undef ARM_VARIANT
21594 #define ARM_VARIANT & arm_ext_sb
21595 #undef THUMB_VARIANT
21596 #define THUMB_VARIANT & arm_ext_sb
21597 TUF("sb", 57ff070, f3bf8f70, 0, (), noargs, noargs),
21598
21599 #undef ARM_VARIANT
21600 #define ARM_VARIANT & arm_ext_predres
21601 #undef THUMB_VARIANT
21602 #define THUMB_VARIANT & arm_ext_predres
21603 CE("cfprctx", e070f93, 1, (RRnpc), rd),
21604 CE("dvprctx", e070fb3, 1, (RRnpc), rd),
21605 CE("cpprctx", e070ff3, 1, (RRnpc), rd),
21606
21607 /* ARMv8-M instructions. */
21608 #undef ARM_VARIANT
21609 #define ARM_VARIANT NULL
21610 #undef THUMB_VARIANT
21611 #define THUMB_VARIANT & arm_ext_v8m
21612 ToU("sg", e97fe97f, 0, (), noargs),
21613 ToC("blxns", 4784, 1, (RRnpc), t_blx),
21614 ToC("bxns", 4704, 1, (RRnpc), t_bx),
21615 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
21616 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
21617 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
21618 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
21619
21620 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21621 instructions behave as nop if no VFP is present. */
21622 #undef THUMB_VARIANT
21623 #define THUMB_VARIANT & arm_ext_v8m_main
21624 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
21625 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
21626 };
21627 #undef ARM_VARIANT
21628 #undef THUMB_VARIANT
21629 #undef TCE
21630 #undef TUE
21631 #undef TUF
21632 #undef TCC
21633 #undef cCE
21634 #undef cCL
21635 #undef C3E
21636 #undef CE
21637 #undef CM
21638 #undef UE
21639 #undef UF
21640 #undef UT
21641 #undef NUF
21642 #undef nUF
21643 #undef NCE
21644 #undef nCE
21645 #undef OPS0
21646 #undef OPS1
21647 #undef OPS2
21648 #undef OPS3
21649 #undef OPS4
21650 #undef OPS5
21651 #undef OPS6
21652 #undef do_0
21653 \f
21654 /* MD interface: bits in the object file. */
21655
21656 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21657 for use in the a.out file, and stores them in the array pointed to by buf.
21658 This knows about the endian-ness of the target machine and does
21659 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21660 2 (short) and 4 (long) Floating numbers are put out as a series of
21661 LITTLENUMS (shorts, here at least). */
21662
21663 void
21664 md_number_to_chars (char * buf, valueT val, int n)
21665 {
21666 if (target_big_endian)
21667 number_to_chars_bigendian (buf, val, n);
21668 else
21669 number_to_chars_littleendian (buf, val, n);
21670 }
21671
21672 static valueT
21673 md_chars_to_number (char * buf, int n)
21674 {
21675 valueT result = 0;
21676 unsigned char * where = (unsigned char *) buf;
21677
21678 if (target_big_endian)
21679 {
21680 while (n--)
21681 {
21682 result <<= 8;
21683 result |= (*where++ & 255);
21684 }
21685 }
21686 else
21687 {
21688 while (n--)
21689 {
21690 result <<= 8;
21691 result |= (where[n] & 255);
21692 }
21693 }
21694
21695 return result;
21696 }
21697
21698 /* MD interface: Sections. */
21699
21700 /* Calculate the maximum variable size (i.e., excluding fr_fix)
21701 that an rs_machine_dependent frag may reach. */
21702
21703 unsigned int
21704 arm_frag_max_var (fragS *fragp)
21705 {
21706 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21707 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21708
21709 Note that we generate relaxable instructions even for cases that don't
21710 really need it, like an immediate that's a trivial constant. So we're
21711 overestimating the instruction size for some of those cases. Rather
21712 than putting more intelligence here, it would probably be better to
21713 avoid generating a relaxation frag in the first place when it can be
21714 determined up front that a short instruction will suffice. */
21715
21716 gas_assert (fragp->fr_type == rs_machine_dependent);
21717 return INSN_SIZE;
21718 }
21719
21720 /* Estimate the size of a frag before relaxing. Assume everything fits in
21721 2 bytes. */
21722
21723 int
21724 md_estimate_size_before_relax (fragS * fragp,
21725 segT segtype ATTRIBUTE_UNUSED)
21726 {
21727 fragp->fr_var = 2;
21728 return 2;
21729 }
21730
21731 /* Convert a machine dependent frag. */
21732
21733 void
21734 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21735 {
21736 unsigned long insn;
21737 unsigned long old_op;
21738 char *buf;
21739 expressionS exp;
21740 fixS *fixp;
21741 int reloc_type;
21742 int pc_rel;
21743 int opcode;
21744
21745 buf = fragp->fr_literal + fragp->fr_fix;
21746
21747 old_op = bfd_get_16(abfd, buf);
21748 if (fragp->fr_symbol)
21749 {
21750 exp.X_op = O_symbol;
21751 exp.X_add_symbol = fragp->fr_symbol;
21752 }
21753 else
21754 {
21755 exp.X_op = O_constant;
21756 }
21757 exp.X_add_number = fragp->fr_offset;
21758 opcode = fragp->fr_subtype;
21759 switch (opcode)
21760 {
21761 case T_MNEM_ldr_pc:
21762 case T_MNEM_ldr_pc2:
21763 case T_MNEM_ldr_sp:
21764 case T_MNEM_str_sp:
21765 case T_MNEM_ldr:
21766 case T_MNEM_ldrb:
21767 case T_MNEM_ldrh:
21768 case T_MNEM_str:
21769 case T_MNEM_strb:
21770 case T_MNEM_strh:
21771 if (fragp->fr_var == 4)
21772 {
21773 insn = THUMB_OP32 (opcode);
21774 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21775 {
21776 insn |= (old_op & 0x700) << 4;
21777 }
21778 else
21779 {
21780 insn |= (old_op & 7) << 12;
21781 insn |= (old_op & 0x38) << 13;
21782 }
21783 insn |= 0x00000c00;
21784 put_thumb32_insn (buf, insn);
21785 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21786 }
21787 else
21788 {
21789 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21790 }
21791 pc_rel = (opcode == T_MNEM_ldr_pc2);
21792 break;
21793 case T_MNEM_adr:
21794 if (fragp->fr_var == 4)
21795 {
21796 insn = THUMB_OP32 (opcode);
21797 insn |= (old_op & 0xf0) << 4;
21798 put_thumb32_insn (buf, insn);
21799 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21800 }
21801 else
21802 {
21803 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21804 exp.X_add_number -= 4;
21805 }
21806 pc_rel = 1;
21807 break;
21808 case T_MNEM_mov:
21809 case T_MNEM_movs:
21810 case T_MNEM_cmp:
21811 case T_MNEM_cmn:
21812 if (fragp->fr_var == 4)
21813 {
21814 int r0off = (opcode == T_MNEM_mov
21815 || opcode == T_MNEM_movs) ? 0 : 8;
21816 insn = THUMB_OP32 (opcode);
21817 insn = (insn & 0xe1ffffff) | 0x10000000;
21818 insn |= (old_op & 0x700) << r0off;
21819 put_thumb32_insn (buf, insn);
21820 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21821 }
21822 else
21823 {
21824 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21825 }
21826 pc_rel = 0;
21827 break;
21828 case T_MNEM_b:
21829 if (fragp->fr_var == 4)
21830 {
21831 insn = THUMB_OP32(opcode);
21832 put_thumb32_insn (buf, insn);
21833 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21834 }
21835 else
21836 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21837 pc_rel = 1;
21838 break;
21839 case T_MNEM_bcond:
21840 if (fragp->fr_var == 4)
21841 {
21842 insn = THUMB_OP32(opcode);
21843 insn |= (old_op & 0xf00) << 14;
21844 put_thumb32_insn (buf, insn);
21845 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21846 }
21847 else
21848 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21849 pc_rel = 1;
21850 break;
21851 case T_MNEM_add_sp:
21852 case T_MNEM_add_pc:
21853 case T_MNEM_inc_sp:
21854 case T_MNEM_dec_sp:
21855 if (fragp->fr_var == 4)
21856 {
21857 /* ??? Choose between add and addw. */
21858 insn = THUMB_OP32 (opcode);
21859 insn |= (old_op & 0xf0) << 4;
21860 put_thumb32_insn (buf, insn);
21861 if (opcode == T_MNEM_add_pc)
21862 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21863 else
21864 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21865 }
21866 else
21867 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21868 pc_rel = 0;
21869 break;
21870
21871 case T_MNEM_addi:
21872 case T_MNEM_addis:
21873 case T_MNEM_subi:
21874 case T_MNEM_subis:
21875 if (fragp->fr_var == 4)
21876 {
21877 insn = THUMB_OP32 (opcode);
21878 insn |= (old_op & 0xf0) << 4;
21879 insn |= (old_op & 0xf) << 16;
21880 put_thumb32_insn (buf, insn);
21881 if (insn & (1 << 20))
21882 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21883 else
21884 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21885 }
21886 else
21887 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21888 pc_rel = 0;
21889 break;
21890 default:
21891 abort ();
21892 }
21893 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21894 (enum bfd_reloc_code_real) reloc_type);
21895 fixp->fx_file = fragp->fr_file;
21896 fixp->fx_line = fragp->fr_line;
21897 fragp->fr_fix += fragp->fr_var;
21898
21899 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21900 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21901 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21902 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
21903 }
21904
21905 /* Return the size of a relaxable immediate operand instruction.
21906 SHIFT and SIZE specify the form of the allowable immediate. */
21907 static int
21908 relax_immediate (fragS *fragp, int size, int shift)
21909 {
21910 offsetT offset;
21911 offsetT mask;
21912 offsetT low;
21913
21914 /* ??? Should be able to do better than this. */
21915 if (fragp->fr_symbol)
21916 return 4;
21917
21918 low = (1 << shift) - 1;
21919 mask = (1 << (shift + size)) - (1 << shift);
21920 offset = fragp->fr_offset;
21921 /* Force misaligned offsets to 32-bit variant. */
21922 if (offset & low)
21923 return 4;
21924 if (offset & ~mask)
21925 return 4;
21926 return 2;
21927 }
21928
21929 /* Get the address of a symbol during relaxation. */
21930 static addressT
21931 relaxed_symbol_addr (fragS *fragp, long stretch)
21932 {
21933 fragS *sym_frag;
21934 addressT addr;
21935 symbolS *sym;
21936
21937 sym = fragp->fr_symbol;
21938 sym_frag = symbol_get_frag (sym);
21939 know (S_GET_SEGMENT (sym) != absolute_section
21940 || sym_frag == &zero_address_frag);
21941 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21942
21943 /* If frag has yet to be reached on this pass, assume it will
21944 move by STRETCH just as we did. If this is not so, it will
21945 be because some frag between grows, and that will force
21946 another pass. */
21947
21948 if (stretch != 0
21949 && sym_frag->relax_marker != fragp->relax_marker)
21950 {
21951 fragS *f;
21952
21953 /* Adjust stretch for any alignment frag. Note that if have
21954 been expanding the earlier code, the symbol may be
21955 defined in what appears to be an earlier frag. FIXME:
21956 This doesn't handle the fr_subtype field, which specifies
21957 a maximum number of bytes to skip when doing an
21958 alignment. */
21959 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21960 {
21961 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21962 {
21963 if (stretch < 0)
21964 stretch = - ((- stretch)
21965 & ~ ((1 << (int) f->fr_offset) - 1));
21966 else
21967 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21968 if (stretch == 0)
21969 break;
21970 }
21971 }
21972 if (f != NULL)
21973 addr += stretch;
21974 }
21975
21976 return addr;
21977 }
21978
21979 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
21980 load. */
21981 static int
21982 relax_adr (fragS *fragp, asection *sec, long stretch)
21983 {
21984 addressT addr;
21985 offsetT val;
21986
21987 /* Assume worst case for symbols not known to be in the same section. */
21988 if (fragp->fr_symbol == NULL
21989 || !S_IS_DEFINED (fragp->fr_symbol)
21990 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21991 || S_IS_WEAK (fragp->fr_symbol))
21992 return 4;
21993
21994 val = relaxed_symbol_addr (fragp, stretch);
21995 addr = fragp->fr_address + fragp->fr_fix;
21996 addr = (addr + 4) & ~3;
21997 /* Force misaligned targets to 32-bit variant. */
21998 if (val & 3)
21999 return 4;
22000 val -= addr;
22001 if (val < 0 || val > 1020)
22002 return 4;
22003 return 2;
22004 }
22005
22006 /* Return the size of a relaxable add/sub immediate instruction. */
22007 static int
22008 relax_addsub (fragS *fragp, asection *sec)
22009 {
22010 char *buf;
22011 int op;
22012
22013 buf = fragp->fr_literal + fragp->fr_fix;
22014 op = bfd_get_16(sec->owner, buf);
22015 if ((op & 0xf) == ((op >> 4) & 0xf))
22016 return relax_immediate (fragp, 8, 0);
22017 else
22018 return relax_immediate (fragp, 3, 0);
22019 }
22020
22021 /* Return TRUE iff the definition of symbol S could be pre-empted
22022 (overridden) at link or load time. */
22023 static bfd_boolean
22024 symbol_preemptible (symbolS *s)
22025 {
22026 /* Weak symbols can always be pre-empted. */
22027 if (S_IS_WEAK (s))
22028 return TRUE;
22029
22030 /* Non-global symbols cannot be pre-empted. */
22031 if (! S_IS_EXTERNAL (s))
22032 return FALSE;
22033
22034 #ifdef OBJ_ELF
22035 /* In ELF, a global symbol can be marked protected, or private. In that
22036 case it can't be pre-empted (other definitions in the same link unit
22037 would violate the ODR). */
22038 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
22039 return FALSE;
22040 #endif
22041
22042 /* Other global symbols might be pre-empted. */
22043 return TRUE;
22044 }
22045
22046 /* Return the size of a relaxable branch instruction. BITS is the
22047 size of the offset field in the narrow instruction. */
22048
22049 static int
22050 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
22051 {
22052 addressT addr;
22053 offsetT val;
22054 offsetT limit;
22055
22056 /* Assume worst case for symbols not known to be in the same section. */
22057 if (!S_IS_DEFINED (fragp->fr_symbol)
22058 || sec != S_GET_SEGMENT (fragp->fr_symbol)
22059 || S_IS_WEAK (fragp->fr_symbol))
22060 return 4;
22061
22062 #ifdef OBJ_ELF
22063 /* A branch to a function in ARM state will require interworking. */
22064 if (S_IS_DEFINED (fragp->fr_symbol)
22065 && ARM_IS_FUNC (fragp->fr_symbol))
22066 return 4;
22067 #endif
22068
22069 if (symbol_preemptible (fragp->fr_symbol))
22070 return 4;
22071
22072 val = relaxed_symbol_addr (fragp, stretch);
22073 addr = fragp->fr_address + fragp->fr_fix + 4;
22074 val -= addr;
22075
22076 /* Offset is a signed value *2 */
22077 limit = 1 << bits;
22078 if (val >= limit || val < -limit)
22079 return 4;
22080 return 2;
22081 }
22082
22083
22084 /* Relax a machine dependent frag. This returns the amount by which
22085 the current size of the frag should change. */
22086
22087 int
22088 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
22089 {
22090 int oldsize;
22091 int newsize;
22092
22093 oldsize = fragp->fr_var;
22094 switch (fragp->fr_subtype)
22095 {
22096 case T_MNEM_ldr_pc2:
22097 newsize = relax_adr (fragp, sec, stretch);
22098 break;
22099 case T_MNEM_ldr_pc:
22100 case T_MNEM_ldr_sp:
22101 case T_MNEM_str_sp:
22102 newsize = relax_immediate (fragp, 8, 2);
22103 break;
22104 case T_MNEM_ldr:
22105 case T_MNEM_str:
22106 newsize = relax_immediate (fragp, 5, 2);
22107 break;
22108 case T_MNEM_ldrh:
22109 case T_MNEM_strh:
22110 newsize = relax_immediate (fragp, 5, 1);
22111 break;
22112 case T_MNEM_ldrb:
22113 case T_MNEM_strb:
22114 newsize = relax_immediate (fragp, 5, 0);
22115 break;
22116 case T_MNEM_adr:
22117 newsize = relax_adr (fragp, sec, stretch);
22118 break;
22119 case T_MNEM_mov:
22120 case T_MNEM_movs:
22121 case T_MNEM_cmp:
22122 case T_MNEM_cmn:
22123 newsize = relax_immediate (fragp, 8, 0);
22124 break;
22125 case T_MNEM_b:
22126 newsize = relax_branch (fragp, sec, 11, stretch);
22127 break;
22128 case T_MNEM_bcond:
22129 newsize = relax_branch (fragp, sec, 8, stretch);
22130 break;
22131 case T_MNEM_add_sp:
22132 case T_MNEM_add_pc:
22133 newsize = relax_immediate (fragp, 8, 2);
22134 break;
22135 case T_MNEM_inc_sp:
22136 case T_MNEM_dec_sp:
22137 newsize = relax_immediate (fragp, 7, 2);
22138 break;
22139 case T_MNEM_addi:
22140 case T_MNEM_addis:
22141 case T_MNEM_subi:
22142 case T_MNEM_subis:
22143 newsize = relax_addsub (fragp, sec);
22144 break;
22145 default:
22146 abort ();
22147 }
22148
22149 fragp->fr_var = newsize;
22150 /* Freeze wide instructions that are at or before the same location as
22151 in the previous pass. This avoids infinite loops.
22152 Don't freeze them unconditionally because targets may be artificially
22153 misaligned by the expansion of preceding frags. */
22154 if (stretch <= 0 && newsize > 2)
22155 {
22156 md_convert_frag (sec->owner, sec, fragp);
22157 frag_wane (fragp);
22158 }
22159
22160 return newsize - oldsize;
22161 }
22162
22163 /* Round up a section size to the appropriate boundary. */
22164
22165 valueT
22166 md_section_align (segT segment ATTRIBUTE_UNUSED,
22167 valueT size)
22168 {
22169 return size;
22170 }
22171
22172 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22173 of an rs_align_code fragment. */
22174
22175 void
22176 arm_handle_align (fragS * fragP)
22177 {
22178 static unsigned char const arm_noop[2][2][4] =
22179 {
22180 { /* ARMv1 */
22181 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22182 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22183 },
22184 { /* ARMv6k */
22185 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22186 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22187 },
22188 };
22189 static unsigned char const thumb_noop[2][2][2] =
22190 {
22191 { /* Thumb-1 */
22192 {0xc0, 0x46}, /* LE */
22193 {0x46, 0xc0}, /* BE */
22194 },
22195 { /* Thumb-2 */
22196 {0x00, 0xbf}, /* LE */
22197 {0xbf, 0x00} /* BE */
22198 }
22199 };
22200 static unsigned char const wide_thumb_noop[2][4] =
22201 { /* Wide Thumb-2 */
22202 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22203 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22204 };
22205
22206 unsigned bytes, fix, noop_size;
22207 char * p;
22208 const unsigned char * noop;
22209 const unsigned char *narrow_noop = NULL;
22210 #ifdef OBJ_ELF
22211 enum mstate state;
22212 #endif
22213
22214 if (fragP->fr_type != rs_align_code)
22215 return;
22216
22217 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22218 p = fragP->fr_literal + fragP->fr_fix;
22219 fix = 0;
22220
22221 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22222 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
22223
22224 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
22225
22226 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
22227 {
22228 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22229 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
22230 {
22231 narrow_noop = thumb_noop[1][target_big_endian];
22232 noop = wide_thumb_noop[target_big_endian];
22233 }
22234 else
22235 noop = thumb_noop[0][target_big_endian];
22236 noop_size = 2;
22237 #ifdef OBJ_ELF
22238 state = MAP_THUMB;
22239 #endif
22240 }
22241 else
22242 {
22243 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22244 ? selected_cpu : arm_arch_none,
22245 arm_ext_v6k) != 0]
22246 [target_big_endian];
22247 noop_size = 4;
22248 #ifdef OBJ_ELF
22249 state = MAP_ARM;
22250 #endif
22251 }
22252
22253 fragP->fr_var = noop_size;
22254
22255 if (bytes & (noop_size - 1))
22256 {
22257 fix = bytes & (noop_size - 1);
22258 #ifdef OBJ_ELF
22259 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22260 #endif
22261 memset (p, 0, fix);
22262 p += fix;
22263 bytes -= fix;
22264 }
22265
22266 if (narrow_noop)
22267 {
22268 if (bytes & noop_size)
22269 {
22270 /* Insert a narrow noop. */
22271 memcpy (p, narrow_noop, noop_size);
22272 p += noop_size;
22273 bytes -= noop_size;
22274 fix += noop_size;
22275 }
22276
22277 /* Use wide noops for the remainder */
22278 noop_size = 4;
22279 }
22280
22281 while (bytes >= noop_size)
22282 {
22283 memcpy (p, noop, noop_size);
22284 p += noop_size;
22285 bytes -= noop_size;
22286 fix += noop_size;
22287 }
22288
22289 fragP->fr_fix += fix;
22290 }
22291
22292 /* Called from md_do_align. Used to create an alignment
22293 frag in a code section. */
22294
22295 void
22296 arm_frag_align_code (int n, int max)
22297 {
22298 char * p;
22299
22300 /* We assume that there will never be a requirement
22301 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
22302 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
22303 {
22304 char err_msg[128];
22305
22306 sprintf (err_msg,
22307 _("alignments greater than %d bytes not supported in .text sections."),
22308 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
22309 as_fatal ("%s", err_msg);
22310 }
22311
22312 p = frag_var (rs_align_code,
22313 MAX_MEM_FOR_RS_ALIGN_CODE,
22314 1,
22315 (relax_substateT) max,
22316 (symbolS *) NULL,
22317 (offsetT) n,
22318 (char *) NULL);
22319 *p = 0;
22320 }
22321
22322 /* Perform target specific initialisation of a frag.
22323 Note - despite the name this initialisation is not done when the frag
22324 is created, but only when its type is assigned. A frag can be created
22325 and used a long time before its type is set, so beware of assuming that
22326 this initialisation is performed first. */
22327
22328 #ifndef OBJ_ELF
22329 void
22330 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22331 {
22332 /* Record whether this frag is in an ARM or a THUMB area. */
22333 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22334 }
22335
22336 #else /* OBJ_ELF is defined. */
22337 void
22338 arm_init_frag (fragS * fragP, int max_chars)
22339 {
22340 bfd_boolean frag_thumb_mode;
22341
22342 /* If the current ARM vs THUMB mode has not already
22343 been recorded into this frag then do so now. */
22344 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
22345 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22346
22347 /* PR 21809: Do not set a mapping state for debug sections
22348 - it just confuses other tools. */
22349 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22350 return;
22351
22352 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
22353
22354 /* Record a mapping symbol for alignment frags. We will delete this
22355 later if the alignment ends up empty. */
22356 switch (fragP->fr_type)
22357 {
22358 case rs_align:
22359 case rs_align_test:
22360 case rs_fill:
22361 mapping_state_2 (MAP_DATA, max_chars);
22362 break;
22363 case rs_align_code:
22364 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
22365 break;
22366 default:
22367 break;
22368 }
22369 }
22370
22371 /* When we change sections we need to issue a new mapping symbol. */
22372
22373 void
22374 arm_elf_change_section (void)
22375 {
22376 /* Link an unlinked unwind index table section to the .text section. */
22377 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22378 && elf_linked_to_section (now_seg) == NULL)
22379 elf_linked_to_section (now_seg) = text_section;
22380 }
22381
22382 int
22383 arm_elf_section_type (const char * str, size_t len)
22384 {
22385 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22386 return SHT_ARM_EXIDX;
22387
22388 return -1;
22389 }
22390 \f
22391 /* Code to deal with unwinding tables. */
22392
22393 static void add_unwind_adjustsp (offsetT);
22394
22395 /* Generate any deferred unwind frame offset. */
22396
22397 static void
22398 flush_pending_unwind (void)
22399 {
22400 offsetT offset;
22401
22402 offset = unwind.pending_offset;
22403 unwind.pending_offset = 0;
22404 if (offset != 0)
22405 add_unwind_adjustsp (offset);
22406 }
22407
22408 /* Add an opcode to this list for this function. Two-byte opcodes should
22409 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22410 order. */
22411
22412 static void
22413 add_unwind_opcode (valueT op, int length)
22414 {
22415 /* Add any deferred stack adjustment. */
22416 if (unwind.pending_offset)
22417 flush_pending_unwind ();
22418
22419 unwind.sp_restored = 0;
22420
22421 if (unwind.opcode_count + length > unwind.opcode_alloc)
22422 {
22423 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22424 if (unwind.opcodes)
22425 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22426 unwind.opcode_alloc);
22427 else
22428 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
22429 }
22430 while (length > 0)
22431 {
22432 length--;
22433 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22434 op >>= 8;
22435 unwind.opcode_count++;
22436 }
22437 }
22438
22439 /* Add unwind opcodes to adjust the stack pointer. */
22440
22441 static void
22442 add_unwind_adjustsp (offsetT offset)
22443 {
22444 valueT op;
22445
22446 if (offset > 0x200)
22447 {
22448 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22449 char bytes[5];
22450 int n;
22451 valueT o;
22452
22453 /* Long form: 0xb2, uleb128. */
22454 /* This might not fit in a word so add the individual bytes,
22455 remembering the list is built in reverse order. */
22456 o = (valueT) ((offset - 0x204) >> 2);
22457 if (o == 0)
22458 add_unwind_opcode (0, 1);
22459
22460 /* Calculate the uleb128 encoding of the offset. */
22461 n = 0;
22462 while (o)
22463 {
22464 bytes[n] = o & 0x7f;
22465 o >>= 7;
22466 if (o)
22467 bytes[n] |= 0x80;
22468 n++;
22469 }
22470 /* Add the insn. */
22471 for (; n; n--)
22472 add_unwind_opcode (bytes[n - 1], 1);
22473 add_unwind_opcode (0xb2, 1);
22474 }
22475 else if (offset > 0x100)
22476 {
22477 /* Two short opcodes. */
22478 add_unwind_opcode (0x3f, 1);
22479 op = (offset - 0x104) >> 2;
22480 add_unwind_opcode (op, 1);
22481 }
22482 else if (offset > 0)
22483 {
22484 /* Short opcode. */
22485 op = (offset - 4) >> 2;
22486 add_unwind_opcode (op, 1);
22487 }
22488 else if (offset < 0)
22489 {
22490 offset = -offset;
22491 while (offset > 0x100)
22492 {
22493 add_unwind_opcode (0x7f, 1);
22494 offset -= 0x100;
22495 }
22496 op = ((offset - 4) >> 2) | 0x40;
22497 add_unwind_opcode (op, 1);
22498 }
22499 }
22500
22501 /* Finish the list of unwind opcodes for this function. */
22502
22503 static void
22504 finish_unwind_opcodes (void)
22505 {
22506 valueT op;
22507
22508 if (unwind.fp_used)
22509 {
22510 /* Adjust sp as necessary. */
22511 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22512 flush_pending_unwind ();
22513
22514 /* After restoring sp from the frame pointer. */
22515 op = 0x90 | unwind.fp_reg;
22516 add_unwind_opcode (op, 1);
22517 }
22518 else
22519 flush_pending_unwind ();
22520 }
22521
22522
22523 /* Start an exception table entry. If idx is nonzero this is an index table
22524 entry. */
22525
22526 static void
22527 start_unwind_section (const segT text_seg, int idx)
22528 {
22529 const char * text_name;
22530 const char * prefix;
22531 const char * prefix_once;
22532 const char * group_name;
22533 char * sec_name;
22534 int type;
22535 int flags;
22536 int linkonce;
22537
22538 if (idx)
22539 {
22540 prefix = ELF_STRING_ARM_unwind;
22541 prefix_once = ELF_STRING_ARM_unwind_once;
22542 type = SHT_ARM_EXIDX;
22543 }
22544 else
22545 {
22546 prefix = ELF_STRING_ARM_unwind_info;
22547 prefix_once = ELF_STRING_ARM_unwind_info_once;
22548 type = SHT_PROGBITS;
22549 }
22550
22551 text_name = segment_name (text_seg);
22552 if (streq (text_name, ".text"))
22553 text_name = "";
22554
22555 if (strncmp (text_name, ".gnu.linkonce.t.",
22556 strlen (".gnu.linkonce.t.")) == 0)
22557 {
22558 prefix = prefix_once;
22559 text_name += strlen (".gnu.linkonce.t.");
22560 }
22561
22562 sec_name = concat (prefix, text_name, (char *) NULL);
22563
22564 flags = SHF_ALLOC;
22565 linkonce = 0;
22566 group_name = 0;
22567
22568 /* Handle COMDAT group. */
22569 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
22570 {
22571 group_name = elf_group_name (text_seg);
22572 if (group_name == NULL)
22573 {
22574 as_bad (_("Group section `%s' has no group signature"),
22575 segment_name (text_seg));
22576 ignore_rest_of_line ();
22577 return;
22578 }
22579 flags |= SHF_GROUP;
22580 linkonce = 1;
22581 }
22582
22583 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22584 linkonce, 0);
22585
22586 /* Set the section link for index tables. */
22587 if (idx)
22588 elf_linked_to_section (now_seg) = text_seg;
22589 }
22590
22591
22592 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22593 personality routine data. Returns zero, or the index table value for
22594 an inline entry. */
22595
22596 static valueT
22597 create_unwind_entry (int have_data)
22598 {
22599 int size;
22600 addressT where;
22601 char *ptr;
22602 /* The current word of data. */
22603 valueT data;
22604 /* The number of bytes left in this word. */
22605 int n;
22606
22607 finish_unwind_opcodes ();
22608
22609 /* Remember the current text section. */
22610 unwind.saved_seg = now_seg;
22611 unwind.saved_subseg = now_subseg;
22612
22613 start_unwind_section (now_seg, 0);
22614
22615 if (unwind.personality_routine == NULL)
22616 {
22617 if (unwind.personality_index == -2)
22618 {
22619 if (have_data)
22620 as_bad (_("handlerdata in cantunwind frame"));
22621 return 1; /* EXIDX_CANTUNWIND. */
22622 }
22623
22624 /* Use a default personality routine if none is specified. */
22625 if (unwind.personality_index == -1)
22626 {
22627 if (unwind.opcode_count > 3)
22628 unwind.personality_index = 1;
22629 else
22630 unwind.personality_index = 0;
22631 }
22632
22633 /* Space for the personality routine entry. */
22634 if (unwind.personality_index == 0)
22635 {
22636 if (unwind.opcode_count > 3)
22637 as_bad (_("too many unwind opcodes for personality routine 0"));
22638
22639 if (!have_data)
22640 {
22641 /* All the data is inline in the index table. */
22642 data = 0x80;
22643 n = 3;
22644 while (unwind.opcode_count > 0)
22645 {
22646 unwind.opcode_count--;
22647 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22648 n--;
22649 }
22650
22651 /* Pad with "finish" opcodes. */
22652 while (n--)
22653 data = (data << 8) | 0xb0;
22654
22655 return data;
22656 }
22657 size = 0;
22658 }
22659 else
22660 /* We get two opcodes "free" in the first word. */
22661 size = unwind.opcode_count - 2;
22662 }
22663 else
22664 {
22665 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22666 if (unwind.personality_index != -1)
22667 {
22668 as_bad (_("attempt to recreate an unwind entry"));
22669 return 1;
22670 }
22671
22672 /* An extra byte is required for the opcode count. */
22673 size = unwind.opcode_count + 1;
22674 }
22675
22676 size = (size + 3) >> 2;
22677 if (size > 0xff)
22678 as_bad (_("too many unwind opcodes"));
22679
22680 frag_align (2, 0, 0);
22681 record_alignment (now_seg, 2);
22682 unwind.table_entry = expr_build_dot ();
22683
22684 /* Allocate the table entry. */
22685 ptr = frag_more ((size << 2) + 4);
22686 /* PR 13449: Zero the table entries in case some of them are not used. */
22687 memset (ptr, 0, (size << 2) + 4);
22688 where = frag_now_fix () - ((size << 2) + 4);
22689
22690 switch (unwind.personality_index)
22691 {
22692 case -1:
22693 /* ??? Should this be a PLT generating relocation? */
22694 /* Custom personality routine. */
22695 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22696 BFD_RELOC_ARM_PREL31);
22697
22698 where += 4;
22699 ptr += 4;
22700
22701 /* Set the first byte to the number of additional words. */
22702 data = size > 0 ? size - 1 : 0;
22703 n = 3;
22704 break;
22705
22706 /* ABI defined personality routines. */
22707 case 0:
22708 /* Three opcodes bytes are packed into the first word. */
22709 data = 0x80;
22710 n = 3;
22711 break;
22712
22713 case 1:
22714 case 2:
22715 /* The size and first two opcode bytes go in the first word. */
22716 data = ((0x80 + unwind.personality_index) << 8) | size;
22717 n = 2;
22718 break;
22719
22720 default:
22721 /* Should never happen. */
22722 abort ();
22723 }
22724
22725 /* Pack the opcodes into words (MSB first), reversing the list at the same
22726 time. */
22727 while (unwind.opcode_count > 0)
22728 {
22729 if (n == 0)
22730 {
22731 md_number_to_chars (ptr, data, 4);
22732 ptr += 4;
22733 n = 4;
22734 data = 0;
22735 }
22736 unwind.opcode_count--;
22737 n--;
22738 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22739 }
22740
22741 /* Finish off the last word. */
22742 if (n < 4)
22743 {
22744 /* Pad with "finish" opcodes. */
22745 while (n--)
22746 data = (data << 8) | 0xb0;
22747
22748 md_number_to_chars (ptr, data, 4);
22749 }
22750
22751 if (!have_data)
22752 {
22753 /* Add an empty descriptor if there is no user-specified data. */
22754 ptr = frag_more (4);
22755 md_number_to_chars (ptr, 0, 4);
22756 }
22757
22758 return 0;
22759 }
22760
22761
22762 /* Initialize the DWARF-2 unwind information for this procedure. */
22763
22764 void
22765 tc_arm_frame_initial_instructions (void)
22766 {
22767 cfi_add_CFA_def_cfa (REG_SP, 0);
22768 }
22769 #endif /* OBJ_ELF */
22770
22771 /* Convert REGNAME to a DWARF-2 register number. */
22772
22773 int
22774 tc_arm_regname_to_dw2regnum (char *regname)
22775 {
22776 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
22777 if (reg != FAIL)
22778 return reg;
22779
22780 /* PR 16694: Allow VFP registers as well. */
22781 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22782 if (reg != FAIL)
22783 return 64 + reg;
22784
22785 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22786 if (reg != FAIL)
22787 return reg + 256;
22788
22789 return FAIL;
22790 }
22791
22792 #ifdef TE_PE
22793 void
22794 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
22795 {
22796 expressionS exp;
22797
22798 exp.X_op = O_secrel;
22799 exp.X_add_symbol = symbol;
22800 exp.X_add_number = 0;
22801 emit_expr (&exp, size);
22802 }
22803 #endif
22804
22805 /* MD interface: Symbol and relocation handling. */
22806
22807 /* Return the address within the segment that a PC-relative fixup is
22808 relative to. For ARM, PC-relative fixups applied to instructions
22809 are generally relative to the location of the fixup plus 8 bytes.
22810 Thumb branches are offset by 4, and Thumb loads relative to PC
22811 require special handling. */
22812
22813 long
22814 md_pcrel_from_section (fixS * fixP, segT seg)
22815 {
22816 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22817
22818 /* If this is pc-relative and we are going to emit a relocation
22819 then we just want to put out any pipeline compensation that the linker
22820 will need. Otherwise we want to use the calculated base.
22821 For WinCE we skip the bias for externals as well, since this
22822 is how the MS ARM-CE assembler behaves and we want to be compatible. */
22823 if (fixP->fx_pcrel
22824 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
22825 || (arm_force_relocation (fixP)
22826 #ifdef TE_WINCE
22827 && !S_IS_EXTERNAL (fixP->fx_addsy)
22828 #endif
22829 )))
22830 base = 0;
22831
22832
22833 switch (fixP->fx_r_type)
22834 {
22835 /* PC relative addressing on the Thumb is slightly odd as the
22836 bottom two bits of the PC are forced to zero for the
22837 calculation. This happens *after* application of the
22838 pipeline offset. However, Thumb adrl already adjusts for
22839 this, so we need not do it again. */
22840 case BFD_RELOC_ARM_THUMB_ADD:
22841 return base & ~3;
22842
22843 case BFD_RELOC_ARM_THUMB_OFFSET:
22844 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22845 case BFD_RELOC_ARM_T32_ADD_PC12:
22846 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
22847 return (base + 4) & ~3;
22848
22849 /* Thumb branches are simply offset by +4. */
22850 case BFD_RELOC_THUMB_PCREL_BRANCH5:
22851 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22852 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22853 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22854 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22855 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22856 case BFD_RELOC_ARM_THUMB_BF17:
22857 return base + 4;
22858
22859 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22860 if (fixP->fx_addsy
22861 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22862 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22863 && ARM_IS_FUNC (fixP->fx_addsy)
22864 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22865 base = fixP->fx_where + fixP->fx_frag->fr_address;
22866 return base + 4;
22867
22868 /* BLX is like branches above, but forces the low two bits of PC to
22869 zero. */
22870 case BFD_RELOC_THUMB_PCREL_BLX:
22871 if (fixP->fx_addsy
22872 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22873 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22874 && THUMB_IS_FUNC (fixP->fx_addsy)
22875 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22876 base = fixP->fx_where + fixP->fx_frag->fr_address;
22877 return (base + 4) & ~3;
22878
22879 /* ARM mode branches are offset by +8. However, the Windows CE
22880 loader expects the relocation not to take this into account. */
22881 case BFD_RELOC_ARM_PCREL_BLX:
22882 if (fixP->fx_addsy
22883 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22884 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22885 && ARM_IS_FUNC (fixP->fx_addsy)
22886 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22887 base = fixP->fx_where + fixP->fx_frag->fr_address;
22888 return base + 8;
22889
22890 case BFD_RELOC_ARM_PCREL_CALL:
22891 if (fixP->fx_addsy
22892 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22893 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22894 && THUMB_IS_FUNC (fixP->fx_addsy)
22895 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22896 base = fixP->fx_where + fixP->fx_frag->fr_address;
22897 return base + 8;
22898
22899 case BFD_RELOC_ARM_PCREL_BRANCH:
22900 case BFD_RELOC_ARM_PCREL_JUMP:
22901 case BFD_RELOC_ARM_PLT32:
22902 #ifdef TE_WINCE
22903 /* When handling fixups immediately, because we have already
22904 discovered the value of a symbol, or the address of the frag involved
22905 we must account for the offset by +8, as the OS loader will never see the reloc.
22906 see fixup_segment() in write.c
22907 The S_IS_EXTERNAL test handles the case of global symbols.
22908 Those need the calculated base, not just the pipe compensation the linker will need. */
22909 if (fixP->fx_pcrel
22910 && fixP->fx_addsy != NULL
22911 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22912 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22913 return base + 8;
22914 return base;
22915 #else
22916 return base + 8;
22917 #endif
22918
22919
22920 /* ARM mode loads relative to PC are also offset by +8. Unlike
22921 branches, the Windows CE loader *does* expect the relocation
22922 to take this into account. */
22923 case BFD_RELOC_ARM_OFFSET_IMM:
22924 case BFD_RELOC_ARM_OFFSET_IMM8:
22925 case BFD_RELOC_ARM_HWLITERAL:
22926 case BFD_RELOC_ARM_LITERAL:
22927 case BFD_RELOC_ARM_CP_OFF_IMM:
22928 return base + 8;
22929
22930
22931 /* Other PC-relative relocations are un-offset. */
22932 default:
22933 return base;
22934 }
22935 }
22936
22937 static bfd_boolean flag_warn_syms = TRUE;
22938
22939 bfd_boolean
22940 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
22941 {
22942 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22943 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22944 does mean that the resulting code might be very confusing to the reader.
22945 Also this warning can be triggered if the user omits an operand before
22946 an immediate address, eg:
22947
22948 LDR =foo
22949
22950 GAS treats this as an assignment of the value of the symbol foo to a
22951 symbol LDR, and so (without this code) it will not issue any kind of
22952 warning or error message.
22953
22954 Note - ARM instructions are case-insensitive but the strings in the hash
22955 table are all stored in lower case, so we must first ensure that name is
22956 lower case too. */
22957 if (flag_warn_syms && arm_ops_hsh)
22958 {
22959 char * nbuf = strdup (name);
22960 char * p;
22961
22962 for (p = nbuf; *p; p++)
22963 *p = TOLOWER (*p);
22964 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22965 {
22966 static struct hash_control * already_warned = NULL;
22967
22968 if (already_warned == NULL)
22969 already_warned = hash_new ();
22970 /* Only warn about the symbol once. To keep the code
22971 simple we let hash_insert do the lookup for us. */
22972 if (hash_insert (already_warned, name, NULL) == NULL)
22973 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
22974 }
22975 else
22976 free (nbuf);
22977 }
22978
22979 return FALSE;
22980 }
22981
22982 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22983 Otherwise we have no need to default values of symbols. */
22984
22985 symbolS *
22986 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22987 {
22988 #ifdef OBJ_ELF
22989 if (name[0] == '_' && name[1] == 'G'
22990 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22991 {
22992 if (!GOT_symbol)
22993 {
22994 if (symbol_find (name))
22995 as_bad (_("GOT already in the symbol table"));
22996
22997 GOT_symbol = symbol_new (name, undefined_section,
22998 (valueT) 0, & zero_address_frag);
22999 }
23000
23001 return GOT_symbol;
23002 }
23003 #endif
23004
23005 return NULL;
23006 }
23007
23008 /* Subroutine of md_apply_fix. Check to see if an immediate can be
23009 computed as two separate immediate values, added together. We
23010 already know that this value cannot be computed by just one ARM
23011 instruction. */
23012
23013 static unsigned int
23014 validate_immediate_twopart (unsigned int val,
23015 unsigned int * highpart)
23016 {
23017 unsigned int a;
23018 unsigned int i;
23019
23020 for (i = 0; i < 32; i += 2)
23021 if (((a = rotate_left (val, i)) & 0xff) != 0)
23022 {
23023 if (a & 0xff00)
23024 {
23025 if (a & ~ 0xffff)
23026 continue;
23027 * highpart = (a >> 8) | ((i + 24) << 7);
23028 }
23029 else if (a & 0xff0000)
23030 {
23031 if (a & 0xff000000)
23032 continue;
23033 * highpart = (a >> 16) | ((i + 16) << 7);
23034 }
23035 else
23036 {
23037 gas_assert (a & 0xff000000);
23038 * highpart = (a >> 24) | ((i + 8) << 7);
23039 }
23040
23041 return (a & 0xff) | (i << 7);
23042 }
23043
23044 return FAIL;
23045 }
23046
23047 static int
23048 validate_offset_imm (unsigned int val, int hwse)
23049 {
23050 if ((hwse && val > 255) || val > 4095)
23051 return FAIL;
23052 return val;
23053 }
23054
23055 /* Subroutine of md_apply_fix. Do those data_ops which can take a
23056 negative immediate constant by altering the instruction. A bit of
23057 a hack really.
23058 MOV <-> MVN
23059 AND <-> BIC
23060 ADC <-> SBC
23061 by inverting the second operand, and
23062 ADD <-> SUB
23063 CMP <-> CMN
23064 by negating the second operand. */
23065
23066 static int
23067 negate_data_op (unsigned long * instruction,
23068 unsigned long value)
23069 {
23070 int op, new_inst;
23071 unsigned long negated, inverted;
23072
23073 negated = encode_arm_immediate (-value);
23074 inverted = encode_arm_immediate (~value);
23075
23076 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
23077 switch (op)
23078 {
23079 /* First negates. */
23080 case OPCODE_SUB: /* ADD <-> SUB */
23081 new_inst = OPCODE_ADD;
23082 value = negated;
23083 break;
23084
23085 case OPCODE_ADD:
23086 new_inst = OPCODE_SUB;
23087 value = negated;
23088 break;
23089
23090 case OPCODE_CMP: /* CMP <-> CMN */
23091 new_inst = OPCODE_CMN;
23092 value = negated;
23093 break;
23094
23095 case OPCODE_CMN:
23096 new_inst = OPCODE_CMP;
23097 value = negated;
23098 break;
23099
23100 /* Now Inverted ops. */
23101 case OPCODE_MOV: /* MOV <-> MVN */
23102 new_inst = OPCODE_MVN;
23103 value = inverted;
23104 break;
23105
23106 case OPCODE_MVN:
23107 new_inst = OPCODE_MOV;
23108 value = inverted;
23109 break;
23110
23111 case OPCODE_AND: /* AND <-> BIC */
23112 new_inst = OPCODE_BIC;
23113 value = inverted;
23114 break;
23115
23116 case OPCODE_BIC:
23117 new_inst = OPCODE_AND;
23118 value = inverted;
23119 break;
23120
23121 case OPCODE_ADC: /* ADC <-> SBC */
23122 new_inst = OPCODE_SBC;
23123 value = inverted;
23124 break;
23125
23126 case OPCODE_SBC:
23127 new_inst = OPCODE_ADC;
23128 value = inverted;
23129 break;
23130
23131 /* We cannot do anything. */
23132 default:
23133 return FAIL;
23134 }
23135
23136 if (value == (unsigned) FAIL)
23137 return FAIL;
23138
23139 *instruction &= OPCODE_MASK;
23140 *instruction |= new_inst << DATA_OP_SHIFT;
23141 return value;
23142 }
23143
23144 /* Like negate_data_op, but for Thumb-2. */
23145
23146 static unsigned int
23147 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
23148 {
23149 int op, new_inst;
23150 int rd;
23151 unsigned int negated, inverted;
23152
23153 negated = encode_thumb32_immediate (-value);
23154 inverted = encode_thumb32_immediate (~value);
23155
23156 rd = (*instruction >> 8) & 0xf;
23157 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
23158 switch (op)
23159 {
23160 /* ADD <-> SUB. Includes CMP <-> CMN. */
23161 case T2_OPCODE_SUB:
23162 new_inst = T2_OPCODE_ADD;
23163 value = negated;
23164 break;
23165
23166 case T2_OPCODE_ADD:
23167 new_inst = T2_OPCODE_SUB;
23168 value = negated;
23169 break;
23170
23171 /* ORR <-> ORN. Includes MOV <-> MVN. */
23172 case T2_OPCODE_ORR:
23173 new_inst = T2_OPCODE_ORN;
23174 value = inverted;
23175 break;
23176
23177 case T2_OPCODE_ORN:
23178 new_inst = T2_OPCODE_ORR;
23179 value = inverted;
23180 break;
23181
23182 /* AND <-> BIC. TST has no inverted equivalent. */
23183 case T2_OPCODE_AND:
23184 new_inst = T2_OPCODE_BIC;
23185 if (rd == 15)
23186 value = FAIL;
23187 else
23188 value = inverted;
23189 break;
23190
23191 case T2_OPCODE_BIC:
23192 new_inst = T2_OPCODE_AND;
23193 value = inverted;
23194 break;
23195
23196 /* ADC <-> SBC */
23197 case T2_OPCODE_ADC:
23198 new_inst = T2_OPCODE_SBC;
23199 value = inverted;
23200 break;
23201
23202 case T2_OPCODE_SBC:
23203 new_inst = T2_OPCODE_ADC;
23204 value = inverted;
23205 break;
23206
23207 /* We cannot do anything. */
23208 default:
23209 return FAIL;
23210 }
23211
23212 if (value == (unsigned int)FAIL)
23213 return FAIL;
23214
23215 *instruction &= T2_OPCODE_MASK;
23216 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23217 return value;
23218 }
23219
23220 /* Read a 32-bit thumb instruction from buf. */
23221
23222 static unsigned long
23223 get_thumb32_insn (char * buf)
23224 {
23225 unsigned long insn;
23226 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23227 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23228
23229 return insn;
23230 }
23231
23232 /* We usually want to set the low bit on the address of thumb function
23233 symbols. In particular .word foo - . should have the low bit set.
23234 Generic code tries to fold the difference of two symbols to
23235 a constant. Prevent this and force a relocation when the first symbols
23236 is a thumb function. */
23237
23238 bfd_boolean
23239 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23240 {
23241 if (op == O_subtract
23242 && l->X_op == O_symbol
23243 && r->X_op == O_symbol
23244 && THUMB_IS_FUNC (l->X_add_symbol))
23245 {
23246 l->X_op = O_subtract;
23247 l->X_op_symbol = r->X_add_symbol;
23248 l->X_add_number -= r->X_add_number;
23249 return TRUE;
23250 }
23251
23252 /* Process as normal. */
23253 return FALSE;
23254 }
23255
23256 /* Encode Thumb2 unconditional branches and calls. The encoding
23257 for the 2 are identical for the immediate values. */
23258
23259 static void
23260 encode_thumb2_b_bl_offset (char * buf, offsetT value)
23261 {
23262 #define T2I1I2MASK ((1 << 13) | (1 << 11))
23263 offsetT newval;
23264 offsetT newval2;
23265 addressT S, I1, I2, lo, hi;
23266
23267 S = (value >> 24) & 0x01;
23268 I1 = (value >> 23) & 0x01;
23269 I2 = (value >> 22) & 0x01;
23270 hi = (value >> 12) & 0x3ff;
23271 lo = (value >> 1) & 0x7ff;
23272 newval = md_chars_to_number (buf, THUMB_SIZE);
23273 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23274 newval |= (S << 10) | hi;
23275 newval2 &= ~T2I1I2MASK;
23276 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23277 md_number_to_chars (buf, newval, THUMB_SIZE);
23278 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23279 }
23280
23281 void
23282 md_apply_fix (fixS * fixP,
23283 valueT * valP,
23284 segT seg)
23285 {
23286 offsetT value = * valP;
23287 offsetT newval;
23288 unsigned int newimm;
23289 unsigned long temp;
23290 int sign;
23291 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
23292
23293 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
23294
23295 /* Note whether this will delete the relocation. */
23296
23297 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23298 fixP->fx_done = 1;
23299
23300 /* On a 64-bit host, silently truncate 'value' to 32 bits for
23301 consistency with the behaviour on 32-bit hosts. Remember value
23302 for emit_reloc. */
23303 value &= 0xffffffff;
23304 value ^= 0x80000000;
23305 value -= 0x80000000;
23306
23307 *valP = value;
23308 fixP->fx_addnumber = value;
23309
23310 /* Same treatment for fixP->fx_offset. */
23311 fixP->fx_offset &= 0xffffffff;
23312 fixP->fx_offset ^= 0x80000000;
23313 fixP->fx_offset -= 0x80000000;
23314
23315 switch (fixP->fx_r_type)
23316 {
23317 case BFD_RELOC_NONE:
23318 /* This will need to go in the object file. */
23319 fixP->fx_done = 0;
23320 break;
23321
23322 case BFD_RELOC_ARM_IMMEDIATE:
23323 /* We claim that this fixup has been processed here,
23324 even if in fact we generate an error because we do
23325 not have a reloc for it, so tc_gen_reloc will reject it. */
23326 fixP->fx_done = 1;
23327
23328 if (fixP->fx_addsy)
23329 {
23330 const char *msg = 0;
23331
23332 if (! S_IS_DEFINED (fixP->fx_addsy))
23333 msg = _("undefined symbol %s used as an immediate value");
23334 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23335 msg = _("symbol %s is in a different section");
23336 else if (S_IS_WEAK (fixP->fx_addsy))
23337 msg = _("symbol %s is weak and may be overridden later");
23338
23339 if (msg)
23340 {
23341 as_bad_where (fixP->fx_file, fixP->fx_line,
23342 msg, S_GET_NAME (fixP->fx_addsy));
23343 break;
23344 }
23345 }
23346
23347 temp = md_chars_to_number (buf, INSN_SIZE);
23348
23349 /* If the offset is negative, we should use encoding A2 for ADR. */
23350 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23351 newimm = negate_data_op (&temp, value);
23352 else
23353 {
23354 newimm = encode_arm_immediate (value);
23355
23356 /* If the instruction will fail, see if we can fix things up by
23357 changing the opcode. */
23358 if (newimm == (unsigned int) FAIL)
23359 newimm = negate_data_op (&temp, value);
23360 /* MOV accepts both ARM modified immediate (A1 encoding) and
23361 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23362 When disassembling, MOV is preferred when there is no encoding
23363 overlap. */
23364 if (newimm == (unsigned int) FAIL
23365 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23366 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23367 && !((temp >> SBIT_SHIFT) & 0x1)
23368 && value >= 0 && value <= 0xffff)
23369 {
23370 /* Clear bits[23:20] to change encoding from A1 to A2. */
23371 temp &= 0xff0fffff;
23372 /* Encoding high 4bits imm. Code below will encode the remaining
23373 low 12bits. */
23374 temp |= (value & 0x0000f000) << 4;
23375 newimm = value & 0x00000fff;
23376 }
23377 }
23378
23379 if (newimm == (unsigned int) FAIL)
23380 {
23381 as_bad_where (fixP->fx_file, fixP->fx_line,
23382 _("invalid constant (%lx) after fixup"),
23383 (unsigned long) value);
23384 break;
23385 }
23386
23387 newimm |= (temp & 0xfffff000);
23388 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23389 break;
23390
23391 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23392 {
23393 unsigned int highpart = 0;
23394 unsigned int newinsn = 0xe1a00000; /* nop. */
23395
23396 if (fixP->fx_addsy)
23397 {
23398 const char *msg = 0;
23399
23400 if (! S_IS_DEFINED (fixP->fx_addsy))
23401 msg = _("undefined symbol %s used as an immediate value");
23402 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23403 msg = _("symbol %s is in a different section");
23404 else if (S_IS_WEAK (fixP->fx_addsy))
23405 msg = _("symbol %s is weak and may be overridden later");
23406
23407 if (msg)
23408 {
23409 as_bad_where (fixP->fx_file, fixP->fx_line,
23410 msg, S_GET_NAME (fixP->fx_addsy));
23411 break;
23412 }
23413 }
23414
23415 newimm = encode_arm_immediate (value);
23416 temp = md_chars_to_number (buf, INSN_SIZE);
23417
23418 /* If the instruction will fail, see if we can fix things up by
23419 changing the opcode. */
23420 if (newimm == (unsigned int) FAIL
23421 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23422 {
23423 /* No ? OK - try using two ADD instructions to generate
23424 the value. */
23425 newimm = validate_immediate_twopart (value, & highpart);
23426
23427 /* Yes - then make sure that the second instruction is
23428 also an add. */
23429 if (newimm != (unsigned int) FAIL)
23430 newinsn = temp;
23431 /* Still No ? Try using a negated value. */
23432 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23433 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23434 /* Otherwise - give up. */
23435 else
23436 {
23437 as_bad_where (fixP->fx_file, fixP->fx_line,
23438 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23439 (long) value);
23440 break;
23441 }
23442
23443 /* Replace the first operand in the 2nd instruction (which
23444 is the PC) with the destination register. We have
23445 already added in the PC in the first instruction and we
23446 do not want to do it again. */
23447 newinsn &= ~ 0xf0000;
23448 newinsn |= ((newinsn & 0x0f000) << 4);
23449 }
23450
23451 newimm |= (temp & 0xfffff000);
23452 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23453
23454 highpart |= (newinsn & 0xfffff000);
23455 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23456 }
23457 break;
23458
23459 case BFD_RELOC_ARM_OFFSET_IMM:
23460 if (!fixP->fx_done && seg->use_rela_p)
23461 value = 0;
23462 /* Fall through. */
23463
23464 case BFD_RELOC_ARM_LITERAL:
23465 sign = value > 0;
23466
23467 if (value < 0)
23468 value = - value;
23469
23470 if (validate_offset_imm (value, 0) == FAIL)
23471 {
23472 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23473 as_bad_where (fixP->fx_file, fixP->fx_line,
23474 _("invalid literal constant: pool needs to be closer"));
23475 else
23476 as_bad_where (fixP->fx_file, fixP->fx_line,
23477 _("bad immediate value for offset (%ld)"),
23478 (long) value);
23479 break;
23480 }
23481
23482 newval = md_chars_to_number (buf, INSN_SIZE);
23483 if (value == 0)
23484 newval &= 0xfffff000;
23485 else
23486 {
23487 newval &= 0xff7ff000;
23488 newval |= value | (sign ? INDEX_UP : 0);
23489 }
23490 md_number_to_chars (buf, newval, INSN_SIZE);
23491 break;
23492
23493 case BFD_RELOC_ARM_OFFSET_IMM8:
23494 case BFD_RELOC_ARM_HWLITERAL:
23495 sign = value > 0;
23496
23497 if (value < 0)
23498 value = - value;
23499
23500 if (validate_offset_imm (value, 1) == FAIL)
23501 {
23502 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23503 as_bad_where (fixP->fx_file, fixP->fx_line,
23504 _("invalid literal constant: pool needs to be closer"));
23505 else
23506 as_bad_where (fixP->fx_file, fixP->fx_line,
23507 _("bad immediate value for 8-bit offset (%ld)"),
23508 (long) value);
23509 break;
23510 }
23511
23512 newval = md_chars_to_number (buf, INSN_SIZE);
23513 if (value == 0)
23514 newval &= 0xfffff0f0;
23515 else
23516 {
23517 newval &= 0xff7ff0f0;
23518 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23519 }
23520 md_number_to_chars (buf, newval, INSN_SIZE);
23521 break;
23522
23523 case BFD_RELOC_ARM_T32_OFFSET_U8:
23524 if (value < 0 || value > 1020 || value % 4 != 0)
23525 as_bad_where (fixP->fx_file, fixP->fx_line,
23526 _("bad immediate value for offset (%ld)"), (long) value);
23527 value /= 4;
23528
23529 newval = md_chars_to_number (buf+2, THUMB_SIZE);
23530 newval |= value;
23531 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23532 break;
23533
23534 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23535 /* This is a complicated relocation used for all varieties of Thumb32
23536 load/store instruction with immediate offset:
23537
23538 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
23539 *4, optional writeback(W)
23540 (doubleword load/store)
23541
23542 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23543 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23544 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23545 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23546 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23547
23548 Uppercase letters indicate bits that are already encoded at
23549 this point. Lowercase letters are our problem. For the
23550 second block of instructions, the secondary opcode nybble
23551 (bits 8..11) is present, and bit 23 is zero, even if this is
23552 a PC-relative operation. */
23553 newval = md_chars_to_number (buf, THUMB_SIZE);
23554 newval <<= 16;
23555 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
23556
23557 if ((newval & 0xf0000000) == 0xe0000000)
23558 {
23559 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23560 if (value >= 0)
23561 newval |= (1 << 23);
23562 else
23563 value = -value;
23564 if (value % 4 != 0)
23565 {
23566 as_bad_where (fixP->fx_file, fixP->fx_line,
23567 _("offset not a multiple of 4"));
23568 break;
23569 }
23570 value /= 4;
23571 if (value > 0xff)
23572 {
23573 as_bad_where (fixP->fx_file, fixP->fx_line,
23574 _("offset out of range"));
23575 break;
23576 }
23577 newval &= ~0xff;
23578 }
23579 else if ((newval & 0x000f0000) == 0x000f0000)
23580 {
23581 /* PC-relative, 12-bit offset. */
23582 if (value >= 0)
23583 newval |= (1 << 23);
23584 else
23585 value = -value;
23586 if (value > 0xfff)
23587 {
23588 as_bad_where (fixP->fx_file, fixP->fx_line,
23589 _("offset out of range"));
23590 break;
23591 }
23592 newval &= ~0xfff;
23593 }
23594 else if ((newval & 0x00000100) == 0x00000100)
23595 {
23596 /* Writeback: 8-bit, +/- offset. */
23597 if (value >= 0)
23598 newval |= (1 << 9);
23599 else
23600 value = -value;
23601 if (value > 0xff)
23602 {
23603 as_bad_where (fixP->fx_file, fixP->fx_line,
23604 _("offset out of range"));
23605 break;
23606 }
23607 newval &= ~0xff;
23608 }
23609 else if ((newval & 0x00000f00) == 0x00000e00)
23610 {
23611 /* T-instruction: positive 8-bit offset. */
23612 if (value < 0 || value > 0xff)
23613 {
23614 as_bad_where (fixP->fx_file, fixP->fx_line,
23615 _("offset out of range"));
23616 break;
23617 }
23618 newval &= ~0xff;
23619 newval |= value;
23620 }
23621 else
23622 {
23623 /* Positive 12-bit or negative 8-bit offset. */
23624 int limit;
23625 if (value >= 0)
23626 {
23627 newval |= (1 << 23);
23628 limit = 0xfff;
23629 }
23630 else
23631 {
23632 value = -value;
23633 limit = 0xff;
23634 }
23635 if (value > limit)
23636 {
23637 as_bad_where (fixP->fx_file, fixP->fx_line,
23638 _("offset out of range"));
23639 break;
23640 }
23641 newval &= ~limit;
23642 }
23643
23644 newval |= value;
23645 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23646 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23647 break;
23648
23649 case BFD_RELOC_ARM_SHIFT_IMM:
23650 newval = md_chars_to_number (buf, INSN_SIZE);
23651 if (((unsigned long) value) > 32
23652 || (value == 32
23653 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23654 {
23655 as_bad_where (fixP->fx_file, fixP->fx_line,
23656 _("shift expression is too large"));
23657 break;
23658 }
23659
23660 if (value == 0)
23661 /* Shifts of zero must be done as lsl. */
23662 newval &= ~0x60;
23663 else if (value == 32)
23664 value = 0;
23665 newval &= 0xfffff07f;
23666 newval |= (value & 0x1f) << 7;
23667 md_number_to_chars (buf, newval, INSN_SIZE);
23668 break;
23669
23670 case BFD_RELOC_ARM_T32_IMMEDIATE:
23671 case BFD_RELOC_ARM_T32_ADD_IMM:
23672 case BFD_RELOC_ARM_T32_IMM12:
23673 case BFD_RELOC_ARM_T32_ADD_PC12:
23674 /* We claim that this fixup has been processed here,
23675 even if in fact we generate an error because we do
23676 not have a reloc for it, so tc_gen_reloc will reject it. */
23677 fixP->fx_done = 1;
23678
23679 if (fixP->fx_addsy
23680 && ! S_IS_DEFINED (fixP->fx_addsy))
23681 {
23682 as_bad_where (fixP->fx_file, fixP->fx_line,
23683 _("undefined symbol %s used as an immediate value"),
23684 S_GET_NAME (fixP->fx_addsy));
23685 break;
23686 }
23687
23688 newval = md_chars_to_number (buf, THUMB_SIZE);
23689 newval <<= 16;
23690 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
23691
23692 newimm = FAIL;
23693 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23694 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23695 Thumb2 modified immediate encoding (T2). */
23696 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
23697 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23698 {
23699 newimm = encode_thumb32_immediate (value);
23700 if (newimm == (unsigned int) FAIL)
23701 newimm = thumb32_negate_data_op (&newval, value);
23702 }
23703 if (newimm == (unsigned int) FAIL)
23704 {
23705 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
23706 {
23707 /* Turn add/sum into addw/subw. */
23708 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23709 newval = (newval & 0xfeffffff) | 0x02000000;
23710 /* No flat 12-bit imm encoding for addsw/subsw. */
23711 if ((newval & 0x00100000) == 0)
23712 {
23713 /* 12 bit immediate for addw/subw. */
23714 if (value < 0)
23715 {
23716 value = -value;
23717 newval ^= 0x00a00000;
23718 }
23719 if (value > 0xfff)
23720 newimm = (unsigned int) FAIL;
23721 else
23722 newimm = value;
23723 }
23724 }
23725 else
23726 {
23727 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23728 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23729 disassembling, MOV is preferred when there is no encoding
23730 overlap. */
23731 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23732 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
23733 but with the Rn field [19:16] set to 1111. */
23734 && (((newval >> 16) & 0xf) == 0xf)
23735 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23736 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23737 && value >= 0 && value <= 0xffff)
23738 {
23739 /* Toggle bit[25] to change encoding from T2 to T3. */
23740 newval ^= 1 << 25;
23741 /* Clear bits[19:16]. */
23742 newval &= 0xfff0ffff;
23743 /* Encoding high 4bits imm. Code below will encode the
23744 remaining low 12bits. */
23745 newval |= (value & 0x0000f000) << 4;
23746 newimm = value & 0x00000fff;
23747 }
23748 }
23749 }
23750
23751 if (newimm == (unsigned int)FAIL)
23752 {
23753 as_bad_where (fixP->fx_file, fixP->fx_line,
23754 _("invalid constant (%lx) after fixup"),
23755 (unsigned long) value);
23756 break;
23757 }
23758
23759 newval |= (newimm & 0x800) << 15;
23760 newval |= (newimm & 0x700) << 4;
23761 newval |= (newimm & 0x0ff);
23762
23763 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23764 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23765 break;
23766
23767 case BFD_RELOC_ARM_SMC:
23768 if (((unsigned long) value) > 0xffff)
23769 as_bad_where (fixP->fx_file, fixP->fx_line,
23770 _("invalid smc expression"));
23771 newval = md_chars_to_number (buf, INSN_SIZE);
23772 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23773 md_number_to_chars (buf, newval, INSN_SIZE);
23774 break;
23775
23776 case BFD_RELOC_ARM_HVC:
23777 if (((unsigned long) value) > 0xffff)
23778 as_bad_where (fixP->fx_file, fixP->fx_line,
23779 _("invalid hvc expression"));
23780 newval = md_chars_to_number (buf, INSN_SIZE);
23781 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23782 md_number_to_chars (buf, newval, INSN_SIZE);
23783 break;
23784
23785 case BFD_RELOC_ARM_SWI:
23786 if (fixP->tc_fix_data != 0)
23787 {
23788 if (((unsigned long) value) > 0xff)
23789 as_bad_where (fixP->fx_file, fixP->fx_line,
23790 _("invalid swi expression"));
23791 newval = md_chars_to_number (buf, THUMB_SIZE);
23792 newval |= value;
23793 md_number_to_chars (buf, newval, THUMB_SIZE);
23794 }
23795 else
23796 {
23797 if (((unsigned long) value) > 0x00ffffff)
23798 as_bad_where (fixP->fx_file, fixP->fx_line,
23799 _("invalid swi expression"));
23800 newval = md_chars_to_number (buf, INSN_SIZE);
23801 newval |= value;
23802 md_number_to_chars (buf, newval, INSN_SIZE);
23803 }
23804 break;
23805
23806 case BFD_RELOC_ARM_MULTI:
23807 if (((unsigned long) value) > 0xffff)
23808 as_bad_where (fixP->fx_file, fixP->fx_line,
23809 _("invalid expression in load/store multiple"));
23810 newval = value | md_chars_to_number (buf, INSN_SIZE);
23811 md_number_to_chars (buf, newval, INSN_SIZE);
23812 break;
23813
23814 #ifdef OBJ_ELF
23815 case BFD_RELOC_ARM_PCREL_CALL:
23816
23817 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23818 && fixP->fx_addsy
23819 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23820 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23821 && THUMB_IS_FUNC (fixP->fx_addsy))
23822 /* Flip the bl to blx. This is a simple flip
23823 bit here because we generate PCREL_CALL for
23824 unconditional bls. */
23825 {
23826 newval = md_chars_to_number (buf, INSN_SIZE);
23827 newval = newval | 0x10000000;
23828 md_number_to_chars (buf, newval, INSN_SIZE);
23829 temp = 1;
23830 fixP->fx_done = 1;
23831 }
23832 else
23833 temp = 3;
23834 goto arm_branch_common;
23835
23836 case BFD_RELOC_ARM_PCREL_JUMP:
23837 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23838 && fixP->fx_addsy
23839 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23840 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23841 && THUMB_IS_FUNC (fixP->fx_addsy))
23842 {
23843 /* This would map to a bl<cond>, b<cond>,
23844 b<always> to a Thumb function. We
23845 need to force a relocation for this particular
23846 case. */
23847 newval = md_chars_to_number (buf, INSN_SIZE);
23848 fixP->fx_done = 0;
23849 }
23850 /* Fall through. */
23851
23852 case BFD_RELOC_ARM_PLT32:
23853 #endif
23854 case BFD_RELOC_ARM_PCREL_BRANCH:
23855 temp = 3;
23856 goto arm_branch_common;
23857
23858 case BFD_RELOC_ARM_PCREL_BLX:
23859
23860 temp = 1;
23861 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23862 && fixP->fx_addsy
23863 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23864 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23865 && ARM_IS_FUNC (fixP->fx_addsy))
23866 {
23867 /* Flip the blx to a bl and warn. */
23868 const char *name = S_GET_NAME (fixP->fx_addsy);
23869 newval = 0xeb000000;
23870 as_warn_where (fixP->fx_file, fixP->fx_line,
23871 _("blx to '%s' an ARM ISA state function changed to bl"),
23872 name);
23873 md_number_to_chars (buf, newval, INSN_SIZE);
23874 temp = 3;
23875 fixP->fx_done = 1;
23876 }
23877
23878 #ifdef OBJ_ELF
23879 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
23880 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
23881 #endif
23882
23883 arm_branch_common:
23884 /* We are going to store value (shifted right by two) in the
23885 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23886 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23887 also be clear. */
23888 if (value & temp)
23889 as_bad_where (fixP->fx_file, fixP->fx_line,
23890 _("misaligned branch destination"));
23891 if ((value & (offsetT)0xfe000000) != (offsetT)0
23892 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
23893 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23894
23895 if (fixP->fx_done || !seg->use_rela_p)
23896 {
23897 newval = md_chars_to_number (buf, INSN_SIZE);
23898 newval |= (value >> 2) & 0x00ffffff;
23899 /* Set the H bit on BLX instructions. */
23900 if (temp == 1)
23901 {
23902 if (value & 2)
23903 newval |= 0x01000000;
23904 else
23905 newval &= ~0x01000000;
23906 }
23907 md_number_to_chars (buf, newval, INSN_SIZE);
23908 }
23909 break;
23910
23911 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23912 /* CBZ can only branch forward. */
23913
23914 /* Attempts to use CBZ to branch to the next instruction
23915 (which, strictly speaking, are prohibited) will be turned into
23916 no-ops.
23917
23918 FIXME: It may be better to remove the instruction completely and
23919 perform relaxation. */
23920 if (value == -2)
23921 {
23922 newval = md_chars_to_number (buf, THUMB_SIZE);
23923 newval = 0xbf00; /* NOP encoding T1 */
23924 md_number_to_chars (buf, newval, THUMB_SIZE);
23925 }
23926 else
23927 {
23928 if (value & ~0x7e)
23929 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23930
23931 if (fixP->fx_done || !seg->use_rela_p)
23932 {
23933 newval = md_chars_to_number (buf, THUMB_SIZE);
23934 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23935 md_number_to_chars (buf, newval, THUMB_SIZE);
23936 }
23937 }
23938 break;
23939
23940 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
23941 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
23942 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23943
23944 if (fixP->fx_done || !seg->use_rela_p)
23945 {
23946 newval = md_chars_to_number (buf, THUMB_SIZE);
23947 newval |= (value & 0x1ff) >> 1;
23948 md_number_to_chars (buf, newval, THUMB_SIZE);
23949 }
23950 break;
23951
23952 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
23953 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
23954 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23955
23956 if (fixP->fx_done || !seg->use_rela_p)
23957 {
23958 newval = md_chars_to_number (buf, THUMB_SIZE);
23959 newval |= (value & 0xfff) >> 1;
23960 md_number_to_chars (buf, newval, THUMB_SIZE);
23961 }
23962 break;
23963
23964 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23965 if (fixP->fx_addsy
23966 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23967 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23968 && ARM_IS_FUNC (fixP->fx_addsy)
23969 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23970 {
23971 /* Force a relocation for a branch 20 bits wide. */
23972 fixP->fx_done = 0;
23973 }
23974 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
23975 as_bad_where (fixP->fx_file, fixP->fx_line,
23976 _("conditional branch out of range"));
23977
23978 if (fixP->fx_done || !seg->use_rela_p)
23979 {
23980 offsetT newval2;
23981 addressT S, J1, J2, lo, hi;
23982
23983 S = (value & 0x00100000) >> 20;
23984 J2 = (value & 0x00080000) >> 19;
23985 J1 = (value & 0x00040000) >> 18;
23986 hi = (value & 0x0003f000) >> 12;
23987 lo = (value & 0x00000ffe) >> 1;
23988
23989 newval = md_chars_to_number (buf, THUMB_SIZE);
23990 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23991 newval |= (S << 10) | hi;
23992 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23993 md_number_to_chars (buf, newval, THUMB_SIZE);
23994 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23995 }
23996 break;
23997
23998 case BFD_RELOC_THUMB_PCREL_BLX:
23999 /* If there is a blx from a thumb state function to
24000 another thumb function flip this to a bl and warn
24001 about it. */
24002
24003 if (fixP->fx_addsy
24004 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24005 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24006 && THUMB_IS_FUNC (fixP->fx_addsy))
24007 {
24008 const char *name = S_GET_NAME (fixP->fx_addsy);
24009 as_warn_where (fixP->fx_file, fixP->fx_line,
24010 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
24011 name);
24012 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24013 newval = newval | 0x1000;
24014 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
24015 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
24016 fixP->fx_done = 1;
24017 }
24018
24019
24020 goto thumb_bl_common;
24021
24022 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24023 /* A bl from Thumb state ISA to an internal ARM state function
24024 is converted to a blx. */
24025 if (fixP->fx_addsy
24026 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24027 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24028 && ARM_IS_FUNC (fixP->fx_addsy)
24029 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
24030 {
24031 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24032 newval = newval & ~0x1000;
24033 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
24034 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
24035 fixP->fx_done = 1;
24036 }
24037
24038 thumb_bl_common:
24039
24040 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
24041 /* For a BLX instruction, make sure that the relocation is rounded up
24042 to a word boundary. This follows the semantics of the instruction
24043 which specifies that bit 1 of the target address will come from bit
24044 1 of the base address. */
24045 value = (value + 3) & ~ 3;
24046
24047 #ifdef OBJ_ELF
24048 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
24049 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
24050 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
24051 #endif
24052
24053 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
24054 {
24055 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
24056 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24057 else if ((value & ~0x1ffffff)
24058 && ((value & ~0x1ffffff) != ~0x1ffffff))
24059 as_bad_where (fixP->fx_file, fixP->fx_line,
24060 _("Thumb2 branch out of range"));
24061 }
24062
24063 if (fixP->fx_done || !seg->use_rela_p)
24064 encode_thumb2_b_bl_offset (buf, value);
24065
24066 break;
24067
24068 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24069 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
24070 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
24071
24072 if (fixP->fx_done || !seg->use_rela_p)
24073 encode_thumb2_b_bl_offset (buf, value);
24074
24075 break;
24076
24077 case BFD_RELOC_8:
24078 if (fixP->fx_done || !seg->use_rela_p)
24079 *buf = value;
24080 break;
24081
24082 case BFD_RELOC_16:
24083 if (fixP->fx_done || !seg->use_rela_p)
24084 md_number_to_chars (buf, value, 2);
24085 break;
24086
24087 #ifdef OBJ_ELF
24088 case BFD_RELOC_ARM_TLS_CALL:
24089 case BFD_RELOC_ARM_THM_TLS_CALL:
24090 case BFD_RELOC_ARM_TLS_DESCSEQ:
24091 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
24092 case BFD_RELOC_ARM_TLS_GOTDESC:
24093 case BFD_RELOC_ARM_TLS_GD32:
24094 case BFD_RELOC_ARM_TLS_LE32:
24095 case BFD_RELOC_ARM_TLS_IE32:
24096 case BFD_RELOC_ARM_TLS_LDM32:
24097 case BFD_RELOC_ARM_TLS_LDO32:
24098 S_SET_THREAD_LOCAL (fixP->fx_addsy);
24099 break;
24100
24101 /* Same handling as above, but with the arm_fdpic guard. */
24102 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
24103 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
24104 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
24105 if (arm_fdpic)
24106 {
24107 S_SET_THREAD_LOCAL (fixP->fx_addsy);
24108 }
24109 else
24110 {
24111 as_bad_where (fixP->fx_file, fixP->fx_line,
24112 _("Relocation supported only in FDPIC mode"));
24113 }
24114 break;
24115
24116 case BFD_RELOC_ARM_GOT32:
24117 case BFD_RELOC_ARM_GOTOFF:
24118 break;
24119
24120 case BFD_RELOC_ARM_GOT_PREL:
24121 if (fixP->fx_done || !seg->use_rela_p)
24122 md_number_to_chars (buf, value, 4);
24123 break;
24124
24125 case BFD_RELOC_ARM_TARGET2:
24126 /* TARGET2 is not partial-inplace, so we need to write the
24127 addend here for REL targets, because it won't be written out
24128 during reloc processing later. */
24129 if (fixP->fx_done || !seg->use_rela_p)
24130 md_number_to_chars (buf, fixP->fx_offset, 4);
24131 break;
24132
24133 /* Relocations for FDPIC. */
24134 case BFD_RELOC_ARM_GOTFUNCDESC:
24135 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24136 case BFD_RELOC_ARM_FUNCDESC:
24137 if (arm_fdpic)
24138 {
24139 if (fixP->fx_done || !seg->use_rela_p)
24140 md_number_to_chars (buf, 0, 4);
24141 }
24142 else
24143 {
24144 as_bad_where (fixP->fx_file, fixP->fx_line,
24145 _("Relocation supported only in FDPIC mode"));
24146 }
24147 break;
24148 #endif
24149
24150 case BFD_RELOC_RVA:
24151 case BFD_RELOC_32:
24152 case BFD_RELOC_ARM_TARGET1:
24153 case BFD_RELOC_ARM_ROSEGREL32:
24154 case BFD_RELOC_ARM_SBREL32:
24155 case BFD_RELOC_32_PCREL:
24156 #ifdef TE_PE
24157 case BFD_RELOC_32_SECREL:
24158 #endif
24159 if (fixP->fx_done || !seg->use_rela_p)
24160 #ifdef TE_WINCE
24161 /* For WinCE we only do this for pcrel fixups. */
24162 if (fixP->fx_done || fixP->fx_pcrel)
24163 #endif
24164 md_number_to_chars (buf, value, 4);
24165 break;
24166
24167 #ifdef OBJ_ELF
24168 case BFD_RELOC_ARM_PREL31:
24169 if (fixP->fx_done || !seg->use_rela_p)
24170 {
24171 newval = md_chars_to_number (buf, 4) & 0x80000000;
24172 if ((value ^ (value >> 1)) & 0x40000000)
24173 {
24174 as_bad_where (fixP->fx_file, fixP->fx_line,
24175 _("rel31 relocation overflow"));
24176 }
24177 newval |= value & 0x7fffffff;
24178 md_number_to_chars (buf, newval, 4);
24179 }
24180 break;
24181 #endif
24182
24183 case BFD_RELOC_ARM_CP_OFF_IMM:
24184 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
24185 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
24186 newval = md_chars_to_number (buf, INSN_SIZE);
24187 else
24188 newval = get_thumb32_insn (buf);
24189 if ((newval & 0x0f200f00) == 0x0d000900)
24190 {
24191 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
24192 has permitted values that are multiples of 2, in the range 0
24193 to 510. */
24194 if (value < -510 || value > 510 || (value & 1))
24195 as_bad_where (fixP->fx_file, fixP->fx_line,
24196 _("co-processor offset out of range"));
24197 }
24198 else if (value < -1023 || value > 1023 || (value & 3))
24199 as_bad_where (fixP->fx_file, fixP->fx_line,
24200 _("co-processor offset out of range"));
24201 cp_off_common:
24202 sign = value > 0;
24203 if (value < 0)
24204 value = -value;
24205 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24206 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24207 newval = md_chars_to_number (buf, INSN_SIZE);
24208 else
24209 newval = get_thumb32_insn (buf);
24210 if (value == 0)
24211 newval &= 0xffffff00;
24212 else
24213 {
24214 newval &= 0xff7fff00;
24215 if ((newval & 0x0f200f00) == 0x0d000900)
24216 {
24217 /* This is a fp16 vstr/vldr.
24218
24219 It requires the immediate offset in the instruction is shifted
24220 left by 1 to be a half-word offset.
24221
24222 Here, left shift by 1 first, and later right shift by 2
24223 should get the right offset. */
24224 value <<= 1;
24225 }
24226 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24227 }
24228 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24229 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24230 md_number_to_chars (buf, newval, INSN_SIZE);
24231 else
24232 put_thumb32_insn (buf, newval);
24233 break;
24234
24235 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
24236 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
24237 if (value < -255 || value > 255)
24238 as_bad_where (fixP->fx_file, fixP->fx_line,
24239 _("co-processor offset out of range"));
24240 value *= 4;
24241 goto cp_off_common;
24242
24243 case BFD_RELOC_ARM_THUMB_OFFSET:
24244 newval = md_chars_to_number (buf, THUMB_SIZE);
24245 /* Exactly what ranges, and where the offset is inserted depends
24246 on the type of instruction, we can establish this from the
24247 top 4 bits. */
24248 switch (newval >> 12)
24249 {
24250 case 4: /* PC load. */
24251 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24252 forced to zero for these loads; md_pcrel_from has already
24253 compensated for this. */
24254 if (value & 3)
24255 as_bad_where (fixP->fx_file, fixP->fx_line,
24256 _("invalid offset, target not word aligned (0x%08lX)"),
24257 (((unsigned long) fixP->fx_frag->fr_address
24258 + (unsigned long) fixP->fx_where) & ~3)
24259 + (unsigned long) value);
24260
24261 if (value & ~0x3fc)
24262 as_bad_where (fixP->fx_file, fixP->fx_line,
24263 _("invalid offset, value too big (0x%08lX)"),
24264 (long) value);
24265
24266 newval |= value >> 2;
24267 break;
24268
24269 case 9: /* SP load/store. */
24270 if (value & ~0x3fc)
24271 as_bad_where (fixP->fx_file, fixP->fx_line,
24272 _("invalid offset, value too big (0x%08lX)"),
24273 (long) value);
24274 newval |= value >> 2;
24275 break;
24276
24277 case 6: /* Word load/store. */
24278 if (value & ~0x7c)
24279 as_bad_where (fixP->fx_file, fixP->fx_line,
24280 _("invalid offset, value too big (0x%08lX)"),
24281 (long) value);
24282 newval |= value << 4; /* 6 - 2. */
24283 break;
24284
24285 case 7: /* Byte load/store. */
24286 if (value & ~0x1f)
24287 as_bad_where (fixP->fx_file, fixP->fx_line,
24288 _("invalid offset, value too big (0x%08lX)"),
24289 (long) value);
24290 newval |= value << 6;
24291 break;
24292
24293 case 8: /* Halfword load/store. */
24294 if (value & ~0x3e)
24295 as_bad_where (fixP->fx_file, fixP->fx_line,
24296 _("invalid offset, value too big (0x%08lX)"),
24297 (long) value);
24298 newval |= value << 5; /* 6 - 1. */
24299 break;
24300
24301 default:
24302 as_bad_where (fixP->fx_file, fixP->fx_line,
24303 "Unable to process relocation for thumb opcode: %lx",
24304 (unsigned long) newval);
24305 break;
24306 }
24307 md_number_to_chars (buf, newval, THUMB_SIZE);
24308 break;
24309
24310 case BFD_RELOC_ARM_THUMB_ADD:
24311 /* This is a complicated relocation, since we use it for all of
24312 the following immediate relocations:
24313
24314 3bit ADD/SUB
24315 8bit ADD/SUB
24316 9bit ADD/SUB SP word-aligned
24317 10bit ADD PC/SP word-aligned
24318
24319 The type of instruction being processed is encoded in the
24320 instruction field:
24321
24322 0x8000 SUB
24323 0x00F0 Rd
24324 0x000F Rs
24325 */
24326 newval = md_chars_to_number (buf, THUMB_SIZE);
24327 {
24328 int rd = (newval >> 4) & 0xf;
24329 int rs = newval & 0xf;
24330 int subtract = !!(newval & 0x8000);
24331
24332 /* Check for HI regs, only very restricted cases allowed:
24333 Adjusting SP, and using PC or SP to get an address. */
24334 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24335 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24336 as_bad_where (fixP->fx_file, fixP->fx_line,
24337 _("invalid Hi register with immediate"));
24338
24339 /* If value is negative, choose the opposite instruction. */
24340 if (value < 0)
24341 {
24342 value = -value;
24343 subtract = !subtract;
24344 if (value < 0)
24345 as_bad_where (fixP->fx_file, fixP->fx_line,
24346 _("immediate value out of range"));
24347 }
24348
24349 if (rd == REG_SP)
24350 {
24351 if (value & ~0x1fc)
24352 as_bad_where (fixP->fx_file, fixP->fx_line,
24353 _("invalid immediate for stack address calculation"));
24354 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24355 newval |= value >> 2;
24356 }
24357 else if (rs == REG_PC || rs == REG_SP)
24358 {
24359 /* PR gas/18541. If the addition is for a defined symbol
24360 within range of an ADR instruction then accept it. */
24361 if (subtract
24362 && value == 4
24363 && fixP->fx_addsy != NULL)
24364 {
24365 subtract = 0;
24366
24367 if (! S_IS_DEFINED (fixP->fx_addsy)
24368 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24369 || S_IS_WEAK (fixP->fx_addsy))
24370 {
24371 as_bad_where (fixP->fx_file, fixP->fx_line,
24372 _("address calculation needs a strongly defined nearby symbol"));
24373 }
24374 else
24375 {
24376 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24377
24378 /* Round up to the next 4-byte boundary. */
24379 if (v & 3)
24380 v = (v + 3) & ~ 3;
24381 else
24382 v += 4;
24383 v = S_GET_VALUE (fixP->fx_addsy) - v;
24384
24385 if (v & ~0x3fc)
24386 {
24387 as_bad_where (fixP->fx_file, fixP->fx_line,
24388 _("symbol too far away"));
24389 }
24390 else
24391 {
24392 fixP->fx_done = 1;
24393 value = v;
24394 }
24395 }
24396 }
24397
24398 if (subtract || value & ~0x3fc)
24399 as_bad_where (fixP->fx_file, fixP->fx_line,
24400 _("invalid immediate for address calculation (value = 0x%08lX)"),
24401 (unsigned long) (subtract ? - value : value));
24402 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24403 newval |= rd << 8;
24404 newval |= value >> 2;
24405 }
24406 else if (rs == rd)
24407 {
24408 if (value & ~0xff)
24409 as_bad_where (fixP->fx_file, fixP->fx_line,
24410 _("immediate value out of range"));
24411 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24412 newval |= (rd << 8) | value;
24413 }
24414 else
24415 {
24416 if (value & ~0x7)
24417 as_bad_where (fixP->fx_file, fixP->fx_line,
24418 _("immediate value out of range"));
24419 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24420 newval |= rd | (rs << 3) | (value << 6);
24421 }
24422 }
24423 md_number_to_chars (buf, newval, THUMB_SIZE);
24424 break;
24425
24426 case BFD_RELOC_ARM_THUMB_IMM:
24427 newval = md_chars_to_number (buf, THUMB_SIZE);
24428 if (value < 0 || value > 255)
24429 as_bad_where (fixP->fx_file, fixP->fx_line,
24430 _("invalid immediate: %ld is out of range"),
24431 (long) value);
24432 newval |= value;
24433 md_number_to_chars (buf, newval, THUMB_SIZE);
24434 break;
24435
24436 case BFD_RELOC_ARM_THUMB_SHIFT:
24437 /* 5bit shift value (0..32). LSL cannot take 32. */
24438 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24439 temp = newval & 0xf800;
24440 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24441 as_bad_where (fixP->fx_file, fixP->fx_line,
24442 _("invalid shift value: %ld"), (long) value);
24443 /* Shifts of zero must be encoded as LSL. */
24444 if (value == 0)
24445 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24446 /* Shifts of 32 are encoded as zero. */
24447 else if (value == 32)
24448 value = 0;
24449 newval |= value << 6;
24450 md_number_to_chars (buf, newval, THUMB_SIZE);
24451 break;
24452
24453 case BFD_RELOC_VTABLE_INHERIT:
24454 case BFD_RELOC_VTABLE_ENTRY:
24455 fixP->fx_done = 0;
24456 return;
24457
24458 case BFD_RELOC_ARM_MOVW:
24459 case BFD_RELOC_ARM_MOVT:
24460 case BFD_RELOC_ARM_THUMB_MOVW:
24461 case BFD_RELOC_ARM_THUMB_MOVT:
24462 if (fixP->fx_done || !seg->use_rela_p)
24463 {
24464 /* REL format relocations are limited to a 16-bit addend. */
24465 if (!fixP->fx_done)
24466 {
24467 if (value < -0x8000 || value > 0x7fff)
24468 as_bad_where (fixP->fx_file, fixP->fx_line,
24469 _("offset out of range"));
24470 }
24471 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24472 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24473 {
24474 value >>= 16;
24475 }
24476
24477 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24478 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24479 {
24480 newval = get_thumb32_insn (buf);
24481 newval &= 0xfbf08f00;
24482 newval |= (value & 0xf000) << 4;
24483 newval |= (value & 0x0800) << 15;
24484 newval |= (value & 0x0700) << 4;
24485 newval |= (value & 0x00ff);
24486 put_thumb32_insn (buf, newval);
24487 }
24488 else
24489 {
24490 newval = md_chars_to_number (buf, 4);
24491 newval &= 0xfff0f000;
24492 newval |= value & 0x0fff;
24493 newval |= (value & 0xf000) << 4;
24494 md_number_to_chars (buf, newval, 4);
24495 }
24496 }
24497 return;
24498
24499 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24500 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24501 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24502 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24503 gas_assert (!fixP->fx_done);
24504 {
24505 bfd_vma insn;
24506 bfd_boolean is_mov;
24507 bfd_vma encoded_addend = value;
24508
24509 /* Check that addend can be encoded in instruction. */
24510 if (!seg->use_rela_p && (value < 0 || value > 255))
24511 as_bad_where (fixP->fx_file, fixP->fx_line,
24512 _("the offset 0x%08lX is not representable"),
24513 (unsigned long) encoded_addend);
24514
24515 /* Extract the instruction. */
24516 insn = md_chars_to_number (buf, THUMB_SIZE);
24517 is_mov = (insn & 0xf800) == 0x2000;
24518
24519 /* Encode insn. */
24520 if (is_mov)
24521 {
24522 if (!seg->use_rela_p)
24523 insn |= encoded_addend;
24524 }
24525 else
24526 {
24527 int rd, rs;
24528
24529 /* Extract the instruction. */
24530 /* Encoding is the following
24531 0x8000 SUB
24532 0x00F0 Rd
24533 0x000F Rs
24534 */
24535 /* The following conditions must be true :
24536 - ADD
24537 - Rd == Rs
24538 - Rd <= 7
24539 */
24540 rd = (insn >> 4) & 0xf;
24541 rs = insn & 0xf;
24542 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24543 as_bad_where (fixP->fx_file, fixP->fx_line,
24544 _("Unable to process relocation for thumb opcode: %lx"),
24545 (unsigned long) insn);
24546
24547 /* Encode as ADD immediate8 thumb 1 code. */
24548 insn = 0x3000 | (rd << 8);
24549
24550 /* Place the encoded addend into the first 8 bits of the
24551 instruction. */
24552 if (!seg->use_rela_p)
24553 insn |= encoded_addend;
24554 }
24555
24556 /* Update the instruction. */
24557 md_number_to_chars (buf, insn, THUMB_SIZE);
24558 }
24559 break;
24560
24561 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24562 case BFD_RELOC_ARM_ALU_PC_G0:
24563 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24564 case BFD_RELOC_ARM_ALU_PC_G1:
24565 case BFD_RELOC_ARM_ALU_PC_G2:
24566 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24567 case BFD_RELOC_ARM_ALU_SB_G0:
24568 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24569 case BFD_RELOC_ARM_ALU_SB_G1:
24570 case BFD_RELOC_ARM_ALU_SB_G2:
24571 gas_assert (!fixP->fx_done);
24572 if (!seg->use_rela_p)
24573 {
24574 bfd_vma insn;
24575 bfd_vma encoded_addend;
24576 bfd_vma addend_abs = llabs (value);
24577
24578 /* Check that the absolute value of the addend can be
24579 expressed as an 8-bit constant plus a rotation. */
24580 encoded_addend = encode_arm_immediate (addend_abs);
24581 if (encoded_addend == (unsigned int) FAIL)
24582 as_bad_where (fixP->fx_file, fixP->fx_line,
24583 _("the offset 0x%08lX is not representable"),
24584 (unsigned long) addend_abs);
24585
24586 /* Extract the instruction. */
24587 insn = md_chars_to_number (buf, INSN_SIZE);
24588
24589 /* If the addend is positive, use an ADD instruction.
24590 Otherwise use a SUB. Take care not to destroy the S bit. */
24591 insn &= 0xff1fffff;
24592 if (value < 0)
24593 insn |= 1 << 22;
24594 else
24595 insn |= 1 << 23;
24596
24597 /* Place the encoded addend into the first 12 bits of the
24598 instruction. */
24599 insn &= 0xfffff000;
24600 insn |= encoded_addend;
24601
24602 /* Update the instruction. */
24603 md_number_to_chars (buf, insn, INSN_SIZE);
24604 }
24605 break;
24606
24607 case BFD_RELOC_ARM_LDR_PC_G0:
24608 case BFD_RELOC_ARM_LDR_PC_G1:
24609 case BFD_RELOC_ARM_LDR_PC_G2:
24610 case BFD_RELOC_ARM_LDR_SB_G0:
24611 case BFD_RELOC_ARM_LDR_SB_G1:
24612 case BFD_RELOC_ARM_LDR_SB_G2:
24613 gas_assert (!fixP->fx_done);
24614 if (!seg->use_rela_p)
24615 {
24616 bfd_vma insn;
24617 bfd_vma addend_abs = llabs (value);
24618
24619 /* Check that the absolute value of the addend can be
24620 encoded in 12 bits. */
24621 if (addend_abs >= 0x1000)
24622 as_bad_where (fixP->fx_file, fixP->fx_line,
24623 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24624 (unsigned long) addend_abs);
24625
24626 /* Extract the instruction. */
24627 insn = md_chars_to_number (buf, INSN_SIZE);
24628
24629 /* If the addend is negative, clear bit 23 of the instruction.
24630 Otherwise set it. */
24631 if (value < 0)
24632 insn &= ~(1 << 23);
24633 else
24634 insn |= 1 << 23;
24635
24636 /* Place the absolute value of the addend into the first 12 bits
24637 of the instruction. */
24638 insn &= 0xfffff000;
24639 insn |= addend_abs;
24640
24641 /* Update the instruction. */
24642 md_number_to_chars (buf, insn, INSN_SIZE);
24643 }
24644 break;
24645
24646 case BFD_RELOC_ARM_LDRS_PC_G0:
24647 case BFD_RELOC_ARM_LDRS_PC_G1:
24648 case BFD_RELOC_ARM_LDRS_PC_G2:
24649 case BFD_RELOC_ARM_LDRS_SB_G0:
24650 case BFD_RELOC_ARM_LDRS_SB_G1:
24651 case BFD_RELOC_ARM_LDRS_SB_G2:
24652 gas_assert (!fixP->fx_done);
24653 if (!seg->use_rela_p)
24654 {
24655 bfd_vma insn;
24656 bfd_vma addend_abs = llabs (value);
24657
24658 /* Check that the absolute value of the addend can be
24659 encoded in 8 bits. */
24660 if (addend_abs >= 0x100)
24661 as_bad_where (fixP->fx_file, fixP->fx_line,
24662 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24663 (unsigned long) addend_abs);
24664
24665 /* Extract the instruction. */
24666 insn = md_chars_to_number (buf, INSN_SIZE);
24667
24668 /* If the addend is negative, clear bit 23 of the instruction.
24669 Otherwise set it. */
24670 if (value < 0)
24671 insn &= ~(1 << 23);
24672 else
24673 insn |= 1 << 23;
24674
24675 /* Place the first four bits of the absolute value of the addend
24676 into the first 4 bits of the instruction, and the remaining
24677 four into bits 8 .. 11. */
24678 insn &= 0xfffff0f0;
24679 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24680
24681 /* Update the instruction. */
24682 md_number_to_chars (buf, insn, INSN_SIZE);
24683 }
24684 break;
24685
24686 case BFD_RELOC_ARM_LDC_PC_G0:
24687 case BFD_RELOC_ARM_LDC_PC_G1:
24688 case BFD_RELOC_ARM_LDC_PC_G2:
24689 case BFD_RELOC_ARM_LDC_SB_G0:
24690 case BFD_RELOC_ARM_LDC_SB_G1:
24691 case BFD_RELOC_ARM_LDC_SB_G2:
24692 gas_assert (!fixP->fx_done);
24693 if (!seg->use_rela_p)
24694 {
24695 bfd_vma insn;
24696 bfd_vma addend_abs = llabs (value);
24697
24698 /* Check that the absolute value of the addend is a multiple of
24699 four and, when divided by four, fits in 8 bits. */
24700 if (addend_abs & 0x3)
24701 as_bad_where (fixP->fx_file, fixP->fx_line,
24702 _("bad offset 0x%08lX (must be word-aligned)"),
24703 (unsigned long) addend_abs);
24704
24705 if ((addend_abs >> 2) > 0xff)
24706 as_bad_where (fixP->fx_file, fixP->fx_line,
24707 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24708 (unsigned long) addend_abs);
24709
24710 /* Extract the instruction. */
24711 insn = md_chars_to_number (buf, INSN_SIZE);
24712
24713 /* If the addend is negative, clear bit 23 of the instruction.
24714 Otherwise set it. */
24715 if (value < 0)
24716 insn &= ~(1 << 23);
24717 else
24718 insn |= 1 << 23;
24719
24720 /* Place the addend (divided by four) into the first eight
24721 bits of the instruction. */
24722 insn &= 0xfffffff0;
24723 insn |= addend_abs >> 2;
24724
24725 /* Update the instruction. */
24726 md_number_to_chars (buf, insn, INSN_SIZE);
24727 }
24728 break;
24729
24730 case BFD_RELOC_THUMB_PCREL_BRANCH5:
24731 if (fixP->fx_addsy
24732 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24733 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24734 && ARM_IS_FUNC (fixP->fx_addsy)
24735 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
24736 {
24737 /* Force a relocation for a branch 5 bits wide. */
24738 fixP->fx_done = 0;
24739 }
24740 if (v8_1_branch_value_check (value, 5, FALSE) == FAIL)
24741 as_bad_where (fixP->fx_file, fixP->fx_line,
24742 BAD_BRANCH_OFF);
24743
24744 if (fixP->fx_done || !seg->use_rela_p)
24745 {
24746 addressT boff = value >> 1;
24747
24748 newval = md_chars_to_number (buf, THUMB_SIZE);
24749 newval |= (boff << 7);
24750 md_number_to_chars (buf, newval, THUMB_SIZE);
24751 }
24752 break;
24753
24754 case BFD_RELOC_ARM_THUMB_BF17:
24755 if (fixP->fx_addsy
24756 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
24757 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
24758 && ARM_IS_FUNC (fixP->fx_addsy)
24759 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v8_1m_main))
24760 {
24761 /* Force a relocation for a branch 17 bits wide. */
24762 fixP->fx_done = 0;
24763 }
24764
24765 if (v8_1_branch_value_check (value, 17, TRUE) == FAIL)
24766 as_bad_where (fixP->fx_file, fixP->fx_line,
24767 BAD_BRANCH_OFF);
24768
24769 if (fixP->fx_done || !seg->use_rela_p)
24770 {
24771 offsetT newval2;
24772 addressT immA, immB, immC;
24773
24774 immA = (value & 0x0001f000) >> 12;
24775 immB = (value & 0x00000ffc) >> 2;
24776 immC = (value & 0x00000002) >> 1;
24777
24778 newval = md_chars_to_number (buf, THUMB_SIZE);
24779 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
24780 newval |= immA;
24781 newval2 |= (immC << 11) | (immB << 1);
24782 md_number_to_chars (buf, newval, THUMB_SIZE);
24783 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
24784 }
24785 break;
24786
24787 case BFD_RELOC_ARM_V4BX:
24788 /* This will need to go in the object file. */
24789 fixP->fx_done = 0;
24790 break;
24791
24792 case BFD_RELOC_UNUSED:
24793 default:
24794 as_bad_where (fixP->fx_file, fixP->fx_line,
24795 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24796 }
24797 }
24798
24799 /* Translate internal representation of relocation info to BFD target
24800 format. */
24801
24802 arelent *
24803 tc_gen_reloc (asection *section, fixS *fixp)
24804 {
24805 arelent * reloc;
24806 bfd_reloc_code_real_type code;
24807
24808 reloc = XNEW (arelent);
24809
24810 reloc->sym_ptr_ptr = XNEW (asymbol *);
24811 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24812 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
24813
24814 if (fixp->fx_pcrel)
24815 {
24816 if (section->use_rela_p)
24817 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24818 else
24819 fixp->fx_offset = reloc->address;
24820 }
24821 reloc->addend = fixp->fx_offset;
24822
24823 switch (fixp->fx_r_type)
24824 {
24825 case BFD_RELOC_8:
24826 if (fixp->fx_pcrel)
24827 {
24828 code = BFD_RELOC_8_PCREL;
24829 break;
24830 }
24831 /* Fall through. */
24832
24833 case BFD_RELOC_16:
24834 if (fixp->fx_pcrel)
24835 {
24836 code = BFD_RELOC_16_PCREL;
24837 break;
24838 }
24839 /* Fall through. */
24840
24841 case BFD_RELOC_32:
24842 if (fixp->fx_pcrel)
24843 {
24844 code = BFD_RELOC_32_PCREL;
24845 break;
24846 }
24847 /* Fall through. */
24848
24849 case BFD_RELOC_ARM_MOVW:
24850 if (fixp->fx_pcrel)
24851 {
24852 code = BFD_RELOC_ARM_MOVW_PCREL;
24853 break;
24854 }
24855 /* Fall through. */
24856
24857 case BFD_RELOC_ARM_MOVT:
24858 if (fixp->fx_pcrel)
24859 {
24860 code = BFD_RELOC_ARM_MOVT_PCREL;
24861 break;
24862 }
24863 /* Fall through. */
24864
24865 case BFD_RELOC_ARM_THUMB_MOVW:
24866 if (fixp->fx_pcrel)
24867 {
24868 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24869 break;
24870 }
24871 /* Fall through. */
24872
24873 case BFD_RELOC_ARM_THUMB_MOVT:
24874 if (fixp->fx_pcrel)
24875 {
24876 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24877 break;
24878 }
24879 /* Fall through. */
24880
24881 case BFD_RELOC_NONE:
24882 case BFD_RELOC_ARM_PCREL_BRANCH:
24883 case BFD_RELOC_ARM_PCREL_BLX:
24884 case BFD_RELOC_RVA:
24885 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24886 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24887 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24888 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24889 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24890 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24891 case BFD_RELOC_VTABLE_ENTRY:
24892 case BFD_RELOC_VTABLE_INHERIT:
24893 #ifdef TE_PE
24894 case BFD_RELOC_32_SECREL:
24895 #endif
24896 code = fixp->fx_r_type;
24897 break;
24898
24899 case BFD_RELOC_THUMB_PCREL_BLX:
24900 #ifdef OBJ_ELF
24901 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24902 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24903 else
24904 #endif
24905 code = BFD_RELOC_THUMB_PCREL_BLX;
24906 break;
24907
24908 case BFD_RELOC_ARM_LITERAL:
24909 case BFD_RELOC_ARM_HWLITERAL:
24910 /* If this is called then the a literal has
24911 been referenced across a section boundary. */
24912 as_bad_where (fixp->fx_file, fixp->fx_line,
24913 _("literal referenced across section boundary"));
24914 return NULL;
24915
24916 #ifdef OBJ_ELF
24917 case BFD_RELOC_ARM_TLS_CALL:
24918 case BFD_RELOC_ARM_THM_TLS_CALL:
24919 case BFD_RELOC_ARM_TLS_DESCSEQ:
24920 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
24921 case BFD_RELOC_ARM_GOT32:
24922 case BFD_RELOC_ARM_GOTOFF:
24923 case BFD_RELOC_ARM_GOT_PREL:
24924 case BFD_RELOC_ARM_PLT32:
24925 case BFD_RELOC_ARM_TARGET1:
24926 case BFD_RELOC_ARM_ROSEGREL32:
24927 case BFD_RELOC_ARM_SBREL32:
24928 case BFD_RELOC_ARM_PREL31:
24929 case BFD_RELOC_ARM_TARGET2:
24930 case BFD_RELOC_ARM_TLS_LDO32:
24931 case BFD_RELOC_ARM_PCREL_CALL:
24932 case BFD_RELOC_ARM_PCREL_JUMP:
24933 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24934 case BFD_RELOC_ARM_ALU_PC_G0:
24935 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24936 case BFD_RELOC_ARM_ALU_PC_G1:
24937 case BFD_RELOC_ARM_ALU_PC_G2:
24938 case BFD_RELOC_ARM_LDR_PC_G0:
24939 case BFD_RELOC_ARM_LDR_PC_G1:
24940 case BFD_RELOC_ARM_LDR_PC_G2:
24941 case BFD_RELOC_ARM_LDRS_PC_G0:
24942 case BFD_RELOC_ARM_LDRS_PC_G1:
24943 case BFD_RELOC_ARM_LDRS_PC_G2:
24944 case BFD_RELOC_ARM_LDC_PC_G0:
24945 case BFD_RELOC_ARM_LDC_PC_G1:
24946 case BFD_RELOC_ARM_LDC_PC_G2:
24947 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24948 case BFD_RELOC_ARM_ALU_SB_G0:
24949 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24950 case BFD_RELOC_ARM_ALU_SB_G1:
24951 case BFD_RELOC_ARM_ALU_SB_G2:
24952 case BFD_RELOC_ARM_LDR_SB_G0:
24953 case BFD_RELOC_ARM_LDR_SB_G1:
24954 case BFD_RELOC_ARM_LDR_SB_G2:
24955 case BFD_RELOC_ARM_LDRS_SB_G0:
24956 case BFD_RELOC_ARM_LDRS_SB_G1:
24957 case BFD_RELOC_ARM_LDRS_SB_G2:
24958 case BFD_RELOC_ARM_LDC_SB_G0:
24959 case BFD_RELOC_ARM_LDC_SB_G1:
24960 case BFD_RELOC_ARM_LDC_SB_G2:
24961 case BFD_RELOC_ARM_V4BX:
24962 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24963 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24964 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24965 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24966 case BFD_RELOC_ARM_GOTFUNCDESC:
24967 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24968 case BFD_RELOC_ARM_FUNCDESC:
24969 case BFD_RELOC_ARM_THUMB_BF17:
24970 code = fixp->fx_r_type;
24971 break;
24972
24973 case BFD_RELOC_ARM_TLS_GOTDESC:
24974 case BFD_RELOC_ARM_TLS_GD32:
24975 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
24976 case BFD_RELOC_ARM_TLS_LE32:
24977 case BFD_RELOC_ARM_TLS_IE32:
24978 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
24979 case BFD_RELOC_ARM_TLS_LDM32:
24980 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
24981 /* BFD will include the symbol's address in the addend.
24982 But we don't want that, so subtract it out again here. */
24983 if (!S_IS_COMMON (fixp->fx_addsy))
24984 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24985 code = fixp->fx_r_type;
24986 break;
24987 #endif
24988
24989 case BFD_RELOC_ARM_IMMEDIATE:
24990 as_bad_where (fixp->fx_file, fixp->fx_line,
24991 _("internal relocation (type: IMMEDIATE) not fixed up"));
24992 return NULL;
24993
24994 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24995 as_bad_where (fixp->fx_file, fixp->fx_line,
24996 _("ADRL used for a symbol not defined in the same file"));
24997 return NULL;
24998
24999 case BFD_RELOC_THUMB_PCREL_BRANCH5:
25000 as_bad_where (fixp->fx_file, fixp->fx_line,
25001 _("%s used for a symbol not defined in the same file"),
25002 bfd_get_reloc_code_name (fixp->fx_r_type));
25003 return NULL;
25004
25005 case BFD_RELOC_ARM_OFFSET_IMM:
25006 if (section->use_rela_p)
25007 {
25008 code = fixp->fx_r_type;
25009 break;
25010 }
25011
25012 if (fixp->fx_addsy != NULL
25013 && !S_IS_DEFINED (fixp->fx_addsy)
25014 && S_IS_LOCAL (fixp->fx_addsy))
25015 {
25016 as_bad_where (fixp->fx_file, fixp->fx_line,
25017 _("undefined local label `%s'"),
25018 S_GET_NAME (fixp->fx_addsy));
25019 return NULL;
25020 }
25021
25022 as_bad_where (fixp->fx_file, fixp->fx_line,
25023 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
25024 return NULL;
25025
25026 default:
25027 {
25028 const char * type;
25029
25030 switch (fixp->fx_r_type)
25031 {
25032 case BFD_RELOC_NONE: type = "NONE"; break;
25033 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
25034 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
25035 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
25036 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
25037 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
25038 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
25039 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
25040 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
25041 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
25042 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
25043 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
25044 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
25045 default: type = _("<unknown>"); break;
25046 }
25047 as_bad_where (fixp->fx_file, fixp->fx_line,
25048 _("cannot represent %s relocation in this object file format"),
25049 type);
25050 return NULL;
25051 }
25052 }
25053
25054 #ifdef OBJ_ELF
25055 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
25056 && GOT_symbol
25057 && fixp->fx_addsy == GOT_symbol)
25058 {
25059 code = BFD_RELOC_ARM_GOTPC;
25060 reloc->addend = fixp->fx_offset = reloc->address;
25061 }
25062 #endif
25063
25064 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
25065
25066 if (reloc->howto == NULL)
25067 {
25068 as_bad_where (fixp->fx_file, fixp->fx_line,
25069 _("cannot represent %s relocation in this object file format"),
25070 bfd_get_reloc_code_name (code));
25071 return NULL;
25072 }
25073
25074 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
25075 vtable entry to be used in the relocation's section offset. */
25076 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
25077 reloc->address = fixp->fx_offset;
25078
25079 return reloc;
25080 }
25081
25082 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
25083
25084 void
25085 cons_fix_new_arm (fragS * frag,
25086 int where,
25087 int size,
25088 expressionS * exp,
25089 bfd_reloc_code_real_type reloc)
25090 {
25091 int pcrel = 0;
25092
25093 /* Pick a reloc.
25094 FIXME: @@ Should look at CPU word size. */
25095 switch (size)
25096 {
25097 case 1:
25098 reloc = BFD_RELOC_8;
25099 break;
25100 case 2:
25101 reloc = BFD_RELOC_16;
25102 break;
25103 case 4:
25104 default:
25105 reloc = BFD_RELOC_32;
25106 break;
25107 case 8:
25108 reloc = BFD_RELOC_64;
25109 break;
25110 }
25111
25112 #ifdef TE_PE
25113 if (exp->X_op == O_secrel)
25114 {
25115 exp->X_op = O_symbol;
25116 reloc = BFD_RELOC_32_SECREL;
25117 }
25118 #endif
25119
25120 fix_new_exp (frag, where, size, exp, pcrel, reloc);
25121 }
25122
25123 #if defined (OBJ_COFF)
25124 void
25125 arm_validate_fix (fixS * fixP)
25126 {
25127 /* If the destination of the branch is a defined symbol which does not have
25128 the THUMB_FUNC attribute, then we must be calling a function which has
25129 the (interfacearm) attribute. We look for the Thumb entry point to that
25130 function and change the branch to refer to that function instead. */
25131 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
25132 && fixP->fx_addsy != NULL
25133 && S_IS_DEFINED (fixP->fx_addsy)
25134 && ! THUMB_IS_FUNC (fixP->fx_addsy))
25135 {
25136 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
25137 }
25138 }
25139 #endif
25140
25141
25142 int
25143 arm_force_relocation (struct fix * fixp)
25144 {
25145 #if defined (OBJ_COFF) && defined (TE_PE)
25146 if (fixp->fx_r_type == BFD_RELOC_RVA)
25147 return 1;
25148 #endif
25149
25150 /* In case we have a call or a branch to a function in ARM ISA mode from
25151 a thumb function or vice-versa force the relocation. These relocations
25152 are cleared off for some cores that might have blx and simple transformations
25153 are possible. */
25154
25155 #ifdef OBJ_ELF
25156 switch (fixp->fx_r_type)
25157 {
25158 case BFD_RELOC_ARM_PCREL_JUMP:
25159 case BFD_RELOC_ARM_PCREL_CALL:
25160 case BFD_RELOC_THUMB_PCREL_BLX:
25161 if (THUMB_IS_FUNC (fixp->fx_addsy))
25162 return 1;
25163 break;
25164
25165 case BFD_RELOC_ARM_PCREL_BLX:
25166 case BFD_RELOC_THUMB_PCREL_BRANCH25:
25167 case BFD_RELOC_THUMB_PCREL_BRANCH20:
25168 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25169 if (ARM_IS_FUNC (fixp->fx_addsy))
25170 return 1;
25171 break;
25172
25173 default:
25174 break;
25175 }
25176 #endif
25177
25178 /* Resolve these relocations even if the symbol is extern or weak.
25179 Technically this is probably wrong due to symbol preemption.
25180 In practice these relocations do not have enough range to be useful
25181 at dynamic link time, and some code (e.g. in the Linux kernel)
25182 expects these references to be resolved. */
25183 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
25184 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
25185 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
25186 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
25187 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25188 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
25189 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
25190 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
25191 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
25192 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
25193 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
25194 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
25195 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
25196 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
25197 return 0;
25198
25199 /* Always leave these relocations for the linker. */
25200 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25201 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25202 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25203 return 1;
25204
25205 /* Always generate relocations against function symbols. */
25206 if (fixp->fx_r_type == BFD_RELOC_32
25207 && fixp->fx_addsy
25208 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
25209 return 1;
25210
25211 return generic_force_reloc (fixp);
25212 }
25213
25214 #if defined (OBJ_ELF) || defined (OBJ_COFF)
25215 /* Relocations against function names must be left unadjusted,
25216 so that the linker can use this information to generate interworking
25217 stubs. The MIPS version of this function
25218 also prevents relocations that are mips-16 specific, but I do not
25219 know why it does this.
25220
25221 FIXME:
25222 There is one other problem that ought to be addressed here, but
25223 which currently is not: Taking the address of a label (rather
25224 than a function) and then later jumping to that address. Such
25225 addresses also ought to have their bottom bit set (assuming that
25226 they reside in Thumb code), but at the moment they will not. */
25227
25228 bfd_boolean
25229 arm_fix_adjustable (fixS * fixP)
25230 {
25231 if (fixP->fx_addsy == NULL)
25232 return 1;
25233
25234 /* Preserve relocations against symbols with function type. */
25235 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
25236 return FALSE;
25237
25238 if (THUMB_IS_FUNC (fixP->fx_addsy)
25239 && fixP->fx_subsy == NULL)
25240 return FALSE;
25241
25242 /* We need the symbol name for the VTABLE entries. */
25243 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
25244 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
25245 return FALSE;
25246
25247 /* Don't allow symbols to be discarded on GOT related relocs. */
25248 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
25249 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
25250 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
25251 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
25252 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
25253 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
25254 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
25255 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
25256 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
25257 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
25258 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
25259 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
25260 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
25261 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
25262 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
25263 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
25264 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
25265 return FALSE;
25266
25267 /* Similarly for group relocations. */
25268 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25269 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25270 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25271 return FALSE;
25272
25273 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25274 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25275 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25276 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25277 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25278 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25279 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25280 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25281 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
25282 return FALSE;
25283
25284 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25285 offsets, so keep these symbols. */
25286 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25287 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25288 return FALSE;
25289
25290 return TRUE;
25291 }
25292 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25293
25294 #ifdef OBJ_ELF
25295 const char *
25296 elf32_arm_target_format (void)
25297 {
25298 #ifdef TE_SYMBIAN
25299 return (target_big_endian
25300 ? "elf32-bigarm-symbian"
25301 : "elf32-littlearm-symbian");
25302 #elif defined (TE_VXWORKS)
25303 return (target_big_endian
25304 ? "elf32-bigarm-vxworks"
25305 : "elf32-littlearm-vxworks");
25306 #elif defined (TE_NACL)
25307 return (target_big_endian
25308 ? "elf32-bigarm-nacl"
25309 : "elf32-littlearm-nacl");
25310 #else
25311 if (arm_fdpic)
25312 {
25313 if (target_big_endian)
25314 return "elf32-bigarm-fdpic";
25315 else
25316 return "elf32-littlearm-fdpic";
25317 }
25318 else
25319 {
25320 if (target_big_endian)
25321 return "elf32-bigarm";
25322 else
25323 return "elf32-littlearm";
25324 }
25325 #endif
25326 }
25327
25328 void
25329 armelf_frob_symbol (symbolS * symp,
25330 int * puntp)
25331 {
25332 elf_frob_symbol (symp, puntp);
25333 }
25334 #endif
25335
25336 /* MD interface: Finalization. */
25337
25338 void
25339 arm_cleanup (void)
25340 {
25341 literal_pool * pool;
25342
25343 /* Ensure that all the IT blocks are properly closed. */
25344 check_it_blocks_finished ();
25345
25346 for (pool = list_of_pools; pool; pool = pool->next)
25347 {
25348 /* Put it at the end of the relevant section. */
25349 subseg_set (pool->section, pool->sub_section);
25350 #ifdef OBJ_ELF
25351 arm_elf_change_section ();
25352 #endif
25353 s_ltorg (0);
25354 }
25355 }
25356
25357 #ifdef OBJ_ELF
25358 /* Remove any excess mapping symbols generated for alignment frags in
25359 SEC. We may have created a mapping symbol before a zero byte
25360 alignment; remove it if there's a mapping symbol after the
25361 alignment. */
25362 static void
25363 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25364 void *dummy ATTRIBUTE_UNUSED)
25365 {
25366 segment_info_type *seginfo = seg_info (sec);
25367 fragS *fragp;
25368
25369 if (seginfo == NULL || seginfo->frchainP == NULL)
25370 return;
25371
25372 for (fragp = seginfo->frchainP->frch_root;
25373 fragp != NULL;
25374 fragp = fragp->fr_next)
25375 {
25376 symbolS *sym = fragp->tc_frag_data.last_map;
25377 fragS *next = fragp->fr_next;
25378
25379 /* Variable-sized frags have been converted to fixed size by
25380 this point. But if this was variable-sized to start with,
25381 there will be a fixed-size frag after it. So don't handle
25382 next == NULL. */
25383 if (sym == NULL || next == NULL)
25384 continue;
25385
25386 if (S_GET_VALUE (sym) < next->fr_address)
25387 /* Not at the end of this frag. */
25388 continue;
25389 know (S_GET_VALUE (sym) == next->fr_address);
25390
25391 do
25392 {
25393 if (next->tc_frag_data.first_map != NULL)
25394 {
25395 /* Next frag starts with a mapping symbol. Discard this
25396 one. */
25397 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25398 break;
25399 }
25400
25401 if (next->fr_next == NULL)
25402 {
25403 /* This mapping symbol is at the end of the section. Discard
25404 it. */
25405 know (next->fr_fix == 0 && next->fr_var == 0);
25406 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25407 break;
25408 }
25409
25410 /* As long as we have empty frags without any mapping symbols,
25411 keep looking. */
25412 /* If the next frag is non-empty and does not start with a
25413 mapping symbol, then this mapping symbol is required. */
25414 if (next->fr_address != next->fr_next->fr_address)
25415 break;
25416
25417 next = next->fr_next;
25418 }
25419 while (next != NULL);
25420 }
25421 }
25422 #endif
25423
25424 /* Adjust the symbol table. This marks Thumb symbols as distinct from
25425 ARM ones. */
25426
25427 void
25428 arm_adjust_symtab (void)
25429 {
25430 #ifdef OBJ_COFF
25431 symbolS * sym;
25432
25433 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25434 {
25435 if (ARM_IS_THUMB (sym))
25436 {
25437 if (THUMB_IS_FUNC (sym))
25438 {
25439 /* Mark the symbol as a Thumb function. */
25440 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25441 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25442 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
25443
25444 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25445 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25446 else
25447 as_bad (_("%s: unexpected function type: %d"),
25448 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25449 }
25450 else switch (S_GET_STORAGE_CLASS (sym))
25451 {
25452 case C_EXT:
25453 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25454 break;
25455 case C_STAT:
25456 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25457 break;
25458 case C_LABEL:
25459 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25460 break;
25461 default:
25462 /* Do nothing. */
25463 break;
25464 }
25465 }
25466
25467 if (ARM_IS_INTERWORK (sym))
25468 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
25469 }
25470 #endif
25471 #ifdef OBJ_ELF
25472 symbolS * sym;
25473 char bind;
25474
25475 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25476 {
25477 if (ARM_IS_THUMB (sym))
25478 {
25479 elf_symbol_type * elf_sym;
25480
25481 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25482 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
25483
25484 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25485 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
25486 {
25487 /* If it's a .thumb_func, declare it as so,
25488 otherwise tag label as .code 16. */
25489 if (THUMB_IS_FUNC (sym))
25490 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25491 ST_BRANCH_TO_THUMB);
25492 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
25493 elf_sym->internal_elf_sym.st_info =
25494 ELF_ST_INFO (bind, STT_ARM_16BIT);
25495 }
25496 }
25497 }
25498
25499 /* Remove any overlapping mapping symbols generated by alignment frags. */
25500 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
25501 /* Now do generic ELF adjustments. */
25502 elf_adjust_symtab ();
25503 #endif
25504 }
25505
25506 /* MD interface: Initialization. */
25507
25508 static void
25509 set_constant_flonums (void)
25510 {
25511 int i;
25512
25513 for (i = 0; i < NUM_FLOAT_VALS; i++)
25514 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25515 abort ();
25516 }
25517
25518 /* Auto-select Thumb mode if it's the only available instruction set for the
25519 given architecture. */
25520
25521 static void
25522 autoselect_thumb_from_cpu_variant (void)
25523 {
25524 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25525 opcode_select (16);
25526 }
25527
25528 void
25529 md_begin (void)
25530 {
25531 unsigned mach;
25532 unsigned int i;
25533
25534 if ( (arm_ops_hsh = hash_new ()) == NULL
25535 || (arm_cond_hsh = hash_new ()) == NULL
25536 || (arm_shift_hsh = hash_new ()) == NULL
25537 || (arm_psr_hsh = hash_new ()) == NULL
25538 || (arm_v7m_psr_hsh = hash_new ()) == NULL
25539 || (arm_reg_hsh = hash_new ()) == NULL
25540 || (arm_reloc_hsh = hash_new ()) == NULL
25541 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
25542 as_fatal (_("virtual memory exhausted"));
25543
25544 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
25545 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
25546 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
25547 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
25548 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
25549 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
25550 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
25551 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
25552 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
25553 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
25554 (void *) (v7m_psrs + i));
25555 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
25556 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
25557 for (i = 0;
25558 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25559 i++)
25560 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
25561 (void *) (barrier_opt_names + i));
25562 #ifdef OBJ_ELF
25563 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25564 {
25565 struct reloc_entry * entry = reloc_names + i;
25566
25567 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25568 /* This makes encode_branch() use the EABI versions of this relocation. */
25569 entry->reloc = BFD_RELOC_UNUSED;
25570
25571 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25572 }
25573 #endif
25574
25575 set_constant_flonums ();
25576
25577 /* Set the cpu variant based on the command-line options. We prefer
25578 -mcpu= over -march= if both are set (as for GCC); and we prefer
25579 -mfpu= over any other way of setting the floating point unit.
25580 Use of legacy options with new options are faulted. */
25581 if (legacy_cpu)
25582 {
25583 if (mcpu_cpu_opt || march_cpu_opt)
25584 as_bad (_("use of old and new-style options to set CPU type"));
25585
25586 selected_arch = *legacy_cpu;
25587 }
25588 else if (mcpu_cpu_opt)
25589 {
25590 selected_arch = *mcpu_cpu_opt;
25591 selected_ext = *mcpu_ext_opt;
25592 }
25593 else if (march_cpu_opt)
25594 {
25595 selected_arch = *march_cpu_opt;
25596 selected_ext = *march_ext_opt;
25597 }
25598 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
25599
25600 if (legacy_fpu)
25601 {
25602 if (mfpu_opt)
25603 as_bad (_("use of old and new-style options to set FPU type"));
25604
25605 selected_fpu = *legacy_fpu;
25606 }
25607 else if (mfpu_opt)
25608 selected_fpu = *mfpu_opt;
25609 else
25610 {
25611 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25612 || defined (TE_NetBSD) || defined (TE_VXWORKS))
25613 /* Some environments specify a default FPU. If they don't, infer it
25614 from the processor. */
25615 if (mcpu_fpu_opt)
25616 selected_fpu = *mcpu_fpu_opt;
25617 else if (march_fpu_opt)
25618 selected_fpu = *march_fpu_opt;
25619 #else
25620 selected_fpu = fpu_default;
25621 #endif
25622 }
25623
25624 if (ARM_FEATURE_ZERO (selected_fpu))
25625 {
25626 if (!no_cpu_selected ())
25627 selected_fpu = fpu_default;
25628 else
25629 selected_fpu = fpu_arch_fpa;
25630 }
25631
25632 #ifdef CPU_DEFAULT
25633 if (ARM_FEATURE_ZERO (selected_arch))
25634 {
25635 selected_arch = cpu_default;
25636 selected_cpu = selected_arch;
25637 }
25638 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
25639 #else
25640 /* Autodection of feature mode: allow all features in cpu_variant but leave
25641 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
25642 after all instruction have been processed and we can decide what CPU
25643 should be selected. */
25644 if (ARM_FEATURE_ZERO (selected_arch))
25645 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
25646 else
25647 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
25648 #endif
25649
25650 autoselect_thumb_from_cpu_variant ();
25651
25652 arm_arch_used = thumb_arch_used = arm_arch_none;
25653
25654 #if defined OBJ_COFF || defined OBJ_ELF
25655 {
25656 unsigned int flags = 0;
25657
25658 #if defined OBJ_ELF
25659 flags = meabi_flags;
25660
25661 switch (meabi_flags)
25662 {
25663 case EF_ARM_EABI_UNKNOWN:
25664 #endif
25665 /* Set the flags in the private structure. */
25666 if (uses_apcs_26) flags |= F_APCS26;
25667 if (support_interwork) flags |= F_INTERWORK;
25668 if (uses_apcs_float) flags |= F_APCS_FLOAT;
25669 if (pic_code) flags |= F_PIC;
25670 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
25671 flags |= F_SOFT_FLOAT;
25672
25673 switch (mfloat_abi_opt)
25674 {
25675 case ARM_FLOAT_ABI_SOFT:
25676 case ARM_FLOAT_ABI_SOFTFP:
25677 flags |= F_SOFT_FLOAT;
25678 break;
25679
25680 case ARM_FLOAT_ABI_HARD:
25681 if (flags & F_SOFT_FLOAT)
25682 as_bad (_("hard-float conflicts with specified fpu"));
25683 break;
25684 }
25685
25686 /* Using pure-endian doubles (even if soft-float). */
25687 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
25688 flags |= F_VFP_FLOAT;
25689
25690 #if defined OBJ_ELF
25691 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
25692 flags |= EF_ARM_MAVERICK_FLOAT;
25693 break;
25694
25695 case EF_ARM_EABI_VER4:
25696 case EF_ARM_EABI_VER5:
25697 /* No additional flags to set. */
25698 break;
25699
25700 default:
25701 abort ();
25702 }
25703 #endif
25704 bfd_set_private_flags (stdoutput, flags);
25705
25706 /* We have run out flags in the COFF header to encode the
25707 status of ATPCS support, so instead we create a dummy,
25708 empty, debug section called .arm.atpcs. */
25709 if (atpcs)
25710 {
25711 asection * sec;
25712
25713 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25714
25715 if (sec != NULL)
25716 {
25717 bfd_set_section_flags
25718 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25719 bfd_set_section_size (stdoutput, sec, 0);
25720 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25721 }
25722 }
25723 }
25724 #endif
25725
25726 /* Record the CPU type as well. */
25727 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25728 mach = bfd_mach_arm_iWMMXt2;
25729 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
25730 mach = bfd_mach_arm_iWMMXt;
25731 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
25732 mach = bfd_mach_arm_XScale;
25733 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
25734 mach = bfd_mach_arm_ep9312;
25735 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
25736 mach = bfd_mach_arm_5TE;
25737 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
25738 {
25739 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
25740 mach = bfd_mach_arm_5T;
25741 else
25742 mach = bfd_mach_arm_5;
25743 }
25744 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
25745 {
25746 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
25747 mach = bfd_mach_arm_4T;
25748 else
25749 mach = bfd_mach_arm_4;
25750 }
25751 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
25752 mach = bfd_mach_arm_3M;
25753 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25754 mach = bfd_mach_arm_3;
25755 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25756 mach = bfd_mach_arm_2a;
25757 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25758 mach = bfd_mach_arm_2;
25759 else
25760 mach = bfd_mach_arm_unknown;
25761
25762 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25763 }
25764
25765 /* Command line processing. */
25766
25767 /* md_parse_option
25768 Invocation line includes a switch not recognized by the base assembler.
25769 See if it's a processor-specific option.
25770
25771 This routine is somewhat complicated by the need for backwards
25772 compatibility (since older releases of gcc can't be changed).
25773 The new options try to make the interface as compatible as
25774 possible with GCC.
25775
25776 New options (supported) are:
25777
25778 -mcpu=<cpu name> Assemble for selected processor
25779 -march=<architecture name> Assemble for selected architecture
25780 -mfpu=<fpu architecture> Assemble for selected FPU.
25781 -EB/-mbig-endian Big-endian
25782 -EL/-mlittle-endian Little-endian
25783 -k Generate PIC code
25784 -mthumb Start in Thumb mode
25785 -mthumb-interwork Code supports ARM/Thumb interworking
25786
25787 -m[no-]warn-deprecated Warn about deprecated features
25788 -m[no-]warn-syms Warn when symbols match instructions
25789
25790 For now we will also provide support for:
25791
25792 -mapcs-32 32-bit Program counter
25793 -mapcs-26 26-bit Program counter
25794 -macps-float Floats passed in FP registers
25795 -mapcs-reentrant Reentrant code
25796 -matpcs
25797 (sometime these will probably be replaced with -mapcs=<list of options>
25798 and -matpcs=<list of options>)
25799
25800 The remaining options are only supported for back-wards compatibility.
25801 Cpu variants, the arm part is optional:
25802 -m[arm]1 Currently not supported.
25803 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25804 -m[arm]3 Arm 3 processor
25805 -m[arm]6[xx], Arm 6 processors
25806 -m[arm]7[xx][t][[d]m] Arm 7 processors
25807 -m[arm]8[10] Arm 8 processors
25808 -m[arm]9[20][tdmi] Arm 9 processors
25809 -mstrongarm[110[0]] StrongARM processors
25810 -mxscale XScale processors
25811 -m[arm]v[2345[t[e]]] Arm architectures
25812 -mall All (except the ARM1)
25813 FP variants:
25814 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25815 -mfpe-old (No float load/store multiples)
25816 -mvfpxd VFP Single precision
25817 -mvfp All VFP
25818 -mno-fpu Disable all floating point instructions
25819
25820 The following CPU names are recognized:
25821 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25822 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25823 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25824 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25825 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25826 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25827 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
25828
25829 */
25830
25831 const char * md_shortopts = "m:k";
25832
25833 #ifdef ARM_BI_ENDIAN
25834 #define OPTION_EB (OPTION_MD_BASE + 0)
25835 #define OPTION_EL (OPTION_MD_BASE + 1)
25836 #else
25837 #if TARGET_BYTES_BIG_ENDIAN
25838 #define OPTION_EB (OPTION_MD_BASE + 0)
25839 #else
25840 #define OPTION_EL (OPTION_MD_BASE + 1)
25841 #endif
25842 #endif
25843 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
25844 #define OPTION_FDPIC (OPTION_MD_BASE + 3)
25845
25846 struct option md_longopts[] =
25847 {
25848 #ifdef OPTION_EB
25849 {"EB", no_argument, NULL, OPTION_EB},
25850 #endif
25851 #ifdef OPTION_EL
25852 {"EL", no_argument, NULL, OPTION_EL},
25853 #endif
25854 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
25855 #ifdef OBJ_ELF
25856 {"fdpic", no_argument, NULL, OPTION_FDPIC},
25857 #endif
25858 {NULL, no_argument, NULL, 0}
25859 };
25860
25861 size_t md_longopts_size = sizeof (md_longopts);
25862
25863 struct arm_option_table
25864 {
25865 const char * option; /* Option name to match. */
25866 const char * help; /* Help information. */
25867 int * var; /* Variable to change. */
25868 int value; /* What to change it to. */
25869 const char * deprecated; /* If non-null, print this message. */
25870 };
25871
25872 struct arm_option_table arm_opts[] =
25873 {
25874 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25875 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25876 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25877 &support_interwork, 1, NULL},
25878 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25879 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25880 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25881 1, NULL},
25882 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25883 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25884 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25885 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25886 NULL},
25887
25888 /* These are recognized by the assembler, but have no affect on code. */
25889 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25890 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
25891
25892 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25893 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25894 &warn_on_deprecated, 0, NULL},
25895 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25896 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
25897 {NULL, NULL, NULL, 0, NULL}
25898 };
25899
25900 struct arm_legacy_option_table
25901 {
25902 const char * option; /* Option name to match. */
25903 const arm_feature_set ** var; /* Variable to change. */
25904 const arm_feature_set value; /* What to change it to. */
25905 const char * deprecated; /* If non-null, print this message. */
25906 };
25907
25908 const struct arm_legacy_option_table arm_legacy_opts[] =
25909 {
25910 /* DON'T add any new processors to this list -- we want the whole list
25911 to go away... Add them to the processors table instead. */
25912 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25913 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25914 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25915 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25916 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25917 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25918 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25919 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25920 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25921 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25922 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25923 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25924 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25925 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25926 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25927 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25928 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25929 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25930 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25931 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25932 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25933 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25934 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25935 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25936 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25937 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25938 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25939 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25940 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25941 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25942 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25943 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25944 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25945 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25946 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25947 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25948 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25949 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25950 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25951 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25952 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25953 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25954 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25955 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25956 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25957 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25958 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25959 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25960 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25961 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25962 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25963 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25964 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25965 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25966 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25967 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25968 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25969 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25970 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25971 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25972 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25973 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25974 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25975 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25976 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25977 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25978 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25979 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25980 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25981 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
25982 N_("use -mcpu=strongarm110")},
25983 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
25984 N_("use -mcpu=strongarm1100")},
25985 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
25986 N_("use -mcpu=strongarm1110")},
25987 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25988 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25989 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
25990
25991 /* Architecture variants -- don't add any more to this list either. */
25992 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25993 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25994 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25995 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25996 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25997 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25998 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25999 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
26000 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
26001 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
26002 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
26003 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
26004 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
26005 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
26006 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
26007 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
26008 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
26009 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
26010
26011 /* Floating point variants -- don't add any more to this list either. */
26012 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
26013 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
26014 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
26015 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
26016 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
26017
26018 {NULL, NULL, ARM_ARCH_NONE, NULL}
26019 };
26020
26021 struct arm_cpu_option_table
26022 {
26023 const char * name;
26024 size_t name_len;
26025 const arm_feature_set value;
26026 const arm_feature_set ext;
26027 /* For some CPUs we assume an FPU unless the user explicitly sets
26028 -mfpu=... */
26029 const arm_feature_set default_fpu;
26030 /* The canonical name of the CPU, or NULL to use NAME converted to upper
26031 case. */
26032 const char * canonical_name;
26033 };
26034
26035 /* This list should, at a minimum, contain all the cpu names
26036 recognized by GCC. */
26037 #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
26038
26039 static const struct arm_cpu_option_table arm_cpus[] =
26040 {
26041 ARM_CPU_OPT ("all", NULL, ARM_ANY,
26042 ARM_ARCH_NONE,
26043 FPU_ARCH_FPA),
26044 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
26045 ARM_ARCH_NONE,
26046 FPU_ARCH_FPA),
26047 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
26048 ARM_ARCH_NONE,
26049 FPU_ARCH_FPA),
26050 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
26051 ARM_ARCH_NONE,
26052 FPU_ARCH_FPA),
26053 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
26054 ARM_ARCH_NONE,
26055 FPU_ARCH_FPA),
26056 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
26057 ARM_ARCH_NONE,
26058 FPU_ARCH_FPA),
26059 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
26060 ARM_ARCH_NONE,
26061 FPU_ARCH_FPA),
26062 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
26063 ARM_ARCH_NONE,
26064 FPU_ARCH_FPA),
26065 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
26066 ARM_ARCH_NONE,
26067 FPU_ARCH_FPA),
26068 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
26069 ARM_ARCH_NONE,
26070 FPU_ARCH_FPA),
26071 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
26072 ARM_ARCH_NONE,
26073 FPU_ARCH_FPA),
26074 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
26075 ARM_ARCH_NONE,
26076 FPU_ARCH_FPA),
26077 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
26078 ARM_ARCH_NONE,
26079 FPU_ARCH_FPA),
26080 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
26081 ARM_ARCH_NONE,
26082 FPU_ARCH_FPA),
26083 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
26084 ARM_ARCH_NONE,
26085 FPU_ARCH_FPA),
26086 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
26087 ARM_ARCH_NONE,
26088 FPU_ARCH_FPA),
26089 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
26090 ARM_ARCH_NONE,
26091 FPU_ARCH_FPA),
26092 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
26093 ARM_ARCH_NONE,
26094 FPU_ARCH_FPA),
26095 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
26096 ARM_ARCH_NONE,
26097 FPU_ARCH_FPA),
26098 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
26099 ARM_ARCH_NONE,
26100 FPU_ARCH_FPA),
26101 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
26102 ARM_ARCH_NONE,
26103 FPU_ARCH_FPA),
26104 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
26105 ARM_ARCH_NONE,
26106 FPU_ARCH_FPA),
26107 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
26108 ARM_ARCH_NONE,
26109 FPU_ARCH_FPA),
26110 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
26111 ARM_ARCH_NONE,
26112 FPU_ARCH_FPA),
26113 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
26114 ARM_ARCH_NONE,
26115 FPU_ARCH_FPA),
26116 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
26117 ARM_ARCH_NONE,
26118 FPU_ARCH_FPA),
26119 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
26120 ARM_ARCH_NONE,
26121 FPU_ARCH_FPA),
26122 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
26123 ARM_ARCH_NONE,
26124 FPU_ARCH_FPA),
26125 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
26126 ARM_ARCH_NONE,
26127 FPU_ARCH_FPA),
26128 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
26129 ARM_ARCH_NONE,
26130 FPU_ARCH_FPA),
26131 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
26132 ARM_ARCH_NONE,
26133 FPU_ARCH_FPA),
26134 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
26135 ARM_ARCH_NONE,
26136 FPU_ARCH_FPA),
26137 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
26138 ARM_ARCH_NONE,
26139 FPU_ARCH_FPA),
26140 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
26141 ARM_ARCH_NONE,
26142 FPU_ARCH_FPA),
26143 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
26144 ARM_ARCH_NONE,
26145 FPU_ARCH_FPA),
26146 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
26147 ARM_ARCH_NONE,
26148 FPU_ARCH_FPA),
26149 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
26150 ARM_ARCH_NONE,
26151 FPU_ARCH_FPA),
26152 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
26153 ARM_ARCH_NONE,
26154 FPU_ARCH_FPA),
26155 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
26156 ARM_ARCH_NONE,
26157 FPU_ARCH_FPA),
26158 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
26159 ARM_ARCH_NONE,
26160 FPU_ARCH_FPA),
26161 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
26162 ARM_ARCH_NONE,
26163 FPU_ARCH_FPA),
26164 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
26165 ARM_ARCH_NONE,
26166 FPU_ARCH_FPA),
26167 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
26168 ARM_ARCH_NONE,
26169 FPU_ARCH_FPA),
26170 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
26171 ARM_ARCH_NONE,
26172 FPU_ARCH_FPA),
26173 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
26174 ARM_ARCH_NONE,
26175 FPU_ARCH_FPA),
26176 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
26177 ARM_ARCH_NONE,
26178 FPU_ARCH_FPA),
26179
26180 /* For V5 or later processors we default to using VFP; but the user
26181 should really set the FPU type explicitly. */
26182 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
26183 ARM_ARCH_NONE,
26184 FPU_ARCH_VFP_V2),
26185 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
26186 ARM_ARCH_NONE,
26187 FPU_ARCH_VFP_V2),
26188 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26189 ARM_ARCH_NONE,
26190 FPU_ARCH_VFP_V2),
26191 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26192 ARM_ARCH_NONE,
26193 FPU_ARCH_VFP_V2),
26194 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
26195 ARM_ARCH_NONE,
26196 FPU_ARCH_VFP_V2),
26197 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
26198 ARM_ARCH_NONE,
26199 FPU_ARCH_VFP_V2),
26200 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
26201 ARM_ARCH_NONE,
26202 FPU_ARCH_VFP_V2),
26203 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
26204 ARM_ARCH_NONE,
26205 FPU_ARCH_VFP_V2),
26206 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
26207 ARM_ARCH_NONE,
26208 FPU_ARCH_VFP_V2),
26209 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
26210 ARM_ARCH_NONE,
26211 FPU_ARCH_VFP_V2),
26212 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
26213 ARM_ARCH_NONE,
26214 FPU_ARCH_VFP_V2),
26215 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
26216 ARM_ARCH_NONE,
26217 FPU_ARCH_VFP_V2),
26218 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
26219 ARM_ARCH_NONE,
26220 FPU_ARCH_VFP_V1),
26221 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
26222 ARM_ARCH_NONE,
26223 FPU_ARCH_VFP_V1),
26224 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
26225 ARM_ARCH_NONE,
26226 FPU_ARCH_VFP_V2),
26227 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
26228 ARM_ARCH_NONE,
26229 FPU_ARCH_VFP_V2),
26230 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
26231 ARM_ARCH_NONE,
26232 FPU_ARCH_VFP_V1),
26233 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
26234 ARM_ARCH_NONE,
26235 FPU_ARCH_VFP_V2),
26236 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
26237 ARM_ARCH_NONE,
26238 FPU_ARCH_VFP_V2),
26239 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
26240 ARM_ARCH_NONE,
26241 FPU_ARCH_VFP_V2),
26242 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
26243 ARM_ARCH_NONE,
26244 FPU_ARCH_VFP_V2),
26245 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
26246 ARM_ARCH_NONE,
26247 FPU_ARCH_VFP_V2),
26248 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
26249 ARM_ARCH_NONE,
26250 FPU_ARCH_VFP_V2),
26251 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
26252 ARM_ARCH_NONE,
26253 FPU_ARCH_VFP_V2),
26254 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
26255 ARM_ARCH_NONE,
26256 FPU_ARCH_VFP_V2),
26257 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
26258 ARM_ARCH_NONE,
26259 FPU_ARCH_VFP_V2),
26260 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
26261 ARM_ARCH_NONE,
26262 FPU_NONE),
26263 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
26264 ARM_ARCH_NONE,
26265 FPU_NONE),
26266 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
26267 ARM_ARCH_NONE,
26268 FPU_ARCH_VFP_V2),
26269 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
26270 ARM_ARCH_NONE,
26271 FPU_ARCH_VFP_V2),
26272 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
26273 ARM_ARCH_NONE,
26274 FPU_ARCH_VFP_V2),
26275 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
26276 ARM_ARCH_NONE,
26277 FPU_NONE),
26278 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
26279 ARM_ARCH_NONE,
26280 FPU_NONE),
26281 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
26282 ARM_ARCH_NONE,
26283 FPU_ARCH_VFP_V2),
26284 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
26285 ARM_ARCH_NONE,
26286 FPU_NONE),
26287 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26288 ARM_ARCH_NONE,
26289 FPU_ARCH_VFP_V2),
26290 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26291 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26292 FPU_NONE),
26293 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26294 ARM_ARCH_NONE,
26295 FPU_ARCH_NEON_VFP_V4),
26296 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26297 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26298 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26299 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26300 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26301 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26302 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26303 ARM_ARCH_NONE,
26304 FPU_ARCH_NEON_VFP_V4),
26305 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26306 ARM_ARCH_NONE,
26307 FPU_ARCH_NEON_VFP_V4),
26308 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26309 ARM_ARCH_NONE,
26310 FPU_ARCH_NEON_VFP_V4),
26311 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26312 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26313 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26314 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26315 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26316 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26317 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26318 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26319 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26320 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26321 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26322 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
26323 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26324 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26325 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26326 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26327 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26328 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26329 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26330 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26331 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26332 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26333 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26334 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
26335 ARM_CPU_OPT ("cortex-a76", "Cortex-A76", ARM_ARCH_V8_2A,
26336 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26337 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
26338 ARM_CPU_OPT ("ares", "Ares", ARM_ARCH_V8_2A,
26339 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26340 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
26341 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26342 ARM_ARCH_NONE,
26343 FPU_NONE),
26344 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26345 ARM_ARCH_NONE,
26346 FPU_ARCH_VFP_V3D16),
26347 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26348 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26349 FPU_NONE),
26350 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26351 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26352 FPU_ARCH_VFP_V3D16),
26353 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26354 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26355 FPU_ARCH_VFP_V3D16),
26356 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26357 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26358 FPU_ARCH_NEON_VFP_ARMV8),
26359 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26360 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26361 FPU_NONE),
26362 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26363 ARM_ARCH_NONE,
26364 FPU_NONE),
26365 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26366 ARM_ARCH_NONE,
26367 FPU_NONE),
26368 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26369 ARM_ARCH_NONE,
26370 FPU_NONE),
26371 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26372 ARM_ARCH_NONE,
26373 FPU_NONE),
26374 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26375 ARM_ARCH_NONE,
26376 FPU_NONE),
26377 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26378 ARM_ARCH_NONE,
26379 FPU_NONE),
26380 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26381 ARM_ARCH_NONE,
26382 FPU_NONE),
26383 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26384 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26385 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26386 ARM_CPU_OPT ("neoverse-n1", "Neoverse N1", ARM_ARCH_V8_2A,
26387 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26388 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
26389 /* ??? XSCALE is really an architecture. */
26390 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26391 ARM_ARCH_NONE,
26392 FPU_ARCH_VFP_V2),
26393
26394 /* ??? iwmmxt is not a processor. */
26395 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26396 ARM_ARCH_NONE,
26397 FPU_ARCH_VFP_V2),
26398 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26399 ARM_ARCH_NONE,
26400 FPU_ARCH_VFP_V2),
26401 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26402 ARM_ARCH_NONE,
26403 FPU_ARCH_VFP_V2),
26404
26405 /* Maverick. */
26406 ARM_CPU_OPT ("ep9312", "ARM920T",
26407 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26408 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26409
26410 /* Marvell processors. */
26411 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26412 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26413 FPU_ARCH_VFP_V3D16),
26414 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26415 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26416 FPU_ARCH_NEON_VFP_V4),
26417
26418 /* APM X-Gene family. */
26419 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26420 ARM_ARCH_NONE,
26421 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26422 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26423 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26424 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26425
26426 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
26427 };
26428 #undef ARM_CPU_OPT
26429
26430 struct arm_ext_table
26431 {
26432 const char * name;
26433 size_t name_len;
26434 const arm_feature_set merge;
26435 const arm_feature_set clear;
26436 };
26437
26438 struct arm_arch_option_table
26439 {
26440 const char * name;
26441 size_t name_len;
26442 const arm_feature_set value;
26443 const arm_feature_set default_fpu;
26444 const struct arm_ext_table * ext_table;
26445 };
26446
26447 /* Used to add support for +E and +noE extension. */
26448 #define ARM_EXT(E, M, C) { E, sizeof (E) - 1, M, C }
26449 /* Used to add support for a +E extension. */
26450 #define ARM_ADD(E, M) { E, sizeof(E) - 1, M, ARM_ARCH_NONE }
26451 /* Used to add support for a +noE extension. */
26452 #define ARM_REMOVE(E, C) { E, sizeof(E) -1, ARM_ARCH_NONE, C }
26453
26454 #define ALL_FP ARM_FEATURE (0, ARM_EXT2_FP16_INST | ARM_EXT2_FP16_FML, \
26455 ~0 & ~FPU_ENDIAN_PURE)
26456
26457 static const struct arm_ext_table armv5te_ext_table[] =
26458 {
26459 ARM_EXT ("fp", FPU_ARCH_VFP_V2, ALL_FP),
26460 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26461 };
26462
26463 static const struct arm_ext_table armv7_ext_table[] =
26464 {
26465 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26466 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26467 };
26468
26469 static const struct arm_ext_table armv7ve_ext_table[] =
26470 {
26471 ARM_EXT ("fp", FPU_ARCH_VFP_V4D16, ALL_FP),
26472 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16),
26473 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
26474 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26475 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
26476 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16), /* Alias for +fp. */
26477 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
26478
26479 ARM_EXT ("simd", FPU_ARCH_NEON_VFP_V4,
26480 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
26481
26482 /* Aliases for +simd. */
26483 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
26484
26485 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26486 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26487 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
26488
26489 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26490 };
26491
26492 static const struct arm_ext_table armv7a_ext_table[] =
26493 {
26494 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26495 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
26496 ARM_ADD ("vfpv3", FPU_ARCH_VFP_V3),
26497 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26498 ARM_ADD ("vfpv3-fp16", FPU_ARCH_VFP_V3_FP16),
26499 ARM_ADD ("vfpv4-d16", FPU_ARCH_VFP_V4D16),
26500 ARM_ADD ("vfpv4", FPU_ARCH_VFP_V4),
26501
26502 ARM_EXT ("simd", FPU_ARCH_VFP_V3_PLUS_NEON_V1,
26503 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_NEON_EXT_FMA)),
26504
26505 /* Aliases for +simd. */
26506 ARM_ADD ("neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26507 ARM_ADD ("neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1),
26508
26509 ARM_ADD ("neon-fp16", FPU_ARCH_NEON_FP16),
26510 ARM_ADD ("neon-vfpv4", FPU_ARCH_NEON_VFP_V4),
26511
26512 ARM_ADD ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP)),
26513 ARM_ADD ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC)),
26514 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26515 };
26516
26517 static const struct arm_ext_table armv7r_ext_table[] =
26518 {
26519 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V3xD),
26520 ARM_ADD ("vfpv3xd", FPU_ARCH_VFP_V3xD), /* Alias for +fp.sp. */
26521 ARM_EXT ("fp", FPU_ARCH_VFP_V3D16, ALL_FP),
26522 ARM_ADD ("vfpv3-d16", FPU_ARCH_VFP_V3D16), /* Alias for +fp. */
26523 ARM_ADD ("vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16),
26524 ARM_ADD ("vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16),
26525 ARM_EXT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
26526 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV)),
26527 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26528 };
26529
26530 static const struct arm_ext_table armv7em_ext_table[] =
26531 {
26532 ARM_EXT ("fp", FPU_ARCH_VFP_V4_SP_D16, ALL_FP),
26533 /* Alias for +fp, used to be known as fpv4-sp-d16. */
26534 ARM_ADD ("vfpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16),
26535 ARM_ADD ("fpv5", FPU_ARCH_VFP_V5_SP_D16),
26536 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
26537 ARM_ADD ("fpv5-d16", FPU_ARCH_VFP_V5D16),
26538 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26539 };
26540
26541 static const struct arm_ext_table armv8a_ext_table[] =
26542 {
26543 ARM_ADD ("crc", ARCH_CRC_ARMV8),
26544 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
26545 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
26546 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26547
26548 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26549 should use the +simd option to turn on FP. */
26550 ARM_REMOVE ("fp", ALL_FP),
26551 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26552 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26553 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26554 };
26555
26556
26557 static const struct arm_ext_table armv81a_ext_table[] =
26558 {
26559 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
26560 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
26561 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26562
26563 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26564 should use the +simd option to turn on FP. */
26565 ARM_REMOVE ("fp", ALL_FP),
26566 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26567 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26568 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26569 };
26570
26571 static const struct arm_ext_table armv82a_ext_table[] =
26572 {
26573 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8_1),
26574 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_2_FP16),
26575 ARM_ADD ("fp16fml", FPU_ARCH_NEON_VFP_ARMV8_2_FP16FML),
26576 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1,
26577 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26578 ARM_ADD ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26579
26580 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26581 should use the +simd option to turn on FP. */
26582 ARM_REMOVE ("fp", ALL_FP),
26583 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26584 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26585 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26586 };
26587
26588 static const struct arm_ext_table armv84a_ext_table[] =
26589 {
26590 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26591 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
26592 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
26593 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26594
26595 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26596 should use the +simd option to turn on FP. */
26597 ARM_REMOVE ("fp", ALL_FP),
26598 ARM_ADD ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB)),
26599 ARM_ADD ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES)),
26600 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26601 };
26602
26603 static const struct arm_ext_table armv85a_ext_table[] =
26604 {
26605 ARM_ADD ("simd", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8),
26606 ARM_ADD ("fp16", FPU_ARCH_NEON_VFP_ARMV8_4_FP16FML),
26607 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_4,
26608 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26609
26610 /* Armv8-a does not allow an FP implementation without SIMD, so the user
26611 should use the +simd option to turn on FP. */
26612 ARM_REMOVE ("fp", ALL_FP),
26613 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26614 };
26615
26616 static const struct arm_ext_table armv8m_main_ext_table[] =
26617 {
26618 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26619 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
26620 ARM_EXT ("fp", FPU_ARCH_VFP_V5_SP_D16, ALL_FP),
26621 ARM_ADD ("fp.dp", FPU_ARCH_VFP_V5D16),
26622 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26623 };
26624
26625 static const struct arm_ext_table armv8_1m_main_ext_table[] =
26626 {
26627 ARM_EXT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26628 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP)),
26629 ARM_EXT ("fp",
26630 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
26631 FPU_VFP_V5_SP_D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA),
26632 ALL_FP),
26633 ARM_ADD ("fp.dp",
26634 ARM_FEATURE (0, ARM_EXT2_FP16_INST,
26635 FPU_VFP_V5D16 | FPU_VFP_EXT_FP16 | FPU_VFP_EXT_FMA)),
26636 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26637 };
26638
26639 static const struct arm_ext_table armv8r_ext_table[] =
26640 {
26641 ARM_ADD ("crc", ARCH_CRC_ARMV8),
26642 ARM_ADD ("simd", FPU_ARCH_NEON_VFP_ARMV8),
26643 ARM_EXT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
26644 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8)),
26645 ARM_REMOVE ("fp", ALL_FP),
26646 ARM_ADD ("fp.sp", FPU_ARCH_VFP_V5_SP_D16),
26647 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26648 };
26649
26650 /* This list should, at a minimum, contain all the architecture names
26651 recognized by GCC. */
26652 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF, NULL }
26653 #define ARM_ARCH_OPT2(N, V, DF, ext) \
26654 { N, sizeof (N) - 1, V, DF, ext##_ext_table }
26655
26656 static const struct arm_arch_option_table arm_archs[] =
26657 {
26658 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
26659 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
26660 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
26661 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
26662 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
26663 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
26664 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
26665 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
26666 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
26667 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
26668 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26669 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26670 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26671 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
26672 ARM_ARCH_OPT2 ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP, armv5te),
26673 ARM_ARCH_OPT2 ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP, armv5te),
26674 ARM_ARCH_OPT2 ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP, armv5te),
26675 ARM_ARCH_OPT2 ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
26676 ARM_ARCH_OPT2 ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP, armv5te),
26677 ARM_ARCH_OPT2 ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP, armv5te),
26678 ARM_ARCH_OPT2 ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP, armv5te),
26679 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26680 kept to preserve existing behaviour. */
26681 ARM_ARCH_OPT2 ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
26682 ARM_ARCH_OPT2 ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP, armv5te),
26683 ARM_ARCH_OPT2 ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP, armv5te),
26684 ARM_ARCH_OPT2 ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP, armv5te),
26685 ARM_ARCH_OPT2 ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP, armv5te),
26686 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26687 kept to preserve existing behaviour. */
26688 ARM_ARCH_OPT2 ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
26689 ARM_ARCH_OPT2 ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP, armv5te),
26690 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26691 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26692 ARM_ARCH_OPT2 ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP, armv7),
26693 /* The official spelling of the ARMv7 profile variants is the dashed form.
26694 Accept the non-dashed form for compatibility with old toolchains. */
26695 ARM_ARCH_OPT2 ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
26696 ARM_ARCH_OPT2 ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP, armv7ve),
26697 ARM_ARCH_OPT2 ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
26698 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26699 ARM_ARCH_OPT2 ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP, armv7a),
26700 ARM_ARCH_OPT2 ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP, armv7r),
26701 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26702 ARM_ARCH_OPT2 ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP, armv7em),
26703 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
26704 ARM_ARCH_OPT2 ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP,
26705 armv8m_main),
26706 ARM_ARCH_OPT2 ("armv8.1-m.main", ARM_ARCH_V8_1M_MAIN, FPU_ARCH_VFP,
26707 armv8_1m_main),
26708 ARM_ARCH_OPT2 ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP, armv8a),
26709 ARM_ARCH_OPT2 ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP, armv81a),
26710 ARM_ARCH_OPT2 ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP, armv82a),
26711 ARM_ARCH_OPT2 ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP, armv82a),
26712 ARM_ARCH_OPT2 ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP, armv8r),
26713 ARM_ARCH_OPT2 ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP, armv84a),
26714 ARM_ARCH_OPT2 ("armv8.5-a", ARM_ARCH_V8_5A, FPU_ARCH_VFP, armv85a),
26715 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26716 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26717 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2, FPU_ARCH_VFP),
26718 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
26719 };
26720 #undef ARM_ARCH_OPT
26721
26722 /* ISA extensions in the co-processor and main instruction set space. */
26723
26724 struct arm_option_extension_value_table
26725 {
26726 const char * name;
26727 size_t name_len;
26728 const arm_feature_set merge_value;
26729 const arm_feature_set clear_value;
26730 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26731 indicates that an extension is available for all architectures while
26732 ARM_ANY marks an empty entry. */
26733 const arm_feature_set allowed_archs[2];
26734 };
26735
26736 /* The following table must be in alphabetical order with a NULL last entry. */
26737
26738 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26739 #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
26740
26741 /* DEPRECATED: Refrain from using this table to add any new extensions, instead
26742 use the context sensitive approach using arm_ext_table's. */
26743 static const struct arm_option_extension_value_table arm_extensions[] =
26744 {
26745 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26746 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
26747 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
26748 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26749 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
26750 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26751 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26752 ARM_ARCH_V8_2A),
26753 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26754 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26755 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
26756 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26757 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
26758 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26759 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26760 ARM_ARCH_V8_2A),
26761 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26762 | ARM_EXT2_FP16_FML),
26763 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26764 | ARM_EXT2_FP16_FML),
26765 ARM_ARCH_V8_2A),
26766 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
26767 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
26768 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26769 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
26770 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26771 Thumb divide instruction. Due to this having the same name as the
26772 previous entry, this will be ignored when doing command-line parsing and
26773 only considered by build attribute selection code. */
26774 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26775 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26776 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
26777 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
26778 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
26779 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
26780 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
26781 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
26782 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26783 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
26784 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
26785 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26786 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
26787 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26788 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26789 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
26790 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26791 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
26792 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
26793 ARM_EXT_OPT ("predres", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
26794 ARM_FEATURE_CORE_HIGH (ARM_EXT2_PREDRES),
26795 ARM_ARCH_V8A),
26796 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26797 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
26798 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
26799 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26800 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
26801 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
26802 ARM_EXT_OPT ("sb", ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
26803 ARM_FEATURE_CORE_HIGH (ARM_EXT2_SB),
26804 ARM_ARCH_V8A),
26805 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26806 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26807 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26808 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26809 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26810 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26811 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
26812 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26813 | ARM_EXT_DIV),
26814 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26815 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26816 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
26817 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26818 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
26819 };
26820 #undef ARM_EXT_OPT
26821
26822 /* ISA floating-point and Advanced SIMD extensions. */
26823 struct arm_option_fpu_value_table
26824 {
26825 const char * name;
26826 const arm_feature_set value;
26827 };
26828
26829 /* This list should, at a minimum, contain all the fpu names
26830 recognized by GCC. */
26831 static const struct arm_option_fpu_value_table arm_fpus[] =
26832 {
26833 {"softfpa", FPU_NONE},
26834 {"fpe", FPU_ARCH_FPE},
26835 {"fpe2", FPU_ARCH_FPE},
26836 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26837 {"fpa", FPU_ARCH_FPA},
26838 {"fpa10", FPU_ARCH_FPA},
26839 {"fpa11", FPU_ARCH_FPA},
26840 {"arm7500fe", FPU_ARCH_FPA},
26841 {"softvfp", FPU_ARCH_VFP},
26842 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26843 {"vfp", FPU_ARCH_VFP_V2},
26844 {"vfp9", FPU_ARCH_VFP_V2},
26845 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
26846 {"vfp10", FPU_ARCH_VFP_V2},
26847 {"vfp10-r0", FPU_ARCH_VFP_V1},
26848 {"vfpxd", FPU_ARCH_VFP_V1xD},
26849 {"vfpv2", FPU_ARCH_VFP_V2},
26850 {"vfpv3", FPU_ARCH_VFP_V3},
26851 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
26852 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
26853 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26854 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26855 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
26856 {"arm1020t", FPU_ARCH_VFP_V1},
26857 {"arm1020e", FPU_ARCH_VFP_V2},
26858 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
26859 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26860 {"maverick", FPU_ARCH_MAVERICK},
26861 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
26862 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
26863 {"neon-fp16", FPU_ARCH_NEON_FP16},
26864 {"vfpv4", FPU_ARCH_VFP_V4},
26865 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
26866 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
26867 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26868 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
26869 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
26870 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26871 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26872 {"crypto-neon-fp-armv8",
26873 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
26874 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
26875 {"crypto-neon-fp-armv8.1",
26876 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
26877 {NULL, ARM_ARCH_NONE}
26878 };
26879
26880 struct arm_option_value_table
26881 {
26882 const char *name;
26883 long value;
26884 };
26885
26886 static const struct arm_option_value_table arm_float_abis[] =
26887 {
26888 {"hard", ARM_FLOAT_ABI_HARD},
26889 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26890 {"soft", ARM_FLOAT_ABI_SOFT},
26891 {NULL, 0}
26892 };
26893
26894 #ifdef OBJ_ELF
26895 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
26896 static const struct arm_option_value_table arm_eabis[] =
26897 {
26898 {"gnu", EF_ARM_EABI_UNKNOWN},
26899 {"4", EF_ARM_EABI_VER4},
26900 {"5", EF_ARM_EABI_VER5},
26901 {NULL, 0}
26902 };
26903 #endif
26904
26905 struct arm_long_option_table
26906 {
26907 const char * option; /* Substring to match. */
26908 const char * help; /* Help information. */
26909 int (* func) (const char * subopt); /* Function to decode sub-option. */
26910 const char * deprecated; /* If non-null, print this message. */
26911 };
26912
26913 static bfd_boolean
26914 arm_parse_extension (const char *str, const arm_feature_set *opt_set,
26915 arm_feature_set *ext_set,
26916 const struct arm_ext_table *ext_table)
26917 {
26918 /* We insist on extensions being specified in alphabetical order, and with
26919 extensions being added before being removed. We achieve this by having
26920 the global ARM_EXTENSIONS table in alphabetical order, and using the
26921 ADDING_VALUE variable to indicate whether we are adding an extension (1)
26922 or removing it (0) and only allowing it to change in the order
26923 -1 -> 1 -> 0. */
26924 const struct arm_option_extension_value_table * opt = NULL;
26925 const arm_feature_set arm_any = ARM_ANY;
26926 int adding_value = -1;
26927
26928 while (str != NULL && *str != 0)
26929 {
26930 const char *ext;
26931 size_t len;
26932
26933 if (*str != '+')
26934 {
26935 as_bad (_("invalid architectural extension"));
26936 return FALSE;
26937 }
26938
26939 str++;
26940 ext = strchr (str, '+');
26941
26942 if (ext != NULL)
26943 len = ext - str;
26944 else
26945 len = strlen (str);
26946
26947 if (len >= 2 && strncmp (str, "no", 2) == 0)
26948 {
26949 if (adding_value != 0)
26950 {
26951 adding_value = 0;
26952 opt = arm_extensions;
26953 }
26954
26955 len -= 2;
26956 str += 2;
26957 }
26958 else if (len > 0)
26959 {
26960 if (adding_value == -1)
26961 {
26962 adding_value = 1;
26963 opt = arm_extensions;
26964 }
26965 else if (adding_value != 1)
26966 {
26967 as_bad (_("must specify extensions to add before specifying "
26968 "those to remove"));
26969 return FALSE;
26970 }
26971 }
26972
26973 if (len == 0)
26974 {
26975 as_bad (_("missing architectural extension"));
26976 return FALSE;
26977 }
26978
26979 gas_assert (adding_value != -1);
26980 gas_assert (opt != NULL);
26981
26982 if (ext_table != NULL)
26983 {
26984 const struct arm_ext_table * ext_opt = ext_table;
26985 bfd_boolean found = FALSE;
26986 for (; ext_opt->name != NULL; ext_opt++)
26987 if (ext_opt->name_len == len
26988 && strncmp (ext_opt->name, str, len) == 0)
26989 {
26990 if (adding_value)
26991 {
26992 if (ARM_FEATURE_ZERO (ext_opt->merge))
26993 /* TODO: Option not supported. When we remove the
26994 legacy table this case should error out. */
26995 continue;
26996
26997 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, ext_opt->merge);
26998 }
26999 else
27000 {
27001 if (ARM_FEATURE_ZERO (ext_opt->clear))
27002 /* TODO: Option not supported. When we remove the
27003 legacy table this case should error out. */
27004 continue;
27005 ARM_CLEAR_FEATURE (*ext_set, *ext_set, ext_opt->clear);
27006 }
27007 found = TRUE;
27008 break;
27009 }
27010 if (found)
27011 {
27012 str = ext;
27013 continue;
27014 }
27015 }
27016
27017 /* Scan over the options table trying to find an exact match. */
27018 for (; opt->name != NULL; opt++)
27019 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
27020 {
27021 int i, nb_allowed_archs =
27022 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
27023 /* Check we can apply the extension to this architecture. */
27024 for (i = 0; i < nb_allowed_archs; i++)
27025 {
27026 /* Empty entry. */
27027 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
27028 continue;
27029 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
27030 break;
27031 }
27032 if (i == nb_allowed_archs)
27033 {
27034 as_bad (_("extension does not apply to the base architecture"));
27035 return FALSE;
27036 }
27037
27038 /* Add or remove the extension. */
27039 if (adding_value)
27040 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
27041 else
27042 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
27043
27044 /* Allowing Thumb division instructions for ARMv7 in autodetection
27045 rely on this break so that duplicate extensions (extensions
27046 with the same name as a previous extension in the list) are not
27047 considered for command-line parsing. */
27048 break;
27049 }
27050
27051 if (opt->name == NULL)
27052 {
27053 /* Did we fail to find an extension because it wasn't specified in
27054 alphabetical order, or because it does not exist? */
27055
27056 for (opt = arm_extensions; opt->name != NULL; opt++)
27057 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
27058 break;
27059
27060 if (opt->name == NULL)
27061 as_bad (_("unknown architectural extension `%s'"), str);
27062 else
27063 as_bad (_("architectural extensions must be specified in "
27064 "alphabetical order"));
27065
27066 return FALSE;
27067 }
27068 else
27069 {
27070 /* We should skip the extension we've just matched the next time
27071 round. */
27072 opt++;
27073 }
27074
27075 str = ext;
27076 };
27077
27078 return TRUE;
27079 }
27080
27081 static bfd_boolean
27082 arm_parse_cpu (const char *str)
27083 {
27084 const struct arm_cpu_option_table *opt;
27085 const char *ext = strchr (str, '+');
27086 size_t len;
27087
27088 if (ext != NULL)
27089 len = ext - str;
27090 else
27091 len = strlen (str);
27092
27093 if (len == 0)
27094 {
27095 as_bad (_("missing cpu name `%s'"), str);
27096 return FALSE;
27097 }
27098
27099 for (opt = arm_cpus; opt->name != NULL; opt++)
27100 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
27101 {
27102 mcpu_cpu_opt = &opt->value;
27103 if (mcpu_ext_opt == NULL)
27104 mcpu_ext_opt = XNEW (arm_feature_set);
27105 *mcpu_ext_opt = opt->ext;
27106 mcpu_fpu_opt = &opt->default_fpu;
27107 if (opt->canonical_name)
27108 {
27109 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
27110 strcpy (selected_cpu_name, opt->canonical_name);
27111 }
27112 else
27113 {
27114 size_t i;
27115
27116 if (len >= sizeof selected_cpu_name)
27117 len = (sizeof selected_cpu_name) - 1;
27118
27119 for (i = 0; i < len; i++)
27120 selected_cpu_name[i] = TOUPPER (opt->name[i]);
27121 selected_cpu_name[i] = 0;
27122 }
27123
27124 if (ext != NULL)
27125 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt, NULL);
27126
27127 return TRUE;
27128 }
27129
27130 as_bad (_("unknown cpu `%s'"), str);
27131 return FALSE;
27132 }
27133
27134 static bfd_boolean
27135 arm_parse_arch (const char *str)
27136 {
27137 const struct arm_arch_option_table *opt;
27138 const char *ext = strchr (str, '+');
27139 size_t len;
27140
27141 if (ext != NULL)
27142 len = ext - str;
27143 else
27144 len = strlen (str);
27145
27146 if (len == 0)
27147 {
27148 as_bad (_("missing architecture name `%s'"), str);
27149 return FALSE;
27150 }
27151
27152 for (opt = arm_archs; opt->name != NULL; opt++)
27153 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
27154 {
27155 march_cpu_opt = &opt->value;
27156 if (march_ext_opt == NULL)
27157 march_ext_opt = XNEW (arm_feature_set);
27158 *march_ext_opt = arm_arch_none;
27159 march_fpu_opt = &opt->default_fpu;
27160 strcpy (selected_cpu_name, opt->name);
27161
27162 if (ext != NULL)
27163 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt,
27164 opt->ext_table);
27165
27166 return TRUE;
27167 }
27168
27169 as_bad (_("unknown architecture `%s'\n"), str);
27170 return FALSE;
27171 }
27172
27173 static bfd_boolean
27174 arm_parse_fpu (const char * str)
27175 {
27176 const struct arm_option_fpu_value_table * opt;
27177
27178 for (opt = arm_fpus; opt->name != NULL; opt++)
27179 if (streq (opt->name, str))
27180 {
27181 mfpu_opt = &opt->value;
27182 return TRUE;
27183 }
27184
27185 as_bad (_("unknown floating point format `%s'\n"), str);
27186 return FALSE;
27187 }
27188
27189 static bfd_boolean
27190 arm_parse_float_abi (const char * str)
27191 {
27192 const struct arm_option_value_table * opt;
27193
27194 for (opt = arm_float_abis; opt->name != NULL; opt++)
27195 if (streq (opt->name, str))
27196 {
27197 mfloat_abi_opt = opt->value;
27198 return TRUE;
27199 }
27200
27201 as_bad (_("unknown floating point abi `%s'\n"), str);
27202 return FALSE;
27203 }
27204
27205 #ifdef OBJ_ELF
27206 static bfd_boolean
27207 arm_parse_eabi (const char * str)
27208 {
27209 const struct arm_option_value_table *opt;
27210
27211 for (opt = arm_eabis; opt->name != NULL; opt++)
27212 if (streq (opt->name, str))
27213 {
27214 meabi_flags = opt->value;
27215 return TRUE;
27216 }
27217 as_bad (_("unknown EABI `%s'\n"), str);
27218 return FALSE;
27219 }
27220 #endif
27221
27222 static bfd_boolean
27223 arm_parse_it_mode (const char * str)
27224 {
27225 bfd_boolean ret = TRUE;
27226
27227 if (streq ("arm", str))
27228 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
27229 else if (streq ("thumb", str))
27230 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
27231 else if (streq ("always", str))
27232 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
27233 else if (streq ("never", str))
27234 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
27235 else
27236 {
27237 as_bad (_("unknown implicit IT mode `%s', should be "\
27238 "arm, thumb, always, or never."), str);
27239 ret = FALSE;
27240 }
27241
27242 return ret;
27243 }
27244
27245 static bfd_boolean
27246 arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
27247 {
27248 codecomposer_syntax = TRUE;
27249 arm_comment_chars[0] = ';';
27250 arm_line_separator_chars[0] = 0;
27251 return TRUE;
27252 }
27253
27254 struct arm_long_option_table arm_long_opts[] =
27255 {
27256 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
27257 arm_parse_cpu, NULL},
27258 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
27259 arm_parse_arch, NULL},
27260 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
27261 arm_parse_fpu, NULL},
27262 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
27263 arm_parse_float_abi, NULL},
27264 #ifdef OBJ_ELF
27265 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
27266 arm_parse_eabi, NULL},
27267 #endif
27268 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
27269 arm_parse_it_mode, NULL},
27270 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
27271 arm_ccs_mode, NULL},
27272 {NULL, NULL, 0, NULL}
27273 };
27274
27275 int
27276 md_parse_option (int c, const char * arg)
27277 {
27278 struct arm_option_table *opt;
27279 const struct arm_legacy_option_table *fopt;
27280 struct arm_long_option_table *lopt;
27281
27282 switch (c)
27283 {
27284 #ifdef OPTION_EB
27285 case OPTION_EB:
27286 target_big_endian = 1;
27287 break;
27288 #endif
27289
27290 #ifdef OPTION_EL
27291 case OPTION_EL:
27292 target_big_endian = 0;
27293 break;
27294 #endif
27295
27296 case OPTION_FIX_V4BX:
27297 fix_v4bx = TRUE;
27298 break;
27299
27300 #ifdef OBJ_ELF
27301 case OPTION_FDPIC:
27302 arm_fdpic = TRUE;
27303 break;
27304 #endif /* OBJ_ELF */
27305
27306 case 'a':
27307 /* Listing option. Just ignore these, we don't support additional
27308 ones. */
27309 return 0;
27310
27311 default:
27312 for (opt = arm_opts; opt->option != NULL; opt++)
27313 {
27314 if (c == opt->option[0]
27315 && ((arg == NULL && opt->option[1] == 0)
27316 || streq (arg, opt->option + 1)))
27317 {
27318 /* If the option is deprecated, tell the user. */
27319 if (warn_on_deprecated && opt->deprecated != NULL)
27320 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
27321 arg ? arg : "", _(opt->deprecated));
27322
27323 if (opt->var != NULL)
27324 *opt->var = opt->value;
27325
27326 return 1;
27327 }
27328 }
27329
27330 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
27331 {
27332 if (c == fopt->option[0]
27333 && ((arg == NULL && fopt->option[1] == 0)
27334 || streq (arg, fopt->option + 1)))
27335 {
27336 /* If the option is deprecated, tell the user. */
27337 if (warn_on_deprecated && fopt->deprecated != NULL)
27338 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
27339 arg ? arg : "", _(fopt->deprecated));
27340
27341 if (fopt->var != NULL)
27342 *fopt->var = &fopt->value;
27343
27344 return 1;
27345 }
27346 }
27347
27348 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
27349 {
27350 /* These options are expected to have an argument. */
27351 if (c == lopt->option[0]
27352 && arg != NULL
27353 && strncmp (arg, lopt->option + 1,
27354 strlen (lopt->option + 1)) == 0)
27355 {
27356 /* If the option is deprecated, tell the user. */
27357 if (warn_on_deprecated && lopt->deprecated != NULL)
27358 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
27359 _(lopt->deprecated));
27360
27361 /* Call the sup-option parser. */
27362 return lopt->func (arg + strlen (lopt->option) - 1);
27363 }
27364 }
27365
27366 return 0;
27367 }
27368
27369 return 1;
27370 }
27371
27372 void
27373 md_show_usage (FILE * fp)
27374 {
27375 struct arm_option_table *opt;
27376 struct arm_long_option_table *lopt;
27377
27378 fprintf (fp, _(" ARM-specific assembler options:\n"));
27379
27380 for (opt = arm_opts; opt->option != NULL; opt++)
27381 if (opt->help != NULL)
27382 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
27383
27384 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
27385 if (lopt->help != NULL)
27386 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
27387
27388 #ifdef OPTION_EB
27389 fprintf (fp, _("\
27390 -EB assemble code for a big-endian cpu\n"));
27391 #endif
27392
27393 #ifdef OPTION_EL
27394 fprintf (fp, _("\
27395 -EL assemble code for a little-endian cpu\n"));
27396 #endif
27397
27398 fprintf (fp, _("\
27399 --fix-v4bx Allow BX in ARMv4 code\n"));
27400
27401 #ifdef OBJ_ELF
27402 fprintf (fp, _("\
27403 --fdpic generate an FDPIC object file\n"));
27404 #endif /* OBJ_ELF */
27405 }
27406
27407 #ifdef OBJ_ELF
27408
27409 typedef struct
27410 {
27411 int val;
27412 arm_feature_set flags;
27413 } cpu_arch_ver_table;
27414
27415 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
27416 chronologically for architectures, with an exception for ARMv6-M and
27417 ARMv6S-M due to legacy reasons. No new architecture should have a
27418 special case. This allows for build attribute selection results to be
27419 stable when new architectures are added. */
27420 static const cpu_arch_ver_table cpu_arch_ver[] =
27421 {
27422 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V1},
27423 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2},
27424 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V2S},
27425 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3},
27426 {TAG_CPU_ARCH_PRE_V4, ARM_ARCH_V3M},
27427 {TAG_CPU_ARCH_V4, ARM_ARCH_V4xM},
27428 {TAG_CPU_ARCH_V4, ARM_ARCH_V4},
27429 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4TxM},
27430 {TAG_CPU_ARCH_V4T, ARM_ARCH_V4T},
27431 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5xM},
27432 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5},
27433 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5TxM},
27434 {TAG_CPU_ARCH_V5T, ARM_ARCH_V5T},
27435 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TExP},
27436 {TAG_CPU_ARCH_V5TE, ARM_ARCH_V5TE},
27437 {TAG_CPU_ARCH_V5TEJ, ARM_ARCH_V5TEJ},
27438 {TAG_CPU_ARCH_V6, ARM_ARCH_V6},
27439 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6Z},
27440 {TAG_CPU_ARCH_V6KZ, ARM_ARCH_V6KZ},
27441 {TAG_CPU_ARCH_V6K, ARM_ARCH_V6K},
27442 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6T2},
27443 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KT2},
27444 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6ZT2},
27445 {TAG_CPU_ARCH_V6T2, ARM_ARCH_V6KZT2},
27446
27447 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
27448 always selected build attributes to match those of ARMv6-M
27449 (resp. ARMv6S-M). However, due to these architectures being a strict
27450 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
27451 would be selected when fully respecting chronology of architectures.
27452 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
27453 move them before ARMv7 architectures. */
27454 {TAG_CPU_ARCH_V6_M, ARM_ARCH_V6M},
27455 {TAG_CPU_ARCH_V6S_M, ARM_ARCH_V6SM},
27456
27457 {TAG_CPU_ARCH_V7, ARM_ARCH_V7},
27458 {TAG_CPU_ARCH_V7, ARM_ARCH_V7A},
27459 {TAG_CPU_ARCH_V7, ARM_ARCH_V7R},
27460 {TAG_CPU_ARCH_V7, ARM_ARCH_V7M},
27461 {TAG_CPU_ARCH_V7, ARM_ARCH_V7VE},
27462 {TAG_CPU_ARCH_V7E_M, ARM_ARCH_V7EM},
27463 {TAG_CPU_ARCH_V8, ARM_ARCH_V8A},
27464 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_1A},
27465 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_2A},
27466 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_3A},
27467 {TAG_CPU_ARCH_V8M_BASE, ARM_ARCH_V8M_BASE},
27468 {TAG_CPU_ARCH_V8M_MAIN, ARM_ARCH_V8M_MAIN},
27469 {TAG_CPU_ARCH_V8R, ARM_ARCH_V8R},
27470 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_4A},
27471 {TAG_CPU_ARCH_V8, ARM_ARCH_V8_5A},
27472 {TAG_CPU_ARCH_V8_1M_MAIN, ARM_ARCH_V8_1M_MAIN},
27473 {-1, ARM_ARCH_NONE}
27474 };
27475
27476 /* Set an attribute if it has not already been set by the user. */
27477
27478 static void
27479 aeabi_set_attribute_int (int tag, int value)
27480 {
27481 if (tag < 1
27482 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27483 || !attributes_set_explicitly[tag])
27484 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
27485 }
27486
27487 static void
27488 aeabi_set_attribute_string (int tag, const char *value)
27489 {
27490 if (tag < 1
27491 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27492 || !attributes_set_explicitly[tag])
27493 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
27494 }
27495
27496 /* Return whether features in the *NEEDED feature set are available via
27497 extensions for the architecture whose feature set is *ARCH_FSET. */
27498
27499 static bfd_boolean
27500 have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
27501 const arm_feature_set *needed)
27502 {
27503 int i, nb_allowed_archs;
27504 arm_feature_set ext_fset;
27505 const struct arm_option_extension_value_table *opt;
27506
27507 ext_fset = arm_arch_none;
27508 for (opt = arm_extensions; opt->name != NULL; opt++)
27509 {
27510 /* Extension does not provide any feature we need. */
27511 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
27512 continue;
27513
27514 nb_allowed_archs =
27515 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
27516 for (i = 0; i < nb_allowed_archs; i++)
27517 {
27518 /* Empty entry. */
27519 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
27520 break;
27521
27522 /* Extension is available, add it. */
27523 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
27524 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
27525 }
27526 }
27527
27528 /* Can we enable all features in *needed? */
27529 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
27530 }
27531
27532 /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
27533 a given architecture feature set *ARCH_EXT_FSET including extension feature
27534 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
27535 - if true, check for an exact match of the architecture modulo extensions;
27536 - otherwise, select build attribute value of the first superset
27537 architecture released so that results remains stable when new architectures
27538 are added.
27539 For -march/-mcpu=all the build attribute value of the most featureful
27540 architecture is returned. Tag_CPU_arch_profile result is returned in
27541 PROFILE. */
27542
27543 static int
27544 get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
27545 const arm_feature_set *ext_fset,
27546 char *profile, int exact_match)
27547 {
27548 arm_feature_set arch_fset;
27549 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
27550
27551 /* Select most featureful architecture with all its extensions if building
27552 for -march=all as the feature sets used to set build attributes. */
27553 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
27554 {
27555 /* Force revisiting of decision for each new architecture. */
27556 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8_1M_MAIN);
27557 *profile = 'A';
27558 return TAG_CPU_ARCH_V8;
27559 }
27560
27561 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
27562
27563 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
27564 {
27565 arm_feature_set known_arch_fset;
27566
27567 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
27568 if (exact_match)
27569 {
27570 /* Base architecture match user-specified architecture and
27571 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27572 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27573 {
27574 p_ver_ret = p_ver;
27575 goto found;
27576 }
27577 /* Base architecture match user-specified architecture only
27578 (eg. ARMv6-M in the same case as above). Record it in case we
27579 find a match with above condition. */
27580 else if (p_ver_ret == NULL
27581 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27582 p_ver_ret = p_ver;
27583 }
27584 else
27585 {
27586
27587 /* Architecture has all features wanted. */
27588 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27589 {
27590 arm_feature_set added_fset;
27591
27592 /* Compute features added by this architecture over the one
27593 recorded in p_ver_ret. */
27594 if (p_ver_ret != NULL)
27595 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27596 p_ver_ret->flags);
27597 /* First architecture that match incl. with extensions, or the
27598 only difference in features over the recorded match is
27599 features that were optional and are now mandatory. */
27600 if (p_ver_ret == NULL
27601 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27602 {
27603 p_ver_ret = p_ver;
27604 goto found;
27605 }
27606 }
27607 else if (p_ver_ret == NULL)
27608 {
27609 arm_feature_set needed_ext_fset;
27610
27611 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27612
27613 /* Architecture has all features needed when using some
27614 extensions. Record it and continue searching in case there
27615 exist an architecture providing all needed features without
27616 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27617 OS extension). */
27618 if (have_ext_for_needed_feat_p (&known_arch_fset,
27619 &needed_ext_fset))
27620 p_ver_ret = p_ver;
27621 }
27622 }
27623 }
27624
27625 if (p_ver_ret == NULL)
27626 return -1;
27627
27628 found:
27629 /* Tag_CPU_arch_profile. */
27630 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27631 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27632 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27633 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27634 *profile = 'A';
27635 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27636 *profile = 'R';
27637 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27638 *profile = 'M';
27639 else
27640 *profile = '\0';
27641 return p_ver_ret->val;
27642 }
27643
27644 /* Set the public EABI object attributes. */
27645
27646 static void
27647 aeabi_set_public_attributes (void)
27648 {
27649 char profile = '\0';
27650 int arch = -1;
27651 int virt_sec = 0;
27652 int fp16_optional = 0;
27653 int skip_exact_match = 0;
27654 arm_feature_set flags, flags_arch, flags_ext;
27655
27656 /* Autodetection mode, choose the architecture based the instructions
27657 actually used. */
27658 if (no_cpu_selected ())
27659 {
27660 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
27661
27662 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
27663 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
27664
27665 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
27666 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
27667
27668 /* Code run during relaxation relies on selected_cpu being set. */
27669 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27670 flags_ext = arm_arch_none;
27671 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
27672 selected_ext = flags_ext;
27673 selected_cpu = flags;
27674 }
27675 /* Otherwise, choose the architecture based on the capabilities of the
27676 requested cpu. */
27677 else
27678 {
27679 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
27680 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
27681 flags_ext = selected_ext;
27682 flags = selected_cpu;
27683 }
27684 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
27685
27686 /* Allow the user to override the reported architecture. */
27687 if (!ARM_FEATURE_ZERO (selected_object_arch))
27688 {
27689 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
27690 flags_ext = arm_arch_none;
27691 }
27692 else
27693 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
27694
27695 /* When this function is run again after relaxation has happened there is no
27696 way to determine whether an architecture or CPU was specified by the user:
27697 - selected_cpu is set above for relaxation to work;
27698 - march_cpu_opt is not set if only -mcpu or .cpu is used;
27699 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
27700 Therefore, if not in -march=all case we first try an exact match and fall
27701 back to autodetection. */
27702 if (!skip_exact_match)
27703 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
27704 if (arch == -1)
27705 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
27706 if (arch == -1)
27707 as_bad (_("no architecture contains all the instructions used\n"));
27708
27709 /* Tag_CPU_name. */
27710 if (selected_cpu_name[0])
27711 {
27712 char *q;
27713
27714 q = selected_cpu_name;
27715 if (strncmp (q, "armv", 4) == 0)
27716 {
27717 int i;
27718
27719 q += 4;
27720 for (i = 0; q[i]; i++)
27721 q[i] = TOUPPER (q[i]);
27722 }
27723 aeabi_set_attribute_string (Tag_CPU_name, q);
27724 }
27725
27726 /* Tag_CPU_arch. */
27727 aeabi_set_attribute_int (Tag_CPU_arch, arch);
27728
27729 /* Tag_CPU_arch_profile. */
27730 if (profile != '\0')
27731 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
27732
27733 /* Tag_DSP_extension. */
27734 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
27735 aeabi_set_attribute_int (Tag_DSP_extension, 1);
27736
27737 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27738 /* Tag_ARM_ISA_use. */
27739 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
27740 || ARM_FEATURE_ZERO (flags_arch))
27741 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
27742
27743 /* Tag_THUMB_ISA_use. */
27744 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
27745 || ARM_FEATURE_ZERO (flags_arch))
27746 {
27747 int thumb_isa_use;
27748
27749 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27750 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
27751 thumb_isa_use = 3;
27752 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27753 thumb_isa_use = 2;
27754 else
27755 thumb_isa_use = 1;
27756 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27757 }
27758
27759 /* Tag_VFP_arch. */
27760 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27761 aeabi_set_attribute_int (Tag_VFP_arch,
27762 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27763 ? 7 : 8);
27764 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
27765 aeabi_set_attribute_int (Tag_VFP_arch,
27766 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27767 ? 5 : 6);
27768 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
27769 {
27770 fp16_optional = 1;
27771 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27772 }
27773 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
27774 {
27775 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27776 fp16_optional = 1;
27777 }
27778 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27779 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27780 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
27781 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
27782 aeabi_set_attribute_int (Tag_VFP_arch, 1);
27783
27784 /* Tag_ABI_HardFP_use. */
27785 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27786 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27787 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27788
27789 /* Tag_WMMX_arch. */
27790 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27791 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27792 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27793 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
27794
27795 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
27796 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27797 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27798 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
27799 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27800 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27801 {
27802 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27803 {
27804 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27805 }
27806 else
27807 {
27808 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27809 fp16_optional = 1;
27810 }
27811 }
27812
27813 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
27814 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
27815 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
27816
27817 /* Tag_DIV_use.
27818
27819 We set Tag_DIV_use to two when integer divide instructions have been used
27820 in ARM state, or when Thumb integer divide instructions have been used,
27821 but we have no architecture profile set, nor have we any ARM instructions.
27822
27823 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27824 by the base architecture.
27825
27826 For new architectures we will have to check these tests. */
27827 gas_assert (arch <= TAG_CPU_ARCH_V8_1M_MAIN);
27828 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27829 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
27830 aeabi_set_attribute_int (Tag_DIV_use, 0);
27831 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27832 || (profile == '\0'
27833 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27834 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
27835 aeabi_set_attribute_int (Tag_DIV_use, 2);
27836
27837 /* Tag_MP_extension_use. */
27838 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27839 aeabi_set_attribute_int (Tag_MPextension_use, 1);
27840
27841 /* Tag Virtualization_use. */
27842 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
27843 virt_sec |= 1;
27844 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27845 virt_sec |= 2;
27846 if (virt_sec != 0)
27847 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
27848 }
27849
27850 /* Post relaxation hook. Recompute ARM attributes now that relaxation is
27851 finished and free extension feature bits which will not be used anymore. */
27852
27853 void
27854 arm_md_post_relax (void)
27855 {
27856 aeabi_set_public_attributes ();
27857 XDELETE (mcpu_ext_opt);
27858 mcpu_ext_opt = NULL;
27859 XDELETE (march_ext_opt);
27860 march_ext_opt = NULL;
27861 }
27862
27863 /* Add the default contents for the .ARM.attributes section. */
27864
27865 void
27866 arm_md_end (void)
27867 {
27868 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27869 return;
27870
27871 aeabi_set_public_attributes ();
27872 }
27873 #endif /* OBJ_ELF */
27874
27875 /* Parse a .cpu directive. */
27876
27877 static void
27878 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27879 {
27880 const struct arm_cpu_option_table *opt;
27881 char *name;
27882 char saved_char;
27883
27884 name = input_line_pointer;
27885 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27886 input_line_pointer++;
27887 saved_char = *input_line_pointer;
27888 *input_line_pointer = 0;
27889
27890 /* Skip the first "all" entry. */
27891 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27892 if (streq (opt->name, name))
27893 {
27894 selected_arch = opt->value;
27895 selected_ext = opt->ext;
27896 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
27897 if (opt->canonical_name)
27898 strcpy (selected_cpu_name, opt->canonical_name);
27899 else
27900 {
27901 int i;
27902 for (i = 0; opt->name[i]; i++)
27903 selected_cpu_name[i] = TOUPPER (opt->name[i]);
27904
27905 selected_cpu_name[i] = 0;
27906 }
27907 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27908
27909 *input_line_pointer = saved_char;
27910 demand_empty_rest_of_line ();
27911 return;
27912 }
27913 as_bad (_("unknown cpu `%s'"), name);
27914 *input_line_pointer = saved_char;
27915 ignore_rest_of_line ();
27916 }
27917
27918 /* Parse a .arch directive. */
27919
27920 static void
27921 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27922 {
27923 const struct arm_arch_option_table *opt;
27924 char saved_char;
27925 char *name;
27926
27927 name = input_line_pointer;
27928 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27929 input_line_pointer++;
27930 saved_char = *input_line_pointer;
27931 *input_line_pointer = 0;
27932
27933 /* Skip the first "all" entry. */
27934 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27935 if (streq (opt->name, name))
27936 {
27937 selected_arch = opt->value;
27938 selected_ext = arm_arch_none;
27939 selected_cpu = selected_arch;
27940 strcpy (selected_cpu_name, opt->name);
27941 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27942 *input_line_pointer = saved_char;
27943 demand_empty_rest_of_line ();
27944 return;
27945 }
27946
27947 as_bad (_("unknown architecture `%s'\n"), name);
27948 *input_line_pointer = saved_char;
27949 ignore_rest_of_line ();
27950 }
27951
27952 /* Parse a .object_arch directive. */
27953
27954 static void
27955 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27956 {
27957 const struct arm_arch_option_table *opt;
27958 char saved_char;
27959 char *name;
27960
27961 name = input_line_pointer;
27962 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27963 input_line_pointer++;
27964 saved_char = *input_line_pointer;
27965 *input_line_pointer = 0;
27966
27967 /* Skip the first "all" entry. */
27968 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27969 if (streq (opt->name, name))
27970 {
27971 selected_object_arch = opt->value;
27972 *input_line_pointer = saved_char;
27973 demand_empty_rest_of_line ();
27974 return;
27975 }
27976
27977 as_bad (_("unknown architecture `%s'\n"), name);
27978 *input_line_pointer = saved_char;
27979 ignore_rest_of_line ();
27980 }
27981
27982 /* Parse a .arch_extension directive. */
27983
27984 static void
27985 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27986 {
27987 const struct arm_option_extension_value_table *opt;
27988 char saved_char;
27989 char *name;
27990 int adding_value = 1;
27991
27992 name = input_line_pointer;
27993 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27994 input_line_pointer++;
27995 saved_char = *input_line_pointer;
27996 *input_line_pointer = 0;
27997
27998 if (strlen (name) >= 2
27999 && strncmp (name, "no", 2) == 0)
28000 {
28001 adding_value = 0;
28002 name += 2;
28003 }
28004
28005 for (opt = arm_extensions; opt->name != NULL; opt++)
28006 if (streq (opt->name, name))
28007 {
28008 int i, nb_allowed_archs =
28009 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
28010 for (i = 0; i < nb_allowed_archs; i++)
28011 {
28012 /* Empty entry. */
28013 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
28014 continue;
28015 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
28016 break;
28017 }
28018
28019 if (i == nb_allowed_archs)
28020 {
28021 as_bad (_("architectural extension `%s' is not allowed for the "
28022 "current base architecture"), name);
28023 break;
28024 }
28025
28026 if (adding_value)
28027 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
28028 opt->merge_value);
28029 else
28030 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
28031
28032 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
28033 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
28034 *input_line_pointer = saved_char;
28035 demand_empty_rest_of_line ();
28036 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
28037 on this return so that duplicate extensions (extensions with the
28038 same name as a previous extension in the list) are not considered
28039 for command-line parsing. */
28040 return;
28041 }
28042
28043 if (opt->name == NULL)
28044 as_bad (_("unknown architecture extension `%s'\n"), name);
28045
28046 *input_line_pointer = saved_char;
28047 ignore_rest_of_line ();
28048 }
28049
28050 /* Parse a .fpu directive. */
28051
28052 static void
28053 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
28054 {
28055 const struct arm_option_fpu_value_table *opt;
28056 char saved_char;
28057 char *name;
28058
28059 name = input_line_pointer;
28060 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
28061 input_line_pointer++;
28062 saved_char = *input_line_pointer;
28063 *input_line_pointer = 0;
28064
28065 for (opt = arm_fpus; opt->name != NULL; opt++)
28066 if (streq (opt->name, name))
28067 {
28068 selected_fpu = opt->value;
28069 #ifndef CPU_DEFAULT
28070 if (no_cpu_selected ())
28071 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
28072 else
28073 #endif
28074 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
28075 *input_line_pointer = saved_char;
28076 demand_empty_rest_of_line ();
28077 return;
28078 }
28079
28080 as_bad (_("unknown floating point format `%s'\n"), name);
28081 *input_line_pointer = saved_char;
28082 ignore_rest_of_line ();
28083 }
28084
28085 /* Copy symbol information. */
28086
28087 void
28088 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
28089 {
28090 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
28091 }
28092
28093 #ifdef OBJ_ELF
28094 /* Given a symbolic attribute NAME, return the proper integer value.
28095 Returns -1 if the attribute is not known. */
28096
28097 int
28098 arm_convert_symbolic_attribute (const char *name)
28099 {
28100 static const struct
28101 {
28102 const char * name;
28103 const int tag;
28104 }
28105 attribute_table[] =
28106 {
28107 /* When you modify this table you should
28108 also modify the list in doc/c-arm.texi. */
28109 #define T(tag) {#tag, tag}
28110 T (Tag_CPU_raw_name),
28111 T (Tag_CPU_name),
28112 T (Tag_CPU_arch),
28113 T (Tag_CPU_arch_profile),
28114 T (Tag_ARM_ISA_use),
28115 T (Tag_THUMB_ISA_use),
28116 T (Tag_FP_arch),
28117 T (Tag_VFP_arch),
28118 T (Tag_WMMX_arch),
28119 T (Tag_Advanced_SIMD_arch),
28120 T (Tag_PCS_config),
28121 T (Tag_ABI_PCS_R9_use),
28122 T (Tag_ABI_PCS_RW_data),
28123 T (Tag_ABI_PCS_RO_data),
28124 T (Tag_ABI_PCS_GOT_use),
28125 T (Tag_ABI_PCS_wchar_t),
28126 T (Tag_ABI_FP_rounding),
28127 T (Tag_ABI_FP_denormal),
28128 T (Tag_ABI_FP_exceptions),
28129 T (Tag_ABI_FP_user_exceptions),
28130 T (Tag_ABI_FP_number_model),
28131 T (Tag_ABI_align_needed),
28132 T (Tag_ABI_align8_needed),
28133 T (Tag_ABI_align_preserved),
28134 T (Tag_ABI_align8_preserved),
28135 T (Tag_ABI_enum_size),
28136 T (Tag_ABI_HardFP_use),
28137 T (Tag_ABI_VFP_args),
28138 T (Tag_ABI_WMMX_args),
28139 T (Tag_ABI_optimization_goals),
28140 T (Tag_ABI_FP_optimization_goals),
28141 T (Tag_compatibility),
28142 T (Tag_CPU_unaligned_access),
28143 T (Tag_FP_HP_extension),
28144 T (Tag_VFP_HP_extension),
28145 T (Tag_ABI_FP_16bit_format),
28146 T (Tag_MPextension_use),
28147 T (Tag_DIV_use),
28148 T (Tag_nodefaults),
28149 T (Tag_also_compatible_with),
28150 T (Tag_conformance),
28151 T (Tag_T2EE_use),
28152 T (Tag_Virtualization_use),
28153 T (Tag_DSP_extension),
28154 /* We deliberately do not include Tag_MPextension_use_legacy. */
28155 #undef T
28156 };
28157 unsigned int i;
28158
28159 if (name == NULL)
28160 return -1;
28161
28162 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
28163 if (streq (name, attribute_table[i].name))
28164 return attribute_table[i].tag;
28165
28166 return -1;
28167 }
28168
28169 /* Apply sym value for relocations only in the case that they are for
28170 local symbols in the same segment as the fixup and you have the
28171 respective architectural feature for blx and simple switches. */
28172
28173 int
28174 arm_apply_sym_value (struct fix * fixP, segT this_seg)
28175 {
28176 if (fixP->fx_addsy
28177 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
28178 /* PR 17444: If the local symbol is in a different section then a reloc
28179 will always be generated for it, so applying the symbol value now
28180 will result in a double offset being stored in the relocation. */
28181 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
28182 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
28183 {
28184 switch (fixP->fx_r_type)
28185 {
28186 case BFD_RELOC_ARM_PCREL_BLX:
28187 case BFD_RELOC_THUMB_PCREL_BRANCH23:
28188 if (ARM_IS_FUNC (fixP->fx_addsy))
28189 return 1;
28190 break;
28191
28192 case BFD_RELOC_ARM_PCREL_CALL:
28193 case BFD_RELOC_THUMB_PCREL_BLX:
28194 if (THUMB_IS_FUNC (fixP->fx_addsy))
28195 return 1;
28196 break;
28197
28198 default:
28199 break;
28200 }
28201
28202 }
28203 return 0;
28204 }
28205 #endif /* OBJ_ELF */