Allow integer immediate for VFP vmov instructions.
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright (C) 1994-2018 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 static const arm_feature_set arm_ext_v6_notm =
208 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_NOTM);
209 static const arm_feature_set arm_ext_v6_dsp =
210 ARM_FEATURE_CORE_LOW (ARM_EXT_V6_DSP);
211 static const arm_feature_set arm_ext_barrier =
212 ARM_FEATURE_CORE_LOW (ARM_EXT_BARRIER);
213 static const arm_feature_set arm_ext_msr =
214 ARM_FEATURE_CORE_LOW (ARM_EXT_THUMB_MSR);
215 static const arm_feature_set arm_ext_div = ARM_FEATURE_CORE_LOW (ARM_EXT_DIV);
216 static const arm_feature_set arm_ext_v7 = ARM_FEATURE_CORE_LOW (ARM_EXT_V7);
217 static const arm_feature_set arm_ext_v7a = ARM_FEATURE_CORE_LOW (ARM_EXT_V7A);
218 static const arm_feature_set arm_ext_v7r = ARM_FEATURE_CORE_LOW (ARM_EXT_V7R);
219 #ifdef OBJ_ELF
220 static const arm_feature_set ATTRIBUTE_UNUSED arm_ext_v7m = ARM_FEATURE_CORE_LOW (ARM_EXT_V7M);
221 #endif
222 static const arm_feature_set arm_ext_v8 = ARM_FEATURE_CORE_LOW (ARM_EXT_V8);
223 static const arm_feature_set arm_ext_m =
224 ARM_FEATURE_CORE (ARM_EXT_V6M | ARM_EXT_V7M,
225 ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
226 static const arm_feature_set arm_ext_mp = ARM_FEATURE_CORE_LOW (ARM_EXT_MP);
227 static const arm_feature_set arm_ext_sec = ARM_FEATURE_CORE_LOW (ARM_EXT_SEC);
228 static const arm_feature_set arm_ext_os = ARM_FEATURE_CORE_LOW (ARM_EXT_OS);
229 static const arm_feature_set arm_ext_adiv = ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV);
230 static const arm_feature_set arm_ext_virt = ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT);
231 static const arm_feature_set arm_ext_pan = ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN);
232 static const arm_feature_set arm_ext_v8m = ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M);
233 static const arm_feature_set arm_ext_v8m_main =
234 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M_MAIN);
235 /* Instructions in ARMv8-M only found in M profile architectures. */
236 static const arm_feature_set arm_ext_v8m_m_only =
237 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8M | ARM_EXT2_V8M_MAIN);
238 static const arm_feature_set arm_ext_v6t2_v8m =
239 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V6T2_V8M);
240 /* Instructions shared between ARMv8-A and ARMv8-M. */
241 static const arm_feature_set arm_ext_atomics =
242 ARM_FEATURE_CORE_HIGH (ARM_EXT2_ATOMICS);
243 #ifdef OBJ_ELF
244 /* DSP instructions Tag_DSP_extension refers to. */
245 static const arm_feature_set arm_ext_dsp =
246 ARM_FEATURE_CORE_LOW (ARM_EXT_V5E | ARM_EXT_V5ExP | ARM_EXT_V6_DSP);
247 #endif
248 static const arm_feature_set arm_ext_ras =
249 ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS);
250 /* FP16 instructions. */
251 static const arm_feature_set arm_ext_fp16 =
252 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST);
253 static const arm_feature_set arm_ext_fp16_fml =
254 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_FML);
255 static const arm_feature_set arm_ext_v8_2 =
256 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_2A);
257 static const arm_feature_set arm_ext_v8_3 =
258 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8_3A);
259
260 static const arm_feature_set arm_arch_any = ARM_ANY;
261 #ifdef OBJ_ELF
262 static const arm_feature_set fpu_any = FPU_ANY;
263 #endif
264 static const arm_feature_set arm_arch_full ATTRIBUTE_UNUSED = ARM_FEATURE (-1, -1, -1);
265 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
266 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
267
268 static const arm_feature_set arm_cext_iwmmxt2 =
269 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2);
270 static const arm_feature_set arm_cext_iwmmxt =
271 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT);
272 static const arm_feature_set arm_cext_xscale =
273 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE);
274 static const arm_feature_set arm_cext_maverick =
275 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK);
276 static const arm_feature_set fpu_fpa_ext_v1 =
277 ARM_FEATURE_COPROC (FPU_FPA_EXT_V1);
278 static const arm_feature_set fpu_fpa_ext_v2 =
279 ARM_FEATURE_COPROC (FPU_FPA_EXT_V2);
280 static const arm_feature_set fpu_vfp_ext_v1xd =
281 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1xD);
282 static const arm_feature_set fpu_vfp_ext_v1 =
283 ARM_FEATURE_COPROC (FPU_VFP_EXT_V1);
284 static const arm_feature_set fpu_vfp_ext_v2 =
285 ARM_FEATURE_COPROC (FPU_VFP_EXT_V2);
286 static const arm_feature_set fpu_vfp_ext_v3xd =
287 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3xD);
288 static const arm_feature_set fpu_vfp_ext_v3 =
289 ARM_FEATURE_COPROC (FPU_VFP_EXT_V3);
290 static const arm_feature_set fpu_vfp_ext_d32 =
291 ARM_FEATURE_COPROC (FPU_VFP_EXT_D32);
292 static const arm_feature_set fpu_neon_ext_v1 =
293 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1);
294 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
295 ARM_FEATURE_COPROC (FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
296 #ifdef OBJ_ELF
297 static const arm_feature_set fpu_vfp_fp16 =
298 ARM_FEATURE_COPROC (FPU_VFP_EXT_FP16);
299 static const arm_feature_set fpu_neon_ext_fma =
300 ARM_FEATURE_COPROC (FPU_NEON_EXT_FMA);
301 #endif
302 static const arm_feature_set fpu_vfp_ext_fma =
303 ARM_FEATURE_COPROC (FPU_VFP_EXT_FMA);
304 static const arm_feature_set fpu_vfp_ext_armv8 =
305 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8);
306 static const arm_feature_set fpu_vfp_ext_armv8xd =
307 ARM_FEATURE_COPROC (FPU_VFP_EXT_ARMV8xD);
308 static const arm_feature_set fpu_neon_ext_armv8 =
309 ARM_FEATURE_COPROC (FPU_NEON_EXT_ARMV8);
310 static const arm_feature_set fpu_crypto_ext_armv8 =
311 ARM_FEATURE_COPROC (FPU_CRYPTO_EXT_ARMV8);
312 static const arm_feature_set crc_ext_armv8 =
313 ARM_FEATURE_COPROC (CRC_EXT_ARMV8);
314 static const arm_feature_set fpu_neon_ext_v8_1 =
315 ARM_FEATURE_COPROC (FPU_NEON_EXT_RDMA);
316 static const arm_feature_set fpu_neon_ext_dotprod =
317 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD);
318
319 static int mfloat_abi_opt = -1;
320 /* Architecture feature bits selected by the last -mcpu/-march or .cpu/.arch
321 directive. */
322 static arm_feature_set selected_arch = ARM_ARCH_NONE;
323 /* Extension feature bits selected by the last -mcpu/-march or .arch_extension
324 directive. */
325 static arm_feature_set selected_ext = ARM_ARCH_NONE;
326 /* Feature bits selected by the last -mcpu/-march or by the combination of the
327 last .cpu/.arch directive .arch_extension directives since that
328 directive. */
329 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
330 /* FPU feature bits selected by the last -mfpu or .fpu directive. */
331 static arm_feature_set selected_fpu = FPU_NONE;
332 /* Feature bits selected by the last .object_arch directive. */
333 static arm_feature_set selected_object_arch = ARM_ARCH_NONE;
334 /* Must be long enough to hold any of the names in arm_cpus. */
335 static char selected_cpu_name[20];
336
337 extern FLONUM_TYPE generic_floating_point_number;
338
339 /* Return if no cpu was selected on command-line. */
340 static bfd_boolean
341 no_cpu_selected (void)
342 {
343 return ARM_FEATURE_EQUAL (selected_cpu, arm_arch_none);
344 }
345
346 #ifdef OBJ_ELF
347 # ifdef EABI_DEFAULT
348 static int meabi_flags = EABI_DEFAULT;
349 # else
350 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
351 # endif
352
353 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
354
355 bfd_boolean
356 arm_is_eabi (void)
357 {
358 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
359 }
360 #endif
361
362 #ifdef OBJ_ELF
363 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
364 symbolS * GOT_symbol;
365 #endif
366
367 /* 0: assemble for ARM,
368 1: assemble for Thumb,
369 2: assemble for Thumb even though target CPU does not support thumb
370 instructions. */
371 static int thumb_mode = 0;
372 /* A value distinct from the possible values for thumb_mode that we
373 can use to record whether thumb_mode has been copied into the
374 tc_frag_data field of a frag. */
375 #define MODE_RECORDED (1 << 4)
376
377 /* Specifies the intrinsic IT insn behavior mode. */
378 enum implicit_it_mode
379 {
380 IMPLICIT_IT_MODE_NEVER = 0x00,
381 IMPLICIT_IT_MODE_ARM = 0x01,
382 IMPLICIT_IT_MODE_THUMB = 0x02,
383 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
384 };
385 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
386
387 /* If unified_syntax is true, we are processing the new unified
388 ARM/Thumb syntax. Important differences from the old ARM mode:
389
390 - Immediate operands do not require a # prefix.
391 - Conditional affixes always appear at the end of the
392 instruction. (For backward compatibility, those instructions
393 that formerly had them in the middle, continue to accept them
394 there.)
395 - The IT instruction may appear, and if it does is validated
396 against subsequent conditional affixes. It does not generate
397 machine code.
398
399 Important differences from the old Thumb mode:
400
401 - Immediate operands do not require a # prefix.
402 - Most of the V6T2 instructions are only available in unified mode.
403 - The .N and .W suffixes are recognized and honored (it is an error
404 if they cannot be honored).
405 - All instructions set the flags if and only if they have an 's' affix.
406 - Conditional affixes may be used. They are validated against
407 preceding IT instructions. Unlike ARM mode, you cannot use a
408 conditional affix except in the scope of an IT instruction. */
409
410 static bfd_boolean unified_syntax = FALSE;
411
412 /* An immediate operand can start with #, and ld*, st*, pld operands
413 can contain [ and ]. We need to tell APP not to elide whitespace
414 before a [, which can appear as the first operand for pld.
415 Likewise, a { can appear as the first operand for push, pop, vld*, etc. */
416 const char arm_symbol_chars[] = "#[]{}";
417
418 enum neon_el_type
419 {
420 NT_invtype,
421 NT_untyped,
422 NT_integer,
423 NT_float,
424 NT_poly,
425 NT_signed,
426 NT_unsigned
427 };
428
429 struct neon_type_el
430 {
431 enum neon_el_type type;
432 unsigned size;
433 };
434
435 #define NEON_MAX_TYPE_ELS 4
436
437 struct neon_type
438 {
439 struct neon_type_el el[NEON_MAX_TYPE_ELS];
440 unsigned elems;
441 };
442
443 enum it_instruction_type
444 {
445 OUTSIDE_IT_INSN,
446 INSIDE_IT_INSN,
447 INSIDE_IT_LAST_INSN,
448 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
449 if inside, should be the last one. */
450 NEUTRAL_IT_INSN, /* This could be either inside or outside,
451 i.e. BKPT and NOP. */
452 IT_INSN /* The IT insn has been parsed. */
453 };
454
455 /* The maximum number of operands we need. */
456 #define ARM_IT_MAX_OPERANDS 6
457
458 struct arm_it
459 {
460 const char * error;
461 unsigned long instruction;
462 int size;
463 int size_req;
464 int cond;
465 /* "uncond_value" is set to the value in place of the conditional field in
466 unconditional versions of the instruction, or -1 if nothing is
467 appropriate. */
468 int uncond_value;
469 struct neon_type vectype;
470 /* This does not indicate an actual NEON instruction, only that
471 the mnemonic accepts neon-style type suffixes. */
472 int is_neon;
473 /* Set to the opcode if the instruction needs relaxation.
474 Zero if the instruction is not relaxed. */
475 unsigned long relax;
476 struct
477 {
478 bfd_reloc_code_real_type type;
479 expressionS exp;
480 int pc_rel;
481 } reloc;
482
483 enum it_instruction_type it_insn_type;
484
485 struct
486 {
487 unsigned reg;
488 signed int imm;
489 struct neon_type_el vectype;
490 unsigned present : 1; /* Operand present. */
491 unsigned isreg : 1; /* Operand was a register. */
492 unsigned immisreg : 1; /* .imm field is a second register. */
493 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
494 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
495 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
496 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
497 instructions. This allows us to disambiguate ARM <-> vector insns. */
498 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
499 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
500 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
501 unsigned issingle : 1; /* Operand is VFP single-precision register. */
502 unsigned hasreloc : 1; /* Operand has relocation suffix. */
503 unsigned writeback : 1; /* Operand has trailing ! */
504 unsigned preind : 1; /* Preindexed address. */
505 unsigned postind : 1; /* Postindexed address. */
506 unsigned negative : 1; /* Index register was negated. */
507 unsigned shifted : 1; /* Shift applied to operation. */
508 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
509 } operands[ARM_IT_MAX_OPERANDS];
510 };
511
512 static struct arm_it inst;
513
514 #define NUM_FLOAT_VALS 8
515
516 const char * fp_const[] =
517 {
518 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
519 };
520
521 /* Number of littlenums required to hold an extended precision number. */
522 #define MAX_LITTLENUMS 6
523
524 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
525
526 #define FAIL (-1)
527 #define SUCCESS (0)
528
529 #define SUFF_S 1
530 #define SUFF_D 2
531 #define SUFF_E 3
532 #define SUFF_P 4
533
534 #define CP_T_X 0x00008000
535 #define CP_T_Y 0x00400000
536
537 #define CONDS_BIT 0x00100000
538 #define LOAD_BIT 0x00100000
539
540 #define DOUBLE_LOAD_FLAG 0x00000001
541
542 struct asm_cond
543 {
544 const char * template_name;
545 unsigned long value;
546 };
547
548 #define COND_ALWAYS 0xE
549
550 struct asm_psr
551 {
552 const char * template_name;
553 unsigned long field;
554 };
555
556 struct asm_barrier_opt
557 {
558 const char * template_name;
559 unsigned long value;
560 const arm_feature_set arch;
561 };
562
563 /* The bit that distinguishes CPSR and SPSR. */
564 #define SPSR_BIT (1 << 22)
565
566 /* The individual PSR flag bits. */
567 #define PSR_c (1 << 16)
568 #define PSR_x (1 << 17)
569 #define PSR_s (1 << 18)
570 #define PSR_f (1 << 19)
571
572 struct reloc_entry
573 {
574 const char * name;
575 bfd_reloc_code_real_type reloc;
576 };
577
578 enum vfp_reg_pos
579 {
580 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
581 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
582 };
583
584 enum vfp_ldstm_type
585 {
586 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
587 };
588
589 /* Bits for DEFINED field in neon_typed_alias. */
590 #define NTA_HASTYPE 1
591 #define NTA_HASINDEX 2
592
593 struct neon_typed_alias
594 {
595 unsigned char defined;
596 unsigned char index;
597 struct neon_type_el eltype;
598 };
599
600 /* ARM register categories. This includes coprocessor numbers and various
601 architecture extensions' registers. Each entry should have an error message
602 in reg_expected_msgs below. */
603 enum arm_reg_type
604 {
605 REG_TYPE_RN,
606 REG_TYPE_CP,
607 REG_TYPE_CN,
608 REG_TYPE_FN,
609 REG_TYPE_VFS,
610 REG_TYPE_VFD,
611 REG_TYPE_NQ,
612 REG_TYPE_VFSD,
613 REG_TYPE_NDQ,
614 REG_TYPE_NSD,
615 REG_TYPE_NSDQ,
616 REG_TYPE_VFC,
617 REG_TYPE_MVF,
618 REG_TYPE_MVD,
619 REG_TYPE_MVFX,
620 REG_TYPE_MVDX,
621 REG_TYPE_MVAX,
622 REG_TYPE_DSPSC,
623 REG_TYPE_MMXWR,
624 REG_TYPE_MMXWC,
625 REG_TYPE_MMXWCG,
626 REG_TYPE_XSCALE,
627 REG_TYPE_RNB
628 };
629
630 /* Structure for a hash table entry for a register.
631 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
632 information which states whether a vector type or index is specified (for a
633 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
634 struct reg_entry
635 {
636 const char * name;
637 unsigned int number;
638 unsigned char type;
639 unsigned char builtin;
640 struct neon_typed_alias * neon;
641 };
642
643 /* Diagnostics used when we don't get a register of the expected type. */
644 const char * const reg_expected_msgs[] =
645 {
646 [REG_TYPE_RN] = N_("ARM register expected"),
647 [REG_TYPE_CP] = N_("bad or missing co-processor number"),
648 [REG_TYPE_CN] = N_("co-processor register expected"),
649 [REG_TYPE_FN] = N_("FPA register expected"),
650 [REG_TYPE_VFS] = N_("VFP single precision register expected"),
651 [REG_TYPE_VFD] = N_("VFP/Neon double precision register expected"),
652 [REG_TYPE_NQ] = N_("Neon quad precision register expected"),
653 [REG_TYPE_VFSD] = N_("VFP single or double precision register expected"),
654 [REG_TYPE_NDQ] = N_("Neon double or quad precision register expected"),
655 [REG_TYPE_NSD] = N_("Neon single or double precision register expected"),
656 [REG_TYPE_NSDQ] = N_("VFP single, double or Neon quad precision register"
657 " expected"),
658 [REG_TYPE_VFC] = N_("VFP system register expected"),
659 [REG_TYPE_MVF] = N_("Maverick MVF register expected"),
660 [REG_TYPE_MVD] = N_("Maverick MVD register expected"),
661 [REG_TYPE_MVFX] = N_("Maverick MVFX register expected"),
662 [REG_TYPE_MVDX] = N_("Maverick MVDX register expected"),
663 [REG_TYPE_MVAX] = N_("Maverick MVAX register expected"),
664 [REG_TYPE_DSPSC] = N_("Maverick DSPSC register expected"),
665 [REG_TYPE_MMXWR] = N_("iWMMXt data register expected"),
666 [REG_TYPE_MMXWC] = N_("iWMMXt control register expected"),
667 [REG_TYPE_MMXWCG] = N_("iWMMXt scalar register expected"),
668 [REG_TYPE_XSCALE] = N_("XScale accumulator register expected"),
669 [REG_TYPE_RNB] = N_("")
670 };
671
672 /* Some well known registers that we refer to directly elsewhere. */
673 #define REG_R12 12
674 #define REG_SP 13
675 #define REG_LR 14
676 #define REG_PC 15
677
678 /* ARM instructions take 4bytes in the object file, Thumb instructions
679 take 2: */
680 #define INSN_SIZE 4
681
682 struct asm_opcode
683 {
684 /* Basic string to match. */
685 const char * template_name;
686
687 /* Parameters to instruction. */
688 unsigned int operands[8];
689
690 /* Conditional tag - see opcode_lookup. */
691 unsigned int tag : 4;
692
693 /* Basic instruction code. */
694 unsigned int avalue : 28;
695
696 /* Thumb-format instruction code. */
697 unsigned int tvalue;
698
699 /* Which architecture variant provides this instruction. */
700 const arm_feature_set * avariant;
701 const arm_feature_set * tvariant;
702
703 /* Function to call to encode instruction in ARM format. */
704 void (* aencode) (void);
705
706 /* Function to call to encode instruction in Thumb format. */
707 void (* tencode) (void);
708 };
709
710 /* Defines for various bits that we will want to toggle. */
711 #define INST_IMMEDIATE 0x02000000
712 #define OFFSET_REG 0x02000000
713 #define HWOFFSET_IMM 0x00400000
714 #define SHIFT_BY_REG 0x00000010
715 #define PRE_INDEX 0x01000000
716 #define INDEX_UP 0x00800000
717 #define WRITE_BACK 0x00200000
718 #define LDM_TYPE_2_OR_3 0x00400000
719 #define CPSI_MMOD 0x00020000
720
721 #define LITERAL_MASK 0xf000f000
722 #define OPCODE_MASK 0xfe1fffff
723 #define V4_STR_BIT 0x00000020
724 #define VLDR_VMOV_SAME 0x0040f000
725
726 #define T2_SUBS_PC_LR 0xf3de8f00
727
728 #define DATA_OP_SHIFT 21
729 #define SBIT_SHIFT 20
730
731 #define T2_OPCODE_MASK 0xfe1fffff
732 #define T2_DATA_OP_SHIFT 21
733 #define T2_SBIT_SHIFT 20
734
735 #define A_COND_MASK 0xf0000000
736 #define A_PUSH_POP_OP_MASK 0x0fff0000
737
738 /* Opcodes for pushing/poping registers to/from the stack. */
739 #define A1_OPCODE_PUSH 0x092d0000
740 #define A2_OPCODE_PUSH 0x052d0004
741 #define A2_OPCODE_POP 0x049d0004
742
743 /* Codes to distinguish the arithmetic instructions. */
744 #define OPCODE_AND 0
745 #define OPCODE_EOR 1
746 #define OPCODE_SUB 2
747 #define OPCODE_RSB 3
748 #define OPCODE_ADD 4
749 #define OPCODE_ADC 5
750 #define OPCODE_SBC 6
751 #define OPCODE_RSC 7
752 #define OPCODE_TST 8
753 #define OPCODE_TEQ 9
754 #define OPCODE_CMP 10
755 #define OPCODE_CMN 11
756 #define OPCODE_ORR 12
757 #define OPCODE_MOV 13
758 #define OPCODE_BIC 14
759 #define OPCODE_MVN 15
760
761 #define T2_OPCODE_AND 0
762 #define T2_OPCODE_BIC 1
763 #define T2_OPCODE_ORR 2
764 #define T2_OPCODE_ORN 3
765 #define T2_OPCODE_EOR 4
766 #define T2_OPCODE_ADD 8
767 #define T2_OPCODE_ADC 10
768 #define T2_OPCODE_SBC 11
769 #define T2_OPCODE_SUB 13
770 #define T2_OPCODE_RSB 14
771
772 #define T_OPCODE_MUL 0x4340
773 #define T_OPCODE_TST 0x4200
774 #define T_OPCODE_CMN 0x42c0
775 #define T_OPCODE_NEG 0x4240
776 #define T_OPCODE_MVN 0x43c0
777
778 #define T_OPCODE_ADD_R3 0x1800
779 #define T_OPCODE_SUB_R3 0x1a00
780 #define T_OPCODE_ADD_HI 0x4400
781 #define T_OPCODE_ADD_ST 0xb000
782 #define T_OPCODE_SUB_ST 0xb080
783 #define T_OPCODE_ADD_SP 0xa800
784 #define T_OPCODE_ADD_PC 0xa000
785 #define T_OPCODE_ADD_I8 0x3000
786 #define T_OPCODE_SUB_I8 0x3800
787 #define T_OPCODE_ADD_I3 0x1c00
788 #define T_OPCODE_SUB_I3 0x1e00
789
790 #define T_OPCODE_ASR_R 0x4100
791 #define T_OPCODE_LSL_R 0x4080
792 #define T_OPCODE_LSR_R 0x40c0
793 #define T_OPCODE_ROR_R 0x41c0
794 #define T_OPCODE_ASR_I 0x1000
795 #define T_OPCODE_LSL_I 0x0000
796 #define T_OPCODE_LSR_I 0x0800
797
798 #define T_OPCODE_MOV_I8 0x2000
799 #define T_OPCODE_CMP_I8 0x2800
800 #define T_OPCODE_CMP_LR 0x4280
801 #define T_OPCODE_MOV_HR 0x4600
802 #define T_OPCODE_CMP_HR 0x4500
803
804 #define T_OPCODE_LDR_PC 0x4800
805 #define T_OPCODE_LDR_SP 0x9800
806 #define T_OPCODE_STR_SP 0x9000
807 #define T_OPCODE_LDR_IW 0x6800
808 #define T_OPCODE_STR_IW 0x6000
809 #define T_OPCODE_LDR_IH 0x8800
810 #define T_OPCODE_STR_IH 0x8000
811 #define T_OPCODE_LDR_IB 0x7800
812 #define T_OPCODE_STR_IB 0x7000
813 #define T_OPCODE_LDR_RW 0x5800
814 #define T_OPCODE_STR_RW 0x5000
815 #define T_OPCODE_LDR_RH 0x5a00
816 #define T_OPCODE_STR_RH 0x5200
817 #define T_OPCODE_LDR_RB 0x5c00
818 #define T_OPCODE_STR_RB 0x5400
819
820 #define T_OPCODE_PUSH 0xb400
821 #define T_OPCODE_POP 0xbc00
822
823 #define T_OPCODE_BRANCH 0xe000
824
825 #define THUMB_SIZE 2 /* Size of thumb instruction. */
826 #define THUMB_PP_PC_LR 0x0100
827 #define THUMB_LOAD_BIT 0x0800
828 #define THUMB2_LOAD_BIT 0x00100000
829
830 #define BAD_ARGS _("bad arguments to instruction")
831 #define BAD_SP _("r13 not allowed here")
832 #define BAD_PC _("r15 not allowed here")
833 #define BAD_COND _("instruction cannot be conditional")
834 #define BAD_OVERLAP _("registers may not be the same")
835 #define BAD_HIREG _("lo register required")
836 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
837 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
838 #define BAD_BRANCH _("branch must be last instruction in IT block")
839 #define BAD_NOT_IT _("instruction not allowed in IT block")
840 #define BAD_FPU _("selected FPU does not support instruction")
841 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
842 #define BAD_IT_COND _("incorrect condition in IT block")
843 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
844 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
845 #define BAD_PC_ADDRESSING \
846 _("cannot use register index with PC-relative addressing")
847 #define BAD_PC_WRITEBACK \
848 _("cannot use writeback with PC-relative addressing")
849 #define BAD_RANGE _("branch out of range")
850 #define BAD_FP16 _("selected processor does not support fp16 instruction")
851 #define UNPRED_REG(R) _("using " R " results in unpredictable behaviour")
852 #define THUMB1_RELOC_ONLY _("relocation valid in thumb1 code only")
853
854 static struct hash_control * arm_ops_hsh;
855 static struct hash_control * arm_cond_hsh;
856 static struct hash_control * arm_shift_hsh;
857 static struct hash_control * arm_psr_hsh;
858 static struct hash_control * arm_v7m_psr_hsh;
859 static struct hash_control * arm_reg_hsh;
860 static struct hash_control * arm_reloc_hsh;
861 static struct hash_control * arm_barrier_opt_hsh;
862
863 /* Stuff needed to resolve the label ambiguity
864 As:
865 ...
866 label: <insn>
867 may differ from:
868 ...
869 label:
870 <insn> */
871
872 symbolS * last_label_seen;
873 static int label_is_thumb_function_name = FALSE;
874
875 /* Literal pool structure. Held on a per-section
876 and per-sub-section basis. */
877
878 #define MAX_LITERAL_POOL_SIZE 1024
879 typedef struct literal_pool
880 {
881 expressionS literals [MAX_LITERAL_POOL_SIZE];
882 unsigned int next_free_entry;
883 unsigned int id;
884 symbolS * symbol;
885 segT section;
886 subsegT sub_section;
887 #ifdef OBJ_ELF
888 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
889 #endif
890 struct literal_pool * next;
891 unsigned int alignment;
892 } literal_pool;
893
894 /* Pointer to a linked list of literal pools. */
895 literal_pool * list_of_pools = NULL;
896
897 typedef enum asmfunc_states
898 {
899 OUTSIDE_ASMFUNC,
900 WAITING_ASMFUNC_NAME,
901 WAITING_ENDASMFUNC
902 } asmfunc_states;
903
904 static asmfunc_states asmfunc_state = OUTSIDE_ASMFUNC;
905
906 #ifdef OBJ_ELF
907 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
908 #else
909 static struct current_it now_it;
910 #endif
911
912 static inline int
913 now_it_compatible (int cond)
914 {
915 return (cond & ~1) == (now_it.cc & ~1);
916 }
917
918 static inline int
919 conditional_insn (void)
920 {
921 return inst.cond != COND_ALWAYS;
922 }
923
924 static int in_it_block (void);
925
926 static int handle_it_state (void);
927
928 static void force_automatic_it_block_close (void);
929
930 static void it_fsm_post_encode (void);
931
932 #define set_it_insn_type(type) \
933 do \
934 { \
935 inst.it_insn_type = type; \
936 if (handle_it_state () == FAIL) \
937 return; \
938 } \
939 while (0)
940
941 #define set_it_insn_type_nonvoid(type, failret) \
942 do \
943 { \
944 inst.it_insn_type = type; \
945 if (handle_it_state () == FAIL) \
946 return failret; \
947 } \
948 while(0)
949
950 #define set_it_insn_type_last() \
951 do \
952 { \
953 if (inst.cond == COND_ALWAYS) \
954 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
955 else \
956 set_it_insn_type (INSIDE_IT_LAST_INSN); \
957 } \
958 while (0)
959
960 /* Pure syntax. */
961
962 /* This array holds the chars that always start a comment. If the
963 pre-processor is disabled, these aren't very useful. */
964 char arm_comment_chars[] = "@";
965
966 /* This array holds the chars that only start a comment at the beginning of
967 a line. If the line seems to have the form '# 123 filename'
968 .line and .file directives will appear in the pre-processed output. */
969 /* Note that input_file.c hand checks for '#' at the beginning of the
970 first line of the input file. This is because the compiler outputs
971 #NO_APP at the beginning of its output. */
972 /* Also note that comments like this one will always work. */
973 const char line_comment_chars[] = "#";
974
975 char arm_line_separator_chars[] = ";";
976
977 /* Chars that can be used to separate mant
978 from exp in floating point numbers. */
979 const char EXP_CHARS[] = "eE";
980
981 /* Chars that mean this number is a floating point constant. */
982 /* As in 0f12.456 */
983 /* or 0d1.2345e12 */
984
985 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
986
987 /* Prefix characters that indicate the start of an immediate
988 value. */
989 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
990
991 /* Separator character handling. */
992
993 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
994
995 static inline int
996 skip_past_char (char ** str, char c)
997 {
998 /* PR gas/14987: Allow for whitespace before the expected character. */
999 skip_whitespace (*str);
1000
1001 if (**str == c)
1002 {
1003 (*str)++;
1004 return SUCCESS;
1005 }
1006 else
1007 return FAIL;
1008 }
1009
1010 #define skip_past_comma(str) skip_past_char (str, ',')
1011
1012 /* Arithmetic expressions (possibly involving symbols). */
1013
1014 /* Return TRUE if anything in the expression is a bignum. */
1015
1016 static bfd_boolean
1017 walk_no_bignums (symbolS * sp)
1018 {
1019 if (symbol_get_value_expression (sp)->X_op == O_big)
1020 return TRUE;
1021
1022 if (symbol_get_value_expression (sp)->X_add_symbol)
1023 {
1024 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
1025 || (symbol_get_value_expression (sp)->X_op_symbol
1026 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
1027 }
1028
1029 return FALSE;
1030 }
1031
1032 static bfd_boolean in_my_get_expression = FALSE;
1033
1034 /* Third argument to my_get_expression. */
1035 #define GE_NO_PREFIX 0
1036 #define GE_IMM_PREFIX 1
1037 #define GE_OPT_PREFIX 2
1038 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
1039 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
1040 #define GE_OPT_PREFIX_BIG 3
1041
1042 static int
1043 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
1044 {
1045 char * save_in;
1046
1047 /* In unified syntax, all prefixes are optional. */
1048 if (unified_syntax)
1049 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
1050 : GE_OPT_PREFIX;
1051
1052 switch (prefix_mode)
1053 {
1054 case GE_NO_PREFIX: break;
1055 case GE_IMM_PREFIX:
1056 if (!is_immediate_prefix (**str))
1057 {
1058 inst.error = _("immediate expression requires a # prefix");
1059 return FAIL;
1060 }
1061 (*str)++;
1062 break;
1063 case GE_OPT_PREFIX:
1064 case GE_OPT_PREFIX_BIG:
1065 if (is_immediate_prefix (**str))
1066 (*str)++;
1067 break;
1068 default:
1069 abort ();
1070 }
1071
1072 memset (ep, 0, sizeof (expressionS));
1073
1074 save_in = input_line_pointer;
1075 input_line_pointer = *str;
1076 in_my_get_expression = TRUE;
1077 expression (ep);
1078 in_my_get_expression = FALSE;
1079
1080 if (ep->X_op == O_illegal || ep->X_op == O_absent)
1081 {
1082 /* We found a bad or missing expression in md_operand(). */
1083 *str = input_line_pointer;
1084 input_line_pointer = save_in;
1085 if (inst.error == NULL)
1086 inst.error = (ep->X_op == O_absent
1087 ? _("missing expression") :_("bad expression"));
1088 return 1;
1089 }
1090
1091 /* Get rid of any bignums now, so that we don't generate an error for which
1092 we can't establish a line number later on. Big numbers are never valid
1093 in instructions, which is where this routine is always called. */
1094 if (prefix_mode != GE_OPT_PREFIX_BIG
1095 && (ep->X_op == O_big
1096 || (ep->X_add_symbol
1097 && (walk_no_bignums (ep->X_add_symbol)
1098 || (ep->X_op_symbol
1099 && walk_no_bignums (ep->X_op_symbol))))))
1100 {
1101 inst.error = _("invalid constant");
1102 *str = input_line_pointer;
1103 input_line_pointer = save_in;
1104 return 1;
1105 }
1106
1107 *str = input_line_pointer;
1108 input_line_pointer = save_in;
1109 return SUCCESS;
1110 }
1111
1112 /* Turn a string in input_line_pointer into a floating point constant
1113 of type TYPE, and store the appropriate bytes in *LITP. The number
1114 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1115 returned, or NULL on OK.
1116
1117 Note that fp constants aren't represent in the normal way on the ARM.
1118 In big endian mode, things are as expected. However, in little endian
1119 mode fp constants are big-endian word-wise, and little-endian byte-wise
1120 within the words. For example, (double) 1.1 in big endian mode is
1121 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1122 the byte sequence 99 99 f1 3f 9a 99 99 99.
1123
1124 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1125
1126 const char *
1127 md_atof (int type, char * litP, int * sizeP)
1128 {
1129 int prec;
1130 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1131 char *t;
1132 int i;
1133
1134 switch (type)
1135 {
1136 case 'f':
1137 case 'F':
1138 case 's':
1139 case 'S':
1140 prec = 2;
1141 break;
1142
1143 case 'd':
1144 case 'D':
1145 case 'r':
1146 case 'R':
1147 prec = 4;
1148 break;
1149
1150 case 'x':
1151 case 'X':
1152 prec = 5;
1153 break;
1154
1155 case 'p':
1156 case 'P':
1157 prec = 5;
1158 break;
1159
1160 default:
1161 *sizeP = 0;
1162 return _("Unrecognized or unsupported floating point constant");
1163 }
1164
1165 t = atof_ieee (input_line_pointer, type, words);
1166 if (t)
1167 input_line_pointer = t;
1168 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1169
1170 if (target_big_endian)
1171 {
1172 for (i = 0; i < prec; i++)
1173 {
1174 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1175 litP += sizeof (LITTLENUM_TYPE);
1176 }
1177 }
1178 else
1179 {
1180 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1181 for (i = prec - 1; i >= 0; i--)
1182 {
1183 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1184 litP += sizeof (LITTLENUM_TYPE);
1185 }
1186 else
1187 /* For a 4 byte float the order of elements in `words' is 1 0.
1188 For an 8 byte float the order is 1 0 3 2. */
1189 for (i = 0; i < prec; i += 2)
1190 {
1191 md_number_to_chars (litP, (valueT) words[i + 1],
1192 sizeof (LITTLENUM_TYPE));
1193 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1194 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1195 litP += 2 * sizeof (LITTLENUM_TYPE);
1196 }
1197 }
1198
1199 return NULL;
1200 }
1201
1202 /* We handle all bad expressions here, so that we can report the faulty
1203 instruction in the error message. */
1204
1205 void
1206 md_operand (expressionS * exp)
1207 {
1208 if (in_my_get_expression)
1209 exp->X_op = O_illegal;
1210 }
1211
1212 /* Immediate values. */
1213
1214 #ifdef OBJ_ELF
1215 /* Generic immediate-value read function for use in directives.
1216 Accepts anything that 'expression' can fold to a constant.
1217 *val receives the number. */
1218
1219 static int
1220 immediate_for_directive (int *val)
1221 {
1222 expressionS exp;
1223 exp.X_op = O_illegal;
1224
1225 if (is_immediate_prefix (*input_line_pointer))
1226 {
1227 input_line_pointer++;
1228 expression (&exp);
1229 }
1230
1231 if (exp.X_op != O_constant)
1232 {
1233 as_bad (_("expected #constant"));
1234 ignore_rest_of_line ();
1235 return FAIL;
1236 }
1237 *val = exp.X_add_number;
1238 return SUCCESS;
1239 }
1240 #endif
1241
1242 /* Register parsing. */
1243
1244 /* Generic register parser. CCP points to what should be the
1245 beginning of a register name. If it is indeed a valid register
1246 name, advance CCP over it and return the reg_entry structure;
1247 otherwise return NULL. Does not issue diagnostics. */
1248
1249 static struct reg_entry *
1250 arm_reg_parse_multi (char **ccp)
1251 {
1252 char *start = *ccp;
1253 char *p;
1254 struct reg_entry *reg;
1255
1256 skip_whitespace (start);
1257
1258 #ifdef REGISTER_PREFIX
1259 if (*start != REGISTER_PREFIX)
1260 return NULL;
1261 start++;
1262 #endif
1263 #ifdef OPTIONAL_REGISTER_PREFIX
1264 if (*start == OPTIONAL_REGISTER_PREFIX)
1265 start++;
1266 #endif
1267
1268 p = start;
1269 if (!ISALPHA (*p) || !is_name_beginner (*p))
1270 return NULL;
1271
1272 do
1273 p++;
1274 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1275
1276 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1277
1278 if (!reg)
1279 return NULL;
1280
1281 *ccp = p;
1282 return reg;
1283 }
1284
1285 static int
1286 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1287 enum arm_reg_type type)
1288 {
1289 /* Alternative syntaxes are accepted for a few register classes. */
1290 switch (type)
1291 {
1292 case REG_TYPE_MVF:
1293 case REG_TYPE_MVD:
1294 case REG_TYPE_MVFX:
1295 case REG_TYPE_MVDX:
1296 /* Generic coprocessor register names are allowed for these. */
1297 if (reg && reg->type == REG_TYPE_CN)
1298 return reg->number;
1299 break;
1300
1301 case REG_TYPE_CP:
1302 /* For backward compatibility, a bare number is valid here. */
1303 {
1304 unsigned long processor = strtoul (start, ccp, 10);
1305 if (*ccp != start && processor <= 15)
1306 return processor;
1307 }
1308 /* Fall through. */
1309
1310 case REG_TYPE_MMXWC:
1311 /* WC includes WCG. ??? I'm not sure this is true for all
1312 instructions that take WC registers. */
1313 if (reg && reg->type == REG_TYPE_MMXWCG)
1314 return reg->number;
1315 break;
1316
1317 default:
1318 break;
1319 }
1320
1321 return FAIL;
1322 }
1323
1324 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1325 return value is the register number or FAIL. */
1326
1327 static int
1328 arm_reg_parse (char **ccp, enum arm_reg_type type)
1329 {
1330 char *start = *ccp;
1331 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1332 int ret;
1333
1334 /* Do not allow a scalar (reg+index) to parse as a register. */
1335 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1336 return FAIL;
1337
1338 if (reg && reg->type == type)
1339 return reg->number;
1340
1341 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1342 return ret;
1343
1344 *ccp = start;
1345 return FAIL;
1346 }
1347
1348 /* Parse a Neon type specifier. *STR should point at the leading '.'
1349 character. Does no verification at this stage that the type fits the opcode
1350 properly. E.g.,
1351
1352 .i32.i32.s16
1353 .s32.f32
1354 .u16
1355
1356 Can all be legally parsed by this function.
1357
1358 Fills in neon_type struct pointer with parsed information, and updates STR
1359 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1360 type, FAIL if not. */
1361
1362 static int
1363 parse_neon_type (struct neon_type *type, char **str)
1364 {
1365 char *ptr = *str;
1366
1367 if (type)
1368 type->elems = 0;
1369
1370 while (type->elems < NEON_MAX_TYPE_ELS)
1371 {
1372 enum neon_el_type thistype = NT_untyped;
1373 unsigned thissize = -1u;
1374
1375 if (*ptr != '.')
1376 break;
1377
1378 ptr++;
1379
1380 /* Just a size without an explicit type. */
1381 if (ISDIGIT (*ptr))
1382 goto parsesize;
1383
1384 switch (TOLOWER (*ptr))
1385 {
1386 case 'i': thistype = NT_integer; break;
1387 case 'f': thistype = NT_float; break;
1388 case 'p': thistype = NT_poly; break;
1389 case 's': thistype = NT_signed; break;
1390 case 'u': thistype = NT_unsigned; break;
1391 case 'd':
1392 thistype = NT_float;
1393 thissize = 64;
1394 ptr++;
1395 goto done;
1396 default:
1397 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1398 return FAIL;
1399 }
1400
1401 ptr++;
1402
1403 /* .f is an abbreviation for .f32. */
1404 if (thistype == NT_float && !ISDIGIT (*ptr))
1405 thissize = 32;
1406 else
1407 {
1408 parsesize:
1409 thissize = strtoul (ptr, &ptr, 10);
1410
1411 if (thissize != 8 && thissize != 16 && thissize != 32
1412 && thissize != 64)
1413 {
1414 as_bad (_("bad size %d in type specifier"), thissize);
1415 return FAIL;
1416 }
1417 }
1418
1419 done:
1420 if (type)
1421 {
1422 type->el[type->elems].type = thistype;
1423 type->el[type->elems].size = thissize;
1424 type->elems++;
1425 }
1426 }
1427
1428 /* Empty/missing type is not a successful parse. */
1429 if (type->elems == 0)
1430 return FAIL;
1431
1432 *str = ptr;
1433
1434 return SUCCESS;
1435 }
1436
1437 /* Errors may be set multiple times during parsing or bit encoding
1438 (particularly in the Neon bits), but usually the earliest error which is set
1439 will be the most meaningful. Avoid overwriting it with later (cascading)
1440 errors by calling this function. */
1441
1442 static void
1443 first_error (const char *err)
1444 {
1445 if (!inst.error)
1446 inst.error = err;
1447 }
1448
1449 /* Parse a single type, e.g. ".s32", leading period included. */
1450 static int
1451 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1452 {
1453 char *str = *ccp;
1454 struct neon_type optype;
1455
1456 if (*str == '.')
1457 {
1458 if (parse_neon_type (&optype, &str) == SUCCESS)
1459 {
1460 if (optype.elems == 1)
1461 *vectype = optype.el[0];
1462 else
1463 {
1464 first_error (_("only one type should be specified for operand"));
1465 return FAIL;
1466 }
1467 }
1468 else
1469 {
1470 first_error (_("vector type expected"));
1471 return FAIL;
1472 }
1473 }
1474 else
1475 return FAIL;
1476
1477 *ccp = str;
1478
1479 return SUCCESS;
1480 }
1481
1482 /* Special meanings for indices (which have a range of 0-7), which will fit into
1483 a 4-bit integer. */
1484
1485 #define NEON_ALL_LANES 15
1486 #define NEON_INTERLEAVE_LANES 14
1487
1488 /* Parse either a register or a scalar, with an optional type. Return the
1489 register number, and optionally fill in the actual type of the register
1490 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1491 type/index information in *TYPEINFO. */
1492
1493 static int
1494 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1495 enum arm_reg_type *rtype,
1496 struct neon_typed_alias *typeinfo)
1497 {
1498 char *str = *ccp;
1499 struct reg_entry *reg = arm_reg_parse_multi (&str);
1500 struct neon_typed_alias atype;
1501 struct neon_type_el parsetype;
1502
1503 atype.defined = 0;
1504 atype.index = -1;
1505 atype.eltype.type = NT_invtype;
1506 atype.eltype.size = -1;
1507
1508 /* Try alternate syntax for some types of register. Note these are mutually
1509 exclusive with the Neon syntax extensions. */
1510 if (reg == NULL)
1511 {
1512 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1513 if (altreg != FAIL)
1514 *ccp = str;
1515 if (typeinfo)
1516 *typeinfo = atype;
1517 return altreg;
1518 }
1519
1520 /* Undo polymorphism when a set of register types may be accepted. */
1521 if ((type == REG_TYPE_NDQ
1522 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1523 || (type == REG_TYPE_VFSD
1524 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1525 || (type == REG_TYPE_NSDQ
1526 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1527 || reg->type == REG_TYPE_NQ))
1528 || (type == REG_TYPE_NSD
1529 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1530 || (type == REG_TYPE_MMXWC
1531 && (reg->type == REG_TYPE_MMXWCG)))
1532 type = (enum arm_reg_type) reg->type;
1533
1534 if (type != reg->type)
1535 return FAIL;
1536
1537 if (reg->neon)
1538 atype = *reg->neon;
1539
1540 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1541 {
1542 if ((atype.defined & NTA_HASTYPE) != 0)
1543 {
1544 first_error (_("can't redefine type for operand"));
1545 return FAIL;
1546 }
1547 atype.defined |= NTA_HASTYPE;
1548 atype.eltype = parsetype;
1549 }
1550
1551 if (skip_past_char (&str, '[') == SUCCESS)
1552 {
1553 if (type != REG_TYPE_VFD
1554 && !(type == REG_TYPE_VFS
1555 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8_2)))
1556 {
1557 first_error (_("only D registers may be indexed"));
1558 return FAIL;
1559 }
1560
1561 if ((atype.defined & NTA_HASINDEX) != 0)
1562 {
1563 first_error (_("can't change index for operand"));
1564 return FAIL;
1565 }
1566
1567 atype.defined |= NTA_HASINDEX;
1568
1569 if (skip_past_char (&str, ']') == SUCCESS)
1570 atype.index = NEON_ALL_LANES;
1571 else
1572 {
1573 expressionS exp;
1574
1575 my_get_expression (&exp, &str, GE_NO_PREFIX);
1576
1577 if (exp.X_op != O_constant)
1578 {
1579 first_error (_("constant expression required"));
1580 return FAIL;
1581 }
1582
1583 if (skip_past_char (&str, ']') == FAIL)
1584 return FAIL;
1585
1586 atype.index = exp.X_add_number;
1587 }
1588 }
1589
1590 if (typeinfo)
1591 *typeinfo = atype;
1592
1593 if (rtype)
1594 *rtype = type;
1595
1596 *ccp = str;
1597
1598 return reg->number;
1599 }
1600
1601 /* Like arm_reg_parse, but allow allow the following extra features:
1602 - If RTYPE is non-zero, return the (possibly restricted) type of the
1603 register (e.g. Neon double or quad reg when either has been requested).
1604 - If this is a Neon vector type with additional type information, fill
1605 in the struct pointed to by VECTYPE (if non-NULL).
1606 This function will fault on encountering a scalar. */
1607
1608 static int
1609 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1610 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1611 {
1612 struct neon_typed_alias atype;
1613 char *str = *ccp;
1614 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1615
1616 if (reg == FAIL)
1617 return FAIL;
1618
1619 /* Do not allow regname(... to parse as a register. */
1620 if (*str == '(')
1621 return FAIL;
1622
1623 /* Do not allow a scalar (reg+index) to parse as a register. */
1624 if ((atype.defined & NTA_HASINDEX) != 0)
1625 {
1626 first_error (_("register operand expected, but got scalar"));
1627 return FAIL;
1628 }
1629
1630 if (vectype)
1631 *vectype = atype.eltype;
1632
1633 *ccp = str;
1634
1635 return reg;
1636 }
1637
1638 #define NEON_SCALAR_REG(X) ((X) >> 4)
1639 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1640
1641 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1642 have enough information to be able to do a good job bounds-checking. So, we
1643 just do easy checks here, and do further checks later. */
1644
1645 static int
1646 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1647 {
1648 int reg;
1649 char *str = *ccp;
1650 struct neon_typed_alias atype;
1651 enum arm_reg_type reg_type = REG_TYPE_VFD;
1652
1653 if (elsize == 4)
1654 reg_type = REG_TYPE_VFS;
1655
1656 reg = parse_typed_reg_or_scalar (&str, reg_type, NULL, &atype);
1657
1658 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1659 return FAIL;
1660
1661 if (atype.index == NEON_ALL_LANES)
1662 {
1663 first_error (_("scalar must have an index"));
1664 return FAIL;
1665 }
1666 else if (atype.index >= 64 / elsize)
1667 {
1668 first_error (_("scalar index out of range"));
1669 return FAIL;
1670 }
1671
1672 if (type)
1673 *type = atype.eltype;
1674
1675 *ccp = str;
1676
1677 return reg * 16 + atype.index;
1678 }
1679
1680 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1681
1682 static long
1683 parse_reg_list (char ** strp)
1684 {
1685 char * str = * strp;
1686 long range = 0;
1687 int another_range;
1688
1689 /* We come back here if we get ranges concatenated by '+' or '|'. */
1690 do
1691 {
1692 skip_whitespace (str);
1693
1694 another_range = 0;
1695
1696 if (*str == '{')
1697 {
1698 int in_range = 0;
1699 int cur_reg = -1;
1700
1701 str++;
1702 do
1703 {
1704 int reg;
1705
1706 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1707 {
1708 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1709 return FAIL;
1710 }
1711
1712 if (in_range)
1713 {
1714 int i;
1715
1716 if (reg <= cur_reg)
1717 {
1718 first_error (_("bad range in register list"));
1719 return FAIL;
1720 }
1721
1722 for (i = cur_reg + 1; i < reg; i++)
1723 {
1724 if (range & (1 << i))
1725 as_tsktsk
1726 (_("Warning: duplicated register (r%d) in register list"),
1727 i);
1728 else
1729 range |= 1 << i;
1730 }
1731 in_range = 0;
1732 }
1733
1734 if (range & (1 << reg))
1735 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1736 reg);
1737 else if (reg <= cur_reg)
1738 as_tsktsk (_("Warning: register range not in ascending order"));
1739
1740 range |= 1 << reg;
1741 cur_reg = reg;
1742 }
1743 while (skip_past_comma (&str) != FAIL
1744 || (in_range = 1, *str++ == '-'));
1745 str--;
1746
1747 if (skip_past_char (&str, '}') == FAIL)
1748 {
1749 first_error (_("missing `}'"));
1750 return FAIL;
1751 }
1752 }
1753 else
1754 {
1755 expressionS exp;
1756
1757 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1758 return FAIL;
1759
1760 if (exp.X_op == O_constant)
1761 {
1762 if (exp.X_add_number
1763 != (exp.X_add_number & 0x0000ffff))
1764 {
1765 inst.error = _("invalid register mask");
1766 return FAIL;
1767 }
1768
1769 if ((range & exp.X_add_number) != 0)
1770 {
1771 int regno = range & exp.X_add_number;
1772
1773 regno &= -regno;
1774 regno = (1 << regno) - 1;
1775 as_tsktsk
1776 (_("Warning: duplicated register (r%d) in register list"),
1777 regno);
1778 }
1779
1780 range |= exp.X_add_number;
1781 }
1782 else
1783 {
1784 if (inst.reloc.type != 0)
1785 {
1786 inst.error = _("expression too complex");
1787 return FAIL;
1788 }
1789
1790 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1791 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1792 inst.reloc.pc_rel = 0;
1793 }
1794 }
1795
1796 if (*str == '|' || *str == '+')
1797 {
1798 str++;
1799 another_range = 1;
1800 }
1801 }
1802 while (another_range);
1803
1804 *strp = str;
1805 return range;
1806 }
1807
1808 /* Types of registers in a list. */
1809
1810 enum reg_list_els
1811 {
1812 REGLIST_VFP_S,
1813 REGLIST_VFP_D,
1814 REGLIST_NEON_D
1815 };
1816
1817 /* Parse a VFP register list. If the string is invalid return FAIL.
1818 Otherwise return the number of registers, and set PBASE to the first
1819 register. Parses registers of type ETYPE.
1820 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1821 - Q registers can be used to specify pairs of D registers
1822 - { } can be omitted from around a singleton register list
1823 FIXME: This is not implemented, as it would require backtracking in
1824 some cases, e.g.:
1825 vtbl.8 d3,d4,d5
1826 This could be done (the meaning isn't really ambiguous), but doesn't
1827 fit in well with the current parsing framework.
1828 - 32 D registers may be used (also true for VFPv3).
1829 FIXME: Types are ignored in these register lists, which is probably a
1830 bug. */
1831
1832 static int
1833 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1834 {
1835 char *str = *ccp;
1836 int base_reg;
1837 int new_base;
1838 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1839 int max_regs = 0;
1840 int count = 0;
1841 int warned = 0;
1842 unsigned long mask = 0;
1843 int i;
1844
1845 if (skip_past_char (&str, '{') == FAIL)
1846 {
1847 inst.error = _("expecting {");
1848 return FAIL;
1849 }
1850
1851 switch (etype)
1852 {
1853 case REGLIST_VFP_S:
1854 regtype = REG_TYPE_VFS;
1855 max_regs = 32;
1856 break;
1857
1858 case REGLIST_VFP_D:
1859 regtype = REG_TYPE_VFD;
1860 break;
1861
1862 case REGLIST_NEON_D:
1863 regtype = REG_TYPE_NDQ;
1864 break;
1865 }
1866
1867 if (etype != REGLIST_VFP_S)
1868 {
1869 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1870 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1871 {
1872 max_regs = 32;
1873 if (thumb_mode)
1874 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1875 fpu_vfp_ext_d32);
1876 else
1877 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1878 fpu_vfp_ext_d32);
1879 }
1880 else
1881 max_regs = 16;
1882 }
1883
1884 base_reg = max_regs;
1885
1886 do
1887 {
1888 int setmask = 1, addregs = 1;
1889
1890 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1891
1892 if (new_base == FAIL)
1893 {
1894 first_error (_(reg_expected_msgs[regtype]));
1895 return FAIL;
1896 }
1897
1898 if (new_base >= max_regs)
1899 {
1900 first_error (_("register out of range in list"));
1901 return FAIL;
1902 }
1903
1904 /* Note: a value of 2 * n is returned for the register Q<n>. */
1905 if (regtype == REG_TYPE_NQ)
1906 {
1907 setmask = 3;
1908 addregs = 2;
1909 }
1910
1911 if (new_base < base_reg)
1912 base_reg = new_base;
1913
1914 if (mask & (setmask << new_base))
1915 {
1916 first_error (_("invalid register list"));
1917 return FAIL;
1918 }
1919
1920 if ((mask >> new_base) != 0 && ! warned)
1921 {
1922 as_tsktsk (_("register list not in ascending order"));
1923 warned = 1;
1924 }
1925
1926 mask |= setmask << new_base;
1927 count += addregs;
1928
1929 if (*str == '-') /* We have the start of a range expression */
1930 {
1931 int high_range;
1932
1933 str++;
1934
1935 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1936 == FAIL)
1937 {
1938 inst.error = gettext (reg_expected_msgs[regtype]);
1939 return FAIL;
1940 }
1941
1942 if (high_range >= max_regs)
1943 {
1944 first_error (_("register out of range in list"));
1945 return FAIL;
1946 }
1947
1948 if (regtype == REG_TYPE_NQ)
1949 high_range = high_range + 1;
1950
1951 if (high_range <= new_base)
1952 {
1953 inst.error = _("register range not in ascending order");
1954 return FAIL;
1955 }
1956
1957 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1958 {
1959 if (mask & (setmask << new_base))
1960 {
1961 inst.error = _("invalid register list");
1962 return FAIL;
1963 }
1964
1965 mask |= setmask << new_base;
1966 count += addregs;
1967 }
1968 }
1969 }
1970 while (skip_past_comma (&str) != FAIL);
1971
1972 str++;
1973
1974 /* Sanity check -- should have raised a parse error above. */
1975 if (count == 0 || count > max_regs)
1976 abort ();
1977
1978 *pbase = base_reg;
1979
1980 /* Final test -- the registers must be consecutive. */
1981 mask >>= base_reg;
1982 for (i = 0; i < count; i++)
1983 {
1984 if ((mask & (1u << i)) == 0)
1985 {
1986 inst.error = _("non-contiguous register range");
1987 return FAIL;
1988 }
1989 }
1990
1991 *ccp = str;
1992
1993 return count;
1994 }
1995
1996 /* True if two alias types are the same. */
1997
1998 static bfd_boolean
1999 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
2000 {
2001 if (!a && !b)
2002 return TRUE;
2003
2004 if (!a || !b)
2005 return FALSE;
2006
2007 if (a->defined != b->defined)
2008 return FALSE;
2009
2010 if ((a->defined & NTA_HASTYPE) != 0
2011 && (a->eltype.type != b->eltype.type
2012 || a->eltype.size != b->eltype.size))
2013 return FALSE;
2014
2015 if ((a->defined & NTA_HASINDEX) != 0
2016 && (a->index != b->index))
2017 return FALSE;
2018
2019 return TRUE;
2020 }
2021
2022 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
2023 The base register is put in *PBASE.
2024 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
2025 the return value.
2026 The register stride (minus one) is put in bit 4 of the return value.
2027 Bits [6:5] encode the list length (minus one).
2028 The type of the list elements is put in *ELTYPE, if non-NULL. */
2029
2030 #define NEON_LANE(X) ((X) & 0xf)
2031 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
2032 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
2033
2034 static int
2035 parse_neon_el_struct_list (char **str, unsigned *pbase,
2036 struct neon_type_el *eltype)
2037 {
2038 char *ptr = *str;
2039 int base_reg = -1;
2040 int reg_incr = -1;
2041 int count = 0;
2042 int lane = -1;
2043 int leading_brace = 0;
2044 enum arm_reg_type rtype = REG_TYPE_NDQ;
2045 const char *const incr_error = _("register stride must be 1 or 2");
2046 const char *const type_error = _("mismatched element/structure types in list");
2047 struct neon_typed_alias firsttype;
2048 firsttype.defined = 0;
2049 firsttype.eltype.type = NT_invtype;
2050 firsttype.eltype.size = -1;
2051 firsttype.index = -1;
2052
2053 if (skip_past_char (&ptr, '{') == SUCCESS)
2054 leading_brace = 1;
2055
2056 do
2057 {
2058 struct neon_typed_alias atype;
2059 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
2060
2061 if (getreg == FAIL)
2062 {
2063 first_error (_(reg_expected_msgs[rtype]));
2064 return FAIL;
2065 }
2066
2067 if (base_reg == -1)
2068 {
2069 base_reg = getreg;
2070 if (rtype == REG_TYPE_NQ)
2071 {
2072 reg_incr = 1;
2073 }
2074 firsttype = atype;
2075 }
2076 else if (reg_incr == -1)
2077 {
2078 reg_incr = getreg - base_reg;
2079 if (reg_incr < 1 || reg_incr > 2)
2080 {
2081 first_error (_(incr_error));
2082 return FAIL;
2083 }
2084 }
2085 else if (getreg != base_reg + reg_incr * count)
2086 {
2087 first_error (_(incr_error));
2088 return FAIL;
2089 }
2090
2091 if (! neon_alias_types_same (&atype, &firsttype))
2092 {
2093 first_error (_(type_error));
2094 return FAIL;
2095 }
2096
2097 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
2098 modes. */
2099 if (ptr[0] == '-')
2100 {
2101 struct neon_typed_alias htype;
2102 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
2103 if (lane == -1)
2104 lane = NEON_INTERLEAVE_LANES;
2105 else if (lane != NEON_INTERLEAVE_LANES)
2106 {
2107 first_error (_(type_error));
2108 return FAIL;
2109 }
2110 if (reg_incr == -1)
2111 reg_incr = 1;
2112 else if (reg_incr != 1)
2113 {
2114 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
2115 return FAIL;
2116 }
2117 ptr++;
2118 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
2119 if (hireg == FAIL)
2120 {
2121 first_error (_(reg_expected_msgs[rtype]));
2122 return FAIL;
2123 }
2124 if (! neon_alias_types_same (&htype, &firsttype))
2125 {
2126 first_error (_(type_error));
2127 return FAIL;
2128 }
2129 count += hireg + dregs - getreg;
2130 continue;
2131 }
2132
2133 /* If we're using Q registers, we can't use [] or [n] syntax. */
2134 if (rtype == REG_TYPE_NQ)
2135 {
2136 count += 2;
2137 continue;
2138 }
2139
2140 if ((atype.defined & NTA_HASINDEX) != 0)
2141 {
2142 if (lane == -1)
2143 lane = atype.index;
2144 else if (lane != atype.index)
2145 {
2146 first_error (_(type_error));
2147 return FAIL;
2148 }
2149 }
2150 else if (lane == -1)
2151 lane = NEON_INTERLEAVE_LANES;
2152 else if (lane != NEON_INTERLEAVE_LANES)
2153 {
2154 first_error (_(type_error));
2155 return FAIL;
2156 }
2157 count++;
2158 }
2159 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2160
2161 /* No lane set by [x]. We must be interleaving structures. */
2162 if (lane == -1)
2163 lane = NEON_INTERLEAVE_LANES;
2164
2165 /* Sanity check. */
2166 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2167 || (count > 1 && reg_incr == -1))
2168 {
2169 first_error (_("error parsing element/structure list"));
2170 return FAIL;
2171 }
2172
2173 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2174 {
2175 first_error (_("expected }"));
2176 return FAIL;
2177 }
2178
2179 if (reg_incr == -1)
2180 reg_incr = 1;
2181
2182 if (eltype)
2183 *eltype = firsttype.eltype;
2184
2185 *pbase = base_reg;
2186 *str = ptr;
2187
2188 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2189 }
2190
2191 /* Parse an explicit relocation suffix on an expression. This is
2192 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2193 arm_reloc_hsh contains no entries, so this function can only
2194 succeed if there is no () after the word. Returns -1 on error,
2195 BFD_RELOC_UNUSED if there wasn't any suffix. */
2196
2197 static int
2198 parse_reloc (char **str)
2199 {
2200 struct reloc_entry *r;
2201 char *p, *q;
2202
2203 if (**str != '(')
2204 return BFD_RELOC_UNUSED;
2205
2206 p = *str + 1;
2207 q = p;
2208
2209 while (*q && *q != ')' && *q != ',')
2210 q++;
2211 if (*q != ')')
2212 return -1;
2213
2214 if ((r = (struct reloc_entry *)
2215 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2216 return -1;
2217
2218 *str = q + 1;
2219 return r->reloc;
2220 }
2221
2222 /* Directives: register aliases. */
2223
2224 static struct reg_entry *
2225 insert_reg_alias (char *str, unsigned number, int type)
2226 {
2227 struct reg_entry *new_reg;
2228 const char *name;
2229
2230 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2231 {
2232 if (new_reg->builtin)
2233 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2234
2235 /* Only warn about a redefinition if it's not defined as the
2236 same register. */
2237 else if (new_reg->number != number || new_reg->type != type)
2238 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2239
2240 return NULL;
2241 }
2242
2243 name = xstrdup (str);
2244 new_reg = XNEW (struct reg_entry);
2245
2246 new_reg->name = name;
2247 new_reg->number = number;
2248 new_reg->type = type;
2249 new_reg->builtin = FALSE;
2250 new_reg->neon = NULL;
2251
2252 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2253 abort ();
2254
2255 return new_reg;
2256 }
2257
2258 static void
2259 insert_neon_reg_alias (char *str, int number, int type,
2260 struct neon_typed_alias *atype)
2261 {
2262 struct reg_entry *reg = insert_reg_alias (str, number, type);
2263
2264 if (!reg)
2265 {
2266 first_error (_("attempt to redefine typed alias"));
2267 return;
2268 }
2269
2270 if (atype)
2271 {
2272 reg->neon = XNEW (struct neon_typed_alias);
2273 *reg->neon = *atype;
2274 }
2275 }
2276
2277 /* Look for the .req directive. This is of the form:
2278
2279 new_register_name .req existing_register_name
2280
2281 If we find one, or if it looks sufficiently like one that we want to
2282 handle any error here, return TRUE. Otherwise return FALSE. */
2283
2284 static bfd_boolean
2285 create_register_alias (char * newname, char *p)
2286 {
2287 struct reg_entry *old;
2288 char *oldname, *nbuf;
2289 size_t nlen;
2290
2291 /* The input scrubber ensures that whitespace after the mnemonic is
2292 collapsed to single spaces. */
2293 oldname = p;
2294 if (strncmp (oldname, " .req ", 6) != 0)
2295 return FALSE;
2296
2297 oldname += 6;
2298 if (*oldname == '\0')
2299 return FALSE;
2300
2301 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2302 if (!old)
2303 {
2304 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2305 return TRUE;
2306 }
2307
2308 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2309 the desired alias name, and p points to its end. If not, then
2310 the desired alias name is in the global original_case_string. */
2311 #ifdef TC_CASE_SENSITIVE
2312 nlen = p - newname;
2313 #else
2314 newname = original_case_string;
2315 nlen = strlen (newname);
2316 #endif
2317
2318 nbuf = xmemdup0 (newname, nlen);
2319
2320 /* Create aliases under the new name as stated; an all-lowercase
2321 version of the new name; and an all-uppercase version of the new
2322 name. */
2323 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2324 {
2325 for (p = nbuf; *p; p++)
2326 *p = TOUPPER (*p);
2327
2328 if (strncmp (nbuf, newname, nlen))
2329 {
2330 /* If this attempt to create an additional alias fails, do not bother
2331 trying to create the all-lower case alias. We will fail and issue
2332 a second, duplicate error message. This situation arises when the
2333 programmer does something like:
2334 foo .req r0
2335 Foo .req r1
2336 The second .req creates the "Foo" alias but then fails to create
2337 the artificial FOO alias because it has already been created by the
2338 first .req. */
2339 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2340 {
2341 free (nbuf);
2342 return TRUE;
2343 }
2344 }
2345
2346 for (p = nbuf; *p; p++)
2347 *p = TOLOWER (*p);
2348
2349 if (strncmp (nbuf, newname, nlen))
2350 insert_reg_alias (nbuf, old->number, old->type);
2351 }
2352
2353 free (nbuf);
2354 return TRUE;
2355 }
2356
2357 /* Create a Neon typed/indexed register alias using directives, e.g.:
2358 X .dn d5.s32[1]
2359 Y .qn 6.s16
2360 Z .dn d7
2361 T .dn Z[0]
2362 These typed registers can be used instead of the types specified after the
2363 Neon mnemonic, so long as all operands given have types. Types can also be
2364 specified directly, e.g.:
2365 vadd d0.s32, d1.s32, d2.s32 */
2366
2367 static bfd_boolean
2368 create_neon_reg_alias (char *newname, char *p)
2369 {
2370 enum arm_reg_type basetype;
2371 struct reg_entry *basereg;
2372 struct reg_entry mybasereg;
2373 struct neon_type ntype;
2374 struct neon_typed_alias typeinfo;
2375 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2376 int namelen;
2377
2378 typeinfo.defined = 0;
2379 typeinfo.eltype.type = NT_invtype;
2380 typeinfo.eltype.size = -1;
2381 typeinfo.index = -1;
2382
2383 nameend = p;
2384
2385 if (strncmp (p, " .dn ", 5) == 0)
2386 basetype = REG_TYPE_VFD;
2387 else if (strncmp (p, " .qn ", 5) == 0)
2388 basetype = REG_TYPE_NQ;
2389 else
2390 return FALSE;
2391
2392 p += 5;
2393
2394 if (*p == '\0')
2395 return FALSE;
2396
2397 basereg = arm_reg_parse_multi (&p);
2398
2399 if (basereg && basereg->type != basetype)
2400 {
2401 as_bad (_("bad type for register"));
2402 return FALSE;
2403 }
2404
2405 if (basereg == NULL)
2406 {
2407 expressionS exp;
2408 /* Try parsing as an integer. */
2409 my_get_expression (&exp, &p, GE_NO_PREFIX);
2410 if (exp.X_op != O_constant)
2411 {
2412 as_bad (_("expression must be constant"));
2413 return FALSE;
2414 }
2415 basereg = &mybasereg;
2416 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2417 : exp.X_add_number;
2418 basereg->neon = 0;
2419 }
2420
2421 if (basereg->neon)
2422 typeinfo = *basereg->neon;
2423
2424 if (parse_neon_type (&ntype, &p) == SUCCESS)
2425 {
2426 /* We got a type. */
2427 if (typeinfo.defined & NTA_HASTYPE)
2428 {
2429 as_bad (_("can't redefine the type of a register alias"));
2430 return FALSE;
2431 }
2432
2433 typeinfo.defined |= NTA_HASTYPE;
2434 if (ntype.elems != 1)
2435 {
2436 as_bad (_("you must specify a single type only"));
2437 return FALSE;
2438 }
2439 typeinfo.eltype = ntype.el[0];
2440 }
2441
2442 if (skip_past_char (&p, '[') == SUCCESS)
2443 {
2444 expressionS exp;
2445 /* We got a scalar index. */
2446
2447 if (typeinfo.defined & NTA_HASINDEX)
2448 {
2449 as_bad (_("can't redefine the index of a scalar alias"));
2450 return FALSE;
2451 }
2452
2453 my_get_expression (&exp, &p, GE_NO_PREFIX);
2454
2455 if (exp.X_op != O_constant)
2456 {
2457 as_bad (_("scalar index must be constant"));
2458 return FALSE;
2459 }
2460
2461 typeinfo.defined |= NTA_HASINDEX;
2462 typeinfo.index = exp.X_add_number;
2463
2464 if (skip_past_char (&p, ']') == FAIL)
2465 {
2466 as_bad (_("expecting ]"));
2467 return FALSE;
2468 }
2469 }
2470
2471 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2472 the desired alias name, and p points to its end. If not, then
2473 the desired alias name is in the global original_case_string. */
2474 #ifdef TC_CASE_SENSITIVE
2475 namelen = nameend - newname;
2476 #else
2477 newname = original_case_string;
2478 namelen = strlen (newname);
2479 #endif
2480
2481 namebuf = xmemdup0 (newname, namelen);
2482
2483 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2484 typeinfo.defined != 0 ? &typeinfo : NULL);
2485
2486 /* Insert name in all uppercase. */
2487 for (p = namebuf; *p; p++)
2488 *p = TOUPPER (*p);
2489
2490 if (strncmp (namebuf, newname, namelen))
2491 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2492 typeinfo.defined != 0 ? &typeinfo : NULL);
2493
2494 /* Insert name in all lowercase. */
2495 for (p = namebuf; *p; p++)
2496 *p = TOLOWER (*p);
2497
2498 if (strncmp (namebuf, newname, namelen))
2499 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2500 typeinfo.defined != 0 ? &typeinfo : NULL);
2501
2502 free (namebuf);
2503 return TRUE;
2504 }
2505
2506 /* Should never be called, as .req goes between the alias and the
2507 register name, not at the beginning of the line. */
2508
2509 static void
2510 s_req (int a ATTRIBUTE_UNUSED)
2511 {
2512 as_bad (_("invalid syntax for .req directive"));
2513 }
2514
2515 static void
2516 s_dn (int a ATTRIBUTE_UNUSED)
2517 {
2518 as_bad (_("invalid syntax for .dn directive"));
2519 }
2520
2521 static void
2522 s_qn (int a ATTRIBUTE_UNUSED)
2523 {
2524 as_bad (_("invalid syntax for .qn directive"));
2525 }
2526
2527 /* The .unreq directive deletes an alias which was previously defined
2528 by .req. For example:
2529
2530 my_alias .req r11
2531 .unreq my_alias */
2532
2533 static void
2534 s_unreq (int a ATTRIBUTE_UNUSED)
2535 {
2536 char * name;
2537 char saved_char;
2538
2539 name = input_line_pointer;
2540
2541 while (*input_line_pointer != 0
2542 && *input_line_pointer != ' '
2543 && *input_line_pointer != '\n')
2544 ++input_line_pointer;
2545
2546 saved_char = *input_line_pointer;
2547 *input_line_pointer = 0;
2548
2549 if (!*name)
2550 as_bad (_("invalid syntax for .unreq directive"));
2551 else
2552 {
2553 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2554 name);
2555
2556 if (!reg)
2557 as_bad (_("unknown register alias '%s'"), name);
2558 else if (reg->builtin)
2559 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2560 name);
2561 else
2562 {
2563 char * p;
2564 char * nbuf;
2565
2566 hash_delete (arm_reg_hsh, name, FALSE);
2567 free ((char *) reg->name);
2568 if (reg->neon)
2569 free (reg->neon);
2570 free (reg);
2571
2572 /* Also locate the all upper case and all lower case versions.
2573 Do not complain if we cannot find one or the other as it
2574 was probably deleted above. */
2575
2576 nbuf = strdup (name);
2577 for (p = nbuf; *p; p++)
2578 *p = TOUPPER (*p);
2579 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2580 if (reg)
2581 {
2582 hash_delete (arm_reg_hsh, nbuf, FALSE);
2583 free ((char *) reg->name);
2584 if (reg->neon)
2585 free (reg->neon);
2586 free (reg);
2587 }
2588
2589 for (p = nbuf; *p; p++)
2590 *p = TOLOWER (*p);
2591 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2592 if (reg)
2593 {
2594 hash_delete (arm_reg_hsh, nbuf, FALSE);
2595 free ((char *) reg->name);
2596 if (reg->neon)
2597 free (reg->neon);
2598 free (reg);
2599 }
2600
2601 free (nbuf);
2602 }
2603 }
2604
2605 *input_line_pointer = saved_char;
2606 demand_empty_rest_of_line ();
2607 }
2608
2609 /* Directives: Instruction set selection. */
2610
2611 #ifdef OBJ_ELF
2612 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2613 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2614 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2615 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2616
2617 /* Create a new mapping symbol for the transition to STATE. */
2618
2619 static void
2620 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2621 {
2622 symbolS * symbolP;
2623 const char * symname;
2624 int type;
2625
2626 switch (state)
2627 {
2628 case MAP_DATA:
2629 symname = "$d";
2630 type = BSF_NO_FLAGS;
2631 break;
2632 case MAP_ARM:
2633 symname = "$a";
2634 type = BSF_NO_FLAGS;
2635 break;
2636 case MAP_THUMB:
2637 symname = "$t";
2638 type = BSF_NO_FLAGS;
2639 break;
2640 default:
2641 abort ();
2642 }
2643
2644 symbolP = symbol_new (symname, now_seg, value, frag);
2645 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2646
2647 switch (state)
2648 {
2649 case MAP_ARM:
2650 THUMB_SET_FUNC (symbolP, 0);
2651 ARM_SET_THUMB (symbolP, 0);
2652 ARM_SET_INTERWORK (symbolP, support_interwork);
2653 break;
2654
2655 case MAP_THUMB:
2656 THUMB_SET_FUNC (symbolP, 1);
2657 ARM_SET_THUMB (symbolP, 1);
2658 ARM_SET_INTERWORK (symbolP, support_interwork);
2659 break;
2660
2661 case MAP_DATA:
2662 default:
2663 break;
2664 }
2665
2666 /* Save the mapping symbols for future reference. Also check that
2667 we do not place two mapping symbols at the same offset within a
2668 frag. We'll handle overlap between frags in
2669 check_mapping_symbols.
2670
2671 If .fill or other data filling directive generates zero sized data,
2672 the mapping symbol for the following code will have the same value
2673 as the one generated for the data filling directive. In this case,
2674 we replace the old symbol with the new one at the same address. */
2675 if (value == 0)
2676 {
2677 if (frag->tc_frag_data.first_map != NULL)
2678 {
2679 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2680 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2681 }
2682 frag->tc_frag_data.first_map = symbolP;
2683 }
2684 if (frag->tc_frag_data.last_map != NULL)
2685 {
2686 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2687 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2688 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2689 }
2690 frag->tc_frag_data.last_map = symbolP;
2691 }
2692
2693 /* We must sometimes convert a region marked as code to data during
2694 code alignment, if an odd number of bytes have to be padded. The
2695 code mapping symbol is pushed to an aligned address. */
2696
2697 static void
2698 insert_data_mapping_symbol (enum mstate state,
2699 valueT value, fragS *frag, offsetT bytes)
2700 {
2701 /* If there was already a mapping symbol, remove it. */
2702 if (frag->tc_frag_data.last_map != NULL
2703 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2704 {
2705 symbolS *symp = frag->tc_frag_data.last_map;
2706
2707 if (value == 0)
2708 {
2709 know (frag->tc_frag_data.first_map == symp);
2710 frag->tc_frag_data.first_map = NULL;
2711 }
2712 frag->tc_frag_data.last_map = NULL;
2713 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2714 }
2715
2716 make_mapping_symbol (MAP_DATA, value, frag);
2717 make_mapping_symbol (state, value + bytes, frag);
2718 }
2719
2720 static void mapping_state_2 (enum mstate state, int max_chars);
2721
2722 /* Set the mapping state to STATE. Only call this when about to
2723 emit some STATE bytes to the file. */
2724
2725 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2726 void
2727 mapping_state (enum mstate state)
2728 {
2729 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2730
2731 if (mapstate == state)
2732 /* The mapping symbol has already been emitted.
2733 There is nothing else to do. */
2734 return;
2735
2736 if (state == MAP_ARM || state == MAP_THUMB)
2737 /* PR gas/12931
2738 All ARM instructions require 4-byte alignment.
2739 (Almost) all Thumb instructions require 2-byte alignment.
2740
2741 When emitting instructions into any section, mark the section
2742 appropriately.
2743
2744 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2745 but themselves require 2-byte alignment; this applies to some
2746 PC- relative forms. However, these cases will involve implicit
2747 literal pool generation or an explicit .align >=2, both of
2748 which will cause the section to me marked with sufficient
2749 alignment. Thus, we don't handle those cases here. */
2750 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2751
2752 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2753 /* This case will be evaluated later. */
2754 return;
2755
2756 mapping_state_2 (state, 0);
2757 }
2758
2759 /* Same as mapping_state, but MAX_CHARS bytes have already been
2760 allocated. Put the mapping symbol that far back. */
2761
2762 static void
2763 mapping_state_2 (enum mstate state, int max_chars)
2764 {
2765 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2766
2767 if (!SEG_NORMAL (now_seg))
2768 return;
2769
2770 if (mapstate == state)
2771 /* The mapping symbol has already been emitted.
2772 There is nothing else to do. */
2773 return;
2774
2775 if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2776 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2777 {
2778 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2779 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2780
2781 if (add_symbol)
2782 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2783 }
2784
2785 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2786 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2787 }
2788 #undef TRANSITION
2789 #else
2790 #define mapping_state(x) ((void)0)
2791 #define mapping_state_2(x, y) ((void)0)
2792 #endif
2793
2794 /* Find the real, Thumb encoded start of a Thumb function. */
2795
2796 #ifdef OBJ_COFF
2797 static symbolS *
2798 find_real_start (symbolS * symbolP)
2799 {
2800 char * real_start;
2801 const char * name = S_GET_NAME (symbolP);
2802 symbolS * new_target;
2803
2804 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2805 #define STUB_NAME ".real_start_of"
2806
2807 if (name == NULL)
2808 abort ();
2809
2810 /* The compiler may generate BL instructions to local labels because
2811 it needs to perform a branch to a far away location. These labels
2812 do not have a corresponding ".real_start_of" label. We check
2813 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2814 the ".real_start_of" convention for nonlocal branches. */
2815 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2816 return symbolP;
2817
2818 real_start = concat (STUB_NAME, name, NULL);
2819 new_target = symbol_find (real_start);
2820 free (real_start);
2821
2822 if (new_target == NULL)
2823 {
2824 as_warn (_("Failed to find real start of function: %s\n"), name);
2825 new_target = symbolP;
2826 }
2827
2828 return new_target;
2829 }
2830 #endif
2831
2832 static void
2833 opcode_select (int width)
2834 {
2835 switch (width)
2836 {
2837 case 16:
2838 if (! thumb_mode)
2839 {
2840 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2841 as_bad (_("selected processor does not support THUMB opcodes"));
2842
2843 thumb_mode = 1;
2844 /* No need to force the alignment, since we will have been
2845 coming from ARM mode, which is word-aligned. */
2846 record_alignment (now_seg, 1);
2847 }
2848 break;
2849
2850 case 32:
2851 if (thumb_mode)
2852 {
2853 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2854 as_bad (_("selected processor does not support ARM opcodes"));
2855
2856 thumb_mode = 0;
2857
2858 if (!need_pass_2)
2859 frag_align (2, 0, 0);
2860
2861 record_alignment (now_seg, 1);
2862 }
2863 break;
2864
2865 default:
2866 as_bad (_("invalid instruction size selected (%d)"), width);
2867 }
2868 }
2869
2870 static void
2871 s_arm (int ignore ATTRIBUTE_UNUSED)
2872 {
2873 opcode_select (32);
2874 demand_empty_rest_of_line ();
2875 }
2876
2877 static void
2878 s_thumb (int ignore ATTRIBUTE_UNUSED)
2879 {
2880 opcode_select (16);
2881 demand_empty_rest_of_line ();
2882 }
2883
2884 static void
2885 s_code (int unused ATTRIBUTE_UNUSED)
2886 {
2887 int temp;
2888
2889 temp = get_absolute_expression ();
2890 switch (temp)
2891 {
2892 case 16:
2893 case 32:
2894 opcode_select (temp);
2895 break;
2896
2897 default:
2898 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2899 }
2900 }
2901
2902 static void
2903 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2904 {
2905 /* If we are not already in thumb mode go into it, EVEN if
2906 the target processor does not support thumb instructions.
2907 This is used by gcc/config/arm/lib1funcs.asm for example
2908 to compile interworking support functions even if the
2909 target processor should not support interworking. */
2910 if (! thumb_mode)
2911 {
2912 thumb_mode = 2;
2913 record_alignment (now_seg, 1);
2914 }
2915
2916 demand_empty_rest_of_line ();
2917 }
2918
2919 static void
2920 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2921 {
2922 s_thumb (0);
2923
2924 /* The following label is the name/address of the start of a Thumb function.
2925 We need to know this for the interworking support. */
2926 label_is_thumb_function_name = TRUE;
2927 }
2928
2929 /* Perform a .set directive, but also mark the alias as
2930 being a thumb function. */
2931
2932 static void
2933 s_thumb_set (int equiv)
2934 {
2935 /* XXX the following is a duplicate of the code for s_set() in read.c
2936 We cannot just call that code as we need to get at the symbol that
2937 is created. */
2938 char * name;
2939 char delim;
2940 char * end_name;
2941 symbolS * symbolP;
2942
2943 /* Especial apologies for the random logic:
2944 This just grew, and could be parsed much more simply!
2945 Dean - in haste. */
2946 delim = get_symbol_name (& name);
2947 end_name = input_line_pointer;
2948 (void) restore_line_pointer (delim);
2949
2950 if (*input_line_pointer != ',')
2951 {
2952 *end_name = 0;
2953 as_bad (_("expected comma after name \"%s\""), name);
2954 *end_name = delim;
2955 ignore_rest_of_line ();
2956 return;
2957 }
2958
2959 input_line_pointer++;
2960 *end_name = 0;
2961
2962 if (name[0] == '.' && name[1] == '\0')
2963 {
2964 /* XXX - this should not happen to .thumb_set. */
2965 abort ();
2966 }
2967
2968 if ((symbolP = symbol_find (name)) == NULL
2969 && (symbolP = md_undefined_symbol (name)) == NULL)
2970 {
2971 #ifndef NO_LISTING
2972 /* When doing symbol listings, play games with dummy fragments living
2973 outside the normal fragment chain to record the file and line info
2974 for this symbol. */
2975 if (listing & LISTING_SYMBOLS)
2976 {
2977 extern struct list_info_struct * listing_tail;
2978 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2979
2980 memset (dummy_frag, 0, sizeof (fragS));
2981 dummy_frag->fr_type = rs_fill;
2982 dummy_frag->line = listing_tail;
2983 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2984 dummy_frag->fr_symbol = symbolP;
2985 }
2986 else
2987 #endif
2988 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2989
2990 #ifdef OBJ_COFF
2991 /* "set" symbols are local unless otherwise specified. */
2992 SF_SET_LOCAL (symbolP);
2993 #endif /* OBJ_COFF */
2994 } /* Make a new symbol. */
2995
2996 symbol_table_insert (symbolP);
2997
2998 * end_name = delim;
2999
3000 if (equiv
3001 && S_IS_DEFINED (symbolP)
3002 && S_GET_SEGMENT (symbolP) != reg_section)
3003 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
3004
3005 pseudo_set (symbolP);
3006
3007 demand_empty_rest_of_line ();
3008
3009 /* XXX Now we come to the Thumb specific bit of code. */
3010
3011 THUMB_SET_FUNC (symbolP, 1);
3012 ARM_SET_THUMB (symbolP, 1);
3013 #if defined OBJ_ELF || defined OBJ_COFF
3014 ARM_SET_INTERWORK (symbolP, support_interwork);
3015 #endif
3016 }
3017
3018 /* Directives: Mode selection. */
3019
3020 /* .syntax [unified|divided] - choose the new unified syntax
3021 (same for Arm and Thumb encoding, modulo slight differences in what
3022 can be represented) or the old divergent syntax for each mode. */
3023 static void
3024 s_syntax (int unused ATTRIBUTE_UNUSED)
3025 {
3026 char *name, delim;
3027
3028 delim = get_symbol_name (& name);
3029
3030 if (!strcasecmp (name, "unified"))
3031 unified_syntax = TRUE;
3032 else if (!strcasecmp (name, "divided"))
3033 unified_syntax = FALSE;
3034 else
3035 {
3036 as_bad (_("unrecognized syntax mode \"%s\""), name);
3037 return;
3038 }
3039 (void) restore_line_pointer (delim);
3040 demand_empty_rest_of_line ();
3041 }
3042
3043 /* Directives: sectioning and alignment. */
3044
3045 static void
3046 s_bss (int ignore ATTRIBUTE_UNUSED)
3047 {
3048 /* We don't support putting frags in the BSS segment, we fake it by
3049 marking in_bss, then looking at s_skip for clues. */
3050 subseg_set (bss_section, 0);
3051 demand_empty_rest_of_line ();
3052
3053 #ifdef md_elf_section_change_hook
3054 md_elf_section_change_hook ();
3055 #endif
3056 }
3057
3058 static void
3059 s_even (int ignore ATTRIBUTE_UNUSED)
3060 {
3061 /* Never make frag if expect extra pass. */
3062 if (!need_pass_2)
3063 frag_align (1, 0, 0);
3064
3065 record_alignment (now_seg, 1);
3066
3067 demand_empty_rest_of_line ();
3068 }
3069
3070 /* Directives: CodeComposer Studio. */
3071
3072 /* .ref (for CodeComposer Studio syntax only). */
3073 static void
3074 s_ccs_ref (int unused ATTRIBUTE_UNUSED)
3075 {
3076 if (codecomposer_syntax)
3077 ignore_rest_of_line ();
3078 else
3079 as_bad (_(".ref pseudo-op only available with -mccs flag."));
3080 }
3081
3082 /* If name is not NULL, then it is used for marking the beginning of a
3083 function, whereas if it is NULL then it means the function end. */
3084 static void
3085 asmfunc_debug (const char * name)
3086 {
3087 static const char * last_name = NULL;
3088
3089 if (name != NULL)
3090 {
3091 gas_assert (last_name == NULL);
3092 last_name = name;
3093
3094 if (debug_type == DEBUG_STABS)
3095 stabs_generate_asm_func (name, name);
3096 }
3097 else
3098 {
3099 gas_assert (last_name != NULL);
3100
3101 if (debug_type == DEBUG_STABS)
3102 stabs_generate_asm_endfunc (last_name, last_name);
3103
3104 last_name = NULL;
3105 }
3106 }
3107
3108 static void
3109 s_ccs_asmfunc (int unused ATTRIBUTE_UNUSED)
3110 {
3111 if (codecomposer_syntax)
3112 {
3113 switch (asmfunc_state)
3114 {
3115 case OUTSIDE_ASMFUNC:
3116 asmfunc_state = WAITING_ASMFUNC_NAME;
3117 break;
3118
3119 case WAITING_ASMFUNC_NAME:
3120 as_bad (_(".asmfunc repeated."));
3121 break;
3122
3123 case WAITING_ENDASMFUNC:
3124 as_bad (_(".asmfunc without function."));
3125 break;
3126 }
3127 demand_empty_rest_of_line ();
3128 }
3129 else
3130 as_bad (_(".asmfunc pseudo-op only available with -mccs flag."));
3131 }
3132
3133 static void
3134 s_ccs_endasmfunc (int unused ATTRIBUTE_UNUSED)
3135 {
3136 if (codecomposer_syntax)
3137 {
3138 switch (asmfunc_state)
3139 {
3140 case OUTSIDE_ASMFUNC:
3141 as_bad (_(".endasmfunc without a .asmfunc."));
3142 break;
3143
3144 case WAITING_ASMFUNC_NAME:
3145 as_bad (_(".endasmfunc without function."));
3146 break;
3147
3148 case WAITING_ENDASMFUNC:
3149 asmfunc_state = OUTSIDE_ASMFUNC;
3150 asmfunc_debug (NULL);
3151 break;
3152 }
3153 demand_empty_rest_of_line ();
3154 }
3155 else
3156 as_bad (_(".endasmfunc pseudo-op only available with -mccs flag."));
3157 }
3158
3159 static void
3160 s_ccs_def (int name)
3161 {
3162 if (codecomposer_syntax)
3163 s_globl (name);
3164 else
3165 as_bad (_(".def pseudo-op only available with -mccs flag."));
3166 }
3167
3168 /* Directives: Literal pools. */
3169
3170 static literal_pool *
3171 find_literal_pool (void)
3172 {
3173 literal_pool * pool;
3174
3175 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3176 {
3177 if (pool->section == now_seg
3178 && pool->sub_section == now_subseg)
3179 break;
3180 }
3181
3182 return pool;
3183 }
3184
3185 static literal_pool *
3186 find_or_make_literal_pool (void)
3187 {
3188 /* Next literal pool ID number. */
3189 static unsigned int latest_pool_num = 1;
3190 literal_pool * pool;
3191
3192 pool = find_literal_pool ();
3193
3194 if (pool == NULL)
3195 {
3196 /* Create a new pool. */
3197 pool = XNEW (literal_pool);
3198 if (! pool)
3199 return NULL;
3200
3201 pool->next_free_entry = 0;
3202 pool->section = now_seg;
3203 pool->sub_section = now_subseg;
3204 pool->next = list_of_pools;
3205 pool->symbol = NULL;
3206 pool->alignment = 2;
3207
3208 /* Add it to the list. */
3209 list_of_pools = pool;
3210 }
3211
3212 /* New pools, and emptied pools, will have a NULL symbol. */
3213 if (pool->symbol == NULL)
3214 {
3215 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3216 (valueT) 0, &zero_address_frag);
3217 pool->id = latest_pool_num ++;
3218 }
3219
3220 /* Done. */
3221 return pool;
3222 }
3223
3224 /* Add the literal in the global 'inst'
3225 structure to the relevant literal pool. */
3226
3227 static int
3228 add_to_lit_pool (unsigned int nbytes)
3229 {
3230 #define PADDING_SLOT 0x1
3231 #define LIT_ENTRY_SIZE_MASK 0xFF
3232 literal_pool * pool;
3233 unsigned int entry, pool_size = 0;
3234 bfd_boolean padding_slot_p = FALSE;
3235 unsigned imm1 = 0;
3236 unsigned imm2 = 0;
3237
3238 if (nbytes == 8)
3239 {
3240 imm1 = inst.operands[1].imm;
3241 imm2 = (inst.operands[1].regisimm ? inst.operands[1].reg
3242 : inst.reloc.exp.X_unsigned ? 0
3243 : ((bfd_int64_t) inst.operands[1].imm) >> 32);
3244 if (target_big_endian)
3245 {
3246 imm1 = imm2;
3247 imm2 = inst.operands[1].imm;
3248 }
3249 }
3250
3251 pool = find_or_make_literal_pool ();
3252
3253 /* Check if this literal value is already in the pool. */
3254 for (entry = 0; entry < pool->next_free_entry; entry ++)
3255 {
3256 if (nbytes == 4)
3257 {
3258 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3259 && (inst.reloc.exp.X_op == O_constant)
3260 && (pool->literals[entry].X_add_number
3261 == inst.reloc.exp.X_add_number)
3262 && (pool->literals[entry].X_md == nbytes)
3263 && (pool->literals[entry].X_unsigned
3264 == inst.reloc.exp.X_unsigned))
3265 break;
3266
3267 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3268 && (inst.reloc.exp.X_op == O_symbol)
3269 && (pool->literals[entry].X_add_number
3270 == inst.reloc.exp.X_add_number)
3271 && (pool->literals[entry].X_add_symbol
3272 == inst.reloc.exp.X_add_symbol)
3273 && (pool->literals[entry].X_op_symbol
3274 == inst.reloc.exp.X_op_symbol)
3275 && (pool->literals[entry].X_md == nbytes))
3276 break;
3277 }
3278 else if ((nbytes == 8)
3279 && !(pool_size & 0x7)
3280 && ((entry + 1) != pool->next_free_entry)
3281 && (pool->literals[entry].X_op == O_constant)
3282 && (pool->literals[entry].X_add_number == (offsetT) imm1)
3283 && (pool->literals[entry].X_unsigned
3284 == inst.reloc.exp.X_unsigned)
3285 && (pool->literals[entry + 1].X_op == O_constant)
3286 && (pool->literals[entry + 1].X_add_number == (offsetT) imm2)
3287 && (pool->literals[entry + 1].X_unsigned
3288 == inst.reloc.exp.X_unsigned))
3289 break;
3290
3291 padding_slot_p = ((pool->literals[entry].X_md >> 8) == PADDING_SLOT);
3292 if (padding_slot_p && (nbytes == 4))
3293 break;
3294
3295 pool_size += 4;
3296 }
3297
3298 /* Do we need to create a new entry? */
3299 if (entry == pool->next_free_entry)
3300 {
3301 if (entry >= MAX_LITERAL_POOL_SIZE)
3302 {
3303 inst.error = _("literal pool overflow");
3304 return FAIL;
3305 }
3306
3307 if (nbytes == 8)
3308 {
3309 /* For 8-byte entries, we align to an 8-byte boundary,
3310 and split it into two 4-byte entries, because on 32-bit
3311 host, 8-byte constants are treated as big num, thus
3312 saved in "generic_bignum" which will be overwritten
3313 by later assignments.
3314
3315 We also need to make sure there is enough space for
3316 the split.
3317
3318 We also check to make sure the literal operand is a
3319 constant number. */
3320 if (!(inst.reloc.exp.X_op == O_constant
3321 || inst.reloc.exp.X_op == O_big))
3322 {
3323 inst.error = _("invalid type for literal pool");
3324 return FAIL;
3325 }
3326 else if (pool_size & 0x7)
3327 {
3328 if ((entry + 2) >= MAX_LITERAL_POOL_SIZE)
3329 {
3330 inst.error = _("literal pool overflow");
3331 return FAIL;
3332 }
3333
3334 pool->literals[entry] = inst.reloc.exp;
3335 pool->literals[entry].X_op = O_constant;
3336 pool->literals[entry].X_add_number = 0;
3337 pool->literals[entry++].X_md = (PADDING_SLOT << 8) | 4;
3338 pool->next_free_entry += 1;
3339 pool_size += 4;
3340 }
3341 else if ((entry + 1) >= MAX_LITERAL_POOL_SIZE)
3342 {
3343 inst.error = _("literal pool overflow");
3344 return FAIL;
3345 }
3346
3347 pool->literals[entry] = inst.reloc.exp;
3348 pool->literals[entry].X_op = O_constant;
3349 pool->literals[entry].X_add_number = imm1;
3350 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3351 pool->literals[entry++].X_md = 4;
3352 pool->literals[entry] = inst.reloc.exp;
3353 pool->literals[entry].X_op = O_constant;
3354 pool->literals[entry].X_add_number = imm2;
3355 pool->literals[entry].X_unsigned = inst.reloc.exp.X_unsigned;
3356 pool->literals[entry].X_md = 4;
3357 pool->alignment = 3;
3358 pool->next_free_entry += 1;
3359 }
3360 else
3361 {
3362 pool->literals[entry] = inst.reloc.exp;
3363 pool->literals[entry].X_md = 4;
3364 }
3365
3366 #ifdef OBJ_ELF
3367 /* PR ld/12974: Record the location of the first source line to reference
3368 this entry in the literal pool. If it turns out during linking that the
3369 symbol does not exist we will be able to give an accurate line number for
3370 the (first use of the) missing reference. */
3371 if (debug_type == DEBUG_DWARF2)
3372 dwarf2_where (pool->locs + entry);
3373 #endif
3374 pool->next_free_entry += 1;
3375 }
3376 else if (padding_slot_p)
3377 {
3378 pool->literals[entry] = inst.reloc.exp;
3379 pool->literals[entry].X_md = nbytes;
3380 }
3381
3382 inst.reloc.exp.X_op = O_symbol;
3383 inst.reloc.exp.X_add_number = pool_size;
3384 inst.reloc.exp.X_add_symbol = pool->symbol;
3385
3386 return SUCCESS;
3387 }
3388
3389 bfd_boolean
3390 tc_start_label_without_colon (void)
3391 {
3392 bfd_boolean ret = TRUE;
3393
3394 if (codecomposer_syntax && asmfunc_state == WAITING_ASMFUNC_NAME)
3395 {
3396 const char *label = input_line_pointer;
3397
3398 while (!is_end_of_line[(int) label[-1]])
3399 --label;
3400
3401 if (*label == '.')
3402 {
3403 as_bad (_("Invalid label '%s'"), label);
3404 ret = FALSE;
3405 }
3406
3407 asmfunc_debug (label);
3408
3409 asmfunc_state = WAITING_ENDASMFUNC;
3410 }
3411
3412 return ret;
3413 }
3414
3415 /* Can't use symbol_new here, so have to create a symbol and then at
3416 a later date assign it a value. That's what these functions do. */
3417
3418 static void
3419 symbol_locate (symbolS * symbolP,
3420 const char * name, /* It is copied, the caller can modify. */
3421 segT segment, /* Segment identifier (SEG_<something>). */
3422 valueT valu, /* Symbol value. */
3423 fragS * frag) /* Associated fragment. */
3424 {
3425 size_t name_length;
3426 char * preserved_copy_of_name;
3427
3428 name_length = strlen (name) + 1; /* +1 for \0. */
3429 obstack_grow (&notes, name, name_length);
3430 preserved_copy_of_name = (char *) obstack_finish (&notes);
3431
3432 #ifdef tc_canonicalize_symbol_name
3433 preserved_copy_of_name =
3434 tc_canonicalize_symbol_name (preserved_copy_of_name);
3435 #endif
3436
3437 S_SET_NAME (symbolP, preserved_copy_of_name);
3438
3439 S_SET_SEGMENT (symbolP, segment);
3440 S_SET_VALUE (symbolP, valu);
3441 symbol_clear_list_pointers (symbolP);
3442
3443 symbol_set_frag (symbolP, frag);
3444
3445 /* Link to end of symbol chain. */
3446 {
3447 extern int symbol_table_frozen;
3448
3449 if (symbol_table_frozen)
3450 abort ();
3451 }
3452
3453 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3454
3455 obj_symbol_new_hook (symbolP);
3456
3457 #ifdef tc_symbol_new_hook
3458 tc_symbol_new_hook (symbolP);
3459 #endif
3460
3461 #ifdef DEBUG_SYMS
3462 verify_symbol_chain (symbol_rootP, symbol_lastP);
3463 #endif /* DEBUG_SYMS */
3464 }
3465
3466 static void
3467 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3468 {
3469 unsigned int entry;
3470 literal_pool * pool;
3471 char sym_name[20];
3472
3473 pool = find_literal_pool ();
3474 if (pool == NULL
3475 || pool->symbol == NULL
3476 || pool->next_free_entry == 0)
3477 return;
3478
3479 /* Align pool as you have word accesses.
3480 Only make a frag if we have to. */
3481 if (!need_pass_2)
3482 frag_align (pool->alignment, 0, 0);
3483
3484 record_alignment (now_seg, 2);
3485
3486 #ifdef OBJ_ELF
3487 seg_info (now_seg)->tc_segment_info_data.mapstate = MAP_DATA;
3488 make_mapping_symbol (MAP_DATA, (valueT) frag_now_fix (), frag_now);
3489 #endif
3490 sprintf (sym_name, "$$lit_\002%x", pool->id);
3491
3492 symbol_locate (pool->symbol, sym_name, now_seg,
3493 (valueT) frag_now_fix (), frag_now);
3494 symbol_table_insert (pool->symbol);
3495
3496 ARM_SET_THUMB (pool->symbol, thumb_mode);
3497
3498 #if defined OBJ_COFF || defined OBJ_ELF
3499 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3500 #endif
3501
3502 for (entry = 0; entry < pool->next_free_entry; entry ++)
3503 {
3504 #ifdef OBJ_ELF
3505 if (debug_type == DEBUG_DWARF2)
3506 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3507 #endif
3508 /* First output the expression in the instruction to the pool. */
3509 emit_expr (&(pool->literals[entry]),
3510 pool->literals[entry].X_md & LIT_ENTRY_SIZE_MASK);
3511 }
3512
3513 /* Mark the pool as empty. */
3514 pool->next_free_entry = 0;
3515 pool->symbol = NULL;
3516 }
3517
3518 #ifdef OBJ_ELF
3519 /* Forward declarations for functions below, in the MD interface
3520 section. */
3521 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3522 static valueT create_unwind_entry (int);
3523 static void start_unwind_section (const segT, int);
3524 static void add_unwind_opcode (valueT, int);
3525 static void flush_pending_unwind (void);
3526
3527 /* Directives: Data. */
3528
3529 static void
3530 s_arm_elf_cons (int nbytes)
3531 {
3532 expressionS exp;
3533
3534 #ifdef md_flush_pending_output
3535 md_flush_pending_output ();
3536 #endif
3537
3538 if (is_it_end_of_statement ())
3539 {
3540 demand_empty_rest_of_line ();
3541 return;
3542 }
3543
3544 #ifdef md_cons_align
3545 md_cons_align (nbytes);
3546 #endif
3547
3548 mapping_state (MAP_DATA);
3549 do
3550 {
3551 int reloc;
3552 char *base = input_line_pointer;
3553
3554 expression (& exp);
3555
3556 if (exp.X_op != O_symbol)
3557 emit_expr (&exp, (unsigned int) nbytes);
3558 else
3559 {
3560 char *before_reloc = input_line_pointer;
3561 reloc = parse_reloc (&input_line_pointer);
3562 if (reloc == -1)
3563 {
3564 as_bad (_("unrecognized relocation suffix"));
3565 ignore_rest_of_line ();
3566 return;
3567 }
3568 else if (reloc == BFD_RELOC_UNUSED)
3569 emit_expr (&exp, (unsigned int) nbytes);
3570 else
3571 {
3572 reloc_howto_type *howto = (reloc_howto_type *)
3573 bfd_reloc_type_lookup (stdoutput,
3574 (bfd_reloc_code_real_type) reloc);
3575 int size = bfd_get_reloc_size (howto);
3576
3577 if (reloc == BFD_RELOC_ARM_PLT32)
3578 {
3579 as_bad (_("(plt) is only valid on branch targets"));
3580 reloc = BFD_RELOC_UNUSED;
3581 size = 0;
3582 }
3583
3584 if (size > nbytes)
3585 as_bad (ngettext ("%s relocations do not fit in %d byte",
3586 "%s relocations do not fit in %d bytes",
3587 nbytes),
3588 howto->name, nbytes);
3589 else
3590 {
3591 /* We've parsed an expression stopping at O_symbol.
3592 But there may be more expression left now that we
3593 have parsed the relocation marker. Parse it again.
3594 XXX Surely there is a cleaner way to do this. */
3595 char *p = input_line_pointer;
3596 int offset;
3597 char *save_buf = XNEWVEC (char, input_line_pointer - base);
3598
3599 memcpy (save_buf, base, input_line_pointer - base);
3600 memmove (base + (input_line_pointer - before_reloc),
3601 base, before_reloc - base);
3602
3603 input_line_pointer = base + (input_line_pointer-before_reloc);
3604 expression (&exp);
3605 memcpy (base, save_buf, p - base);
3606
3607 offset = nbytes - size;
3608 p = frag_more (nbytes);
3609 memset (p, 0, nbytes);
3610 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3611 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3612 free (save_buf);
3613 }
3614 }
3615 }
3616 }
3617 while (*input_line_pointer++ == ',');
3618
3619 /* Put terminator back into stream. */
3620 input_line_pointer --;
3621 demand_empty_rest_of_line ();
3622 }
3623
3624 /* Emit an expression containing a 32-bit thumb instruction.
3625 Implementation based on put_thumb32_insn. */
3626
3627 static void
3628 emit_thumb32_expr (expressionS * exp)
3629 {
3630 expressionS exp_high = *exp;
3631
3632 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3633 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3634 exp->X_add_number &= 0xffff;
3635 emit_expr (exp, (unsigned int) THUMB_SIZE);
3636 }
3637
3638 /* Guess the instruction size based on the opcode. */
3639
3640 static int
3641 thumb_insn_size (int opcode)
3642 {
3643 if ((unsigned int) opcode < 0xe800u)
3644 return 2;
3645 else if ((unsigned int) opcode >= 0xe8000000u)
3646 return 4;
3647 else
3648 return 0;
3649 }
3650
3651 static bfd_boolean
3652 emit_insn (expressionS *exp, int nbytes)
3653 {
3654 int size = 0;
3655
3656 if (exp->X_op == O_constant)
3657 {
3658 size = nbytes;
3659
3660 if (size == 0)
3661 size = thumb_insn_size (exp->X_add_number);
3662
3663 if (size != 0)
3664 {
3665 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3666 {
3667 as_bad (_(".inst.n operand too big. "\
3668 "Use .inst.w instead"));
3669 size = 0;
3670 }
3671 else
3672 {
3673 if (now_it.state == AUTOMATIC_IT_BLOCK)
3674 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3675 else
3676 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3677
3678 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3679 emit_thumb32_expr (exp);
3680 else
3681 emit_expr (exp, (unsigned int) size);
3682
3683 it_fsm_post_encode ();
3684 }
3685 }
3686 else
3687 as_bad (_("cannot determine Thumb instruction size. " \
3688 "Use .inst.n/.inst.w instead"));
3689 }
3690 else
3691 as_bad (_("constant expression required"));
3692
3693 return (size != 0);
3694 }
3695
3696 /* Like s_arm_elf_cons but do not use md_cons_align and
3697 set the mapping state to MAP_ARM/MAP_THUMB. */
3698
3699 static void
3700 s_arm_elf_inst (int nbytes)
3701 {
3702 if (is_it_end_of_statement ())
3703 {
3704 demand_empty_rest_of_line ();
3705 return;
3706 }
3707
3708 /* Calling mapping_state () here will not change ARM/THUMB,
3709 but will ensure not to be in DATA state. */
3710
3711 if (thumb_mode)
3712 mapping_state (MAP_THUMB);
3713 else
3714 {
3715 if (nbytes != 0)
3716 {
3717 as_bad (_("width suffixes are invalid in ARM mode"));
3718 ignore_rest_of_line ();
3719 return;
3720 }
3721
3722 nbytes = 4;
3723
3724 mapping_state (MAP_ARM);
3725 }
3726
3727 do
3728 {
3729 expressionS exp;
3730
3731 expression (& exp);
3732
3733 if (! emit_insn (& exp, nbytes))
3734 {
3735 ignore_rest_of_line ();
3736 return;
3737 }
3738 }
3739 while (*input_line_pointer++ == ',');
3740
3741 /* Put terminator back into stream. */
3742 input_line_pointer --;
3743 demand_empty_rest_of_line ();
3744 }
3745
3746 /* Parse a .rel31 directive. */
3747
3748 static void
3749 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3750 {
3751 expressionS exp;
3752 char *p;
3753 valueT highbit;
3754
3755 highbit = 0;
3756 if (*input_line_pointer == '1')
3757 highbit = 0x80000000;
3758 else if (*input_line_pointer != '0')
3759 as_bad (_("expected 0 or 1"));
3760
3761 input_line_pointer++;
3762 if (*input_line_pointer != ',')
3763 as_bad (_("missing comma"));
3764 input_line_pointer++;
3765
3766 #ifdef md_flush_pending_output
3767 md_flush_pending_output ();
3768 #endif
3769
3770 #ifdef md_cons_align
3771 md_cons_align (4);
3772 #endif
3773
3774 mapping_state (MAP_DATA);
3775
3776 expression (&exp);
3777
3778 p = frag_more (4);
3779 md_number_to_chars (p, highbit, 4);
3780 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3781 BFD_RELOC_ARM_PREL31);
3782
3783 demand_empty_rest_of_line ();
3784 }
3785
3786 /* Directives: AEABI stack-unwind tables. */
3787
3788 /* Parse an unwind_fnstart directive. Simply records the current location. */
3789
3790 static void
3791 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3792 {
3793 demand_empty_rest_of_line ();
3794 if (unwind.proc_start)
3795 {
3796 as_bad (_("duplicate .fnstart directive"));
3797 return;
3798 }
3799
3800 /* Mark the start of the function. */
3801 unwind.proc_start = expr_build_dot ();
3802
3803 /* Reset the rest of the unwind info. */
3804 unwind.opcode_count = 0;
3805 unwind.table_entry = NULL;
3806 unwind.personality_routine = NULL;
3807 unwind.personality_index = -1;
3808 unwind.frame_size = 0;
3809 unwind.fp_offset = 0;
3810 unwind.fp_reg = REG_SP;
3811 unwind.fp_used = 0;
3812 unwind.sp_restored = 0;
3813 }
3814
3815
3816 /* Parse a handlerdata directive. Creates the exception handling table entry
3817 for the function. */
3818
3819 static void
3820 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3821 {
3822 demand_empty_rest_of_line ();
3823 if (!unwind.proc_start)
3824 as_bad (MISSING_FNSTART);
3825
3826 if (unwind.table_entry)
3827 as_bad (_("duplicate .handlerdata directive"));
3828
3829 create_unwind_entry (1);
3830 }
3831
3832 /* Parse an unwind_fnend directive. Generates the index table entry. */
3833
3834 static void
3835 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3836 {
3837 long where;
3838 char *ptr;
3839 valueT val;
3840 unsigned int marked_pr_dependency;
3841
3842 demand_empty_rest_of_line ();
3843
3844 if (!unwind.proc_start)
3845 {
3846 as_bad (_(".fnend directive without .fnstart"));
3847 return;
3848 }
3849
3850 /* Add eh table entry. */
3851 if (unwind.table_entry == NULL)
3852 val = create_unwind_entry (0);
3853 else
3854 val = 0;
3855
3856 /* Add index table entry. This is two words. */
3857 start_unwind_section (unwind.saved_seg, 1);
3858 frag_align (2, 0, 0);
3859 record_alignment (now_seg, 2);
3860
3861 ptr = frag_more (8);
3862 memset (ptr, 0, 8);
3863 where = frag_now_fix () - 8;
3864
3865 /* Self relative offset of the function start. */
3866 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3867 BFD_RELOC_ARM_PREL31);
3868
3869 /* Indicate dependency on EHABI-defined personality routines to the
3870 linker, if it hasn't been done already. */
3871 marked_pr_dependency
3872 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3873 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3874 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3875 {
3876 static const char *const name[] =
3877 {
3878 "__aeabi_unwind_cpp_pr0",
3879 "__aeabi_unwind_cpp_pr1",
3880 "__aeabi_unwind_cpp_pr2"
3881 };
3882 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3883 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3884 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3885 |= 1 << unwind.personality_index;
3886 }
3887
3888 if (val)
3889 /* Inline exception table entry. */
3890 md_number_to_chars (ptr + 4, val, 4);
3891 else
3892 /* Self relative offset of the table entry. */
3893 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3894 BFD_RELOC_ARM_PREL31);
3895
3896 /* Restore the original section. */
3897 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3898
3899 unwind.proc_start = NULL;
3900 }
3901
3902
3903 /* Parse an unwind_cantunwind directive. */
3904
3905 static void
3906 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3907 {
3908 demand_empty_rest_of_line ();
3909 if (!unwind.proc_start)
3910 as_bad (MISSING_FNSTART);
3911
3912 if (unwind.personality_routine || unwind.personality_index != -1)
3913 as_bad (_("personality routine specified for cantunwind frame"));
3914
3915 unwind.personality_index = -2;
3916 }
3917
3918
3919 /* Parse a personalityindex directive. */
3920
3921 static void
3922 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3923 {
3924 expressionS exp;
3925
3926 if (!unwind.proc_start)
3927 as_bad (MISSING_FNSTART);
3928
3929 if (unwind.personality_routine || unwind.personality_index != -1)
3930 as_bad (_("duplicate .personalityindex directive"));
3931
3932 expression (&exp);
3933
3934 if (exp.X_op != O_constant
3935 || exp.X_add_number < 0 || exp.X_add_number > 15)
3936 {
3937 as_bad (_("bad personality routine number"));
3938 ignore_rest_of_line ();
3939 return;
3940 }
3941
3942 unwind.personality_index = exp.X_add_number;
3943
3944 demand_empty_rest_of_line ();
3945 }
3946
3947
3948 /* Parse a personality directive. */
3949
3950 static void
3951 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3952 {
3953 char *name, *p, c;
3954
3955 if (!unwind.proc_start)
3956 as_bad (MISSING_FNSTART);
3957
3958 if (unwind.personality_routine || unwind.personality_index != -1)
3959 as_bad (_("duplicate .personality directive"));
3960
3961 c = get_symbol_name (& name);
3962 p = input_line_pointer;
3963 if (c == '"')
3964 ++ input_line_pointer;
3965 unwind.personality_routine = symbol_find_or_make (name);
3966 *p = c;
3967 demand_empty_rest_of_line ();
3968 }
3969
3970
3971 /* Parse a directive saving core registers. */
3972
3973 static void
3974 s_arm_unwind_save_core (void)
3975 {
3976 valueT op;
3977 long range;
3978 int n;
3979
3980 range = parse_reg_list (&input_line_pointer);
3981 if (range == FAIL)
3982 {
3983 as_bad (_("expected register list"));
3984 ignore_rest_of_line ();
3985 return;
3986 }
3987
3988 demand_empty_rest_of_line ();
3989
3990 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3991 into .unwind_save {..., sp...}. We aren't bothered about the value of
3992 ip because it is clobbered by calls. */
3993 if (unwind.sp_restored && unwind.fp_reg == 12
3994 && (range & 0x3000) == 0x1000)
3995 {
3996 unwind.opcode_count--;
3997 unwind.sp_restored = 0;
3998 range = (range | 0x2000) & ~0x1000;
3999 unwind.pending_offset = 0;
4000 }
4001
4002 /* Pop r4-r15. */
4003 if (range & 0xfff0)
4004 {
4005 /* See if we can use the short opcodes. These pop a block of up to 8
4006 registers starting with r4, plus maybe r14. */
4007 for (n = 0; n < 8; n++)
4008 {
4009 /* Break at the first non-saved register. */
4010 if ((range & (1 << (n + 4))) == 0)
4011 break;
4012 }
4013 /* See if there are any other bits set. */
4014 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
4015 {
4016 /* Use the long form. */
4017 op = 0x8000 | ((range >> 4) & 0xfff);
4018 add_unwind_opcode (op, 2);
4019 }
4020 else
4021 {
4022 /* Use the short form. */
4023 if (range & 0x4000)
4024 op = 0xa8; /* Pop r14. */
4025 else
4026 op = 0xa0; /* Do not pop r14. */
4027 op |= (n - 1);
4028 add_unwind_opcode (op, 1);
4029 }
4030 }
4031
4032 /* Pop r0-r3. */
4033 if (range & 0xf)
4034 {
4035 op = 0xb100 | (range & 0xf);
4036 add_unwind_opcode (op, 2);
4037 }
4038
4039 /* Record the number of bytes pushed. */
4040 for (n = 0; n < 16; n++)
4041 {
4042 if (range & (1 << n))
4043 unwind.frame_size += 4;
4044 }
4045 }
4046
4047
4048 /* Parse a directive saving FPA registers. */
4049
4050 static void
4051 s_arm_unwind_save_fpa (int reg)
4052 {
4053 expressionS exp;
4054 int num_regs;
4055 valueT op;
4056
4057 /* Get Number of registers to transfer. */
4058 if (skip_past_comma (&input_line_pointer) != FAIL)
4059 expression (&exp);
4060 else
4061 exp.X_op = O_illegal;
4062
4063 if (exp.X_op != O_constant)
4064 {
4065 as_bad (_("expected , <constant>"));
4066 ignore_rest_of_line ();
4067 return;
4068 }
4069
4070 num_regs = exp.X_add_number;
4071
4072 if (num_regs < 1 || num_regs > 4)
4073 {
4074 as_bad (_("number of registers must be in the range [1:4]"));
4075 ignore_rest_of_line ();
4076 return;
4077 }
4078
4079 demand_empty_rest_of_line ();
4080
4081 if (reg == 4)
4082 {
4083 /* Short form. */
4084 op = 0xb4 | (num_regs - 1);
4085 add_unwind_opcode (op, 1);
4086 }
4087 else
4088 {
4089 /* Long form. */
4090 op = 0xc800 | (reg << 4) | (num_regs - 1);
4091 add_unwind_opcode (op, 2);
4092 }
4093 unwind.frame_size += num_regs * 12;
4094 }
4095
4096
4097 /* Parse a directive saving VFP registers for ARMv6 and above. */
4098
4099 static void
4100 s_arm_unwind_save_vfp_armv6 (void)
4101 {
4102 int count;
4103 unsigned int start;
4104 valueT op;
4105 int num_vfpv3_regs = 0;
4106 int num_regs_below_16;
4107
4108 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
4109 if (count == FAIL)
4110 {
4111 as_bad (_("expected register list"));
4112 ignore_rest_of_line ();
4113 return;
4114 }
4115
4116 demand_empty_rest_of_line ();
4117
4118 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
4119 than FSTMX/FLDMX-style ones). */
4120
4121 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
4122 if (start >= 16)
4123 num_vfpv3_regs = count;
4124 else if (start + count > 16)
4125 num_vfpv3_regs = start + count - 16;
4126
4127 if (num_vfpv3_regs > 0)
4128 {
4129 int start_offset = start > 16 ? start - 16 : 0;
4130 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
4131 add_unwind_opcode (op, 2);
4132 }
4133
4134 /* Generate opcode for registers numbered in the range 0 .. 15. */
4135 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
4136 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
4137 if (num_regs_below_16 > 0)
4138 {
4139 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
4140 add_unwind_opcode (op, 2);
4141 }
4142
4143 unwind.frame_size += count * 8;
4144 }
4145
4146
4147 /* Parse a directive saving VFP registers for pre-ARMv6. */
4148
4149 static void
4150 s_arm_unwind_save_vfp (void)
4151 {
4152 int count;
4153 unsigned int reg;
4154 valueT op;
4155
4156 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
4157 if (count == FAIL)
4158 {
4159 as_bad (_("expected register list"));
4160 ignore_rest_of_line ();
4161 return;
4162 }
4163
4164 demand_empty_rest_of_line ();
4165
4166 if (reg == 8)
4167 {
4168 /* Short form. */
4169 op = 0xb8 | (count - 1);
4170 add_unwind_opcode (op, 1);
4171 }
4172 else
4173 {
4174 /* Long form. */
4175 op = 0xb300 | (reg << 4) | (count - 1);
4176 add_unwind_opcode (op, 2);
4177 }
4178 unwind.frame_size += count * 8 + 4;
4179 }
4180
4181
4182 /* Parse a directive saving iWMMXt data registers. */
4183
4184 static void
4185 s_arm_unwind_save_mmxwr (void)
4186 {
4187 int reg;
4188 int hi_reg;
4189 int i;
4190 unsigned mask = 0;
4191 valueT op;
4192
4193 if (*input_line_pointer == '{')
4194 input_line_pointer++;
4195
4196 do
4197 {
4198 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4199
4200 if (reg == FAIL)
4201 {
4202 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4203 goto error;
4204 }
4205
4206 if (mask >> reg)
4207 as_tsktsk (_("register list not in ascending order"));
4208 mask |= 1 << reg;
4209
4210 if (*input_line_pointer == '-')
4211 {
4212 input_line_pointer++;
4213 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
4214 if (hi_reg == FAIL)
4215 {
4216 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
4217 goto error;
4218 }
4219 else if (reg >= hi_reg)
4220 {
4221 as_bad (_("bad register range"));
4222 goto error;
4223 }
4224 for (; reg < hi_reg; reg++)
4225 mask |= 1 << reg;
4226 }
4227 }
4228 while (skip_past_comma (&input_line_pointer) != FAIL);
4229
4230 skip_past_char (&input_line_pointer, '}');
4231
4232 demand_empty_rest_of_line ();
4233
4234 /* Generate any deferred opcodes because we're going to be looking at
4235 the list. */
4236 flush_pending_unwind ();
4237
4238 for (i = 0; i < 16; i++)
4239 {
4240 if (mask & (1 << i))
4241 unwind.frame_size += 8;
4242 }
4243
4244 /* Attempt to combine with a previous opcode. We do this because gcc
4245 likes to output separate unwind directives for a single block of
4246 registers. */
4247 if (unwind.opcode_count > 0)
4248 {
4249 i = unwind.opcodes[unwind.opcode_count - 1];
4250 if ((i & 0xf8) == 0xc0)
4251 {
4252 i &= 7;
4253 /* Only merge if the blocks are contiguous. */
4254 if (i < 6)
4255 {
4256 if ((mask & 0xfe00) == (1 << 9))
4257 {
4258 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
4259 unwind.opcode_count--;
4260 }
4261 }
4262 else if (i == 6 && unwind.opcode_count >= 2)
4263 {
4264 i = unwind.opcodes[unwind.opcode_count - 2];
4265 reg = i >> 4;
4266 i &= 0xf;
4267
4268 op = 0xffff << (reg - 1);
4269 if (reg > 0
4270 && ((mask & op) == (1u << (reg - 1))))
4271 {
4272 op = (1 << (reg + i + 1)) - 1;
4273 op &= ~((1 << reg) - 1);
4274 mask |= op;
4275 unwind.opcode_count -= 2;
4276 }
4277 }
4278 }
4279 }
4280
4281 hi_reg = 15;
4282 /* We want to generate opcodes in the order the registers have been
4283 saved, ie. descending order. */
4284 for (reg = 15; reg >= -1; reg--)
4285 {
4286 /* Save registers in blocks. */
4287 if (reg < 0
4288 || !(mask & (1 << reg)))
4289 {
4290 /* We found an unsaved reg. Generate opcodes to save the
4291 preceding block. */
4292 if (reg != hi_reg)
4293 {
4294 if (reg == 9)
4295 {
4296 /* Short form. */
4297 op = 0xc0 | (hi_reg - 10);
4298 add_unwind_opcode (op, 1);
4299 }
4300 else
4301 {
4302 /* Long form. */
4303 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4304 add_unwind_opcode (op, 2);
4305 }
4306 }
4307 hi_reg = reg - 1;
4308 }
4309 }
4310
4311 return;
4312 error:
4313 ignore_rest_of_line ();
4314 }
4315
4316 static void
4317 s_arm_unwind_save_mmxwcg (void)
4318 {
4319 int reg;
4320 int hi_reg;
4321 unsigned mask = 0;
4322 valueT op;
4323
4324 if (*input_line_pointer == '{')
4325 input_line_pointer++;
4326
4327 skip_whitespace (input_line_pointer);
4328
4329 do
4330 {
4331 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4332
4333 if (reg == FAIL)
4334 {
4335 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4336 goto error;
4337 }
4338
4339 reg -= 8;
4340 if (mask >> reg)
4341 as_tsktsk (_("register list not in ascending order"));
4342 mask |= 1 << reg;
4343
4344 if (*input_line_pointer == '-')
4345 {
4346 input_line_pointer++;
4347 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4348 if (hi_reg == FAIL)
4349 {
4350 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4351 goto error;
4352 }
4353 else if (reg >= hi_reg)
4354 {
4355 as_bad (_("bad register range"));
4356 goto error;
4357 }
4358 for (; reg < hi_reg; reg++)
4359 mask |= 1 << reg;
4360 }
4361 }
4362 while (skip_past_comma (&input_line_pointer) != FAIL);
4363
4364 skip_past_char (&input_line_pointer, '}');
4365
4366 demand_empty_rest_of_line ();
4367
4368 /* Generate any deferred opcodes because we're going to be looking at
4369 the list. */
4370 flush_pending_unwind ();
4371
4372 for (reg = 0; reg < 16; reg++)
4373 {
4374 if (mask & (1 << reg))
4375 unwind.frame_size += 4;
4376 }
4377 op = 0xc700 | mask;
4378 add_unwind_opcode (op, 2);
4379 return;
4380 error:
4381 ignore_rest_of_line ();
4382 }
4383
4384
4385 /* Parse an unwind_save directive.
4386 If the argument is non-zero, this is a .vsave directive. */
4387
4388 static void
4389 s_arm_unwind_save (int arch_v6)
4390 {
4391 char *peek;
4392 struct reg_entry *reg;
4393 bfd_boolean had_brace = FALSE;
4394
4395 if (!unwind.proc_start)
4396 as_bad (MISSING_FNSTART);
4397
4398 /* Figure out what sort of save we have. */
4399 peek = input_line_pointer;
4400
4401 if (*peek == '{')
4402 {
4403 had_brace = TRUE;
4404 peek++;
4405 }
4406
4407 reg = arm_reg_parse_multi (&peek);
4408
4409 if (!reg)
4410 {
4411 as_bad (_("register expected"));
4412 ignore_rest_of_line ();
4413 return;
4414 }
4415
4416 switch (reg->type)
4417 {
4418 case REG_TYPE_FN:
4419 if (had_brace)
4420 {
4421 as_bad (_("FPA .unwind_save does not take a register list"));
4422 ignore_rest_of_line ();
4423 return;
4424 }
4425 input_line_pointer = peek;
4426 s_arm_unwind_save_fpa (reg->number);
4427 return;
4428
4429 case REG_TYPE_RN:
4430 s_arm_unwind_save_core ();
4431 return;
4432
4433 case REG_TYPE_VFD:
4434 if (arch_v6)
4435 s_arm_unwind_save_vfp_armv6 ();
4436 else
4437 s_arm_unwind_save_vfp ();
4438 return;
4439
4440 case REG_TYPE_MMXWR:
4441 s_arm_unwind_save_mmxwr ();
4442 return;
4443
4444 case REG_TYPE_MMXWCG:
4445 s_arm_unwind_save_mmxwcg ();
4446 return;
4447
4448 default:
4449 as_bad (_(".unwind_save does not support this kind of register"));
4450 ignore_rest_of_line ();
4451 }
4452 }
4453
4454
4455 /* Parse an unwind_movsp directive. */
4456
4457 static void
4458 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4459 {
4460 int reg;
4461 valueT op;
4462 int offset;
4463
4464 if (!unwind.proc_start)
4465 as_bad (MISSING_FNSTART);
4466
4467 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4468 if (reg == FAIL)
4469 {
4470 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4471 ignore_rest_of_line ();
4472 return;
4473 }
4474
4475 /* Optional constant. */
4476 if (skip_past_comma (&input_line_pointer) != FAIL)
4477 {
4478 if (immediate_for_directive (&offset) == FAIL)
4479 return;
4480 }
4481 else
4482 offset = 0;
4483
4484 demand_empty_rest_of_line ();
4485
4486 if (reg == REG_SP || reg == REG_PC)
4487 {
4488 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4489 return;
4490 }
4491
4492 if (unwind.fp_reg != REG_SP)
4493 as_bad (_("unexpected .unwind_movsp directive"));
4494
4495 /* Generate opcode to restore the value. */
4496 op = 0x90 | reg;
4497 add_unwind_opcode (op, 1);
4498
4499 /* Record the information for later. */
4500 unwind.fp_reg = reg;
4501 unwind.fp_offset = unwind.frame_size - offset;
4502 unwind.sp_restored = 1;
4503 }
4504
4505 /* Parse an unwind_pad directive. */
4506
4507 static void
4508 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4509 {
4510 int offset;
4511
4512 if (!unwind.proc_start)
4513 as_bad (MISSING_FNSTART);
4514
4515 if (immediate_for_directive (&offset) == FAIL)
4516 return;
4517
4518 if (offset & 3)
4519 {
4520 as_bad (_("stack increment must be multiple of 4"));
4521 ignore_rest_of_line ();
4522 return;
4523 }
4524
4525 /* Don't generate any opcodes, just record the details for later. */
4526 unwind.frame_size += offset;
4527 unwind.pending_offset += offset;
4528
4529 demand_empty_rest_of_line ();
4530 }
4531
4532 /* Parse an unwind_setfp directive. */
4533
4534 static void
4535 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4536 {
4537 int sp_reg;
4538 int fp_reg;
4539 int offset;
4540
4541 if (!unwind.proc_start)
4542 as_bad (MISSING_FNSTART);
4543
4544 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4545 if (skip_past_comma (&input_line_pointer) == FAIL)
4546 sp_reg = FAIL;
4547 else
4548 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4549
4550 if (fp_reg == FAIL || sp_reg == FAIL)
4551 {
4552 as_bad (_("expected <reg>, <reg>"));
4553 ignore_rest_of_line ();
4554 return;
4555 }
4556
4557 /* Optional constant. */
4558 if (skip_past_comma (&input_line_pointer) != FAIL)
4559 {
4560 if (immediate_for_directive (&offset) == FAIL)
4561 return;
4562 }
4563 else
4564 offset = 0;
4565
4566 demand_empty_rest_of_line ();
4567
4568 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4569 {
4570 as_bad (_("register must be either sp or set by a previous"
4571 "unwind_movsp directive"));
4572 return;
4573 }
4574
4575 /* Don't generate any opcodes, just record the information for later. */
4576 unwind.fp_reg = fp_reg;
4577 unwind.fp_used = 1;
4578 if (sp_reg == REG_SP)
4579 unwind.fp_offset = unwind.frame_size - offset;
4580 else
4581 unwind.fp_offset -= offset;
4582 }
4583
4584 /* Parse an unwind_raw directive. */
4585
4586 static void
4587 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4588 {
4589 expressionS exp;
4590 /* This is an arbitrary limit. */
4591 unsigned char op[16];
4592 int count;
4593
4594 if (!unwind.proc_start)
4595 as_bad (MISSING_FNSTART);
4596
4597 expression (&exp);
4598 if (exp.X_op == O_constant
4599 && skip_past_comma (&input_line_pointer) != FAIL)
4600 {
4601 unwind.frame_size += exp.X_add_number;
4602 expression (&exp);
4603 }
4604 else
4605 exp.X_op = O_illegal;
4606
4607 if (exp.X_op != O_constant)
4608 {
4609 as_bad (_("expected <offset>, <opcode>"));
4610 ignore_rest_of_line ();
4611 return;
4612 }
4613
4614 count = 0;
4615
4616 /* Parse the opcode. */
4617 for (;;)
4618 {
4619 if (count >= 16)
4620 {
4621 as_bad (_("unwind opcode too long"));
4622 ignore_rest_of_line ();
4623 }
4624 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4625 {
4626 as_bad (_("invalid unwind opcode"));
4627 ignore_rest_of_line ();
4628 return;
4629 }
4630 op[count++] = exp.X_add_number;
4631
4632 /* Parse the next byte. */
4633 if (skip_past_comma (&input_line_pointer) == FAIL)
4634 break;
4635
4636 expression (&exp);
4637 }
4638
4639 /* Add the opcode bytes in reverse order. */
4640 while (count--)
4641 add_unwind_opcode (op[count], 1);
4642
4643 demand_empty_rest_of_line ();
4644 }
4645
4646
4647 /* Parse a .eabi_attribute directive. */
4648
4649 static void
4650 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4651 {
4652 int tag = obj_elf_vendor_attribute (OBJ_ATTR_PROC);
4653
4654 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4655 attributes_set_explicitly[tag] = 1;
4656 }
4657
4658 /* Emit a tls fix for the symbol. */
4659
4660 static void
4661 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4662 {
4663 char *p;
4664 expressionS exp;
4665 #ifdef md_flush_pending_output
4666 md_flush_pending_output ();
4667 #endif
4668
4669 #ifdef md_cons_align
4670 md_cons_align (4);
4671 #endif
4672
4673 /* Since we're just labelling the code, there's no need to define a
4674 mapping symbol. */
4675 expression (&exp);
4676 p = obstack_next_free (&frchain_now->frch_obstack);
4677 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4678 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4679 : BFD_RELOC_ARM_TLS_DESCSEQ);
4680 }
4681 #endif /* OBJ_ELF */
4682
4683 static void s_arm_arch (int);
4684 static void s_arm_object_arch (int);
4685 static void s_arm_cpu (int);
4686 static void s_arm_fpu (int);
4687 static void s_arm_arch_extension (int);
4688
4689 #ifdef TE_PE
4690
4691 static void
4692 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4693 {
4694 expressionS exp;
4695
4696 do
4697 {
4698 expression (&exp);
4699 if (exp.X_op == O_symbol)
4700 exp.X_op = O_secrel;
4701
4702 emit_expr (&exp, 4);
4703 }
4704 while (*input_line_pointer++ == ',');
4705
4706 input_line_pointer--;
4707 demand_empty_rest_of_line ();
4708 }
4709 #endif /* TE_PE */
4710
4711 /* This table describes all the machine specific pseudo-ops the assembler
4712 has to support. The fields are:
4713 pseudo-op name without dot
4714 function to call to execute this pseudo-op
4715 Integer arg to pass to the function. */
4716
4717 const pseudo_typeS md_pseudo_table[] =
4718 {
4719 /* Never called because '.req' does not start a line. */
4720 { "req", s_req, 0 },
4721 /* Following two are likewise never called. */
4722 { "dn", s_dn, 0 },
4723 { "qn", s_qn, 0 },
4724 { "unreq", s_unreq, 0 },
4725 { "bss", s_bss, 0 },
4726 { "align", s_align_ptwo, 2 },
4727 { "arm", s_arm, 0 },
4728 { "thumb", s_thumb, 0 },
4729 { "code", s_code, 0 },
4730 { "force_thumb", s_force_thumb, 0 },
4731 { "thumb_func", s_thumb_func, 0 },
4732 { "thumb_set", s_thumb_set, 0 },
4733 { "even", s_even, 0 },
4734 { "ltorg", s_ltorg, 0 },
4735 { "pool", s_ltorg, 0 },
4736 { "syntax", s_syntax, 0 },
4737 { "cpu", s_arm_cpu, 0 },
4738 { "arch", s_arm_arch, 0 },
4739 { "object_arch", s_arm_object_arch, 0 },
4740 { "fpu", s_arm_fpu, 0 },
4741 { "arch_extension", s_arm_arch_extension, 0 },
4742 #ifdef OBJ_ELF
4743 { "word", s_arm_elf_cons, 4 },
4744 { "long", s_arm_elf_cons, 4 },
4745 { "inst.n", s_arm_elf_inst, 2 },
4746 { "inst.w", s_arm_elf_inst, 4 },
4747 { "inst", s_arm_elf_inst, 0 },
4748 { "rel31", s_arm_rel31, 0 },
4749 { "fnstart", s_arm_unwind_fnstart, 0 },
4750 { "fnend", s_arm_unwind_fnend, 0 },
4751 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4752 { "personality", s_arm_unwind_personality, 0 },
4753 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4754 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4755 { "save", s_arm_unwind_save, 0 },
4756 { "vsave", s_arm_unwind_save, 1 },
4757 { "movsp", s_arm_unwind_movsp, 0 },
4758 { "pad", s_arm_unwind_pad, 0 },
4759 { "setfp", s_arm_unwind_setfp, 0 },
4760 { "unwind_raw", s_arm_unwind_raw, 0 },
4761 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4762 { "tlsdescseq", s_arm_tls_descseq, 0 },
4763 #else
4764 { "word", cons, 4},
4765
4766 /* These are used for dwarf. */
4767 {"2byte", cons, 2},
4768 {"4byte", cons, 4},
4769 {"8byte", cons, 8},
4770 /* These are used for dwarf2. */
4771 { "file", dwarf2_directive_file, 0 },
4772 { "loc", dwarf2_directive_loc, 0 },
4773 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4774 #endif
4775 { "extend", float_cons, 'x' },
4776 { "ldouble", float_cons, 'x' },
4777 { "packed", float_cons, 'p' },
4778 #ifdef TE_PE
4779 {"secrel32", pe_directive_secrel, 0},
4780 #endif
4781
4782 /* These are for compatibility with CodeComposer Studio. */
4783 {"ref", s_ccs_ref, 0},
4784 {"def", s_ccs_def, 0},
4785 {"asmfunc", s_ccs_asmfunc, 0},
4786 {"endasmfunc", s_ccs_endasmfunc, 0},
4787
4788 { 0, 0, 0 }
4789 };
4790 \f
4791 /* Parser functions used exclusively in instruction operands. */
4792
4793 /* Generic immediate-value read function for use in insn parsing.
4794 STR points to the beginning of the immediate (the leading #);
4795 VAL receives the value; if the value is outside [MIN, MAX]
4796 issue an error. PREFIX_OPT is true if the immediate prefix is
4797 optional. */
4798
4799 static int
4800 parse_immediate (char **str, int *val, int min, int max,
4801 bfd_boolean prefix_opt)
4802 {
4803 expressionS exp;
4804
4805 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4806 if (exp.X_op != O_constant)
4807 {
4808 inst.error = _("constant expression required");
4809 return FAIL;
4810 }
4811
4812 if (exp.X_add_number < min || exp.X_add_number > max)
4813 {
4814 inst.error = _("immediate value out of range");
4815 return FAIL;
4816 }
4817
4818 *val = exp.X_add_number;
4819 return SUCCESS;
4820 }
4821
4822 /* Less-generic immediate-value read function with the possibility of loading a
4823 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4824 instructions. Puts the result directly in inst.operands[i]. */
4825
4826 static int
4827 parse_big_immediate (char **str, int i, expressionS *in_exp,
4828 bfd_boolean allow_symbol_p)
4829 {
4830 expressionS exp;
4831 expressionS *exp_p = in_exp ? in_exp : &exp;
4832 char *ptr = *str;
4833
4834 my_get_expression (exp_p, &ptr, GE_OPT_PREFIX_BIG);
4835
4836 if (exp_p->X_op == O_constant)
4837 {
4838 inst.operands[i].imm = exp_p->X_add_number & 0xffffffff;
4839 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4840 O_constant. We have to be careful not to break compilation for
4841 32-bit X_add_number, though. */
4842 if ((exp_p->X_add_number & ~(offsetT)(0xffffffffU)) != 0)
4843 {
4844 /* X >> 32 is illegal if sizeof (exp_p->X_add_number) == 4. */
4845 inst.operands[i].reg = (((exp_p->X_add_number >> 16) >> 16)
4846 & 0xffffffff);
4847 inst.operands[i].regisimm = 1;
4848 }
4849 }
4850 else if (exp_p->X_op == O_big
4851 && LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 32)
4852 {
4853 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4854
4855 /* Bignums have their least significant bits in
4856 generic_bignum[0]. Make sure we put 32 bits in imm and
4857 32 bits in reg, in a (hopefully) portable way. */
4858 gas_assert (parts != 0);
4859
4860 /* Make sure that the number is not too big.
4861 PR 11972: Bignums can now be sign-extended to the
4862 size of a .octa so check that the out of range bits
4863 are all zero or all one. */
4864 if (LITTLENUM_NUMBER_OF_BITS * exp_p->X_add_number > 64)
4865 {
4866 LITTLENUM_TYPE m = -1;
4867
4868 if (generic_bignum[parts * 2] != 0
4869 && generic_bignum[parts * 2] != m)
4870 return FAIL;
4871
4872 for (j = parts * 2 + 1; j < (unsigned) exp_p->X_add_number; j++)
4873 if (generic_bignum[j] != generic_bignum[j-1])
4874 return FAIL;
4875 }
4876
4877 inst.operands[i].imm = 0;
4878 for (j = 0; j < parts; j++, idx++)
4879 inst.operands[i].imm |= generic_bignum[idx]
4880 << (LITTLENUM_NUMBER_OF_BITS * j);
4881 inst.operands[i].reg = 0;
4882 for (j = 0; j < parts; j++, idx++)
4883 inst.operands[i].reg |= generic_bignum[idx]
4884 << (LITTLENUM_NUMBER_OF_BITS * j);
4885 inst.operands[i].regisimm = 1;
4886 }
4887 else if (!(exp_p->X_op == O_symbol && allow_symbol_p))
4888 return FAIL;
4889
4890 *str = ptr;
4891
4892 return SUCCESS;
4893 }
4894
4895 /* Returns the pseudo-register number of an FPA immediate constant,
4896 or FAIL if there isn't a valid constant here. */
4897
4898 static int
4899 parse_fpa_immediate (char ** str)
4900 {
4901 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4902 char * save_in;
4903 expressionS exp;
4904 int i;
4905 int j;
4906
4907 /* First try and match exact strings, this is to guarantee
4908 that some formats will work even for cross assembly. */
4909
4910 for (i = 0; fp_const[i]; i++)
4911 {
4912 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4913 {
4914 char *start = *str;
4915
4916 *str += strlen (fp_const[i]);
4917 if (is_end_of_line[(unsigned char) **str])
4918 return i + 8;
4919 *str = start;
4920 }
4921 }
4922
4923 /* Just because we didn't get a match doesn't mean that the constant
4924 isn't valid, just that it is in a format that we don't
4925 automatically recognize. Try parsing it with the standard
4926 expression routines. */
4927
4928 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4929
4930 /* Look for a raw floating point number. */
4931 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4932 && is_end_of_line[(unsigned char) *save_in])
4933 {
4934 for (i = 0; i < NUM_FLOAT_VALS; i++)
4935 {
4936 for (j = 0; j < MAX_LITTLENUMS; j++)
4937 {
4938 if (words[j] != fp_values[i][j])
4939 break;
4940 }
4941
4942 if (j == MAX_LITTLENUMS)
4943 {
4944 *str = save_in;
4945 return i + 8;
4946 }
4947 }
4948 }
4949
4950 /* Try and parse a more complex expression, this will probably fail
4951 unless the code uses a floating point prefix (eg "0f"). */
4952 save_in = input_line_pointer;
4953 input_line_pointer = *str;
4954 if (expression (&exp) == absolute_section
4955 && exp.X_op == O_big
4956 && exp.X_add_number < 0)
4957 {
4958 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4959 Ditto for 15. */
4960 #define X_PRECISION 5
4961 #define E_PRECISION 15L
4962 if (gen_to_words (words, X_PRECISION, E_PRECISION) == 0)
4963 {
4964 for (i = 0; i < NUM_FLOAT_VALS; i++)
4965 {
4966 for (j = 0; j < MAX_LITTLENUMS; j++)
4967 {
4968 if (words[j] != fp_values[i][j])
4969 break;
4970 }
4971
4972 if (j == MAX_LITTLENUMS)
4973 {
4974 *str = input_line_pointer;
4975 input_line_pointer = save_in;
4976 return i + 8;
4977 }
4978 }
4979 }
4980 }
4981
4982 *str = input_line_pointer;
4983 input_line_pointer = save_in;
4984 inst.error = _("invalid FPA immediate expression");
4985 return FAIL;
4986 }
4987
4988 /* Returns 1 if a number has "quarter-precision" float format
4989 0baBbbbbbc defgh000 00000000 00000000. */
4990
4991 static int
4992 is_quarter_float (unsigned imm)
4993 {
4994 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4995 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4996 }
4997
4998
4999 /* Detect the presence of a floating point or integer zero constant,
5000 i.e. #0.0 or #0. */
5001
5002 static bfd_boolean
5003 parse_ifimm_zero (char **in)
5004 {
5005 int error_code;
5006
5007 if (!is_immediate_prefix (**in))
5008 {
5009 /* In unified syntax, all prefixes are optional. */
5010 if (!unified_syntax)
5011 return FALSE;
5012 }
5013 else
5014 ++*in;
5015
5016 /* Accept #0x0 as a synonym for #0. */
5017 if (strncmp (*in, "0x", 2) == 0)
5018 {
5019 int val;
5020 if (parse_immediate (in, &val, 0, 0, TRUE) == FAIL)
5021 return FALSE;
5022 return TRUE;
5023 }
5024
5025 error_code = atof_generic (in, ".", EXP_CHARS,
5026 &generic_floating_point_number);
5027
5028 if (!error_code
5029 && generic_floating_point_number.sign == '+'
5030 && (generic_floating_point_number.low
5031 > generic_floating_point_number.leader))
5032 return TRUE;
5033
5034 return FALSE;
5035 }
5036
5037 /* Parse an 8-bit "quarter-precision" floating point number of the form:
5038 0baBbbbbbc defgh000 00000000 00000000.
5039 The zero and minus-zero cases need special handling, since they can't be
5040 encoded in the "quarter-precision" float format, but can nonetheless be
5041 loaded as integer constants. */
5042
5043 static unsigned
5044 parse_qfloat_immediate (char **ccp, int *immed)
5045 {
5046 char *str = *ccp;
5047 char *fpnum;
5048 LITTLENUM_TYPE words[MAX_LITTLENUMS];
5049 int found_fpchar = 0;
5050
5051 skip_past_char (&str, '#');
5052
5053 /* We must not accidentally parse an integer as a floating-point number. Make
5054 sure that the value we parse is not an integer by checking for special
5055 characters '.' or 'e'.
5056 FIXME: This is a horrible hack, but doing better is tricky because type
5057 information isn't in a very usable state at parse time. */
5058 fpnum = str;
5059 skip_whitespace (fpnum);
5060
5061 if (strncmp (fpnum, "0x", 2) == 0)
5062 return FAIL;
5063 else
5064 {
5065 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
5066 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
5067 {
5068 found_fpchar = 1;
5069 break;
5070 }
5071
5072 if (!found_fpchar)
5073 return FAIL;
5074 }
5075
5076 if ((str = atof_ieee (str, 's', words)) != NULL)
5077 {
5078 unsigned fpword = 0;
5079 int i;
5080
5081 /* Our FP word must be 32 bits (single-precision FP). */
5082 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
5083 {
5084 fpword <<= LITTLENUM_NUMBER_OF_BITS;
5085 fpword |= words[i];
5086 }
5087
5088 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
5089 *immed = fpword;
5090 else
5091 return FAIL;
5092
5093 *ccp = str;
5094
5095 return SUCCESS;
5096 }
5097
5098 return FAIL;
5099 }
5100
5101 /* Shift operands. */
5102 enum shift_kind
5103 {
5104 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
5105 };
5106
5107 struct asm_shift_name
5108 {
5109 const char *name;
5110 enum shift_kind kind;
5111 };
5112
5113 /* Third argument to parse_shift. */
5114 enum parse_shift_mode
5115 {
5116 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
5117 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
5118 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
5119 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
5120 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
5121 };
5122
5123 /* Parse a <shift> specifier on an ARM data processing instruction.
5124 This has three forms:
5125
5126 (LSL|LSR|ASL|ASR|ROR) Rs
5127 (LSL|LSR|ASL|ASR|ROR) #imm
5128 RRX
5129
5130 Note that ASL is assimilated to LSL in the instruction encoding, and
5131 RRX to ROR #0 (which cannot be written as such). */
5132
5133 static int
5134 parse_shift (char **str, int i, enum parse_shift_mode mode)
5135 {
5136 const struct asm_shift_name *shift_name;
5137 enum shift_kind shift;
5138 char *s = *str;
5139 char *p = s;
5140 int reg;
5141
5142 for (p = *str; ISALPHA (*p); p++)
5143 ;
5144
5145 if (p == *str)
5146 {
5147 inst.error = _("shift expression expected");
5148 return FAIL;
5149 }
5150
5151 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
5152 p - *str);
5153
5154 if (shift_name == NULL)
5155 {
5156 inst.error = _("shift expression expected");
5157 return FAIL;
5158 }
5159
5160 shift = shift_name->kind;
5161
5162 switch (mode)
5163 {
5164 case NO_SHIFT_RESTRICT:
5165 case SHIFT_IMMEDIATE: break;
5166
5167 case SHIFT_LSL_OR_ASR_IMMEDIATE:
5168 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
5169 {
5170 inst.error = _("'LSL' or 'ASR' required");
5171 return FAIL;
5172 }
5173 break;
5174
5175 case SHIFT_LSL_IMMEDIATE:
5176 if (shift != SHIFT_LSL)
5177 {
5178 inst.error = _("'LSL' required");
5179 return FAIL;
5180 }
5181 break;
5182
5183 case SHIFT_ASR_IMMEDIATE:
5184 if (shift != SHIFT_ASR)
5185 {
5186 inst.error = _("'ASR' required");
5187 return FAIL;
5188 }
5189 break;
5190
5191 default: abort ();
5192 }
5193
5194 if (shift != SHIFT_RRX)
5195 {
5196 /* Whitespace can appear here if the next thing is a bare digit. */
5197 skip_whitespace (p);
5198
5199 if (mode == NO_SHIFT_RESTRICT
5200 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5201 {
5202 inst.operands[i].imm = reg;
5203 inst.operands[i].immisreg = 1;
5204 }
5205 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5206 return FAIL;
5207 }
5208 inst.operands[i].shift_kind = shift;
5209 inst.operands[i].shifted = 1;
5210 *str = p;
5211 return SUCCESS;
5212 }
5213
5214 /* Parse a <shifter_operand> for an ARM data processing instruction:
5215
5216 #<immediate>
5217 #<immediate>, <rotate>
5218 <Rm>
5219 <Rm>, <shift>
5220
5221 where <shift> is defined by parse_shift above, and <rotate> is a
5222 multiple of 2 between 0 and 30. Validation of immediate operands
5223 is deferred to md_apply_fix. */
5224
5225 static int
5226 parse_shifter_operand (char **str, int i)
5227 {
5228 int value;
5229 expressionS exp;
5230
5231 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
5232 {
5233 inst.operands[i].reg = value;
5234 inst.operands[i].isreg = 1;
5235
5236 /* parse_shift will override this if appropriate */
5237 inst.reloc.exp.X_op = O_constant;
5238 inst.reloc.exp.X_add_number = 0;
5239
5240 if (skip_past_comma (str) == FAIL)
5241 return SUCCESS;
5242
5243 /* Shift operation on register. */
5244 return parse_shift (str, i, NO_SHIFT_RESTRICT);
5245 }
5246
5247 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
5248 return FAIL;
5249
5250 if (skip_past_comma (str) == SUCCESS)
5251 {
5252 /* #x, y -- ie explicit rotation by Y. */
5253 if (my_get_expression (&exp, str, GE_NO_PREFIX))
5254 return FAIL;
5255
5256 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
5257 {
5258 inst.error = _("constant expression expected");
5259 return FAIL;
5260 }
5261
5262 value = exp.X_add_number;
5263 if (value < 0 || value > 30 || value % 2 != 0)
5264 {
5265 inst.error = _("invalid rotation");
5266 return FAIL;
5267 }
5268 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
5269 {
5270 inst.error = _("invalid constant");
5271 return FAIL;
5272 }
5273
5274 /* Encode as specified. */
5275 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
5276 return SUCCESS;
5277 }
5278
5279 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
5280 inst.reloc.pc_rel = 0;
5281 return SUCCESS;
5282 }
5283
5284 /* Group relocation information. Each entry in the table contains the
5285 textual name of the relocation as may appear in assembler source
5286 and must end with a colon.
5287 Along with this textual name are the relocation codes to be used if
5288 the corresponding instruction is an ALU instruction (ADD or SUB only),
5289 an LDR, an LDRS, or an LDC. */
5290
5291 struct group_reloc_table_entry
5292 {
5293 const char *name;
5294 int alu_code;
5295 int ldr_code;
5296 int ldrs_code;
5297 int ldc_code;
5298 };
5299
5300 typedef enum
5301 {
5302 /* Varieties of non-ALU group relocation. */
5303
5304 GROUP_LDR,
5305 GROUP_LDRS,
5306 GROUP_LDC
5307 } group_reloc_type;
5308
5309 static struct group_reloc_table_entry group_reloc_table[] =
5310 { /* Program counter relative: */
5311 { "pc_g0_nc",
5312 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
5313 0, /* LDR */
5314 0, /* LDRS */
5315 0 }, /* LDC */
5316 { "pc_g0",
5317 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
5318 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
5319 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
5320 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
5321 { "pc_g1_nc",
5322 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
5323 0, /* LDR */
5324 0, /* LDRS */
5325 0 }, /* LDC */
5326 { "pc_g1",
5327 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
5328 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
5329 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
5330 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
5331 { "pc_g2",
5332 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
5333 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
5334 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
5335 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
5336 /* Section base relative */
5337 { "sb_g0_nc",
5338 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
5339 0, /* LDR */
5340 0, /* LDRS */
5341 0 }, /* LDC */
5342 { "sb_g0",
5343 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
5344 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
5345 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
5346 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
5347 { "sb_g1_nc",
5348 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
5349 0, /* LDR */
5350 0, /* LDRS */
5351 0 }, /* LDC */
5352 { "sb_g1",
5353 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
5354 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
5355 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
5356 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
5357 { "sb_g2",
5358 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
5359 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
5360 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
5361 BFD_RELOC_ARM_LDC_SB_G2 }, /* LDC */
5362 /* Absolute thumb alu relocations. */
5363 { "lower0_7",
5364 BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC,/* ALU. */
5365 0, /* LDR. */
5366 0, /* LDRS. */
5367 0 }, /* LDC. */
5368 { "lower8_15",
5369 BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC,/* ALU. */
5370 0, /* LDR. */
5371 0, /* LDRS. */
5372 0 }, /* LDC. */
5373 { "upper0_7",
5374 BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC,/* ALU. */
5375 0, /* LDR. */
5376 0, /* LDRS. */
5377 0 }, /* LDC. */
5378 { "upper8_15",
5379 BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC,/* ALU. */
5380 0, /* LDR. */
5381 0, /* LDRS. */
5382 0 } }; /* LDC. */
5383
5384 /* Given the address of a pointer pointing to the textual name of a group
5385 relocation as may appear in assembler source, attempt to find its details
5386 in group_reloc_table. The pointer will be updated to the character after
5387 the trailing colon. On failure, FAIL will be returned; SUCCESS
5388 otherwise. On success, *entry will be updated to point at the relevant
5389 group_reloc_table entry. */
5390
5391 static int
5392 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5393 {
5394 unsigned int i;
5395 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5396 {
5397 int length = strlen (group_reloc_table[i].name);
5398
5399 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5400 && (*str)[length] == ':')
5401 {
5402 *out = &group_reloc_table[i];
5403 *str += (length + 1);
5404 return SUCCESS;
5405 }
5406 }
5407
5408 return FAIL;
5409 }
5410
5411 /* Parse a <shifter_operand> for an ARM data processing instruction
5412 (as for parse_shifter_operand) where group relocations are allowed:
5413
5414 #<immediate>
5415 #<immediate>, <rotate>
5416 #:<group_reloc>:<expression>
5417 <Rm>
5418 <Rm>, <shift>
5419
5420 where <group_reloc> is one of the strings defined in group_reloc_table.
5421 The hashes are optional.
5422
5423 Everything else is as for parse_shifter_operand. */
5424
5425 static parse_operand_result
5426 parse_shifter_operand_group_reloc (char **str, int i)
5427 {
5428 /* Determine if we have the sequence of characters #: or just :
5429 coming next. If we do, then we check for a group relocation.
5430 If we don't, punt the whole lot to parse_shifter_operand. */
5431
5432 if (((*str)[0] == '#' && (*str)[1] == ':')
5433 || (*str)[0] == ':')
5434 {
5435 struct group_reloc_table_entry *entry;
5436
5437 if ((*str)[0] == '#')
5438 (*str) += 2;
5439 else
5440 (*str)++;
5441
5442 /* Try to parse a group relocation. Anything else is an error. */
5443 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5444 {
5445 inst.error = _("unknown group relocation");
5446 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5447 }
5448
5449 /* We now have the group relocation table entry corresponding to
5450 the name in the assembler source. Next, we parse the expression. */
5451 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5452 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5453
5454 /* Record the relocation type (always the ALU variant here). */
5455 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
5456 gas_assert (inst.reloc.type != 0);
5457
5458 return PARSE_OPERAND_SUCCESS;
5459 }
5460 else
5461 return parse_shifter_operand (str, i) == SUCCESS
5462 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5463
5464 /* Never reached. */
5465 }
5466
5467 /* Parse a Neon alignment expression. Information is written to
5468 inst.operands[i]. We assume the initial ':' has been skipped.
5469
5470 align .imm = align << 8, .immisalign=1, .preind=0 */
5471 static parse_operand_result
5472 parse_neon_alignment (char **str, int i)
5473 {
5474 char *p = *str;
5475 expressionS exp;
5476
5477 my_get_expression (&exp, &p, GE_NO_PREFIX);
5478
5479 if (exp.X_op != O_constant)
5480 {
5481 inst.error = _("alignment must be constant");
5482 return PARSE_OPERAND_FAIL;
5483 }
5484
5485 inst.operands[i].imm = exp.X_add_number << 8;
5486 inst.operands[i].immisalign = 1;
5487 /* Alignments are not pre-indexes. */
5488 inst.operands[i].preind = 0;
5489
5490 *str = p;
5491 return PARSE_OPERAND_SUCCESS;
5492 }
5493
5494 /* Parse all forms of an ARM address expression. Information is written
5495 to inst.operands[i] and/or inst.reloc.
5496
5497 Preindexed addressing (.preind=1):
5498
5499 [Rn, #offset] .reg=Rn .reloc.exp=offset
5500 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5501 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5502 .shift_kind=shift .reloc.exp=shift_imm
5503
5504 These three may have a trailing ! which causes .writeback to be set also.
5505
5506 Postindexed addressing (.postind=1, .writeback=1):
5507
5508 [Rn], #offset .reg=Rn .reloc.exp=offset
5509 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5510 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5511 .shift_kind=shift .reloc.exp=shift_imm
5512
5513 Unindexed addressing (.preind=0, .postind=0):
5514
5515 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5516
5517 Other:
5518
5519 [Rn]{!} shorthand for [Rn,#0]{!}
5520 =immediate .isreg=0 .reloc.exp=immediate
5521 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5522
5523 It is the caller's responsibility to check for addressing modes not
5524 supported by the instruction, and to set inst.reloc.type. */
5525
5526 static parse_operand_result
5527 parse_address_main (char **str, int i, int group_relocations,
5528 group_reloc_type group_type)
5529 {
5530 char *p = *str;
5531 int reg;
5532
5533 if (skip_past_char (&p, '[') == FAIL)
5534 {
5535 if (skip_past_char (&p, '=') == FAIL)
5536 {
5537 /* Bare address - translate to PC-relative offset. */
5538 inst.reloc.pc_rel = 1;
5539 inst.operands[i].reg = REG_PC;
5540 inst.operands[i].isreg = 1;
5541 inst.operands[i].preind = 1;
5542
5543 if (my_get_expression (&inst.reloc.exp, &p, GE_OPT_PREFIX_BIG))
5544 return PARSE_OPERAND_FAIL;
5545 }
5546 else if (parse_big_immediate (&p, i, &inst.reloc.exp,
5547 /*allow_symbol_p=*/TRUE))
5548 return PARSE_OPERAND_FAIL;
5549
5550 *str = p;
5551 return PARSE_OPERAND_SUCCESS;
5552 }
5553
5554 /* PR gas/14887: Allow for whitespace after the opening bracket. */
5555 skip_whitespace (p);
5556
5557 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5558 {
5559 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5560 return PARSE_OPERAND_FAIL;
5561 }
5562 inst.operands[i].reg = reg;
5563 inst.operands[i].isreg = 1;
5564
5565 if (skip_past_comma (&p) == SUCCESS)
5566 {
5567 inst.operands[i].preind = 1;
5568
5569 if (*p == '+') p++;
5570 else if (*p == '-') p++, inst.operands[i].negative = 1;
5571
5572 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5573 {
5574 inst.operands[i].imm = reg;
5575 inst.operands[i].immisreg = 1;
5576
5577 if (skip_past_comma (&p) == SUCCESS)
5578 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5579 return PARSE_OPERAND_FAIL;
5580 }
5581 else if (skip_past_char (&p, ':') == SUCCESS)
5582 {
5583 /* FIXME: '@' should be used here, but it's filtered out by generic
5584 code before we get to see it here. This may be subject to
5585 change. */
5586 parse_operand_result result = parse_neon_alignment (&p, i);
5587
5588 if (result != PARSE_OPERAND_SUCCESS)
5589 return result;
5590 }
5591 else
5592 {
5593 if (inst.operands[i].negative)
5594 {
5595 inst.operands[i].negative = 0;
5596 p--;
5597 }
5598
5599 if (group_relocations
5600 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5601 {
5602 struct group_reloc_table_entry *entry;
5603
5604 /* Skip over the #: or : sequence. */
5605 if (*p == '#')
5606 p += 2;
5607 else
5608 p++;
5609
5610 /* Try to parse a group relocation. Anything else is an
5611 error. */
5612 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5613 {
5614 inst.error = _("unknown group relocation");
5615 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5616 }
5617
5618 /* We now have the group relocation table entry corresponding to
5619 the name in the assembler source. Next, we parse the
5620 expression. */
5621 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5622 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5623
5624 /* Record the relocation type. */
5625 switch (group_type)
5626 {
5627 case GROUP_LDR:
5628 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5629 break;
5630
5631 case GROUP_LDRS:
5632 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5633 break;
5634
5635 case GROUP_LDC:
5636 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5637 break;
5638
5639 default:
5640 gas_assert (0);
5641 }
5642
5643 if (inst.reloc.type == 0)
5644 {
5645 inst.error = _("this group relocation is not allowed on this instruction");
5646 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5647 }
5648 }
5649 else
5650 {
5651 char *q = p;
5652
5653 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5654 return PARSE_OPERAND_FAIL;
5655 /* If the offset is 0, find out if it's a +0 or -0. */
5656 if (inst.reloc.exp.X_op == O_constant
5657 && inst.reloc.exp.X_add_number == 0)
5658 {
5659 skip_whitespace (q);
5660 if (*q == '#')
5661 {
5662 q++;
5663 skip_whitespace (q);
5664 }
5665 if (*q == '-')
5666 inst.operands[i].negative = 1;
5667 }
5668 }
5669 }
5670 }
5671 else if (skip_past_char (&p, ':') == SUCCESS)
5672 {
5673 /* FIXME: '@' should be used here, but it's filtered out by generic code
5674 before we get to see it here. This may be subject to change. */
5675 parse_operand_result result = parse_neon_alignment (&p, i);
5676
5677 if (result != PARSE_OPERAND_SUCCESS)
5678 return result;
5679 }
5680
5681 if (skip_past_char (&p, ']') == FAIL)
5682 {
5683 inst.error = _("']' expected");
5684 return PARSE_OPERAND_FAIL;
5685 }
5686
5687 if (skip_past_char (&p, '!') == SUCCESS)
5688 inst.operands[i].writeback = 1;
5689
5690 else if (skip_past_comma (&p) == SUCCESS)
5691 {
5692 if (skip_past_char (&p, '{') == SUCCESS)
5693 {
5694 /* [Rn], {expr} - unindexed, with option */
5695 if (parse_immediate (&p, &inst.operands[i].imm,
5696 0, 255, TRUE) == FAIL)
5697 return PARSE_OPERAND_FAIL;
5698
5699 if (skip_past_char (&p, '}') == FAIL)
5700 {
5701 inst.error = _("'}' expected at end of 'option' field");
5702 return PARSE_OPERAND_FAIL;
5703 }
5704 if (inst.operands[i].preind)
5705 {
5706 inst.error = _("cannot combine index with option");
5707 return PARSE_OPERAND_FAIL;
5708 }
5709 *str = p;
5710 return PARSE_OPERAND_SUCCESS;
5711 }
5712 else
5713 {
5714 inst.operands[i].postind = 1;
5715 inst.operands[i].writeback = 1;
5716
5717 if (inst.operands[i].preind)
5718 {
5719 inst.error = _("cannot combine pre- and post-indexing");
5720 return PARSE_OPERAND_FAIL;
5721 }
5722
5723 if (*p == '+') p++;
5724 else if (*p == '-') p++, inst.operands[i].negative = 1;
5725
5726 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5727 {
5728 /* We might be using the immediate for alignment already. If we
5729 are, OR the register number into the low-order bits. */
5730 if (inst.operands[i].immisalign)
5731 inst.operands[i].imm |= reg;
5732 else
5733 inst.operands[i].imm = reg;
5734 inst.operands[i].immisreg = 1;
5735
5736 if (skip_past_comma (&p) == SUCCESS)
5737 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5738 return PARSE_OPERAND_FAIL;
5739 }
5740 else
5741 {
5742 char *q = p;
5743
5744 if (inst.operands[i].negative)
5745 {
5746 inst.operands[i].negative = 0;
5747 p--;
5748 }
5749 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5750 return PARSE_OPERAND_FAIL;
5751 /* If the offset is 0, find out if it's a +0 or -0. */
5752 if (inst.reloc.exp.X_op == O_constant
5753 && inst.reloc.exp.X_add_number == 0)
5754 {
5755 skip_whitespace (q);
5756 if (*q == '#')
5757 {
5758 q++;
5759 skip_whitespace (q);
5760 }
5761 if (*q == '-')
5762 inst.operands[i].negative = 1;
5763 }
5764 }
5765 }
5766 }
5767
5768 /* If at this point neither .preind nor .postind is set, we have a
5769 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5770 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5771 {
5772 inst.operands[i].preind = 1;
5773 inst.reloc.exp.X_op = O_constant;
5774 inst.reloc.exp.X_add_number = 0;
5775 }
5776 *str = p;
5777 return PARSE_OPERAND_SUCCESS;
5778 }
5779
5780 static int
5781 parse_address (char **str, int i)
5782 {
5783 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5784 ? SUCCESS : FAIL;
5785 }
5786
5787 static parse_operand_result
5788 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5789 {
5790 return parse_address_main (str, i, 1, type);
5791 }
5792
5793 /* Parse an operand for a MOVW or MOVT instruction. */
5794 static int
5795 parse_half (char **str)
5796 {
5797 char * p;
5798
5799 p = *str;
5800 skip_past_char (&p, '#');
5801 if (strncasecmp (p, ":lower16:", 9) == 0)
5802 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5803 else if (strncasecmp (p, ":upper16:", 9) == 0)
5804 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5805
5806 if (inst.reloc.type != BFD_RELOC_UNUSED)
5807 {
5808 p += 9;
5809 skip_whitespace (p);
5810 }
5811
5812 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5813 return FAIL;
5814
5815 if (inst.reloc.type == BFD_RELOC_UNUSED)
5816 {
5817 if (inst.reloc.exp.X_op != O_constant)
5818 {
5819 inst.error = _("constant expression expected");
5820 return FAIL;
5821 }
5822 if (inst.reloc.exp.X_add_number < 0
5823 || inst.reloc.exp.X_add_number > 0xffff)
5824 {
5825 inst.error = _("immediate value out of range");
5826 return FAIL;
5827 }
5828 }
5829 *str = p;
5830 return SUCCESS;
5831 }
5832
5833 /* Miscellaneous. */
5834
5835 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5836 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5837 static int
5838 parse_psr (char **str, bfd_boolean lhs)
5839 {
5840 char *p;
5841 unsigned long psr_field;
5842 const struct asm_psr *psr;
5843 char *start;
5844 bfd_boolean is_apsr = FALSE;
5845 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
5846
5847 /* PR gas/12698: If the user has specified -march=all then m_profile will
5848 be TRUE, but we want to ignore it in this case as we are building for any
5849 CPU type, including non-m variants. */
5850 if (ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any))
5851 m_profile = FALSE;
5852
5853 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5854 feature for ease of use and backwards compatibility. */
5855 p = *str;
5856 if (strncasecmp (p, "SPSR", 4) == 0)
5857 {
5858 if (m_profile)
5859 goto unsupported_psr;
5860
5861 psr_field = SPSR_BIT;
5862 }
5863 else if (strncasecmp (p, "CPSR", 4) == 0)
5864 {
5865 if (m_profile)
5866 goto unsupported_psr;
5867
5868 psr_field = 0;
5869 }
5870 else if (strncasecmp (p, "APSR", 4) == 0)
5871 {
5872 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5873 and ARMv7-R architecture CPUs. */
5874 is_apsr = TRUE;
5875 psr_field = 0;
5876 }
5877 else if (m_profile)
5878 {
5879 start = p;
5880 do
5881 p++;
5882 while (ISALNUM (*p) || *p == '_');
5883
5884 if (strncasecmp (start, "iapsr", 5) == 0
5885 || strncasecmp (start, "eapsr", 5) == 0
5886 || strncasecmp (start, "xpsr", 4) == 0
5887 || strncasecmp (start, "psr", 3) == 0)
5888 p = start + strcspn (start, "rR") + 1;
5889
5890 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5891 p - start);
5892
5893 if (!psr)
5894 return FAIL;
5895
5896 /* If APSR is being written, a bitfield may be specified. Note that
5897 APSR itself is handled above. */
5898 if (psr->field <= 3)
5899 {
5900 psr_field = psr->field;
5901 is_apsr = TRUE;
5902 goto check_suffix;
5903 }
5904
5905 *str = p;
5906 /* M-profile MSR instructions have the mask field set to "10", except
5907 *PSR variants which modify APSR, which may use a different mask (and
5908 have been handled already). Do that by setting the PSR_f field
5909 here. */
5910 return psr->field | (lhs ? PSR_f : 0);
5911 }
5912 else
5913 goto unsupported_psr;
5914
5915 p += 4;
5916 check_suffix:
5917 if (*p == '_')
5918 {
5919 /* A suffix follows. */
5920 p++;
5921 start = p;
5922
5923 do
5924 p++;
5925 while (ISALNUM (*p) || *p == '_');
5926
5927 if (is_apsr)
5928 {
5929 /* APSR uses a notation for bits, rather than fields. */
5930 unsigned int nzcvq_bits = 0;
5931 unsigned int g_bit = 0;
5932 char *bit;
5933
5934 for (bit = start; bit != p; bit++)
5935 {
5936 switch (TOLOWER (*bit))
5937 {
5938 case 'n':
5939 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5940 break;
5941
5942 case 'z':
5943 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5944 break;
5945
5946 case 'c':
5947 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5948 break;
5949
5950 case 'v':
5951 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5952 break;
5953
5954 case 'q':
5955 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5956 break;
5957
5958 case 'g':
5959 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5960 break;
5961
5962 default:
5963 inst.error = _("unexpected bit specified after APSR");
5964 return FAIL;
5965 }
5966 }
5967
5968 if (nzcvq_bits == 0x1f)
5969 psr_field |= PSR_f;
5970
5971 if (g_bit == 0x1)
5972 {
5973 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5974 {
5975 inst.error = _("selected processor does not "
5976 "support DSP extension");
5977 return FAIL;
5978 }
5979
5980 psr_field |= PSR_s;
5981 }
5982
5983 if ((nzcvq_bits & 0x20) != 0
5984 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5985 || (g_bit & 0x2) != 0)
5986 {
5987 inst.error = _("bad bitmask specified after APSR");
5988 return FAIL;
5989 }
5990 }
5991 else
5992 {
5993 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5994 p - start);
5995 if (!psr)
5996 goto error;
5997
5998 psr_field |= psr->field;
5999 }
6000 }
6001 else
6002 {
6003 if (ISALNUM (*p))
6004 goto error; /* Garbage after "[CS]PSR". */
6005
6006 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
6007 is deprecated, but allow it anyway. */
6008 if (is_apsr && lhs)
6009 {
6010 psr_field |= PSR_f;
6011 as_tsktsk (_("writing to APSR without specifying a bitmask is "
6012 "deprecated"));
6013 }
6014 else if (!m_profile)
6015 /* These bits are never right for M-profile devices: don't set them
6016 (only code paths which read/write APSR reach here). */
6017 psr_field |= (PSR_c | PSR_f);
6018 }
6019 *str = p;
6020 return psr_field;
6021
6022 unsupported_psr:
6023 inst.error = _("selected processor does not support requested special "
6024 "purpose register");
6025 return FAIL;
6026
6027 error:
6028 inst.error = _("flag for {c}psr instruction expected");
6029 return FAIL;
6030 }
6031
6032 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
6033 value suitable for splatting into the AIF field of the instruction. */
6034
6035 static int
6036 parse_cps_flags (char **str)
6037 {
6038 int val = 0;
6039 int saw_a_flag = 0;
6040 char *s = *str;
6041
6042 for (;;)
6043 switch (*s++)
6044 {
6045 case '\0': case ',':
6046 goto done;
6047
6048 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
6049 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
6050 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
6051
6052 default:
6053 inst.error = _("unrecognized CPS flag");
6054 return FAIL;
6055 }
6056
6057 done:
6058 if (saw_a_flag == 0)
6059 {
6060 inst.error = _("missing CPS flags");
6061 return FAIL;
6062 }
6063
6064 *str = s - 1;
6065 return val;
6066 }
6067
6068 /* Parse an endian specifier ("BE" or "LE", case insensitive);
6069 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
6070
6071 static int
6072 parse_endian_specifier (char **str)
6073 {
6074 int little_endian;
6075 char *s = *str;
6076
6077 if (strncasecmp (s, "BE", 2))
6078 little_endian = 0;
6079 else if (strncasecmp (s, "LE", 2))
6080 little_endian = 1;
6081 else
6082 {
6083 inst.error = _("valid endian specifiers are be or le");
6084 return FAIL;
6085 }
6086
6087 if (ISALNUM (s[2]) || s[2] == '_')
6088 {
6089 inst.error = _("valid endian specifiers are be or le");
6090 return FAIL;
6091 }
6092
6093 *str = s + 2;
6094 return little_endian;
6095 }
6096
6097 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
6098 value suitable for poking into the rotate field of an sxt or sxta
6099 instruction, or FAIL on error. */
6100
6101 static int
6102 parse_ror (char **str)
6103 {
6104 int rot;
6105 char *s = *str;
6106
6107 if (strncasecmp (s, "ROR", 3) == 0)
6108 s += 3;
6109 else
6110 {
6111 inst.error = _("missing rotation field after comma");
6112 return FAIL;
6113 }
6114
6115 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
6116 return FAIL;
6117
6118 switch (rot)
6119 {
6120 case 0: *str = s; return 0x0;
6121 case 8: *str = s; return 0x1;
6122 case 16: *str = s; return 0x2;
6123 case 24: *str = s; return 0x3;
6124
6125 default:
6126 inst.error = _("rotation can only be 0, 8, 16, or 24");
6127 return FAIL;
6128 }
6129 }
6130
6131 /* Parse a conditional code (from conds[] below). The value returned is in the
6132 range 0 .. 14, or FAIL. */
6133 static int
6134 parse_cond (char **str)
6135 {
6136 char *q;
6137 const struct asm_cond *c;
6138 int n;
6139 /* Condition codes are always 2 characters, so matching up to
6140 3 characters is sufficient. */
6141 char cond[3];
6142
6143 q = *str;
6144 n = 0;
6145 while (ISALPHA (*q) && n < 3)
6146 {
6147 cond[n] = TOLOWER (*q);
6148 q++;
6149 n++;
6150 }
6151
6152 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
6153 if (!c)
6154 {
6155 inst.error = _("condition required");
6156 return FAIL;
6157 }
6158
6159 *str = q;
6160 return c->value;
6161 }
6162
6163 /* Record a use of the given feature. */
6164 static void
6165 record_feature_use (const arm_feature_set *feature)
6166 {
6167 if (thumb_mode)
6168 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, *feature);
6169 else
6170 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, *feature);
6171 }
6172
6173 /* If the given feature is currently allowed, mark it as used and return TRUE.
6174 Return FALSE otherwise. */
6175 static bfd_boolean
6176 mark_feature_used (const arm_feature_set *feature)
6177 {
6178 /* Ensure the option is currently allowed. */
6179 if (!ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
6180 return FALSE;
6181
6182 /* Add the appropriate architecture feature for the barrier option used. */
6183 record_feature_use (feature);
6184
6185 return TRUE;
6186 }
6187
6188 /* Parse an option for a barrier instruction. Returns the encoding for the
6189 option, or FAIL. */
6190 static int
6191 parse_barrier (char **str)
6192 {
6193 char *p, *q;
6194 const struct asm_barrier_opt *o;
6195
6196 p = q = *str;
6197 while (ISALPHA (*q))
6198 q++;
6199
6200 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
6201 q - p);
6202 if (!o)
6203 return FAIL;
6204
6205 if (!mark_feature_used (&o->arch))
6206 return FAIL;
6207
6208 *str = q;
6209 return o->value;
6210 }
6211
6212 /* Parse the operands of a table branch instruction. Similar to a memory
6213 operand. */
6214 static int
6215 parse_tb (char **str)
6216 {
6217 char * p = *str;
6218 int reg;
6219
6220 if (skip_past_char (&p, '[') == FAIL)
6221 {
6222 inst.error = _("'[' expected");
6223 return FAIL;
6224 }
6225
6226 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6227 {
6228 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6229 return FAIL;
6230 }
6231 inst.operands[0].reg = reg;
6232
6233 if (skip_past_comma (&p) == FAIL)
6234 {
6235 inst.error = _("',' expected");
6236 return FAIL;
6237 }
6238
6239 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
6240 {
6241 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
6242 return FAIL;
6243 }
6244 inst.operands[0].imm = reg;
6245
6246 if (skip_past_comma (&p) == SUCCESS)
6247 {
6248 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
6249 return FAIL;
6250 if (inst.reloc.exp.X_add_number != 1)
6251 {
6252 inst.error = _("invalid shift");
6253 return FAIL;
6254 }
6255 inst.operands[0].shifted = 1;
6256 }
6257
6258 if (skip_past_char (&p, ']') == FAIL)
6259 {
6260 inst.error = _("']' expected");
6261 return FAIL;
6262 }
6263 *str = p;
6264 return SUCCESS;
6265 }
6266
6267 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
6268 information on the types the operands can take and how they are encoded.
6269 Up to four operands may be read; this function handles setting the
6270 ".present" field for each read operand itself.
6271 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
6272 else returns FAIL. */
6273
6274 static int
6275 parse_neon_mov (char **str, int *which_operand)
6276 {
6277 int i = *which_operand, val;
6278 enum arm_reg_type rtype;
6279 char *ptr = *str;
6280 struct neon_type_el optype;
6281
6282 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6283 {
6284 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
6285 inst.operands[i].reg = val;
6286 inst.operands[i].isscalar = 1;
6287 inst.operands[i].vectype = optype;
6288 inst.operands[i++].present = 1;
6289
6290 if (skip_past_comma (&ptr) == FAIL)
6291 goto wanted_comma;
6292
6293 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6294 goto wanted_arm;
6295
6296 inst.operands[i].reg = val;
6297 inst.operands[i].isreg = 1;
6298 inst.operands[i].present = 1;
6299 }
6300 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
6301 != FAIL)
6302 {
6303 /* Cases 0, 1, 2, 3, 5 (D only). */
6304 if (skip_past_comma (&ptr) == FAIL)
6305 goto wanted_comma;
6306
6307 inst.operands[i].reg = val;
6308 inst.operands[i].isreg = 1;
6309 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6310 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6311 inst.operands[i].isvec = 1;
6312 inst.operands[i].vectype = optype;
6313 inst.operands[i++].present = 1;
6314
6315 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6316 {
6317 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
6318 Case 13: VMOV <Sd>, <Rm> */
6319 inst.operands[i].reg = val;
6320 inst.operands[i].isreg = 1;
6321 inst.operands[i].present = 1;
6322
6323 if (rtype == REG_TYPE_NQ)
6324 {
6325 first_error (_("can't use Neon quad register here"));
6326 return FAIL;
6327 }
6328 else if (rtype != REG_TYPE_VFS)
6329 {
6330 i++;
6331 if (skip_past_comma (&ptr) == FAIL)
6332 goto wanted_comma;
6333 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6334 goto wanted_arm;
6335 inst.operands[i].reg = val;
6336 inst.operands[i].isreg = 1;
6337 inst.operands[i].present = 1;
6338 }
6339 }
6340 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
6341 &optype)) != FAIL)
6342 {
6343 /* Case 0: VMOV<c><q> <Qd>, <Qm>
6344 Case 1: VMOV<c><q> <Dd>, <Dm>
6345 Case 8: VMOV.F32 <Sd>, <Sm>
6346 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
6347
6348 inst.operands[i].reg = val;
6349 inst.operands[i].isreg = 1;
6350 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
6351 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6352 inst.operands[i].isvec = 1;
6353 inst.operands[i].vectype = optype;
6354 inst.operands[i].present = 1;
6355
6356 if (skip_past_comma (&ptr) == SUCCESS)
6357 {
6358 /* Case 15. */
6359 i++;
6360
6361 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6362 goto wanted_arm;
6363
6364 inst.operands[i].reg = val;
6365 inst.operands[i].isreg = 1;
6366 inst.operands[i++].present = 1;
6367
6368 if (skip_past_comma (&ptr) == FAIL)
6369 goto wanted_comma;
6370
6371 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
6372 goto wanted_arm;
6373
6374 inst.operands[i].reg = val;
6375 inst.operands[i].isreg = 1;
6376 inst.operands[i].present = 1;
6377 }
6378 }
6379 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
6380 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
6381 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
6382 Case 10: VMOV.F32 <Sd>, #<imm>
6383 Case 11: VMOV.F64 <Dd>, #<imm> */
6384 inst.operands[i].immisfloat = 1;
6385 else if (parse_big_immediate (&ptr, i, NULL, /*allow_symbol_p=*/FALSE)
6386 == SUCCESS)
6387 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
6388 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
6389 ;
6390 else
6391 {
6392 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
6393 return FAIL;
6394 }
6395 }
6396 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6397 {
6398 /* Cases 6, 7. */
6399 inst.operands[i].reg = val;
6400 inst.operands[i].isreg = 1;
6401 inst.operands[i++].present = 1;
6402
6403 if (skip_past_comma (&ptr) == FAIL)
6404 goto wanted_comma;
6405
6406 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
6407 {
6408 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
6409 inst.operands[i].reg = val;
6410 inst.operands[i].isscalar = 1;
6411 inst.operands[i].present = 1;
6412 inst.operands[i].vectype = optype;
6413 }
6414 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
6415 {
6416 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
6417 inst.operands[i].reg = val;
6418 inst.operands[i].isreg = 1;
6419 inst.operands[i++].present = 1;
6420
6421 if (skip_past_comma (&ptr) == FAIL)
6422 goto wanted_comma;
6423
6424 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6425 == FAIL)
6426 {
6427 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6428 return FAIL;
6429 }
6430
6431 inst.operands[i].reg = val;
6432 inst.operands[i].isreg = 1;
6433 inst.operands[i].isvec = 1;
6434 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6435 inst.operands[i].vectype = optype;
6436 inst.operands[i].present = 1;
6437
6438 if (rtype == REG_TYPE_VFS)
6439 {
6440 /* Case 14. */
6441 i++;
6442 if (skip_past_comma (&ptr) == FAIL)
6443 goto wanted_comma;
6444 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6445 &optype)) == FAIL)
6446 {
6447 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6448 return FAIL;
6449 }
6450 inst.operands[i].reg = val;
6451 inst.operands[i].isreg = 1;
6452 inst.operands[i].isvec = 1;
6453 inst.operands[i].issingle = 1;
6454 inst.operands[i].vectype = optype;
6455 inst.operands[i].present = 1;
6456 }
6457 }
6458 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6459 != FAIL)
6460 {
6461 /* Case 13. */
6462 inst.operands[i].reg = val;
6463 inst.operands[i].isreg = 1;
6464 inst.operands[i].isvec = 1;
6465 inst.operands[i].issingle = 1;
6466 inst.operands[i].vectype = optype;
6467 inst.operands[i].present = 1;
6468 }
6469 }
6470 else
6471 {
6472 first_error (_("parse error"));
6473 return FAIL;
6474 }
6475
6476 /* Successfully parsed the operands. Update args. */
6477 *which_operand = i;
6478 *str = ptr;
6479 return SUCCESS;
6480
6481 wanted_comma:
6482 first_error (_("expected comma"));
6483 return FAIL;
6484
6485 wanted_arm:
6486 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6487 return FAIL;
6488 }
6489
6490 /* Use this macro when the operand constraints are different
6491 for ARM and THUMB (e.g. ldrd). */
6492 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6493 ((arm_operand) | ((thumb_operand) << 16))
6494
6495 /* Matcher codes for parse_operands. */
6496 enum operand_parse_code
6497 {
6498 OP_stop, /* end of line */
6499
6500 OP_RR, /* ARM register */
6501 OP_RRnpc, /* ARM register, not r15 */
6502 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6503 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6504 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6505 optional trailing ! */
6506 OP_RRw, /* ARM register, not r15, optional trailing ! */
6507 OP_RCP, /* Coprocessor number */
6508 OP_RCN, /* Coprocessor register */
6509 OP_RF, /* FPA register */
6510 OP_RVS, /* VFP single precision register */
6511 OP_RVD, /* VFP double precision register (0..15) */
6512 OP_RND, /* Neon double precision register (0..31) */
6513 OP_RNQ, /* Neon quad precision register */
6514 OP_RVSD, /* VFP single or double precision register */
6515 OP_RNSD, /* Neon single or double precision register */
6516 OP_RNDQ, /* Neon double or quad precision register */
6517 OP_RNSDQ, /* Neon single, double or quad precision register */
6518 OP_RNSC, /* Neon scalar D[X] */
6519 OP_RVC, /* VFP control register */
6520 OP_RMF, /* Maverick F register */
6521 OP_RMD, /* Maverick D register */
6522 OP_RMFX, /* Maverick FX register */
6523 OP_RMDX, /* Maverick DX register */
6524 OP_RMAX, /* Maverick AX register */
6525 OP_RMDS, /* Maverick DSPSC register */
6526 OP_RIWR, /* iWMMXt wR register */
6527 OP_RIWC, /* iWMMXt wC register */
6528 OP_RIWG, /* iWMMXt wCG register */
6529 OP_RXA, /* XScale accumulator register */
6530
6531 OP_REGLST, /* ARM register list */
6532 OP_VRSLST, /* VFP single-precision register list */
6533 OP_VRDLST, /* VFP double-precision register list */
6534 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6535 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6536 OP_NSTRLST, /* Neon element/structure list */
6537
6538 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6539 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6540 OP_RSVD_FI0, /* VFP S or D reg, or floating point immediate zero. */
6541 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6542 OP_RNSD_RNSC, /* Neon S or D reg, or Neon scalar. */
6543 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6544 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6545 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6546 OP_VMOV, /* Neon VMOV operands. */
6547 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6548 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6549 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6550
6551 OP_I0, /* immediate zero */
6552 OP_I7, /* immediate value 0 .. 7 */
6553 OP_I15, /* 0 .. 15 */
6554 OP_I16, /* 1 .. 16 */
6555 OP_I16z, /* 0 .. 16 */
6556 OP_I31, /* 0 .. 31 */
6557 OP_I31w, /* 0 .. 31, optional trailing ! */
6558 OP_I32, /* 1 .. 32 */
6559 OP_I32z, /* 0 .. 32 */
6560 OP_I63, /* 0 .. 63 */
6561 OP_I63s, /* -64 .. 63 */
6562 OP_I64, /* 1 .. 64 */
6563 OP_I64z, /* 0 .. 64 */
6564 OP_I255, /* 0 .. 255 */
6565
6566 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6567 OP_I7b, /* 0 .. 7 */
6568 OP_I15b, /* 0 .. 15 */
6569 OP_I31b, /* 0 .. 31 */
6570
6571 OP_SH, /* shifter operand */
6572 OP_SHG, /* shifter operand with possible group relocation */
6573 OP_ADDR, /* Memory address expression (any mode) */
6574 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6575 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6576 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6577 OP_EXP, /* arbitrary expression */
6578 OP_EXPi, /* same, with optional immediate prefix */
6579 OP_EXPr, /* same, with optional relocation suffix */
6580 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6581 OP_IROT1, /* VCADD rotate immediate: 90, 270. */
6582 OP_IROT2, /* VCMLA rotate immediate: 0, 90, 180, 270. */
6583
6584 OP_CPSF, /* CPS flags */
6585 OP_ENDI, /* Endianness specifier */
6586 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6587 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6588 OP_COND, /* conditional code */
6589 OP_TB, /* Table branch. */
6590
6591 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6592
6593 OP_RRnpc_I0, /* ARM register or literal 0 */
6594 OP_RR_EXr, /* ARM register or expression with opt. reloc stuff. */
6595 OP_RR_EXi, /* ARM register or expression with imm prefix */
6596 OP_RF_IF, /* FPA register or immediate */
6597 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6598 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6599
6600 /* Optional operands. */
6601 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6602 OP_oI31b, /* 0 .. 31 */
6603 OP_oI32b, /* 1 .. 32 */
6604 OP_oI32z, /* 0 .. 32 */
6605 OP_oIffffb, /* 0 .. 65535 */
6606 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6607
6608 OP_oRR, /* ARM register */
6609 OP_oRRnpc, /* ARM register, not the PC */
6610 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6611 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6612 OP_oRND, /* Optional Neon double precision register */
6613 OP_oRNQ, /* Optional Neon quad precision register */
6614 OP_oRNDQ, /* Optional Neon double or quad precision register */
6615 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6616 OP_oSHll, /* LSL immediate */
6617 OP_oSHar, /* ASR immediate */
6618 OP_oSHllar, /* LSL or ASR immediate */
6619 OP_oROR, /* ROR 0/8/16/24 */
6620 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6621
6622 /* Some pre-defined mixed (ARM/THUMB) operands. */
6623 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6624 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6625 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6626
6627 OP_FIRST_OPTIONAL = OP_oI7b
6628 };
6629
6630 /* Generic instruction operand parser. This does no encoding and no
6631 semantic validation; it merely squirrels values away in the inst
6632 structure. Returns SUCCESS or FAIL depending on whether the
6633 specified grammar matched. */
6634 static int
6635 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6636 {
6637 unsigned const int *upat = pattern;
6638 char *backtrack_pos = 0;
6639 const char *backtrack_error = 0;
6640 int i, val = 0, backtrack_index = 0;
6641 enum arm_reg_type rtype;
6642 parse_operand_result result;
6643 unsigned int op_parse_code;
6644
6645 #define po_char_or_fail(chr) \
6646 do \
6647 { \
6648 if (skip_past_char (&str, chr) == FAIL) \
6649 goto bad_args; \
6650 } \
6651 while (0)
6652
6653 #define po_reg_or_fail(regtype) \
6654 do \
6655 { \
6656 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6657 & inst.operands[i].vectype); \
6658 if (val == FAIL) \
6659 { \
6660 first_error (_(reg_expected_msgs[regtype])); \
6661 goto failure; \
6662 } \
6663 inst.operands[i].reg = val; \
6664 inst.operands[i].isreg = 1; \
6665 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6666 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6667 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6668 || rtype == REG_TYPE_VFD \
6669 || rtype == REG_TYPE_NQ); \
6670 } \
6671 while (0)
6672
6673 #define po_reg_or_goto(regtype, label) \
6674 do \
6675 { \
6676 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6677 & inst.operands[i].vectype); \
6678 if (val == FAIL) \
6679 goto label; \
6680 \
6681 inst.operands[i].reg = val; \
6682 inst.operands[i].isreg = 1; \
6683 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6684 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6685 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6686 || rtype == REG_TYPE_VFD \
6687 || rtype == REG_TYPE_NQ); \
6688 } \
6689 while (0)
6690
6691 #define po_imm_or_fail(min, max, popt) \
6692 do \
6693 { \
6694 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6695 goto failure; \
6696 inst.operands[i].imm = val; \
6697 } \
6698 while (0)
6699
6700 #define po_scalar_or_goto(elsz, label) \
6701 do \
6702 { \
6703 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6704 if (val == FAIL) \
6705 goto label; \
6706 inst.operands[i].reg = val; \
6707 inst.operands[i].isscalar = 1; \
6708 } \
6709 while (0)
6710
6711 #define po_misc_or_fail(expr) \
6712 do \
6713 { \
6714 if (expr) \
6715 goto failure; \
6716 } \
6717 while (0)
6718
6719 #define po_misc_or_fail_no_backtrack(expr) \
6720 do \
6721 { \
6722 result = expr; \
6723 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6724 backtrack_pos = 0; \
6725 if (result != PARSE_OPERAND_SUCCESS) \
6726 goto failure; \
6727 } \
6728 while (0)
6729
6730 #define po_barrier_or_imm(str) \
6731 do \
6732 { \
6733 val = parse_barrier (&str); \
6734 if (val == FAIL && ! ISALPHA (*str)) \
6735 goto immediate; \
6736 if (val == FAIL \
6737 /* ISB can only take SY as an option. */ \
6738 || ((inst.instruction & 0xf0) == 0x60 \
6739 && val != 0xf)) \
6740 { \
6741 inst.error = _("invalid barrier type"); \
6742 backtrack_pos = 0; \
6743 goto failure; \
6744 } \
6745 } \
6746 while (0)
6747
6748 skip_whitespace (str);
6749
6750 for (i = 0; upat[i] != OP_stop; i++)
6751 {
6752 op_parse_code = upat[i];
6753 if (op_parse_code >= 1<<16)
6754 op_parse_code = thumb ? (op_parse_code >> 16)
6755 : (op_parse_code & ((1<<16)-1));
6756
6757 if (op_parse_code >= OP_FIRST_OPTIONAL)
6758 {
6759 /* Remember where we are in case we need to backtrack. */
6760 gas_assert (!backtrack_pos);
6761 backtrack_pos = str;
6762 backtrack_error = inst.error;
6763 backtrack_index = i;
6764 }
6765
6766 if (i > 0 && (i > 1 || inst.operands[0].present))
6767 po_char_or_fail (',');
6768
6769 switch (op_parse_code)
6770 {
6771 /* Registers */
6772 case OP_oRRnpc:
6773 case OP_oRRnpcsp:
6774 case OP_RRnpc:
6775 case OP_RRnpcsp:
6776 case OP_oRR:
6777 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6778 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6779 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6780 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6781 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6782 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6783 case OP_oRND:
6784 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6785 case OP_RVC:
6786 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6787 break;
6788 /* Also accept generic coprocessor regs for unknown registers. */
6789 coproc_reg:
6790 po_reg_or_fail (REG_TYPE_CN);
6791 break;
6792 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6793 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6794 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6795 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6796 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6797 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6798 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6799 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6800 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6801 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6802 case OP_oRNQ:
6803 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6804 case OP_RNSD: po_reg_or_fail (REG_TYPE_NSD); break;
6805 case OP_oRNDQ:
6806 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6807 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6808 case OP_oRNSDQ:
6809 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6810
6811 /* Neon scalar. Using an element size of 8 means that some invalid
6812 scalars are accepted here, so deal with those in later code. */
6813 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6814
6815 case OP_RNDQ_I0:
6816 {
6817 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6818 break;
6819 try_imm0:
6820 po_imm_or_fail (0, 0, TRUE);
6821 }
6822 break;
6823
6824 case OP_RVSD_I0:
6825 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6826 break;
6827
6828 case OP_RSVD_FI0:
6829 {
6830 po_reg_or_goto (REG_TYPE_VFSD, try_ifimm0);
6831 break;
6832 try_ifimm0:
6833 if (parse_ifimm_zero (&str))
6834 inst.operands[i].imm = 0;
6835 else
6836 {
6837 inst.error
6838 = _("only floating point zero is allowed as immediate value");
6839 goto failure;
6840 }
6841 }
6842 break;
6843
6844 case OP_RR_RNSC:
6845 {
6846 po_scalar_or_goto (8, try_rr);
6847 break;
6848 try_rr:
6849 po_reg_or_fail (REG_TYPE_RN);
6850 }
6851 break;
6852
6853 case OP_RNSDQ_RNSC:
6854 {
6855 po_scalar_or_goto (8, try_nsdq);
6856 break;
6857 try_nsdq:
6858 po_reg_or_fail (REG_TYPE_NSDQ);
6859 }
6860 break;
6861
6862 case OP_RNSD_RNSC:
6863 {
6864 po_scalar_or_goto (8, try_s_scalar);
6865 break;
6866 try_s_scalar:
6867 po_scalar_or_goto (4, try_nsd);
6868 break;
6869 try_nsd:
6870 po_reg_or_fail (REG_TYPE_NSD);
6871 }
6872 break;
6873
6874 case OP_RNDQ_RNSC:
6875 {
6876 po_scalar_or_goto (8, try_ndq);
6877 break;
6878 try_ndq:
6879 po_reg_or_fail (REG_TYPE_NDQ);
6880 }
6881 break;
6882
6883 case OP_RND_RNSC:
6884 {
6885 po_scalar_or_goto (8, try_vfd);
6886 break;
6887 try_vfd:
6888 po_reg_or_fail (REG_TYPE_VFD);
6889 }
6890 break;
6891
6892 case OP_VMOV:
6893 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6894 not careful then bad things might happen. */
6895 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6896 break;
6897
6898 case OP_RNDQ_Ibig:
6899 {
6900 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6901 break;
6902 try_immbig:
6903 /* There's a possibility of getting a 64-bit immediate here, so
6904 we need special handling. */
6905 if (parse_big_immediate (&str, i, NULL, /*allow_symbol_p=*/FALSE)
6906 == FAIL)
6907 {
6908 inst.error = _("immediate value is out of range");
6909 goto failure;
6910 }
6911 }
6912 break;
6913
6914 case OP_RNDQ_I63b:
6915 {
6916 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6917 break;
6918 try_shimm:
6919 po_imm_or_fail (0, 63, TRUE);
6920 }
6921 break;
6922
6923 case OP_RRnpcb:
6924 po_char_or_fail ('[');
6925 po_reg_or_fail (REG_TYPE_RN);
6926 po_char_or_fail (']');
6927 break;
6928
6929 case OP_RRnpctw:
6930 case OP_RRw:
6931 case OP_oRRw:
6932 po_reg_or_fail (REG_TYPE_RN);
6933 if (skip_past_char (&str, '!') == SUCCESS)
6934 inst.operands[i].writeback = 1;
6935 break;
6936
6937 /* Immediates */
6938 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6939 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6940 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6941 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6942 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6943 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6944 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6945 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6946 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6947 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6948 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6949 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6950
6951 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6952 case OP_oI7b:
6953 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6954 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6955 case OP_oI31b:
6956 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6957 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6958 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
6959 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6960
6961 /* Immediate variants */
6962 case OP_oI255c:
6963 po_char_or_fail ('{');
6964 po_imm_or_fail (0, 255, TRUE);
6965 po_char_or_fail ('}');
6966 break;
6967
6968 case OP_I31w:
6969 /* The expression parser chokes on a trailing !, so we have
6970 to find it first and zap it. */
6971 {
6972 char *s = str;
6973 while (*s && *s != ',')
6974 s++;
6975 if (s[-1] == '!')
6976 {
6977 s[-1] = '\0';
6978 inst.operands[i].writeback = 1;
6979 }
6980 po_imm_or_fail (0, 31, TRUE);
6981 if (str == s - 1)
6982 str = s;
6983 }
6984 break;
6985
6986 /* Expressions */
6987 case OP_EXPi: EXPi:
6988 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6989 GE_OPT_PREFIX));
6990 break;
6991
6992 case OP_EXP:
6993 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6994 GE_NO_PREFIX));
6995 break;
6996
6997 case OP_EXPr: EXPr:
6998 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6999 GE_NO_PREFIX));
7000 if (inst.reloc.exp.X_op == O_symbol)
7001 {
7002 val = parse_reloc (&str);
7003 if (val == -1)
7004 {
7005 inst.error = _("unrecognized relocation suffix");
7006 goto failure;
7007 }
7008 else if (val != BFD_RELOC_UNUSED)
7009 {
7010 inst.operands[i].imm = val;
7011 inst.operands[i].hasreloc = 1;
7012 }
7013 }
7014 break;
7015
7016 /* Operand for MOVW or MOVT. */
7017 case OP_HALF:
7018 po_misc_or_fail (parse_half (&str));
7019 break;
7020
7021 /* Register or expression. */
7022 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
7023 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
7024
7025 /* Register or immediate. */
7026 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
7027 I0: po_imm_or_fail (0, 0, FALSE); break;
7028
7029 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
7030 IF:
7031 if (!is_immediate_prefix (*str))
7032 goto bad_args;
7033 str++;
7034 val = parse_fpa_immediate (&str);
7035 if (val == FAIL)
7036 goto failure;
7037 /* FPA immediates are encoded as registers 8-15.
7038 parse_fpa_immediate has already applied the offset. */
7039 inst.operands[i].reg = val;
7040 inst.operands[i].isreg = 1;
7041 break;
7042
7043 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
7044 I32z: po_imm_or_fail (0, 32, FALSE); break;
7045
7046 /* Two kinds of register. */
7047 case OP_RIWR_RIWC:
7048 {
7049 struct reg_entry *rege = arm_reg_parse_multi (&str);
7050 if (!rege
7051 || (rege->type != REG_TYPE_MMXWR
7052 && rege->type != REG_TYPE_MMXWC
7053 && rege->type != REG_TYPE_MMXWCG))
7054 {
7055 inst.error = _("iWMMXt data or control register expected");
7056 goto failure;
7057 }
7058 inst.operands[i].reg = rege->number;
7059 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
7060 }
7061 break;
7062
7063 case OP_RIWC_RIWG:
7064 {
7065 struct reg_entry *rege = arm_reg_parse_multi (&str);
7066 if (!rege
7067 || (rege->type != REG_TYPE_MMXWC
7068 && rege->type != REG_TYPE_MMXWCG))
7069 {
7070 inst.error = _("iWMMXt control register expected");
7071 goto failure;
7072 }
7073 inst.operands[i].reg = rege->number;
7074 inst.operands[i].isreg = 1;
7075 }
7076 break;
7077
7078 /* Misc */
7079 case OP_CPSF: val = parse_cps_flags (&str); break;
7080 case OP_ENDI: val = parse_endian_specifier (&str); break;
7081 case OP_oROR: val = parse_ror (&str); break;
7082 case OP_COND: val = parse_cond (&str); break;
7083 case OP_oBARRIER_I15:
7084 po_barrier_or_imm (str); break;
7085 immediate:
7086 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
7087 goto failure;
7088 break;
7089
7090 case OP_wPSR:
7091 case OP_rPSR:
7092 po_reg_or_goto (REG_TYPE_RNB, try_psr);
7093 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
7094 {
7095 inst.error = _("Banked registers are not available with this "
7096 "architecture.");
7097 goto failure;
7098 }
7099 break;
7100 try_psr:
7101 val = parse_psr (&str, op_parse_code == OP_wPSR);
7102 break;
7103
7104 case OP_APSR_RR:
7105 po_reg_or_goto (REG_TYPE_RN, try_apsr);
7106 break;
7107 try_apsr:
7108 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
7109 instruction). */
7110 if (strncasecmp (str, "APSR_", 5) == 0)
7111 {
7112 unsigned found = 0;
7113 str += 5;
7114 while (found < 15)
7115 switch (*str++)
7116 {
7117 case 'c': found = (found & 1) ? 16 : found | 1; break;
7118 case 'n': found = (found & 2) ? 16 : found | 2; break;
7119 case 'z': found = (found & 4) ? 16 : found | 4; break;
7120 case 'v': found = (found & 8) ? 16 : found | 8; break;
7121 default: found = 16;
7122 }
7123 if (found != 15)
7124 goto failure;
7125 inst.operands[i].isvec = 1;
7126 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
7127 inst.operands[i].reg = REG_PC;
7128 }
7129 else
7130 goto failure;
7131 break;
7132
7133 case OP_TB:
7134 po_misc_or_fail (parse_tb (&str));
7135 break;
7136
7137 /* Register lists. */
7138 case OP_REGLST:
7139 val = parse_reg_list (&str);
7140 if (*str == '^')
7141 {
7142 inst.operands[i].writeback = 1;
7143 str++;
7144 }
7145 break;
7146
7147 case OP_VRSLST:
7148 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
7149 break;
7150
7151 case OP_VRDLST:
7152 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
7153 break;
7154
7155 case OP_VRSDLST:
7156 /* Allow Q registers too. */
7157 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7158 REGLIST_NEON_D);
7159 if (val == FAIL)
7160 {
7161 inst.error = NULL;
7162 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7163 REGLIST_VFP_S);
7164 inst.operands[i].issingle = 1;
7165 }
7166 break;
7167
7168 case OP_NRDLST:
7169 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
7170 REGLIST_NEON_D);
7171 break;
7172
7173 case OP_NSTRLST:
7174 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
7175 &inst.operands[i].vectype);
7176 break;
7177
7178 /* Addressing modes */
7179 case OP_ADDR:
7180 po_misc_or_fail (parse_address (&str, i));
7181 break;
7182
7183 case OP_ADDRGLDR:
7184 po_misc_or_fail_no_backtrack (
7185 parse_address_group_reloc (&str, i, GROUP_LDR));
7186 break;
7187
7188 case OP_ADDRGLDRS:
7189 po_misc_or_fail_no_backtrack (
7190 parse_address_group_reloc (&str, i, GROUP_LDRS));
7191 break;
7192
7193 case OP_ADDRGLDC:
7194 po_misc_or_fail_no_backtrack (
7195 parse_address_group_reloc (&str, i, GROUP_LDC));
7196 break;
7197
7198 case OP_SH:
7199 po_misc_or_fail (parse_shifter_operand (&str, i));
7200 break;
7201
7202 case OP_SHG:
7203 po_misc_or_fail_no_backtrack (
7204 parse_shifter_operand_group_reloc (&str, i));
7205 break;
7206
7207 case OP_oSHll:
7208 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
7209 break;
7210
7211 case OP_oSHar:
7212 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
7213 break;
7214
7215 case OP_oSHllar:
7216 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
7217 break;
7218
7219 default:
7220 as_fatal (_("unhandled operand code %d"), op_parse_code);
7221 }
7222
7223 /* Various value-based sanity checks and shared operations. We
7224 do not signal immediate failures for the register constraints;
7225 this allows a syntax error to take precedence. */
7226 switch (op_parse_code)
7227 {
7228 case OP_oRRnpc:
7229 case OP_RRnpc:
7230 case OP_RRnpcb:
7231 case OP_RRw:
7232 case OP_oRRw:
7233 case OP_RRnpc_I0:
7234 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
7235 inst.error = BAD_PC;
7236 break;
7237
7238 case OP_oRRnpcsp:
7239 case OP_RRnpcsp:
7240 if (inst.operands[i].isreg)
7241 {
7242 if (inst.operands[i].reg == REG_PC)
7243 inst.error = BAD_PC;
7244 else if (inst.operands[i].reg == REG_SP
7245 /* The restriction on Rd/Rt/Rt2 on Thumb mode has been
7246 relaxed since ARMv8-A. */
7247 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
7248 {
7249 gas_assert (thumb);
7250 inst.error = BAD_SP;
7251 }
7252 }
7253 break;
7254
7255 case OP_RRnpctw:
7256 if (inst.operands[i].isreg
7257 && inst.operands[i].reg == REG_PC
7258 && (inst.operands[i].writeback || thumb))
7259 inst.error = BAD_PC;
7260 break;
7261
7262 case OP_CPSF:
7263 case OP_ENDI:
7264 case OP_oROR:
7265 case OP_wPSR:
7266 case OP_rPSR:
7267 case OP_COND:
7268 case OP_oBARRIER_I15:
7269 case OP_REGLST:
7270 case OP_VRSLST:
7271 case OP_VRDLST:
7272 case OP_VRSDLST:
7273 case OP_NRDLST:
7274 case OP_NSTRLST:
7275 if (val == FAIL)
7276 goto failure;
7277 inst.operands[i].imm = val;
7278 break;
7279
7280 default:
7281 break;
7282 }
7283
7284 /* If we get here, this operand was successfully parsed. */
7285 inst.operands[i].present = 1;
7286 continue;
7287
7288 bad_args:
7289 inst.error = BAD_ARGS;
7290
7291 failure:
7292 if (!backtrack_pos)
7293 {
7294 /* The parse routine should already have set inst.error, but set a
7295 default here just in case. */
7296 if (!inst.error)
7297 inst.error = _("syntax error");
7298 return FAIL;
7299 }
7300
7301 /* Do not backtrack over a trailing optional argument that
7302 absorbed some text. We will only fail again, with the
7303 'garbage following instruction' error message, which is
7304 probably less helpful than the current one. */
7305 if (backtrack_index == i && backtrack_pos != str
7306 && upat[i+1] == OP_stop)
7307 {
7308 if (!inst.error)
7309 inst.error = _("syntax error");
7310 return FAIL;
7311 }
7312
7313 /* Try again, skipping the optional argument at backtrack_pos. */
7314 str = backtrack_pos;
7315 inst.error = backtrack_error;
7316 inst.operands[backtrack_index].present = 0;
7317 i = backtrack_index;
7318 backtrack_pos = 0;
7319 }
7320
7321 /* Check that we have parsed all the arguments. */
7322 if (*str != '\0' && !inst.error)
7323 inst.error = _("garbage following instruction");
7324
7325 return inst.error ? FAIL : SUCCESS;
7326 }
7327
7328 #undef po_char_or_fail
7329 #undef po_reg_or_fail
7330 #undef po_reg_or_goto
7331 #undef po_imm_or_fail
7332 #undef po_scalar_or_fail
7333 #undef po_barrier_or_imm
7334
7335 /* Shorthand macro for instruction encoding functions issuing errors. */
7336 #define constraint(expr, err) \
7337 do \
7338 { \
7339 if (expr) \
7340 { \
7341 inst.error = err; \
7342 return; \
7343 } \
7344 } \
7345 while (0)
7346
7347 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
7348 instructions are unpredictable if these registers are used. This
7349 is the BadReg predicate in ARM's Thumb-2 documentation.
7350
7351 Before ARMv8-A, REG_PC and REG_SP were not allowed in quite a few
7352 places, while the restriction on REG_SP was relaxed since ARMv8-A. */
7353 #define reject_bad_reg(reg) \
7354 do \
7355 if (reg == REG_PC) \
7356 { \
7357 inst.error = BAD_PC; \
7358 return; \
7359 } \
7360 else if (reg == REG_SP \
7361 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)) \
7362 { \
7363 inst.error = BAD_SP; \
7364 return; \
7365 } \
7366 while (0)
7367
7368 /* If REG is R13 (the stack pointer), warn that its use is
7369 deprecated. */
7370 #define warn_deprecated_sp(reg) \
7371 do \
7372 if (warn_on_deprecated && reg == REG_SP) \
7373 as_tsktsk (_("use of r13 is deprecated")); \
7374 while (0)
7375
7376 /* Functions for operand encoding. ARM, then Thumb. */
7377
7378 #define rotate_left(v, n) (v << (n & 31) | v >> ((32 - n) & 31))
7379
7380 /* If the current inst is scalar ARMv8.2 fp16 instruction, do special encoding.
7381
7382 The only binary encoding difference is the Coprocessor number. Coprocessor
7383 9 is used for half-precision calculations or conversions. The format of the
7384 instruction is the same as the equivalent Coprocessor 10 instruction that
7385 exists for Single-Precision operation. */
7386
7387 static void
7388 do_scalar_fp16_v82_encode (void)
7389 {
7390 if (inst.cond != COND_ALWAYS)
7391 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
7392 " the behaviour is UNPREDICTABLE"));
7393 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
7394 _(BAD_FP16));
7395
7396 inst.instruction = (inst.instruction & 0xfffff0ff) | 0x900;
7397 mark_feature_used (&arm_ext_fp16);
7398 }
7399
7400 /* If VAL can be encoded in the immediate field of an ARM instruction,
7401 return the encoded form. Otherwise, return FAIL. */
7402
7403 static unsigned int
7404 encode_arm_immediate (unsigned int val)
7405 {
7406 unsigned int a, i;
7407
7408 if (val <= 0xff)
7409 return val;
7410
7411 for (i = 2; i < 32; i += 2)
7412 if ((a = rotate_left (val, i)) <= 0xff)
7413 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
7414
7415 return FAIL;
7416 }
7417
7418 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
7419 return the encoded form. Otherwise, return FAIL. */
7420 static unsigned int
7421 encode_thumb32_immediate (unsigned int val)
7422 {
7423 unsigned int a, i;
7424
7425 if (val <= 0xff)
7426 return val;
7427
7428 for (i = 1; i <= 24; i++)
7429 {
7430 a = val >> i;
7431 if ((val & ~(0xff << i)) == 0)
7432 return ((val >> i) & 0x7f) | ((32 - i) << 7);
7433 }
7434
7435 a = val & 0xff;
7436 if (val == ((a << 16) | a))
7437 return 0x100 | a;
7438 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
7439 return 0x300 | a;
7440
7441 a = val & 0xff00;
7442 if (val == ((a << 16) | a))
7443 return 0x200 | (a >> 8);
7444
7445 return FAIL;
7446 }
7447 /* Encode a VFP SP or DP register number into inst.instruction. */
7448
7449 static void
7450 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
7451 {
7452 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
7453 && reg > 15)
7454 {
7455 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
7456 {
7457 if (thumb_mode)
7458 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
7459 fpu_vfp_ext_d32);
7460 else
7461 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
7462 fpu_vfp_ext_d32);
7463 }
7464 else
7465 {
7466 first_error (_("D register out of range for selected VFP version"));
7467 return;
7468 }
7469 }
7470
7471 switch (pos)
7472 {
7473 case VFP_REG_Sd:
7474 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
7475 break;
7476
7477 case VFP_REG_Sn:
7478 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
7479 break;
7480
7481 case VFP_REG_Sm:
7482 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
7483 break;
7484
7485 case VFP_REG_Dd:
7486 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
7487 break;
7488
7489 case VFP_REG_Dn:
7490 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7491 break;
7492
7493 case VFP_REG_Dm:
7494 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7495 break;
7496
7497 default:
7498 abort ();
7499 }
7500 }
7501
7502 /* Encode a <shift> in an ARM-format instruction. The immediate,
7503 if any, is handled by md_apply_fix. */
7504 static void
7505 encode_arm_shift (int i)
7506 {
7507 /* register-shifted register. */
7508 if (inst.operands[i].immisreg)
7509 {
7510 int op_index;
7511 for (op_index = 0; op_index <= i; ++op_index)
7512 {
7513 /* Check the operand only when it's presented. In pre-UAL syntax,
7514 if the destination register is the same as the first operand, two
7515 register form of the instruction can be used. */
7516 if (inst.operands[op_index].present && inst.operands[op_index].isreg
7517 && inst.operands[op_index].reg == REG_PC)
7518 as_warn (UNPRED_REG ("r15"));
7519 }
7520
7521 if (inst.operands[i].imm == REG_PC)
7522 as_warn (UNPRED_REG ("r15"));
7523 }
7524
7525 if (inst.operands[i].shift_kind == SHIFT_RRX)
7526 inst.instruction |= SHIFT_ROR << 5;
7527 else
7528 {
7529 inst.instruction |= inst.operands[i].shift_kind << 5;
7530 if (inst.operands[i].immisreg)
7531 {
7532 inst.instruction |= SHIFT_BY_REG;
7533 inst.instruction |= inst.operands[i].imm << 8;
7534 }
7535 else
7536 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7537 }
7538 }
7539
7540 static void
7541 encode_arm_shifter_operand (int i)
7542 {
7543 if (inst.operands[i].isreg)
7544 {
7545 inst.instruction |= inst.operands[i].reg;
7546 encode_arm_shift (i);
7547 }
7548 else
7549 {
7550 inst.instruction |= INST_IMMEDIATE;
7551 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7552 inst.instruction |= inst.operands[i].imm;
7553 }
7554 }
7555
7556 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7557 static void
7558 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7559 {
7560 /* PR 14260:
7561 Generate an error if the operand is not a register. */
7562 constraint (!inst.operands[i].isreg,
7563 _("Instruction does not support =N addresses"));
7564
7565 inst.instruction |= inst.operands[i].reg << 16;
7566
7567 if (inst.operands[i].preind)
7568 {
7569 if (is_t)
7570 {
7571 inst.error = _("instruction does not accept preindexed addressing");
7572 return;
7573 }
7574 inst.instruction |= PRE_INDEX;
7575 if (inst.operands[i].writeback)
7576 inst.instruction |= WRITE_BACK;
7577
7578 }
7579 else if (inst.operands[i].postind)
7580 {
7581 gas_assert (inst.operands[i].writeback);
7582 if (is_t)
7583 inst.instruction |= WRITE_BACK;
7584 }
7585 else /* unindexed - only for coprocessor */
7586 {
7587 inst.error = _("instruction does not accept unindexed addressing");
7588 return;
7589 }
7590
7591 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7592 && (((inst.instruction & 0x000f0000) >> 16)
7593 == ((inst.instruction & 0x0000f000) >> 12)))
7594 as_warn ((inst.instruction & LOAD_BIT)
7595 ? _("destination register same as write-back base")
7596 : _("source register same as write-back base"));
7597 }
7598
7599 /* inst.operands[i] was set up by parse_address. Encode it into an
7600 ARM-format mode 2 load or store instruction. If is_t is true,
7601 reject forms that cannot be used with a T instruction (i.e. not
7602 post-indexed). */
7603 static void
7604 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7605 {
7606 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7607
7608 encode_arm_addr_mode_common (i, is_t);
7609
7610 if (inst.operands[i].immisreg)
7611 {
7612 constraint ((inst.operands[i].imm == REG_PC
7613 || (is_pc && inst.operands[i].writeback)),
7614 BAD_PC_ADDRESSING);
7615 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7616 inst.instruction |= inst.operands[i].imm;
7617 if (!inst.operands[i].negative)
7618 inst.instruction |= INDEX_UP;
7619 if (inst.operands[i].shifted)
7620 {
7621 if (inst.operands[i].shift_kind == SHIFT_RRX)
7622 inst.instruction |= SHIFT_ROR << 5;
7623 else
7624 {
7625 inst.instruction |= inst.operands[i].shift_kind << 5;
7626 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7627 }
7628 }
7629 }
7630 else /* immediate offset in inst.reloc */
7631 {
7632 if (is_pc && !inst.reloc.pc_rel)
7633 {
7634 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7635
7636 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7637 cannot use PC in addressing.
7638 PC cannot be used in writeback addressing, either. */
7639 constraint ((is_t || inst.operands[i].writeback),
7640 BAD_PC_ADDRESSING);
7641
7642 /* Use of PC in str is deprecated for ARMv7. */
7643 if (warn_on_deprecated
7644 && !is_load
7645 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7646 as_tsktsk (_("use of PC in this instruction is deprecated"));
7647 }
7648
7649 if (inst.reloc.type == BFD_RELOC_UNUSED)
7650 {
7651 /* Prefer + for zero encoded value. */
7652 if (!inst.operands[i].negative)
7653 inst.instruction |= INDEX_UP;
7654 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7655 }
7656 }
7657 }
7658
7659 /* inst.operands[i] was set up by parse_address. Encode it into an
7660 ARM-format mode 3 load or store instruction. Reject forms that
7661 cannot be used with such instructions. If is_t is true, reject
7662 forms that cannot be used with a T instruction (i.e. not
7663 post-indexed). */
7664 static void
7665 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7666 {
7667 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7668 {
7669 inst.error = _("instruction does not accept scaled register index");
7670 return;
7671 }
7672
7673 encode_arm_addr_mode_common (i, is_t);
7674
7675 if (inst.operands[i].immisreg)
7676 {
7677 constraint ((inst.operands[i].imm == REG_PC
7678 || (is_t && inst.operands[i].reg == REG_PC)),
7679 BAD_PC_ADDRESSING);
7680 constraint (inst.operands[i].reg == REG_PC && inst.operands[i].writeback,
7681 BAD_PC_WRITEBACK);
7682 inst.instruction |= inst.operands[i].imm;
7683 if (!inst.operands[i].negative)
7684 inst.instruction |= INDEX_UP;
7685 }
7686 else /* immediate offset in inst.reloc */
7687 {
7688 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7689 && inst.operands[i].writeback),
7690 BAD_PC_WRITEBACK);
7691 inst.instruction |= HWOFFSET_IMM;
7692 if (inst.reloc.type == BFD_RELOC_UNUSED)
7693 {
7694 /* Prefer + for zero encoded value. */
7695 if (!inst.operands[i].negative)
7696 inst.instruction |= INDEX_UP;
7697
7698 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7699 }
7700 }
7701 }
7702
7703 /* Write immediate bits [7:0] to the following locations:
7704
7705 |28/24|23 19|18 16|15 4|3 0|
7706 | 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|
7707
7708 This function is used by VMOV/VMVN/VORR/VBIC. */
7709
7710 static void
7711 neon_write_immbits (unsigned immbits)
7712 {
7713 inst.instruction |= immbits & 0xf;
7714 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
7715 inst.instruction |= ((immbits >> 7) & 0x1) << (thumb_mode ? 28 : 24);
7716 }
7717
7718 /* Invert low-order SIZE bits of XHI:XLO. */
7719
7720 static void
7721 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
7722 {
7723 unsigned immlo = xlo ? *xlo : 0;
7724 unsigned immhi = xhi ? *xhi : 0;
7725
7726 switch (size)
7727 {
7728 case 8:
7729 immlo = (~immlo) & 0xff;
7730 break;
7731
7732 case 16:
7733 immlo = (~immlo) & 0xffff;
7734 break;
7735
7736 case 64:
7737 immhi = (~immhi) & 0xffffffff;
7738 /* fall through. */
7739
7740 case 32:
7741 immlo = (~immlo) & 0xffffffff;
7742 break;
7743
7744 default:
7745 abort ();
7746 }
7747
7748 if (xlo)
7749 *xlo = immlo;
7750
7751 if (xhi)
7752 *xhi = immhi;
7753 }
7754
7755 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
7756 A, B, C, D. */
7757
7758 static int
7759 neon_bits_same_in_bytes (unsigned imm)
7760 {
7761 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
7762 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
7763 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
7764 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
7765 }
7766
7767 /* For immediate of above form, return 0bABCD. */
7768
7769 static unsigned
7770 neon_squash_bits (unsigned imm)
7771 {
7772 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
7773 | ((imm & 0x01000000) >> 21);
7774 }
7775
7776 /* Compress quarter-float representation to 0b...000 abcdefgh. */
7777
7778 static unsigned
7779 neon_qfloat_bits (unsigned imm)
7780 {
7781 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
7782 }
7783
7784 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
7785 the instruction. *OP is passed as the initial value of the op field, and
7786 may be set to a different value depending on the constant (i.e.
7787 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
7788 MVN). If the immediate looks like a repeated pattern then also
7789 try smaller element sizes. */
7790
7791 static int
7792 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
7793 unsigned *immbits, int *op, int size,
7794 enum neon_el_type type)
7795 {
7796 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
7797 float. */
7798 if (type == NT_float && !float_p)
7799 return FAIL;
7800
7801 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
7802 {
7803 if (size != 32 || *op == 1)
7804 return FAIL;
7805 *immbits = neon_qfloat_bits (immlo);
7806 return 0xf;
7807 }
7808
7809 if (size == 64)
7810 {
7811 if (neon_bits_same_in_bytes (immhi)
7812 && neon_bits_same_in_bytes (immlo))
7813 {
7814 if (*op == 1)
7815 return FAIL;
7816 *immbits = (neon_squash_bits (immhi) << 4)
7817 | neon_squash_bits (immlo);
7818 *op = 1;
7819 return 0xe;
7820 }
7821
7822 if (immhi != immlo)
7823 return FAIL;
7824 }
7825
7826 if (size >= 32)
7827 {
7828 if (immlo == (immlo & 0x000000ff))
7829 {
7830 *immbits = immlo;
7831 return 0x0;
7832 }
7833 else if (immlo == (immlo & 0x0000ff00))
7834 {
7835 *immbits = immlo >> 8;
7836 return 0x2;
7837 }
7838 else if (immlo == (immlo & 0x00ff0000))
7839 {
7840 *immbits = immlo >> 16;
7841 return 0x4;
7842 }
7843 else if (immlo == (immlo & 0xff000000))
7844 {
7845 *immbits = immlo >> 24;
7846 return 0x6;
7847 }
7848 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
7849 {
7850 *immbits = (immlo >> 8) & 0xff;
7851 return 0xc;
7852 }
7853 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
7854 {
7855 *immbits = (immlo >> 16) & 0xff;
7856 return 0xd;
7857 }
7858
7859 if ((immlo & 0xffff) != (immlo >> 16))
7860 return FAIL;
7861 immlo &= 0xffff;
7862 }
7863
7864 if (size >= 16)
7865 {
7866 if (immlo == (immlo & 0x000000ff))
7867 {
7868 *immbits = immlo;
7869 return 0x8;
7870 }
7871 else if (immlo == (immlo & 0x0000ff00))
7872 {
7873 *immbits = immlo >> 8;
7874 return 0xa;
7875 }
7876
7877 if ((immlo & 0xff) != (immlo >> 8))
7878 return FAIL;
7879 immlo &= 0xff;
7880 }
7881
7882 if (immlo == (immlo & 0x000000ff))
7883 {
7884 /* Don't allow MVN with 8-bit immediate. */
7885 if (*op == 1)
7886 return FAIL;
7887 *immbits = immlo;
7888 return 0xe;
7889 }
7890
7891 return FAIL;
7892 }
7893
7894 #if defined BFD_HOST_64_BIT
7895 /* Returns TRUE if double precision value V may be cast
7896 to single precision without loss of accuracy. */
7897
7898 static bfd_boolean
7899 is_double_a_single (bfd_int64_t v)
7900 {
7901 int exp = (int)((v >> 52) & 0x7FF);
7902 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
7903
7904 return (exp == 0 || exp == 0x7FF
7905 || (exp >= 1023 - 126 && exp <= 1023 + 127))
7906 && (mantissa & 0x1FFFFFFFl) == 0;
7907 }
7908
7909 /* Returns a double precision value casted to single precision
7910 (ignoring the least significant bits in exponent and mantissa). */
7911
7912 static int
7913 double_to_single (bfd_int64_t v)
7914 {
7915 int sign = (int) ((v >> 63) & 1l);
7916 int exp = (int) ((v >> 52) & 0x7FF);
7917 bfd_int64_t mantissa = (v & (bfd_int64_t)0xFFFFFFFFFFFFFULL);
7918
7919 if (exp == 0x7FF)
7920 exp = 0xFF;
7921 else
7922 {
7923 exp = exp - 1023 + 127;
7924 if (exp >= 0xFF)
7925 {
7926 /* Infinity. */
7927 exp = 0x7F;
7928 mantissa = 0;
7929 }
7930 else if (exp < 0)
7931 {
7932 /* No denormalized numbers. */
7933 exp = 0;
7934 mantissa = 0;
7935 }
7936 }
7937 mantissa >>= 29;
7938 return (sign << 31) | (exp << 23) | mantissa;
7939 }
7940 #endif /* BFD_HOST_64_BIT */
7941
7942 enum lit_type
7943 {
7944 CONST_THUMB,
7945 CONST_ARM,
7946 CONST_VEC
7947 };
7948
7949 static void do_vfp_nsyn_opcode (const char *);
7950
7951 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
7952 Determine whether it can be performed with a move instruction; if
7953 it can, convert inst.instruction to that move instruction and
7954 return TRUE; if it can't, convert inst.instruction to a literal-pool
7955 load and return FALSE. If this is not a valid thing to do in the
7956 current context, set inst.error and return TRUE.
7957
7958 inst.operands[i] describes the destination register. */
7959
7960 static bfd_boolean
7961 move_or_literal_pool (int i, enum lit_type t, bfd_boolean mode_3)
7962 {
7963 unsigned long tbit;
7964 bfd_boolean thumb_p = (t == CONST_THUMB);
7965 bfd_boolean arm_p = (t == CONST_ARM);
7966
7967 if (thumb_p)
7968 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7969 else
7970 tbit = LOAD_BIT;
7971
7972 if ((inst.instruction & tbit) == 0)
7973 {
7974 inst.error = _("invalid pseudo operation");
7975 return TRUE;
7976 }
7977
7978 if (inst.reloc.exp.X_op != O_constant
7979 && inst.reloc.exp.X_op != O_symbol
7980 && inst.reloc.exp.X_op != O_big)
7981 {
7982 inst.error = _("constant expression expected");
7983 return TRUE;
7984 }
7985
7986 if (inst.reloc.exp.X_op == O_constant
7987 || inst.reloc.exp.X_op == O_big)
7988 {
7989 #if defined BFD_HOST_64_BIT
7990 bfd_int64_t v;
7991 #else
7992 offsetT v;
7993 #endif
7994 if (inst.reloc.exp.X_op == O_big)
7995 {
7996 LITTLENUM_TYPE w[X_PRECISION];
7997 LITTLENUM_TYPE * l;
7998
7999 if (inst.reloc.exp.X_add_number == -1)
8000 {
8001 gen_to_words (w, X_PRECISION, E_PRECISION);
8002 l = w;
8003 /* FIXME: Should we check words w[2..5] ? */
8004 }
8005 else
8006 l = generic_bignum;
8007
8008 #if defined BFD_HOST_64_BIT
8009 v =
8010 ((((((((bfd_int64_t) l[3] & LITTLENUM_MASK)
8011 << LITTLENUM_NUMBER_OF_BITS)
8012 | ((bfd_int64_t) l[2] & LITTLENUM_MASK))
8013 << LITTLENUM_NUMBER_OF_BITS)
8014 | ((bfd_int64_t) l[1] & LITTLENUM_MASK))
8015 << LITTLENUM_NUMBER_OF_BITS)
8016 | ((bfd_int64_t) l[0] & LITTLENUM_MASK));
8017 #else
8018 v = ((l[1] & LITTLENUM_MASK) << LITTLENUM_NUMBER_OF_BITS)
8019 | (l[0] & LITTLENUM_MASK);
8020 #endif
8021 }
8022 else
8023 v = inst.reloc.exp.X_add_number;
8024
8025 if (!inst.operands[i].issingle)
8026 {
8027 if (thumb_p)
8028 {
8029 /* LDR should not use lead in a flag-setting instruction being
8030 chosen so we do not check whether movs can be used. */
8031
8032 if ((ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
8033 || ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8034 && inst.operands[i].reg != 13
8035 && inst.operands[i].reg != 15)
8036 {
8037 /* Check if on thumb2 it can be done with a mov.w, mvn or
8038 movw instruction. */
8039 unsigned int newimm;
8040 bfd_boolean isNegated;
8041
8042 newimm = encode_thumb32_immediate (v);
8043 if (newimm != (unsigned int) FAIL)
8044 isNegated = FALSE;
8045 else
8046 {
8047 newimm = encode_thumb32_immediate (~v);
8048 if (newimm != (unsigned int) FAIL)
8049 isNegated = TRUE;
8050 }
8051
8052 /* The number can be loaded with a mov.w or mvn
8053 instruction. */
8054 if (newimm != (unsigned int) FAIL
8055 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
8056 {
8057 inst.instruction = (0xf04f0000 /* MOV.W. */
8058 | (inst.operands[i].reg << 8));
8059 /* Change to MOVN. */
8060 inst.instruction |= (isNegated ? 0x200000 : 0);
8061 inst.instruction |= (newimm & 0x800) << 15;
8062 inst.instruction |= (newimm & 0x700) << 4;
8063 inst.instruction |= (newimm & 0x0ff);
8064 return TRUE;
8065 }
8066 /* The number can be loaded with a movw instruction. */
8067 else if ((v & ~0xFFFF) == 0
8068 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m))
8069 {
8070 int imm = v & 0xFFFF;
8071
8072 inst.instruction = 0xf2400000; /* MOVW. */
8073 inst.instruction |= (inst.operands[i].reg << 8);
8074 inst.instruction |= (imm & 0xf000) << 4;
8075 inst.instruction |= (imm & 0x0800) << 15;
8076 inst.instruction |= (imm & 0x0700) << 4;
8077 inst.instruction |= (imm & 0x00ff);
8078 return TRUE;
8079 }
8080 }
8081 }
8082 else if (arm_p)
8083 {
8084 int value = encode_arm_immediate (v);
8085
8086 if (value != FAIL)
8087 {
8088 /* This can be done with a mov instruction. */
8089 inst.instruction &= LITERAL_MASK;
8090 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
8091 inst.instruction |= value & 0xfff;
8092 return TRUE;
8093 }
8094
8095 value = encode_arm_immediate (~ v);
8096 if (value != FAIL)
8097 {
8098 /* This can be done with a mvn instruction. */
8099 inst.instruction &= LITERAL_MASK;
8100 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
8101 inst.instruction |= value & 0xfff;
8102 return TRUE;
8103 }
8104 }
8105 else if (t == CONST_VEC && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
8106 {
8107 int op = 0;
8108 unsigned immbits = 0;
8109 unsigned immlo = inst.operands[1].imm;
8110 unsigned immhi = inst.operands[1].regisimm
8111 ? inst.operands[1].reg
8112 : inst.reloc.exp.X_unsigned
8113 ? 0
8114 : ((bfd_int64_t)((int) immlo)) >> 32;
8115 int cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8116 &op, 64, NT_invtype);
8117
8118 if (cmode == FAIL)
8119 {
8120 neon_invert_size (&immlo, &immhi, 64);
8121 op = !op;
8122 cmode = neon_cmode_for_move_imm (immlo, immhi, FALSE, &immbits,
8123 &op, 64, NT_invtype);
8124 }
8125
8126 if (cmode != FAIL)
8127 {
8128 inst.instruction = (inst.instruction & VLDR_VMOV_SAME)
8129 | (1 << 23)
8130 | (cmode << 8)
8131 | (op << 5)
8132 | (1 << 4);
8133
8134 /* Fill other bits in vmov encoding for both thumb and arm. */
8135 if (thumb_mode)
8136 inst.instruction |= (0x7U << 29) | (0xF << 24);
8137 else
8138 inst.instruction |= (0xFU << 28) | (0x1 << 25);
8139 neon_write_immbits (immbits);
8140 return TRUE;
8141 }
8142 }
8143 }
8144
8145 if (t == CONST_VEC)
8146 {
8147 /* Check if vldr Rx, =constant could be optimized to vmov Rx, #constant. */
8148 if (inst.operands[i].issingle
8149 && is_quarter_float (inst.operands[1].imm)
8150 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3xd))
8151 {
8152 inst.operands[1].imm =
8153 neon_qfloat_bits (v);
8154 do_vfp_nsyn_opcode ("fconsts");
8155 return TRUE;
8156 }
8157
8158 /* If our host does not support a 64-bit type then we cannot perform
8159 the following optimization. This mean that there will be a
8160 discrepancy between the output produced by an assembler built for
8161 a 32-bit-only host and the output produced from a 64-bit host, but
8162 this cannot be helped. */
8163 #if defined BFD_HOST_64_BIT
8164 else if (!inst.operands[1].issingle
8165 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
8166 {
8167 if (is_double_a_single (v)
8168 && is_quarter_float (double_to_single (v)))
8169 {
8170 inst.operands[1].imm =
8171 neon_qfloat_bits (double_to_single (v));
8172 do_vfp_nsyn_opcode ("fconstd");
8173 return TRUE;
8174 }
8175 }
8176 #endif
8177 }
8178 }
8179
8180 if (add_to_lit_pool ((!inst.operands[i].isvec
8181 || inst.operands[i].issingle) ? 4 : 8) == FAIL)
8182 return TRUE;
8183
8184 inst.operands[1].reg = REG_PC;
8185 inst.operands[1].isreg = 1;
8186 inst.operands[1].preind = 1;
8187 inst.reloc.pc_rel = 1;
8188 inst.reloc.type = (thumb_p
8189 ? BFD_RELOC_ARM_THUMB_OFFSET
8190 : (mode_3
8191 ? BFD_RELOC_ARM_HWLITERAL
8192 : BFD_RELOC_ARM_LITERAL));
8193 return FALSE;
8194 }
8195
8196 /* inst.operands[i] was set up by parse_address. Encode it into an
8197 ARM-format instruction. Reject all forms which cannot be encoded
8198 into a coprocessor load/store instruction. If wb_ok is false,
8199 reject use of writeback; if unind_ok is false, reject use of
8200 unindexed addressing. If reloc_override is not 0, use it instead
8201 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
8202 (in which case it is preserved). */
8203
8204 static int
8205 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
8206 {
8207 if (!inst.operands[i].isreg)
8208 {
8209 /* PR 18256 */
8210 if (! inst.operands[0].isvec)
8211 {
8212 inst.error = _("invalid co-processor operand");
8213 return FAIL;
8214 }
8215 if (move_or_literal_pool (0, CONST_VEC, /*mode_3=*/FALSE))
8216 return SUCCESS;
8217 }
8218
8219 inst.instruction |= inst.operands[i].reg << 16;
8220
8221 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
8222
8223 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
8224 {
8225 gas_assert (!inst.operands[i].writeback);
8226 if (!unind_ok)
8227 {
8228 inst.error = _("instruction does not support unindexed addressing");
8229 return FAIL;
8230 }
8231 inst.instruction |= inst.operands[i].imm;
8232 inst.instruction |= INDEX_UP;
8233 return SUCCESS;
8234 }
8235
8236 if (inst.operands[i].preind)
8237 inst.instruction |= PRE_INDEX;
8238
8239 if (inst.operands[i].writeback)
8240 {
8241 if (inst.operands[i].reg == REG_PC)
8242 {
8243 inst.error = _("pc may not be used with write-back");
8244 return FAIL;
8245 }
8246 if (!wb_ok)
8247 {
8248 inst.error = _("instruction does not support writeback");
8249 return FAIL;
8250 }
8251 inst.instruction |= WRITE_BACK;
8252 }
8253
8254 if (reloc_override)
8255 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
8256 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
8257 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
8258 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
8259 {
8260 if (thumb_mode)
8261 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
8262 else
8263 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
8264 }
8265
8266 /* Prefer + for zero encoded value. */
8267 if (!inst.operands[i].negative)
8268 inst.instruction |= INDEX_UP;
8269
8270 return SUCCESS;
8271 }
8272
8273 /* Functions for instruction encoding, sorted by sub-architecture.
8274 First some generics; their names are taken from the conventional
8275 bit positions for register arguments in ARM format instructions. */
8276
8277 static void
8278 do_noargs (void)
8279 {
8280 }
8281
8282 static void
8283 do_rd (void)
8284 {
8285 inst.instruction |= inst.operands[0].reg << 12;
8286 }
8287
8288 static void
8289 do_rn (void)
8290 {
8291 inst.instruction |= inst.operands[0].reg << 16;
8292 }
8293
8294 static void
8295 do_rd_rm (void)
8296 {
8297 inst.instruction |= inst.operands[0].reg << 12;
8298 inst.instruction |= inst.operands[1].reg;
8299 }
8300
8301 static void
8302 do_rm_rn (void)
8303 {
8304 inst.instruction |= inst.operands[0].reg;
8305 inst.instruction |= inst.operands[1].reg << 16;
8306 }
8307
8308 static void
8309 do_rd_rn (void)
8310 {
8311 inst.instruction |= inst.operands[0].reg << 12;
8312 inst.instruction |= inst.operands[1].reg << 16;
8313 }
8314
8315 static void
8316 do_rn_rd (void)
8317 {
8318 inst.instruction |= inst.operands[0].reg << 16;
8319 inst.instruction |= inst.operands[1].reg << 12;
8320 }
8321
8322 static void
8323 do_tt (void)
8324 {
8325 inst.instruction |= inst.operands[0].reg << 8;
8326 inst.instruction |= inst.operands[1].reg << 16;
8327 }
8328
8329 static bfd_boolean
8330 check_obsolete (const arm_feature_set *feature, const char *msg)
8331 {
8332 if (ARM_CPU_IS_ANY (cpu_variant))
8333 {
8334 as_tsktsk ("%s", msg);
8335 return TRUE;
8336 }
8337 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
8338 {
8339 as_bad ("%s", msg);
8340 return TRUE;
8341 }
8342
8343 return FALSE;
8344 }
8345
8346 static void
8347 do_rd_rm_rn (void)
8348 {
8349 unsigned Rn = inst.operands[2].reg;
8350 /* Enforce restrictions on SWP instruction. */
8351 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
8352 {
8353 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
8354 _("Rn must not overlap other operands"));
8355
8356 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
8357 */
8358 if (!check_obsolete (&arm_ext_v8,
8359 _("swp{b} use is obsoleted for ARMv8 and later"))
8360 && warn_on_deprecated
8361 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
8362 as_tsktsk (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
8363 }
8364
8365 inst.instruction |= inst.operands[0].reg << 12;
8366 inst.instruction |= inst.operands[1].reg;
8367 inst.instruction |= Rn << 16;
8368 }
8369
8370 static void
8371 do_rd_rn_rm (void)
8372 {
8373 inst.instruction |= inst.operands[0].reg << 12;
8374 inst.instruction |= inst.operands[1].reg << 16;
8375 inst.instruction |= inst.operands[2].reg;
8376 }
8377
8378 static void
8379 do_rm_rd_rn (void)
8380 {
8381 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
8382 constraint (((inst.reloc.exp.X_op != O_constant
8383 && inst.reloc.exp.X_op != O_illegal)
8384 || inst.reloc.exp.X_add_number != 0),
8385 BAD_ADDR_MODE);
8386 inst.instruction |= inst.operands[0].reg;
8387 inst.instruction |= inst.operands[1].reg << 12;
8388 inst.instruction |= inst.operands[2].reg << 16;
8389 }
8390
8391 static void
8392 do_imm0 (void)
8393 {
8394 inst.instruction |= inst.operands[0].imm;
8395 }
8396
8397 static void
8398 do_rd_cpaddr (void)
8399 {
8400 inst.instruction |= inst.operands[0].reg << 12;
8401 encode_arm_cp_address (1, TRUE, TRUE, 0);
8402 }
8403
8404 /* ARM instructions, in alphabetical order by function name (except
8405 that wrapper functions appear immediately after the function they
8406 wrap). */
8407
8408 /* This is a pseudo-op of the form "adr rd, label" to be converted
8409 into a relative address of the form "add rd, pc, #label-.-8". */
8410
8411 static void
8412 do_adr (void)
8413 {
8414 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
8415
8416 /* Frag hacking will turn this into a sub instruction if the offset turns
8417 out to be negative. */
8418 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8419 inst.reloc.pc_rel = 1;
8420 inst.reloc.exp.X_add_number -= 8;
8421
8422 if (inst.reloc.exp.X_op == O_symbol
8423 && inst.reloc.exp.X_add_symbol != NULL
8424 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8425 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8426 inst.reloc.exp.X_add_number += 1;
8427 }
8428
8429 /* This is a pseudo-op of the form "adrl rd, label" to be converted
8430 into a relative address of the form:
8431 add rd, pc, #low(label-.-8)"
8432 add rd, rd, #high(label-.-8)" */
8433
8434 static void
8435 do_adrl (void)
8436 {
8437 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
8438
8439 /* Frag hacking will turn this into a sub instruction if the offset turns
8440 out to be negative. */
8441 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
8442 inst.reloc.pc_rel = 1;
8443 inst.size = INSN_SIZE * 2;
8444 inst.reloc.exp.X_add_number -= 8;
8445
8446 if (inst.reloc.exp.X_op == O_symbol
8447 && inst.reloc.exp.X_add_symbol != NULL
8448 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8449 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8450 inst.reloc.exp.X_add_number += 1;
8451 }
8452
8453 static void
8454 do_arit (void)
8455 {
8456 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
8457 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
8458 THUMB1_RELOC_ONLY);
8459 if (!inst.operands[1].present)
8460 inst.operands[1].reg = inst.operands[0].reg;
8461 inst.instruction |= inst.operands[0].reg << 12;
8462 inst.instruction |= inst.operands[1].reg << 16;
8463 encode_arm_shifter_operand (2);
8464 }
8465
8466 static void
8467 do_barrier (void)
8468 {
8469 if (inst.operands[0].present)
8470 inst.instruction |= inst.operands[0].imm;
8471 else
8472 inst.instruction |= 0xf;
8473 }
8474
8475 static void
8476 do_bfc (void)
8477 {
8478 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8479 constraint (msb > 32, _("bit-field extends past end of register"));
8480 /* The instruction encoding stores the LSB and MSB,
8481 not the LSB and width. */
8482 inst.instruction |= inst.operands[0].reg << 12;
8483 inst.instruction |= inst.operands[1].imm << 7;
8484 inst.instruction |= (msb - 1) << 16;
8485 }
8486
8487 static void
8488 do_bfi (void)
8489 {
8490 unsigned int msb;
8491
8492 /* #0 in second position is alternative syntax for bfc, which is
8493 the same instruction but with REG_PC in the Rm field. */
8494 if (!inst.operands[1].isreg)
8495 inst.operands[1].reg = REG_PC;
8496
8497 msb = inst.operands[2].imm + inst.operands[3].imm;
8498 constraint (msb > 32, _("bit-field extends past end of register"));
8499 /* The instruction encoding stores the LSB and MSB,
8500 not the LSB and width. */
8501 inst.instruction |= inst.operands[0].reg << 12;
8502 inst.instruction |= inst.operands[1].reg;
8503 inst.instruction |= inst.operands[2].imm << 7;
8504 inst.instruction |= (msb - 1) << 16;
8505 }
8506
8507 static void
8508 do_bfx (void)
8509 {
8510 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8511 _("bit-field extends past end of register"));
8512 inst.instruction |= inst.operands[0].reg << 12;
8513 inst.instruction |= inst.operands[1].reg;
8514 inst.instruction |= inst.operands[2].imm << 7;
8515 inst.instruction |= (inst.operands[3].imm - 1) << 16;
8516 }
8517
8518 /* ARM V5 breakpoint instruction (argument parse)
8519 BKPT <16 bit unsigned immediate>
8520 Instruction is not conditional.
8521 The bit pattern given in insns[] has the COND_ALWAYS condition,
8522 and it is an error if the caller tried to override that. */
8523
8524 static void
8525 do_bkpt (void)
8526 {
8527 /* Top 12 of 16 bits to bits 19:8. */
8528 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
8529
8530 /* Bottom 4 of 16 bits to bits 3:0. */
8531 inst.instruction |= inst.operands[0].imm & 0xf;
8532 }
8533
8534 static void
8535 encode_branch (int default_reloc)
8536 {
8537 if (inst.operands[0].hasreloc)
8538 {
8539 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
8540 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
8541 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
8542 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
8543 ? BFD_RELOC_ARM_PLT32
8544 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
8545 }
8546 else
8547 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
8548 inst.reloc.pc_rel = 1;
8549 }
8550
8551 static void
8552 do_branch (void)
8553 {
8554 #ifdef OBJ_ELF
8555 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8556 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8557 else
8558 #endif
8559 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8560 }
8561
8562 static void
8563 do_bl (void)
8564 {
8565 #ifdef OBJ_ELF
8566 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8567 {
8568 if (inst.cond == COND_ALWAYS)
8569 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
8570 else
8571 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
8572 }
8573 else
8574 #endif
8575 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
8576 }
8577
8578 /* ARM V5 branch-link-exchange instruction (argument parse)
8579 BLX <target_addr> ie BLX(1)
8580 BLX{<condition>} <Rm> ie BLX(2)
8581 Unfortunately, there are two different opcodes for this mnemonic.
8582 So, the insns[].value is not used, and the code here zaps values
8583 into inst.instruction.
8584 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
8585
8586 static void
8587 do_blx (void)
8588 {
8589 if (inst.operands[0].isreg)
8590 {
8591 /* Arg is a register; the opcode provided by insns[] is correct.
8592 It is not illegal to do "blx pc", just useless. */
8593 if (inst.operands[0].reg == REG_PC)
8594 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
8595
8596 inst.instruction |= inst.operands[0].reg;
8597 }
8598 else
8599 {
8600 /* Arg is an address; this instruction cannot be executed
8601 conditionally, and the opcode must be adjusted.
8602 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
8603 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
8604 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8605 inst.instruction = 0xfa000000;
8606 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
8607 }
8608 }
8609
8610 static void
8611 do_bx (void)
8612 {
8613 bfd_boolean want_reloc;
8614
8615 if (inst.operands[0].reg == REG_PC)
8616 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
8617
8618 inst.instruction |= inst.operands[0].reg;
8619 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
8620 it is for ARMv4t or earlier. */
8621 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
8622 if (!ARM_FEATURE_ZERO (selected_object_arch)
8623 && !ARM_CPU_HAS_FEATURE (selected_object_arch, arm_ext_v5))
8624 want_reloc = TRUE;
8625
8626 #ifdef OBJ_ELF
8627 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
8628 #endif
8629 want_reloc = FALSE;
8630
8631 if (want_reloc)
8632 inst.reloc.type = BFD_RELOC_ARM_V4BX;
8633 }
8634
8635
8636 /* ARM v5TEJ. Jump to Jazelle code. */
8637
8638 static void
8639 do_bxj (void)
8640 {
8641 if (inst.operands[0].reg == REG_PC)
8642 as_tsktsk (_("use of r15 in bxj is not really useful"));
8643
8644 inst.instruction |= inst.operands[0].reg;
8645 }
8646
8647 /* Co-processor data operation:
8648 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
8649 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
8650 static void
8651 do_cdp (void)
8652 {
8653 inst.instruction |= inst.operands[0].reg << 8;
8654 inst.instruction |= inst.operands[1].imm << 20;
8655 inst.instruction |= inst.operands[2].reg << 12;
8656 inst.instruction |= inst.operands[3].reg << 16;
8657 inst.instruction |= inst.operands[4].reg;
8658 inst.instruction |= inst.operands[5].imm << 5;
8659 }
8660
8661 static void
8662 do_cmp (void)
8663 {
8664 inst.instruction |= inst.operands[0].reg << 16;
8665 encode_arm_shifter_operand (1);
8666 }
8667
8668 /* Transfer between coprocessor and ARM registers.
8669 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
8670 MRC2
8671 MCR{cond}
8672 MCR2
8673
8674 No special properties. */
8675
8676 struct deprecated_coproc_regs_s
8677 {
8678 unsigned cp;
8679 int opc1;
8680 unsigned crn;
8681 unsigned crm;
8682 int opc2;
8683 arm_feature_set deprecated;
8684 arm_feature_set obsoleted;
8685 const char *dep_msg;
8686 const char *obs_msg;
8687 };
8688
8689 #define DEPR_ACCESS_V8 \
8690 N_("This coprocessor register access is deprecated in ARMv8")
8691
8692 /* Table of all deprecated coprocessor registers. */
8693 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
8694 {
8695 {15, 0, 7, 10, 5, /* CP15DMB. */
8696 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8697 DEPR_ACCESS_V8, NULL},
8698 {15, 0, 7, 10, 4, /* CP15DSB. */
8699 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8700 DEPR_ACCESS_V8, NULL},
8701 {15, 0, 7, 5, 4, /* CP15ISB. */
8702 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8703 DEPR_ACCESS_V8, NULL},
8704 {14, 6, 1, 0, 0, /* TEEHBR. */
8705 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8706 DEPR_ACCESS_V8, NULL},
8707 {14, 6, 0, 0, 0, /* TEECR. */
8708 ARM_FEATURE_CORE_LOW (ARM_EXT_V8), ARM_ARCH_NONE,
8709 DEPR_ACCESS_V8, NULL},
8710 };
8711
8712 #undef DEPR_ACCESS_V8
8713
8714 static const size_t deprecated_coproc_reg_count =
8715 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
8716
8717 static void
8718 do_co_reg (void)
8719 {
8720 unsigned Rd;
8721 size_t i;
8722
8723 Rd = inst.operands[2].reg;
8724 if (thumb_mode)
8725 {
8726 if (inst.instruction == 0xee000010
8727 || inst.instruction == 0xfe000010)
8728 /* MCR, MCR2 */
8729 reject_bad_reg (Rd);
8730 else if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
8731 /* MRC, MRC2 */
8732 constraint (Rd == REG_SP, BAD_SP);
8733 }
8734 else
8735 {
8736 /* MCR */
8737 if (inst.instruction == 0xe000010)
8738 constraint (Rd == REG_PC, BAD_PC);
8739 }
8740
8741 for (i = 0; i < deprecated_coproc_reg_count; ++i)
8742 {
8743 const struct deprecated_coproc_regs_s *r =
8744 deprecated_coproc_regs + i;
8745
8746 if (inst.operands[0].reg == r->cp
8747 && inst.operands[1].imm == r->opc1
8748 && inst.operands[3].reg == r->crn
8749 && inst.operands[4].reg == r->crm
8750 && inst.operands[5].imm == r->opc2)
8751 {
8752 if (! ARM_CPU_IS_ANY (cpu_variant)
8753 && warn_on_deprecated
8754 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
8755 as_tsktsk ("%s", r->dep_msg);
8756 }
8757 }
8758
8759 inst.instruction |= inst.operands[0].reg << 8;
8760 inst.instruction |= inst.operands[1].imm << 21;
8761 inst.instruction |= Rd << 12;
8762 inst.instruction |= inst.operands[3].reg << 16;
8763 inst.instruction |= inst.operands[4].reg;
8764 inst.instruction |= inst.operands[5].imm << 5;
8765 }
8766
8767 /* Transfer between coprocessor register and pair of ARM registers.
8768 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
8769 MCRR2
8770 MRRC{cond}
8771 MRRC2
8772
8773 Two XScale instructions are special cases of these:
8774
8775 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
8776 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
8777
8778 Result unpredictable if Rd or Rn is R15. */
8779
8780 static void
8781 do_co_reg2c (void)
8782 {
8783 unsigned Rd, Rn;
8784
8785 Rd = inst.operands[2].reg;
8786 Rn = inst.operands[3].reg;
8787
8788 if (thumb_mode)
8789 {
8790 reject_bad_reg (Rd);
8791 reject_bad_reg (Rn);
8792 }
8793 else
8794 {
8795 constraint (Rd == REG_PC, BAD_PC);
8796 constraint (Rn == REG_PC, BAD_PC);
8797 }
8798
8799 /* Only check the MRRC{2} variants. */
8800 if ((inst.instruction & 0x0FF00000) == 0x0C500000)
8801 {
8802 /* If Rd == Rn, error that the operation is
8803 unpredictable (example MRRC p3,#1,r1,r1,c4). */
8804 constraint (Rd == Rn, BAD_OVERLAP);
8805 }
8806
8807 inst.instruction |= inst.operands[0].reg << 8;
8808 inst.instruction |= inst.operands[1].imm << 4;
8809 inst.instruction |= Rd << 12;
8810 inst.instruction |= Rn << 16;
8811 inst.instruction |= inst.operands[4].reg;
8812 }
8813
8814 static void
8815 do_cpsi (void)
8816 {
8817 inst.instruction |= inst.operands[0].imm << 6;
8818 if (inst.operands[1].present)
8819 {
8820 inst.instruction |= CPSI_MMOD;
8821 inst.instruction |= inst.operands[1].imm;
8822 }
8823 }
8824
8825 static void
8826 do_dbg (void)
8827 {
8828 inst.instruction |= inst.operands[0].imm;
8829 }
8830
8831 static void
8832 do_div (void)
8833 {
8834 unsigned Rd, Rn, Rm;
8835
8836 Rd = inst.operands[0].reg;
8837 Rn = (inst.operands[1].present
8838 ? inst.operands[1].reg : Rd);
8839 Rm = inst.operands[2].reg;
8840
8841 constraint ((Rd == REG_PC), BAD_PC);
8842 constraint ((Rn == REG_PC), BAD_PC);
8843 constraint ((Rm == REG_PC), BAD_PC);
8844
8845 inst.instruction |= Rd << 16;
8846 inst.instruction |= Rn << 0;
8847 inst.instruction |= Rm << 8;
8848 }
8849
8850 static void
8851 do_it (void)
8852 {
8853 /* There is no IT instruction in ARM mode. We
8854 process it to do the validation as if in
8855 thumb mode, just in case the code gets
8856 assembled for thumb using the unified syntax. */
8857
8858 inst.size = 0;
8859 if (unified_syntax)
8860 {
8861 set_it_insn_type (IT_INSN);
8862 now_it.mask = (inst.instruction & 0xf) | 0x10;
8863 now_it.cc = inst.operands[0].imm;
8864 }
8865 }
8866
8867 /* If there is only one register in the register list,
8868 then return its register number. Otherwise return -1. */
8869 static int
8870 only_one_reg_in_list (int range)
8871 {
8872 int i = ffs (range) - 1;
8873 return (i > 15 || range != (1 << i)) ? -1 : i;
8874 }
8875
8876 static void
8877 encode_ldmstm(int from_push_pop_mnem)
8878 {
8879 int base_reg = inst.operands[0].reg;
8880 int range = inst.operands[1].imm;
8881 int one_reg;
8882
8883 inst.instruction |= base_reg << 16;
8884 inst.instruction |= range;
8885
8886 if (inst.operands[1].writeback)
8887 inst.instruction |= LDM_TYPE_2_OR_3;
8888
8889 if (inst.operands[0].writeback)
8890 {
8891 inst.instruction |= WRITE_BACK;
8892 /* Check for unpredictable uses of writeback. */
8893 if (inst.instruction & LOAD_BIT)
8894 {
8895 /* Not allowed in LDM type 2. */
8896 if ((inst.instruction & LDM_TYPE_2_OR_3)
8897 && ((range & (1 << REG_PC)) == 0))
8898 as_warn (_("writeback of base register is UNPREDICTABLE"));
8899 /* Only allowed if base reg not in list for other types. */
8900 else if (range & (1 << base_reg))
8901 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
8902 }
8903 else /* STM. */
8904 {
8905 /* Not allowed for type 2. */
8906 if (inst.instruction & LDM_TYPE_2_OR_3)
8907 as_warn (_("writeback of base register is UNPREDICTABLE"));
8908 /* Only allowed if base reg not in list, or first in list. */
8909 else if ((range & (1 << base_reg))
8910 && (range & ((1 << base_reg) - 1)))
8911 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
8912 }
8913 }
8914
8915 /* If PUSH/POP has only one register, then use the A2 encoding. */
8916 one_reg = only_one_reg_in_list (range);
8917 if (from_push_pop_mnem && one_reg >= 0)
8918 {
8919 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
8920
8921 if (is_push && one_reg == 13 /* SP */)
8922 /* PR 22483: The A2 encoding cannot be used when
8923 pushing the stack pointer as this is UNPREDICTABLE. */
8924 return;
8925
8926 inst.instruction &= A_COND_MASK;
8927 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
8928 inst.instruction |= one_reg << 12;
8929 }
8930 }
8931
8932 static void
8933 do_ldmstm (void)
8934 {
8935 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
8936 }
8937
8938 /* ARMv5TE load-consecutive (argument parse)
8939 Mode is like LDRH.
8940
8941 LDRccD R, mode
8942 STRccD R, mode. */
8943
8944 static void
8945 do_ldrd (void)
8946 {
8947 constraint (inst.operands[0].reg % 2 != 0,
8948 _("first transfer register must be even"));
8949 constraint (inst.operands[1].present
8950 && inst.operands[1].reg != inst.operands[0].reg + 1,
8951 _("can only transfer two consecutive registers"));
8952 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8953 constraint (!inst.operands[2].isreg, _("'[' expected"));
8954
8955 if (!inst.operands[1].present)
8956 inst.operands[1].reg = inst.operands[0].reg + 1;
8957
8958 /* encode_arm_addr_mode_3 will diagnose overlap between the base
8959 register and the first register written; we have to diagnose
8960 overlap between the base and the second register written here. */
8961
8962 if (inst.operands[2].reg == inst.operands[1].reg
8963 && (inst.operands[2].writeback || inst.operands[2].postind))
8964 as_warn (_("base register written back, and overlaps "
8965 "second transfer register"));
8966
8967 if (!(inst.instruction & V4_STR_BIT))
8968 {
8969 /* For an index-register load, the index register must not overlap the
8970 destination (even if not write-back). */
8971 if (inst.operands[2].immisreg
8972 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
8973 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
8974 as_warn (_("index register overlaps transfer register"));
8975 }
8976 inst.instruction |= inst.operands[0].reg << 12;
8977 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
8978 }
8979
8980 static void
8981 do_ldrex (void)
8982 {
8983 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8984 || inst.operands[1].postind || inst.operands[1].writeback
8985 || inst.operands[1].immisreg || inst.operands[1].shifted
8986 || inst.operands[1].negative
8987 /* This can arise if the programmer has written
8988 strex rN, rM, foo
8989 or if they have mistakenly used a register name as the last
8990 operand, eg:
8991 strex rN, rM, rX
8992 It is very difficult to distinguish between these two cases
8993 because "rX" might actually be a label. ie the register
8994 name has been occluded by a symbol of the same name. So we
8995 just generate a general 'bad addressing mode' type error
8996 message and leave it up to the programmer to discover the
8997 true cause and fix their mistake. */
8998 || (inst.operands[1].reg == REG_PC),
8999 BAD_ADDR_MODE);
9000
9001 constraint (inst.reloc.exp.X_op != O_constant
9002 || inst.reloc.exp.X_add_number != 0,
9003 _("offset must be zero in ARM encoding"));
9004
9005 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9006
9007 inst.instruction |= inst.operands[0].reg << 12;
9008 inst.instruction |= inst.operands[1].reg << 16;
9009 inst.reloc.type = BFD_RELOC_UNUSED;
9010 }
9011
9012 static void
9013 do_ldrexd (void)
9014 {
9015 constraint (inst.operands[0].reg % 2 != 0,
9016 _("even register required"));
9017 constraint (inst.operands[1].present
9018 && inst.operands[1].reg != inst.operands[0].reg + 1,
9019 _("can only load two consecutive registers"));
9020 /* If op 1 were present and equal to PC, this function wouldn't
9021 have been called in the first place. */
9022 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
9023
9024 inst.instruction |= inst.operands[0].reg << 12;
9025 inst.instruction |= inst.operands[2].reg << 16;
9026 }
9027
9028 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
9029 which is not a multiple of four is UNPREDICTABLE. */
9030 static void
9031 check_ldr_r15_aligned (void)
9032 {
9033 constraint (!(inst.operands[1].immisreg)
9034 && (inst.operands[0].reg == REG_PC
9035 && inst.operands[1].reg == REG_PC
9036 && (inst.reloc.exp.X_add_number & 0x3)),
9037 _("ldr to register 15 must be 4-byte aligned"));
9038 }
9039
9040 static void
9041 do_ldst (void)
9042 {
9043 inst.instruction |= inst.operands[0].reg << 12;
9044 if (!inst.operands[1].isreg)
9045 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/FALSE))
9046 return;
9047 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
9048 check_ldr_r15_aligned ();
9049 }
9050
9051 static void
9052 do_ldstt (void)
9053 {
9054 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
9055 reject [Rn,...]. */
9056 if (inst.operands[1].preind)
9057 {
9058 constraint (inst.reloc.exp.X_op != O_constant
9059 || inst.reloc.exp.X_add_number != 0,
9060 _("this instruction requires a post-indexed address"));
9061
9062 inst.operands[1].preind = 0;
9063 inst.operands[1].postind = 1;
9064 inst.operands[1].writeback = 1;
9065 }
9066 inst.instruction |= inst.operands[0].reg << 12;
9067 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
9068 }
9069
9070 /* Halfword and signed-byte load/store operations. */
9071
9072 static void
9073 do_ldstv4 (void)
9074 {
9075 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9076 inst.instruction |= inst.operands[0].reg << 12;
9077 if (!inst.operands[1].isreg)
9078 if (move_or_literal_pool (0, CONST_ARM, /*mode_3=*/TRUE))
9079 return;
9080 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
9081 }
9082
9083 static void
9084 do_ldsttv4 (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.reloc.exp.X_op != O_constant
9091 || inst.reloc.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_3 (1, /*is_t=*/TRUE);
9100 }
9101
9102 /* Co-processor register load/store.
9103 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
9104 static void
9105 do_lstc (void)
9106 {
9107 inst.instruction |= inst.operands[0].reg << 8;
9108 inst.instruction |= inst.operands[1].reg << 12;
9109 encode_arm_cp_address (2, TRUE, TRUE, 0);
9110 }
9111
9112 static void
9113 do_mlas (void)
9114 {
9115 /* This restriction does not apply to mls (nor to mla in v6 or later). */
9116 if (inst.operands[0].reg == inst.operands[1].reg
9117 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
9118 && !(inst.instruction & 0x00400000))
9119 as_tsktsk (_("Rd and Rm should be different in mla"));
9120
9121 inst.instruction |= inst.operands[0].reg << 16;
9122 inst.instruction |= inst.operands[1].reg;
9123 inst.instruction |= inst.operands[2].reg << 8;
9124 inst.instruction |= inst.operands[3].reg << 12;
9125 }
9126
9127 static void
9128 do_mov (void)
9129 {
9130 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
9131 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
9132 THUMB1_RELOC_ONLY);
9133 inst.instruction |= inst.operands[0].reg << 12;
9134 encode_arm_shifter_operand (1);
9135 }
9136
9137 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
9138 static void
9139 do_mov16 (void)
9140 {
9141 bfd_vma imm;
9142 bfd_boolean top;
9143
9144 top = (inst.instruction & 0x00400000) != 0;
9145 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
9146 _(":lower16: not allowed in this instruction"));
9147 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
9148 _(":upper16: not allowed in this instruction"));
9149 inst.instruction |= inst.operands[0].reg << 12;
9150 if (inst.reloc.type == BFD_RELOC_UNUSED)
9151 {
9152 imm = inst.reloc.exp.X_add_number;
9153 /* The value is in two pieces: 0:11, 16:19. */
9154 inst.instruction |= (imm & 0x00000fff);
9155 inst.instruction |= (imm & 0x0000f000) << 4;
9156 }
9157 }
9158
9159 static int
9160 do_vfp_nsyn_mrs (void)
9161 {
9162 if (inst.operands[0].isvec)
9163 {
9164 if (inst.operands[1].reg != 1)
9165 first_error (_("operand 1 must be FPSCR"));
9166 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
9167 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
9168 do_vfp_nsyn_opcode ("fmstat");
9169 }
9170 else if (inst.operands[1].isvec)
9171 do_vfp_nsyn_opcode ("fmrx");
9172 else
9173 return FAIL;
9174
9175 return SUCCESS;
9176 }
9177
9178 static int
9179 do_vfp_nsyn_msr (void)
9180 {
9181 if (inst.operands[0].isvec)
9182 do_vfp_nsyn_opcode ("fmxr");
9183 else
9184 return FAIL;
9185
9186 return SUCCESS;
9187 }
9188
9189 static void
9190 do_vmrs (void)
9191 {
9192 unsigned Rt = inst.operands[0].reg;
9193
9194 if (thumb_mode && Rt == REG_SP)
9195 {
9196 inst.error = BAD_SP;
9197 return;
9198 }
9199
9200 /* MVFR2 is only valid at ARMv8-A. */
9201 if (inst.operands[1].reg == 5)
9202 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9203 _(BAD_FPU));
9204
9205 /* APSR_ sets isvec. All other refs to PC are illegal. */
9206 if (!inst.operands[0].isvec && Rt == REG_PC)
9207 {
9208 inst.error = BAD_PC;
9209 return;
9210 }
9211
9212 /* If we get through parsing the register name, we just insert the number
9213 generated into the instruction without further validation. */
9214 inst.instruction |= (inst.operands[1].reg << 16);
9215 inst.instruction |= (Rt << 12);
9216 }
9217
9218 static void
9219 do_vmsr (void)
9220 {
9221 unsigned Rt = inst.operands[1].reg;
9222
9223 if (thumb_mode)
9224 reject_bad_reg (Rt);
9225 else if (Rt == REG_PC)
9226 {
9227 inst.error = BAD_PC;
9228 return;
9229 }
9230
9231 /* MVFR2 is only valid for ARMv8-A. */
9232 if (inst.operands[0].reg == 5)
9233 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
9234 _(BAD_FPU));
9235
9236 /* If we get through parsing the register name, we just insert the number
9237 generated into the instruction without further validation. */
9238 inst.instruction |= (inst.operands[0].reg << 16);
9239 inst.instruction |= (Rt << 12);
9240 }
9241
9242 static void
9243 do_mrs (void)
9244 {
9245 unsigned br;
9246
9247 if (do_vfp_nsyn_mrs () == SUCCESS)
9248 return;
9249
9250 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9251 inst.instruction |= inst.operands[0].reg << 12;
9252
9253 if (inst.operands[1].isreg)
9254 {
9255 br = inst.operands[1].reg;
9256 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf0000))
9257 as_bad (_("bad register for mrs"));
9258 }
9259 else
9260 {
9261 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9262 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
9263 != (PSR_c|PSR_f),
9264 _("'APSR', 'CPSR' or 'SPSR' expected"));
9265 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
9266 }
9267
9268 inst.instruction |= br;
9269 }
9270
9271 /* Two possible forms:
9272 "{C|S}PSR_<field>, Rm",
9273 "{C|S}PSR_f, #expression". */
9274
9275 static void
9276 do_msr (void)
9277 {
9278 if (do_vfp_nsyn_msr () == SUCCESS)
9279 return;
9280
9281 inst.instruction |= inst.operands[0].imm;
9282 if (inst.operands[1].isreg)
9283 inst.instruction |= inst.operands[1].reg;
9284 else
9285 {
9286 inst.instruction |= INST_IMMEDIATE;
9287 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
9288 inst.reloc.pc_rel = 0;
9289 }
9290 }
9291
9292 static void
9293 do_mul (void)
9294 {
9295 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
9296
9297 if (!inst.operands[2].present)
9298 inst.operands[2].reg = inst.operands[0].reg;
9299 inst.instruction |= inst.operands[0].reg << 16;
9300 inst.instruction |= inst.operands[1].reg;
9301 inst.instruction |= inst.operands[2].reg << 8;
9302
9303 if (inst.operands[0].reg == inst.operands[1].reg
9304 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9305 as_tsktsk (_("Rd and Rm should be different in mul"));
9306 }
9307
9308 /* Long Multiply Parser
9309 UMULL RdLo, RdHi, Rm, Rs
9310 SMULL RdLo, RdHi, Rm, Rs
9311 UMLAL RdLo, RdHi, Rm, Rs
9312 SMLAL RdLo, RdHi, Rm, Rs. */
9313
9314 static void
9315 do_mull (void)
9316 {
9317 inst.instruction |= inst.operands[0].reg << 12;
9318 inst.instruction |= inst.operands[1].reg << 16;
9319 inst.instruction |= inst.operands[2].reg;
9320 inst.instruction |= inst.operands[3].reg << 8;
9321
9322 /* rdhi and rdlo must be different. */
9323 if (inst.operands[0].reg == inst.operands[1].reg)
9324 as_tsktsk (_("rdhi and rdlo must be different"));
9325
9326 /* rdhi, rdlo and rm must all be different before armv6. */
9327 if ((inst.operands[0].reg == inst.operands[2].reg
9328 || inst.operands[1].reg == inst.operands[2].reg)
9329 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
9330 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
9331 }
9332
9333 static void
9334 do_nop (void)
9335 {
9336 if (inst.operands[0].present
9337 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
9338 {
9339 /* Architectural NOP hints are CPSR sets with no bits selected. */
9340 inst.instruction &= 0xf0000000;
9341 inst.instruction |= 0x0320f000;
9342 if (inst.operands[0].present)
9343 inst.instruction |= inst.operands[0].imm;
9344 }
9345 }
9346
9347 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
9348 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
9349 Condition defaults to COND_ALWAYS.
9350 Error if Rd, Rn or Rm are R15. */
9351
9352 static void
9353 do_pkhbt (void)
9354 {
9355 inst.instruction |= inst.operands[0].reg << 12;
9356 inst.instruction |= inst.operands[1].reg << 16;
9357 inst.instruction |= inst.operands[2].reg;
9358 if (inst.operands[3].present)
9359 encode_arm_shift (3);
9360 }
9361
9362 /* ARM V6 PKHTB (Argument Parse). */
9363
9364 static void
9365 do_pkhtb (void)
9366 {
9367 if (!inst.operands[3].present)
9368 {
9369 /* If the shift specifier is omitted, turn the instruction
9370 into pkhbt rd, rm, rn. */
9371 inst.instruction &= 0xfff00010;
9372 inst.instruction |= inst.operands[0].reg << 12;
9373 inst.instruction |= inst.operands[1].reg;
9374 inst.instruction |= inst.operands[2].reg << 16;
9375 }
9376 else
9377 {
9378 inst.instruction |= inst.operands[0].reg << 12;
9379 inst.instruction |= inst.operands[1].reg << 16;
9380 inst.instruction |= inst.operands[2].reg;
9381 encode_arm_shift (3);
9382 }
9383 }
9384
9385 /* ARMv5TE: Preload-Cache
9386 MP Extensions: Preload for write
9387
9388 PLD(W) <addr_mode>
9389
9390 Syntactically, like LDR with B=1, W=0, L=1. */
9391
9392 static void
9393 do_pld (void)
9394 {
9395 constraint (!inst.operands[0].isreg,
9396 _("'[' expected after PLD mnemonic"));
9397 constraint (inst.operands[0].postind,
9398 _("post-indexed expression used in preload instruction"));
9399 constraint (inst.operands[0].writeback,
9400 _("writeback used in preload instruction"));
9401 constraint (!inst.operands[0].preind,
9402 _("unindexed addressing used in preload instruction"));
9403 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9404 }
9405
9406 /* ARMv7: PLI <addr_mode> */
9407 static void
9408 do_pli (void)
9409 {
9410 constraint (!inst.operands[0].isreg,
9411 _("'[' expected after PLI mnemonic"));
9412 constraint (inst.operands[0].postind,
9413 _("post-indexed expression used in preload instruction"));
9414 constraint (inst.operands[0].writeback,
9415 _("writeback used in preload instruction"));
9416 constraint (!inst.operands[0].preind,
9417 _("unindexed addressing used in preload instruction"));
9418 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
9419 inst.instruction &= ~PRE_INDEX;
9420 }
9421
9422 static void
9423 do_push_pop (void)
9424 {
9425 constraint (inst.operands[0].writeback,
9426 _("push/pop do not support {reglist}^"));
9427 inst.operands[1] = inst.operands[0];
9428 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
9429 inst.operands[0].isreg = 1;
9430 inst.operands[0].writeback = 1;
9431 inst.operands[0].reg = REG_SP;
9432 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
9433 }
9434
9435 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
9436 word at the specified address and the following word
9437 respectively.
9438 Unconditionally executed.
9439 Error if Rn is R15. */
9440
9441 static void
9442 do_rfe (void)
9443 {
9444 inst.instruction |= inst.operands[0].reg << 16;
9445 if (inst.operands[0].writeback)
9446 inst.instruction |= WRITE_BACK;
9447 }
9448
9449 /* ARM V6 ssat (argument parse). */
9450
9451 static void
9452 do_ssat (void)
9453 {
9454 inst.instruction |= inst.operands[0].reg << 12;
9455 inst.instruction |= (inst.operands[1].imm - 1) << 16;
9456 inst.instruction |= inst.operands[2].reg;
9457
9458 if (inst.operands[3].present)
9459 encode_arm_shift (3);
9460 }
9461
9462 /* ARM V6 usat (argument parse). */
9463
9464 static void
9465 do_usat (void)
9466 {
9467 inst.instruction |= inst.operands[0].reg << 12;
9468 inst.instruction |= inst.operands[1].imm << 16;
9469 inst.instruction |= inst.operands[2].reg;
9470
9471 if (inst.operands[3].present)
9472 encode_arm_shift (3);
9473 }
9474
9475 /* ARM V6 ssat16 (argument parse). */
9476
9477 static void
9478 do_ssat16 (void)
9479 {
9480 inst.instruction |= inst.operands[0].reg << 12;
9481 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
9482 inst.instruction |= inst.operands[2].reg;
9483 }
9484
9485 static void
9486 do_usat16 (void)
9487 {
9488 inst.instruction |= inst.operands[0].reg << 12;
9489 inst.instruction |= inst.operands[1].imm << 16;
9490 inst.instruction |= inst.operands[2].reg;
9491 }
9492
9493 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
9494 preserving the other bits.
9495
9496 setend <endian_specifier>, where <endian_specifier> is either
9497 BE or LE. */
9498
9499 static void
9500 do_setend (void)
9501 {
9502 if (warn_on_deprecated
9503 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
9504 as_tsktsk (_("setend use is deprecated for ARMv8"));
9505
9506 if (inst.operands[0].imm)
9507 inst.instruction |= 0x200;
9508 }
9509
9510 static void
9511 do_shift (void)
9512 {
9513 unsigned int Rm = (inst.operands[1].present
9514 ? inst.operands[1].reg
9515 : inst.operands[0].reg);
9516
9517 inst.instruction |= inst.operands[0].reg << 12;
9518 inst.instruction |= Rm;
9519 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
9520 {
9521 inst.instruction |= inst.operands[2].reg << 8;
9522 inst.instruction |= SHIFT_BY_REG;
9523 /* PR 12854: Error on extraneous shifts. */
9524 constraint (inst.operands[2].shifted,
9525 _("extraneous shift as part of operand to shift insn"));
9526 }
9527 else
9528 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
9529 }
9530
9531 static void
9532 do_smc (void)
9533 {
9534 inst.reloc.type = BFD_RELOC_ARM_SMC;
9535 inst.reloc.pc_rel = 0;
9536 }
9537
9538 static void
9539 do_hvc (void)
9540 {
9541 inst.reloc.type = BFD_RELOC_ARM_HVC;
9542 inst.reloc.pc_rel = 0;
9543 }
9544
9545 static void
9546 do_swi (void)
9547 {
9548 inst.reloc.type = BFD_RELOC_ARM_SWI;
9549 inst.reloc.pc_rel = 0;
9550 }
9551
9552 static void
9553 do_setpan (void)
9554 {
9555 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9556 _("selected processor does not support SETPAN instruction"));
9557
9558 inst.instruction |= ((inst.operands[0].imm & 1) << 9);
9559 }
9560
9561 static void
9562 do_t_setpan (void)
9563 {
9564 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_pan),
9565 _("selected processor does not support SETPAN instruction"));
9566
9567 inst.instruction |= (inst.operands[0].imm << 3);
9568 }
9569
9570 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
9571 SMLAxy{cond} Rd,Rm,Rs,Rn
9572 SMLAWy{cond} Rd,Rm,Rs,Rn
9573 Error if any register is R15. */
9574
9575 static void
9576 do_smla (void)
9577 {
9578 inst.instruction |= inst.operands[0].reg << 16;
9579 inst.instruction |= inst.operands[1].reg;
9580 inst.instruction |= inst.operands[2].reg << 8;
9581 inst.instruction |= inst.operands[3].reg << 12;
9582 }
9583
9584 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
9585 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
9586 Error if any register is R15.
9587 Warning if Rdlo == Rdhi. */
9588
9589 static void
9590 do_smlal (void)
9591 {
9592 inst.instruction |= inst.operands[0].reg << 12;
9593 inst.instruction |= inst.operands[1].reg << 16;
9594 inst.instruction |= inst.operands[2].reg;
9595 inst.instruction |= inst.operands[3].reg << 8;
9596
9597 if (inst.operands[0].reg == inst.operands[1].reg)
9598 as_tsktsk (_("rdhi and rdlo must be different"));
9599 }
9600
9601 /* ARM V5E (El Segundo) signed-multiply (argument parse)
9602 SMULxy{cond} Rd,Rm,Rs
9603 Error if any register is R15. */
9604
9605 static void
9606 do_smul (void)
9607 {
9608 inst.instruction |= inst.operands[0].reg << 16;
9609 inst.instruction |= inst.operands[1].reg;
9610 inst.instruction |= inst.operands[2].reg << 8;
9611 }
9612
9613 /* ARM V6 srs (argument parse). The variable fields in the encoding are
9614 the same for both ARM and Thumb-2. */
9615
9616 static void
9617 do_srs (void)
9618 {
9619 int reg;
9620
9621 if (inst.operands[0].present)
9622 {
9623 reg = inst.operands[0].reg;
9624 constraint (reg != REG_SP, _("SRS base register must be r13"));
9625 }
9626 else
9627 reg = REG_SP;
9628
9629 inst.instruction |= reg << 16;
9630 inst.instruction |= inst.operands[1].imm;
9631 if (inst.operands[0].writeback || inst.operands[1].writeback)
9632 inst.instruction |= WRITE_BACK;
9633 }
9634
9635 /* ARM V6 strex (argument parse). */
9636
9637 static void
9638 do_strex (void)
9639 {
9640 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9641 || inst.operands[2].postind || inst.operands[2].writeback
9642 || inst.operands[2].immisreg || inst.operands[2].shifted
9643 || inst.operands[2].negative
9644 /* See comment in do_ldrex(). */
9645 || (inst.operands[2].reg == REG_PC),
9646 BAD_ADDR_MODE);
9647
9648 constraint (inst.operands[0].reg == inst.operands[1].reg
9649 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9650
9651 constraint (inst.reloc.exp.X_op != O_constant
9652 || inst.reloc.exp.X_add_number != 0,
9653 _("offset must be zero in ARM encoding"));
9654
9655 inst.instruction |= inst.operands[0].reg << 12;
9656 inst.instruction |= inst.operands[1].reg;
9657 inst.instruction |= inst.operands[2].reg << 16;
9658 inst.reloc.type = BFD_RELOC_UNUSED;
9659 }
9660
9661 static void
9662 do_t_strexbh (void)
9663 {
9664 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9665 || inst.operands[2].postind || inst.operands[2].writeback
9666 || inst.operands[2].immisreg || inst.operands[2].shifted
9667 || inst.operands[2].negative,
9668 BAD_ADDR_MODE);
9669
9670 constraint (inst.operands[0].reg == inst.operands[1].reg
9671 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9672
9673 do_rm_rd_rn ();
9674 }
9675
9676 static void
9677 do_strexd (void)
9678 {
9679 constraint (inst.operands[1].reg % 2 != 0,
9680 _("even register required"));
9681 constraint (inst.operands[2].present
9682 && inst.operands[2].reg != inst.operands[1].reg + 1,
9683 _("can only store two consecutive registers"));
9684 /* If op 2 were present and equal to PC, this function wouldn't
9685 have been called in the first place. */
9686 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
9687
9688 constraint (inst.operands[0].reg == inst.operands[1].reg
9689 || inst.operands[0].reg == inst.operands[1].reg + 1
9690 || inst.operands[0].reg == inst.operands[3].reg,
9691 BAD_OVERLAP);
9692
9693 inst.instruction |= inst.operands[0].reg << 12;
9694 inst.instruction |= inst.operands[1].reg;
9695 inst.instruction |= inst.operands[3].reg << 16;
9696 }
9697
9698 /* ARM V8 STRL. */
9699 static void
9700 do_stlex (void)
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_rd_rm_rn ();
9706 }
9707
9708 static void
9709 do_t_stlex (void)
9710 {
9711 constraint (inst.operands[0].reg == inst.operands[1].reg
9712 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
9713
9714 do_rm_rd_rn ();
9715 }
9716
9717 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
9718 extends it to 32-bits, and adds the result to a value in another
9719 register. You can specify a rotation by 0, 8, 16, or 24 bits
9720 before extracting the 16-bit value.
9721 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
9722 Condition defaults to COND_ALWAYS.
9723 Error if any register uses R15. */
9724
9725 static void
9726 do_sxtah (void)
9727 {
9728 inst.instruction |= inst.operands[0].reg << 12;
9729 inst.instruction |= inst.operands[1].reg << 16;
9730 inst.instruction |= inst.operands[2].reg;
9731 inst.instruction |= inst.operands[3].imm << 10;
9732 }
9733
9734 /* ARM V6 SXTH.
9735
9736 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
9737 Condition defaults to COND_ALWAYS.
9738 Error if any register uses R15. */
9739
9740 static void
9741 do_sxth (void)
9742 {
9743 inst.instruction |= inst.operands[0].reg << 12;
9744 inst.instruction |= inst.operands[1].reg;
9745 inst.instruction |= inst.operands[2].imm << 10;
9746 }
9747 \f
9748 /* VFP instructions. In a logical order: SP variant first, monad
9749 before dyad, arithmetic then move then load/store. */
9750
9751 static void
9752 do_vfp_sp_monadic (void)
9753 {
9754 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9755 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
9756 }
9757
9758 static void
9759 do_vfp_sp_dyadic (void)
9760 {
9761 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9762 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9763 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
9764 }
9765
9766 static void
9767 do_vfp_sp_compare_z (void)
9768 {
9769 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9770 }
9771
9772 static void
9773 do_vfp_dp_sp_cvt (void)
9774 {
9775 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9776 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
9777 }
9778
9779 static void
9780 do_vfp_sp_dp_cvt (void)
9781 {
9782 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9783 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9784 }
9785
9786 static void
9787 do_vfp_reg_from_sp (void)
9788 {
9789 inst.instruction |= inst.operands[0].reg << 12;
9790 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
9791 }
9792
9793 static void
9794 do_vfp_reg2_from_sp2 (void)
9795 {
9796 constraint (inst.operands[2].imm != 2,
9797 _("only two consecutive VFP SP registers allowed here"));
9798 inst.instruction |= inst.operands[0].reg << 12;
9799 inst.instruction |= inst.operands[1].reg << 16;
9800 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
9801 }
9802
9803 static void
9804 do_vfp_sp_from_reg (void)
9805 {
9806 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
9807 inst.instruction |= inst.operands[1].reg << 12;
9808 }
9809
9810 static void
9811 do_vfp_sp2_from_reg2 (void)
9812 {
9813 constraint (inst.operands[0].imm != 2,
9814 _("only two consecutive VFP SP registers allowed here"));
9815 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
9816 inst.instruction |= inst.operands[1].reg << 12;
9817 inst.instruction |= inst.operands[2].reg << 16;
9818 }
9819
9820 static void
9821 do_vfp_sp_ldst (void)
9822 {
9823 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9824 encode_arm_cp_address (1, FALSE, TRUE, 0);
9825 }
9826
9827 static void
9828 do_vfp_dp_ldst (void)
9829 {
9830 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9831 encode_arm_cp_address (1, FALSE, TRUE, 0);
9832 }
9833
9834
9835 static void
9836 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
9837 {
9838 if (inst.operands[0].writeback)
9839 inst.instruction |= WRITE_BACK;
9840 else
9841 constraint (ldstm_type != VFP_LDSTMIA,
9842 _("this addressing mode requires base-register writeback"));
9843 inst.instruction |= inst.operands[0].reg << 16;
9844 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
9845 inst.instruction |= inst.operands[1].imm;
9846 }
9847
9848 static void
9849 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
9850 {
9851 int count;
9852
9853 if (inst.operands[0].writeback)
9854 inst.instruction |= WRITE_BACK;
9855 else
9856 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
9857 _("this addressing mode requires base-register writeback"));
9858
9859 inst.instruction |= inst.operands[0].reg << 16;
9860 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9861
9862 count = inst.operands[1].imm << 1;
9863 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
9864 count += 1;
9865
9866 inst.instruction |= count;
9867 }
9868
9869 static void
9870 do_vfp_sp_ldstmia (void)
9871 {
9872 vfp_sp_ldstm (VFP_LDSTMIA);
9873 }
9874
9875 static void
9876 do_vfp_sp_ldstmdb (void)
9877 {
9878 vfp_sp_ldstm (VFP_LDSTMDB);
9879 }
9880
9881 static void
9882 do_vfp_dp_ldstmia (void)
9883 {
9884 vfp_dp_ldstm (VFP_LDSTMIA);
9885 }
9886
9887 static void
9888 do_vfp_dp_ldstmdb (void)
9889 {
9890 vfp_dp_ldstm (VFP_LDSTMDB);
9891 }
9892
9893 static void
9894 do_vfp_xp_ldstmia (void)
9895 {
9896 vfp_dp_ldstm (VFP_LDSTMIAX);
9897 }
9898
9899 static void
9900 do_vfp_xp_ldstmdb (void)
9901 {
9902 vfp_dp_ldstm (VFP_LDSTMDBX);
9903 }
9904
9905 static void
9906 do_vfp_dp_rd_rm (void)
9907 {
9908 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9909 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
9910 }
9911
9912 static void
9913 do_vfp_dp_rn_rd (void)
9914 {
9915 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
9916 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9917 }
9918
9919 static void
9920 do_vfp_dp_rd_rn (void)
9921 {
9922 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9923 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9924 }
9925
9926 static void
9927 do_vfp_dp_rd_rn_rm (void)
9928 {
9929 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9930 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
9931 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
9932 }
9933
9934 static void
9935 do_vfp_dp_rd (void)
9936 {
9937 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9938 }
9939
9940 static void
9941 do_vfp_dp_rm_rd_rn (void)
9942 {
9943 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
9944 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
9945 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
9946 }
9947
9948 /* VFPv3 instructions. */
9949 static void
9950 do_vfp_sp_const (void)
9951 {
9952 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9953 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9954 inst.instruction |= (inst.operands[1].imm & 0x0f);
9955 }
9956
9957 static void
9958 do_vfp_dp_const (void)
9959 {
9960 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9961 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
9962 inst.instruction |= (inst.operands[1].imm & 0x0f);
9963 }
9964
9965 static void
9966 vfp_conv (int srcsize)
9967 {
9968 int immbits = srcsize - inst.operands[1].imm;
9969
9970 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
9971 {
9972 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
9973 i.e. immbits must be in range 0 - 16. */
9974 inst.error = _("immediate value out of range, expected range [0, 16]");
9975 return;
9976 }
9977 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
9978 {
9979 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
9980 i.e. immbits must be in range 0 - 31. */
9981 inst.error = _("immediate value out of range, expected range [1, 32]");
9982 return;
9983 }
9984
9985 inst.instruction |= (immbits & 1) << 5;
9986 inst.instruction |= (immbits >> 1);
9987 }
9988
9989 static void
9990 do_vfp_sp_conv_16 (void)
9991 {
9992 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
9993 vfp_conv (16);
9994 }
9995
9996 static void
9997 do_vfp_dp_conv_16 (void)
9998 {
9999 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10000 vfp_conv (16);
10001 }
10002
10003 static void
10004 do_vfp_sp_conv_32 (void)
10005 {
10006 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
10007 vfp_conv (32);
10008 }
10009
10010 static void
10011 do_vfp_dp_conv_32 (void)
10012 {
10013 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
10014 vfp_conv (32);
10015 }
10016 \f
10017 /* FPA instructions. Also in a logical order. */
10018
10019 static void
10020 do_fpa_cmp (void)
10021 {
10022 inst.instruction |= inst.operands[0].reg << 16;
10023 inst.instruction |= inst.operands[1].reg;
10024 }
10025
10026 static void
10027 do_fpa_ldmstm (void)
10028 {
10029 inst.instruction |= inst.operands[0].reg << 12;
10030 switch (inst.operands[1].imm)
10031 {
10032 case 1: inst.instruction |= CP_T_X; break;
10033 case 2: inst.instruction |= CP_T_Y; break;
10034 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
10035 case 4: break;
10036 default: abort ();
10037 }
10038
10039 if (inst.instruction & (PRE_INDEX | INDEX_UP))
10040 {
10041 /* The instruction specified "ea" or "fd", so we can only accept
10042 [Rn]{!}. The instruction does not really support stacking or
10043 unstacking, so we have to emulate these by setting appropriate
10044 bits and offsets. */
10045 constraint (inst.reloc.exp.X_op != O_constant
10046 || inst.reloc.exp.X_add_number != 0,
10047 _("this instruction does not support indexing"));
10048
10049 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
10050 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
10051
10052 if (!(inst.instruction & INDEX_UP))
10053 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
10054
10055 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
10056 {
10057 inst.operands[2].preind = 0;
10058 inst.operands[2].postind = 1;
10059 }
10060 }
10061
10062 encode_arm_cp_address (2, TRUE, TRUE, 0);
10063 }
10064 \f
10065 /* iWMMXt instructions: strictly in alphabetical order. */
10066
10067 static void
10068 do_iwmmxt_tandorc (void)
10069 {
10070 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
10071 }
10072
10073 static void
10074 do_iwmmxt_textrc (void)
10075 {
10076 inst.instruction |= inst.operands[0].reg << 12;
10077 inst.instruction |= inst.operands[1].imm;
10078 }
10079
10080 static void
10081 do_iwmmxt_textrm (void)
10082 {
10083 inst.instruction |= inst.operands[0].reg << 12;
10084 inst.instruction |= inst.operands[1].reg << 16;
10085 inst.instruction |= inst.operands[2].imm;
10086 }
10087
10088 static void
10089 do_iwmmxt_tinsr (void)
10090 {
10091 inst.instruction |= inst.operands[0].reg << 16;
10092 inst.instruction |= inst.operands[1].reg << 12;
10093 inst.instruction |= inst.operands[2].imm;
10094 }
10095
10096 static void
10097 do_iwmmxt_tmia (void)
10098 {
10099 inst.instruction |= inst.operands[0].reg << 5;
10100 inst.instruction |= inst.operands[1].reg;
10101 inst.instruction |= inst.operands[2].reg << 12;
10102 }
10103
10104 static void
10105 do_iwmmxt_waligni (void)
10106 {
10107 inst.instruction |= inst.operands[0].reg << 12;
10108 inst.instruction |= inst.operands[1].reg << 16;
10109 inst.instruction |= inst.operands[2].reg;
10110 inst.instruction |= inst.operands[3].imm << 20;
10111 }
10112
10113 static void
10114 do_iwmmxt_wmerge (void)
10115 {
10116 inst.instruction |= inst.operands[0].reg << 12;
10117 inst.instruction |= inst.operands[1].reg << 16;
10118 inst.instruction |= inst.operands[2].reg;
10119 inst.instruction |= inst.operands[3].imm << 21;
10120 }
10121
10122 static void
10123 do_iwmmxt_wmov (void)
10124 {
10125 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
10126 inst.instruction |= inst.operands[0].reg << 12;
10127 inst.instruction |= inst.operands[1].reg << 16;
10128 inst.instruction |= inst.operands[1].reg;
10129 }
10130
10131 static void
10132 do_iwmmxt_wldstbh (void)
10133 {
10134 int reloc;
10135 inst.instruction |= inst.operands[0].reg << 12;
10136 if (thumb_mode)
10137 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
10138 else
10139 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
10140 encode_arm_cp_address (1, TRUE, FALSE, reloc);
10141 }
10142
10143 static void
10144 do_iwmmxt_wldstw (void)
10145 {
10146 /* RIWR_RIWC clears .isreg for a control register. */
10147 if (!inst.operands[0].isreg)
10148 {
10149 constraint (inst.cond != COND_ALWAYS, BAD_COND);
10150 inst.instruction |= 0xf0000000;
10151 }
10152
10153 inst.instruction |= inst.operands[0].reg << 12;
10154 encode_arm_cp_address (1, TRUE, TRUE, 0);
10155 }
10156
10157 static void
10158 do_iwmmxt_wldstd (void)
10159 {
10160 inst.instruction |= inst.operands[0].reg << 12;
10161 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
10162 && inst.operands[1].immisreg)
10163 {
10164 inst.instruction &= ~0x1a000ff;
10165 inst.instruction |= (0xfU << 28);
10166 if (inst.operands[1].preind)
10167 inst.instruction |= PRE_INDEX;
10168 if (!inst.operands[1].negative)
10169 inst.instruction |= INDEX_UP;
10170 if (inst.operands[1].writeback)
10171 inst.instruction |= WRITE_BACK;
10172 inst.instruction |= inst.operands[1].reg << 16;
10173 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10174 inst.instruction |= inst.operands[1].imm;
10175 }
10176 else
10177 encode_arm_cp_address (1, TRUE, FALSE, 0);
10178 }
10179
10180 static void
10181 do_iwmmxt_wshufh (void)
10182 {
10183 inst.instruction |= inst.operands[0].reg << 12;
10184 inst.instruction |= inst.operands[1].reg << 16;
10185 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
10186 inst.instruction |= (inst.operands[2].imm & 0x0f);
10187 }
10188
10189 static void
10190 do_iwmmxt_wzero (void)
10191 {
10192 /* WZERO reg is an alias for WANDN reg, reg, reg. */
10193 inst.instruction |= inst.operands[0].reg;
10194 inst.instruction |= inst.operands[0].reg << 12;
10195 inst.instruction |= inst.operands[0].reg << 16;
10196 }
10197
10198 static void
10199 do_iwmmxt_wrwrwr_or_imm5 (void)
10200 {
10201 if (inst.operands[2].isreg)
10202 do_rd_rn_rm ();
10203 else {
10204 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
10205 _("immediate operand requires iWMMXt2"));
10206 do_rd_rn ();
10207 if (inst.operands[2].imm == 0)
10208 {
10209 switch ((inst.instruction >> 20) & 0xf)
10210 {
10211 case 4:
10212 case 5:
10213 case 6:
10214 case 7:
10215 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
10216 inst.operands[2].imm = 16;
10217 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
10218 break;
10219 case 8:
10220 case 9:
10221 case 10:
10222 case 11:
10223 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
10224 inst.operands[2].imm = 32;
10225 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
10226 break;
10227 case 12:
10228 case 13:
10229 case 14:
10230 case 15:
10231 {
10232 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
10233 unsigned long wrn;
10234 wrn = (inst.instruction >> 16) & 0xf;
10235 inst.instruction &= 0xff0fff0f;
10236 inst.instruction |= wrn;
10237 /* Bail out here; the instruction is now assembled. */
10238 return;
10239 }
10240 }
10241 }
10242 /* Map 32 -> 0, etc. */
10243 inst.operands[2].imm &= 0x1f;
10244 inst.instruction |= (0xfU << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
10245 }
10246 }
10247 \f
10248 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
10249 operations first, then control, shift, and load/store. */
10250
10251 /* Insns like "foo X,Y,Z". */
10252
10253 static void
10254 do_mav_triple (void)
10255 {
10256 inst.instruction |= inst.operands[0].reg << 16;
10257 inst.instruction |= inst.operands[1].reg;
10258 inst.instruction |= inst.operands[2].reg << 12;
10259 }
10260
10261 /* Insns like "foo W,X,Y,Z".
10262 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
10263
10264 static void
10265 do_mav_quad (void)
10266 {
10267 inst.instruction |= inst.operands[0].reg << 5;
10268 inst.instruction |= inst.operands[1].reg << 12;
10269 inst.instruction |= inst.operands[2].reg << 16;
10270 inst.instruction |= inst.operands[3].reg;
10271 }
10272
10273 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
10274 static void
10275 do_mav_dspsc (void)
10276 {
10277 inst.instruction |= inst.operands[1].reg << 12;
10278 }
10279
10280 /* Maverick shift immediate instructions.
10281 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
10282 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
10283
10284 static void
10285 do_mav_shift (void)
10286 {
10287 int imm = inst.operands[2].imm;
10288
10289 inst.instruction |= inst.operands[0].reg << 12;
10290 inst.instruction |= inst.operands[1].reg << 16;
10291
10292 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
10293 Bits 5-7 of the insn should have bits 4-6 of the immediate.
10294 Bit 4 should be 0. */
10295 imm = (imm & 0xf) | ((imm & 0x70) << 1);
10296
10297 inst.instruction |= imm;
10298 }
10299 \f
10300 /* XScale instructions. Also sorted arithmetic before move. */
10301
10302 /* Xscale multiply-accumulate (argument parse)
10303 MIAcc acc0,Rm,Rs
10304 MIAPHcc acc0,Rm,Rs
10305 MIAxycc acc0,Rm,Rs. */
10306
10307 static void
10308 do_xsc_mia (void)
10309 {
10310 inst.instruction |= inst.operands[1].reg;
10311 inst.instruction |= inst.operands[2].reg << 12;
10312 }
10313
10314 /* Xscale move-accumulator-register (argument parse)
10315
10316 MARcc acc0,RdLo,RdHi. */
10317
10318 static void
10319 do_xsc_mar (void)
10320 {
10321 inst.instruction |= inst.operands[1].reg << 12;
10322 inst.instruction |= inst.operands[2].reg << 16;
10323 }
10324
10325 /* Xscale move-register-accumulator (argument parse)
10326
10327 MRAcc RdLo,RdHi,acc0. */
10328
10329 static void
10330 do_xsc_mra (void)
10331 {
10332 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
10333 inst.instruction |= inst.operands[0].reg << 12;
10334 inst.instruction |= inst.operands[1].reg << 16;
10335 }
10336 \f
10337 /* Encoding functions relevant only to Thumb. */
10338
10339 /* inst.operands[i] is a shifted-register operand; encode
10340 it into inst.instruction in the format used by Thumb32. */
10341
10342 static void
10343 encode_thumb32_shifted_operand (int i)
10344 {
10345 unsigned int value = inst.reloc.exp.X_add_number;
10346 unsigned int shift = inst.operands[i].shift_kind;
10347
10348 constraint (inst.operands[i].immisreg,
10349 _("shift by register not allowed in thumb mode"));
10350 inst.instruction |= inst.operands[i].reg;
10351 if (shift == SHIFT_RRX)
10352 inst.instruction |= SHIFT_ROR << 4;
10353 else
10354 {
10355 constraint (inst.reloc.exp.X_op != O_constant,
10356 _("expression too complex"));
10357
10358 constraint (value > 32
10359 || (value == 32 && (shift == SHIFT_LSL
10360 || shift == SHIFT_ROR)),
10361 _("shift expression is too large"));
10362
10363 if (value == 0)
10364 shift = SHIFT_LSL;
10365 else if (value == 32)
10366 value = 0;
10367
10368 inst.instruction |= shift << 4;
10369 inst.instruction |= (value & 0x1c) << 10;
10370 inst.instruction |= (value & 0x03) << 6;
10371 }
10372 }
10373
10374
10375 /* inst.operands[i] was set up by parse_address. Encode it into a
10376 Thumb32 format load or store instruction. Reject forms that cannot
10377 be used with such instructions. If is_t is true, reject forms that
10378 cannot be used with a T instruction; if is_d is true, reject forms
10379 that cannot be used with a D instruction. If it is a store insn,
10380 reject PC in Rn. */
10381
10382 static void
10383 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
10384 {
10385 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
10386
10387 constraint (!inst.operands[i].isreg,
10388 _("Instruction does not support =N addresses"));
10389
10390 inst.instruction |= inst.operands[i].reg << 16;
10391 if (inst.operands[i].immisreg)
10392 {
10393 constraint (is_pc, BAD_PC_ADDRESSING);
10394 constraint (is_t || is_d, _("cannot use register index with this instruction"));
10395 constraint (inst.operands[i].negative,
10396 _("Thumb does not support negative register indexing"));
10397 constraint (inst.operands[i].postind,
10398 _("Thumb does not support register post-indexing"));
10399 constraint (inst.operands[i].writeback,
10400 _("Thumb does not support register indexing with writeback"));
10401 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
10402 _("Thumb supports only LSL in shifted register indexing"));
10403
10404 inst.instruction |= inst.operands[i].imm;
10405 if (inst.operands[i].shifted)
10406 {
10407 constraint (inst.reloc.exp.X_op != O_constant,
10408 _("expression too complex"));
10409 constraint (inst.reloc.exp.X_add_number < 0
10410 || inst.reloc.exp.X_add_number > 3,
10411 _("shift out of range"));
10412 inst.instruction |= inst.reloc.exp.X_add_number << 4;
10413 }
10414 inst.reloc.type = BFD_RELOC_UNUSED;
10415 }
10416 else if (inst.operands[i].preind)
10417 {
10418 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
10419 constraint (is_t && inst.operands[i].writeback,
10420 _("cannot use writeback with this instruction"));
10421 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0),
10422 BAD_PC_ADDRESSING);
10423
10424 if (is_d)
10425 {
10426 inst.instruction |= 0x01000000;
10427 if (inst.operands[i].writeback)
10428 inst.instruction |= 0x00200000;
10429 }
10430 else
10431 {
10432 inst.instruction |= 0x00000c00;
10433 if (inst.operands[i].writeback)
10434 inst.instruction |= 0x00000100;
10435 }
10436 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10437 }
10438 else if (inst.operands[i].postind)
10439 {
10440 gas_assert (inst.operands[i].writeback);
10441 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
10442 constraint (is_t, _("cannot use post-indexing with this instruction"));
10443
10444 if (is_d)
10445 inst.instruction |= 0x00200000;
10446 else
10447 inst.instruction |= 0x00000900;
10448 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
10449 }
10450 else /* unindexed - only for coprocessor */
10451 inst.error = _("instruction does not accept unindexed addressing");
10452 }
10453
10454 /* Table of Thumb instructions which exist in both 16- and 32-bit
10455 encodings (the latter only in post-V6T2 cores). The index is the
10456 value used in the insns table below. When there is more than one
10457 possible 16-bit encoding for the instruction, this table always
10458 holds variant (1).
10459 Also contains several pseudo-instructions used during relaxation. */
10460 #define T16_32_TAB \
10461 X(_adc, 4140, eb400000), \
10462 X(_adcs, 4140, eb500000), \
10463 X(_add, 1c00, eb000000), \
10464 X(_adds, 1c00, eb100000), \
10465 X(_addi, 0000, f1000000), \
10466 X(_addis, 0000, f1100000), \
10467 X(_add_pc,000f, f20f0000), \
10468 X(_add_sp,000d, f10d0000), \
10469 X(_adr, 000f, f20f0000), \
10470 X(_and, 4000, ea000000), \
10471 X(_ands, 4000, ea100000), \
10472 X(_asr, 1000, fa40f000), \
10473 X(_asrs, 1000, fa50f000), \
10474 X(_b, e000, f000b000), \
10475 X(_bcond, d000, f0008000), \
10476 X(_bic, 4380, ea200000), \
10477 X(_bics, 4380, ea300000), \
10478 X(_cmn, 42c0, eb100f00), \
10479 X(_cmp, 2800, ebb00f00), \
10480 X(_cpsie, b660, f3af8400), \
10481 X(_cpsid, b670, f3af8600), \
10482 X(_cpy, 4600, ea4f0000), \
10483 X(_dec_sp,80dd, f1ad0d00), \
10484 X(_eor, 4040, ea800000), \
10485 X(_eors, 4040, ea900000), \
10486 X(_inc_sp,00dd, f10d0d00), \
10487 X(_ldmia, c800, e8900000), \
10488 X(_ldr, 6800, f8500000), \
10489 X(_ldrb, 7800, f8100000), \
10490 X(_ldrh, 8800, f8300000), \
10491 X(_ldrsb, 5600, f9100000), \
10492 X(_ldrsh, 5e00, f9300000), \
10493 X(_ldr_pc,4800, f85f0000), \
10494 X(_ldr_pc2,4800, f85f0000), \
10495 X(_ldr_sp,9800, f85d0000), \
10496 X(_lsl, 0000, fa00f000), \
10497 X(_lsls, 0000, fa10f000), \
10498 X(_lsr, 0800, fa20f000), \
10499 X(_lsrs, 0800, fa30f000), \
10500 X(_mov, 2000, ea4f0000), \
10501 X(_movs, 2000, ea5f0000), \
10502 X(_mul, 4340, fb00f000), \
10503 X(_muls, 4340, ffffffff), /* no 32b muls */ \
10504 X(_mvn, 43c0, ea6f0000), \
10505 X(_mvns, 43c0, ea7f0000), \
10506 X(_neg, 4240, f1c00000), /* rsb #0 */ \
10507 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
10508 X(_orr, 4300, ea400000), \
10509 X(_orrs, 4300, ea500000), \
10510 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
10511 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
10512 X(_rev, ba00, fa90f080), \
10513 X(_rev16, ba40, fa90f090), \
10514 X(_revsh, bac0, fa90f0b0), \
10515 X(_ror, 41c0, fa60f000), \
10516 X(_rors, 41c0, fa70f000), \
10517 X(_sbc, 4180, eb600000), \
10518 X(_sbcs, 4180, eb700000), \
10519 X(_stmia, c000, e8800000), \
10520 X(_str, 6000, f8400000), \
10521 X(_strb, 7000, f8000000), \
10522 X(_strh, 8000, f8200000), \
10523 X(_str_sp,9000, f84d0000), \
10524 X(_sub, 1e00, eba00000), \
10525 X(_subs, 1e00, ebb00000), \
10526 X(_subi, 8000, f1a00000), \
10527 X(_subis, 8000, f1b00000), \
10528 X(_sxtb, b240, fa4ff080), \
10529 X(_sxth, b200, fa0ff080), \
10530 X(_tst, 4200, ea100f00), \
10531 X(_uxtb, b2c0, fa5ff080), \
10532 X(_uxth, b280, fa1ff080), \
10533 X(_nop, bf00, f3af8000), \
10534 X(_yield, bf10, f3af8001), \
10535 X(_wfe, bf20, f3af8002), \
10536 X(_wfi, bf30, f3af8003), \
10537 X(_sev, bf40, f3af8004), \
10538 X(_sevl, bf50, f3af8005), \
10539 X(_udf, de00, f7f0a000)
10540
10541 /* To catch errors in encoding functions, the codes are all offset by
10542 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
10543 as 16-bit instructions. */
10544 #define X(a,b,c) T_MNEM##a
10545 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
10546 #undef X
10547
10548 #define X(a,b,c) 0x##b
10549 static const unsigned short thumb_op16[] = { T16_32_TAB };
10550 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
10551 #undef X
10552
10553 #define X(a,b,c) 0x##c
10554 static const unsigned int thumb_op32[] = { T16_32_TAB };
10555 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
10556 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
10557 #undef X
10558 #undef T16_32_TAB
10559
10560 /* Thumb instruction encoders, in alphabetical order. */
10561
10562 /* ADDW or SUBW. */
10563
10564 static void
10565 do_t_add_sub_w (void)
10566 {
10567 int Rd, Rn;
10568
10569 Rd = inst.operands[0].reg;
10570 Rn = inst.operands[1].reg;
10571
10572 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
10573 is the SP-{plus,minus}-immediate form of the instruction. */
10574 if (Rn == REG_SP)
10575 constraint (Rd == REG_PC, BAD_PC);
10576 else
10577 reject_bad_reg (Rd);
10578
10579 inst.instruction |= (Rn << 16) | (Rd << 8);
10580 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10581 }
10582
10583 /* Parse an add or subtract instruction. We get here with inst.instruction
10584 equaling any of THUMB_OPCODE_add, adds, sub, or subs. */
10585
10586 static void
10587 do_t_add_sub (void)
10588 {
10589 int Rd, Rs, Rn;
10590
10591 Rd = inst.operands[0].reg;
10592 Rs = (inst.operands[1].present
10593 ? inst.operands[1].reg /* Rd, Rs, foo */
10594 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10595
10596 if (Rd == REG_PC)
10597 set_it_insn_type_last ();
10598
10599 if (unified_syntax)
10600 {
10601 bfd_boolean flags;
10602 bfd_boolean narrow;
10603 int opcode;
10604
10605 flags = (inst.instruction == T_MNEM_adds
10606 || inst.instruction == T_MNEM_subs);
10607 if (flags)
10608 narrow = !in_it_block ();
10609 else
10610 narrow = in_it_block ();
10611 if (!inst.operands[2].isreg)
10612 {
10613 int add;
10614
10615 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10616 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10617
10618 add = (inst.instruction == T_MNEM_add
10619 || inst.instruction == T_MNEM_adds);
10620 opcode = 0;
10621 if (inst.size_req != 4)
10622 {
10623 /* Attempt to use a narrow opcode, with relaxation if
10624 appropriate. */
10625 if (Rd == REG_SP && Rs == REG_SP && !flags)
10626 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
10627 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
10628 opcode = T_MNEM_add_sp;
10629 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
10630 opcode = T_MNEM_add_pc;
10631 else if (Rd <= 7 && Rs <= 7 && narrow)
10632 {
10633 if (flags)
10634 opcode = add ? T_MNEM_addis : T_MNEM_subis;
10635 else
10636 opcode = add ? T_MNEM_addi : T_MNEM_subi;
10637 }
10638 if (opcode)
10639 {
10640 inst.instruction = THUMB_OP16(opcode);
10641 inst.instruction |= (Rd << 4) | Rs;
10642 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10643 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
10644 {
10645 if (inst.size_req == 2)
10646 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10647 else
10648 inst.relax = opcode;
10649 }
10650 }
10651 else
10652 constraint (inst.size_req == 2, BAD_HIREG);
10653 }
10654 if (inst.size_req == 4
10655 || (inst.size_req != 2 && !opcode))
10656 {
10657 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
10658 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
10659 THUMB1_RELOC_ONLY);
10660 if (Rd == REG_PC)
10661 {
10662 constraint (add, BAD_PC);
10663 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
10664 _("only SUBS PC, LR, #const allowed"));
10665 constraint (inst.reloc.exp.X_op != O_constant,
10666 _("expression too complex"));
10667 constraint (inst.reloc.exp.X_add_number < 0
10668 || inst.reloc.exp.X_add_number > 0xff,
10669 _("immediate value out of range"));
10670 inst.instruction = T2_SUBS_PC_LR
10671 | inst.reloc.exp.X_add_number;
10672 inst.reloc.type = BFD_RELOC_UNUSED;
10673 return;
10674 }
10675 else if (Rs == REG_PC)
10676 {
10677 /* Always use addw/subw. */
10678 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
10679 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
10680 }
10681 else
10682 {
10683 inst.instruction = THUMB_OP32 (inst.instruction);
10684 inst.instruction = (inst.instruction & 0xe1ffffff)
10685 | 0x10000000;
10686 if (flags)
10687 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10688 else
10689 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
10690 }
10691 inst.instruction |= Rd << 8;
10692 inst.instruction |= Rs << 16;
10693 }
10694 }
10695 else
10696 {
10697 unsigned int value = inst.reloc.exp.X_add_number;
10698 unsigned int shift = inst.operands[2].shift_kind;
10699
10700 Rn = inst.operands[2].reg;
10701 /* See if we can do this with a 16-bit instruction. */
10702 if (!inst.operands[2].shifted && inst.size_req != 4)
10703 {
10704 if (Rd > 7 || Rs > 7 || Rn > 7)
10705 narrow = FALSE;
10706
10707 if (narrow)
10708 {
10709 inst.instruction = ((inst.instruction == T_MNEM_adds
10710 || inst.instruction == T_MNEM_add)
10711 ? T_OPCODE_ADD_R3
10712 : T_OPCODE_SUB_R3);
10713 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10714 return;
10715 }
10716
10717 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
10718 {
10719 /* Thumb-1 cores (except v6-M) require at least one high
10720 register in a narrow non flag setting add. */
10721 if (Rd > 7 || Rn > 7
10722 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
10723 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
10724 {
10725 if (Rd == Rn)
10726 {
10727 Rn = Rs;
10728 Rs = Rd;
10729 }
10730 inst.instruction = T_OPCODE_ADD_HI;
10731 inst.instruction |= (Rd & 8) << 4;
10732 inst.instruction |= (Rd & 7);
10733 inst.instruction |= Rn << 3;
10734 return;
10735 }
10736 }
10737 }
10738
10739 constraint (Rd == REG_PC, BAD_PC);
10740 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
10741 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
10742 constraint (Rs == REG_PC, BAD_PC);
10743 reject_bad_reg (Rn);
10744
10745 /* If we get here, it can't be done in 16 bits. */
10746 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
10747 _("shift must be constant"));
10748 inst.instruction = THUMB_OP32 (inst.instruction);
10749 inst.instruction |= Rd << 8;
10750 inst.instruction |= Rs << 16;
10751 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
10752 _("shift value over 3 not allowed in thumb mode"));
10753 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
10754 _("only LSL shift allowed in thumb mode"));
10755 encode_thumb32_shifted_operand (2);
10756 }
10757 }
10758 else
10759 {
10760 constraint (inst.instruction == T_MNEM_adds
10761 || inst.instruction == T_MNEM_subs,
10762 BAD_THUMB32);
10763
10764 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
10765 {
10766 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
10767 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
10768 BAD_HIREG);
10769
10770 inst.instruction = (inst.instruction == T_MNEM_add
10771 ? 0x0000 : 0x8000);
10772 inst.instruction |= (Rd << 4) | Rs;
10773 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10774 return;
10775 }
10776
10777 Rn = inst.operands[2].reg;
10778 constraint (inst.operands[2].shifted, _("unshifted register required"));
10779
10780 /* We now have Rd, Rs, and Rn set to registers. */
10781 if (Rd > 7 || Rs > 7 || Rn > 7)
10782 {
10783 /* Can't do this for SUB. */
10784 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
10785 inst.instruction = T_OPCODE_ADD_HI;
10786 inst.instruction |= (Rd & 8) << 4;
10787 inst.instruction |= (Rd & 7);
10788 if (Rs == Rd)
10789 inst.instruction |= Rn << 3;
10790 else if (Rn == Rd)
10791 inst.instruction |= Rs << 3;
10792 else
10793 constraint (1, _("dest must overlap one source register"));
10794 }
10795 else
10796 {
10797 inst.instruction = (inst.instruction == T_MNEM_add
10798 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
10799 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
10800 }
10801 }
10802 }
10803
10804 static void
10805 do_t_adr (void)
10806 {
10807 unsigned Rd;
10808
10809 Rd = inst.operands[0].reg;
10810 reject_bad_reg (Rd);
10811
10812 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
10813 {
10814 /* Defer to section relaxation. */
10815 inst.relax = inst.instruction;
10816 inst.instruction = THUMB_OP16 (inst.instruction);
10817 inst.instruction |= Rd << 4;
10818 }
10819 else if (unified_syntax && inst.size_req != 2)
10820 {
10821 /* Generate a 32-bit opcode. */
10822 inst.instruction = THUMB_OP32 (inst.instruction);
10823 inst.instruction |= Rd << 8;
10824 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
10825 inst.reloc.pc_rel = 1;
10826 }
10827 else
10828 {
10829 /* Generate a 16-bit opcode. */
10830 inst.instruction = THUMB_OP16 (inst.instruction);
10831 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
10832 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
10833 inst.reloc.pc_rel = 1;
10834 inst.instruction |= Rd << 4;
10835 }
10836
10837 if (inst.reloc.exp.X_op == O_symbol
10838 && inst.reloc.exp.X_add_symbol != NULL
10839 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10840 && THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10841 inst.reloc.exp.X_add_number += 1;
10842 }
10843
10844 /* Arithmetic instructions for which there is just one 16-bit
10845 instruction encoding, and it allows only two low registers.
10846 For maximal compatibility with ARM syntax, we allow three register
10847 operands even when Thumb-32 instructions are not available, as long
10848 as the first two are identical. For instance, both "sbc r0,r1" and
10849 "sbc r0,r0,r1" are allowed. */
10850 static void
10851 do_t_arit3 (void)
10852 {
10853 int Rd, Rs, Rn;
10854
10855 Rd = inst.operands[0].reg;
10856 Rs = (inst.operands[1].present
10857 ? inst.operands[1].reg /* Rd, Rs, foo */
10858 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10859 Rn = inst.operands[2].reg;
10860
10861 reject_bad_reg (Rd);
10862 reject_bad_reg (Rs);
10863 if (inst.operands[2].isreg)
10864 reject_bad_reg (Rn);
10865
10866 if (unified_syntax)
10867 {
10868 if (!inst.operands[2].isreg)
10869 {
10870 /* For an immediate, we always generate a 32-bit opcode;
10871 section relaxation will shrink it later if possible. */
10872 inst.instruction = THUMB_OP32 (inst.instruction);
10873 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10874 inst.instruction |= Rd << 8;
10875 inst.instruction |= Rs << 16;
10876 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10877 }
10878 else
10879 {
10880 bfd_boolean narrow;
10881
10882 /* See if we can do this with a 16-bit instruction. */
10883 if (THUMB_SETS_FLAGS (inst.instruction))
10884 narrow = !in_it_block ();
10885 else
10886 narrow = in_it_block ();
10887
10888 if (Rd > 7 || Rn > 7 || Rs > 7)
10889 narrow = FALSE;
10890 if (inst.operands[2].shifted)
10891 narrow = FALSE;
10892 if (inst.size_req == 4)
10893 narrow = FALSE;
10894
10895 if (narrow
10896 && Rd == Rs)
10897 {
10898 inst.instruction = THUMB_OP16 (inst.instruction);
10899 inst.instruction |= Rd;
10900 inst.instruction |= Rn << 3;
10901 return;
10902 }
10903
10904 /* If we get here, it can't be done in 16 bits. */
10905 constraint (inst.operands[2].shifted
10906 && inst.operands[2].immisreg,
10907 _("shift must be constant"));
10908 inst.instruction = THUMB_OP32 (inst.instruction);
10909 inst.instruction |= Rd << 8;
10910 inst.instruction |= Rs << 16;
10911 encode_thumb32_shifted_operand (2);
10912 }
10913 }
10914 else
10915 {
10916 /* On its face this is a lie - the instruction does set the
10917 flags. However, the only supported mnemonic in this mode
10918 says it doesn't. */
10919 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10920
10921 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
10922 _("unshifted register required"));
10923 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
10924 constraint (Rd != Rs,
10925 _("dest and source1 must be the same register"));
10926
10927 inst.instruction = THUMB_OP16 (inst.instruction);
10928 inst.instruction |= Rd;
10929 inst.instruction |= Rn << 3;
10930 }
10931 }
10932
10933 /* Similarly, but for instructions where the arithmetic operation is
10934 commutative, so we can allow either of them to be different from
10935 the destination operand in a 16-bit instruction. For instance, all
10936 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
10937 accepted. */
10938 static void
10939 do_t_arit3c (void)
10940 {
10941 int Rd, Rs, Rn;
10942
10943 Rd = inst.operands[0].reg;
10944 Rs = (inst.operands[1].present
10945 ? inst.operands[1].reg /* Rd, Rs, foo */
10946 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10947 Rn = inst.operands[2].reg;
10948
10949 reject_bad_reg (Rd);
10950 reject_bad_reg (Rs);
10951 if (inst.operands[2].isreg)
10952 reject_bad_reg (Rn);
10953
10954 if (unified_syntax)
10955 {
10956 if (!inst.operands[2].isreg)
10957 {
10958 /* For an immediate, we always generate a 32-bit opcode;
10959 section relaxation will shrink it later if possible. */
10960 inst.instruction = THUMB_OP32 (inst.instruction);
10961 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10962 inst.instruction |= Rd << 8;
10963 inst.instruction |= Rs << 16;
10964 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10965 }
10966 else
10967 {
10968 bfd_boolean narrow;
10969
10970 /* See if we can do this with a 16-bit instruction. */
10971 if (THUMB_SETS_FLAGS (inst.instruction))
10972 narrow = !in_it_block ();
10973 else
10974 narrow = in_it_block ();
10975
10976 if (Rd > 7 || Rn > 7 || Rs > 7)
10977 narrow = FALSE;
10978 if (inst.operands[2].shifted)
10979 narrow = FALSE;
10980 if (inst.size_req == 4)
10981 narrow = FALSE;
10982
10983 if (narrow)
10984 {
10985 if (Rd == Rs)
10986 {
10987 inst.instruction = THUMB_OP16 (inst.instruction);
10988 inst.instruction |= Rd;
10989 inst.instruction |= Rn << 3;
10990 return;
10991 }
10992 if (Rd == Rn)
10993 {
10994 inst.instruction = THUMB_OP16 (inst.instruction);
10995 inst.instruction |= Rd;
10996 inst.instruction |= Rs << 3;
10997 return;
10998 }
10999 }
11000
11001 /* If we get here, it can't be done in 16 bits. */
11002 constraint (inst.operands[2].shifted
11003 && inst.operands[2].immisreg,
11004 _("shift must be constant"));
11005 inst.instruction = THUMB_OP32 (inst.instruction);
11006 inst.instruction |= Rd << 8;
11007 inst.instruction |= Rs << 16;
11008 encode_thumb32_shifted_operand (2);
11009 }
11010 }
11011 else
11012 {
11013 /* On its face this is a lie - the instruction does set the
11014 flags. However, the only supported mnemonic in this mode
11015 says it doesn't. */
11016 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11017
11018 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
11019 _("unshifted register required"));
11020 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
11021
11022 inst.instruction = THUMB_OP16 (inst.instruction);
11023 inst.instruction |= Rd;
11024
11025 if (Rd == Rs)
11026 inst.instruction |= Rn << 3;
11027 else if (Rd == Rn)
11028 inst.instruction |= Rs << 3;
11029 else
11030 constraint (1, _("dest must overlap one source register"));
11031 }
11032 }
11033
11034 static void
11035 do_t_bfc (void)
11036 {
11037 unsigned Rd;
11038 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
11039 constraint (msb > 32, _("bit-field extends past end of register"));
11040 /* The instruction encoding stores the LSB and MSB,
11041 not the LSB and width. */
11042 Rd = inst.operands[0].reg;
11043 reject_bad_reg (Rd);
11044 inst.instruction |= Rd << 8;
11045 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
11046 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
11047 inst.instruction |= msb - 1;
11048 }
11049
11050 static void
11051 do_t_bfi (void)
11052 {
11053 int Rd, Rn;
11054 unsigned int msb;
11055
11056 Rd = inst.operands[0].reg;
11057 reject_bad_reg (Rd);
11058
11059 /* #0 in second position is alternative syntax for bfc, which is
11060 the same instruction but with REG_PC in the Rm field. */
11061 if (!inst.operands[1].isreg)
11062 Rn = REG_PC;
11063 else
11064 {
11065 Rn = inst.operands[1].reg;
11066 reject_bad_reg (Rn);
11067 }
11068
11069 msb = inst.operands[2].imm + inst.operands[3].imm;
11070 constraint (msb > 32, _("bit-field extends past end of register"));
11071 /* The instruction encoding stores the LSB and MSB,
11072 not the LSB and width. */
11073 inst.instruction |= Rd << 8;
11074 inst.instruction |= Rn << 16;
11075 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11076 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11077 inst.instruction |= msb - 1;
11078 }
11079
11080 static void
11081 do_t_bfx (void)
11082 {
11083 unsigned Rd, Rn;
11084
11085 Rd = inst.operands[0].reg;
11086 Rn = inst.operands[1].reg;
11087
11088 reject_bad_reg (Rd);
11089 reject_bad_reg (Rn);
11090
11091 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
11092 _("bit-field extends past end of register"));
11093 inst.instruction |= Rd << 8;
11094 inst.instruction |= Rn << 16;
11095 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
11096 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
11097 inst.instruction |= inst.operands[3].imm - 1;
11098 }
11099
11100 /* ARM V5 Thumb BLX (argument parse)
11101 BLX <target_addr> which is BLX(1)
11102 BLX <Rm> which is BLX(2)
11103 Unfortunately, there are two different opcodes for this mnemonic.
11104 So, the insns[].value is not used, and the code here zaps values
11105 into inst.instruction.
11106
11107 ??? How to take advantage of the additional two bits of displacement
11108 available in Thumb32 mode? Need new relocation? */
11109
11110 static void
11111 do_t_blx (void)
11112 {
11113 set_it_insn_type_last ();
11114
11115 if (inst.operands[0].isreg)
11116 {
11117 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
11118 /* We have a register, so this is BLX(2). */
11119 inst.instruction |= inst.operands[0].reg << 3;
11120 }
11121 else
11122 {
11123 /* No register. This must be BLX(1). */
11124 inst.instruction = 0xf000e800;
11125 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
11126 }
11127 }
11128
11129 static void
11130 do_t_branch (void)
11131 {
11132 int opcode;
11133 int cond;
11134 bfd_reloc_code_real_type reloc;
11135
11136 cond = inst.cond;
11137 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
11138
11139 if (in_it_block ())
11140 {
11141 /* Conditional branches inside IT blocks are encoded as unconditional
11142 branches. */
11143 cond = COND_ALWAYS;
11144 }
11145 else
11146 cond = inst.cond;
11147
11148 if (cond != COND_ALWAYS)
11149 opcode = T_MNEM_bcond;
11150 else
11151 opcode = inst.instruction;
11152
11153 if (unified_syntax
11154 && (inst.size_req == 4
11155 || (inst.size_req != 2
11156 && (inst.operands[0].hasreloc
11157 || inst.reloc.exp.X_op == O_constant))))
11158 {
11159 inst.instruction = THUMB_OP32(opcode);
11160 if (cond == COND_ALWAYS)
11161 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
11162 else
11163 {
11164 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2),
11165 _("selected architecture does not support "
11166 "wide conditional branch instruction"));
11167
11168 gas_assert (cond != 0xF);
11169 inst.instruction |= cond << 22;
11170 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
11171 }
11172 }
11173 else
11174 {
11175 inst.instruction = THUMB_OP16(opcode);
11176 if (cond == COND_ALWAYS)
11177 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
11178 else
11179 {
11180 inst.instruction |= cond << 8;
11181 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
11182 }
11183 /* Allow section relaxation. */
11184 if (unified_syntax && inst.size_req != 2)
11185 inst.relax = opcode;
11186 }
11187 inst.reloc.type = reloc;
11188 inst.reloc.pc_rel = 1;
11189 }
11190
11191 /* Actually do the work for Thumb state bkpt and hlt. The only difference
11192 between the two is the maximum immediate allowed - which is passed in
11193 RANGE. */
11194 static void
11195 do_t_bkpt_hlt1 (int range)
11196 {
11197 constraint (inst.cond != COND_ALWAYS,
11198 _("instruction is always unconditional"));
11199 if (inst.operands[0].present)
11200 {
11201 constraint (inst.operands[0].imm > range,
11202 _("immediate value out of range"));
11203 inst.instruction |= inst.operands[0].imm;
11204 }
11205
11206 set_it_insn_type (NEUTRAL_IT_INSN);
11207 }
11208
11209 static void
11210 do_t_hlt (void)
11211 {
11212 do_t_bkpt_hlt1 (63);
11213 }
11214
11215 static void
11216 do_t_bkpt (void)
11217 {
11218 do_t_bkpt_hlt1 (255);
11219 }
11220
11221 static void
11222 do_t_branch23 (void)
11223 {
11224 set_it_insn_type_last ();
11225 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
11226
11227 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
11228 this file. We used to simply ignore the PLT reloc type here --
11229 the branch encoding is now needed to deal with TLSCALL relocs.
11230 So if we see a PLT reloc now, put it back to how it used to be to
11231 keep the preexisting behaviour. */
11232 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
11233 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
11234
11235 #if defined(OBJ_COFF)
11236 /* If the destination of the branch is a defined symbol which does not have
11237 the THUMB_FUNC attribute, then we must be calling a function which has
11238 the (interfacearm) attribute. We look for the Thumb entry point to that
11239 function and change the branch to refer to that function instead. */
11240 if ( inst.reloc.exp.X_op == O_symbol
11241 && inst.reloc.exp.X_add_symbol != NULL
11242 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
11243 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
11244 inst.reloc.exp.X_add_symbol =
11245 find_real_start (inst.reloc.exp.X_add_symbol);
11246 #endif
11247 }
11248
11249 static void
11250 do_t_bx (void)
11251 {
11252 set_it_insn_type_last ();
11253 inst.instruction |= inst.operands[0].reg << 3;
11254 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
11255 should cause the alignment to be checked once it is known. This is
11256 because BX PC only works if the instruction is word aligned. */
11257 }
11258
11259 static void
11260 do_t_bxj (void)
11261 {
11262 int Rm;
11263
11264 set_it_insn_type_last ();
11265 Rm = inst.operands[0].reg;
11266 reject_bad_reg (Rm);
11267 inst.instruction |= Rm << 16;
11268 }
11269
11270 static void
11271 do_t_clz (void)
11272 {
11273 unsigned Rd;
11274 unsigned Rm;
11275
11276 Rd = inst.operands[0].reg;
11277 Rm = inst.operands[1].reg;
11278
11279 reject_bad_reg (Rd);
11280 reject_bad_reg (Rm);
11281
11282 inst.instruction |= Rd << 8;
11283 inst.instruction |= Rm << 16;
11284 inst.instruction |= Rm;
11285 }
11286
11287 static void
11288 do_t_csdb (void)
11289 {
11290 set_it_insn_type (OUTSIDE_IT_INSN);
11291 }
11292
11293 static void
11294 do_t_cps (void)
11295 {
11296 set_it_insn_type (OUTSIDE_IT_INSN);
11297 inst.instruction |= inst.operands[0].imm;
11298 }
11299
11300 static void
11301 do_t_cpsi (void)
11302 {
11303 set_it_insn_type (OUTSIDE_IT_INSN);
11304 if (unified_syntax
11305 && (inst.operands[1].present || inst.size_req == 4)
11306 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
11307 {
11308 unsigned int imod = (inst.instruction & 0x0030) >> 4;
11309 inst.instruction = 0xf3af8000;
11310 inst.instruction |= imod << 9;
11311 inst.instruction |= inst.operands[0].imm << 5;
11312 if (inst.operands[1].present)
11313 inst.instruction |= 0x100 | inst.operands[1].imm;
11314 }
11315 else
11316 {
11317 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
11318 && (inst.operands[0].imm & 4),
11319 _("selected processor does not support 'A' form "
11320 "of this instruction"));
11321 constraint (inst.operands[1].present || inst.size_req == 4,
11322 _("Thumb does not support the 2-argument "
11323 "form of this instruction"));
11324 inst.instruction |= inst.operands[0].imm;
11325 }
11326 }
11327
11328 /* THUMB CPY instruction (argument parse). */
11329
11330 static void
11331 do_t_cpy (void)
11332 {
11333 if (inst.size_req == 4)
11334 {
11335 inst.instruction = THUMB_OP32 (T_MNEM_mov);
11336 inst.instruction |= inst.operands[0].reg << 8;
11337 inst.instruction |= inst.operands[1].reg;
11338 }
11339 else
11340 {
11341 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
11342 inst.instruction |= (inst.operands[0].reg & 0x7);
11343 inst.instruction |= inst.operands[1].reg << 3;
11344 }
11345 }
11346
11347 static void
11348 do_t_cbz (void)
11349 {
11350 set_it_insn_type (OUTSIDE_IT_INSN);
11351 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11352 inst.instruction |= inst.operands[0].reg;
11353 inst.reloc.pc_rel = 1;
11354 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
11355 }
11356
11357 static void
11358 do_t_dbg (void)
11359 {
11360 inst.instruction |= inst.operands[0].imm;
11361 }
11362
11363 static void
11364 do_t_div (void)
11365 {
11366 unsigned Rd, Rn, Rm;
11367
11368 Rd = inst.operands[0].reg;
11369 Rn = (inst.operands[1].present
11370 ? inst.operands[1].reg : Rd);
11371 Rm = inst.operands[2].reg;
11372
11373 reject_bad_reg (Rd);
11374 reject_bad_reg (Rn);
11375 reject_bad_reg (Rm);
11376
11377 inst.instruction |= Rd << 8;
11378 inst.instruction |= Rn << 16;
11379 inst.instruction |= Rm;
11380 }
11381
11382 static void
11383 do_t_hint (void)
11384 {
11385 if (unified_syntax && inst.size_req == 4)
11386 inst.instruction = THUMB_OP32 (inst.instruction);
11387 else
11388 inst.instruction = THUMB_OP16 (inst.instruction);
11389 }
11390
11391 static void
11392 do_t_it (void)
11393 {
11394 unsigned int cond = inst.operands[0].imm;
11395
11396 set_it_insn_type (IT_INSN);
11397 now_it.mask = (inst.instruction & 0xf) | 0x10;
11398 now_it.cc = cond;
11399 now_it.warn_deprecated = FALSE;
11400
11401 /* If the condition is a negative condition, invert the mask. */
11402 if ((cond & 0x1) == 0x0)
11403 {
11404 unsigned int mask = inst.instruction & 0x000f;
11405
11406 if ((mask & 0x7) == 0)
11407 {
11408 /* No conversion needed. */
11409 now_it.block_length = 1;
11410 }
11411 else if ((mask & 0x3) == 0)
11412 {
11413 mask ^= 0x8;
11414 now_it.block_length = 2;
11415 }
11416 else if ((mask & 0x1) == 0)
11417 {
11418 mask ^= 0xC;
11419 now_it.block_length = 3;
11420 }
11421 else
11422 {
11423 mask ^= 0xE;
11424 now_it.block_length = 4;
11425 }
11426
11427 inst.instruction &= 0xfff0;
11428 inst.instruction |= mask;
11429 }
11430
11431 inst.instruction |= cond << 4;
11432 }
11433
11434 /* Helper function used for both push/pop and ldm/stm. */
11435 static void
11436 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
11437 {
11438 bfd_boolean load;
11439
11440 load = (inst.instruction & (1 << 20)) != 0;
11441
11442 if (mask & (1 << 13))
11443 inst.error = _("SP not allowed in register list");
11444
11445 if ((mask & (1 << base)) != 0
11446 && writeback)
11447 inst.error = _("having the base register in the register list when "
11448 "using write back is UNPREDICTABLE");
11449
11450 if (load)
11451 {
11452 if (mask & (1 << 15))
11453 {
11454 if (mask & (1 << 14))
11455 inst.error = _("LR and PC should not both be in register list");
11456 else
11457 set_it_insn_type_last ();
11458 }
11459 }
11460 else
11461 {
11462 if (mask & (1 << 15))
11463 inst.error = _("PC not allowed in register list");
11464 }
11465
11466 if ((mask & (mask - 1)) == 0)
11467 {
11468 /* Single register transfers implemented as str/ldr. */
11469 if (writeback)
11470 {
11471 if (inst.instruction & (1 << 23))
11472 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
11473 else
11474 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
11475 }
11476 else
11477 {
11478 if (inst.instruction & (1 << 23))
11479 inst.instruction = 0x00800000; /* ia -> [base] */
11480 else
11481 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
11482 }
11483
11484 inst.instruction |= 0xf8400000;
11485 if (load)
11486 inst.instruction |= 0x00100000;
11487
11488 mask = ffs (mask) - 1;
11489 mask <<= 12;
11490 }
11491 else if (writeback)
11492 inst.instruction |= WRITE_BACK;
11493
11494 inst.instruction |= mask;
11495 inst.instruction |= base << 16;
11496 }
11497
11498 static void
11499 do_t_ldmstm (void)
11500 {
11501 /* This really doesn't seem worth it. */
11502 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11503 _("expression too complex"));
11504 constraint (inst.operands[1].writeback,
11505 _("Thumb load/store multiple does not support {reglist}^"));
11506
11507 if (unified_syntax)
11508 {
11509 bfd_boolean narrow;
11510 unsigned mask;
11511
11512 narrow = FALSE;
11513 /* See if we can use a 16-bit instruction. */
11514 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
11515 && inst.size_req != 4
11516 && !(inst.operands[1].imm & ~0xff))
11517 {
11518 mask = 1 << inst.operands[0].reg;
11519
11520 if (inst.operands[0].reg <= 7)
11521 {
11522 if (inst.instruction == T_MNEM_stmia
11523 ? inst.operands[0].writeback
11524 : (inst.operands[0].writeback
11525 == !(inst.operands[1].imm & mask)))
11526 {
11527 if (inst.instruction == T_MNEM_stmia
11528 && (inst.operands[1].imm & mask)
11529 && (inst.operands[1].imm & (mask - 1)))
11530 as_warn (_("value stored for r%d is UNKNOWN"),
11531 inst.operands[0].reg);
11532
11533 inst.instruction = THUMB_OP16 (inst.instruction);
11534 inst.instruction |= inst.operands[0].reg << 8;
11535 inst.instruction |= inst.operands[1].imm;
11536 narrow = TRUE;
11537 }
11538 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11539 {
11540 /* This means 1 register in reg list one of 3 situations:
11541 1. Instruction is stmia, but without writeback.
11542 2. lmdia without writeback, but with Rn not in
11543 reglist.
11544 3. ldmia with writeback, but with Rn in reglist.
11545 Case 3 is UNPREDICTABLE behaviour, so we handle
11546 case 1 and 2 which can be converted into a 16-bit
11547 str or ldr. The SP cases are handled below. */
11548 unsigned long opcode;
11549 /* First, record an error for Case 3. */
11550 if (inst.operands[1].imm & mask
11551 && inst.operands[0].writeback)
11552 inst.error =
11553 _("having the base register in the register list when "
11554 "using write back is UNPREDICTABLE");
11555
11556 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
11557 : T_MNEM_ldr);
11558 inst.instruction = THUMB_OP16 (opcode);
11559 inst.instruction |= inst.operands[0].reg << 3;
11560 inst.instruction |= (ffs (inst.operands[1].imm)-1);
11561 narrow = TRUE;
11562 }
11563 }
11564 else if (inst.operands[0] .reg == REG_SP)
11565 {
11566 if (inst.operands[0].writeback)
11567 {
11568 inst.instruction =
11569 THUMB_OP16 (inst.instruction == T_MNEM_stmia
11570 ? T_MNEM_push : T_MNEM_pop);
11571 inst.instruction |= inst.operands[1].imm;
11572 narrow = TRUE;
11573 }
11574 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
11575 {
11576 inst.instruction =
11577 THUMB_OP16 (inst.instruction == T_MNEM_stmia
11578 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
11579 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
11580 narrow = TRUE;
11581 }
11582 }
11583 }
11584
11585 if (!narrow)
11586 {
11587 if (inst.instruction < 0xffff)
11588 inst.instruction = THUMB_OP32 (inst.instruction);
11589
11590 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
11591 inst.operands[0].writeback);
11592 }
11593 }
11594 else
11595 {
11596 constraint (inst.operands[0].reg > 7
11597 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
11598 constraint (inst.instruction != T_MNEM_ldmia
11599 && inst.instruction != T_MNEM_stmia,
11600 _("Thumb-2 instruction only valid in unified syntax"));
11601 if (inst.instruction == T_MNEM_stmia)
11602 {
11603 if (!inst.operands[0].writeback)
11604 as_warn (_("this instruction will write back the base register"));
11605 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
11606 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
11607 as_warn (_("value stored for r%d is UNKNOWN"),
11608 inst.operands[0].reg);
11609 }
11610 else
11611 {
11612 if (!inst.operands[0].writeback
11613 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
11614 as_warn (_("this instruction will write back the base register"));
11615 else if (inst.operands[0].writeback
11616 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
11617 as_warn (_("this instruction will not write back the base register"));
11618 }
11619
11620 inst.instruction = THUMB_OP16 (inst.instruction);
11621 inst.instruction |= inst.operands[0].reg << 8;
11622 inst.instruction |= inst.operands[1].imm;
11623 }
11624 }
11625
11626 static void
11627 do_t_ldrex (void)
11628 {
11629 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
11630 || inst.operands[1].postind || inst.operands[1].writeback
11631 || inst.operands[1].immisreg || inst.operands[1].shifted
11632 || inst.operands[1].negative,
11633 BAD_ADDR_MODE);
11634
11635 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
11636
11637 inst.instruction |= inst.operands[0].reg << 12;
11638 inst.instruction |= inst.operands[1].reg << 16;
11639 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11640 }
11641
11642 static void
11643 do_t_ldrexd (void)
11644 {
11645 if (!inst.operands[1].present)
11646 {
11647 constraint (inst.operands[0].reg == REG_LR,
11648 _("r14 not allowed as first register "
11649 "when second register is omitted"));
11650 inst.operands[1].reg = inst.operands[0].reg + 1;
11651 }
11652 constraint (inst.operands[0].reg == inst.operands[1].reg,
11653 BAD_OVERLAP);
11654
11655 inst.instruction |= inst.operands[0].reg << 12;
11656 inst.instruction |= inst.operands[1].reg << 8;
11657 inst.instruction |= inst.operands[2].reg << 16;
11658 }
11659
11660 static void
11661 do_t_ldst (void)
11662 {
11663 unsigned long opcode;
11664 int Rn;
11665
11666 if (inst.operands[0].isreg
11667 && !inst.operands[0].preind
11668 && inst.operands[0].reg == REG_PC)
11669 set_it_insn_type_last ();
11670
11671 opcode = inst.instruction;
11672 if (unified_syntax)
11673 {
11674 if (!inst.operands[1].isreg)
11675 {
11676 if (opcode <= 0xffff)
11677 inst.instruction = THUMB_OP32 (opcode);
11678 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
11679 return;
11680 }
11681 if (inst.operands[1].isreg
11682 && !inst.operands[1].writeback
11683 && !inst.operands[1].shifted && !inst.operands[1].postind
11684 && !inst.operands[1].negative && inst.operands[0].reg <= 7
11685 && opcode <= 0xffff
11686 && inst.size_req != 4)
11687 {
11688 /* Insn may have a 16-bit form. */
11689 Rn = inst.operands[1].reg;
11690 if (inst.operands[1].immisreg)
11691 {
11692 inst.instruction = THUMB_OP16 (opcode);
11693 /* [Rn, Rik] */
11694 if (Rn <= 7 && inst.operands[1].imm <= 7)
11695 goto op16;
11696 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
11697 reject_bad_reg (inst.operands[1].imm);
11698 }
11699 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
11700 && opcode != T_MNEM_ldrsb)
11701 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
11702 || (Rn == REG_SP && opcode == T_MNEM_str))
11703 {
11704 /* [Rn, #const] */
11705 if (Rn > 7)
11706 {
11707 if (Rn == REG_PC)
11708 {
11709 if (inst.reloc.pc_rel)
11710 opcode = T_MNEM_ldr_pc2;
11711 else
11712 opcode = T_MNEM_ldr_pc;
11713 }
11714 else
11715 {
11716 if (opcode == T_MNEM_ldr)
11717 opcode = T_MNEM_ldr_sp;
11718 else
11719 opcode = T_MNEM_str_sp;
11720 }
11721 inst.instruction = inst.operands[0].reg << 8;
11722 }
11723 else
11724 {
11725 inst.instruction = inst.operands[0].reg;
11726 inst.instruction |= inst.operands[1].reg << 3;
11727 }
11728 inst.instruction |= THUMB_OP16 (opcode);
11729 if (inst.size_req == 2)
11730 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11731 else
11732 inst.relax = opcode;
11733 return;
11734 }
11735 }
11736 /* Definitely a 32-bit variant. */
11737
11738 /* Warning for Erratum 752419. */
11739 if (opcode == T_MNEM_ldr
11740 && inst.operands[0].reg == REG_SP
11741 && inst.operands[1].writeback == 1
11742 && !inst.operands[1].immisreg)
11743 {
11744 if (no_cpu_selected ()
11745 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
11746 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
11747 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
11748 as_warn (_("This instruction may be unpredictable "
11749 "if executed on M-profile cores "
11750 "with interrupts enabled."));
11751 }
11752
11753 /* Do some validations regarding addressing modes. */
11754 if (inst.operands[1].immisreg)
11755 reject_bad_reg (inst.operands[1].imm);
11756
11757 constraint (inst.operands[1].writeback == 1
11758 && inst.operands[0].reg == inst.operands[1].reg,
11759 BAD_OVERLAP);
11760
11761 inst.instruction = THUMB_OP32 (opcode);
11762 inst.instruction |= inst.operands[0].reg << 12;
11763 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
11764 check_ldr_r15_aligned ();
11765 return;
11766 }
11767
11768 constraint (inst.operands[0].reg > 7, BAD_HIREG);
11769
11770 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
11771 {
11772 /* Only [Rn,Rm] is acceptable. */
11773 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
11774 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
11775 || inst.operands[1].postind || inst.operands[1].shifted
11776 || inst.operands[1].negative,
11777 _("Thumb does not support this addressing mode"));
11778 inst.instruction = THUMB_OP16 (inst.instruction);
11779 goto op16;
11780 }
11781
11782 inst.instruction = THUMB_OP16 (inst.instruction);
11783 if (!inst.operands[1].isreg)
11784 if (move_or_literal_pool (0, CONST_THUMB, /*mode_3=*/FALSE))
11785 return;
11786
11787 constraint (!inst.operands[1].preind
11788 || inst.operands[1].shifted
11789 || inst.operands[1].writeback,
11790 _("Thumb does not support this addressing mode"));
11791 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
11792 {
11793 constraint (inst.instruction & 0x0600,
11794 _("byte or halfword not valid for base register"));
11795 constraint (inst.operands[1].reg == REG_PC
11796 && !(inst.instruction & THUMB_LOAD_BIT),
11797 _("r15 based store not allowed"));
11798 constraint (inst.operands[1].immisreg,
11799 _("invalid base register for register offset"));
11800
11801 if (inst.operands[1].reg == REG_PC)
11802 inst.instruction = T_OPCODE_LDR_PC;
11803 else if (inst.instruction & THUMB_LOAD_BIT)
11804 inst.instruction = T_OPCODE_LDR_SP;
11805 else
11806 inst.instruction = T_OPCODE_STR_SP;
11807
11808 inst.instruction |= inst.operands[0].reg << 8;
11809 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11810 return;
11811 }
11812
11813 constraint (inst.operands[1].reg > 7, BAD_HIREG);
11814 if (!inst.operands[1].immisreg)
11815 {
11816 /* Immediate offset. */
11817 inst.instruction |= inst.operands[0].reg;
11818 inst.instruction |= inst.operands[1].reg << 3;
11819 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
11820 return;
11821 }
11822
11823 /* Register offset. */
11824 constraint (inst.operands[1].imm > 7, BAD_HIREG);
11825 constraint (inst.operands[1].negative,
11826 _("Thumb does not support this addressing mode"));
11827
11828 op16:
11829 switch (inst.instruction)
11830 {
11831 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
11832 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
11833 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
11834 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
11835 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
11836 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
11837 case 0x5600 /* ldrsb */:
11838 case 0x5e00 /* ldrsh */: break;
11839 default: abort ();
11840 }
11841
11842 inst.instruction |= inst.operands[0].reg;
11843 inst.instruction |= inst.operands[1].reg << 3;
11844 inst.instruction |= inst.operands[1].imm << 6;
11845 }
11846
11847 static void
11848 do_t_ldstd (void)
11849 {
11850 if (!inst.operands[1].present)
11851 {
11852 inst.operands[1].reg = inst.operands[0].reg + 1;
11853 constraint (inst.operands[0].reg == REG_LR,
11854 _("r14 not allowed here"));
11855 constraint (inst.operands[0].reg == REG_R12,
11856 _("r12 not allowed here"));
11857 }
11858
11859 if (inst.operands[2].writeback
11860 && (inst.operands[0].reg == inst.operands[2].reg
11861 || inst.operands[1].reg == inst.operands[2].reg))
11862 as_warn (_("base register written back, and overlaps "
11863 "one of transfer registers"));
11864
11865 inst.instruction |= inst.operands[0].reg << 12;
11866 inst.instruction |= inst.operands[1].reg << 8;
11867 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
11868 }
11869
11870 static void
11871 do_t_ldstt (void)
11872 {
11873 inst.instruction |= inst.operands[0].reg << 12;
11874 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
11875 }
11876
11877 static void
11878 do_t_mla (void)
11879 {
11880 unsigned Rd, Rn, Rm, Ra;
11881
11882 Rd = inst.operands[0].reg;
11883 Rn = inst.operands[1].reg;
11884 Rm = inst.operands[2].reg;
11885 Ra = inst.operands[3].reg;
11886
11887 reject_bad_reg (Rd);
11888 reject_bad_reg (Rn);
11889 reject_bad_reg (Rm);
11890 reject_bad_reg (Ra);
11891
11892 inst.instruction |= Rd << 8;
11893 inst.instruction |= Rn << 16;
11894 inst.instruction |= Rm;
11895 inst.instruction |= Ra << 12;
11896 }
11897
11898 static void
11899 do_t_mlal (void)
11900 {
11901 unsigned RdLo, RdHi, Rn, Rm;
11902
11903 RdLo = inst.operands[0].reg;
11904 RdHi = inst.operands[1].reg;
11905 Rn = inst.operands[2].reg;
11906 Rm = inst.operands[3].reg;
11907
11908 reject_bad_reg (RdLo);
11909 reject_bad_reg (RdHi);
11910 reject_bad_reg (Rn);
11911 reject_bad_reg (Rm);
11912
11913 inst.instruction |= RdLo << 12;
11914 inst.instruction |= RdHi << 8;
11915 inst.instruction |= Rn << 16;
11916 inst.instruction |= Rm;
11917 }
11918
11919 static void
11920 do_t_mov_cmp (void)
11921 {
11922 unsigned Rn, Rm;
11923
11924 Rn = inst.operands[0].reg;
11925 Rm = inst.operands[1].reg;
11926
11927 if (Rn == REG_PC)
11928 set_it_insn_type_last ();
11929
11930 if (unified_syntax)
11931 {
11932 int r0off = (inst.instruction == T_MNEM_mov
11933 || inst.instruction == T_MNEM_movs) ? 8 : 16;
11934 unsigned long opcode;
11935 bfd_boolean narrow;
11936 bfd_boolean low_regs;
11937
11938 low_regs = (Rn <= 7 && Rm <= 7);
11939 opcode = inst.instruction;
11940 if (in_it_block ())
11941 narrow = opcode != T_MNEM_movs;
11942 else
11943 narrow = opcode != T_MNEM_movs || low_regs;
11944 if (inst.size_req == 4
11945 || inst.operands[1].shifted)
11946 narrow = FALSE;
11947
11948 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
11949 if (opcode == T_MNEM_movs && inst.operands[1].isreg
11950 && !inst.operands[1].shifted
11951 && Rn == REG_PC
11952 && Rm == REG_LR)
11953 {
11954 inst.instruction = T2_SUBS_PC_LR;
11955 return;
11956 }
11957
11958 if (opcode == T_MNEM_cmp)
11959 {
11960 constraint (Rn == REG_PC, BAD_PC);
11961 if (narrow)
11962 {
11963 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
11964 but valid. */
11965 warn_deprecated_sp (Rm);
11966 /* R15 was documented as a valid choice for Rm in ARMv6,
11967 but as UNPREDICTABLE in ARMv7. ARM's proprietary
11968 tools reject R15, so we do too. */
11969 constraint (Rm == REG_PC, BAD_PC);
11970 }
11971 else
11972 reject_bad_reg (Rm);
11973 }
11974 else if (opcode == T_MNEM_mov
11975 || opcode == T_MNEM_movs)
11976 {
11977 if (inst.operands[1].isreg)
11978 {
11979 if (opcode == T_MNEM_movs)
11980 {
11981 reject_bad_reg (Rn);
11982 reject_bad_reg (Rm);
11983 }
11984 else if (narrow)
11985 {
11986 /* This is mov.n. */
11987 if ((Rn == REG_SP || Rn == REG_PC)
11988 && (Rm == REG_SP || Rm == REG_PC))
11989 {
11990 as_tsktsk (_("Use of r%u as a source register is "
11991 "deprecated when r%u is the destination "
11992 "register."), Rm, Rn);
11993 }
11994 }
11995 else
11996 {
11997 /* This is mov.w. */
11998 constraint (Rn == REG_PC, BAD_PC);
11999 constraint (Rm == REG_PC, BAD_PC);
12000 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12001 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
12002 }
12003 }
12004 else
12005 reject_bad_reg (Rn);
12006 }
12007
12008 if (!inst.operands[1].isreg)
12009 {
12010 /* Immediate operand. */
12011 if (!in_it_block () && opcode == T_MNEM_mov)
12012 narrow = 0;
12013 if (low_regs && narrow)
12014 {
12015 inst.instruction = THUMB_OP16 (opcode);
12016 inst.instruction |= Rn << 8;
12017 if (inst.reloc.type < BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12018 || inst.reloc.type > BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
12019 {
12020 if (inst.size_req == 2)
12021 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12022 else
12023 inst.relax = opcode;
12024 }
12025 }
12026 else
12027 {
12028 constraint (inst.reloc.type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
12029 && inst.reloc.type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC ,
12030 THUMB1_RELOC_ONLY);
12031
12032 inst.instruction = THUMB_OP32 (inst.instruction);
12033 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12034 inst.instruction |= Rn << r0off;
12035 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12036 }
12037 }
12038 else if (inst.operands[1].shifted && inst.operands[1].immisreg
12039 && (inst.instruction == T_MNEM_mov
12040 || inst.instruction == T_MNEM_movs))
12041 {
12042 /* Register shifts are encoded as separate shift instructions. */
12043 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
12044
12045 if (in_it_block ())
12046 narrow = !flags;
12047 else
12048 narrow = flags;
12049
12050 if (inst.size_req == 4)
12051 narrow = FALSE;
12052
12053 if (!low_regs || inst.operands[1].imm > 7)
12054 narrow = FALSE;
12055
12056 if (Rn != Rm)
12057 narrow = FALSE;
12058
12059 switch (inst.operands[1].shift_kind)
12060 {
12061 case SHIFT_LSL:
12062 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
12063 break;
12064 case SHIFT_ASR:
12065 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
12066 break;
12067 case SHIFT_LSR:
12068 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
12069 break;
12070 case SHIFT_ROR:
12071 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
12072 break;
12073 default:
12074 abort ();
12075 }
12076
12077 inst.instruction = opcode;
12078 if (narrow)
12079 {
12080 inst.instruction |= Rn;
12081 inst.instruction |= inst.operands[1].imm << 3;
12082 }
12083 else
12084 {
12085 if (flags)
12086 inst.instruction |= CONDS_BIT;
12087
12088 inst.instruction |= Rn << 8;
12089 inst.instruction |= Rm << 16;
12090 inst.instruction |= inst.operands[1].imm;
12091 }
12092 }
12093 else if (!narrow)
12094 {
12095 /* Some mov with immediate shift have narrow variants.
12096 Register shifts are handled above. */
12097 if (low_regs && inst.operands[1].shifted
12098 && (inst.instruction == T_MNEM_mov
12099 || inst.instruction == T_MNEM_movs))
12100 {
12101 if (in_it_block ())
12102 narrow = (inst.instruction == T_MNEM_mov);
12103 else
12104 narrow = (inst.instruction == T_MNEM_movs);
12105 }
12106
12107 if (narrow)
12108 {
12109 switch (inst.operands[1].shift_kind)
12110 {
12111 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12112 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12113 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12114 default: narrow = FALSE; break;
12115 }
12116 }
12117
12118 if (narrow)
12119 {
12120 inst.instruction |= Rn;
12121 inst.instruction |= Rm << 3;
12122 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12123 }
12124 else
12125 {
12126 inst.instruction = THUMB_OP32 (inst.instruction);
12127 inst.instruction |= Rn << r0off;
12128 encode_thumb32_shifted_operand (1);
12129 }
12130 }
12131 else
12132 switch (inst.instruction)
12133 {
12134 case T_MNEM_mov:
12135 /* In v4t or v5t a move of two lowregs produces unpredictable
12136 results. Don't allow this. */
12137 if (low_regs)
12138 {
12139 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
12140 "MOV Rd, Rs with two low registers is not "
12141 "permitted on this architecture");
12142 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
12143 arm_ext_v6);
12144 }
12145
12146 inst.instruction = T_OPCODE_MOV_HR;
12147 inst.instruction |= (Rn & 0x8) << 4;
12148 inst.instruction |= (Rn & 0x7);
12149 inst.instruction |= Rm << 3;
12150 break;
12151
12152 case T_MNEM_movs:
12153 /* We know we have low registers at this point.
12154 Generate LSLS Rd, Rs, #0. */
12155 inst.instruction = T_OPCODE_LSL_I;
12156 inst.instruction |= Rn;
12157 inst.instruction |= Rm << 3;
12158 break;
12159
12160 case T_MNEM_cmp:
12161 if (low_regs)
12162 {
12163 inst.instruction = T_OPCODE_CMP_LR;
12164 inst.instruction |= Rn;
12165 inst.instruction |= Rm << 3;
12166 }
12167 else
12168 {
12169 inst.instruction = T_OPCODE_CMP_HR;
12170 inst.instruction |= (Rn & 0x8) << 4;
12171 inst.instruction |= (Rn & 0x7);
12172 inst.instruction |= Rm << 3;
12173 }
12174 break;
12175 }
12176 return;
12177 }
12178
12179 inst.instruction = THUMB_OP16 (inst.instruction);
12180
12181 /* PR 10443: Do not silently ignore shifted operands. */
12182 constraint (inst.operands[1].shifted,
12183 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
12184
12185 if (inst.operands[1].isreg)
12186 {
12187 if (Rn < 8 && Rm < 8)
12188 {
12189 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
12190 since a MOV instruction produces unpredictable results. */
12191 if (inst.instruction == T_OPCODE_MOV_I8)
12192 inst.instruction = T_OPCODE_ADD_I3;
12193 else
12194 inst.instruction = T_OPCODE_CMP_LR;
12195
12196 inst.instruction |= Rn;
12197 inst.instruction |= Rm << 3;
12198 }
12199 else
12200 {
12201 if (inst.instruction == T_OPCODE_MOV_I8)
12202 inst.instruction = T_OPCODE_MOV_HR;
12203 else
12204 inst.instruction = T_OPCODE_CMP_HR;
12205 do_t_cpy ();
12206 }
12207 }
12208 else
12209 {
12210 constraint (Rn > 7,
12211 _("only lo regs allowed with immediate"));
12212 inst.instruction |= Rn << 8;
12213 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
12214 }
12215 }
12216
12217 static void
12218 do_t_mov16 (void)
12219 {
12220 unsigned Rd;
12221 bfd_vma imm;
12222 bfd_boolean top;
12223
12224 top = (inst.instruction & 0x00800000) != 0;
12225 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
12226 {
12227 constraint (top, _(":lower16: not allowed in this instruction"));
12228 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
12229 }
12230 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
12231 {
12232 constraint (!top, _(":upper16: not allowed in this instruction"));
12233 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
12234 }
12235
12236 Rd = inst.operands[0].reg;
12237 reject_bad_reg (Rd);
12238
12239 inst.instruction |= Rd << 8;
12240 if (inst.reloc.type == BFD_RELOC_UNUSED)
12241 {
12242 imm = inst.reloc.exp.X_add_number;
12243 inst.instruction |= (imm & 0xf000) << 4;
12244 inst.instruction |= (imm & 0x0800) << 15;
12245 inst.instruction |= (imm & 0x0700) << 4;
12246 inst.instruction |= (imm & 0x00ff);
12247 }
12248 }
12249
12250 static void
12251 do_t_mvn_tst (void)
12252 {
12253 unsigned Rn, Rm;
12254
12255 Rn = inst.operands[0].reg;
12256 Rm = inst.operands[1].reg;
12257
12258 if (inst.instruction == T_MNEM_cmp
12259 || inst.instruction == T_MNEM_cmn)
12260 constraint (Rn == REG_PC, BAD_PC);
12261 else
12262 reject_bad_reg (Rn);
12263 reject_bad_reg (Rm);
12264
12265 if (unified_syntax)
12266 {
12267 int r0off = (inst.instruction == T_MNEM_mvn
12268 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
12269 bfd_boolean narrow;
12270
12271 if (inst.size_req == 4
12272 || inst.instruction > 0xffff
12273 || inst.operands[1].shifted
12274 || Rn > 7 || Rm > 7)
12275 narrow = FALSE;
12276 else if (inst.instruction == T_MNEM_cmn
12277 || inst.instruction == T_MNEM_tst)
12278 narrow = TRUE;
12279 else if (THUMB_SETS_FLAGS (inst.instruction))
12280 narrow = !in_it_block ();
12281 else
12282 narrow = in_it_block ();
12283
12284 if (!inst.operands[1].isreg)
12285 {
12286 /* For an immediate, we always generate a 32-bit opcode;
12287 section relaxation will shrink it later if possible. */
12288 if (inst.instruction < 0xffff)
12289 inst.instruction = THUMB_OP32 (inst.instruction);
12290 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12291 inst.instruction |= Rn << r0off;
12292 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12293 }
12294 else
12295 {
12296 /* See if we can do this with a 16-bit instruction. */
12297 if (narrow)
12298 {
12299 inst.instruction = THUMB_OP16 (inst.instruction);
12300 inst.instruction |= Rn;
12301 inst.instruction |= Rm << 3;
12302 }
12303 else
12304 {
12305 constraint (inst.operands[1].shifted
12306 && inst.operands[1].immisreg,
12307 _("shift must be constant"));
12308 if (inst.instruction < 0xffff)
12309 inst.instruction = THUMB_OP32 (inst.instruction);
12310 inst.instruction |= Rn << r0off;
12311 encode_thumb32_shifted_operand (1);
12312 }
12313 }
12314 }
12315 else
12316 {
12317 constraint (inst.instruction > 0xffff
12318 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
12319 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
12320 _("unshifted register required"));
12321 constraint (Rn > 7 || Rm > 7,
12322 BAD_HIREG);
12323
12324 inst.instruction = THUMB_OP16 (inst.instruction);
12325 inst.instruction |= Rn;
12326 inst.instruction |= Rm << 3;
12327 }
12328 }
12329
12330 static void
12331 do_t_mrs (void)
12332 {
12333 unsigned Rd;
12334
12335 if (do_vfp_nsyn_mrs () == SUCCESS)
12336 return;
12337
12338 Rd = inst.operands[0].reg;
12339 reject_bad_reg (Rd);
12340 inst.instruction |= Rd << 8;
12341
12342 if (inst.operands[1].isreg)
12343 {
12344 unsigned br = inst.operands[1].reg;
12345 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
12346 as_bad (_("bad register for mrs"));
12347
12348 inst.instruction |= br & (0xf << 16);
12349 inst.instruction |= (br & 0x300) >> 4;
12350 inst.instruction |= (br & SPSR_BIT) >> 2;
12351 }
12352 else
12353 {
12354 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12355
12356 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
12357 {
12358 /* PR gas/12698: The constraint is only applied for m_profile.
12359 If the user has specified -march=all, we want to ignore it as
12360 we are building for any CPU type, including non-m variants. */
12361 bfd_boolean m_profile =
12362 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
12363 constraint ((flags != 0) && m_profile, _("selected processor does "
12364 "not support requested special purpose register"));
12365 }
12366 else
12367 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
12368 devices). */
12369 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
12370 _("'APSR', 'CPSR' or 'SPSR' expected"));
12371
12372 inst.instruction |= (flags & SPSR_BIT) >> 2;
12373 inst.instruction |= inst.operands[1].imm & 0xff;
12374 inst.instruction |= 0xf0000;
12375 }
12376 }
12377
12378 static void
12379 do_t_msr (void)
12380 {
12381 int flags;
12382 unsigned Rn;
12383
12384 if (do_vfp_nsyn_msr () == SUCCESS)
12385 return;
12386
12387 constraint (!inst.operands[1].isreg,
12388 _("Thumb encoding does not support an immediate here"));
12389
12390 if (inst.operands[0].isreg)
12391 flags = (int)(inst.operands[0].reg);
12392 else
12393 flags = inst.operands[0].imm;
12394
12395 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
12396 {
12397 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
12398
12399 /* PR gas/12698: The constraint is only applied for m_profile.
12400 If the user has specified -march=all, we want to ignore it as
12401 we are building for any CPU type, including non-m variants. */
12402 bfd_boolean m_profile =
12403 !ARM_FEATURE_CORE_EQUAL (selected_cpu, arm_arch_any);
12404 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12405 && (bits & ~(PSR_s | PSR_f)) != 0)
12406 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
12407 && bits != PSR_f)) && m_profile,
12408 _("selected processor does not support requested special "
12409 "purpose register"));
12410 }
12411 else
12412 constraint ((flags & 0xff) != 0, _("selected processor does not support "
12413 "requested special purpose register"));
12414
12415 Rn = inst.operands[1].reg;
12416 reject_bad_reg (Rn);
12417
12418 inst.instruction |= (flags & SPSR_BIT) >> 2;
12419 inst.instruction |= (flags & 0xf0000) >> 8;
12420 inst.instruction |= (flags & 0x300) >> 4;
12421 inst.instruction |= (flags & 0xff);
12422 inst.instruction |= Rn << 16;
12423 }
12424
12425 static void
12426 do_t_mul (void)
12427 {
12428 bfd_boolean narrow;
12429 unsigned Rd, Rn, Rm;
12430
12431 if (!inst.operands[2].present)
12432 inst.operands[2].reg = inst.operands[0].reg;
12433
12434 Rd = inst.operands[0].reg;
12435 Rn = inst.operands[1].reg;
12436 Rm = inst.operands[2].reg;
12437
12438 if (unified_syntax)
12439 {
12440 if (inst.size_req == 4
12441 || (Rd != Rn
12442 && Rd != Rm)
12443 || Rn > 7
12444 || Rm > 7)
12445 narrow = FALSE;
12446 else if (inst.instruction == T_MNEM_muls)
12447 narrow = !in_it_block ();
12448 else
12449 narrow = in_it_block ();
12450 }
12451 else
12452 {
12453 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
12454 constraint (Rn > 7 || Rm > 7,
12455 BAD_HIREG);
12456 narrow = TRUE;
12457 }
12458
12459 if (narrow)
12460 {
12461 /* 16-bit MULS/Conditional MUL. */
12462 inst.instruction = THUMB_OP16 (inst.instruction);
12463 inst.instruction |= Rd;
12464
12465 if (Rd == Rn)
12466 inst.instruction |= Rm << 3;
12467 else if (Rd == Rm)
12468 inst.instruction |= Rn << 3;
12469 else
12470 constraint (1, _("dest must overlap one source register"));
12471 }
12472 else
12473 {
12474 constraint (inst.instruction != T_MNEM_mul,
12475 _("Thumb-2 MUL must not set flags"));
12476 /* 32-bit MUL. */
12477 inst.instruction = THUMB_OP32 (inst.instruction);
12478 inst.instruction |= Rd << 8;
12479 inst.instruction |= Rn << 16;
12480 inst.instruction |= Rm << 0;
12481
12482 reject_bad_reg (Rd);
12483 reject_bad_reg (Rn);
12484 reject_bad_reg (Rm);
12485 }
12486 }
12487
12488 static void
12489 do_t_mull (void)
12490 {
12491 unsigned RdLo, RdHi, Rn, Rm;
12492
12493 RdLo = inst.operands[0].reg;
12494 RdHi = inst.operands[1].reg;
12495 Rn = inst.operands[2].reg;
12496 Rm = inst.operands[3].reg;
12497
12498 reject_bad_reg (RdLo);
12499 reject_bad_reg (RdHi);
12500 reject_bad_reg (Rn);
12501 reject_bad_reg (Rm);
12502
12503 inst.instruction |= RdLo << 12;
12504 inst.instruction |= RdHi << 8;
12505 inst.instruction |= Rn << 16;
12506 inst.instruction |= Rm;
12507
12508 if (RdLo == RdHi)
12509 as_tsktsk (_("rdhi and rdlo must be different"));
12510 }
12511
12512 static void
12513 do_t_nop (void)
12514 {
12515 set_it_insn_type (NEUTRAL_IT_INSN);
12516
12517 if (unified_syntax)
12518 {
12519 if (inst.size_req == 4 || inst.operands[0].imm > 15)
12520 {
12521 inst.instruction = THUMB_OP32 (inst.instruction);
12522 inst.instruction |= inst.operands[0].imm;
12523 }
12524 else
12525 {
12526 /* PR9722: Check for Thumb2 availability before
12527 generating a thumb2 nop instruction. */
12528 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
12529 {
12530 inst.instruction = THUMB_OP16 (inst.instruction);
12531 inst.instruction |= inst.operands[0].imm << 4;
12532 }
12533 else
12534 inst.instruction = 0x46c0;
12535 }
12536 }
12537 else
12538 {
12539 constraint (inst.operands[0].present,
12540 _("Thumb does not support NOP with hints"));
12541 inst.instruction = 0x46c0;
12542 }
12543 }
12544
12545 static void
12546 do_t_neg (void)
12547 {
12548 if (unified_syntax)
12549 {
12550 bfd_boolean narrow;
12551
12552 if (THUMB_SETS_FLAGS (inst.instruction))
12553 narrow = !in_it_block ();
12554 else
12555 narrow = in_it_block ();
12556 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12557 narrow = FALSE;
12558 if (inst.size_req == 4)
12559 narrow = FALSE;
12560
12561 if (!narrow)
12562 {
12563 inst.instruction = THUMB_OP32 (inst.instruction);
12564 inst.instruction |= inst.operands[0].reg << 8;
12565 inst.instruction |= inst.operands[1].reg << 16;
12566 }
12567 else
12568 {
12569 inst.instruction = THUMB_OP16 (inst.instruction);
12570 inst.instruction |= inst.operands[0].reg;
12571 inst.instruction |= inst.operands[1].reg << 3;
12572 }
12573 }
12574 else
12575 {
12576 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
12577 BAD_HIREG);
12578 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12579
12580 inst.instruction = THUMB_OP16 (inst.instruction);
12581 inst.instruction |= inst.operands[0].reg;
12582 inst.instruction |= inst.operands[1].reg << 3;
12583 }
12584 }
12585
12586 static void
12587 do_t_orn (void)
12588 {
12589 unsigned Rd, Rn;
12590
12591 Rd = inst.operands[0].reg;
12592 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
12593
12594 reject_bad_reg (Rd);
12595 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
12596 reject_bad_reg (Rn);
12597
12598 inst.instruction |= Rd << 8;
12599 inst.instruction |= Rn << 16;
12600
12601 if (!inst.operands[2].isreg)
12602 {
12603 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12604 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12605 }
12606 else
12607 {
12608 unsigned Rm;
12609
12610 Rm = inst.operands[2].reg;
12611 reject_bad_reg (Rm);
12612
12613 constraint (inst.operands[2].shifted
12614 && inst.operands[2].immisreg,
12615 _("shift must be constant"));
12616 encode_thumb32_shifted_operand (2);
12617 }
12618 }
12619
12620 static void
12621 do_t_pkhbt (void)
12622 {
12623 unsigned Rd, Rn, Rm;
12624
12625 Rd = inst.operands[0].reg;
12626 Rn = inst.operands[1].reg;
12627 Rm = inst.operands[2].reg;
12628
12629 reject_bad_reg (Rd);
12630 reject_bad_reg (Rn);
12631 reject_bad_reg (Rm);
12632
12633 inst.instruction |= Rd << 8;
12634 inst.instruction |= Rn << 16;
12635 inst.instruction |= Rm;
12636 if (inst.operands[3].present)
12637 {
12638 unsigned int val = inst.reloc.exp.X_add_number;
12639 constraint (inst.reloc.exp.X_op != O_constant,
12640 _("expression too complex"));
12641 inst.instruction |= (val & 0x1c) << 10;
12642 inst.instruction |= (val & 0x03) << 6;
12643 }
12644 }
12645
12646 static void
12647 do_t_pkhtb (void)
12648 {
12649 if (!inst.operands[3].present)
12650 {
12651 unsigned Rtmp;
12652
12653 inst.instruction &= ~0x00000020;
12654
12655 /* PR 10168. Swap the Rm and Rn registers. */
12656 Rtmp = inst.operands[1].reg;
12657 inst.operands[1].reg = inst.operands[2].reg;
12658 inst.operands[2].reg = Rtmp;
12659 }
12660 do_t_pkhbt ();
12661 }
12662
12663 static void
12664 do_t_pld (void)
12665 {
12666 if (inst.operands[0].immisreg)
12667 reject_bad_reg (inst.operands[0].imm);
12668
12669 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
12670 }
12671
12672 static void
12673 do_t_push_pop (void)
12674 {
12675 unsigned mask;
12676
12677 constraint (inst.operands[0].writeback,
12678 _("push/pop do not support {reglist}^"));
12679 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
12680 _("expression too complex"));
12681
12682 mask = inst.operands[0].imm;
12683 if (inst.size_req != 4 && (mask & ~0xff) == 0)
12684 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
12685 else if (inst.size_req != 4
12686 && (mask & ~0xff) == (1U << (inst.instruction == T_MNEM_push
12687 ? REG_LR : REG_PC)))
12688 {
12689 inst.instruction = THUMB_OP16 (inst.instruction);
12690 inst.instruction |= THUMB_PP_PC_LR;
12691 inst.instruction |= mask & 0xff;
12692 }
12693 else if (unified_syntax)
12694 {
12695 inst.instruction = THUMB_OP32 (inst.instruction);
12696 encode_thumb2_ldmstm (13, mask, TRUE);
12697 }
12698 else
12699 {
12700 inst.error = _("invalid register list to push/pop instruction");
12701 return;
12702 }
12703 }
12704
12705 static void
12706 do_t_rbit (void)
12707 {
12708 unsigned Rd, Rm;
12709
12710 Rd = inst.operands[0].reg;
12711 Rm = inst.operands[1].reg;
12712
12713 reject_bad_reg (Rd);
12714 reject_bad_reg (Rm);
12715
12716 inst.instruction |= Rd << 8;
12717 inst.instruction |= Rm << 16;
12718 inst.instruction |= Rm;
12719 }
12720
12721 static void
12722 do_t_rev (void)
12723 {
12724 unsigned Rd, Rm;
12725
12726 Rd = inst.operands[0].reg;
12727 Rm = inst.operands[1].reg;
12728
12729 reject_bad_reg (Rd);
12730 reject_bad_reg (Rm);
12731
12732 if (Rd <= 7 && Rm <= 7
12733 && inst.size_req != 4)
12734 {
12735 inst.instruction = THUMB_OP16 (inst.instruction);
12736 inst.instruction |= Rd;
12737 inst.instruction |= Rm << 3;
12738 }
12739 else if (unified_syntax)
12740 {
12741 inst.instruction = THUMB_OP32 (inst.instruction);
12742 inst.instruction |= Rd << 8;
12743 inst.instruction |= Rm << 16;
12744 inst.instruction |= Rm;
12745 }
12746 else
12747 inst.error = BAD_HIREG;
12748 }
12749
12750 static void
12751 do_t_rrx (void)
12752 {
12753 unsigned Rd, Rm;
12754
12755 Rd = inst.operands[0].reg;
12756 Rm = inst.operands[1].reg;
12757
12758 reject_bad_reg (Rd);
12759 reject_bad_reg (Rm);
12760
12761 inst.instruction |= Rd << 8;
12762 inst.instruction |= Rm;
12763 }
12764
12765 static void
12766 do_t_rsb (void)
12767 {
12768 unsigned Rd, Rs;
12769
12770 Rd = inst.operands[0].reg;
12771 Rs = (inst.operands[1].present
12772 ? inst.operands[1].reg /* Rd, Rs, foo */
12773 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
12774
12775 reject_bad_reg (Rd);
12776 reject_bad_reg (Rs);
12777 if (inst.operands[2].isreg)
12778 reject_bad_reg (inst.operands[2].reg);
12779
12780 inst.instruction |= Rd << 8;
12781 inst.instruction |= Rs << 16;
12782 if (!inst.operands[2].isreg)
12783 {
12784 bfd_boolean narrow;
12785
12786 if ((inst.instruction & 0x00100000) != 0)
12787 narrow = !in_it_block ();
12788 else
12789 narrow = in_it_block ();
12790
12791 if (Rd > 7 || Rs > 7)
12792 narrow = FALSE;
12793
12794 if (inst.size_req == 4 || !unified_syntax)
12795 narrow = FALSE;
12796
12797 if (inst.reloc.exp.X_op != O_constant
12798 || inst.reloc.exp.X_add_number != 0)
12799 narrow = FALSE;
12800
12801 /* Turn rsb #0 into 16-bit neg. We should probably do this via
12802 relaxation, but it doesn't seem worth the hassle. */
12803 if (narrow)
12804 {
12805 inst.reloc.type = BFD_RELOC_UNUSED;
12806 inst.instruction = THUMB_OP16 (T_MNEM_negs);
12807 inst.instruction |= Rs << 3;
12808 inst.instruction |= Rd;
12809 }
12810 else
12811 {
12812 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
12813 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
12814 }
12815 }
12816 else
12817 encode_thumb32_shifted_operand (2);
12818 }
12819
12820 static void
12821 do_t_setend (void)
12822 {
12823 if (warn_on_deprecated
12824 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
12825 as_tsktsk (_("setend use is deprecated for ARMv8"));
12826
12827 set_it_insn_type (OUTSIDE_IT_INSN);
12828 if (inst.operands[0].imm)
12829 inst.instruction |= 0x8;
12830 }
12831
12832 static void
12833 do_t_shift (void)
12834 {
12835 if (!inst.operands[1].present)
12836 inst.operands[1].reg = inst.operands[0].reg;
12837
12838 if (unified_syntax)
12839 {
12840 bfd_boolean narrow;
12841 int shift_kind;
12842
12843 switch (inst.instruction)
12844 {
12845 case T_MNEM_asr:
12846 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
12847 case T_MNEM_lsl:
12848 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
12849 case T_MNEM_lsr:
12850 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
12851 case T_MNEM_ror:
12852 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
12853 default: abort ();
12854 }
12855
12856 if (THUMB_SETS_FLAGS (inst.instruction))
12857 narrow = !in_it_block ();
12858 else
12859 narrow = in_it_block ();
12860 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
12861 narrow = FALSE;
12862 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
12863 narrow = FALSE;
12864 if (inst.operands[2].isreg
12865 && (inst.operands[1].reg != inst.operands[0].reg
12866 || inst.operands[2].reg > 7))
12867 narrow = FALSE;
12868 if (inst.size_req == 4)
12869 narrow = FALSE;
12870
12871 reject_bad_reg (inst.operands[0].reg);
12872 reject_bad_reg (inst.operands[1].reg);
12873
12874 if (!narrow)
12875 {
12876 if (inst.operands[2].isreg)
12877 {
12878 reject_bad_reg (inst.operands[2].reg);
12879 inst.instruction = THUMB_OP32 (inst.instruction);
12880 inst.instruction |= inst.operands[0].reg << 8;
12881 inst.instruction |= inst.operands[1].reg << 16;
12882 inst.instruction |= inst.operands[2].reg;
12883
12884 /* PR 12854: Error on extraneous shifts. */
12885 constraint (inst.operands[2].shifted,
12886 _("extraneous shift as part of operand to shift insn"));
12887 }
12888 else
12889 {
12890 inst.operands[1].shifted = 1;
12891 inst.operands[1].shift_kind = shift_kind;
12892 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
12893 ? T_MNEM_movs : T_MNEM_mov);
12894 inst.instruction |= inst.operands[0].reg << 8;
12895 encode_thumb32_shifted_operand (1);
12896 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
12897 inst.reloc.type = BFD_RELOC_UNUSED;
12898 }
12899 }
12900 else
12901 {
12902 if (inst.operands[2].isreg)
12903 {
12904 switch (shift_kind)
12905 {
12906 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
12907 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
12908 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
12909 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
12910 default: abort ();
12911 }
12912
12913 inst.instruction |= inst.operands[0].reg;
12914 inst.instruction |= inst.operands[2].reg << 3;
12915
12916 /* PR 12854: Error on extraneous shifts. */
12917 constraint (inst.operands[2].shifted,
12918 _("extraneous shift as part of operand to shift insn"));
12919 }
12920 else
12921 {
12922 switch (shift_kind)
12923 {
12924 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
12925 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
12926 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
12927 default: abort ();
12928 }
12929 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12930 inst.instruction |= inst.operands[0].reg;
12931 inst.instruction |= inst.operands[1].reg << 3;
12932 }
12933 }
12934 }
12935 else
12936 {
12937 constraint (inst.operands[0].reg > 7
12938 || inst.operands[1].reg > 7, BAD_HIREG);
12939 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
12940
12941 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
12942 {
12943 constraint (inst.operands[2].reg > 7, BAD_HIREG);
12944 constraint (inst.operands[0].reg != inst.operands[1].reg,
12945 _("source1 and dest must be same register"));
12946
12947 switch (inst.instruction)
12948 {
12949 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
12950 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
12951 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
12952 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
12953 default: abort ();
12954 }
12955
12956 inst.instruction |= inst.operands[0].reg;
12957 inst.instruction |= inst.operands[2].reg << 3;
12958
12959 /* PR 12854: Error on extraneous shifts. */
12960 constraint (inst.operands[2].shifted,
12961 _("extraneous shift as part of operand to shift insn"));
12962 }
12963 else
12964 {
12965 switch (inst.instruction)
12966 {
12967 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
12968 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
12969 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
12970 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
12971 default: abort ();
12972 }
12973 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
12974 inst.instruction |= inst.operands[0].reg;
12975 inst.instruction |= inst.operands[1].reg << 3;
12976 }
12977 }
12978 }
12979
12980 static void
12981 do_t_simd (void)
12982 {
12983 unsigned Rd, Rn, Rm;
12984
12985 Rd = inst.operands[0].reg;
12986 Rn = inst.operands[1].reg;
12987 Rm = inst.operands[2].reg;
12988
12989 reject_bad_reg (Rd);
12990 reject_bad_reg (Rn);
12991 reject_bad_reg (Rm);
12992
12993 inst.instruction |= Rd << 8;
12994 inst.instruction |= Rn << 16;
12995 inst.instruction |= Rm;
12996 }
12997
12998 static void
12999 do_t_simd2 (void)
13000 {
13001 unsigned Rd, Rn, Rm;
13002
13003 Rd = inst.operands[0].reg;
13004 Rm = inst.operands[1].reg;
13005 Rn = inst.operands[2].reg;
13006
13007 reject_bad_reg (Rd);
13008 reject_bad_reg (Rn);
13009 reject_bad_reg (Rm);
13010
13011 inst.instruction |= Rd << 8;
13012 inst.instruction |= Rn << 16;
13013 inst.instruction |= Rm;
13014 }
13015
13016 static void
13017 do_t_smc (void)
13018 {
13019 unsigned int value = inst.reloc.exp.X_add_number;
13020 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
13021 _("SMC is not permitted on this architecture"));
13022 constraint (inst.reloc.exp.X_op != O_constant,
13023 _("expression too complex"));
13024 inst.reloc.type = BFD_RELOC_UNUSED;
13025 inst.instruction |= (value & 0xf000) >> 12;
13026 inst.instruction |= (value & 0x0ff0);
13027 inst.instruction |= (value & 0x000f) << 16;
13028 /* PR gas/15623: SMC instructions must be last in an IT block. */
13029 set_it_insn_type_last ();
13030 }
13031
13032 static void
13033 do_t_hvc (void)
13034 {
13035 unsigned int value = inst.reloc.exp.X_add_number;
13036
13037 inst.reloc.type = BFD_RELOC_UNUSED;
13038 inst.instruction |= (value & 0x0fff);
13039 inst.instruction |= (value & 0xf000) << 4;
13040 }
13041
13042 static void
13043 do_t_ssat_usat (int bias)
13044 {
13045 unsigned Rd, Rn;
13046
13047 Rd = inst.operands[0].reg;
13048 Rn = inst.operands[2].reg;
13049
13050 reject_bad_reg (Rd);
13051 reject_bad_reg (Rn);
13052
13053 inst.instruction |= Rd << 8;
13054 inst.instruction |= inst.operands[1].imm - bias;
13055 inst.instruction |= Rn << 16;
13056
13057 if (inst.operands[3].present)
13058 {
13059 offsetT shift_amount = inst.reloc.exp.X_add_number;
13060
13061 inst.reloc.type = BFD_RELOC_UNUSED;
13062
13063 constraint (inst.reloc.exp.X_op != O_constant,
13064 _("expression too complex"));
13065
13066 if (shift_amount != 0)
13067 {
13068 constraint (shift_amount > 31,
13069 _("shift expression is too large"));
13070
13071 if (inst.operands[3].shift_kind == SHIFT_ASR)
13072 inst.instruction |= 0x00200000; /* sh bit. */
13073
13074 inst.instruction |= (shift_amount & 0x1c) << 10;
13075 inst.instruction |= (shift_amount & 0x03) << 6;
13076 }
13077 }
13078 }
13079
13080 static void
13081 do_t_ssat (void)
13082 {
13083 do_t_ssat_usat (1);
13084 }
13085
13086 static void
13087 do_t_ssat16 (void)
13088 {
13089 unsigned Rd, Rn;
13090
13091 Rd = inst.operands[0].reg;
13092 Rn = inst.operands[2].reg;
13093
13094 reject_bad_reg (Rd);
13095 reject_bad_reg (Rn);
13096
13097 inst.instruction |= Rd << 8;
13098 inst.instruction |= inst.operands[1].imm - 1;
13099 inst.instruction |= Rn << 16;
13100 }
13101
13102 static void
13103 do_t_strex (void)
13104 {
13105 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
13106 || inst.operands[2].postind || inst.operands[2].writeback
13107 || inst.operands[2].immisreg || inst.operands[2].shifted
13108 || inst.operands[2].negative,
13109 BAD_ADDR_MODE);
13110
13111 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
13112
13113 inst.instruction |= inst.operands[0].reg << 8;
13114 inst.instruction |= inst.operands[1].reg << 12;
13115 inst.instruction |= inst.operands[2].reg << 16;
13116 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
13117 }
13118
13119 static void
13120 do_t_strexd (void)
13121 {
13122 if (!inst.operands[2].present)
13123 inst.operands[2].reg = inst.operands[1].reg + 1;
13124
13125 constraint (inst.operands[0].reg == inst.operands[1].reg
13126 || inst.operands[0].reg == inst.operands[2].reg
13127 || inst.operands[0].reg == inst.operands[3].reg,
13128 BAD_OVERLAP);
13129
13130 inst.instruction |= inst.operands[0].reg;
13131 inst.instruction |= inst.operands[1].reg << 12;
13132 inst.instruction |= inst.operands[2].reg << 8;
13133 inst.instruction |= inst.operands[3].reg << 16;
13134 }
13135
13136 static void
13137 do_t_sxtah (void)
13138 {
13139 unsigned Rd, Rn, Rm;
13140
13141 Rd = inst.operands[0].reg;
13142 Rn = inst.operands[1].reg;
13143 Rm = inst.operands[2].reg;
13144
13145 reject_bad_reg (Rd);
13146 reject_bad_reg (Rn);
13147 reject_bad_reg (Rm);
13148
13149 inst.instruction |= Rd << 8;
13150 inst.instruction |= Rn << 16;
13151 inst.instruction |= Rm;
13152 inst.instruction |= inst.operands[3].imm << 4;
13153 }
13154
13155 static void
13156 do_t_sxth (void)
13157 {
13158 unsigned Rd, Rm;
13159
13160 Rd = inst.operands[0].reg;
13161 Rm = inst.operands[1].reg;
13162
13163 reject_bad_reg (Rd);
13164 reject_bad_reg (Rm);
13165
13166 if (inst.instruction <= 0xffff
13167 && inst.size_req != 4
13168 && Rd <= 7 && Rm <= 7
13169 && (!inst.operands[2].present || inst.operands[2].imm == 0))
13170 {
13171 inst.instruction = THUMB_OP16 (inst.instruction);
13172 inst.instruction |= Rd;
13173 inst.instruction |= Rm << 3;
13174 }
13175 else if (unified_syntax)
13176 {
13177 if (inst.instruction <= 0xffff)
13178 inst.instruction = THUMB_OP32 (inst.instruction);
13179 inst.instruction |= Rd << 8;
13180 inst.instruction |= Rm;
13181 inst.instruction |= inst.operands[2].imm << 4;
13182 }
13183 else
13184 {
13185 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
13186 _("Thumb encoding does not support rotation"));
13187 constraint (1, BAD_HIREG);
13188 }
13189 }
13190
13191 static void
13192 do_t_swi (void)
13193 {
13194 inst.reloc.type = BFD_RELOC_ARM_SWI;
13195 }
13196
13197 static void
13198 do_t_tb (void)
13199 {
13200 unsigned Rn, Rm;
13201 int half;
13202
13203 half = (inst.instruction & 0x10) != 0;
13204 set_it_insn_type_last ();
13205 constraint (inst.operands[0].immisreg,
13206 _("instruction requires register index"));
13207
13208 Rn = inst.operands[0].reg;
13209 Rm = inst.operands[0].imm;
13210
13211 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8))
13212 constraint (Rn == REG_SP, BAD_SP);
13213 reject_bad_reg (Rm);
13214
13215 constraint (!half && inst.operands[0].shifted,
13216 _("instruction does not allow shifted index"));
13217 inst.instruction |= (Rn << 16) | Rm;
13218 }
13219
13220 static void
13221 do_t_udf (void)
13222 {
13223 if (!inst.operands[0].present)
13224 inst.operands[0].imm = 0;
13225
13226 if ((unsigned int) inst.operands[0].imm > 255 || inst.size_req == 4)
13227 {
13228 constraint (inst.size_req == 2,
13229 _("immediate value out of range"));
13230 inst.instruction = THUMB_OP32 (inst.instruction);
13231 inst.instruction |= (inst.operands[0].imm & 0xf000u) << 4;
13232 inst.instruction |= (inst.operands[0].imm & 0x0fffu) << 0;
13233 }
13234 else
13235 {
13236 inst.instruction = THUMB_OP16 (inst.instruction);
13237 inst.instruction |= inst.operands[0].imm;
13238 }
13239
13240 set_it_insn_type (NEUTRAL_IT_INSN);
13241 }
13242
13243
13244 static void
13245 do_t_usat (void)
13246 {
13247 do_t_ssat_usat (0);
13248 }
13249
13250 static void
13251 do_t_usat16 (void)
13252 {
13253 unsigned Rd, Rn;
13254
13255 Rd = inst.operands[0].reg;
13256 Rn = inst.operands[2].reg;
13257
13258 reject_bad_reg (Rd);
13259 reject_bad_reg (Rn);
13260
13261 inst.instruction |= Rd << 8;
13262 inst.instruction |= inst.operands[1].imm;
13263 inst.instruction |= Rn << 16;
13264 }
13265
13266 /* Neon instruction encoder helpers. */
13267
13268 /* Encodings for the different types for various Neon opcodes. */
13269
13270 /* An "invalid" code for the following tables. */
13271 #define N_INV -1u
13272
13273 struct neon_tab_entry
13274 {
13275 unsigned integer;
13276 unsigned float_or_poly;
13277 unsigned scalar_or_imm;
13278 };
13279
13280 /* Map overloaded Neon opcodes to their respective encodings. */
13281 #define NEON_ENC_TAB \
13282 X(vabd, 0x0000700, 0x1200d00, N_INV), \
13283 X(vmax, 0x0000600, 0x0000f00, N_INV), \
13284 X(vmin, 0x0000610, 0x0200f00, N_INV), \
13285 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
13286 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
13287 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
13288 X(vadd, 0x0000800, 0x0000d00, N_INV), \
13289 X(vsub, 0x1000800, 0x0200d00, N_INV), \
13290 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
13291 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
13292 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
13293 /* Register variants of the following two instructions are encoded as
13294 vcge / vcgt with the operands reversed. */ \
13295 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
13296 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
13297 X(vfma, N_INV, 0x0000c10, N_INV), \
13298 X(vfms, N_INV, 0x0200c10, N_INV), \
13299 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
13300 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
13301 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
13302 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
13303 X(vmlal, 0x0800800, N_INV, 0x0800240), \
13304 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
13305 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
13306 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
13307 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
13308 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
13309 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
13310 X(vqrdmlah, 0x3000b10, N_INV, 0x0800e40), \
13311 X(vqrdmlsh, 0x3000c10, N_INV, 0x0800f40), \
13312 X(vshl, 0x0000400, N_INV, 0x0800510), \
13313 X(vqshl, 0x0000410, N_INV, 0x0800710), \
13314 X(vand, 0x0000110, N_INV, 0x0800030), \
13315 X(vbic, 0x0100110, N_INV, 0x0800030), \
13316 X(veor, 0x1000110, N_INV, N_INV), \
13317 X(vorn, 0x0300110, N_INV, 0x0800010), \
13318 X(vorr, 0x0200110, N_INV, 0x0800010), \
13319 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
13320 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
13321 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
13322 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
13323 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
13324 X(vst1, 0x0000000, 0x0800000, N_INV), \
13325 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
13326 X(vst2, 0x0000100, 0x0800100, N_INV), \
13327 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
13328 X(vst3, 0x0000200, 0x0800200, N_INV), \
13329 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
13330 X(vst4, 0x0000300, 0x0800300, N_INV), \
13331 X(vmovn, 0x1b20200, N_INV, N_INV), \
13332 X(vtrn, 0x1b20080, N_INV, N_INV), \
13333 X(vqmovn, 0x1b20200, N_INV, N_INV), \
13334 X(vqmovun, 0x1b20240, N_INV, N_INV), \
13335 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
13336 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
13337 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
13338 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
13339 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
13340 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
13341 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
13342 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
13343 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV), \
13344 X(vseleq, 0xe000a00, N_INV, N_INV), \
13345 X(vselvs, 0xe100a00, N_INV, N_INV), \
13346 X(vselge, 0xe200a00, N_INV, N_INV), \
13347 X(vselgt, 0xe300a00, N_INV, N_INV), \
13348 X(vmaxnm, 0xe800a00, 0x3000f10, N_INV), \
13349 X(vminnm, 0xe800a40, 0x3200f10, N_INV), \
13350 X(vcvta, 0xebc0a40, 0x3bb0000, N_INV), \
13351 X(vrintr, 0xeb60a40, 0x3ba0400, N_INV), \
13352 X(vrinta, 0xeb80a40, 0x3ba0400, N_INV), \
13353 X(aes, 0x3b00300, N_INV, N_INV), \
13354 X(sha3op, 0x2000c00, N_INV, N_INV), \
13355 X(sha1h, 0x3b902c0, N_INV, N_INV), \
13356 X(sha2op, 0x3ba0380, N_INV, N_INV)
13357
13358 enum neon_opc
13359 {
13360 #define X(OPC,I,F,S) N_MNEM_##OPC
13361 NEON_ENC_TAB
13362 #undef X
13363 };
13364
13365 static const struct neon_tab_entry neon_enc_tab[] =
13366 {
13367 #define X(OPC,I,F,S) { (I), (F), (S) }
13368 NEON_ENC_TAB
13369 #undef X
13370 };
13371
13372 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
13373 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13374 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13375 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13376 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13377 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13378 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13379 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
13380 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
13381 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
13382 #define NEON_ENC_SINGLE_(X) \
13383 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
13384 #define NEON_ENC_DOUBLE_(X) \
13385 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
13386 #define NEON_ENC_FPV8_(X) \
13387 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf000000))
13388
13389 #define NEON_ENCODE(type, inst) \
13390 do \
13391 { \
13392 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
13393 inst.is_neon = 1; \
13394 } \
13395 while (0)
13396
13397 #define check_neon_suffixes \
13398 do \
13399 { \
13400 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
13401 { \
13402 as_bad (_("invalid neon suffix for non neon instruction")); \
13403 return; \
13404 } \
13405 } \
13406 while (0)
13407
13408 /* Define shapes for instruction operands. The following mnemonic characters
13409 are used in this table:
13410
13411 F - VFP S<n> register
13412 D - Neon D<n> register
13413 Q - Neon Q<n> register
13414 I - Immediate
13415 S - Scalar
13416 R - ARM register
13417 L - D<n> register list
13418
13419 This table is used to generate various data:
13420 - enumerations of the form NS_DDR to be used as arguments to
13421 neon_select_shape.
13422 - a table classifying shapes into single, double, quad, mixed.
13423 - a table used to drive neon_select_shape. */
13424
13425 #define NEON_SHAPE_DEF \
13426 X(3, (D, D, D), DOUBLE), \
13427 X(3, (Q, Q, Q), QUAD), \
13428 X(3, (D, D, I), DOUBLE), \
13429 X(3, (Q, Q, I), QUAD), \
13430 X(3, (D, D, S), DOUBLE), \
13431 X(3, (Q, Q, S), QUAD), \
13432 X(2, (D, D), DOUBLE), \
13433 X(2, (Q, Q), QUAD), \
13434 X(2, (D, S), DOUBLE), \
13435 X(2, (Q, S), QUAD), \
13436 X(2, (D, R), DOUBLE), \
13437 X(2, (Q, R), QUAD), \
13438 X(2, (D, I), DOUBLE), \
13439 X(2, (Q, I), QUAD), \
13440 X(3, (D, L, D), DOUBLE), \
13441 X(2, (D, Q), MIXED), \
13442 X(2, (Q, D), MIXED), \
13443 X(3, (D, Q, I), MIXED), \
13444 X(3, (Q, D, I), MIXED), \
13445 X(3, (Q, D, D), MIXED), \
13446 X(3, (D, Q, Q), MIXED), \
13447 X(3, (Q, Q, D), MIXED), \
13448 X(3, (Q, D, S), MIXED), \
13449 X(3, (D, Q, S), MIXED), \
13450 X(4, (D, D, D, I), DOUBLE), \
13451 X(4, (Q, Q, Q, I), QUAD), \
13452 X(4, (D, D, S, I), DOUBLE), \
13453 X(4, (Q, Q, S, I), QUAD), \
13454 X(2, (F, F), SINGLE), \
13455 X(3, (F, F, F), SINGLE), \
13456 X(2, (F, I), SINGLE), \
13457 X(2, (F, D), MIXED), \
13458 X(2, (D, F), MIXED), \
13459 X(3, (F, F, I), MIXED), \
13460 X(4, (R, R, F, F), SINGLE), \
13461 X(4, (F, F, R, R), SINGLE), \
13462 X(3, (D, R, R), DOUBLE), \
13463 X(3, (R, R, D), DOUBLE), \
13464 X(2, (S, R), SINGLE), \
13465 X(2, (R, S), SINGLE), \
13466 X(2, (F, R), SINGLE), \
13467 X(2, (R, F), SINGLE), \
13468 /* Half float shape supported so far. */\
13469 X (2, (H, D), MIXED), \
13470 X (2, (D, H), MIXED), \
13471 X (2, (H, F), MIXED), \
13472 X (2, (F, H), MIXED), \
13473 X (2, (H, H), HALF), \
13474 X (2, (H, R), HALF), \
13475 X (2, (R, H), HALF), \
13476 X (2, (H, I), HALF), \
13477 X (3, (H, H, H), HALF), \
13478 X (3, (H, F, I), MIXED), \
13479 X (3, (F, H, I), MIXED), \
13480 X (3, (D, H, H), MIXED), \
13481 X (3, (D, H, S), MIXED)
13482
13483 #define S2(A,B) NS_##A##B
13484 #define S3(A,B,C) NS_##A##B##C
13485 #define S4(A,B,C,D) NS_##A##B##C##D
13486
13487 #define X(N, L, C) S##N L
13488
13489 enum neon_shape
13490 {
13491 NEON_SHAPE_DEF,
13492 NS_NULL
13493 };
13494
13495 #undef X
13496 #undef S2
13497 #undef S3
13498 #undef S4
13499
13500 enum neon_shape_class
13501 {
13502 SC_HALF,
13503 SC_SINGLE,
13504 SC_DOUBLE,
13505 SC_QUAD,
13506 SC_MIXED
13507 };
13508
13509 #define X(N, L, C) SC_##C
13510
13511 static enum neon_shape_class neon_shape_class[] =
13512 {
13513 NEON_SHAPE_DEF
13514 };
13515
13516 #undef X
13517
13518 enum neon_shape_el
13519 {
13520 SE_H,
13521 SE_F,
13522 SE_D,
13523 SE_Q,
13524 SE_I,
13525 SE_S,
13526 SE_R,
13527 SE_L
13528 };
13529
13530 /* Register widths of above. */
13531 static unsigned neon_shape_el_size[] =
13532 {
13533 16,
13534 32,
13535 64,
13536 128,
13537 0,
13538 32,
13539 32,
13540 0
13541 };
13542
13543 struct neon_shape_info
13544 {
13545 unsigned els;
13546 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
13547 };
13548
13549 #define S2(A,B) { SE_##A, SE_##B }
13550 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
13551 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
13552
13553 #define X(N, L, C) { N, S##N L }
13554
13555 static struct neon_shape_info neon_shape_tab[] =
13556 {
13557 NEON_SHAPE_DEF
13558 };
13559
13560 #undef X
13561 #undef S2
13562 #undef S3
13563 #undef S4
13564
13565 /* Bit masks used in type checking given instructions.
13566 'N_EQK' means the type must be the same as (or based on in some way) the key
13567 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
13568 set, various other bits can be set as well in order to modify the meaning of
13569 the type constraint. */
13570
13571 enum neon_type_mask
13572 {
13573 N_S8 = 0x0000001,
13574 N_S16 = 0x0000002,
13575 N_S32 = 0x0000004,
13576 N_S64 = 0x0000008,
13577 N_U8 = 0x0000010,
13578 N_U16 = 0x0000020,
13579 N_U32 = 0x0000040,
13580 N_U64 = 0x0000080,
13581 N_I8 = 0x0000100,
13582 N_I16 = 0x0000200,
13583 N_I32 = 0x0000400,
13584 N_I64 = 0x0000800,
13585 N_8 = 0x0001000,
13586 N_16 = 0x0002000,
13587 N_32 = 0x0004000,
13588 N_64 = 0x0008000,
13589 N_P8 = 0x0010000,
13590 N_P16 = 0x0020000,
13591 N_F16 = 0x0040000,
13592 N_F32 = 0x0080000,
13593 N_F64 = 0x0100000,
13594 N_P64 = 0x0200000,
13595 N_KEY = 0x1000000, /* Key element (main type specifier). */
13596 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
13597 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
13598 N_UNT = 0x8000000, /* Must be explicitly untyped. */
13599 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
13600 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
13601 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
13602 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
13603 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
13604 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
13605 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
13606 N_UTYP = 0,
13607 N_MAX_NONSPECIAL = N_P64
13608 };
13609
13610 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
13611
13612 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
13613 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
13614 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
13615 #define N_S_32 (N_S8 | N_S16 | N_S32)
13616 #define N_F_16_32 (N_F16 | N_F32)
13617 #define N_SUF_32 (N_SU_32 | N_F_16_32)
13618 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
13619 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F16 | N_F32)
13620 #define N_F_ALL (N_F16 | N_F32 | N_F64)
13621
13622 /* Pass this as the first type argument to neon_check_type to ignore types
13623 altogether. */
13624 #define N_IGNORE_TYPE (N_KEY | N_EQK)
13625
13626 /* Select a "shape" for the current instruction (describing register types or
13627 sizes) from a list of alternatives. Return NS_NULL if the current instruction
13628 doesn't fit. For non-polymorphic shapes, checking is usually done as a
13629 function of operand parsing, so this function doesn't need to be called.
13630 Shapes should be listed in order of decreasing length. */
13631
13632 static enum neon_shape
13633 neon_select_shape (enum neon_shape shape, ...)
13634 {
13635 va_list ap;
13636 enum neon_shape first_shape = shape;
13637
13638 /* Fix missing optional operands. FIXME: we don't know at this point how
13639 many arguments we should have, so this makes the assumption that we have
13640 > 1. This is true of all current Neon opcodes, I think, but may not be
13641 true in the future. */
13642 if (!inst.operands[1].present)
13643 inst.operands[1] = inst.operands[0];
13644
13645 va_start (ap, shape);
13646
13647 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
13648 {
13649 unsigned j;
13650 int matches = 1;
13651
13652 for (j = 0; j < neon_shape_tab[shape].els; j++)
13653 {
13654 if (!inst.operands[j].present)
13655 {
13656 matches = 0;
13657 break;
13658 }
13659
13660 switch (neon_shape_tab[shape].el[j])
13661 {
13662 /* If a .f16, .16, .u16, .s16 type specifier is given over
13663 a VFP single precision register operand, it's essentially
13664 means only half of the register is used.
13665
13666 If the type specifier is given after the mnemonics, the
13667 information is stored in inst.vectype. If the type specifier
13668 is given after register operand, the information is stored
13669 in inst.operands[].vectype.
13670
13671 When there is only one type specifier, and all the register
13672 operands are the same type of hardware register, the type
13673 specifier applies to all register operands.
13674
13675 If no type specifier is given, the shape is inferred from
13676 operand information.
13677
13678 for example:
13679 vadd.f16 s0, s1, s2: NS_HHH
13680 vabs.f16 s0, s1: NS_HH
13681 vmov.f16 s0, r1: NS_HR
13682 vmov.f16 r0, s1: NS_RH
13683 vcvt.f16 r0, s1: NS_RH
13684 vcvt.f16.s32 s2, s2, #29: NS_HFI
13685 vcvt.f16.s32 s2, s2: NS_HF
13686 */
13687 case SE_H:
13688 if (!(inst.operands[j].isreg
13689 && inst.operands[j].isvec
13690 && inst.operands[j].issingle
13691 && !inst.operands[j].isquad
13692 && ((inst.vectype.elems == 1
13693 && inst.vectype.el[0].size == 16)
13694 || (inst.vectype.elems > 1
13695 && inst.vectype.el[j].size == 16)
13696 || (inst.vectype.elems == 0
13697 && inst.operands[j].vectype.type != NT_invtype
13698 && inst.operands[j].vectype.size == 16))))
13699 matches = 0;
13700 break;
13701
13702 case SE_F:
13703 if (!(inst.operands[j].isreg
13704 && inst.operands[j].isvec
13705 && inst.operands[j].issingle
13706 && !inst.operands[j].isquad
13707 && ((inst.vectype.elems == 1 && inst.vectype.el[0].size == 32)
13708 || (inst.vectype.elems > 1 && inst.vectype.el[j].size == 32)
13709 || (inst.vectype.elems == 0
13710 && (inst.operands[j].vectype.size == 32
13711 || inst.operands[j].vectype.type == NT_invtype)))))
13712 matches = 0;
13713 break;
13714
13715 case SE_D:
13716 if (!(inst.operands[j].isreg
13717 && inst.operands[j].isvec
13718 && !inst.operands[j].isquad
13719 && !inst.operands[j].issingle))
13720 matches = 0;
13721 break;
13722
13723 case SE_R:
13724 if (!(inst.operands[j].isreg
13725 && !inst.operands[j].isvec))
13726 matches = 0;
13727 break;
13728
13729 case SE_Q:
13730 if (!(inst.operands[j].isreg
13731 && inst.operands[j].isvec
13732 && inst.operands[j].isquad
13733 && !inst.operands[j].issingle))
13734 matches = 0;
13735 break;
13736
13737 case SE_I:
13738 if (!(!inst.operands[j].isreg
13739 && !inst.operands[j].isscalar))
13740 matches = 0;
13741 break;
13742
13743 case SE_S:
13744 if (!(!inst.operands[j].isreg
13745 && inst.operands[j].isscalar))
13746 matches = 0;
13747 break;
13748
13749 case SE_L:
13750 break;
13751 }
13752 if (!matches)
13753 break;
13754 }
13755 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
13756 /* We've matched all the entries in the shape table, and we don't
13757 have any left over operands which have not been matched. */
13758 break;
13759 }
13760
13761 va_end (ap);
13762
13763 if (shape == NS_NULL && first_shape != NS_NULL)
13764 first_error (_("invalid instruction shape"));
13765
13766 return shape;
13767 }
13768
13769 /* True if SHAPE is predominantly a quadword operation (most of the time, this
13770 means the Q bit should be set). */
13771
13772 static int
13773 neon_quad (enum neon_shape shape)
13774 {
13775 return neon_shape_class[shape] == SC_QUAD;
13776 }
13777
13778 static void
13779 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
13780 unsigned *g_size)
13781 {
13782 /* Allow modification to be made to types which are constrained to be
13783 based on the key element, based on bits set alongside N_EQK. */
13784 if ((typebits & N_EQK) != 0)
13785 {
13786 if ((typebits & N_HLF) != 0)
13787 *g_size /= 2;
13788 else if ((typebits & N_DBL) != 0)
13789 *g_size *= 2;
13790 if ((typebits & N_SGN) != 0)
13791 *g_type = NT_signed;
13792 else if ((typebits & N_UNS) != 0)
13793 *g_type = NT_unsigned;
13794 else if ((typebits & N_INT) != 0)
13795 *g_type = NT_integer;
13796 else if ((typebits & N_FLT) != 0)
13797 *g_type = NT_float;
13798 else if ((typebits & N_SIZ) != 0)
13799 *g_type = NT_untyped;
13800 }
13801 }
13802
13803 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
13804 operand type, i.e. the single type specified in a Neon instruction when it
13805 is the only one given. */
13806
13807 static struct neon_type_el
13808 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
13809 {
13810 struct neon_type_el dest = *key;
13811
13812 gas_assert ((thisarg & N_EQK) != 0);
13813
13814 neon_modify_type_size (thisarg, &dest.type, &dest.size);
13815
13816 return dest;
13817 }
13818
13819 /* Convert Neon type and size into compact bitmask representation. */
13820
13821 static enum neon_type_mask
13822 type_chk_of_el_type (enum neon_el_type type, unsigned size)
13823 {
13824 switch (type)
13825 {
13826 case NT_untyped:
13827 switch (size)
13828 {
13829 case 8: return N_8;
13830 case 16: return N_16;
13831 case 32: return N_32;
13832 case 64: return N_64;
13833 default: ;
13834 }
13835 break;
13836
13837 case NT_integer:
13838 switch (size)
13839 {
13840 case 8: return N_I8;
13841 case 16: return N_I16;
13842 case 32: return N_I32;
13843 case 64: return N_I64;
13844 default: ;
13845 }
13846 break;
13847
13848 case NT_float:
13849 switch (size)
13850 {
13851 case 16: return N_F16;
13852 case 32: return N_F32;
13853 case 64: return N_F64;
13854 default: ;
13855 }
13856 break;
13857
13858 case NT_poly:
13859 switch (size)
13860 {
13861 case 8: return N_P8;
13862 case 16: return N_P16;
13863 case 64: return N_P64;
13864 default: ;
13865 }
13866 break;
13867
13868 case NT_signed:
13869 switch (size)
13870 {
13871 case 8: return N_S8;
13872 case 16: return N_S16;
13873 case 32: return N_S32;
13874 case 64: return N_S64;
13875 default: ;
13876 }
13877 break;
13878
13879 case NT_unsigned:
13880 switch (size)
13881 {
13882 case 8: return N_U8;
13883 case 16: return N_U16;
13884 case 32: return N_U32;
13885 case 64: return N_U64;
13886 default: ;
13887 }
13888 break;
13889
13890 default: ;
13891 }
13892
13893 return N_UTYP;
13894 }
13895
13896 /* Convert compact Neon bitmask type representation to a type and size. Only
13897 handles the case where a single bit is set in the mask. */
13898
13899 static int
13900 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
13901 enum neon_type_mask mask)
13902 {
13903 if ((mask & N_EQK) != 0)
13904 return FAIL;
13905
13906 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
13907 *size = 8;
13908 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_F16 | N_P16)) != 0)
13909 *size = 16;
13910 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
13911 *size = 32;
13912 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64 | N_P64)) != 0)
13913 *size = 64;
13914 else
13915 return FAIL;
13916
13917 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
13918 *type = NT_signed;
13919 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
13920 *type = NT_unsigned;
13921 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
13922 *type = NT_integer;
13923 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
13924 *type = NT_untyped;
13925 else if ((mask & (N_P8 | N_P16 | N_P64)) != 0)
13926 *type = NT_poly;
13927 else if ((mask & (N_F_ALL)) != 0)
13928 *type = NT_float;
13929 else
13930 return FAIL;
13931
13932 return SUCCESS;
13933 }
13934
13935 /* Modify a bitmask of allowed types. This is only needed for type
13936 relaxation. */
13937
13938 static unsigned
13939 modify_types_allowed (unsigned allowed, unsigned mods)
13940 {
13941 unsigned size;
13942 enum neon_el_type type;
13943 unsigned destmask;
13944 int i;
13945
13946 destmask = 0;
13947
13948 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
13949 {
13950 if (el_type_of_type_chk (&type, &size,
13951 (enum neon_type_mask) (allowed & i)) == SUCCESS)
13952 {
13953 neon_modify_type_size (mods, &type, &size);
13954 destmask |= type_chk_of_el_type (type, size);
13955 }
13956 }
13957
13958 return destmask;
13959 }
13960
13961 /* Check type and return type classification.
13962 The manual states (paraphrase): If one datatype is given, it indicates the
13963 type given in:
13964 - the second operand, if there is one
13965 - the operand, if there is no second operand
13966 - the result, if there are no operands.
13967 This isn't quite good enough though, so we use a concept of a "key" datatype
13968 which is set on a per-instruction basis, which is the one which matters when
13969 only one data type is written.
13970 Note: this function has side-effects (e.g. filling in missing operands). All
13971 Neon instructions should call it before performing bit encoding. */
13972
13973 static struct neon_type_el
13974 neon_check_type (unsigned els, enum neon_shape ns, ...)
13975 {
13976 va_list ap;
13977 unsigned i, pass, key_el = 0;
13978 unsigned types[NEON_MAX_TYPE_ELS];
13979 enum neon_el_type k_type = NT_invtype;
13980 unsigned k_size = -1u;
13981 struct neon_type_el badtype = {NT_invtype, -1};
13982 unsigned key_allowed = 0;
13983
13984 /* Optional registers in Neon instructions are always (not) in operand 1.
13985 Fill in the missing operand here, if it was omitted. */
13986 if (els > 1 && !inst.operands[1].present)
13987 inst.operands[1] = inst.operands[0];
13988
13989 /* Suck up all the varargs. */
13990 va_start (ap, ns);
13991 for (i = 0; i < els; i++)
13992 {
13993 unsigned thisarg = va_arg (ap, unsigned);
13994 if (thisarg == N_IGNORE_TYPE)
13995 {
13996 va_end (ap);
13997 return badtype;
13998 }
13999 types[i] = thisarg;
14000 if ((thisarg & N_KEY) != 0)
14001 key_el = i;
14002 }
14003 va_end (ap);
14004
14005 if (inst.vectype.elems > 0)
14006 for (i = 0; i < els; i++)
14007 if (inst.operands[i].vectype.type != NT_invtype)
14008 {
14009 first_error (_("types specified in both the mnemonic and operands"));
14010 return badtype;
14011 }
14012
14013 /* Duplicate inst.vectype elements here as necessary.
14014 FIXME: No idea if this is exactly the same as the ARM assembler,
14015 particularly when an insn takes one register and one non-register
14016 operand. */
14017 if (inst.vectype.elems == 1 && els > 1)
14018 {
14019 unsigned j;
14020 inst.vectype.elems = els;
14021 inst.vectype.el[key_el] = inst.vectype.el[0];
14022 for (j = 0; j < els; j++)
14023 if (j != key_el)
14024 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14025 types[j]);
14026 }
14027 else if (inst.vectype.elems == 0 && els > 0)
14028 {
14029 unsigned j;
14030 /* No types were given after the mnemonic, so look for types specified
14031 after each operand. We allow some flexibility here; as long as the
14032 "key" operand has a type, we can infer the others. */
14033 for (j = 0; j < els; j++)
14034 if (inst.operands[j].vectype.type != NT_invtype)
14035 inst.vectype.el[j] = inst.operands[j].vectype;
14036
14037 if (inst.operands[key_el].vectype.type != NT_invtype)
14038 {
14039 for (j = 0; j < els; j++)
14040 if (inst.operands[j].vectype.type == NT_invtype)
14041 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
14042 types[j]);
14043 }
14044 else
14045 {
14046 first_error (_("operand types can't be inferred"));
14047 return badtype;
14048 }
14049 }
14050 else if (inst.vectype.elems != els)
14051 {
14052 first_error (_("type specifier has the wrong number of parts"));
14053 return badtype;
14054 }
14055
14056 for (pass = 0; pass < 2; pass++)
14057 {
14058 for (i = 0; i < els; i++)
14059 {
14060 unsigned thisarg = types[i];
14061 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
14062 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
14063 enum neon_el_type g_type = inst.vectype.el[i].type;
14064 unsigned g_size = inst.vectype.el[i].size;
14065
14066 /* Decay more-specific signed & unsigned types to sign-insensitive
14067 integer types if sign-specific variants are unavailable. */
14068 if ((g_type == NT_signed || g_type == NT_unsigned)
14069 && (types_allowed & N_SU_ALL) == 0)
14070 g_type = NT_integer;
14071
14072 /* If only untyped args are allowed, decay any more specific types to
14073 them. Some instructions only care about signs for some element
14074 sizes, so handle that properly. */
14075 if (((types_allowed & N_UNT) == 0)
14076 && ((g_size == 8 && (types_allowed & N_8) != 0)
14077 || (g_size == 16 && (types_allowed & N_16) != 0)
14078 || (g_size == 32 && (types_allowed & N_32) != 0)
14079 || (g_size == 64 && (types_allowed & N_64) != 0)))
14080 g_type = NT_untyped;
14081
14082 if (pass == 0)
14083 {
14084 if ((thisarg & N_KEY) != 0)
14085 {
14086 k_type = g_type;
14087 k_size = g_size;
14088 key_allowed = thisarg & ~N_KEY;
14089
14090 /* Check architecture constraint on FP16 extension. */
14091 if (k_size == 16
14092 && k_type == NT_float
14093 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14094 {
14095 inst.error = _(BAD_FP16);
14096 return badtype;
14097 }
14098 }
14099 }
14100 else
14101 {
14102 if ((thisarg & N_VFP) != 0)
14103 {
14104 enum neon_shape_el regshape;
14105 unsigned regwidth, match;
14106
14107 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
14108 if (ns == NS_NULL)
14109 {
14110 first_error (_("invalid instruction shape"));
14111 return badtype;
14112 }
14113 regshape = neon_shape_tab[ns].el[i];
14114 regwidth = neon_shape_el_size[regshape];
14115
14116 /* In VFP mode, operands must match register widths. If we
14117 have a key operand, use its width, else use the width of
14118 the current operand. */
14119 if (k_size != -1u)
14120 match = k_size;
14121 else
14122 match = g_size;
14123
14124 /* FP16 will use a single precision register. */
14125 if (regwidth == 32 && match == 16)
14126 {
14127 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16))
14128 match = regwidth;
14129 else
14130 {
14131 inst.error = _(BAD_FP16);
14132 return badtype;
14133 }
14134 }
14135
14136 if (regwidth != match)
14137 {
14138 first_error (_("operand size must match register width"));
14139 return badtype;
14140 }
14141 }
14142
14143 if ((thisarg & N_EQK) == 0)
14144 {
14145 unsigned given_type = type_chk_of_el_type (g_type, g_size);
14146
14147 if ((given_type & types_allowed) == 0)
14148 {
14149 first_error (_("bad type in Neon instruction"));
14150 return badtype;
14151 }
14152 }
14153 else
14154 {
14155 enum neon_el_type mod_k_type = k_type;
14156 unsigned mod_k_size = k_size;
14157 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
14158 if (g_type != mod_k_type || g_size != mod_k_size)
14159 {
14160 first_error (_("inconsistent types in Neon instruction"));
14161 return badtype;
14162 }
14163 }
14164 }
14165 }
14166 }
14167
14168 return inst.vectype.el[key_el];
14169 }
14170
14171 /* Neon-style VFP instruction forwarding. */
14172
14173 /* Thumb VFP instructions have 0xE in the condition field. */
14174
14175 static void
14176 do_vfp_cond_or_thumb (void)
14177 {
14178 inst.is_neon = 1;
14179
14180 if (thumb_mode)
14181 inst.instruction |= 0xe0000000;
14182 else
14183 inst.instruction |= inst.cond << 28;
14184 }
14185
14186 /* Look up and encode a simple mnemonic, for use as a helper function for the
14187 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
14188 etc. It is assumed that operand parsing has already been done, and that the
14189 operands are in the form expected by the given opcode (this isn't necessarily
14190 the same as the form in which they were parsed, hence some massaging must
14191 take place before this function is called).
14192 Checks current arch version against that in the looked-up opcode. */
14193
14194 static void
14195 do_vfp_nsyn_opcode (const char *opname)
14196 {
14197 const struct asm_opcode *opcode;
14198
14199 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
14200
14201 if (!opcode)
14202 abort ();
14203
14204 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
14205 thumb_mode ? *opcode->tvariant : *opcode->avariant),
14206 _(BAD_FPU));
14207
14208 inst.is_neon = 1;
14209
14210 if (thumb_mode)
14211 {
14212 inst.instruction = opcode->tvalue;
14213 opcode->tencode ();
14214 }
14215 else
14216 {
14217 inst.instruction = (inst.cond << 28) | opcode->avalue;
14218 opcode->aencode ();
14219 }
14220 }
14221
14222 static void
14223 do_vfp_nsyn_add_sub (enum neon_shape rs)
14224 {
14225 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
14226
14227 if (rs == NS_FFF || rs == NS_HHH)
14228 {
14229 if (is_add)
14230 do_vfp_nsyn_opcode ("fadds");
14231 else
14232 do_vfp_nsyn_opcode ("fsubs");
14233
14234 /* ARMv8.2 fp16 instruction. */
14235 if (rs == NS_HHH)
14236 do_scalar_fp16_v82_encode ();
14237 }
14238 else
14239 {
14240 if (is_add)
14241 do_vfp_nsyn_opcode ("faddd");
14242 else
14243 do_vfp_nsyn_opcode ("fsubd");
14244 }
14245 }
14246
14247 /* Check operand types to see if this is a VFP instruction, and if so call
14248 PFN (). */
14249
14250 static int
14251 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
14252 {
14253 enum neon_shape rs;
14254 struct neon_type_el et;
14255
14256 switch (args)
14257 {
14258 case 2:
14259 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14260 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
14261 break;
14262
14263 case 3:
14264 rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14265 et = neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14266 N_F_ALL | N_KEY | N_VFP);
14267 break;
14268
14269 default:
14270 abort ();
14271 }
14272
14273 if (et.type != NT_invtype)
14274 {
14275 pfn (rs);
14276 return SUCCESS;
14277 }
14278
14279 inst.error = NULL;
14280 return FAIL;
14281 }
14282
14283 static void
14284 do_vfp_nsyn_mla_mls (enum neon_shape rs)
14285 {
14286 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
14287
14288 if (rs == NS_FFF || rs == NS_HHH)
14289 {
14290 if (is_mla)
14291 do_vfp_nsyn_opcode ("fmacs");
14292 else
14293 do_vfp_nsyn_opcode ("fnmacs");
14294
14295 /* ARMv8.2 fp16 instruction. */
14296 if (rs == NS_HHH)
14297 do_scalar_fp16_v82_encode ();
14298 }
14299 else
14300 {
14301 if (is_mla)
14302 do_vfp_nsyn_opcode ("fmacd");
14303 else
14304 do_vfp_nsyn_opcode ("fnmacd");
14305 }
14306 }
14307
14308 static void
14309 do_vfp_nsyn_fma_fms (enum neon_shape rs)
14310 {
14311 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
14312
14313 if (rs == NS_FFF || rs == NS_HHH)
14314 {
14315 if (is_fma)
14316 do_vfp_nsyn_opcode ("ffmas");
14317 else
14318 do_vfp_nsyn_opcode ("ffnmas");
14319
14320 /* ARMv8.2 fp16 instruction. */
14321 if (rs == NS_HHH)
14322 do_scalar_fp16_v82_encode ();
14323 }
14324 else
14325 {
14326 if (is_fma)
14327 do_vfp_nsyn_opcode ("ffmad");
14328 else
14329 do_vfp_nsyn_opcode ("ffnmad");
14330 }
14331 }
14332
14333 static void
14334 do_vfp_nsyn_mul (enum neon_shape rs)
14335 {
14336 if (rs == NS_FFF || rs == NS_HHH)
14337 {
14338 do_vfp_nsyn_opcode ("fmuls");
14339
14340 /* ARMv8.2 fp16 instruction. */
14341 if (rs == NS_HHH)
14342 do_scalar_fp16_v82_encode ();
14343 }
14344 else
14345 do_vfp_nsyn_opcode ("fmuld");
14346 }
14347
14348 static void
14349 do_vfp_nsyn_abs_neg (enum neon_shape rs)
14350 {
14351 int is_neg = (inst.instruction & 0x80) != 0;
14352 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_VFP | N_KEY);
14353
14354 if (rs == NS_FF || rs == NS_HH)
14355 {
14356 if (is_neg)
14357 do_vfp_nsyn_opcode ("fnegs");
14358 else
14359 do_vfp_nsyn_opcode ("fabss");
14360
14361 /* ARMv8.2 fp16 instruction. */
14362 if (rs == NS_HH)
14363 do_scalar_fp16_v82_encode ();
14364 }
14365 else
14366 {
14367 if (is_neg)
14368 do_vfp_nsyn_opcode ("fnegd");
14369 else
14370 do_vfp_nsyn_opcode ("fabsd");
14371 }
14372 }
14373
14374 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
14375 insns belong to Neon, and are handled elsewhere. */
14376
14377 static void
14378 do_vfp_nsyn_ldm_stm (int is_dbmode)
14379 {
14380 int is_ldm = (inst.instruction & (1 << 20)) != 0;
14381 if (is_ldm)
14382 {
14383 if (is_dbmode)
14384 do_vfp_nsyn_opcode ("fldmdbs");
14385 else
14386 do_vfp_nsyn_opcode ("fldmias");
14387 }
14388 else
14389 {
14390 if (is_dbmode)
14391 do_vfp_nsyn_opcode ("fstmdbs");
14392 else
14393 do_vfp_nsyn_opcode ("fstmias");
14394 }
14395 }
14396
14397 static void
14398 do_vfp_nsyn_sqrt (void)
14399 {
14400 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14401 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
14402
14403 if (rs == NS_FF || rs == NS_HH)
14404 {
14405 do_vfp_nsyn_opcode ("fsqrts");
14406
14407 /* ARMv8.2 fp16 instruction. */
14408 if (rs == NS_HH)
14409 do_scalar_fp16_v82_encode ();
14410 }
14411 else
14412 do_vfp_nsyn_opcode ("fsqrtd");
14413 }
14414
14415 static void
14416 do_vfp_nsyn_div (void)
14417 {
14418 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14419 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14420 N_F_ALL | N_KEY | N_VFP);
14421
14422 if (rs == NS_FFF || rs == NS_HHH)
14423 {
14424 do_vfp_nsyn_opcode ("fdivs");
14425
14426 /* ARMv8.2 fp16 instruction. */
14427 if (rs == NS_HHH)
14428 do_scalar_fp16_v82_encode ();
14429 }
14430 else
14431 do_vfp_nsyn_opcode ("fdivd");
14432 }
14433
14434 static void
14435 do_vfp_nsyn_nmul (void)
14436 {
14437 enum neon_shape rs = neon_select_shape (NS_HHH, NS_FFF, NS_DDD, NS_NULL);
14438 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
14439 N_F_ALL | N_KEY | N_VFP);
14440
14441 if (rs == NS_FFF || rs == NS_HHH)
14442 {
14443 NEON_ENCODE (SINGLE, inst);
14444 do_vfp_sp_dyadic ();
14445
14446 /* ARMv8.2 fp16 instruction. */
14447 if (rs == NS_HHH)
14448 do_scalar_fp16_v82_encode ();
14449 }
14450 else
14451 {
14452 NEON_ENCODE (DOUBLE, inst);
14453 do_vfp_dp_rd_rn_rm ();
14454 }
14455 do_vfp_cond_or_thumb ();
14456
14457 }
14458
14459 static void
14460 do_vfp_nsyn_cmp (void)
14461 {
14462 enum neon_shape rs;
14463 if (inst.operands[1].isreg)
14464 {
14465 rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_NULL);
14466 neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY | N_VFP);
14467
14468 if (rs == NS_FF || rs == NS_HH)
14469 {
14470 NEON_ENCODE (SINGLE, inst);
14471 do_vfp_sp_monadic ();
14472 }
14473 else
14474 {
14475 NEON_ENCODE (DOUBLE, inst);
14476 do_vfp_dp_rd_rm ();
14477 }
14478 }
14479 else
14480 {
14481 rs = neon_select_shape (NS_HI, NS_FI, NS_DI, NS_NULL);
14482 neon_check_type (2, rs, N_F_ALL | N_KEY | N_VFP, N_EQK);
14483
14484 switch (inst.instruction & 0x0fffffff)
14485 {
14486 case N_MNEM_vcmp:
14487 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
14488 break;
14489 case N_MNEM_vcmpe:
14490 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
14491 break;
14492 default:
14493 abort ();
14494 }
14495
14496 if (rs == NS_FI || rs == NS_HI)
14497 {
14498 NEON_ENCODE (SINGLE, inst);
14499 do_vfp_sp_compare_z ();
14500 }
14501 else
14502 {
14503 NEON_ENCODE (DOUBLE, inst);
14504 do_vfp_dp_rd ();
14505 }
14506 }
14507 do_vfp_cond_or_thumb ();
14508
14509 /* ARMv8.2 fp16 instruction. */
14510 if (rs == NS_HI || rs == NS_HH)
14511 do_scalar_fp16_v82_encode ();
14512 }
14513
14514 static void
14515 nsyn_insert_sp (void)
14516 {
14517 inst.operands[1] = inst.operands[0];
14518 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
14519 inst.operands[0].reg = REG_SP;
14520 inst.operands[0].isreg = 1;
14521 inst.operands[0].writeback = 1;
14522 inst.operands[0].present = 1;
14523 }
14524
14525 static void
14526 do_vfp_nsyn_push (void)
14527 {
14528 nsyn_insert_sp ();
14529
14530 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14531 _("register list must contain at least 1 and at most 16 "
14532 "registers"));
14533
14534 if (inst.operands[1].issingle)
14535 do_vfp_nsyn_opcode ("fstmdbs");
14536 else
14537 do_vfp_nsyn_opcode ("fstmdbd");
14538 }
14539
14540 static void
14541 do_vfp_nsyn_pop (void)
14542 {
14543 nsyn_insert_sp ();
14544
14545 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14546 _("register list must contain at least 1 and at most 16 "
14547 "registers"));
14548
14549 if (inst.operands[1].issingle)
14550 do_vfp_nsyn_opcode ("fldmias");
14551 else
14552 do_vfp_nsyn_opcode ("fldmiad");
14553 }
14554
14555 /* Fix up Neon data-processing instructions, ORing in the correct bits for
14556 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
14557
14558 static void
14559 neon_dp_fixup (struct arm_it* insn)
14560 {
14561 unsigned int i = insn->instruction;
14562 insn->is_neon = 1;
14563
14564 if (thumb_mode)
14565 {
14566 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
14567 if (i & (1 << 24))
14568 i |= 1 << 28;
14569
14570 i &= ~(1 << 24);
14571
14572 i |= 0xef000000;
14573 }
14574 else
14575 i |= 0xf2000000;
14576
14577 insn->instruction = i;
14578 }
14579
14580 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
14581 (0, 1, 2, 3). */
14582
14583 static unsigned
14584 neon_logbits (unsigned x)
14585 {
14586 return ffs (x) - 4;
14587 }
14588
14589 #define LOW4(R) ((R) & 0xf)
14590 #define HI1(R) (((R) >> 4) & 1)
14591
14592 /* Encode insns with bit pattern:
14593
14594 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14595 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
14596
14597 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
14598 different meaning for some instruction. */
14599
14600 static void
14601 neon_three_same (int isquad, int ubit, int size)
14602 {
14603 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14604 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14605 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14606 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14607 inst.instruction |= LOW4 (inst.operands[2].reg);
14608 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14609 inst.instruction |= (isquad != 0) << 6;
14610 inst.instruction |= (ubit != 0) << 24;
14611 if (size != -1)
14612 inst.instruction |= neon_logbits (size) << 20;
14613
14614 neon_dp_fixup (&inst);
14615 }
14616
14617 /* Encode instructions of the form:
14618
14619 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
14620 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
14621
14622 Don't write size if SIZE == -1. */
14623
14624 static void
14625 neon_two_same (int qbit, int ubit, int size)
14626 {
14627 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14628 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14629 inst.instruction |= LOW4 (inst.operands[1].reg);
14630 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14631 inst.instruction |= (qbit != 0) << 6;
14632 inst.instruction |= (ubit != 0) << 24;
14633
14634 if (size != -1)
14635 inst.instruction |= neon_logbits (size) << 18;
14636
14637 neon_dp_fixup (&inst);
14638 }
14639
14640 /* Neon instruction encoders, in approximate order of appearance. */
14641
14642 static void
14643 do_neon_dyadic_i_su (void)
14644 {
14645 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14646 struct neon_type_el et = neon_check_type (3, rs,
14647 N_EQK, N_EQK, N_SU_32 | N_KEY);
14648 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14649 }
14650
14651 static void
14652 do_neon_dyadic_i64_su (void)
14653 {
14654 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14655 struct neon_type_el et = neon_check_type (3, rs,
14656 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14657 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14658 }
14659
14660 static void
14661 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
14662 unsigned immbits)
14663 {
14664 unsigned size = et.size >> 3;
14665 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14666 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14667 inst.instruction |= LOW4 (inst.operands[1].reg);
14668 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14669 inst.instruction |= (isquad != 0) << 6;
14670 inst.instruction |= immbits << 16;
14671 inst.instruction |= (size >> 3) << 7;
14672 inst.instruction |= (size & 0x7) << 19;
14673 if (write_ubit)
14674 inst.instruction |= (uval != 0) << 24;
14675
14676 neon_dp_fixup (&inst);
14677 }
14678
14679 static void
14680 do_neon_shl_imm (void)
14681 {
14682 if (!inst.operands[2].isreg)
14683 {
14684 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14685 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
14686 int imm = inst.operands[2].imm;
14687
14688 constraint (imm < 0 || (unsigned)imm >= et.size,
14689 _("immediate out of range for shift"));
14690 NEON_ENCODE (IMMED, inst);
14691 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14692 }
14693 else
14694 {
14695 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14696 struct neon_type_el et = neon_check_type (3, rs,
14697 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
14698 unsigned int tmp;
14699
14700 /* VSHL/VQSHL 3-register variants have syntax such as:
14701 vshl.xx Dd, Dm, Dn
14702 whereas other 3-register operations encoded by neon_three_same have
14703 syntax like:
14704 vadd.xx Dd, Dn, Dm
14705 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
14706 here. */
14707 tmp = inst.operands[2].reg;
14708 inst.operands[2].reg = inst.operands[1].reg;
14709 inst.operands[1].reg = tmp;
14710 NEON_ENCODE (INTEGER, inst);
14711 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14712 }
14713 }
14714
14715 static void
14716 do_neon_qshl_imm (void)
14717 {
14718 if (!inst.operands[2].isreg)
14719 {
14720 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14721 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14722 int imm = inst.operands[2].imm;
14723
14724 constraint (imm < 0 || (unsigned)imm >= et.size,
14725 _("immediate out of range for shift"));
14726 NEON_ENCODE (IMMED, inst);
14727 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et, imm);
14728 }
14729 else
14730 {
14731 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14732 struct neon_type_el et = neon_check_type (3, rs,
14733 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
14734 unsigned int tmp;
14735
14736 /* See note in do_neon_shl_imm. */
14737 tmp = inst.operands[2].reg;
14738 inst.operands[2].reg = inst.operands[1].reg;
14739 inst.operands[1].reg = tmp;
14740 NEON_ENCODE (INTEGER, inst);
14741 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14742 }
14743 }
14744
14745 static void
14746 do_neon_rshl (void)
14747 {
14748 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14749 struct neon_type_el et = neon_check_type (3, rs,
14750 N_EQK, N_EQK, N_SU_ALL | N_KEY);
14751 unsigned int tmp;
14752
14753 tmp = inst.operands[2].reg;
14754 inst.operands[2].reg = inst.operands[1].reg;
14755 inst.operands[1].reg = tmp;
14756 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
14757 }
14758
14759 static int
14760 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
14761 {
14762 /* Handle .I8 pseudo-instructions. */
14763 if (size == 8)
14764 {
14765 /* Unfortunately, this will make everything apart from zero out-of-range.
14766 FIXME is this the intended semantics? There doesn't seem much point in
14767 accepting .I8 if so. */
14768 immediate |= immediate << 8;
14769 size = 16;
14770 }
14771
14772 if (size >= 32)
14773 {
14774 if (immediate == (immediate & 0x000000ff))
14775 {
14776 *immbits = immediate;
14777 return 0x1;
14778 }
14779 else if (immediate == (immediate & 0x0000ff00))
14780 {
14781 *immbits = immediate >> 8;
14782 return 0x3;
14783 }
14784 else if (immediate == (immediate & 0x00ff0000))
14785 {
14786 *immbits = immediate >> 16;
14787 return 0x5;
14788 }
14789 else if (immediate == (immediate & 0xff000000))
14790 {
14791 *immbits = immediate >> 24;
14792 return 0x7;
14793 }
14794 if ((immediate & 0xffff) != (immediate >> 16))
14795 goto bad_immediate;
14796 immediate &= 0xffff;
14797 }
14798
14799 if (immediate == (immediate & 0x000000ff))
14800 {
14801 *immbits = immediate;
14802 return 0x9;
14803 }
14804 else if (immediate == (immediate & 0x0000ff00))
14805 {
14806 *immbits = immediate >> 8;
14807 return 0xb;
14808 }
14809
14810 bad_immediate:
14811 first_error (_("immediate value out of range"));
14812 return FAIL;
14813 }
14814
14815 static void
14816 do_neon_logic (void)
14817 {
14818 if (inst.operands[2].present && inst.operands[2].isreg)
14819 {
14820 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14821 neon_check_type (3, rs, N_IGNORE_TYPE);
14822 /* U bit and size field were set as part of the bitmask. */
14823 NEON_ENCODE (INTEGER, inst);
14824 neon_three_same (neon_quad (rs), 0, -1);
14825 }
14826 else
14827 {
14828 const int three_ops_form = (inst.operands[2].present
14829 && !inst.operands[2].isreg);
14830 const int immoperand = (three_ops_form ? 2 : 1);
14831 enum neon_shape rs = (three_ops_form
14832 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
14833 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
14834 struct neon_type_el et = neon_check_type (2, rs,
14835 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14836 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
14837 unsigned immbits;
14838 int cmode;
14839
14840 if (et.type == NT_invtype)
14841 return;
14842
14843 if (three_ops_form)
14844 constraint (inst.operands[0].reg != inst.operands[1].reg,
14845 _("first and second operands shall be the same register"));
14846
14847 NEON_ENCODE (IMMED, inst);
14848
14849 immbits = inst.operands[immoperand].imm;
14850 if (et.size == 64)
14851 {
14852 /* .i64 is a pseudo-op, so the immediate must be a repeating
14853 pattern. */
14854 if (immbits != (inst.operands[immoperand].regisimm ?
14855 inst.operands[immoperand].reg : 0))
14856 {
14857 /* Set immbits to an invalid constant. */
14858 immbits = 0xdeadbeef;
14859 }
14860 }
14861
14862 switch (opcode)
14863 {
14864 case N_MNEM_vbic:
14865 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14866 break;
14867
14868 case N_MNEM_vorr:
14869 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14870 break;
14871
14872 case N_MNEM_vand:
14873 /* Pseudo-instruction for VBIC. */
14874 neon_invert_size (&immbits, 0, et.size);
14875 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14876 break;
14877
14878 case N_MNEM_vorn:
14879 /* Pseudo-instruction for VORR. */
14880 neon_invert_size (&immbits, 0, et.size);
14881 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
14882 break;
14883
14884 default:
14885 abort ();
14886 }
14887
14888 if (cmode == FAIL)
14889 return;
14890
14891 inst.instruction |= neon_quad (rs) << 6;
14892 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14893 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14894 inst.instruction |= cmode << 8;
14895 neon_write_immbits (immbits);
14896
14897 neon_dp_fixup (&inst);
14898 }
14899 }
14900
14901 static void
14902 do_neon_bitfield (void)
14903 {
14904 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14905 neon_check_type (3, rs, N_IGNORE_TYPE);
14906 neon_three_same (neon_quad (rs), 0, -1);
14907 }
14908
14909 static void
14910 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
14911 unsigned destbits)
14912 {
14913 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14914 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
14915 types | N_KEY);
14916 if (et.type == NT_float)
14917 {
14918 NEON_ENCODE (FLOAT, inst);
14919 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
14920 }
14921 else
14922 {
14923 NEON_ENCODE (INTEGER, inst);
14924 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
14925 }
14926 }
14927
14928 static void
14929 do_neon_dyadic_if_su (void)
14930 {
14931 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
14932 }
14933
14934 static void
14935 do_neon_dyadic_if_su_d (void)
14936 {
14937 /* This version only allow D registers, but that constraint is enforced during
14938 operand parsing so we don't need to do anything extra here. */
14939 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
14940 }
14941
14942 static void
14943 do_neon_dyadic_if_i_d (void)
14944 {
14945 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14946 affected if we specify unsigned args. */
14947 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14948 }
14949
14950 enum vfp_or_neon_is_neon_bits
14951 {
14952 NEON_CHECK_CC = 1,
14953 NEON_CHECK_ARCH = 2,
14954 NEON_CHECK_ARCH8 = 4
14955 };
14956
14957 /* Call this function if an instruction which may have belonged to the VFP or
14958 Neon instruction sets, but turned out to be a Neon instruction (due to the
14959 operand types involved, etc.). We have to check and/or fix-up a couple of
14960 things:
14961
14962 - Make sure the user hasn't attempted to make a Neon instruction
14963 conditional.
14964 - Alter the value in the condition code field if necessary.
14965 - Make sure that the arch supports Neon instructions.
14966
14967 Which of these operations take place depends on bits from enum
14968 vfp_or_neon_is_neon_bits.
14969
14970 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
14971 current instruction's condition is COND_ALWAYS, the condition field is
14972 changed to inst.uncond_value. This is necessary because instructions shared
14973 between VFP and Neon may be conditional for the VFP variants only, and the
14974 unconditional Neon version must have, e.g., 0xF in the condition field. */
14975
14976 static int
14977 vfp_or_neon_is_neon (unsigned check)
14978 {
14979 /* Conditions are always legal in Thumb mode (IT blocks). */
14980 if (!thumb_mode && (check & NEON_CHECK_CC))
14981 {
14982 if (inst.cond != COND_ALWAYS)
14983 {
14984 first_error (_(BAD_COND));
14985 return FAIL;
14986 }
14987 if (inst.uncond_value != -1)
14988 inst.instruction |= inst.uncond_value << 28;
14989 }
14990
14991 if ((check & NEON_CHECK_ARCH)
14992 && !mark_feature_used (&fpu_neon_ext_v1))
14993 {
14994 first_error (_(BAD_FPU));
14995 return FAIL;
14996 }
14997
14998 if ((check & NEON_CHECK_ARCH8)
14999 && !mark_feature_used (&fpu_neon_ext_armv8))
15000 {
15001 first_error (_(BAD_FPU));
15002 return FAIL;
15003 }
15004
15005 return SUCCESS;
15006 }
15007
15008 static void
15009 do_neon_addsub_if_i (void)
15010 {
15011 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
15012 return;
15013
15014 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15015 return;
15016
15017 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15018 affected if we specify unsigned args. */
15019 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
15020 }
15021
15022 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
15023 result to be:
15024 V<op> A,B (A is operand 0, B is operand 2)
15025 to mean:
15026 V<op> A,B,A
15027 not:
15028 V<op> A,B,B
15029 so handle that case specially. */
15030
15031 static void
15032 neon_exchange_operands (void)
15033 {
15034 if (inst.operands[1].present)
15035 {
15036 void *scratch = xmalloc (sizeof (inst.operands[0]));
15037
15038 /* Swap operands[1] and operands[2]. */
15039 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
15040 inst.operands[1] = inst.operands[2];
15041 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
15042 free (scratch);
15043 }
15044 else
15045 {
15046 inst.operands[1] = inst.operands[2];
15047 inst.operands[2] = inst.operands[0];
15048 }
15049 }
15050
15051 static void
15052 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
15053 {
15054 if (inst.operands[2].isreg)
15055 {
15056 if (invert)
15057 neon_exchange_operands ();
15058 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
15059 }
15060 else
15061 {
15062 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15063 struct neon_type_el et = neon_check_type (2, rs,
15064 N_EQK | N_SIZ, immtypes | N_KEY);
15065
15066 NEON_ENCODE (IMMED, inst);
15067 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15068 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15069 inst.instruction |= LOW4 (inst.operands[1].reg);
15070 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15071 inst.instruction |= neon_quad (rs) << 6;
15072 inst.instruction |= (et.type == NT_float) << 10;
15073 inst.instruction |= neon_logbits (et.size) << 18;
15074
15075 neon_dp_fixup (&inst);
15076 }
15077 }
15078
15079 static void
15080 do_neon_cmp (void)
15081 {
15082 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, FALSE);
15083 }
15084
15085 static void
15086 do_neon_cmp_inv (void)
15087 {
15088 neon_compare (N_SUF_32, N_S_32 | N_F_16_32, TRUE);
15089 }
15090
15091 static void
15092 do_neon_ceq (void)
15093 {
15094 neon_compare (N_IF_32, N_IF_32, FALSE);
15095 }
15096
15097 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
15098 scalars, which are encoded in 5 bits, M : Rm.
15099 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
15100 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
15101 index in M.
15102
15103 Dot Product instructions are similar to multiply instructions except elsize
15104 should always be 32.
15105
15106 This function translates SCALAR, which is GAS's internal encoding of indexed
15107 scalar register, to raw encoding. There is also register and index range
15108 check based on ELSIZE. */
15109
15110 static unsigned
15111 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
15112 {
15113 unsigned regno = NEON_SCALAR_REG (scalar);
15114 unsigned elno = NEON_SCALAR_INDEX (scalar);
15115
15116 switch (elsize)
15117 {
15118 case 16:
15119 if (regno > 7 || elno > 3)
15120 goto bad_scalar;
15121 return regno | (elno << 3);
15122
15123 case 32:
15124 if (regno > 15 || elno > 1)
15125 goto bad_scalar;
15126 return regno | (elno << 4);
15127
15128 default:
15129 bad_scalar:
15130 first_error (_("scalar out of range for multiply instruction"));
15131 }
15132
15133 return 0;
15134 }
15135
15136 /* Encode multiply / multiply-accumulate scalar instructions. */
15137
15138 static void
15139 neon_mul_mac (struct neon_type_el et, int ubit)
15140 {
15141 unsigned scalar;
15142
15143 /* Give a more helpful error message if we have an invalid type. */
15144 if (et.type == NT_invtype)
15145 return;
15146
15147 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
15148 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15149 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15150 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15151 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15152 inst.instruction |= LOW4 (scalar);
15153 inst.instruction |= HI1 (scalar) << 5;
15154 inst.instruction |= (et.type == NT_float) << 8;
15155 inst.instruction |= neon_logbits (et.size) << 20;
15156 inst.instruction |= (ubit != 0) << 24;
15157
15158 neon_dp_fixup (&inst);
15159 }
15160
15161 static void
15162 do_neon_mac_maybe_scalar (void)
15163 {
15164 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
15165 return;
15166
15167 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15168 return;
15169
15170 if (inst.operands[2].isscalar)
15171 {
15172 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15173 struct neon_type_el et = neon_check_type (3, rs,
15174 N_EQK, N_EQK, N_I16 | N_I32 | N_F_16_32 | N_KEY);
15175 NEON_ENCODE (SCALAR, inst);
15176 neon_mul_mac (et, neon_quad (rs));
15177 }
15178 else
15179 {
15180 /* The "untyped" case can't happen. Do this to stop the "U" bit being
15181 affected if we specify unsigned args. */
15182 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15183 }
15184 }
15185
15186 static void
15187 do_neon_fmac (void)
15188 {
15189 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
15190 return;
15191
15192 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15193 return;
15194
15195 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
15196 }
15197
15198 static void
15199 do_neon_tst (void)
15200 {
15201 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15202 struct neon_type_el et = neon_check_type (3, rs,
15203 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
15204 neon_three_same (neon_quad (rs), 0, et.size);
15205 }
15206
15207 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
15208 same types as the MAC equivalents. The polynomial type for this instruction
15209 is encoded the same as the integer type. */
15210
15211 static void
15212 do_neon_mul (void)
15213 {
15214 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
15215 return;
15216
15217 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15218 return;
15219
15220 if (inst.operands[2].isscalar)
15221 do_neon_mac_maybe_scalar ();
15222 else
15223 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F16 | N_F32 | N_P8, 0);
15224 }
15225
15226 static void
15227 do_neon_qdmulh (void)
15228 {
15229 if (inst.operands[2].isscalar)
15230 {
15231 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15232 struct neon_type_el et = neon_check_type (3, rs,
15233 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15234 NEON_ENCODE (SCALAR, inst);
15235 neon_mul_mac (et, neon_quad (rs));
15236 }
15237 else
15238 {
15239 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15240 struct neon_type_el et = neon_check_type (3, rs,
15241 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15242 NEON_ENCODE (INTEGER, inst);
15243 /* The U bit (rounding) comes from bit mask. */
15244 neon_three_same (neon_quad (rs), 0, et.size);
15245 }
15246 }
15247
15248 static void
15249 do_neon_qrdmlah (void)
15250 {
15251 /* Check we're on the correct architecture. */
15252 if (!mark_feature_used (&fpu_neon_ext_armv8))
15253 inst.error =
15254 _("instruction form not available on this architecture.");
15255 else if (!mark_feature_used (&fpu_neon_ext_v8_1))
15256 {
15257 as_warn (_("this instruction implies use of ARMv8.1 AdvSIMD."));
15258 record_feature_use (&fpu_neon_ext_v8_1);
15259 }
15260
15261 if (inst.operands[2].isscalar)
15262 {
15263 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
15264 struct neon_type_el et = neon_check_type (3, rs,
15265 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15266 NEON_ENCODE (SCALAR, inst);
15267 neon_mul_mac (et, neon_quad (rs));
15268 }
15269 else
15270 {
15271 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15272 struct neon_type_el et = neon_check_type (3, rs,
15273 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
15274 NEON_ENCODE (INTEGER, inst);
15275 /* The U bit (rounding) comes from bit mask. */
15276 neon_three_same (neon_quad (rs), 0, et.size);
15277 }
15278 }
15279
15280 static void
15281 do_neon_fcmp_absolute (void)
15282 {
15283 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15284 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15285 N_F_16_32 | N_KEY);
15286 /* Size field comes from bit mask. */
15287 neon_three_same (neon_quad (rs), 1, et.size == 16 ? (int) et.size : -1);
15288 }
15289
15290 static void
15291 do_neon_fcmp_absolute_inv (void)
15292 {
15293 neon_exchange_operands ();
15294 do_neon_fcmp_absolute ();
15295 }
15296
15297 static void
15298 do_neon_step (void)
15299 {
15300 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
15301 struct neon_type_el et = neon_check_type (3, rs, N_EQK, N_EQK,
15302 N_F_16_32 | N_KEY);
15303 neon_three_same (neon_quad (rs), 0, et.size == 16 ? (int) et.size : -1);
15304 }
15305
15306 static void
15307 do_neon_abs_neg (void)
15308 {
15309 enum neon_shape rs;
15310 struct neon_type_el et;
15311
15312 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
15313 return;
15314
15315 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15316 return;
15317
15318 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15319 et = neon_check_type (2, rs, N_EQK, N_S_32 | N_F_16_32 | N_KEY);
15320
15321 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15322 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15323 inst.instruction |= LOW4 (inst.operands[1].reg);
15324 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15325 inst.instruction |= neon_quad (rs) << 6;
15326 inst.instruction |= (et.type == NT_float) << 10;
15327 inst.instruction |= neon_logbits (et.size) << 18;
15328
15329 neon_dp_fixup (&inst);
15330 }
15331
15332 static void
15333 do_neon_sli (void)
15334 {
15335 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15336 struct neon_type_el et = neon_check_type (2, rs,
15337 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15338 int imm = inst.operands[2].imm;
15339 constraint (imm < 0 || (unsigned)imm >= et.size,
15340 _("immediate out of range for insert"));
15341 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
15342 }
15343
15344 static void
15345 do_neon_sri (void)
15346 {
15347 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15348 struct neon_type_el et = neon_check_type (2, rs,
15349 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
15350 int imm = inst.operands[2].imm;
15351 constraint (imm < 1 || (unsigned)imm > et.size,
15352 _("immediate out of range for insert"));
15353 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
15354 }
15355
15356 static void
15357 do_neon_qshlu_imm (void)
15358 {
15359 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15360 struct neon_type_el et = neon_check_type (2, rs,
15361 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
15362 int imm = inst.operands[2].imm;
15363 constraint (imm < 0 || (unsigned)imm >= et.size,
15364 _("immediate out of range for shift"));
15365 /* Only encodes the 'U present' variant of the instruction.
15366 In this case, signed types have OP (bit 8) set to 0.
15367 Unsigned types have OP set to 1. */
15368 inst.instruction |= (et.type == NT_unsigned) << 8;
15369 /* The rest of the bits are the same as other immediate shifts. */
15370 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
15371 }
15372
15373 static void
15374 do_neon_qmovn (void)
15375 {
15376 struct neon_type_el et = neon_check_type (2, NS_DQ,
15377 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15378 /* Saturating move where operands can be signed or unsigned, and the
15379 destination has the same signedness. */
15380 NEON_ENCODE (INTEGER, inst);
15381 if (et.type == NT_unsigned)
15382 inst.instruction |= 0xc0;
15383 else
15384 inst.instruction |= 0x80;
15385 neon_two_same (0, 1, et.size / 2);
15386 }
15387
15388 static void
15389 do_neon_qmovun (void)
15390 {
15391 struct neon_type_el et = neon_check_type (2, NS_DQ,
15392 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15393 /* Saturating move with unsigned results. Operands must be signed. */
15394 NEON_ENCODE (INTEGER, inst);
15395 neon_two_same (0, 1, et.size / 2);
15396 }
15397
15398 static void
15399 do_neon_rshift_sat_narrow (void)
15400 {
15401 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15402 or unsigned. If operands are unsigned, results must also be unsigned. */
15403 struct neon_type_el et = neon_check_type (2, NS_DQI,
15404 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
15405 int imm = inst.operands[2].imm;
15406 /* This gets the bounds check, size encoding and immediate bits calculation
15407 right. */
15408 et.size /= 2;
15409
15410 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
15411 VQMOVN.I<size> <Dd>, <Qm>. */
15412 if (imm == 0)
15413 {
15414 inst.operands[2].present = 0;
15415 inst.instruction = N_MNEM_vqmovn;
15416 do_neon_qmovn ();
15417 return;
15418 }
15419
15420 constraint (imm < 1 || (unsigned)imm > et.size,
15421 _("immediate out of range"));
15422 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
15423 }
15424
15425 static void
15426 do_neon_rshift_sat_narrow_u (void)
15427 {
15428 /* FIXME: Types for narrowing. If operands are signed, results can be signed
15429 or unsigned. If operands are unsigned, results must also be unsigned. */
15430 struct neon_type_el et = neon_check_type (2, NS_DQI,
15431 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
15432 int imm = inst.operands[2].imm;
15433 /* This gets the bounds check, size encoding and immediate bits calculation
15434 right. */
15435 et.size /= 2;
15436
15437 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
15438 VQMOVUN.I<size> <Dd>, <Qm>. */
15439 if (imm == 0)
15440 {
15441 inst.operands[2].present = 0;
15442 inst.instruction = N_MNEM_vqmovun;
15443 do_neon_qmovun ();
15444 return;
15445 }
15446
15447 constraint (imm < 1 || (unsigned)imm > et.size,
15448 _("immediate out of range"));
15449 /* FIXME: The manual is kind of unclear about what value U should have in
15450 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
15451 must be 1. */
15452 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
15453 }
15454
15455 static void
15456 do_neon_movn (void)
15457 {
15458 struct neon_type_el et = neon_check_type (2, NS_DQ,
15459 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15460 NEON_ENCODE (INTEGER, inst);
15461 neon_two_same (0, 1, et.size / 2);
15462 }
15463
15464 static void
15465 do_neon_rshift_narrow (void)
15466 {
15467 struct neon_type_el et = neon_check_type (2, NS_DQI,
15468 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
15469 int imm = inst.operands[2].imm;
15470 /* This gets the bounds check, size encoding and immediate bits calculation
15471 right. */
15472 et.size /= 2;
15473
15474 /* If immediate is zero then we are a pseudo-instruction for
15475 VMOVN.I<size> <Dd>, <Qm> */
15476 if (imm == 0)
15477 {
15478 inst.operands[2].present = 0;
15479 inst.instruction = N_MNEM_vmovn;
15480 do_neon_movn ();
15481 return;
15482 }
15483
15484 constraint (imm < 1 || (unsigned)imm > et.size,
15485 _("immediate out of range for narrowing operation"));
15486 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
15487 }
15488
15489 static void
15490 do_neon_shll (void)
15491 {
15492 /* FIXME: Type checking when lengthening. */
15493 struct neon_type_el et = neon_check_type (2, NS_QDI,
15494 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
15495 unsigned imm = inst.operands[2].imm;
15496
15497 if (imm == et.size)
15498 {
15499 /* Maximum shift variant. */
15500 NEON_ENCODE (INTEGER, inst);
15501 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15502 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15503 inst.instruction |= LOW4 (inst.operands[1].reg);
15504 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15505 inst.instruction |= neon_logbits (et.size) << 18;
15506
15507 neon_dp_fixup (&inst);
15508 }
15509 else
15510 {
15511 /* A more-specific type check for non-max versions. */
15512 et = neon_check_type (2, NS_QDI,
15513 N_EQK | N_DBL, N_SU_32 | N_KEY);
15514 NEON_ENCODE (IMMED, inst);
15515 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
15516 }
15517 }
15518
15519 /* Check the various types for the VCVT instruction, and return which version
15520 the current instruction is. */
15521
15522 #define CVT_FLAVOUR_VAR \
15523 CVT_VAR (s32_f32, N_S32, N_F32, whole_reg, "ftosls", "ftosis", "ftosizs") \
15524 CVT_VAR (u32_f32, N_U32, N_F32, whole_reg, "ftouls", "ftouis", "ftouizs") \
15525 CVT_VAR (f32_s32, N_F32, N_S32, whole_reg, "fsltos", "fsitos", NULL) \
15526 CVT_VAR (f32_u32, N_F32, N_U32, whole_reg, "fultos", "fuitos", NULL) \
15527 /* Half-precision conversions. */ \
15528 CVT_VAR (s16_f16, N_S16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15529 CVT_VAR (u16_f16, N_U16, N_F16 | N_KEY, whole_reg, NULL, NULL, NULL) \
15530 CVT_VAR (f16_s16, N_F16 | N_KEY, N_S16, whole_reg, NULL, NULL, NULL) \
15531 CVT_VAR (f16_u16, N_F16 | N_KEY, N_U16, whole_reg, NULL, NULL, NULL) \
15532 CVT_VAR (f32_f16, N_F32, N_F16, whole_reg, NULL, NULL, NULL) \
15533 CVT_VAR (f16_f32, N_F16, N_F32, whole_reg, NULL, NULL, NULL) \
15534 /* New VCVT instructions introduced by ARMv8.2 fp16 extension. \
15535 Compared with single/double precision variants, only the co-processor \
15536 field is different, so the encoding flow is reused here. */ \
15537 CVT_VAR (f16_s32, N_F16 | N_KEY, N_S32, N_VFP, "fsltos", "fsitos", NULL) \
15538 CVT_VAR (f16_u32, N_F16 | N_KEY, N_U32, N_VFP, "fultos", "fuitos", NULL) \
15539 CVT_VAR (u32_f16, N_U32, N_F16 | N_KEY, N_VFP, "ftouls", "ftouis", "ftouizs")\
15540 CVT_VAR (s32_f16, N_S32, N_F16 | N_KEY, N_VFP, "ftosls", "ftosis", "ftosizs")\
15541 /* VFP instructions. */ \
15542 CVT_VAR (f32_f64, N_F32, N_F64, N_VFP, NULL, "fcvtsd", NULL) \
15543 CVT_VAR (f64_f32, N_F64, N_F32, N_VFP, NULL, "fcvtds", NULL) \
15544 CVT_VAR (s32_f64, N_S32, N_F64 | key, N_VFP, "ftosld", "ftosid", "ftosizd") \
15545 CVT_VAR (u32_f64, N_U32, N_F64 | key, N_VFP, "ftould", "ftouid", "ftouizd") \
15546 CVT_VAR (f64_s32, N_F64 | key, N_S32, N_VFP, "fsltod", "fsitod", NULL) \
15547 CVT_VAR (f64_u32, N_F64 | key, N_U32, N_VFP, "fultod", "fuitod", NULL) \
15548 /* VFP instructions with bitshift. */ \
15549 CVT_VAR (f32_s16, N_F32 | key, N_S16, N_VFP, "fshtos", NULL, NULL) \
15550 CVT_VAR (f32_u16, N_F32 | key, N_U16, N_VFP, "fuhtos", NULL, NULL) \
15551 CVT_VAR (f64_s16, N_F64 | key, N_S16, N_VFP, "fshtod", NULL, NULL) \
15552 CVT_VAR (f64_u16, N_F64 | key, N_U16, N_VFP, "fuhtod", NULL, NULL) \
15553 CVT_VAR (s16_f32, N_S16, N_F32 | key, N_VFP, "ftoshs", NULL, NULL) \
15554 CVT_VAR (u16_f32, N_U16, N_F32 | key, N_VFP, "ftouhs", NULL, NULL) \
15555 CVT_VAR (s16_f64, N_S16, N_F64 | key, N_VFP, "ftoshd", NULL, NULL) \
15556 CVT_VAR (u16_f64, N_U16, N_F64 | key, N_VFP, "ftouhd", NULL, NULL)
15557
15558 #define CVT_VAR(C, X, Y, R, BSN, CN, ZN) \
15559 neon_cvt_flavour_##C,
15560
15561 /* The different types of conversions we can do. */
15562 enum neon_cvt_flavour
15563 {
15564 CVT_FLAVOUR_VAR
15565 neon_cvt_flavour_invalid,
15566 neon_cvt_flavour_first_fp = neon_cvt_flavour_f32_f64
15567 };
15568
15569 #undef CVT_VAR
15570
15571 static enum neon_cvt_flavour
15572 get_neon_cvt_flavour (enum neon_shape rs)
15573 {
15574 #define CVT_VAR(C,X,Y,R,BSN,CN,ZN) \
15575 et = neon_check_type (2, rs, (R) | (X), (R) | (Y)); \
15576 if (et.type != NT_invtype) \
15577 { \
15578 inst.error = NULL; \
15579 return (neon_cvt_flavour_##C); \
15580 }
15581
15582 struct neon_type_el et;
15583 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
15584 || rs == NS_FF) ? N_VFP : 0;
15585 /* The instruction versions which take an immediate take one register
15586 argument, which is extended to the width of the full register. Thus the
15587 "source" and "destination" registers must have the same width. Hack that
15588 here by making the size equal to the key (wider, in this case) operand. */
15589 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
15590
15591 CVT_FLAVOUR_VAR;
15592
15593 return neon_cvt_flavour_invalid;
15594 #undef CVT_VAR
15595 }
15596
15597 enum neon_cvt_mode
15598 {
15599 neon_cvt_mode_a,
15600 neon_cvt_mode_n,
15601 neon_cvt_mode_p,
15602 neon_cvt_mode_m,
15603 neon_cvt_mode_z,
15604 neon_cvt_mode_x,
15605 neon_cvt_mode_r
15606 };
15607
15608 /* Neon-syntax VFP conversions. */
15609
15610 static void
15611 do_vfp_nsyn_cvt (enum neon_shape rs, enum neon_cvt_flavour flavour)
15612 {
15613 const char *opname = 0;
15614
15615 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI
15616 || rs == NS_FHI || rs == NS_HFI)
15617 {
15618 /* Conversions with immediate bitshift. */
15619 const char *enc[] =
15620 {
15621 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) BSN,
15622 CVT_FLAVOUR_VAR
15623 NULL
15624 #undef CVT_VAR
15625 };
15626
15627 if (flavour < (int) ARRAY_SIZE (enc))
15628 {
15629 opname = enc[flavour];
15630 constraint (inst.operands[0].reg != inst.operands[1].reg,
15631 _("operands 0 and 1 must be the same register"));
15632 inst.operands[1] = inst.operands[2];
15633 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
15634 }
15635 }
15636 else
15637 {
15638 /* Conversions without bitshift. */
15639 const char *enc[] =
15640 {
15641 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) CN,
15642 CVT_FLAVOUR_VAR
15643 NULL
15644 #undef CVT_VAR
15645 };
15646
15647 if (flavour < (int) ARRAY_SIZE (enc))
15648 opname = enc[flavour];
15649 }
15650
15651 if (opname)
15652 do_vfp_nsyn_opcode (opname);
15653
15654 /* ARMv8.2 fp16 VCVT instruction. */
15655 if (flavour == neon_cvt_flavour_s32_f16
15656 || flavour == neon_cvt_flavour_u32_f16
15657 || flavour == neon_cvt_flavour_f16_u32
15658 || flavour == neon_cvt_flavour_f16_s32)
15659 do_scalar_fp16_v82_encode ();
15660 }
15661
15662 static void
15663 do_vfp_nsyn_cvtz (void)
15664 {
15665 enum neon_shape rs = neon_select_shape (NS_FH, NS_FF, NS_FD, NS_NULL);
15666 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
15667 const char *enc[] =
15668 {
15669 #define CVT_VAR(C,A,B,R,BSN,CN,ZN) ZN,
15670 CVT_FLAVOUR_VAR
15671 NULL
15672 #undef CVT_VAR
15673 };
15674
15675 if (flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
15676 do_vfp_nsyn_opcode (enc[flavour]);
15677 }
15678
15679 static void
15680 do_vfp_nsyn_cvt_fpv8 (enum neon_cvt_flavour flavour,
15681 enum neon_cvt_mode mode)
15682 {
15683 int sz, op;
15684 int rm;
15685
15686 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
15687 D register operands. */
15688 if (flavour == neon_cvt_flavour_s32_f64
15689 || flavour == neon_cvt_flavour_u32_f64)
15690 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
15691 _(BAD_FPU));
15692
15693 if (flavour == neon_cvt_flavour_s32_f16
15694 || flavour == neon_cvt_flavour_u32_f16)
15695 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16),
15696 _(BAD_FP16));
15697
15698 set_it_insn_type (OUTSIDE_IT_INSN);
15699
15700 switch (flavour)
15701 {
15702 case neon_cvt_flavour_s32_f64:
15703 sz = 1;
15704 op = 1;
15705 break;
15706 case neon_cvt_flavour_s32_f32:
15707 sz = 0;
15708 op = 1;
15709 break;
15710 case neon_cvt_flavour_s32_f16:
15711 sz = 0;
15712 op = 1;
15713 break;
15714 case neon_cvt_flavour_u32_f64:
15715 sz = 1;
15716 op = 0;
15717 break;
15718 case neon_cvt_flavour_u32_f32:
15719 sz = 0;
15720 op = 0;
15721 break;
15722 case neon_cvt_flavour_u32_f16:
15723 sz = 0;
15724 op = 0;
15725 break;
15726 default:
15727 first_error (_("invalid instruction shape"));
15728 return;
15729 }
15730
15731 switch (mode)
15732 {
15733 case neon_cvt_mode_a: rm = 0; break;
15734 case neon_cvt_mode_n: rm = 1; break;
15735 case neon_cvt_mode_p: rm = 2; break;
15736 case neon_cvt_mode_m: rm = 3; break;
15737 default: first_error (_("invalid rounding mode")); return;
15738 }
15739
15740 NEON_ENCODE (FPV8, inst);
15741 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
15742 encode_arm_vfp_reg (inst.operands[1].reg, sz == 1 ? VFP_REG_Dm : VFP_REG_Sm);
15743 inst.instruction |= sz << 8;
15744
15745 /* ARMv8.2 fp16 VCVT instruction. */
15746 if (flavour == neon_cvt_flavour_s32_f16
15747 ||flavour == neon_cvt_flavour_u32_f16)
15748 do_scalar_fp16_v82_encode ();
15749 inst.instruction |= op << 7;
15750 inst.instruction |= rm << 16;
15751 inst.instruction |= 0xf0000000;
15752 inst.is_neon = TRUE;
15753 }
15754
15755 static void
15756 do_neon_cvt_1 (enum neon_cvt_mode mode)
15757 {
15758 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
15759 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ,
15760 NS_FH, NS_HF, NS_FHI, NS_HFI,
15761 NS_NULL);
15762 enum neon_cvt_flavour flavour = get_neon_cvt_flavour (rs);
15763
15764 if (flavour == neon_cvt_flavour_invalid)
15765 return;
15766
15767 /* PR11109: Handle round-to-zero for VCVT conversions. */
15768 if (mode == neon_cvt_mode_z
15769 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
15770 && (flavour == neon_cvt_flavour_s16_f16
15771 || flavour == neon_cvt_flavour_u16_f16
15772 || flavour == neon_cvt_flavour_s32_f32
15773 || flavour == neon_cvt_flavour_u32_f32
15774 || flavour == neon_cvt_flavour_s32_f64
15775 || flavour == neon_cvt_flavour_u32_f64)
15776 && (rs == NS_FD || rs == NS_FF))
15777 {
15778 do_vfp_nsyn_cvtz ();
15779 return;
15780 }
15781
15782 /* ARMv8.2 fp16 VCVT conversions. */
15783 if (mode == neon_cvt_mode_z
15784 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16)
15785 && (flavour == neon_cvt_flavour_s32_f16
15786 || flavour == neon_cvt_flavour_u32_f16)
15787 && (rs == NS_FH))
15788 {
15789 do_vfp_nsyn_cvtz ();
15790 do_scalar_fp16_v82_encode ();
15791 return;
15792 }
15793
15794 /* VFP rather than Neon conversions. */
15795 if (flavour >= neon_cvt_flavour_first_fp)
15796 {
15797 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15798 do_vfp_nsyn_cvt (rs, flavour);
15799 else
15800 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15801
15802 return;
15803 }
15804
15805 switch (rs)
15806 {
15807 case NS_DDI:
15808 case NS_QQI:
15809 {
15810 unsigned immbits;
15811 unsigned enctab[] = {0x0000100, 0x1000100, 0x0, 0x1000000,
15812 0x0000100, 0x1000100, 0x0, 0x1000000};
15813
15814 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15815 return;
15816
15817 /* Fixed-point conversion with #0 immediate is encoded as an
15818 integer conversion. */
15819 if (inst.operands[2].present && inst.operands[2].imm == 0)
15820 goto int_encode;
15821 NEON_ENCODE (IMMED, inst);
15822 if (flavour != neon_cvt_flavour_invalid)
15823 inst.instruction |= enctab[flavour];
15824 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15825 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15826 inst.instruction |= LOW4 (inst.operands[1].reg);
15827 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15828 inst.instruction |= neon_quad (rs) << 6;
15829 inst.instruction |= 1 << 21;
15830 if (flavour < neon_cvt_flavour_s16_f16)
15831 {
15832 inst.instruction |= 1 << 21;
15833 immbits = 32 - inst.operands[2].imm;
15834 inst.instruction |= immbits << 16;
15835 }
15836 else
15837 {
15838 inst.instruction |= 3 << 20;
15839 immbits = 16 - inst.operands[2].imm;
15840 inst.instruction |= immbits << 16;
15841 inst.instruction &= ~(1 << 9);
15842 }
15843
15844 neon_dp_fixup (&inst);
15845 }
15846 break;
15847
15848 case NS_DD:
15849 case NS_QQ:
15850 if (mode != neon_cvt_mode_x && mode != neon_cvt_mode_z)
15851 {
15852 NEON_ENCODE (FLOAT, inst);
15853 set_it_insn_type (OUTSIDE_IT_INSN);
15854
15855 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
15856 return;
15857
15858 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15859 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15860 inst.instruction |= LOW4 (inst.operands[1].reg);
15861 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15862 inst.instruction |= neon_quad (rs) << 6;
15863 inst.instruction |= (flavour == neon_cvt_flavour_u16_f16
15864 || flavour == neon_cvt_flavour_u32_f32) << 7;
15865 inst.instruction |= mode << 8;
15866 if (flavour == neon_cvt_flavour_u16_f16
15867 || flavour == neon_cvt_flavour_s16_f16)
15868 /* Mask off the original size bits and reencode them. */
15869 inst.instruction = ((inst.instruction & 0xfff3ffff) | (1 << 18));
15870
15871 if (thumb_mode)
15872 inst.instruction |= 0xfc000000;
15873 else
15874 inst.instruction |= 0xf0000000;
15875 }
15876 else
15877 {
15878 int_encode:
15879 {
15880 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080,
15881 0x100, 0x180, 0x0, 0x080};
15882
15883 NEON_ENCODE (INTEGER, inst);
15884
15885 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15886 return;
15887
15888 if (flavour != neon_cvt_flavour_invalid)
15889 inst.instruction |= enctab[flavour];
15890
15891 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15892 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15893 inst.instruction |= LOW4 (inst.operands[1].reg);
15894 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15895 inst.instruction |= neon_quad (rs) << 6;
15896 if (flavour >= neon_cvt_flavour_s16_f16
15897 && flavour <= neon_cvt_flavour_f16_u16)
15898 /* Half precision. */
15899 inst.instruction |= 1 << 18;
15900 else
15901 inst.instruction |= 2 << 18;
15902
15903 neon_dp_fixup (&inst);
15904 }
15905 }
15906 break;
15907
15908 /* Half-precision conversions for Advanced SIMD -- neon. */
15909 case NS_QD:
15910 case NS_DQ:
15911
15912 if ((rs == NS_DQ)
15913 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
15914 {
15915 as_bad (_("operand size must match register width"));
15916 break;
15917 }
15918
15919 if ((rs == NS_QD)
15920 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
15921 {
15922 as_bad (_("operand size must match register width"));
15923 break;
15924 }
15925
15926 if (rs == NS_DQ)
15927 inst.instruction = 0x3b60600;
15928 else
15929 inst.instruction = 0x3b60700;
15930
15931 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15932 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15933 inst.instruction |= LOW4 (inst.operands[1].reg);
15934 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15935 neon_dp_fixup (&inst);
15936 break;
15937
15938 default:
15939 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
15940 if (mode == neon_cvt_mode_x || mode == neon_cvt_mode_z)
15941 do_vfp_nsyn_cvt (rs, flavour);
15942 else
15943 do_vfp_nsyn_cvt_fpv8 (flavour, mode);
15944 }
15945 }
15946
15947 static void
15948 do_neon_cvtr (void)
15949 {
15950 do_neon_cvt_1 (neon_cvt_mode_x);
15951 }
15952
15953 static void
15954 do_neon_cvt (void)
15955 {
15956 do_neon_cvt_1 (neon_cvt_mode_z);
15957 }
15958
15959 static void
15960 do_neon_cvta (void)
15961 {
15962 do_neon_cvt_1 (neon_cvt_mode_a);
15963 }
15964
15965 static void
15966 do_neon_cvtn (void)
15967 {
15968 do_neon_cvt_1 (neon_cvt_mode_n);
15969 }
15970
15971 static void
15972 do_neon_cvtp (void)
15973 {
15974 do_neon_cvt_1 (neon_cvt_mode_p);
15975 }
15976
15977 static void
15978 do_neon_cvtm (void)
15979 {
15980 do_neon_cvt_1 (neon_cvt_mode_m);
15981 }
15982
15983 static void
15984 do_neon_cvttb_2 (bfd_boolean t, bfd_boolean to, bfd_boolean is_double)
15985 {
15986 if (is_double)
15987 mark_feature_used (&fpu_vfp_ext_armv8);
15988
15989 encode_arm_vfp_reg (inst.operands[0].reg,
15990 (is_double && !to) ? VFP_REG_Dd : VFP_REG_Sd);
15991 encode_arm_vfp_reg (inst.operands[1].reg,
15992 (is_double && to) ? VFP_REG_Dm : VFP_REG_Sm);
15993 inst.instruction |= to ? 0x10000 : 0;
15994 inst.instruction |= t ? 0x80 : 0;
15995 inst.instruction |= is_double ? 0x100 : 0;
15996 do_vfp_cond_or_thumb ();
15997 }
15998
15999 static void
16000 do_neon_cvttb_1 (bfd_boolean t)
16001 {
16002 enum neon_shape rs = neon_select_shape (NS_HF, NS_HD, NS_FH, NS_FF, NS_FD,
16003 NS_DF, NS_DH, NS_NULL);
16004
16005 if (rs == NS_NULL)
16006 return;
16007 else if (neon_check_type (2, rs, N_F16, N_F32 | N_VFP).type != NT_invtype)
16008 {
16009 inst.error = NULL;
16010 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/FALSE);
16011 }
16012 else if (neon_check_type (2, rs, N_F32 | N_VFP, N_F16).type != NT_invtype)
16013 {
16014 inst.error = NULL;
16015 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/FALSE);
16016 }
16017 else if (neon_check_type (2, rs, N_F16, N_F64 | N_VFP).type != NT_invtype)
16018 {
16019 /* The VCVTB and VCVTT instructions with D-register operands
16020 don't work for SP only targets. */
16021 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16022 _(BAD_FPU));
16023
16024 inst.error = NULL;
16025 do_neon_cvttb_2 (t, /*to=*/TRUE, /*is_double=*/TRUE);
16026 }
16027 else if (neon_check_type (2, rs, N_F64 | N_VFP, N_F16).type != NT_invtype)
16028 {
16029 /* The VCVTB and VCVTT instructions with D-register operands
16030 don't work for SP only targets. */
16031 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16032 _(BAD_FPU));
16033
16034 inst.error = NULL;
16035 do_neon_cvttb_2 (t, /*to=*/FALSE, /*is_double=*/TRUE);
16036 }
16037 else
16038 return;
16039 }
16040
16041 static void
16042 do_neon_cvtb (void)
16043 {
16044 do_neon_cvttb_1 (FALSE);
16045 }
16046
16047
16048 static void
16049 do_neon_cvtt (void)
16050 {
16051 do_neon_cvttb_1 (TRUE);
16052 }
16053
16054 static void
16055 neon_move_immediate (void)
16056 {
16057 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
16058 struct neon_type_el et = neon_check_type (2, rs,
16059 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
16060 unsigned immlo, immhi = 0, immbits;
16061 int op, cmode, float_p;
16062
16063 constraint (et.type == NT_invtype,
16064 _("operand size must be specified for immediate VMOV"));
16065
16066 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
16067 op = (inst.instruction & (1 << 5)) != 0;
16068
16069 immlo = inst.operands[1].imm;
16070 if (inst.operands[1].regisimm)
16071 immhi = inst.operands[1].reg;
16072
16073 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
16074 _("immediate has bits set outside the operand size"));
16075
16076 float_p = inst.operands[1].immisfloat;
16077
16078 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
16079 et.size, et.type)) == FAIL)
16080 {
16081 /* Invert relevant bits only. */
16082 neon_invert_size (&immlo, &immhi, et.size);
16083 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
16084 with one or the other; those cases are caught by
16085 neon_cmode_for_move_imm. */
16086 op = !op;
16087 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
16088 &op, et.size, et.type)) == FAIL)
16089 {
16090 first_error (_("immediate out of range"));
16091 return;
16092 }
16093 }
16094
16095 inst.instruction &= ~(1 << 5);
16096 inst.instruction |= op << 5;
16097
16098 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16099 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16100 inst.instruction |= neon_quad (rs) << 6;
16101 inst.instruction |= cmode << 8;
16102
16103 neon_write_immbits (immbits);
16104 }
16105
16106 static void
16107 do_neon_mvn (void)
16108 {
16109 if (inst.operands[1].isreg)
16110 {
16111 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16112
16113 NEON_ENCODE (INTEGER, inst);
16114 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16115 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16116 inst.instruction |= LOW4 (inst.operands[1].reg);
16117 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16118 inst.instruction |= neon_quad (rs) << 6;
16119 }
16120 else
16121 {
16122 NEON_ENCODE (IMMED, inst);
16123 neon_move_immediate ();
16124 }
16125
16126 neon_dp_fixup (&inst);
16127 }
16128
16129 /* Encode instructions of form:
16130
16131 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
16132 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
16133
16134 static void
16135 neon_mixed_length (struct neon_type_el et, unsigned size)
16136 {
16137 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16138 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16139 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16140 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16141 inst.instruction |= LOW4 (inst.operands[2].reg);
16142 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16143 inst.instruction |= (et.type == NT_unsigned) << 24;
16144 inst.instruction |= neon_logbits (size) << 20;
16145
16146 neon_dp_fixup (&inst);
16147 }
16148
16149 static void
16150 do_neon_dyadic_long (void)
16151 {
16152 /* FIXME: Type checking for lengthening op. */
16153 struct neon_type_el et = neon_check_type (3, NS_QDD,
16154 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
16155 neon_mixed_length (et, et.size);
16156 }
16157
16158 static void
16159 do_neon_abal (void)
16160 {
16161 struct neon_type_el et = neon_check_type (3, NS_QDD,
16162 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
16163 neon_mixed_length (et, et.size);
16164 }
16165
16166 static void
16167 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
16168 {
16169 if (inst.operands[2].isscalar)
16170 {
16171 struct neon_type_el et = neon_check_type (3, NS_QDS,
16172 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
16173 NEON_ENCODE (SCALAR, inst);
16174 neon_mul_mac (et, et.type == NT_unsigned);
16175 }
16176 else
16177 {
16178 struct neon_type_el et = neon_check_type (3, NS_QDD,
16179 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
16180 NEON_ENCODE (INTEGER, inst);
16181 neon_mixed_length (et, et.size);
16182 }
16183 }
16184
16185 static void
16186 do_neon_mac_maybe_scalar_long (void)
16187 {
16188 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
16189 }
16190
16191 /* Like neon_scalar_for_mul, this function generate Rm encoding from GAS's
16192 internal SCALAR. QUAD_P is 1 if it's for Q format, otherwise it's 0. */
16193
16194 static unsigned
16195 neon_scalar_for_fmac_fp16_long (unsigned scalar, unsigned quad_p)
16196 {
16197 unsigned regno = NEON_SCALAR_REG (scalar);
16198 unsigned elno = NEON_SCALAR_INDEX (scalar);
16199
16200 if (quad_p)
16201 {
16202 if (regno > 7 || elno > 3)
16203 goto bad_scalar;
16204
16205 return ((regno & 0x7)
16206 | ((elno & 0x1) << 3)
16207 | (((elno >> 1) & 0x1) << 5));
16208 }
16209 else
16210 {
16211 if (regno > 15 || elno > 1)
16212 goto bad_scalar;
16213
16214 return (((regno & 0x1) << 5)
16215 | ((regno >> 1) & 0x7)
16216 | ((elno & 0x1) << 3));
16217 }
16218
16219 bad_scalar:
16220 first_error (_("scalar out of range for multiply instruction"));
16221 return 0;
16222 }
16223
16224 static void
16225 do_neon_fmac_maybe_scalar_long (int subtype)
16226 {
16227 enum neon_shape rs;
16228 int high8;
16229 /* NOTE: vfmal/vfmsl use slightly different NEON three-same encoding. 'size"
16230 field (bits[21:20]) has different meaning. For scalar index variant, it's
16231 used to differentiate add and subtract, otherwise it's with fixed value
16232 0x2. */
16233 int size = -1;
16234
16235 if (inst.cond != COND_ALWAYS)
16236 as_warn (_("vfmal/vfmsl with FP16 type cannot be conditional, the "
16237 "behaviour is UNPREDICTABLE"));
16238
16239 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_fp16_fml),
16240 _(BAD_FP16));
16241
16242 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
16243 _(BAD_FPU));
16244
16245 /* vfmal/vfmsl are in three-same D/Q register format or the third operand can
16246 be a scalar index register. */
16247 if (inst.operands[2].isscalar)
16248 {
16249 high8 = 0xfe000000;
16250 if (subtype)
16251 size = 16;
16252 rs = neon_select_shape (NS_DHS, NS_QDS, NS_NULL);
16253 }
16254 else
16255 {
16256 high8 = 0xfc000000;
16257 size = 32;
16258 if (subtype)
16259 inst.instruction |= (0x1 << 23);
16260 rs = neon_select_shape (NS_DHH, NS_QDD, NS_NULL);
16261 }
16262
16263 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_F16);
16264
16265 /* "opcode" from template has included "ubit", so simply pass 0 here. Also,
16266 the "S" bit in size field has been reused to differentiate vfmal and vfmsl,
16267 so we simply pass -1 as size. */
16268 unsigned quad_p = (rs == NS_QDD || rs == NS_QDS);
16269 neon_three_same (quad_p, 0, size);
16270
16271 /* Undo neon_dp_fixup. Redo the high eight bits. */
16272 inst.instruction &= 0x00ffffff;
16273 inst.instruction |= high8;
16274
16275 #define LOW1(R) ((R) & 0x1)
16276 #define HI4(R) (((R) >> 1) & 0xf)
16277 /* Unlike usually NEON three-same, encoding for Vn and Vm will depend on
16278 whether the instruction is in Q form and whether Vm is a scalar indexed
16279 operand. */
16280 if (inst.operands[2].isscalar)
16281 {
16282 unsigned rm
16283 = neon_scalar_for_fmac_fp16_long (inst.operands[2].reg, quad_p);
16284 inst.instruction &= 0xffffffd0;
16285 inst.instruction |= rm;
16286
16287 if (!quad_p)
16288 {
16289 /* Redo Rn as well. */
16290 inst.instruction &= 0xfff0ff7f;
16291 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16292 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16293 }
16294 }
16295 else if (!quad_p)
16296 {
16297 /* Redo Rn and Rm. */
16298 inst.instruction &= 0xfff0ff50;
16299 inst.instruction |= HI4 (inst.operands[1].reg) << 16;
16300 inst.instruction |= LOW1 (inst.operands[1].reg) << 7;
16301 inst.instruction |= HI4 (inst.operands[2].reg);
16302 inst.instruction |= LOW1 (inst.operands[2].reg) << 5;
16303 }
16304 }
16305
16306 static void
16307 do_neon_vfmal (void)
16308 {
16309 return do_neon_fmac_maybe_scalar_long (0);
16310 }
16311
16312 static void
16313 do_neon_vfmsl (void)
16314 {
16315 return do_neon_fmac_maybe_scalar_long (1);
16316 }
16317
16318 static void
16319 do_neon_dyadic_wide (void)
16320 {
16321 struct neon_type_el et = neon_check_type (3, NS_QQD,
16322 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
16323 neon_mixed_length (et, et.size);
16324 }
16325
16326 static void
16327 do_neon_dyadic_narrow (void)
16328 {
16329 struct neon_type_el et = neon_check_type (3, NS_QDD,
16330 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
16331 /* Operand sign is unimportant, and the U bit is part of the opcode,
16332 so force the operand type to integer. */
16333 et.type = NT_integer;
16334 neon_mixed_length (et, et.size / 2);
16335 }
16336
16337 static void
16338 do_neon_mul_sat_scalar_long (void)
16339 {
16340 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
16341 }
16342
16343 static void
16344 do_neon_vmull (void)
16345 {
16346 if (inst.operands[2].isscalar)
16347 do_neon_mac_maybe_scalar_long ();
16348 else
16349 {
16350 struct neon_type_el et = neon_check_type (3, NS_QDD,
16351 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_P64 | N_KEY);
16352
16353 if (et.type == NT_poly)
16354 NEON_ENCODE (POLY, inst);
16355 else
16356 NEON_ENCODE (INTEGER, inst);
16357
16358 /* For polynomial encoding the U bit must be zero, and the size must
16359 be 8 (encoded as 0b00) or, on ARMv8 or later 64 (encoded, non
16360 obviously, as 0b10). */
16361 if (et.size == 64)
16362 {
16363 /* Check we're on the correct architecture. */
16364 if (!mark_feature_used (&fpu_crypto_ext_armv8))
16365 inst.error =
16366 _("Instruction form not available on this architecture.");
16367
16368 et.size = 32;
16369 }
16370
16371 neon_mixed_length (et, et.size);
16372 }
16373 }
16374
16375 static void
16376 do_neon_ext (void)
16377 {
16378 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
16379 struct neon_type_el et = neon_check_type (3, rs,
16380 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
16381 unsigned imm = (inst.operands[3].imm * et.size) / 8;
16382
16383 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
16384 _("shift out of range"));
16385 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16386 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16387 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16388 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16389 inst.instruction |= LOW4 (inst.operands[2].reg);
16390 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16391 inst.instruction |= neon_quad (rs) << 6;
16392 inst.instruction |= imm << 8;
16393
16394 neon_dp_fixup (&inst);
16395 }
16396
16397 static void
16398 do_neon_rev (void)
16399 {
16400 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16401 struct neon_type_el et = neon_check_type (2, rs,
16402 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16403 unsigned op = (inst.instruction >> 7) & 3;
16404 /* N (width of reversed regions) is encoded as part of the bitmask. We
16405 extract it here to check the elements to be reversed are smaller.
16406 Otherwise we'd get a reserved instruction. */
16407 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
16408 gas_assert (elsize != 0);
16409 constraint (et.size >= elsize,
16410 _("elements must be smaller than reversal region"));
16411 neon_two_same (neon_quad (rs), 1, et.size);
16412 }
16413
16414 static void
16415 do_neon_dup (void)
16416 {
16417 if (inst.operands[1].isscalar)
16418 {
16419 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
16420 struct neon_type_el et = neon_check_type (2, rs,
16421 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16422 unsigned sizebits = et.size >> 3;
16423 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
16424 int logsize = neon_logbits (et.size);
16425 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
16426
16427 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
16428 return;
16429
16430 NEON_ENCODE (SCALAR, inst);
16431 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16432 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16433 inst.instruction |= LOW4 (dm);
16434 inst.instruction |= HI1 (dm) << 5;
16435 inst.instruction |= neon_quad (rs) << 6;
16436 inst.instruction |= x << 17;
16437 inst.instruction |= sizebits << 16;
16438
16439 neon_dp_fixup (&inst);
16440 }
16441 else
16442 {
16443 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
16444 struct neon_type_el et = neon_check_type (2, rs,
16445 N_8 | N_16 | N_32 | N_KEY, N_EQK);
16446 /* Duplicate ARM register to lanes of vector. */
16447 NEON_ENCODE (ARMREG, inst);
16448 switch (et.size)
16449 {
16450 case 8: inst.instruction |= 0x400000; break;
16451 case 16: inst.instruction |= 0x000020; break;
16452 case 32: inst.instruction |= 0x000000; break;
16453 default: break;
16454 }
16455 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16456 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
16457 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
16458 inst.instruction |= neon_quad (rs) << 21;
16459 /* The encoding for this instruction is identical for the ARM and Thumb
16460 variants, except for the condition field. */
16461 do_vfp_cond_or_thumb ();
16462 }
16463 }
16464
16465 /* VMOV has particularly many variations. It can be one of:
16466 0. VMOV<c><q> <Qd>, <Qm>
16467 1. VMOV<c><q> <Dd>, <Dm>
16468 (Register operations, which are VORR with Rm = Rn.)
16469 2. VMOV<c><q>.<dt> <Qd>, #<imm>
16470 3. VMOV<c><q>.<dt> <Dd>, #<imm>
16471 (Immediate loads.)
16472 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
16473 (ARM register to scalar.)
16474 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
16475 (Two ARM registers to vector.)
16476 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
16477 (Scalar to ARM register.)
16478 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
16479 (Vector to two ARM registers.)
16480 8. VMOV.F32 <Sd>, <Sm>
16481 9. VMOV.F64 <Dd>, <Dm>
16482 (VFP register moves.)
16483 10. VMOV.F32 <Sd>, #imm
16484 11. VMOV.F64 <Dd>, #imm
16485 (VFP float immediate load.)
16486 12. VMOV <Rd>, <Sm>
16487 (VFP single to ARM reg.)
16488 13. VMOV <Sd>, <Rm>
16489 (ARM reg to VFP single.)
16490 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
16491 (Two ARM regs to two VFP singles.)
16492 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
16493 (Two VFP singles to two ARM regs.)
16494
16495 These cases can be disambiguated using neon_select_shape, except cases 1/9
16496 and 3/11 which depend on the operand type too.
16497
16498 All the encoded bits are hardcoded by this function.
16499
16500 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
16501 Cases 5, 7 may be used with VFPv2 and above.
16502
16503 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
16504 can specify a type where it doesn't make sense to, and is ignored). */
16505
16506 static void
16507 do_neon_mov (void)
16508 {
16509 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
16510 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR,
16511 NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
16512 NS_HR, NS_RH, NS_HI, NS_NULL);
16513 struct neon_type_el et;
16514 const char *ldconst = 0;
16515
16516 switch (rs)
16517 {
16518 case NS_DD: /* case 1/9. */
16519 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16520 /* It is not an error here if no type is given. */
16521 inst.error = NULL;
16522 if (et.type == NT_float && et.size == 64)
16523 {
16524 do_vfp_nsyn_opcode ("fcpyd");
16525 break;
16526 }
16527 /* fall through. */
16528
16529 case NS_QQ: /* case 0/1. */
16530 {
16531 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16532 return;
16533 /* The architecture manual I have doesn't explicitly state which
16534 value the U bit should have for register->register moves, but
16535 the equivalent VORR instruction has U = 0, so do that. */
16536 inst.instruction = 0x0200110;
16537 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16538 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16539 inst.instruction |= LOW4 (inst.operands[1].reg);
16540 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
16541 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16542 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16543 inst.instruction |= neon_quad (rs) << 6;
16544
16545 neon_dp_fixup (&inst);
16546 }
16547 break;
16548
16549 case NS_DI: /* case 3/11. */
16550 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
16551 inst.error = NULL;
16552 if (et.type == NT_float && et.size == 64)
16553 {
16554 /* case 11 (fconstd). */
16555 ldconst = "fconstd";
16556 goto encode_fconstd;
16557 }
16558 /* fall through. */
16559
16560 case NS_QI: /* case 2/3. */
16561 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
16562 return;
16563 inst.instruction = 0x0800010;
16564 neon_move_immediate ();
16565 neon_dp_fixup (&inst);
16566 break;
16567
16568 case NS_SR: /* case 4. */
16569 {
16570 unsigned bcdebits = 0;
16571 int logsize;
16572 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
16573 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
16574
16575 /* .<size> is optional here, defaulting to .32. */
16576 if (inst.vectype.elems == 0
16577 && inst.operands[0].vectype.type == NT_invtype
16578 && inst.operands[1].vectype.type == NT_invtype)
16579 {
16580 inst.vectype.el[0].type = NT_untyped;
16581 inst.vectype.el[0].size = 32;
16582 inst.vectype.elems = 1;
16583 }
16584
16585 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
16586 logsize = neon_logbits (et.size);
16587
16588 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16589 _(BAD_FPU));
16590 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16591 && et.size != 32, _(BAD_FPU));
16592 constraint (et.type == NT_invtype, _("bad type for scalar"));
16593 constraint (x >= 64 / et.size, _("scalar index out of range"));
16594
16595 switch (et.size)
16596 {
16597 case 8: bcdebits = 0x8; break;
16598 case 16: bcdebits = 0x1; break;
16599 case 32: bcdebits = 0x0; break;
16600 default: ;
16601 }
16602
16603 bcdebits |= x << logsize;
16604
16605 inst.instruction = 0xe000b10;
16606 do_vfp_cond_or_thumb ();
16607 inst.instruction |= LOW4 (dn) << 16;
16608 inst.instruction |= HI1 (dn) << 7;
16609 inst.instruction |= inst.operands[1].reg << 12;
16610 inst.instruction |= (bcdebits & 3) << 5;
16611 inst.instruction |= (bcdebits >> 2) << 21;
16612 }
16613 break;
16614
16615 case NS_DRR: /* case 5 (fmdrr). */
16616 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
16617 _(BAD_FPU));
16618
16619 inst.instruction = 0xc400b10;
16620 do_vfp_cond_or_thumb ();
16621 inst.instruction |= LOW4 (inst.operands[0].reg);
16622 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
16623 inst.instruction |= inst.operands[1].reg << 12;
16624 inst.instruction |= inst.operands[2].reg << 16;
16625 break;
16626
16627 case NS_RS: /* case 6. */
16628 {
16629 unsigned logsize;
16630 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
16631 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
16632 unsigned abcdebits = 0;
16633
16634 /* .<dt> 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,
16645 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
16646 logsize = neon_logbits (et.size);
16647
16648 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
16649 _(BAD_FPU));
16650 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
16651 && et.size != 32, _(BAD_FPU));
16652 constraint (et.type == NT_invtype, _("bad type for scalar"));
16653 constraint (x >= 64 / et.size, _("scalar index out of range"));
16654
16655 switch (et.size)
16656 {
16657 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
16658 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
16659 case 32: abcdebits = 0x00; break;
16660 default: ;
16661 }
16662
16663 abcdebits |= x << logsize;
16664 inst.instruction = 0xe100b10;
16665 do_vfp_cond_or_thumb ();
16666 inst.instruction |= LOW4 (dn) << 16;
16667 inst.instruction |= HI1 (dn) << 7;
16668 inst.instruction |= inst.operands[0].reg << 12;
16669 inst.instruction |= (abcdebits & 3) << 5;
16670 inst.instruction |= (abcdebits >> 2) << 21;
16671 }
16672 break;
16673
16674 case NS_RRD: /* case 7 (fmrrd). */
16675 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
16676 _(BAD_FPU));
16677
16678 inst.instruction = 0xc500b10;
16679 do_vfp_cond_or_thumb ();
16680 inst.instruction |= inst.operands[0].reg << 12;
16681 inst.instruction |= inst.operands[1].reg << 16;
16682 inst.instruction |= LOW4 (inst.operands[2].reg);
16683 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16684 break;
16685
16686 case NS_FF: /* case 8 (fcpys). */
16687 do_vfp_nsyn_opcode ("fcpys");
16688 break;
16689
16690 case NS_HI:
16691 case NS_FI: /* case 10 (fconsts). */
16692 ldconst = "fconsts";
16693 encode_fconstd:
16694 if (!inst.operands[1].immisfloat)
16695 {
16696 /* Immediate has to fit in 8 bits so float is enough. */
16697 float imm = (float)inst.operands[1].imm;
16698 memcpy (&inst.operands[1].imm, &imm, sizeof (float));
16699 inst.operands[1].immisfloat = 1;
16700 }
16701
16702 if (is_quarter_float (inst.operands[1].imm))
16703 {
16704 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
16705 do_vfp_nsyn_opcode (ldconst);
16706
16707 /* ARMv8.2 fp16 vmov.f16 instruction. */
16708 if (rs == NS_HI)
16709 do_scalar_fp16_v82_encode ();
16710 }
16711 else
16712 first_error (_("immediate out of range"));
16713 break;
16714
16715 case NS_RH:
16716 case NS_RF: /* case 12 (fmrs). */
16717 do_vfp_nsyn_opcode ("fmrs");
16718 /* ARMv8.2 fp16 vmov.f16 instruction. */
16719 if (rs == NS_RH)
16720 do_scalar_fp16_v82_encode ();
16721 break;
16722
16723 case NS_HR:
16724 case NS_FR: /* case 13 (fmsr). */
16725 do_vfp_nsyn_opcode ("fmsr");
16726 /* ARMv8.2 fp16 vmov.f16 instruction. */
16727 if (rs == NS_HR)
16728 do_scalar_fp16_v82_encode ();
16729 break;
16730
16731 /* The encoders for the fmrrs and fmsrr instructions expect three operands
16732 (one of which is a list), but we have parsed four. Do some fiddling to
16733 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
16734 expect. */
16735 case NS_RRFF: /* case 14 (fmrrs). */
16736 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
16737 _("VFP registers must be adjacent"));
16738 inst.operands[2].imm = 2;
16739 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16740 do_vfp_nsyn_opcode ("fmrrs");
16741 break;
16742
16743 case NS_FFRR: /* case 15 (fmsrr). */
16744 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
16745 _("VFP registers must be adjacent"));
16746 inst.operands[1] = inst.operands[2];
16747 inst.operands[2] = inst.operands[3];
16748 inst.operands[0].imm = 2;
16749 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
16750 do_vfp_nsyn_opcode ("fmsrr");
16751 break;
16752
16753 case NS_NULL:
16754 /* neon_select_shape has determined that the instruction
16755 shape is wrong and has already set the error message. */
16756 break;
16757
16758 default:
16759 abort ();
16760 }
16761 }
16762
16763 static void
16764 do_neon_rshift_round_imm (void)
16765 {
16766 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
16767 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
16768 int imm = inst.operands[2].imm;
16769
16770 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
16771 if (imm == 0)
16772 {
16773 inst.operands[2].present = 0;
16774 do_neon_mov ();
16775 return;
16776 }
16777
16778 constraint (imm < 1 || (unsigned)imm > et.size,
16779 _("immediate out of range for shift"));
16780 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
16781 et.size - imm);
16782 }
16783
16784 static void
16785 do_neon_movhf (void)
16786 {
16787 enum neon_shape rs = neon_select_shape (NS_HH, NS_NULL);
16788 constraint (rs != NS_HH, _("invalid suffix"));
16789
16790 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
16791 _(BAD_FPU));
16792
16793 if (inst.cond != COND_ALWAYS)
16794 {
16795 if (thumb_mode)
16796 {
16797 as_warn (_("ARMv8.2 scalar fp16 instruction cannot be conditional,"
16798 " the behaviour is UNPREDICTABLE"));
16799 }
16800 else
16801 {
16802 inst.error = BAD_COND;
16803 return;
16804 }
16805 }
16806
16807 do_vfp_sp_monadic ();
16808
16809 inst.is_neon = 1;
16810 inst.instruction |= 0xf0000000;
16811 }
16812
16813 static void
16814 do_neon_movl (void)
16815 {
16816 struct neon_type_el et = neon_check_type (2, NS_QD,
16817 N_EQK | N_DBL, N_SU_32 | N_KEY);
16818 unsigned sizebits = et.size >> 3;
16819 inst.instruction |= sizebits << 19;
16820 neon_two_same (0, et.type == NT_unsigned, -1);
16821 }
16822
16823 static void
16824 do_neon_trn (void)
16825 {
16826 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16827 struct neon_type_el et = neon_check_type (2, rs,
16828 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16829 NEON_ENCODE (INTEGER, inst);
16830 neon_two_same (neon_quad (rs), 1, et.size);
16831 }
16832
16833 static void
16834 do_neon_zip_uzp (void)
16835 {
16836 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16837 struct neon_type_el et = neon_check_type (2, rs,
16838 N_EQK, N_8 | N_16 | N_32 | N_KEY);
16839 if (rs == NS_DD && et.size == 32)
16840 {
16841 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
16842 inst.instruction = N_MNEM_vtrn;
16843 do_neon_trn ();
16844 return;
16845 }
16846 neon_two_same (neon_quad (rs), 1, et.size);
16847 }
16848
16849 static void
16850 do_neon_sat_abs_neg (void)
16851 {
16852 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16853 struct neon_type_el et = neon_check_type (2, rs,
16854 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
16855 neon_two_same (neon_quad (rs), 1, et.size);
16856 }
16857
16858 static void
16859 do_neon_pair_long (void)
16860 {
16861 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16862 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
16863 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
16864 inst.instruction |= (et.type == NT_unsigned) << 7;
16865 neon_two_same (neon_quad (rs), 1, et.size);
16866 }
16867
16868 static void
16869 do_neon_recip_est (void)
16870 {
16871 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16872 struct neon_type_el et = neon_check_type (2, rs,
16873 N_EQK | N_FLT, N_F_16_32 | N_U32 | N_KEY);
16874 inst.instruction |= (et.type == NT_float) << 8;
16875 neon_two_same (neon_quad (rs), 1, et.size);
16876 }
16877
16878 static void
16879 do_neon_cls (void)
16880 {
16881 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16882 struct neon_type_el et = neon_check_type (2, rs,
16883 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
16884 neon_two_same (neon_quad (rs), 1, et.size);
16885 }
16886
16887 static void
16888 do_neon_clz (void)
16889 {
16890 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16891 struct neon_type_el et = neon_check_type (2, rs,
16892 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
16893 neon_two_same (neon_quad (rs), 1, et.size);
16894 }
16895
16896 static void
16897 do_neon_cnt (void)
16898 {
16899 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16900 struct neon_type_el et = neon_check_type (2, rs,
16901 N_EQK | N_INT, N_8 | N_KEY);
16902 neon_two_same (neon_quad (rs), 1, et.size);
16903 }
16904
16905 static void
16906 do_neon_swp (void)
16907 {
16908 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
16909 neon_two_same (neon_quad (rs), 1, -1);
16910 }
16911
16912 static void
16913 do_neon_tbl_tbx (void)
16914 {
16915 unsigned listlenbits;
16916 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
16917
16918 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
16919 {
16920 first_error (_("bad list length for table lookup"));
16921 return;
16922 }
16923
16924 listlenbits = inst.operands[1].imm - 1;
16925 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
16926 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
16927 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
16928 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
16929 inst.instruction |= LOW4 (inst.operands[2].reg);
16930 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
16931 inst.instruction |= listlenbits << 8;
16932
16933 neon_dp_fixup (&inst);
16934 }
16935
16936 static void
16937 do_neon_ldm_stm (void)
16938 {
16939 /* P, U and L bits are part of bitmask. */
16940 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
16941 unsigned offsetbits = inst.operands[1].imm * 2;
16942
16943 if (inst.operands[1].issingle)
16944 {
16945 do_vfp_nsyn_ldm_stm (is_dbmode);
16946 return;
16947 }
16948
16949 constraint (is_dbmode && !inst.operands[0].writeback,
16950 _("writeback (!) must be used for VLDMDB and VSTMDB"));
16951
16952 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
16953 _("register list must contain at least 1 and at most 16 "
16954 "registers"));
16955
16956 inst.instruction |= inst.operands[0].reg << 16;
16957 inst.instruction |= inst.operands[0].writeback << 21;
16958 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
16959 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
16960
16961 inst.instruction |= offsetbits;
16962
16963 do_vfp_cond_or_thumb ();
16964 }
16965
16966 static void
16967 do_neon_ldr_str (void)
16968 {
16969 int is_ldr = (inst.instruction & (1 << 20)) != 0;
16970
16971 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
16972 And is UNPREDICTABLE in thumb mode. */
16973 if (!is_ldr
16974 && inst.operands[1].reg == REG_PC
16975 && (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7) || thumb_mode))
16976 {
16977 if (thumb_mode)
16978 inst.error = _("Use of PC here is UNPREDICTABLE");
16979 else if (warn_on_deprecated)
16980 as_tsktsk (_("Use of PC here is deprecated"));
16981 }
16982
16983 if (inst.operands[0].issingle)
16984 {
16985 if (is_ldr)
16986 do_vfp_nsyn_opcode ("flds");
16987 else
16988 do_vfp_nsyn_opcode ("fsts");
16989
16990 /* ARMv8.2 vldr.16/vstr.16 instruction. */
16991 if (inst.vectype.el[0].size == 16)
16992 do_scalar_fp16_v82_encode ();
16993 }
16994 else
16995 {
16996 if (is_ldr)
16997 do_vfp_nsyn_opcode ("fldd");
16998 else
16999 do_vfp_nsyn_opcode ("fstd");
17000 }
17001 }
17002
17003 /* "interleave" version also handles non-interleaving register VLD1/VST1
17004 instructions. */
17005
17006 static void
17007 do_neon_ld_st_interleave (void)
17008 {
17009 struct neon_type_el et = neon_check_type (1, NS_NULL,
17010 N_8 | N_16 | N_32 | N_64);
17011 unsigned alignbits = 0;
17012 unsigned idx;
17013 /* The bits in this table go:
17014 0: register stride of one (0) or two (1)
17015 1,2: register list length, minus one (1, 2, 3, 4).
17016 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
17017 We use -1 for invalid entries. */
17018 const int typetable[] =
17019 {
17020 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
17021 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
17022 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
17023 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
17024 };
17025 int typebits;
17026
17027 if (et.type == NT_invtype)
17028 return;
17029
17030 if (inst.operands[1].immisalign)
17031 switch (inst.operands[1].imm >> 8)
17032 {
17033 case 64: alignbits = 1; break;
17034 case 128:
17035 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
17036 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17037 goto bad_alignment;
17038 alignbits = 2;
17039 break;
17040 case 256:
17041 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
17042 goto bad_alignment;
17043 alignbits = 3;
17044 break;
17045 default:
17046 bad_alignment:
17047 first_error (_("bad alignment"));
17048 return;
17049 }
17050
17051 inst.instruction |= alignbits << 4;
17052 inst.instruction |= neon_logbits (et.size) << 6;
17053
17054 /* Bits [4:6] of the immediate in a list specifier encode register stride
17055 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
17056 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
17057 up the right value for "type" in a table based on this value and the given
17058 list style, then stick it back. */
17059 idx = ((inst.operands[0].imm >> 4) & 7)
17060 | (((inst.instruction >> 8) & 3) << 3);
17061
17062 typebits = typetable[idx];
17063
17064 constraint (typebits == -1, _("bad list type for instruction"));
17065 constraint (((inst.instruction >> 8) & 3) && et.size == 64,
17066 _("bad element type for instruction"));
17067
17068 inst.instruction &= ~0xf00;
17069 inst.instruction |= typebits << 8;
17070 }
17071
17072 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
17073 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
17074 otherwise. The variable arguments are a list of pairs of legal (size, align)
17075 values, terminated with -1. */
17076
17077 static int
17078 neon_alignment_bit (int size, int align, int *do_alignment, ...)
17079 {
17080 va_list ap;
17081 int result = FAIL, thissize, thisalign;
17082
17083 if (!inst.operands[1].immisalign)
17084 {
17085 *do_alignment = 0;
17086 return SUCCESS;
17087 }
17088
17089 va_start (ap, do_alignment);
17090
17091 do
17092 {
17093 thissize = va_arg (ap, int);
17094 if (thissize == -1)
17095 break;
17096 thisalign = va_arg (ap, int);
17097
17098 if (size == thissize && align == thisalign)
17099 result = SUCCESS;
17100 }
17101 while (result != SUCCESS);
17102
17103 va_end (ap);
17104
17105 if (result == SUCCESS)
17106 *do_alignment = 1;
17107 else
17108 first_error (_("unsupported alignment for instruction"));
17109
17110 return result;
17111 }
17112
17113 static void
17114 do_neon_ld_st_lane (void)
17115 {
17116 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
17117 int align_good, do_alignment = 0;
17118 int logsize = neon_logbits (et.size);
17119 int align = inst.operands[1].imm >> 8;
17120 int n = (inst.instruction >> 8) & 3;
17121 int max_el = 64 / et.size;
17122
17123 if (et.type == NT_invtype)
17124 return;
17125
17126 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
17127 _("bad list length"));
17128 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
17129 _("scalar index out of range"));
17130 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
17131 && et.size == 8,
17132 _("stride of 2 unavailable when element size is 8"));
17133
17134 switch (n)
17135 {
17136 case 0: /* VLD1 / VST1. */
17137 align_good = neon_alignment_bit (et.size, align, &do_alignment, 16, 16,
17138 32, 32, -1);
17139 if (align_good == FAIL)
17140 return;
17141 if (do_alignment)
17142 {
17143 unsigned alignbits = 0;
17144 switch (et.size)
17145 {
17146 case 16: alignbits = 0x1; break;
17147 case 32: alignbits = 0x3; break;
17148 default: ;
17149 }
17150 inst.instruction |= alignbits << 4;
17151 }
17152 break;
17153
17154 case 1: /* VLD2 / VST2. */
17155 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 16,
17156 16, 32, 32, 64, -1);
17157 if (align_good == FAIL)
17158 return;
17159 if (do_alignment)
17160 inst.instruction |= 1 << 4;
17161 break;
17162
17163 case 2: /* VLD3 / VST3. */
17164 constraint (inst.operands[1].immisalign,
17165 _("can't use alignment with this instruction"));
17166 break;
17167
17168 case 3: /* VLD4 / VST4. */
17169 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
17170 16, 64, 32, 64, 32, 128, -1);
17171 if (align_good == FAIL)
17172 return;
17173 if (do_alignment)
17174 {
17175 unsigned alignbits = 0;
17176 switch (et.size)
17177 {
17178 case 8: alignbits = 0x1; break;
17179 case 16: alignbits = 0x1; break;
17180 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
17181 default: ;
17182 }
17183 inst.instruction |= alignbits << 4;
17184 }
17185 break;
17186
17187 default: ;
17188 }
17189
17190 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
17191 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17192 inst.instruction |= 1 << (4 + logsize);
17193
17194 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
17195 inst.instruction |= logsize << 10;
17196 }
17197
17198 /* Encode single n-element structure to all lanes VLD<n> instructions. */
17199
17200 static void
17201 do_neon_ld_dup (void)
17202 {
17203 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
17204 int align_good, do_alignment = 0;
17205
17206 if (et.type == NT_invtype)
17207 return;
17208
17209 switch ((inst.instruction >> 8) & 3)
17210 {
17211 case 0: /* VLD1. */
17212 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
17213 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
17214 &do_alignment, 16, 16, 32, 32, -1);
17215 if (align_good == FAIL)
17216 return;
17217 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
17218 {
17219 case 1: break;
17220 case 2: inst.instruction |= 1 << 5; break;
17221 default: first_error (_("bad list length")); return;
17222 }
17223 inst.instruction |= neon_logbits (et.size) << 6;
17224 break;
17225
17226 case 1: /* VLD2. */
17227 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
17228 &do_alignment, 8, 16, 16, 32, 32, 64,
17229 -1);
17230 if (align_good == FAIL)
17231 return;
17232 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
17233 _("bad list length"));
17234 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17235 inst.instruction |= 1 << 5;
17236 inst.instruction |= neon_logbits (et.size) << 6;
17237 break;
17238
17239 case 2: /* VLD3. */
17240 constraint (inst.operands[1].immisalign,
17241 _("can't use alignment with this instruction"));
17242 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
17243 _("bad list length"));
17244 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17245 inst.instruction |= 1 << 5;
17246 inst.instruction |= neon_logbits (et.size) << 6;
17247 break;
17248
17249 case 3: /* VLD4. */
17250 {
17251 int align = inst.operands[1].imm >> 8;
17252 align_good = neon_alignment_bit (et.size, align, &do_alignment, 8, 32,
17253 16, 64, 32, 64, 32, 128, -1);
17254 if (align_good == FAIL)
17255 return;
17256 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
17257 _("bad list length"));
17258 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
17259 inst.instruction |= 1 << 5;
17260 if (et.size == 32 && align == 128)
17261 inst.instruction |= 0x3 << 6;
17262 else
17263 inst.instruction |= neon_logbits (et.size) << 6;
17264 }
17265 break;
17266
17267 default: ;
17268 }
17269
17270 inst.instruction |= do_alignment << 4;
17271 }
17272
17273 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
17274 apart from bits [11:4]. */
17275
17276 static void
17277 do_neon_ldx_stx (void)
17278 {
17279 if (inst.operands[1].isreg)
17280 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
17281
17282 switch (NEON_LANE (inst.operands[0].imm))
17283 {
17284 case NEON_INTERLEAVE_LANES:
17285 NEON_ENCODE (INTERLV, inst);
17286 do_neon_ld_st_interleave ();
17287 break;
17288
17289 case NEON_ALL_LANES:
17290 NEON_ENCODE (DUP, inst);
17291 if (inst.instruction == N_INV)
17292 {
17293 first_error ("only loads support such operands");
17294 break;
17295 }
17296 do_neon_ld_dup ();
17297 break;
17298
17299 default:
17300 NEON_ENCODE (LANE, inst);
17301 do_neon_ld_st_lane ();
17302 }
17303
17304 /* L bit comes from bit mask. */
17305 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17306 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17307 inst.instruction |= inst.operands[1].reg << 16;
17308
17309 if (inst.operands[1].postind)
17310 {
17311 int postreg = inst.operands[1].imm & 0xf;
17312 constraint (!inst.operands[1].immisreg,
17313 _("post-index must be a register"));
17314 constraint (postreg == 0xd || postreg == 0xf,
17315 _("bad register for post-index"));
17316 inst.instruction |= postreg;
17317 }
17318 else
17319 {
17320 constraint (inst.operands[1].immisreg, BAD_ADDR_MODE);
17321 constraint (inst.reloc.exp.X_op != O_constant
17322 || inst.reloc.exp.X_add_number != 0,
17323 BAD_ADDR_MODE);
17324
17325 if (inst.operands[1].writeback)
17326 {
17327 inst.instruction |= 0xd;
17328 }
17329 else
17330 inst.instruction |= 0xf;
17331 }
17332
17333 if (thumb_mode)
17334 inst.instruction |= 0xf9000000;
17335 else
17336 inst.instruction |= 0xf4000000;
17337 }
17338
17339 /* FP v8. */
17340 static void
17341 do_vfp_nsyn_fpv8 (enum neon_shape rs)
17342 {
17343 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17344 D register operands. */
17345 if (neon_shape_class[rs] == SC_DOUBLE)
17346 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17347 _(BAD_FPU));
17348
17349 NEON_ENCODE (FPV8, inst);
17350
17351 if (rs == NS_FFF || rs == NS_HHH)
17352 {
17353 do_vfp_sp_dyadic ();
17354
17355 /* ARMv8.2 fp16 instruction. */
17356 if (rs == NS_HHH)
17357 do_scalar_fp16_v82_encode ();
17358 }
17359 else
17360 do_vfp_dp_rd_rn_rm ();
17361
17362 if (rs == NS_DDD)
17363 inst.instruction |= 0x100;
17364
17365 inst.instruction |= 0xf0000000;
17366 }
17367
17368 static void
17369 do_vsel (void)
17370 {
17371 set_it_insn_type (OUTSIDE_IT_INSN);
17372
17373 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) != SUCCESS)
17374 first_error (_("invalid instruction shape"));
17375 }
17376
17377 static void
17378 do_vmaxnm (void)
17379 {
17380 set_it_insn_type (OUTSIDE_IT_INSN);
17381
17382 if (try_vfp_nsyn (3, do_vfp_nsyn_fpv8) == SUCCESS)
17383 return;
17384
17385 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17386 return;
17387
17388 neon_dyadic_misc (NT_untyped, N_F_16_32, 0);
17389 }
17390
17391 static void
17392 do_vrint_1 (enum neon_cvt_mode mode)
17393 {
17394 enum neon_shape rs = neon_select_shape (NS_HH, NS_FF, NS_DD, NS_QQ, NS_NULL);
17395 struct neon_type_el et;
17396
17397 if (rs == NS_NULL)
17398 return;
17399
17400 /* Targets like FPv5-SP-D16 don't support FP v8 instructions with
17401 D register operands. */
17402 if (neon_shape_class[rs] == SC_DOUBLE)
17403 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17404 _(BAD_FPU));
17405
17406 et = neon_check_type (2, rs, N_EQK | N_VFP, N_F_ALL | N_KEY
17407 | N_VFP);
17408 if (et.type != NT_invtype)
17409 {
17410 /* VFP encodings. */
17411 if (mode == neon_cvt_mode_a || mode == neon_cvt_mode_n
17412 || mode == neon_cvt_mode_p || mode == neon_cvt_mode_m)
17413 set_it_insn_type (OUTSIDE_IT_INSN);
17414
17415 NEON_ENCODE (FPV8, inst);
17416 if (rs == NS_FF || rs == NS_HH)
17417 do_vfp_sp_monadic ();
17418 else
17419 do_vfp_dp_rd_rm ();
17420
17421 switch (mode)
17422 {
17423 case neon_cvt_mode_r: inst.instruction |= 0x00000000; break;
17424 case neon_cvt_mode_z: inst.instruction |= 0x00000080; break;
17425 case neon_cvt_mode_x: inst.instruction |= 0x00010000; break;
17426 case neon_cvt_mode_a: inst.instruction |= 0xf0000000; break;
17427 case neon_cvt_mode_n: inst.instruction |= 0xf0010000; break;
17428 case neon_cvt_mode_p: inst.instruction |= 0xf0020000; break;
17429 case neon_cvt_mode_m: inst.instruction |= 0xf0030000; break;
17430 default: abort ();
17431 }
17432
17433 inst.instruction |= (rs == NS_DD) << 8;
17434 do_vfp_cond_or_thumb ();
17435
17436 /* ARMv8.2 fp16 vrint instruction. */
17437 if (rs == NS_HH)
17438 do_scalar_fp16_v82_encode ();
17439 }
17440 else
17441 {
17442 /* Neon encodings (or something broken...). */
17443 inst.error = NULL;
17444 et = neon_check_type (2, rs, N_EQK, N_F_16_32 | N_KEY);
17445
17446 if (et.type == NT_invtype)
17447 return;
17448
17449 set_it_insn_type (OUTSIDE_IT_INSN);
17450 NEON_ENCODE (FLOAT, inst);
17451
17452 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH8) == FAIL)
17453 return;
17454
17455 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17456 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17457 inst.instruction |= LOW4 (inst.operands[1].reg);
17458 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17459 inst.instruction |= neon_quad (rs) << 6;
17460 /* Mask off the original size bits and reencode them. */
17461 inst.instruction = ((inst.instruction & 0xfff3ffff)
17462 | neon_logbits (et.size) << 18);
17463
17464 switch (mode)
17465 {
17466 case neon_cvt_mode_z: inst.instruction |= 3 << 7; break;
17467 case neon_cvt_mode_x: inst.instruction |= 1 << 7; break;
17468 case neon_cvt_mode_a: inst.instruction |= 2 << 7; break;
17469 case neon_cvt_mode_n: inst.instruction |= 0 << 7; break;
17470 case neon_cvt_mode_p: inst.instruction |= 7 << 7; break;
17471 case neon_cvt_mode_m: inst.instruction |= 5 << 7; break;
17472 case neon_cvt_mode_r: inst.error = _("invalid rounding mode"); break;
17473 default: abort ();
17474 }
17475
17476 if (thumb_mode)
17477 inst.instruction |= 0xfc000000;
17478 else
17479 inst.instruction |= 0xf0000000;
17480 }
17481 }
17482
17483 static void
17484 do_vrintx (void)
17485 {
17486 do_vrint_1 (neon_cvt_mode_x);
17487 }
17488
17489 static void
17490 do_vrintz (void)
17491 {
17492 do_vrint_1 (neon_cvt_mode_z);
17493 }
17494
17495 static void
17496 do_vrintr (void)
17497 {
17498 do_vrint_1 (neon_cvt_mode_r);
17499 }
17500
17501 static void
17502 do_vrinta (void)
17503 {
17504 do_vrint_1 (neon_cvt_mode_a);
17505 }
17506
17507 static void
17508 do_vrintn (void)
17509 {
17510 do_vrint_1 (neon_cvt_mode_n);
17511 }
17512
17513 static void
17514 do_vrintp (void)
17515 {
17516 do_vrint_1 (neon_cvt_mode_p);
17517 }
17518
17519 static void
17520 do_vrintm (void)
17521 {
17522 do_vrint_1 (neon_cvt_mode_m);
17523 }
17524
17525 static unsigned
17526 neon_scalar_for_vcmla (unsigned opnd, unsigned elsize)
17527 {
17528 unsigned regno = NEON_SCALAR_REG (opnd);
17529 unsigned elno = NEON_SCALAR_INDEX (opnd);
17530
17531 if (elsize == 16 && elno < 2 && regno < 16)
17532 return regno | (elno << 4);
17533 else if (elsize == 32 && elno == 0)
17534 return regno;
17535
17536 first_error (_("scalar out of range"));
17537 return 0;
17538 }
17539
17540 static void
17541 do_vcmla (void)
17542 {
17543 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17544 _(BAD_FPU));
17545 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17546 unsigned rot = inst.reloc.exp.X_add_number;
17547 constraint (rot != 0 && rot != 90 && rot != 180 && rot != 270,
17548 _("immediate out of range"));
17549 rot /= 90;
17550 if (inst.operands[2].isscalar)
17551 {
17552 enum neon_shape rs = neon_select_shape (NS_DDSI, NS_QQSI, NS_NULL);
17553 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17554 N_KEY | N_F16 | N_F32).size;
17555 unsigned m = neon_scalar_for_vcmla (inst.operands[2].reg, size);
17556 inst.is_neon = 1;
17557 inst.instruction = 0xfe000800;
17558 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17559 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17560 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
17561 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
17562 inst.instruction |= LOW4 (m);
17563 inst.instruction |= HI1 (m) << 5;
17564 inst.instruction |= neon_quad (rs) << 6;
17565 inst.instruction |= rot << 20;
17566 inst.instruction |= (size == 32) << 23;
17567 }
17568 else
17569 {
17570 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17571 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17572 N_KEY | N_F16 | N_F32).size;
17573 neon_three_same (neon_quad (rs), 0, -1);
17574 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17575 inst.instruction |= 0xfc200800;
17576 inst.instruction |= rot << 23;
17577 inst.instruction |= (size == 32) << 20;
17578 }
17579 }
17580
17581 static void
17582 do_vcadd (void)
17583 {
17584 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17585 _(BAD_FPU));
17586 constraint (inst.reloc.exp.X_op != O_constant, _("expression too complex"));
17587 unsigned rot = inst.reloc.exp.X_add_number;
17588 constraint (rot != 90 && rot != 270, _("immediate out of range"));
17589 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
17590 unsigned size = neon_check_type (3, rs, N_EQK, N_EQK,
17591 N_KEY | N_F16 | N_F32).size;
17592 neon_three_same (neon_quad (rs), 0, -1);
17593 inst.instruction &= 0x00ffffff; /* Undo neon_dp_fixup. */
17594 inst.instruction |= 0xfc800800;
17595 inst.instruction |= (rot == 270) << 24;
17596 inst.instruction |= (size == 32) << 20;
17597 }
17598
17599 /* Dot Product instructions encoding support. */
17600
17601 static void
17602 do_neon_dotproduct (int unsigned_p)
17603 {
17604 enum neon_shape rs;
17605 unsigned scalar_oprd2 = 0;
17606 int high8;
17607
17608 if (inst.cond != COND_ALWAYS)
17609 as_warn (_("Dot Product instructions cannot be conditional, the behaviour "
17610 "is UNPREDICTABLE"));
17611
17612 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_armv8),
17613 _(BAD_FPU));
17614
17615 /* Dot Product instructions are in three-same D/Q register format or the third
17616 operand can be a scalar index register. */
17617 if (inst.operands[2].isscalar)
17618 {
17619 scalar_oprd2 = neon_scalar_for_mul (inst.operands[2].reg, 32);
17620 high8 = 0xfe000000;
17621 rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
17622 }
17623 else
17624 {
17625 high8 = 0xfc000000;
17626 rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
17627 }
17628
17629 if (unsigned_p)
17630 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_U8);
17631 else
17632 neon_check_type (3, rs, N_EQK, N_EQK, N_KEY | N_S8);
17633
17634 /* The "U" bit in traditional Three Same encoding is fixed to 0 for Dot
17635 Product instruction, so we pass 0 as the "ubit" parameter. And the
17636 "Size" field are fixed to 0x2, so we pass 32 as the "size" parameter. */
17637 neon_three_same (neon_quad (rs), 0, 32);
17638
17639 /* Undo neon_dp_fixup. Dot Product instructions are using a slightly
17640 different NEON three-same encoding. */
17641 inst.instruction &= 0x00ffffff;
17642 inst.instruction |= high8;
17643 /* Encode 'U' bit which indicates signedness. */
17644 inst.instruction |= (unsigned_p ? 1 : 0) << 4;
17645 /* Re-encode operand2 if it's indexed scalar operand. What has been encoded
17646 from inst.operand[2].reg in neon_three_same is GAS's internal encoding, not
17647 the instruction encoding. */
17648 if (inst.operands[2].isscalar)
17649 {
17650 inst.instruction &= 0xffffffd0;
17651 inst.instruction |= LOW4 (scalar_oprd2);
17652 inst.instruction |= HI1 (scalar_oprd2) << 5;
17653 }
17654 }
17655
17656 /* Dot Product instructions for signed integer. */
17657
17658 static void
17659 do_neon_dotproduct_s (void)
17660 {
17661 return do_neon_dotproduct (0);
17662 }
17663
17664 /* Dot Product instructions for unsigned integer. */
17665
17666 static void
17667 do_neon_dotproduct_u (void)
17668 {
17669 return do_neon_dotproduct (1);
17670 }
17671
17672 /* Crypto v1 instructions. */
17673 static void
17674 do_crypto_2op_1 (unsigned elttype, int op)
17675 {
17676 set_it_insn_type (OUTSIDE_IT_INSN);
17677
17678 if (neon_check_type (2, NS_QQ, N_EQK | N_UNT, elttype | N_UNT | N_KEY).type
17679 == NT_invtype)
17680 return;
17681
17682 inst.error = NULL;
17683
17684 NEON_ENCODE (INTEGER, inst);
17685 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
17686 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
17687 inst.instruction |= LOW4 (inst.operands[1].reg);
17688 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
17689 if (op != -1)
17690 inst.instruction |= op << 6;
17691
17692 if (thumb_mode)
17693 inst.instruction |= 0xfc000000;
17694 else
17695 inst.instruction |= 0xf0000000;
17696 }
17697
17698 static void
17699 do_crypto_3op_1 (int u, int op)
17700 {
17701 set_it_insn_type (OUTSIDE_IT_INSN);
17702
17703 if (neon_check_type (3, NS_QQQ, N_EQK | N_UNT, N_EQK | N_UNT,
17704 N_32 | N_UNT | N_KEY).type == NT_invtype)
17705 return;
17706
17707 inst.error = NULL;
17708
17709 NEON_ENCODE (INTEGER, inst);
17710 neon_three_same (1, u, 8 << op);
17711 }
17712
17713 static void
17714 do_aese (void)
17715 {
17716 do_crypto_2op_1 (N_8, 0);
17717 }
17718
17719 static void
17720 do_aesd (void)
17721 {
17722 do_crypto_2op_1 (N_8, 1);
17723 }
17724
17725 static void
17726 do_aesmc (void)
17727 {
17728 do_crypto_2op_1 (N_8, 2);
17729 }
17730
17731 static void
17732 do_aesimc (void)
17733 {
17734 do_crypto_2op_1 (N_8, 3);
17735 }
17736
17737 static void
17738 do_sha1c (void)
17739 {
17740 do_crypto_3op_1 (0, 0);
17741 }
17742
17743 static void
17744 do_sha1p (void)
17745 {
17746 do_crypto_3op_1 (0, 1);
17747 }
17748
17749 static void
17750 do_sha1m (void)
17751 {
17752 do_crypto_3op_1 (0, 2);
17753 }
17754
17755 static void
17756 do_sha1su0 (void)
17757 {
17758 do_crypto_3op_1 (0, 3);
17759 }
17760
17761 static void
17762 do_sha256h (void)
17763 {
17764 do_crypto_3op_1 (1, 0);
17765 }
17766
17767 static void
17768 do_sha256h2 (void)
17769 {
17770 do_crypto_3op_1 (1, 1);
17771 }
17772
17773 static void
17774 do_sha256su1 (void)
17775 {
17776 do_crypto_3op_1 (1, 2);
17777 }
17778
17779 static void
17780 do_sha1h (void)
17781 {
17782 do_crypto_2op_1 (N_32, -1);
17783 }
17784
17785 static void
17786 do_sha1su1 (void)
17787 {
17788 do_crypto_2op_1 (N_32, 0);
17789 }
17790
17791 static void
17792 do_sha256su0 (void)
17793 {
17794 do_crypto_2op_1 (N_32, 1);
17795 }
17796
17797 static void
17798 do_crc32_1 (unsigned int poly, unsigned int sz)
17799 {
17800 unsigned int Rd = inst.operands[0].reg;
17801 unsigned int Rn = inst.operands[1].reg;
17802 unsigned int Rm = inst.operands[2].reg;
17803
17804 set_it_insn_type (OUTSIDE_IT_INSN);
17805 inst.instruction |= LOW4 (Rd) << (thumb_mode ? 8 : 12);
17806 inst.instruction |= LOW4 (Rn) << 16;
17807 inst.instruction |= LOW4 (Rm);
17808 inst.instruction |= sz << (thumb_mode ? 4 : 21);
17809 inst.instruction |= poly << (thumb_mode ? 20 : 9);
17810
17811 if (Rd == REG_PC || Rn == REG_PC || Rm == REG_PC)
17812 as_warn (UNPRED_REG ("r15"));
17813 }
17814
17815 static void
17816 do_crc32b (void)
17817 {
17818 do_crc32_1 (0, 0);
17819 }
17820
17821 static void
17822 do_crc32h (void)
17823 {
17824 do_crc32_1 (0, 1);
17825 }
17826
17827 static void
17828 do_crc32w (void)
17829 {
17830 do_crc32_1 (0, 2);
17831 }
17832
17833 static void
17834 do_crc32cb (void)
17835 {
17836 do_crc32_1 (1, 0);
17837 }
17838
17839 static void
17840 do_crc32ch (void)
17841 {
17842 do_crc32_1 (1, 1);
17843 }
17844
17845 static void
17846 do_crc32cw (void)
17847 {
17848 do_crc32_1 (1, 2);
17849 }
17850
17851 static void
17852 do_vjcvt (void)
17853 {
17854 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_armv8),
17855 _(BAD_FPU));
17856 neon_check_type (2, NS_FD, N_S32, N_F64);
17857 do_vfp_sp_dp_cvt ();
17858 do_vfp_cond_or_thumb ();
17859 }
17860
17861 \f
17862 /* Overall per-instruction processing. */
17863
17864 /* We need to be able to fix up arbitrary expressions in some statements.
17865 This is so that we can handle symbols that are an arbitrary distance from
17866 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
17867 which returns part of an address in a form which will be valid for
17868 a data instruction. We do this by pushing the expression into a symbol
17869 in the expr_section, and creating a fix for that. */
17870
17871 static void
17872 fix_new_arm (fragS * frag,
17873 int where,
17874 short int size,
17875 expressionS * exp,
17876 int pc_rel,
17877 int reloc)
17878 {
17879 fixS * new_fix;
17880
17881 switch (exp->X_op)
17882 {
17883 case O_constant:
17884 if (pc_rel)
17885 {
17886 /* Create an absolute valued symbol, so we have something to
17887 refer to in the object file. Unfortunately for us, gas's
17888 generic expression parsing will already have folded out
17889 any use of .set foo/.type foo %function that may have
17890 been used to set type information of the target location,
17891 that's being specified symbolically. We have to presume
17892 the user knows what they are doing. */
17893 char name[16 + 8];
17894 symbolS *symbol;
17895
17896 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
17897
17898 symbol = symbol_find_or_make (name);
17899 S_SET_SEGMENT (symbol, absolute_section);
17900 symbol_set_frag (symbol, &zero_address_frag);
17901 S_SET_VALUE (symbol, exp->X_add_number);
17902 exp->X_op = O_symbol;
17903 exp->X_add_symbol = symbol;
17904 exp->X_add_number = 0;
17905 }
17906 /* FALLTHROUGH */
17907 case O_symbol:
17908 case O_add:
17909 case O_subtract:
17910 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
17911 (enum bfd_reloc_code_real) reloc);
17912 break;
17913
17914 default:
17915 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
17916 pc_rel, (enum bfd_reloc_code_real) reloc);
17917 break;
17918 }
17919
17920 /* Mark whether the fix is to a THUMB instruction, or an ARM
17921 instruction. */
17922 new_fix->tc_fix_data = thumb_mode;
17923 }
17924
17925 /* Create a frg for an instruction requiring relaxation. */
17926 static void
17927 output_relax_insn (void)
17928 {
17929 char * to;
17930 symbolS *sym;
17931 int offset;
17932
17933 /* The size of the instruction is unknown, so tie the debug info to the
17934 start of the instruction. */
17935 dwarf2_emit_insn (0);
17936
17937 switch (inst.reloc.exp.X_op)
17938 {
17939 case O_symbol:
17940 sym = inst.reloc.exp.X_add_symbol;
17941 offset = inst.reloc.exp.X_add_number;
17942 break;
17943 case O_constant:
17944 sym = NULL;
17945 offset = inst.reloc.exp.X_add_number;
17946 break;
17947 default:
17948 sym = make_expr_symbol (&inst.reloc.exp);
17949 offset = 0;
17950 break;
17951 }
17952 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
17953 inst.relax, sym, offset, NULL/*offset, opcode*/);
17954 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
17955 }
17956
17957 /* Write a 32-bit thumb instruction to buf. */
17958 static void
17959 put_thumb32_insn (char * buf, unsigned long insn)
17960 {
17961 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
17962 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
17963 }
17964
17965 static void
17966 output_inst (const char * str)
17967 {
17968 char * to = NULL;
17969
17970 if (inst.error)
17971 {
17972 as_bad ("%s -- `%s'", inst.error, str);
17973 return;
17974 }
17975 if (inst.relax)
17976 {
17977 output_relax_insn ();
17978 return;
17979 }
17980 if (inst.size == 0)
17981 return;
17982
17983 to = frag_more (inst.size);
17984 /* PR 9814: Record the thumb mode into the current frag so that we know
17985 what type of NOP padding to use, if necessary. We override any previous
17986 setting so that if the mode has changed then the NOPS that we use will
17987 match the encoding of the last instruction in the frag. */
17988 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
17989
17990 if (thumb_mode && (inst.size > THUMB_SIZE))
17991 {
17992 gas_assert (inst.size == (2 * THUMB_SIZE));
17993 put_thumb32_insn (to, inst.instruction);
17994 }
17995 else if (inst.size > INSN_SIZE)
17996 {
17997 gas_assert (inst.size == (2 * INSN_SIZE));
17998 md_number_to_chars (to, inst.instruction, INSN_SIZE);
17999 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
18000 }
18001 else
18002 md_number_to_chars (to, inst.instruction, inst.size);
18003
18004 if (inst.reloc.type != BFD_RELOC_UNUSED)
18005 fix_new_arm (frag_now, to - frag_now->fr_literal,
18006 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
18007 inst.reloc.type);
18008
18009 dwarf2_emit_insn (inst.size);
18010 }
18011
18012 static char *
18013 output_it_inst (int cond, int mask, char * to)
18014 {
18015 unsigned long instruction = 0xbf00;
18016
18017 mask &= 0xf;
18018 instruction |= mask;
18019 instruction |= cond << 4;
18020
18021 if (to == NULL)
18022 {
18023 to = frag_more (2);
18024 #ifdef OBJ_ELF
18025 dwarf2_emit_insn (2);
18026 #endif
18027 }
18028
18029 md_number_to_chars (to, instruction, 2);
18030
18031 return to;
18032 }
18033
18034 /* Tag values used in struct asm_opcode's tag field. */
18035 enum opcode_tag
18036 {
18037 OT_unconditional, /* Instruction cannot be conditionalized.
18038 The ARM condition field is still 0xE. */
18039 OT_unconditionalF, /* Instruction cannot be conditionalized
18040 and carries 0xF in its ARM condition field. */
18041 OT_csuffix, /* Instruction takes a conditional suffix. */
18042 OT_csuffixF, /* Some forms of the instruction take a conditional
18043 suffix, others place 0xF where the condition field
18044 would be. */
18045 OT_cinfix3, /* Instruction takes a conditional infix,
18046 beginning at character index 3. (In
18047 unified mode, it becomes a suffix.) */
18048 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
18049 tsts, cmps, cmns, and teqs. */
18050 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
18051 character index 3, even in unified mode. Used for
18052 legacy instructions where suffix and infix forms
18053 may be ambiguous. */
18054 OT_csuf_or_in3, /* Instruction takes either a conditional
18055 suffix or an infix at character index 3. */
18056 OT_odd_infix_unc, /* This is the unconditional variant of an
18057 instruction that takes a conditional infix
18058 at an unusual position. In unified mode,
18059 this variant will accept a suffix. */
18060 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
18061 are the conditional variants of instructions that
18062 take conditional infixes in unusual positions.
18063 The infix appears at character index
18064 (tag - OT_odd_infix_0). These are not accepted
18065 in unified mode. */
18066 };
18067
18068 /* Subroutine of md_assemble, responsible for looking up the primary
18069 opcode from the mnemonic the user wrote. STR points to the
18070 beginning of the mnemonic.
18071
18072 This is not simply a hash table lookup, because of conditional
18073 variants. Most instructions have conditional variants, which are
18074 expressed with a _conditional affix_ to the mnemonic. If we were
18075 to encode each conditional variant as a literal string in the opcode
18076 table, it would have approximately 20,000 entries.
18077
18078 Most mnemonics take this affix as a suffix, and in unified syntax,
18079 'most' is upgraded to 'all'. However, in the divided syntax, some
18080 instructions take the affix as an infix, notably the s-variants of
18081 the arithmetic instructions. Of those instructions, all but six
18082 have the infix appear after the third character of the mnemonic.
18083
18084 Accordingly, the algorithm for looking up primary opcodes given
18085 an identifier is:
18086
18087 1. Look up the identifier in the opcode table.
18088 If we find a match, go to step U.
18089
18090 2. Look up the last two characters of the identifier in the
18091 conditions table. If we find a match, look up the first N-2
18092 characters of the identifier in the opcode table. If we
18093 find a match, go to step CE.
18094
18095 3. Look up the fourth and fifth characters of the identifier in
18096 the conditions table. If we find a match, extract those
18097 characters from the identifier, and look up the remaining
18098 characters in the opcode table. If we find a match, go
18099 to step CM.
18100
18101 4. Fail.
18102
18103 U. Examine the tag field of the opcode structure, in case this is
18104 one of the six instructions with its conditional infix in an
18105 unusual place. If it is, the tag tells us where to find the
18106 infix; look it up in the conditions table and set inst.cond
18107 accordingly. Otherwise, this is an unconditional instruction.
18108 Again set inst.cond accordingly. Return the opcode structure.
18109
18110 CE. Examine the tag field to make sure this is an instruction that
18111 should receive a conditional suffix. If it is not, fail.
18112 Otherwise, set inst.cond from the suffix we already looked up,
18113 and return the opcode structure.
18114
18115 CM. Examine the tag field to make sure this is an instruction that
18116 should receive a conditional infix after the third character.
18117 If it is not, fail. Otherwise, undo the edits to the current
18118 line of input and proceed as for case CE. */
18119
18120 static const struct asm_opcode *
18121 opcode_lookup (char **str)
18122 {
18123 char *end, *base;
18124 char *affix;
18125 const struct asm_opcode *opcode;
18126 const struct asm_cond *cond;
18127 char save[2];
18128
18129 /* Scan up to the end of the mnemonic, which must end in white space,
18130 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
18131 for (base = end = *str; *end != '\0'; end++)
18132 if (*end == ' ' || *end == '.')
18133 break;
18134
18135 if (end == base)
18136 return NULL;
18137
18138 /* Handle a possible width suffix and/or Neon type suffix. */
18139 if (end[0] == '.')
18140 {
18141 int offset = 2;
18142
18143 /* The .w and .n suffixes are only valid if the unified syntax is in
18144 use. */
18145 if (unified_syntax && end[1] == 'w')
18146 inst.size_req = 4;
18147 else if (unified_syntax && end[1] == 'n')
18148 inst.size_req = 2;
18149 else
18150 offset = 0;
18151
18152 inst.vectype.elems = 0;
18153
18154 *str = end + offset;
18155
18156 if (end[offset] == '.')
18157 {
18158 /* See if we have a Neon type suffix (possible in either unified or
18159 non-unified ARM syntax mode). */
18160 if (parse_neon_type (&inst.vectype, str) == FAIL)
18161 return NULL;
18162 }
18163 else if (end[offset] != '\0' && end[offset] != ' ')
18164 return NULL;
18165 }
18166 else
18167 *str = end;
18168
18169 /* Look for unaffixed or special-case affixed mnemonic. */
18170 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18171 end - base);
18172 if (opcode)
18173 {
18174 /* step U */
18175 if (opcode->tag < OT_odd_infix_0)
18176 {
18177 inst.cond = COND_ALWAYS;
18178 return opcode;
18179 }
18180
18181 if (warn_on_deprecated && unified_syntax)
18182 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
18183 affix = base + (opcode->tag - OT_odd_infix_0);
18184 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18185 gas_assert (cond);
18186
18187 inst.cond = cond->value;
18188 return opcode;
18189 }
18190
18191 /* Cannot have a conditional suffix on a mnemonic of less than two
18192 characters. */
18193 if (end - base < 3)
18194 return NULL;
18195
18196 /* Look for suffixed mnemonic. */
18197 affix = end - 2;
18198 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18199 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18200 affix - base);
18201 if (opcode && cond)
18202 {
18203 /* step CE */
18204 switch (opcode->tag)
18205 {
18206 case OT_cinfix3_legacy:
18207 /* Ignore conditional suffixes matched on infix only mnemonics. */
18208 break;
18209
18210 case OT_cinfix3:
18211 case OT_cinfix3_deprecated:
18212 case OT_odd_infix_unc:
18213 if (!unified_syntax)
18214 return NULL;
18215 /* Fall through. */
18216
18217 case OT_csuffix:
18218 case OT_csuffixF:
18219 case OT_csuf_or_in3:
18220 inst.cond = cond->value;
18221 return opcode;
18222
18223 case OT_unconditional:
18224 case OT_unconditionalF:
18225 if (thumb_mode)
18226 inst.cond = cond->value;
18227 else
18228 {
18229 /* Delayed diagnostic. */
18230 inst.error = BAD_COND;
18231 inst.cond = COND_ALWAYS;
18232 }
18233 return opcode;
18234
18235 default:
18236 return NULL;
18237 }
18238 }
18239
18240 /* Cannot have a usual-position infix on a mnemonic of less than
18241 six characters (five would be a suffix). */
18242 if (end - base < 6)
18243 return NULL;
18244
18245 /* Look for infixed mnemonic in the usual position. */
18246 affix = base + 3;
18247 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
18248 if (!cond)
18249 return NULL;
18250
18251 memcpy (save, affix, 2);
18252 memmove (affix, affix + 2, (end - affix) - 2);
18253 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
18254 (end - base) - 2);
18255 memmove (affix + 2, affix, (end - affix) - 2);
18256 memcpy (affix, save, 2);
18257
18258 if (opcode
18259 && (opcode->tag == OT_cinfix3
18260 || opcode->tag == OT_cinfix3_deprecated
18261 || opcode->tag == OT_csuf_or_in3
18262 || opcode->tag == OT_cinfix3_legacy))
18263 {
18264 /* Step CM. */
18265 if (warn_on_deprecated && unified_syntax
18266 && (opcode->tag == OT_cinfix3
18267 || opcode->tag == OT_cinfix3_deprecated))
18268 as_tsktsk (_("conditional infixes are deprecated in unified syntax"));
18269
18270 inst.cond = cond->value;
18271 return opcode;
18272 }
18273
18274 return NULL;
18275 }
18276
18277 /* This function generates an initial IT instruction, leaving its block
18278 virtually open for the new instructions. Eventually,
18279 the mask will be updated by now_it_add_mask () each time
18280 a new instruction needs to be included in the IT block.
18281 Finally, the block is closed with close_automatic_it_block ().
18282 The block closure can be requested either from md_assemble (),
18283 a tencode (), or due to a label hook. */
18284
18285 static void
18286 new_automatic_it_block (int cond)
18287 {
18288 now_it.state = AUTOMATIC_IT_BLOCK;
18289 now_it.mask = 0x18;
18290 now_it.cc = cond;
18291 now_it.block_length = 1;
18292 mapping_state (MAP_THUMB);
18293 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
18294 now_it.warn_deprecated = FALSE;
18295 now_it.insn_cond = TRUE;
18296 }
18297
18298 /* Close an automatic IT block.
18299 See comments in new_automatic_it_block (). */
18300
18301 static void
18302 close_automatic_it_block (void)
18303 {
18304 now_it.mask = 0x10;
18305 now_it.block_length = 0;
18306 }
18307
18308 /* Update the mask of the current automatically-generated IT
18309 instruction. See comments in new_automatic_it_block (). */
18310
18311 static void
18312 now_it_add_mask (int cond)
18313 {
18314 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
18315 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
18316 | ((bitvalue) << (nbit)))
18317 const int resulting_bit = (cond & 1);
18318
18319 now_it.mask &= 0xf;
18320 now_it.mask = SET_BIT_VALUE (now_it.mask,
18321 resulting_bit,
18322 (5 - now_it.block_length));
18323 now_it.mask = SET_BIT_VALUE (now_it.mask,
18324 1,
18325 ((5 - now_it.block_length) - 1) );
18326 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
18327
18328 #undef CLEAR_BIT
18329 #undef SET_BIT_VALUE
18330 }
18331
18332 /* The IT blocks handling machinery is accessed through the these functions:
18333 it_fsm_pre_encode () from md_assemble ()
18334 set_it_insn_type () optional, from the tencode functions
18335 set_it_insn_type_last () ditto
18336 in_it_block () ditto
18337 it_fsm_post_encode () from md_assemble ()
18338 force_automatic_it_block_close () from label handling functions
18339
18340 Rationale:
18341 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
18342 initializing the IT insn type with a generic initial value depending
18343 on the inst.condition.
18344 2) During the tencode function, two things may happen:
18345 a) The tencode function overrides the IT insn type by
18346 calling either set_it_insn_type (type) or set_it_insn_type_last ().
18347 b) The tencode function queries the IT block state by
18348 calling in_it_block () (i.e. to determine narrow/not narrow mode).
18349
18350 Both set_it_insn_type and in_it_block run the internal FSM state
18351 handling function (handle_it_state), because: a) setting the IT insn
18352 type may incur in an invalid state (exiting the function),
18353 and b) querying the state requires the FSM to be updated.
18354 Specifically we want to avoid creating an IT block for conditional
18355 branches, so it_fsm_pre_encode is actually a guess and we can't
18356 determine whether an IT block is required until the tencode () routine
18357 has decided what type of instruction this actually it.
18358 Because of this, if set_it_insn_type and in_it_block have to be used,
18359 set_it_insn_type has to be called first.
18360
18361 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
18362 determines the insn IT type depending on the inst.cond code.
18363 When a tencode () routine encodes an instruction that can be
18364 either outside an IT block, or, in the case of being inside, has to be
18365 the last one, set_it_insn_type_last () will determine the proper
18366 IT instruction type based on the inst.cond code. Otherwise,
18367 set_it_insn_type can be called for overriding that logic or
18368 for covering other cases.
18369
18370 Calling handle_it_state () may not transition the IT block state to
18371 OUTSIDE_IT_BLOCK immediately, since the (current) state could be
18372 still queried. Instead, if the FSM determines that the state should
18373 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
18374 after the tencode () function: that's what it_fsm_post_encode () does.
18375
18376 Since in_it_block () calls the state handling function to get an
18377 updated state, an error may occur (due to invalid insns combination).
18378 In that case, inst.error is set.
18379 Therefore, inst.error has to be checked after the execution of
18380 the tencode () routine.
18381
18382 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
18383 any pending state change (if any) that didn't take place in
18384 handle_it_state () as explained above. */
18385
18386 static void
18387 it_fsm_pre_encode (void)
18388 {
18389 if (inst.cond != COND_ALWAYS)
18390 inst.it_insn_type = INSIDE_IT_INSN;
18391 else
18392 inst.it_insn_type = OUTSIDE_IT_INSN;
18393
18394 now_it.state_handled = 0;
18395 }
18396
18397 /* IT state FSM handling function. */
18398
18399 static int
18400 handle_it_state (void)
18401 {
18402 now_it.state_handled = 1;
18403 now_it.insn_cond = FALSE;
18404
18405 switch (now_it.state)
18406 {
18407 case OUTSIDE_IT_BLOCK:
18408 switch (inst.it_insn_type)
18409 {
18410 case OUTSIDE_IT_INSN:
18411 break;
18412
18413 case INSIDE_IT_INSN:
18414 case INSIDE_IT_LAST_INSN:
18415 if (thumb_mode == 0)
18416 {
18417 if (unified_syntax
18418 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
18419 as_tsktsk (_("Warning: conditional outside an IT block"\
18420 " for Thumb."));
18421 }
18422 else
18423 {
18424 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
18425 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
18426 {
18427 /* Automatically generate the IT instruction. */
18428 new_automatic_it_block (inst.cond);
18429 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
18430 close_automatic_it_block ();
18431 }
18432 else
18433 {
18434 inst.error = BAD_OUT_IT;
18435 return FAIL;
18436 }
18437 }
18438 break;
18439
18440 case IF_INSIDE_IT_LAST_INSN:
18441 case NEUTRAL_IT_INSN:
18442 break;
18443
18444 case IT_INSN:
18445 now_it.state = MANUAL_IT_BLOCK;
18446 now_it.block_length = 0;
18447 break;
18448 }
18449 break;
18450
18451 case AUTOMATIC_IT_BLOCK:
18452 /* Three things may happen now:
18453 a) We should increment current it block size;
18454 b) We should close current it block (closing insn or 4 insns);
18455 c) We should close current it block and start a new one (due
18456 to incompatible conditions or
18457 4 insns-length block reached). */
18458
18459 switch (inst.it_insn_type)
18460 {
18461 case OUTSIDE_IT_INSN:
18462 /* The closure of the block shall happen immediately,
18463 so any in_it_block () call reports the block as closed. */
18464 force_automatic_it_block_close ();
18465 break;
18466
18467 case INSIDE_IT_INSN:
18468 case INSIDE_IT_LAST_INSN:
18469 case IF_INSIDE_IT_LAST_INSN:
18470 now_it.block_length++;
18471
18472 if (now_it.block_length > 4
18473 || !now_it_compatible (inst.cond))
18474 {
18475 force_automatic_it_block_close ();
18476 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
18477 new_automatic_it_block (inst.cond);
18478 }
18479 else
18480 {
18481 now_it.insn_cond = TRUE;
18482 now_it_add_mask (inst.cond);
18483 }
18484
18485 if (now_it.state == AUTOMATIC_IT_BLOCK
18486 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
18487 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
18488 close_automatic_it_block ();
18489 break;
18490
18491 case NEUTRAL_IT_INSN:
18492 now_it.block_length++;
18493 now_it.insn_cond = TRUE;
18494
18495 if (now_it.block_length > 4)
18496 force_automatic_it_block_close ();
18497 else
18498 now_it_add_mask (now_it.cc & 1);
18499 break;
18500
18501 case IT_INSN:
18502 close_automatic_it_block ();
18503 now_it.state = MANUAL_IT_BLOCK;
18504 break;
18505 }
18506 break;
18507
18508 case MANUAL_IT_BLOCK:
18509 {
18510 /* Check conditional suffixes. */
18511 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
18512 int is_last;
18513 now_it.mask <<= 1;
18514 now_it.mask &= 0x1f;
18515 is_last = (now_it.mask == 0x10);
18516 now_it.insn_cond = TRUE;
18517
18518 switch (inst.it_insn_type)
18519 {
18520 case OUTSIDE_IT_INSN:
18521 inst.error = BAD_NOT_IT;
18522 return FAIL;
18523
18524 case INSIDE_IT_INSN:
18525 if (cond != inst.cond)
18526 {
18527 inst.error = BAD_IT_COND;
18528 return FAIL;
18529 }
18530 break;
18531
18532 case INSIDE_IT_LAST_INSN:
18533 case IF_INSIDE_IT_LAST_INSN:
18534 if (cond != inst.cond)
18535 {
18536 inst.error = BAD_IT_COND;
18537 return FAIL;
18538 }
18539 if (!is_last)
18540 {
18541 inst.error = BAD_BRANCH;
18542 return FAIL;
18543 }
18544 break;
18545
18546 case NEUTRAL_IT_INSN:
18547 /* The BKPT instruction is unconditional even in an IT block. */
18548 break;
18549
18550 case IT_INSN:
18551 inst.error = BAD_IT_IT;
18552 return FAIL;
18553 }
18554 }
18555 break;
18556 }
18557
18558 return SUCCESS;
18559 }
18560
18561 struct depr_insn_mask
18562 {
18563 unsigned long pattern;
18564 unsigned long mask;
18565 const char* description;
18566 };
18567
18568 /* List of 16-bit instruction patterns deprecated in an IT block in
18569 ARMv8. */
18570 static const struct depr_insn_mask depr_it_insns[] = {
18571 { 0xc000, 0xc000, N_("Short branches, Undefined, SVC, LDM/STM") },
18572 { 0xb000, 0xb000, N_("Miscellaneous 16-bit instructions") },
18573 { 0xa000, 0xb800, N_("ADR") },
18574 { 0x4800, 0xf800, N_("Literal loads") },
18575 { 0x4478, 0xf478, N_("Hi-register ADD, MOV, CMP, BX, BLX using pc") },
18576 { 0x4487, 0xfc87, N_("Hi-register ADD, MOV, CMP using pc") },
18577 /* NOTE: 0x00dd is not the real encoding, instead, it is the 'tvalue'
18578 field in asm_opcode. 'tvalue' is used at the stage this check happen. */
18579 { 0x00dd, 0x7fff, N_("ADD/SUB sp, sp #imm") },
18580 { 0, 0, NULL }
18581 };
18582
18583 static void
18584 it_fsm_post_encode (void)
18585 {
18586 int is_last;
18587
18588 if (!now_it.state_handled)
18589 handle_it_state ();
18590
18591 if (now_it.insn_cond
18592 && !now_it.warn_deprecated
18593 && warn_on_deprecated
18594 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v8)
18595 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m))
18596 {
18597 if (inst.instruction >= 0x10000)
18598 {
18599 as_tsktsk (_("IT blocks containing 32-bit Thumb instructions are "
18600 "performance deprecated in ARMv8-A and ARMv8-R"));
18601 now_it.warn_deprecated = TRUE;
18602 }
18603 else
18604 {
18605 const struct depr_insn_mask *p = depr_it_insns;
18606
18607 while (p->mask != 0)
18608 {
18609 if ((inst.instruction & p->mask) == p->pattern)
18610 {
18611 as_tsktsk (_("IT blocks containing 16-bit Thumb "
18612 "instructions of the following class are "
18613 "performance deprecated in ARMv8-A and "
18614 "ARMv8-R: %s"), p->description);
18615 now_it.warn_deprecated = TRUE;
18616 break;
18617 }
18618
18619 ++p;
18620 }
18621 }
18622
18623 if (now_it.block_length > 1)
18624 {
18625 as_tsktsk (_("IT blocks containing more than one conditional "
18626 "instruction are performance deprecated in ARMv8-A and "
18627 "ARMv8-R"));
18628 now_it.warn_deprecated = TRUE;
18629 }
18630 }
18631
18632 is_last = (now_it.mask == 0x10);
18633 if (is_last)
18634 {
18635 now_it.state = OUTSIDE_IT_BLOCK;
18636 now_it.mask = 0;
18637 }
18638 }
18639
18640 static void
18641 force_automatic_it_block_close (void)
18642 {
18643 if (now_it.state == AUTOMATIC_IT_BLOCK)
18644 {
18645 close_automatic_it_block ();
18646 now_it.state = OUTSIDE_IT_BLOCK;
18647 now_it.mask = 0;
18648 }
18649 }
18650
18651 static int
18652 in_it_block (void)
18653 {
18654 if (!now_it.state_handled)
18655 handle_it_state ();
18656
18657 return now_it.state != OUTSIDE_IT_BLOCK;
18658 }
18659
18660 /* Whether OPCODE only has T32 encoding. Since this function is only used by
18661 t32_insn_ok, OPCODE enabled by v6t2 extension bit do not need to be listed
18662 here, hence the "known" in the function name. */
18663
18664 static bfd_boolean
18665 known_t32_only_insn (const struct asm_opcode *opcode)
18666 {
18667 /* Original Thumb-1 wide instruction. */
18668 if (opcode->tencode == do_t_blx
18669 || opcode->tencode == do_t_branch23
18670 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
18671 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier))
18672 return TRUE;
18673
18674 /* Wide-only instruction added to ARMv8-M Baseline. */
18675 if (ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v8m_m_only)
18676 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_atomics)
18677 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_v6t2_v8m)
18678 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_div))
18679 return TRUE;
18680
18681 return FALSE;
18682 }
18683
18684 /* Whether wide instruction variant can be used if available for a valid OPCODE
18685 in ARCH. */
18686
18687 static bfd_boolean
18688 t32_insn_ok (arm_feature_set arch, const struct asm_opcode *opcode)
18689 {
18690 if (known_t32_only_insn (opcode))
18691 return TRUE;
18692
18693 /* Instruction with narrow and wide encoding added to ARMv8-M. Availability
18694 of variant T3 of B.W is checked in do_t_branch. */
18695 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18696 && opcode->tencode == do_t_branch)
18697 return TRUE;
18698
18699 /* MOV accepts T1/T3 encodings under Baseline, T3 encoding is 32bit. */
18700 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v8m)
18701 && opcode->tencode == do_t_mov_cmp
18702 /* Make sure CMP instruction is not affected. */
18703 && opcode->aencode == do_mov)
18704 return TRUE;
18705
18706 /* Wide instruction variants of all instructions with narrow *and* wide
18707 variants become available with ARMv6t2. Other opcodes are either
18708 narrow-only or wide-only and are thus available if OPCODE is valid. */
18709 if (ARM_CPU_HAS_FEATURE (arch, arm_ext_v6t2))
18710 return TRUE;
18711
18712 /* OPCODE with narrow only instruction variant or wide variant not
18713 available. */
18714 return FALSE;
18715 }
18716
18717 void
18718 md_assemble (char *str)
18719 {
18720 char *p = str;
18721 const struct asm_opcode * opcode;
18722
18723 /* Align the previous label if needed. */
18724 if (last_label_seen != NULL)
18725 {
18726 symbol_set_frag (last_label_seen, frag_now);
18727 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
18728 S_SET_SEGMENT (last_label_seen, now_seg);
18729 }
18730
18731 memset (&inst, '\0', sizeof (inst));
18732 inst.reloc.type = BFD_RELOC_UNUSED;
18733
18734 opcode = opcode_lookup (&p);
18735 if (!opcode)
18736 {
18737 /* It wasn't an instruction, but it might be a register alias of
18738 the form alias .req reg, or a Neon .dn/.qn directive. */
18739 if (! create_register_alias (str, p)
18740 && ! create_neon_reg_alias (str, p))
18741 as_bad (_("bad instruction `%s'"), str);
18742
18743 return;
18744 }
18745
18746 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
18747 as_tsktsk (_("s suffix on comparison instruction is deprecated"));
18748
18749 /* The value which unconditional instructions should have in place of the
18750 condition field. */
18751 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
18752
18753 if (thumb_mode)
18754 {
18755 arm_feature_set variant;
18756
18757 variant = cpu_variant;
18758 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
18759 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
18760 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
18761 /* Check that this instruction is supported for this CPU. */
18762 if (!opcode->tvariant
18763 || (thumb_mode == 1
18764 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
18765 {
18766 if (opcode->tencode == do_t_swi)
18767 as_bad (_("SVC is not permitted on this architecture"));
18768 else
18769 as_bad (_("selected processor does not support `%s' in Thumb mode"), str);
18770 return;
18771 }
18772 if (inst.cond != COND_ALWAYS && !unified_syntax
18773 && opcode->tencode != do_t_branch)
18774 {
18775 as_bad (_("Thumb does not support conditional execution"));
18776 return;
18777 }
18778
18779 /* Two things are addressed here:
18780 1) Implicit require narrow instructions on Thumb-1.
18781 This avoids relaxation accidentally introducing Thumb-2
18782 instructions.
18783 2) Reject wide instructions in non Thumb-2 cores.
18784
18785 Only instructions with narrow and wide variants need to be handled
18786 but selecting all non wide-only instructions is easier. */
18787 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2)
18788 && !t32_insn_ok (variant, opcode))
18789 {
18790 if (inst.size_req == 0)
18791 inst.size_req = 2;
18792 else if (inst.size_req == 4)
18793 {
18794 if (ARM_CPU_HAS_FEATURE (variant, arm_ext_v8m))
18795 as_bad (_("selected processor does not support 32bit wide "
18796 "variant of instruction `%s'"), str);
18797 else
18798 as_bad (_("selected processor does not support `%s' in "
18799 "Thumb-2 mode"), str);
18800 return;
18801 }
18802 }
18803
18804 inst.instruction = opcode->tvalue;
18805
18806 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
18807 {
18808 /* Prepare the it_insn_type for those encodings that don't set
18809 it. */
18810 it_fsm_pre_encode ();
18811
18812 opcode->tencode ();
18813
18814 it_fsm_post_encode ();
18815 }
18816
18817 if (!(inst.error || inst.relax))
18818 {
18819 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
18820 inst.size = (inst.instruction > 0xffff ? 4 : 2);
18821 if (inst.size_req && inst.size_req != inst.size)
18822 {
18823 as_bad (_("cannot honor width suffix -- `%s'"), str);
18824 return;
18825 }
18826 }
18827
18828 /* Something has gone badly wrong if we try to relax a fixed size
18829 instruction. */
18830 gas_assert (inst.size_req == 0 || !inst.relax);
18831
18832 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18833 *opcode->tvariant);
18834 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
18835 set those bits when Thumb-2 32-bit instructions are seen. The impact
18836 of relaxable instructions will be considered later after we finish all
18837 relaxation. */
18838 if (ARM_FEATURE_CORE_EQUAL (cpu_variant, arm_arch_any))
18839 variant = arm_arch_none;
18840 else
18841 variant = cpu_variant;
18842 if (inst.size == 4 && !t32_insn_ok (variant, opcode))
18843 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
18844 arm_ext_v6t2);
18845
18846 check_neon_suffixes;
18847
18848 if (!inst.error)
18849 {
18850 mapping_state (MAP_THUMB);
18851 }
18852 }
18853 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
18854 {
18855 bfd_boolean is_bx;
18856
18857 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
18858 is_bx = (opcode->aencode == do_bx);
18859
18860 /* Check that this instruction is supported for this CPU. */
18861 if (!(is_bx && fix_v4bx)
18862 && !(opcode->avariant &&
18863 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
18864 {
18865 as_bad (_("selected processor does not support `%s' in ARM mode"), str);
18866 return;
18867 }
18868 if (inst.size_req)
18869 {
18870 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
18871 return;
18872 }
18873
18874 inst.instruction = opcode->avalue;
18875 if (opcode->tag == OT_unconditionalF)
18876 inst.instruction |= 0xFU << 28;
18877 else
18878 inst.instruction |= inst.cond << 28;
18879 inst.size = INSN_SIZE;
18880 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
18881 {
18882 it_fsm_pre_encode ();
18883 opcode->aencode ();
18884 it_fsm_post_encode ();
18885 }
18886 /* Arm mode bx is marked as both v4T and v5 because it's still required
18887 on a hypothetical non-thumb v5 core. */
18888 if (is_bx)
18889 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
18890 else
18891 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
18892 *opcode->avariant);
18893
18894 check_neon_suffixes;
18895
18896 if (!inst.error)
18897 {
18898 mapping_state (MAP_ARM);
18899 }
18900 }
18901 else
18902 {
18903 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
18904 "-- `%s'"), str);
18905 return;
18906 }
18907 output_inst (str);
18908 }
18909
18910 static void
18911 check_it_blocks_finished (void)
18912 {
18913 #ifdef OBJ_ELF
18914 asection *sect;
18915
18916 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
18917 if (seg_info (sect)->tc_segment_info_data.current_it.state
18918 == MANUAL_IT_BLOCK)
18919 {
18920 as_warn (_("section '%s' finished with an open IT block."),
18921 sect->name);
18922 }
18923 #else
18924 if (now_it.state == MANUAL_IT_BLOCK)
18925 as_warn (_("file finished with an open IT block."));
18926 #endif
18927 }
18928
18929 /* Various frobbings of labels and their addresses. */
18930
18931 void
18932 arm_start_line_hook (void)
18933 {
18934 last_label_seen = NULL;
18935 }
18936
18937 void
18938 arm_frob_label (symbolS * sym)
18939 {
18940 last_label_seen = sym;
18941
18942 ARM_SET_THUMB (sym, thumb_mode);
18943
18944 #if defined OBJ_COFF || defined OBJ_ELF
18945 ARM_SET_INTERWORK (sym, support_interwork);
18946 #endif
18947
18948 force_automatic_it_block_close ();
18949
18950 /* Note - do not allow local symbols (.Lxxx) to be labelled
18951 as Thumb functions. This is because these labels, whilst
18952 they exist inside Thumb code, are not the entry points for
18953 possible ARM->Thumb calls. Also, these labels can be used
18954 as part of a computed goto or switch statement. eg gcc
18955 can generate code that looks like this:
18956
18957 ldr r2, [pc, .Laaa]
18958 lsl r3, r3, #2
18959 ldr r2, [r3, r2]
18960 mov pc, r2
18961
18962 .Lbbb: .word .Lxxx
18963 .Lccc: .word .Lyyy
18964 ..etc...
18965 .Laaa: .word Lbbb
18966
18967 The first instruction loads the address of the jump table.
18968 The second instruction converts a table index into a byte offset.
18969 The third instruction gets the jump address out of the table.
18970 The fourth instruction performs the jump.
18971
18972 If the address stored at .Laaa is that of a symbol which has the
18973 Thumb_Func bit set, then the linker will arrange for this address
18974 to have the bottom bit set, which in turn would mean that the
18975 address computation performed by the third instruction would end
18976 up with the bottom bit set. Since the ARM is capable of unaligned
18977 word loads, the instruction would then load the incorrect address
18978 out of the jump table, and chaos would ensue. */
18979 if (label_is_thumb_function_name
18980 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
18981 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
18982 {
18983 /* When the address of a Thumb function is taken the bottom
18984 bit of that address should be set. This will allow
18985 interworking between Arm and Thumb functions to work
18986 correctly. */
18987
18988 THUMB_SET_FUNC (sym, 1);
18989
18990 label_is_thumb_function_name = FALSE;
18991 }
18992
18993 dwarf2_emit_label (sym);
18994 }
18995
18996 bfd_boolean
18997 arm_data_in_code (void)
18998 {
18999 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
19000 {
19001 *input_line_pointer = '/';
19002 input_line_pointer += 5;
19003 *input_line_pointer = 0;
19004 return TRUE;
19005 }
19006
19007 return FALSE;
19008 }
19009
19010 char *
19011 arm_canonicalize_symbol_name (char * name)
19012 {
19013 int len;
19014
19015 if (thumb_mode && (len = strlen (name)) > 5
19016 && streq (name + len - 5, "/data"))
19017 *(name + len - 5) = 0;
19018
19019 return name;
19020 }
19021 \f
19022 /* Table of all register names defined by default. The user can
19023 define additional names with .req. Note that all register names
19024 should appear in both upper and lowercase variants. Some registers
19025 also have mixed-case names. */
19026
19027 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
19028 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
19029 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
19030 #define REGSET(p,t) \
19031 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
19032 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
19033 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
19034 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
19035 #define REGSETH(p,t) \
19036 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
19037 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
19038 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
19039 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
19040 #define REGSET2(p,t) \
19041 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
19042 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
19043 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
19044 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
19045 #define SPLRBANK(base,bank,t) \
19046 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
19047 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
19048 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
19049 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
19050 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
19051 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
19052
19053 static const struct reg_entry reg_names[] =
19054 {
19055 /* ARM integer registers. */
19056 REGSET(r, RN), REGSET(R, RN),
19057
19058 /* ATPCS synonyms. */
19059 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
19060 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
19061 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
19062
19063 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
19064 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
19065 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
19066
19067 /* Well-known aliases. */
19068 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
19069 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
19070
19071 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
19072 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
19073
19074 /* Coprocessor numbers. */
19075 REGSET(p, CP), REGSET(P, CP),
19076
19077 /* Coprocessor register numbers. The "cr" variants are for backward
19078 compatibility. */
19079 REGSET(c, CN), REGSET(C, CN),
19080 REGSET(cr, CN), REGSET(CR, CN),
19081
19082 /* ARM banked registers. */
19083 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
19084 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
19085 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
19086 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
19087 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
19088 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
19089 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
19090
19091 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
19092 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
19093 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
19094 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
19095 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
19096 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(sp_fiq,512|(13<<16),RNB),
19097 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
19098 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
19099
19100 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
19101 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
19102 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
19103 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
19104 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
19105 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
19106 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
19107 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
19108 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
19109
19110 /* FPA registers. */
19111 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
19112 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
19113
19114 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
19115 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
19116
19117 /* VFP SP registers. */
19118 REGSET(s,VFS), REGSET(S,VFS),
19119 REGSETH(s,VFS), REGSETH(S,VFS),
19120
19121 /* VFP DP Registers. */
19122 REGSET(d,VFD), REGSET(D,VFD),
19123 /* Extra Neon DP registers. */
19124 REGSETH(d,VFD), REGSETH(D,VFD),
19125
19126 /* Neon QP registers. */
19127 REGSET2(q,NQ), REGSET2(Q,NQ),
19128
19129 /* VFP control registers. */
19130 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
19131 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
19132 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
19133 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
19134 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
19135 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
19136 REGDEF(mvfr2,5,VFC), REGDEF(MVFR2,5,VFC),
19137
19138 /* Maverick DSP coprocessor registers. */
19139 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
19140 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
19141
19142 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
19143 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
19144 REGDEF(dspsc,0,DSPSC),
19145
19146 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
19147 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
19148 REGDEF(DSPSC,0,DSPSC),
19149
19150 /* iWMMXt data registers - p0, c0-15. */
19151 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
19152
19153 /* iWMMXt control registers - p1, c0-3. */
19154 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
19155 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
19156 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
19157 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
19158
19159 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
19160 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
19161 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
19162 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
19163 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
19164
19165 /* XScale accumulator registers. */
19166 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
19167 };
19168 #undef REGDEF
19169 #undef REGNUM
19170 #undef REGSET
19171
19172 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
19173 within psr_required_here. */
19174 static const struct asm_psr psrs[] =
19175 {
19176 /* Backward compatibility notation. Note that "all" is no longer
19177 truly all possible PSR bits. */
19178 {"all", PSR_c | PSR_f},
19179 {"flg", PSR_f},
19180 {"ctl", PSR_c},
19181
19182 /* Individual flags. */
19183 {"f", PSR_f},
19184 {"c", PSR_c},
19185 {"x", PSR_x},
19186 {"s", PSR_s},
19187
19188 /* Combinations of flags. */
19189 {"fs", PSR_f | PSR_s},
19190 {"fx", PSR_f | PSR_x},
19191 {"fc", PSR_f | PSR_c},
19192 {"sf", PSR_s | PSR_f},
19193 {"sx", PSR_s | PSR_x},
19194 {"sc", PSR_s | PSR_c},
19195 {"xf", PSR_x | PSR_f},
19196 {"xs", PSR_x | PSR_s},
19197 {"xc", PSR_x | PSR_c},
19198 {"cf", PSR_c | PSR_f},
19199 {"cs", PSR_c | PSR_s},
19200 {"cx", PSR_c | PSR_x},
19201 {"fsx", PSR_f | PSR_s | PSR_x},
19202 {"fsc", PSR_f | PSR_s | PSR_c},
19203 {"fxs", PSR_f | PSR_x | PSR_s},
19204 {"fxc", PSR_f | PSR_x | PSR_c},
19205 {"fcs", PSR_f | PSR_c | PSR_s},
19206 {"fcx", PSR_f | PSR_c | PSR_x},
19207 {"sfx", PSR_s | PSR_f | PSR_x},
19208 {"sfc", PSR_s | PSR_f | PSR_c},
19209 {"sxf", PSR_s | PSR_x | PSR_f},
19210 {"sxc", PSR_s | PSR_x | PSR_c},
19211 {"scf", PSR_s | PSR_c | PSR_f},
19212 {"scx", PSR_s | PSR_c | PSR_x},
19213 {"xfs", PSR_x | PSR_f | PSR_s},
19214 {"xfc", PSR_x | PSR_f | PSR_c},
19215 {"xsf", PSR_x | PSR_s | PSR_f},
19216 {"xsc", PSR_x | PSR_s | PSR_c},
19217 {"xcf", PSR_x | PSR_c | PSR_f},
19218 {"xcs", PSR_x | PSR_c | PSR_s},
19219 {"cfs", PSR_c | PSR_f | PSR_s},
19220 {"cfx", PSR_c | PSR_f | PSR_x},
19221 {"csf", PSR_c | PSR_s | PSR_f},
19222 {"csx", PSR_c | PSR_s | PSR_x},
19223 {"cxf", PSR_c | PSR_x | PSR_f},
19224 {"cxs", PSR_c | PSR_x | PSR_s},
19225 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
19226 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
19227 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
19228 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
19229 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
19230 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
19231 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
19232 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
19233 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
19234 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
19235 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
19236 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
19237 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
19238 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
19239 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
19240 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
19241 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
19242 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
19243 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
19244 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
19245 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
19246 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
19247 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
19248 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
19249 };
19250
19251 /* Table of V7M psr names. */
19252 static const struct asm_psr v7m_psrs[] =
19253 {
19254 {"apsr", 0x0 }, {"APSR", 0x0 },
19255 {"iapsr", 0x1 }, {"IAPSR", 0x1 },
19256 {"eapsr", 0x2 }, {"EAPSR", 0x2 },
19257 {"psr", 0x3 }, {"PSR", 0x3 },
19258 {"xpsr", 0x3 }, {"XPSR", 0x3 }, {"xPSR", 3 },
19259 {"ipsr", 0x5 }, {"IPSR", 0x5 },
19260 {"epsr", 0x6 }, {"EPSR", 0x6 },
19261 {"iepsr", 0x7 }, {"IEPSR", 0x7 },
19262 {"msp", 0x8 }, {"MSP", 0x8 },
19263 {"psp", 0x9 }, {"PSP", 0x9 },
19264 {"msplim", 0xa }, {"MSPLIM", 0xa },
19265 {"psplim", 0xb }, {"PSPLIM", 0xb },
19266 {"primask", 0x10}, {"PRIMASK", 0x10},
19267 {"basepri", 0x11}, {"BASEPRI", 0x11},
19268 {"basepri_max", 0x12}, {"BASEPRI_MAX", 0x12},
19269 {"faultmask", 0x13}, {"FAULTMASK", 0x13},
19270 {"control", 0x14}, {"CONTROL", 0x14},
19271 {"msp_ns", 0x88}, {"MSP_NS", 0x88},
19272 {"psp_ns", 0x89}, {"PSP_NS", 0x89},
19273 {"msplim_ns", 0x8a}, {"MSPLIM_NS", 0x8a},
19274 {"psplim_ns", 0x8b}, {"PSPLIM_NS", 0x8b},
19275 {"primask_ns", 0x90}, {"PRIMASK_NS", 0x90},
19276 {"basepri_ns", 0x91}, {"BASEPRI_NS", 0x91},
19277 {"faultmask_ns", 0x93}, {"FAULTMASK_NS", 0x93},
19278 {"control_ns", 0x94}, {"CONTROL_NS", 0x94},
19279 {"sp_ns", 0x98}, {"SP_NS", 0x98 }
19280 };
19281
19282 /* Table of all shift-in-operand names. */
19283 static const struct asm_shift_name shift_names [] =
19284 {
19285 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
19286 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
19287 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
19288 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
19289 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
19290 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
19291 };
19292
19293 /* Table of all explicit relocation names. */
19294 #ifdef OBJ_ELF
19295 static struct reloc_entry reloc_names[] =
19296 {
19297 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
19298 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
19299 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
19300 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
19301 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
19302 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
19303 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
19304 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
19305 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
19306 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
19307 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
19308 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
19309 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
19310 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
19311 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
19312 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
19313 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
19314 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ},
19315 { "gotfuncdesc", BFD_RELOC_ARM_GOTFUNCDESC },
19316 { "GOTFUNCDESC", BFD_RELOC_ARM_GOTFUNCDESC },
19317 { "gotofffuncdesc", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19318 { "GOTOFFFUNCDESC", BFD_RELOC_ARM_GOTOFFFUNCDESC },
19319 { "funcdesc", BFD_RELOC_ARM_FUNCDESC },
19320 { "FUNCDESC", BFD_RELOC_ARM_FUNCDESC },
19321 { "tlsgd_fdpic", BFD_RELOC_ARM_TLS_GD32_FDPIC }, { "TLSGD_FDPIC", BFD_RELOC_ARM_TLS_GD32_FDPIC },
19322 { "tlsldm_fdpic", BFD_RELOC_ARM_TLS_LDM32_FDPIC }, { "TLSLDM_FDPIC", BFD_RELOC_ARM_TLS_LDM32_FDPIC },
19323 { "gottpoff_fdpic", BFD_RELOC_ARM_TLS_IE32_FDPIC }, { "GOTTPOFF_FDIC", BFD_RELOC_ARM_TLS_IE32_FDPIC },
19324 };
19325 #endif
19326
19327 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
19328 static const struct asm_cond conds[] =
19329 {
19330 {"eq", 0x0},
19331 {"ne", 0x1},
19332 {"cs", 0x2}, {"hs", 0x2},
19333 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
19334 {"mi", 0x4},
19335 {"pl", 0x5},
19336 {"vs", 0x6},
19337 {"vc", 0x7},
19338 {"hi", 0x8},
19339 {"ls", 0x9},
19340 {"ge", 0xa},
19341 {"lt", 0xb},
19342 {"gt", 0xc},
19343 {"le", 0xd},
19344 {"al", 0xe}
19345 };
19346
19347 #define UL_BARRIER(L,U,CODE,FEAT) \
19348 { L, CODE, ARM_FEATURE_CORE_LOW (FEAT) }, \
19349 { U, CODE, ARM_FEATURE_CORE_LOW (FEAT) }
19350
19351 static struct asm_barrier_opt barrier_opt_names[] =
19352 {
19353 UL_BARRIER ("sy", "SY", 0xf, ARM_EXT_BARRIER),
19354 UL_BARRIER ("st", "ST", 0xe, ARM_EXT_BARRIER),
19355 UL_BARRIER ("ld", "LD", 0xd, ARM_EXT_V8),
19356 UL_BARRIER ("ish", "ISH", 0xb, ARM_EXT_BARRIER),
19357 UL_BARRIER ("sh", "SH", 0xb, ARM_EXT_BARRIER),
19358 UL_BARRIER ("ishst", "ISHST", 0xa, ARM_EXT_BARRIER),
19359 UL_BARRIER ("shst", "SHST", 0xa, ARM_EXT_BARRIER),
19360 UL_BARRIER ("ishld", "ISHLD", 0x9, ARM_EXT_V8),
19361 UL_BARRIER ("un", "UN", 0x7, ARM_EXT_BARRIER),
19362 UL_BARRIER ("nsh", "NSH", 0x7, ARM_EXT_BARRIER),
19363 UL_BARRIER ("unst", "UNST", 0x6, ARM_EXT_BARRIER),
19364 UL_BARRIER ("nshst", "NSHST", 0x6, ARM_EXT_BARRIER),
19365 UL_BARRIER ("nshld", "NSHLD", 0x5, ARM_EXT_V8),
19366 UL_BARRIER ("osh", "OSH", 0x3, ARM_EXT_BARRIER),
19367 UL_BARRIER ("oshst", "OSHST", 0x2, ARM_EXT_BARRIER),
19368 UL_BARRIER ("oshld", "OSHLD", 0x1, ARM_EXT_V8)
19369 };
19370
19371 #undef UL_BARRIER
19372
19373 /* Table of ARM-format instructions. */
19374
19375 /* Macros for gluing together operand strings. N.B. In all cases
19376 other than OPS0, the trailing OP_stop comes from default
19377 zero-initialization of the unspecified elements of the array. */
19378 #define OPS0() { OP_stop, }
19379 #define OPS1(a) { OP_##a, }
19380 #define OPS2(a,b) { OP_##a,OP_##b, }
19381 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
19382 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
19383 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
19384 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
19385
19386 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
19387 This is useful when mixing operands for ARM and THUMB, i.e. using the
19388 MIX_ARM_THUMB_OPERANDS macro.
19389 In order to use these macros, prefix the number of operands with _
19390 e.g. _3. */
19391 #define OPS_1(a) { a, }
19392 #define OPS_2(a,b) { a,b, }
19393 #define OPS_3(a,b,c) { a,b,c, }
19394 #define OPS_4(a,b,c,d) { a,b,c,d, }
19395 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
19396 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
19397
19398 /* These macros abstract out the exact format of the mnemonic table and
19399 save some repeated characters. */
19400
19401 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
19402 #define TxCE(mnem, op, top, nops, ops, ae, te) \
19403 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
19404 THUMB_VARIANT, do_##ae, do_##te }
19405
19406 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
19407 a T_MNEM_xyz enumerator. */
19408 #define TCE(mnem, aop, top, nops, ops, ae, te) \
19409 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
19410 #define tCE(mnem, aop, top, nops, ops, ae, te) \
19411 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
19412
19413 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
19414 infix after the third character. */
19415 #define TxC3(mnem, op, top, nops, ops, ae, te) \
19416 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
19417 THUMB_VARIANT, do_##ae, do_##te }
19418 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
19419 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
19420 THUMB_VARIANT, do_##ae, do_##te }
19421 #define TC3(mnem, aop, top, nops, ops, ae, te) \
19422 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
19423 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
19424 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
19425 #define tC3(mnem, aop, top, nops, ops, ae, te) \
19426 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
19427 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
19428 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
19429
19430 /* Mnemonic that cannot be conditionalized. The ARM condition-code
19431 field is still 0xE. Many of the Thumb variants can be executed
19432 conditionally, so this is checked separately. */
19433 #define TUE(mnem, op, top, nops, ops, ae, te) \
19434 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19435 THUMB_VARIANT, do_##ae, do_##te }
19436
19437 /* Same as TUE but the encoding function for ARM and Thumb modes is the same.
19438 Used by mnemonics that have very minimal differences in the encoding for
19439 ARM and Thumb variants and can be handled in a common function. */
19440 #define TUEc(mnem, op, top, nops, ops, en) \
19441 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
19442 THUMB_VARIANT, do_##en, do_##en }
19443
19444 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
19445 condition code field. */
19446 #define TUF(mnem, op, top, nops, ops, ae, te) \
19447 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
19448 THUMB_VARIANT, do_##ae, do_##te }
19449
19450 /* ARM-only variants of all the above. */
19451 #define CE(mnem, op, nops, ops, ae) \
19452 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19453
19454 #define C3(mnem, op, nops, ops, ae) \
19455 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19456
19457 /* Thumb-only variants of TCE and TUE. */
19458 #define ToC(mnem, top, nops, ops, te) \
19459 { mnem, OPS##nops ops, OT_csuffix, 0x0, 0x##top, 0, THUMB_VARIANT, NULL, \
19460 do_##te }
19461
19462 #define ToU(mnem, top, nops, ops, te) \
19463 { mnem, OPS##nops ops, OT_unconditional, 0x0, 0x##top, 0, THUMB_VARIANT, \
19464 NULL, do_##te }
19465
19466 /* Legacy mnemonics that always have conditional infix after the third
19467 character. */
19468 #define CL(mnem, op, nops, ops, ae) \
19469 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
19470 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19471
19472 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
19473 #define cCE(mnem, op, nops, ops, ae) \
19474 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19475
19476 /* Legacy coprocessor instructions where conditional infix and conditional
19477 suffix are ambiguous. For consistency this includes all FPA instructions,
19478 not just the potentially ambiguous ones. */
19479 #define cCL(mnem, op, nops, ops, ae) \
19480 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
19481 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19482
19483 /* Coprocessor, takes either a suffix or a position-3 infix
19484 (for an FPA corner case). */
19485 #define C3E(mnem, op, nops, ops, ae) \
19486 { mnem, OPS##nops ops, OT_csuf_or_in3, \
19487 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
19488
19489 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
19490 { m1 #m2 m3, OPS##nops ops, \
19491 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
19492 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
19493
19494 #define CM(m1, m2, op, nops, ops, ae) \
19495 xCM_ (m1, , m2, op, nops, ops, ae), \
19496 xCM_ (m1, eq, m2, op, nops, ops, ae), \
19497 xCM_ (m1, ne, m2, op, nops, ops, ae), \
19498 xCM_ (m1, cs, m2, op, nops, ops, ae), \
19499 xCM_ (m1, hs, m2, op, nops, ops, ae), \
19500 xCM_ (m1, cc, m2, op, nops, ops, ae), \
19501 xCM_ (m1, ul, m2, op, nops, ops, ae), \
19502 xCM_ (m1, lo, m2, op, nops, ops, ae), \
19503 xCM_ (m1, mi, m2, op, nops, ops, ae), \
19504 xCM_ (m1, pl, m2, op, nops, ops, ae), \
19505 xCM_ (m1, vs, m2, op, nops, ops, ae), \
19506 xCM_ (m1, vc, m2, op, nops, ops, ae), \
19507 xCM_ (m1, hi, m2, op, nops, ops, ae), \
19508 xCM_ (m1, ls, m2, op, nops, ops, ae), \
19509 xCM_ (m1, ge, m2, op, nops, ops, ae), \
19510 xCM_ (m1, lt, m2, op, nops, ops, ae), \
19511 xCM_ (m1, gt, m2, op, nops, ops, ae), \
19512 xCM_ (m1, le, m2, op, nops, ops, ae), \
19513 xCM_ (m1, al, m2, op, nops, ops, ae)
19514
19515 #define UE(mnem, op, nops, ops, ae) \
19516 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19517
19518 #define UF(mnem, op, nops, ops, ae) \
19519 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
19520
19521 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
19522 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
19523 use the same encoding function for each. */
19524 #define NUF(mnem, op, nops, ops, enc) \
19525 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
19526 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19527
19528 /* Neon data processing, version which indirects through neon_enc_tab for
19529 the various overloaded versions of opcodes. */
19530 #define nUF(mnem, op, nops, ops, enc) \
19531 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
19532 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19533
19534 /* Neon insn with conditional suffix for the ARM version, non-overloaded
19535 version. */
19536 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
19537 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
19538 THUMB_VARIANT, do_##enc, do_##enc }
19539
19540 #define NCE(mnem, op, nops, ops, enc) \
19541 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
19542
19543 #define NCEF(mnem, op, nops, ops, enc) \
19544 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
19545
19546 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
19547 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
19548 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
19549 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
19550
19551 #define nCE(mnem, op, nops, ops, enc) \
19552 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
19553
19554 #define nCEF(mnem, op, nops, ops, enc) \
19555 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
19556
19557 #define do_0 0
19558
19559 static const struct asm_opcode insns[] =
19560 {
19561 #define ARM_VARIANT & arm_ext_v1 /* Core ARM Instructions. */
19562 #define THUMB_VARIANT & arm_ext_v4t
19563 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
19564 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
19565 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
19566 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
19567 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
19568 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
19569 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
19570 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
19571 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
19572 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
19573 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
19574 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
19575 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
19576 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
19577 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
19578 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
19579
19580 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
19581 for setting PSR flag bits. They are obsolete in V6 and do not
19582 have Thumb equivalents. */
19583 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19584 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
19585 CL("tstp", 110f000, 2, (RR, SH), cmp),
19586 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19587 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
19588 CL("cmpp", 150f000, 2, (RR, SH), cmp),
19589 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19590 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
19591 CL("cmnp", 170f000, 2, (RR, SH), cmp),
19592
19593 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
19594 tC3("movs", 1b00000, _movs, 2, (RR, SHG), mov, t_mov_cmp),
19595 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
19596 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
19597
19598 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
19599 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19600 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
19601 OP_RRnpc),
19602 OP_ADDRGLDR),ldst, t_ldst),
19603 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
19604
19605 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19606 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19607 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19608 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19609 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19610 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19611
19612 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
19613 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
19614
19615 /* Pseudo ops. */
19616 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
19617 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
19618 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
19619 tCE("udf", 7f000f0, _udf, 1, (oIffffb), bkpt, t_udf),
19620
19621 /* Thumb-compatibility pseudo ops. */
19622 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
19623 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
19624 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
19625 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
19626 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
19627 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
19628 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
19629 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
19630 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
19631 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
19632 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
19633 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
19634
19635 /* These may simplify to neg. */
19636 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
19637 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
19638
19639 #undef THUMB_VARIANT
19640 #define THUMB_VARIANT & arm_ext_os
19641
19642 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
19643 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
19644
19645 #undef THUMB_VARIANT
19646 #define THUMB_VARIANT & arm_ext_v6
19647
19648 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
19649
19650 /* V1 instructions with no Thumb analogue prior to V6T2. */
19651 #undef THUMB_VARIANT
19652 #define THUMB_VARIANT & arm_ext_v6t2
19653
19654 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19655 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
19656 CL("teqp", 130f000, 2, (RR, SH), cmp),
19657
19658 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19659 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19660 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
19661 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
19662
19663 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19664 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19665
19666 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19667 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
19668
19669 /* V1 instructions with no Thumb analogue at all. */
19670 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
19671 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
19672
19673 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
19674 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
19675 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
19676 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
19677 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
19678 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
19679 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
19680 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
19681
19682 #undef ARM_VARIANT
19683 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
19684 #undef THUMB_VARIANT
19685 #define THUMB_VARIANT & arm_ext_v4t
19686
19687 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19688 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
19689
19690 #undef THUMB_VARIANT
19691 #define THUMB_VARIANT & arm_ext_v6t2
19692
19693 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
19694 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
19695
19696 /* Generic coprocessor instructions. */
19697 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19698 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19699 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19700 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19701 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19702 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19703 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
19704
19705 #undef ARM_VARIANT
19706 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
19707
19708 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19709 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
19710
19711 #undef ARM_VARIANT
19712 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
19713 #undef THUMB_VARIANT
19714 #define THUMB_VARIANT & arm_ext_msr
19715
19716 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
19717 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
19718
19719 #undef ARM_VARIANT
19720 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
19721 #undef THUMB_VARIANT
19722 #define THUMB_VARIANT & arm_ext_v6t2
19723
19724 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19725 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19726 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19727 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19728 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19729 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19730 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
19731 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
19732
19733 #undef ARM_VARIANT
19734 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
19735 #undef THUMB_VARIANT
19736 #define THUMB_VARIANT & arm_ext_v4t
19737
19738 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19739 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19740 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19741 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19742 tC3("ldsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19743 tC3("ldsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
19744
19745 #undef ARM_VARIANT
19746 #define ARM_VARIANT & arm_ext_v4t_5
19747
19748 /* ARM Architecture 4T. */
19749 /* Note: bx (and blx) are required on V5, even if the processor does
19750 not support Thumb. */
19751 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
19752
19753 #undef ARM_VARIANT
19754 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
19755 #undef THUMB_VARIANT
19756 #define THUMB_VARIANT & arm_ext_v5t
19757
19758 /* Note: blx has 2 variants; the .value coded here is for
19759 BLX(2). Only this variant has conditional execution. */
19760 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
19761 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
19762
19763 #undef THUMB_VARIANT
19764 #define THUMB_VARIANT & arm_ext_v6t2
19765
19766 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
19767 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19768 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19769 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19770 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
19771 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
19772 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19773 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
19774
19775 #undef ARM_VARIANT
19776 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
19777 #undef THUMB_VARIANT
19778 #define THUMB_VARIANT & arm_ext_v5exp
19779
19780 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19781 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19782 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19783 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19784
19785 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19786 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
19787
19788 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19789 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19790 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19791 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
19792
19793 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19794 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19795 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19796 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19797
19798 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19799 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19800
19801 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19802 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19803 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19804 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
19805
19806 #undef ARM_VARIANT
19807 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
19808 #undef THUMB_VARIANT
19809 #define THUMB_VARIANT & arm_ext_v6t2
19810
19811 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
19812 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
19813 ldrd, t_ldstd),
19814 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
19815 ADDRGLDRS), ldrd, t_ldstd),
19816
19817 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19818 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19819
19820 #undef ARM_VARIANT
19821 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
19822
19823 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
19824
19825 #undef ARM_VARIANT
19826 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
19827 #undef THUMB_VARIANT
19828 #define THUMB_VARIANT & arm_ext_v6
19829
19830 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
19831 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
19832 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19833 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19834 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
19835 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19836 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19837 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19838 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19839 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
19840
19841 #undef THUMB_VARIANT
19842 #define THUMB_VARIANT & arm_ext_v6t2_v8m
19843
19844 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
19845 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
19846 strex, t_strex),
19847 #undef THUMB_VARIANT
19848 #define THUMB_VARIANT & arm_ext_v6t2
19849
19850 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19851 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
19852
19853 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
19854 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
19855
19856 /* ARM V6 not included in V7M. */
19857 #undef THUMB_VARIANT
19858 #define THUMB_VARIANT & arm_ext_v6_notm
19859 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
19860 TUF("rfe", 8900a00, e990c000, 1, (RRw), rfe, rfe),
19861 UF(rfeib, 9900a00, 1, (RRw), rfe),
19862 UF(rfeda, 8100a00, 1, (RRw), rfe),
19863 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19864 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
19865 UF(rfefa, 8100a00, 1, (RRw), rfe),
19866 TUF("rfeea", 9100a00, e810c000, 1, (RRw), rfe, rfe),
19867 UF(rfeed, 9900a00, 1, (RRw), rfe),
19868 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19869 TUF("srs", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19870 TUF("srsea", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
19871 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
19872 UF(srsfa, 9c00500, 2, (oRRw, I31w), srs),
19873 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
19874 UF(srsed, 8400500, 2, (oRRw, I31w), srs),
19875 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
19876 TUF("srsfd", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
19877 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
19878
19879 /* ARM V6 not included in V7M (eg. integer SIMD). */
19880 #undef THUMB_VARIANT
19881 #define THUMB_VARIANT & arm_ext_v6_dsp
19882 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
19883 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
19884 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19885 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19886 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19887 /* Old name for QASX. */
19888 TCE("qaddsubx",6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19889 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19890 /* Old name for QSAX. */
19891 TCE("qsubaddx",6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19892 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19893 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19894 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19895 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19896 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19897 /* Old name for SASX. */
19898 TCE("saddsubx",6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19899 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19900 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19901 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19902 /* Old name for SHASX. */
19903 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19904 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19905 /* Old name for SHSAX. */
19906 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19907 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19908 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19909 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19910 /* Old name for SSAX. */
19911 TCE("ssubaddx",6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19912 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19913 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19914 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19915 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19916 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19917 /* Old name for UASX. */
19918 TCE("uaddsubx",6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19919 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19920 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19921 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19922 /* Old name for UHASX. */
19923 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19924 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19925 /* Old name for UHSAX. */
19926 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19927 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19928 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19929 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19930 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19931 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19932 /* Old name for UQASX. */
19933 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19934 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19935 /* Old name for UQSAX. */
19936 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19937 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19938 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19939 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19940 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19941 /* Old name for USAX. */
19942 TCE("usubaddx",6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19943 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19944 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19945 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19946 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19947 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19948 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19949 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19950 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
19951 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
19952 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
19953 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19954 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19955 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19956 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19957 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19958 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19959 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19960 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
19961 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19962 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19963 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19964 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19965 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19966 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19967 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19968 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19969 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19970 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19971 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
19972 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
19973 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
19974 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
19975 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
19976
19977 #undef ARM_VARIANT
19978 #define ARM_VARIANT & arm_ext_v6k
19979 #undef THUMB_VARIANT
19980 #define THUMB_VARIANT & arm_ext_v6k
19981
19982 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
19983 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
19984 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
19985 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
19986
19987 #undef THUMB_VARIANT
19988 #define THUMB_VARIANT & arm_ext_v6_notm
19989 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
19990 ldrexd, t_ldrexd),
19991 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
19992 RRnpcb), strexd, t_strexd),
19993
19994 #undef THUMB_VARIANT
19995 #define THUMB_VARIANT & arm_ext_v6t2_v8m
19996 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
19997 rd_rn, rd_rn),
19998 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
19999 rd_rn, rd_rn),
20000 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
20001 strex, t_strexbh),
20002 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
20003 strex, t_strexbh),
20004 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
20005
20006 #undef ARM_VARIANT
20007 #define ARM_VARIANT & arm_ext_sec
20008 #undef THUMB_VARIANT
20009 #define THUMB_VARIANT & arm_ext_sec
20010
20011 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
20012
20013 #undef ARM_VARIANT
20014 #define ARM_VARIANT & arm_ext_virt
20015 #undef THUMB_VARIANT
20016 #define THUMB_VARIANT & arm_ext_virt
20017
20018 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
20019 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
20020
20021 #undef ARM_VARIANT
20022 #define ARM_VARIANT & arm_ext_pan
20023 #undef THUMB_VARIANT
20024 #define THUMB_VARIANT & arm_ext_pan
20025
20026 TUF("setpan", 1100000, b610, 1, (I7), setpan, t_setpan),
20027
20028 #undef ARM_VARIANT
20029 #define ARM_VARIANT & arm_ext_v6t2
20030 #undef THUMB_VARIANT
20031 #define THUMB_VARIANT & arm_ext_v6t2
20032
20033 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
20034 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
20035 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20036 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
20037
20038 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
20039 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
20040
20041 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20042 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20043 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20044 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
20045
20046 #undef ARM_VARIANT
20047 #define ARM_VARIANT & arm_ext_v3
20048 #undef THUMB_VARIANT
20049 #define THUMB_VARIANT & arm_ext_v6t2
20050
20051 TUE("csdb", 320f014, f3af8014, 0, (), noargs, t_csdb),
20052
20053 #undef ARM_VARIANT
20054 #define ARM_VARIANT & arm_ext_v6t2
20055 #undef THUMB_VARIANT
20056 #define THUMB_VARIANT & arm_ext_v6t2_v8m
20057 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
20058 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
20059
20060 /* Thumb-only instructions. */
20061 #undef ARM_VARIANT
20062 #define ARM_VARIANT NULL
20063 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
20064 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
20065
20066 /* ARM does not really have an IT instruction, so always allow it.
20067 The opcode is copied from Thumb in order to allow warnings in
20068 -mimplicit-it=[never | arm] modes. */
20069 #undef ARM_VARIANT
20070 #define ARM_VARIANT & arm_ext_v1
20071 #undef THUMB_VARIANT
20072 #define THUMB_VARIANT & arm_ext_v6t2
20073
20074 TUE("it", bf08, bf08, 1, (COND), it, t_it),
20075 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
20076 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
20077 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
20078 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
20079 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
20080 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
20081 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
20082 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
20083 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
20084 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
20085 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
20086 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
20087 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
20088 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
20089 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
20090 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
20091 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
20092
20093 /* Thumb2 only instructions. */
20094 #undef ARM_VARIANT
20095 #define ARM_VARIANT NULL
20096
20097 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20098 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
20099 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
20100 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
20101 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
20102 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
20103
20104 /* Hardware division instructions. */
20105 #undef ARM_VARIANT
20106 #define ARM_VARIANT & arm_ext_adiv
20107 #undef THUMB_VARIANT
20108 #define THUMB_VARIANT & arm_ext_div
20109
20110 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
20111 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
20112
20113 /* ARM V6M/V7 instructions. */
20114 #undef ARM_VARIANT
20115 #define ARM_VARIANT & arm_ext_barrier
20116 #undef THUMB_VARIANT
20117 #define THUMB_VARIANT & arm_ext_barrier
20118
20119 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, barrier),
20120 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, barrier),
20121 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, barrier),
20122
20123 /* ARM V7 instructions. */
20124 #undef ARM_VARIANT
20125 #define ARM_VARIANT & arm_ext_v7
20126 #undef THUMB_VARIANT
20127 #define THUMB_VARIANT & arm_ext_v7
20128
20129 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
20130 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
20131
20132 #undef ARM_VARIANT
20133 #define ARM_VARIANT & arm_ext_mp
20134 #undef THUMB_VARIANT
20135 #define THUMB_VARIANT & arm_ext_mp
20136
20137 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
20138
20139 /* AArchv8 instructions. */
20140 #undef ARM_VARIANT
20141 #define ARM_VARIANT & arm_ext_v8
20142
20143 /* Instructions shared between armv8-a and armv8-m. */
20144 #undef THUMB_VARIANT
20145 #define THUMB_VARIANT & arm_ext_atomics
20146
20147 TCE("lda", 1900c9f, e8d00faf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20148 TCE("ldab", 1d00c9f, e8d00f8f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20149 TCE("ldah", 1f00c9f, e8d00f9f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20150 TCE("stl", 180fc90, e8c00faf, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20151 TCE("stlb", 1c0fc90, e8c00f8f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20152 TCE("stlh", 1e0fc90, e8c00f9f, 2, (RRnpc, RRnpcb), rm_rn, rd_rn),
20153 TCE("ldaex", 1900e9f, e8d00fef, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20154 TCE("ldaexb", 1d00e9f, e8d00fcf, 2, (RRnpc,RRnpcb), rd_rn, rd_rn),
20155 TCE("ldaexh", 1f00e9f, e8d00fdf, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
20156 TCE("stlex", 1800e90, e8c00fe0, 3, (RRnpc, RRnpc, RRnpcb),
20157 stlex, t_stlex),
20158 TCE("stlexb", 1c00e90, e8c00fc0, 3, (RRnpc, RRnpc, RRnpcb),
20159 stlex, t_stlex),
20160 TCE("stlexh", 1e00e90, e8c00fd0, 3, (RRnpc, RRnpc, RRnpcb),
20161 stlex, t_stlex),
20162 #undef THUMB_VARIANT
20163 #define THUMB_VARIANT & arm_ext_v8
20164
20165 tCE("sevl", 320f005, _sevl, 0, (), noargs, t_hint),
20166 TUE("hlt", 1000070, ba80, 1, (oIffffb), bkpt, t_hlt),
20167 TCE("ldaexd", 1b00e9f, e8d000ff, 3, (RRnpc, oRRnpc, RRnpcb),
20168 ldrexd, t_ldrexd),
20169 TCE("stlexd", 1a00e90, e8c000f0, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb),
20170 strexd, t_strexd),
20171 /* ARMv8 T32 only. */
20172 #undef ARM_VARIANT
20173 #define ARM_VARIANT NULL
20174 TUF("dcps1", 0, f78f8001, 0, (), noargs, noargs),
20175 TUF("dcps2", 0, f78f8002, 0, (), noargs, noargs),
20176 TUF("dcps3", 0, f78f8003, 0, (), noargs, noargs),
20177
20178 /* FP for ARMv8. */
20179 #undef ARM_VARIANT
20180 #define ARM_VARIANT & fpu_vfp_ext_armv8xd
20181 #undef THUMB_VARIANT
20182 #define THUMB_VARIANT & fpu_vfp_ext_armv8xd
20183
20184 nUF(vseleq, _vseleq, 3, (RVSD, RVSD, RVSD), vsel),
20185 nUF(vselvs, _vselvs, 3, (RVSD, RVSD, RVSD), vsel),
20186 nUF(vselge, _vselge, 3, (RVSD, RVSD, RVSD), vsel),
20187 nUF(vselgt, _vselgt, 3, (RVSD, RVSD, RVSD), vsel),
20188 nUF(vmaxnm, _vmaxnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20189 nUF(vminnm, _vminnm, 3, (RNSDQ, oRNSDQ, RNSDQ), vmaxnm),
20190 nUF(vcvta, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvta),
20191 nUF(vcvtn, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtn),
20192 nUF(vcvtp, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtp),
20193 nUF(vcvtm, _vcvta, 2, (RNSDQ, oRNSDQ), neon_cvtm),
20194 nCE(vrintr, _vrintr, 2, (RNSDQ, oRNSDQ), vrintr),
20195 nCE(vrintz, _vrintr, 2, (RNSDQ, oRNSDQ), vrintz),
20196 nCE(vrintx, _vrintr, 2, (RNSDQ, oRNSDQ), vrintx),
20197 nUF(vrinta, _vrinta, 2, (RNSDQ, oRNSDQ), vrinta),
20198 nUF(vrintn, _vrinta, 2, (RNSDQ, oRNSDQ), vrintn),
20199 nUF(vrintp, _vrinta, 2, (RNSDQ, oRNSDQ), vrintp),
20200 nUF(vrintm, _vrinta, 2, (RNSDQ, oRNSDQ), vrintm),
20201
20202 /* Crypto v1 extensions. */
20203 #undef ARM_VARIANT
20204 #define ARM_VARIANT & fpu_crypto_ext_armv8
20205 #undef THUMB_VARIANT
20206 #define THUMB_VARIANT & fpu_crypto_ext_armv8
20207
20208 nUF(aese, _aes, 2, (RNQ, RNQ), aese),
20209 nUF(aesd, _aes, 2, (RNQ, RNQ), aesd),
20210 nUF(aesmc, _aes, 2, (RNQ, RNQ), aesmc),
20211 nUF(aesimc, _aes, 2, (RNQ, RNQ), aesimc),
20212 nUF(sha1c, _sha3op, 3, (RNQ, RNQ, RNQ), sha1c),
20213 nUF(sha1p, _sha3op, 3, (RNQ, RNQ, RNQ), sha1p),
20214 nUF(sha1m, _sha3op, 3, (RNQ, RNQ, RNQ), sha1m),
20215 nUF(sha1su0, _sha3op, 3, (RNQ, RNQ, RNQ), sha1su0),
20216 nUF(sha256h, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h),
20217 nUF(sha256h2, _sha3op, 3, (RNQ, RNQ, RNQ), sha256h2),
20218 nUF(sha256su1, _sha3op, 3, (RNQ, RNQ, RNQ), sha256su1),
20219 nUF(sha1h, _sha1h, 2, (RNQ, RNQ), sha1h),
20220 nUF(sha1su1, _sha2op, 2, (RNQ, RNQ), sha1su1),
20221 nUF(sha256su0, _sha2op, 2, (RNQ, RNQ), sha256su0),
20222
20223 #undef ARM_VARIANT
20224 #define ARM_VARIANT & crc_ext_armv8
20225 #undef THUMB_VARIANT
20226 #define THUMB_VARIANT & crc_ext_armv8
20227 TUEc("crc32b", 1000040, fac0f080, 3, (RR, oRR, RR), crc32b),
20228 TUEc("crc32h", 1200040, fac0f090, 3, (RR, oRR, RR), crc32h),
20229 TUEc("crc32w", 1400040, fac0f0a0, 3, (RR, oRR, RR), crc32w),
20230 TUEc("crc32cb",1000240, fad0f080, 3, (RR, oRR, RR), crc32cb),
20231 TUEc("crc32ch",1200240, fad0f090, 3, (RR, oRR, RR), crc32ch),
20232 TUEc("crc32cw",1400240, fad0f0a0, 3, (RR, oRR, RR), crc32cw),
20233
20234 /* ARMv8.2 RAS extension. */
20235 #undef ARM_VARIANT
20236 #define ARM_VARIANT & arm_ext_ras
20237 #undef THUMB_VARIANT
20238 #define THUMB_VARIANT & arm_ext_ras
20239 TUE ("esb", 320f010, f3af8010, 0, (), noargs, noargs),
20240
20241 #undef ARM_VARIANT
20242 #define ARM_VARIANT & arm_ext_v8_3
20243 #undef THUMB_VARIANT
20244 #define THUMB_VARIANT & arm_ext_v8_3
20245 NCE (vjcvt, eb90bc0, 2, (RVS, RVD), vjcvt),
20246 NUF (vcmla, 0, 4, (RNDQ, RNDQ, RNDQ_RNSC, EXPi), vcmla),
20247 NUF (vcadd, 0, 4, (RNDQ, RNDQ, RNDQ, EXPi), vcadd),
20248
20249 #undef ARM_VARIANT
20250 #define ARM_VARIANT & fpu_neon_ext_dotprod
20251 #undef THUMB_VARIANT
20252 #define THUMB_VARIANT & fpu_neon_ext_dotprod
20253 NUF (vsdot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_s),
20254 NUF (vudot, d00, 3, (RNDQ, RNDQ, RNDQ_RNSC), neon_dotproduct_u),
20255
20256 #undef ARM_VARIANT
20257 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
20258 #undef THUMB_VARIANT
20259 #define THUMB_VARIANT NULL
20260
20261 cCE("wfs", e200110, 1, (RR), rd),
20262 cCE("rfs", e300110, 1, (RR), rd),
20263 cCE("wfc", e400110, 1, (RR), rd),
20264 cCE("rfc", e500110, 1, (RR), rd),
20265
20266 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
20267 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
20268 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
20269 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
20270
20271 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
20272 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
20273 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
20274 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
20275
20276 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
20277 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
20278 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
20279 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
20280 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
20281 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
20282 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
20283 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
20284 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
20285 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
20286 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
20287 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
20288
20289 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
20290 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
20291 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
20292 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
20293 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
20294 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
20295 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
20296 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
20297 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
20298 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
20299 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
20300 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
20301
20302 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
20303 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
20304 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
20305 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
20306 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
20307 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
20308 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
20309 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
20310 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
20311 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
20312 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
20313 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
20314
20315 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
20316 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
20317 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
20318 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
20319 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
20320 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
20321 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
20322 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
20323 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
20324 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
20325 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
20326 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
20327
20328 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
20329 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
20330 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
20331 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
20332 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
20333 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
20334 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
20335 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
20336 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
20337 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
20338 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
20339 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
20340
20341 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
20342 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
20343 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
20344 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
20345 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
20346 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
20347 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
20348 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
20349 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
20350 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
20351 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
20352 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
20353
20354 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
20355 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
20356 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
20357 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
20358 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
20359 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
20360 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
20361 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
20362 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
20363 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
20364 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
20365 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
20366
20367 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
20368 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
20369 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
20370 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
20371 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
20372 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
20373 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
20374 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
20375 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
20376 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
20377 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
20378 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
20379
20380 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
20381 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
20382 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
20383 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
20384 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
20385 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
20386 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
20387 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
20388 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
20389 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
20390 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
20391 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
20392
20393 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
20394 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
20395 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
20396 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
20397 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
20398 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
20399 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
20400 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
20401 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
20402 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
20403 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
20404 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
20405
20406 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
20407 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
20408 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
20409 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
20410 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
20411 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
20412 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
20413 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
20414 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
20415 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
20416 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
20417 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
20418
20419 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
20420 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
20421 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
20422 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
20423 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
20424 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
20425 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
20426 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
20427 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
20428 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
20429 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
20430 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
20431
20432 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
20433 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
20434 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
20435 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
20436 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
20437 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
20438 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
20439 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
20440 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
20441 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
20442 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
20443 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
20444
20445 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
20446 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
20447 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
20448 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
20449 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
20450 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
20451 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
20452 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
20453 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
20454 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
20455 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
20456 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
20457
20458 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
20459 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
20460 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
20461 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
20462 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
20463 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
20464 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
20465 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
20466 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
20467 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
20468 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
20469 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
20470
20471 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
20472 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
20473 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
20474 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
20475 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
20476 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
20477 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
20478 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
20479 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
20480 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
20481 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
20482 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
20483
20484 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
20485 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
20486 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
20487 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
20488 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
20489 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20490 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20491 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20492 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
20493 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
20494 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
20495 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
20496
20497 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
20498 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
20499 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
20500 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
20501 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
20502 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20503 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20504 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20505 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
20506 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
20507 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
20508 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
20509
20510 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
20511 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
20512 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
20513 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
20514 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
20515 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20516 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20517 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20518 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
20519 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
20520 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
20521 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
20522
20523 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
20524 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
20525 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
20526 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
20527 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
20528 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20529 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20530 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20531 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
20532 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
20533 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
20534 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
20535
20536 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
20537 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
20538 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
20539 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
20540 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
20541 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20542 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20543 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20544 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
20545 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
20546 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
20547 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
20548
20549 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
20550 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
20551 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
20552 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
20553 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
20554 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20555 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20556 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20557 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
20558 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
20559 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
20560 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
20561
20562 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
20563 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
20564 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
20565 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
20566 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
20567 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20568 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20569 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20570 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
20571 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
20572 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
20573 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
20574
20575 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
20576 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
20577 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
20578 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
20579 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
20580 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20581 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20582 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20583 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
20584 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
20585 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
20586 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
20587
20588 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
20589 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
20590 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
20591 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
20592 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
20593 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20594 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20595 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20596 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
20597 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
20598 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
20599 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
20600
20601 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
20602 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
20603 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
20604 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
20605 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
20606 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20607 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20608 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20609 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
20610 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
20611 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
20612 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
20613
20614 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20615 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20616 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20617 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20618 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20619 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20620 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20621 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20622 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20623 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20624 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20625 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20626
20627 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20628 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20629 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20630 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20631 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20632 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20633 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20634 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20635 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20636 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20637 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20638 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20639
20640 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
20641 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
20642 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
20643 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
20644 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
20645 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
20646 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
20647 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
20648 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
20649 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
20650 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
20651 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
20652
20653 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
20654 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
20655 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
20656 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
20657
20658 cCL("flts", e000110, 2, (RF, RR), rn_rd),
20659 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
20660 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
20661 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
20662 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
20663 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
20664 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
20665 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
20666 cCL("flte", e080110, 2, (RF, RR), rn_rd),
20667 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
20668 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
20669 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
20670
20671 /* The implementation of the FIX instruction is broken on some
20672 assemblers, in that it accepts a precision specifier as well as a
20673 rounding specifier, despite the fact that this is meaningless.
20674 To be more compatible, we accept it as well, though of course it
20675 does not set any bits. */
20676 cCE("fix", e100110, 2, (RR, RF), rd_rm),
20677 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
20678 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
20679 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
20680 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
20681 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
20682 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
20683 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
20684 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
20685 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
20686 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
20687 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
20688 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
20689
20690 /* Instructions that were new with the real FPA, call them V2. */
20691 #undef ARM_VARIANT
20692 #define ARM_VARIANT & fpu_fpa_ext_v2
20693
20694 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20695 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20696 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20697 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20698 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20699 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
20700
20701 #undef ARM_VARIANT
20702 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
20703
20704 /* Moves and type conversions. */
20705 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
20706 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
20707 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
20708 cCE("fmstat", ef1fa10, 0, (), noargs),
20709 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
20710 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
20711 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
20712 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
20713 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
20714 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20715 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
20716 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
20717 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
20718 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
20719
20720 /* Memory operations. */
20721 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20722 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
20723 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20724 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20725 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20726 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20727 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20728 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20729 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20730 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20731 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20732 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
20733 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20734 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
20735 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20736 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
20737 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20738 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
20739
20740 /* Monadic operations. */
20741 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
20742 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
20743 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
20744
20745 /* Dyadic operations. */
20746 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20747 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20748 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20749 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20750 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20751 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20752 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20753 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20754 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
20755
20756 /* Comparisons. */
20757 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
20758 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
20759 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
20760 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
20761
20762 /* Double precision load/store are still present on single precision
20763 implementations. */
20764 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20765 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
20766 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20767 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20768 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20769 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20770 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20771 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
20772 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20773 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
20774
20775 #undef ARM_VARIANT
20776 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
20777
20778 /* Moves and type conversions. */
20779 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20780 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20781 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20782 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
20783 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
20784 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
20785 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
20786 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
20787 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
20788 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20789 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20790 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
20791 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
20792
20793 /* Monadic operations. */
20794 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20795 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20796 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20797
20798 /* Dyadic operations. */
20799 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20800 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20801 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20802 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20803 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20804 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20805 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20806 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20807 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
20808
20809 /* Comparisons. */
20810 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
20811 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
20812 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
20813 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
20814
20815 #undef ARM_VARIANT
20816 #define ARM_VARIANT & fpu_vfp_ext_v2
20817
20818 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
20819 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
20820 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
20821 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
20822
20823 /* Instructions which may belong to either the Neon or VFP instruction sets.
20824 Individual encoder functions perform additional architecture checks. */
20825 #undef ARM_VARIANT
20826 #define ARM_VARIANT & fpu_vfp_ext_v1xd
20827 #undef THUMB_VARIANT
20828 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
20829
20830 /* These mnemonics are unique to VFP. */
20831 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
20832 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
20833 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20834 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20835 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
20836 nCE(vcmp, _vcmp, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20837 nCE(vcmpe, _vcmpe, 2, (RVSD, RSVD_FI0), vfp_nsyn_cmp),
20838 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
20839 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
20840 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
20841
20842 /* Mnemonics shared by Neon and VFP. */
20843 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
20844 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20845 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
20846
20847 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20848 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
20849
20850 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20851 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
20852
20853 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20854 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20855 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20856 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20857 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20858 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
20859 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20860 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
20861
20862 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
20863 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
20864 NCEF(vcvtb, eb20a40, 2, (RVSD, RVSD), neon_cvtb),
20865 NCEF(vcvtt, eb20a40, 2, (RVSD, RVSD), neon_cvtt),
20866
20867
20868 /* NOTE: All VMOV encoding is special-cased! */
20869 NCE(vmov, 0, 1, (VMOV), neon_mov),
20870 NCE(vmovq, 0, 1, (VMOV), neon_mov),
20871
20872 #undef ARM_VARIANT
20873 #define ARM_VARIANT & arm_ext_fp16
20874 #undef THUMB_VARIANT
20875 #define THUMB_VARIANT & arm_ext_fp16
20876 /* New instructions added from v8.2, allowing the extraction and insertion of
20877 the upper 16 bits of a 32-bit vector register. */
20878 NCE (vmovx, eb00a40, 2, (RVS, RVS), neon_movhf),
20879 NCE (vins, eb00ac0, 2, (RVS, RVS), neon_movhf),
20880
20881 /* New backported fma/fms instructions optional in v8.2. */
20882 NCE (vfmal, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmal),
20883 NCE (vfmsl, 810, 3, (RNDQ, RNSD, RNSD_RNSC), neon_vfmsl),
20884
20885 #undef THUMB_VARIANT
20886 #define THUMB_VARIANT & fpu_neon_ext_v1
20887 #undef ARM_VARIANT
20888 #define ARM_VARIANT & fpu_neon_ext_v1
20889
20890 /* Data processing with three registers of the same length. */
20891 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
20892 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
20893 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
20894 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20895 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20896 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20897 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20898 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
20899 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
20900 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
20901 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20902 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20903 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
20904 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
20905 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20906 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20907 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
20908 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
20909 /* If not immediate, fall back to neon_dyadic_i64_su.
20910 shl_imm should accept I8 I16 I32 I64,
20911 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
20912 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
20913 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
20914 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
20915 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
20916 /* Logic ops, types optional & ignored. */
20917 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20918 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20919 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20920 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20921 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20922 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20923 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
20924 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
20925 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
20926 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
20927 /* Bitfield ops, untyped. */
20928 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20929 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20930 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20931 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20932 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
20933 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
20934 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F16 F32. */
20935 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20936 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20937 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20938 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20939 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
20940 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
20941 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
20942 back to neon_dyadic_if_su. */
20943 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20944 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20945 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
20946 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
20947 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20948 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20949 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
20950 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
20951 /* Comparison. Type I8 I16 I32 F32. */
20952 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
20953 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
20954 /* As above, D registers only. */
20955 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20956 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
20957 /* Int and float variants, signedness unimportant. */
20958 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20959 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
20960 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
20961 /* Add/sub take types I8 I16 I32 I64 F32. */
20962 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20963 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
20964 /* vtst takes sizes 8, 16, 32. */
20965 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
20966 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
20967 /* VMUL takes I8 I16 I32 F32 P8. */
20968 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
20969 /* VQD{R}MULH takes S16 S32. */
20970 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20971 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20972 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
20973 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
20974 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20975 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20976 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
20977 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
20978 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20979 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20980 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
20981 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
20982 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20983 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20984 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
20985 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
20986 /* ARM v8.1 extension. */
20987 nUF (vqrdmlah, _vqrdmlah, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20988 nUF (vqrdmlahq, _vqrdmlah, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20989 nUF (vqrdmlsh, _vqrdmlsh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qrdmlah),
20990 nUF (vqrdmlshq, _vqrdmlsh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qrdmlah),
20991
20992 /* Two address, int/float. Types S8 S16 S32 F32. */
20993 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
20994 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
20995
20996 /* Data processing with two registers and a shift amount. */
20997 /* Right shifts, and variants with rounding.
20998 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
20999 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21000 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21001 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
21002 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
21003 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21004 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21005 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
21006 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
21007 /* Shift and insert. Sizes accepted 8 16 32 64. */
21008 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
21009 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
21010 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
21011 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
21012 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
21013 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
21014 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
21015 /* Right shift immediate, saturating & narrowing, with rounding variants.
21016 Types accepted S16 S32 S64 U16 U32 U64. */
21017 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21018 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
21019 /* As above, unsigned. Types accepted S16 S32 S64. */
21020 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21021 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
21022 /* Right shift narrowing. Types accepted I16 I32 I64. */
21023 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21024 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
21025 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21026 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
21027 /* CVT with optional immediate for fixed-point variant. */
21028 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
21029
21030 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
21031 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
21032
21033 /* Data processing, three registers of different lengths. */
21034 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
21035 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
21036 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
21037 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
21038 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
21039 /* If not scalar, fall back to neon_dyadic_long.
21040 Vector types as above, scalar types S16 S32 U16 U32. */
21041 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21042 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
21043 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
21044 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21045 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
21046 /* Dyadic, narrowing insns. Types I16 I32 I64. */
21047 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21048 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21049 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21050 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
21051 /* Saturating doubling multiplies. Types S16 S32. */
21052 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21053 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21054 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
21055 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
21056 S16 S32 U16 U32. */
21057 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
21058
21059 /* Extract. Size 8. */
21060 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
21061 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
21062
21063 /* Two registers, miscellaneous. */
21064 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
21065 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
21066 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
21067 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
21068 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
21069 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
21070 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
21071 /* Vector replicate. Sizes 8 16 32. */
21072 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
21073 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
21074 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
21075 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
21076 /* VMOVN. Types I16 I32 I64. */
21077 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
21078 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21079 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
21080 /* VQMOVUN. Types S16 S32 S64. */
21081 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
21082 /* VZIP / VUZP. Sizes 8 16 32. */
21083 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
21084 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
21085 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
21086 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
21087 /* VQABS / VQNEG. Types S8 S16 S32. */
21088 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21089 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
21090 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
21091 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
21092 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
21093 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
21094 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
21095 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
21096 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
21097 /* Reciprocal estimates. Types U32 F16 F32. */
21098 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
21099 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
21100 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
21101 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
21102 /* VCLS. Types S8 S16 S32. */
21103 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
21104 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
21105 /* VCLZ. Types I8 I16 I32. */
21106 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
21107 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
21108 /* VCNT. Size 8. */
21109 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
21110 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
21111 /* Two address, untyped. */
21112 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
21113 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
21114 /* VTRN. Sizes 8 16 32. */
21115 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
21116 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
21117
21118 /* Table lookup. Size 8. */
21119 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21120 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
21121
21122 #undef THUMB_VARIANT
21123 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
21124 #undef ARM_VARIANT
21125 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
21126
21127 /* Neon element/structure load/store. */
21128 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21129 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
21130 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21131 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
21132 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21133 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
21134 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21135 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
21136
21137 #undef THUMB_VARIANT
21138 #define THUMB_VARIANT & fpu_vfp_ext_v3xd
21139 #undef ARM_VARIANT
21140 #define ARM_VARIANT & fpu_vfp_ext_v3xd
21141 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
21142 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21143 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21144 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21145 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21146 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21147 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21148 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
21149 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
21150
21151 #undef THUMB_VARIANT
21152 #define THUMB_VARIANT & fpu_vfp_ext_v3
21153 #undef ARM_VARIANT
21154 #define ARM_VARIANT & fpu_vfp_ext_v3
21155
21156 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21157 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21158 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21159 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21160 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21161 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21162 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21163 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21164 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21165
21166 #undef ARM_VARIANT
21167 #define ARM_VARIANT & fpu_vfp_ext_fma
21168 #undef THUMB_VARIANT
21169 #define THUMB_VARIANT & fpu_vfp_ext_fma
21170 /* Mnemonics shared by Neon and VFP. These are included in the
21171 VFP FMA variant; NEON and VFP FMA always includes the NEON
21172 FMA instructions. */
21173 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21174 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
21175 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
21176 the v form should always be used. */
21177 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21178 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
21179 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21180 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
21181 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21182 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
21183
21184 #undef THUMB_VARIANT
21185 #undef ARM_VARIANT
21186 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
21187
21188 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21189 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21190 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21191 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21192 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21193 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
21194 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
21195 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
21196
21197 #undef ARM_VARIANT
21198 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
21199
21200 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
21201 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
21202 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
21203 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
21204 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
21205 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
21206 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
21207 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
21208 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
21209 cCE("textrmub",e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21210 cCE("textrmuh",e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21211 cCE("textrmuw",e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
21212 cCE("textrmsb",e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21213 cCE("textrmsh",e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21214 cCE("textrmsw",e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
21215 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21216 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21217 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
21218 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
21219 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
21220 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21221 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21222 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21223 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21224 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21225 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
21226 cCE("tmovmskb",e100030, 2, (RR, RIWR), rd_rn),
21227 cCE("tmovmskh",e500030, 2, (RR, RIWR), rd_rn),
21228 cCE("tmovmskw",e900030, 2, (RR, RIWR), rd_rn),
21229 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
21230 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
21231 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
21232 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
21233 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
21234 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
21235 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
21236 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
21237 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21238 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21239 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21240 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21241 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21242 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21243 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21244 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21245 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21246 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
21247 cCE("walignr0",e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21248 cCE("walignr1",e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21249 cCE("walignr2",ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21250 cCE("walignr3",eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21251 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21252 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21253 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21254 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21255 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21256 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21257 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21258 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21259 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21260 cCE("wcmpgtub",e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21261 cCE("wcmpgtuh",e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21262 cCE("wcmpgtuw",e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21263 cCE("wcmpgtsb",e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21264 cCE("wcmpgtsh",e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21265 cCE("wcmpgtsw",eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21266 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21267 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21268 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21269 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21270 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21271 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21272 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21273 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21274 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21275 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21276 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21277 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21278 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21279 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21280 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21281 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21282 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21283 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21284 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21285 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21286 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21287 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21288 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
21289 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21290 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21291 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21292 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21293 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21294 cCE("wpackhss",e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21295 cCE("wpackhus",e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21296 cCE("wpackwss",eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21297 cCE("wpackwus",e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21298 cCE("wpackdss",ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21299 cCE("wpackdus",ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21300 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21301 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21302 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21303 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21304 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21305 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21306 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21307 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21308 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21309 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21310 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
21311 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21312 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21313 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21314 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21315 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21316 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21317 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21318 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21319 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21320 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21321 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21322 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21323 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21324 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21325 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21326 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21327 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
21328 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
21329 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21330 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
21331 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
21332 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
21333 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21334 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21335 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21336 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21337 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21338 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21339 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21340 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21341 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21342 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
21343 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
21344 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
21345 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
21346 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
21347 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
21348 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21349 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21350 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21351 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
21352 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
21353 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
21354 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
21355 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
21356 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
21357 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21358 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21359 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21360 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21361 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
21362
21363 #undef ARM_VARIANT
21364 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
21365
21366 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
21367 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
21368 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
21369 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
21370 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
21371 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
21372 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21373 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21374 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21375 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21376 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21377 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21378 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21379 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21380 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21381 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21382 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21383 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21384 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21385 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21386 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
21387 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21388 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21389 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21390 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21391 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21392 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21393 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21394 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21395 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21396 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21397 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21398 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21399 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21400 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21401 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21402 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21403 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21404 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21405 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21406 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21407 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21408 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21409 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21410 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21411 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21412 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21413 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21414 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21415 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21416 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21417 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21418 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21419 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21420 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21421 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21422 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
21423
21424 #undef ARM_VARIANT
21425 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
21426
21427 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21428 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21429 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21430 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21431 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
21432 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
21433 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
21434 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
21435 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
21436 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
21437 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
21438 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
21439 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
21440 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
21441 cCE("cfmv64lr",e000510, 2, (RMDX, RR), rn_rd),
21442 cCE("cfmvr64l",e100510, 2, (RR, RMDX), rd_rn),
21443 cCE("cfmv64hr",e000530, 2, (RMDX, RR), rn_rd),
21444 cCE("cfmvr64h",e100530, 2, (RR, RMDX), rd_rn),
21445 cCE("cfmval32",e200440, 2, (RMAX, RMFX), rd_rn),
21446 cCE("cfmv32al",e100440, 2, (RMFX, RMAX), rd_rn),
21447 cCE("cfmvam32",e200460, 2, (RMAX, RMFX), rd_rn),
21448 cCE("cfmv32am",e100460, 2, (RMFX, RMAX), rd_rn),
21449 cCE("cfmvah32",e200480, 2, (RMAX, RMFX), rd_rn),
21450 cCE("cfmv32ah",e100480, 2, (RMFX, RMAX), rd_rn),
21451 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
21452 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
21453 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
21454 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
21455 cCE("cfmvsc32",e2004e0, 2, (RMDS, RMDX), mav_dspsc),
21456 cCE("cfmv32sc",e1004e0, 2, (RMDX, RMDS), rd),
21457 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
21458 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
21459 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
21460 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
21461 cCE("cfcvt32s",e000480, 2, (RMF, RMFX), rd_rn),
21462 cCE("cfcvt32d",e0004a0, 2, (RMD, RMFX), rd_rn),
21463 cCE("cfcvt64s",e0004c0, 2, (RMF, RMDX), rd_rn),
21464 cCE("cfcvt64d",e0004e0, 2, (RMD, RMDX), rd_rn),
21465 cCE("cfcvts32",e100580, 2, (RMFX, RMF), rd_rn),
21466 cCE("cfcvtd32",e1005a0, 2, (RMFX, RMD), rd_rn),
21467 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
21468 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
21469 cCE("cfrshl32",e000550, 3, (RMFX, RMFX, RR), mav_triple),
21470 cCE("cfrshl64",e000570, 3, (RMDX, RMDX, RR), mav_triple),
21471 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
21472 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
21473 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
21474 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
21475 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
21476 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
21477 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
21478 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
21479 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
21480 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
21481 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
21482 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
21483 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
21484 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
21485 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
21486 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
21487 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
21488 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
21489 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
21490 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
21491 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21492 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21493 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21494 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21495 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21496 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
21497 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21498 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
21499 cCE("cfmadd32",e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21500 cCE("cfmsub32",e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
21501 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21502 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
21503
21504 /* ARMv8-M instructions. */
21505 #undef ARM_VARIANT
21506 #define ARM_VARIANT NULL
21507 #undef THUMB_VARIANT
21508 #define THUMB_VARIANT & arm_ext_v8m
21509 ToU("sg", e97fe97f, 0, (), noargs),
21510 ToC("blxns", 4784, 1, (RRnpc), t_blx),
21511 ToC("bxns", 4704, 1, (RRnpc), t_bx),
21512 ToC("tt", e840f000, 2, (RRnpc, RRnpc), tt),
21513 ToC("ttt", e840f040, 2, (RRnpc, RRnpc), tt),
21514 ToC("tta", e840f080, 2, (RRnpc, RRnpc), tt),
21515 ToC("ttat", e840f0c0, 2, (RRnpc, RRnpc), tt),
21516
21517 /* FP for ARMv8-M Mainline. Enabled for ARMv8-M Mainline because the
21518 instructions behave as nop if no VFP is present. */
21519 #undef THUMB_VARIANT
21520 #define THUMB_VARIANT & arm_ext_v8m_main
21521 ToC("vlldm", ec300a00, 1, (RRnpc), rn),
21522 ToC("vlstm", ec200a00, 1, (RRnpc), rn),
21523 };
21524 #undef ARM_VARIANT
21525 #undef THUMB_VARIANT
21526 #undef TCE
21527 #undef TUE
21528 #undef TUF
21529 #undef TCC
21530 #undef cCE
21531 #undef cCL
21532 #undef C3E
21533 #undef CE
21534 #undef CM
21535 #undef UE
21536 #undef UF
21537 #undef UT
21538 #undef NUF
21539 #undef nUF
21540 #undef NCE
21541 #undef nCE
21542 #undef OPS0
21543 #undef OPS1
21544 #undef OPS2
21545 #undef OPS3
21546 #undef OPS4
21547 #undef OPS5
21548 #undef OPS6
21549 #undef do_0
21550 \f
21551 /* MD interface: bits in the object file. */
21552
21553 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
21554 for use in the a.out file, and stores them in the array pointed to by buf.
21555 This knows about the endian-ness of the target machine and does
21556 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
21557 2 (short) and 4 (long) Floating numbers are put out as a series of
21558 LITTLENUMS (shorts, here at least). */
21559
21560 void
21561 md_number_to_chars (char * buf, valueT val, int n)
21562 {
21563 if (target_big_endian)
21564 number_to_chars_bigendian (buf, val, n);
21565 else
21566 number_to_chars_littleendian (buf, val, n);
21567 }
21568
21569 static valueT
21570 md_chars_to_number (char * buf, int n)
21571 {
21572 valueT result = 0;
21573 unsigned char * where = (unsigned char *) buf;
21574
21575 if (target_big_endian)
21576 {
21577 while (n--)
21578 {
21579 result <<= 8;
21580 result |= (*where++ & 255);
21581 }
21582 }
21583 else
21584 {
21585 while (n--)
21586 {
21587 result <<= 8;
21588 result |= (where[n] & 255);
21589 }
21590 }
21591
21592 return result;
21593 }
21594
21595 /* MD interface: Sections. */
21596
21597 /* Calculate the maximum variable size (i.e., excluding fr_fix)
21598 that an rs_machine_dependent frag may reach. */
21599
21600 unsigned int
21601 arm_frag_max_var (fragS *fragp)
21602 {
21603 /* We only use rs_machine_dependent for variable-size Thumb instructions,
21604 which are either THUMB_SIZE (2) or INSN_SIZE (4).
21605
21606 Note that we generate relaxable instructions even for cases that don't
21607 really need it, like an immediate that's a trivial constant. So we're
21608 overestimating the instruction size for some of those cases. Rather
21609 than putting more intelligence here, it would probably be better to
21610 avoid generating a relaxation frag in the first place when it can be
21611 determined up front that a short instruction will suffice. */
21612
21613 gas_assert (fragp->fr_type == rs_machine_dependent);
21614 return INSN_SIZE;
21615 }
21616
21617 /* Estimate the size of a frag before relaxing. Assume everything fits in
21618 2 bytes. */
21619
21620 int
21621 md_estimate_size_before_relax (fragS * fragp,
21622 segT segtype ATTRIBUTE_UNUSED)
21623 {
21624 fragp->fr_var = 2;
21625 return 2;
21626 }
21627
21628 /* Convert a machine dependent frag. */
21629
21630 void
21631 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
21632 {
21633 unsigned long insn;
21634 unsigned long old_op;
21635 char *buf;
21636 expressionS exp;
21637 fixS *fixp;
21638 int reloc_type;
21639 int pc_rel;
21640 int opcode;
21641
21642 buf = fragp->fr_literal + fragp->fr_fix;
21643
21644 old_op = bfd_get_16(abfd, buf);
21645 if (fragp->fr_symbol)
21646 {
21647 exp.X_op = O_symbol;
21648 exp.X_add_symbol = fragp->fr_symbol;
21649 }
21650 else
21651 {
21652 exp.X_op = O_constant;
21653 }
21654 exp.X_add_number = fragp->fr_offset;
21655 opcode = fragp->fr_subtype;
21656 switch (opcode)
21657 {
21658 case T_MNEM_ldr_pc:
21659 case T_MNEM_ldr_pc2:
21660 case T_MNEM_ldr_sp:
21661 case T_MNEM_str_sp:
21662 case T_MNEM_ldr:
21663 case T_MNEM_ldrb:
21664 case T_MNEM_ldrh:
21665 case T_MNEM_str:
21666 case T_MNEM_strb:
21667 case T_MNEM_strh:
21668 if (fragp->fr_var == 4)
21669 {
21670 insn = THUMB_OP32 (opcode);
21671 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
21672 {
21673 insn |= (old_op & 0x700) << 4;
21674 }
21675 else
21676 {
21677 insn |= (old_op & 7) << 12;
21678 insn |= (old_op & 0x38) << 13;
21679 }
21680 insn |= 0x00000c00;
21681 put_thumb32_insn (buf, insn);
21682 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
21683 }
21684 else
21685 {
21686 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
21687 }
21688 pc_rel = (opcode == T_MNEM_ldr_pc2);
21689 break;
21690 case T_MNEM_adr:
21691 if (fragp->fr_var == 4)
21692 {
21693 insn = THUMB_OP32 (opcode);
21694 insn |= (old_op & 0xf0) << 4;
21695 put_thumb32_insn (buf, insn);
21696 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
21697 }
21698 else
21699 {
21700 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21701 exp.X_add_number -= 4;
21702 }
21703 pc_rel = 1;
21704 break;
21705 case T_MNEM_mov:
21706 case T_MNEM_movs:
21707 case T_MNEM_cmp:
21708 case T_MNEM_cmn:
21709 if (fragp->fr_var == 4)
21710 {
21711 int r0off = (opcode == T_MNEM_mov
21712 || opcode == T_MNEM_movs) ? 0 : 8;
21713 insn = THUMB_OP32 (opcode);
21714 insn = (insn & 0xe1ffffff) | 0x10000000;
21715 insn |= (old_op & 0x700) << r0off;
21716 put_thumb32_insn (buf, insn);
21717 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21718 }
21719 else
21720 {
21721 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
21722 }
21723 pc_rel = 0;
21724 break;
21725 case T_MNEM_b:
21726 if (fragp->fr_var == 4)
21727 {
21728 insn = THUMB_OP32(opcode);
21729 put_thumb32_insn (buf, insn);
21730 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
21731 }
21732 else
21733 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
21734 pc_rel = 1;
21735 break;
21736 case T_MNEM_bcond:
21737 if (fragp->fr_var == 4)
21738 {
21739 insn = THUMB_OP32(opcode);
21740 insn |= (old_op & 0xf00) << 14;
21741 put_thumb32_insn (buf, insn);
21742 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
21743 }
21744 else
21745 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
21746 pc_rel = 1;
21747 break;
21748 case T_MNEM_add_sp:
21749 case T_MNEM_add_pc:
21750 case T_MNEM_inc_sp:
21751 case T_MNEM_dec_sp:
21752 if (fragp->fr_var == 4)
21753 {
21754 /* ??? Choose between add and addw. */
21755 insn = THUMB_OP32 (opcode);
21756 insn |= (old_op & 0xf0) << 4;
21757 put_thumb32_insn (buf, insn);
21758 if (opcode == T_MNEM_add_pc)
21759 reloc_type = BFD_RELOC_ARM_T32_IMM12;
21760 else
21761 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21762 }
21763 else
21764 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21765 pc_rel = 0;
21766 break;
21767
21768 case T_MNEM_addi:
21769 case T_MNEM_addis:
21770 case T_MNEM_subi:
21771 case T_MNEM_subis:
21772 if (fragp->fr_var == 4)
21773 {
21774 insn = THUMB_OP32 (opcode);
21775 insn |= (old_op & 0xf0) << 4;
21776 insn |= (old_op & 0xf) << 16;
21777 put_thumb32_insn (buf, insn);
21778 if (insn & (1 << 20))
21779 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
21780 else
21781 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
21782 }
21783 else
21784 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
21785 pc_rel = 0;
21786 break;
21787 default:
21788 abort ();
21789 }
21790 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21791 (enum bfd_reloc_code_real) reloc_type);
21792 fixp->fx_file = fragp->fr_file;
21793 fixp->fx_line = fragp->fr_line;
21794 fragp->fr_fix += fragp->fr_var;
21795
21796 /* Set whether we use thumb-2 ISA based on final relaxation results. */
21797 if (thumb_mode && fragp->fr_var == 4 && no_cpu_selected ()
21798 && !ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2))
21799 ARM_MERGE_FEATURE_SETS (arm_arch_used, thumb_arch_used, arm_ext_v6t2);
21800 }
21801
21802 /* Return the size of a relaxable immediate operand instruction.
21803 SHIFT and SIZE specify the form of the allowable immediate. */
21804 static int
21805 relax_immediate (fragS *fragp, int size, int shift)
21806 {
21807 offsetT offset;
21808 offsetT mask;
21809 offsetT low;
21810
21811 /* ??? Should be able to do better than this. */
21812 if (fragp->fr_symbol)
21813 return 4;
21814
21815 low = (1 << shift) - 1;
21816 mask = (1 << (shift + size)) - (1 << shift);
21817 offset = fragp->fr_offset;
21818 /* Force misaligned offsets to 32-bit variant. */
21819 if (offset & low)
21820 return 4;
21821 if (offset & ~mask)
21822 return 4;
21823 return 2;
21824 }
21825
21826 /* Get the address of a symbol during relaxation. */
21827 static addressT
21828 relaxed_symbol_addr (fragS *fragp, long stretch)
21829 {
21830 fragS *sym_frag;
21831 addressT addr;
21832 symbolS *sym;
21833
21834 sym = fragp->fr_symbol;
21835 sym_frag = symbol_get_frag (sym);
21836 know (S_GET_SEGMENT (sym) != absolute_section
21837 || sym_frag == &zero_address_frag);
21838 addr = S_GET_VALUE (sym) + fragp->fr_offset;
21839
21840 /* If frag has yet to be reached on this pass, assume it will
21841 move by STRETCH just as we did. If this is not so, it will
21842 be because some frag between grows, and that will force
21843 another pass. */
21844
21845 if (stretch != 0
21846 && sym_frag->relax_marker != fragp->relax_marker)
21847 {
21848 fragS *f;
21849
21850 /* Adjust stretch for any alignment frag. Note that if have
21851 been expanding the earlier code, the symbol may be
21852 defined in what appears to be an earlier frag. FIXME:
21853 This doesn't handle the fr_subtype field, which specifies
21854 a maximum number of bytes to skip when doing an
21855 alignment. */
21856 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
21857 {
21858 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
21859 {
21860 if (stretch < 0)
21861 stretch = - ((- stretch)
21862 & ~ ((1 << (int) f->fr_offset) - 1));
21863 else
21864 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
21865 if (stretch == 0)
21866 break;
21867 }
21868 }
21869 if (f != NULL)
21870 addr += stretch;
21871 }
21872
21873 return addr;
21874 }
21875
21876 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
21877 load. */
21878 static int
21879 relax_adr (fragS *fragp, asection *sec, long stretch)
21880 {
21881 addressT addr;
21882 offsetT val;
21883
21884 /* Assume worst case for symbols not known to be in the same section. */
21885 if (fragp->fr_symbol == NULL
21886 || !S_IS_DEFINED (fragp->fr_symbol)
21887 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21888 || S_IS_WEAK (fragp->fr_symbol))
21889 return 4;
21890
21891 val = relaxed_symbol_addr (fragp, stretch);
21892 addr = fragp->fr_address + fragp->fr_fix;
21893 addr = (addr + 4) & ~3;
21894 /* Force misaligned targets to 32-bit variant. */
21895 if (val & 3)
21896 return 4;
21897 val -= addr;
21898 if (val < 0 || val > 1020)
21899 return 4;
21900 return 2;
21901 }
21902
21903 /* Return the size of a relaxable add/sub immediate instruction. */
21904 static int
21905 relax_addsub (fragS *fragp, asection *sec)
21906 {
21907 char *buf;
21908 int op;
21909
21910 buf = fragp->fr_literal + fragp->fr_fix;
21911 op = bfd_get_16(sec->owner, buf);
21912 if ((op & 0xf) == ((op >> 4) & 0xf))
21913 return relax_immediate (fragp, 8, 0);
21914 else
21915 return relax_immediate (fragp, 3, 0);
21916 }
21917
21918 /* Return TRUE iff the definition of symbol S could be pre-empted
21919 (overridden) at link or load time. */
21920 static bfd_boolean
21921 symbol_preemptible (symbolS *s)
21922 {
21923 /* Weak symbols can always be pre-empted. */
21924 if (S_IS_WEAK (s))
21925 return TRUE;
21926
21927 /* Non-global symbols cannot be pre-empted. */
21928 if (! S_IS_EXTERNAL (s))
21929 return FALSE;
21930
21931 #ifdef OBJ_ELF
21932 /* In ELF, a global symbol can be marked protected, or private. In that
21933 case it can't be pre-empted (other definitions in the same link unit
21934 would violate the ODR). */
21935 if (ELF_ST_VISIBILITY (S_GET_OTHER (s)) > STV_DEFAULT)
21936 return FALSE;
21937 #endif
21938
21939 /* Other global symbols might be pre-empted. */
21940 return TRUE;
21941 }
21942
21943 /* Return the size of a relaxable branch instruction. BITS is the
21944 size of the offset field in the narrow instruction. */
21945
21946 static int
21947 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
21948 {
21949 addressT addr;
21950 offsetT val;
21951 offsetT limit;
21952
21953 /* Assume worst case for symbols not known to be in the same section. */
21954 if (!S_IS_DEFINED (fragp->fr_symbol)
21955 || sec != S_GET_SEGMENT (fragp->fr_symbol)
21956 || S_IS_WEAK (fragp->fr_symbol))
21957 return 4;
21958
21959 #ifdef OBJ_ELF
21960 /* A branch to a function in ARM state will require interworking. */
21961 if (S_IS_DEFINED (fragp->fr_symbol)
21962 && ARM_IS_FUNC (fragp->fr_symbol))
21963 return 4;
21964 #endif
21965
21966 if (symbol_preemptible (fragp->fr_symbol))
21967 return 4;
21968
21969 val = relaxed_symbol_addr (fragp, stretch);
21970 addr = fragp->fr_address + fragp->fr_fix + 4;
21971 val -= addr;
21972
21973 /* Offset is a signed value *2 */
21974 limit = 1 << bits;
21975 if (val >= limit || val < -limit)
21976 return 4;
21977 return 2;
21978 }
21979
21980
21981 /* Relax a machine dependent frag. This returns the amount by which
21982 the current size of the frag should change. */
21983
21984 int
21985 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
21986 {
21987 int oldsize;
21988 int newsize;
21989
21990 oldsize = fragp->fr_var;
21991 switch (fragp->fr_subtype)
21992 {
21993 case T_MNEM_ldr_pc2:
21994 newsize = relax_adr (fragp, sec, stretch);
21995 break;
21996 case T_MNEM_ldr_pc:
21997 case T_MNEM_ldr_sp:
21998 case T_MNEM_str_sp:
21999 newsize = relax_immediate (fragp, 8, 2);
22000 break;
22001 case T_MNEM_ldr:
22002 case T_MNEM_str:
22003 newsize = relax_immediate (fragp, 5, 2);
22004 break;
22005 case T_MNEM_ldrh:
22006 case T_MNEM_strh:
22007 newsize = relax_immediate (fragp, 5, 1);
22008 break;
22009 case T_MNEM_ldrb:
22010 case T_MNEM_strb:
22011 newsize = relax_immediate (fragp, 5, 0);
22012 break;
22013 case T_MNEM_adr:
22014 newsize = relax_adr (fragp, sec, stretch);
22015 break;
22016 case T_MNEM_mov:
22017 case T_MNEM_movs:
22018 case T_MNEM_cmp:
22019 case T_MNEM_cmn:
22020 newsize = relax_immediate (fragp, 8, 0);
22021 break;
22022 case T_MNEM_b:
22023 newsize = relax_branch (fragp, sec, 11, stretch);
22024 break;
22025 case T_MNEM_bcond:
22026 newsize = relax_branch (fragp, sec, 8, stretch);
22027 break;
22028 case T_MNEM_add_sp:
22029 case T_MNEM_add_pc:
22030 newsize = relax_immediate (fragp, 8, 2);
22031 break;
22032 case T_MNEM_inc_sp:
22033 case T_MNEM_dec_sp:
22034 newsize = relax_immediate (fragp, 7, 2);
22035 break;
22036 case T_MNEM_addi:
22037 case T_MNEM_addis:
22038 case T_MNEM_subi:
22039 case T_MNEM_subis:
22040 newsize = relax_addsub (fragp, sec);
22041 break;
22042 default:
22043 abort ();
22044 }
22045
22046 fragp->fr_var = newsize;
22047 /* Freeze wide instructions that are at or before the same location as
22048 in the previous pass. This avoids infinite loops.
22049 Don't freeze them unconditionally because targets may be artificially
22050 misaligned by the expansion of preceding frags. */
22051 if (stretch <= 0 && newsize > 2)
22052 {
22053 md_convert_frag (sec->owner, sec, fragp);
22054 frag_wane (fragp);
22055 }
22056
22057 return newsize - oldsize;
22058 }
22059
22060 /* Round up a section size to the appropriate boundary. */
22061
22062 valueT
22063 md_section_align (segT segment ATTRIBUTE_UNUSED,
22064 valueT size)
22065 {
22066 return size;
22067 }
22068
22069 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
22070 of an rs_align_code fragment. */
22071
22072 void
22073 arm_handle_align (fragS * fragP)
22074 {
22075 static unsigned char const arm_noop[2][2][4] =
22076 {
22077 { /* ARMv1 */
22078 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
22079 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
22080 },
22081 { /* ARMv6k */
22082 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
22083 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
22084 },
22085 };
22086 static unsigned char const thumb_noop[2][2][2] =
22087 {
22088 { /* Thumb-1 */
22089 {0xc0, 0x46}, /* LE */
22090 {0x46, 0xc0}, /* BE */
22091 },
22092 { /* Thumb-2 */
22093 {0x00, 0xbf}, /* LE */
22094 {0xbf, 0x00} /* BE */
22095 }
22096 };
22097 static unsigned char const wide_thumb_noop[2][4] =
22098 { /* Wide Thumb-2 */
22099 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
22100 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
22101 };
22102
22103 unsigned bytes, fix, noop_size;
22104 char * p;
22105 const unsigned char * noop;
22106 const unsigned char *narrow_noop = NULL;
22107 #ifdef OBJ_ELF
22108 enum mstate state;
22109 #endif
22110
22111 if (fragP->fr_type != rs_align_code)
22112 return;
22113
22114 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
22115 p = fragP->fr_literal + fragP->fr_fix;
22116 fix = 0;
22117
22118 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
22119 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
22120
22121 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
22122
22123 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
22124 {
22125 if (ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22126 ? selected_cpu : arm_arch_none, arm_ext_v6t2))
22127 {
22128 narrow_noop = thumb_noop[1][target_big_endian];
22129 noop = wide_thumb_noop[target_big_endian];
22130 }
22131 else
22132 noop = thumb_noop[0][target_big_endian];
22133 noop_size = 2;
22134 #ifdef OBJ_ELF
22135 state = MAP_THUMB;
22136 #endif
22137 }
22138 else
22139 {
22140 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu_name[0]
22141 ? selected_cpu : arm_arch_none,
22142 arm_ext_v6k) != 0]
22143 [target_big_endian];
22144 noop_size = 4;
22145 #ifdef OBJ_ELF
22146 state = MAP_ARM;
22147 #endif
22148 }
22149
22150 fragP->fr_var = noop_size;
22151
22152 if (bytes & (noop_size - 1))
22153 {
22154 fix = bytes & (noop_size - 1);
22155 #ifdef OBJ_ELF
22156 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
22157 #endif
22158 memset (p, 0, fix);
22159 p += fix;
22160 bytes -= fix;
22161 }
22162
22163 if (narrow_noop)
22164 {
22165 if (bytes & noop_size)
22166 {
22167 /* Insert a narrow noop. */
22168 memcpy (p, narrow_noop, noop_size);
22169 p += noop_size;
22170 bytes -= noop_size;
22171 fix += noop_size;
22172 }
22173
22174 /* Use wide noops for the remainder */
22175 noop_size = 4;
22176 }
22177
22178 while (bytes >= noop_size)
22179 {
22180 memcpy (p, noop, noop_size);
22181 p += noop_size;
22182 bytes -= noop_size;
22183 fix += noop_size;
22184 }
22185
22186 fragP->fr_fix += fix;
22187 }
22188
22189 /* Called from md_do_align. Used to create an alignment
22190 frag in a code section. */
22191
22192 void
22193 arm_frag_align_code (int n, int max)
22194 {
22195 char * p;
22196
22197 /* We assume that there will never be a requirement
22198 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
22199 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
22200 {
22201 char err_msg[128];
22202
22203 sprintf (err_msg,
22204 _("alignments greater than %d bytes not supported in .text sections."),
22205 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
22206 as_fatal ("%s", err_msg);
22207 }
22208
22209 p = frag_var (rs_align_code,
22210 MAX_MEM_FOR_RS_ALIGN_CODE,
22211 1,
22212 (relax_substateT) max,
22213 (symbolS *) NULL,
22214 (offsetT) n,
22215 (char *) NULL);
22216 *p = 0;
22217 }
22218
22219 /* Perform target specific initialisation of a frag.
22220 Note - despite the name this initialisation is not done when the frag
22221 is created, but only when its type is assigned. A frag can be created
22222 and used a long time before its type is set, so beware of assuming that
22223 this initialisation is performed first. */
22224
22225 #ifndef OBJ_ELF
22226 void
22227 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
22228 {
22229 /* Record whether this frag is in an ARM or a THUMB area. */
22230 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22231 }
22232
22233 #else /* OBJ_ELF is defined. */
22234 void
22235 arm_init_frag (fragS * fragP, int max_chars)
22236 {
22237 bfd_boolean frag_thumb_mode;
22238
22239 /* If the current ARM vs THUMB mode has not already
22240 been recorded into this frag then do so now. */
22241 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
22242 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
22243
22244 /* PR 21809: Do not set a mapping state for debug sections
22245 - it just confuses other tools. */
22246 if (bfd_get_section_flags (NULL, now_seg) & SEC_DEBUGGING)
22247 return;
22248
22249 frag_thumb_mode = fragP->tc_frag_data.thumb_mode ^ MODE_RECORDED;
22250
22251 /* Record a mapping symbol for alignment frags. We will delete this
22252 later if the alignment ends up empty. */
22253 switch (fragP->fr_type)
22254 {
22255 case rs_align:
22256 case rs_align_test:
22257 case rs_fill:
22258 mapping_state_2 (MAP_DATA, max_chars);
22259 break;
22260 case rs_align_code:
22261 mapping_state_2 (frag_thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
22262 break;
22263 default:
22264 break;
22265 }
22266 }
22267
22268 /* When we change sections we need to issue a new mapping symbol. */
22269
22270 void
22271 arm_elf_change_section (void)
22272 {
22273 /* Link an unlinked unwind index table section to the .text section. */
22274 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
22275 && elf_linked_to_section (now_seg) == NULL)
22276 elf_linked_to_section (now_seg) = text_section;
22277 }
22278
22279 int
22280 arm_elf_section_type (const char * str, size_t len)
22281 {
22282 if (len == 5 && strncmp (str, "exidx", 5) == 0)
22283 return SHT_ARM_EXIDX;
22284
22285 return -1;
22286 }
22287 \f
22288 /* Code to deal with unwinding tables. */
22289
22290 static void add_unwind_adjustsp (offsetT);
22291
22292 /* Generate any deferred unwind frame offset. */
22293
22294 static void
22295 flush_pending_unwind (void)
22296 {
22297 offsetT offset;
22298
22299 offset = unwind.pending_offset;
22300 unwind.pending_offset = 0;
22301 if (offset != 0)
22302 add_unwind_adjustsp (offset);
22303 }
22304
22305 /* Add an opcode to this list for this function. Two-byte opcodes should
22306 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
22307 order. */
22308
22309 static void
22310 add_unwind_opcode (valueT op, int length)
22311 {
22312 /* Add any deferred stack adjustment. */
22313 if (unwind.pending_offset)
22314 flush_pending_unwind ();
22315
22316 unwind.sp_restored = 0;
22317
22318 if (unwind.opcode_count + length > unwind.opcode_alloc)
22319 {
22320 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
22321 if (unwind.opcodes)
22322 unwind.opcodes = XRESIZEVEC (unsigned char, unwind.opcodes,
22323 unwind.opcode_alloc);
22324 else
22325 unwind.opcodes = XNEWVEC (unsigned char, unwind.opcode_alloc);
22326 }
22327 while (length > 0)
22328 {
22329 length--;
22330 unwind.opcodes[unwind.opcode_count] = op & 0xff;
22331 op >>= 8;
22332 unwind.opcode_count++;
22333 }
22334 }
22335
22336 /* Add unwind opcodes to adjust the stack pointer. */
22337
22338 static void
22339 add_unwind_adjustsp (offsetT offset)
22340 {
22341 valueT op;
22342
22343 if (offset > 0x200)
22344 {
22345 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
22346 char bytes[5];
22347 int n;
22348 valueT o;
22349
22350 /* Long form: 0xb2, uleb128. */
22351 /* This might not fit in a word so add the individual bytes,
22352 remembering the list is built in reverse order. */
22353 o = (valueT) ((offset - 0x204) >> 2);
22354 if (o == 0)
22355 add_unwind_opcode (0, 1);
22356
22357 /* Calculate the uleb128 encoding of the offset. */
22358 n = 0;
22359 while (o)
22360 {
22361 bytes[n] = o & 0x7f;
22362 o >>= 7;
22363 if (o)
22364 bytes[n] |= 0x80;
22365 n++;
22366 }
22367 /* Add the insn. */
22368 for (; n; n--)
22369 add_unwind_opcode (bytes[n - 1], 1);
22370 add_unwind_opcode (0xb2, 1);
22371 }
22372 else if (offset > 0x100)
22373 {
22374 /* Two short opcodes. */
22375 add_unwind_opcode (0x3f, 1);
22376 op = (offset - 0x104) >> 2;
22377 add_unwind_opcode (op, 1);
22378 }
22379 else if (offset > 0)
22380 {
22381 /* Short opcode. */
22382 op = (offset - 4) >> 2;
22383 add_unwind_opcode (op, 1);
22384 }
22385 else if (offset < 0)
22386 {
22387 offset = -offset;
22388 while (offset > 0x100)
22389 {
22390 add_unwind_opcode (0x7f, 1);
22391 offset -= 0x100;
22392 }
22393 op = ((offset - 4) >> 2) | 0x40;
22394 add_unwind_opcode (op, 1);
22395 }
22396 }
22397
22398 /* Finish the list of unwind opcodes for this function. */
22399
22400 static void
22401 finish_unwind_opcodes (void)
22402 {
22403 valueT op;
22404
22405 if (unwind.fp_used)
22406 {
22407 /* Adjust sp as necessary. */
22408 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
22409 flush_pending_unwind ();
22410
22411 /* After restoring sp from the frame pointer. */
22412 op = 0x90 | unwind.fp_reg;
22413 add_unwind_opcode (op, 1);
22414 }
22415 else
22416 flush_pending_unwind ();
22417 }
22418
22419
22420 /* Start an exception table entry. If idx is nonzero this is an index table
22421 entry. */
22422
22423 static void
22424 start_unwind_section (const segT text_seg, int idx)
22425 {
22426 const char * text_name;
22427 const char * prefix;
22428 const char * prefix_once;
22429 const char * group_name;
22430 char * sec_name;
22431 int type;
22432 int flags;
22433 int linkonce;
22434
22435 if (idx)
22436 {
22437 prefix = ELF_STRING_ARM_unwind;
22438 prefix_once = ELF_STRING_ARM_unwind_once;
22439 type = SHT_ARM_EXIDX;
22440 }
22441 else
22442 {
22443 prefix = ELF_STRING_ARM_unwind_info;
22444 prefix_once = ELF_STRING_ARM_unwind_info_once;
22445 type = SHT_PROGBITS;
22446 }
22447
22448 text_name = segment_name (text_seg);
22449 if (streq (text_name, ".text"))
22450 text_name = "";
22451
22452 if (strncmp (text_name, ".gnu.linkonce.t.",
22453 strlen (".gnu.linkonce.t.")) == 0)
22454 {
22455 prefix = prefix_once;
22456 text_name += strlen (".gnu.linkonce.t.");
22457 }
22458
22459 sec_name = concat (prefix, text_name, (char *) NULL);
22460
22461 flags = SHF_ALLOC;
22462 linkonce = 0;
22463 group_name = 0;
22464
22465 /* Handle COMDAT group. */
22466 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
22467 {
22468 group_name = elf_group_name (text_seg);
22469 if (group_name == NULL)
22470 {
22471 as_bad (_("Group section `%s' has no group signature"),
22472 segment_name (text_seg));
22473 ignore_rest_of_line ();
22474 return;
22475 }
22476 flags |= SHF_GROUP;
22477 linkonce = 1;
22478 }
22479
22480 obj_elf_change_section (sec_name, type, 0, flags, 0, group_name,
22481 linkonce, 0);
22482
22483 /* Set the section link for index tables. */
22484 if (idx)
22485 elf_linked_to_section (now_seg) = text_seg;
22486 }
22487
22488
22489 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
22490 personality routine data. Returns zero, or the index table value for
22491 an inline entry. */
22492
22493 static valueT
22494 create_unwind_entry (int have_data)
22495 {
22496 int size;
22497 addressT where;
22498 char *ptr;
22499 /* The current word of data. */
22500 valueT data;
22501 /* The number of bytes left in this word. */
22502 int n;
22503
22504 finish_unwind_opcodes ();
22505
22506 /* Remember the current text section. */
22507 unwind.saved_seg = now_seg;
22508 unwind.saved_subseg = now_subseg;
22509
22510 start_unwind_section (now_seg, 0);
22511
22512 if (unwind.personality_routine == NULL)
22513 {
22514 if (unwind.personality_index == -2)
22515 {
22516 if (have_data)
22517 as_bad (_("handlerdata in cantunwind frame"));
22518 return 1; /* EXIDX_CANTUNWIND. */
22519 }
22520
22521 /* Use a default personality routine if none is specified. */
22522 if (unwind.personality_index == -1)
22523 {
22524 if (unwind.opcode_count > 3)
22525 unwind.personality_index = 1;
22526 else
22527 unwind.personality_index = 0;
22528 }
22529
22530 /* Space for the personality routine entry. */
22531 if (unwind.personality_index == 0)
22532 {
22533 if (unwind.opcode_count > 3)
22534 as_bad (_("too many unwind opcodes for personality routine 0"));
22535
22536 if (!have_data)
22537 {
22538 /* All the data is inline in the index table. */
22539 data = 0x80;
22540 n = 3;
22541 while (unwind.opcode_count > 0)
22542 {
22543 unwind.opcode_count--;
22544 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22545 n--;
22546 }
22547
22548 /* Pad with "finish" opcodes. */
22549 while (n--)
22550 data = (data << 8) | 0xb0;
22551
22552 return data;
22553 }
22554 size = 0;
22555 }
22556 else
22557 /* We get two opcodes "free" in the first word. */
22558 size = unwind.opcode_count - 2;
22559 }
22560 else
22561 {
22562 /* PR 16765: Missing or misplaced unwind directives can trigger this. */
22563 if (unwind.personality_index != -1)
22564 {
22565 as_bad (_("attempt to recreate an unwind entry"));
22566 return 1;
22567 }
22568
22569 /* An extra byte is required for the opcode count. */
22570 size = unwind.opcode_count + 1;
22571 }
22572
22573 size = (size + 3) >> 2;
22574 if (size > 0xff)
22575 as_bad (_("too many unwind opcodes"));
22576
22577 frag_align (2, 0, 0);
22578 record_alignment (now_seg, 2);
22579 unwind.table_entry = expr_build_dot ();
22580
22581 /* Allocate the table entry. */
22582 ptr = frag_more ((size << 2) + 4);
22583 /* PR 13449: Zero the table entries in case some of them are not used. */
22584 memset (ptr, 0, (size << 2) + 4);
22585 where = frag_now_fix () - ((size << 2) + 4);
22586
22587 switch (unwind.personality_index)
22588 {
22589 case -1:
22590 /* ??? Should this be a PLT generating relocation? */
22591 /* Custom personality routine. */
22592 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
22593 BFD_RELOC_ARM_PREL31);
22594
22595 where += 4;
22596 ptr += 4;
22597
22598 /* Set the first byte to the number of additional words. */
22599 data = size > 0 ? size - 1 : 0;
22600 n = 3;
22601 break;
22602
22603 /* ABI defined personality routines. */
22604 case 0:
22605 /* Three opcodes bytes are packed into the first word. */
22606 data = 0x80;
22607 n = 3;
22608 break;
22609
22610 case 1:
22611 case 2:
22612 /* The size and first two opcode bytes go in the first word. */
22613 data = ((0x80 + unwind.personality_index) << 8) | size;
22614 n = 2;
22615 break;
22616
22617 default:
22618 /* Should never happen. */
22619 abort ();
22620 }
22621
22622 /* Pack the opcodes into words (MSB first), reversing the list at the same
22623 time. */
22624 while (unwind.opcode_count > 0)
22625 {
22626 if (n == 0)
22627 {
22628 md_number_to_chars (ptr, data, 4);
22629 ptr += 4;
22630 n = 4;
22631 data = 0;
22632 }
22633 unwind.opcode_count--;
22634 n--;
22635 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
22636 }
22637
22638 /* Finish off the last word. */
22639 if (n < 4)
22640 {
22641 /* Pad with "finish" opcodes. */
22642 while (n--)
22643 data = (data << 8) | 0xb0;
22644
22645 md_number_to_chars (ptr, data, 4);
22646 }
22647
22648 if (!have_data)
22649 {
22650 /* Add an empty descriptor if there is no user-specified data. */
22651 ptr = frag_more (4);
22652 md_number_to_chars (ptr, 0, 4);
22653 }
22654
22655 return 0;
22656 }
22657
22658
22659 /* Initialize the DWARF-2 unwind information for this procedure. */
22660
22661 void
22662 tc_arm_frame_initial_instructions (void)
22663 {
22664 cfi_add_CFA_def_cfa (REG_SP, 0);
22665 }
22666 #endif /* OBJ_ELF */
22667
22668 /* Convert REGNAME to a DWARF-2 register number. */
22669
22670 int
22671 tc_arm_regname_to_dw2regnum (char *regname)
22672 {
22673 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
22674 if (reg != FAIL)
22675 return reg;
22676
22677 /* PR 16694: Allow VFP registers as well. */
22678 reg = arm_reg_parse (&regname, REG_TYPE_VFS);
22679 if (reg != FAIL)
22680 return 64 + reg;
22681
22682 reg = arm_reg_parse (&regname, REG_TYPE_VFD);
22683 if (reg != FAIL)
22684 return reg + 256;
22685
22686 return FAIL;
22687 }
22688
22689 #ifdef TE_PE
22690 void
22691 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
22692 {
22693 expressionS exp;
22694
22695 exp.X_op = O_secrel;
22696 exp.X_add_symbol = symbol;
22697 exp.X_add_number = 0;
22698 emit_expr (&exp, size);
22699 }
22700 #endif
22701
22702 /* MD interface: Symbol and relocation handling. */
22703
22704 /* Return the address within the segment that a PC-relative fixup is
22705 relative to. For ARM, PC-relative fixups applied to instructions
22706 are generally relative to the location of the fixup plus 8 bytes.
22707 Thumb branches are offset by 4, and Thumb loads relative to PC
22708 require special handling. */
22709
22710 long
22711 md_pcrel_from_section (fixS * fixP, segT seg)
22712 {
22713 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
22714
22715 /* If this is pc-relative and we are going to emit a relocation
22716 then we just want to put out any pipeline compensation that the linker
22717 will need. Otherwise we want to use the calculated base.
22718 For WinCE we skip the bias for externals as well, since this
22719 is how the MS ARM-CE assembler behaves and we want to be compatible. */
22720 if (fixP->fx_pcrel
22721 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
22722 || (arm_force_relocation (fixP)
22723 #ifdef TE_WINCE
22724 && !S_IS_EXTERNAL (fixP->fx_addsy)
22725 #endif
22726 )))
22727 base = 0;
22728
22729
22730 switch (fixP->fx_r_type)
22731 {
22732 /* PC relative addressing on the Thumb is slightly odd as the
22733 bottom two bits of the PC are forced to zero for the
22734 calculation. This happens *after* application of the
22735 pipeline offset. However, Thumb adrl already adjusts for
22736 this, so we need not do it again. */
22737 case BFD_RELOC_ARM_THUMB_ADD:
22738 return base & ~3;
22739
22740 case BFD_RELOC_ARM_THUMB_OFFSET:
22741 case BFD_RELOC_ARM_T32_OFFSET_IMM:
22742 case BFD_RELOC_ARM_T32_ADD_PC12:
22743 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
22744 return (base + 4) & ~3;
22745
22746 /* Thumb branches are simply offset by +4. */
22747 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22748 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22749 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22750 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22751 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22752 return base + 4;
22753
22754 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22755 if (fixP->fx_addsy
22756 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22757 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22758 && ARM_IS_FUNC (fixP->fx_addsy)
22759 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22760 base = fixP->fx_where + fixP->fx_frag->fr_address;
22761 return base + 4;
22762
22763 /* BLX is like branches above, but forces the low two bits of PC to
22764 zero. */
22765 case BFD_RELOC_THUMB_PCREL_BLX:
22766 if (fixP->fx_addsy
22767 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22768 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22769 && THUMB_IS_FUNC (fixP->fx_addsy)
22770 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22771 base = fixP->fx_where + fixP->fx_frag->fr_address;
22772 return (base + 4) & ~3;
22773
22774 /* ARM mode branches are offset by +8. However, the Windows CE
22775 loader expects the relocation not to take this into account. */
22776 case BFD_RELOC_ARM_PCREL_BLX:
22777 if (fixP->fx_addsy
22778 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22779 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22780 && ARM_IS_FUNC (fixP->fx_addsy)
22781 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22782 base = fixP->fx_where + fixP->fx_frag->fr_address;
22783 return base + 8;
22784
22785 case BFD_RELOC_ARM_PCREL_CALL:
22786 if (fixP->fx_addsy
22787 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22788 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
22789 && THUMB_IS_FUNC (fixP->fx_addsy)
22790 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
22791 base = fixP->fx_where + fixP->fx_frag->fr_address;
22792 return base + 8;
22793
22794 case BFD_RELOC_ARM_PCREL_BRANCH:
22795 case BFD_RELOC_ARM_PCREL_JUMP:
22796 case BFD_RELOC_ARM_PLT32:
22797 #ifdef TE_WINCE
22798 /* When handling fixups immediately, because we have already
22799 discovered the value of a symbol, or the address of the frag involved
22800 we must account for the offset by +8, as the OS loader will never see the reloc.
22801 see fixup_segment() in write.c
22802 The S_IS_EXTERNAL test handles the case of global symbols.
22803 Those need the calculated base, not just the pipe compensation the linker will need. */
22804 if (fixP->fx_pcrel
22805 && fixP->fx_addsy != NULL
22806 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
22807 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
22808 return base + 8;
22809 return base;
22810 #else
22811 return base + 8;
22812 #endif
22813
22814
22815 /* ARM mode loads relative to PC are also offset by +8. Unlike
22816 branches, the Windows CE loader *does* expect the relocation
22817 to take this into account. */
22818 case BFD_RELOC_ARM_OFFSET_IMM:
22819 case BFD_RELOC_ARM_OFFSET_IMM8:
22820 case BFD_RELOC_ARM_HWLITERAL:
22821 case BFD_RELOC_ARM_LITERAL:
22822 case BFD_RELOC_ARM_CP_OFF_IMM:
22823 return base + 8;
22824
22825
22826 /* Other PC-relative relocations are un-offset. */
22827 default:
22828 return base;
22829 }
22830 }
22831
22832 static bfd_boolean flag_warn_syms = TRUE;
22833
22834 bfd_boolean
22835 arm_tc_equal_in_insn (int c ATTRIBUTE_UNUSED, char * name)
22836 {
22837 /* PR 18347 - Warn if the user attempts to create a symbol with the same
22838 name as an ARM instruction. Whilst strictly speaking it is allowed, it
22839 does mean that the resulting code might be very confusing to the reader.
22840 Also this warning can be triggered if the user omits an operand before
22841 an immediate address, eg:
22842
22843 LDR =foo
22844
22845 GAS treats this as an assignment of the value of the symbol foo to a
22846 symbol LDR, and so (without this code) it will not issue any kind of
22847 warning or error message.
22848
22849 Note - ARM instructions are case-insensitive but the strings in the hash
22850 table are all stored in lower case, so we must first ensure that name is
22851 lower case too. */
22852 if (flag_warn_syms && arm_ops_hsh)
22853 {
22854 char * nbuf = strdup (name);
22855 char * p;
22856
22857 for (p = nbuf; *p; p++)
22858 *p = TOLOWER (*p);
22859 if (hash_find (arm_ops_hsh, nbuf) != NULL)
22860 {
22861 static struct hash_control * already_warned = NULL;
22862
22863 if (already_warned == NULL)
22864 already_warned = hash_new ();
22865 /* Only warn about the symbol once. To keep the code
22866 simple we let hash_insert do the lookup for us. */
22867 if (hash_insert (already_warned, name, NULL) == NULL)
22868 as_warn (_("[-mwarn-syms]: Assignment makes a symbol match an ARM instruction: %s"), name);
22869 }
22870 else
22871 free (nbuf);
22872 }
22873
22874 return FALSE;
22875 }
22876
22877 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
22878 Otherwise we have no need to default values of symbols. */
22879
22880 symbolS *
22881 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
22882 {
22883 #ifdef OBJ_ELF
22884 if (name[0] == '_' && name[1] == 'G'
22885 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
22886 {
22887 if (!GOT_symbol)
22888 {
22889 if (symbol_find (name))
22890 as_bad (_("GOT already in the symbol table"));
22891
22892 GOT_symbol = symbol_new (name, undefined_section,
22893 (valueT) 0, & zero_address_frag);
22894 }
22895
22896 return GOT_symbol;
22897 }
22898 #endif
22899
22900 return NULL;
22901 }
22902
22903 /* Subroutine of md_apply_fix. Check to see if an immediate can be
22904 computed as two separate immediate values, added together. We
22905 already know that this value cannot be computed by just one ARM
22906 instruction. */
22907
22908 static unsigned int
22909 validate_immediate_twopart (unsigned int val,
22910 unsigned int * highpart)
22911 {
22912 unsigned int a;
22913 unsigned int i;
22914
22915 for (i = 0; i < 32; i += 2)
22916 if (((a = rotate_left (val, i)) & 0xff) != 0)
22917 {
22918 if (a & 0xff00)
22919 {
22920 if (a & ~ 0xffff)
22921 continue;
22922 * highpart = (a >> 8) | ((i + 24) << 7);
22923 }
22924 else if (a & 0xff0000)
22925 {
22926 if (a & 0xff000000)
22927 continue;
22928 * highpart = (a >> 16) | ((i + 16) << 7);
22929 }
22930 else
22931 {
22932 gas_assert (a & 0xff000000);
22933 * highpart = (a >> 24) | ((i + 8) << 7);
22934 }
22935
22936 return (a & 0xff) | (i << 7);
22937 }
22938
22939 return FAIL;
22940 }
22941
22942 static int
22943 validate_offset_imm (unsigned int val, int hwse)
22944 {
22945 if ((hwse && val > 255) || val > 4095)
22946 return FAIL;
22947 return val;
22948 }
22949
22950 /* Subroutine of md_apply_fix. Do those data_ops which can take a
22951 negative immediate constant by altering the instruction. A bit of
22952 a hack really.
22953 MOV <-> MVN
22954 AND <-> BIC
22955 ADC <-> SBC
22956 by inverting the second operand, and
22957 ADD <-> SUB
22958 CMP <-> CMN
22959 by negating the second operand. */
22960
22961 static int
22962 negate_data_op (unsigned long * instruction,
22963 unsigned long value)
22964 {
22965 int op, new_inst;
22966 unsigned long negated, inverted;
22967
22968 negated = encode_arm_immediate (-value);
22969 inverted = encode_arm_immediate (~value);
22970
22971 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
22972 switch (op)
22973 {
22974 /* First negates. */
22975 case OPCODE_SUB: /* ADD <-> SUB */
22976 new_inst = OPCODE_ADD;
22977 value = negated;
22978 break;
22979
22980 case OPCODE_ADD:
22981 new_inst = OPCODE_SUB;
22982 value = negated;
22983 break;
22984
22985 case OPCODE_CMP: /* CMP <-> CMN */
22986 new_inst = OPCODE_CMN;
22987 value = negated;
22988 break;
22989
22990 case OPCODE_CMN:
22991 new_inst = OPCODE_CMP;
22992 value = negated;
22993 break;
22994
22995 /* Now Inverted ops. */
22996 case OPCODE_MOV: /* MOV <-> MVN */
22997 new_inst = OPCODE_MVN;
22998 value = inverted;
22999 break;
23000
23001 case OPCODE_MVN:
23002 new_inst = OPCODE_MOV;
23003 value = inverted;
23004 break;
23005
23006 case OPCODE_AND: /* AND <-> BIC */
23007 new_inst = OPCODE_BIC;
23008 value = inverted;
23009 break;
23010
23011 case OPCODE_BIC:
23012 new_inst = OPCODE_AND;
23013 value = inverted;
23014 break;
23015
23016 case OPCODE_ADC: /* ADC <-> SBC */
23017 new_inst = OPCODE_SBC;
23018 value = inverted;
23019 break;
23020
23021 case OPCODE_SBC:
23022 new_inst = OPCODE_ADC;
23023 value = inverted;
23024 break;
23025
23026 /* We cannot do anything. */
23027 default:
23028 return FAIL;
23029 }
23030
23031 if (value == (unsigned) FAIL)
23032 return FAIL;
23033
23034 *instruction &= OPCODE_MASK;
23035 *instruction |= new_inst << DATA_OP_SHIFT;
23036 return value;
23037 }
23038
23039 /* Like negate_data_op, but for Thumb-2. */
23040
23041 static unsigned int
23042 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
23043 {
23044 int op, new_inst;
23045 int rd;
23046 unsigned int negated, inverted;
23047
23048 negated = encode_thumb32_immediate (-value);
23049 inverted = encode_thumb32_immediate (~value);
23050
23051 rd = (*instruction >> 8) & 0xf;
23052 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
23053 switch (op)
23054 {
23055 /* ADD <-> SUB. Includes CMP <-> CMN. */
23056 case T2_OPCODE_SUB:
23057 new_inst = T2_OPCODE_ADD;
23058 value = negated;
23059 break;
23060
23061 case T2_OPCODE_ADD:
23062 new_inst = T2_OPCODE_SUB;
23063 value = negated;
23064 break;
23065
23066 /* ORR <-> ORN. Includes MOV <-> MVN. */
23067 case T2_OPCODE_ORR:
23068 new_inst = T2_OPCODE_ORN;
23069 value = inverted;
23070 break;
23071
23072 case T2_OPCODE_ORN:
23073 new_inst = T2_OPCODE_ORR;
23074 value = inverted;
23075 break;
23076
23077 /* AND <-> BIC. TST has no inverted equivalent. */
23078 case T2_OPCODE_AND:
23079 new_inst = T2_OPCODE_BIC;
23080 if (rd == 15)
23081 value = FAIL;
23082 else
23083 value = inverted;
23084 break;
23085
23086 case T2_OPCODE_BIC:
23087 new_inst = T2_OPCODE_AND;
23088 value = inverted;
23089 break;
23090
23091 /* ADC <-> SBC */
23092 case T2_OPCODE_ADC:
23093 new_inst = T2_OPCODE_SBC;
23094 value = inverted;
23095 break;
23096
23097 case T2_OPCODE_SBC:
23098 new_inst = T2_OPCODE_ADC;
23099 value = inverted;
23100 break;
23101
23102 /* We cannot do anything. */
23103 default:
23104 return FAIL;
23105 }
23106
23107 if (value == (unsigned int)FAIL)
23108 return FAIL;
23109
23110 *instruction &= T2_OPCODE_MASK;
23111 *instruction |= new_inst << T2_DATA_OP_SHIFT;
23112 return value;
23113 }
23114
23115 /* Read a 32-bit thumb instruction from buf. */
23116
23117 static unsigned long
23118 get_thumb32_insn (char * buf)
23119 {
23120 unsigned long insn;
23121 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
23122 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23123
23124 return insn;
23125 }
23126
23127 /* We usually want to set the low bit on the address of thumb function
23128 symbols. In particular .word foo - . should have the low bit set.
23129 Generic code tries to fold the difference of two symbols to
23130 a constant. Prevent this and force a relocation when the first symbols
23131 is a thumb function. */
23132
23133 bfd_boolean
23134 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
23135 {
23136 if (op == O_subtract
23137 && l->X_op == O_symbol
23138 && r->X_op == O_symbol
23139 && THUMB_IS_FUNC (l->X_add_symbol))
23140 {
23141 l->X_op = O_subtract;
23142 l->X_op_symbol = r->X_add_symbol;
23143 l->X_add_number -= r->X_add_number;
23144 return TRUE;
23145 }
23146
23147 /* Process as normal. */
23148 return FALSE;
23149 }
23150
23151 /* Encode Thumb2 unconditional branches and calls. The encoding
23152 for the 2 are identical for the immediate values. */
23153
23154 static void
23155 encode_thumb2_b_bl_offset (char * buf, offsetT value)
23156 {
23157 #define T2I1I2MASK ((1 << 13) | (1 << 11))
23158 offsetT newval;
23159 offsetT newval2;
23160 addressT S, I1, I2, lo, hi;
23161
23162 S = (value >> 24) & 0x01;
23163 I1 = (value >> 23) & 0x01;
23164 I2 = (value >> 22) & 0x01;
23165 hi = (value >> 12) & 0x3ff;
23166 lo = (value >> 1) & 0x7ff;
23167 newval = md_chars_to_number (buf, THUMB_SIZE);
23168 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23169 newval |= (S << 10) | hi;
23170 newval2 &= ~T2I1I2MASK;
23171 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
23172 md_number_to_chars (buf, newval, THUMB_SIZE);
23173 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23174 }
23175
23176 void
23177 md_apply_fix (fixS * fixP,
23178 valueT * valP,
23179 segT seg)
23180 {
23181 offsetT value = * valP;
23182 offsetT newval;
23183 unsigned int newimm;
23184 unsigned long temp;
23185 int sign;
23186 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
23187
23188 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
23189
23190 /* Note whether this will delete the relocation. */
23191
23192 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
23193 fixP->fx_done = 1;
23194
23195 /* On a 64-bit host, silently truncate 'value' to 32 bits for
23196 consistency with the behaviour on 32-bit hosts. Remember value
23197 for emit_reloc. */
23198 value &= 0xffffffff;
23199 value ^= 0x80000000;
23200 value -= 0x80000000;
23201
23202 *valP = value;
23203 fixP->fx_addnumber = value;
23204
23205 /* Same treatment for fixP->fx_offset. */
23206 fixP->fx_offset &= 0xffffffff;
23207 fixP->fx_offset ^= 0x80000000;
23208 fixP->fx_offset -= 0x80000000;
23209
23210 switch (fixP->fx_r_type)
23211 {
23212 case BFD_RELOC_NONE:
23213 /* This will need to go in the object file. */
23214 fixP->fx_done = 0;
23215 break;
23216
23217 case BFD_RELOC_ARM_IMMEDIATE:
23218 /* We claim that this fixup has been processed here,
23219 even if in fact we generate an error because we do
23220 not have a reloc for it, so tc_gen_reloc will reject it. */
23221 fixP->fx_done = 1;
23222
23223 if (fixP->fx_addsy)
23224 {
23225 const char *msg = 0;
23226
23227 if (! S_IS_DEFINED (fixP->fx_addsy))
23228 msg = _("undefined symbol %s used as an immediate value");
23229 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23230 msg = _("symbol %s is in a different section");
23231 else if (S_IS_WEAK (fixP->fx_addsy))
23232 msg = _("symbol %s is weak and may be overridden later");
23233
23234 if (msg)
23235 {
23236 as_bad_where (fixP->fx_file, fixP->fx_line,
23237 msg, S_GET_NAME (fixP->fx_addsy));
23238 break;
23239 }
23240 }
23241
23242 temp = md_chars_to_number (buf, INSN_SIZE);
23243
23244 /* If the offset is negative, we should use encoding A2 for ADR. */
23245 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
23246 newimm = negate_data_op (&temp, value);
23247 else
23248 {
23249 newimm = encode_arm_immediate (value);
23250
23251 /* If the instruction will fail, see if we can fix things up by
23252 changing the opcode. */
23253 if (newimm == (unsigned int) FAIL)
23254 newimm = negate_data_op (&temp, value);
23255 /* MOV accepts both ARM modified immediate (A1 encoding) and
23256 UINT16 (A2 encoding) when possible, MOVW only accepts UINT16.
23257 When disassembling, MOV is preferred when there is no encoding
23258 overlap. */
23259 if (newimm == (unsigned int) FAIL
23260 && ((temp >> DATA_OP_SHIFT) & 0xf) == OPCODE_MOV
23261 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)
23262 && !((temp >> SBIT_SHIFT) & 0x1)
23263 && value >= 0 && value <= 0xffff)
23264 {
23265 /* Clear bits[23:20] to change encoding from A1 to A2. */
23266 temp &= 0xff0fffff;
23267 /* Encoding high 4bits imm. Code below will encode the remaining
23268 low 12bits. */
23269 temp |= (value & 0x0000f000) << 4;
23270 newimm = value & 0x00000fff;
23271 }
23272 }
23273
23274 if (newimm == (unsigned int) FAIL)
23275 {
23276 as_bad_where (fixP->fx_file, fixP->fx_line,
23277 _("invalid constant (%lx) after fixup"),
23278 (unsigned long) value);
23279 break;
23280 }
23281
23282 newimm |= (temp & 0xfffff000);
23283 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23284 break;
23285
23286 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
23287 {
23288 unsigned int highpart = 0;
23289 unsigned int newinsn = 0xe1a00000; /* nop. */
23290
23291 if (fixP->fx_addsy)
23292 {
23293 const char *msg = 0;
23294
23295 if (! S_IS_DEFINED (fixP->fx_addsy))
23296 msg = _("undefined symbol %s used as an immediate value");
23297 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
23298 msg = _("symbol %s is in a different section");
23299 else if (S_IS_WEAK (fixP->fx_addsy))
23300 msg = _("symbol %s is weak and may be overridden later");
23301
23302 if (msg)
23303 {
23304 as_bad_where (fixP->fx_file, fixP->fx_line,
23305 msg, S_GET_NAME (fixP->fx_addsy));
23306 break;
23307 }
23308 }
23309
23310 newimm = encode_arm_immediate (value);
23311 temp = md_chars_to_number (buf, INSN_SIZE);
23312
23313 /* If the instruction will fail, see if we can fix things up by
23314 changing the opcode. */
23315 if (newimm == (unsigned int) FAIL
23316 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
23317 {
23318 /* No ? OK - try using two ADD instructions to generate
23319 the value. */
23320 newimm = validate_immediate_twopart (value, & highpart);
23321
23322 /* Yes - then make sure that the second instruction is
23323 also an add. */
23324 if (newimm != (unsigned int) FAIL)
23325 newinsn = temp;
23326 /* Still No ? Try using a negated value. */
23327 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
23328 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
23329 /* Otherwise - give up. */
23330 else
23331 {
23332 as_bad_where (fixP->fx_file, fixP->fx_line,
23333 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
23334 (long) value);
23335 break;
23336 }
23337
23338 /* Replace the first operand in the 2nd instruction (which
23339 is the PC) with the destination register. We have
23340 already added in the PC in the first instruction and we
23341 do not want to do it again. */
23342 newinsn &= ~ 0xf0000;
23343 newinsn |= ((newinsn & 0x0f000) << 4);
23344 }
23345
23346 newimm |= (temp & 0xfffff000);
23347 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
23348
23349 highpart |= (newinsn & 0xfffff000);
23350 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
23351 }
23352 break;
23353
23354 case BFD_RELOC_ARM_OFFSET_IMM:
23355 if (!fixP->fx_done && seg->use_rela_p)
23356 value = 0;
23357 /* Fall through. */
23358
23359 case BFD_RELOC_ARM_LITERAL:
23360 sign = value > 0;
23361
23362 if (value < 0)
23363 value = - value;
23364
23365 if (validate_offset_imm (value, 0) == FAIL)
23366 {
23367 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
23368 as_bad_where (fixP->fx_file, fixP->fx_line,
23369 _("invalid literal constant: pool needs to be closer"));
23370 else
23371 as_bad_where (fixP->fx_file, fixP->fx_line,
23372 _("bad immediate value for offset (%ld)"),
23373 (long) value);
23374 break;
23375 }
23376
23377 newval = md_chars_to_number (buf, INSN_SIZE);
23378 if (value == 0)
23379 newval &= 0xfffff000;
23380 else
23381 {
23382 newval &= 0xff7ff000;
23383 newval |= value | (sign ? INDEX_UP : 0);
23384 }
23385 md_number_to_chars (buf, newval, INSN_SIZE);
23386 break;
23387
23388 case BFD_RELOC_ARM_OFFSET_IMM8:
23389 case BFD_RELOC_ARM_HWLITERAL:
23390 sign = value > 0;
23391
23392 if (value < 0)
23393 value = - value;
23394
23395 if (validate_offset_imm (value, 1) == FAIL)
23396 {
23397 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
23398 as_bad_where (fixP->fx_file, fixP->fx_line,
23399 _("invalid literal constant: pool needs to be closer"));
23400 else
23401 as_bad_where (fixP->fx_file, fixP->fx_line,
23402 _("bad immediate value for 8-bit offset (%ld)"),
23403 (long) value);
23404 break;
23405 }
23406
23407 newval = md_chars_to_number (buf, INSN_SIZE);
23408 if (value == 0)
23409 newval &= 0xfffff0f0;
23410 else
23411 {
23412 newval &= 0xff7ff0f0;
23413 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
23414 }
23415 md_number_to_chars (buf, newval, INSN_SIZE);
23416 break;
23417
23418 case BFD_RELOC_ARM_T32_OFFSET_U8:
23419 if (value < 0 || value > 1020 || value % 4 != 0)
23420 as_bad_where (fixP->fx_file, fixP->fx_line,
23421 _("bad immediate value for offset (%ld)"), (long) value);
23422 value /= 4;
23423
23424 newval = md_chars_to_number (buf+2, THUMB_SIZE);
23425 newval |= value;
23426 md_number_to_chars (buf+2, newval, THUMB_SIZE);
23427 break;
23428
23429 case BFD_RELOC_ARM_T32_OFFSET_IMM:
23430 /* This is a complicated relocation used for all varieties of Thumb32
23431 load/store instruction with immediate offset:
23432
23433 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
23434 *4, optional writeback(W)
23435 (doubleword load/store)
23436
23437 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
23438 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
23439 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
23440 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
23441 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
23442
23443 Uppercase letters indicate bits that are already encoded at
23444 this point. Lowercase letters are our problem. For the
23445 second block of instructions, the secondary opcode nybble
23446 (bits 8..11) is present, and bit 23 is zero, even if this is
23447 a PC-relative operation. */
23448 newval = md_chars_to_number (buf, THUMB_SIZE);
23449 newval <<= 16;
23450 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
23451
23452 if ((newval & 0xf0000000) == 0xe0000000)
23453 {
23454 /* Doubleword load/store: 8-bit offset, scaled by 4. */
23455 if (value >= 0)
23456 newval |= (1 << 23);
23457 else
23458 value = -value;
23459 if (value % 4 != 0)
23460 {
23461 as_bad_where (fixP->fx_file, fixP->fx_line,
23462 _("offset not a multiple of 4"));
23463 break;
23464 }
23465 value /= 4;
23466 if (value > 0xff)
23467 {
23468 as_bad_where (fixP->fx_file, fixP->fx_line,
23469 _("offset out of range"));
23470 break;
23471 }
23472 newval &= ~0xff;
23473 }
23474 else if ((newval & 0x000f0000) == 0x000f0000)
23475 {
23476 /* PC-relative, 12-bit offset. */
23477 if (value >= 0)
23478 newval |= (1 << 23);
23479 else
23480 value = -value;
23481 if (value > 0xfff)
23482 {
23483 as_bad_where (fixP->fx_file, fixP->fx_line,
23484 _("offset out of range"));
23485 break;
23486 }
23487 newval &= ~0xfff;
23488 }
23489 else if ((newval & 0x00000100) == 0x00000100)
23490 {
23491 /* Writeback: 8-bit, +/- offset. */
23492 if (value >= 0)
23493 newval |= (1 << 9);
23494 else
23495 value = -value;
23496 if (value > 0xff)
23497 {
23498 as_bad_where (fixP->fx_file, fixP->fx_line,
23499 _("offset out of range"));
23500 break;
23501 }
23502 newval &= ~0xff;
23503 }
23504 else if ((newval & 0x00000f00) == 0x00000e00)
23505 {
23506 /* T-instruction: positive 8-bit offset. */
23507 if (value < 0 || value > 0xff)
23508 {
23509 as_bad_where (fixP->fx_file, fixP->fx_line,
23510 _("offset out of range"));
23511 break;
23512 }
23513 newval &= ~0xff;
23514 newval |= value;
23515 }
23516 else
23517 {
23518 /* Positive 12-bit or negative 8-bit offset. */
23519 int limit;
23520 if (value >= 0)
23521 {
23522 newval |= (1 << 23);
23523 limit = 0xfff;
23524 }
23525 else
23526 {
23527 value = -value;
23528 limit = 0xff;
23529 }
23530 if (value > limit)
23531 {
23532 as_bad_where (fixP->fx_file, fixP->fx_line,
23533 _("offset out of range"));
23534 break;
23535 }
23536 newval &= ~limit;
23537 }
23538
23539 newval |= value;
23540 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
23541 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
23542 break;
23543
23544 case BFD_RELOC_ARM_SHIFT_IMM:
23545 newval = md_chars_to_number (buf, INSN_SIZE);
23546 if (((unsigned long) value) > 32
23547 || (value == 32
23548 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
23549 {
23550 as_bad_where (fixP->fx_file, fixP->fx_line,
23551 _("shift expression is too large"));
23552 break;
23553 }
23554
23555 if (value == 0)
23556 /* Shifts of zero must be done as lsl. */
23557 newval &= ~0x60;
23558 else if (value == 32)
23559 value = 0;
23560 newval &= 0xfffff07f;
23561 newval |= (value & 0x1f) << 7;
23562 md_number_to_chars (buf, newval, INSN_SIZE);
23563 break;
23564
23565 case BFD_RELOC_ARM_T32_IMMEDIATE:
23566 case BFD_RELOC_ARM_T32_ADD_IMM:
23567 case BFD_RELOC_ARM_T32_IMM12:
23568 case BFD_RELOC_ARM_T32_ADD_PC12:
23569 /* We claim that this fixup has been processed here,
23570 even if in fact we generate an error because we do
23571 not have a reloc for it, so tc_gen_reloc will reject it. */
23572 fixP->fx_done = 1;
23573
23574 if (fixP->fx_addsy
23575 && ! S_IS_DEFINED (fixP->fx_addsy))
23576 {
23577 as_bad_where (fixP->fx_file, fixP->fx_line,
23578 _("undefined symbol %s used as an immediate value"),
23579 S_GET_NAME (fixP->fx_addsy));
23580 break;
23581 }
23582
23583 newval = md_chars_to_number (buf, THUMB_SIZE);
23584 newval <<= 16;
23585 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
23586
23587 newimm = FAIL;
23588 if ((fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
23589 /* ARMv8-M Baseline MOV will reach here, but it doesn't support
23590 Thumb2 modified immediate encoding (T2). */
23591 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2))
23592 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23593 {
23594 newimm = encode_thumb32_immediate (value);
23595 if (newimm == (unsigned int) FAIL)
23596 newimm = thumb32_negate_data_op (&newval, value);
23597 }
23598 if (newimm == (unsigned int) FAIL)
23599 {
23600 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE)
23601 {
23602 /* Turn add/sum into addw/subw. */
23603 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
23604 newval = (newval & 0xfeffffff) | 0x02000000;
23605 /* No flat 12-bit imm encoding for addsw/subsw. */
23606 if ((newval & 0x00100000) == 0)
23607 {
23608 /* 12 bit immediate for addw/subw. */
23609 if (value < 0)
23610 {
23611 value = -value;
23612 newval ^= 0x00a00000;
23613 }
23614 if (value > 0xfff)
23615 newimm = (unsigned int) FAIL;
23616 else
23617 newimm = value;
23618 }
23619 }
23620 else
23621 {
23622 /* MOV accepts both Thumb2 modified immediate (T2 encoding) and
23623 UINT16 (T3 encoding), MOVW only accepts UINT16. When
23624 disassembling, MOV is preferred when there is no encoding
23625 overlap. */
23626 if (((newval >> T2_DATA_OP_SHIFT) & 0xf) == T2_OPCODE_ORR
23627 /* NOTE: MOV uses the ORR opcode in Thumb 2 mode
23628 but with the Rn field [19:16] set to 1111. */
23629 && (((newval >> 16) & 0xf) == 0xf)
23630 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2_v8m)
23631 && !((newval >> T2_SBIT_SHIFT) & 0x1)
23632 && value >= 0 && value <= 0xffff)
23633 {
23634 /* Toggle bit[25] to change encoding from T2 to T3. */
23635 newval ^= 1 << 25;
23636 /* Clear bits[19:16]. */
23637 newval &= 0xfff0ffff;
23638 /* Encoding high 4bits imm. Code below will encode the
23639 remaining low 12bits. */
23640 newval |= (value & 0x0000f000) << 4;
23641 newimm = value & 0x00000fff;
23642 }
23643 }
23644 }
23645
23646 if (newimm == (unsigned int)FAIL)
23647 {
23648 as_bad_where (fixP->fx_file, fixP->fx_line,
23649 _("invalid constant (%lx) after fixup"),
23650 (unsigned long) value);
23651 break;
23652 }
23653
23654 newval |= (newimm & 0x800) << 15;
23655 newval |= (newimm & 0x700) << 4;
23656 newval |= (newimm & 0x0ff);
23657
23658 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
23659 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
23660 break;
23661
23662 case BFD_RELOC_ARM_SMC:
23663 if (((unsigned long) value) > 0xffff)
23664 as_bad_where (fixP->fx_file, fixP->fx_line,
23665 _("invalid smc expression"));
23666 newval = md_chars_to_number (buf, INSN_SIZE);
23667 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23668 md_number_to_chars (buf, newval, INSN_SIZE);
23669 break;
23670
23671 case BFD_RELOC_ARM_HVC:
23672 if (((unsigned long) value) > 0xffff)
23673 as_bad_where (fixP->fx_file, fixP->fx_line,
23674 _("invalid hvc expression"));
23675 newval = md_chars_to_number (buf, INSN_SIZE);
23676 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
23677 md_number_to_chars (buf, newval, INSN_SIZE);
23678 break;
23679
23680 case BFD_RELOC_ARM_SWI:
23681 if (fixP->tc_fix_data != 0)
23682 {
23683 if (((unsigned long) value) > 0xff)
23684 as_bad_where (fixP->fx_file, fixP->fx_line,
23685 _("invalid swi expression"));
23686 newval = md_chars_to_number (buf, THUMB_SIZE);
23687 newval |= value;
23688 md_number_to_chars (buf, newval, THUMB_SIZE);
23689 }
23690 else
23691 {
23692 if (((unsigned long) value) > 0x00ffffff)
23693 as_bad_where (fixP->fx_file, fixP->fx_line,
23694 _("invalid swi expression"));
23695 newval = md_chars_to_number (buf, INSN_SIZE);
23696 newval |= value;
23697 md_number_to_chars (buf, newval, INSN_SIZE);
23698 }
23699 break;
23700
23701 case BFD_RELOC_ARM_MULTI:
23702 if (((unsigned long) value) > 0xffff)
23703 as_bad_where (fixP->fx_file, fixP->fx_line,
23704 _("invalid expression in load/store multiple"));
23705 newval = value | md_chars_to_number (buf, INSN_SIZE);
23706 md_number_to_chars (buf, newval, INSN_SIZE);
23707 break;
23708
23709 #ifdef OBJ_ELF
23710 case BFD_RELOC_ARM_PCREL_CALL:
23711
23712 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23713 && fixP->fx_addsy
23714 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23715 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23716 && THUMB_IS_FUNC (fixP->fx_addsy))
23717 /* Flip the bl to blx. This is a simple flip
23718 bit here because we generate PCREL_CALL for
23719 unconditional bls. */
23720 {
23721 newval = md_chars_to_number (buf, INSN_SIZE);
23722 newval = newval | 0x10000000;
23723 md_number_to_chars (buf, newval, INSN_SIZE);
23724 temp = 1;
23725 fixP->fx_done = 1;
23726 }
23727 else
23728 temp = 3;
23729 goto arm_branch_common;
23730
23731 case BFD_RELOC_ARM_PCREL_JUMP:
23732 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23733 && fixP->fx_addsy
23734 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23735 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23736 && THUMB_IS_FUNC (fixP->fx_addsy))
23737 {
23738 /* This would map to a bl<cond>, b<cond>,
23739 b<always> to a Thumb function. We
23740 need to force a relocation for this particular
23741 case. */
23742 newval = md_chars_to_number (buf, INSN_SIZE);
23743 fixP->fx_done = 0;
23744 }
23745 /* Fall through. */
23746
23747 case BFD_RELOC_ARM_PLT32:
23748 #endif
23749 case BFD_RELOC_ARM_PCREL_BRANCH:
23750 temp = 3;
23751 goto arm_branch_common;
23752
23753 case BFD_RELOC_ARM_PCREL_BLX:
23754
23755 temp = 1;
23756 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23757 && fixP->fx_addsy
23758 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23759 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23760 && ARM_IS_FUNC (fixP->fx_addsy))
23761 {
23762 /* Flip the blx to a bl and warn. */
23763 const char *name = S_GET_NAME (fixP->fx_addsy);
23764 newval = 0xeb000000;
23765 as_warn_where (fixP->fx_file, fixP->fx_line,
23766 _("blx to '%s' an ARM ISA state function changed to bl"),
23767 name);
23768 md_number_to_chars (buf, newval, INSN_SIZE);
23769 temp = 3;
23770 fixP->fx_done = 1;
23771 }
23772
23773 #ifdef OBJ_ELF
23774 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
23775 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
23776 #endif
23777
23778 arm_branch_common:
23779 /* We are going to store value (shifted right by two) in the
23780 instruction, in a 24 bit, signed field. Bits 26 through 32 either
23781 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
23782 also be clear. */
23783 if (value & temp)
23784 as_bad_where (fixP->fx_file, fixP->fx_line,
23785 _("misaligned branch destination"));
23786 if ((value & (offsetT)0xfe000000) != (offsetT)0
23787 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
23788 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23789
23790 if (fixP->fx_done || !seg->use_rela_p)
23791 {
23792 newval = md_chars_to_number (buf, INSN_SIZE);
23793 newval |= (value >> 2) & 0x00ffffff;
23794 /* Set the H bit on BLX instructions. */
23795 if (temp == 1)
23796 {
23797 if (value & 2)
23798 newval |= 0x01000000;
23799 else
23800 newval &= ~0x01000000;
23801 }
23802 md_number_to_chars (buf, newval, INSN_SIZE);
23803 }
23804 break;
23805
23806 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
23807 /* CBZ can only branch forward. */
23808
23809 /* Attempts to use CBZ to branch to the next instruction
23810 (which, strictly speaking, are prohibited) will be turned into
23811 no-ops.
23812
23813 FIXME: It may be better to remove the instruction completely and
23814 perform relaxation. */
23815 if (value == -2)
23816 {
23817 newval = md_chars_to_number (buf, THUMB_SIZE);
23818 newval = 0xbf00; /* NOP encoding T1 */
23819 md_number_to_chars (buf, newval, THUMB_SIZE);
23820 }
23821 else
23822 {
23823 if (value & ~0x7e)
23824 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23825
23826 if (fixP->fx_done || !seg->use_rela_p)
23827 {
23828 newval = md_chars_to_number (buf, THUMB_SIZE);
23829 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
23830 md_number_to_chars (buf, newval, THUMB_SIZE);
23831 }
23832 }
23833 break;
23834
23835 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
23836 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
23837 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23838
23839 if (fixP->fx_done || !seg->use_rela_p)
23840 {
23841 newval = md_chars_to_number (buf, THUMB_SIZE);
23842 newval |= (value & 0x1ff) >> 1;
23843 md_number_to_chars (buf, newval, THUMB_SIZE);
23844 }
23845 break;
23846
23847 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
23848 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
23849 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23850
23851 if (fixP->fx_done || !seg->use_rela_p)
23852 {
23853 newval = md_chars_to_number (buf, THUMB_SIZE);
23854 newval |= (value & 0xfff) >> 1;
23855 md_number_to_chars (buf, newval, THUMB_SIZE);
23856 }
23857 break;
23858
23859 case BFD_RELOC_THUMB_PCREL_BRANCH20:
23860 if (fixP->fx_addsy
23861 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23862 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23863 && ARM_IS_FUNC (fixP->fx_addsy)
23864 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23865 {
23866 /* Force a relocation for a branch 20 bits wide. */
23867 fixP->fx_done = 0;
23868 }
23869 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
23870 as_bad_where (fixP->fx_file, fixP->fx_line,
23871 _("conditional branch out of range"));
23872
23873 if (fixP->fx_done || !seg->use_rela_p)
23874 {
23875 offsetT newval2;
23876 addressT S, J1, J2, lo, hi;
23877
23878 S = (value & 0x00100000) >> 20;
23879 J2 = (value & 0x00080000) >> 19;
23880 J1 = (value & 0x00040000) >> 18;
23881 hi = (value & 0x0003f000) >> 12;
23882 lo = (value & 0x00000ffe) >> 1;
23883
23884 newval = md_chars_to_number (buf, THUMB_SIZE);
23885 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23886 newval |= (S << 10) | hi;
23887 newval2 |= (J1 << 13) | (J2 << 11) | lo;
23888 md_number_to_chars (buf, newval, THUMB_SIZE);
23889 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
23890 }
23891 break;
23892
23893 case BFD_RELOC_THUMB_PCREL_BLX:
23894 /* If there is a blx from a thumb state function to
23895 another thumb function flip this to a bl and warn
23896 about it. */
23897
23898 if (fixP->fx_addsy
23899 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23900 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23901 && THUMB_IS_FUNC (fixP->fx_addsy))
23902 {
23903 const char *name = S_GET_NAME (fixP->fx_addsy);
23904 as_warn_where (fixP->fx_file, fixP->fx_line,
23905 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
23906 name);
23907 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23908 newval = newval | 0x1000;
23909 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23910 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23911 fixP->fx_done = 1;
23912 }
23913
23914
23915 goto thumb_bl_common;
23916
23917 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23918 /* A bl from Thumb state ISA to an internal ARM state function
23919 is converted to a blx. */
23920 if (fixP->fx_addsy
23921 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
23922 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
23923 && ARM_IS_FUNC (fixP->fx_addsy)
23924 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
23925 {
23926 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
23927 newval = newval & ~0x1000;
23928 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
23929 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
23930 fixP->fx_done = 1;
23931 }
23932
23933 thumb_bl_common:
23934
23935 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23936 /* For a BLX instruction, make sure that the relocation is rounded up
23937 to a word boundary. This follows the semantics of the instruction
23938 which specifies that bit 1 of the target address will come from bit
23939 1 of the base address. */
23940 value = (value + 3) & ~ 3;
23941
23942 #ifdef OBJ_ELF
23943 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
23944 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
23945 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
23946 #endif
23947
23948 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
23949 {
23950 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6t2)))
23951 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23952 else if ((value & ~0x1ffffff)
23953 && ((value & ~0x1ffffff) != ~0x1ffffff))
23954 as_bad_where (fixP->fx_file, fixP->fx_line,
23955 _("Thumb2 branch out of range"));
23956 }
23957
23958 if (fixP->fx_done || !seg->use_rela_p)
23959 encode_thumb2_b_bl_offset (buf, value);
23960
23961 break;
23962
23963 case BFD_RELOC_THUMB_PCREL_BRANCH25:
23964 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
23965 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
23966
23967 if (fixP->fx_done || !seg->use_rela_p)
23968 encode_thumb2_b_bl_offset (buf, value);
23969
23970 break;
23971
23972 case BFD_RELOC_8:
23973 if (fixP->fx_done || !seg->use_rela_p)
23974 *buf = value;
23975 break;
23976
23977 case BFD_RELOC_16:
23978 if (fixP->fx_done || !seg->use_rela_p)
23979 md_number_to_chars (buf, value, 2);
23980 break;
23981
23982 #ifdef OBJ_ELF
23983 case BFD_RELOC_ARM_TLS_CALL:
23984 case BFD_RELOC_ARM_THM_TLS_CALL:
23985 case BFD_RELOC_ARM_TLS_DESCSEQ:
23986 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
23987 case BFD_RELOC_ARM_TLS_GOTDESC:
23988 case BFD_RELOC_ARM_TLS_GD32:
23989 case BFD_RELOC_ARM_TLS_LE32:
23990 case BFD_RELOC_ARM_TLS_IE32:
23991 case BFD_RELOC_ARM_TLS_LDM32:
23992 case BFD_RELOC_ARM_TLS_LDO32:
23993 S_SET_THREAD_LOCAL (fixP->fx_addsy);
23994 break;
23995
23996 /* Same handling as above, but with the arm_fdpic guard. */
23997 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
23998 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
23999 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
24000 if (arm_fdpic)
24001 {
24002 S_SET_THREAD_LOCAL (fixP->fx_addsy);
24003 }
24004 else
24005 {
24006 as_bad_where (fixP->fx_file, fixP->fx_line,
24007 _("Relocation supported only in FDPIC mode"));
24008 }
24009 break;
24010
24011 case BFD_RELOC_ARM_GOT32:
24012 case BFD_RELOC_ARM_GOTOFF:
24013 break;
24014
24015 case BFD_RELOC_ARM_GOT_PREL:
24016 if (fixP->fx_done || !seg->use_rela_p)
24017 md_number_to_chars (buf, value, 4);
24018 break;
24019
24020 case BFD_RELOC_ARM_TARGET2:
24021 /* TARGET2 is not partial-inplace, so we need to write the
24022 addend here for REL targets, because it won't be written out
24023 during reloc processing later. */
24024 if (fixP->fx_done || !seg->use_rela_p)
24025 md_number_to_chars (buf, fixP->fx_offset, 4);
24026 break;
24027
24028 /* Relocations for FDPIC. */
24029 case BFD_RELOC_ARM_GOTFUNCDESC:
24030 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24031 case BFD_RELOC_ARM_FUNCDESC:
24032 if (arm_fdpic)
24033 {
24034 if (fixP->fx_done || !seg->use_rela_p)
24035 md_number_to_chars (buf, 0, 4);
24036 }
24037 else
24038 {
24039 as_bad_where (fixP->fx_file, fixP->fx_line,
24040 _("Relocation supported only in FDPIC mode"));
24041 }
24042 break;
24043 #endif
24044
24045 case BFD_RELOC_RVA:
24046 case BFD_RELOC_32:
24047 case BFD_RELOC_ARM_TARGET1:
24048 case BFD_RELOC_ARM_ROSEGREL32:
24049 case BFD_RELOC_ARM_SBREL32:
24050 case BFD_RELOC_32_PCREL:
24051 #ifdef TE_PE
24052 case BFD_RELOC_32_SECREL:
24053 #endif
24054 if (fixP->fx_done || !seg->use_rela_p)
24055 #ifdef TE_WINCE
24056 /* For WinCE we only do this for pcrel fixups. */
24057 if (fixP->fx_done || fixP->fx_pcrel)
24058 #endif
24059 md_number_to_chars (buf, value, 4);
24060 break;
24061
24062 #ifdef OBJ_ELF
24063 case BFD_RELOC_ARM_PREL31:
24064 if (fixP->fx_done || !seg->use_rela_p)
24065 {
24066 newval = md_chars_to_number (buf, 4) & 0x80000000;
24067 if ((value ^ (value >> 1)) & 0x40000000)
24068 {
24069 as_bad_where (fixP->fx_file, fixP->fx_line,
24070 _("rel31 relocation overflow"));
24071 }
24072 newval |= value & 0x7fffffff;
24073 md_number_to_chars (buf, newval, 4);
24074 }
24075 break;
24076 #endif
24077
24078 case BFD_RELOC_ARM_CP_OFF_IMM:
24079 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
24080 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM)
24081 newval = md_chars_to_number (buf, INSN_SIZE);
24082 else
24083 newval = get_thumb32_insn (buf);
24084 if ((newval & 0x0f200f00) == 0x0d000900)
24085 {
24086 /* This is a fp16 vstr/vldr. The immediate offset in the mnemonic
24087 has permitted values that are multiples of 2, in the range 0
24088 to 510. */
24089 if (value < -510 || value > 510 || (value & 1))
24090 as_bad_where (fixP->fx_file, fixP->fx_line,
24091 _("co-processor offset out of range"));
24092 }
24093 else if (value < -1023 || value > 1023 || (value & 3))
24094 as_bad_where (fixP->fx_file, fixP->fx_line,
24095 _("co-processor offset out of range"));
24096 cp_off_common:
24097 sign = value > 0;
24098 if (value < 0)
24099 value = -value;
24100 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24101 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24102 newval = md_chars_to_number (buf, INSN_SIZE);
24103 else
24104 newval = get_thumb32_insn (buf);
24105 if (value == 0)
24106 newval &= 0xffffff00;
24107 else
24108 {
24109 newval &= 0xff7fff00;
24110 if ((newval & 0x0f200f00) == 0x0d000900)
24111 {
24112 /* This is a fp16 vstr/vldr.
24113
24114 It requires the immediate offset in the instruction is shifted
24115 left by 1 to be a half-word offset.
24116
24117 Here, left shift by 1 first, and later right shift by 2
24118 should get the right offset. */
24119 value <<= 1;
24120 }
24121 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
24122 }
24123 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
24124 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
24125 md_number_to_chars (buf, newval, INSN_SIZE);
24126 else
24127 put_thumb32_insn (buf, newval);
24128 break;
24129
24130 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
24131 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
24132 if (value < -255 || value > 255)
24133 as_bad_where (fixP->fx_file, fixP->fx_line,
24134 _("co-processor offset out of range"));
24135 value *= 4;
24136 goto cp_off_common;
24137
24138 case BFD_RELOC_ARM_THUMB_OFFSET:
24139 newval = md_chars_to_number (buf, THUMB_SIZE);
24140 /* Exactly what ranges, and where the offset is inserted depends
24141 on the type of instruction, we can establish this from the
24142 top 4 bits. */
24143 switch (newval >> 12)
24144 {
24145 case 4: /* PC load. */
24146 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
24147 forced to zero for these loads; md_pcrel_from has already
24148 compensated for this. */
24149 if (value & 3)
24150 as_bad_where (fixP->fx_file, fixP->fx_line,
24151 _("invalid offset, target not word aligned (0x%08lX)"),
24152 (((unsigned long) fixP->fx_frag->fr_address
24153 + (unsigned long) fixP->fx_where) & ~3)
24154 + (unsigned long) value);
24155
24156 if (value & ~0x3fc)
24157 as_bad_where (fixP->fx_file, fixP->fx_line,
24158 _("invalid offset, value too big (0x%08lX)"),
24159 (long) value);
24160
24161 newval |= value >> 2;
24162 break;
24163
24164 case 9: /* SP load/store. */
24165 if (value & ~0x3fc)
24166 as_bad_where (fixP->fx_file, fixP->fx_line,
24167 _("invalid offset, value too big (0x%08lX)"),
24168 (long) value);
24169 newval |= value >> 2;
24170 break;
24171
24172 case 6: /* Word load/store. */
24173 if (value & ~0x7c)
24174 as_bad_where (fixP->fx_file, fixP->fx_line,
24175 _("invalid offset, value too big (0x%08lX)"),
24176 (long) value);
24177 newval |= value << 4; /* 6 - 2. */
24178 break;
24179
24180 case 7: /* Byte load/store. */
24181 if (value & ~0x1f)
24182 as_bad_where (fixP->fx_file, fixP->fx_line,
24183 _("invalid offset, value too big (0x%08lX)"),
24184 (long) value);
24185 newval |= value << 6;
24186 break;
24187
24188 case 8: /* Halfword load/store. */
24189 if (value & ~0x3e)
24190 as_bad_where (fixP->fx_file, fixP->fx_line,
24191 _("invalid offset, value too big (0x%08lX)"),
24192 (long) value);
24193 newval |= value << 5; /* 6 - 1. */
24194 break;
24195
24196 default:
24197 as_bad_where (fixP->fx_file, fixP->fx_line,
24198 "Unable to process relocation for thumb opcode: %lx",
24199 (unsigned long) newval);
24200 break;
24201 }
24202 md_number_to_chars (buf, newval, THUMB_SIZE);
24203 break;
24204
24205 case BFD_RELOC_ARM_THUMB_ADD:
24206 /* This is a complicated relocation, since we use it for all of
24207 the following immediate relocations:
24208
24209 3bit ADD/SUB
24210 8bit ADD/SUB
24211 9bit ADD/SUB SP word-aligned
24212 10bit ADD PC/SP word-aligned
24213
24214 The type of instruction being processed is encoded in the
24215 instruction field:
24216
24217 0x8000 SUB
24218 0x00F0 Rd
24219 0x000F Rs
24220 */
24221 newval = md_chars_to_number (buf, THUMB_SIZE);
24222 {
24223 int rd = (newval >> 4) & 0xf;
24224 int rs = newval & 0xf;
24225 int subtract = !!(newval & 0x8000);
24226
24227 /* Check for HI regs, only very restricted cases allowed:
24228 Adjusting SP, and using PC or SP to get an address. */
24229 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
24230 || (rs > 7 && rs != REG_SP && rs != REG_PC))
24231 as_bad_where (fixP->fx_file, fixP->fx_line,
24232 _("invalid Hi register with immediate"));
24233
24234 /* If value is negative, choose the opposite instruction. */
24235 if (value < 0)
24236 {
24237 value = -value;
24238 subtract = !subtract;
24239 if (value < 0)
24240 as_bad_where (fixP->fx_file, fixP->fx_line,
24241 _("immediate value out of range"));
24242 }
24243
24244 if (rd == REG_SP)
24245 {
24246 if (value & ~0x1fc)
24247 as_bad_where (fixP->fx_file, fixP->fx_line,
24248 _("invalid immediate for stack address calculation"));
24249 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
24250 newval |= value >> 2;
24251 }
24252 else if (rs == REG_PC || rs == REG_SP)
24253 {
24254 /* PR gas/18541. If the addition is for a defined symbol
24255 within range of an ADR instruction then accept it. */
24256 if (subtract
24257 && value == 4
24258 && fixP->fx_addsy != NULL)
24259 {
24260 subtract = 0;
24261
24262 if (! S_IS_DEFINED (fixP->fx_addsy)
24263 || S_GET_SEGMENT (fixP->fx_addsy) != seg
24264 || S_IS_WEAK (fixP->fx_addsy))
24265 {
24266 as_bad_where (fixP->fx_file, fixP->fx_line,
24267 _("address calculation needs a strongly defined nearby symbol"));
24268 }
24269 else
24270 {
24271 offsetT v = fixP->fx_where + fixP->fx_frag->fr_address;
24272
24273 /* Round up to the next 4-byte boundary. */
24274 if (v & 3)
24275 v = (v + 3) & ~ 3;
24276 else
24277 v += 4;
24278 v = S_GET_VALUE (fixP->fx_addsy) - v;
24279
24280 if (v & ~0x3fc)
24281 {
24282 as_bad_where (fixP->fx_file, fixP->fx_line,
24283 _("symbol too far away"));
24284 }
24285 else
24286 {
24287 fixP->fx_done = 1;
24288 value = v;
24289 }
24290 }
24291 }
24292
24293 if (subtract || value & ~0x3fc)
24294 as_bad_where (fixP->fx_file, fixP->fx_line,
24295 _("invalid immediate for address calculation (value = 0x%08lX)"),
24296 (unsigned long) (subtract ? - value : value));
24297 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
24298 newval |= rd << 8;
24299 newval |= value >> 2;
24300 }
24301 else if (rs == rd)
24302 {
24303 if (value & ~0xff)
24304 as_bad_where (fixP->fx_file, fixP->fx_line,
24305 _("immediate value out of range"));
24306 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
24307 newval |= (rd << 8) | value;
24308 }
24309 else
24310 {
24311 if (value & ~0x7)
24312 as_bad_where (fixP->fx_file, fixP->fx_line,
24313 _("immediate value out of range"));
24314 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
24315 newval |= rd | (rs << 3) | (value << 6);
24316 }
24317 }
24318 md_number_to_chars (buf, newval, THUMB_SIZE);
24319 break;
24320
24321 case BFD_RELOC_ARM_THUMB_IMM:
24322 newval = md_chars_to_number (buf, THUMB_SIZE);
24323 if (value < 0 || value > 255)
24324 as_bad_where (fixP->fx_file, fixP->fx_line,
24325 _("invalid immediate: %ld is out of range"),
24326 (long) value);
24327 newval |= value;
24328 md_number_to_chars (buf, newval, THUMB_SIZE);
24329 break;
24330
24331 case BFD_RELOC_ARM_THUMB_SHIFT:
24332 /* 5bit shift value (0..32). LSL cannot take 32. */
24333 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
24334 temp = newval & 0xf800;
24335 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
24336 as_bad_where (fixP->fx_file, fixP->fx_line,
24337 _("invalid shift value: %ld"), (long) value);
24338 /* Shifts of zero must be encoded as LSL. */
24339 if (value == 0)
24340 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
24341 /* Shifts of 32 are encoded as zero. */
24342 else if (value == 32)
24343 value = 0;
24344 newval |= value << 6;
24345 md_number_to_chars (buf, newval, THUMB_SIZE);
24346 break;
24347
24348 case BFD_RELOC_VTABLE_INHERIT:
24349 case BFD_RELOC_VTABLE_ENTRY:
24350 fixP->fx_done = 0;
24351 return;
24352
24353 case BFD_RELOC_ARM_MOVW:
24354 case BFD_RELOC_ARM_MOVT:
24355 case BFD_RELOC_ARM_THUMB_MOVW:
24356 case BFD_RELOC_ARM_THUMB_MOVT:
24357 if (fixP->fx_done || !seg->use_rela_p)
24358 {
24359 /* REL format relocations are limited to a 16-bit addend. */
24360 if (!fixP->fx_done)
24361 {
24362 if (value < -0x8000 || value > 0x7fff)
24363 as_bad_where (fixP->fx_file, fixP->fx_line,
24364 _("offset out of range"));
24365 }
24366 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
24367 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24368 {
24369 value >>= 16;
24370 }
24371
24372 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
24373 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
24374 {
24375 newval = get_thumb32_insn (buf);
24376 newval &= 0xfbf08f00;
24377 newval |= (value & 0xf000) << 4;
24378 newval |= (value & 0x0800) << 15;
24379 newval |= (value & 0x0700) << 4;
24380 newval |= (value & 0x00ff);
24381 put_thumb32_insn (buf, newval);
24382 }
24383 else
24384 {
24385 newval = md_chars_to_number (buf, 4);
24386 newval &= 0xfff0f000;
24387 newval |= value & 0x0fff;
24388 newval |= (value & 0xf000) << 4;
24389 md_number_to_chars (buf, newval, 4);
24390 }
24391 }
24392 return;
24393
24394 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24395 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24396 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24397 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24398 gas_assert (!fixP->fx_done);
24399 {
24400 bfd_vma insn;
24401 bfd_boolean is_mov;
24402 bfd_vma encoded_addend = value;
24403
24404 /* Check that addend can be encoded in instruction. */
24405 if (!seg->use_rela_p && (value < 0 || value > 255))
24406 as_bad_where (fixP->fx_file, fixP->fx_line,
24407 _("the offset 0x%08lX is not representable"),
24408 (unsigned long) encoded_addend);
24409
24410 /* Extract the instruction. */
24411 insn = md_chars_to_number (buf, THUMB_SIZE);
24412 is_mov = (insn & 0xf800) == 0x2000;
24413
24414 /* Encode insn. */
24415 if (is_mov)
24416 {
24417 if (!seg->use_rela_p)
24418 insn |= encoded_addend;
24419 }
24420 else
24421 {
24422 int rd, rs;
24423
24424 /* Extract the instruction. */
24425 /* Encoding is the following
24426 0x8000 SUB
24427 0x00F0 Rd
24428 0x000F Rs
24429 */
24430 /* The following conditions must be true :
24431 - ADD
24432 - Rd == Rs
24433 - Rd <= 7
24434 */
24435 rd = (insn >> 4) & 0xf;
24436 rs = insn & 0xf;
24437 if ((insn & 0x8000) || (rd != rs) || rd > 7)
24438 as_bad_where (fixP->fx_file, fixP->fx_line,
24439 _("Unable to process relocation for thumb opcode: %lx"),
24440 (unsigned long) insn);
24441
24442 /* Encode as ADD immediate8 thumb 1 code. */
24443 insn = 0x3000 | (rd << 8);
24444
24445 /* Place the encoded addend into the first 8 bits of the
24446 instruction. */
24447 if (!seg->use_rela_p)
24448 insn |= encoded_addend;
24449 }
24450
24451 /* Update the instruction. */
24452 md_number_to_chars (buf, insn, THUMB_SIZE);
24453 }
24454 break;
24455
24456 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24457 case BFD_RELOC_ARM_ALU_PC_G0:
24458 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24459 case BFD_RELOC_ARM_ALU_PC_G1:
24460 case BFD_RELOC_ARM_ALU_PC_G2:
24461 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24462 case BFD_RELOC_ARM_ALU_SB_G0:
24463 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24464 case BFD_RELOC_ARM_ALU_SB_G1:
24465 case BFD_RELOC_ARM_ALU_SB_G2:
24466 gas_assert (!fixP->fx_done);
24467 if (!seg->use_rela_p)
24468 {
24469 bfd_vma insn;
24470 bfd_vma encoded_addend;
24471 bfd_vma addend_abs = abs (value);
24472
24473 /* Check that the absolute value of the addend can be
24474 expressed as an 8-bit constant plus a rotation. */
24475 encoded_addend = encode_arm_immediate (addend_abs);
24476 if (encoded_addend == (unsigned int) FAIL)
24477 as_bad_where (fixP->fx_file, fixP->fx_line,
24478 _("the offset 0x%08lX is not representable"),
24479 (unsigned long) addend_abs);
24480
24481 /* Extract the instruction. */
24482 insn = md_chars_to_number (buf, INSN_SIZE);
24483
24484 /* If the addend is positive, use an ADD instruction.
24485 Otherwise use a SUB. Take care not to destroy the S bit. */
24486 insn &= 0xff1fffff;
24487 if (value < 0)
24488 insn |= 1 << 22;
24489 else
24490 insn |= 1 << 23;
24491
24492 /* Place the encoded addend into the first 12 bits of the
24493 instruction. */
24494 insn &= 0xfffff000;
24495 insn |= encoded_addend;
24496
24497 /* Update the instruction. */
24498 md_number_to_chars (buf, insn, INSN_SIZE);
24499 }
24500 break;
24501
24502 case BFD_RELOC_ARM_LDR_PC_G0:
24503 case BFD_RELOC_ARM_LDR_PC_G1:
24504 case BFD_RELOC_ARM_LDR_PC_G2:
24505 case BFD_RELOC_ARM_LDR_SB_G0:
24506 case BFD_RELOC_ARM_LDR_SB_G1:
24507 case BFD_RELOC_ARM_LDR_SB_G2:
24508 gas_assert (!fixP->fx_done);
24509 if (!seg->use_rela_p)
24510 {
24511 bfd_vma insn;
24512 bfd_vma addend_abs = abs (value);
24513
24514 /* Check that the absolute value of the addend can be
24515 encoded in 12 bits. */
24516 if (addend_abs >= 0x1000)
24517 as_bad_where (fixP->fx_file, fixP->fx_line,
24518 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
24519 (unsigned long) addend_abs);
24520
24521 /* Extract the instruction. */
24522 insn = md_chars_to_number (buf, INSN_SIZE);
24523
24524 /* If the addend is negative, clear bit 23 of the instruction.
24525 Otherwise set it. */
24526 if (value < 0)
24527 insn &= ~(1 << 23);
24528 else
24529 insn |= 1 << 23;
24530
24531 /* Place the absolute value of the addend into the first 12 bits
24532 of the instruction. */
24533 insn &= 0xfffff000;
24534 insn |= addend_abs;
24535
24536 /* Update the instruction. */
24537 md_number_to_chars (buf, insn, INSN_SIZE);
24538 }
24539 break;
24540
24541 case BFD_RELOC_ARM_LDRS_PC_G0:
24542 case BFD_RELOC_ARM_LDRS_PC_G1:
24543 case BFD_RELOC_ARM_LDRS_PC_G2:
24544 case BFD_RELOC_ARM_LDRS_SB_G0:
24545 case BFD_RELOC_ARM_LDRS_SB_G1:
24546 case BFD_RELOC_ARM_LDRS_SB_G2:
24547 gas_assert (!fixP->fx_done);
24548 if (!seg->use_rela_p)
24549 {
24550 bfd_vma insn;
24551 bfd_vma addend_abs = abs (value);
24552
24553 /* Check that the absolute value of the addend can be
24554 encoded in 8 bits. */
24555 if (addend_abs >= 0x100)
24556 as_bad_where (fixP->fx_file, fixP->fx_line,
24557 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
24558 (unsigned long) addend_abs);
24559
24560 /* Extract the instruction. */
24561 insn = md_chars_to_number (buf, INSN_SIZE);
24562
24563 /* If the addend is negative, clear bit 23 of the instruction.
24564 Otherwise set it. */
24565 if (value < 0)
24566 insn &= ~(1 << 23);
24567 else
24568 insn |= 1 << 23;
24569
24570 /* Place the first four bits of the absolute value of the addend
24571 into the first 4 bits of the instruction, and the remaining
24572 four into bits 8 .. 11. */
24573 insn &= 0xfffff0f0;
24574 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
24575
24576 /* Update the instruction. */
24577 md_number_to_chars (buf, insn, INSN_SIZE);
24578 }
24579 break;
24580
24581 case BFD_RELOC_ARM_LDC_PC_G0:
24582 case BFD_RELOC_ARM_LDC_PC_G1:
24583 case BFD_RELOC_ARM_LDC_PC_G2:
24584 case BFD_RELOC_ARM_LDC_SB_G0:
24585 case BFD_RELOC_ARM_LDC_SB_G1:
24586 case BFD_RELOC_ARM_LDC_SB_G2:
24587 gas_assert (!fixP->fx_done);
24588 if (!seg->use_rela_p)
24589 {
24590 bfd_vma insn;
24591 bfd_vma addend_abs = abs (value);
24592
24593 /* Check that the absolute value of the addend is a multiple of
24594 four and, when divided by four, fits in 8 bits. */
24595 if (addend_abs & 0x3)
24596 as_bad_where (fixP->fx_file, fixP->fx_line,
24597 _("bad offset 0x%08lX (must be word-aligned)"),
24598 (unsigned long) addend_abs);
24599
24600 if ((addend_abs >> 2) > 0xff)
24601 as_bad_where (fixP->fx_file, fixP->fx_line,
24602 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
24603 (unsigned long) addend_abs);
24604
24605 /* Extract the instruction. */
24606 insn = md_chars_to_number (buf, INSN_SIZE);
24607
24608 /* If the addend is negative, clear bit 23 of the instruction.
24609 Otherwise set it. */
24610 if (value < 0)
24611 insn &= ~(1 << 23);
24612 else
24613 insn |= 1 << 23;
24614
24615 /* Place the addend (divided by four) into the first eight
24616 bits of the instruction. */
24617 insn &= 0xfffffff0;
24618 insn |= addend_abs >> 2;
24619
24620 /* Update the instruction. */
24621 md_number_to_chars (buf, insn, INSN_SIZE);
24622 }
24623 break;
24624
24625 case BFD_RELOC_ARM_V4BX:
24626 /* This will need to go in the object file. */
24627 fixP->fx_done = 0;
24628 break;
24629
24630 case BFD_RELOC_UNUSED:
24631 default:
24632 as_bad_where (fixP->fx_file, fixP->fx_line,
24633 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
24634 }
24635 }
24636
24637 /* Translate internal representation of relocation info to BFD target
24638 format. */
24639
24640 arelent *
24641 tc_gen_reloc (asection *section, fixS *fixp)
24642 {
24643 arelent * reloc;
24644 bfd_reloc_code_real_type code;
24645
24646 reloc = XNEW (arelent);
24647
24648 reloc->sym_ptr_ptr = XNEW (asymbol *);
24649 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
24650 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
24651
24652 if (fixp->fx_pcrel)
24653 {
24654 if (section->use_rela_p)
24655 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
24656 else
24657 fixp->fx_offset = reloc->address;
24658 }
24659 reloc->addend = fixp->fx_offset;
24660
24661 switch (fixp->fx_r_type)
24662 {
24663 case BFD_RELOC_8:
24664 if (fixp->fx_pcrel)
24665 {
24666 code = BFD_RELOC_8_PCREL;
24667 break;
24668 }
24669 /* Fall through. */
24670
24671 case BFD_RELOC_16:
24672 if (fixp->fx_pcrel)
24673 {
24674 code = BFD_RELOC_16_PCREL;
24675 break;
24676 }
24677 /* Fall through. */
24678
24679 case BFD_RELOC_32:
24680 if (fixp->fx_pcrel)
24681 {
24682 code = BFD_RELOC_32_PCREL;
24683 break;
24684 }
24685 /* Fall through. */
24686
24687 case BFD_RELOC_ARM_MOVW:
24688 if (fixp->fx_pcrel)
24689 {
24690 code = BFD_RELOC_ARM_MOVW_PCREL;
24691 break;
24692 }
24693 /* Fall through. */
24694
24695 case BFD_RELOC_ARM_MOVT:
24696 if (fixp->fx_pcrel)
24697 {
24698 code = BFD_RELOC_ARM_MOVT_PCREL;
24699 break;
24700 }
24701 /* Fall through. */
24702
24703 case BFD_RELOC_ARM_THUMB_MOVW:
24704 if (fixp->fx_pcrel)
24705 {
24706 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
24707 break;
24708 }
24709 /* Fall through. */
24710
24711 case BFD_RELOC_ARM_THUMB_MOVT:
24712 if (fixp->fx_pcrel)
24713 {
24714 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
24715 break;
24716 }
24717 /* Fall through. */
24718
24719 case BFD_RELOC_NONE:
24720 case BFD_RELOC_ARM_PCREL_BRANCH:
24721 case BFD_RELOC_ARM_PCREL_BLX:
24722 case BFD_RELOC_RVA:
24723 case BFD_RELOC_THUMB_PCREL_BRANCH7:
24724 case BFD_RELOC_THUMB_PCREL_BRANCH9:
24725 case BFD_RELOC_THUMB_PCREL_BRANCH12:
24726 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24727 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24728 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24729 case BFD_RELOC_VTABLE_ENTRY:
24730 case BFD_RELOC_VTABLE_INHERIT:
24731 #ifdef TE_PE
24732 case BFD_RELOC_32_SECREL:
24733 #endif
24734 code = fixp->fx_r_type;
24735 break;
24736
24737 case BFD_RELOC_THUMB_PCREL_BLX:
24738 #ifdef OBJ_ELF
24739 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
24740 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
24741 else
24742 #endif
24743 code = BFD_RELOC_THUMB_PCREL_BLX;
24744 break;
24745
24746 case BFD_RELOC_ARM_LITERAL:
24747 case BFD_RELOC_ARM_HWLITERAL:
24748 /* If this is called then the a literal has
24749 been referenced across a section boundary. */
24750 as_bad_where (fixp->fx_file, fixp->fx_line,
24751 _("literal referenced across section boundary"));
24752 return NULL;
24753
24754 #ifdef OBJ_ELF
24755 case BFD_RELOC_ARM_TLS_CALL:
24756 case BFD_RELOC_ARM_THM_TLS_CALL:
24757 case BFD_RELOC_ARM_TLS_DESCSEQ:
24758 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
24759 case BFD_RELOC_ARM_GOT32:
24760 case BFD_RELOC_ARM_GOTOFF:
24761 case BFD_RELOC_ARM_GOT_PREL:
24762 case BFD_RELOC_ARM_PLT32:
24763 case BFD_RELOC_ARM_TARGET1:
24764 case BFD_RELOC_ARM_ROSEGREL32:
24765 case BFD_RELOC_ARM_SBREL32:
24766 case BFD_RELOC_ARM_PREL31:
24767 case BFD_RELOC_ARM_TARGET2:
24768 case BFD_RELOC_ARM_TLS_LDO32:
24769 case BFD_RELOC_ARM_PCREL_CALL:
24770 case BFD_RELOC_ARM_PCREL_JUMP:
24771 case BFD_RELOC_ARM_ALU_PC_G0_NC:
24772 case BFD_RELOC_ARM_ALU_PC_G0:
24773 case BFD_RELOC_ARM_ALU_PC_G1_NC:
24774 case BFD_RELOC_ARM_ALU_PC_G1:
24775 case BFD_RELOC_ARM_ALU_PC_G2:
24776 case BFD_RELOC_ARM_LDR_PC_G0:
24777 case BFD_RELOC_ARM_LDR_PC_G1:
24778 case BFD_RELOC_ARM_LDR_PC_G2:
24779 case BFD_RELOC_ARM_LDRS_PC_G0:
24780 case BFD_RELOC_ARM_LDRS_PC_G1:
24781 case BFD_RELOC_ARM_LDRS_PC_G2:
24782 case BFD_RELOC_ARM_LDC_PC_G0:
24783 case BFD_RELOC_ARM_LDC_PC_G1:
24784 case BFD_RELOC_ARM_LDC_PC_G2:
24785 case BFD_RELOC_ARM_ALU_SB_G0_NC:
24786 case BFD_RELOC_ARM_ALU_SB_G0:
24787 case BFD_RELOC_ARM_ALU_SB_G1_NC:
24788 case BFD_RELOC_ARM_ALU_SB_G1:
24789 case BFD_RELOC_ARM_ALU_SB_G2:
24790 case BFD_RELOC_ARM_LDR_SB_G0:
24791 case BFD_RELOC_ARM_LDR_SB_G1:
24792 case BFD_RELOC_ARM_LDR_SB_G2:
24793 case BFD_RELOC_ARM_LDRS_SB_G0:
24794 case BFD_RELOC_ARM_LDRS_SB_G1:
24795 case BFD_RELOC_ARM_LDRS_SB_G2:
24796 case BFD_RELOC_ARM_LDC_SB_G0:
24797 case BFD_RELOC_ARM_LDC_SB_G1:
24798 case BFD_RELOC_ARM_LDC_SB_G2:
24799 case BFD_RELOC_ARM_V4BX:
24800 case BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC:
24801 case BFD_RELOC_ARM_THUMB_ALU_ABS_G1_NC:
24802 case BFD_RELOC_ARM_THUMB_ALU_ABS_G2_NC:
24803 case BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC:
24804 case BFD_RELOC_ARM_GOTFUNCDESC:
24805 case BFD_RELOC_ARM_GOTOFFFUNCDESC:
24806 case BFD_RELOC_ARM_FUNCDESC:
24807 code = fixp->fx_r_type;
24808 break;
24809
24810 case BFD_RELOC_ARM_TLS_GOTDESC:
24811 case BFD_RELOC_ARM_TLS_GD32:
24812 case BFD_RELOC_ARM_TLS_GD32_FDPIC:
24813 case BFD_RELOC_ARM_TLS_LE32:
24814 case BFD_RELOC_ARM_TLS_IE32:
24815 case BFD_RELOC_ARM_TLS_IE32_FDPIC:
24816 case BFD_RELOC_ARM_TLS_LDM32:
24817 case BFD_RELOC_ARM_TLS_LDM32_FDPIC:
24818 /* BFD will include the symbol's address in the addend.
24819 But we don't want that, so subtract it out again here. */
24820 if (!S_IS_COMMON (fixp->fx_addsy))
24821 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
24822 code = fixp->fx_r_type;
24823 break;
24824 #endif
24825
24826 case BFD_RELOC_ARM_IMMEDIATE:
24827 as_bad_where (fixp->fx_file, fixp->fx_line,
24828 _("internal relocation (type: IMMEDIATE) not fixed up"));
24829 return NULL;
24830
24831 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
24832 as_bad_where (fixp->fx_file, fixp->fx_line,
24833 _("ADRL used for a symbol not defined in the same file"));
24834 return NULL;
24835
24836 case BFD_RELOC_ARM_OFFSET_IMM:
24837 if (section->use_rela_p)
24838 {
24839 code = fixp->fx_r_type;
24840 break;
24841 }
24842
24843 if (fixp->fx_addsy != NULL
24844 && !S_IS_DEFINED (fixp->fx_addsy)
24845 && S_IS_LOCAL (fixp->fx_addsy))
24846 {
24847 as_bad_where (fixp->fx_file, fixp->fx_line,
24848 _("undefined local label `%s'"),
24849 S_GET_NAME (fixp->fx_addsy));
24850 return NULL;
24851 }
24852
24853 as_bad_where (fixp->fx_file, fixp->fx_line,
24854 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
24855 return NULL;
24856
24857 default:
24858 {
24859 const char * type;
24860
24861 switch (fixp->fx_r_type)
24862 {
24863 case BFD_RELOC_NONE: type = "NONE"; break;
24864 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
24865 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
24866 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
24867 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
24868 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
24869 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
24870 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
24871 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
24872 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
24873 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
24874 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
24875 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
24876 default: type = _("<unknown>"); break;
24877 }
24878 as_bad_where (fixp->fx_file, fixp->fx_line,
24879 _("cannot represent %s relocation in this object file format"),
24880 type);
24881 return NULL;
24882 }
24883 }
24884
24885 #ifdef OBJ_ELF
24886 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
24887 && GOT_symbol
24888 && fixp->fx_addsy == GOT_symbol)
24889 {
24890 code = BFD_RELOC_ARM_GOTPC;
24891 reloc->addend = fixp->fx_offset = reloc->address;
24892 }
24893 #endif
24894
24895 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
24896
24897 if (reloc->howto == NULL)
24898 {
24899 as_bad_where (fixp->fx_file, fixp->fx_line,
24900 _("cannot represent %s relocation in this object file format"),
24901 bfd_get_reloc_code_name (code));
24902 return NULL;
24903 }
24904
24905 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
24906 vtable entry to be used in the relocation's section offset. */
24907 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
24908 reloc->address = fixp->fx_offset;
24909
24910 return reloc;
24911 }
24912
24913 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
24914
24915 void
24916 cons_fix_new_arm (fragS * frag,
24917 int where,
24918 int size,
24919 expressionS * exp,
24920 bfd_reloc_code_real_type reloc)
24921 {
24922 int pcrel = 0;
24923
24924 /* Pick a reloc.
24925 FIXME: @@ Should look at CPU word size. */
24926 switch (size)
24927 {
24928 case 1:
24929 reloc = BFD_RELOC_8;
24930 break;
24931 case 2:
24932 reloc = BFD_RELOC_16;
24933 break;
24934 case 4:
24935 default:
24936 reloc = BFD_RELOC_32;
24937 break;
24938 case 8:
24939 reloc = BFD_RELOC_64;
24940 break;
24941 }
24942
24943 #ifdef TE_PE
24944 if (exp->X_op == O_secrel)
24945 {
24946 exp->X_op = O_symbol;
24947 reloc = BFD_RELOC_32_SECREL;
24948 }
24949 #endif
24950
24951 fix_new_exp (frag, where, size, exp, pcrel, reloc);
24952 }
24953
24954 #if defined (OBJ_COFF)
24955 void
24956 arm_validate_fix (fixS * fixP)
24957 {
24958 /* If the destination of the branch is a defined symbol which does not have
24959 the THUMB_FUNC attribute, then we must be calling a function which has
24960 the (interfacearm) attribute. We look for the Thumb entry point to that
24961 function and change the branch to refer to that function instead. */
24962 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
24963 && fixP->fx_addsy != NULL
24964 && S_IS_DEFINED (fixP->fx_addsy)
24965 && ! THUMB_IS_FUNC (fixP->fx_addsy))
24966 {
24967 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
24968 }
24969 }
24970 #endif
24971
24972
24973 int
24974 arm_force_relocation (struct fix * fixp)
24975 {
24976 #if defined (OBJ_COFF) && defined (TE_PE)
24977 if (fixp->fx_r_type == BFD_RELOC_RVA)
24978 return 1;
24979 #endif
24980
24981 /* In case we have a call or a branch to a function in ARM ISA mode from
24982 a thumb function or vice-versa force the relocation. These relocations
24983 are cleared off for some cores that might have blx and simple transformations
24984 are possible. */
24985
24986 #ifdef OBJ_ELF
24987 switch (fixp->fx_r_type)
24988 {
24989 case BFD_RELOC_ARM_PCREL_JUMP:
24990 case BFD_RELOC_ARM_PCREL_CALL:
24991 case BFD_RELOC_THUMB_PCREL_BLX:
24992 if (THUMB_IS_FUNC (fixp->fx_addsy))
24993 return 1;
24994 break;
24995
24996 case BFD_RELOC_ARM_PCREL_BLX:
24997 case BFD_RELOC_THUMB_PCREL_BRANCH25:
24998 case BFD_RELOC_THUMB_PCREL_BRANCH20:
24999 case BFD_RELOC_THUMB_PCREL_BRANCH23:
25000 if (ARM_IS_FUNC (fixp->fx_addsy))
25001 return 1;
25002 break;
25003
25004 default:
25005 break;
25006 }
25007 #endif
25008
25009 /* Resolve these relocations even if the symbol is extern or weak.
25010 Technically this is probably wrong due to symbol preemption.
25011 In practice these relocations do not have enough range to be useful
25012 at dynamic link time, and some code (e.g. in the Linux kernel)
25013 expects these references to be resolved. */
25014 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
25015 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
25016 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
25017 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
25018 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
25019 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
25020 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
25021 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
25022 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
25023 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
25024 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
25025 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
25026 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
25027 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
25028 return 0;
25029
25030 /* Always leave these relocations for the linker. */
25031 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25032 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25033 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25034 return 1;
25035
25036 /* Always generate relocations against function symbols. */
25037 if (fixp->fx_r_type == BFD_RELOC_32
25038 && fixp->fx_addsy
25039 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
25040 return 1;
25041
25042 return generic_force_reloc (fixp);
25043 }
25044
25045 #if defined (OBJ_ELF) || defined (OBJ_COFF)
25046 /* Relocations against function names must be left unadjusted,
25047 so that the linker can use this information to generate interworking
25048 stubs. The MIPS version of this function
25049 also prevents relocations that are mips-16 specific, but I do not
25050 know why it does this.
25051
25052 FIXME:
25053 There is one other problem that ought to be addressed here, but
25054 which currently is not: Taking the address of a label (rather
25055 than a function) and then later jumping to that address. Such
25056 addresses also ought to have their bottom bit set (assuming that
25057 they reside in Thumb code), but at the moment they will not. */
25058
25059 bfd_boolean
25060 arm_fix_adjustable (fixS * fixP)
25061 {
25062 if (fixP->fx_addsy == NULL)
25063 return 1;
25064
25065 /* Preserve relocations against symbols with function type. */
25066 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
25067 return FALSE;
25068
25069 if (THUMB_IS_FUNC (fixP->fx_addsy)
25070 && fixP->fx_subsy == NULL)
25071 return FALSE;
25072
25073 /* We need the symbol name for the VTABLE entries. */
25074 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
25075 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
25076 return FALSE;
25077
25078 /* Don't allow symbols to be discarded on GOT related relocs. */
25079 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
25080 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
25081 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
25082 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
25083 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32_FDPIC
25084 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
25085 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
25086 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32_FDPIC
25087 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
25088 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32_FDPIC
25089 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
25090 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
25091 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
25092 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
25093 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
25094 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
25095 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
25096 return FALSE;
25097
25098 /* Similarly for group relocations. */
25099 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
25100 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
25101 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
25102 return FALSE;
25103
25104 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
25105 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
25106 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
25107 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
25108 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
25109 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
25110 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
25111 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
25112 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
25113 return FALSE;
25114
25115 /* BFD_RELOC_ARM_THUMB_ALU_ABS_Gx_NC relocations have VERY limited
25116 offsets, so keep these symbols. */
25117 if (fixP->fx_r_type >= BFD_RELOC_ARM_THUMB_ALU_ABS_G0_NC
25118 && fixP->fx_r_type <= BFD_RELOC_ARM_THUMB_ALU_ABS_G3_NC)
25119 return FALSE;
25120
25121 return TRUE;
25122 }
25123 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
25124
25125 #ifdef OBJ_ELF
25126 const char *
25127 elf32_arm_target_format (void)
25128 {
25129 #ifdef TE_SYMBIAN
25130 return (target_big_endian
25131 ? "elf32-bigarm-symbian"
25132 : "elf32-littlearm-symbian");
25133 #elif defined (TE_VXWORKS)
25134 return (target_big_endian
25135 ? "elf32-bigarm-vxworks"
25136 : "elf32-littlearm-vxworks");
25137 #elif defined (TE_NACL)
25138 return (target_big_endian
25139 ? "elf32-bigarm-nacl"
25140 : "elf32-littlearm-nacl");
25141 #else
25142 if (arm_fdpic)
25143 {
25144 if (target_big_endian)
25145 return "elf32-bigarm-fdpic";
25146 else
25147 return "elf32-littlearm-fdpic";
25148 }
25149 else
25150 {
25151 if (target_big_endian)
25152 return "elf32-bigarm";
25153 else
25154 return "elf32-littlearm";
25155 }
25156 #endif
25157 }
25158
25159 void
25160 armelf_frob_symbol (symbolS * symp,
25161 int * puntp)
25162 {
25163 elf_frob_symbol (symp, puntp);
25164 }
25165 #endif
25166
25167 /* MD interface: Finalization. */
25168
25169 void
25170 arm_cleanup (void)
25171 {
25172 literal_pool * pool;
25173
25174 /* Ensure that all the IT blocks are properly closed. */
25175 check_it_blocks_finished ();
25176
25177 for (pool = list_of_pools; pool; pool = pool->next)
25178 {
25179 /* Put it at the end of the relevant section. */
25180 subseg_set (pool->section, pool->sub_section);
25181 #ifdef OBJ_ELF
25182 arm_elf_change_section ();
25183 #endif
25184 s_ltorg (0);
25185 }
25186 }
25187
25188 #ifdef OBJ_ELF
25189 /* Remove any excess mapping symbols generated for alignment frags in
25190 SEC. We may have created a mapping symbol before a zero byte
25191 alignment; remove it if there's a mapping symbol after the
25192 alignment. */
25193 static void
25194 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
25195 void *dummy ATTRIBUTE_UNUSED)
25196 {
25197 segment_info_type *seginfo = seg_info (sec);
25198 fragS *fragp;
25199
25200 if (seginfo == NULL || seginfo->frchainP == NULL)
25201 return;
25202
25203 for (fragp = seginfo->frchainP->frch_root;
25204 fragp != NULL;
25205 fragp = fragp->fr_next)
25206 {
25207 symbolS *sym = fragp->tc_frag_data.last_map;
25208 fragS *next = fragp->fr_next;
25209
25210 /* Variable-sized frags have been converted to fixed size by
25211 this point. But if this was variable-sized to start with,
25212 there will be a fixed-size frag after it. So don't handle
25213 next == NULL. */
25214 if (sym == NULL || next == NULL)
25215 continue;
25216
25217 if (S_GET_VALUE (sym) < next->fr_address)
25218 /* Not at the end of this frag. */
25219 continue;
25220 know (S_GET_VALUE (sym) == next->fr_address);
25221
25222 do
25223 {
25224 if (next->tc_frag_data.first_map != NULL)
25225 {
25226 /* Next frag starts with a mapping symbol. Discard this
25227 one. */
25228 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25229 break;
25230 }
25231
25232 if (next->fr_next == NULL)
25233 {
25234 /* This mapping symbol is at the end of the section. Discard
25235 it. */
25236 know (next->fr_fix == 0 && next->fr_var == 0);
25237 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
25238 break;
25239 }
25240
25241 /* As long as we have empty frags without any mapping symbols,
25242 keep looking. */
25243 /* If the next frag is non-empty and does not start with a
25244 mapping symbol, then this mapping symbol is required. */
25245 if (next->fr_address != next->fr_next->fr_address)
25246 break;
25247
25248 next = next->fr_next;
25249 }
25250 while (next != NULL);
25251 }
25252 }
25253 #endif
25254
25255 /* Adjust the symbol table. This marks Thumb symbols as distinct from
25256 ARM ones. */
25257
25258 void
25259 arm_adjust_symtab (void)
25260 {
25261 #ifdef OBJ_COFF
25262 symbolS * sym;
25263
25264 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25265 {
25266 if (ARM_IS_THUMB (sym))
25267 {
25268 if (THUMB_IS_FUNC (sym))
25269 {
25270 /* Mark the symbol as a Thumb function. */
25271 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
25272 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
25273 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
25274
25275 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
25276 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
25277 else
25278 as_bad (_("%s: unexpected function type: %d"),
25279 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
25280 }
25281 else switch (S_GET_STORAGE_CLASS (sym))
25282 {
25283 case C_EXT:
25284 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
25285 break;
25286 case C_STAT:
25287 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
25288 break;
25289 case C_LABEL:
25290 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
25291 break;
25292 default:
25293 /* Do nothing. */
25294 break;
25295 }
25296 }
25297
25298 if (ARM_IS_INTERWORK (sym))
25299 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
25300 }
25301 #endif
25302 #ifdef OBJ_ELF
25303 symbolS * sym;
25304 char bind;
25305
25306 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
25307 {
25308 if (ARM_IS_THUMB (sym))
25309 {
25310 elf_symbol_type * elf_sym;
25311
25312 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
25313 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
25314
25315 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
25316 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
25317 {
25318 /* If it's a .thumb_func, declare it as so,
25319 otherwise tag label as .code 16. */
25320 if (THUMB_IS_FUNC (sym))
25321 ARM_SET_SYM_BRANCH_TYPE (elf_sym->internal_elf_sym.st_target_internal,
25322 ST_BRANCH_TO_THUMB);
25323 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
25324 elf_sym->internal_elf_sym.st_info =
25325 ELF_ST_INFO (bind, STT_ARM_16BIT);
25326 }
25327 }
25328 }
25329
25330 /* Remove any overlapping mapping symbols generated by alignment frags. */
25331 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
25332 /* Now do generic ELF adjustments. */
25333 elf_adjust_symtab ();
25334 #endif
25335 }
25336
25337 /* MD interface: Initialization. */
25338
25339 static void
25340 set_constant_flonums (void)
25341 {
25342 int i;
25343
25344 for (i = 0; i < NUM_FLOAT_VALS; i++)
25345 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
25346 abort ();
25347 }
25348
25349 /* Auto-select Thumb mode if it's the only available instruction set for the
25350 given architecture. */
25351
25352 static void
25353 autoselect_thumb_from_cpu_variant (void)
25354 {
25355 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
25356 opcode_select (16);
25357 }
25358
25359 void
25360 md_begin (void)
25361 {
25362 unsigned mach;
25363 unsigned int i;
25364
25365 if ( (arm_ops_hsh = hash_new ()) == NULL
25366 || (arm_cond_hsh = hash_new ()) == NULL
25367 || (arm_shift_hsh = hash_new ()) == NULL
25368 || (arm_psr_hsh = hash_new ()) == NULL
25369 || (arm_v7m_psr_hsh = hash_new ()) == NULL
25370 || (arm_reg_hsh = hash_new ()) == NULL
25371 || (arm_reloc_hsh = hash_new ()) == NULL
25372 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
25373 as_fatal (_("virtual memory exhausted"));
25374
25375 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
25376 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
25377 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
25378 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
25379 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
25380 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
25381 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
25382 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
25383 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
25384 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
25385 (void *) (v7m_psrs + i));
25386 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
25387 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
25388 for (i = 0;
25389 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
25390 i++)
25391 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
25392 (void *) (barrier_opt_names + i));
25393 #ifdef OBJ_ELF
25394 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
25395 {
25396 struct reloc_entry * entry = reloc_names + i;
25397
25398 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
25399 /* This makes encode_branch() use the EABI versions of this relocation. */
25400 entry->reloc = BFD_RELOC_UNUSED;
25401
25402 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
25403 }
25404 #endif
25405
25406 set_constant_flonums ();
25407
25408 /* Set the cpu variant based on the command-line options. We prefer
25409 -mcpu= over -march= if both are set (as for GCC); and we prefer
25410 -mfpu= over any other way of setting the floating point unit.
25411 Use of legacy options with new options are faulted. */
25412 if (legacy_cpu)
25413 {
25414 if (mcpu_cpu_opt || march_cpu_opt)
25415 as_bad (_("use of old and new-style options to set CPU type"));
25416
25417 selected_arch = *legacy_cpu;
25418 }
25419 else if (mcpu_cpu_opt)
25420 {
25421 selected_arch = *mcpu_cpu_opt;
25422 selected_ext = *mcpu_ext_opt;
25423 }
25424 else if (march_cpu_opt)
25425 {
25426 selected_arch = *march_cpu_opt;
25427 selected_ext = *march_ext_opt;
25428 }
25429 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
25430
25431 if (legacy_fpu)
25432 {
25433 if (mfpu_opt)
25434 as_bad (_("use of old and new-style options to set FPU type"));
25435
25436 selected_fpu = *legacy_fpu;
25437 }
25438 else if (mfpu_opt)
25439 selected_fpu = *mfpu_opt;
25440 else
25441 {
25442 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
25443 || defined (TE_NetBSD) || defined (TE_VXWORKS))
25444 /* Some environments specify a default FPU. If they don't, infer it
25445 from the processor. */
25446 if (mcpu_fpu_opt)
25447 selected_fpu = *mcpu_fpu_opt;
25448 else if (march_fpu_opt)
25449 selected_fpu = *march_fpu_opt;
25450 #else
25451 selected_fpu = fpu_default;
25452 #endif
25453 }
25454
25455 if (ARM_FEATURE_ZERO (selected_fpu))
25456 {
25457 if (!no_cpu_selected ())
25458 selected_fpu = fpu_default;
25459 else
25460 selected_fpu = fpu_arch_fpa;
25461 }
25462
25463 #ifdef CPU_DEFAULT
25464 if (ARM_FEATURE_ZERO (selected_arch))
25465 {
25466 selected_arch = cpu_default;
25467 selected_cpu = selected_arch;
25468 }
25469 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
25470 #else
25471 /* Autodection of feature mode: allow all features in cpu_variant but leave
25472 selected_cpu unset. It will be set in aeabi_set_public_attributes ()
25473 after all instruction have been processed and we can decide what CPU
25474 should be selected. */
25475 if (ARM_FEATURE_ZERO (selected_arch))
25476 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
25477 else
25478 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
25479 #endif
25480
25481 autoselect_thumb_from_cpu_variant ();
25482
25483 arm_arch_used = thumb_arch_used = arm_arch_none;
25484
25485 #if defined OBJ_COFF || defined OBJ_ELF
25486 {
25487 unsigned int flags = 0;
25488
25489 #if defined OBJ_ELF
25490 flags = meabi_flags;
25491
25492 switch (meabi_flags)
25493 {
25494 case EF_ARM_EABI_UNKNOWN:
25495 #endif
25496 /* Set the flags in the private structure. */
25497 if (uses_apcs_26) flags |= F_APCS26;
25498 if (support_interwork) flags |= F_INTERWORK;
25499 if (uses_apcs_float) flags |= F_APCS_FLOAT;
25500 if (pic_code) flags |= F_PIC;
25501 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
25502 flags |= F_SOFT_FLOAT;
25503
25504 switch (mfloat_abi_opt)
25505 {
25506 case ARM_FLOAT_ABI_SOFT:
25507 case ARM_FLOAT_ABI_SOFTFP:
25508 flags |= F_SOFT_FLOAT;
25509 break;
25510
25511 case ARM_FLOAT_ABI_HARD:
25512 if (flags & F_SOFT_FLOAT)
25513 as_bad (_("hard-float conflicts with specified fpu"));
25514 break;
25515 }
25516
25517 /* Using pure-endian doubles (even if soft-float). */
25518 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
25519 flags |= F_VFP_FLOAT;
25520
25521 #if defined OBJ_ELF
25522 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
25523 flags |= EF_ARM_MAVERICK_FLOAT;
25524 break;
25525
25526 case EF_ARM_EABI_VER4:
25527 case EF_ARM_EABI_VER5:
25528 /* No additional flags to set. */
25529 break;
25530
25531 default:
25532 abort ();
25533 }
25534 #endif
25535 bfd_set_private_flags (stdoutput, flags);
25536
25537 /* We have run out flags in the COFF header to encode the
25538 status of ATPCS support, so instead we create a dummy,
25539 empty, debug section called .arm.atpcs. */
25540 if (atpcs)
25541 {
25542 asection * sec;
25543
25544 sec = bfd_make_section (stdoutput, ".arm.atpcs");
25545
25546 if (sec != NULL)
25547 {
25548 bfd_set_section_flags
25549 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
25550 bfd_set_section_size (stdoutput, sec, 0);
25551 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
25552 }
25553 }
25554 }
25555 #endif
25556
25557 /* Record the CPU type as well. */
25558 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
25559 mach = bfd_mach_arm_iWMMXt2;
25560 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
25561 mach = bfd_mach_arm_iWMMXt;
25562 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
25563 mach = bfd_mach_arm_XScale;
25564 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
25565 mach = bfd_mach_arm_ep9312;
25566 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
25567 mach = bfd_mach_arm_5TE;
25568 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
25569 {
25570 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
25571 mach = bfd_mach_arm_5T;
25572 else
25573 mach = bfd_mach_arm_5;
25574 }
25575 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
25576 {
25577 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
25578 mach = bfd_mach_arm_4T;
25579 else
25580 mach = bfd_mach_arm_4;
25581 }
25582 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
25583 mach = bfd_mach_arm_3M;
25584 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
25585 mach = bfd_mach_arm_3;
25586 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
25587 mach = bfd_mach_arm_2a;
25588 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
25589 mach = bfd_mach_arm_2;
25590 else
25591 mach = bfd_mach_arm_unknown;
25592
25593 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
25594 }
25595
25596 /* Command line processing. */
25597
25598 /* md_parse_option
25599 Invocation line includes a switch not recognized by the base assembler.
25600 See if it's a processor-specific option.
25601
25602 This routine is somewhat complicated by the need for backwards
25603 compatibility (since older releases of gcc can't be changed).
25604 The new options try to make the interface as compatible as
25605 possible with GCC.
25606
25607 New options (supported) are:
25608
25609 -mcpu=<cpu name> Assemble for selected processor
25610 -march=<architecture name> Assemble for selected architecture
25611 -mfpu=<fpu architecture> Assemble for selected FPU.
25612 -EB/-mbig-endian Big-endian
25613 -EL/-mlittle-endian Little-endian
25614 -k Generate PIC code
25615 -mthumb Start in Thumb mode
25616 -mthumb-interwork Code supports ARM/Thumb interworking
25617
25618 -m[no-]warn-deprecated Warn about deprecated features
25619 -m[no-]warn-syms Warn when symbols match instructions
25620
25621 For now we will also provide support for:
25622
25623 -mapcs-32 32-bit Program counter
25624 -mapcs-26 26-bit Program counter
25625 -macps-float Floats passed in FP registers
25626 -mapcs-reentrant Reentrant code
25627 -matpcs
25628 (sometime these will probably be replaced with -mapcs=<list of options>
25629 and -matpcs=<list of options>)
25630
25631 The remaining options are only supported for back-wards compatibility.
25632 Cpu variants, the arm part is optional:
25633 -m[arm]1 Currently not supported.
25634 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
25635 -m[arm]3 Arm 3 processor
25636 -m[arm]6[xx], Arm 6 processors
25637 -m[arm]7[xx][t][[d]m] Arm 7 processors
25638 -m[arm]8[10] Arm 8 processors
25639 -m[arm]9[20][tdmi] Arm 9 processors
25640 -mstrongarm[110[0]] StrongARM processors
25641 -mxscale XScale processors
25642 -m[arm]v[2345[t[e]]] Arm architectures
25643 -mall All (except the ARM1)
25644 FP variants:
25645 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
25646 -mfpe-old (No float load/store multiples)
25647 -mvfpxd VFP Single precision
25648 -mvfp All VFP
25649 -mno-fpu Disable all floating point instructions
25650
25651 The following CPU names are recognized:
25652 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
25653 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
25654 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
25655 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
25656 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
25657 arm10t arm10e, arm1020t, arm1020e, arm10200e,
25658 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
25659
25660 */
25661
25662 const char * md_shortopts = "m:k";
25663
25664 #ifdef ARM_BI_ENDIAN
25665 #define OPTION_EB (OPTION_MD_BASE + 0)
25666 #define OPTION_EL (OPTION_MD_BASE + 1)
25667 #else
25668 #if TARGET_BYTES_BIG_ENDIAN
25669 #define OPTION_EB (OPTION_MD_BASE + 0)
25670 #else
25671 #define OPTION_EL (OPTION_MD_BASE + 1)
25672 #endif
25673 #endif
25674 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
25675 #define OPTION_FDPIC (OPTION_MD_BASE + 3)
25676
25677 struct option md_longopts[] =
25678 {
25679 #ifdef OPTION_EB
25680 {"EB", no_argument, NULL, OPTION_EB},
25681 #endif
25682 #ifdef OPTION_EL
25683 {"EL", no_argument, NULL, OPTION_EL},
25684 #endif
25685 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
25686 #ifdef OBJ_ELF
25687 {"fdpic", no_argument, NULL, OPTION_FDPIC},
25688 #endif
25689 {NULL, no_argument, NULL, 0}
25690 };
25691
25692 size_t md_longopts_size = sizeof (md_longopts);
25693
25694 struct arm_option_table
25695 {
25696 const char * option; /* Option name to match. */
25697 const char * help; /* Help information. */
25698 int * var; /* Variable to change. */
25699 int value; /* What to change it to. */
25700 const char * deprecated; /* If non-null, print this message. */
25701 };
25702
25703 struct arm_option_table arm_opts[] =
25704 {
25705 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
25706 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
25707 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
25708 &support_interwork, 1, NULL},
25709 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
25710 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
25711 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
25712 1, NULL},
25713 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
25714 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
25715 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
25716 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
25717 NULL},
25718
25719 /* These are recognized by the assembler, but have no affect on code. */
25720 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
25721 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
25722
25723 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
25724 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
25725 &warn_on_deprecated, 0, NULL},
25726 {"mwarn-syms", N_("warn about symbols that match instruction names [default]"), (int *) (& flag_warn_syms), TRUE, NULL},
25727 {"mno-warn-syms", N_("disable warnings about symobls that match instructions"), (int *) (& flag_warn_syms), FALSE, NULL},
25728 {NULL, NULL, NULL, 0, NULL}
25729 };
25730
25731 struct arm_legacy_option_table
25732 {
25733 const char * option; /* Option name to match. */
25734 const arm_feature_set ** var; /* Variable to change. */
25735 const arm_feature_set value; /* What to change it to. */
25736 const char * deprecated; /* If non-null, print this message. */
25737 };
25738
25739 const struct arm_legacy_option_table arm_legacy_opts[] =
25740 {
25741 /* DON'T add any new processors to this list -- we want the whole list
25742 to go away... Add them to the processors table instead. */
25743 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25744 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
25745 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25746 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
25747 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25748 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
25749 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25750 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
25751 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25752 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
25753 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25754 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
25755 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25756 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
25757 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25758 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
25759 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25760 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
25761 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25762 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
25763 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25764 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
25765 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25766 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
25767 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25768 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
25769 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25770 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
25771 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25772 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
25773 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25774 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
25775 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25776 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
25777 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25778 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
25779 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25780 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
25781 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25782 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
25783 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25784 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
25785 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25786 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
25787 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25788 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
25789 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25790 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25791 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25792 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
25793 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25794 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
25795 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25796 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
25797 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25798 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
25799 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25800 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
25801 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25802 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
25803 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25804 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
25805 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25806 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
25807 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25808 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
25809 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25810 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
25811 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
25812 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
25813 N_("use -mcpu=strongarm110")},
25814 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
25815 N_("use -mcpu=strongarm1100")},
25816 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
25817 N_("use -mcpu=strongarm1110")},
25818 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
25819 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
25820 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
25821
25822 /* Architecture variants -- don't add any more to this list either. */
25823 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25824 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
25825 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25826 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
25827 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25828 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
25829 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25830 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
25831 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25832 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
25833 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25834 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
25835 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25836 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
25837 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25838 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
25839 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25840 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
25841
25842 /* Floating point variants -- don't add any more to this list either. */
25843 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
25844 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
25845 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
25846 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
25847 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
25848
25849 {NULL, NULL, ARM_ARCH_NONE, NULL}
25850 };
25851
25852 struct arm_cpu_option_table
25853 {
25854 const char * name;
25855 size_t name_len;
25856 const arm_feature_set value;
25857 const arm_feature_set ext;
25858 /* For some CPUs we assume an FPU unless the user explicitly sets
25859 -mfpu=... */
25860 const arm_feature_set default_fpu;
25861 /* The canonical name of the CPU, or NULL to use NAME converted to upper
25862 case. */
25863 const char * canonical_name;
25864 };
25865
25866 /* This list should, at a minimum, contain all the cpu names
25867 recognized by GCC. */
25868 #define ARM_CPU_OPT(N, CN, V, E, DF) { N, sizeof (N) - 1, V, E, DF, CN }
25869
25870 static const struct arm_cpu_option_table arm_cpus[] =
25871 {
25872 ARM_CPU_OPT ("all", NULL, ARM_ANY,
25873 ARM_ARCH_NONE,
25874 FPU_ARCH_FPA),
25875 ARM_CPU_OPT ("arm1", NULL, ARM_ARCH_V1,
25876 ARM_ARCH_NONE,
25877 FPU_ARCH_FPA),
25878 ARM_CPU_OPT ("arm2", NULL, ARM_ARCH_V2,
25879 ARM_ARCH_NONE,
25880 FPU_ARCH_FPA),
25881 ARM_CPU_OPT ("arm250", NULL, ARM_ARCH_V2S,
25882 ARM_ARCH_NONE,
25883 FPU_ARCH_FPA),
25884 ARM_CPU_OPT ("arm3", NULL, ARM_ARCH_V2S,
25885 ARM_ARCH_NONE,
25886 FPU_ARCH_FPA),
25887 ARM_CPU_OPT ("arm6", NULL, ARM_ARCH_V3,
25888 ARM_ARCH_NONE,
25889 FPU_ARCH_FPA),
25890 ARM_CPU_OPT ("arm60", NULL, ARM_ARCH_V3,
25891 ARM_ARCH_NONE,
25892 FPU_ARCH_FPA),
25893 ARM_CPU_OPT ("arm600", NULL, ARM_ARCH_V3,
25894 ARM_ARCH_NONE,
25895 FPU_ARCH_FPA),
25896 ARM_CPU_OPT ("arm610", NULL, ARM_ARCH_V3,
25897 ARM_ARCH_NONE,
25898 FPU_ARCH_FPA),
25899 ARM_CPU_OPT ("arm620", NULL, ARM_ARCH_V3,
25900 ARM_ARCH_NONE,
25901 FPU_ARCH_FPA),
25902 ARM_CPU_OPT ("arm7", NULL, ARM_ARCH_V3,
25903 ARM_ARCH_NONE,
25904 FPU_ARCH_FPA),
25905 ARM_CPU_OPT ("arm7m", NULL, ARM_ARCH_V3M,
25906 ARM_ARCH_NONE,
25907 FPU_ARCH_FPA),
25908 ARM_CPU_OPT ("arm7d", NULL, ARM_ARCH_V3,
25909 ARM_ARCH_NONE,
25910 FPU_ARCH_FPA),
25911 ARM_CPU_OPT ("arm7dm", NULL, ARM_ARCH_V3M,
25912 ARM_ARCH_NONE,
25913 FPU_ARCH_FPA),
25914 ARM_CPU_OPT ("arm7di", NULL, ARM_ARCH_V3,
25915 ARM_ARCH_NONE,
25916 FPU_ARCH_FPA),
25917 ARM_CPU_OPT ("arm7dmi", NULL, ARM_ARCH_V3M,
25918 ARM_ARCH_NONE,
25919 FPU_ARCH_FPA),
25920 ARM_CPU_OPT ("arm70", NULL, ARM_ARCH_V3,
25921 ARM_ARCH_NONE,
25922 FPU_ARCH_FPA),
25923 ARM_CPU_OPT ("arm700", NULL, ARM_ARCH_V3,
25924 ARM_ARCH_NONE,
25925 FPU_ARCH_FPA),
25926 ARM_CPU_OPT ("arm700i", NULL, ARM_ARCH_V3,
25927 ARM_ARCH_NONE,
25928 FPU_ARCH_FPA),
25929 ARM_CPU_OPT ("arm710", NULL, ARM_ARCH_V3,
25930 ARM_ARCH_NONE,
25931 FPU_ARCH_FPA),
25932 ARM_CPU_OPT ("arm710t", NULL, ARM_ARCH_V4T,
25933 ARM_ARCH_NONE,
25934 FPU_ARCH_FPA),
25935 ARM_CPU_OPT ("arm720", NULL, ARM_ARCH_V3,
25936 ARM_ARCH_NONE,
25937 FPU_ARCH_FPA),
25938 ARM_CPU_OPT ("arm720t", NULL, ARM_ARCH_V4T,
25939 ARM_ARCH_NONE,
25940 FPU_ARCH_FPA),
25941 ARM_CPU_OPT ("arm740t", NULL, ARM_ARCH_V4T,
25942 ARM_ARCH_NONE,
25943 FPU_ARCH_FPA),
25944 ARM_CPU_OPT ("arm710c", NULL, ARM_ARCH_V3,
25945 ARM_ARCH_NONE,
25946 FPU_ARCH_FPA),
25947 ARM_CPU_OPT ("arm7100", NULL, ARM_ARCH_V3,
25948 ARM_ARCH_NONE,
25949 FPU_ARCH_FPA),
25950 ARM_CPU_OPT ("arm7500", NULL, ARM_ARCH_V3,
25951 ARM_ARCH_NONE,
25952 FPU_ARCH_FPA),
25953 ARM_CPU_OPT ("arm7500fe", NULL, ARM_ARCH_V3,
25954 ARM_ARCH_NONE,
25955 FPU_ARCH_FPA),
25956 ARM_CPU_OPT ("arm7t", NULL, ARM_ARCH_V4T,
25957 ARM_ARCH_NONE,
25958 FPU_ARCH_FPA),
25959 ARM_CPU_OPT ("arm7tdmi", NULL, ARM_ARCH_V4T,
25960 ARM_ARCH_NONE,
25961 FPU_ARCH_FPA),
25962 ARM_CPU_OPT ("arm7tdmi-s", NULL, ARM_ARCH_V4T,
25963 ARM_ARCH_NONE,
25964 FPU_ARCH_FPA),
25965 ARM_CPU_OPT ("arm8", NULL, ARM_ARCH_V4,
25966 ARM_ARCH_NONE,
25967 FPU_ARCH_FPA),
25968 ARM_CPU_OPT ("arm810", NULL, ARM_ARCH_V4,
25969 ARM_ARCH_NONE,
25970 FPU_ARCH_FPA),
25971 ARM_CPU_OPT ("strongarm", NULL, ARM_ARCH_V4,
25972 ARM_ARCH_NONE,
25973 FPU_ARCH_FPA),
25974 ARM_CPU_OPT ("strongarm1", NULL, ARM_ARCH_V4,
25975 ARM_ARCH_NONE,
25976 FPU_ARCH_FPA),
25977 ARM_CPU_OPT ("strongarm110", NULL, ARM_ARCH_V4,
25978 ARM_ARCH_NONE,
25979 FPU_ARCH_FPA),
25980 ARM_CPU_OPT ("strongarm1100", NULL, ARM_ARCH_V4,
25981 ARM_ARCH_NONE,
25982 FPU_ARCH_FPA),
25983 ARM_CPU_OPT ("strongarm1110", NULL, ARM_ARCH_V4,
25984 ARM_ARCH_NONE,
25985 FPU_ARCH_FPA),
25986 ARM_CPU_OPT ("arm9", NULL, ARM_ARCH_V4T,
25987 ARM_ARCH_NONE,
25988 FPU_ARCH_FPA),
25989 ARM_CPU_OPT ("arm920", "ARM920T", ARM_ARCH_V4T,
25990 ARM_ARCH_NONE,
25991 FPU_ARCH_FPA),
25992 ARM_CPU_OPT ("arm920t", NULL, ARM_ARCH_V4T,
25993 ARM_ARCH_NONE,
25994 FPU_ARCH_FPA),
25995 ARM_CPU_OPT ("arm922t", NULL, ARM_ARCH_V4T,
25996 ARM_ARCH_NONE,
25997 FPU_ARCH_FPA),
25998 ARM_CPU_OPT ("arm940t", NULL, ARM_ARCH_V4T,
25999 ARM_ARCH_NONE,
26000 FPU_ARCH_FPA),
26001 ARM_CPU_OPT ("arm9tdmi", NULL, ARM_ARCH_V4T,
26002 ARM_ARCH_NONE,
26003 FPU_ARCH_FPA),
26004 ARM_CPU_OPT ("fa526", NULL, ARM_ARCH_V4,
26005 ARM_ARCH_NONE,
26006 FPU_ARCH_FPA),
26007 ARM_CPU_OPT ("fa626", NULL, ARM_ARCH_V4,
26008 ARM_ARCH_NONE,
26009 FPU_ARCH_FPA),
26010
26011 /* For V5 or later processors we default to using VFP; but the user
26012 should really set the FPU type explicitly. */
26013 ARM_CPU_OPT ("arm9e-r0", NULL, ARM_ARCH_V5TExP,
26014 ARM_ARCH_NONE,
26015 FPU_ARCH_VFP_V2),
26016 ARM_CPU_OPT ("arm9e", NULL, ARM_ARCH_V5TE,
26017 ARM_ARCH_NONE,
26018 FPU_ARCH_VFP_V2),
26019 ARM_CPU_OPT ("arm926ej", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26020 ARM_ARCH_NONE,
26021 FPU_ARCH_VFP_V2),
26022 ARM_CPU_OPT ("arm926ejs", "ARM926EJ-S", ARM_ARCH_V5TEJ,
26023 ARM_ARCH_NONE,
26024 FPU_ARCH_VFP_V2),
26025 ARM_CPU_OPT ("arm926ej-s", NULL, ARM_ARCH_V5TEJ,
26026 ARM_ARCH_NONE,
26027 FPU_ARCH_VFP_V2),
26028 ARM_CPU_OPT ("arm946e-r0", NULL, ARM_ARCH_V5TExP,
26029 ARM_ARCH_NONE,
26030 FPU_ARCH_VFP_V2),
26031 ARM_CPU_OPT ("arm946e", "ARM946E-S", ARM_ARCH_V5TE,
26032 ARM_ARCH_NONE,
26033 FPU_ARCH_VFP_V2),
26034 ARM_CPU_OPT ("arm946e-s", NULL, ARM_ARCH_V5TE,
26035 ARM_ARCH_NONE,
26036 FPU_ARCH_VFP_V2),
26037 ARM_CPU_OPT ("arm966e-r0", NULL, ARM_ARCH_V5TExP,
26038 ARM_ARCH_NONE,
26039 FPU_ARCH_VFP_V2),
26040 ARM_CPU_OPT ("arm966e", "ARM966E-S", ARM_ARCH_V5TE,
26041 ARM_ARCH_NONE,
26042 FPU_ARCH_VFP_V2),
26043 ARM_CPU_OPT ("arm966e-s", NULL, ARM_ARCH_V5TE,
26044 ARM_ARCH_NONE,
26045 FPU_ARCH_VFP_V2),
26046 ARM_CPU_OPT ("arm968e-s", NULL, ARM_ARCH_V5TE,
26047 ARM_ARCH_NONE,
26048 FPU_ARCH_VFP_V2),
26049 ARM_CPU_OPT ("arm10t", NULL, ARM_ARCH_V5T,
26050 ARM_ARCH_NONE,
26051 FPU_ARCH_VFP_V1),
26052 ARM_CPU_OPT ("arm10tdmi", NULL, ARM_ARCH_V5T,
26053 ARM_ARCH_NONE,
26054 FPU_ARCH_VFP_V1),
26055 ARM_CPU_OPT ("arm10e", NULL, ARM_ARCH_V5TE,
26056 ARM_ARCH_NONE,
26057 FPU_ARCH_VFP_V2),
26058 ARM_CPU_OPT ("arm1020", "ARM1020E", ARM_ARCH_V5TE,
26059 ARM_ARCH_NONE,
26060 FPU_ARCH_VFP_V2),
26061 ARM_CPU_OPT ("arm1020t", NULL, ARM_ARCH_V5T,
26062 ARM_ARCH_NONE,
26063 FPU_ARCH_VFP_V1),
26064 ARM_CPU_OPT ("arm1020e", NULL, ARM_ARCH_V5TE,
26065 ARM_ARCH_NONE,
26066 FPU_ARCH_VFP_V2),
26067 ARM_CPU_OPT ("arm1022e", NULL, ARM_ARCH_V5TE,
26068 ARM_ARCH_NONE,
26069 FPU_ARCH_VFP_V2),
26070 ARM_CPU_OPT ("arm1026ejs", "ARM1026EJ-S", ARM_ARCH_V5TEJ,
26071 ARM_ARCH_NONE,
26072 FPU_ARCH_VFP_V2),
26073 ARM_CPU_OPT ("arm1026ej-s", NULL, ARM_ARCH_V5TEJ,
26074 ARM_ARCH_NONE,
26075 FPU_ARCH_VFP_V2),
26076 ARM_CPU_OPT ("fa606te", NULL, ARM_ARCH_V5TE,
26077 ARM_ARCH_NONE,
26078 FPU_ARCH_VFP_V2),
26079 ARM_CPU_OPT ("fa616te", NULL, ARM_ARCH_V5TE,
26080 ARM_ARCH_NONE,
26081 FPU_ARCH_VFP_V2),
26082 ARM_CPU_OPT ("fa626te", NULL, ARM_ARCH_V5TE,
26083 ARM_ARCH_NONE,
26084 FPU_ARCH_VFP_V2),
26085 ARM_CPU_OPT ("fmp626", NULL, ARM_ARCH_V5TE,
26086 ARM_ARCH_NONE,
26087 FPU_ARCH_VFP_V2),
26088 ARM_CPU_OPT ("fa726te", NULL, ARM_ARCH_V5TE,
26089 ARM_ARCH_NONE,
26090 FPU_ARCH_VFP_V2),
26091 ARM_CPU_OPT ("arm1136js", "ARM1136J-S", ARM_ARCH_V6,
26092 ARM_ARCH_NONE,
26093 FPU_NONE),
26094 ARM_CPU_OPT ("arm1136j-s", NULL, ARM_ARCH_V6,
26095 ARM_ARCH_NONE,
26096 FPU_NONE),
26097 ARM_CPU_OPT ("arm1136jfs", "ARM1136JF-S", ARM_ARCH_V6,
26098 ARM_ARCH_NONE,
26099 FPU_ARCH_VFP_V2),
26100 ARM_CPU_OPT ("arm1136jf-s", NULL, ARM_ARCH_V6,
26101 ARM_ARCH_NONE,
26102 FPU_ARCH_VFP_V2),
26103 ARM_CPU_OPT ("mpcore", "MPCore", ARM_ARCH_V6K,
26104 ARM_ARCH_NONE,
26105 FPU_ARCH_VFP_V2),
26106 ARM_CPU_OPT ("mpcorenovfp", "MPCore", ARM_ARCH_V6K,
26107 ARM_ARCH_NONE,
26108 FPU_NONE),
26109 ARM_CPU_OPT ("arm1156t2-s", NULL, ARM_ARCH_V6T2,
26110 ARM_ARCH_NONE,
26111 FPU_NONE),
26112 ARM_CPU_OPT ("arm1156t2f-s", NULL, ARM_ARCH_V6T2,
26113 ARM_ARCH_NONE,
26114 FPU_ARCH_VFP_V2),
26115 ARM_CPU_OPT ("arm1176jz-s", NULL, ARM_ARCH_V6KZ,
26116 ARM_ARCH_NONE,
26117 FPU_NONE),
26118 ARM_CPU_OPT ("arm1176jzf-s", NULL, ARM_ARCH_V6KZ,
26119 ARM_ARCH_NONE,
26120 FPU_ARCH_VFP_V2),
26121 ARM_CPU_OPT ("cortex-a5", "Cortex-A5", ARM_ARCH_V7A,
26122 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26123 FPU_NONE),
26124 ARM_CPU_OPT ("cortex-a7", "Cortex-A7", ARM_ARCH_V7VE,
26125 ARM_ARCH_NONE,
26126 FPU_ARCH_NEON_VFP_V4),
26127 ARM_CPU_OPT ("cortex-a8", "Cortex-A8", ARM_ARCH_V7A,
26128 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26129 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26130 ARM_CPU_OPT ("cortex-a9", "Cortex-A9", ARM_ARCH_V7A,
26131 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26132 ARM_FEATURE_COPROC (FPU_VFP_V3 | FPU_NEON_EXT_V1)),
26133 ARM_CPU_OPT ("cortex-a12", "Cortex-A12", ARM_ARCH_V7VE,
26134 ARM_ARCH_NONE,
26135 FPU_ARCH_NEON_VFP_V4),
26136 ARM_CPU_OPT ("cortex-a15", "Cortex-A15", ARM_ARCH_V7VE,
26137 ARM_ARCH_NONE,
26138 FPU_ARCH_NEON_VFP_V4),
26139 ARM_CPU_OPT ("cortex-a17", "Cortex-A17", ARM_ARCH_V7VE,
26140 ARM_ARCH_NONE,
26141 FPU_ARCH_NEON_VFP_V4),
26142 ARM_CPU_OPT ("cortex-a32", "Cortex-A32", ARM_ARCH_V8A,
26143 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26144 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26145 ARM_CPU_OPT ("cortex-a35", "Cortex-A35", ARM_ARCH_V8A,
26146 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26147 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26148 ARM_CPU_OPT ("cortex-a53", "Cortex-A53", ARM_ARCH_V8A,
26149 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26150 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26151 ARM_CPU_OPT ("cortex-a55", "Cortex-A55", ARM_ARCH_V8_2A,
26152 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26153 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
26154 ARM_CPU_OPT ("cortex-a57", "Cortex-A57", ARM_ARCH_V8A,
26155 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26156 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26157 ARM_CPU_OPT ("cortex-a72", "Cortex-A72", ARM_ARCH_V8A,
26158 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26159 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26160 ARM_CPU_OPT ("cortex-a73", "Cortex-A73", ARM_ARCH_V8A,
26161 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26162 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26163 ARM_CPU_OPT ("cortex-a75", "Cortex-A75", ARM_ARCH_V8_2A,
26164 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26165 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_DOTPROD),
26166 ARM_CPU_OPT ("cortex-r4", "Cortex-R4", ARM_ARCH_V7R,
26167 ARM_ARCH_NONE,
26168 FPU_NONE),
26169 ARM_CPU_OPT ("cortex-r4f", "Cortex-R4F", ARM_ARCH_V7R,
26170 ARM_ARCH_NONE,
26171 FPU_ARCH_VFP_V3D16),
26172 ARM_CPU_OPT ("cortex-r5", "Cortex-R5", ARM_ARCH_V7R,
26173 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26174 FPU_NONE),
26175 ARM_CPU_OPT ("cortex-r7", "Cortex-R7", ARM_ARCH_V7R,
26176 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26177 FPU_ARCH_VFP_V3D16),
26178 ARM_CPU_OPT ("cortex-r8", "Cortex-R8", ARM_ARCH_V7R,
26179 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV),
26180 FPU_ARCH_VFP_V3D16),
26181 ARM_CPU_OPT ("cortex-r52", "Cortex-R52", ARM_ARCH_V8R,
26182 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26183 FPU_ARCH_NEON_VFP_ARMV8),
26184 ARM_CPU_OPT ("cortex-m33", "Cortex-M33", ARM_ARCH_V8M_MAIN,
26185 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26186 FPU_NONE),
26187 ARM_CPU_OPT ("cortex-m23", "Cortex-M23", ARM_ARCH_V8M_BASE,
26188 ARM_ARCH_NONE,
26189 FPU_NONE),
26190 ARM_CPU_OPT ("cortex-m7", "Cortex-M7", ARM_ARCH_V7EM,
26191 ARM_ARCH_NONE,
26192 FPU_NONE),
26193 ARM_CPU_OPT ("cortex-m4", "Cortex-M4", ARM_ARCH_V7EM,
26194 ARM_ARCH_NONE,
26195 FPU_NONE),
26196 ARM_CPU_OPT ("cortex-m3", "Cortex-M3", ARM_ARCH_V7M,
26197 ARM_ARCH_NONE,
26198 FPU_NONE),
26199 ARM_CPU_OPT ("cortex-m1", "Cortex-M1", ARM_ARCH_V6SM,
26200 ARM_ARCH_NONE,
26201 FPU_NONE),
26202 ARM_CPU_OPT ("cortex-m0", "Cortex-M0", ARM_ARCH_V6SM,
26203 ARM_ARCH_NONE,
26204 FPU_NONE),
26205 ARM_CPU_OPT ("cortex-m0plus", "Cortex-M0+", ARM_ARCH_V6SM,
26206 ARM_ARCH_NONE,
26207 FPU_NONE),
26208 ARM_CPU_OPT ("exynos-m1", "Samsung Exynos M1", ARM_ARCH_V8A,
26209 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26210 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26211
26212 /* ??? XSCALE is really an architecture. */
26213 ARM_CPU_OPT ("xscale", NULL, ARM_ARCH_XSCALE,
26214 ARM_ARCH_NONE,
26215 FPU_ARCH_VFP_V2),
26216
26217 /* ??? iwmmxt is not a processor. */
26218 ARM_CPU_OPT ("iwmmxt", NULL, ARM_ARCH_IWMMXT,
26219 ARM_ARCH_NONE,
26220 FPU_ARCH_VFP_V2),
26221 ARM_CPU_OPT ("iwmmxt2", NULL, ARM_ARCH_IWMMXT2,
26222 ARM_ARCH_NONE,
26223 FPU_ARCH_VFP_V2),
26224 ARM_CPU_OPT ("i80200", NULL, ARM_ARCH_XSCALE,
26225 ARM_ARCH_NONE,
26226 FPU_ARCH_VFP_V2),
26227
26228 /* Maverick. */
26229 ARM_CPU_OPT ("ep9312", "ARM920T",
26230 ARM_FEATURE_LOW (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
26231 ARM_ARCH_NONE, FPU_ARCH_MAVERICK),
26232
26233 /* Marvell processors. */
26234 ARM_CPU_OPT ("marvell-pj4", NULL, ARM_ARCH_V7A,
26235 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26236 FPU_ARCH_VFP_V3D16),
26237 ARM_CPU_OPT ("marvell-whitney", NULL, ARM_ARCH_V7A,
26238 ARM_FEATURE_CORE_LOW (ARM_EXT_MP | ARM_EXT_SEC),
26239 FPU_ARCH_NEON_VFP_V4),
26240
26241 /* APM X-Gene family. */
26242 ARM_CPU_OPT ("xgene1", "APM X-Gene 1", ARM_ARCH_V8A,
26243 ARM_ARCH_NONE,
26244 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26245 ARM_CPU_OPT ("xgene2", "APM X-Gene 2", ARM_ARCH_V8A,
26246 ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26247 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8),
26248
26249 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
26250 };
26251 #undef ARM_CPU_OPT
26252
26253 struct arm_arch_option_table
26254 {
26255 const char * name;
26256 size_t name_len;
26257 const arm_feature_set value;
26258 const arm_feature_set default_fpu;
26259 };
26260
26261 /* This list should, at a minimum, contain all the architecture names
26262 recognized by GCC. */
26263 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
26264
26265 static const struct arm_arch_option_table arm_archs[] =
26266 {
26267 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
26268 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
26269 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
26270 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
26271 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
26272 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
26273 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
26274 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
26275 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
26276 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
26277 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
26278 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
26279 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
26280 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
26281 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
26282 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
26283 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
26284 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
26285 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
26286 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
26287 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
26288 /* The official spelling of this variant is ARMv6KZ, the name "armv6zk" is
26289 kept to preserve existing behaviour. */
26290 ARM_ARCH_OPT ("armv6kz", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26291 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6KZ, FPU_ARCH_VFP),
26292 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
26293 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
26294 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
26295 /* The official spelling of this variant is ARMv6KZ, the name "armv6zkt2" is
26296 kept to preserve existing behaviour. */
26297 ARM_ARCH_OPT ("armv6kzt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26298 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6KZT2, FPU_ARCH_VFP),
26299 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
26300 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
26301 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
26302 /* The official spelling of the ARMv7 profile variants is the dashed form.
26303 Accept the non-dashed form for compatibility with old toolchains. */
26304 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26305 ARM_ARCH_OPT ("armv7ve", ARM_ARCH_V7VE, FPU_ARCH_VFP),
26306 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26307 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26308 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
26309 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
26310 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
26311 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
26312 ARM_ARCH_OPT ("armv8-m.base", ARM_ARCH_V8M_BASE, FPU_ARCH_VFP),
26313 ARM_ARCH_OPT ("armv8-m.main", ARM_ARCH_V8M_MAIN, FPU_ARCH_VFP),
26314 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
26315 ARM_ARCH_OPT ("armv8.1-a", ARM_ARCH_V8_1A, FPU_ARCH_VFP),
26316 ARM_ARCH_OPT ("armv8.2-a", ARM_ARCH_V8_2A, FPU_ARCH_VFP),
26317 ARM_ARCH_OPT ("armv8.3-a", ARM_ARCH_V8_3A, FPU_ARCH_VFP),
26318 ARM_ARCH_OPT ("armv8-r", ARM_ARCH_V8R, FPU_ARCH_VFP),
26319 ARM_ARCH_OPT ("armv8.4-a", ARM_ARCH_V8_4A, FPU_ARCH_VFP),
26320 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
26321 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
26322 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
26323 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
26324 };
26325 #undef ARM_ARCH_OPT
26326
26327 /* ISA extensions in the co-processor and main instruction set space. */
26328
26329 struct arm_option_extension_value_table
26330 {
26331 const char * name;
26332 size_t name_len;
26333 const arm_feature_set merge_value;
26334 const arm_feature_set clear_value;
26335 /* List of architectures for which an extension is available. ARM_ARCH_NONE
26336 indicates that an extension is available for all architectures while
26337 ARM_ANY marks an empty entry. */
26338 const arm_feature_set allowed_archs[2];
26339 };
26340
26341 /* The following table must be in alphabetical order with a NULL last entry. */
26342
26343 #define ARM_EXT_OPT(N, M, C, AA) { N, sizeof (N) - 1, M, C, { AA, ARM_ANY } }
26344 #define ARM_EXT_OPT2(N, M, C, AA1, AA2) { N, sizeof (N) - 1, M, C, {AA1, AA2} }
26345
26346 static const struct arm_option_extension_value_table arm_extensions[] =
26347 {
26348 ARM_EXT_OPT ("crc", ARCH_CRC_ARMV8, ARM_FEATURE_COPROC (CRC_EXT_ARMV8),
26349 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
26350 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
26351 ARM_FEATURE_COPROC (FPU_CRYPTO_ARMV8),
26352 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
26353 ARM_EXT_OPT ("dotprod", FPU_ARCH_DOTPROD_NEON_VFP_ARMV8,
26354 ARM_FEATURE_COPROC (FPU_NEON_EXT_DOTPROD),
26355 ARM_ARCH_V8_2A),
26356 ARM_EXT_OPT ("dsp", ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26357 ARM_FEATURE_CORE_LOW (ARM_EXT_V5ExP | ARM_EXT_V6_DSP),
26358 ARM_FEATURE_CORE (ARM_EXT_V7M, ARM_EXT2_V8M)),
26359 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8, ARM_FEATURE_COPROC (FPU_VFP_ARMV8),
26360 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
26361 ARM_EXT_OPT ("fp16", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26362 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST),
26363 ARM_ARCH_V8_2A),
26364 ARM_EXT_OPT ("fp16fml", ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26365 | ARM_EXT2_FP16_FML),
26366 ARM_FEATURE_CORE_HIGH (ARM_EXT2_FP16_INST
26367 | ARM_EXT2_FP16_FML),
26368 ARM_ARCH_V8_2A),
26369 ARM_EXT_OPT2 ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
26370 ARM_FEATURE_CORE_LOW (ARM_EXT_ADIV | ARM_EXT_DIV),
26371 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26372 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
26373 /* Duplicate entry for the purpose of allowing ARMv7 to match in presence of
26374 Thumb divide instruction. Due to this having the same name as the
26375 previous entry, this will be ignored when doing command-line parsing and
26376 only considered by build attribute selection code. */
26377 ARM_EXT_OPT ("idiv", ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26378 ARM_FEATURE_CORE_LOW (ARM_EXT_DIV),
26379 ARM_FEATURE_CORE_LOW (ARM_EXT_V7)),
26380 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT),
26381 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT), ARM_ARCH_NONE),
26382 ARM_EXT_OPT ("iwmmxt2", ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2),
26383 ARM_FEATURE_COPROC (ARM_CEXT_IWMMXT2), ARM_ARCH_NONE),
26384 ARM_EXT_OPT ("maverick", ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK),
26385 ARM_FEATURE_COPROC (ARM_CEXT_MAVERICK), ARM_ARCH_NONE),
26386 ARM_EXT_OPT2 ("mp", ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
26387 ARM_FEATURE_CORE_LOW (ARM_EXT_MP),
26388 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A),
26389 ARM_FEATURE_CORE_LOW (ARM_EXT_V7R)),
26390 ARM_EXT_OPT ("os", ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26391 ARM_FEATURE_CORE_LOW (ARM_EXT_OS),
26392 ARM_FEATURE_CORE_LOW (ARM_EXT_V6M)),
26393 ARM_EXT_OPT ("pan", ARM_FEATURE_CORE_HIGH (ARM_EXT2_PAN),
26394 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_PAN, 0),
26395 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
26396 ARM_EXT_OPT ("ras", ARM_FEATURE_CORE_HIGH (ARM_EXT2_RAS),
26397 ARM_FEATURE (ARM_EXT_V8, ARM_EXT2_RAS, 0),
26398 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
26399 ARM_EXT_OPT ("rdma", FPU_ARCH_NEON_VFP_ARMV8_1,
26400 ARM_FEATURE_COPROC (FPU_NEON_ARMV8 | FPU_NEON_EXT_RDMA),
26401 ARM_FEATURE_CORE_HIGH (ARM_EXT2_V8A)),
26402 ARM_EXT_OPT2 ("sec", ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26403 ARM_FEATURE_CORE_LOW (ARM_EXT_SEC),
26404 ARM_FEATURE_CORE_LOW (ARM_EXT_V6K),
26405 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26406 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
26407 ARM_FEATURE_COPROC (FPU_NEON_ARMV8),
26408 ARM_FEATURE_CORE_LOW (ARM_EXT_V8)),
26409 ARM_EXT_OPT ("virt", ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT | ARM_EXT_ADIV
26410 | ARM_EXT_DIV),
26411 ARM_FEATURE_CORE_LOW (ARM_EXT_VIRT),
26412 ARM_FEATURE_CORE_LOW (ARM_EXT_V7A)),
26413 ARM_EXT_OPT ("xscale",ARM_FEATURE_COPROC (ARM_CEXT_XSCALE),
26414 ARM_FEATURE_COPROC (ARM_CEXT_XSCALE), ARM_ARCH_NONE),
26415 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, { ARM_ARCH_NONE, ARM_ARCH_NONE } }
26416 };
26417 #undef ARM_EXT_OPT
26418
26419 /* ISA floating-point and Advanced SIMD extensions. */
26420 struct arm_option_fpu_value_table
26421 {
26422 const char * name;
26423 const arm_feature_set value;
26424 };
26425
26426 /* This list should, at a minimum, contain all the fpu names
26427 recognized by GCC. */
26428 static const struct arm_option_fpu_value_table arm_fpus[] =
26429 {
26430 {"softfpa", FPU_NONE},
26431 {"fpe", FPU_ARCH_FPE},
26432 {"fpe2", FPU_ARCH_FPE},
26433 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
26434 {"fpa", FPU_ARCH_FPA},
26435 {"fpa10", FPU_ARCH_FPA},
26436 {"fpa11", FPU_ARCH_FPA},
26437 {"arm7500fe", FPU_ARCH_FPA},
26438 {"softvfp", FPU_ARCH_VFP},
26439 {"softvfp+vfp", FPU_ARCH_VFP_V2},
26440 {"vfp", FPU_ARCH_VFP_V2},
26441 {"vfp9", FPU_ARCH_VFP_V2},
26442 {"vfp3", FPU_ARCH_VFP_V3}, /* Undocumented, use vfpv3. */
26443 {"vfp10", FPU_ARCH_VFP_V2},
26444 {"vfp10-r0", FPU_ARCH_VFP_V1},
26445 {"vfpxd", FPU_ARCH_VFP_V1xD},
26446 {"vfpv2", FPU_ARCH_VFP_V2},
26447 {"vfpv3", FPU_ARCH_VFP_V3},
26448 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
26449 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
26450 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
26451 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
26452 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
26453 {"arm1020t", FPU_ARCH_VFP_V1},
26454 {"arm1020e", FPU_ARCH_VFP_V2},
26455 {"arm1136jfs", FPU_ARCH_VFP_V2}, /* Undocumented, use arm1136jf-s. */
26456 {"arm1136jf-s", FPU_ARCH_VFP_V2},
26457 {"maverick", FPU_ARCH_MAVERICK},
26458 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
26459 {"neon-vfpv3", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
26460 {"neon-fp16", FPU_ARCH_NEON_FP16},
26461 {"vfpv4", FPU_ARCH_VFP_V4},
26462 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
26463 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
26464 {"fpv5-d16", FPU_ARCH_VFP_V5D16},
26465 {"fpv5-sp-d16", FPU_ARCH_VFP_V5_SP_D16},
26466 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
26467 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
26468 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
26469 {"crypto-neon-fp-armv8",
26470 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
26471 {"neon-fp-armv8.1", FPU_ARCH_NEON_VFP_ARMV8_1},
26472 {"crypto-neon-fp-armv8.1",
26473 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8_1},
26474 {NULL, ARM_ARCH_NONE}
26475 };
26476
26477 struct arm_option_value_table
26478 {
26479 const char *name;
26480 long value;
26481 };
26482
26483 static const struct arm_option_value_table arm_float_abis[] =
26484 {
26485 {"hard", ARM_FLOAT_ABI_HARD},
26486 {"softfp", ARM_FLOAT_ABI_SOFTFP},
26487 {"soft", ARM_FLOAT_ABI_SOFT},
26488 {NULL, 0}
26489 };
26490
26491 #ifdef OBJ_ELF
26492 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
26493 static const struct arm_option_value_table arm_eabis[] =
26494 {
26495 {"gnu", EF_ARM_EABI_UNKNOWN},
26496 {"4", EF_ARM_EABI_VER4},
26497 {"5", EF_ARM_EABI_VER5},
26498 {NULL, 0}
26499 };
26500 #endif
26501
26502 struct arm_long_option_table
26503 {
26504 const char * option; /* Substring to match. */
26505 const char * help; /* Help information. */
26506 int (* func) (const char * subopt); /* Function to decode sub-option. */
26507 const char * deprecated; /* If non-null, print this message. */
26508 };
26509
26510 static bfd_boolean
26511 arm_parse_extension (const char *str, const arm_feature_set *opt_set,
26512 arm_feature_set *ext_set)
26513 {
26514 /* We insist on extensions being specified in alphabetical order, and with
26515 extensions being added before being removed. We achieve this by having
26516 the global ARM_EXTENSIONS table in alphabetical order, and using the
26517 ADDING_VALUE variable to indicate whether we are adding an extension (1)
26518 or removing it (0) and only allowing it to change in the order
26519 -1 -> 1 -> 0. */
26520 const struct arm_option_extension_value_table * opt = NULL;
26521 const arm_feature_set arm_any = ARM_ANY;
26522 int adding_value = -1;
26523
26524 while (str != NULL && *str != 0)
26525 {
26526 const char *ext;
26527 size_t len;
26528
26529 if (*str != '+')
26530 {
26531 as_bad (_("invalid architectural extension"));
26532 return FALSE;
26533 }
26534
26535 str++;
26536 ext = strchr (str, '+');
26537
26538 if (ext != NULL)
26539 len = ext - str;
26540 else
26541 len = strlen (str);
26542
26543 if (len >= 2 && strncmp (str, "no", 2) == 0)
26544 {
26545 if (adding_value != 0)
26546 {
26547 adding_value = 0;
26548 opt = arm_extensions;
26549 }
26550
26551 len -= 2;
26552 str += 2;
26553 }
26554 else if (len > 0)
26555 {
26556 if (adding_value == -1)
26557 {
26558 adding_value = 1;
26559 opt = arm_extensions;
26560 }
26561 else if (adding_value != 1)
26562 {
26563 as_bad (_("must specify extensions to add before specifying "
26564 "those to remove"));
26565 return FALSE;
26566 }
26567 }
26568
26569 if (len == 0)
26570 {
26571 as_bad (_("missing architectural extension"));
26572 return FALSE;
26573 }
26574
26575 gas_assert (adding_value != -1);
26576 gas_assert (opt != NULL);
26577
26578 /* Scan over the options table trying to find an exact match. */
26579 for (; opt->name != NULL; opt++)
26580 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
26581 {
26582 int i, nb_allowed_archs =
26583 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
26584 /* Check we can apply the extension to this architecture. */
26585 for (i = 0; i < nb_allowed_archs; i++)
26586 {
26587 /* Empty entry. */
26588 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_any))
26589 continue;
26590 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *opt_set))
26591 break;
26592 }
26593 if (i == nb_allowed_archs)
26594 {
26595 as_bad (_("extension does not apply to the base architecture"));
26596 return FALSE;
26597 }
26598
26599 /* Add or remove the extension. */
26600 if (adding_value)
26601 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->merge_value);
26602 else
26603 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->clear_value);
26604
26605 /* Allowing Thumb division instructions for ARMv7 in autodetection
26606 rely on this break so that duplicate extensions (extensions
26607 with the same name as a previous extension in the list) are not
26608 considered for command-line parsing. */
26609 break;
26610 }
26611
26612 if (opt->name == NULL)
26613 {
26614 /* Did we fail to find an extension because it wasn't specified in
26615 alphabetical order, or because it does not exist? */
26616
26617 for (opt = arm_extensions; opt->name != NULL; opt++)
26618 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
26619 break;
26620
26621 if (opt->name == NULL)
26622 as_bad (_("unknown architectural extension `%s'"), str);
26623 else
26624 as_bad (_("architectural extensions must be specified in "
26625 "alphabetical order"));
26626
26627 return FALSE;
26628 }
26629 else
26630 {
26631 /* We should skip the extension we've just matched the next time
26632 round. */
26633 opt++;
26634 }
26635
26636 str = ext;
26637 };
26638
26639 return TRUE;
26640 }
26641
26642 static bfd_boolean
26643 arm_parse_cpu (const char *str)
26644 {
26645 const struct arm_cpu_option_table *opt;
26646 const char *ext = strchr (str, '+');
26647 size_t len;
26648
26649 if (ext != NULL)
26650 len = ext - str;
26651 else
26652 len = strlen (str);
26653
26654 if (len == 0)
26655 {
26656 as_bad (_("missing cpu name `%s'"), str);
26657 return FALSE;
26658 }
26659
26660 for (opt = arm_cpus; opt->name != NULL; opt++)
26661 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
26662 {
26663 mcpu_cpu_opt = &opt->value;
26664 if (mcpu_ext_opt == NULL)
26665 mcpu_ext_opt = XNEW (arm_feature_set);
26666 *mcpu_ext_opt = opt->ext;
26667 mcpu_fpu_opt = &opt->default_fpu;
26668 if (opt->canonical_name)
26669 {
26670 gas_assert (sizeof selected_cpu_name > strlen (opt->canonical_name));
26671 strcpy (selected_cpu_name, opt->canonical_name);
26672 }
26673 else
26674 {
26675 size_t i;
26676
26677 if (len >= sizeof selected_cpu_name)
26678 len = (sizeof selected_cpu_name) - 1;
26679
26680 for (i = 0; i < len; i++)
26681 selected_cpu_name[i] = TOUPPER (opt->name[i]);
26682 selected_cpu_name[i] = 0;
26683 }
26684
26685 if (ext != NULL)
26686 return arm_parse_extension (ext, mcpu_cpu_opt, mcpu_ext_opt);
26687
26688 return TRUE;
26689 }
26690
26691 as_bad (_("unknown cpu `%s'"), str);
26692 return FALSE;
26693 }
26694
26695 static bfd_boolean
26696 arm_parse_arch (const char *str)
26697 {
26698 const struct arm_arch_option_table *opt;
26699 const char *ext = strchr (str, '+');
26700 size_t len;
26701
26702 if (ext != NULL)
26703 len = ext - str;
26704 else
26705 len = strlen (str);
26706
26707 if (len == 0)
26708 {
26709 as_bad (_("missing architecture name `%s'"), str);
26710 return FALSE;
26711 }
26712
26713 for (opt = arm_archs; opt->name != NULL; opt++)
26714 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
26715 {
26716 march_cpu_opt = &opt->value;
26717 if (march_ext_opt == NULL)
26718 march_ext_opt = XNEW (arm_feature_set);
26719 *march_ext_opt = arm_arch_none;
26720 march_fpu_opt = &opt->default_fpu;
26721 strcpy (selected_cpu_name, opt->name);
26722
26723 if (ext != NULL)
26724 return arm_parse_extension (ext, march_cpu_opt, march_ext_opt);
26725
26726 return TRUE;
26727 }
26728
26729 as_bad (_("unknown architecture `%s'\n"), str);
26730 return FALSE;
26731 }
26732
26733 static bfd_boolean
26734 arm_parse_fpu (const char * str)
26735 {
26736 const struct arm_option_fpu_value_table * opt;
26737
26738 for (opt = arm_fpus; opt->name != NULL; opt++)
26739 if (streq (opt->name, str))
26740 {
26741 mfpu_opt = &opt->value;
26742 return TRUE;
26743 }
26744
26745 as_bad (_("unknown floating point format `%s'\n"), str);
26746 return FALSE;
26747 }
26748
26749 static bfd_boolean
26750 arm_parse_float_abi (const char * str)
26751 {
26752 const struct arm_option_value_table * opt;
26753
26754 for (opt = arm_float_abis; opt->name != NULL; opt++)
26755 if (streq (opt->name, str))
26756 {
26757 mfloat_abi_opt = opt->value;
26758 return TRUE;
26759 }
26760
26761 as_bad (_("unknown floating point abi `%s'\n"), str);
26762 return FALSE;
26763 }
26764
26765 #ifdef OBJ_ELF
26766 static bfd_boolean
26767 arm_parse_eabi (const char * str)
26768 {
26769 const struct arm_option_value_table *opt;
26770
26771 for (opt = arm_eabis; opt->name != NULL; opt++)
26772 if (streq (opt->name, str))
26773 {
26774 meabi_flags = opt->value;
26775 return TRUE;
26776 }
26777 as_bad (_("unknown EABI `%s'\n"), str);
26778 return FALSE;
26779 }
26780 #endif
26781
26782 static bfd_boolean
26783 arm_parse_it_mode (const char * str)
26784 {
26785 bfd_boolean ret = TRUE;
26786
26787 if (streq ("arm", str))
26788 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
26789 else if (streq ("thumb", str))
26790 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
26791 else if (streq ("always", str))
26792 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
26793 else if (streq ("never", str))
26794 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
26795 else
26796 {
26797 as_bad (_("unknown implicit IT mode `%s', should be "\
26798 "arm, thumb, always, or never."), str);
26799 ret = FALSE;
26800 }
26801
26802 return ret;
26803 }
26804
26805 static bfd_boolean
26806 arm_ccs_mode (const char * unused ATTRIBUTE_UNUSED)
26807 {
26808 codecomposer_syntax = TRUE;
26809 arm_comment_chars[0] = ';';
26810 arm_line_separator_chars[0] = 0;
26811 return TRUE;
26812 }
26813
26814 struct arm_long_option_table arm_long_opts[] =
26815 {
26816 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
26817 arm_parse_cpu, NULL},
26818 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
26819 arm_parse_arch, NULL},
26820 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
26821 arm_parse_fpu, NULL},
26822 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
26823 arm_parse_float_abi, NULL},
26824 #ifdef OBJ_ELF
26825 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
26826 arm_parse_eabi, NULL},
26827 #endif
26828 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
26829 arm_parse_it_mode, NULL},
26830 {"mccs", N_("\t\t\t TI CodeComposer Studio syntax compatibility mode"),
26831 arm_ccs_mode, NULL},
26832 {NULL, NULL, 0, NULL}
26833 };
26834
26835 int
26836 md_parse_option (int c, const char * arg)
26837 {
26838 struct arm_option_table *opt;
26839 const struct arm_legacy_option_table *fopt;
26840 struct arm_long_option_table *lopt;
26841
26842 switch (c)
26843 {
26844 #ifdef OPTION_EB
26845 case OPTION_EB:
26846 target_big_endian = 1;
26847 break;
26848 #endif
26849
26850 #ifdef OPTION_EL
26851 case OPTION_EL:
26852 target_big_endian = 0;
26853 break;
26854 #endif
26855
26856 case OPTION_FIX_V4BX:
26857 fix_v4bx = TRUE;
26858 break;
26859
26860 #ifdef OBJ_ELF
26861 case OPTION_FDPIC:
26862 arm_fdpic = TRUE;
26863 break;
26864 #endif /* OBJ_ELF */
26865
26866 case 'a':
26867 /* Listing option. Just ignore these, we don't support additional
26868 ones. */
26869 return 0;
26870
26871 default:
26872 for (opt = arm_opts; opt->option != NULL; opt++)
26873 {
26874 if (c == opt->option[0]
26875 && ((arg == NULL && opt->option[1] == 0)
26876 || streq (arg, opt->option + 1)))
26877 {
26878 /* If the option is deprecated, tell the user. */
26879 if (warn_on_deprecated && opt->deprecated != NULL)
26880 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26881 arg ? arg : "", _(opt->deprecated));
26882
26883 if (opt->var != NULL)
26884 *opt->var = opt->value;
26885
26886 return 1;
26887 }
26888 }
26889
26890 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
26891 {
26892 if (c == fopt->option[0]
26893 && ((arg == NULL && fopt->option[1] == 0)
26894 || streq (arg, fopt->option + 1)))
26895 {
26896 /* If the option is deprecated, tell the user. */
26897 if (warn_on_deprecated && fopt->deprecated != NULL)
26898 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
26899 arg ? arg : "", _(fopt->deprecated));
26900
26901 if (fopt->var != NULL)
26902 *fopt->var = &fopt->value;
26903
26904 return 1;
26905 }
26906 }
26907
26908 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26909 {
26910 /* These options are expected to have an argument. */
26911 if (c == lopt->option[0]
26912 && arg != NULL
26913 && strncmp (arg, lopt->option + 1,
26914 strlen (lopt->option + 1)) == 0)
26915 {
26916 /* If the option is deprecated, tell the user. */
26917 if (warn_on_deprecated && lopt->deprecated != NULL)
26918 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
26919 _(lopt->deprecated));
26920
26921 /* Call the sup-option parser. */
26922 return lopt->func (arg + strlen (lopt->option) - 1);
26923 }
26924 }
26925
26926 return 0;
26927 }
26928
26929 return 1;
26930 }
26931
26932 void
26933 md_show_usage (FILE * fp)
26934 {
26935 struct arm_option_table *opt;
26936 struct arm_long_option_table *lopt;
26937
26938 fprintf (fp, _(" ARM-specific assembler options:\n"));
26939
26940 for (opt = arm_opts; opt->option != NULL; opt++)
26941 if (opt->help != NULL)
26942 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
26943
26944 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
26945 if (lopt->help != NULL)
26946 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
26947
26948 #ifdef OPTION_EB
26949 fprintf (fp, _("\
26950 -EB assemble code for a big-endian cpu\n"));
26951 #endif
26952
26953 #ifdef OPTION_EL
26954 fprintf (fp, _("\
26955 -EL assemble code for a little-endian cpu\n"));
26956 #endif
26957
26958 fprintf (fp, _("\
26959 --fix-v4bx Allow BX in ARMv4 code\n"));
26960
26961 #ifdef OBJ_ELF
26962 fprintf (fp, _("\
26963 --fdpic generate an FDPIC object file\n"));
26964 #endif /* OBJ_ELF */
26965 }
26966
26967 #ifdef OBJ_ELF
26968
26969 typedef struct
26970 {
26971 int val;
26972 arm_feature_set flags;
26973 } cpu_arch_ver_table;
26974
26975 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
26976 chronologically for architectures, with an exception for ARMv6-M and
26977 ARMv6S-M due to legacy reasons. No new architecture should have a
26978 special case. This allows for build attribute selection results to be
26979 stable when new architectures are added. */
26980 static const cpu_arch_ver_table cpu_arch_ver[] =
26981 {
26982 {0, ARM_ARCH_V1},
26983 {0, ARM_ARCH_V2},
26984 {0, ARM_ARCH_V2S},
26985 {0, ARM_ARCH_V3},
26986 {0, ARM_ARCH_V3M},
26987 {1, ARM_ARCH_V4xM},
26988 {1, ARM_ARCH_V4},
26989 {2, ARM_ARCH_V4TxM},
26990 {2, ARM_ARCH_V4T},
26991 {3, ARM_ARCH_V5xM},
26992 {3, ARM_ARCH_V5},
26993 {3, ARM_ARCH_V5TxM},
26994 {3, ARM_ARCH_V5T},
26995 {4, ARM_ARCH_V5TExP},
26996 {4, ARM_ARCH_V5TE},
26997 {5, ARM_ARCH_V5TEJ},
26998 {6, ARM_ARCH_V6},
26999 {7, ARM_ARCH_V6Z},
27000 {7, ARM_ARCH_V6KZ},
27001 {9, ARM_ARCH_V6K},
27002 {8, ARM_ARCH_V6T2},
27003 {8, ARM_ARCH_V6KT2},
27004 {8, ARM_ARCH_V6ZT2},
27005 {8, ARM_ARCH_V6KZT2},
27006
27007 /* When assembling a file with only ARMv6-M or ARMv6S-M instruction, GNU as
27008 always selected build attributes to match those of ARMv6-M
27009 (resp. ARMv6S-M). However, due to these architectures being a strict
27010 subset of ARMv7-M in terms of instructions available, ARMv7-M attributes
27011 would be selected when fully respecting chronology of architectures.
27012 It is thus necessary to make a special case of ARMv6-M and ARMv6S-M and
27013 move them before ARMv7 architectures. */
27014 {11, ARM_ARCH_V6M},
27015 {12, ARM_ARCH_V6SM},
27016
27017 {10, ARM_ARCH_V7},
27018 {10, ARM_ARCH_V7A},
27019 {10, ARM_ARCH_V7R},
27020 {10, ARM_ARCH_V7M},
27021 {10, ARM_ARCH_V7VE},
27022 {13, ARM_ARCH_V7EM},
27023 {14, ARM_ARCH_V8A},
27024 {14, ARM_ARCH_V8_1A},
27025 {14, ARM_ARCH_V8_2A},
27026 {14, ARM_ARCH_V8_3A},
27027 {16, ARM_ARCH_V8M_BASE},
27028 {17, ARM_ARCH_V8M_MAIN},
27029 {15, ARM_ARCH_V8R},
27030 {14, ARM_ARCH_V8_4A},
27031 {-1, ARM_ARCH_NONE}
27032 };
27033
27034 /* Set an attribute if it has not already been set by the user. */
27035
27036 static void
27037 aeabi_set_attribute_int (int tag, int value)
27038 {
27039 if (tag < 1
27040 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27041 || !attributes_set_explicitly[tag])
27042 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
27043 }
27044
27045 static void
27046 aeabi_set_attribute_string (int tag, const char *value)
27047 {
27048 if (tag < 1
27049 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
27050 || !attributes_set_explicitly[tag])
27051 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
27052 }
27053
27054 /* Return whether features in the *NEEDED feature set are available via
27055 extensions for the architecture whose feature set is *ARCH_FSET. */
27056
27057 static bfd_boolean
27058 have_ext_for_needed_feat_p (const arm_feature_set *arch_fset,
27059 const arm_feature_set *needed)
27060 {
27061 int i, nb_allowed_archs;
27062 arm_feature_set ext_fset;
27063 const struct arm_option_extension_value_table *opt;
27064
27065 ext_fset = arm_arch_none;
27066 for (opt = arm_extensions; opt->name != NULL; opt++)
27067 {
27068 /* Extension does not provide any feature we need. */
27069 if (!ARM_CPU_HAS_FEATURE (*needed, opt->merge_value))
27070 continue;
27071
27072 nb_allowed_archs =
27073 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[0]);
27074 for (i = 0; i < nb_allowed_archs; i++)
27075 {
27076 /* Empty entry. */
27077 if (ARM_FEATURE_EQUAL (opt->allowed_archs[i], arm_arch_any))
27078 break;
27079
27080 /* Extension is available, add it. */
27081 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], *arch_fset))
27082 ARM_MERGE_FEATURE_SETS (ext_fset, ext_fset, opt->merge_value);
27083 }
27084 }
27085
27086 /* Can we enable all features in *needed? */
27087 return ARM_FSET_CPU_SUBSET (*needed, ext_fset);
27088 }
27089
27090 /* Select value for Tag_CPU_arch and Tag_CPU_arch_profile build attributes for
27091 a given architecture feature set *ARCH_EXT_FSET including extension feature
27092 set *EXT_FSET. Selection logic used depend on EXACT_MATCH:
27093 - if true, check for an exact match of the architecture modulo extensions;
27094 - otherwise, select build attribute value of the first superset
27095 architecture released so that results remains stable when new architectures
27096 are added.
27097 For -march/-mcpu=all the build attribute value of the most featureful
27098 architecture is returned. Tag_CPU_arch_profile result is returned in
27099 PROFILE. */
27100
27101 static int
27102 get_aeabi_cpu_arch_from_fset (const arm_feature_set *arch_ext_fset,
27103 const arm_feature_set *ext_fset,
27104 char *profile, int exact_match)
27105 {
27106 arm_feature_set arch_fset;
27107 const cpu_arch_ver_table *p_ver, *p_ver_ret = NULL;
27108
27109 /* Select most featureful architecture with all its extensions if building
27110 for -march=all as the feature sets used to set build attributes. */
27111 if (ARM_FEATURE_EQUAL (*arch_ext_fset, arm_arch_any))
27112 {
27113 /* Force revisiting of decision for each new architecture. */
27114 gas_assert (MAX_TAG_CPU_ARCH <= TAG_CPU_ARCH_V8M_MAIN);
27115 *profile = 'A';
27116 return TAG_CPU_ARCH_V8;
27117 }
27118
27119 ARM_CLEAR_FEATURE (arch_fset, *arch_ext_fset, *ext_fset);
27120
27121 for (p_ver = cpu_arch_ver; p_ver->val != -1; p_ver++)
27122 {
27123 arm_feature_set known_arch_fset;
27124
27125 ARM_CLEAR_FEATURE (known_arch_fset, p_ver->flags, fpu_any);
27126 if (exact_match)
27127 {
27128 /* Base architecture match user-specified architecture and
27129 extensions, eg. ARMv6S-M matching -march=armv6-m+os. */
27130 if (ARM_FEATURE_EQUAL (*arch_ext_fset, known_arch_fset))
27131 {
27132 p_ver_ret = p_ver;
27133 goto found;
27134 }
27135 /* Base architecture match user-specified architecture only
27136 (eg. ARMv6-M in the same case as above). Record it in case we
27137 find a match with above condition. */
27138 else if (p_ver_ret == NULL
27139 && ARM_FEATURE_EQUAL (arch_fset, known_arch_fset))
27140 p_ver_ret = p_ver;
27141 }
27142 else
27143 {
27144
27145 /* Architecture has all features wanted. */
27146 if (ARM_FSET_CPU_SUBSET (arch_fset, known_arch_fset))
27147 {
27148 arm_feature_set added_fset;
27149
27150 /* Compute features added by this architecture over the one
27151 recorded in p_ver_ret. */
27152 if (p_ver_ret != NULL)
27153 ARM_CLEAR_FEATURE (added_fset, known_arch_fset,
27154 p_ver_ret->flags);
27155 /* First architecture that match incl. with extensions, or the
27156 only difference in features over the recorded match is
27157 features that were optional and are now mandatory. */
27158 if (p_ver_ret == NULL
27159 || ARM_FSET_CPU_SUBSET (added_fset, arch_fset))
27160 {
27161 p_ver_ret = p_ver;
27162 goto found;
27163 }
27164 }
27165 else if (p_ver_ret == NULL)
27166 {
27167 arm_feature_set needed_ext_fset;
27168
27169 ARM_CLEAR_FEATURE (needed_ext_fset, arch_fset, known_arch_fset);
27170
27171 /* Architecture has all features needed when using some
27172 extensions. Record it and continue searching in case there
27173 exist an architecture providing all needed features without
27174 the need for extensions (eg. ARMv6S-M Vs ARMv6-M with
27175 OS extension). */
27176 if (have_ext_for_needed_feat_p (&known_arch_fset,
27177 &needed_ext_fset))
27178 p_ver_ret = p_ver;
27179 }
27180 }
27181 }
27182
27183 if (p_ver_ret == NULL)
27184 return -1;
27185
27186 found:
27187 /* Tag_CPU_arch_profile. */
27188 if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7a)
27189 || ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8)
27190 || (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_atomics)
27191 && !ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v8m_m_only)))
27192 *profile = 'A';
27193 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_v7r))
27194 *profile = 'R';
27195 else if (ARM_CPU_HAS_FEATURE (p_ver_ret->flags, arm_ext_m))
27196 *profile = 'M';
27197 else
27198 *profile = '\0';
27199 return p_ver_ret->val;
27200 }
27201
27202 /* Set the public EABI object attributes. */
27203
27204 static void
27205 aeabi_set_public_attributes (void)
27206 {
27207 char profile = '\0';
27208 int arch = -1;
27209 int virt_sec = 0;
27210 int fp16_optional = 0;
27211 int skip_exact_match = 0;
27212 arm_feature_set flags, flags_arch, flags_ext;
27213
27214 /* Autodetection mode, choose the architecture based the instructions
27215 actually used. */
27216 if (no_cpu_selected ())
27217 {
27218 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
27219
27220 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
27221 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
27222
27223 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
27224 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
27225
27226 /* Code run during relaxation relies on selected_cpu being set. */
27227 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27228 flags_ext = arm_arch_none;
27229 ARM_CLEAR_FEATURE (selected_arch, flags_arch, flags_ext);
27230 selected_ext = flags_ext;
27231 selected_cpu = flags;
27232 }
27233 /* Otherwise, choose the architecture based on the capabilities of the
27234 requested cpu. */
27235 else
27236 {
27237 ARM_MERGE_FEATURE_SETS (flags_arch, selected_arch, selected_ext);
27238 ARM_CLEAR_FEATURE (flags_arch, flags_arch, fpu_any);
27239 flags_ext = selected_ext;
27240 flags = selected_cpu;
27241 }
27242 ARM_MERGE_FEATURE_SETS (flags, flags, selected_fpu);
27243
27244 /* Allow the user to override the reported architecture. */
27245 if (!ARM_FEATURE_ZERO (selected_object_arch))
27246 {
27247 ARM_CLEAR_FEATURE (flags_arch, selected_object_arch, fpu_any);
27248 flags_ext = arm_arch_none;
27249 }
27250 else
27251 skip_exact_match = ARM_FEATURE_EQUAL (selected_cpu, arm_arch_any);
27252
27253 /* When this function is run again after relaxation has happened there is no
27254 way to determine whether an architecture or CPU was specified by the user:
27255 - selected_cpu is set above for relaxation to work;
27256 - march_cpu_opt is not set if only -mcpu or .cpu is used;
27257 - mcpu_cpu_opt is set to arm_arch_any for autodetection.
27258 Therefore, if not in -march=all case we first try an exact match and fall
27259 back to autodetection. */
27260 if (!skip_exact_match)
27261 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 1);
27262 if (arch == -1)
27263 arch = get_aeabi_cpu_arch_from_fset (&flags_arch, &flags_ext, &profile, 0);
27264 if (arch == -1)
27265 as_bad (_("no architecture contains all the instructions used\n"));
27266
27267 /* Tag_CPU_name. */
27268 if (selected_cpu_name[0])
27269 {
27270 char *q;
27271
27272 q = selected_cpu_name;
27273 if (strncmp (q, "armv", 4) == 0)
27274 {
27275 int i;
27276
27277 q += 4;
27278 for (i = 0; q[i]; i++)
27279 q[i] = TOUPPER (q[i]);
27280 }
27281 aeabi_set_attribute_string (Tag_CPU_name, q);
27282 }
27283
27284 /* Tag_CPU_arch. */
27285 aeabi_set_attribute_int (Tag_CPU_arch, arch);
27286
27287 /* Tag_CPU_arch_profile. */
27288 if (profile != '\0')
27289 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
27290
27291 /* Tag_DSP_extension. */
27292 if (ARM_CPU_HAS_FEATURE (selected_ext, arm_ext_dsp))
27293 aeabi_set_attribute_int (Tag_DSP_extension, 1);
27294
27295 ARM_CLEAR_FEATURE (flags_arch, flags, fpu_any);
27296 /* Tag_ARM_ISA_use. */
27297 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
27298 || ARM_FEATURE_ZERO (flags_arch))
27299 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
27300
27301 /* Tag_THUMB_ISA_use. */
27302 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
27303 || ARM_FEATURE_ZERO (flags_arch))
27304 {
27305 int thumb_isa_use;
27306
27307 if (!ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27308 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m_m_only))
27309 thumb_isa_use = 3;
27310 else if (ARM_CPU_HAS_FEATURE (flags, arm_arch_t2))
27311 thumb_isa_use = 2;
27312 else
27313 thumb_isa_use = 1;
27314 aeabi_set_attribute_int (Tag_THUMB_ISA_use, thumb_isa_use);
27315 }
27316
27317 /* Tag_VFP_arch. */
27318 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8xd))
27319 aeabi_set_attribute_int (Tag_VFP_arch,
27320 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27321 ? 7 : 8);
27322 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
27323 aeabi_set_attribute_int (Tag_VFP_arch,
27324 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
27325 ? 5 : 6);
27326 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
27327 {
27328 fp16_optional = 1;
27329 aeabi_set_attribute_int (Tag_VFP_arch, 3);
27330 }
27331 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
27332 {
27333 aeabi_set_attribute_int (Tag_VFP_arch, 4);
27334 fp16_optional = 1;
27335 }
27336 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
27337 aeabi_set_attribute_int (Tag_VFP_arch, 2);
27338 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
27339 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
27340 aeabi_set_attribute_int (Tag_VFP_arch, 1);
27341
27342 /* Tag_ABI_HardFP_use. */
27343 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
27344 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
27345 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
27346
27347 /* Tag_WMMX_arch. */
27348 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
27349 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
27350 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
27351 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
27352
27353 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
27354 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v8_1))
27355 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 4);
27356 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
27357 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
27358 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
27359 {
27360 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
27361 {
27362 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
27363 }
27364 else
27365 {
27366 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
27367 fp16_optional = 1;
27368 }
27369 }
27370
27371 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
27372 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
27373 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
27374
27375 /* Tag_DIV_use.
27376
27377 We set Tag_DIV_use to two when integer divide instructions have been used
27378 in ARM state, or when Thumb integer divide instructions have been used,
27379 but we have no architecture profile set, nor have we any ARM instructions.
27380
27381 For ARMv8-A and ARMv8-M we set the tag to 0 as integer divide is implied
27382 by the base architecture.
27383
27384 For new architectures we will have to check these tests. */
27385 gas_assert (arch <= TAG_CPU_ARCH_V8M_MAIN);
27386 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8)
27387 || ARM_CPU_HAS_FEATURE (flags, arm_ext_v8m))
27388 aeabi_set_attribute_int (Tag_DIV_use, 0);
27389 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
27390 || (profile == '\0'
27391 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
27392 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
27393 aeabi_set_attribute_int (Tag_DIV_use, 2);
27394
27395 /* Tag_MP_extension_use. */
27396 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
27397 aeabi_set_attribute_int (Tag_MPextension_use, 1);
27398
27399 /* Tag Virtualization_use. */
27400 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
27401 virt_sec |= 1;
27402 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
27403 virt_sec |= 2;
27404 if (virt_sec != 0)
27405 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
27406 }
27407
27408 /* Post relaxation hook. Recompute ARM attributes now that relaxation is
27409 finished and free extension feature bits which will not be used anymore. */
27410
27411 void
27412 arm_md_post_relax (void)
27413 {
27414 aeabi_set_public_attributes ();
27415 XDELETE (mcpu_ext_opt);
27416 mcpu_ext_opt = NULL;
27417 XDELETE (march_ext_opt);
27418 march_ext_opt = NULL;
27419 }
27420
27421 /* Add the default contents for the .ARM.attributes section. */
27422
27423 void
27424 arm_md_end (void)
27425 {
27426 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
27427 return;
27428
27429 aeabi_set_public_attributes ();
27430 }
27431 #endif /* OBJ_ELF */
27432
27433 /* Parse a .cpu directive. */
27434
27435 static void
27436 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
27437 {
27438 const struct arm_cpu_option_table *opt;
27439 char *name;
27440 char saved_char;
27441
27442 name = input_line_pointer;
27443 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27444 input_line_pointer++;
27445 saved_char = *input_line_pointer;
27446 *input_line_pointer = 0;
27447
27448 /* Skip the first "all" entry. */
27449 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
27450 if (streq (opt->name, name))
27451 {
27452 selected_arch = opt->value;
27453 selected_ext = opt->ext;
27454 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
27455 if (opt->canonical_name)
27456 strcpy (selected_cpu_name, opt->canonical_name);
27457 else
27458 {
27459 int i;
27460 for (i = 0; opt->name[i]; i++)
27461 selected_cpu_name[i] = TOUPPER (opt->name[i]);
27462
27463 selected_cpu_name[i] = 0;
27464 }
27465 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27466
27467 *input_line_pointer = saved_char;
27468 demand_empty_rest_of_line ();
27469 return;
27470 }
27471 as_bad (_("unknown cpu `%s'"), name);
27472 *input_line_pointer = saved_char;
27473 ignore_rest_of_line ();
27474 }
27475
27476 /* Parse a .arch directive. */
27477
27478 static void
27479 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
27480 {
27481 const struct arm_arch_option_table *opt;
27482 char saved_char;
27483 char *name;
27484
27485 name = input_line_pointer;
27486 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27487 input_line_pointer++;
27488 saved_char = *input_line_pointer;
27489 *input_line_pointer = 0;
27490
27491 /* Skip the first "all" entry. */
27492 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27493 if (streq (opt->name, name))
27494 {
27495 selected_arch = opt->value;
27496 selected_ext = arm_arch_none;
27497 selected_cpu = selected_arch;
27498 strcpy (selected_cpu_name, opt->name);
27499 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27500 *input_line_pointer = saved_char;
27501 demand_empty_rest_of_line ();
27502 return;
27503 }
27504
27505 as_bad (_("unknown architecture `%s'\n"), name);
27506 *input_line_pointer = saved_char;
27507 ignore_rest_of_line ();
27508 }
27509
27510 /* Parse a .object_arch directive. */
27511
27512 static void
27513 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
27514 {
27515 const struct arm_arch_option_table *opt;
27516 char saved_char;
27517 char *name;
27518
27519 name = input_line_pointer;
27520 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27521 input_line_pointer++;
27522 saved_char = *input_line_pointer;
27523 *input_line_pointer = 0;
27524
27525 /* Skip the first "all" entry. */
27526 for (opt = arm_archs + 1; opt->name != NULL; opt++)
27527 if (streq (opt->name, name))
27528 {
27529 selected_object_arch = opt->value;
27530 *input_line_pointer = saved_char;
27531 demand_empty_rest_of_line ();
27532 return;
27533 }
27534
27535 as_bad (_("unknown architecture `%s'\n"), name);
27536 *input_line_pointer = saved_char;
27537 ignore_rest_of_line ();
27538 }
27539
27540 /* Parse a .arch_extension directive. */
27541
27542 static void
27543 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
27544 {
27545 const struct arm_option_extension_value_table *opt;
27546 char saved_char;
27547 char *name;
27548 int adding_value = 1;
27549
27550 name = input_line_pointer;
27551 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27552 input_line_pointer++;
27553 saved_char = *input_line_pointer;
27554 *input_line_pointer = 0;
27555
27556 if (strlen (name) >= 2
27557 && strncmp (name, "no", 2) == 0)
27558 {
27559 adding_value = 0;
27560 name += 2;
27561 }
27562
27563 for (opt = arm_extensions; opt->name != NULL; opt++)
27564 if (streq (opt->name, name))
27565 {
27566 int i, nb_allowed_archs =
27567 sizeof (opt->allowed_archs) / sizeof (opt->allowed_archs[i]);
27568 for (i = 0; i < nb_allowed_archs; i++)
27569 {
27570 /* Empty entry. */
27571 if (ARM_CPU_IS_ANY (opt->allowed_archs[i]))
27572 continue;
27573 if (ARM_FSET_CPU_SUBSET (opt->allowed_archs[i], selected_arch))
27574 break;
27575 }
27576
27577 if (i == nb_allowed_archs)
27578 {
27579 as_bad (_("architectural extension `%s' is not allowed for the "
27580 "current base architecture"), name);
27581 break;
27582 }
27583
27584 if (adding_value)
27585 ARM_MERGE_FEATURE_SETS (selected_ext, selected_ext,
27586 opt->merge_value);
27587 else
27588 ARM_CLEAR_FEATURE (selected_ext, selected_ext, opt->clear_value);
27589
27590 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_arch, selected_ext);
27591 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27592 *input_line_pointer = saved_char;
27593 demand_empty_rest_of_line ();
27594 /* Allowing Thumb division instructions for ARMv7 in autodetection rely
27595 on this return so that duplicate extensions (extensions with the
27596 same name as a previous extension in the list) are not considered
27597 for command-line parsing. */
27598 return;
27599 }
27600
27601 if (opt->name == NULL)
27602 as_bad (_("unknown architecture extension `%s'\n"), name);
27603
27604 *input_line_pointer = saved_char;
27605 ignore_rest_of_line ();
27606 }
27607
27608 /* Parse a .fpu directive. */
27609
27610 static void
27611 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
27612 {
27613 const struct arm_option_fpu_value_table *opt;
27614 char saved_char;
27615 char *name;
27616
27617 name = input_line_pointer;
27618 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
27619 input_line_pointer++;
27620 saved_char = *input_line_pointer;
27621 *input_line_pointer = 0;
27622
27623 for (opt = arm_fpus; opt->name != NULL; opt++)
27624 if (streq (opt->name, name))
27625 {
27626 selected_fpu = opt->value;
27627 #ifndef CPU_DEFAULT
27628 if (no_cpu_selected ())
27629 ARM_MERGE_FEATURE_SETS (cpu_variant, arm_arch_any, selected_fpu);
27630 else
27631 #endif
27632 ARM_MERGE_FEATURE_SETS (cpu_variant, selected_cpu, selected_fpu);
27633 *input_line_pointer = saved_char;
27634 demand_empty_rest_of_line ();
27635 return;
27636 }
27637
27638 as_bad (_("unknown floating point format `%s'\n"), name);
27639 *input_line_pointer = saved_char;
27640 ignore_rest_of_line ();
27641 }
27642
27643 /* Copy symbol information. */
27644
27645 void
27646 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
27647 {
27648 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
27649 }
27650
27651 #ifdef OBJ_ELF
27652 /* Given a symbolic attribute NAME, return the proper integer value.
27653 Returns -1 if the attribute is not known. */
27654
27655 int
27656 arm_convert_symbolic_attribute (const char *name)
27657 {
27658 static const struct
27659 {
27660 const char * name;
27661 const int tag;
27662 }
27663 attribute_table[] =
27664 {
27665 /* When you modify this table you should
27666 also modify the list in doc/c-arm.texi. */
27667 #define T(tag) {#tag, tag}
27668 T (Tag_CPU_raw_name),
27669 T (Tag_CPU_name),
27670 T (Tag_CPU_arch),
27671 T (Tag_CPU_arch_profile),
27672 T (Tag_ARM_ISA_use),
27673 T (Tag_THUMB_ISA_use),
27674 T (Tag_FP_arch),
27675 T (Tag_VFP_arch),
27676 T (Tag_WMMX_arch),
27677 T (Tag_Advanced_SIMD_arch),
27678 T (Tag_PCS_config),
27679 T (Tag_ABI_PCS_R9_use),
27680 T (Tag_ABI_PCS_RW_data),
27681 T (Tag_ABI_PCS_RO_data),
27682 T (Tag_ABI_PCS_GOT_use),
27683 T (Tag_ABI_PCS_wchar_t),
27684 T (Tag_ABI_FP_rounding),
27685 T (Tag_ABI_FP_denormal),
27686 T (Tag_ABI_FP_exceptions),
27687 T (Tag_ABI_FP_user_exceptions),
27688 T (Tag_ABI_FP_number_model),
27689 T (Tag_ABI_align_needed),
27690 T (Tag_ABI_align8_needed),
27691 T (Tag_ABI_align_preserved),
27692 T (Tag_ABI_align8_preserved),
27693 T (Tag_ABI_enum_size),
27694 T (Tag_ABI_HardFP_use),
27695 T (Tag_ABI_VFP_args),
27696 T (Tag_ABI_WMMX_args),
27697 T (Tag_ABI_optimization_goals),
27698 T (Tag_ABI_FP_optimization_goals),
27699 T (Tag_compatibility),
27700 T (Tag_CPU_unaligned_access),
27701 T (Tag_FP_HP_extension),
27702 T (Tag_VFP_HP_extension),
27703 T (Tag_ABI_FP_16bit_format),
27704 T (Tag_MPextension_use),
27705 T (Tag_DIV_use),
27706 T (Tag_nodefaults),
27707 T (Tag_also_compatible_with),
27708 T (Tag_conformance),
27709 T (Tag_T2EE_use),
27710 T (Tag_Virtualization_use),
27711 T (Tag_DSP_extension),
27712 /* We deliberately do not include Tag_MPextension_use_legacy. */
27713 #undef T
27714 };
27715 unsigned int i;
27716
27717 if (name == NULL)
27718 return -1;
27719
27720 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
27721 if (streq (name, attribute_table[i].name))
27722 return attribute_table[i].tag;
27723
27724 return -1;
27725 }
27726
27727 /* Apply sym value for relocations only in the case that they are for
27728 local symbols in the same segment as the fixup and you have the
27729 respective architectural feature for blx and simple switches. */
27730
27731 int
27732 arm_apply_sym_value (struct fix * fixP, segT this_seg)
27733 {
27734 if (fixP->fx_addsy
27735 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
27736 /* PR 17444: If the local symbol is in a different section then a reloc
27737 will always be generated for it, so applying the symbol value now
27738 will result in a double offset being stored in the relocation. */
27739 && (S_GET_SEGMENT (fixP->fx_addsy) == this_seg)
27740 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
27741 {
27742 switch (fixP->fx_r_type)
27743 {
27744 case BFD_RELOC_ARM_PCREL_BLX:
27745 case BFD_RELOC_THUMB_PCREL_BRANCH23:
27746 if (ARM_IS_FUNC (fixP->fx_addsy))
27747 return 1;
27748 break;
27749
27750 case BFD_RELOC_ARM_PCREL_CALL:
27751 case BFD_RELOC_THUMB_PCREL_BLX:
27752 if (THUMB_IS_FUNC (fixP->fx_addsy))
27753 return 1;
27754 break;
27755
27756 default:
27757 break;
27758 }
27759
27760 }
27761 return 0;
27762 }
27763 #endif /* OBJ_ELF */
This page took 0.999948 seconds and 4 git commands to generate.