* gas/config/tc-arm.c (deprecated_coproc_regs_s): New structure.
[binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
27
28 #include "as.h"
29 #include <limits.h>
30 #include <stdarg.h>
31 #define NO_RELOC 0
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
35 #include "libiberty.h"
36 #include "opcode/arm.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
42
43 #include "dwarf2dbg.h"
44
45 #ifdef OBJ_ELF
46 /* Must be at least the size of the largest unwind opcode (currently two). */
47 #define ARM_OPCODE_CHUNK_SIZE 8
48
49 /* This structure holds the unwinding state. */
50
51 static struct
52 {
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
57 /* The segment containing the function. */
58 segT saved_seg;
59 subsegT saved_subseg;
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
62 int opcode_count;
63 int opcode_alloc;
64 /* The number of bytes pushed to the stack. */
65 offsetT frame_size;
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
69 offsetT pending_offset;
70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
74 /* Nonzero if an unwind_setfp directive has been seen. */
75 unsigned fp_used:1;
76 /* Nonzero if the last opcode restores sp from fp_reg. */
77 unsigned sp_restored:1;
78 } unwind;
79
80 #endif /* OBJ_ELF */
81
82 /* Results from operand parsing worker functions. */
83
84 typedef enum
85 {
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89 } parse_operand_result;
90
91 enum arm_float_abi
92 {
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96 };
97
98 /* Types of processor to assemble for. */
99 #ifndef CPU_DEFAULT
100 /* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
106 #endif
107
108 #ifndef FPU_DEFAULT
109 # ifdef TE_LINUX
110 # define FPU_DEFAULT FPU_ARCH_FPA
111 # elif defined (TE_NetBSD)
112 # ifdef OBJ_ELF
113 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114 # else
115 /* Legacy a.out format. */
116 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117 # endif
118 # elif defined (TE_VXWORKS)
119 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
120 # else
121 /* For backwards compatibility, default to FPA. */
122 # define FPU_DEFAULT FPU_ARCH_FPA
123 # endif
124 #endif /* ifndef FPU_DEFAULT */
125
126 #define streq(a, b) (strcmp (a, b) == 0)
127
128 static arm_feature_set cpu_variant;
129 static arm_feature_set arm_arch_used;
130 static arm_feature_set thumb_arch_used;
131
132 /* Flags stored in private area of BFD structure. */
133 static int uses_apcs_26 = FALSE;
134 static int atpcs = FALSE;
135 static int support_interwork = FALSE;
136 static int uses_apcs_float = FALSE;
137 static int pic_code = FALSE;
138 static int fix_v4bx = FALSE;
139 /* Warn on using deprecated features. */
140 static int warn_on_deprecated = TRUE;
141
142
143 /* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
146 static const arm_feature_set *legacy_cpu = NULL;
147 static const arm_feature_set *legacy_fpu = NULL;
148
149 static const arm_feature_set *mcpu_cpu_opt = NULL;
150 static const arm_feature_set *mcpu_fpu_opt = NULL;
151 static const arm_feature_set *march_cpu_opt = NULL;
152 static const arm_feature_set *march_fpu_opt = NULL;
153 static const arm_feature_set *mfpu_opt = NULL;
154 static const arm_feature_set *object_arch = NULL;
155
156 /* Constants for known architecture features. */
157 static const arm_feature_set fpu_default = FPU_DEFAULT;
158 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
160 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
162 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167 #ifdef CPU_DEFAULT
168 static const arm_feature_set cpu_default = CPU_DEFAULT;
169 #endif
170
171 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179 static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
187 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
188 static const arm_feature_set arm_ext_v6m = ARM_FEATURE (ARM_EXT_V6M, 0);
189 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
190 static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
191 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
193 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
197 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
198 static const arm_feature_set arm_ext_v8 = ARM_FEATURE (ARM_EXT_V8, 0);
199 static const arm_feature_set arm_ext_m =
200 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_OS | ARM_EXT_V7M, 0);
201 static const arm_feature_set arm_ext_mp = ARM_FEATURE (ARM_EXT_MP, 0);
202 static const arm_feature_set arm_ext_sec = ARM_FEATURE (ARM_EXT_SEC, 0);
203 static const arm_feature_set arm_ext_os = ARM_FEATURE (ARM_EXT_OS, 0);
204 static const arm_feature_set arm_ext_adiv = ARM_FEATURE (ARM_EXT_ADIV, 0);
205 static const arm_feature_set arm_ext_virt = ARM_FEATURE (ARM_EXT_VIRT, 0);
206
207 static const arm_feature_set arm_arch_any = ARM_ANY;
208 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
209 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
210 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
211 static const arm_feature_set arm_arch_v6m_only = ARM_ARCH_V6M_ONLY;
212
213 static const arm_feature_set arm_cext_iwmmxt2 =
214 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
215 static const arm_feature_set arm_cext_iwmmxt =
216 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
217 static const arm_feature_set arm_cext_xscale =
218 ARM_FEATURE (0, ARM_CEXT_XSCALE);
219 static const arm_feature_set arm_cext_maverick =
220 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
221 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
222 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
223 static const arm_feature_set fpu_vfp_ext_v1xd =
224 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
225 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
226 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
227 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
228 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
229 static const arm_feature_set fpu_vfp_ext_d32 =
230 ARM_FEATURE (0, FPU_VFP_EXT_D32);
231 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
232 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
233 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
234 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
235 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
236 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
237 static const arm_feature_set fpu_vfp_ext_armv8 =
238 ARM_FEATURE (0, FPU_VFP_EXT_ARMV8);
239 static const arm_feature_set fpu_neon_ext_armv8 =
240 ARM_FEATURE (0, FPU_NEON_EXT_ARMV8);
241 static const arm_feature_set fpu_crypto_ext_armv8 =
242 ARM_FEATURE (0, FPU_CRYPTO_EXT_ARMV8);
243
244 static int mfloat_abi_opt = -1;
245 /* Record user cpu selection for object attributes. */
246 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
247 /* Must be long enough to hold any of the names in arm_cpus. */
248 static char selected_cpu_name[16];
249
250 /* Return if no cpu was selected on command-line. */
251 static bfd_boolean
252 no_cpu_selected (void)
253 {
254 return selected_cpu.core == arm_arch_none.core
255 && selected_cpu.coproc == arm_arch_none.coproc;
256 }
257
258 #ifdef OBJ_ELF
259 # ifdef EABI_DEFAULT
260 static int meabi_flags = EABI_DEFAULT;
261 # else
262 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
263 # endif
264
265 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
266
267 bfd_boolean
268 arm_is_eabi (void)
269 {
270 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
271 }
272 #endif
273
274 #ifdef OBJ_ELF
275 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
276 symbolS * GOT_symbol;
277 #endif
278
279 /* 0: assemble for ARM,
280 1: assemble for Thumb,
281 2: assemble for Thumb even though target CPU does not support thumb
282 instructions. */
283 static int thumb_mode = 0;
284 /* A value distinct from the possible values for thumb_mode that we
285 can use to record whether thumb_mode has been copied into the
286 tc_frag_data field of a frag. */
287 #define MODE_RECORDED (1 << 4)
288
289 /* Specifies the intrinsic IT insn behavior mode. */
290 enum implicit_it_mode
291 {
292 IMPLICIT_IT_MODE_NEVER = 0x00,
293 IMPLICIT_IT_MODE_ARM = 0x01,
294 IMPLICIT_IT_MODE_THUMB = 0x02,
295 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
296 };
297 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
298
299 /* If unified_syntax is true, we are processing the new unified
300 ARM/Thumb syntax. Important differences from the old ARM mode:
301
302 - Immediate operands do not require a # prefix.
303 - Conditional affixes always appear at the end of the
304 instruction. (For backward compatibility, those instructions
305 that formerly had them in the middle, continue to accept them
306 there.)
307 - The IT instruction may appear, and if it does is validated
308 against subsequent conditional affixes. It does not generate
309 machine code.
310
311 Important differences from the old Thumb mode:
312
313 - Immediate operands do not require a # prefix.
314 - Most of the V6T2 instructions are only available in unified mode.
315 - The .N and .W suffixes are recognized and honored (it is an error
316 if they cannot be honored).
317 - All instructions set the flags if and only if they have an 's' affix.
318 - Conditional affixes may be used. They are validated against
319 preceding IT instructions. Unlike ARM mode, you cannot use a
320 conditional affix except in the scope of an IT instruction. */
321
322 static bfd_boolean unified_syntax = FALSE;
323
324 enum neon_el_type
325 {
326 NT_invtype,
327 NT_untyped,
328 NT_integer,
329 NT_float,
330 NT_poly,
331 NT_signed,
332 NT_unsigned
333 };
334
335 struct neon_type_el
336 {
337 enum neon_el_type type;
338 unsigned size;
339 };
340
341 #define NEON_MAX_TYPE_ELS 4
342
343 struct neon_type
344 {
345 struct neon_type_el el[NEON_MAX_TYPE_ELS];
346 unsigned elems;
347 };
348
349 enum it_instruction_type
350 {
351 OUTSIDE_IT_INSN,
352 INSIDE_IT_INSN,
353 INSIDE_IT_LAST_INSN,
354 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
355 if inside, should be the last one. */
356 NEUTRAL_IT_INSN, /* This could be either inside or outside,
357 i.e. BKPT and NOP. */
358 IT_INSN /* The IT insn has been parsed. */
359 };
360
361 /* The maximum number of operands we need. */
362 #define ARM_IT_MAX_OPERANDS 6
363
364 struct arm_it
365 {
366 const char * error;
367 unsigned long instruction;
368 int size;
369 int size_req;
370 int cond;
371 /* "uncond_value" is set to the value in place of the conditional field in
372 unconditional versions of the instruction, or -1 if nothing is
373 appropriate. */
374 int uncond_value;
375 struct neon_type vectype;
376 /* This does not indicate an actual NEON instruction, only that
377 the mnemonic accepts neon-style type suffixes. */
378 int is_neon;
379 /* Set to the opcode if the instruction needs relaxation.
380 Zero if the instruction is not relaxed. */
381 unsigned long relax;
382 struct
383 {
384 bfd_reloc_code_real_type type;
385 expressionS exp;
386 int pc_rel;
387 } reloc;
388
389 enum it_instruction_type it_insn_type;
390
391 struct
392 {
393 unsigned reg;
394 signed int imm;
395 struct neon_type_el vectype;
396 unsigned present : 1; /* Operand present. */
397 unsigned isreg : 1; /* Operand was a register. */
398 unsigned immisreg : 1; /* .imm field is a second register. */
399 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
400 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
401 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
402 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
403 instructions. This allows us to disambiguate ARM <-> vector insns. */
404 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
405 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
406 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
407 unsigned issingle : 1; /* Operand is VFP single-precision register. */
408 unsigned hasreloc : 1; /* Operand has relocation suffix. */
409 unsigned writeback : 1; /* Operand has trailing ! */
410 unsigned preind : 1; /* Preindexed address. */
411 unsigned postind : 1; /* Postindexed address. */
412 unsigned negative : 1; /* Index register was negated. */
413 unsigned shifted : 1; /* Shift applied to operation. */
414 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
415 } operands[ARM_IT_MAX_OPERANDS];
416 };
417
418 static struct arm_it inst;
419
420 #define NUM_FLOAT_VALS 8
421
422 const char * fp_const[] =
423 {
424 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
425 };
426
427 /* Number of littlenums required to hold an extended precision number. */
428 #define MAX_LITTLENUMS 6
429
430 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
431
432 #define FAIL (-1)
433 #define SUCCESS (0)
434
435 #define SUFF_S 1
436 #define SUFF_D 2
437 #define SUFF_E 3
438 #define SUFF_P 4
439
440 #define CP_T_X 0x00008000
441 #define CP_T_Y 0x00400000
442
443 #define CONDS_BIT 0x00100000
444 #define LOAD_BIT 0x00100000
445
446 #define DOUBLE_LOAD_FLAG 0x00000001
447
448 struct asm_cond
449 {
450 const char * template_name;
451 unsigned long value;
452 };
453
454 #define COND_ALWAYS 0xE
455
456 struct asm_psr
457 {
458 const char * template_name;
459 unsigned long field;
460 };
461
462 struct asm_barrier_opt
463 {
464 const char * template_name;
465 unsigned long value;
466 };
467
468 /* The bit that distinguishes CPSR and SPSR. */
469 #define SPSR_BIT (1 << 22)
470
471 /* The individual PSR flag bits. */
472 #define PSR_c (1 << 16)
473 #define PSR_x (1 << 17)
474 #define PSR_s (1 << 18)
475 #define PSR_f (1 << 19)
476
477 struct reloc_entry
478 {
479 char * name;
480 bfd_reloc_code_real_type reloc;
481 };
482
483 enum vfp_reg_pos
484 {
485 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
486 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
487 };
488
489 enum vfp_ldstm_type
490 {
491 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
492 };
493
494 /* Bits for DEFINED field in neon_typed_alias. */
495 #define NTA_HASTYPE 1
496 #define NTA_HASINDEX 2
497
498 struct neon_typed_alias
499 {
500 unsigned char defined;
501 unsigned char index;
502 struct neon_type_el eltype;
503 };
504
505 /* ARM register categories. This includes coprocessor numbers and various
506 architecture extensions' registers. */
507 enum arm_reg_type
508 {
509 REG_TYPE_RN,
510 REG_TYPE_CP,
511 REG_TYPE_CN,
512 REG_TYPE_FN,
513 REG_TYPE_VFS,
514 REG_TYPE_VFD,
515 REG_TYPE_NQ,
516 REG_TYPE_VFSD,
517 REG_TYPE_NDQ,
518 REG_TYPE_NSDQ,
519 REG_TYPE_VFC,
520 REG_TYPE_MVF,
521 REG_TYPE_MVD,
522 REG_TYPE_MVFX,
523 REG_TYPE_MVDX,
524 REG_TYPE_MVAX,
525 REG_TYPE_DSPSC,
526 REG_TYPE_MMXWR,
527 REG_TYPE_MMXWC,
528 REG_TYPE_MMXWCG,
529 REG_TYPE_XSCALE,
530 REG_TYPE_RNB
531 };
532
533 /* Structure for a hash table entry for a register.
534 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
535 information which states whether a vector type or index is specified (for a
536 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
537 struct reg_entry
538 {
539 const char * name;
540 unsigned int number;
541 unsigned char type;
542 unsigned char builtin;
543 struct neon_typed_alias * neon;
544 };
545
546 /* Diagnostics used when we don't get a register of the expected type. */
547 const char * const reg_expected_msgs[] =
548 {
549 N_("ARM register expected"),
550 N_("bad or missing co-processor number"),
551 N_("co-processor register expected"),
552 N_("FPA register expected"),
553 N_("VFP single precision register expected"),
554 N_("VFP/Neon double precision register expected"),
555 N_("Neon quad precision register expected"),
556 N_("VFP single or double precision register expected"),
557 N_("Neon double or quad precision register expected"),
558 N_("VFP single, double or Neon quad precision register expected"),
559 N_("VFP system register expected"),
560 N_("Maverick MVF register expected"),
561 N_("Maverick MVD register expected"),
562 N_("Maverick MVFX register expected"),
563 N_("Maverick MVDX register expected"),
564 N_("Maverick MVAX register expected"),
565 N_("Maverick DSPSC register expected"),
566 N_("iWMMXt data register expected"),
567 N_("iWMMXt control register expected"),
568 N_("iWMMXt scalar register expected"),
569 N_("XScale accumulator register expected"),
570 };
571
572 /* Some well known registers that we refer to directly elsewhere. */
573 #define REG_R12 12
574 #define REG_SP 13
575 #define REG_LR 14
576 #define REG_PC 15
577
578 /* ARM instructions take 4bytes in the object file, Thumb instructions
579 take 2: */
580 #define INSN_SIZE 4
581
582 struct asm_opcode
583 {
584 /* Basic string to match. */
585 const char * template_name;
586
587 /* Parameters to instruction. */
588 unsigned int operands[8];
589
590 /* Conditional tag - see opcode_lookup. */
591 unsigned int tag : 4;
592
593 /* Basic instruction code. */
594 unsigned int avalue : 28;
595
596 /* Thumb-format instruction code. */
597 unsigned int tvalue;
598
599 /* Which architecture variant provides this instruction. */
600 const arm_feature_set * avariant;
601 const arm_feature_set * tvariant;
602
603 /* Function to call to encode instruction in ARM format. */
604 void (* aencode) (void);
605
606 /* Function to call to encode instruction in Thumb format. */
607 void (* tencode) (void);
608 };
609
610 /* Defines for various bits that we will want to toggle. */
611 #define INST_IMMEDIATE 0x02000000
612 #define OFFSET_REG 0x02000000
613 #define HWOFFSET_IMM 0x00400000
614 #define SHIFT_BY_REG 0x00000010
615 #define PRE_INDEX 0x01000000
616 #define INDEX_UP 0x00800000
617 #define WRITE_BACK 0x00200000
618 #define LDM_TYPE_2_OR_3 0x00400000
619 #define CPSI_MMOD 0x00020000
620
621 #define LITERAL_MASK 0xf000f000
622 #define OPCODE_MASK 0xfe1fffff
623 #define V4_STR_BIT 0x00000020
624
625 #define T2_SUBS_PC_LR 0xf3de8f00
626
627 #define DATA_OP_SHIFT 21
628
629 #define T2_OPCODE_MASK 0xfe1fffff
630 #define T2_DATA_OP_SHIFT 21
631
632 #define A_COND_MASK 0xf0000000
633 #define A_PUSH_POP_OP_MASK 0x0fff0000
634
635 /* Opcodes for pushing/poping registers to/from the stack. */
636 #define A1_OPCODE_PUSH 0x092d0000
637 #define A2_OPCODE_PUSH 0x052d0004
638 #define A2_OPCODE_POP 0x049d0004
639
640 /* Codes to distinguish the arithmetic instructions. */
641 #define OPCODE_AND 0
642 #define OPCODE_EOR 1
643 #define OPCODE_SUB 2
644 #define OPCODE_RSB 3
645 #define OPCODE_ADD 4
646 #define OPCODE_ADC 5
647 #define OPCODE_SBC 6
648 #define OPCODE_RSC 7
649 #define OPCODE_TST 8
650 #define OPCODE_TEQ 9
651 #define OPCODE_CMP 10
652 #define OPCODE_CMN 11
653 #define OPCODE_ORR 12
654 #define OPCODE_MOV 13
655 #define OPCODE_BIC 14
656 #define OPCODE_MVN 15
657
658 #define T2_OPCODE_AND 0
659 #define T2_OPCODE_BIC 1
660 #define T2_OPCODE_ORR 2
661 #define T2_OPCODE_ORN 3
662 #define T2_OPCODE_EOR 4
663 #define T2_OPCODE_ADD 8
664 #define T2_OPCODE_ADC 10
665 #define T2_OPCODE_SBC 11
666 #define T2_OPCODE_SUB 13
667 #define T2_OPCODE_RSB 14
668
669 #define T_OPCODE_MUL 0x4340
670 #define T_OPCODE_TST 0x4200
671 #define T_OPCODE_CMN 0x42c0
672 #define T_OPCODE_NEG 0x4240
673 #define T_OPCODE_MVN 0x43c0
674
675 #define T_OPCODE_ADD_R3 0x1800
676 #define T_OPCODE_SUB_R3 0x1a00
677 #define T_OPCODE_ADD_HI 0x4400
678 #define T_OPCODE_ADD_ST 0xb000
679 #define T_OPCODE_SUB_ST 0xb080
680 #define T_OPCODE_ADD_SP 0xa800
681 #define T_OPCODE_ADD_PC 0xa000
682 #define T_OPCODE_ADD_I8 0x3000
683 #define T_OPCODE_SUB_I8 0x3800
684 #define T_OPCODE_ADD_I3 0x1c00
685 #define T_OPCODE_SUB_I3 0x1e00
686
687 #define T_OPCODE_ASR_R 0x4100
688 #define T_OPCODE_LSL_R 0x4080
689 #define T_OPCODE_LSR_R 0x40c0
690 #define T_OPCODE_ROR_R 0x41c0
691 #define T_OPCODE_ASR_I 0x1000
692 #define T_OPCODE_LSL_I 0x0000
693 #define T_OPCODE_LSR_I 0x0800
694
695 #define T_OPCODE_MOV_I8 0x2000
696 #define T_OPCODE_CMP_I8 0x2800
697 #define T_OPCODE_CMP_LR 0x4280
698 #define T_OPCODE_MOV_HR 0x4600
699 #define T_OPCODE_CMP_HR 0x4500
700
701 #define T_OPCODE_LDR_PC 0x4800
702 #define T_OPCODE_LDR_SP 0x9800
703 #define T_OPCODE_STR_SP 0x9000
704 #define T_OPCODE_LDR_IW 0x6800
705 #define T_OPCODE_STR_IW 0x6000
706 #define T_OPCODE_LDR_IH 0x8800
707 #define T_OPCODE_STR_IH 0x8000
708 #define T_OPCODE_LDR_IB 0x7800
709 #define T_OPCODE_STR_IB 0x7000
710 #define T_OPCODE_LDR_RW 0x5800
711 #define T_OPCODE_STR_RW 0x5000
712 #define T_OPCODE_LDR_RH 0x5a00
713 #define T_OPCODE_STR_RH 0x5200
714 #define T_OPCODE_LDR_RB 0x5c00
715 #define T_OPCODE_STR_RB 0x5400
716
717 #define T_OPCODE_PUSH 0xb400
718 #define T_OPCODE_POP 0xbc00
719
720 #define T_OPCODE_BRANCH 0xe000
721
722 #define THUMB_SIZE 2 /* Size of thumb instruction. */
723 #define THUMB_PP_PC_LR 0x0100
724 #define THUMB_LOAD_BIT 0x0800
725 #define THUMB2_LOAD_BIT 0x00100000
726
727 #define BAD_ARGS _("bad arguments to instruction")
728 #define BAD_SP _("r13 not allowed here")
729 #define BAD_PC _("r15 not allowed here")
730 #define BAD_COND _("instruction cannot be conditional")
731 #define BAD_OVERLAP _("registers may not be the same")
732 #define BAD_HIREG _("lo register required")
733 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
734 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
735 #define BAD_BRANCH _("branch must be last instruction in IT block")
736 #define BAD_NOT_IT _("instruction not allowed in IT block")
737 #define BAD_FPU _("selected FPU does not support instruction")
738 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
739 #define BAD_IT_COND _("incorrect condition in IT block")
740 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
741 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
742 #define BAD_PC_ADDRESSING \
743 _("cannot use register index with PC-relative addressing")
744 #define BAD_PC_WRITEBACK \
745 _("cannot use writeback with PC-relative addressing")
746 #define BAD_RANGE _("branch out of range")
747
748 static struct hash_control * arm_ops_hsh;
749 static struct hash_control * arm_cond_hsh;
750 static struct hash_control * arm_shift_hsh;
751 static struct hash_control * arm_psr_hsh;
752 static struct hash_control * arm_v7m_psr_hsh;
753 static struct hash_control * arm_reg_hsh;
754 static struct hash_control * arm_reloc_hsh;
755 static struct hash_control * arm_barrier_opt_hsh;
756
757 /* Stuff needed to resolve the label ambiguity
758 As:
759 ...
760 label: <insn>
761 may differ from:
762 ...
763 label:
764 <insn> */
765
766 symbolS * last_label_seen;
767 static int label_is_thumb_function_name = FALSE;
768
769 /* Literal pool structure. Held on a per-section
770 and per-sub-section basis. */
771
772 #define MAX_LITERAL_POOL_SIZE 1024
773 typedef struct literal_pool
774 {
775 expressionS literals [MAX_LITERAL_POOL_SIZE];
776 unsigned int next_free_entry;
777 unsigned int id;
778 symbolS * symbol;
779 segT section;
780 subsegT sub_section;
781 #ifdef OBJ_ELF
782 struct dwarf2_line_info locs [MAX_LITERAL_POOL_SIZE];
783 #endif
784 struct literal_pool * next;
785 } literal_pool;
786
787 /* Pointer to a linked list of literal pools. */
788 literal_pool * list_of_pools = NULL;
789
790 #ifdef OBJ_ELF
791 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
792 #else
793 static struct current_it now_it;
794 #endif
795
796 static inline int
797 now_it_compatible (int cond)
798 {
799 return (cond & ~1) == (now_it.cc & ~1);
800 }
801
802 static inline int
803 conditional_insn (void)
804 {
805 return inst.cond != COND_ALWAYS;
806 }
807
808 static int in_it_block (void);
809
810 static int handle_it_state (void);
811
812 static void force_automatic_it_block_close (void);
813
814 static void it_fsm_post_encode (void);
815
816 #define set_it_insn_type(type) \
817 do \
818 { \
819 inst.it_insn_type = type; \
820 if (handle_it_state () == FAIL) \
821 return; \
822 } \
823 while (0)
824
825 #define set_it_insn_type_nonvoid(type, failret) \
826 do \
827 { \
828 inst.it_insn_type = type; \
829 if (handle_it_state () == FAIL) \
830 return failret; \
831 } \
832 while(0)
833
834 #define set_it_insn_type_last() \
835 do \
836 { \
837 if (inst.cond == COND_ALWAYS) \
838 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
839 else \
840 set_it_insn_type (INSIDE_IT_LAST_INSN); \
841 } \
842 while (0)
843
844 /* Pure syntax. */
845
846 /* This array holds the chars that always start a comment. If the
847 pre-processor is disabled, these aren't very useful. */
848 const char comment_chars[] = "@";
849
850 /* This array holds the chars that only start a comment at the beginning of
851 a line. If the line seems to have the form '# 123 filename'
852 .line and .file directives will appear in the pre-processed output. */
853 /* Note that input_file.c hand checks for '#' at the beginning of the
854 first line of the input file. This is because the compiler outputs
855 #NO_APP at the beginning of its output. */
856 /* Also note that comments like this one will always work. */
857 const char line_comment_chars[] = "#";
858
859 const char line_separator_chars[] = ";";
860
861 /* Chars that can be used to separate mant
862 from exp in floating point numbers. */
863 const char EXP_CHARS[] = "eE";
864
865 /* Chars that mean this number is a floating point constant. */
866 /* As in 0f12.456 */
867 /* or 0d1.2345e12 */
868
869 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
870
871 /* Prefix characters that indicate the start of an immediate
872 value. */
873 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
874
875 /* Separator character handling. */
876
877 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
878
879 static inline int
880 skip_past_char (char ** str, char c)
881 {
882 if (**str == c)
883 {
884 (*str)++;
885 return SUCCESS;
886 }
887 else
888 return FAIL;
889 }
890
891 #define skip_past_comma(str) skip_past_char (str, ',')
892
893 /* Arithmetic expressions (possibly involving symbols). */
894
895 /* Return TRUE if anything in the expression is a bignum. */
896
897 static int
898 walk_no_bignums (symbolS * sp)
899 {
900 if (symbol_get_value_expression (sp)->X_op == O_big)
901 return 1;
902
903 if (symbol_get_value_expression (sp)->X_add_symbol)
904 {
905 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
906 || (symbol_get_value_expression (sp)->X_op_symbol
907 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
908 }
909
910 return 0;
911 }
912
913 static int in_my_get_expression = 0;
914
915 /* Third argument to my_get_expression. */
916 #define GE_NO_PREFIX 0
917 #define GE_IMM_PREFIX 1
918 #define GE_OPT_PREFIX 2
919 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
920 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
921 #define GE_OPT_PREFIX_BIG 3
922
923 static int
924 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
925 {
926 char * save_in;
927 segT seg;
928
929 /* In unified syntax, all prefixes are optional. */
930 if (unified_syntax)
931 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
932 : GE_OPT_PREFIX;
933
934 switch (prefix_mode)
935 {
936 case GE_NO_PREFIX: break;
937 case GE_IMM_PREFIX:
938 if (!is_immediate_prefix (**str))
939 {
940 inst.error = _("immediate expression requires a # prefix");
941 return FAIL;
942 }
943 (*str)++;
944 break;
945 case GE_OPT_PREFIX:
946 case GE_OPT_PREFIX_BIG:
947 if (is_immediate_prefix (**str))
948 (*str)++;
949 break;
950 default: abort ();
951 }
952
953 memset (ep, 0, sizeof (expressionS));
954
955 save_in = input_line_pointer;
956 input_line_pointer = *str;
957 in_my_get_expression = 1;
958 seg = expression (ep);
959 in_my_get_expression = 0;
960
961 if (ep->X_op == O_illegal || ep->X_op == O_absent)
962 {
963 /* We found a bad or missing expression in md_operand(). */
964 *str = input_line_pointer;
965 input_line_pointer = save_in;
966 if (inst.error == NULL)
967 inst.error = (ep->X_op == O_absent
968 ? _("missing expression") :_("bad expression"));
969 return 1;
970 }
971
972 #ifdef OBJ_AOUT
973 if (seg != absolute_section
974 && seg != text_section
975 && seg != data_section
976 && seg != bss_section
977 && seg != undefined_section)
978 {
979 inst.error = _("bad segment");
980 *str = input_line_pointer;
981 input_line_pointer = save_in;
982 return 1;
983 }
984 #else
985 (void) seg;
986 #endif
987
988 /* Get rid of any bignums now, so that we don't generate an error for which
989 we can't establish a line number later on. Big numbers are never valid
990 in instructions, which is where this routine is always called. */
991 if (prefix_mode != GE_OPT_PREFIX_BIG
992 && (ep->X_op == O_big
993 || (ep->X_add_symbol
994 && (walk_no_bignums (ep->X_add_symbol)
995 || (ep->X_op_symbol
996 && walk_no_bignums (ep->X_op_symbol))))))
997 {
998 inst.error = _("invalid constant");
999 *str = input_line_pointer;
1000 input_line_pointer = save_in;
1001 return 1;
1002 }
1003
1004 *str = input_line_pointer;
1005 input_line_pointer = save_in;
1006 return 0;
1007 }
1008
1009 /* Turn a string in input_line_pointer into a floating point constant
1010 of type TYPE, and store the appropriate bytes in *LITP. The number
1011 of LITTLENUMS emitted is stored in *SIZEP. An error message is
1012 returned, or NULL on OK.
1013
1014 Note that fp constants aren't represent in the normal way on the ARM.
1015 In big endian mode, things are as expected. However, in little endian
1016 mode fp constants are big-endian word-wise, and little-endian byte-wise
1017 within the words. For example, (double) 1.1 in big endian mode is
1018 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
1019 the byte sequence 99 99 f1 3f 9a 99 99 99.
1020
1021 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
1022
1023 char *
1024 md_atof (int type, char * litP, int * sizeP)
1025 {
1026 int prec;
1027 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1028 char *t;
1029 int i;
1030
1031 switch (type)
1032 {
1033 case 'f':
1034 case 'F':
1035 case 's':
1036 case 'S':
1037 prec = 2;
1038 break;
1039
1040 case 'd':
1041 case 'D':
1042 case 'r':
1043 case 'R':
1044 prec = 4;
1045 break;
1046
1047 case 'x':
1048 case 'X':
1049 prec = 5;
1050 break;
1051
1052 case 'p':
1053 case 'P':
1054 prec = 5;
1055 break;
1056
1057 default:
1058 *sizeP = 0;
1059 return _("Unrecognized or unsupported floating point constant");
1060 }
1061
1062 t = atof_ieee (input_line_pointer, type, words);
1063 if (t)
1064 input_line_pointer = t;
1065 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1066
1067 if (target_big_endian)
1068 {
1069 for (i = 0; i < prec; i++)
1070 {
1071 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1072 litP += sizeof (LITTLENUM_TYPE);
1073 }
1074 }
1075 else
1076 {
1077 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1078 for (i = prec - 1; i >= 0; i--)
1079 {
1080 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1081 litP += sizeof (LITTLENUM_TYPE);
1082 }
1083 else
1084 /* For a 4 byte float the order of elements in `words' is 1 0.
1085 For an 8 byte float the order is 1 0 3 2. */
1086 for (i = 0; i < prec; i += 2)
1087 {
1088 md_number_to_chars (litP, (valueT) words[i + 1],
1089 sizeof (LITTLENUM_TYPE));
1090 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1091 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1092 litP += 2 * sizeof (LITTLENUM_TYPE);
1093 }
1094 }
1095
1096 return NULL;
1097 }
1098
1099 /* We handle all bad expressions here, so that we can report the faulty
1100 instruction in the error message. */
1101 void
1102 md_operand (expressionS * exp)
1103 {
1104 if (in_my_get_expression)
1105 exp->X_op = O_illegal;
1106 }
1107
1108 /* Immediate values. */
1109
1110 /* Generic immediate-value read function for use in directives.
1111 Accepts anything that 'expression' can fold to a constant.
1112 *val receives the number. */
1113 #ifdef OBJ_ELF
1114 static int
1115 immediate_for_directive (int *val)
1116 {
1117 expressionS exp;
1118 exp.X_op = O_illegal;
1119
1120 if (is_immediate_prefix (*input_line_pointer))
1121 {
1122 input_line_pointer++;
1123 expression (&exp);
1124 }
1125
1126 if (exp.X_op != O_constant)
1127 {
1128 as_bad (_("expected #constant"));
1129 ignore_rest_of_line ();
1130 return FAIL;
1131 }
1132 *val = exp.X_add_number;
1133 return SUCCESS;
1134 }
1135 #endif
1136
1137 /* Register parsing. */
1138
1139 /* Generic register parser. CCP points to what should be the
1140 beginning of a register name. If it is indeed a valid register
1141 name, advance CCP over it and return the reg_entry structure;
1142 otherwise return NULL. Does not issue diagnostics. */
1143
1144 static struct reg_entry *
1145 arm_reg_parse_multi (char **ccp)
1146 {
1147 char *start = *ccp;
1148 char *p;
1149 struct reg_entry *reg;
1150
1151 #ifdef REGISTER_PREFIX
1152 if (*start != REGISTER_PREFIX)
1153 return NULL;
1154 start++;
1155 #endif
1156 #ifdef OPTIONAL_REGISTER_PREFIX
1157 if (*start == OPTIONAL_REGISTER_PREFIX)
1158 start++;
1159 #endif
1160
1161 p = start;
1162 if (!ISALPHA (*p) || !is_name_beginner (*p))
1163 return NULL;
1164
1165 do
1166 p++;
1167 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1168
1169 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1170
1171 if (!reg)
1172 return NULL;
1173
1174 *ccp = p;
1175 return reg;
1176 }
1177
1178 static int
1179 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1180 enum arm_reg_type type)
1181 {
1182 /* Alternative syntaxes are accepted for a few register classes. */
1183 switch (type)
1184 {
1185 case REG_TYPE_MVF:
1186 case REG_TYPE_MVD:
1187 case REG_TYPE_MVFX:
1188 case REG_TYPE_MVDX:
1189 /* Generic coprocessor register names are allowed for these. */
1190 if (reg && reg->type == REG_TYPE_CN)
1191 return reg->number;
1192 break;
1193
1194 case REG_TYPE_CP:
1195 /* For backward compatibility, a bare number is valid here. */
1196 {
1197 unsigned long processor = strtoul (start, ccp, 10);
1198 if (*ccp != start && processor <= 15)
1199 return processor;
1200 }
1201
1202 case REG_TYPE_MMXWC:
1203 /* WC includes WCG. ??? I'm not sure this is true for all
1204 instructions that take WC registers. */
1205 if (reg && reg->type == REG_TYPE_MMXWCG)
1206 return reg->number;
1207 break;
1208
1209 default:
1210 break;
1211 }
1212
1213 return FAIL;
1214 }
1215
1216 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1217 return value is the register number or FAIL. */
1218
1219 static int
1220 arm_reg_parse (char **ccp, enum arm_reg_type type)
1221 {
1222 char *start = *ccp;
1223 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1224 int ret;
1225
1226 /* Do not allow a scalar (reg+index) to parse as a register. */
1227 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1228 return FAIL;
1229
1230 if (reg && reg->type == type)
1231 return reg->number;
1232
1233 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1234 return ret;
1235
1236 *ccp = start;
1237 return FAIL;
1238 }
1239
1240 /* Parse a Neon type specifier. *STR should point at the leading '.'
1241 character. Does no verification at this stage that the type fits the opcode
1242 properly. E.g.,
1243
1244 .i32.i32.s16
1245 .s32.f32
1246 .u16
1247
1248 Can all be legally parsed by this function.
1249
1250 Fills in neon_type struct pointer with parsed information, and updates STR
1251 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1252 type, FAIL if not. */
1253
1254 static int
1255 parse_neon_type (struct neon_type *type, char **str)
1256 {
1257 char *ptr = *str;
1258
1259 if (type)
1260 type->elems = 0;
1261
1262 while (type->elems < NEON_MAX_TYPE_ELS)
1263 {
1264 enum neon_el_type thistype = NT_untyped;
1265 unsigned thissize = -1u;
1266
1267 if (*ptr != '.')
1268 break;
1269
1270 ptr++;
1271
1272 /* Just a size without an explicit type. */
1273 if (ISDIGIT (*ptr))
1274 goto parsesize;
1275
1276 switch (TOLOWER (*ptr))
1277 {
1278 case 'i': thistype = NT_integer; break;
1279 case 'f': thistype = NT_float; break;
1280 case 'p': thistype = NT_poly; break;
1281 case 's': thistype = NT_signed; break;
1282 case 'u': thistype = NT_unsigned; break;
1283 case 'd':
1284 thistype = NT_float;
1285 thissize = 64;
1286 ptr++;
1287 goto done;
1288 default:
1289 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1290 return FAIL;
1291 }
1292
1293 ptr++;
1294
1295 /* .f is an abbreviation for .f32. */
1296 if (thistype == NT_float && !ISDIGIT (*ptr))
1297 thissize = 32;
1298 else
1299 {
1300 parsesize:
1301 thissize = strtoul (ptr, &ptr, 10);
1302
1303 if (thissize != 8 && thissize != 16 && thissize != 32
1304 && thissize != 64)
1305 {
1306 as_bad (_("bad size %d in type specifier"), thissize);
1307 return FAIL;
1308 }
1309 }
1310
1311 done:
1312 if (type)
1313 {
1314 type->el[type->elems].type = thistype;
1315 type->el[type->elems].size = thissize;
1316 type->elems++;
1317 }
1318 }
1319
1320 /* Empty/missing type is not a successful parse. */
1321 if (type->elems == 0)
1322 return FAIL;
1323
1324 *str = ptr;
1325
1326 return SUCCESS;
1327 }
1328
1329 /* Errors may be set multiple times during parsing or bit encoding
1330 (particularly in the Neon bits), but usually the earliest error which is set
1331 will be the most meaningful. Avoid overwriting it with later (cascading)
1332 errors by calling this function. */
1333
1334 static void
1335 first_error (const char *err)
1336 {
1337 if (!inst.error)
1338 inst.error = err;
1339 }
1340
1341 /* Parse a single type, e.g. ".s32", leading period included. */
1342 static int
1343 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1344 {
1345 char *str = *ccp;
1346 struct neon_type optype;
1347
1348 if (*str == '.')
1349 {
1350 if (parse_neon_type (&optype, &str) == SUCCESS)
1351 {
1352 if (optype.elems == 1)
1353 *vectype = optype.el[0];
1354 else
1355 {
1356 first_error (_("only one type should be specified for operand"));
1357 return FAIL;
1358 }
1359 }
1360 else
1361 {
1362 first_error (_("vector type expected"));
1363 return FAIL;
1364 }
1365 }
1366 else
1367 return FAIL;
1368
1369 *ccp = str;
1370
1371 return SUCCESS;
1372 }
1373
1374 /* Special meanings for indices (which have a range of 0-7), which will fit into
1375 a 4-bit integer. */
1376
1377 #define NEON_ALL_LANES 15
1378 #define NEON_INTERLEAVE_LANES 14
1379
1380 /* Parse either a register or a scalar, with an optional type. Return the
1381 register number, and optionally fill in the actual type of the register
1382 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1383 type/index information in *TYPEINFO. */
1384
1385 static int
1386 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1387 enum arm_reg_type *rtype,
1388 struct neon_typed_alias *typeinfo)
1389 {
1390 char *str = *ccp;
1391 struct reg_entry *reg = arm_reg_parse_multi (&str);
1392 struct neon_typed_alias atype;
1393 struct neon_type_el parsetype;
1394
1395 atype.defined = 0;
1396 atype.index = -1;
1397 atype.eltype.type = NT_invtype;
1398 atype.eltype.size = -1;
1399
1400 /* Try alternate syntax for some types of register. Note these are mutually
1401 exclusive with the Neon syntax extensions. */
1402 if (reg == NULL)
1403 {
1404 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1405 if (altreg != FAIL)
1406 *ccp = str;
1407 if (typeinfo)
1408 *typeinfo = atype;
1409 return altreg;
1410 }
1411
1412 /* Undo polymorphism when a set of register types may be accepted. */
1413 if ((type == REG_TYPE_NDQ
1414 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1415 || (type == REG_TYPE_VFSD
1416 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1417 || (type == REG_TYPE_NSDQ
1418 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1419 || reg->type == REG_TYPE_NQ))
1420 || (type == REG_TYPE_MMXWC
1421 && (reg->type == REG_TYPE_MMXWCG)))
1422 type = (enum arm_reg_type) reg->type;
1423
1424 if (type != reg->type)
1425 return FAIL;
1426
1427 if (reg->neon)
1428 atype = *reg->neon;
1429
1430 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1431 {
1432 if ((atype.defined & NTA_HASTYPE) != 0)
1433 {
1434 first_error (_("can't redefine type for operand"));
1435 return FAIL;
1436 }
1437 atype.defined |= NTA_HASTYPE;
1438 atype.eltype = parsetype;
1439 }
1440
1441 if (skip_past_char (&str, '[') == SUCCESS)
1442 {
1443 if (type != REG_TYPE_VFD)
1444 {
1445 first_error (_("only D registers may be indexed"));
1446 return FAIL;
1447 }
1448
1449 if ((atype.defined & NTA_HASINDEX) != 0)
1450 {
1451 first_error (_("can't change index for operand"));
1452 return FAIL;
1453 }
1454
1455 atype.defined |= NTA_HASINDEX;
1456
1457 if (skip_past_char (&str, ']') == SUCCESS)
1458 atype.index = NEON_ALL_LANES;
1459 else
1460 {
1461 expressionS exp;
1462
1463 my_get_expression (&exp, &str, GE_NO_PREFIX);
1464
1465 if (exp.X_op != O_constant)
1466 {
1467 first_error (_("constant expression required"));
1468 return FAIL;
1469 }
1470
1471 if (skip_past_char (&str, ']') == FAIL)
1472 return FAIL;
1473
1474 atype.index = exp.X_add_number;
1475 }
1476 }
1477
1478 if (typeinfo)
1479 *typeinfo = atype;
1480
1481 if (rtype)
1482 *rtype = type;
1483
1484 *ccp = str;
1485
1486 return reg->number;
1487 }
1488
1489 /* Like arm_reg_parse, but allow allow the following extra features:
1490 - If RTYPE is non-zero, return the (possibly restricted) type of the
1491 register (e.g. Neon double or quad reg when either has been requested).
1492 - If this is a Neon vector type with additional type information, fill
1493 in the struct pointed to by VECTYPE (if non-NULL).
1494 This function will fault on encountering a scalar. */
1495
1496 static int
1497 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1498 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1499 {
1500 struct neon_typed_alias atype;
1501 char *str = *ccp;
1502 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1503
1504 if (reg == FAIL)
1505 return FAIL;
1506
1507 /* Do not allow regname(... to parse as a register. */
1508 if (*str == '(')
1509 return FAIL;
1510
1511 /* Do not allow a scalar (reg+index) to parse as a register. */
1512 if ((atype.defined & NTA_HASINDEX) != 0)
1513 {
1514 first_error (_("register operand expected, but got scalar"));
1515 return FAIL;
1516 }
1517
1518 if (vectype)
1519 *vectype = atype.eltype;
1520
1521 *ccp = str;
1522
1523 return reg;
1524 }
1525
1526 #define NEON_SCALAR_REG(X) ((X) >> 4)
1527 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1528
1529 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1530 have enough information to be able to do a good job bounds-checking. So, we
1531 just do easy checks here, and do further checks later. */
1532
1533 static int
1534 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1535 {
1536 int reg;
1537 char *str = *ccp;
1538 struct neon_typed_alias atype;
1539
1540 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1541
1542 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1543 return FAIL;
1544
1545 if (atype.index == NEON_ALL_LANES)
1546 {
1547 first_error (_("scalar must have an index"));
1548 return FAIL;
1549 }
1550 else if (atype.index >= 64 / elsize)
1551 {
1552 first_error (_("scalar index out of range"));
1553 return FAIL;
1554 }
1555
1556 if (type)
1557 *type = atype.eltype;
1558
1559 *ccp = str;
1560
1561 return reg * 16 + atype.index;
1562 }
1563
1564 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1565
1566 static long
1567 parse_reg_list (char ** strp)
1568 {
1569 char * str = * strp;
1570 long range = 0;
1571 int another_range;
1572
1573 /* We come back here if we get ranges concatenated by '+' or '|'. */
1574 do
1575 {
1576 another_range = 0;
1577
1578 if (*str == '{')
1579 {
1580 int in_range = 0;
1581 int cur_reg = -1;
1582
1583 str++;
1584 do
1585 {
1586 int reg;
1587
1588 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1589 {
1590 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1591 return FAIL;
1592 }
1593
1594 if (in_range)
1595 {
1596 int i;
1597
1598 if (reg <= cur_reg)
1599 {
1600 first_error (_("bad range in register list"));
1601 return FAIL;
1602 }
1603
1604 for (i = cur_reg + 1; i < reg; i++)
1605 {
1606 if (range & (1 << i))
1607 as_tsktsk
1608 (_("Warning: duplicated register (r%d) in register list"),
1609 i);
1610 else
1611 range |= 1 << i;
1612 }
1613 in_range = 0;
1614 }
1615
1616 if (range & (1 << reg))
1617 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1618 reg);
1619 else if (reg <= cur_reg)
1620 as_tsktsk (_("Warning: register range not in ascending order"));
1621
1622 range |= 1 << reg;
1623 cur_reg = reg;
1624 }
1625 while (skip_past_comma (&str) != FAIL
1626 || (in_range = 1, *str++ == '-'));
1627 str--;
1628
1629 if (*str++ != '}')
1630 {
1631 first_error (_("missing `}'"));
1632 return FAIL;
1633 }
1634 }
1635 else
1636 {
1637 expressionS exp;
1638
1639 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1640 return FAIL;
1641
1642 if (exp.X_op == O_constant)
1643 {
1644 if (exp.X_add_number
1645 != (exp.X_add_number & 0x0000ffff))
1646 {
1647 inst.error = _("invalid register mask");
1648 return FAIL;
1649 }
1650
1651 if ((range & exp.X_add_number) != 0)
1652 {
1653 int regno = range & exp.X_add_number;
1654
1655 regno &= -regno;
1656 regno = (1 << regno) - 1;
1657 as_tsktsk
1658 (_("Warning: duplicated register (r%d) in register list"),
1659 regno);
1660 }
1661
1662 range |= exp.X_add_number;
1663 }
1664 else
1665 {
1666 if (inst.reloc.type != 0)
1667 {
1668 inst.error = _("expression too complex");
1669 return FAIL;
1670 }
1671
1672 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1673 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1674 inst.reloc.pc_rel = 0;
1675 }
1676 }
1677
1678 if (*str == '|' || *str == '+')
1679 {
1680 str++;
1681 another_range = 1;
1682 }
1683 }
1684 while (another_range);
1685
1686 *strp = str;
1687 return range;
1688 }
1689
1690 /* Types of registers in a list. */
1691
1692 enum reg_list_els
1693 {
1694 REGLIST_VFP_S,
1695 REGLIST_VFP_D,
1696 REGLIST_NEON_D
1697 };
1698
1699 /* Parse a VFP register list. If the string is invalid return FAIL.
1700 Otherwise return the number of registers, and set PBASE to the first
1701 register. Parses registers of type ETYPE.
1702 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1703 - Q registers can be used to specify pairs of D registers
1704 - { } can be omitted from around a singleton register list
1705 FIXME: This is not implemented, as it would require backtracking in
1706 some cases, e.g.:
1707 vtbl.8 d3,d4,d5
1708 This could be done (the meaning isn't really ambiguous), but doesn't
1709 fit in well with the current parsing framework.
1710 - 32 D registers may be used (also true for VFPv3).
1711 FIXME: Types are ignored in these register lists, which is probably a
1712 bug. */
1713
1714 static int
1715 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1716 {
1717 char *str = *ccp;
1718 int base_reg;
1719 int new_base;
1720 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1721 int max_regs = 0;
1722 int count = 0;
1723 int warned = 0;
1724 unsigned long mask = 0;
1725 int i;
1726
1727 if (*str != '{')
1728 {
1729 inst.error = _("expecting {");
1730 return FAIL;
1731 }
1732
1733 str++;
1734
1735 switch (etype)
1736 {
1737 case REGLIST_VFP_S:
1738 regtype = REG_TYPE_VFS;
1739 max_regs = 32;
1740 break;
1741
1742 case REGLIST_VFP_D:
1743 regtype = REG_TYPE_VFD;
1744 break;
1745
1746 case REGLIST_NEON_D:
1747 regtype = REG_TYPE_NDQ;
1748 break;
1749 }
1750
1751 if (etype != REGLIST_VFP_S)
1752 {
1753 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1754 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1755 {
1756 max_regs = 32;
1757 if (thumb_mode)
1758 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1759 fpu_vfp_ext_d32);
1760 else
1761 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1762 fpu_vfp_ext_d32);
1763 }
1764 else
1765 max_regs = 16;
1766 }
1767
1768 base_reg = max_regs;
1769
1770 do
1771 {
1772 int setmask = 1, addregs = 1;
1773
1774 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1775
1776 if (new_base == FAIL)
1777 {
1778 first_error (_(reg_expected_msgs[regtype]));
1779 return FAIL;
1780 }
1781
1782 if (new_base >= max_regs)
1783 {
1784 first_error (_("register out of range in list"));
1785 return FAIL;
1786 }
1787
1788 /* Note: a value of 2 * n is returned for the register Q<n>. */
1789 if (regtype == REG_TYPE_NQ)
1790 {
1791 setmask = 3;
1792 addregs = 2;
1793 }
1794
1795 if (new_base < base_reg)
1796 base_reg = new_base;
1797
1798 if (mask & (setmask << new_base))
1799 {
1800 first_error (_("invalid register list"));
1801 return FAIL;
1802 }
1803
1804 if ((mask >> new_base) != 0 && ! warned)
1805 {
1806 as_tsktsk (_("register list not in ascending order"));
1807 warned = 1;
1808 }
1809
1810 mask |= setmask << new_base;
1811 count += addregs;
1812
1813 if (*str == '-') /* We have the start of a range expression */
1814 {
1815 int high_range;
1816
1817 str++;
1818
1819 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1820 == FAIL)
1821 {
1822 inst.error = gettext (reg_expected_msgs[regtype]);
1823 return FAIL;
1824 }
1825
1826 if (high_range >= max_regs)
1827 {
1828 first_error (_("register out of range in list"));
1829 return FAIL;
1830 }
1831
1832 if (regtype == REG_TYPE_NQ)
1833 high_range = high_range + 1;
1834
1835 if (high_range <= new_base)
1836 {
1837 inst.error = _("register range not in ascending order");
1838 return FAIL;
1839 }
1840
1841 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1842 {
1843 if (mask & (setmask << new_base))
1844 {
1845 inst.error = _("invalid register list");
1846 return FAIL;
1847 }
1848
1849 mask |= setmask << new_base;
1850 count += addregs;
1851 }
1852 }
1853 }
1854 while (skip_past_comma (&str) != FAIL);
1855
1856 str++;
1857
1858 /* Sanity check -- should have raised a parse error above. */
1859 if (count == 0 || count > max_regs)
1860 abort ();
1861
1862 *pbase = base_reg;
1863
1864 /* Final test -- the registers must be consecutive. */
1865 mask >>= base_reg;
1866 for (i = 0; i < count; i++)
1867 {
1868 if ((mask & (1u << i)) == 0)
1869 {
1870 inst.error = _("non-contiguous register range");
1871 return FAIL;
1872 }
1873 }
1874
1875 *ccp = str;
1876
1877 return count;
1878 }
1879
1880 /* True if two alias types are the same. */
1881
1882 static bfd_boolean
1883 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1884 {
1885 if (!a && !b)
1886 return TRUE;
1887
1888 if (!a || !b)
1889 return FALSE;
1890
1891 if (a->defined != b->defined)
1892 return FALSE;
1893
1894 if ((a->defined & NTA_HASTYPE) != 0
1895 && (a->eltype.type != b->eltype.type
1896 || a->eltype.size != b->eltype.size))
1897 return FALSE;
1898
1899 if ((a->defined & NTA_HASINDEX) != 0
1900 && (a->index != b->index))
1901 return FALSE;
1902
1903 return TRUE;
1904 }
1905
1906 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1907 The base register is put in *PBASE.
1908 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1909 the return value.
1910 The register stride (minus one) is put in bit 4 of the return value.
1911 Bits [6:5] encode the list length (minus one).
1912 The type of the list elements is put in *ELTYPE, if non-NULL. */
1913
1914 #define NEON_LANE(X) ((X) & 0xf)
1915 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1916 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1917
1918 static int
1919 parse_neon_el_struct_list (char **str, unsigned *pbase,
1920 struct neon_type_el *eltype)
1921 {
1922 char *ptr = *str;
1923 int base_reg = -1;
1924 int reg_incr = -1;
1925 int count = 0;
1926 int lane = -1;
1927 int leading_brace = 0;
1928 enum arm_reg_type rtype = REG_TYPE_NDQ;
1929 const char *const incr_error = _("register stride must be 1 or 2");
1930 const char *const type_error = _("mismatched element/structure types in list");
1931 struct neon_typed_alias firsttype;
1932
1933 if (skip_past_char (&ptr, '{') == SUCCESS)
1934 leading_brace = 1;
1935
1936 do
1937 {
1938 struct neon_typed_alias atype;
1939 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1940
1941 if (getreg == FAIL)
1942 {
1943 first_error (_(reg_expected_msgs[rtype]));
1944 return FAIL;
1945 }
1946
1947 if (base_reg == -1)
1948 {
1949 base_reg = getreg;
1950 if (rtype == REG_TYPE_NQ)
1951 {
1952 reg_incr = 1;
1953 }
1954 firsttype = atype;
1955 }
1956 else if (reg_incr == -1)
1957 {
1958 reg_incr = getreg - base_reg;
1959 if (reg_incr < 1 || reg_incr > 2)
1960 {
1961 first_error (_(incr_error));
1962 return FAIL;
1963 }
1964 }
1965 else if (getreg != base_reg + reg_incr * count)
1966 {
1967 first_error (_(incr_error));
1968 return FAIL;
1969 }
1970
1971 if (! neon_alias_types_same (&atype, &firsttype))
1972 {
1973 first_error (_(type_error));
1974 return FAIL;
1975 }
1976
1977 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1978 modes. */
1979 if (ptr[0] == '-')
1980 {
1981 struct neon_typed_alias htype;
1982 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1983 if (lane == -1)
1984 lane = NEON_INTERLEAVE_LANES;
1985 else if (lane != NEON_INTERLEAVE_LANES)
1986 {
1987 first_error (_(type_error));
1988 return FAIL;
1989 }
1990 if (reg_incr == -1)
1991 reg_incr = 1;
1992 else if (reg_incr != 1)
1993 {
1994 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1995 return FAIL;
1996 }
1997 ptr++;
1998 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1999 if (hireg == FAIL)
2000 {
2001 first_error (_(reg_expected_msgs[rtype]));
2002 return FAIL;
2003 }
2004 if (! neon_alias_types_same (&htype, &firsttype))
2005 {
2006 first_error (_(type_error));
2007 return FAIL;
2008 }
2009 count += hireg + dregs - getreg;
2010 continue;
2011 }
2012
2013 /* If we're using Q registers, we can't use [] or [n] syntax. */
2014 if (rtype == REG_TYPE_NQ)
2015 {
2016 count += 2;
2017 continue;
2018 }
2019
2020 if ((atype.defined & NTA_HASINDEX) != 0)
2021 {
2022 if (lane == -1)
2023 lane = atype.index;
2024 else if (lane != atype.index)
2025 {
2026 first_error (_(type_error));
2027 return FAIL;
2028 }
2029 }
2030 else if (lane == -1)
2031 lane = NEON_INTERLEAVE_LANES;
2032 else if (lane != NEON_INTERLEAVE_LANES)
2033 {
2034 first_error (_(type_error));
2035 return FAIL;
2036 }
2037 count++;
2038 }
2039 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
2040
2041 /* No lane set by [x]. We must be interleaving structures. */
2042 if (lane == -1)
2043 lane = NEON_INTERLEAVE_LANES;
2044
2045 /* Sanity check. */
2046 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2047 || (count > 1 && reg_incr == -1))
2048 {
2049 first_error (_("error parsing element/structure list"));
2050 return FAIL;
2051 }
2052
2053 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2054 {
2055 first_error (_("expected }"));
2056 return FAIL;
2057 }
2058
2059 if (reg_incr == -1)
2060 reg_incr = 1;
2061
2062 if (eltype)
2063 *eltype = firsttype.eltype;
2064
2065 *pbase = base_reg;
2066 *str = ptr;
2067
2068 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2069 }
2070
2071 /* Parse an explicit relocation suffix on an expression. This is
2072 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2073 arm_reloc_hsh contains no entries, so this function can only
2074 succeed if there is no () after the word. Returns -1 on error,
2075 BFD_RELOC_UNUSED if there wasn't any suffix. */
2076
2077 static int
2078 parse_reloc (char **str)
2079 {
2080 struct reloc_entry *r;
2081 char *p, *q;
2082
2083 if (**str != '(')
2084 return BFD_RELOC_UNUSED;
2085
2086 p = *str + 1;
2087 q = p;
2088
2089 while (*q && *q != ')' && *q != ',')
2090 q++;
2091 if (*q != ')')
2092 return -1;
2093
2094 if ((r = (struct reloc_entry *)
2095 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2096 return -1;
2097
2098 *str = q + 1;
2099 return r->reloc;
2100 }
2101
2102 /* Directives: register aliases. */
2103
2104 static struct reg_entry *
2105 insert_reg_alias (char *str, unsigned number, int type)
2106 {
2107 struct reg_entry *new_reg;
2108 const char *name;
2109
2110 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2111 {
2112 if (new_reg->builtin)
2113 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2114
2115 /* Only warn about a redefinition if it's not defined as the
2116 same register. */
2117 else if (new_reg->number != number || new_reg->type != type)
2118 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2119
2120 return NULL;
2121 }
2122
2123 name = xstrdup (str);
2124 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2125
2126 new_reg->name = name;
2127 new_reg->number = number;
2128 new_reg->type = type;
2129 new_reg->builtin = FALSE;
2130 new_reg->neon = NULL;
2131
2132 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2133 abort ();
2134
2135 return new_reg;
2136 }
2137
2138 static void
2139 insert_neon_reg_alias (char *str, int number, int type,
2140 struct neon_typed_alias *atype)
2141 {
2142 struct reg_entry *reg = insert_reg_alias (str, number, type);
2143
2144 if (!reg)
2145 {
2146 first_error (_("attempt to redefine typed alias"));
2147 return;
2148 }
2149
2150 if (atype)
2151 {
2152 reg->neon = (struct neon_typed_alias *)
2153 xmalloc (sizeof (struct neon_typed_alias));
2154 *reg->neon = *atype;
2155 }
2156 }
2157
2158 /* Look for the .req directive. This is of the form:
2159
2160 new_register_name .req existing_register_name
2161
2162 If we find one, or if it looks sufficiently like one that we want to
2163 handle any error here, return TRUE. Otherwise return FALSE. */
2164
2165 static bfd_boolean
2166 create_register_alias (char * newname, char *p)
2167 {
2168 struct reg_entry *old;
2169 char *oldname, *nbuf;
2170 size_t nlen;
2171
2172 /* The input scrubber ensures that whitespace after the mnemonic is
2173 collapsed to single spaces. */
2174 oldname = p;
2175 if (strncmp (oldname, " .req ", 6) != 0)
2176 return FALSE;
2177
2178 oldname += 6;
2179 if (*oldname == '\0')
2180 return FALSE;
2181
2182 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2183 if (!old)
2184 {
2185 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2186 return TRUE;
2187 }
2188
2189 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2190 the desired alias name, and p points to its end. If not, then
2191 the desired alias name is in the global original_case_string. */
2192 #ifdef TC_CASE_SENSITIVE
2193 nlen = p - newname;
2194 #else
2195 newname = original_case_string;
2196 nlen = strlen (newname);
2197 #endif
2198
2199 nbuf = (char *) alloca (nlen + 1);
2200 memcpy (nbuf, newname, nlen);
2201 nbuf[nlen] = '\0';
2202
2203 /* Create aliases under the new name as stated; an all-lowercase
2204 version of the new name; and an all-uppercase version of the new
2205 name. */
2206 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2207 {
2208 for (p = nbuf; *p; p++)
2209 *p = TOUPPER (*p);
2210
2211 if (strncmp (nbuf, newname, nlen))
2212 {
2213 /* If this attempt to create an additional alias fails, do not bother
2214 trying to create the all-lower case alias. We will fail and issue
2215 a second, duplicate error message. This situation arises when the
2216 programmer does something like:
2217 foo .req r0
2218 Foo .req r1
2219 The second .req creates the "Foo" alias but then fails to create
2220 the artificial FOO alias because it has already been created by the
2221 first .req. */
2222 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2223 return TRUE;
2224 }
2225
2226 for (p = nbuf; *p; p++)
2227 *p = TOLOWER (*p);
2228
2229 if (strncmp (nbuf, newname, nlen))
2230 insert_reg_alias (nbuf, old->number, old->type);
2231 }
2232
2233 return TRUE;
2234 }
2235
2236 /* Create a Neon typed/indexed register alias using directives, e.g.:
2237 X .dn d5.s32[1]
2238 Y .qn 6.s16
2239 Z .dn d7
2240 T .dn Z[0]
2241 These typed registers can be used instead of the types specified after the
2242 Neon mnemonic, so long as all operands given have types. Types can also be
2243 specified directly, e.g.:
2244 vadd d0.s32, d1.s32, d2.s32 */
2245
2246 static bfd_boolean
2247 create_neon_reg_alias (char *newname, char *p)
2248 {
2249 enum arm_reg_type basetype;
2250 struct reg_entry *basereg;
2251 struct reg_entry mybasereg;
2252 struct neon_type ntype;
2253 struct neon_typed_alias typeinfo;
2254 char *namebuf, *nameend ATTRIBUTE_UNUSED;
2255 int namelen;
2256
2257 typeinfo.defined = 0;
2258 typeinfo.eltype.type = NT_invtype;
2259 typeinfo.eltype.size = -1;
2260 typeinfo.index = -1;
2261
2262 nameend = p;
2263
2264 if (strncmp (p, " .dn ", 5) == 0)
2265 basetype = REG_TYPE_VFD;
2266 else if (strncmp (p, " .qn ", 5) == 0)
2267 basetype = REG_TYPE_NQ;
2268 else
2269 return FALSE;
2270
2271 p += 5;
2272
2273 if (*p == '\0')
2274 return FALSE;
2275
2276 basereg = arm_reg_parse_multi (&p);
2277
2278 if (basereg && basereg->type != basetype)
2279 {
2280 as_bad (_("bad type for register"));
2281 return FALSE;
2282 }
2283
2284 if (basereg == NULL)
2285 {
2286 expressionS exp;
2287 /* Try parsing as an integer. */
2288 my_get_expression (&exp, &p, GE_NO_PREFIX);
2289 if (exp.X_op != O_constant)
2290 {
2291 as_bad (_("expression must be constant"));
2292 return FALSE;
2293 }
2294 basereg = &mybasereg;
2295 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2296 : exp.X_add_number;
2297 basereg->neon = 0;
2298 }
2299
2300 if (basereg->neon)
2301 typeinfo = *basereg->neon;
2302
2303 if (parse_neon_type (&ntype, &p) == SUCCESS)
2304 {
2305 /* We got a type. */
2306 if (typeinfo.defined & NTA_HASTYPE)
2307 {
2308 as_bad (_("can't redefine the type of a register alias"));
2309 return FALSE;
2310 }
2311
2312 typeinfo.defined |= NTA_HASTYPE;
2313 if (ntype.elems != 1)
2314 {
2315 as_bad (_("you must specify a single type only"));
2316 return FALSE;
2317 }
2318 typeinfo.eltype = ntype.el[0];
2319 }
2320
2321 if (skip_past_char (&p, '[') == SUCCESS)
2322 {
2323 expressionS exp;
2324 /* We got a scalar index. */
2325
2326 if (typeinfo.defined & NTA_HASINDEX)
2327 {
2328 as_bad (_("can't redefine the index of a scalar alias"));
2329 return FALSE;
2330 }
2331
2332 my_get_expression (&exp, &p, GE_NO_PREFIX);
2333
2334 if (exp.X_op != O_constant)
2335 {
2336 as_bad (_("scalar index must be constant"));
2337 return FALSE;
2338 }
2339
2340 typeinfo.defined |= NTA_HASINDEX;
2341 typeinfo.index = exp.X_add_number;
2342
2343 if (skip_past_char (&p, ']') == FAIL)
2344 {
2345 as_bad (_("expecting ]"));
2346 return FALSE;
2347 }
2348 }
2349
2350 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2351 the desired alias name, and p points to its end. If not, then
2352 the desired alias name is in the global original_case_string. */
2353 #ifdef TC_CASE_SENSITIVE
2354 namelen = nameend - newname;
2355 #else
2356 newname = original_case_string;
2357 namelen = strlen (newname);
2358 #endif
2359
2360 namebuf = (char *) alloca (namelen + 1);
2361 strncpy (namebuf, newname, namelen);
2362 namebuf[namelen] = '\0';
2363
2364 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2365 typeinfo.defined != 0 ? &typeinfo : NULL);
2366
2367 /* Insert name in all uppercase. */
2368 for (p = namebuf; *p; p++)
2369 *p = TOUPPER (*p);
2370
2371 if (strncmp (namebuf, newname, namelen))
2372 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2373 typeinfo.defined != 0 ? &typeinfo : NULL);
2374
2375 /* Insert name in all lowercase. */
2376 for (p = namebuf; *p; p++)
2377 *p = TOLOWER (*p);
2378
2379 if (strncmp (namebuf, newname, namelen))
2380 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2381 typeinfo.defined != 0 ? &typeinfo : NULL);
2382
2383 return TRUE;
2384 }
2385
2386 /* Should never be called, as .req goes between the alias and the
2387 register name, not at the beginning of the line. */
2388
2389 static void
2390 s_req (int a ATTRIBUTE_UNUSED)
2391 {
2392 as_bad (_("invalid syntax for .req directive"));
2393 }
2394
2395 static void
2396 s_dn (int a ATTRIBUTE_UNUSED)
2397 {
2398 as_bad (_("invalid syntax for .dn directive"));
2399 }
2400
2401 static void
2402 s_qn (int a ATTRIBUTE_UNUSED)
2403 {
2404 as_bad (_("invalid syntax for .qn directive"));
2405 }
2406
2407 /* The .unreq directive deletes an alias which was previously defined
2408 by .req. For example:
2409
2410 my_alias .req r11
2411 .unreq my_alias */
2412
2413 static void
2414 s_unreq (int a ATTRIBUTE_UNUSED)
2415 {
2416 char * name;
2417 char saved_char;
2418
2419 name = input_line_pointer;
2420
2421 while (*input_line_pointer != 0
2422 && *input_line_pointer != ' '
2423 && *input_line_pointer != '\n')
2424 ++input_line_pointer;
2425
2426 saved_char = *input_line_pointer;
2427 *input_line_pointer = 0;
2428
2429 if (!*name)
2430 as_bad (_("invalid syntax for .unreq directive"));
2431 else
2432 {
2433 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2434 name);
2435
2436 if (!reg)
2437 as_bad (_("unknown register alias '%s'"), name);
2438 else if (reg->builtin)
2439 as_warn (_("ignoring attempt to use .unreq on fixed register name: '%s'"),
2440 name);
2441 else
2442 {
2443 char * p;
2444 char * nbuf;
2445
2446 hash_delete (arm_reg_hsh, name, FALSE);
2447 free ((char *) reg->name);
2448 if (reg->neon)
2449 free (reg->neon);
2450 free (reg);
2451
2452 /* Also locate the all upper case and all lower case versions.
2453 Do not complain if we cannot find one or the other as it
2454 was probably deleted above. */
2455
2456 nbuf = strdup (name);
2457 for (p = nbuf; *p; p++)
2458 *p = TOUPPER (*p);
2459 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2460 if (reg)
2461 {
2462 hash_delete (arm_reg_hsh, nbuf, FALSE);
2463 free ((char *) reg->name);
2464 if (reg->neon)
2465 free (reg->neon);
2466 free (reg);
2467 }
2468
2469 for (p = nbuf; *p; p++)
2470 *p = TOLOWER (*p);
2471 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2472 if (reg)
2473 {
2474 hash_delete (arm_reg_hsh, nbuf, FALSE);
2475 free ((char *) reg->name);
2476 if (reg->neon)
2477 free (reg->neon);
2478 free (reg);
2479 }
2480
2481 free (nbuf);
2482 }
2483 }
2484
2485 *input_line_pointer = saved_char;
2486 demand_empty_rest_of_line ();
2487 }
2488
2489 /* Directives: Instruction set selection. */
2490
2491 #ifdef OBJ_ELF
2492 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2493 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2494 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2495 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2496
2497 /* Create a new mapping symbol for the transition to STATE. */
2498
2499 static void
2500 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2501 {
2502 symbolS * symbolP;
2503 const char * symname;
2504 int type;
2505
2506 switch (state)
2507 {
2508 case MAP_DATA:
2509 symname = "$d";
2510 type = BSF_NO_FLAGS;
2511 break;
2512 case MAP_ARM:
2513 symname = "$a";
2514 type = BSF_NO_FLAGS;
2515 break;
2516 case MAP_THUMB:
2517 symname = "$t";
2518 type = BSF_NO_FLAGS;
2519 break;
2520 default:
2521 abort ();
2522 }
2523
2524 symbolP = symbol_new (symname, now_seg, value, frag);
2525 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2526
2527 switch (state)
2528 {
2529 case MAP_ARM:
2530 THUMB_SET_FUNC (symbolP, 0);
2531 ARM_SET_THUMB (symbolP, 0);
2532 ARM_SET_INTERWORK (symbolP, support_interwork);
2533 break;
2534
2535 case MAP_THUMB:
2536 THUMB_SET_FUNC (symbolP, 1);
2537 ARM_SET_THUMB (symbolP, 1);
2538 ARM_SET_INTERWORK (symbolP, support_interwork);
2539 break;
2540
2541 case MAP_DATA:
2542 default:
2543 break;
2544 }
2545
2546 /* Save the mapping symbols for future reference. Also check that
2547 we do not place two mapping symbols at the same offset within a
2548 frag. We'll handle overlap between frags in
2549 check_mapping_symbols.
2550
2551 If .fill or other data filling directive generates zero sized data,
2552 the mapping symbol for the following code will have the same value
2553 as the one generated for the data filling directive. In this case,
2554 we replace the old symbol with the new one at the same address. */
2555 if (value == 0)
2556 {
2557 if (frag->tc_frag_data.first_map != NULL)
2558 {
2559 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2560 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2561 }
2562 frag->tc_frag_data.first_map = symbolP;
2563 }
2564 if (frag->tc_frag_data.last_map != NULL)
2565 {
2566 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2567 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2568 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2569 }
2570 frag->tc_frag_data.last_map = symbolP;
2571 }
2572
2573 /* We must sometimes convert a region marked as code to data during
2574 code alignment, if an odd number of bytes have to be padded. The
2575 code mapping symbol is pushed to an aligned address. */
2576
2577 static void
2578 insert_data_mapping_symbol (enum mstate state,
2579 valueT value, fragS *frag, offsetT bytes)
2580 {
2581 /* If there was already a mapping symbol, remove it. */
2582 if (frag->tc_frag_data.last_map != NULL
2583 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2584 {
2585 symbolS *symp = frag->tc_frag_data.last_map;
2586
2587 if (value == 0)
2588 {
2589 know (frag->tc_frag_data.first_map == symp);
2590 frag->tc_frag_data.first_map = NULL;
2591 }
2592 frag->tc_frag_data.last_map = NULL;
2593 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2594 }
2595
2596 make_mapping_symbol (MAP_DATA, value, frag);
2597 make_mapping_symbol (state, value + bytes, frag);
2598 }
2599
2600 static void mapping_state_2 (enum mstate state, int max_chars);
2601
2602 /* Set the mapping state to STATE. Only call this when about to
2603 emit some STATE bytes to the file. */
2604
2605 void
2606 mapping_state (enum mstate state)
2607 {
2608 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2609
2610 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2611
2612 if (mapstate == state)
2613 /* The mapping symbol has already been emitted.
2614 There is nothing else to do. */
2615 return;
2616
2617 if (state == MAP_ARM || state == MAP_THUMB)
2618 /* PR gas/12931
2619 All ARM instructions require 4-byte alignment.
2620 (Almost) all Thumb instructions require 2-byte alignment.
2621
2622 When emitting instructions into any section, mark the section
2623 appropriately.
2624
2625 Some Thumb instructions are alignment-sensitive modulo 4 bytes,
2626 but themselves require 2-byte alignment; this applies to some
2627 PC- relative forms. However, these cases will invovle implicit
2628 literal pool generation or an explicit .align >=2, both of
2629 which will cause the section to me marked with sufficient
2630 alignment. Thus, we don't handle those cases here. */
2631 record_alignment (now_seg, state == MAP_ARM ? 2 : 1);
2632
2633 if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2634 /* This case will be evaluated later in the next else. */
2635 return;
2636 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2637 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2638 {
2639 /* Only add the symbol if the offset is > 0:
2640 if we're at the first frag, check it's size > 0;
2641 if we're not at the first frag, then for sure
2642 the offset is > 0. */
2643 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2644 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2645
2646 if (add_symbol)
2647 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2648 }
2649
2650 mapping_state_2 (state, 0);
2651 #undef TRANSITION
2652 }
2653
2654 /* Same as mapping_state, but MAX_CHARS bytes have already been
2655 allocated. Put the mapping symbol that far back. */
2656
2657 static void
2658 mapping_state_2 (enum mstate state, int max_chars)
2659 {
2660 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2661
2662 if (!SEG_NORMAL (now_seg))
2663 return;
2664
2665 if (mapstate == state)
2666 /* The mapping symbol has already been emitted.
2667 There is nothing else to do. */
2668 return;
2669
2670 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2671 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2672 }
2673 #else
2674 #define mapping_state(x) ((void)0)
2675 #define mapping_state_2(x, y) ((void)0)
2676 #endif
2677
2678 /* Find the real, Thumb encoded start of a Thumb function. */
2679
2680 #ifdef OBJ_COFF
2681 static symbolS *
2682 find_real_start (symbolS * symbolP)
2683 {
2684 char * real_start;
2685 const char * name = S_GET_NAME (symbolP);
2686 symbolS * new_target;
2687
2688 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2689 #define STUB_NAME ".real_start_of"
2690
2691 if (name == NULL)
2692 abort ();
2693
2694 /* The compiler may generate BL instructions to local labels because
2695 it needs to perform a branch to a far away location. These labels
2696 do not have a corresponding ".real_start_of" label. We check
2697 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2698 the ".real_start_of" convention for nonlocal branches. */
2699 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2700 return symbolP;
2701
2702 real_start = ACONCAT ((STUB_NAME, name, NULL));
2703 new_target = symbol_find (real_start);
2704
2705 if (new_target == NULL)
2706 {
2707 as_warn (_("Failed to find real start of function: %s\n"), name);
2708 new_target = symbolP;
2709 }
2710
2711 return new_target;
2712 }
2713 #endif
2714
2715 static void
2716 opcode_select (int width)
2717 {
2718 switch (width)
2719 {
2720 case 16:
2721 if (! thumb_mode)
2722 {
2723 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2724 as_bad (_("selected processor does not support THUMB opcodes"));
2725
2726 thumb_mode = 1;
2727 /* No need to force the alignment, since we will have been
2728 coming from ARM mode, which is word-aligned. */
2729 record_alignment (now_seg, 1);
2730 }
2731 break;
2732
2733 case 32:
2734 if (thumb_mode)
2735 {
2736 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2737 as_bad (_("selected processor does not support ARM opcodes"));
2738
2739 thumb_mode = 0;
2740
2741 if (!need_pass_2)
2742 frag_align (2, 0, 0);
2743
2744 record_alignment (now_seg, 1);
2745 }
2746 break;
2747
2748 default:
2749 as_bad (_("invalid instruction size selected (%d)"), width);
2750 }
2751 }
2752
2753 static void
2754 s_arm (int ignore ATTRIBUTE_UNUSED)
2755 {
2756 opcode_select (32);
2757 demand_empty_rest_of_line ();
2758 }
2759
2760 static void
2761 s_thumb (int ignore ATTRIBUTE_UNUSED)
2762 {
2763 opcode_select (16);
2764 demand_empty_rest_of_line ();
2765 }
2766
2767 static void
2768 s_code (int unused ATTRIBUTE_UNUSED)
2769 {
2770 int temp;
2771
2772 temp = get_absolute_expression ();
2773 switch (temp)
2774 {
2775 case 16:
2776 case 32:
2777 opcode_select (temp);
2778 break;
2779
2780 default:
2781 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2782 }
2783 }
2784
2785 static void
2786 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2787 {
2788 /* If we are not already in thumb mode go into it, EVEN if
2789 the target processor does not support thumb instructions.
2790 This is used by gcc/config/arm/lib1funcs.asm for example
2791 to compile interworking support functions even if the
2792 target processor should not support interworking. */
2793 if (! thumb_mode)
2794 {
2795 thumb_mode = 2;
2796 record_alignment (now_seg, 1);
2797 }
2798
2799 demand_empty_rest_of_line ();
2800 }
2801
2802 static void
2803 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2804 {
2805 s_thumb (0);
2806
2807 /* The following label is the name/address of the start of a Thumb function.
2808 We need to know this for the interworking support. */
2809 label_is_thumb_function_name = TRUE;
2810 }
2811
2812 /* Perform a .set directive, but also mark the alias as
2813 being a thumb function. */
2814
2815 static void
2816 s_thumb_set (int equiv)
2817 {
2818 /* XXX the following is a duplicate of the code for s_set() in read.c
2819 We cannot just call that code as we need to get at the symbol that
2820 is created. */
2821 char * name;
2822 char delim;
2823 char * end_name;
2824 symbolS * symbolP;
2825
2826 /* Especial apologies for the random logic:
2827 This just grew, and could be parsed much more simply!
2828 Dean - in haste. */
2829 name = input_line_pointer;
2830 delim = get_symbol_end ();
2831 end_name = input_line_pointer;
2832 *end_name = delim;
2833
2834 if (*input_line_pointer != ',')
2835 {
2836 *end_name = 0;
2837 as_bad (_("expected comma after name \"%s\""), name);
2838 *end_name = delim;
2839 ignore_rest_of_line ();
2840 return;
2841 }
2842
2843 input_line_pointer++;
2844 *end_name = 0;
2845
2846 if (name[0] == '.' && name[1] == '\0')
2847 {
2848 /* XXX - this should not happen to .thumb_set. */
2849 abort ();
2850 }
2851
2852 if ((symbolP = symbol_find (name)) == NULL
2853 && (symbolP = md_undefined_symbol (name)) == NULL)
2854 {
2855 #ifndef NO_LISTING
2856 /* When doing symbol listings, play games with dummy fragments living
2857 outside the normal fragment chain to record the file and line info
2858 for this symbol. */
2859 if (listing & LISTING_SYMBOLS)
2860 {
2861 extern struct list_info_struct * listing_tail;
2862 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2863
2864 memset (dummy_frag, 0, sizeof (fragS));
2865 dummy_frag->fr_type = rs_fill;
2866 dummy_frag->line = listing_tail;
2867 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2868 dummy_frag->fr_symbol = symbolP;
2869 }
2870 else
2871 #endif
2872 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2873
2874 #ifdef OBJ_COFF
2875 /* "set" symbols are local unless otherwise specified. */
2876 SF_SET_LOCAL (symbolP);
2877 #endif /* OBJ_COFF */
2878 } /* Make a new symbol. */
2879
2880 symbol_table_insert (symbolP);
2881
2882 * end_name = delim;
2883
2884 if (equiv
2885 && S_IS_DEFINED (symbolP)
2886 && S_GET_SEGMENT (symbolP) != reg_section)
2887 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2888
2889 pseudo_set (symbolP);
2890
2891 demand_empty_rest_of_line ();
2892
2893 /* XXX Now we come to the Thumb specific bit of code. */
2894
2895 THUMB_SET_FUNC (symbolP, 1);
2896 ARM_SET_THUMB (symbolP, 1);
2897 #if defined OBJ_ELF || defined OBJ_COFF
2898 ARM_SET_INTERWORK (symbolP, support_interwork);
2899 #endif
2900 }
2901
2902 /* Directives: Mode selection. */
2903
2904 /* .syntax [unified|divided] - choose the new unified syntax
2905 (same for Arm and Thumb encoding, modulo slight differences in what
2906 can be represented) or the old divergent syntax for each mode. */
2907 static void
2908 s_syntax (int unused ATTRIBUTE_UNUSED)
2909 {
2910 char *name, delim;
2911
2912 name = input_line_pointer;
2913 delim = get_symbol_end ();
2914
2915 if (!strcasecmp (name, "unified"))
2916 unified_syntax = TRUE;
2917 else if (!strcasecmp (name, "divided"))
2918 unified_syntax = FALSE;
2919 else
2920 {
2921 as_bad (_("unrecognized syntax mode \"%s\""), name);
2922 return;
2923 }
2924 *input_line_pointer = delim;
2925 demand_empty_rest_of_line ();
2926 }
2927
2928 /* Directives: sectioning and alignment. */
2929
2930 /* Same as s_align_ptwo but align 0 => align 2. */
2931
2932 static void
2933 s_align (int unused ATTRIBUTE_UNUSED)
2934 {
2935 int temp;
2936 bfd_boolean fill_p;
2937 long temp_fill;
2938 long max_alignment = 15;
2939
2940 temp = get_absolute_expression ();
2941 if (temp > max_alignment)
2942 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2943 else if (temp < 0)
2944 {
2945 as_bad (_("alignment negative. 0 assumed."));
2946 temp = 0;
2947 }
2948
2949 if (*input_line_pointer == ',')
2950 {
2951 input_line_pointer++;
2952 temp_fill = get_absolute_expression ();
2953 fill_p = TRUE;
2954 }
2955 else
2956 {
2957 fill_p = FALSE;
2958 temp_fill = 0;
2959 }
2960
2961 if (!temp)
2962 temp = 2;
2963
2964 /* Only make a frag if we HAVE to. */
2965 if (temp && !need_pass_2)
2966 {
2967 if (!fill_p && subseg_text_p (now_seg))
2968 frag_align_code (temp, 0);
2969 else
2970 frag_align (temp, (int) temp_fill, 0);
2971 }
2972 demand_empty_rest_of_line ();
2973
2974 record_alignment (now_seg, temp);
2975 }
2976
2977 static void
2978 s_bss (int ignore ATTRIBUTE_UNUSED)
2979 {
2980 /* We don't support putting frags in the BSS segment, we fake it by
2981 marking in_bss, then looking at s_skip for clues. */
2982 subseg_set (bss_section, 0);
2983 demand_empty_rest_of_line ();
2984
2985 #ifdef md_elf_section_change_hook
2986 md_elf_section_change_hook ();
2987 #endif
2988 }
2989
2990 static void
2991 s_even (int ignore ATTRIBUTE_UNUSED)
2992 {
2993 /* Never make frag if expect extra pass. */
2994 if (!need_pass_2)
2995 frag_align (1, 0, 0);
2996
2997 record_alignment (now_seg, 1);
2998
2999 demand_empty_rest_of_line ();
3000 }
3001
3002 /* Directives: Literal pools. */
3003
3004 static literal_pool *
3005 find_literal_pool (void)
3006 {
3007 literal_pool * pool;
3008
3009 for (pool = list_of_pools; pool != NULL; pool = pool->next)
3010 {
3011 if (pool->section == now_seg
3012 && pool->sub_section == now_subseg)
3013 break;
3014 }
3015
3016 return pool;
3017 }
3018
3019 static literal_pool *
3020 find_or_make_literal_pool (void)
3021 {
3022 /* Next literal pool ID number. */
3023 static unsigned int latest_pool_num = 1;
3024 literal_pool * pool;
3025
3026 pool = find_literal_pool ();
3027
3028 if (pool == NULL)
3029 {
3030 /* Create a new pool. */
3031 pool = (literal_pool *) xmalloc (sizeof (* pool));
3032 if (! pool)
3033 return NULL;
3034
3035 pool->next_free_entry = 0;
3036 pool->section = now_seg;
3037 pool->sub_section = now_subseg;
3038 pool->next = list_of_pools;
3039 pool->symbol = NULL;
3040
3041 /* Add it to the list. */
3042 list_of_pools = pool;
3043 }
3044
3045 /* New pools, and emptied pools, will have a NULL symbol. */
3046 if (pool->symbol == NULL)
3047 {
3048 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
3049 (valueT) 0, &zero_address_frag);
3050 pool->id = latest_pool_num ++;
3051 }
3052
3053 /* Done. */
3054 return pool;
3055 }
3056
3057 /* Add the literal in the global 'inst'
3058 structure to the relevant literal pool. */
3059
3060 static int
3061 add_to_lit_pool (void)
3062 {
3063 literal_pool * pool;
3064 unsigned int entry;
3065
3066 pool = find_or_make_literal_pool ();
3067
3068 /* Check if this literal value is already in the pool. */
3069 for (entry = 0; entry < pool->next_free_entry; entry ++)
3070 {
3071 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3072 && (inst.reloc.exp.X_op == O_constant)
3073 && (pool->literals[entry].X_add_number
3074 == inst.reloc.exp.X_add_number)
3075 && (pool->literals[entry].X_unsigned
3076 == inst.reloc.exp.X_unsigned))
3077 break;
3078
3079 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3080 && (inst.reloc.exp.X_op == O_symbol)
3081 && (pool->literals[entry].X_add_number
3082 == inst.reloc.exp.X_add_number)
3083 && (pool->literals[entry].X_add_symbol
3084 == inst.reloc.exp.X_add_symbol)
3085 && (pool->literals[entry].X_op_symbol
3086 == inst.reloc.exp.X_op_symbol))
3087 break;
3088 }
3089
3090 /* Do we need to create a new entry? */
3091 if (entry == pool->next_free_entry)
3092 {
3093 if (entry >= MAX_LITERAL_POOL_SIZE)
3094 {
3095 inst.error = _("literal pool overflow");
3096 return FAIL;
3097 }
3098
3099 pool->literals[entry] = inst.reloc.exp;
3100 #ifdef OBJ_ELF
3101 /* PR ld/12974: Record the location of the first source line to reference
3102 this entry in the literal pool. If it turns out during linking that the
3103 symbol does not exist we will be able to give an accurate line number for
3104 the (first use of the) missing reference. */
3105 if (debug_type == DEBUG_DWARF2)
3106 dwarf2_where (pool->locs + entry);
3107 #endif
3108 pool->next_free_entry += 1;
3109 }
3110
3111 inst.reloc.exp.X_op = O_symbol;
3112 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3113 inst.reloc.exp.X_add_symbol = pool->symbol;
3114
3115 return SUCCESS;
3116 }
3117
3118 /* Can't use symbol_new here, so have to create a symbol and then at
3119 a later date assign it a value. Thats what these functions do. */
3120
3121 static void
3122 symbol_locate (symbolS * symbolP,
3123 const char * name, /* It is copied, the caller can modify. */
3124 segT segment, /* Segment identifier (SEG_<something>). */
3125 valueT valu, /* Symbol value. */
3126 fragS * frag) /* Associated fragment. */
3127 {
3128 unsigned int name_length;
3129 char * preserved_copy_of_name;
3130
3131 name_length = strlen (name) + 1; /* +1 for \0. */
3132 obstack_grow (&notes, name, name_length);
3133 preserved_copy_of_name = (char *) obstack_finish (&notes);
3134
3135 #ifdef tc_canonicalize_symbol_name
3136 preserved_copy_of_name =
3137 tc_canonicalize_symbol_name (preserved_copy_of_name);
3138 #endif
3139
3140 S_SET_NAME (symbolP, preserved_copy_of_name);
3141
3142 S_SET_SEGMENT (symbolP, segment);
3143 S_SET_VALUE (symbolP, valu);
3144 symbol_clear_list_pointers (symbolP);
3145
3146 symbol_set_frag (symbolP, frag);
3147
3148 /* Link to end of symbol chain. */
3149 {
3150 extern int symbol_table_frozen;
3151
3152 if (symbol_table_frozen)
3153 abort ();
3154 }
3155
3156 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3157
3158 obj_symbol_new_hook (symbolP);
3159
3160 #ifdef tc_symbol_new_hook
3161 tc_symbol_new_hook (symbolP);
3162 #endif
3163
3164 #ifdef DEBUG_SYMS
3165 verify_symbol_chain (symbol_rootP, symbol_lastP);
3166 #endif /* DEBUG_SYMS */
3167 }
3168
3169
3170 static void
3171 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3172 {
3173 unsigned int entry;
3174 literal_pool * pool;
3175 char sym_name[20];
3176
3177 pool = find_literal_pool ();
3178 if (pool == NULL
3179 || pool->symbol == NULL
3180 || pool->next_free_entry == 0)
3181 return;
3182
3183 mapping_state (MAP_DATA);
3184
3185 /* Align pool as you have word accesses.
3186 Only make a frag if we have to. */
3187 if (!need_pass_2)
3188 frag_align (2, 0, 0);
3189
3190 record_alignment (now_seg, 2);
3191
3192 sprintf (sym_name, "$$lit_\002%x", pool->id);
3193
3194 symbol_locate (pool->symbol, sym_name, now_seg,
3195 (valueT) frag_now_fix (), frag_now);
3196 symbol_table_insert (pool->symbol);
3197
3198 ARM_SET_THUMB (pool->symbol, thumb_mode);
3199
3200 #if defined OBJ_COFF || defined OBJ_ELF
3201 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3202 #endif
3203
3204 for (entry = 0; entry < pool->next_free_entry; entry ++)
3205 {
3206 #ifdef OBJ_ELF
3207 if (debug_type == DEBUG_DWARF2)
3208 dwarf2_gen_line_info (frag_now_fix (), pool->locs + entry);
3209 #endif
3210 /* First output the expression in the instruction to the pool. */
3211 emit_expr (&(pool->literals[entry]), 4); /* .word */
3212 }
3213
3214 /* Mark the pool as empty. */
3215 pool->next_free_entry = 0;
3216 pool->symbol = NULL;
3217 }
3218
3219 #ifdef OBJ_ELF
3220 /* Forward declarations for functions below, in the MD interface
3221 section. */
3222 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3223 static valueT create_unwind_entry (int);
3224 static void start_unwind_section (const segT, int);
3225 static void add_unwind_opcode (valueT, int);
3226 static void flush_pending_unwind (void);
3227
3228 /* Directives: Data. */
3229
3230 static void
3231 s_arm_elf_cons (int nbytes)
3232 {
3233 expressionS exp;
3234
3235 #ifdef md_flush_pending_output
3236 md_flush_pending_output ();
3237 #endif
3238
3239 if (is_it_end_of_statement ())
3240 {
3241 demand_empty_rest_of_line ();
3242 return;
3243 }
3244
3245 #ifdef md_cons_align
3246 md_cons_align (nbytes);
3247 #endif
3248
3249 mapping_state (MAP_DATA);
3250 do
3251 {
3252 int reloc;
3253 char *base = input_line_pointer;
3254
3255 expression (& exp);
3256
3257 if (exp.X_op != O_symbol)
3258 emit_expr (&exp, (unsigned int) nbytes);
3259 else
3260 {
3261 char *before_reloc = input_line_pointer;
3262 reloc = parse_reloc (&input_line_pointer);
3263 if (reloc == -1)
3264 {
3265 as_bad (_("unrecognized relocation suffix"));
3266 ignore_rest_of_line ();
3267 return;
3268 }
3269 else if (reloc == BFD_RELOC_UNUSED)
3270 emit_expr (&exp, (unsigned int) nbytes);
3271 else
3272 {
3273 reloc_howto_type *howto = (reloc_howto_type *)
3274 bfd_reloc_type_lookup (stdoutput,
3275 (bfd_reloc_code_real_type) reloc);
3276 int size = bfd_get_reloc_size (howto);
3277
3278 if (reloc == BFD_RELOC_ARM_PLT32)
3279 {
3280 as_bad (_("(plt) is only valid on branch targets"));
3281 reloc = BFD_RELOC_UNUSED;
3282 size = 0;
3283 }
3284
3285 if (size > nbytes)
3286 as_bad (_("%s relocations do not fit in %d bytes"),
3287 howto->name, nbytes);
3288 else
3289 {
3290 /* We've parsed an expression stopping at O_symbol.
3291 But there may be more expression left now that we
3292 have parsed the relocation marker. Parse it again.
3293 XXX Surely there is a cleaner way to do this. */
3294 char *p = input_line_pointer;
3295 int offset;
3296 char *save_buf = (char *) alloca (input_line_pointer - base);
3297 memcpy (save_buf, base, input_line_pointer - base);
3298 memmove (base + (input_line_pointer - before_reloc),
3299 base, before_reloc - base);
3300
3301 input_line_pointer = base + (input_line_pointer-before_reloc);
3302 expression (&exp);
3303 memcpy (base, save_buf, p - base);
3304
3305 offset = nbytes - size;
3306 p = frag_more ((int) nbytes);
3307 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3308 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3309 }
3310 }
3311 }
3312 }
3313 while (*input_line_pointer++ == ',');
3314
3315 /* Put terminator back into stream. */
3316 input_line_pointer --;
3317 demand_empty_rest_of_line ();
3318 }
3319
3320 /* Emit an expression containing a 32-bit thumb instruction.
3321 Implementation based on put_thumb32_insn. */
3322
3323 static void
3324 emit_thumb32_expr (expressionS * exp)
3325 {
3326 expressionS exp_high = *exp;
3327
3328 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3329 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3330 exp->X_add_number &= 0xffff;
3331 emit_expr (exp, (unsigned int) THUMB_SIZE);
3332 }
3333
3334 /* Guess the instruction size based on the opcode. */
3335
3336 static int
3337 thumb_insn_size (int opcode)
3338 {
3339 if ((unsigned int) opcode < 0xe800u)
3340 return 2;
3341 else if ((unsigned int) opcode >= 0xe8000000u)
3342 return 4;
3343 else
3344 return 0;
3345 }
3346
3347 static bfd_boolean
3348 emit_insn (expressionS *exp, int nbytes)
3349 {
3350 int size = 0;
3351
3352 if (exp->X_op == O_constant)
3353 {
3354 size = nbytes;
3355
3356 if (size == 0)
3357 size = thumb_insn_size (exp->X_add_number);
3358
3359 if (size != 0)
3360 {
3361 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3362 {
3363 as_bad (_(".inst.n operand too big. "\
3364 "Use .inst.w instead"));
3365 size = 0;
3366 }
3367 else
3368 {
3369 if (now_it.state == AUTOMATIC_IT_BLOCK)
3370 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3371 else
3372 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3373
3374 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3375 emit_thumb32_expr (exp);
3376 else
3377 emit_expr (exp, (unsigned int) size);
3378
3379 it_fsm_post_encode ();
3380 }
3381 }
3382 else
3383 as_bad (_("cannot determine Thumb instruction size. " \
3384 "Use .inst.n/.inst.w instead"));
3385 }
3386 else
3387 as_bad (_("constant expression required"));
3388
3389 return (size != 0);
3390 }
3391
3392 /* Like s_arm_elf_cons but do not use md_cons_align and
3393 set the mapping state to MAP_ARM/MAP_THUMB. */
3394
3395 static void
3396 s_arm_elf_inst (int nbytes)
3397 {
3398 if (is_it_end_of_statement ())
3399 {
3400 demand_empty_rest_of_line ();
3401 return;
3402 }
3403
3404 /* Calling mapping_state () here will not change ARM/THUMB,
3405 but will ensure not to be in DATA state. */
3406
3407 if (thumb_mode)
3408 mapping_state (MAP_THUMB);
3409 else
3410 {
3411 if (nbytes != 0)
3412 {
3413 as_bad (_("width suffixes are invalid in ARM mode"));
3414 ignore_rest_of_line ();
3415 return;
3416 }
3417
3418 nbytes = 4;
3419
3420 mapping_state (MAP_ARM);
3421 }
3422
3423 do
3424 {
3425 expressionS exp;
3426
3427 expression (& exp);
3428
3429 if (! emit_insn (& exp, nbytes))
3430 {
3431 ignore_rest_of_line ();
3432 return;
3433 }
3434 }
3435 while (*input_line_pointer++ == ',');
3436
3437 /* Put terminator back into stream. */
3438 input_line_pointer --;
3439 demand_empty_rest_of_line ();
3440 }
3441
3442 /* Parse a .rel31 directive. */
3443
3444 static void
3445 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3446 {
3447 expressionS exp;
3448 char *p;
3449 valueT highbit;
3450
3451 highbit = 0;
3452 if (*input_line_pointer == '1')
3453 highbit = 0x80000000;
3454 else if (*input_line_pointer != '0')
3455 as_bad (_("expected 0 or 1"));
3456
3457 input_line_pointer++;
3458 if (*input_line_pointer != ',')
3459 as_bad (_("missing comma"));
3460 input_line_pointer++;
3461
3462 #ifdef md_flush_pending_output
3463 md_flush_pending_output ();
3464 #endif
3465
3466 #ifdef md_cons_align
3467 md_cons_align (4);
3468 #endif
3469
3470 mapping_state (MAP_DATA);
3471
3472 expression (&exp);
3473
3474 p = frag_more (4);
3475 md_number_to_chars (p, highbit, 4);
3476 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3477 BFD_RELOC_ARM_PREL31);
3478
3479 demand_empty_rest_of_line ();
3480 }
3481
3482 /* Directives: AEABI stack-unwind tables. */
3483
3484 /* Parse an unwind_fnstart directive. Simply records the current location. */
3485
3486 static void
3487 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3488 {
3489 demand_empty_rest_of_line ();
3490 if (unwind.proc_start)
3491 {
3492 as_bad (_("duplicate .fnstart directive"));
3493 return;
3494 }
3495
3496 /* Mark the start of the function. */
3497 unwind.proc_start = expr_build_dot ();
3498
3499 /* Reset the rest of the unwind info. */
3500 unwind.opcode_count = 0;
3501 unwind.table_entry = NULL;
3502 unwind.personality_routine = NULL;
3503 unwind.personality_index = -1;
3504 unwind.frame_size = 0;
3505 unwind.fp_offset = 0;
3506 unwind.fp_reg = REG_SP;
3507 unwind.fp_used = 0;
3508 unwind.sp_restored = 0;
3509 }
3510
3511
3512 /* Parse a handlerdata directive. Creates the exception handling table entry
3513 for the function. */
3514
3515 static void
3516 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3517 {
3518 demand_empty_rest_of_line ();
3519 if (!unwind.proc_start)
3520 as_bad (MISSING_FNSTART);
3521
3522 if (unwind.table_entry)
3523 as_bad (_("duplicate .handlerdata directive"));
3524
3525 create_unwind_entry (1);
3526 }
3527
3528 /* Parse an unwind_fnend directive. Generates the index table entry. */
3529
3530 static void
3531 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3532 {
3533 long where;
3534 char *ptr;
3535 valueT val;
3536 unsigned int marked_pr_dependency;
3537
3538 demand_empty_rest_of_line ();
3539
3540 if (!unwind.proc_start)
3541 {
3542 as_bad (_(".fnend directive without .fnstart"));
3543 return;
3544 }
3545
3546 /* Add eh table entry. */
3547 if (unwind.table_entry == NULL)
3548 val = create_unwind_entry (0);
3549 else
3550 val = 0;
3551
3552 /* Add index table entry. This is two words. */
3553 start_unwind_section (unwind.saved_seg, 1);
3554 frag_align (2, 0, 0);
3555 record_alignment (now_seg, 2);
3556
3557 ptr = frag_more (8);
3558 memset (ptr, 0, 8);
3559 where = frag_now_fix () - 8;
3560
3561 /* Self relative offset of the function start. */
3562 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3563 BFD_RELOC_ARM_PREL31);
3564
3565 /* Indicate dependency on EHABI-defined personality routines to the
3566 linker, if it hasn't been done already. */
3567 marked_pr_dependency
3568 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3569 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3570 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3571 {
3572 static const char *const name[] =
3573 {
3574 "__aeabi_unwind_cpp_pr0",
3575 "__aeabi_unwind_cpp_pr1",
3576 "__aeabi_unwind_cpp_pr2"
3577 };
3578 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3579 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3580 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3581 |= 1 << unwind.personality_index;
3582 }
3583
3584 if (val)
3585 /* Inline exception table entry. */
3586 md_number_to_chars (ptr + 4, val, 4);
3587 else
3588 /* Self relative offset of the table entry. */
3589 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3590 BFD_RELOC_ARM_PREL31);
3591
3592 /* Restore the original section. */
3593 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3594
3595 unwind.proc_start = NULL;
3596 }
3597
3598
3599 /* Parse an unwind_cantunwind directive. */
3600
3601 static void
3602 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3603 {
3604 demand_empty_rest_of_line ();
3605 if (!unwind.proc_start)
3606 as_bad (MISSING_FNSTART);
3607
3608 if (unwind.personality_routine || unwind.personality_index != -1)
3609 as_bad (_("personality routine specified for cantunwind frame"));
3610
3611 unwind.personality_index = -2;
3612 }
3613
3614
3615 /* Parse a personalityindex directive. */
3616
3617 static void
3618 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3619 {
3620 expressionS exp;
3621
3622 if (!unwind.proc_start)
3623 as_bad (MISSING_FNSTART);
3624
3625 if (unwind.personality_routine || unwind.personality_index != -1)
3626 as_bad (_("duplicate .personalityindex directive"));
3627
3628 expression (&exp);
3629
3630 if (exp.X_op != O_constant
3631 || exp.X_add_number < 0 || exp.X_add_number > 15)
3632 {
3633 as_bad (_("bad personality routine number"));
3634 ignore_rest_of_line ();
3635 return;
3636 }
3637
3638 unwind.personality_index = exp.X_add_number;
3639
3640 demand_empty_rest_of_line ();
3641 }
3642
3643
3644 /* Parse a personality directive. */
3645
3646 static void
3647 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3648 {
3649 char *name, *p, c;
3650
3651 if (!unwind.proc_start)
3652 as_bad (MISSING_FNSTART);
3653
3654 if (unwind.personality_routine || unwind.personality_index != -1)
3655 as_bad (_("duplicate .personality directive"));
3656
3657 name = input_line_pointer;
3658 c = get_symbol_end ();
3659 p = input_line_pointer;
3660 unwind.personality_routine = symbol_find_or_make (name);
3661 *p = c;
3662 demand_empty_rest_of_line ();
3663 }
3664
3665
3666 /* Parse a directive saving core registers. */
3667
3668 static void
3669 s_arm_unwind_save_core (void)
3670 {
3671 valueT op;
3672 long range;
3673 int n;
3674
3675 range = parse_reg_list (&input_line_pointer);
3676 if (range == FAIL)
3677 {
3678 as_bad (_("expected register list"));
3679 ignore_rest_of_line ();
3680 return;
3681 }
3682
3683 demand_empty_rest_of_line ();
3684
3685 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3686 into .unwind_save {..., sp...}. We aren't bothered about the value of
3687 ip because it is clobbered by calls. */
3688 if (unwind.sp_restored && unwind.fp_reg == 12
3689 && (range & 0x3000) == 0x1000)
3690 {
3691 unwind.opcode_count--;
3692 unwind.sp_restored = 0;
3693 range = (range | 0x2000) & ~0x1000;
3694 unwind.pending_offset = 0;
3695 }
3696
3697 /* Pop r4-r15. */
3698 if (range & 0xfff0)
3699 {
3700 /* See if we can use the short opcodes. These pop a block of up to 8
3701 registers starting with r4, plus maybe r14. */
3702 for (n = 0; n < 8; n++)
3703 {
3704 /* Break at the first non-saved register. */
3705 if ((range & (1 << (n + 4))) == 0)
3706 break;
3707 }
3708 /* See if there are any other bits set. */
3709 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3710 {
3711 /* Use the long form. */
3712 op = 0x8000 | ((range >> 4) & 0xfff);
3713 add_unwind_opcode (op, 2);
3714 }
3715 else
3716 {
3717 /* Use the short form. */
3718 if (range & 0x4000)
3719 op = 0xa8; /* Pop r14. */
3720 else
3721 op = 0xa0; /* Do not pop r14. */
3722 op |= (n - 1);
3723 add_unwind_opcode (op, 1);
3724 }
3725 }
3726
3727 /* Pop r0-r3. */
3728 if (range & 0xf)
3729 {
3730 op = 0xb100 | (range & 0xf);
3731 add_unwind_opcode (op, 2);
3732 }
3733
3734 /* Record the number of bytes pushed. */
3735 for (n = 0; n < 16; n++)
3736 {
3737 if (range & (1 << n))
3738 unwind.frame_size += 4;
3739 }
3740 }
3741
3742
3743 /* Parse a directive saving FPA registers. */
3744
3745 static void
3746 s_arm_unwind_save_fpa (int reg)
3747 {
3748 expressionS exp;
3749 int num_regs;
3750 valueT op;
3751
3752 /* Get Number of registers to transfer. */
3753 if (skip_past_comma (&input_line_pointer) != FAIL)
3754 expression (&exp);
3755 else
3756 exp.X_op = O_illegal;
3757
3758 if (exp.X_op != O_constant)
3759 {
3760 as_bad (_("expected , <constant>"));
3761 ignore_rest_of_line ();
3762 return;
3763 }
3764
3765 num_regs = exp.X_add_number;
3766
3767 if (num_regs < 1 || num_regs > 4)
3768 {
3769 as_bad (_("number of registers must be in the range [1:4]"));
3770 ignore_rest_of_line ();
3771 return;
3772 }
3773
3774 demand_empty_rest_of_line ();
3775
3776 if (reg == 4)
3777 {
3778 /* Short form. */
3779 op = 0xb4 | (num_regs - 1);
3780 add_unwind_opcode (op, 1);
3781 }
3782 else
3783 {
3784 /* Long form. */
3785 op = 0xc800 | (reg << 4) | (num_regs - 1);
3786 add_unwind_opcode (op, 2);
3787 }
3788 unwind.frame_size += num_regs * 12;
3789 }
3790
3791
3792 /* Parse a directive saving VFP registers for ARMv6 and above. */
3793
3794 static void
3795 s_arm_unwind_save_vfp_armv6 (void)
3796 {
3797 int count;
3798 unsigned int start;
3799 valueT op;
3800 int num_vfpv3_regs = 0;
3801 int num_regs_below_16;
3802
3803 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3804 if (count == FAIL)
3805 {
3806 as_bad (_("expected register list"));
3807 ignore_rest_of_line ();
3808 return;
3809 }
3810
3811 demand_empty_rest_of_line ();
3812
3813 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3814 than FSTMX/FLDMX-style ones). */
3815
3816 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3817 if (start >= 16)
3818 num_vfpv3_regs = count;
3819 else if (start + count > 16)
3820 num_vfpv3_regs = start + count - 16;
3821
3822 if (num_vfpv3_regs > 0)
3823 {
3824 int start_offset = start > 16 ? start - 16 : 0;
3825 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3826 add_unwind_opcode (op, 2);
3827 }
3828
3829 /* Generate opcode for registers numbered in the range 0 .. 15. */
3830 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3831 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3832 if (num_regs_below_16 > 0)
3833 {
3834 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3835 add_unwind_opcode (op, 2);
3836 }
3837
3838 unwind.frame_size += count * 8;
3839 }
3840
3841
3842 /* Parse a directive saving VFP registers for pre-ARMv6. */
3843
3844 static void
3845 s_arm_unwind_save_vfp (void)
3846 {
3847 int count;
3848 unsigned int reg;
3849 valueT op;
3850
3851 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3852 if (count == FAIL)
3853 {
3854 as_bad (_("expected register list"));
3855 ignore_rest_of_line ();
3856 return;
3857 }
3858
3859 demand_empty_rest_of_line ();
3860
3861 if (reg == 8)
3862 {
3863 /* Short form. */
3864 op = 0xb8 | (count - 1);
3865 add_unwind_opcode (op, 1);
3866 }
3867 else
3868 {
3869 /* Long form. */
3870 op = 0xb300 | (reg << 4) | (count - 1);
3871 add_unwind_opcode (op, 2);
3872 }
3873 unwind.frame_size += count * 8 + 4;
3874 }
3875
3876
3877 /* Parse a directive saving iWMMXt data registers. */
3878
3879 static void
3880 s_arm_unwind_save_mmxwr (void)
3881 {
3882 int reg;
3883 int hi_reg;
3884 int i;
3885 unsigned mask = 0;
3886 valueT op;
3887
3888 if (*input_line_pointer == '{')
3889 input_line_pointer++;
3890
3891 do
3892 {
3893 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3894
3895 if (reg == FAIL)
3896 {
3897 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3898 goto error;
3899 }
3900
3901 if (mask >> reg)
3902 as_tsktsk (_("register list not in ascending order"));
3903 mask |= 1 << reg;
3904
3905 if (*input_line_pointer == '-')
3906 {
3907 input_line_pointer++;
3908 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3909 if (hi_reg == FAIL)
3910 {
3911 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3912 goto error;
3913 }
3914 else if (reg >= hi_reg)
3915 {
3916 as_bad (_("bad register range"));
3917 goto error;
3918 }
3919 for (; reg < hi_reg; reg++)
3920 mask |= 1 << reg;
3921 }
3922 }
3923 while (skip_past_comma (&input_line_pointer) != FAIL);
3924
3925 if (*input_line_pointer == '}')
3926 input_line_pointer++;
3927
3928 demand_empty_rest_of_line ();
3929
3930 /* Generate any deferred opcodes because we're going to be looking at
3931 the list. */
3932 flush_pending_unwind ();
3933
3934 for (i = 0; i < 16; i++)
3935 {
3936 if (mask & (1 << i))
3937 unwind.frame_size += 8;
3938 }
3939
3940 /* Attempt to combine with a previous opcode. We do this because gcc
3941 likes to output separate unwind directives for a single block of
3942 registers. */
3943 if (unwind.opcode_count > 0)
3944 {
3945 i = unwind.opcodes[unwind.opcode_count - 1];
3946 if ((i & 0xf8) == 0xc0)
3947 {
3948 i &= 7;
3949 /* Only merge if the blocks are contiguous. */
3950 if (i < 6)
3951 {
3952 if ((mask & 0xfe00) == (1 << 9))
3953 {
3954 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3955 unwind.opcode_count--;
3956 }
3957 }
3958 else if (i == 6 && unwind.opcode_count >= 2)
3959 {
3960 i = unwind.opcodes[unwind.opcode_count - 2];
3961 reg = i >> 4;
3962 i &= 0xf;
3963
3964 op = 0xffff << (reg - 1);
3965 if (reg > 0
3966 && ((mask & op) == (1u << (reg - 1))))
3967 {
3968 op = (1 << (reg + i + 1)) - 1;
3969 op &= ~((1 << reg) - 1);
3970 mask |= op;
3971 unwind.opcode_count -= 2;
3972 }
3973 }
3974 }
3975 }
3976
3977 hi_reg = 15;
3978 /* We want to generate opcodes in the order the registers have been
3979 saved, ie. descending order. */
3980 for (reg = 15; reg >= -1; reg--)
3981 {
3982 /* Save registers in blocks. */
3983 if (reg < 0
3984 || !(mask & (1 << reg)))
3985 {
3986 /* We found an unsaved reg. Generate opcodes to save the
3987 preceding block. */
3988 if (reg != hi_reg)
3989 {
3990 if (reg == 9)
3991 {
3992 /* Short form. */
3993 op = 0xc0 | (hi_reg - 10);
3994 add_unwind_opcode (op, 1);
3995 }
3996 else
3997 {
3998 /* Long form. */
3999 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
4000 add_unwind_opcode (op, 2);
4001 }
4002 }
4003 hi_reg = reg - 1;
4004 }
4005 }
4006
4007 return;
4008 error:
4009 ignore_rest_of_line ();
4010 }
4011
4012 static void
4013 s_arm_unwind_save_mmxwcg (void)
4014 {
4015 int reg;
4016 int hi_reg;
4017 unsigned mask = 0;
4018 valueT op;
4019
4020 if (*input_line_pointer == '{')
4021 input_line_pointer++;
4022
4023 do
4024 {
4025 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4026
4027 if (reg == FAIL)
4028 {
4029 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4030 goto error;
4031 }
4032
4033 reg -= 8;
4034 if (mask >> reg)
4035 as_tsktsk (_("register list not in ascending order"));
4036 mask |= 1 << reg;
4037
4038 if (*input_line_pointer == '-')
4039 {
4040 input_line_pointer++;
4041 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
4042 if (hi_reg == FAIL)
4043 {
4044 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
4045 goto error;
4046 }
4047 else if (reg >= hi_reg)
4048 {
4049 as_bad (_("bad register range"));
4050 goto error;
4051 }
4052 for (; reg < hi_reg; reg++)
4053 mask |= 1 << reg;
4054 }
4055 }
4056 while (skip_past_comma (&input_line_pointer) != FAIL);
4057
4058 if (*input_line_pointer == '}')
4059 input_line_pointer++;
4060
4061 demand_empty_rest_of_line ();
4062
4063 /* Generate any deferred opcodes because we're going to be looking at
4064 the list. */
4065 flush_pending_unwind ();
4066
4067 for (reg = 0; reg < 16; reg++)
4068 {
4069 if (mask & (1 << reg))
4070 unwind.frame_size += 4;
4071 }
4072 op = 0xc700 | mask;
4073 add_unwind_opcode (op, 2);
4074 return;
4075 error:
4076 ignore_rest_of_line ();
4077 }
4078
4079
4080 /* Parse an unwind_save directive.
4081 If the argument is non-zero, this is a .vsave directive. */
4082
4083 static void
4084 s_arm_unwind_save (int arch_v6)
4085 {
4086 char *peek;
4087 struct reg_entry *reg;
4088 bfd_boolean had_brace = FALSE;
4089
4090 if (!unwind.proc_start)
4091 as_bad (MISSING_FNSTART);
4092
4093 /* Figure out what sort of save we have. */
4094 peek = input_line_pointer;
4095
4096 if (*peek == '{')
4097 {
4098 had_brace = TRUE;
4099 peek++;
4100 }
4101
4102 reg = arm_reg_parse_multi (&peek);
4103
4104 if (!reg)
4105 {
4106 as_bad (_("register expected"));
4107 ignore_rest_of_line ();
4108 return;
4109 }
4110
4111 switch (reg->type)
4112 {
4113 case REG_TYPE_FN:
4114 if (had_brace)
4115 {
4116 as_bad (_("FPA .unwind_save does not take a register list"));
4117 ignore_rest_of_line ();
4118 return;
4119 }
4120 input_line_pointer = peek;
4121 s_arm_unwind_save_fpa (reg->number);
4122 return;
4123
4124 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4125 case REG_TYPE_VFD:
4126 if (arch_v6)
4127 s_arm_unwind_save_vfp_armv6 ();
4128 else
4129 s_arm_unwind_save_vfp ();
4130 return;
4131 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4132 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4133
4134 default:
4135 as_bad (_(".unwind_save does not support this kind of register"));
4136 ignore_rest_of_line ();
4137 }
4138 }
4139
4140
4141 /* Parse an unwind_movsp directive. */
4142
4143 static void
4144 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4145 {
4146 int reg;
4147 valueT op;
4148 int offset;
4149
4150 if (!unwind.proc_start)
4151 as_bad (MISSING_FNSTART);
4152
4153 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4154 if (reg == FAIL)
4155 {
4156 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4157 ignore_rest_of_line ();
4158 return;
4159 }
4160
4161 /* Optional constant. */
4162 if (skip_past_comma (&input_line_pointer) != FAIL)
4163 {
4164 if (immediate_for_directive (&offset) == FAIL)
4165 return;
4166 }
4167 else
4168 offset = 0;
4169
4170 demand_empty_rest_of_line ();
4171
4172 if (reg == REG_SP || reg == REG_PC)
4173 {
4174 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4175 return;
4176 }
4177
4178 if (unwind.fp_reg != REG_SP)
4179 as_bad (_("unexpected .unwind_movsp directive"));
4180
4181 /* Generate opcode to restore the value. */
4182 op = 0x90 | reg;
4183 add_unwind_opcode (op, 1);
4184
4185 /* Record the information for later. */
4186 unwind.fp_reg = reg;
4187 unwind.fp_offset = unwind.frame_size - offset;
4188 unwind.sp_restored = 1;
4189 }
4190
4191 /* Parse an unwind_pad directive. */
4192
4193 static void
4194 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4195 {
4196 int offset;
4197
4198 if (!unwind.proc_start)
4199 as_bad (MISSING_FNSTART);
4200
4201 if (immediate_for_directive (&offset) == FAIL)
4202 return;
4203
4204 if (offset & 3)
4205 {
4206 as_bad (_("stack increment must be multiple of 4"));
4207 ignore_rest_of_line ();
4208 return;
4209 }
4210
4211 /* Don't generate any opcodes, just record the details for later. */
4212 unwind.frame_size += offset;
4213 unwind.pending_offset += offset;
4214
4215 demand_empty_rest_of_line ();
4216 }
4217
4218 /* Parse an unwind_setfp directive. */
4219
4220 static void
4221 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4222 {
4223 int sp_reg;
4224 int fp_reg;
4225 int offset;
4226
4227 if (!unwind.proc_start)
4228 as_bad (MISSING_FNSTART);
4229
4230 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4231 if (skip_past_comma (&input_line_pointer) == FAIL)
4232 sp_reg = FAIL;
4233 else
4234 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4235
4236 if (fp_reg == FAIL || sp_reg == FAIL)
4237 {
4238 as_bad (_("expected <reg>, <reg>"));
4239 ignore_rest_of_line ();
4240 return;
4241 }
4242
4243 /* Optional constant. */
4244 if (skip_past_comma (&input_line_pointer) != FAIL)
4245 {
4246 if (immediate_for_directive (&offset) == FAIL)
4247 return;
4248 }
4249 else
4250 offset = 0;
4251
4252 demand_empty_rest_of_line ();
4253
4254 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4255 {
4256 as_bad (_("register must be either sp or set by a previous"
4257 "unwind_movsp directive"));
4258 return;
4259 }
4260
4261 /* Don't generate any opcodes, just record the information for later. */
4262 unwind.fp_reg = fp_reg;
4263 unwind.fp_used = 1;
4264 if (sp_reg == REG_SP)
4265 unwind.fp_offset = unwind.frame_size - offset;
4266 else
4267 unwind.fp_offset -= offset;
4268 }
4269
4270 /* Parse an unwind_raw directive. */
4271
4272 static void
4273 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4274 {
4275 expressionS exp;
4276 /* This is an arbitrary limit. */
4277 unsigned char op[16];
4278 int count;
4279
4280 if (!unwind.proc_start)
4281 as_bad (MISSING_FNSTART);
4282
4283 expression (&exp);
4284 if (exp.X_op == O_constant
4285 && skip_past_comma (&input_line_pointer) != FAIL)
4286 {
4287 unwind.frame_size += exp.X_add_number;
4288 expression (&exp);
4289 }
4290 else
4291 exp.X_op = O_illegal;
4292
4293 if (exp.X_op != O_constant)
4294 {
4295 as_bad (_("expected <offset>, <opcode>"));
4296 ignore_rest_of_line ();
4297 return;
4298 }
4299
4300 count = 0;
4301
4302 /* Parse the opcode. */
4303 for (;;)
4304 {
4305 if (count >= 16)
4306 {
4307 as_bad (_("unwind opcode too long"));
4308 ignore_rest_of_line ();
4309 }
4310 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4311 {
4312 as_bad (_("invalid unwind opcode"));
4313 ignore_rest_of_line ();
4314 return;
4315 }
4316 op[count++] = exp.X_add_number;
4317
4318 /* Parse the next byte. */
4319 if (skip_past_comma (&input_line_pointer) == FAIL)
4320 break;
4321
4322 expression (&exp);
4323 }
4324
4325 /* Add the opcode bytes in reverse order. */
4326 while (count--)
4327 add_unwind_opcode (op[count], 1);
4328
4329 demand_empty_rest_of_line ();
4330 }
4331
4332
4333 /* Parse a .eabi_attribute directive. */
4334
4335 static void
4336 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4337 {
4338 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4339
4340 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4341 attributes_set_explicitly[tag] = 1;
4342 }
4343
4344 /* Emit a tls fix for the symbol. */
4345
4346 static void
4347 s_arm_tls_descseq (int ignored ATTRIBUTE_UNUSED)
4348 {
4349 char *p;
4350 expressionS exp;
4351 #ifdef md_flush_pending_output
4352 md_flush_pending_output ();
4353 #endif
4354
4355 #ifdef md_cons_align
4356 md_cons_align (4);
4357 #endif
4358
4359 /* Since we're just labelling the code, there's no need to define a
4360 mapping symbol. */
4361 expression (&exp);
4362 p = obstack_next_free (&frchain_now->frch_obstack);
4363 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 0,
4364 thumb_mode ? BFD_RELOC_ARM_THM_TLS_DESCSEQ
4365 : BFD_RELOC_ARM_TLS_DESCSEQ);
4366 }
4367 #endif /* OBJ_ELF */
4368
4369 static void s_arm_arch (int);
4370 static void s_arm_object_arch (int);
4371 static void s_arm_cpu (int);
4372 static void s_arm_fpu (int);
4373 static void s_arm_arch_extension (int);
4374
4375 #ifdef TE_PE
4376
4377 static void
4378 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4379 {
4380 expressionS exp;
4381
4382 do
4383 {
4384 expression (&exp);
4385 if (exp.X_op == O_symbol)
4386 exp.X_op = O_secrel;
4387
4388 emit_expr (&exp, 4);
4389 }
4390 while (*input_line_pointer++ == ',');
4391
4392 input_line_pointer--;
4393 demand_empty_rest_of_line ();
4394 }
4395 #endif /* TE_PE */
4396
4397 /* This table describes all the machine specific pseudo-ops the assembler
4398 has to support. The fields are:
4399 pseudo-op name without dot
4400 function to call to execute this pseudo-op
4401 Integer arg to pass to the function. */
4402
4403 const pseudo_typeS md_pseudo_table[] =
4404 {
4405 /* Never called because '.req' does not start a line. */
4406 { "req", s_req, 0 },
4407 /* Following two are likewise never called. */
4408 { "dn", s_dn, 0 },
4409 { "qn", s_qn, 0 },
4410 { "unreq", s_unreq, 0 },
4411 { "bss", s_bss, 0 },
4412 { "align", s_align, 0 },
4413 { "arm", s_arm, 0 },
4414 { "thumb", s_thumb, 0 },
4415 { "code", s_code, 0 },
4416 { "force_thumb", s_force_thumb, 0 },
4417 { "thumb_func", s_thumb_func, 0 },
4418 { "thumb_set", s_thumb_set, 0 },
4419 { "even", s_even, 0 },
4420 { "ltorg", s_ltorg, 0 },
4421 { "pool", s_ltorg, 0 },
4422 { "syntax", s_syntax, 0 },
4423 { "cpu", s_arm_cpu, 0 },
4424 { "arch", s_arm_arch, 0 },
4425 { "object_arch", s_arm_object_arch, 0 },
4426 { "fpu", s_arm_fpu, 0 },
4427 { "arch_extension", s_arm_arch_extension, 0 },
4428 #ifdef OBJ_ELF
4429 { "word", s_arm_elf_cons, 4 },
4430 { "long", s_arm_elf_cons, 4 },
4431 { "inst.n", s_arm_elf_inst, 2 },
4432 { "inst.w", s_arm_elf_inst, 4 },
4433 { "inst", s_arm_elf_inst, 0 },
4434 { "rel31", s_arm_rel31, 0 },
4435 { "fnstart", s_arm_unwind_fnstart, 0 },
4436 { "fnend", s_arm_unwind_fnend, 0 },
4437 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4438 { "personality", s_arm_unwind_personality, 0 },
4439 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4440 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4441 { "save", s_arm_unwind_save, 0 },
4442 { "vsave", s_arm_unwind_save, 1 },
4443 { "movsp", s_arm_unwind_movsp, 0 },
4444 { "pad", s_arm_unwind_pad, 0 },
4445 { "setfp", s_arm_unwind_setfp, 0 },
4446 { "unwind_raw", s_arm_unwind_raw, 0 },
4447 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4448 { "tlsdescseq", s_arm_tls_descseq, 0 },
4449 #else
4450 { "word", cons, 4},
4451
4452 /* These are used for dwarf. */
4453 {"2byte", cons, 2},
4454 {"4byte", cons, 4},
4455 {"8byte", cons, 8},
4456 /* These are used for dwarf2. */
4457 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4458 { "loc", dwarf2_directive_loc, 0 },
4459 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4460 #endif
4461 { "extend", float_cons, 'x' },
4462 { "ldouble", float_cons, 'x' },
4463 { "packed", float_cons, 'p' },
4464 #ifdef TE_PE
4465 {"secrel32", pe_directive_secrel, 0},
4466 #endif
4467 { 0, 0, 0 }
4468 };
4469 \f
4470 /* Parser functions used exclusively in instruction operands. */
4471
4472 /* Generic immediate-value read function for use in insn parsing.
4473 STR points to the beginning of the immediate (the leading #);
4474 VAL receives the value; if the value is outside [MIN, MAX]
4475 issue an error. PREFIX_OPT is true if the immediate prefix is
4476 optional. */
4477
4478 static int
4479 parse_immediate (char **str, int *val, int min, int max,
4480 bfd_boolean prefix_opt)
4481 {
4482 expressionS exp;
4483 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4484 if (exp.X_op != O_constant)
4485 {
4486 inst.error = _("constant expression required");
4487 return FAIL;
4488 }
4489
4490 if (exp.X_add_number < min || exp.X_add_number > max)
4491 {
4492 inst.error = _("immediate value out of range");
4493 return FAIL;
4494 }
4495
4496 *val = exp.X_add_number;
4497 return SUCCESS;
4498 }
4499
4500 /* Less-generic immediate-value read function with the possibility of loading a
4501 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4502 instructions. Puts the result directly in inst.operands[i]. */
4503
4504 static int
4505 parse_big_immediate (char **str, int i)
4506 {
4507 expressionS exp;
4508 char *ptr = *str;
4509
4510 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4511
4512 if (exp.X_op == O_constant)
4513 {
4514 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4515 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4516 O_constant. We have to be careful not to break compilation for
4517 32-bit X_add_number, though. */
4518 if ((exp.X_add_number & ~(offsetT)(0xffffffffU)) != 0)
4519 {
4520 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4521 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4522 inst.operands[i].regisimm = 1;
4523 }
4524 }
4525 else if (exp.X_op == O_big
4526 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32)
4527 {
4528 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4529
4530 /* Bignums have their least significant bits in
4531 generic_bignum[0]. Make sure we put 32 bits in imm and
4532 32 bits in reg, in a (hopefully) portable way. */
4533 gas_assert (parts != 0);
4534
4535 /* Make sure that the number is not too big.
4536 PR 11972: Bignums can now be sign-extended to the
4537 size of a .octa so check that the out of range bits
4538 are all zero or all one. */
4539 if (LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 64)
4540 {
4541 LITTLENUM_TYPE m = -1;
4542
4543 if (generic_bignum[parts * 2] != 0
4544 && generic_bignum[parts * 2] != m)
4545 return FAIL;
4546
4547 for (j = parts * 2 + 1; j < (unsigned) exp.X_add_number; j++)
4548 if (generic_bignum[j] != generic_bignum[j-1])
4549 return FAIL;
4550 }
4551
4552 inst.operands[i].imm = 0;
4553 for (j = 0; j < parts; j++, idx++)
4554 inst.operands[i].imm |= generic_bignum[idx]
4555 << (LITTLENUM_NUMBER_OF_BITS * j);
4556 inst.operands[i].reg = 0;
4557 for (j = 0; j < parts; j++, idx++)
4558 inst.operands[i].reg |= generic_bignum[idx]
4559 << (LITTLENUM_NUMBER_OF_BITS * j);
4560 inst.operands[i].regisimm = 1;
4561 }
4562 else
4563 return FAIL;
4564
4565 *str = ptr;
4566
4567 return SUCCESS;
4568 }
4569
4570 /* Returns the pseudo-register number of an FPA immediate constant,
4571 or FAIL if there isn't a valid constant here. */
4572
4573 static int
4574 parse_fpa_immediate (char ** str)
4575 {
4576 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4577 char * save_in;
4578 expressionS exp;
4579 int i;
4580 int j;
4581
4582 /* First try and match exact strings, this is to guarantee
4583 that some formats will work even for cross assembly. */
4584
4585 for (i = 0; fp_const[i]; i++)
4586 {
4587 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4588 {
4589 char *start = *str;
4590
4591 *str += strlen (fp_const[i]);
4592 if (is_end_of_line[(unsigned char) **str])
4593 return i + 8;
4594 *str = start;
4595 }
4596 }
4597
4598 /* Just because we didn't get a match doesn't mean that the constant
4599 isn't valid, just that it is in a format that we don't
4600 automatically recognize. Try parsing it with the standard
4601 expression routines. */
4602
4603 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4604
4605 /* Look for a raw floating point number. */
4606 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4607 && is_end_of_line[(unsigned char) *save_in])
4608 {
4609 for (i = 0; i < NUM_FLOAT_VALS; i++)
4610 {
4611 for (j = 0; j < MAX_LITTLENUMS; j++)
4612 {
4613 if (words[j] != fp_values[i][j])
4614 break;
4615 }
4616
4617 if (j == MAX_LITTLENUMS)
4618 {
4619 *str = save_in;
4620 return i + 8;
4621 }
4622 }
4623 }
4624
4625 /* Try and parse a more complex expression, this will probably fail
4626 unless the code uses a floating point prefix (eg "0f"). */
4627 save_in = input_line_pointer;
4628 input_line_pointer = *str;
4629 if (expression (&exp) == absolute_section
4630 && exp.X_op == O_big
4631 && exp.X_add_number < 0)
4632 {
4633 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4634 Ditto for 15. */
4635 if (gen_to_words (words, 5, (long) 15) == 0)
4636 {
4637 for (i = 0; i < NUM_FLOAT_VALS; i++)
4638 {
4639 for (j = 0; j < MAX_LITTLENUMS; j++)
4640 {
4641 if (words[j] != fp_values[i][j])
4642 break;
4643 }
4644
4645 if (j == MAX_LITTLENUMS)
4646 {
4647 *str = input_line_pointer;
4648 input_line_pointer = save_in;
4649 return i + 8;
4650 }
4651 }
4652 }
4653 }
4654
4655 *str = input_line_pointer;
4656 input_line_pointer = save_in;
4657 inst.error = _("invalid FPA immediate expression");
4658 return FAIL;
4659 }
4660
4661 /* Returns 1 if a number has "quarter-precision" float format
4662 0baBbbbbbc defgh000 00000000 00000000. */
4663
4664 static int
4665 is_quarter_float (unsigned imm)
4666 {
4667 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4668 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4669 }
4670
4671 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4672 0baBbbbbbc defgh000 00000000 00000000.
4673 The zero and minus-zero cases need special handling, since they can't be
4674 encoded in the "quarter-precision" float format, but can nonetheless be
4675 loaded as integer constants. */
4676
4677 static unsigned
4678 parse_qfloat_immediate (char **ccp, int *immed)
4679 {
4680 char *str = *ccp;
4681 char *fpnum;
4682 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4683 int found_fpchar = 0;
4684
4685 skip_past_char (&str, '#');
4686
4687 /* We must not accidentally parse an integer as a floating-point number. Make
4688 sure that the value we parse is not an integer by checking for special
4689 characters '.' or 'e'.
4690 FIXME: This is a horrible hack, but doing better is tricky because type
4691 information isn't in a very usable state at parse time. */
4692 fpnum = str;
4693 skip_whitespace (fpnum);
4694
4695 if (strncmp (fpnum, "0x", 2) == 0)
4696 return FAIL;
4697 else
4698 {
4699 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4700 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4701 {
4702 found_fpchar = 1;
4703 break;
4704 }
4705
4706 if (!found_fpchar)
4707 return FAIL;
4708 }
4709
4710 if ((str = atof_ieee (str, 's', words)) != NULL)
4711 {
4712 unsigned fpword = 0;
4713 int i;
4714
4715 /* Our FP word must be 32 bits (single-precision FP). */
4716 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4717 {
4718 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4719 fpword |= words[i];
4720 }
4721
4722 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4723 *immed = fpword;
4724 else
4725 return FAIL;
4726
4727 *ccp = str;
4728
4729 return SUCCESS;
4730 }
4731
4732 return FAIL;
4733 }
4734
4735 /* Shift operands. */
4736 enum shift_kind
4737 {
4738 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4739 };
4740
4741 struct asm_shift_name
4742 {
4743 const char *name;
4744 enum shift_kind kind;
4745 };
4746
4747 /* Third argument to parse_shift. */
4748 enum parse_shift_mode
4749 {
4750 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4751 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4752 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4753 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4754 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4755 };
4756
4757 /* Parse a <shift> specifier on an ARM data processing instruction.
4758 This has three forms:
4759
4760 (LSL|LSR|ASL|ASR|ROR) Rs
4761 (LSL|LSR|ASL|ASR|ROR) #imm
4762 RRX
4763
4764 Note that ASL is assimilated to LSL in the instruction encoding, and
4765 RRX to ROR #0 (which cannot be written as such). */
4766
4767 static int
4768 parse_shift (char **str, int i, enum parse_shift_mode mode)
4769 {
4770 const struct asm_shift_name *shift_name;
4771 enum shift_kind shift;
4772 char *s = *str;
4773 char *p = s;
4774 int reg;
4775
4776 for (p = *str; ISALPHA (*p); p++)
4777 ;
4778
4779 if (p == *str)
4780 {
4781 inst.error = _("shift expression expected");
4782 return FAIL;
4783 }
4784
4785 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4786 p - *str);
4787
4788 if (shift_name == NULL)
4789 {
4790 inst.error = _("shift expression expected");
4791 return FAIL;
4792 }
4793
4794 shift = shift_name->kind;
4795
4796 switch (mode)
4797 {
4798 case NO_SHIFT_RESTRICT:
4799 case SHIFT_IMMEDIATE: break;
4800
4801 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4802 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4803 {
4804 inst.error = _("'LSL' or 'ASR' required");
4805 return FAIL;
4806 }
4807 break;
4808
4809 case SHIFT_LSL_IMMEDIATE:
4810 if (shift != SHIFT_LSL)
4811 {
4812 inst.error = _("'LSL' required");
4813 return FAIL;
4814 }
4815 break;
4816
4817 case SHIFT_ASR_IMMEDIATE:
4818 if (shift != SHIFT_ASR)
4819 {
4820 inst.error = _("'ASR' required");
4821 return FAIL;
4822 }
4823 break;
4824
4825 default: abort ();
4826 }
4827
4828 if (shift != SHIFT_RRX)
4829 {
4830 /* Whitespace can appear here if the next thing is a bare digit. */
4831 skip_whitespace (p);
4832
4833 if (mode == NO_SHIFT_RESTRICT
4834 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4835 {
4836 inst.operands[i].imm = reg;
4837 inst.operands[i].immisreg = 1;
4838 }
4839 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4840 return FAIL;
4841 }
4842 inst.operands[i].shift_kind = shift;
4843 inst.operands[i].shifted = 1;
4844 *str = p;
4845 return SUCCESS;
4846 }
4847
4848 /* Parse a <shifter_operand> for an ARM data processing instruction:
4849
4850 #<immediate>
4851 #<immediate>, <rotate>
4852 <Rm>
4853 <Rm>, <shift>
4854
4855 where <shift> is defined by parse_shift above, and <rotate> is a
4856 multiple of 2 between 0 and 30. Validation of immediate operands
4857 is deferred to md_apply_fix. */
4858
4859 static int
4860 parse_shifter_operand (char **str, int i)
4861 {
4862 int value;
4863 expressionS exp;
4864
4865 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4866 {
4867 inst.operands[i].reg = value;
4868 inst.operands[i].isreg = 1;
4869
4870 /* parse_shift will override this if appropriate */
4871 inst.reloc.exp.X_op = O_constant;
4872 inst.reloc.exp.X_add_number = 0;
4873
4874 if (skip_past_comma (str) == FAIL)
4875 return SUCCESS;
4876
4877 /* Shift operation on register. */
4878 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4879 }
4880
4881 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4882 return FAIL;
4883
4884 if (skip_past_comma (str) == SUCCESS)
4885 {
4886 /* #x, y -- ie explicit rotation by Y. */
4887 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4888 return FAIL;
4889
4890 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4891 {
4892 inst.error = _("constant expression expected");
4893 return FAIL;
4894 }
4895
4896 value = exp.X_add_number;
4897 if (value < 0 || value > 30 || value % 2 != 0)
4898 {
4899 inst.error = _("invalid rotation");
4900 return FAIL;
4901 }
4902 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4903 {
4904 inst.error = _("invalid constant");
4905 return FAIL;
4906 }
4907
4908 /* Encode as specified. */
4909 inst.operands[i].imm = inst.reloc.exp.X_add_number | value << 7;
4910 return SUCCESS;
4911 }
4912
4913 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4914 inst.reloc.pc_rel = 0;
4915 return SUCCESS;
4916 }
4917
4918 /* Group relocation information. Each entry in the table contains the
4919 textual name of the relocation as may appear in assembler source
4920 and must end with a colon.
4921 Along with this textual name are the relocation codes to be used if
4922 the corresponding instruction is an ALU instruction (ADD or SUB only),
4923 an LDR, an LDRS, or an LDC. */
4924
4925 struct group_reloc_table_entry
4926 {
4927 const char *name;
4928 int alu_code;
4929 int ldr_code;
4930 int ldrs_code;
4931 int ldc_code;
4932 };
4933
4934 typedef enum
4935 {
4936 /* Varieties of non-ALU group relocation. */
4937
4938 GROUP_LDR,
4939 GROUP_LDRS,
4940 GROUP_LDC
4941 } group_reloc_type;
4942
4943 static struct group_reloc_table_entry group_reloc_table[] =
4944 { /* Program counter relative: */
4945 { "pc_g0_nc",
4946 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4947 0, /* LDR */
4948 0, /* LDRS */
4949 0 }, /* LDC */
4950 { "pc_g0",
4951 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4952 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4953 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4954 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4955 { "pc_g1_nc",
4956 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4957 0, /* LDR */
4958 0, /* LDRS */
4959 0 }, /* LDC */
4960 { "pc_g1",
4961 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4962 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4963 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4964 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4965 { "pc_g2",
4966 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4967 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4968 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4969 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4970 /* Section base relative */
4971 { "sb_g0_nc",
4972 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4973 0, /* LDR */
4974 0, /* LDRS */
4975 0 }, /* LDC */
4976 { "sb_g0",
4977 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4978 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4979 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4980 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4981 { "sb_g1_nc",
4982 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4983 0, /* LDR */
4984 0, /* LDRS */
4985 0 }, /* LDC */
4986 { "sb_g1",
4987 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4988 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4989 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4990 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4991 { "sb_g2",
4992 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4993 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4994 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4995 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4996
4997 /* Given the address of a pointer pointing to the textual name of a group
4998 relocation as may appear in assembler source, attempt to find its details
4999 in group_reloc_table. The pointer will be updated to the character after
5000 the trailing colon. On failure, FAIL will be returned; SUCCESS
5001 otherwise. On success, *entry will be updated to point at the relevant
5002 group_reloc_table entry. */
5003
5004 static int
5005 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
5006 {
5007 unsigned int i;
5008 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
5009 {
5010 int length = strlen (group_reloc_table[i].name);
5011
5012 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
5013 && (*str)[length] == ':')
5014 {
5015 *out = &group_reloc_table[i];
5016 *str += (length + 1);
5017 return SUCCESS;
5018 }
5019 }
5020
5021 return FAIL;
5022 }
5023
5024 /* Parse a <shifter_operand> for an ARM data processing instruction
5025 (as for parse_shifter_operand) where group relocations are allowed:
5026
5027 #<immediate>
5028 #<immediate>, <rotate>
5029 #:<group_reloc>:<expression>
5030 <Rm>
5031 <Rm>, <shift>
5032
5033 where <group_reloc> is one of the strings defined in group_reloc_table.
5034 The hashes are optional.
5035
5036 Everything else is as for parse_shifter_operand. */
5037
5038 static parse_operand_result
5039 parse_shifter_operand_group_reloc (char **str, int i)
5040 {
5041 /* Determine if we have the sequence of characters #: or just :
5042 coming next. If we do, then we check for a group relocation.
5043 If we don't, punt the whole lot to parse_shifter_operand. */
5044
5045 if (((*str)[0] == '#' && (*str)[1] == ':')
5046 || (*str)[0] == ':')
5047 {
5048 struct group_reloc_table_entry *entry;
5049
5050 if ((*str)[0] == '#')
5051 (*str) += 2;
5052 else
5053 (*str)++;
5054
5055 /* Try to parse a group relocation. Anything else is an error. */
5056 if (find_group_reloc_table_entry (str, &entry) == FAIL)
5057 {
5058 inst.error = _("unknown group relocation");
5059 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5060 }
5061
5062 /* We now have the group relocation table entry corresponding to
5063 the name in the assembler source. Next, we parse the expression. */
5064 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
5065 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5066
5067 /* Record the relocation type (always the ALU variant here). */
5068 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
5069 gas_assert (inst.reloc.type != 0);
5070
5071 return PARSE_OPERAND_SUCCESS;
5072 }
5073 else
5074 return parse_shifter_operand (str, i) == SUCCESS
5075 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
5076
5077 /* Never reached. */
5078 }
5079
5080 /* Parse a Neon alignment expression. Information is written to
5081 inst.operands[i]. We assume the initial ':' has been skipped.
5082
5083 align .imm = align << 8, .immisalign=1, .preind=0 */
5084 static parse_operand_result
5085 parse_neon_alignment (char **str, int i)
5086 {
5087 char *p = *str;
5088 expressionS exp;
5089
5090 my_get_expression (&exp, &p, GE_NO_PREFIX);
5091
5092 if (exp.X_op != O_constant)
5093 {
5094 inst.error = _("alignment must be constant");
5095 return PARSE_OPERAND_FAIL;
5096 }
5097
5098 inst.operands[i].imm = exp.X_add_number << 8;
5099 inst.operands[i].immisalign = 1;
5100 /* Alignments are not pre-indexes. */
5101 inst.operands[i].preind = 0;
5102
5103 *str = p;
5104 return PARSE_OPERAND_SUCCESS;
5105 }
5106
5107 /* Parse all forms of an ARM address expression. Information is written
5108 to inst.operands[i] and/or inst.reloc.
5109
5110 Preindexed addressing (.preind=1):
5111
5112 [Rn, #offset] .reg=Rn .reloc.exp=offset
5113 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5114 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5115 .shift_kind=shift .reloc.exp=shift_imm
5116
5117 These three may have a trailing ! which causes .writeback to be set also.
5118
5119 Postindexed addressing (.postind=1, .writeback=1):
5120
5121 [Rn], #offset .reg=Rn .reloc.exp=offset
5122 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5123 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
5124 .shift_kind=shift .reloc.exp=shift_imm
5125
5126 Unindexed addressing (.preind=0, .postind=0):
5127
5128 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5129
5130 Other:
5131
5132 [Rn]{!} shorthand for [Rn,#0]{!}
5133 =immediate .isreg=0 .reloc.exp=immediate
5134 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5135
5136 It is the caller's responsibility to check for addressing modes not
5137 supported by the instruction, and to set inst.reloc.type. */
5138
5139 static parse_operand_result
5140 parse_address_main (char **str, int i, int group_relocations,
5141 group_reloc_type group_type)
5142 {
5143 char *p = *str;
5144 int reg;
5145
5146 if (skip_past_char (&p, '[') == FAIL)
5147 {
5148 if (skip_past_char (&p, '=') == FAIL)
5149 {
5150 /* Bare address - translate to PC-relative offset. */
5151 inst.reloc.pc_rel = 1;
5152 inst.operands[i].reg = REG_PC;
5153 inst.operands[i].isreg = 1;
5154 inst.operands[i].preind = 1;
5155 }
5156 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
5157
5158 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5159 return PARSE_OPERAND_FAIL;
5160
5161 *str = p;
5162 return PARSE_OPERAND_SUCCESS;
5163 }
5164
5165 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5166 {
5167 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5168 return PARSE_OPERAND_FAIL;
5169 }
5170 inst.operands[i].reg = reg;
5171 inst.operands[i].isreg = 1;
5172
5173 if (skip_past_comma (&p) == SUCCESS)
5174 {
5175 inst.operands[i].preind = 1;
5176
5177 if (*p == '+') p++;
5178 else if (*p == '-') p++, inst.operands[i].negative = 1;
5179
5180 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5181 {
5182 inst.operands[i].imm = reg;
5183 inst.operands[i].immisreg = 1;
5184
5185 if (skip_past_comma (&p) == SUCCESS)
5186 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5187 return PARSE_OPERAND_FAIL;
5188 }
5189 else if (skip_past_char (&p, ':') == SUCCESS)
5190 {
5191 /* FIXME: '@' should be used here, but it's filtered out by generic
5192 code before we get to see it here. This may be subject to
5193 change. */
5194 parse_operand_result result = parse_neon_alignment (&p, i);
5195
5196 if (result != PARSE_OPERAND_SUCCESS)
5197 return result;
5198 }
5199 else
5200 {
5201 if (inst.operands[i].negative)
5202 {
5203 inst.operands[i].negative = 0;
5204 p--;
5205 }
5206
5207 if (group_relocations
5208 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5209 {
5210 struct group_reloc_table_entry *entry;
5211
5212 /* Skip over the #: or : sequence. */
5213 if (*p == '#')
5214 p += 2;
5215 else
5216 p++;
5217
5218 /* Try to parse a group relocation. Anything else is an
5219 error. */
5220 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5221 {
5222 inst.error = _("unknown group relocation");
5223 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5224 }
5225
5226 /* We now have the group relocation table entry corresponding to
5227 the name in the assembler source. Next, we parse the
5228 expression. */
5229 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5230 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5231
5232 /* Record the relocation type. */
5233 switch (group_type)
5234 {
5235 case GROUP_LDR:
5236 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5237 break;
5238
5239 case GROUP_LDRS:
5240 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5241 break;
5242
5243 case GROUP_LDC:
5244 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5245 break;
5246
5247 default:
5248 gas_assert (0);
5249 }
5250
5251 if (inst.reloc.type == 0)
5252 {
5253 inst.error = _("this group relocation is not allowed on this instruction");
5254 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5255 }
5256 }
5257 else
5258 {
5259 char *q = p;
5260 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5261 return PARSE_OPERAND_FAIL;
5262 /* If the offset is 0, find out if it's a +0 or -0. */
5263 if (inst.reloc.exp.X_op == O_constant
5264 && inst.reloc.exp.X_add_number == 0)
5265 {
5266 skip_whitespace (q);
5267 if (*q == '#')
5268 {
5269 q++;
5270 skip_whitespace (q);
5271 }
5272 if (*q == '-')
5273 inst.operands[i].negative = 1;
5274 }
5275 }
5276 }
5277 }
5278 else if (skip_past_char (&p, ':') == SUCCESS)
5279 {
5280 /* FIXME: '@' should be used here, but it's filtered out by generic code
5281 before we get to see it here. This may be subject to change. */
5282 parse_operand_result result = parse_neon_alignment (&p, i);
5283
5284 if (result != PARSE_OPERAND_SUCCESS)
5285 return result;
5286 }
5287
5288 if (skip_past_char (&p, ']') == FAIL)
5289 {
5290 inst.error = _("']' expected");
5291 return PARSE_OPERAND_FAIL;
5292 }
5293
5294 if (skip_past_char (&p, '!') == SUCCESS)
5295 inst.operands[i].writeback = 1;
5296
5297 else if (skip_past_comma (&p) == SUCCESS)
5298 {
5299 if (skip_past_char (&p, '{') == SUCCESS)
5300 {
5301 /* [Rn], {expr} - unindexed, with option */
5302 if (parse_immediate (&p, &inst.operands[i].imm,
5303 0, 255, TRUE) == FAIL)
5304 return PARSE_OPERAND_FAIL;
5305
5306 if (skip_past_char (&p, '}') == FAIL)
5307 {
5308 inst.error = _("'}' expected at end of 'option' field");
5309 return PARSE_OPERAND_FAIL;
5310 }
5311 if (inst.operands[i].preind)
5312 {
5313 inst.error = _("cannot combine index with option");
5314 return PARSE_OPERAND_FAIL;
5315 }
5316 *str = p;
5317 return PARSE_OPERAND_SUCCESS;
5318 }
5319 else
5320 {
5321 inst.operands[i].postind = 1;
5322 inst.operands[i].writeback = 1;
5323
5324 if (inst.operands[i].preind)
5325 {
5326 inst.error = _("cannot combine pre- and post-indexing");
5327 return PARSE_OPERAND_FAIL;
5328 }
5329
5330 if (*p == '+') p++;
5331 else if (*p == '-') p++, inst.operands[i].negative = 1;
5332
5333 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5334 {
5335 /* We might be using the immediate for alignment already. If we
5336 are, OR the register number into the low-order bits. */
5337 if (inst.operands[i].immisalign)
5338 inst.operands[i].imm |= reg;
5339 else
5340 inst.operands[i].imm = reg;
5341 inst.operands[i].immisreg = 1;
5342
5343 if (skip_past_comma (&p) == SUCCESS)
5344 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5345 return PARSE_OPERAND_FAIL;
5346 }
5347 else
5348 {
5349 char *q = p;
5350 if (inst.operands[i].negative)
5351 {
5352 inst.operands[i].negative = 0;
5353 p--;
5354 }
5355 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5356 return PARSE_OPERAND_FAIL;
5357 /* If the offset is 0, find out if it's a +0 or -0. */
5358 if (inst.reloc.exp.X_op == O_constant
5359 && inst.reloc.exp.X_add_number == 0)
5360 {
5361 skip_whitespace (q);
5362 if (*q == '#')
5363 {
5364 q++;
5365 skip_whitespace (q);
5366 }
5367 if (*q == '-')
5368 inst.operands[i].negative = 1;
5369 }
5370 }
5371 }
5372 }
5373
5374 /* If at this point neither .preind nor .postind is set, we have a
5375 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5376 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5377 {
5378 inst.operands[i].preind = 1;
5379 inst.reloc.exp.X_op = O_constant;
5380 inst.reloc.exp.X_add_number = 0;
5381 }
5382 *str = p;
5383 return PARSE_OPERAND_SUCCESS;
5384 }
5385
5386 static int
5387 parse_address (char **str, int i)
5388 {
5389 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5390 ? SUCCESS : FAIL;
5391 }
5392
5393 static parse_operand_result
5394 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5395 {
5396 return parse_address_main (str, i, 1, type);
5397 }
5398
5399 /* Parse an operand for a MOVW or MOVT instruction. */
5400 static int
5401 parse_half (char **str)
5402 {
5403 char * p;
5404
5405 p = *str;
5406 skip_past_char (&p, '#');
5407 if (strncasecmp (p, ":lower16:", 9) == 0)
5408 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5409 else if (strncasecmp (p, ":upper16:", 9) == 0)
5410 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5411
5412 if (inst.reloc.type != BFD_RELOC_UNUSED)
5413 {
5414 p += 9;
5415 skip_whitespace (p);
5416 }
5417
5418 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5419 return FAIL;
5420
5421 if (inst.reloc.type == BFD_RELOC_UNUSED)
5422 {
5423 if (inst.reloc.exp.X_op != O_constant)
5424 {
5425 inst.error = _("constant expression expected");
5426 return FAIL;
5427 }
5428 if (inst.reloc.exp.X_add_number < 0
5429 || inst.reloc.exp.X_add_number > 0xffff)
5430 {
5431 inst.error = _("immediate value out of range");
5432 return FAIL;
5433 }
5434 }
5435 *str = p;
5436 return SUCCESS;
5437 }
5438
5439 /* Miscellaneous. */
5440
5441 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5442 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5443 static int
5444 parse_psr (char **str, bfd_boolean lhs)
5445 {
5446 char *p;
5447 unsigned long psr_field;
5448 const struct asm_psr *psr;
5449 char *start;
5450 bfd_boolean is_apsr = FALSE;
5451 bfd_boolean m_profile = ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m);
5452
5453 /* PR gas/12698: If the user has specified -march=all then m_profile will
5454 be TRUE, but we want to ignore it in this case as we are building for any
5455 CPU type, including non-m variants. */
5456 if (selected_cpu.core == arm_arch_any.core)
5457 m_profile = FALSE;
5458
5459 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5460 feature for ease of use and backwards compatibility. */
5461 p = *str;
5462 if (strncasecmp (p, "SPSR", 4) == 0)
5463 {
5464 if (m_profile)
5465 goto unsupported_psr;
5466
5467 psr_field = SPSR_BIT;
5468 }
5469 else if (strncasecmp (p, "CPSR", 4) == 0)
5470 {
5471 if (m_profile)
5472 goto unsupported_psr;
5473
5474 psr_field = 0;
5475 }
5476 else if (strncasecmp (p, "APSR", 4) == 0)
5477 {
5478 /* APSR[_<bits>] can be used as a synonym for CPSR[_<flags>] on ARMv7-A
5479 and ARMv7-R architecture CPUs. */
5480 is_apsr = TRUE;
5481 psr_field = 0;
5482 }
5483 else if (m_profile)
5484 {
5485 start = p;
5486 do
5487 p++;
5488 while (ISALNUM (*p) || *p == '_');
5489
5490 if (strncasecmp (start, "iapsr", 5) == 0
5491 || strncasecmp (start, "eapsr", 5) == 0
5492 || strncasecmp (start, "xpsr", 4) == 0
5493 || strncasecmp (start, "psr", 3) == 0)
5494 p = start + strcspn (start, "rR") + 1;
5495
5496 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5497 p - start);
5498
5499 if (!psr)
5500 return FAIL;
5501
5502 /* If APSR is being written, a bitfield may be specified. Note that
5503 APSR itself is handled above. */
5504 if (psr->field <= 3)
5505 {
5506 psr_field = psr->field;
5507 is_apsr = TRUE;
5508 goto check_suffix;
5509 }
5510
5511 *str = p;
5512 /* M-profile MSR instructions have the mask field set to "10", except
5513 *PSR variants which modify APSR, which may use a different mask (and
5514 have been handled already). Do that by setting the PSR_f field
5515 here. */
5516 return psr->field | (lhs ? PSR_f : 0);
5517 }
5518 else
5519 goto unsupported_psr;
5520
5521 p += 4;
5522 check_suffix:
5523 if (*p == '_')
5524 {
5525 /* A suffix follows. */
5526 p++;
5527 start = p;
5528
5529 do
5530 p++;
5531 while (ISALNUM (*p) || *p == '_');
5532
5533 if (is_apsr)
5534 {
5535 /* APSR uses a notation for bits, rather than fields. */
5536 unsigned int nzcvq_bits = 0;
5537 unsigned int g_bit = 0;
5538 char *bit;
5539
5540 for (bit = start; bit != p; bit++)
5541 {
5542 switch (TOLOWER (*bit))
5543 {
5544 case 'n':
5545 nzcvq_bits |= (nzcvq_bits & 0x01) ? 0x20 : 0x01;
5546 break;
5547
5548 case 'z':
5549 nzcvq_bits |= (nzcvq_bits & 0x02) ? 0x20 : 0x02;
5550 break;
5551
5552 case 'c':
5553 nzcvq_bits |= (nzcvq_bits & 0x04) ? 0x20 : 0x04;
5554 break;
5555
5556 case 'v':
5557 nzcvq_bits |= (nzcvq_bits & 0x08) ? 0x20 : 0x08;
5558 break;
5559
5560 case 'q':
5561 nzcvq_bits |= (nzcvq_bits & 0x10) ? 0x20 : 0x10;
5562 break;
5563
5564 case 'g':
5565 g_bit |= (g_bit & 0x1) ? 0x2 : 0x1;
5566 break;
5567
5568 default:
5569 inst.error = _("unexpected bit specified after APSR");
5570 return FAIL;
5571 }
5572 }
5573
5574 if (nzcvq_bits == 0x1f)
5575 psr_field |= PSR_f;
5576
5577 if (g_bit == 0x1)
5578 {
5579 if (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp))
5580 {
5581 inst.error = _("selected processor does not "
5582 "support DSP extension");
5583 return FAIL;
5584 }
5585
5586 psr_field |= PSR_s;
5587 }
5588
5589 if ((nzcvq_bits & 0x20) != 0
5590 || (nzcvq_bits != 0x1f && nzcvq_bits != 0)
5591 || (g_bit & 0x2) != 0)
5592 {
5593 inst.error = _("bad bitmask specified after APSR");
5594 return FAIL;
5595 }
5596 }
5597 else
5598 {
5599 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5600 p - start);
5601 if (!psr)
5602 goto error;
5603
5604 psr_field |= psr->field;
5605 }
5606 }
5607 else
5608 {
5609 if (ISALNUM (*p))
5610 goto error; /* Garbage after "[CS]PSR". */
5611
5612 /* Unadorned APSR is equivalent to APSR_nzcvq/CPSR_f (for writes). This
5613 is deprecated, but allow it anyway. */
5614 if (is_apsr && lhs)
5615 {
5616 psr_field |= PSR_f;
5617 as_tsktsk (_("writing to APSR without specifying a bitmask is "
5618 "deprecated"));
5619 }
5620 else if (!m_profile)
5621 /* These bits are never right for M-profile devices: don't set them
5622 (only code paths which read/write APSR reach here). */
5623 psr_field |= (PSR_c | PSR_f);
5624 }
5625 *str = p;
5626 return psr_field;
5627
5628 unsupported_psr:
5629 inst.error = _("selected processor does not support requested special "
5630 "purpose register");
5631 return FAIL;
5632
5633 error:
5634 inst.error = _("flag for {c}psr instruction expected");
5635 return FAIL;
5636 }
5637
5638 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5639 value suitable for splatting into the AIF field of the instruction. */
5640
5641 static int
5642 parse_cps_flags (char **str)
5643 {
5644 int val = 0;
5645 int saw_a_flag = 0;
5646 char *s = *str;
5647
5648 for (;;)
5649 switch (*s++)
5650 {
5651 case '\0': case ',':
5652 goto done;
5653
5654 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5655 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5656 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5657
5658 default:
5659 inst.error = _("unrecognized CPS flag");
5660 return FAIL;
5661 }
5662
5663 done:
5664 if (saw_a_flag == 0)
5665 {
5666 inst.error = _("missing CPS flags");
5667 return FAIL;
5668 }
5669
5670 *str = s - 1;
5671 return val;
5672 }
5673
5674 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5675 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5676
5677 static int
5678 parse_endian_specifier (char **str)
5679 {
5680 int little_endian;
5681 char *s = *str;
5682
5683 if (strncasecmp (s, "BE", 2))
5684 little_endian = 0;
5685 else if (strncasecmp (s, "LE", 2))
5686 little_endian = 1;
5687 else
5688 {
5689 inst.error = _("valid endian specifiers are be or le");
5690 return FAIL;
5691 }
5692
5693 if (ISALNUM (s[2]) || s[2] == '_')
5694 {
5695 inst.error = _("valid endian specifiers are be or le");
5696 return FAIL;
5697 }
5698
5699 *str = s + 2;
5700 return little_endian;
5701 }
5702
5703 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5704 value suitable for poking into the rotate field of an sxt or sxta
5705 instruction, or FAIL on error. */
5706
5707 static int
5708 parse_ror (char **str)
5709 {
5710 int rot;
5711 char *s = *str;
5712
5713 if (strncasecmp (s, "ROR", 3) == 0)
5714 s += 3;
5715 else
5716 {
5717 inst.error = _("missing rotation field after comma");
5718 return FAIL;
5719 }
5720
5721 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5722 return FAIL;
5723
5724 switch (rot)
5725 {
5726 case 0: *str = s; return 0x0;
5727 case 8: *str = s; return 0x1;
5728 case 16: *str = s; return 0x2;
5729 case 24: *str = s; return 0x3;
5730
5731 default:
5732 inst.error = _("rotation can only be 0, 8, 16, or 24");
5733 return FAIL;
5734 }
5735 }
5736
5737 /* Parse a conditional code (from conds[] below). The value returned is in the
5738 range 0 .. 14, or FAIL. */
5739 static int
5740 parse_cond (char **str)
5741 {
5742 char *q;
5743 const struct asm_cond *c;
5744 int n;
5745 /* Condition codes are always 2 characters, so matching up to
5746 3 characters is sufficient. */
5747 char cond[3];
5748
5749 q = *str;
5750 n = 0;
5751 while (ISALPHA (*q) && n < 3)
5752 {
5753 cond[n] = TOLOWER (*q);
5754 q++;
5755 n++;
5756 }
5757
5758 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5759 if (!c)
5760 {
5761 inst.error = _("condition required");
5762 return FAIL;
5763 }
5764
5765 *str = q;
5766 return c->value;
5767 }
5768
5769 /* Parse an option for a barrier instruction. Returns the encoding for the
5770 option, or FAIL. */
5771 static int
5772 parse_barrier (char **str)
5773 {
5774 char *p, *q;
5775 const struct asm_barrier_opt *o;
5776
5777 p = q = *str;
5778 while (ISALPHA (*q))
5779 q++;
5780
5781 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5782 q - p);
5783 if (!o)
5784 return FAIL;
5785
5786 *str = q;
5787 return o->value;
5788 }
5789
5790 /* Parse the operands of a table branch instruction. Similar to a memory
5791 operand. */
5792 static int
5793 parse_tb (char **str)
5794 {
5795 char * p = *str;
5796 int reg;
5797
5798 if (skip_past_char (&p, '[') == FAIL)
5799 {
5800 inst.error = _("'[' expected");
5801 return FAIL;
5802 }
5803
5804 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5805 {
5806 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5807 return FAIL;
5808 }
5809 inst.operands[0].reg = reg;
5810
5811 if (skip_past_comma (&p) == FAIL)
5812 {
5813 inst.error = _("',' expected");
5814 return FAIL;
5815 }
5816
5817 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5818 {
5819 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5820 return FAIL;
5821 }
5822 inst.operands[0].imm = reg;
5823
5824 if (skip_past_comma (&p) == SUCCESS)
5825 {
5826 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5827 return FAIL;
5828 if (inst.reloc.exp.X_add_number != 1)
5829 {
5830 inst.error = _("invalid shift");
5831 return FAIL;
5832 }
5833 inst.operands[0].shifted = 1;
5834 }
5835
5836 if (skip_past_char (&p, ']') == FAIL)
5837 {
5838 inst.error = _("']' expected");
5839 return FAIL;
5840 }
5841 *str = p;
5842 return SUCCESS;
5843 }
5844
5845 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5846 information on the types the operands can take and how they are encoded.
5847 Up to four operands may be read; this function handles setting the
5848 ".present" field for each read operand itself.
5849 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5850 else returns FAIL. */
5851
5852 static int
5853 parse_neon_mov (char **str, int *which_operand)
5854 {
5855 int i = *which_operand, val;
5856 enum arm_reg_type rtype;
5857 char *ptr = *str;
5858 struct neon_type_el optype;
5859
5860 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5861 {
5862 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5863 inst.operands[i].reg = val;
5864 inst.operands[i].isscalar = 1;
5865 inst.operands[i].vectype = optype;
5866 inst.operands[i++].present = 1;
5867
5868 if (skip_past_comma (&ptr) == FAIL)
5869 goto wanted_comma;
5870
5871 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5872 goto wanted_arm;
5873
5874 inst.operands[i].reg = val;
5875 inst.operands[i].isreg = 1;
5876 inst.operands[i].present = 1;
5877 }
5878 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5879 != FAIL)
5880 {
5881 /* Cases 0, 1, 2, 3, 5 (D only). */
5882 if (skip_past_comma (&ptr) == FAIL)
5883 goto wanted_comma;
5884
5885 inst.operands[i].reg = val;
5886 inst.operands[i].isreg = 1;
5887 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5888 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5889 inst.operands[i].isvec = 1;
5890 inst.operands[i].vectype = optype;
5891 inst.operands[i++].present = 1;
5892
5893 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5894 {
5895 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5896 Case 13: VMOV <Sd>, <Rm> */
5897 inst.operands[i].reg = val;
5898 inst.operands[i].isreg = 1;
5899 inst.operands[i].present = 1;
5900
5901 if (rtype == REG_TYPE_NQ)
5902 {
5903 first_error (_("can't use Neon quad register here"));
5904 return FAIL;
5905 }
5906 else if (rtype != REG_TYPE_VFS)
5907 {
5908 i++;
5909 if (skip_past_comma (&ptr) == FAIL)
5910 goto wanted_comma;
5911 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5912 goto wanted_arm;
5913 inst.operands[i].reg = val;
5914 inst.operands[i].isreg = 1;
5915 inst.operands[i].present = 1;
5916 }
5917 }
5918 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5919 &optype)) != FAIL)
5920 {
5921 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5922 Case 1: VMOV<c><q> <Dd>, <Dm>
5923 Case 8: VMOV.F32 <Sd>, <Sm>
5924 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5925
5926 inst.operands[i].reg = val;
5927 inst.operands[i].isreg = 1;
5928 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5929 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5930 inst.operands[i].isvec = 1;
5931 inst.operands[i].vectype = optype;
5932 inst.operands[i].present = 1;
5933
5934 if (skip_past_comma (&ptr) == SUCCESS)
5935 {
5936 /* Case 15. */
5937 i++;
5938
5939 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5940 goto wanted_arm;
5941
5942 inst.operands[i].reg = val;
5943 inst.operands[i].isreg = 1;
5944 inst.operands[i++].present = 1;
5945
5946 if (skip_past_comma (&ptr) == FAIL)
5947 goto wanted_comma;
5948
5949 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5950 goto wanted_arm;
5951
5952 inst.operands[i].reg = val;
5953 inst.operands[i].isreg = 1;
5954 inst.operands[i].present = 1;
5955 }
5956 }
5957 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5958 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5959 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5960 Case 10: VMOV.F32 <Sd>, #<imm>
5961 Case 11: VMOV.F64 <Dd>, #<imm> */
5962 inst.operands[i].immisfloat = 1;
5963 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5964 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5965 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5966 ;
5967 else
5968 {
5969 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5970 return FAIL;
5971 }
5972 }
5973 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5974 {
5975 /* Cases 6, 7. */
5976 inst.operands[i].reg = val;
5977 inst.operands[i].isreg = 1;
5978 inst.operands[i++].present = 1;
5979
5980 if (skip_past_comma (&ptr) == FAIL)
5981 goto wanted_comma;
5982
5983 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5984 {
5985 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5986 inst.operands[i].reg = val;
5987 inst.operands[i].isscalar = 1;
5988 inst.operands[i].present = 1;
5989 inst.operands[i].vectype = optype;
5990 }
5991 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5992 {
5993 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5994 inst.operands[i].reg = val;
5995 inst.operands[i].isreg = 1;
5996 inst.operands[i++].present = 1;
5997
5998 if (skip_past_comma (&ptr) == FAIL)
5999 goto wanted_comma;
6000
6001 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
6002 == FAIL)
6003 {
6004 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
6005 return FAIL;
6006 }
6007
6008 inst.operands[i].reg = val;
6009 inst.operands[i].isreg = 1;
6010 inst.operands[i].isvec = 1;
6011 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
6012 inst.operands[i].vectype = optype;
6013 inst.operands[i].present = 1;
6014
6015 if (rtype == REG_TYPE_VFS)
6016 {
6017 /* Case 14. */
6018 i++;
6019 if (skip_past_comma (&ptr) == FAIL)
6020 goto wanted_comma;
6021 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
6022 &optype)) == FAIL)
6023 {
6024 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
6025 return FAIL;
6026 }
6027 inst.operands[i].reg = val;
6028 inst.operands[i].isreg = 1;
6029 inst.operands[i].isvec = 1;
6030 inst.operands[i].issingle = 1;
6031 inst.operands[i].vectype = optype;
6032 inst.operands[i].present = 1;
6033 }
6034 }
6035 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
6036 != FAIL)
6037 {
6038 /* Case 13. */
6039 inst.operands[i].reg = val;
6040 inst.operands[i].isreg = 1;
6041 inst.operands[i].isvec = 1;
6042 inst.operands[i].issingle = 1;
6043 inst.operands[i].vectype = optype;
6044 inst.operands[i].present = 1;
6045 }
6046 }
6047 else
6048 {
6049 first_error (_("parse error"));
6050 return FAIL;
6051 }
6052
6053 /* Successfully parsed the operands. Update args. */
6054 *which_operand = i;
6055 *str = ptr;
6056 return SUCCESS;
6057
6058 wanted_comma:
6059 first_error (_("expected comma"));
6060 return FAIL;
6061
6062 wanted_arm:
6063 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
6064 return FAIL;
6065 }
6066
6067 /* Use this macro when the operand constraints are different
6068 for ARM and THUMB (e.g. ldrd). */
6069 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
6070 ((arm_operand) | ((thumb_operand) << 16))
6071
6072 /* Matcher codes for parse_operands. */
6073 enum operand_parse_code
6074 {
6075 OP_stop, /* end of line */
6076
6077 OP_RR, /* ARM register */
6078 OP_RRnpc, /* ARM register, not r15 */
6079 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
6080 OP_RRnpcb, /* ARM register, not r15, in square brackets */
6081 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
6082 optional trailing ! */
6083 OP_RRw, /* ARM register, not r15, optional trailing ! */
6084 OP_RCP, /* Coprocessor number */
6085 OP_RCN, /* Coprocessor register */
6086 OP_RF, /* FPA register */
6087 OP_RVS, /* VFP single precision register */
6088 OP_RVD, /* VFP double precision register (0..15) */
6089 OP_RND, /* Neon double precision register (0..31) */
6090 OP_RNQ, /* Neon quad precision register */
6091 OP_RVSD, /* VFP single or double precision register */
6092 OP_RNDQ, /* Neon double or quad precision register */
6093 OP_RNSDQ, /* Neon single, double or quad precision register */
6094 OP_RNSC, /* Neon scalar D[X] */
6095 OP_RVC, /* VFP control register */
6096 OP_RMF, /* Maverick F register */
6097 OP_RMD, /* Maverick D register */
6098 OP_RMFX, /* Maverick FX register */
6099 OP_RMDX, /* Maverick DX register */
6100 OP_RMAX, /* Maverick AX register */
6101 OP_RMDS, /* Maverick DSPSC register */
6102 OP_RIWR, /* iWMMXt wR register */
6103 OP_RIWC, /* iWMMXt wC register */
6104 OP_RIWG, /* iWMMXt wCG register */
6105 OP_RXA, /* XScale accumulator register */
6106
6107 OP_REGLST, /* ARM register list */
6108 OP_VRSLST, /* VFP single-precision register list */
6109 OP_VRDLST, /* VFP double-precision register list */
6110 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
6111 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
6112 OP_NSTRLST, /* Neon element/structure list */
6113
6114 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
6115 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
6116 OP_RR_RNSC, /* ARM reg or Neon scalar. */
6117 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
6118 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
6119 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
6120 OP_VMOV, /* Neon VMOV operands. */
6121 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
6122 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
6123 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
6124
6125 OP_I0, /* immediate zero */
6126 OP_I7, /* immediate value 0 .. 7 */
6127 OP_I15, /* 0 .. 15 */
6128 OP_I16, /* 1 .. 16 */
6129 OP_I16z, /* 0 .. 16 */
6130 OP_I31, /* 0 .. 31 */
6131 OP_I31w, /* 0 .. 31, optional trailing ! */
6132 OP_I32, /* 1 .. 32 */
6133 OP_I32z, /* 0 .. 32 */
6134 OP_I63, /* 0 .. 63 */
6135 OP_I63s, /* -64 .. 63 */
6136 OP_I64, /* 1 .. 64 */
6137 OP_I64z, /* 0 .. 64 */
6138 OP_I255, /* 0 .. 255 */
6139
6140 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
6141 OP_I7b, /* 0 .. 7 */
6142 OP_I15b, /* 0 .. 15 */
6143 OP_I31b, /* 0 .. 31 */
6144
6145 OP_SH, /* shifter operand */
6146 OP_SHG, /* shifter operand with possible group relocation */
6147 OP_ADDR, /* Memory address expression (any mode) */
6148 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
6149 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
6150 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
6151 OP_EXP, /* arbitrary expression */
6152 OP_EXPi, /* same, with optional immediate prefix */
6153 OP_EXPr, /* same, with optional relocation suffix */
6154 OP_HALF, /* 0 .. 65535 or low/high reloc. */
6155
6156 OP_CPSF, /* CPS flags */
6157 OP_ENDI, /* Endianness specifier */
6158 OP_wPSR, /* CPSR/SPSR/APSR mask for msr (writing). */
6159 OP_rPSR, /* CPSR/SPSR/APSR mask for msr (reading). */
6160 OP_COND, /* conditional code */
6161 OP_TB, /* Table branch. */
6162
6163 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
6164
6165 OP_RRnpc_I0, /* ARM register or literal 0 */
6166 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
6167 OP_RR_EXi, /* ARM register or expression with imm prefix */
6168 OP_RF_IF, /* FPA register or immediate */
6169 OP_RIWR_RIWC, /* iWMMXt R or C reg */
6170 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
6171
6172 /* Optional operands. */
6173 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
6174 OP_oI31b, /* 0 .. 31 */
6175 OP_oI32b, /* 1 .. 32 */
6176 OP_oI32z, /* 0 .. 32 */
6177 OP_oIffffb, /* 0 .. 65535 */
6178 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
6179
6180 OP_oRR, /* ARM register */
6181 OP_oRRnpc, /* ARM register, not the PC */
6182 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
6183 OP_oRRw, /* ARM register, not r15, optional trailing ! */
6184 OP_oRND, /* Optional Neon double precision register */
6185 OP_oRNQ, /* Optional Neon quad precision register */
6186 OP_oRNDQ, /* Optional Neon double or quad precision register */
6187 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
6188 OP_oSHll, /* LSL immediate */
6189 OP_oSHar, /* ASR immediate */
6190 OP_oSHllar, /* LSL or ASR immediate */
6191 OP_oROR, /* ROR 0/8/16/24 */
6192 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
6193
6194 /* Some pre-defined mixed (ARM/THUMB) operands. */
6195 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
6196 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
6197 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
6198
6199 OP_FIRST_OPTIONAL = OP_oI7b
6200 };
6201
6202 /* Generic instruction operand parser. This does no encoding and no
6203 semantic validation; it merely squirrels values away in the inst
6204 structure. Returns SUCCESS or FAIL depending on whether the
6205 specified grammar matched. */
6206 static int
6207 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
6208 {
6209 unsigned const int *upat = pattern;
6210 char *backtrack_pos = 0;
6211 const char *backtrack_error = 0;
6212 int i, val = 0, backtrack_index = 0;
6213 enum arm_reg_type rtype;
6214 parse_operand_result result;
6215 unsigned int op_parse_code;
6216
6217 #define po_char_or_fail(chr) \
6218 do \
6219 { \
6220 if (skip_past_char (&str, chr) == FAIL) \
6221 goto bad_args; \
6222 } \
6223 while (0)
6224
6225 #define po_reg_or_fail(regtype) \
6226 do \
6227 { \
6228 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6229 & inst.operands[i].vectype); \
6230 if (val == FAIL) \
6231 { \
6232 first_error (_(reg_expected_msgs[regtype])); \
6233 goto failure; \
6234 } \
6235 inst.operands[i].reg = val; \
6236 inst.operands[i].isreg = 1; \
6237 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6238 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6239 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6240 || rtype == REG_TYPE_VFD \
6241 || rtype == REG_TYPE_NQ); \
6242 } \
6243 while (0)
6244
6245 #define po_reg_or_goto(regtype, label) \
6246 do \
6247 { \
6248 val = arm_typed_reg_parse (& str, regtype, & rtype, \
6249 & inst.operands[i].vectype); \
6250 if (val == FAIL) \
6251 goto label; \
6252 \
6253 inst.operands[i].reg = val; \
6254 inst.operands[i].isreg = 1; \
6255 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
6256 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
6257 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
6258 || rtype == REG_TYPE_VFD \
6259 || rtype == REG_TYPE_NQ); \
6260 } \
6261 while (0)
6262
6263 #define po_imm_or_fail(min, max, popt) \
6264 do \
6265 { \
6266 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
6267 goto failure; \
6268 inst.operands[i].imm = val; \
6269 } \
6270 while (0)
6271
6272 #define po_scalar_or_goto(elsz, label) \
6273 do \
6274 { \
6275 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
6276 if (val == FAIL) \
6277 goto label; \
6278 inst.operands[i].reg = val; \
6279 inst.operands[i].isscalar = 1; \
6280 } \
6281 while (0)
6282
6283 #define po_misc_or_fail(expr) \
6284 do \
6285 { \
6286 if (expr) \
6287 goto failure; \
6288 } \
6289 while (0)
6290
6291 #define po_misc_or_fail_no_backtrack(expr) \
6292 do \
6293 { \
6294 result = expr; \
6295 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6296 backtrack_pos = 0; \
6297 if (result != PARSE_OPERAND_SUCCESS) \
6298 goto failure; \
6299 } \
6300 while (0)
6301
6302 #define po_barrier_or_imm(str) \
6303 do \
6304 { \
6305 val = parse_barrier (&str); \
6306 if (val == FAIL) \
6307 { \
6308 if (ISALPHA (*str)) \
6309 goto failure; \
6310 else \
6311 goto immediate; \
6312 } \
6313 else \
6314 { \
6315 if ((inst.instruction & 0xf0) == 0x60 \
6316 && val != 0xf) \
6317 { \
6318 /* ISB can only take SY as an option. */ \
6319 inst.error = _("invalid barrier type"); \
6320 goto failure; \
6321 } \
6322 } \
6323 } \
6324 while (0)
6325
6326 skip_whitespace (str);
6327
6328 for (i = 0; upat[i] != OP_stop; i++)
6329 {
6330 op_parse_code = upat[i];
6331 if (op_parse_code >= 1<<16)
6332 op_parse_code = thumb ? (op_parse_code >> 16)
6333 : (op_parse_code & ((1<<16)-1));
6334
6335 if (op_parse_code >= OP_FIRST_OPTIONAL)
6336 {
6337 /* Remember where we are in case we need to backtrack. */
6338 gas_assert (!backtrack_pos);
6339 backtrack_pos = str;
6340 backtrack_error = inst.error;
6341 backtrack_index = i;
6342 }
6343
6344 if (i > 0 && (i > 1 || inst.operands[0].present))
6345 po_char_or_fail (',');
6346
6347 switch (op_parse_code)
6348 {
6349 /* Registers */
6350 case OP_oRRnpc:
6351 case OP_oRRnpcsp:
6352 case OP_RRnpc:
6353 case OP_RRnpcsp:
6354 case OP_oRR:
6355 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6356 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6357 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6358 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6359 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6360 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6361 case OP_oRND:
6362 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6363 case OP_RVC:
6364 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6365 break;
6366 /* Also accept generic coprocessor regs for unknown registers. */
6367 coproc_reg:
6368 po_reg_or_fail (REG_TYPE_CN);
6369 break;
6370 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6371 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6372 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6373 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6374 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6375 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6376 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6377 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6378 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6379 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6380 case OP_oRNQ:
6381 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6382 case OP_oRNDQ:
6383 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6384 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6385 case OP_oRNSDQ:
6386 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6387
6388 /* Neon scalar. Using an element size of 8 means that some invalid
6389 scalars are accepted here, so deal with those in later code. */
6390 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6391
6392 case OP_RNDQ_I0:
6393 {
6394 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6395 break;
6396 try_imm0:
6397 po_imm_or_fail (0, 0, TRUE);
6398 }
6399 break;
6400
6401 case OP_RVSD_I0:
6402 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6403 break;
6404
6405 case OP_RR_RNSC:
6406 {
6407 po_scalar_or_goto (8, try_rr);
6408 break;
6409 try_rr:
6410 po_reg_or_fail (REG_TYPE_RN);
6411 }
6412 break;
6413
6414 case OP_RNSDQ_RNSC:
6415 {
6416 po_scalar_or_goto (8, try_nsdq);
6417 break;
6418 try_nsdq:
6419 po_reg_or_fail (REG_TYPE_NSDQ);
6420 }
6421 break;
6422
6423 case OP_RNDQ_RNSC:
6424 {
6425 po_scalar_or_goto (8, try_ndq);
6426 break;
6427 try_ndq:
6428 po_reg_or_fail (REG_TYPE_NDQ);
6429 }
6430 break;
6431
6432 case OP_RND_RNSC:
6433 {
6434 po_scalar_or_goto (8, try_vfd);
6435 break;
6436 try_vfd:
6437 po_reg_or_fail (REG_TYPE_VFD);
6438 }
6439 break;
6440
6441 case OP_VMOV:
6442 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6443 not careful then bad things might happen. */
6444 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6445 break;
6446
6447 case OP_RNDQ_Ibig:
6448 {
6449 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6450 break;
6451 try_immbig:
6452 /* There's a possibility of getting a 64-bit immediate here, so
6453 we need special handling. */
6454 if (parse_big_immediate (&str, i) == FAIL)
6455 {
6456 inst.error = _("immediate value is out of range");
6457 goto failure;
6458 }
6459 }
6460 break;
6461
6462 case OP_RNDQ_I63b:
6463 {
6464 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6465 break;
6466 try_shimm:
6467 po_imm_or_fail (0, 63, TRUE);
6468 }
6469 break;
6470
6471 case OP_RRnpcb:
6472 po_char_or_fail ('[');
6473 po_reg_or_fail (REG_TYPE_RN);
6474 po_char_or_fail (']');
6475 break;
6476
6477 case OP_RRnpctw:
6478 case OP_RRw:
6479 case OP_oRRw:
6480 po_reg_or_fail (REG_TYPE_RN);
6481 if (skip_past_char (&str, '!') == SUCCESS)
6482 inst.operands[i].writeback = 1;
6483 break;
6484
6485 /* Immediates */
6486 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6487 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6488 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6489 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6490 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6491 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6492 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6493 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6494 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6495 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6496 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6497 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6498
6499 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6500 case OP_oI7b:
6501 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6502 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6503 case OP_oI31b:
6504 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6505 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6506 case OP_oI32z: po_imm_or_fail ( 0, 32, TRUE); break;
6507 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6508
6509 /* Immediate variants */
6510 case OP_oI255c:
6511 po_char_or_fail ('{');
6512 po_imm_or_fail (0, 255, TRUE);
6513 po_char_or_fail ('}');
6514 break;
6515
6516 case OP_I31w:
6517 /* The expression parser chokes on a trailing !, so we have
6518 to find it first and zap it. */
6519 {
6520 char *s = str;
6521 while (*s && *s != ',')
6522 s++;
6523 if (s[-1] == '!')
6524 {
6525 s[-1] = '\0';
6526 inst.operands[i].writeback = 1;
6527 }
6528 po_imm_or_fail (0, 31, TRUE);
6529 if (str == s - 1)
6530 str = s;
6531 }
6532 break;
6533
6534 /* Expressions */
6535 case OP_EXPi: EXPi:
6536 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6537 GE_OPT_PREFIX));
6538 break;
6539
6540 case OP_EXP:
6541 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6542 GE_NO_PREFIX));
6543 break;
6544
6545 case OP_EXPr: EXPr:
6546 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6547 GE_NO_PREFIX));
6548 if (inst.reloc.exp.X_op == O_symbol)
6549 {
6550 val = parse_reloc (&str);
6551 if (val == -1)
6552 {
6553 inst.error = _("unrecognized relocation suffix");
6554 goto failure;
6555 }
6556 else if (val != BFD_RELOC_UNUSED)
6557 {
6558 inst.operands[i].imm = val;
6559 inst.operands[i].hasreloc = 1;
6560 }
6561 }
6562 break;
6563
6564 /* Operand for MOVW or MOVT. */
6565 case OP_HALF:
6566 po_misc_or_fail (parse_half (&str));
6567 break;
6568
6569 /* Register or expression. */
6570 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6571 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6572
6573 /* Register or immediate. */
6574 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6575 I0: po_imm_or_fail (0, 0, FALSE); break;
6576
6577 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6578 IF:
6579 if (!is_immediate_prefix (*str))
6580 goto bad_args;
6581 str++;
6582 val = parse_fpa_immediate (&str);
6583 if (val == FAIL)
6584 goto failure;
6585 /* FPA immediates are encoded as registers 8-15.
6586 parse_fpa_immediate has already applied the offset. */
6587 inst.operands[i].reg = val;
6588 inst.operands[i].isreg = 1;
6589 break;
6590
6591 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6592 I32z: po_imm_or_fail (0, 32, FALSE); break;
6593
6594 /* Two kinds of register. */
6595 case OP_RIWR_RIWC:
6596 {
6597 struct reg_entry *rege = arm_reg_parse_multi (&str);
6598 if (!rege
6599 || (rege->type != REG_TYPE_MMXWR
6600 && rege->type != REG_TYPE_MMXWC
6601 && rege->type != REG_TYPE_MMXWCG))
6602 {
6603 inst.error = _("iWMMXt data or control register expected");
6604 goto failure;
6605 }
6606 inst.operands[i].reg = rege->number;
6607 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6608 }
6609 break;
6610
6611 case OP_RIWC_RIWG:
6612 {
6613 struct reg_entry *rege = arm_reg_parse_multi (&str);
6614 if (!rege
6615 || (rege->type != REG_TYPE_MMXWC
6616 && rege->type != REG_TYPE_MMXWCG))
6617 {
6618 inst.error = _("iWMMXt control register expected");
6619 goto failure;
6620 }
6621 inst.operands[i].reg = rege->number;
6622 inst.operands[i].isreg = 1;
6623 }
6624 break;
6625
6626 /* Misc */
6627 case OP_CPSF: val = parse_cps_flags (&str); break;
6628 case OP_ENDI: val = parse_endian_specifier (&str); break;
6629 case OP_oROR: val = parse_ror (&str); break;
6630 case OP_COND: val = parse_cond (&str); break;
6631 case OP_oBARRIER_I15:
6632 po_barrier_or_imm (str); break;
6633 immediate:
6634 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6635 goto failure;
6636 break;
6637
6638 case OP_wPSR:
6639 case OP_rPSR:
6640 po_reg_or_goto (REG_TYPE_RNB, try_psr);
6641 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_virt))
6642 {
6643 inst.error = _("Banked registers are not available with this "
6644 "architecture.");
6645 goto failure;
6646 }
6647 break;
6648 try_psr:
6649 val = parse_psr (&str, op_parse_code == OP_wPSR);
6650 break;
6651
6652 case OP_APSR_RR:
6653 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6654 break;
6655 try_apsr:
6656 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6657 instruction). */
6658 if (strncasecmp (str, "APSR_", 5) == 0)
6659 {
6660 unsigned found = 0;
6661 str += 5;
6662 while (found < 15)
6663 switch (*str++)
6664 {
6665 case 'c': found = (found & 1) ? 16 : found | 1; break;
6666 case 'n': found = (found & 2) ? 16 : found | 2; break;
6667 case 'z': found = (found & 4) ? 16 : found | 4; break;
6668 case 'v': found = (found & 8) ? 16 : found | 8; break;
6669 default: found = 16;
6670 }
6671 if (found != 15)
6672 goto failure;
6673 inst.operands[i].isvec = 1;
6674 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6675 inst.operands[i].reg = REG_PC;
6676 }
6677 else
6678 goto failure;
6679 break;
6680
6681 case OP_TB:
6682 po_misc_or_fail (parse_tb (&str));
6683 break;
6684
6685 /* Register lists. */
6686 case OP_REGLST:
6687 val = parse_reg_list (&str);
6688 if (*str == '^')
6689 {
6690 inst.operands[1].writeback = 1;
6691 str++;
6692 }
6693 break;
6694
6695 case OP_VRSLST:
6696 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6697 break;
6698
6699 case OP_VRDLST:
6700 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6701 break;
6702
6703 case OP_VRSDLST:
6704 /* Allow Q registers too. */
6705 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6706 REGLIST_NEON_D);
6707 if (val == FAIL)
6708 {
6709 inst.error = NULL;
6710 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6711 REGLIST_VFP_S);
6712 inst.operands[i].issingle = 1;
6713 }
6714 break;
6715
6716 case OP_NRDLST:
6717 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6718 REGLIST_NEON_D);
6719 break;
6720
6721 case OP_NSTRLST:
6722 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6723 &inst.operands[i].vectype);
6724 break;
6725
6726 /* Addressing modes */
6727 case OP_ADDR:
6728 po_misc_or_fail (parse_address (&str, i));
6729 break;
6730
6731 case OP_ADDRGLDR:
6732 po_misc_or_fail_no_backtrack (
6733 parse_address_group_reloc (&str, i, GROUP_LDR));
6734 break;
6735
6736 case OP_ADDRGLDRS:
6737 po_misc_or_fail_no_backtrack (
6738 parse_address_group_reloc (&str, i, GROUP_LDRS));
6739 break;
6740
6741 case OP_ADDRGLDC:
6742 po_misc_or_fail_no_backtrack (
6743 parse_address_group_reloc (&str, i, GROUP_LDC));
6744 break;
6745
6746 case OP_SH:
6747 po_misc_or_fail (parse_shifter_operand (&str, i));
6748 break;
6749
6750 case OP_SHG:
6751 po_misc_or_fail_no_backtrack (
6752 parse_shifter_operand_group_reloc (&str, i));
6753 break;
6754
6755 case OP_oSHll:
6756 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6757 break;
6758
6759 case OP_oSHar:
6760 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6761 break;
6762
6763 case OP_oSHllar:
6764 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6765 break;
6766
6767 default:
6768 as_fatal (_("unhandled operand code %d"), op_parse_code);
6769 }
6770
6771 /* Various value-based sanity checks and shared operations. We
6772 do not signal immediate failures for the register constraints;
6773 this allows a syntax error to take precedence. */
6774 switch (op_parse_code)
6775 {
6776 case OP_oRRnpc:
6777 case OP_RRnpc:
6778 case OP_RRnpcb:
6779 case OP_RRw:
6780 case OP_oRRw:
6781 case OP_RRnpc_I0:
6782 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6783 inst.error = BAD_PC;
6784 break;
6785
6786 case OP_oRRnpcsp:
6787 case OP_RRnpcsp:
6788 if (inst.operands[i].isreg)
6789 {
6790 if (inst.operands[i].reg == REG_PC)
6791 inst.error = BAD_PC;
6792 else if (inst.operands[i].reg == REG_SP)
6793 inst.error = BAD_SP;
6794 }
6795 break;
6796
6797 case OP_RRnpctw:
6798 if (inst.operands[i].isreg
6799 && inst.operands[i].reg == REG_PC
6800 && (inst.operands[i].writeback || thumb))
6801 inst.error = BAD_PC;
6802 break;
6803
6804 case OP_CPSF:
6805 case OP_ENDI:
6806 case OP_oROR:
6807 case OP_wPSR:
6808 case OP_rPSR:
6809 case OP_COND:
6810 case OP_oBARRIER_I15:
6811 case OP_REGLST:
6812 case OP_VRSLST:
6813 case OP_VRDLST:
6814 case OP_VRSDLST:
6815 case OP_NRDLST:
6816 case OP_NSTRLST:
6817 if (val == FAIL)
6818 goto failure;
6819 inst.operands[i].imm = val;
6820 break;
6821
6822 default:
6823 break;
6824 }
6825
6826 /* If we get here, this operand was successfully parsed. */
6827 inst.operands[i].present = 1;
6828 continue;
6829
6830 bad_args:
6831 inst.error = BAD_ARGS;
6832
6833 failure:
6834 if (!backtrack_pos)
6835 {
6836 /* The parse routine should already have set inst.error, but set a
6837 default here just in case. */
6838 if (!inst.error)
6839 inst.error = _("syntax error");
6840 return FAIL;
6841 }
6842
6843 /* Do not backtrack over a trailing optional argument that
6844 absorbed some text. We will only fail again, with the
6845 'garbage following instruction' error message, which is
6846 probably less helpful than the current one. */
6847 if (backtrack_index == i && backtrack_pos != str
6848 && upat[i+1] == OP_stop)
6849 {
6850 if (!inst.error)
6851 inst.error = _("syntax error");
6852 return FAIL;
6853 }
6854
6855 /* Try again, skipping the optional argument at backtrack_pos. */
6856 str = backtrack_pos;
6857 inst.error = backtrack_error;
6858 inst.operands[backtrack_index].present = 0;
6859 i = backtrack_index;
6860 backtrack_pos = 0;
6861 }
6862
6863 /* Check that we have parsed all the arguments. */
6864 if (*str != '\0' && !inst.error)
6865 inst.error = _("garbage following instruction");
6866
6867 return inst.error ? FAIL : SUCCESS;
6868 }
6869
6870 #undef po_char_or_fail
6871 #undef po_reg_or_fail
6872 #undef po_reg_or_goto
6873 #undef po_imm_or_fail
6874 #undef po_scalar_or_fail
6875 #undef po_barrier_or_imm
6876
6877 /* Shorthand macro for instruction encoding functions issuing errors. */
6878 #define constraint(expr, err) \
6879 do \
6880 { \
6881 if (expr) \
6882 { \
6883 inst.error = err; \
6884 return; \
6885 } \
6886 } \
6887 while (0)
6888
6889 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6890 instructions are unpredictable if these registers are used. This
6891 is the BadReg predicate in ARM's Thumb-2 documentation. */
6892 #define reject_bad_reg(reg) \
6893 do \
6894 if (reg == REG_SP || reg == REG_PC) \
6895 { \
6896 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6897 return; \
6898 } \
6899 while (0)
6900
6901 /* If REG is R13 (the stack pointer), warn that its use is
6902 deprecated. */
6903 #define warn_deprecated_sp(reg) \
6904 do \
6905 if (warn_on_deprecated && reg == REG_SP) \
6906 as_warn (_("use of r13 is deprecated")); \
6907 while (0)
6908
6909 /* Functions for operand encoding. ARM, then Thumb. */
6910
6911 #define rotate_left(v, n) (v << n | v >> (32 - n))
6912
6913 /* If VAL can be encoded in the immediate field of an ARM instruction,
6914 return the encoded form. Otherwise, return FAIL. */
6915
6916 static unsigned int
6917 encode_arm_immediate (unsigned int val)
6918 {
6919 unsigned int a, i;
6920
6921 for (i = 0; i < 32; i += 2)
6922 if ((a = rotate_left (val, i)) <= 0xff)
6923 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6924
6925 return FAIL;
6926 }
6927
6928 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6929 return the encoded form. Otherwise, return FAIL. */
6930 static unsigned int
6931 encode_thumb32_immediate (unsigned int val)
6932 {
6933 unsigned int a, i;
6934
6935 if (val <= 0xff)
6936 return val;
6937
6938 for (i = 1; i <= 24; i++)
6939 {
6940 a = val >> i;
6941 if ((val & ~(0xff << i)) == 0)
6942 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6943 }
6944
6945 a = val & 0xff;
6946 if (val == ((a << 16) | a))
6947 return 0x100 | a;
6948 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6949 return 0x300 | a;
6950
6951 a = val & 0xff00;
6952 if (val == ((a << 16) | a))
6953 return 0x200 | (a >> 8);
6954
6955 return FAIL;
6956 }
6957 /* Encode a VFP SP or DP register number into inst.instruction. */
6958
6959 static void
6960 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6961 {
6962 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6963 && reg > 15)
6964 {
6965 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6966 {
6967 if (thumb_mode)
6968 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6969 fpu_vfp_ext_d32);
6970 else
6971 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6972 fpu_vfp_ext_d32);
6973 }
6974 else
6975 {
6976 first_error (_("D register out of range for selected VFP version"));
6977 return;
6978 }
6979 }
6980
6981 switch (pos)
6982 {
6983 case VFP_REG_Sd:
6984 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6985 break;
6986
6987 case VFP_REG_Sn:
6988 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6989 break;
6990
6991 case VFP_REG_Sm:
6992 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6993 break;
6994
6995 case VFP_REG_Dd:
6996 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6997 break;
6998
6999 case VFP_REG_Dn:
7000 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
7001 break;
7002
7003 case VFP_REG_Dm:
7004 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
7005 break;
7006
7007 default:
7008 abort ();
7009 }
7010 }
7011
7012 /* Encode a <shift> in an ARM-format instruction. The immediate,
7013 if any, is handled by md_apply_fix. */
7014 static void
7015 encode_arm_shift (int i)
7016 {
7017 if (inst.operands[i].shift_kind == SHIFT_RRX)
7018 inst.instruction |= SHIFT_ROR << 5;
7019 else
7020 {
7021 inst.instruction |= inst.operands[i].shift_kind << 5;
7022 if (inst.operands[i].immisreg)
7023 {
7024 inst.instruction |= SHIFT_BY_REG;
7025 inst.instruction |= inst.operands[i].imm << 8;
7026 }
7027 else
7028 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7029 }
7030 }
7031
7032 static void
7033 encode_arm_shifter_operand (int i)
7034 {
7035 if (inst.operands[i].isreg)
7036 {
7037 inst.instruction |= inst.operands[i].reg;
7038 encode_arm_shift (i);
7039 }
7040 else
7041 {
7042 inst.instruction |= INST_IMMEDIATE;
7043 if (inst.reloc.type != BFD_RELOC_ARM_IMMEDIATE)
7044 inst.instruction |= inst.operands[i].imm;
7045 }
7046 }
7047
7048 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
7049 static void
7050 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
7051 {
7052 /* PR 14260:
7053 Generate an error if the operand is not a register. */
7054 constraint (!inst.operands[i].isreg,
7055 _("Instruction does not support =N addresses"));
7056
7057 inst.instruction |= inst.operands[i].reg << 16;
7058
7059 if (inst.operands[i].preind)
7060 {
7061 if (is_t)
7062 {
7063 inst.error = _("instruction does not accept preindexed addressing");
7064 return;
7065 }
7066 inst.instruction |= PRE_INDEX;
7067 if (inst.operands[i].writeback)
7068 inst.instruction |= WRITE_BACK;
7069
7070 }
7071 else if (inst.operands[i].postind)
7072 {
7073 gas_assert (inst.operands[i].writeback);
7074 if (is_t)
7075 inst.instruction |= WRITE_BACK;
7076 }
7077 else /* unindexed - only for coprocessor */
7078 {
7079 inst.error = _("instruction does not accept unindexed addressing");
7080 return;
7081 }
7082
7083 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
7084 && (((inst.instruction & 0x000f0000) >> 16)
7085 == ((inst.instruction & 0x0000f000) >> 12)))
7086 as_warn ((inst.instruction & LOAD_BIT)
7087 ? _("destination register same as write-back base")
7088 : _("source register same as write-back base"));
7089 }
7090
7091 /* inst.operands[i] was set up by parse_address. Encode it into an
7092 ARM-format mode 2 load or store instruction. If is_t is true,
7093 reject forms that cannot be used with a T instruction (i.e. not
7094 post-indexed). */
7095 static void
7096 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
7097 {
7098 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
7099
7100 encode_arm_addr_mode_common (i, is_t);
7101
7102 if (inst.operands[i].immisreg)
7103 {
7104 constraint ((inst.operands[i].imm == REG_PC
7105 || (is_pc && inst.operands[i].writeback)),
7106 BAD_PC_ADDRESSING);
7107 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
7108 inst.instruction |= inst.operands[i].imm;
7109 if (!inst.operands[i].negative)
7110 inst.instruction |= INDEX_UP;
7111 if (inst.operands[i].shifted)
7112 {
7113 if (inst.operands[i].shift_kind == SHIFT_RRX)
7114 inst.instruction |= SHIFT_ROR << 5;
7115 else
7116 {
7117 inst.instruction |= inst.operands[i].shift_kind << 5;
7118 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7119 }
7120 }
7121 }
7122 else /* immediate offset in inst.reloc */
7123 {
7124 if (is_pc && !inst.reloc.pc_rel)
7125 {
7126 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
7127
7128 /* If is_t is TRUE, it's called from do_ldstt. ldrt/strt
7129 cannot use PC in addressing.
7130 PC cannot be used in writeback addressing, either. */
7131 constraint ((is_t || inst.operands[i].writeback),
7132 BAD_PC_ADDRESSING);
7133
7134 /* Use of PC in str is deprecated for ARMv7. */
7135 if (warn_on_deprecated
7136 && !is_load
7137 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
7138 as_warn (_("use of PC in this instruction is deprecated"));
7139 }
7140
7141 if (inst.reloc.type == BFD_RELOC_UNUSED)
7142 {
7143 /* Prefer + for zero encoded value. */
7144 if (!inst.operands[i].negative)
7145 inst.instruction |= INDEX_UP;
7146 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
7147 }
7148 }
7149 }
7150
7151 /* inst.operands[i] was set up by parse_address. Encode it into an
7152 ARM-format mode 3 load or store instruction. Reject forms that
7153 cannot be used with such instructions. If is_t is true, reject
7154 forms that cannot be used with a T instruction (i.e. not
7155 post-indexed). */
7156 static void
7157 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
7158 {
7159 if (inst.operands[i].immisreg && inst.operands[i].shifted)
7160 {
7161 inst.error = _("instruction does not accept scaled register index");
7162 return;
7163 }
7164
7165 encode_arm_addr_mode_common (i, is_t);
7166
7167 if (inst.operands[i].immisreg)
7168 {
7169 constraint ((inst.operands[i].imm == REG_PC
7170 || inst.operands[i].reg == REG_PC),
7171 BAD_PC_ADDRESSING);
7172 inst.instruction |= inst.operands[i].imm;
7173 if (!inst.operands[i].negative)
7174 inst.instruction |= INDEX_UP;
7175 }
7176 else /* immediate offset in inst.reloc */
7177 {
7178 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
7179 && inst.operands[i].writeback),
7180 BAD_PC_WRITEBACK);
7181 inst.instruction |= HWOFFSET_IMM;
7182 if (inst.reloc.type == BFD_RELOC_UNUSED)
7183 {
7184 /* Prefer + for zero encoded value. */
7185 if (!inst.operands[i].negative)
7186 inst.instruction |= INDEX_UP;
7187
7188 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
7189 }
7190 }
7191 }
7192
7193 /* inst.operands[i] was set up by parse_address. Encode it into an
7194 ARM-format instruction. Reject all forms which cannot be encoded
7195 into a coprocessor load/store instruction. If wb_ok is false,
7196 reject use of writeback; if unind_ok is false, reject use of
7197 unindexed addressing. If reloc_override is not 0, use it instead
7198 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
7199 (in which case it is preserved). */
7200
7201 static int
7202 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
7203 {
7204 inst.instruction |= inst.operands[i].reg << 16;
7205
7206 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
7207
7208 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
7209 {
7210 gas_assert (!inst.operands[i].writeback);
7211 if (!unind_ok)
7212 {
7213 inst.error = _("instruction does not support unindexed addressing");
7214 return FAIL;
7215 }
7216 inst.instruction |= inst.operands[i].imm;
7217 inst.instruction |= INDEX_UP;
7218 return SUCCESS;
7219 }
7220
7221 if (inst.operands[i].preind)
7222 inst.instruction |= PRE_INDEX;
7223
7224 if (inst.operands[i].writeback)
7225 {
7226 if (inst.operands[i].reg == REG_PC)
7227 {
7228 inst.error = _("pc may not be used with write-back");
7229 return FAIL;
7230 }
7231 if (!wb_ok)
7232 {
7233 inst.error = _("instruction does not support writeback");
7234 return FAIL;
7235 }
7236 inst.instruction |= WRITE_BACK;
7237 }
7238
7239 if (reloc_override)
7240 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
7241 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
7242 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
7243 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
7244 {
7245 if (thumb_mode)
7246 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
7247 else
7248 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
7249 }
7250
7251 /* Prefer + for zero encoded value. */
7252 if (!inst.operands[i].negative)
7253 inst.instruction |= INDEX_UP;
7254
7255 return SUCCESS;
7256 }
7257
7258 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
7259 Determine whether it can be performed with a move instruction; if
7260 it can, convert inst.instruction to that move instruction and
7261 return TRUE; if it can't, convert inst.instruction to a literal-pool
7262 load and return FALSE. If this is not a valid thing to do in the
7263 current context, set inst.error and return TRUE.
7264
7265 inst.operands[i] describes the destination register. */
7266
7267 static bfd_boolean
7268 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
7269 {
7270 unsigned long tbit;
7271
7272 if (thumb_p)
7273 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
7274 else
7275 tbit = LOAD_BIT;
7276
7277 if ((inst.instruction & tbit) == 0)
7278 {
7279 inst.error = _("invalid pseudo operation");
7280 return TRUE;
7281 }
7282 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
7283 {
7284 inst.error = _("constant expression expected");
7285 return TRUE;
7286 }
7287 if (inst.reloc.exp.X_op == O_constant)
7288 {
7289 if (thumb_p)
7290 {
7291 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
7292 {
7293 /* This can be done with a mov(1) instruction. */
7294 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
7295 inst.instruction |= inst.reloc.exp.X_add_number;
7296 return TRUE;
7297 }
7298 }
7299 else
7300 {
7301 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
7302 if (value != FAIL)
7303 {
7304 /* This can be done with a mov instruction. */
7305 inst.instruction &= LITERAL_MASK;
7306 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
7307 inst.instruction |= value & 0xfff;
7308 return TRUE;
7309 }
7310
7311 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
7312 if (value != FAIL)
7313 {
7314 /* This can be done with a mvn instruction. */
7315 inst.instruction &= LITERAL_MASK;
7316 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
7317 inst.instruction |= value & 0xfff;
7318 return TRUE;
7319 }
7320 }
7321 }
7322
7323 if (add_to_lit_pool () == FAIL)
7324 {
7325 inst.error = _("literal pool insertion failed");
7326 return TRUE;
7327 }
7328 inst.operands[1].reg = REG_PC;
7329 inst.operands[1].isreg = 1;
7330 inst.operands[1].preind = 1;
7331 inst.reloc.pc_rel = 1;
7332 inst.reloc.type = (thumb_p
7333 ? BFD_RELOC_ARM_THUMB_OFFSET
7334 : (mode_3
7335 ? BFD_RELOC_ARM_HWLITERAL
7336 : BFD_RELOC_ARM_LITERAL));
7337 return FALSE;
7338 }
7339
7340 /* Functions for instruction encoding, sorted by sub-architecture.
7341 First some generics; their names are taken from the conventional
7342 bit positions for register arguments in ARM format instructions. */
7343
7344 static void
7345 do_noargs (void)
7346 {
7347 }
7348
7349 static void
7350 do_rd (void)
7351 {
7352 inst.instruction |= inst.operands[0].reg << 12;
7353 }
7354
7355 static void
7356 do_rd_rm (void)
7357 {
7358 inst.instruction |= inst.operands[0].reg << 12;
7359 inst.instruction |= inst.operands[1].reg;
7360 }
7361
7362 static void
7363 do_rd_rn (void)
7364 {
7365 inst.instruction |= inst.operands[0].reg << 12;
7366 inst.instruction |= inst.operands[1].reg << 16;
7367 }
7368
7369 static void
7370 do_rn_rd (void)
7371 {
7372 inst.instruction |= inst.operands[0].reg << 16;
7373 inst.instruction |= inst.operands[1].reg << 12;
7374 }
7375
7376 static bfd_boolean
7377 check_obsolete (const arm_feature_set *feature, const char *msg)
7378 {
7379 if (ARM_CPU_IS_ANY (cpu_variant))
7380 {
7381 as_warn ("%s", msg);
7382 return TRUE;
7383 }
7384 else if (ARM_CPU_HAS_FEATURE (cpu_variant, *feature))
7385 {
7386 as_bad ("%s", msg);
7387 return TRUE;
7388 }
7389
7390 return FALSE;
7391 }
7392
7393 static void
7394 do_rd_rm_rn (void)
7395 {
7396 unsigned Rn = inst.operands[2].reg;
7397 /* Enforce restrictions on SWP instruction. */
7398 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
7399 {
7400 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7401 _("Rn must not overlap other operands"));
7402
7403 /* SWP{b} is obsolete for ARMv8-A, and deprecated for ARMv6* and ARMv7.
7404 */
7405 if (!check_obsolete (&arm_ext_v8,
7406 _("swp{b} use is obsoleted for ARMv8 and later"))
7407 && warn_on_deprecated
7408 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6))
7409 as_warn (_("swp{b} use is deprecated for ARMv6 and ARMv7"));
7410 }
7411
7412 inst.instruction |= inst.operands[0].reg << 12;
7413 inst.instruction |= inst.operands[1].reg;
7414 inst.instruction |= Rn << 16;
7415 }
7416
7417 static void
7418 do_rd_rn_rm (void)
7419 {
7420 inst.instruction |= inst.operands[0].reg << 12;
7421 inst.instruction |= inst.operands[1].reg << 16;
7422 inst.instruction |= inst.operands[2].reg;
7423 }
7424
7425 static void
7426 do_rm_rd_rn (void)
7427 {
7428 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7429 constraint (((inst.reloc.exp.X_op != O_constant
7430 && inst.reloc.exp.X_op != O_illegal)
7431 || inst.reloc.exp.X_add_number != 0),
7432 BAD_ADDR_MODE);
7433 inst.instruction |= inst.operands[0].reg;
7434 inst.instruction |= inst.operands[1].reg << 12;
7435 inst.instruction |= inst.operands[2].reg << 16;
7436 }
7437
7438 static void
7439 do_imm0 (void)
7440 {
7441 inst.instruction |= inst.operands[0].imm;
7442 }
7443
7444 static void
7445 do_rd_cpaddr (void)
7446 {
7447 inst.instruction |= inst.operands[0].reg << 12;
7448 encode_arm_cp_address (1, TRUE, TRUE, 0);
7449 }
7450
7451 /* ARM instructions, in alphabetical order by function name (except
7452 that wrapper functions appear immediately after the function they
7453 wrap). */
7454
7455 /* This is a pseudo-op of the form "adr rd, label" to be converted
7456 into a relative address of the form "add rd, pc, #label-.-8". */
7457
7458 static void
7459 do_adr (void)
7460 {
7461 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7462
7463 /* Frag hacking will turn this into a sub instruction if the offset turns
7464 out to be negative. */
7465 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7466 inst.reloc.pc_rel = 1;
7467 inst.reloc.exp.X_add_number -= 8;
7468 }
7469
7470 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7471 into a relative address of the form:
7472 add rd, pc, #low(label-.-8)"
7473 add rd, rd, #high(label-.-8)" */
7474
7475 static void
7476 do_adrl (void)
7477 {
7478 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7479
7480 /* Frag hacking will turn this into a sub instruction if the offset turns
7481 out to be negative. */
7482 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7483 inst.reloc.pc_rel = 1;
7484 inst.size = INSN_SIZE * 2;
7485 inst.reloc.exp.X_add_number -= 8;
7486 }
7487
7488 static void
7489 do_arit (void)
7490 {
7491 if (!inst.operands[1].present)
7492 inst.operands[1].reg = inst.operands[0].reg;
7493 inst.instruction |= inst.operands[0].reg << 12;
7494 inst.instruction |= inst.operands[1].reg << 16;
7495 encode_arm_shifter_operand (2);
7496 }
7497
7498 static void
7499 do_barrier (void)
7500 {
7501 if (inst.operands[0].present)
7502 {
7503 constraint ((inst.instruction & 0xf0) != 0x40
7504 && inst.operands[0].imm > 0xf
7505 && inst.operands[0].imm < 0x0,
7506 _("bad barrier type"));
7507 inst.instruction |= inst.operands[0].imm;
7508 }
7509 else
7510 inst.instruction |= 0xf;
7511 }
7512
7513 static void
7514 do_bfc (void)
7515 {
7516 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7517 constraint (msb > 32, _("bit-field extends past end of register"));
7518 /* The instruction encoding stores the LSB and MSB,
7519 not the LSB and width. */
7520 inst.instruction |= inst.operands[0].reg << 12;
7521 inst.instruction |= inst.operands[1].imm << 7;
7522 inst.instruction |= (msb - 1) << 16;
7523 }
7524
7525 static void
7526 do_bfi (void)
7527 {
7528 unsigned int msb;
7529
7530 /* #0 in second position is alternative syntax for bfc, which is
7531 the same instruction but with REG_PC in the Rm field. */
7532 if (!inst.operands[1].isreg)
7533 inst.operands[1].reg = REG_PC;
7534
7535 msb = inst.operands[2].imm + inst.operands[3].imm;
7536 constraint (msb > 32, _("bit-field extends past end of register"));
7537 /* The instruction encoding stores the LSB and MSB,
7538 not the LSB and width. */
7539 inst.instruction |= inst.operands[0].reg << 12;
7540 inst.instruction |= inst.operands[1].reg;
7541 inst.instruction |= inst.operands[2].imm << 7;
7542 inst.instruction |= (msb - 1) << 16;
7543 }
7544
7545 static void
7546 do_bfx (void)
7547 {
7548 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7549 _("bit-field extends past end of register"));
7550 inst.instruction |= inst.operands[0].reg << 12;
7551 inst.instruction |= inst.operands[1].reg;
7552 inst.instruction |= inst.operands[2].imm << 7;
7553 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7554 }
7555
7556 /* ARM V5 breakpoint instruction (argument parse)
7557 BKPT <16 bit unsigned immediate>
7558 Instruction is not conditional.
7559 The bit pattern given in insns[] has the COND_ALWAYS condition,
7560 and it is an error if the caller tried to override that. */
7561
7562 static void
7563 do_bkpt (void)
7564 {
7565 /* Top 12 of 16 bits to bits 19:8. */
7566 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7567
7568 /* Bottom 4 of 16 bits to bits 3:0. */
7569 inst.instruction |= inst.operands[0].imm & 0xf;
7570 }
7571
7572 static void
7573 encode_branch (int default_reloc)
7574 {
7575 if (inst.operands[0].hasreloc)
7576 {
7577 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32
7578 && inst.operands[0].imm != BFD_RELOC_ARM_TLS_CALL,
7579 _("the only valid suffixes here are '(plt)' and '(tlscall)'"));
7580 inst.reloc.type = inst.operands[0].imm == BFD_RELOC_ARM_PLT32
7581 ? BFD_RELOC_ARM_PLT32
7582 : thumb_mode ? BFD_RELOC_ARM_THM_TLS_CALL : BFD_RELOC_ARM_TLS_CALL;
7583 }
7584 else
7585 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7586 inst.reloc.pc_rel = 1;
7587 }
7588
7589 static void
7590 do_branch (void)
7591 {
7592 #ifdef OBJ_ELF
7593 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7594 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7595 else
7596 #endif
7597 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7598 }
7599
7600 static void
7601 do_bl (void)
7602 {
7603 #ifdef OBJ_ELF
7604 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7605 {
7606 if (inst.cond == COND_ALWAYS)
7607 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7608 else
7609 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7610 }
7611 else
7612 #endif
7613 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7614 }
7615
7616 /* ARM V5 branch-link-exchange instruction (argument parse)
7617 BLX <target_addr> ie BLX(1)
7618 BLX{<condition>} <Rm> ie BLX(2)
7619 Unfortunately, there are two different opcodes for this mnemonic.
7620 So, the insns[].value is not used, and the code here zaps values
7621 into inst.instruction.
7622 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7623
7624 static void
7625 do_blx (void)
7626 {
7627 if (inst.operands[0].isreg)
7628 {
7629 /* Arg is a register; the opcode provided by insns[] is correct.
7630 It is not illegal to do "blx pc", just useless. */
7631 if (inst.operands[0].reg == REG_PC)
7632 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7633
7634 inst.instruction |= inst.operands[0].reg;
7635 }
7636 else
7637 {
7638 /* Arg is an address; this instruction cannot be executed
7639 conditionally, and the opcode must be adjusted.
7640 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7641 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7642 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7643 inst.instruction = 0xfa000000;
7644 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7645 }
7646 }
7647
7648 static void
7649 do_bx (void)
7650 {
7651 bfd_boolean want_reloc;
7652
7653 if (inst.operands[0].reg == REG_PC)
7654 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7655
7656 inst.instruction |= inst.operands[0].reg;
7657 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7658 it is for ARMv4t or earlier. */
7659 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7660 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7661 want_reloc = TRUE;
7662
7663 #ifdef OBJ_ELF
7664 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7665 #endif
7666 want_reloc = FALSE;
7667
7668 if (want_reloc)
7669 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7670 }
7671
7672
7673 /* ARM v5TEJ. Jump to Jazelle code. */
7674
7675 static void
7676 do_bxj (void)
7677 {
7678 if (inst.operands[0].reg == REG_PC)
7679 as_tsktsk (_("use of r15 in bxj is not really useful"));
7680
7681 inst.instruction |= inst.operands[0].reg;
7682 }
7683
7684 /* Co-processor data operation:
7685 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7686 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7687 static void
7688 do_cdp (void)
7689 {
7690 inst.instruction |= inst.operands[0].reg << 8;
7691 inst.instruction |= inst.operands[1].imm << 20;
7692 inst.instruction |= inst.operands[2].reg << 12;
7693 inst.instruction |= inst.operands[3].reg << 16;
7694 inst.instruction |= inst.operands[4].reg;
7695 inst.instruction |= inst.operands[5].imm << 5;
7696 }
7697
7698 static void
7699 do_cmp (void)
7700 {
7701 inst.instruction |= inst.operands[0].reg << 16;
7702 encode_arm_shifter_operand (1);
7703 }
7704
7705 /* Transfer between coprocessor and ARM registers.
7706 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7707 MRC2
7708 MCR{cond}
7709 MCR2
7710
7711 No special properties. */
7712
7713 struct deprecated_coproc_regs_s
7714 {
7715 unsigned cp;
7716 int opc1;
7717 unsigned crn;
7718 unsigned crm;
7719 int opc2;
7720 arm_feature_set deprecated;
7721 arm_feature_set obsoleted;
7722 const char *dep_msg;
7723 const char *obs_msg;
7724 };
7725
7726 #define DEPR_ACCESS_V8 \
7727 N_("This coprocessor register access is deprecated in ARMv8")
7728
7729 /* Table of all deprecated coprocessor registers. */
7730 static struct deprecated_coproc_regs_s deprecated_coproc_regs[] =
7731 {
7732 {15, 0, 7, 10, 5, /* CP15DMB. */
7733 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7734 DEPR_ACCESS_V8, NULL},
7735 {15, 0, 7, 10, 4, /* CP15DSB. */
7736 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7737 DEPR_ACCESS_V8, NULL},
7738 {15, 0, 7, 5, 4, /* CP15ISB. */
7739 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7740 DEPR_ACCESS_V8, NULL},
7741 {14, 6, 1, 0, 0, /* TEEHBR. */
7742 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7743 DEPR_ACCESS_V8, NULL},
7744 {14, 6, 0, 0, 0, /* TEECR. */
7745 ARM_FEATURE (ARM_EXT_V8, 0), ARM_FEATURE (0, 0),
7746 DEPR_ACCESS_V8, NULL},
7747 };
7748
7749 #undef DEPR_ACCESS_V8
7750
7751 static const size_t deprecated_coproc_reg_count =
7752 sizeof (deprecated_coproc_regs) / sizeof (deprecated_coproc_regs[0]);
7753
7754 static void
7755 do_co_reg (void)
7756 {
7757 unsigned Rd;
7758 size_t i;
7759
7760 Rd = inst.operands[2].reg;
7761 if (thumb_mode)
7762 {
7763 if (inst.instruction == 0xee000010
7764 || inst.instruction == 0xfe000010)
7765 /* MCR, MCR2 */
7766 reject_bad_reg (Rd);
7767 else
7768 /* MRC, MRC2 */
7769 constraint (Rd == REG_SP, BAD_SP);
7770 }
7771 else
7772 {
7773 /* MCR */
7774 if (inst.instruction == 0xe000010)
7775 constraint (Rd == REG_PC, BAD_PC);
7776 }
7777
7778 for (i = 0; i < deprecated_coproc_reg_count; ++i)
7779 {
7780 const struct deprecated_coproc_regs_s *r =
7781 deprecated_coproc_regs + i;
7782
7783 if (inst.operands[0].reg == r->cp
7784 && inst.operands[1].imm == r->opc1
7785 && inst.operands[3].reg == r->crn
7786 && inst.operands[4].reg == r->crm
7787 && inst.operands[5].imm == r->opc2)
7788 {
7789 if (!check_obsolete (&r->obsoleted, r->obs_msg)
7790 && warn_on_deprecated
7791 && ARM_CPU_HAS_FEATURE (cpu_variant, r->deprecated))
7792 as_warn ("%s", r->dep_msg);
7793 }
7794 }
7795
7796 inst.instruction |= inst.operands[0].reg << 8;
7797 inst.instruction |= inst.operands[1].imm << 21;
7798 inst.instruction |= Rd << 12;
7799 inst.instruction |= inst.operands[3].reg << 16;
7800 inst.instruction |= inst.operands[4].reg;
7801 inst.instruction |= inst.operands[5].imm << 5;
7802 }
7803
7804 /* Transfer between coprocessor register and pair of ARM registers.
7805 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7806 MCRR2
7807 MRRC{cond}
7808 MRRC2
7809
7810 Two XScale instructions are special cases of these:
7811
7812 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7813 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7814
7815 Result unpredictable if Rd or Rn is R15. */
7816
7817 static void
7818 do_co_reg2c (void)
7819 {
7820 unsigned Rd, Rn;
7821
7822 Rd = inst.operands[2].reg;
7823 Rn = inst.operands[3].reg;
7824
7825 if (thumb_mode)
7826 {
7827 reject_bad_reg (Rd);
7828 reject_bad_reg (Rn);
7829 }
7830 else
7831 {
7832 constraint (Rd == REG_PC, BAD_PC);
7833 constraint (Rn == REG_PC, BAD_PC);
7834 }
7835
7836 inst.instruction |= inst.operands[0].reg << 8;
7837 inst.instruction |= inst.operands[1].imm << 4;
7838 inst.instruction |= Rd << 12;
7839 inst.instruction |= Rn << 16;
7840 inst.instruction |= inst.operands[4].reg;
7841 }
7842
7843 static void
7844 do_cpsi (void)
7845 {
7846 inst.instruction |= inst.operands[0].imm << 6;
7847 if (inst.operands[1].present)
7848 {
7849 inst.instruction |= CPSI_MMOD;
7850 inst.instruction |= inst.operands[1].imm;
7851 }
7852 }
7853
7854 static void
7855 do_dbg (void)
7856 {
7857 inst.instruction |= inst.operands[0].imm;
7858 }
7859
7860 static void
7861 do_div (void)
7862 {
7863 unsigned Rd, Rn, Rm;
7864
7865 Rd = inst.operands[0].reg;
7866 Rn = (inst.operands[1].present
7867 ? inst.operands[1].reg : Rd);
7868 Rm = inst.operands[2].reg;
7869
7870 constraint ((Rd == REG_PC), BAD_PC);
7871 constraint ((Rn == REG_PC), BAD_PC);
7872 constraint ((Rm == REG_PC), BAD_PC);
7873
7874 inst.instruction |= Rd << 16;
7875 inst.instruction |= Rn << 0;
7876 inst.instruction |= Rm << 8;
7877 }
7878
7879 static void
7880 do_it (void)
7881 {
7882 /* There is no IT instruction in ARM mode. We
7883 process it to do the validation as if in
7884 thumb mode, just in case the code gets
7885 assembled for thumb using the unified syntax. */
7886
7887 inst.size = 0;
7888 if (unified_syntax)
7889 {
7890 set_it_insn_type (IT_INSN);
7891 now_it.mask = (inst.instruction & 0xf) | 0x10;
7892 now_it.cc = inst.operands[0].imm;
7893 }
7894 }
7895
7896 /* If there is only one register in the register list,
7897 then return its register number. Otherwise return -1. */
7898 static int
7899 only_one_reg_in_list (int range)
7900 {
7901 int i = ffs (range) - 1;
7902 return (i > 15 || range != (1 << i)) ? -1 : i;
7903 }
7904
7905 static void
7906 encode_ldmstm(int from_push_pop_mnem)
7907 {
7908 int base_reg = inst.operands[0].reg;
7909 int range = inst.operands[1].imm;
7910 int one_reg;
7911
7912 inst.instruction |= base_reg << 16;
7913 inst.instruction |= range;
7914
7915 if (inst.operands[1].writeback)
7916 inst.instruction |= LDM_TYPE_2_OR_3;
7917
7918 if (inst.operands[0].writeback)
7919 {
7920 inst.instruction |= WRITE_BACK;
7921 /* Check for unpredictable uses of writeback. */
7922 if (inst.instruction & LOAD_BIT)
7923 {
7924 /* Not allowed in LDM type 2. */
7925 if ((inst.instruction & LDM_TYPE_2_OR_3)
7926 && ((range & (1 << REG_PC)) == 0))
7927 as_warn (_("writeback of base register is UNPREDICTABLE"));
7928 /* Only allowed if base reg not in list for other types. */
7929 else if (range & (1 << base_reg))
7930 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7931 }
7932 else /* STM. */
7933 {
7934 /* Not allowed for type 2. */
7935 if (inst.instruction & LDM_TYPE_2_OR_3)
7936 as_warn (_("writeback of base register is UNPREDICTABLE"));
7937 /* Only allowed if base reg not in list, or first in list. */
7938 else if ((range & (1 << base_reg))
7939 && (range & ((1 << base_reg) - 1)))
7940 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7941 }
7942 }
7943
7944 /* If PUSH/POP has only one register, then use the A2 encoding. */
7945 one_reg = only_one_reg_in_list (range);
7946 if (from_push_pop_mnem && one_reg >= 0)
7947 {
7948 int is_push = (inst.instruction & A_PUSH_POP_OP_MASK) == A1_OPCODE_PUSH;
7949
7950 inst.instruction &= A_COND_MASK;
7951 inst.instruction |= is_push ? A2_OPCODE_PUSH : A2_OPCODE_POP;
7952 inst.instruction |= one_reg << 12;
7953 }
7954 }
7955
7956 static void
7957 do_ldmstm (void)
7958 {
7959 encode_ldmstm (/*from_push_pop_mnem=*/FALSE);
7960 }
7961
7962 /* ARMv5TE load-consecutive (argument parse)
7963 Mode is like LDRH.
7964
7965 LDRccD R, mode
7966 STRccD R, mode. */
7967
7968 static void
7969 do_ldrd (void)
7970 {
7971 constraint (inst.operands[0].reg % 2 != 0,
7972 _("first transfer register must be even"));
7973 constraint (inst.operands[1].present
7974 && inst.operands[1].reg != inst.operands[0].reg + 1,
7975 _("can only transfer two consecutive registers"));
7976 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7977 constraint (!inst.operands[2].isreg, _("'[' expected"));
7978
7979 if (!inst.operands[1].present)
7980 inst.operands[1].reg = inst.operands[0].reg + 1;
7981
7982 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7983 register and the first register written; we have to diagnose
7984 overlap between the base and the second register written here. */
7985
7986 if (inst.operands[2].reg == inst.operands[1].reg
7987 && (inst.operands[2].writeback || inst.operands[2].postind))
7988 as_warn (_("base register written back, and overlaps "
7989 "second transfer register"));
7990
7991 if (!(inst.instruction & V4_STR_BIT))
7992 {
7993 /* For an index-register load, the index register must not overlap the
7994 destination (even if not write-back). */
7995 if (inst.operands[2].immisreg
7996 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7997 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7998 as_warn (_("index register overlaps transfer register"));
7999 }
8000 inst.instruction |= inst.operands[0].reg << 12;
8001 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
8002 }
8003
8004 static void
8005 do_ldrex (void)
8006 {
8007 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
8008 || inst.operands[1].postind || inst.operands[1].writeback
8009 || inst.operands[1].immisreg || inst.operands[1].shifted
8010 || inst.operands[1].negative
8011 /* This can arise if the programmer has written
8012 strex rN, rM, foo
8013 or if they have mistakenly used a register name as the last
8014 operand, eg:
8015 strex rN, rM, rX
8016 It is very difficult to distinguish between these two cases
8017 because "rX" might actually be a label. ie the register
8018 name has been occluded by a symbol of the same name. So we
8019 just generate a general 'bad addressing mode' type error
8020 message and leave it up to the programmer to discover the
8021 true cause and fix their mistake. */
8022 || (inst.operands[1].reg == REG_PC),
8023 BAD_ADDR_MODE);
8024
8025 constraint (inst.reloc.exp.X_op != O_constant
8026 || inst.reloc.exp.X_add_number != 0,
8027 _("offset must be zero in ARM encoding"));
8028
8029 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
8030
8031 inst.instruction |= inst.operands[0].reg << 12;
8032 inst.instruction |= inst.operands[1].reg << 16;
8033 inst.reloc.type = BFD_RELOC_UNUSED;
8034 }
8035
8036 static void
8037 do_ldrexd (void)
8038 {
8039 constraint (inst.operands[0].reg % 2 != 0,
8040 _("even register required"));
8041 constraint (inst.operands[1].present
8042 && inst.operands[1].reg != inst.operands[0].reg + 1,
8043 _("can only load two consecutive registers"));
8044 /* If op 1 were present and equal to PC, this function wouldn't
8045 have been called in the first place. */
8046 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
8047
8048 inst.instruction |= inst.operands[0].reg << 12;
8049 inst.instruction |= inst.operands[2].reg << 16;
8050 }
8051
8052 /* In both ARM and thumb state 'ldr pc, #imm' with an immediate
8053 which is not a multiple of four is UNPREDICTABLE. */
8054 static void
8055 check_ldr_r15_aligned (void)
8056 {
8057 constraint (!(inst.operands[1].immisreg)
8058 && (inst.operands[0].reg == REG_PC
8059 && inst.operands[1].reg == REG_PC
8060 && (inst.reloc.exp.X_add_number & 0x3)),
8061 _("ldr to register 15 must be 4-byte alligned"));
8062 }
8063
8064 static void
8065 do_ldst (void)
8066 {
8067 inst.instruction |= inst.operands[0].reg << 12;
8068 if (!inst.operands[1].isreg)
8069 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
8070 return;
8071 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
8072 check_ldr_r15_aligned ();
8073 }
8074
8075 static void
8076 do_ldstt (void)
8077 {
8078 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8079 reject [Rn,...]. */
8080 if (inst.operands[1].preind)
8081 {
8082 constraint (inst.reloc.exp.X_op != O_constant
8083 || inst.reloc.exp.X_add_number != 0,
8084 _("this instruction requires a post-indexed address"));
8085
8086 inst.operands[1].preind = 0;
8087 inst.operands[1].postind = 1;
8088 inst.operands[1].writeback = 1;
8089 }
8090 inst.instruction |= inst.operands[0].reg << 12;
8091 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
8092 }
8093
8094 /* Halfword and signed-byte load/store operations. */
8095
8096 static void
8097 do_ldstv4 (void)
8098 {
8099 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8100 inst.instruction |= inst.operands[0].reg << 12;
8101 if (!inst.operands[1].isreg)
8102 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
8103 return;
8104 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
8105 }
8106
8107 static void
8108 do_ldsttv4 (void)
8109 {
8110 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
8111 reject [Rn,...]. */
8112 if (inst.operands[1].preind)
8113 {
8114 constraint (inst.reloc.exp.X_op != O_constant
8115 || inst.reloc.exp.X_add_number != 0,
8116 _("this instruction requires a post-indexed address"));
8117
8118 inst.operands[1].preind = 0;
8119 inst.operands[1].postind = 1;
8120 inst.operands[1].writeback = 1;
8121 }
8122 inst.instruction |= inst.operands[0].reg << 12;
8123 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
8124 }
8125
8126 /* Co-processor register load/store.
8127 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
8128 static void
8129 do_lstc (void)
8130 {
8131 inst.instruction |= inst.operands[0].reg << 8;
8132 inst.instruction |= inst.operands[1].reg << 12;
8133 encode_arm_cp_address (2, TRUE, TRUE, 0);
8134 }
8135
8136 static void
8137 do_mlas (void)
8138 {
8139 /* This restriction does not apply to mls (nor to mla in v6 or later). */
8140 if (inst.operands[0].reg == inst.operands[1].reg
8141 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
8142 && !(inst.instruction & 0x00400000))
8143 as_tsktsk (_("Rd and Rm should be different in mla"));
8144
8145 inst.instruction |= inst.operands[0].reg << 16;
8146 inst.instruction |= inst.operands[1].reg;
8147 inst.instruction |= inst.operands[2].reg << 8;
8148 inst.instruction |= inst.operands[3].reg << 12;
8149 }
8150
8151 static void
8152 do_mov (void)
8153 {
8154 inst.instruction |= inst.operands[0].reg << 12;
8155 encode_arm_shifter_operand (1);
8156 }
8157
8158 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
8159 static void
8160 do_mov16 (void)
8161 {
8162 bfd_vma imm;
8163 bfd_boolean top;
8164
8165 top = (inst.instruction & 0x00400000) != 0;
8166 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
8167 _(":lower16: not allowed this instruction"));
8168 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
8169 _(":upper16: not allowed instruction"));
8170 inst.instruction |= inst.operands[0].reg << 12;
8171 if (inst.reloc.type == BFD_RELOC_UNUSED)
8172 {
8173 imm = inst.reloc.exp.X_add_number;
8174 /* The value is in two pieces: 0:11, 16:19. */
8175 inst.instruction |= (imm & 0x00000fff);
8176 inst.instruction |= (imm & 0x0000f000) << 4;
8177 }
8178 }
8179
8180 static void do_vfp_nsyn_opcode (const char *);
8181
8182 static int
8183 do_vfp_nsyn_mrs (void)
8184 {
8185 if (inst.operands[0].isvec)
8186 {
8187 if (inst.operands[1].reg != 1)
8188 first_error (_("operand 1 must be FPSCR"));
8189 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
8190 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
8191 do_vfp_nsyn_opcode ("fmstat");
8192 }
8193 else if (inst.operands[1].isvec)
8194 do_vfp_nsyn_opcode ("fmrx");
8195 else
8196 return FAIL;
8197
8198 return SUCCESS;
8199 }
8200
8201 static int
8202 do_vfp_nsyn_msr (void)
8203 {
8204 if (inst.operands[0].isvec)
8205 do_vfp_nsyn_opcode ("fmxr");
8206 else
8207 return FAIL;
8208
8209 return SUCCESS;
8210 }
8211
8212 static void
8213 do_vmrs (void)
8214 {
8215 unsigned Rt = inst.operands[0].reg;
8216
8217 if (thumb_mode && inst.operands[0].reg == REG_SP)
8218 {
8219 inst.error = BAD_SP;
8220 return;
8221 }
8222
8223 /* APSR_ sets isvec. All other refs to PC are illegal. */
8224 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
8225 {
8226 inst.error = BAD_PC;
8227 return;
8228 }
8229
8230 switch (inst.operands[1].reg)
8231 {
8232 case 0: /* FPSID */
8233 case 1: /* FPSCR */
8234 case 6: /* MVFR1 */
8235 case 7: /* MVFR0 */
8236 case 8: /* FPEXC */
8237 inst.instruction |= (inst.operands[1].reg << 16);
8238 break;
8239 default:
8240 first_error (_("operand 1 must be a VFP extension System Register"));
8241 }
8242
8243 inst.instruction |= (Rt << 12);
8244 }
8245
8246 static void
8247 do_vmsr (void)
8248 {
8249 unsigned Rt = inst.operands[1].reg;
8250
8251 if (thumb_mode)
8252 reject_bad_reg (Rt);
8253 else if (Rt == REG_PC)
8254 {
8255 inst.error = BAD_PC;
8256 return;
8257 }
8258
8259 switch (inst.operands[0].reg)
8260 {
8261 case 0: /* FPSID */
8262 case 1: /* FPSCR */
8263 case 8: /* FPEXC */
8264 inst.instruction |= (inst.operands[0].reg << 16);
8265 break;
8266 default:
8267 first_error (_("operand 0 must be FPSID or FPSCR pr FPEXC"));
8268 }
8269
8270 inst.instruction |= (Rt << 12);
8271 }
8272
8273 static void
8274 do_mrs (void)
8275 {
8276 unsigned br;
8277
8278 if (do_vfp_nsyn_mrs () == SUCCESS)
8279 return;
8280
8281 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8282 inst.instruction |= inst.operands[0].reg << 12;
8283
8284 if (inst.operands[1].isreg)
8285 {
8286 br = inst.operands[1].reg;
8287 if (((br & 0x200) == 0) && ((br & 0xf0000) != 0xf000))
8288 as_bad (_("bad register for mrs"));
8289 }
8290 else
8291 {
8292 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
8293 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
8294 != (PSR_c|PSR_f),
8295 _("'APSR', 'CPSR' or 'SPSR' expected"));
8296 br = (15<<16) | (inst.operands[1].imm & SPSR_BIT);
8297 }
8298
8299 inst.instruction |= br;
8300 }
8301
8302 /* Two possible forms:
8303 "{C|S}PSR_<field>, Rm",
8304 "{C|S}PSR_f, #expression". */
8305
8306 static void
8307 do_msr (void)
8308 {
8309 if (do_vfp_nsyn_msr () == SUCCESS)
8310 return;
8311
8312 inst.instruction |= inst.operands[0].imm;
8313 if (inst.operands[1].isreg)
8314 inst.instruction |= inst.operands[1].reg;
8315 else
8316 {
8317 inst.instruction |= INST_IMMEDIATE;
8318 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
8319 inst.reloc.pc_rel = 0;
8320 }
8321 }
8322
8323 static void
8324 do_mul (void)
8325 {
8326 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
8327
8328 if (!inst.operands[2].present)
8329 inst.operands[2].reg = inst.operands[0].reg;
8330 inst.instruction |= inst.operands[0].reg << 16;
8331 inst.instruction |= inst.operands[1].reg;
8332 inst.instruction |= inst.operands[2].reg << 8;
8333
8334 if (inst.operands[0].reg == inst.operands[1].reg
8335 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8336 as_tsktsk (_("Rd and Rm should be different in mul"));
8337 }
8338
8339 /* Long Multiply Parser
8340 UMULL RdLo, RdHi, Rm, Rs
8341 SMULL RdLo, RdHi, Rm, Rs
8342 UMLAL RdLo, RdHi, Rm, Rs
8343 SMLAL RdLo, RdHi, Rm, Rs. */
8344
8345 static void
8346 do_mull (void)
8347 {
8348 inst.instruction |= inst.operands[0].reg << 12;
8349 inst.instruction |= inst.operands[1].reg << 16;
8350 inst.instruction |= inst.operands[2].reg;
8351 inst.instruction |= inst.operands[3].reg << 8;
8352
8353 /* rdhi and rdlo must be different. */
8354 if (inst.operands[0].reg == inst.operands[1].reg)
8355 as_tsktsk (_("rdhi and rdlo must be different"));
8356
8357 /* rdhi, rdlo and rm must all be different before armv6. */
8358 if ((inst.operands[0].reg == inst.operands[2].reg
8359 || inst.operands[1].reg == inst.operands[2].reg)
8360 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
8361 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
8362 }
8363
8364 static void
8365 do_nop (void)
8366 {
8367 if (inst.operands[0].present
8368 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
8369 {
8370 /* Architectural NOP hints are CPSR sets with no bits selected. */
8371 inst.instruction &= 0xf0000000;
8372 inst.instruction |= 0x0320f000;
8373 if (inst.operands[0].present)
8374 inst.instruction |= inst.operands[0].imm;
8375 }
8376 }
8377
8378 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
8379 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
8380 Condition defaults to COND_ALWAYS.
8381 Error if Rd, Rn or Rm are R15. */
8382
8383 static void
8384 do_pkhbt (void)
8385 {
8386 inst.instruction |= inst.operands[0].reg << 12;
8387 inst.instruction |= inst.operands[1].reg << 16;
8388 inst.instruction |= inst.operands[2].reg;
8389 if (inst.operands[3].present)
8390 encode_arm_shift (3);
8391 }
8392
8393 /* ARM V6 PKHTB (Argument Parse). */
8394
8395 static void
8396 do_pkhtb (void)
8397 {
8398 if (!inst.operands[3].present)
8399 {
8400 /* If the shift specifier is omitted, turn the instruction
8401 into pkhbt rd, rm, rn. */
8402 inst.instruction &= 0xfff00010;
8403 inst.instruction |= inst.operands[0].reg << 12;
8404 inst.instruction |= inst.operands[1].reg;
8405 inst.instruction |= inst.operands[2].reg << 16;
8406 }
8407 else
8408 {
8409 inst.instruction |= inst.operands[0].reg << 12;
8410 inst.instruction |= inst.operands[1].reg << 16;
8411 inst.instruction |= inst.operands[2].reg;
8412 encode_arm_shift (3);
8413 }
8414 }
8415
8416 /* ARMv5TE: Preload-Cache
8417 MP Extensions: Preload for write
8418
8419 PLD(W) <addr_mode>
8420
8421 Syntactically, like LDR with B=1, W=0, L=1. */
8422
8423 static void
8424 do_pld (void)
8425 {
8426 constraint (!inst.operands[0].isreg,
8427 _("'[' expected after PLD mnemonic"));
8428 constraint (inst.operands[0].postind,
8429 _("post-indexed expression used in preload instruction"));
8430 constraint (inst.operands[0].writeback,
8431 _("writeback used in preload instruction"));
8432 constraint (!inst.operands[0].preind,
8433 _("unindexed addressing used in preload instruction"));
8434 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8435 }
8436
8437 /* ARMv7: PLI <addr_mode> */
8438 static void
8439 do_pli (void)
8440 {
8441 constraint (!inst.operands[0].isreg,
8442 _("'[' expected after PLI mnemonic"));
8443 constraint (inst.operands[0].postind,
8444 _("post-indexed expression used in preload instruction"));
8445 constraint (inst.operands[0].writeback,
8446 _("writeback used in preload instruction"));
8447 constraint (!inst.operands[0].preind,
8448 _("unindexed addressing used in preload instruction"));
8449 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
8450 inst.instruction &= ~PRE_INDEX;
8451 }
8452
8453 static void
8454 do_push_pop (void)
8455 {
8456 inst.operands[1] = inst.operands[0];
8457 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
8458 inst.operands[0].isreg = 1;
8459 inst.operands[0].writeback = 1;
8460 inst.operands[0].reg = REG_SP;
8461 encode_ldmstm (/*from_push_pop_mnem=*/TRUE);
8462 }
8463
8464 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
8465 word at the specified address and the following word
8466 respectively.
8467 Unconditionally executed.
8468 Error if Rn is R15. */
8469
8470 static void
8471 do_rfe (void)
8472 {
8473 inst.instruction |= inst.operands[0].reg << 16;
8474 if (inst.operands[0].writeback)
8475 inst.instruction |= WRITE_BACK;
8476 }
8477
8478 /* ARM V6 ssat (argument parse). */
8479
8480 static void
8481 do_ssat (void)
8482 {
8483 inst.instruction |= inst.operands[0].reg << 12;
8484 inst.instruction |= (inst.operands[1].imm - 1) << 16;
8485 inst.instruction |= inst.operands[2].reg;
8486
8487 if (inst.operands[3].present)
8488 encode_arm_shift (3);
8489 }
8490
8491 /* ARM V6 usat (argument parse). */
8492
8493 static void
8494 do_usat (void)
8495 {
8496 inst.instruction |= inst.operands[0].reg << 12;
8497 inst.instruction |= inst.operands[1].imm << 16;
8498 inst.instruction |= inst.operands[2].reg;
8499
8500 if (inst.operands[3].present)
8501 encode_arm_shift (3);
8502 }
8503
8504 /* ARM V6 ssat16 (argument parse). */
8505
8506 static void
8507 do_ssat16 (void)
8508 {
8509 inst.instruction |= inst.operands[0].reg << 12;
8510 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8511 inst.instruction |= inst.operands[2].reg;
8512 }
8513
8514 static void
8515 do_usat16 (void)
8516 {
8517 inst.instruction |= inst.operands[0].reg << 12;
8518 inst.instruction |= inst.operands[1].imm << 16;
8519 inst.instruction |= inst.operands[2].reg;
8520 }
8521
8522 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8523 preserving the other bits.
8524
8525 setend <endian_specifier>, where <endian_specifier> is either
8526 BE or LE. */
8527
8528 static void
8529 do_setend (void)
8530 {
8531 if (inst.operands[0].imm)
8532 inst.instruction |= 0x200;
8533 }
8534
8535 static void
8536 do_shift (void)
8537 {
8538 unsigned int Rm = (inst.operands[1].present
8539 ? inst.operands[1].reg
8540 : inst.operands[0].reg);
8541
8542 inst.instruction |= inst.operands[0].reg << 12;
8543 inst.instruction |= Rm;
8544 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
8545 {
8546 inst.instruction |= inst.operands[2].reg << 8;
8547 inst.instruction |= SHIFT_BY_REG;
8548 /* PR 12854: Error on extraneous shifts. */
8549 constraint (inst.operands[2].shifted,
8550 _("extraneous shift as part of operand to shift insn"));
8551 }
8552 else
8553 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
8554 }
8555
8556 static void
8557 do_smc (void)
8558 {
8559 inst.reloc.type = BFD_RELOC_ARM_SMC;
8560 inst.reloc.pc_rel = 0;
8561 }
8562
8563 static void
8564 do_hvc (void)
8565 {
8566 inst.reloc.type = BFD_RELOC_ARM_HVC;
8567 inst.reloc.pc_rel = 0;
8568 }
8569
8570 static void
8571 do_swi (void)
8572 {
8573 inst.reloc.type = BFD_RELOC_ARM_SWI;
8574 inst.reloc.pc_rel = 0;
8575 }
8576
8577 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8578 SMLAxy{cond} Rd,Rm,Rs,Rn
8579 SMLAWy{cond} Rd,Rm,Rs,Rn
8580 Error if any register is R15. */
8581
8582 static void
8583 do_smla (void)
8584 {
8585 inst.instruction |= inst.operands[0].reg << 16;
8586 inst.instruction |= inst.operands[1].reg;
8587 inst.instruction |= inst.operands[2].reg << 8;
8588 inst.instruction |= inst.operands[3].reg << 12;
8589 }
8590
8591 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8592 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8593 Error if any register is R15.
8594 Warning if Rdlo == Rdhi. */
8595
8596 static void
8597 do_smlal (void)
8598 {
8599 inst.instruction |= inst.operands[0].reg << 12;
8600 inst.instruction |= inst.operands[1].reg << 16;
8601 inst.instruction |= inst.operands[2].reg;
8602 inst.instruction |= inst.operands[3].reg << 8;
8603
8604 if (inst.operands[0].reg == inst.operands[1].reg)
8605 as_tsktsk (_("rdhi and rdlo must be different"));
8606 }
8607
8608 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8609 SMULxy{cond} Rd,Rm,Rs
8610 Error if any register is R15. */
8611
8612 static void
8613 do_smul (void)
8614 {
8615 inst.instruction |= inst.operands[0].reg << 16;
8616 inst.instruction |= inst.operands[1].reg;
8617 inst.instruction |= inst.operands[2].reg << 8;
8618 }
8619
8620 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8621 the same for both ARM and Thumb-2. */
8622
8623 static void
8624 do_srs (void)
8625 {
8626 int reg;
8627
8628 if (inst.operands[0].present)
8629 {
8630 reg = inst.operands[0].reg;
8631 constraint (reg != REG_SP, _("SRS base register must be r13"));
8632 }
8633 else
8634 reg = REG_SP;
8635
8636 inst.instruction |= reg << 16;
8637 inst.instruction |= inst.operands[1].imm;
8638 if (inst.operands[0].writeback || inst.operands[1].writeback)
8639 inst.instruction |= WRITE_BACK;
8640 }
8641
8642 /* ARM V6 strex (argument parse). */
8643
8644 static void
8645 do_strex (void)
8646 {
8647 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8648 || inst.operands[2].postind || inst.operands[2].writeback
8649 || inst.operands[2].immisreg || inst.operands[2].shifted
8650 || inst.operands[2].negative
8651 /* See comment in do_ldrex(). */
8652 || (inst.operands[2].reg == REG_PC),
8653 BAD_ADDR_MODE);
8654
8655 constraint (inst.operands[0].reg == inst.operands[1].reg
8656 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8657
8658 constraint (inst.reloc.exp.X_op != O_constant
8659 || inst.reloc.exp.X_add_number != 0,
8660 _("offset must be zero in ARM encoding"));
8661
8662 inst.instruction |= inst.operands[0].reg << 12;
8663 inst.instruction |= inst.operands[1].reg;
8664 inst.instruction |= inst.operands[2].reg << 16;
8665 inst.reloc.type = BFD_RELOC_UNUSED;
8666 }
8667
8668 static void
8669 do_t_strexbh (void)
8670 {
8671 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8672 || inst.operands[2].postind || inst.operands[2].writeback
8673 || inst.operands[2].immisreg || inst.operands[2].shifted
8674 || inst.operands[2].negative,
8675 BAD_ADDR_MODE);
8676
8677 constraint (inst.operands[0].reg == inst.operands[1].reg
8678 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8679
8680 do_rm_rd_rn ();
8681 }
8682
8683 static void
8684 do_strexd (void)
8685 {
8686 constraint (inst.operands[1].reg % 2 != 0,
8687 _("even register required"));
8688 constraint (inst.operands[2].present
8689 && inst.operands[2].reg != inst.operands[1].reg + 1,
8690 _("can only store two consecutive registers"));
8691 /* If op 2 were present and equal to PC, this function wouldn't
8692 have been called in the first place. */
8693 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8694
8695 constraint (inst.operands[0].reg == inst.operands[1].reg
8696 || inst.operands[0].reg == inst.operands[1].reg + 1
8697 || inst.operands[0].reg == inst.operands[3].reg,
8698 BAD_OVERLAP);
8699
8700 inst.instruction |= inst.operands[0].reg << 12;
8701 inst.instruction |= inst.operands[1].reg;
8702 inst.instruction |= inst.operands[3].reg << 16;
8703 }
8704
8705 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8706 extends it to 32-bits, and adds the result to a value in another
8707 register. You can specify a rotation by 0, 8, 16, or 24 bits
8708 before extracting the 16-bit value.
8709 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8710 Condition defaults to COND_ALWAYS.
8711 Error if any register uses R15. */
8712
8713 static void
8714 do_sxtah (void)
8715 {
8716 inst.instruction |= inst.operands[0].reg << 12;
8717 inst.instruction |= inst.operands[1].reg << 16;
8718 inst.instruction |= inst.operands[2].reg;
8719 inst.instruction |= inst.operands[3].imm << 10;
8720 }
8721
8722 /* ARM V6 SXTH.
8723
8724 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8725 Condition defaults to COND_ALWAYS.
8726 Error if any register uses R15. */
8727
8728 static void
8729 do_sxth (void)
8730 {
8731 inst.instruction |= inst.operands[0].reg << 12;
8732 inst.instruction |= inst.operands[1].reg;
8733 inst.instruction |= inst.operands[2].imm << 10;
8734 }
8735 \f
8736 /* VFP instructions. In a logical order: SP variant first, monad
8737 before dyad, arithmetic then move then load/store. */
8738
8739 static void
8740 do_vfp_sp_monadic (void)
8741 {
8742 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8743 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8744 }
8745
8746 static void
8747 do_vfp_sp_dyadic (void)
8748 {
8749 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8750 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8751 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8752 }
8753
8754 static void
8755 do_vfp_sp_compare_z (void)
8756 {
8757 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8758 }
8759
8760 static void
8761 do_vfp_dp_sp_cvt (void)
8762 {
8763 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8764 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8765 }
8766
8767 static void
8768 do_vfp_sp_dp_cvt (void)
8769 {
8770 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8771 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8772 }
8773
8774 static void
8775 do_vfp_reg_from_sp (void)
8776 {
8777 inst.instruction |= inst.operands[0].reg << 12;
8778 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8779 }
8780
8781 static void
8782 do_vfp_reg2_from_sp2 (void)
8783 {
8784 constraint (inst.operands[2].imm != 2,
8785 _("only two consecutive VFP SP registers allowed here"));
8786 inst.instruction |= inst.operands[0].reg << 12;
8787 inst.instruction |= inst.operands[1].reg << 16;
8788 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8789 }
8790
8791 static void
8792 do_vfp_sp_from_reg (void)
8793 {
8794 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8795 inst.instruction |= inst.operands[1].reg << 12;
8796 }
8797
8798 static void
8799 do_vfp_sp2_from_reg2 (void)
8800 {
8801 constraint (inst.operands[0].imm != 2,
8802 _("only two consecutive VFP SP registers allowed here"));
8803 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8804 inst.instruction |= inst.operands[1].reg << 12;
8805 inst.instruction |= inst.operands[2].reg << 16;
8806 }
8807
8808 static void
8809 do_vfp_sp_ldst (void)
8810 {
8811 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8812 encode_arm_cp_address (1, FALSE, TRUE, 0);
8813 }
8814
8815 static void
8816 do_vfp_dp_ldst (void)
8817 {
8818 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8819 encode_arm_cp_address (1, FALSE, TRUE, 0);
8820 }
8821
8822
8823 static void
8824 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8825 {
8826 if (inst.operands[0].writeback)
8827 inst.instruction |= WRITE_BACK;
8828 else
8829 constraint (ldstm_type != VFP_LDSTMIA,
8830 _("this addressing mode requires base-register writeback"));
8831 inst.instruction |= inst.operands[0].reg << 16;
8832 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8833 inst.instruction |= inst.operands[1].imm;
8834 }
8835
8836 static void
8837 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8838 {
8839 int count;
8840
8841 if (inst.operands[0].writeback)
8842 inst.instruction |= WRITE_BACK;
8843 else
8844 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8845 _("this addressing mode requires base-register writeback"));
8846
8847 inst.instruction |= inst.operands[0].reg << 16;
8848 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8849
8850 count = inst.operands[1].imm << 1;
8851 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8852 count += 1;
8853
8854 inst.instruction |= count;
8855 }
8856
8857 static void
8858 do_vfp_sp_ldstmia (void)
8859 {
8860 vfp_sp_ldstm (VFP_LDSTMIA);
8861 }
8862
8863 static void
8864 do_vfp_sp_ldstmdb (void)
8865 {
8866 vfp_sp_ldstm (VFP_LDSTMDB);
8867 }
8868
8869 static void
8870 do_vfp_dp_ldstmia (void)
8871 {
8872 vfp_dp_ldstm (VFP_LDSTMIA);
8873 }
8874
8875 static void
8876 do_vfp_dp_ldstmdb (void)
8877 {
8878 vfp_dp_ldstm (VFP_LDSTMDB);
8879 }
8880
8881 static void
8882 do_vfp_xp_ldstmia (void)
8883 {
8884 vfp_dp_ldstm (VFP_LDSTMIAX);
8885 }
8886
8887 static void
8888 do_vfp_xp_ldstmdb (void)
8889 {
8890 vfp_dp_ldstm (VFP_LDSTMDBX);
8891 }
8892
8893 static void
8894 do_vfp_dp_rd_rm (void)
8895 {
8896 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8897 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8898 }
8899
8900 static void
8901 do_vfp_dp_rn_rd (void)
8902 {
8903 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8904 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8905 }
8906
8907 static void
8908 do_vfp_dp_rd_rn (void)
8909 {
8910 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8911 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8912 }
8913
8914 static void
8915 do_vfp_dp_rd_rn_rm (void)
8916 {
8917 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8918 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8919 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8920 }
8921
8922 static void
8923 do_vfp_dp_rd (void)
8924 {
8925 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8926 }
8927
8928 static void
8929 do_vfp_dp_rm_rd_rn (void)
8930 {
8931 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8932 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8933 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8934 }
8935
8936 /* VFPv3 instructions. */
8937 static void
8938 do_vfp_sp_const (void)
8939 {
8940 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8941 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8942 inst.instruction |= (inst.operands[1].imm & 0x0f);
8943 }
8944
8945 static void
8946 do_vfp_dp_const (void)
8947 {
8948 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8949 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8950 inst.instruction |= (inst.operands[1].imm & 0x0f);
8951 }
8952
8953 static void
8954 vfp_conv (int srcsize)
8955 {
8956 int immbits = srcsize - inst.operands[1].imm;
8957
8958 if (srcsize == 16 && !(immbits >= 0 && immbits <= srcsize))
8959 {
8960 /* If srcsize is 16, inst.operands[1].imm must be in the range 0-16.
8961 i.e. immbits must be in range 0 - 16. */
8962 inst.error = _("immediate value out of range, expected range [0, 16]");
8963 return;
8964 }
8965 else if (srcsize == 32 && !(immbits >= 0 && immbits < srcsize))
8966 {
8967 /* If srcsize is 32, inst.operands[1].imm must be in the range 1-32.
8968 i.e. immbits must be in range 0 - 31. */
8969 inst.error = _("immediate value out of range, expected range [1, 32]");
8970 return;
8971 }
8972
8973 inst.instruction |= (immbits & 1) << 5;
8974 inst.instruction |= (immbits >> 1);
8975 }
8976
8977 static void
8978 do_vfp_sp_conv_16 (void)
8979 {
8980 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8981 vfp_conv (16);
8982 }
8983
8984 static void
8985 do_vfp_dp_conv_16 (void)
8986 {
8987 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8988 vfp_conv (16);
8989 }
8990
8991 static void
8992 do_vfp_sp_conv_32 (void)
8993 {
8994 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8995 vfp_conv (32);
8996 }
8997
8998 static void
8999 do_vfp_dp_conv_32 (void)
9000 {
9001 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
9002 vfp_conv (32);
9003 }
9004 \f
9005 /* FPA instructions. Also in a logical order. */
9006
9007 static void
9008 do_fpa_cmp (void)
9009 {
9010 inst.instruction |= inst.operands[0].reg << 16;
9011 inst.instruction |= inst.operands[1].reg;
9012 }
9013
9014 static void
9015 do_fpa_ldmstm (void)
9016 {
9017 inst.instruction |= inst.operands[0].reg << 12;
9018 switch (inst.operands[1].imm)
9019 {
9020 case 1: inst.instruction |= CP_T_X; break;
9021 case 2: inst.instruction |= CP_T_Y; break;
9022 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
9023 case 4: break;
9024 default: abort ();
9025 }
9026
9027 if (inst.instruction & (PRE_INDEX | INDEX_UP))
9028 {
9029 /* The instruction specified "ea" or "fd", so we can only accept
9030 [Rn]{!}. The instruction does not really support stacking or
9031 unstacking, so we have to emulate these by setting appropriate
9032 bits and offsets. */
9033 constraint (inst.reloc.exp.X_op != O_constant
9034 || inst.reloc.exp.X_add_number != 0,
9035 _("this instruction does not support indexing"));
9036
9037 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
9038 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
9039
9040 if (!(inst.instruction & INDEX_UP))
9041 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
9042
9043 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
9044 {
9045 inst.operands[2].preind = 0;
9046 inst.operands[2].postind = 1;
9047 }
9048 }
9049
9050 encode_arm_cp_address (2, TRUE, TRUE, 0);
9051 }
9052 \f
9053 /* iWMMXt instructions: strictly in alphabetical order. */
9054
9055 static void
9056 do_iwmmxt_tandorc (void)
9057 {
9058 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
9059 }
9060
9061 static void
9062 do_iwmmxt_textrc (void)
9063 {
9064 inst.instruction |= inst.operands[0].reg << 12;
9065 inst.instruction |= inst.operands[1].imm;
9066 }
9067
9068 static void
9069 do_iwmmxt_textrm (void)
9070 {
9071 inst.instruction |= inst.operands[0].reg << 12;
9072 inst.instruction |= inst.operands[1].reg << 16;
9073 inst.instruction |= inst.operands[2].imm;
9074 }
9075
9076 static void
9077 do_iwmmxt_tinsr (void)
9078 {
9079 inst.instruction |= inst.operands[0].reg << 16;
9080 inst.instruction |= inst.operands[1].reg << 12;
9081 inst.instruction |= inst.operands[2].imm;
9082 }
9083
9084 static void
9085 do_iwmmxt_tmia (void)
9086 {
9087 inst.instruction |= inst.operands[0].reg << 5;
9088 inst.instruction |= inst.operands[1].reg;
9089 inst.instruction |= inst.operands[2].reg << 12;
9090 }
9091
9092 static void
9093 do_iwmmxt_waligni (void)
9094 {
9095 inst.instruction |= inst.operands[0].reg << 12;
9096 inst.instruction |= inst.operands[1].reg << 16;
9097 inst.instruction |= inst.operands[2].reg;
9098 inst.instruction |= inst.operands[3].imm << 20;
9099 }
9100
9101 static void
9102 do_iwmmxt_wmerge (void)
9103 {
9104 inst.instruction |= inst.operands[0].reg << 12;
9105 inst.instruction |= inst.operands[1].reg << 16;
9106 inst.instruction |= inst.operands[2].reg;
9107 inst.instruction |= inst.operands[3].imm << 21;
9108 }
9109
9110 static void
9111 do_iwmmxt_wmov (void)
9112 {
9113 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
9114 inst.instruction |= inst.operands[0].reg << 12;
9115 inst.instruction |= inst.operands[1].reg << 16;
9116 inst.instruction |= inst.operands[1].reg;
9117 }
9118
9119 static void
9120 do_iwmmxt_wldstbh (void)
9121 {
9122 int reloc;
9123 inst.instruction |= inst.operands[0].reg << 12;
9124 if (thumb_mode)
9125 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
9126 else
9127 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
9128 encode_arm_cp_address (1, TRUE, FALSE, reloc);
9129 }
9130
9131 static void
9132 do_iwmmxt_wldstw (void)
9133 {
9134 /* RIWR_RIWC clears .isreg for a control register. */
9135 if (!inst.operands[0].isreg)
9136 {
9137 constraint (inst.cond != COND_ALWAYS, BAD_COND);
9138 inst.instruction |= 0xf0000000;
9139 }
9140
9141 inst.instruction |= inst.operands[0].reg << 12;
9142 encode_arm_cp_address (1, TRUE, TRUE, 0);
9143 }
9144
9145 static void
9146 do_iwmmxt_wldstd (void)
9147 {
9148 inst.instruction |= inst.operands[0].reg << 12;
9149 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
9150 && inst.operands[1].immisreg)
9151 {
9152 inst.instruction &= ~0x1a000ff;
9153 inst.instruction |= (0xf << 28);
9154 if (inst.operands[1].preind)
9155 inst.instruction |= PRE_INDEX;
9156 if (!inst.operands[1].negative)
9157 inst.instruction |= INDEX_UP;
9158 if (inst.operands[1].writeback)
9159 inst.instruction |= WRITE_BACK;
9160 inst.instruction |= inst.operands[1].reg << 16;
9161 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9162 inst.instruction |= inst.operands[1].imm;
9163 }
9164 else
9165 encode_arm_cp_address (1, TRUE, FALSE, 0);
9166 }
9167
9168 static void
9169 do_iwmmxt_wshufh (void)
9170 {
9171 inst.instruction |= inst.operands[0].reg << 12;
9172 inst.instruction |= inst.operands[1].reg << 16;
9173 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
9174 inst.instruction |= (inst.operands[2].imm & 0x0f);
9175 }
9176
9177 static void
9178 do_iwmmxt_wzero (void)
9179 {
9180 /* WZERO reg is an alias for WANDN reg, reg, reg. */
9181 inst.instruction |= inst.operands[0].reg;
9182 inst.instruction |= inst.operands[0].reg << 12;
9183 inst.instruction |= inst.operands[0].reg << 16;
9184 }
9185
9186 static void
9187 do_iwmmxt_wrwrwr_or_imm5 (void)
9188 {
9189 if (inst.operands[2].isreg)
9190 do_rd_rn_rm ();
9191 else {
9192 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
9193 _("immediate operand requires iWMMXt2"));
9194 do_rd_rn ();
9195 if (inst.operands[2].imm == 0)
9196 {
9197 switch ((inst.instruction >> 20) & 0xf)
9198 {
9199 case 4:
9200 case 5:
9201 case 6:
9202 case 7:
9203 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
9204 inst.operands[2].imm = 16;
9205 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
9206 break;
9207 case 8:
9208 case 9:
9209 case 10:
9210 case 11:
9211 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
9212 inst.operands[2].imm = 32;
9213 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
9214 break;
9215 case 12:
9216 case 13:
9217 case 14:
9218 case 15:
9219 {
9220 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
9221 unsigned long wrn;
9222 wrn = (inst.instruction >> 16) & 0xf;
9223 inst.instruction &= 0xff0fff0f;
9224 inst.instruction |= wrn;
9225 /* Bail out here; the instruction is now assembled. */
9226 return;
9227 }
9228 }
9229 }
9230 /* Map 32 -> 0, etc. */
9231 inst.operands[2].imm &= 0x1f;
9232 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
9233 }
9234 }
9235 \f
9236 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
9237 operations first, then control, shift, and load/store. */
9238
9239 /* Insns like "foo X,Y,Z". */
9240
9241 static void
9242 do_mav_triple (void)
9243 {
9244 inst.instruction |= inst.operands[0].reg << 16;
9245 inst.instruction |= inst.operands[1].reg;
9246 inst.instruction |= inst.operands[2].reg << 12;
9247 }
9248
9249 /* Insns like "foo W,X,Y,Z".
9250 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
9251
9252 static void
9253 do_mav_quad (void)
9254 {
9255 inst.instruction |= inst.operands[0].reg << 5;
9256 inst.instruction |= inst.operands[1].reg << 12;
9257 inst.instruction |= inst.operands[2].reg << 16;
9258 inst.instruction |= inst.operands[3].reg;
9259 }
9260
9261 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
9262 static void
9263 do_mav_dspsc (void)
9264 {
9265 inst.instruction |= inst.operands[1].reg << 12;
9266 }
9267
9268 /* Maverick shift immediate instructions.
9269 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
9270 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
9271
9272 static void
9273 do_mav_shift (void)
9274 {
9275 int imm = inst.operands[2].imm;
9276
9277 inst.instruction |= inst.operands[0].reg << 12;
9278 inst.instruction |= inst.operands[1].reg << 16;
9279
9280 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
9281 Bits 5-7 of the insn should have bits 4-6 of the immediate.
9282 Bit 4 should be 0. */
9283 imm = (imm & 0xf) | ((imm & 0x70) << 1);
9284
9285 inst.instruction |= imm;
9286 }
9287 \f
9288 /* XScale instructions. Also sorted arithmetic before move. */
9289
9290 /* Xscale multiply-accumulate (argument parse)
9291 MIAcc acc0,Rm,Rs
9292 MIAPHcc acc0,Rm,Rs
9293 MIAxycc acc0,Rm,Rs. */
9294
9295 static void
9296 do_xsc_mia (void)
9297 {
9298 inst.instruction |= inst.operands[1].reg;
9299 inst.instruction |= inst.operands[2].reg << 12;
9300 }
9301
9302 /* Xscale move-accumulator-register (argument parse)
9303
9304 MARcc acc0,RdLo,RdHi. */
9305
9306 static void
9307 do_xsc_mar (void)
9308 {
9309 inst.instruction |= inst.operands[1].reg << 12;
9310 inst.instruction |= inst.operands[2].reg << 16;
9311 }
9312
9313 /* Xscale move-register-accumulator (argument parse)
9314
9315 MRAcc RdLo,RdHi,acc0. */
9316
9317 static void
9318 do_xsc_mra (void)
9319 {
9320 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
9321 inst.instruction |= inst.operands[0].reg << 12;
9322 inst.instruction |= inst.operands[1].reg << 16;
9323 }
9324 \f
9325 /* Encoding functions relevant only to Thumb. */
9326
9327 /* inst.operands[i] is a shifted-register operand; encode
9328 it into inst.instruction in the format used by Thumb32. */
9329
9330 static void
9331 encode_thumb32_shifted_operand (int i)
9332 {
9333 unsigned int value = inst.reloc.exp.X_add_number;
9334 unsigned int shift = inst.operands[i].shift_kind;
9335
9336 constraint (inst.operands[i].immisreg,
9337 _("shift by register not allowed in thumb mode"));
9338 inst.instruction |= inst.operands[i].reg;
9339 if (shift == SHIFT_RRX)
9340 inst.instruction |= SHIFT_ROR << 4;
9341 else
9342 {
9343 constraint (inst.reloc.exp.X_op != O_constant,
9344 _("expression too complex"));
9345
9346 constraint (value > 32
9347 || (value == 32 && (shift == SHIFT_LSL
9348 || shift == SHIFT_ROR)),
9349 _("shift expression is too large"));
9350
9351 if (value == 0)
9352 shift = SHIFT_LSL;
9353 else if (value == 32)
9354 value = 0;
9355
9356 inst.instruction |= shift << 4;
9357 inst.instruction |= (value & 0x1c) << 10;
9358 inst.instruction |= (value & 0x03) << 6;
9359 }
9360 }
9361
9362
9363 /* inst.operands[i] was set up by parse_address. Encode it into a
9364 Thumb32 format load or store instruction. Reject forms that cannot
9365 be used with such instructions. If is_t is true, reject forms that
9366 cannot be used with a T instruction; if is_d is true, reject forms
9367 that cannot be used with a D instruction. If it is a store insn,
9368 reject PC in Rn. */
9369
9370 static void
9371 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
9372 {
9373 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
9374
9375 constraint (!inst.operands[i].isreg,
9376 _("Instruction does not support =N addresses"));
9377
9378 inst.instruction |= inst.operands[i].reg << 16;
9379 if (inst.operands[i].immisreg)
9380 {
9381 constraint (is_pc, BAD_PC_ADDRESSING);
9382 constraint (is_t || is_d, _("cannot use register index with this instruction"));
9383 constraint (inst.operands[i].negative,
9384 _("Thumb does not support negative register indexing"));
9385 constraint (inst.operands[i].postind,
9386 _("Thumb does not support register post-indexing"));
9387 constraint (inst.operands[i].writeback,
9388 _("Thumb does not support register indexing with writeback"));
9389 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
9390 _("Thumb supports only LSL in shifted register indexing"));
9391
9392 inst.instruction |= inst.operands[i].imm;
9393 if (inst.operands[i].shifted)
9394 {
9395 constraint (inst.reloc.exp.X_op != O_constant,
9396 _("expression too complex"));
9397 constraint (inst.reloc.exp.X_add_number < 0
9398 || inst.reloc.exp.X_add_number > 3,
9399 _("shift out of range"));
9400 inst.instruction |= inst.reloc.exp.X_add_number << 4;
9401 }
9402 inst.reloc.type = BFD_RELOC_UNUSED;
9403 }
9404 else if (inst.operands[i].preind)
9405 {
9406 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
9407 constraint (is_t && inst.operands[i].writeback,
9408 _("cannot use writeback with this instruction"));
9409 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
9410 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
9411
9412 if (is_d)
9413 {
9414 inst.instruction |= 0x01000000;
9415 if (inst.operands[i].writeback)
9416 inst.instruction |= 0x00200000;
9417 }
9418 else
9419 {
9420 inst.instruction |= 0x00000c00;
9421 if (inst.operands[i].writeback)
9422 inst.instruction |= 0x00000100;
9423 }
9424 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9425 }
9426 else if (inst.operands[i].postind)
9427 {
9428 gas_assert (inst.operands[i].writeback);
9429 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
9430 constraint (is_t, _("cannot use post-indexing with this instruction"));
9431
9432 if (is_d)
9433 inst.instruction |= 0x00200000;
9434 else
9435 inst.instruction |= 0x00000900;
9436 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
9437 }
9438 else /* unindexed - only for coprocessor */
9439 inst.error = _("instruction does not accept unindexed addressing");
9440 }
9441
9442 /* Table of Thumb instructions which exist in both 16- and 32-bit
9443 encodings (the latter only in post-V6T2 cores). The index is the
9444 value used in the insns table below. When there is more than one
9445 possible 16-bit encoding for the instruction, this table always
9446 holds variant (1).
9447 Also contains several pseudo-instructions used during relaxation. */
9448 #define T16_32_TAB \
9449 X(_adc, 4140, eb400000), \
9450 X(_adcs, 4140, eb500000), \
9451 X(_add, 1c00, eb000000), \
9452 X(_adds, 1c00, eb100000), \
9453 X(_addi, 0000, f1000000), \
9454 X(_addis, 0000, f1100000), \
9455 X(_add_pc,000f, f20f0000), \
9456 X(_add_sp,000d, f10d0000), \
9457 X(_adr, 000f, f20f0000), \
9458 X(_and, 4000, ea000000), \
9459 X(_ands, 4000, ea100000), \
9460 X(_asr, 1000, fa40f000), \
9461 X(_asrs, 1000, fa50f000), \
9462 X(_b, e000, f000b000), \
9463 X(_bcond, d000, f0008000), \
9464 X(_bic, 4380, ea200000), \
9465 X(_bics, 4380, ea300000), \
9466 X(_cmn, 42c0, eb100f00), \
9467 X(_cmp, 2800, ebb00f00), \
9468 X(_cpsie, b660, f3af8400), \
9469 X(_cpsid, b670, f3af8600), \
9470 X(_cpy, 4600, ea4f0000), \
9471 X(_dec_sp,80dd, f1ad0d00), \
9472 X(_eor, 4040, ea800000), \
9473 X(_eors, 4040, ea900000), \
9474 X(_inc_sp,00dd, f10d0d00), \
9475 X(_ldmia, c800, e8900000), \
9476 X(_ldr, 6800, f8500000), \
9477 X(_ldrb, 7800, f8100000), \
9478 X(_ldrh, 8800, f8300000), \
9479 X(_ldrsb, 5600, f9100000), \
9480 X(_ldrsh, 5e00, f9300000), \
9481 X(_ldr_pc,4800, f85f0000), \
9482 X(_ldr_pc2,4800, f85f0000), \
9483 X(_ldr_sp,9800, f85d0000), \
9484 X(_lsl, 0000, fa00f000), \
9485 X(_lsls, 0000, fa10f000), \
9486 X(_lsr, 0800, fa20f000), \
9487 X(_lsrs, 0800, fa30f000), \
9488 X(_mov, 2000, ea4f0000), \
9489 X(_movs, 2000, ea5f0000), \
9490 X(_mul, 4340, fb00f000), \
9491 X(_muls, 4340, ffffffff), /* no 32b muls */ \
9492 X(_mvn, 43c0, ea6f0000), \
9493 X(_mvns, 43c0, ea7f0000), \
9494 X(_neg, 4240, f1c00000), /* rsb #0 */ \
9495 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
9496 X(_orr, 4300, ea400000), \
9497 X(_orrs, 4300, ea500000), \
9498 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
9499 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
9500 X(_rev, ba00, fa90f080), \
9501 X(_rev16, ba40, fa90f090), \
9502 X(_revsh, bac0, fa90f0b0), \
9503 X(_ror, 41c0, fa60f000), \
9504 X(_rors, 41c0, fa70f000), \
9505 X(_sbc, 4180, eb600000), \
9506 X(_sbcs, 4180, eb700000), \
9507 X(_stmia, c000, e8800000), \
9508 X(_str, 6000, f8400000), \
9509 X(_strb, 7000, f8000000), \
9510 X(_strh, 8000, f8200000), \
9511 X(_str_sp,9000, f84d0000), \
9512 X(_sub, 1e00, eba00000), \
9513 X(_subs, 1e00, ebb00000), \
9514 X(_subi, 8000, f1a00000), \
9515 X(_subis, 8000, f1b00000), \
9516 X(_sxtb, b240, fa4ff080), \
9517 X(_sxth, b200, fa0ff080), \
9518 X(_tst, 4200, ea100f00), \
9519 X(_uxtb, b2c0, fa5ff080), \
9520 X(_uxth, b280, fa1ff080), \
9521 X(_nop, bf00, f3af8000), \
9522 X(_yield, bf10, f3af8001), \
9523 X(_wfe, bf20, f3af8002), \
9524 X(_wfi, bf30, f3af8003), \
9525 X(_sev, bf40, f3af8004),
9526
9527 /* To catch errors in encoding functions, the codes are all offset by
9528 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
9529 as 16-bit instructions. */
9530 #define X(a,b,c) T_MNEM##a
9531 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
9532 #undef X
9533
9534 #define X(a,b,c) 0x##b
9535 static const unsigned short thumb_op16[] = { T16_32_TAB };
9536 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
9537 #undef X
9538
9539 #define X(a,b,c) 0x##c
9540 static const unsigned int thumb_op32[] = { T16_32_TAB };
9541 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9542 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
9543 #undef X
9544 #undef T16_32_TAB
9545
9546 /* Thumb instruction encoders, in alphabetical order. */
9547
9548 /* ADDW or SUBW. */
9549
9550 static void
9551 do_t_add_sub_w (void)
9552 {
9553 int Rd, Rn;
9554
9555 Rd = inst.operands[0].reg;
9556 Rn = inst.operands[1].reg;
9557
9558 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9559 is the SP-{plus,minus}-immediate form of the instruction. */
9560 if (Rn == REG_SP)
9561 constraint (Rd == REG_PC, BAD_PC);
9562 else
9563 reject_bad_reg (Rd);
9564
9565 inst.instruction |= (Rn << 16) | (Rd << 8);
9566 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9567 }
9568
9569 /* Parse an add or subtract instruction. We get here with inst.instruction
9570 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9571
9572 static void
9573 do_t_add_sub (void)
9574 {
9575 int Rd, Rs, Rn;
9576
9577 Rd = inst.operands[0].reg;
9578 Rs = (inst.operands[1].present
9579 ? inst.operands[1].reg /* Rd, Rs, foo */
9580 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9581
9582 if (Rd == REG_PC)
9583 set_it_insn_type_last ();
9584
9585 if (unified_syntax)
9586 {
9587 bfd_boolean flags;
9588 bfd_boolean narrow;
9589 int opcode;
9590
9591 flags = (inst.instruction == T_MNEM_adds
9592 || inst.instruction == T_MNEM_subs);
9593 if (flags)
9594 narrow = !in_it_block ();
9595 else
9596 narrow = in_it_block ();
9597 if (!inst.operands[2].isreg)
9598 {
9599 int add;
9600
9601 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9602
9603 add = (inst.instruction == T_MNEM_add
9604 || inst.instruction == T_MNEM_adds);
9605 opcode = 0;
9606 if (inst.size_req != 4)
9607 {
9608 /* Attempt to use a narrow opcode, with relaxation if
9609 appropriate. */
9610 if (Rd == REG_SP && Rs == REG_SP && !flags)
9611 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9612 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9613 opcode = T_MNEM_add_sp;
9614 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9615 opcode = T_MNEM_add_pc;
9616 else if (Rd <= 7 && Rs <= 7 && narrow)
9617 {
9618 if (flags)
9619 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9620 else
9621 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9622 }
9623 if (opcode)
9624 {
9625 inst.instruction = THUMB_OP16(opcode);
9626 inst.instruction |= (Rd << 4) | Rs;
9627 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9628 if (inst.size_req != 2)
9629 inst.relax = opcode;
9630 }
9631 else
9632 constraint (inst.size_req == 2, BAD_HIREG);
9633 }
9634 if (inst.size_req == 4
9635 || (inst.size_req != 2 && !opcode))
9636 {
9637 if (Rd == REG_PC)
9638 {
9639 constraint (add, BAD_PC);
9640 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9641 _("only SUBS PC, LR, #const allowed"));
9642 constraint (inst.reloc.exp.X_op != O_constant,
9643 _("expression too complex"));
9644 constraint (inst.reloc.exp.X_add_number < 0
9645 || inst.reloc.exp.X_add_number > 0xff,
9646 _("immediate value out of range"));
9647 inst.instruction = T2_SUBS_PC_LR
9648 | inst.reloc.exp.X_add_number;
9649 inst.reloc.type = BFD_RELOC_UNUSED;
9650 return;
9651 }
9652 else if (Rs == REG_PC)
9653 {
9654 /* Always use addw/subw. */
9655 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9656 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9657 }
9658 else
9659 {
9660 inst.instruction = THUMB_OP32 (inst.instruction);
9661 inst.instruction = (inst.instruction & 0xe1ffffff)
9662 | 0x10000000;
9663 if (flags)
9664 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9665 else
9666 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9667 }
9668 inst.instruction |= Rd << 8;
9669 inst.instruction |= Rs << 16;
9670 }
9671 }
9672 else
9673 {
9674 unsigned int value = inst.reloc.exp.X_add_number;
9675 unsigned int shift = inst.operands[2].shift_kind;
9676
9677 Rn = inst.operands[2].reg;
9678 /* See if we can do this with a 16-bit instruction. */
9679 if (!inst.operands[2].shifted && inst.size_req != 4)
9680 {
9681 if (Rd > 7 || Rs > 7 || Rn > 7)
9682 narrow = FALSE;
9683
9684 if (narrow)
9685 {
9686 inst.instruction = ((inst.instruction == T_MNEM_adds
9687 || inst.instruction == T_MNEM_add)
9688 ? T_OPCODE_ADD_R3
9689 : T_OPCODE_SUB_R3);
9690 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9691 return;
9692 }
9693
9694 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9695 {
9696 /* Thumb-1 cores (except v6-M) require at least one high
9697 register in a narrow non flag setting add. */
9698 if (Rd > 7 || Rn > 7
9699 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9700 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9701 {
9702 if (Rd == Rn)
9703 {
9704 Rn = Rs;
9705 Rs = Rd;
9706 }
9707 inst.instruction = T_OPCODE_ADD_HI;
9708 inst.instruction |= (Rd & 8) << 4;
9709 inst.instruction |= (Rd & 7);
9710 inst.instruction |= Rn << 3;
9711 return;
9712 }
9713 }
9714 }
9715
9716 constraint (Rd == REG_PC, BAD_PC);
9717 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9718 constraint (Rs == REG_PC, BAD_PC);
9719 reject_bad_reg (Rn);
9720
9721 /* If we get here, it can't be done in 16 bits. */
9722 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9723 _("shift must be constant"));
9724 inst.instruction = THUMB_OP32 (inst.instruction);
9725 inst.instruction |= Rd << 8;
9726 inst.instruction |= Rs << 16;
9727 constraint (Rd == REG_SP && Rs == REG_SP && value > 3,
9728 _("shift value over 3 not allowed in thumb mode"));
9729 constraint (Rd == REG_SP && Rs == REG_SP && shift != SHIFT_LSL,
9730 _("only LSL shift allowed in thumb mode"));
9731 encode_thumb32_shifted_operand (2);
9732 }
9733 }
9734 else
9735 {
9736 constraint (inst.instruction == T_MNEM_adds
9737 || inst.instruction == T_MNEM_subs,
9738 BAD_THUMB32);
9739
9740 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9741 {
9742 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9743 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9744 BAD_HIREG);
9745
9746 inst.instruction = (inst.instruction == T_MNEM_add
9747 ? 0x0000 : 0x8000);
9748 inst.instruction |= (Rd << 4) | Rs;
9749 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9750 return;
9751 }
9752
9753 Rn = inst.operands[2].reg;
9754 constraint (inst.operands[2].shifted, _("unshifted register required"));
9755
9756 /* We now have Rd, Rs, and Rn set to registers. */
9757 if (Rd > 7 || Rs > 7 || Rn > 7)
9758 {
9759 /* Can't do this for SUB. */
9760 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9761 inst.instruction = T_OPCODE_ADD_HI;
9762 inst.instruction |= (Rd & 8) << 4;
9763 inst.instruction |= (Rd & 7);
9764 if (Rs == Rd)
9765 inst.instruction |= Rn << 3;
9766 else if (Rn == Rd)
9767 inst.instruction |= Rs << 3;
9768 else
9769 constraint (1, _("dest must overlap one source register"));
9770 }
9771 else
9772 {
9773 inst.instruction = (inst.instruction == T_MNEM_add
9774 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9775 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9776 }
9777 }
9778 }
9779
9780 static void
9781 do_t_adr (void)
9782 {
9783 unsigned Rd;
9784
9785 Rd = inst.operands[0].reg;
9786 reject_bad_reg (Rd);
9787
9788 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9789 {
9790 /* Defer to section relaxation. */
9791 inst.relax = inst.instruction;
9792 inst.instruction = THUMB_OP16 (inst.instruction);
9793 inst.instruction |= Rd << 4;
9794 }
9795 else if (unified_syntax && inst.size_req != 2)
9796 {
9797 /* Generate a 32-bit opcode. */
9798 inst.instruction = THUMB_OP32 (inst.instruction);
9799 inst.instruction |= Rd << 8;
9800 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9801 inst.reloc.pc_rel = 1;
9802 }
9803 else
9804 {
9805 /* Generate a 16-bit opcode. */
9806 inst.instruction = THUMB_OP16 (inst.instruction);
9807 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9808 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9809 inst.reloc.pc_rel = 1;
9810
9811 inst.instruction |= Rd << 4;
9812 }
9813 }
9814
9815 /* Arithmetic instructions for which there is just one 16-bit
9816 instruction encoding, and it allows only two low registers.
9817 For maximal compatibility with ARM syntax, we allow three register
9818 operands even when Thumb-32 instructions are not available, as long
9819 as the first two are identical. For instance, both "sbc r0,r1" and
9820 "sbc r0,r0,r1" are allowed. */
9821 static void
9822 do_t_arit3 (void)
9823 {
9824 int Rd, Rs, Rn;
9825
9826 Rd = inst.operands[0].reg;
9827 Rs = (inst.operands[1].present
9828 ? inst.operands[1].reg /* Rd, Rs, foo */
9829 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9830 Rn = inst.operands[2].reg;
9831
9832 reject_bad_reg (Rd);
9833 reject_bad_reg (Rs);
9834 if (inst.operands[2].isreg)
9835 reject_bad_reg (Rn);
9836
9837 if (unified_syntax)
9838 {
9839 if (!inst.operands[2].isreg)
9840 {
9841 /* For an immediate, we always generate a 32-bit opcode;
9842 section relaxation will shrink it later if possible. */
9843 inst.instruction = THUMB_OP32 (inst.instruction);
9844 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9845 inst.instruction |= Rd << 8;
9846 inst.instruction |= Rs << 16;
9847 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9848 }
9849 else
9850 {
9851 bfd_boolean narrow;
9852
9853 /* See if we can do this with a 16-bit instruction. */
9854 if (THUMB_SETS_FLAGS (inst.instruction))
9855 narrow = !in_it_block ();
9856 else
9857 narrow = in_it_block ();
9858
9859 if (Rd > 7 || Rn > 7 || Rs > 7)
9860 narrow = FALSE;
9861 if (inst.operands[2].shifted)
9862 narrow = FALSE;
9863 if (inst.size_req == 4)
9864 narrow = FALSE;
9865
9866 if (narrow
9867 && Rd == Rs)
9868 {
9869 inst.instruction = THUMB_OP16 (inst.instruction);
9870 inst.instruction |= Rd;
9871 inst.instruction |= Rn << 3;
9872 return;
9873 }
9874
9875 /* If we get here, it can't be done in 16 bits. */
9876 constraint (inst.operands[2].shifted
9877 && inst.operands[2].immisreg,
9878 _("shift must be constant"));
9879 inst.instruction = THUMB_OP32 (inst.instruction);
9880 inst.instruction |= Rd << 8;
9881 inst.instruction |= Rs << 16;
9882 encode_thumb32_shifted_operand (2);
9883 }
9884 }
9885 else
9886 {
9887 /* On its face this is a lie - the instruction does set the
9888 flags. However, the only supported mnemonic in this mode
9889 says it doesn't. */
9890 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9891
9892 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9893 _("unshifted register required"));
9894 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9895 constraint (Rd != Rs,
9896 _("dest and source1 must be the same register"));
9897
9898 inst.instruction = THUMB_OP16 (inst.instruction);
9899 inst.instruction |= Rd;
9900 inst.instruction |= Rn << 3;
9901 }
9902 }
9903
9904 /* Similarly, but for instructions where the arithmetic operation is
9905 commutative, so we can allow either of them to be different from
9906 the destination operand in a 16-bit instruction. For instance, all
9907 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9908 accepted. */
9909 static void
9910 do_t_arit3c (void)
9911 {
9912 int Rd, Rs, Rn;
9913
9914 Rd = inst.operands[0].reg;
9915 Rs = (inst.operands[1].present
9916 ? inst.operands[1].reg /* Rd, Rs, foo */
9917 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9918 Rn = inst.operands[2].reg;
9919
9920 reject_bad_reg (Rd);
9921 reject_bad_reg (Rs);
9922 if (inst.operands[2].isreg)
9923 reject_bad_reg (Rn);
9924
9925 if (unified_syntax)
9926 {
9927 if (!inst.operands[2].isreg)
9928 {
9929 /* For an immediate, we always generate a 32-bit opcode;
9930 section relaxation will shrink it later if possible. */
9931 inst.instruction = THUMB_OP32 (inst.instruction);
9932 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9933 inst.instruction |= Rd << 8;
9934 inst.instruction |= Rs << 16;
9935 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9936 }
9937 else
9938 {
9939 bfd_boolean narrow;
9940
9941 /* See if we can do this with a 16-bit instruction. */
9942 if (THUMB_SETS_FLAGS (inst.instruction))
9943 narrow = !in_it_block ();
9944 else
9945 narrow = in_it_block ();
9946
9947 if (Rd > 7 || Rn > 7 || Rs > 7)
9948 narrow = FALSE;
9949 if (inst.operands[2].shifted)
9950 narrow = FALSE;
9951 if (inst.size_req == 4)
9952 narrow = FALSE;
9953
9954 if (narrow)
9955 {
9956 if (Rd == Rs)
9957 {
9958 inst.instruction = THUMB_OP16 (inst.instruction);
9959 inst.instruction |= Rd;
9960 inst.instruction |= Rn << 3;
9961 return;
9962 }
9963 if (Rd == Rn)
9964 {
9965 inst.instruction = THUMB_OP16 (inst.instruction);
9966 inst.instruction |= Rd;
9967 inst.instruction |= Rs << 3;
9968 return;
9969 }
9970 }
9971
9972 /* If we get here, it can't be done in 16 bits. */
9973 constraint (inst.operands[2].shifted
9974 && inst.operands[2].immisreg,
9975 _("shift must be constant"));
9976 inst.instruction = THUMB_OP32 (inst.instruction);
9977 inst.instruction |= Rd << 8;
9978 inst.instruction |= Rs << 16;
9979 encode_thumb32_shifted_operand (2);
9980 }
9981 }
9982 else
9983 {
9984 /* On its face this is a lie - the instruction does set the
9985 flags. However, the only supported mnemonic in this mode
9986 says it doesn't. */
9987 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9988
9989 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9990 _("unshifted register required"));
9991 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9992
9993 inst.instruction = THUMB_OP16 (inst.instruction);
9994 inst.instruction |= Rd;
9995
9996 if (Rd == Rs)
9997 inst.instruction |= Rn << 3;
9998 else if (Rd == Rn)
9999 inst.instruction |= Rs << 3;
10000 else
10001 constraint (1, _("dest must overlap one source register"));
10002 }
10003 }
10004
10005 static void
10006 do_t_barrier (void)
10007 {
10008 if (inst.operands[0].present)
10009 {
10010 constraint ((inst.instruction & 0xf0) != 0x40
10011 && inst.operands[0].imm > 0xf
10012 && inst.operands[0].imm < 0x0,
10013 _("bad barrier type"));
10014 inst.instruction |= inst.operands[0].imm;
10015 }
10016 else
10017 inst.instruction |= 0xf;
10018 }
10019
10020 static void
10021 do_t_bfc (void)
10022 {
10023 unsigned Rd;
10024 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
10025 constraint (msb > 32, _("bit-field extends past end of register"));
10026 /* The instruction encoding stores the LSB and MSB,
10027 not the LSB and width. */
10028 Rd = inst.operands[0].reg;
10029 reject_bad_reg (Rd);
10030 inst.instruction |= Rd << 8;
10031 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
10032 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
10033 inst.instruction |= msb - 1;
10034 }
10035
10036 static void
10037 do_t_bfi (void)
10038 {
10039 int Rd, Rn;
10040 unsigned int msb;
10041
10042 Rd = inst.operands[0].reg;
10043 reject_bad_reg (Rd);
10044
10045 /* #0 in second position is alternative syntax for bfc, which is
10046 the same instruction but with REG_PC in the Rm field. */
10047 if (!inst.operands[1].isreg)
10048 Rn = REG_PC;
10049 else
10050 {
10051 Rn = inst.operands[1].reg;
10052 reject_bad_reg (Rn);
10053 }
10054
10055 msb = inst.operands[2].imm + inst.operands[3].imm;
10056 constraint (msb > 32, _("bit-field extends past end of register"));
10057 /* The instruction encoding stores the LSB and MSB,
10058 not the LSB and width. */
10059 inst.instruction |= Rd << 8;
10060 inst.instruction |= Rn << 16;
10061 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10062 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10063 inst.instruction |= msb - 1;
10064 }
10065
10066 static void
10067 do_t_bfx (void)
10068 {
10069 unsigned Rd, Rn;
10070
10071 Rd = inst.operands[0].reg;
10072 Rn = inst.operands[1].reg;
10073
10074 reject_bad_reg (Rd);
10075 reject_bad_reg (Rn);
10076
10077 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
10078 _("bit-field extends past end of register"));
10079 inst.instruction |= Rd << 8;
10080 inst.instruction |= Rn << 16;
10081 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
10082 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
10083 inst.instruction |= inst.operands[3].imm - 1;
10084 }
10085
10086 /* ARM V5 Thumb BLX (argument parse)
10087 BLX <target_addr> which is BLX(1)
10088 BLX <Rm> which is BLX(2)
10089 Unfortunately, there are two different opcodes for this mnemonic.
10090 So, the insns[].value is not used, and the code here zaps values
10091 into inst.instruction.
10092
10093 ??? How to take advantage of the additional two bits of displacement
10094 available in Thumb32 mode? Need new relocation? */
10095
10096 static void
10097 do_t_blx (void)
10098 {
10099 set_it_insn_type_last ();
10100
10101 if (inst.operands[0].isreg)
10102 {
10103 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
10104 /* We have a register, so this is BLX(2). */
10105 inst.instruction |= inst.operands[0].reg << 3;
10106 }
10107 else
10108 {
10109 /* No register. This must be BLX(1). */
10110 inst.instruction = 0xf000e800;
10111 encode_branch (BFD_RELOC_THUMB_PCREL_BLX);
10112 }
10113 }
10114
10115 static void
10116 do_t_branch (void)
10117 {
10118 int opcode;
10119 int cond;
10120 int reloc;
10121
10122 cond = inst.cond;
10123 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
10124
10125 if (in_it_block ())
10126 {
10127 /* Conditional branches inside IT blocks are encoded as unconditional
10128 branches. */
10129 cond = COND_ALWAYS;
10130 }
10131 else
10132 cond = inst.cond;
10133
10134 if (cond != COND_ALWAYS)
10135 opcode = T_MNEM_bcond;
10136 else
10137 opcode = inst.instruction;
10138
10139 if (unified_syntax
10140 && (inst.size_req == 4
10141 || (inst.size_req != 2
10142 && (inst.operands[0].hasreloc
10143 || inst.reloc.exp.X_op == O_constant))))
10144 {
10145 inst.instruction = THUMB_OP32(opcode);
10146 if (cond == COND_ALWAYS)
10147 reloc = BFD_RELOC_THUMB_PCREL_BRANCH25;
10148 else
10149 {
10150 gas_assert (cond != 0xF);
10151 inst.instruction |= cond << 22;
10152 reloc = BFD_RELOC_THUMB_PCREL_BRANCH20;
10153 }
10154 }
10155 else
10156 {
10157 inst.instruction = THUMB_OP16(opcode);
10158 if (cond == COND_ALWAYS)
10159 reloc = BFD_RELOC_THUMB_PCREL_BRANCH12;
10160 else
10161 {
10162 inst.instruction |= cond << 8;
10163 reloc = BFD_RELOC_THUMB_PCREL_BRANCH9;
10164 }
10165 /* Allow section relaxation. */
10166 if (unified_syntax && inst.size_req != 2)
10167 inst.relax = opcode;
10168 }
10169 inst.reloc.type = reloc;
10170 inst.reloc.pc_rel = 1;
10171 }
10172
10173 static void
10174 do_t_bkpt (void)
10175 {
10176 constraint (inst.cond != COND_ALWAYS,
10177 _("instruction is always unconditional"));
10178 if (inst.operands[0].present)
10179 {
10180 constraint (inst.operands[0].imm > 255,
10181 _("immediate value out of range"));
10182 inst.instruction |= inst.operands[0].imm;
10183 set_it_insn_type (NEUTRAL_IT_INSN);
10184 }
10185 }
10186
10187 static void
10188 do_t_branch23 (void)
10189 {
10190 set_it_insn_type_last ();
10191 encode_branch (BFD_RELOC_THUMB_PCREL_BRANCH23);
10192
10193 /* md_apply_fix blows up with 'bl foo(PLT)' where foo is defined in
10194 this file. We used to simply ignore the PLT reloc type here --
10195 the branch encoding is now needed to deal with TLSCALL relocs.
10196 So if we see a PLT reloc now, put it back to how it used to be to
10197 keep the preexisting behaviour. */
10198 if (inst.reloc.type == BFD_RELOC_ARM_PLT32)
10199 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
10200
10201 #if defined(OBJ_COFF)
10202 /* If the destination of the branch is a defined symbol which does not have
10203 the THUMB_FUNC attribute, then we must be calling a function which has
10204 the (interfacearm) attribute. We look for the Thumb entry point to that
10205 function and change the branch to refer to that function instead. */
10206 if ( inst.reloc.exp.X_op == O_symbol
10207 && inst.reloc.exp.X_add_symbol != NULL
10208 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
10209 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
10210 inst.reloc.exp.X_add_symbol =
10211 find_real_start (inst.reloc.exp.X_add_symbol);
10212 #endif
10213 }
10214
10215 static void
10216 do_t_bx (void)
10217 {
10218 set_it_insn_type_last ();
10219 inst.instruction |= inst.operands[0].reg << 3;
10220 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
10221 should cause the alignment to be checked once it is known. This is
10222 because BX PC only works if the instruction is word aligned. */
10223 }
10224
10225 static void
10226 do_t_bxj (void)
10227 {
10228 int Rm;
10229
10230 set_it_insn_type_last ();
10231 Rm = inst.operands[0].reg;
10232 reject_bad_reg (Rm);
10233 inst.instruction |= Rm << 16;
10234 }
10235
10236 static void
10237 do_t_clz (void)
10238 {
10239 unsigned Rd;
10240 unsigned Rm;
10241
10242 Rd = inst.operands[0].reg;
10243 Rm = inst.operands[1].reg;
10244
10245 reject_bad_reg (Rd);
10246 reject_bad_reg (Rm);
10247
10248 inst.instruction |= Rd << 8;
10249 inst.instruction |= Rm << 16;
10250 inst.instruction |= Rm;
10251 }
10252
10253 static void
10254 do_t_cps (void)
10255 {
10256 set_it_insn_type (OUTSIDE_IT_INSN);
10257 inst.instruction |= inst.operands[0].imm;
10258 }
10259
10260 static void
10261 do_t_cpsi (void)
10262 {
10263 set_it_insn_type (OUTSIDE_IT_INSN);
10264 if (unified_syntax
10265 && (inst.operands[1].present || inst.size_req == 4)
10266 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
10267 {
10268 unsigned int imod = (inst.instruction & 0x0030) >> 4;
10269 inst.instruction = 0xf3af8000;
10270 inst.instruction |= imod << 9;
10271 inst.instruction |= inst.operands[0].imm << 5;
10272 if (inst.operands[1].present)
10273 inst.instruction |= 0x100 | inst.operands[1].imm;
10274 }
10275 else
10276 {
10277 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
10278 && (inst.operands[0].imm & 4),
10279 _("selected processor does not support 'A' form "
10280 "of this instruction"));
10281 constraint (inst.operands[1].present || inst.size_req == 4,
10282 _("Thumb does not support the 2-argument "
10283 "form of this instruction"));
10284 inst.instruction |= inst.operands[0].imm;
10285 }
10286 }
10287
10288 /* THUMB CPY instruction (argument parse). */
10289
10290 static void
10291 do_t_cpy (void)
10292 {
10293 if (inst.size_req == 4)
10294 {
10295 inst.instruction = THUMB_OP32 (T_MNEM_mov);
10296 inst.instruction |= inst.operands[0].reg << 8;
10297 inst.instruction |= inst.operands[1].reg;
10298 }
10299 else
10300 {
10301 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
10302 inst.instruction |= (inst.operands[0].reg & 0x7);
10303 inst.instruction |= inst.operands[1].reg << 3;
10304 }
10305 }
10306
10307 static void
10308 do_t_cbz (void)
10309 {
10310 set_it_insn_type (OUTSIDE_IT_INSN);
10311 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10312 inst.instruction |= inst.operands[0].reg;
10313 inst.reloc.pc_rel = 1;
10314 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
10315 }
10316
10317 static void
10318 do_t_dbg (void)
10319 {
10320 inst.instruction |= inst.operands[0].imm;
10321 }
10322
10323 static void
10324 do_t_div (void)
10325 {
10326 unsigned Rd, Rn, Rm;
10327
10328 Rd = inst.operands[0].reg;
10329 Rn = (inst.operands[1].present
10330 ? inst.operands[1].reg : Rd);
10331 Rm = inst.operands[2].reg;
10332
10333 reject_bad_reg (Rd);
10334 reject_bad_reg (Rn);
10335 reject_bad_reg (Rm);
10336
10337 inst.instruction |= Rd << 8;
10338 inst.instruction |= Rn << 16;
10339 inst.instruction |= Rm;
10340 }
10341
10342 static void
10343 do_t_hint (void)
10344 {
10345 if (unified_syntax && inst.size_req == 4)
10346 inst.instruction = THUMB_OP32 (inst.instruction);
10347 else
10348 inst.instruction = THUMB_OP16 (inst.instruction);
10349 }
10350
10351 static void
10352 do_t_it (void)
10353 {
10354 unsigned int cond = inst.operands[0].imm;
10355
10356 set_it_insn_type (IT_INSN);
10357 now_it.mask = (inst.instruction & 0xf) | 0x10;
10358 now_it.cc = cond;
10359
10360 /* If the condition is a negative condition, invert the mask. */
10361 if ((cond & 0x1) == 0x0)
10362 {
10363 unsigned int mask = inst.instruction & 0x000f;
10364
10365 if ((mask & 0x7) == 0)
10366 /* no conversion needed */;
10367 else if ((mask & 0x3) == 0)
10368 mask ^= 0x8;
10369 else if ((mask & 0x1) == 0)
10370 mask ^= 0xC;
10371 else
10372 mask ^= 0xE;
10373
10374 inst.instruction &= 0xfff0;
10375 inst.instruction |= mask;
10376 }
10377
10378 inst.instruction |= cond << 4;
10379 }
10380
10381 /* Helper function used for both push/pop and ldm/stm. */
10382 static void
10383 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
10384 {
10385 bfd_boolean load;
10386
10387 load = (inst.instruction & (1 << 20)) != 0;
10388
10389 if (mask & (1 << 13))
10390 inst.error = _("SP not allowed in register list");
10391
10392 if ((mask & (1 << base)) != 0
10393 && writeback)
10394 inst.error = _("having the base register in the register list when "
10395 "using write back is UNPREDICTABLE");
10396
10397 if (load)
10398 {
10399 if (mask & (1 << 15))
10400 {
10401 if (mask & (1 << 14))
10402 inst.error = _("LR and PC should not both be in register list");
10403 else
10404 set_it_insn_type_last ();
10405 }
10406 }
10407 else
10408 {
10409 if (mask & (1 << 15))
10410 inst.error = _("PC not allowed in register list");
10411 }
10412
10413 if ((mask & (mask - 1)) == 0)
10414 {
10415 /* Single register transfers implemented as str/ldr. */
10416 if (writeback)
10417 {
10418 if (inst.instruction & (1 << 23))
10419 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
10420 else
10421 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
10422 }
10423 else
10424 {
10425 if (inst.instruction & (1 << 23))
10426 inst.instruction = 0x00800000; /* ia -> [base] */
10427 else
10428 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
10429 }
10430
10431 inst.instruction |= 0xf8400000;
10432 if (load)
10433 inst.instruction |= 0x00100000;
10434
10435 mask = ffs (mask) - 1;
10436 mask <<= 12;
10437 }
10438 else if (writeback)
10439 inst.instruction |= WRITE_BACK;
10440
10441 inst.instruction |= mask;
10442 inst.instruction |= base << 16;
10443 }
10444
10445 static void
10446 do_t_ldmstm (void)
10447 {
10448 /* This really doesn't seem worth it. */
10449 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10450 _("expression too complex"));
10451 constraint (inst.operands[1].writeback,
10452 _("Thumb load/store multiple does not support {reglist}^"));
10453
10454 if (unified_syntax)
10455 {
10456 bfd_boolean narrow;
10457 unsigned mask;
10458
10459 narrow = FALSE;
10460 /* See if we can use a 16-bit instruction. */
10461 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
10462 && inst.size_req != 4
10463 && !(inst.operands[1].imm & ~0xff))
10464 {
10465 mask = 1 << inst.operands[0].reg;
10466
10467 if (inst.operands[0].reg <= 7)
10468 {
10469 if (inst.instruction == T_MNEM_stmia
10470 ? inst.operands[0].writeback
10471 : (inst.operands[0].writeback
10472 == !(inst.operands[1].imm & mask)))
10473 {
10474 if (inst.instruction == T_MNEM_stmia
10475 && (inst.operands[1].imm & mask)
10476 && (inst.operands[1].imm & (mask - 1)))
10477 as_warn (_("value stored for r%d is UNKNOWN"),
10478 inst.operands[0].reg);
10479
10480 inst.instruction = THUMB_OP16 (inst.instruction);
10481 inst.instruction |= inst.operands[0].reg << 8;
10482 inst.instruction |= inst.operands[1].imm;
10483 narrow = TRUE;
10484 }
10485 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10486 {
10487 /* This means 1 register in reg list one of 3 situations:
10488 1. Instruction is stmia, but without writeback.
10489 2. lmdia without writeback, but with Rn not in
10490 reglist.
10491 3. ldmia with writeback, but with Rn in reglist.
10492 Case 3 is UNPREDICTABLE behaviour, so we handle
10493 case 1 and 2 which can be converted into a 16-bit
10494 str or ldr. The SP cases are handled below. */
10495 unsigned long opcode;
10496 /* First, record an error for Case 3. */
10497 if (inst.operands[1].imm & mask
10498 && inst.operands[0].writeback)
10499 inst.error =
10500 _("having the base register in the register list when "
10501 "using write back is UNPREDICTABLE");
10502
10503 opcode = (inst.instruction == T_MNEM_stmia ? T_MNEM_str
10504 : T_MNEM_ldr);
10505 inst.instruction = THUMB_OP16 (opcode);
10506 inst.instruction |= inst.operands[0].reg << 3;
10507 inst.instruction |= (ffs (inst.operands[1].imm)-1);
10508 narrow = TRUE;
10509 }
10510 }
10511 else if (inst.operands[0] .reg == REG_SP)
10512 {
10513 if (inst.operands[0].writeback)
10514 {
10515 inst.instruction =
10516 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10517 ? T_MNEM_push : T_MNEM_pop);
10518 inst.instruction |= inst.operands[1].imm;
10519 narrow = TRUE;
10520 }
10521 else if ((inst.operands[1].imm & (inst.operands[1].imm-1)) == 0)
10522 {
10523 inst.instruction =
10524 THUMB_OP16 (inst.instruction == T_MNEM_stmia
10525 ? T_MNEM_str_sp : T_MNEM_ldr_sp);
10526 inst.instruction |= ((ffs (inst.operands[1].imm)-1) << 8);
10527 narrow = TRUE;
10528 }
10529 }
10530 }
10531
10532 if (!narrow)
10533 {
10534 if (inst.instruction < 0xffff)
10535 inst.instruction = THUMB_OP32 (inst.instruction);
10536
10537 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
10538 inst.operands[0].writeback);
10539 }
10540 }
10541 else
10542 {
10543 constraint (inst.operands[0].reg > 7
10544 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
10545 constraint (inst.instruction != T_MNEM_ldmia
10546 && inst.instruction != T_MNEM_stmia,
10547 _("Thumb-2 instruction only valid in unified syntax"));
10548 if (inst.instruction == T_MNEM_stmia)
10549 {
10550 if (!inst.operands[0].writeback)
10551 as_warn (_("this instruction will write back the base register"));
10552 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
10553 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
10554 as_warn (_("value stored for r%d is UNKNOWN"),
10555 inst.operands[0].reg);
10556 }
10557 else
10558 {
10559 if (!inst.operands[0].writeback
10560 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
10561 as_warn (_("this instruction will write back the base register"));
10562 else if (inst.operands[0].writeback
10563 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
10564 as_warn (_("this instruction will not write back the base register"));
10565 }
10566
10567 inst.instruction = THUMB_OP16 (inst.instruction);
10568 inst.instruction |= inst.operands[0].reg << 8;
10569 inst.instruction |= inst.operands[1].imm;
10570 }
10571 }
10572
10573 static void
10574 do_t_ldrex (void)
10575 {
10576 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
10577 || inst.operands[1].postind || inst.operands[1].writeback
10578 || inst.operands[1].immisreg || inst.operands[1].shifted
10579 || inst.operands[1].negative,
10580 BAD_ADDR_MODE);
10581
10582 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
10583
10584 inst.instruction |= inst.operands[0].reg << 12;
10585 inst.instruction |= inst.operands[1].reg << 16;
10586 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10587 }
10588
10589 static void
10590 do_t_ldrexd (void)
10591 {
10592 if (!inst.operands[1].present)
10593 {
10594 constraint (inst.operands[0].reg == REG_LR,
10595 _("r14 not allowed as first register "
10596 "when second register is omitted"));
10597 inst.operands[1].reg = inst.operands[0].reg + 1;
10598 }
10599 constraint (inst.operands[0].reg == inst.operands[1].reg,
10600 BAD_OVERLAP);
10601
10602 inst.instruction |= inst.operands[0].reg << 12;
10603 inst.instruction |= inst.operands[1].reg << 8;
10604 inst.instruction |= inst.operands[2].reg << 16;
10605 }
10606
10607 static void
10608 do_t_ldst (void)
10609 {
10610 unsigned long opcode;
10611 int Rn;
10612
10613 if (inst.operands[0].isreg
10614 && !inst.operands[0].preind
10615 && inst.operands[0].reg == REG_PC)
10616 set_it_insn_type_last ();
10617
10618 opcode = inst.instruction;
10619 if (unified_syntax)
10620 {
10621 if (!inst.operands[1].isreg)
10622 {
10623 if (opcode <= 0xffff)
10624 inst.instruction = THUMB_OP32 (opcode);
10625 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10626 return;
10627 }
10628 if (inst.operands[1].isreg
10629 && !inst.operands[1].writeback
10630 && !inst.operands[1].shifted && !inst.operands[1].postind
10631 && !inst.operands[1].negative && inst.operands[0].reg <= 7
10632 && opcode <= 0xffff
10633 && inst.size_req != 4)
10634 {
10635 /* Insn may have a 16-bit form. */
10636 Rn = inst.operands[1].reg;
10637 if (inst.operands[1].immisreg)
10638 {
10639 inst.instruction = THUMB_OP16 (opcode);
10640 /* [Rn, Rik] */
10641 if (Rn <= 7 && inst.operands[1].imm <= 7)
10642 goto op16;
10643 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10644 reject_bad_reg (inst.operands[1].imm);
10645 }
10646 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10647 && opcode != T_MNEM_ldrsb)
10648 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10649 || (Rn == REG_SP && opcode == T_MNEM_str))
10650 {
10651 /* [Rn, #const] */
10652 if (Rn > 7)
10653 {
10654 if (Rn == REG_PC)
10655 {
10656 if (inst.reloc.pc_rel)
10657 opcode = T_MNEM_ldr_pc2;
10658 else
10659 opcode = T_MNEM_ldr_pc;
10660 }
10661 else
10662 {
10663 if (opcode == T_MNEM_ldr)
10664 opcode = T_MNEM_ldr_sp;
10665 else
10666 opcode = T_MNEM_str_sp;
10667 }
10668 inst.instruction = inst.operands[0].reg << 8;
10669 }
10670 else
10671 {
10672 inst.instruction = inst.operands[0].reg;
10673 inst.instruction |= inst.operands[1].reg << 3;
10674 }
10675 inst.instruction |= THUMB_OP16 (opcode);
10676 if (inst.size_req == 2)
10677 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10678 else
10679 inst.relax = opcode;
10680 return;
10681 }
10682 }
10683 /* Definitely a 32-bit variant. */
10684
10685 /* Warning for Erratum 752419. */
10686 if (opcode == T_MNEM_ldr
10687 && inst.operands[0].reg == REG_SP
10688 && inst.operands[1].writeback == 1
10689 && !inst.operands[1].immisreg)
10690 {
10691 if (no_cpu_selected ()
10692 || (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7)
10693 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a)
10694 && !ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7r)))
10695 as_warn (_("This instruction may be unpredictable "
10696 "if executed on M-profile cores "
10697 "with interrupts enabled."));
10698 }
10699
10700 /* Do some validations regarding addressing modes. */
10701 if (inst.operands[1].immisreg)
10702 reject_bad_reg (inst.operands[1].imm);
10703
10704 constraint (inst.operands[1].writeback == 1
10705 && inst.operands[0].reg == inst.operands[1].reg,
10706 BAD_OVERLAP);
10707
10708 inst.instruction = THUMB_OP32 (opcode);
10709 inst.instruction |= inst.operands[0].reg << 12;
10710 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10711 check_ldr_r15_aligned ();
10712 return;
10713 }
10714
10715 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10716
10717 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10718 {
10719 /* Only [Rn,Rm] is acceptable. */
10720 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10721 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10722 || inst.operands[1].postind || inst.operands[1].shifted
10723 || inst.operands[1].negative,
10724 _("Thumb does not support this addressing mode"));
10725 inst.instruction = THUMB_OP16 (inst.instruction);
10726 goto op16;
10727 }
10728
10729 inst.instruction = THUMB_OP16 (inst.instruction);
10730 if (!inst.operands[1].isreg)
10731 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10732 return;
10733
10734 constraint (!inst.operands[1].preind
10735 || inst.operands[1].shifted
10736 || inst.operands[1].writeback,
10737 _("Thumb does not support this addressing mode"));
10738 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10739 {
10740 constraint (inst.instruction & 0x0600,
10741 _("byte or halfword not valid for base register"));
10742 constraint (inst.operands[1].reg == REG_PC
10743 && !(inst.instruction & THUMB_LOAD_BIT),
10744 _("r15 based store not allowed"));
10745 constraint (inst.operands[1].immisreg,
10746 _("invalid base register for register offset"));
10747
10748 if (inst.operands[1].reg == REG_PC)
10749 inst.instruction = T_OPCODE_LDR_PC;
10750 else if (inst.instruction & THUMB_LOAD_BIT)
10751 inst.instruction = T_OPCODE_LDR_SP;
10752 else
10753 inst.instruction = T_OPCODE_STR_SP;
10754
10755 inst.instruction |= inst.operands[0].reg << 8;
10756 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10757 return;
10758 }
10759
10760 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10761 if (!inst.operands[1].immisreg)
10762 {
10763 /* Immediate offset. */
10764 inst.instruction |= inst.operands[0].reg;
10765 inst.instruction |= inst.operands[1].reg << 3;
10766 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10767 return;
10768 }
10769
10770 /* Register offset. */
10771 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10772 constraint (inst.operands[1].negative,
10773 _("Thumb does not support this addressing mode"));
10774
10775 op16:
10776 switch (inst.instruction)
10777 {
10778 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10779 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10780 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10781 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10782 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10783 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10784 case 0x5600 /* ldrsb */:
10785 case 0x5e00 /* ldrsh */: break;
10786 default: abort ();
10787 }
10788
10789 inst.instruction |= inst.operands[0].reg;
10790 inst.instruction |= inst.operands[1].reg << 3;
10791 inst.instruction |= inst.operands[1].imm << 6;
10792 }
10793
10794 static void
10795 do_t_ldstd (void)
10796 {
10797 if (!inst.operands[1].present)
10798 {
10799 inst.operands[1].reg = inst.operands[0].reg + 1;
10800 constraint (inst.operands[0].reg == REG_LR,
10801 _("r14 not allowed here"));
10802 constraint (inst.operands[0].reg == REG_R12,
10803 _("r12 not allowed here"));
10804 }
10805
10806 if (inst.operands[2].writeback
10807 && (inst.operands[0].reg == inst.operands[2].reg
10808 || inst.operands[1].reg == inst.operands[2].reg))
10809 as_warn (_("base register written back, and overlaps "
10810 "one of transfer registers"));
10811
10812 inst.instruction |= inst.operands[0].reg << 12;
10813 inst.instruction |= inst.operands[1].reg << 8;
10814 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10815 }
10816
10817 static void
10818 do_t_ldstt (void)
10819 {
10820 inst.instruction |= inst.operands[0].reg << 12;
10821 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10822 }
10823
10824 static void
10825 do_t_mla (void)
10826 {
10827 unsigned Rd, Rn, Rm, Ra;
10828
10829 Rd = inst.operands[0].reg;
10830 Rn = inst.operands[1].reg;
10831 Rm = inst.operands[2].reg;
10832 Ra = inst.operands[3].reg;
10833
10834 reject_bad_reg (Rd);
10835 reject_bad_reg (Rn);
10836 reject_bad_reg (Rm);
10837 reject_bad_reg (Ra);
10838
10839 inst.instruction |= Rd << 8;
10840 inst.instruction |= Rn << 16;
10841 inst.instruction |= Rm;
10842 inst.instruction |= Ra << 12;
10843 }
10844
10845 static void
10846 do_t_mlal (void)
10847 {
10848 unsigned RdLo, RdHi, Rn, Rm;
10849
10850 RdLo = inst.operands[0].reg;
10851 RdHi = inst.operands[1].reg;
10852 Rn = inst.operands[2].reg;
10853 Rm = inst.operands[3].reg;
10854
10855 reject_bad_reg (RdLo);
10856 reject_bad_reg (RdHi);
10857 reject_bad_reg (Rn);
10858 reject_bad_reg (Rm);
10859
10860 inst.instruction |= RdLo << 12;
10861 inst.instruction |= RdHi << 8;
10862 inst.instruction |= Rn << 16;
10863 inst.instruction |= Rm;
10864 }
10865
10866 static void
10867 do_t_mov_cmp (void)
10868 {
10869 unsigned Rn, Rm;
10870
10871 Rn = inst.operands[0].reg;
10872 Rm = inst.operands[1].reg;
10873
10874 if (Rn == REG_PC)
10875 set_it_insn_type_last ();
10876
10877 if (unified_syntax)
10878 {
10879 int r0off = (inst.instruction == T_MNEM_mov
10880 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10881 unsigned long opcode;
10882 bfd_boolean narrow;
10883 bfd_boolean low_regs;
10884
10885 low_regs = (Rn <= 7 && Rm <= 7);
10886 opcode = inst.instruction;
10887 if (in_it_block ())
10888 narrow = opcode != T_MNEM_movs;
10889 else
10890 narrow = opcode != T_MNEM_movs || low_regs;
10891 if (inst.size_req == 4
10892 || inst.operands[1].shifted)
10893 narrow = FALSE;
10894
10895 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10896 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10897 && !inst.operands[1].shifted
10898 && Rn == REG_PC
10899 && Rm == REG_LR)
10900 {
10901 inst.instruction = T2_SUBS_PC_LR;
10902 return;
10903 }
10904
10905 if (opcode == T_MNEM_cmp)
10906 {
10907 constraint (Rn == REG_PC, BAD_PC);
10908 if (narrow)
10909 {
10910 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10911 but valid. */
10912 warn_deprecated_sp (Rm);
10913 /* R15 was documented as a valid choice for Rm in ARMv6,
10914 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10915 tools reject R15, so we do too. */
10916 constraint (Rm == REG_PC, BAD_PC);
10917 }
10918 else
10919 reject_bad_reg (Rm);
10920 }
10921 else if (opcode == T_MNEM_mov
10922 || opcode == T_MNEM_movs)
10923 {
10924 if (inst.operands[1].isreg)
10925 {
10926 if (opcode == T_MNEM_movs)
10927 {
10928 reject_bad_reg (Rn);
10929 reject_bad_reg (Rm);
10930 }
10931 else if (narrow)
10932 {
10933 /* This is mov.n. */
10934 if ((Rn == REG_SP || Rn == REG_PC)
10935 && (Rm == REG_SP || Rm == REG_PC))
10936 {
10937 as_warn (_("Use of r%u as a source register is "
10938 "deprecated when r%u is the destination "
10939 "register."), Rm, Rn);
10940 }
10941 }
10942 else
10943 {
10944 /* This is mov.w. */
10945 constraint (Rn == REG_PC, BAD_PC);
10946 constraint (Rm == REG_PC, BAD_PC);
10947 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10948 }
10949 }
10950 else
10951 reject_bad_reg (Rn);
10952 }
10953
10954 if (!inst.operands[1].isreg)
10955 {
10956 /* Immediate operand. */
10957 if (!in_it_block () && opcode == T_MNEM_mov)
10958 narrow = 0;
10959 if (low_regs && narrow)
10960 {
10961 inst.instruction = THUMB_OP16 (opcode);
10962 inst.instruction |= Rn << 8;
10963 if (inst.size_req == 2)
10964 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10965 else
10966 inst.relax = opcode;
10967 }
10968 else
10969 {
10970 inst.instruction = THUMB_OP32 (inst.instruction);
10971 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10972 inst.instruction |= Rn << r0off;
10973 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10974 }
10975 }
10976 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10977 && (inst.instruction == T_MNEM_mov
10978 || inst.instruction == T_MNEM_movs))
10979 {
10980 /* Register shifts are encoded as separate shift instructions. */
10981 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10982
10983 if (in_it_block ())
10984 narrow = !flags;
10985 else
10986 narrow = flags;
10987
10988 if (inst.size_req == 4)
10989 narrow = FALSE;
10990
10991 if (!low_regs || inst.operands[1].imm > 7)
10992 narrow = FALSE;
10993
10994 if (Rn != Rm)
10995 narrow = FALSE;
10996
10997 switch (inst.operands[1].shift_kind)
10998 {
10999 case SHIFT_LSL:
11000 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
11001 break;
11002 case SHIFT_ASR:
11003 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
11004 break;
11005 case SHIFT_LSR:
11006 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
11007 break;
11008 case SHIFT_ROR:
11009 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
11010 break;
11011 default:
11012 abort ();
11013 }
11014
11015 inst.instruction = opcode;
11016 if (narrow)
11017 {
11018 inst.instruction |= Rn;
11019 inst.instruction |= inst.operands[1].imm << 3;
11020 }
11021 else
11022 {
11023 if (flags)
11024 inst.instruction |= CONDS_BIT;
11025
11026 inst.instruction |= Rn << 8;
11027 inst.instruction |= Rm << 16;
11028 inst.instruction |= inst.operands[1].imm;
11029 }
11030 }
11031 else if (!narrow)
11032 {
11033 /* Some mov with immediate shift have narrow variants.
11034 Register shifts are handled above. */
11035 if (low_regs && inst.operands[1].shifted
11036 && (inst.instruction == T_MNEM_mov
11037 || inst.instruction == T_MNEM_movs))
11038 {
11039 if (in_it_block ())
11040 narrow = (inst.instruction == T_MNEM_mov);
11041 else
11042 narrow = (inst.instruction == T_MNEM_movs);
11043 }
11044
11045 if (narrow)
11046 {
11047 switch (inst.operands[1].shift_kind)
11048 {
11049 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11050 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11051 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11052 default: narrow = FALSE; break;
11053 }
11054 }
11055
11056 if (narrow)
11057 {
11058 inst.instruction |= Rn;
11059 inst.instruction |= Rm << 3;
11060 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11061 }
11062 else
11063 {
11064 inst.instruction = THUMB_OP32 (inst.instruction);
11065 inst.instruction |= Rn << r0off;
11066 encode_thumb32_shifted_operand (1);
11067 }
11068 }
11069 else
11070 switch (inst.instruction)
11071 {
11072 case T_MNEM_mov:
11073 /* In v4t or v5t a move of two lowregs produces unpredictable
11074 results. Don't allow this. */
11075 if (low_regs)
11076 {
11077 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6),
11078 "MOV Rd, Rs with two low registers is not "
11079 "permitted on this architecture");
11080 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
11081 arm_ext_v6);
11082 }
11083
11084 inst.instruction = T_OPCODE_MOV_HR;
11085 inst.instruction |= (Rn & 0x8) << 4;
11086 inst.instruction |= (Rn & 0x7);
11087 inst.instruction |= Rm << 3;
11088 break;
11089
11090 case T_MNEM_movs:
11091 /* We know we have low registers at this point.
11092 Generate LSLS Rd, Rs, #0. */
11093 inst.instruction = T_OPCODE_LSL_I;
11094 inst.instruction |= Rn;
11095 inst.instruction |= Rm << 3;
11096 break;
11097
11098 case T_MNEM_cmp:
11099 if (low_regs)
11100 {
11101 inst.instruction = T_OPCODE_CMP_LR;
11102 inst.instruction |= Rn;
11103 inst.instruction |= Rm << 3;
11104 }
11105 else
11106 {
11107 inst.instruction = T_OPCODE_CMP_HR;
11108 inst.instruction |= (Rn & 0x8) << 4;
11109 inst.instruction |= (Rn & 0x7);
11110 inst.instruction |= Rm << 3;
11111 }
11112 break;
11113 }
11114 return;
11115 }
11116
11117 inst.instruction = THUMB_OP16 (inst.instruction);
11118
11119 /* PR 10443: Do not silently ignore shifted operands. */
11120 constraint (inst.operands[1].shifted,
11121 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
11122
11123 if (inst.operands[1].isreg)
11124 {
11125 if (Rn < 8 && Rm < 8)
11126 {
11127 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
11128 since a MOV instruction produces unpredictable results. */
11129 if (inst.instruction == T_OPCODE_MOV_I8)
11130 inst.instruction = T_OPCODE_ADD_I3;
11131 else
11132 inst.instruction = T_OPCODE_CMP_LR;
11133
11134 inst.instruction |= Rn;
11135 inst.instruction |= Rm << 3;
11136 }
11137 else
11138 {
11139 if (inst.instruction == T_OPCODE_MOV_I8)
11140 inst.instruction = T_OPCODE_MOV_HR;
11141 else
11142 inst.instruction = T_OPCODE_CMP_HR;
11143 do_t_cpy ();
11144 }
11145 }
11146 else
11147 {
11148 constraint (Rn > 7,
11149 _("only lo regs allowed with immediate"));
11150 inst.instruction |= Rn << 8;
11151 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
11152 }
11153 }
11154
11155 static void
11156 do_t_mov16 (void)
11157 {
11158 unsigned Rd;
11159 bfd_vma imm;
11160 bfd_boolean top;
11161
11162 top = (inst.instruction & 0x00800000) != 0;
11163 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
11164 {
11165 constraint (top, _(":lower16: not allowed this instruction"));
11166 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
11167 }
11168 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
11169 {
11170 constraint (!top, _(":upper16: not allowed this instruction"));
11171 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
11172 }
11173
11174 Rd = inst.operands[0].reg;
11175 reject_bad_reg (Rd);
11176
11177 inst.instruction |= Rd << 8;
11178 if (inst.reloc.type == BFD_RELOC_UNUSED)
11179 {
11180 imm = inst.reloc.exp.X_add_number;
11181 inst.instruction |= (imm & 0xf000) << 4;
11182 inst.instruction |= (imm & 0x0800) << 15;
11183 inst.instruction |= (imm & 0x0700) << 4;
11184 inst.instruction |= (imm & 0x00ff);
11185 }
11186 }
11187
11188 static void
11189 do_t_mvn_tst (void)
11190 {
11191 unsigned Rn, Rm;
11192
11193 Rn = inst.operands[0].reg;
11194 Rm = inst.operands[1].reg;
11195
11196 if (inst.instruction == T_MNEM_cmp
11197 || inst.instruction == T_MNEM_cmn)
11198 constraint (Rn == REG_PC, BAD_PC);
11199 else
11200 reject_bad_reg (Rn);
11201 reject_bad_reg (Rm);
11202
11203 if (unified_syntax)
11204 {
11205 int r0off = (inst.instruction == T_MNEM_mvn
11206 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
11207 bfd_boolean narrow;
11208
11209 if (inst.size_req == 4
11210 || inst.instruction > 0xffff
11211 || inst.operands[1].shifted
11212 || Rn > 7 || Rm > 7)
11213 narrow = FALSE;
11214 else if (inst.instruction == T_MNEM_cmn)
11215 narrow = TRUE;
11216 else if (THUMB_SETS_FLAGS (inst.instruction))
11217 narrow = !in_it_block ();
11218 else
11219 narrow = in_it_block ();
11220
11221 if (!inst.operands[1].isreg)
11222 {
11223 /* For an immediate, we always generate a 32-bit opcode;
11224 section relaxation will shrink it later if possible. */
11225 if (inst.instruction < 0xffff)
11226 inst.instruction = THUMB_OP32 (inst.instruction);
11227 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11228 inst.instruction |= Rn << r0off;
11229 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11230 }
11231 else
11232 {
11233 /* See if we can do this with a 16-bit instruction. */
11234 if (narrow)
11235 {
11236 inst.instruction = THUMB_OP16 (inst.instruction);
11237 inst.instruction |= Rn;
11238 inst.instruction |= Rm << 3;
11239 }
11240 else
11241 {
11242 constraint (inst.operands[1].shifted
11243 && inst.operands[1].immisreg,
11244 _("shift must be constant"));
11245 if (inst.instruction < 0xffff)
11246 inst.instruction = THUMB_OP32 (inst.instruction);
11247 inst.instruction |= Rn << r0off;
11248 encode_thumb32_shifted_operand (1);
11249 }
11250 }
11251 }
11252 else
11253 {
11254 constraint (inst.instruction > 0xffff
11255 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
11256 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
11257 _("unshifted register required"));
11258 constraint (Rn > 7 || Rm > 7,
11259 BAD_HIREG);
11260
11261 inst.instruction = THUMB_OP16 (inst.instruction);
11262 inst.instruction |= Rn;
11263 inst.instruction |= Rm << 3;
11264 }
11265 }
11266
11267 static void
11268 do_t_mrs (void)
11269 {
11270 unsigned Rd;
11271
11272 if (do_vfp_nsyn_mrs () == SUCCESS)
11273 return;
11274
11275 Rd = inst.operands[0].reg;
11276 reject_bad_reg (Rd);
11277 inst.instruction |= Rd << 8;
11278
11279 if (inst.operands[1].isreg)
11280 {
11281 unsigned br = inst.operands[1].reg;
11282 if (((br & 0x200) == 0) && ((br & 0xf000) != 0xf000))
11283 as_bad (_("bad register for mrs"));
11284
11285 inst.instruction |= br & (0xf << 16);
11286 inst.instruction |= (br & 0x300) >> 4;
11287 inst.instruction |= (br & SPSR_BIT) >> 2;
11288 }
11289 else
11290 {
11291 int flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11292
11293 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11294 {
11295 /* PR gas/12698: The constraint is only applied for m_profile.
11296 If the user has specified -march=all, we want to ignore it as
11297 we are building for any CPU type, including non-m variants. */
11298 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11299 constraint ((flags != 0) && m_profile, _("selected processor does "
11300 "not support requested special purpose register"));
11301 }
11302 else
11303 /* mrs only accepts APSR/CPSR/SPSR/CPSR_all/SPSR_all (for non-M profile
11304 devices). */
11305 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
11306 _("'APSR', 'CPSR' or 'SPSR' expected"));
11307
11308 inst.instruction |= (flags & SPSR_BIT) >> 2;
11309 inst.instruction |= inst.operands[1].imm & 0xff;
11310 inst.instruction |= 0xf0000;
11311 }
11312 }
11313
11314 static void
11315 do_t_msr (void)
11316 {
11317 int flags;
11318 unsigned Rn;
11319
11320 if (do_vfp_nsyn_msr () == SUCCESS)
11321 return;
11322
11323 constraint (!inst.operands[1].isreg,
11324 _("Thumb encoding does not support an immediate here"));
11325
11326 if (inst.operands[0].isreg)
11327 flags = (int)(inst.operands[0].reg);
11328 else
11329 flags = inst.operands[0].imm;
11330
11331 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_m))
11332 {
11333 int bits = inst.operands[0].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
11334
11335 /* PR gas/12698: The constraint is only applied for m_profile.
11336 If the user has specified -march=all, we want to ignore it as
11337 we are building for any CPU type, including non-m variants. */
11338 bfd_boolean m_profile = selected_cpu.core != arm_arch_any.core;
11339 constraint (((ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11340 && (bits & ~(PSR_s | PSR_f)) != 0)
11341 || (!ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6_dsp)
11342 && bits != PSR_f)) && m_profile,
11343 _("selected processor does not support requested special "
11344 "purpose register"));
11345 }
11346 else
11347 constraint ((flags & 0xff) != 0, _("selected processor does not support "
11348 "requested special purpose register"));
11349
11350 Rn = inst.operands[1].reg;
11351 reject_bad_reg (Rn);
11352
11353 inst.instruction |= (flags & SPSR_BIT) >> 2;
11354 inst.instruction |= (flags & 0xf0000) >> 8;
11355 inst.instruction |= (flags & 0x300) >> 4;
11356 inst.instruction |= (flags & 0xff);
11357 inst.instruction |= Rn << 16;
11358 }
11359
11360 static void
11361 do_t_mul (void)
11362 {
11363 bfd_boolean narrow;
11364 unsigned Rd, Rn, Rm;
11365
11366 if (!inst.operands[2].present)
11367 inst.operands[2].reg = inst.operands[0].reg;
11368
11369 Rd = inst.operands[0].reg;
11370 Rn = inst.operands[1].reg;
11371 Rm = inst.operands[2].reg;
11372
11373 if (unified_syntax)
11374 {
11375 if (inst.size_req == 4
11376 || (Rd != Rn
11377 && Rd != Rm)
11378 || Rn > 7
11379 || Rm > 7)
11380 narrow = FALSE;
11381 else if (inst.instruction == T_MNEM_muls)
11382 narrow = !in_it_block ();
11383 else
11384 narrow = in_it_block ();
11385 }
11386 else
11387 {
11388 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
11389 constraint (Rn > 7 || Rm > 7,
11390 BAD_HIREG);
11391 narrow = TRUE;
11392 }
11393
11394 if (narrow)
11395 {
11396 /* 16-bit MULS/Conditional MUL. */
11397 inst.instruction = THUMB_OP16 (inst.instruction);
11398 inst.instruction |= Rd;
11399
11400 if (Rd == Rn)
11401 inst.instruction |= Rm << 3;
11402 else if (Rd == Rm)
11403 inst.instruction |= Rn << 3;
11404 else
11405 constraint (1, _("dest must overlap one source register"));
11406 }
11407 else
11408 {
11409 constraint (inst.instruction != T_MNEM_mul,
11410 _("Thumb-2 MUL must not set flags"));
11411 /* 32-bit MUL. */
11412 inst.instruction = THUMB_OP32 (inst.instruction);
11413 inst.instruction |= Rd << 8;
11414 inst.instruction |= Rn << 16;
11415 inst.instruction |= Rm << 0;
11416
11417 reject_bad_reg (Rd);
11418 reject_bad_reg (Rn);
11419 reject_bad_reg (Rm);
11420 }
11421 }
11422
11423 static void
11424 do_t_mull (void)
11425 {
11426 unsigned RdLo, RdHi, Rn, Rm;
11427
11428 RdLo = inst.operands[0].reg;
11429 RdHi = inst.operands[1].reg;
11430 Rn = inst.operands[2].reg;
11431 Rm = inst.operands[3].reg;
11432
11433 reject_bad_reg (RdLo);
11434 reject_bad_reg (RdHi);
11435 reject_bad_reg (Rn);
11436 reject_bad_reg (Rm);
11437
11438 inst.instruction |= RdLo << 12;
11439 inst.instruction |= RdHi << 8;
11440 inst.instruction |= Rn << 16;
11441 inst.instruction |= Rm;
11442
11443 if (RdLo == RdHi)
11444 as_tsktsk (_("rdhi and rdlo must be different"));
11445 }
11446
11447 static void
11448 do_t_nop (void)
11449 {
11450 set_it_insn_type (NEUTRAL_IT_INSN);
11451
11452 if (unified_syntax)
11453 {
11454 if (inst.size_req == 4 || inst.operands[0].imm > 15)
11455 {
11456 inst.instruction = THUMB_OP32 (inst.instruction);
11457 inst.instruction |= inst.operands[0].imm;
11458 }
11459 else
11460 {
11461 /* PR9722: Check for Thumb2 availability before
11462 generating a thumb2 nop instruction. */
11463 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
11464 {
11465 inst.instruction = THUMB_OP16 (inst.instruction);
11466 inst.instruction |= inst.operands[0].imm << 4;
11467 }
11468 else
11469 inst.instruction = 0x46c0;
11470 }
11471 }
11472 else
11473 {
11474 constraint (inst.operands[0].present,
11475 _("Thumb does not support NOP with hints"));
11476 inst.instruction = 0x46c0;
11477 }
11478 }
11479
11480 static void
11481 do_t_neg (void)
11482 {
11483 if (unified_syntax)
11484 {
11485 bfd_boolean narrow;
11486
11487 if (THUMB_SETS_FLAGS (inst.instruction))
11488 narrow = !in_it_block ();
11489 else
11490 narrow = in_it_block ();
11491 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11492 narrow = FALSE;
11493 if (inst.size_req == 4)
11494 narrow = FALSE;
11495
11496 if (!narrow)
11497 {
11498 inst.instruction = THUMB_OP32 (inst.instruction);
11499 inst.instruction |= inst.operands[0].reg << 8;
11500 inst.instruction |= inst.operands[1].reg << 16;
11501 }
11502 else
11503 {
11504 inst.instruction = THUMB_OP16 (inst.instruction);
11505 inst.instruction |= inst.operands[0].reg;
11506 inst.instruction |= inst.operands[1].reg << 3;
11507 }
11508 }
11509 else
11510 {
11511 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
11512 BAD_HIREG);
11513 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11514
11515 inst.instruction = THUMB_OP16 (inst.instruction);
11516 inst.instruction |= inst.operands[0].reg;
11517 inst.instruction |= inst.operands[1].reg << 3;
11518 }
11519 }
11520
11521 static void
11522 do_t_orn (void)
11523 {
11524 unsigned Rd, Rn;
11525
11526 Rd = inst.operands[0].reg;
11527 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
11528
11529 reject_bad_reg (Rd);
11530 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
11531 reject_bad_reg (Rn);
11532
11533 inst.instruction |= Rd << 8;
11534 inst.instruction |= Rn << 16;
11535
11536 if (!inst.operands[2].isreg)
11537 {
11538 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11539 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11540 }
11541 else
11542 {
11543 unsigned Rm;
11544
11545 Rm = inst.operands[2].reg;
11546 reject_bad_reg (Rm);
11547
11548 constraint (inst.operands[2].shifted
11549 && inst.operands[2].immisreg,
11550 _("shift must be constant"));
11551 encode_thumb32_shifted_operand (2);
11552 }
11553 }
11554
11555 static void
11556 do_t_pkhbt (void)
11557 {
11558 unsigned Rd, Rn, Rm;
11559
11560 Rd = inst.operands[0].reg;
11561 Rn = inst.operands[1].reg;
11562 Rm = inst.operands[2].reg;
11563
11564 reject_bad_reg (Rd);
11565 reject_bad_reg (Rn);
11566 reject_bad_reg (Rm);
11567
11568 inst.instruction |= Rd << 8;
11569 inst.instruction |= Rn << 16;
11570 inst.instruction |= Rm;
11571 if (inst.operands[3].present)
11572 {
11573 unsigned int val = inst.reloc.exp.X_add_number;
11574 constraint (inst.reloc.exp.X_op != O_constant,
11575 _("expression too complex"));
11576 inst.instruction |= (val & 0x1c) << 10;
11577 inst.instruction |= (val & 0x03) << 6;
11578 }
11579 }
11580
11581 static void
11582 do_t_pkhtb (void)
11583 {
11584 if (!inst.operands[3].present)
11585 {
11586 unsigned Rtmp;
11587
11588 inst.instruction &= ~0x00000020;
11589
11590 /* PR 10168. Swap the Rm and Rn registers. */
11591 Rtmp = inst.operands[1].reg;
11592 inst.operands[1].reg = inst.operands[2].reg;
11593 inst.operands[2].reg = Rtmp;
11594 }
11595 do_t_pkhbt ();
11596 }
11597
11598 static void
11599 do_t_pld (void)
11600 {
11601 if (inst.operands[0].immisreg)
11602 reject_bad_reg (inst.operands[0].imm);
11603
11604 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
11605 }
11606
11607 static void
11608 do_t_push_pop (void)
11609 {
11610 unsigned mask;
11611
11612 constraint (inst.operands[0].writeback,
11613 _("push/pop do not support {reglist}^"));
11614 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
11615 _("expression too complex"));
11616
11617 mask = inst.operands[0].imm;
11618 if ((mask & ~0xff) == 0)
11619 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
11620 else if ((inst.instruction == T_MNEM_push
11621 && (mask & ~0xff) == 1 << REG_LR)
11622 || (inst.instruction == T_MNEM_pop
11623 && (mask & ~0xff) == 1 << REG_PC))
11624 {
11625 inst.instruction = THUMB_OP16 (inst.instruction);
11626 inst.instruction |= THUMB_PP_PC_LR;
11627 inst.instruction |= mask & 0xff;
11628 }
11629 else if (unified_syntax)
11630 {
11631 inst.instruction = THUMB_OP32 (inst.instruction);
11632 encode_thumb2_ldmstm (13, mask, TRUE);
11633 }
11634 else
11635 {
11636 inst.error = _("invalid register list to push/pop instruction");
11637 return;
11638 }
11639 }
11640
11641 static void
11642 do_t_rbit (void)
11643 {
11644 unsigned Rd, Rm;
11645
11646 Rd = inst.operands[0].reg;
11647 Rm = inst.operands[1].reg;
11648
11649 reject_bad_reg (Rd);
11650 reject_bad_reg (Rm);
11651
11652 inst.instruction |= Rd << 8;
11653 inst.instruction |= Rm << 16;
11654 inst.instruction |= Rm;
11655 }
11656
11657 static void
11658 do_t_rev (void)
11659 {
11660 unsigned Rd, Rm;
11661
11662 Rd = inst.operands[0].reg;
11663 Rm = inst.operands[1].reg;
11664
11665 reject_bad_reg (Rd);
11666 reject_bad_reg (Rm);
11667
11668 if (Rd <= 7 && Rm <= 7
11669 && inst.size_req != 4)
11670 {
11671 inst.instruction = THUMB_OP16 (inst.instruction);
11672 inst.instruction |= Rd;
11673 inst.instruction |= Rm << 3;
11674 }
11675 else if (unified_syntax)
11676 {
11677 inst.instruction = THUMB_OP32 (inst.instruction);
11678 inst.instruction |= Rd << 8;
11679 inst.instruction |= Rm << 16;
11680 inst.instruction |= Rm;
11681 }
11682 else
11683 inst.error = BAD_HIREG;
11684 }
11685
11686 static void
11687 do_t_rrx (void)
11688 {
11689 unsigned Rd, Rm;
11690
11691 Rd = inst.operands[0].reg;
11692 Rm = inst.operands[1].reg;
11693
11694 reject_bad_reg (Rd);
11695 reject_bad_reg (Rm);
11696
11697 inst.instruction |= Rd << 8;
11698 inst.instruction |= Rm;
11699 }
11700
11701 static void
11702 do_t_rsb (void)
11703 {
11704 unsigned Rd, Rs;
11705
11706 Rd = inst.operands[0].reg;
11707 Rs = (inst.operands[1].present
11708 ? inst.operands[1].reg /* Rd, Rs, foo */
11709 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11710
11711 reject_bad_reg (Rd);
11712 reject_bad_reg (Rs);
11713 if (inst.operands[2].isreg)
11714 reject_bad_reg (inst.operands[2].reg);
11715
11716 inst.instruction |= Rd << 8;
11717 inst.instruction |= Rs << 16;
11718 if (!inst.operands[2].isreg)
11719 {
11720 bfd_boolean narrow;
11721
11722 if ((inst.instruction & 0x00100000) != 0)
11723 narrow = !in_it_block ();
11724 else
11725 narrow = in_it_block ();
11726
11727 if (Rd > 7 || Rs > 7)
11728 narrow = FALSE;
11729
11730 if (inst.size_req == 4 || !unified_syntax)
11731 narrow = FALSE;
11732
11733 if (inst.reloc.exp.X_op != O_constant
11734 || inst.reloc.exp.X_add_number != 0)
11735 narrow = FALSE;
11736
11737 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11738 relaxation, but it doesn't seem worth the hassle. */
11739 if (narrow)
11740 {
11741 inst.reloc.type = BFD_RELOC_UNUSED;
11742 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11743 inst.instruction |= Rs << 3;
11744 inst.instruction |= Rd;
11745 }
11746 else
11747 {
11748 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11749 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11750 }
11751 }
11752 else
11753 encode_thumb32_shifted_operand (2);
11754 }
11755
11756 static void
11757 do_t_setend (void)
11758 {
11759 set_it_insn_type (OUTSIDE_IT_INSN);
11760 if (inst.operands[0].imm)
11761 inst.instruction |= 0x8;
11762 }
11763
11764 static void
11765 do_t_shift (void)
11766 {
11767 if (!inst.operands[1].present)
11768 inst.operands[1].reg = inst.operands[0].reg;
11769
11770 if (unified_syntax)
11771 {
11772 bfd_boolean narrow;
11773 int shift_kind;
11774
11775 switch (inst.instruction)
11776 {
11777 case T_MNEM_asr:
11778 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11779 case T_MNEM_lsl:
11780 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11781 case T_MNEM_lsr:
11782 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11783 case T_MNEM_ror:
11784 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11785 default: abort ();
11786 }
11787
11788 if (THUMB_SETS_FLAGS (inst.instruction))
11789 narrow = !in_it_block ();
11790 else
11791 narrow = in_it_block ();
11792 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11793 narrow = FALSE;
11794 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11795 narrow = FALSE;
11796 if (inst.operands[2].isreg
11797 && (inst.operands[1].reg != inst.operands[0].reg
11798 || inst.operands[2].reg > 7))
11799 narrow = FALSE;
11800 if (inst.size_req == 4)
11801 narrow = FALSE;
11802
11803 reject_bad_reg (inst.operands[0].reg);
11804 reject_bad_reg (inst.operands[1].reg);
11805
11806 if (!narrow)
11807 {
11808 if (inst.operands[2].isreg)
11809 {
11810 reject_bad_reg (inst.operands[2].reg);
11811 inst.instruction = THUMB_OP32 (inst.instruction);
11812 inst.instruction |= inst.operands[0].reg << 8;
11813 inst.instruction |= inst.operands[1].reg << 16;
11814 inst.instruction |= inst.operands[2].reg;
11815
11816 /* PR 12854: Error on extraneous shifts. */
11817 constraint (inst.operands[2].shifted,
11818 _("extraneous shift as part of operand to shift insn"));
11819 }
11820 else
11821 {
11822 inst.operands[1].shifted = 1;
11823 inst.operands[1].shift_kind = shift_kind;
11824 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11825 ? T_MNEM_movs : T_MNEM_mov);
11826 inst.instruction |= inst.operands[0].reg << 8;
11827 encode_thumb32_shifted_operand (1);
11828 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11829 inst.reloc.type = BFD_RELOC_UNUSED;
11830 }
11831 }
11832 else
11833 {
11834 if (inst.operands[2].isreg)
11835 {
11836 switch (shift_kind)
11837 {
11838 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11839 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11840 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11841 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11842 default: abort ();
11843 }
11844
11845 inst.instruction |= inst.operands[0].reg;
11846 inst.instruction |= inst.operands[2].reg << 3;
11847
11848 /* PR 12854: Error on extraneous shifts. */
11849 constraint (inst.operands[2].shifted,
11850 _("extraneous shift as part of operand to shift insn"));
11851 }
11852 else
11853 {
11854 switch (shift_kind)
11855 {
11856 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11857 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11858 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11859 default: abort ();
11860 }
11861 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11862 inst.instruction |= inst.operands[0].reg;
11863 inst.instruction |= inst.operands[1].reg << 3;
11864 }
11865 }
11866 }
11867 else
11868 {
11869 constraint (inst.operands[0].reg > 7
11870 || inst.operands[1].reg > 7, BAD_HIREG);
11871 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11872
11873 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11874 {
11875 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11876 constraint (inst.operands[0].reg != inst.operands[1].reg,
11877 _("source1 and dest must be same register"));
11878
11879 switch (inst.instruction)
11880 {
11881 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11882 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11883 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11884 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11885 default: abort ();
11886 }
11887
11888 inst.instruction |= inst.operands[0].reg;
11889 inst.instruction |= inst.operands[2].reg << 3;
11890
11891 /* PR 12854: Error on extraneous shifts. */
11892 constraint (inst.operands[2].shifted,
11893 _("extraneous shift as part of operand to shift insn"));
11894 }
11895 else
11896 {
11897 switch (inst.instruction)
11898 {
11899 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11900 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11901 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11902 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11903 default: abort ();
11904 }
11905 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11906 inst.instruction |= inst.operands[0].reg;
11907 inst.instruction |= inst.operands[1].reg << 3;
11908 }
11909 }
11910 }
11911
11912 static void
11913 do_t_simd (void)
11914 {
11915 unsigned Rd, Rn, Rm;
11916
11917 Rd = inst.operands[0].reg;
11918 Rn = inst.operands[1].reg;
11919 Rm = inst.operands[2].reg;
11920
11921 reject_bad_reg (Rd);
11922 reject_bad_reg (Rn);
11923 reject_bad_reg (Rm);
11924
11925 inst.instruction |= Rd << 8;
11926 inst.instruction |= Rn << 16;
11927 inst.instruction |= Rm;
11928 }
11929
11930 static void
11931 do_t_simd2 (void)
11932 {
11933 unsigned Rd, Rn, Rm;
11934
11935 Rd = inst.operands[0].reg;
11936 Rm = inst.operands[1].reg;
11937 Rn = inst.operands[2].reg;
11938
11939 reject_bad_reg (Rd);
11940 reject_bad_reg (Rn);
11941 reject_bad_reg (Rm);
11942
11943 inst.instruction |= Rd << 8;
11944 inst.instruction |= Rn << 16;
11945 inst.instruction |= Rm;
11946 }
11947
11948 static void
11949 do_t_smc (void)
11950 {
11951 unsigned int value = inst.reloc.exp.X_add_number;
11952 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7a),
11953 _("SMC is not permitted on this architecture"));
11954 constraint (inst.reloc.exp.X_op != O_constant,
11955 _("expression too complex"));
11956 inst.reloc.type = BFD_RELOC_UNUSED;
11957 inst.instruction |= (value & 0xf000) >> 12;
11958 inst.instruction |= (value & 0x0ff0);
11959 inst.instruction |= (value & 0x000f) << 16;
11960 }
11961
11962 static void
11963 do_t_hvc (void)
11964 {
11965 unsigned int value = inst.reloc.exp.X_add_number;
11966
11967 inst.reloc.type = BFD_RELOC_UNUSED;
11968 inst.instruction |= (value & 0x0fff);
11969 inst.instruction |= (value & 0xf000) << 4;
11970 }
11971
11972 static void
11973 do_t_ssat_usat (int bias)
11974 {
11975 unsigned Rd, Rn;
11976
11977 Rd = inst.operands[0].reg;
11978 Rn = inst.operands[2].reg;
11979
11980 reject_bad_reg (Rd);
11981 reject_bad_reg (Rn);
11982
11983 inst.instruction |= Rd << 8;
11984 inst.instruction |= inst.operands[1].imm - bias;
11985 inst.instruction |= Rn << 16;
11986
11987 if (inst.operands[3].present)
11988 {
11989 offsetT shift_amount = inst.reloc.exp.X_add_number;
11990
11991 inst.reloc.type = BFD_RELOC_UNUSED;
11992
11993 constraint (inst.reloc.exp.X_op != O_constant,
11994 _("expression too complex"));
11995
11996 if (shift_amount != 0)
11997 {
11998 constraint (shift_amount > 31,
11999 _("shift expression is too large"));
12000
12001 if (inst.operands[3].shift_kind == SHIFT_ASR)
12002 inst.instruction |= 0x00200000; /* sh bit. */
12003
12004 inst.instruction |= (shift_amount & 0x1c) << 10;
12005 inst.instruction |= (shift_amount & 0x03) << 6;
12006 }
12007 }
12008 }
12009
12010 static void
12011 do_t_ssat (void)
12012 {
12013 do_t_ssat_usat (1);
12014 }
12015
12016 static void
12017 do_t_ssat16 (void)
12018 {
12019 unsigned Rd, Rn;
12020
12021 Rd = inst.operands[0].reg;
12022 Rn = inst.operands[2].reg;
12023
12024 reject_bad_reg (Rd);
12025 reject_bad_reg (Rn);
12026
12027 inst.instruction |= Rd << 8;
12028 inst.instruction |= inst.operands[1].imm - 1;
12029 inst.instruction |= Rn << 16;
12030 }
12031
12032 static void
12033 do_t_strex (void)
12034 {
12035 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
12036 || inst.operands[2].postind || inst.operands[2].writeback
12037 || inst.operands[2].immisreg || inst.operands[2].shifted
12038 || inst.operands[2].negative,
12039 BAD_ADDR_MODE);
12040
12041 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
12042
12043 inst.instruction |= inst.operands[0].reg << 8;
12044 inst.instruction |= inst.operands[1].reg << 12;
12045 inst.instruction |= inst.operands[2].reg << 16;
12046 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
12047 }
12048
12049 static void
12050 do_t_strexd (void)
12051 {
12052 if (!inst.operands[2].present)
12053 inst.operands[2].reg = inst.operands[1].reg + 1;
12054
12055 constraint (inst.operands[0].reg == inst.operands[1].reg
12056 || inst.operands[0].reg == inst.operands[2].reg
12057 || inst.operands[0].reg == inst.operands[3].reg,
12058 BAD_OVERLAP);
12059
12060 inst.instruction |= inst.operands[0].reg;
12061 inst.instruction |= inst.operands[1].reg << 12;
12062 inst.instruction |= inst.operands[2].reg << 8;
12063 inst.instruction |= inst.operands[3].reg << 16;
12064 }
12065
12066 static void
12067 do_t_sxtah (void)
12068 {
12069 unsigned Rd, Rn, Rm;
12070
12071 Rd = inst.operands[0].reg;
12072 Rn = inst.operands[1].reg;
12073 Rm = inst.operands[2].reg;
12074
12075 reject_bad_reg (Rd);
12076 reject_bad_reg (Rn);
12077 reject_bad_reg (Rm);
12078
12079 inst.instruction |= Rd << 8;
12080 inst.instruction |= Rn << 16;
12081 inst.instruction |= Rm;
12082 inst.instruction |= inst.operands[3].imm << 4;
12083 }
12084
12085 static void
12086 do_t_sxth (void)
12087 {
12088 unsigned Rd, Rm;
12089
12090 Rd = inst.operands[0].reg;
12091 Rm = inst.operands[1].reg;
12092
12093 reject_bad_reg (Rd);
12094 reject_bad_reg (Rm);
12095
12096 if (inst.instruction <= 0xffff
12097 && inst.size_req != 4
12098 && Rd <= 7 && Rm <= 7
12099 && (!inst.operands[2].present || inst.operands[2].imm == 0))
12100 {
12101 inst.instruction = THUMB_OP16 (inst.instruction);
12102 inst.instruction |= Rd;
12103 inst.instruction |= Rm << 3;
12104 }
12105 else if (unified_syntax)
12106 {
12107 if (inst.instruction <= 0xffff)
12108 inst.instruction = THUMB_OP32 (inst.instruction);
12109 inst.instruction |= Rd << 8;
12110 inst.instruction |= Rm;
12111 inst.instruction |= inst.operands[2].imm << 4;
12112 }
12113 else
12114 {
12115 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
12116 _("Thumb encoding does not support rotation"));
12117 constraint (1, BAD_HIREG);
12118 }
12119 }
12120
12121 static void
12122 do_t_swi (void)
12123 {
12124 /* We have to do the following check manually as ARM_EXT_OS only applies
12125 to ARM_EXT_V6M. */
12126 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6m))
12127 {
12128 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_os)
12129 /* This only applies to the v6m howver, not later architectures. */
12130 && ! ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7))
12131 as_bad (_("SVC is not permitted on this architecture"));
12132 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used, arm_ext_os);
12133 }
12134
12135 inst.reloc.type = BFD_RELOC_ARM_SWI;
12136 }
12137
12138 static void
12139 do_t_tb (void)
12140 {
12141 unsigned Rn, Rm;
12142 int half;
12143
12144 half = (inst.instruction & 0x10) != 0;
12145 set_it_insn_type_last ();
12146 constraint (inst.operands[0].immisreg,
12147 _("instruction requires register index"));
12148
12149 Rn = inst.operands[0].reg;
12150 Rm = inst.operands[0].imm;
12151
12152 constraint (Rn == REG_SP, BAD_SP);
12153 reject_bad_reg (Rm);
12154
12155 constraint (!half && inst.operands[0].shifted,
12156 _("instruction does not allow shifted index"));
12157 inst.instruction |= (Rn << 16) | Rm;
12158 }
12159
12160 static void
12161 do_t_usat (void)
12162 {
12163 do_t_ssat_usat (0);
12164 }
12165
12166 static void
12167 do_t_usat16 (void)
12168 {
12169 unsigned Rd, Rn;
12170
12171 Rd = inst.operands[0].reg;
12172 Rn = inst.operands[2].reg;
12173
12174 reject_bad_reg (Rd);
12175 reject_bad_reg (Rn);
12176
12177 inst.instruction |= Rd << 8;
12178 inst.instruction |= inst.operands[1].imm;
12179 inst.instruction |= Rn << 16;
12180 }
12181
12182 /* Neon instruction encoder helpers. */
12183
12184 /* Encodings for the different types for various Neon opcodes. */
12185
12186 /* An "invalid" code for the following tables. */
12187 #define N_INV -1u
12188
12189 struct neon_tab_entry
12190 {
12191 unsigned integer;
12192 unsigned float_or_poly;
12193 unsigned scalar_or_imm;
12194 };
12195
12196 /* Map overloaded Neon opcodes to their respective encodings. */
12197 #define NEON_ENC_TAB \
12198 X(vabd, 0x0000700, 0x1200d00, N_INV), \
12199 X(vmax, 0x0000600, 0x0000f00, N_INV), \
12200 X(vmin, 0x0000610, 0x0200f00, N_INV), \
12201 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
12202 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
12203 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
12204 X(vadd, 0x0000800, 0x0000d00, N_INV), \
12205 X(vsub, 0x1000800, 0x0200d00, N_INV), \
12206 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
12207 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
12208 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
12209 /* Register variants of the following two instructions are encoded as
12210 vcge / vcgt with the operands reversed. */ \
12211 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
12212 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
12213 X(vfma, N_INV, 0x0000c10, N_INV), \
12214 X(vfms, N_INV, 0x0200c10, N_INV), \
12215 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
12216 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
12217 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
12218 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
12219 X(vmlal, 0x0800800, N_INV, 0x0800240), \
12220 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
12221 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
12222 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
12223 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
12224 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
12225 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
12226 X(vshl, 0x0000400, N_INV, 0x0800510), \
12227 X(vqshl, 0x0000410, N_INV, 0x0800710), \
12228 X(vand, 0x0000110, N_INV, 0x0800030), \
12229 X(vbic, 0x0100110, N_INV, 0x0800030), \
12230 X(veor, 0x1000110, N_INV, N_INV), \
12231 X(vorn, 0x0300110, N_INV, 0x0800010), \
12232 X(vorr, 0x0200110, N_INV, 0x0800010), \
12233 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
12234 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
12235 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
12236 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
12237 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
12238 X(vst1, 0x0000000, 0x0800000, N_INV), \
12239 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
12240 X(vst2, 0x0000100, 0x0800100, N_INV), \
12241 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
12242 X(vst3, 0x0000200, 0x0800200, N_INV), \
12243 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
12244 X(vst4, 0x0000300, 0x0800300, N_INV), \
12245 X(vmovn, 0x1b20200, N_INV, N_INV), \
12246 X(vtrn, 0x1b20080, N_INV, N_INV), \
12247 X(vqmovn, 0x1b20200, N_INV, N_INV), \
12248 X(vqmovun, 0x1b20240, N_INV, N_INV), \
12249 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
12250 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
12251 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
12252 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
12253 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
12254 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
12255 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
12256 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
12257 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
12258
12259 enum neon_opc
12260 {
12261 #define X(OPC,I,F,S) N_MNEM_##OPC
12262 NEON_ENC_TAB
12263 #undef X
12264 };
12265
12266 static const struct neon_tab_entry neon_enc_tab[] =
12267 {
12268 #define X(OPC,I,F,S) { (I), (F), (S) }
12269 NEON_ENC_TAB
12270 #undef X
12271 };
12272
12273 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
12274 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12275 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12276 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12277 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12278 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12279 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12280 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
12281 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
12282 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
12283 #define NEON_ENC_SINGLE_(X) \
12284 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
12285 #define NEON_ENC_DOUBLE_(X) \
12286 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
12287
12288 #define NEON_ENCODE(type, inst) \
12289 do \
12290 { \
12291 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
12292 inst.is_neon = 1; \
12293 } \
12294 while (0)
12295
12296 #define check_neon_suffixes \
12297 do \
12298 { \
12299 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
12300 { \
12301 as_bad (_("invalid neon suffix for non neon instruction")); \
12302 return; \
12303 } \
12304 } \
12305 while (0)
12306
12307 /* Define shapes for instruction operands. The following mnemonic characters
12308 are used in this table:
12309
12310 F - VFP S<n> register
12311 D - Neon D<n> register
12312 Q - Neon Q<n> register
12313 I - Immediate
12314 S - Scalar
12315 R - ARM register
12316 L - D<n> register list
12317
12318 This table is used to generate various data:
12319 - enumerations of the form NS_DDR to be used as arguments to
12320 neon_select_shape.
12321 - a table classifying shapes into single, double, quad, mixed.
12322 - a table used to drive neon_select_shape. */
12323
12324 #define NEON_SHAPE_DEF \
12325 X(3, (D, D, D), DOUBLE), \
12326 X(3, (Q, Q, Q), QUAD), \
12327 X(3, (D, D, I), DOUBLE), \
12328 X(3, (Q, Q, I), QUAD), \
12329 X(3, (D, D, S), DOUBLE), \
12330 X(3, (Q, Q, S), QUAD), \
12331 X(2, (D, D), DOUBLE), \
12332 X(2, (Q, Q), QUAD), \
12333 X(2, (D, S), DOUBLE), \
12334 X(2, (Q, S), QUAD), \
12335 X(2, (D, R), DOUBLE), \
12336 X(2, (Q, R), QUAD), \
12337 X(2, (D, I), DOUBLE), \
12338 X(2, (Q, I), QUAD), \
12339 X(3, (D, L, D), DOUBLE), \
12340 X(2, (D, Q), MIXED), \
12341 X(2, (Q, D), MIXED), \
12342 X(3, (D, Q, I), MIXED), \
12343 X(3, (Q, D, I), MIXED), \
12344 X(3, (Q, D, D), MIXED), \
12345 X(3, (D, Q, Q), MIXED), \
12346 X(3, (Q, Q, D), MIXED), \
12347 X(3, (Q, D, S), MIXED), \
12348 X(3, (D, Q, S), MIXED), \
12349 X(4, (D, D, D, I), DOUBLE), \
12350 X(4, (Q, Q, Q, I), QUAD), \
12351 X(2, (F, F), SINGLE), \
12352 X(3, (F, F, F), SINGLE), \
12353 X(2, (F, I), SINGLE), \
12354 X(2, (F, D), MIXED), \
12355 X(2, (D, F), MIXED), \
12356 X(3, (F, F, I), MIXED), \
12357 X(4, (R, R, F, F), SINGLE), \
12358 X(4, (F, F, R, R), SINGLE), \
12359 X(3, (D, R, R), DOUBLE), \
12360 X(3, (R, R, D), DOUBLE), \
12361 X(2, (S, R), SINGLE), \
12362 X(2, (R, S), SINGLE), \
12363 X(2, (F, R), SINGLE), \
12364 X(2, (R, F), SINGLE)
12365
12366 #define S2(A,B) NS_##A##B
12367 #define S3(A,B,C) NS_##A##B##C
12368 #define S4(A,B,C,D) NS_##A##B##C##D
12369
12370 #define X(N, L, C) S##N L
12371
12372 enum neon_shape
12373 {
12374 NEON_SHAPE_DEF,
12375 NS_NULL
12376 };
12377
12378 #undef X
12379 #undef S2
12380 #undef S3
12381 #undef S4
12382
12383 enum neon_shape_class
12384 {
12385 SC_SINGLE,
12386 SC_DOUBLE,
12387 SC_QUAD,
12388 SC_MIXED
12389 };
12390
12391 #define X(N, L, C) SC_##C
12392
12393 static enum neon_shape_class neon_shape_class[] =
12394 {
12395 NEON_SHAPE_DEF
12396 };
12397
12398 #undef X
12399
12400 enum neon_shape_el
12401 {
12402 SE_F,
12403 SE_D,
12404 SE_Q,
12405 SE_I,
12406 SE_S,
12407 SE_R,
12408 SE_L
12409 };
12410
12411 /* Register widths of above. */
12412 static unsigned neon_shape_el_size[] =
12413 {
12414 32,
12415 64,
12416 128,
12417 0,
12418 32,
12419 32,
12420 0
12421 };
12422
12423 struct neon_shape_info
12424 {
12425 unsigned els;
12426 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
12427 };
12428
12429 #define S2(A,B) { SE_##A, SE_##B }
12430 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
12431 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
12432
12433 #define X(N, L, C) { N, S##N L }
12434
12435 static struct neon_shape_info neon_shape_tab[] =
12436 {
12437 NEON_SHAPE_DEF
12438 };
12439
12440 #undef X
12441 #undef S2
12442 #undef S3
12443 #undef S4
12444
12445 /* Bit masks used in type checking given instructions.
12446 'N_EQK' means the type must be the same as (or based on in some way) the key
12447 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
12448 set, various other bits can be set as well in order to modify the meaning of
12449 the type constraint. */
12450
12451 enum neon_type_mask
12452 {
12453 N_S8 = 0x0000001,
12454 N_S16 = 0x0000002,
12455 N_S32 = 0x0000004,
12456 N_S64 = 0x0000008,
12457 N_U8 = 0x0000010,
12458 N_U16 = 0x0000020,
12459 N_U32 = 0x0000040,
12460 N_U64 = 0x0000080,
12461 N_I8 = 0x0000100,
12462 N_I16 = 0x0000200,
12463 N_I32 = 0x0000400,
12464 N_I64 = 0x0000800,
12465 N_8 = 0x0001000,
12466 N_16 = 0x0002000,
12467 N_32 = 0x0004000,
12468 N_64 = 0x0008000,
12469 N_P8 = 0x0010000,
12470 N_P16 = 0x0020000,
12471 N_F16 = 0x0040000,
12472 N_F32 = 0x0080000,
12473 N_F64 = 0x0100000,
12474 N_KEY = 0x1000000, /* Key element (main type specifier). */
12475 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
12476 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
12477 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
12478 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
12479 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
12480 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
12481 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
12482 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
12483 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
12484 N_UTYP = 0,
12485 N_MAX_NONSPECIAL = N_F64
12486 };
12487
12488 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
12489
12490 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
12491 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
12492 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
12493 #define N_SUF_32 (N_SU_32 | N_F32)
12494 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
12495 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
12496
12497 /* Pass this as the first type argument to neon_check_type to ignore types
12498 altogether. */
12499 #define N_IGNORE_TYPE (N_KEY | N_EQK)
12500
12501 /* Select a "shape" for the current instruction (describing register types or
12502 sizes) from a list of alternatives. Return NS_NULL if the current instruction
12503 doesn't fit. For non-polymorphic shapes, checking is usually done as a
12504 function of operand parsing, so this function doesn't need to be called.
12505 Shapes should be listed in order of decreasing length. */
12506
12507 static enum neon_shape
12508 neon_select_shape (enum neon_shape shape, ...)
12509 {
12510 va_list ap;
12511 enum neon_shape first_shape = shape;
12512
12513 /* Fix missing optional operands. FIXME: we don't know at this point how
12514 many arguments we should have, so this makes the assumption that we have
12515 > 1. This is true of all current Neon opcodes, I think, but may not be
12516 true in the future. */
12517 if (!inst.operands[1].present)
12518 inst.operands[1] = inst.operands[0];
12519
12520 va_start (ap, shape);
12521
12522 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
12523 {
12524 unsigned j;
12525 int matches = 1;
12526
12527 for (j = 0; j < neon_shape_tab[shape].els; j++)
12528 {
12529 if (!inst.operands[j].present)
12530 {
12531 matches = 0;
12532 break;
12533 }
12534
12535 switch (neon_shape_tab[shape].el[j])
12536 {
12537 case SE_F:
12538 if (!(inst.operands[j].isreg
12539 && inst.operands[j].isvec
12540 && inst.operands[j].issingle
12541 && !inst.operands[j].isquad))
12542 matches = 0;
12543 break;
12544
12545 case SE_D:
12546 if (!(inst.operands[j].isreg
12547 && inst.operands[j].isvec
12548 && !inst.operands[j].isquad
12549 && !inst.operands[j].issingle))
12550 matches = 0;
12551 break;
12552
12553 case SE_R:
12554 if (!(inst.operands[j].isreg
12555 && !inst.operands[j].isvec))
12556 matches = 0;
12557 break;
12558
12559 case SE_Q:
12560 if (!(inst.operands[j].isreg
12561 && inst.operands[j].isvec
12562 && inst.operands[j].isquad
12563 && !inst.operands[j].issingle))
12564 matches = 0;
12565 break;
12566
12567 case SE_I:
12568 if (!(!inst.operands[j].isreg
12569 && !inst.operands[j].isscalar))
12570 matches = 0;
12571 break;
12572
12573 case SE_S:
12574 if (!(!inst.operands[j].isreg
12575 && inst.operands[j].isscalar))
12576 matches = 0;
12577 break;
12578
12579 case SE_L:
12580 break;
12581 }
12582 if (!matches)
12583 break;
12584 }
12585 if (matches && (j >= ARM_IT_MAX_OPERANDS || !inst.operands[j].present))
12586 /* We've matched all the entries in the shape table, and we don't
12587 have any left over operands which have not been matched. */
12588 break;
12589 }
12590
12591 va_end (ap);
12592
12593 if (shape == NS_NULL && first_shape != NS_NULL)
12594 first_error (_("invalid instruction shape"));
12595
12596 return shape;
12597 }
12598
12599 /* True if SHAPE is predominantly a quadword operation (most of the time, this
12600 means the Q bit should be set). */
12601
12602 static int
12603 neon_quad (enum neon_shape shape)
12604 {
12605 return neon_shape_class[shape] == SC_QUAD;
12606 }
12607
12608 static void
12609 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
12610 unsigned *g_size)
12611 {
12612 /* Allow modification to be made to types which are constrained to be
12613 based on the key element, based on bits set alongside N_EQK. */
12614 if ((typebits & N_EQK) != 0)
12615 {
12616 if ((typebits & N_HLF) != 0)
12617 *g_size /= 2;
12618 else if ((typebits & N_DBL) != 0)
12619 *g_size *= 2;
12620 if ((typebits & N_SGN) != 0)
12621 *g_type = NT_signed;
12622 else if ((typebits & N_UNS) != 0)
12623 *g_type = NT_unsigned;
12624 else if ((typebits & N_INT) != 0)
12625 *g_type = NT_integer;
12626 else if ((typebits & N_FLT) != 0)
12627 *g_type = NT_float;
12628 else if ((typebits & N_SIZ) != 0)
12629 *g_type = NT_untyped;
12630 }
12631 }
12632
12633 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
12634 operand type, i.e. the single type specified in a Neon instruction when it
12635 is the only one given. */
12636
12637 static struct neon_type_el
12638 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
12639 {
12640 struct neon_type_el dest = *key;
12641
12642 gas_assert ((thisarg & N_EQK) != 0);
12643
12644 neon_modify_type_size (thisarg, &dest.type, &dest.size);
12645
12646 return dest;
12647 }
12648
12649 /* Convert Neon type and size into compact bitmask representation. */
12650
12651 static enum neon_type_mask
12652 type_chk_of_el_type (enum neon_el_type type, unsigned size)
12653 {
12654 switch (type)
12655 {
12656 case NT_untyped:
12657 switch (size)
12658 {
12659 case 8: return N_8;
12660 case 16: return N_16;
12661 case 32: return N_32;
12662 case 64: return N_64;
12663 default: ;
12664 }
12665 break;
12666
12667 case NT_integer:
12668 switch (size)
12669 {
12670 case 8: return N_I8;
12671 case 16: return N_I16;
12672 case 32: return N_I32;
12673 case 64: return N_I64;
12674 default: ;
12675 }
12676 break;
12677
12678 case NT_float:
12679 switch (size)
12680 {
12681 case 16: return N_F16;
12682 case 32: return N_F32;
12683 case 64: return N_F64;
12684 default: ;
12685 }
12686 break;
12687
12688 case NT_poly:
12689 switch (size)
12690 {
12691 case 8: return N_P8;
12692 case 16: return N_P16;
12693 default: ;
12694 }
12695 break;
12696
12697 case NT_signed:
12698 switch (size)
12699 {
12700 case 8: return N_S8;
12701 case 16: return N_S16;
12702 case 32: return N_S32;
12703 case 64: return N_S64;
12704 default: ;
12705 }
12706 break;
12707
12708 case NT_unsigned:
12709 switch (size)
12710 {
12711 case 8: return N_U8;
12712 case 16: return N_U16;
12713 case 32: return N_U32;
12714 case 64: return N_U64;
12715 default: ;
12716 }
12717 break;
12718
12719 default: ;
12720 }
12721
12722 return N_UTYP;
12723 }
12724
12725 /* Convert compact Neon bitmask type representation to a type and size. Only
12726 handles the case where a single bit is set in the mask. */
12727
12728 static int
12729 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12730 enum neon_type_mask mask)
12731 {
12732 if ((mask & N_EQK) != 0)
12733 return FAIL;
12734
12735 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12736 *size = 8;
12737 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
12738 *size = 16;
12739 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
12740 *size = 32;
12741 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
12742 *size = 64;
12743 else
12744 return FAIL;
12745
12746 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12747 *type = NT_signed;
12748 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
12749 *type = NT_unsigned;
12750 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
12751 *type = NT_integer;
12752 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
12753 *type = NT_untyped;
12754 else if ((mask & (N_P8 | N_P16)) != 0)
12755 *type = NT_poly;
12756 else if ((mask & (N_F32 | N_F64)) != 0)
12757 *type = NT_float;
12758 else
12759 return FAIL;
12760
12761 return SUCCESS;
12762 }
12763
12764 /* Modify a bitmask of allowed types. This is only needed for type
12765 relaxation. */
12766
12767 static unsigned
12768 modify_types_allowed (unsigned allowed, unsigned mods)
12769 {
12770 unsigned size;
12771 enum neon_el_type type;
12772 unsigned destmask;
12773 int i;
12774
12775 destmask = 0;
12776
12777 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12778 {
12779 if (el_type_of_type_chk (&type, &size,
12780 (enum neon_type_mask) (allowed & i)) == SUCCESS)
12781 {
12782 neon_modify_type_size (mods, &type, &size);
12783 destmask |= type_chk_of_el_type (type, size);
12784 }
12785 }
12786
12787 return destmask;
12788 }
12789
12790 /* Check type and return type classification.
12791 The manual states (paraphrase): If one datatype is given, it indicates the
12792 type given in:
12793 - the second operand, if there is one
12794 - the operand, if there is no second operand
12795 - the result, if there are no operands.
12796 This isn't quite good enough though, so we use a concept of a "key" datatype
12797 which is set on a per-instruction basis, which is the one which matters when
12798 only one data type is written.
12799 Note: this function has side-effects (e.g. filling in missing operands). All
12800 Neon instructions should call it before performing bit encoding. */
12801
12802 static struct neon_type_el
12803 neon_check_type (unsigned els, enum neon_shape ns, ...)
12804 {
12805 va_list ap;
12806 unsigned i, pass, key_el = 0;
12807 unsigned types[NEON_MAX_TYPE_ELS];
12808 enum neon_el_type k_type = NT_invtype;
12809 unsigned k_size = -1u;
12810 struct neon_type_el badtype = {NT_invtype, -1};
12811 unsigned key_allowed = 0;
12812
12813 /* Optional registers in Neon instructions are always (not) in operand 1.
12814 Fill in the missing operand here, if it was omitted. */
12815 if (els > 1 && !inst.operands[1].present)
12816 inst.operands[1] = inst.operands[0];
12817
12818 /* Suck up all the varargs. */
12819 va_start (ap, ns);
12820 for (i = 0; i < els; i++)
12821 {
12822 unsigned thisarg = va_arg (ap, unsigned);
12823 if (thisarg == N_IGNORE_TYPE)
12824 {
12825 va_end (ap);
12826 return badtype;
12827 }
12828 types[i] = thisarg;
12829 if ((thisarg & N_KEY) != 0)
12830 key_el = i;
12831 }
12832 va_end (ap);
12833
12834 if (inst.vectype.elems > 0)
12835 for (i = 0; i < els; i++)
12836 if (inst.operands[i].vectype.type != NT_invtype)
12837 {
12838 first_error (_("types specified in both the mnemonic and operands"));
12839 return badtype;
12840 }
12841
12842 /* Duplicate inst.vectype elements here as necessary.
12843 FIXME: No idea if this is exactly the same as the ARM assembler,
12844 particularly when an insn takes one register and one non-register
12845 operand. */
12846 if (inst.vectype.elems == 1 && els > 1)
12847 {
12848 unsigned j;
12849 inst.vectype.elems = els;
12850 inst.vectype.el[key_el] = inst.vectype.el[0];
12851 for (j = 0; j < els; j++)
12852 if (j != key_el)
12853 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12854 types[j]);
12855 }
12856 else if (inst.vectype.elems == 0 && els > 0)
12857 {
12858 unsigned j;
12859 /* No types were given after the mnemonic, so look for types specified
12860 after each operand. We allow some flexibility here; as long as the
12861 "key" operand has a type, we can infer the others. */
12862 for (j = 0; j < els; j++)
12863 if (inst.operands[j].vectype.type != NT_invtype)
12864 inst.vectype.el[j] = inst.operands[j].vectype;
12865
12866 if (inst.operands[key_el].vectype.type != NT_invtype)
12867 {
12868 for (j = 0; j < els; j++)
12869 if (inst.operands[j].vectype.type == NT_invtype)
12870 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12871 types[j]);
12872 }
12873 else
12874 {
12875 first_error (_("operand types can't be inferred"));
12876 return badtype;
12877 }
12878 }
12879 else if (inst.vectype.elems != els)
12880 {
12881 first_error (_("type specifier has the wrong number of parts"));
12882 return badtype;
12883 }
12884
12885 for (pass = 0; pass < 2; pass++)
12886 {
12887 for (i = 0; i < els; i++)
12888 {
12889 unsigned thisarg = types[i];
12890 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12891 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12892 enum neon_el_type g_type = inst.vectype.el[i].type;
12893 unsigned g_size = inst.vectype.el[i].size;
12894
12895 /* Decay more-specific signed & unsigned types to sign-insensitive
12896 integer types if sign-specific variants are unavailable. */
12897 if ((g_type == NT_signed || g_type == NT_unsigned)
12898 && (types_allowed & N_SU_ALL) == 0)
12899 g_type = NT_integer;
12900
12901 /* If only untyped args are allowed, decay any more specific types to
12902 them. Some instructions only care about signs for some element
12903 sizes, so handle that properly. */
12904 if ((g_size == 8 && (types_allowed & N_8) != 0)
12905 || (g_size == 16 && (types_allowed & N_16) != 0)
12906 || (g_size == 32 && (types_allowed & N_32) != 0)
12907 || (g_size == 64 && (types_allowed & N_64) != 0))
12908 g_type = NT_untyped;
12909
12910 if (pass == 0)
12911 {
12912 if ((thisarg & N_KEY) != 0)
12913 {
12914 k_type = g_type;
12915 k_size = g_size;
12916 key_allowed = thisarg & ~N_KEY;
12917 }
12918 }
12919 else
12920 {
12921 if ((thisarg & N_VFP) != 0)
12922 {
12923 enum neon_shape_el regshape;
12924 unsigned regwidth, match;
12925
12926 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12927 if (ns == NS_NULL)
12928 {
12929 first_error (_("invalid instruction shape"));
12930 return badtype;
12931 }
12932 regshape = neon_shape_tab[ns].el[i];
12933 regwidth = neon_shape_el_size[regshape];
12934
12935 /* In VFP mode, operands must match register widths. If we
12936 have a key operand, use its width, else use the width of
12937 the current operand. */
12938 if (k_size != -1u)
12939 match = k_size;
12940 else
12941 match = g_size;
12942
12943 if (regwidth != match)
12944 {
12945 first_error (_("operand size must match register width"));
12946 return badtype;
12947 }
12948 }
12949
12950 if ((thisarg & N_EQK) == 0)
12951 {
12952 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12953
12954 if ((given_type & types_allowed) == 0)
12955 {
12956 first_error (_("bad type in Neon instruction"));
12957 return badtype;
12958 }
12959 }
12960 else
12961 {
12962 enum neon_el_type mod_k_type = k_type;
12963 unsigned mod_k_size = k_size;
12964 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12965 if (g_type != mod_k_type || g_size != mod_k_size)
12966 {
12967 first_error (_("inconsistent types in Neon instruction"));
12968 return badtype;
12969 }
12970 }
12971 }
12972 }
12973 }
12974
12975 return inst.vectype.el[key_el];
12976 }
12977
12978 /* Neon-style VFP instruction forwarding. */
12979
12980 /* Thumb VFP instructions have 0xE in the condition field. */
12981
12982 static void
12983 do_vfp_cond_or_thumb (void)
12984 {
12985 inst.is_neon = 1;
12986
12987 if (thumb_mode)
12988 inst.instruction |= 0xe0000000;
12989 else
12990 inst.instruction |= inst.cond << 28;
12991 }
12992
12993 /* Look up and encode a simple mnemonic, for use as a helper function for the
12994 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12995 etc. It is assumed that operand parsing has already been done, and that the
12996 operands are in the form expected by the given opcode (this isn't necessarily
12997 the same as the form in which they were parsed, hence some massaging must
12998 take place before this function is called).
12999 Checks current arch version against that in the looked-up opcode. */
13000
13001 static void
13002 do_vfp_nsyn_opcode (const char *opname)
13003 {
13004 const struct asm_opcode *opcode;
13005
13006 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
13007
13008 if (!opcode)
13009 abort ();
13010
13011 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
13012 thumb_mode ? *opcode->tvariant : *opcode->avariant),
13013 _(BAD_FPU));
13014
13015 inst.is_neon = 1;
13016
13017 if (thumb_mode)
13018 {
13019 inst.instruction = opcode->tvalue;
13020 opcode->tencode ();
13021 }
13022 else
13023 {
13024 inst.instruction = (inst.cond << 28) | opcode->avalue;
13025 opcode->aencode ();
13026 }
13027 }
13028
13029 static void
13030 do_vfp_nsyn_add_sub (enum neon_shape rs)
13031 {
13032 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
13033
13034 if (rs == NS_FFF)
13035 {
13036 if (is_add)
13037 do_vfp_nsyn_opcode ("fadds");
13038 else
13039 do_vfp_nsyn_opcode ("fsubs");
13040 }
13041 else
13042 {
13043 if (is_add)
13044 do_vfp_nsyn_opcode ("faddd");
13045 else
13046 do_vfp_nsyn_opcode ("fsubd");
13047 }
13048 }
13049
13050 /* Check operand types to see if this is a VFP instruction, and if so call
13051 PFN (). */
13052
13053 static int
13054 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
13055 {
13056 enum neon_shape rs;
13057 struct neon_type_el et;
13058
13059 switch (args)
13060 {
13061 case 2:
13062 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13063 et = neon_check_type (2, rs,
13064 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13065 break;
13066
13067 case 3:
13068 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13069 et = neon_check_type (3, rs,
13070 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13071 break;
13072
13073 default:
13074 abort ();
13075 }
13076
13077 if (et.type != NT_invtype)
13078 {
13079 pfn (rs);
13080 return SUCCESS;
13081 }
13082
13083 inst.error = NULL;
13084 return FAIL;
13085 }
13086
13087 static void
13088 do_vfp_nsyn_mla_mls (enum neon_shape rs)
13089 {
13090 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
13091
13092 if (rs == NS_FFF)
13093 {
13094 if (is_mla)
13095 do_vfp_nsyn_opcode ("fmacs");
13096 else
13097 do_vfp_nsyn_opcode ("fnmacs");
13098 }
13099 else
13100 {
13101 if (is_mla)
13102 do_vfp_nsyn_opcode ("fmacd");
13103 else
13104 do_vfp_nsyn_opcode ("fnmacd");
13105 }
13106 }
13107
13108 static void
13109 do_vfp_nsyn_fma_fms (enum neon_shape rs)
13110 {
13111 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
13112
13113 if (rs == NS_FFF)
13114 {
13115 if (is_fma)
13116 do_vfp_nsyn_opcode ("ffmas");
13117 else
13118 do_vfp_nsyn_opcode ("ffnmas");
13119 }
13120 else
13121 {
13122 if (is_fma)
13123 do_vfp_nsyn_opcode ("ffmad");
13124 else
13125 do_vfp_nsyn_opcode ("ffnmad");
13126 }
13127 }
13128
13129 static void
13130 do_vfp_nsyn_mul (enum neon_shape rs)
13131 {
13132 if (rs == NS_FFF)
13133 do_vfp_nsyn_opcode ("fmuls");
13134 else
13135 do_vfp_nsyn_opcode ("fmuld");
13136 }
13137
13138 static void
13139 do_vfp_nsyn_abs_neg (enum neon_shape rs)
13140 {
13141 int is_neg = (inst.instruction & 0x80) != 0;
13142 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
13143
13144 if (rs == NS_FF)
13145 {
13146 if (is_neg)
13147 do_vfp_nsyn_opcode ("fnegs");
13148 else
13149 do_vfp_nsyn_opcode ("fabss");
13150 }
13151 else
13152 {
13153 if (is_neg)
13154 do_vfp_nsyn_opcode ("fnegd");
13155 else
13156 do_vfp_nsyn_opcode ("fabsd");
13157 }
13158 }
13159
13160 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
13161 insns belong to Neon, and are handled elsewhere. */
13162
13163 static void
13164 do_vfp_nsyn_ldm_stm (int is_dbmode)
13165 {
13166 int is_ldm = (inst.instruction & (1 << 20)) != 0;
13167 if (is_ldm)
13168 {
13169 if (is_dbmode)
13170 do_vfp_nsyn_opcode ("fldmdbs");
13171 else
13172 do_vfp_nsyn_opcode ("fldmias");
13173 }
13174 else
13175 {
13176 if (is_dbmode)
13177 do_vfp_nsyn_opcode ("fstmdbs");
13178 else
13179 do_vfp_nsyn_opcode ("fstmias");
13180 }
13181 }
13182
13183 static void
13184 do_vfp_nsyn_sqrt (void)
13185 {
13186 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13187 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13188
13189 if (rs == NS_FF)
13190 do_vfp_nsyn_opcode ("fsqrts");
13191 else
13192 do_vfp_nsyn_opcode ("fsqrtd");
13193 }
13194
13195 static void
13196 do_vfp_nsyn_div (void)
13197 {
13198 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13199 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13200 N_F32 | N_F64 | N_KEY | N_VFP);
13201
13202 if (rs == NS_FFF)
13203 do_vfp_nsyn_opcode ("fdivs");
13204 else
13205 do_vfp_nsyn_opcode ("fdivd");
13206 }
13207
13208 static void
13209 do_vfp_nsyn_nmul (void)
13210 {
13211 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
13212 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
13213 N_F32 | N_F64 | N_KEY | N_VFP);
13214
13215 if (rs == NS_FFF)
13216 {
13217 NEON_ENCODE (SINGLE, inst);
13218 do_vfp_sp_dyadic ();
13219 }
13220 else
13221 {
13222 NEON_ENCODE (DOUBLE, inst);
13223 do_vfp_dp_rd_rn_rm ();
13224 }
13225 do_vfp_cond_or_thumb ();
13226 }
13227
13228 static void
13229 do_vfp_nsyn_cmp (void)
13230 {
13231 if (inst.operands[1].isreg)
13232 {
13233 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
13234 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
13235
13236 if (rs == NS_FF)
13237 {
13238 NEON_ENCODE (SINGLE, inst);
13239 do_vfp_sp_monadic ();
13240 }
13241 else
13242 {
13243 NEON_ENCODE (DOUBLE, inst);
13244 do_vfp_dp_rd_rm ();
13245 }
13246 }
13247 else
13248 {
13249 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
13250 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
13251
13252 switch (inst.instruction & 0x0fffffff)
13253 {
13254 case N_MNEM_vcmp:
13255 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
13256 break;
13257 case N_MNEM_vcmpe:
13258 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
13259 break;
13260 default:
13261 abort ();
13262 }
13263
13264 if (rs == NS_FI)
13265 {
13266 NEON_ENCODE (SINGLE, inst);
13267 do_vfp_sp_compare_z ();
13268 }
13269 else
13270 {
13271 NEON_ENCODE (DOUBLE, inst);
13272 do_vfp_dp_rd ();
13273 }
13274 }
13275 do_vfp_cond_or_thumb ();
13276 }
13277
13278 static void
13279 nsyn_insert_sp (void)
13280 {
13281 inst.operands[1] = inst.operands[0];
13282 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
13283 inst.operands[0].reg = REG_SP;
13284 inst.operands[0].isreg = 1;
13285 inst.operands[0].writeback = 1;
13286 inst.operands[0].present = 1;
13287 }
13288
13289 static void
13290 do_vfp_nsyn_push (void)
13291 {
13292 nsyn_insert_sp ();
13293 if (inst.operands[1].issingle)
13294 do_vfp_nsyn_opcode ("fstmdbs");
13295 else
13296 do_vfp_nsyn_opcode ("fstmdbd");
13297 }
13298
13299 static void
13300 do_vfp_nsyn_pop (void)
13301 {
13302 nsyn_insert_sp ();
13303 if (inst.operands[1].issingle)
13304 do_vfp_nsyn_opcode ("fldmias");
13305 else
13306 do_vfp_nsyn_opcode ("fldmiad");
13307 }
13308
13309 /* Fix up Neon data-processing instructions, ORing in the correct bits for
13310 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
13311
13312 static void
13313 neon_dp_fixup (struct arm_it* insn)
13314 {
13315 unsigned int i = insn->instruction;
13316 insn->is_neon = 1;
13317
13318 if (thumb_mode)
13319 {
13320 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
13321 if (i & (1 << 24))
13322 i |= 1 << 28;
13323
13324 i &= ~(1 << 24);
13325
13326 i |= 0xef000000;
13327 }
13328 else
13329 i |= 0xf2000000;
13330
13331 insn->instruction = i;
13332 }
13333
13334 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
13335 (0, 1, 2, 3). */
13336
13337 static unsigned
13338 neon_logbits (unsigned x)
13339 {
13340 return ffs (x) - 4;
13341 }
13342
13343 #define LOW4(R) ((R) & 0xf)
13344 #define HI1(R) (((R) >> 4) & 1)
13345
13346 /* Encode insns with bit pattern:
13347
13348 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13349 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
13350
13351 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
13352 different meaning for some instruction. */
13353
13354 static void
13355 neon_three_same (int isquad, int ubit, int size)
13356 {
13357 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13358 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13359 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13360 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13361 inst.instruction |= LOW4 (inst.operands[2].reg);
13362 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13363 inst.instruction |= (isquad != 0) << 6;
13364 inst.instruction |= (ubit != 0) << 24;
13365 if (size != -1)
13366 inst.instruction |= neon_logbits (size) << 20;
13367
13368 neon_dp_fixup (&inst);
13369 }
13370
13371 /* Encode instructions of the form:
13372
13373 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
13374 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
13375
13376 Don't write size if SIZE == -1. */
13377
13378 static void
13379 neon_two_same (int qbit, int ubit, int size)
13380 {
13381 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13382 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13383 inst.instruction |= LOW4 (inst.operands[1].reg);
13384 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13385 inst.instruction |= (qbit != 0) << 6;
13386 inst.instruction |= (ubit != 0) << 24;
13387
13388 if (size != -1)
13389 inst.instruction |= neon_logbits (size) << 18;
13390
13391 neon_dp_fixup (&inst);
13392 }
13393
13394 /* Neon instruction encoders, in approximate order of appearance. */
13395
13396 static void
13397 do_neon_dyadic_i_su (void)
13398 {
13399 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13400 struct neon_type_el et = neon_check_type (3, rs,
13401 N_EQK, N_EQK, N_SU_32 | N_KEY);
13402 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13403 }
13404
13405 static void
13406 do_neon_dyadic_i64_su (void)
13407 {
13408 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13409 struct neon_type_el et = neon_check_type (3, rs,
13410 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13411 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13412 }
13413
13414 static void
13415 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
13416 unsigned immbits)
13417 {
13418 unsigned size = et.size >> 3;
13419 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13420 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13421 inst.instruction |= LOW4 (inst.operands[1].reg);
13422 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13423 inst.instruction |= (isquad != 0) << 6;
13424 inst.instruction |= immbits << 16;
13425 inst.instruction |= (size >> 3) << 7;
13426 inst.instruction |= (size & 0x7) << 19;
13427 if (write_ubit)
13428 inst.instruction |= (uval != 0) << 24;
13429
13430 neon_dp_fixup (&inst);
13431 }
13432
13433 static void
13434 do_neon_shl_imm (void)
13435 {
13436 if (!inst.operands[2].isreg)
13437 {
13438 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13439 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
13440 NEON_ENCODE (IMMED, inst);
13441 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
13442 }
13443 else
13444 {
13445 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13446 struct neon_type_el et = neon_check_type (3, rs,
13447 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13448 unsigned int tmp;
13449
13450 /* VSHL/VQSHL 3-register variants have syntax such as:
13451 vshl.xx Dd, Dm, Dn
13452 whereas other 3-register operations encoded by neon_three_same have
13453 syntax like:
13454 vadd.xx Dd, Dn, Dm
13455 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
13456 here. */
13457 tmp = inst.operands[2].reg;
13458 inst.operands[2].reg = inst.operands[1].reg;
13459 inst.operands[1].reg = tmp;
13460 NEON_ENCODE (INTEGER, inst);
13461 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13462 }
13463 }
13464
13465 static void
13466 do_neon_qshl_imm (void)
13467 {
13468 if (!inst.operands[2].isreg)
13469 {
13470 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13471 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13472
13473 NEON_ENCODE (IMMED, inst);
13474 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13475 inst.operands[2].imm);
13476 }
13477 else
13478 {
13479 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13480 struct neon_type_el et = neon_check_type (3, rs,
13481 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
13482 unsigned int tmp;
13483
13484 /* See note in do_neon_shl_imm. */
13485 tmp = inst.operands[2].reg;
13486 inst.operands[2].reg = inst.operands[1].reg;
13487 inst.operands[1].reg = tmp;
13488 NEON_ENCODE (INTEGER, inst);
13489 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13490 }
13491 }
13492
13493 static void
13494 do_neon_rshl (void)
13495 {
13496 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13497 struct neon_type_el et = neon_check_type (3, rs,
13498 N_EQK, N_EQK, N_SU_ALL | N_KEY);
13499 unsigned int tmp;
13500
13501 tmp = inst.operands[2].reg;
13502 inst.operands[2].reg = inst.operands[1].reg;
13503 inst.operands[1].reg = tmp;
13504 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
13505 }
13506
13507 static int
13508 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
13509 {
13510 /* Handle .I8 pseudo-instructions. */
13511 if (size == 8)
13512 {
13513 /* Unfortunately, this will make everything apart from zero out-of-range.
13514 FIXME is this the intended semantics? There doesn't seem much point in
13515 accepting .I8 if so. */
13516 immediate |= immediate << 8;
13517 size = 16;
13518 }
13519
13520 if (size >= 32)
13521 {
13522 if (immediate == (immediate & 0x000000ff))
13523 {
13524 *immbits = immediate;
13525 return 0x1;
13526 }
13527 else if (immediate == (immediate & 0x0000ff00))
13528 {
13529 *immbits = immediate >> 8;
13530 return 0x3;
13531 }
13532 else if (immediate == (immediate & 0x00ff0000))
13533 {
13534 *immbits = immediate >> 16;
13535 return 0x5;
13536 }
13537 else if (immediate == (immediate & 0xff000000))
13538 {
13539 *immbits = immediate >> 24;
13540 return 0x7;
13541 }
13542 if ((immediate & 0xffff) != (immediate >> 16))
13543 goto bad_immediate;
13544 immediate &= 0xffff;
13545 }
13546
13547 if (immediate == (immediate & 0x000000ff))
13548 {
13549 *immbits = immediate;
13550 return 0x9;
13551 }
13552 else if (immediate == (immediate & 0x0000ff00))
13553 {
13554 *immbits = immediate >> 8;
13555 return 0xb;
13556 }
13557
13558 bad_immediate:
13559 first_error (_("immediate value out of range"));
13560 return FAIL;
13561 }
13562
13563 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
13564 A, B, C, D. */
13565
13566 static int
13567 neon_bits_same_in_bytes (unsigned imm)
13568 {
13569 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
13570 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
13571 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
13572 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
13573 }
13574
13575 /* For immediate of above form, return 0bABCD. */
13576
13577 static unsigned
13578 neon_squash_bits (unsigned imm)
13579 {
13580 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
13581 | ((imm & 0x01000000) >> 21);
13582 }
13583
13584 /* Compress quarter-float representation to 0b...000 abcdefgh. */
13585
13586 static unsigned
13587 neon_qfloat_bits (unsigned imm)
13588 {
13589 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
13590 }
13591
13592 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
13593 the instruction. *OP is passed as the initial value of the op field, and
13594 may be set to a different value depending on the constant (i.e.
13595 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
13596 MVN). If the immediate looks like a repeated pattern then also
13597 try smaller element sizes. */
13598
13599 static int
13600 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
13601 unsigned *immbits, int *op, int size,
13602 enum neon_el_type type)
13603 {
13604 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
13605 float. */
13606 if (type == NT_float && !float_p)
13607 return FAIL;
13608
13609 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
13610 {
13611 if (size != 32 || *op == 1)
13612 return FAIL;
13613 *immbits = neon_qfloat_bits (immlo);
13614 return 0xf;
13615 }
13616
13617 if (size == 64)
13618 {
13619 if (neon_bits_same_in_bytes (immhi)
13620 && neon_bits_same_in_bytes (immlo))
13621 {
13622 if (*op == 1)
13623 return FAIL;
13624 *immbits = (neon_squash_bits (immhi) << 4)
13625 | neon_squash_bits (immlo);
13626 *op = 1;
13627 return 0xe;
13628 }
13629
13630 if (immhi != immlo)
13631 return FAIL;
13632 }
13633
13634 if (size >= 32)
13635 {
13636 if (immlo == (immlo & 0x000000ff))
13637 {
13638 *immbits = immlo;
13639 return 0x0;
13640 }
13641 else if (immlo == (immlo & 0x0000ff00))
13642 {
13643 *immbits = immlo >> 8;
13644 return 0x2;
13645 }
13646 else if (immlo == (immlo & 0x00ff0000))
13647 {
13648 *immbits = immlo >> 16;
13649 return 0x4;
13650 }
13651 else if (immlo == (immlo & 0xff000000))
13652 {
13653 *immbits = immlo >> 24;
13654 return 0x6;
13655 }
13656 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
13657 {
13658 *immbits = (immlo >> 8) & 0xff;
13659 return 0xc;
13660 }
13661 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
13662 {
13663 *immbits = (immlo >> 16) & 0xff;
13664 return 0xd;
13665 }
13666
13667 if ((immlo & 0xffff) != (immlo >> 16))
13668 return FAIL;
13669 immlo &= 0xffff;
13670 }
13671
13672 if (size >= 16)
13673 {
13674 if (immlo == (immlo & 0x000000ff))
13675 {
13676 *immbits = immlo;
13677 return 0x8;
13678 }
13679 else if (immlo == (immlo & 0x0000ff00))
13680 {
13681 *immbits = immlo >> 8;
13682 return 0xa;
13683 }
13684
13685 if ((immlo & 0xff) != (immlo >> 8))
13686 return FAIL;
13687 immlo &= 0xff;
13688 }
13689
13690 if (immlo == (immlo & 0x000000ff))
13691 {
13692 /* Don't allow MVN with 8-bit immediate. */
13693 if (*op == 1)
13694 return FAIL;
13695 *immbits = immlo;
13696 return 0xe;
13697 }
13698
13699 return FAIL;
13700 }
13701
13702 /* Write immediate bits [7:0] to the following locations:
13703
13704 |28/24|23 19|18 16|15 4|3 0|
13705 | 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|
13706
13707 This function is used by VMOV/VMVN/VORR/VBIC. */
13708
13709 static void
13710 neon_write_immbits (unsigned immbits)
13711 {
13712 inst.instruction |= immbits & 0xf;
13713 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13714 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13715 }
13716
13717 /* Invert low-order SIZE bits of XHI:XLO. */
13718
13719 static void
13720 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13721 {
13722 unsigned immlo = xlo ? *xlo : 0;
13723 unsigned immhi = xhi ? *xhi : 0;
13724
13725 switch (size)
13726 {
13727 case 8:
13728 immlo = (~immlo) & 0xff;
13729 break;
13730
13731 case 16:
13732 immlo = (~immlo) & 0xffff;
13733 break;
13734
13735 case 64:
13736 immhi = (~immhi) & 0xffffffff;
13737 /* fall through. */
13738
13739 case 32:
13740 immlo = (~immlo) & 0xffffffff;
13741 break;
13742
13743 default:
13744 abort ();
13745 }
13746
13747 if (xlo)
13748 *xlo = immlo;
13749
13750 if (xhi)
13751 *xhi = immhi;
13752 }
13753
13754 static void
13755 do_neon_logic (void)
13756 {
13757 if (inst.operands[2].present && inst.operands[2].isreg)
13758 {
13759 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13760 neon_check_type (3, rs, N_IGNORE_TYPE);
13761 /* U bit and size field were set as part of the bitmask. */
13762 NEON_ENCODE (INTEGER, inst);
13763 neon_three_same (neon_quad (rs), 0, -1);
13764 }
13765 else
13766 {
13767 const int three_ops_form = (inst.operands[2].present
13768 && !inst.operands[2].isreg);
13769 const int immoperand = (three_ops_form ? 2 : 1);
13770 enum neon_shape rs = (three_ops_form
13771 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13772 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
13773 struct neon_type_el et = neon_check_type (2, rs,
13774 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13775 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
13776 unsigned immbits;
13777 int cmode;
13778
13779 if (et.type == NT_invtype)
13780 return;
13781
13782 if (three_ops_form)
13783 constraint (inst.operands[0].reg != inst.operands[1].reg,
13784 _("first and second operands shall be the same register"));
13785
13786 NEON_ENCODE (IMMED, inst);
13787
13788 immbits = inst.operands[immoperand].imm;
13789 if (et.size == 64)
13790 {
13791 /* .i64 is a pseudo-op, so the immediate must be a repeating
13792 pattern. */
13793 if (immbits != (inst.operands[immoperand].regisimm ?
13794 inst.operands[immoperand].reg : 0))
13795 {
13796 /* Set immbits to an invalid constant. */
13797 immbits = 0xdeadbeef;
13798 }
13799 }
13800
13801 switch (opcode)
13802 {
13803 case N_MNEM_vbic:
13804 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13805 break;
13806
13807 case N_MNEM_vorr:
13808 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13809 break;
13810
13811 case N_MNEM_vand:
13812 /* Pseudo-instruction for VBIC. */
13813 neon_invert_size (&immbits, 0, et.size);
13814 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13815 break;
13816
13817 case N_MNEM_vorn:
13818 /* Pseudo-instruction for VORR. */
13819 neon_invert_size (&immbits, 0, et.size);
13820 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13821 break;
13822
13823 default:
13824 abort ();
13825 }
13826
13827 if (cmode == FAIL)
13828 return;
13829
13830 inst.instruction |= neon_quad (rs) << 6;
13831 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13832 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13833 inst.instruction |= cmode << 8;
13834 neon_write_immbits (immbits);
13835
13836 neon_dp_fixup (&inst);
13837 }
13838 }
13839
13840 static void
13841 do_neon_bitfield (void)
13842 {
13843 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13844 neon_check_type (3, rs, N_IGNORE_TYPE);
13845 neon_three_same (neon_quad (rs), 0, -1);
13846 }
13847
13848 static void
13849 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13850 unsigned destbits)
13851 {
13852 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13853 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13854 types | N_KEY);
13855 if (et.type == NT_float)
13856 {
13857 NEON_ENCODE (FLOAT, inst);
13858 neon_three_same (neon_quad (rs), 0, -1);
13859 }
13860 else
13861 {
13862 NEON_ENCODE (INTEGER, inst);
13863 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13864 }
13865 }
13866
13867 static void
13868 do_neon_dyadic_if_su (void)
13869 {
13870 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13871 }
13872
13873 static void
13874 do_neon_dyadic_if_su_d (void)
13875 {
13876 /* This version only allow D registers, but that constraint is enforced during
13877 operand parsing so we don't need to do anything extra here. */
13878 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13879 }
13880
13881 static void
13882 do_neon_dyadic_if_i_d (void)
13883 {
13884 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13885 affected if we specify unsigned args. */
13886 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13887 }
13888
13889 enum vfp_or_neon_is_neon_bits
13890 {
13891 NEON_CHECK_CC = 1,
13892 NEON_CHECK_ARCH = 2
13893 };
13894
13895 /* Call this function if an instruction which may have belonged to the VFP or
13896 Neon instruction sets, but turned out to be a Neon instruction (due to the
13897 operand types involved, etc.). We have to check and/or fix-up a couple of
13898 things:
13899
13900 - Make sure the user hasn't attempted to make a Neon instruction
13901 conditional.
13902 - Alter the value in the condition code field if necessary.
13903 - Make sure that the arch supports Neon instructions.
13904
13905 Which of these operations take place depends on bits from enum
13906 vfp_or_neon_is_neon_bits.
13907
13908 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13909 current instruction's condition is COND_ALWAYS, the condition field is
13910 changed to inst.uncond_value. This is necessary because instructions shared
13911 between VFP and Neon may be conditional for the VFP variants only, and the
13912 unconditional Neon version must have, e.g., 0xF in the condition field. */
13913
13914 static int
13915 vfp_or_neon_is_neon (unsigned check)
13916 {
13917 /* Conditions are always legal in Thumb mode (IT blocks). */
13918 if (!thumb_mode && (check & NEON_CHECK_CC))
13919 {
13920 if (inst.cond != COND_ALWAYS)
13921 {
13922 first_error (_(BAD_COND));
13923 return FAIL;
13924 }
13925 if (inst.uncond_value != -1)
13926 inst.instruction |= inst.uncond_value << 28;
13927 }
13928
13929 if ((check & NEON_CHECK_ARCH)
13930 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13931 {
13932 first_error (_(BAD_FPU));
13933 return FAIL;
13934 }
13935
13936 return SUCCESS;
13937 }
13938
13939 static void
13940 do_neon_addsub_if_i (void)
13941 {
13942 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13943 return;
13944
13945 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13946 return;
13947
13948 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13949 affected if we specify unsigned args. */
13950 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
13951 }
13952
13953 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13954 result to be:
13955 V<op> A,B (A is operand 0, B is operand 2)
13956 to mean:
13957 V<op> A,B,A
13958 not:
13959 V<op> A,B,B
13960 so handle that case specially. */
13961
13962 static void
13963 neon_exchange_operands (void)
13964 {
13965 void *scratch = alloca (sizeof (inst.operands[0]));
13966 if (inst.operands[1].present)
13967 {
13968 /* Swap operands[1] and operands[2]. */
13969 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13970 inst.operands[1] = inst.operands[2];
13971 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13972 }
13973 else
13974 {
13975 inst.operands[1] = inst.operands[2];
13976 inst.operands[2] = inst.operands[0];
13977 }
13978 }
13979
13980 static void
13981 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13982 {
13983 if (inst.operands[2].isreg)
13984 {
13985 if (invert)
13986 neon_exchange_operands ();
13987 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
13988 }
13989 else
13990 {
13991 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13992 struct neon_type_el et = neon_check_type (2, rs,
13993 N_EQK | N_SIZ, immtypes | N_KEY);
13994
13995 NEON_ENCODE (IMMED, inst);
13996 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13997 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13998 inst.instruction |= LOW4 (inst.operands[1].reg);
13999 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14000 inst.instruction |= neon_quad (rs) << 6;
14001 inst.instruction |= (et.type == NT_float) << 10;
14002 inst.instruction |= neon_logbits (et.size) << 18;
14003
14004 neon_dp_fixup (&inst);
14005 }
14006 }
14007
14008 static void
14009 do_neon_cmp (void)
14010 {
14011 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
14012 }
14013
14014 static void
14015 do_neon_cmp_inv (void)
14016 {
14017 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
14018 }
14019
14020 static void
14021 do_neon_ceq (void)
14022 {
14023 neon_compare (N_IF_32, N_IF_32, FALSE);
14024 }
14025
14026 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
14027 scalars, which are encoded in 5 bits, M : Rm.
14028 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
14029 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
14030 index in M. */
14031
14032 static unsigned
14033 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
14034 {
14035 unsigned regno = NEON_SCALAR_REG (scalar);
14036 unsigned elno = NEON_SCALAR_INDEX (scalar);
14037
14038 switch (elsize)
14039 {
14040 case 16:
14041 if (regno > 7 || elno > 3)
14042 goto bad_scalar;
14043 return regno | (elno << 3);
14044
14045 case 32:
14046 if (regno > 15 || elno > 1)
14047 goto bad_scalar;
14048 return regno | (elno << 4);
14049
14050 default:
14051 bad_scalar:
14052 first_error (_("scalar out of range for multiply instruction"));
14053 }
14054
14055 return 0;
14056 }
14057
14058 /* Encode multiply / multiply-accumulate scalar instructions. */
14059
14060 static void
14061 neon_mul_mac (struct neon_type_el et, int ubit)
14062 {
14063 unsigned scalar;
14064
14065 /* Give a more helpful error message if we have an invalid type. */
14066 if (et.type == NT_invtype)
14067 return;
14068
14069 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
14070 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14071 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14072 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14073 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14074 inst.instruction |= LOW4 (scalar);
14075 inst.instruction |= HI1 (scalar) << 5;
14076 inst.instruction |= (et.type == NT_float) << 8;
14077 inst.instruction |= neon_logbits (et.size) << 20;
14078 inst.instruction |= (ubit != 0) << 24;
14079
14080 neon_dp_fixup (&inst);
14081 }
14082
14083 static void
14084 do_neon_mac_maybe_scalar (void)
14085 {
14086 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
14087 return;
14088
14089 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14090 return;
14091
14092 if (inst.operands[2].isscalar)
14093 {
14094 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14095 struct neon_type_el et = neon_check_type (3, rs,
14096 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
14097 NEON_ENCODE (SCALAR, inst);
14098 neon_mul_mac (et, neon_quad (rs));
14099 }
14100 else
14101 {
14102 /* The "untyped" case can't happen. Do this to stop the "U" bit being
14103 affected if we specify unsigned args. */
14104 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14105 }
14106 }
14107
14108 static void
14109 do_neon_fmac (void)
14110 {
14111 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
14112 return;
14113
14114 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14115 return;
14116
14117 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
14118 }
14119
14120 static void
14121 do_neon_tst (void)
14122 {
14123 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14124 struct neon_type_el et = neon_check_type (3, rs,
14125 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
14126 neon_three_same (neon_quad (rs), 0, et.size);
14127 }
14128
14129 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
14130 same types as the MAC equivalents. The polynomial type for this instruction
14131 is encoded the same as the integer type. */
14132
14133 static void
14134 do_neon_mul (void)
14135 {
14136 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
14137 return;
14138
14139 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14140 return;
14141
14142 if (inst.operands[2].isscalar)
14143 do_neon_mac_maybe_scalar ();
14144 else
14145 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
14146 }
14147
14148 static void
14149 do_neon_qdmulh (void)
14150 {
14151 if (inst.operands[2].isscalar)
14152 {
14153 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
14154 struct neon_type_el et = neon_check_type (3, rs,
14155 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14156 NEON_ENCODE (SCALAR, inst);
14157 neon_mul_mac (et, neon_quad (rs));
14158 }
14159 else
14160 {
14161 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14162 struct neon_type_el et = neon_check_type (3, rs,
14163 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
14164 NEON_ENCODE (INTEGER, inst);
14165 /* The U bit (rounding) comes from bit mask. */
14166 neon_three_same (neon_quad (rs), 0, et.size);
14167 }
14168 }
14169
14170 static void
14171 do_neon_fcmp_absolute (void)
14172 {
14173 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14174 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14175 /* Size field comes from bit mask. */
14176 neon_three_same (neon_quad (rs), 1, -1);
14177 }
14178
14179 static void
14180 do_neon_fcmp_absolute_inv (void)
14181 {
14182 neon_exchange_operands ();
14183 do_neon_fcmp_absolute ();
14184 }
14185
14186 static void
14187 do_neon_step (void)
14188 {
14189 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
14190 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
14191 neon_three_same (neon_quad (rs), 0, -1);
14192 }
14193
14194 static void
14195 do_neon_abs_neg (void)
14196 {
14197 enum neon_shape rs;
14198 struct neon_type_el et;
14199
14200 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
14201 return;
14202
14203 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14204 return;
14205
14206 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14207 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
14208
14209 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14210 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14211 inst.instruction |= LOW4 (inst.operands[1].reg);
14212 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14213 inst.instruction |= neon_quad (rs) << 6;
14214 inst.instruction |= (et.type == NT_float) << 10;
14215 inst.instruction |= neon_logbits (et.size) << 18;
14216
14217 neon_dp_fixup (&inst);
14218 }
14219
14220 static void
14221 do_neon_sli (void)
14222 {
14223 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14224 struct neon_type_el et = neon_check_type (2, rs,
14225 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14226 int imm = inst.operands[2].imm;
14227 constraint (imm < 0 || (unsigned)imm >= et.size,
14228 _("immediate out of range for insert"));
14229 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14230 }
14231
14232 static void
14233 do_neon_sri (void)
14234 {
14235 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14236 struct neon_type_el et = neon_check_type (2, rs,
14237 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14238 int imm = inst.operands[2].imm;
14239 constraint (imm < 1 || (unsigned)imm > et.size,
14240 _("immediate out of range for insert"));
14241 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
14242 }
14243
14244 static void
14245 do_neon_qshlu_imm (void)
14246 {
14247 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14248 struct neon_type_el et = neon_check_type (2, rs,
14249 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
14250 int imm = inst.operands[2].imm;
14251 constraint (imm < 0 || (unsigned)imm >= et.size,
14252 _("immediate out of range for shift"));
14253 /* Only encodes the 'U present' variant of the instruction.
14254 In this case, signed types have OP (bit 8) set to 0.
14255 Unsigned types have OP set to 1. */
14256 inst.instruction |= (et.type == NT_unsigned) << 8;
14257 /* The rest of the bits are the same as other immediate shifts. */
14258 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
14259 }
14260
14261 static void
14262 do_neon_qmovn (void)
14263 {
14264 struct neon_type_el et = neon_check_type (2, NS_DQ,
14265 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14266 /* Saturating move where operands can be signed or unsigned, and the
14267 destination has the same signedness. */
14268 NEON_ENCODE (INTEGER, inst);
14269 if (et.type == NT_unsigned)
14270 inst.instruction |= 0xc0;
14271 else
14272 inst.instruction |= 0x80;
14273 neon_two_same (0, 1, et.size / 2);
14274 }
14275
14276 static void
14277 do_neon_qmovun (void)
14278 {
14279 struct neon_type_el et = neon_check_type (2, NS_DQ,
14280 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14281 /* Saturating move with unsigned results. Operands must be signed. */
14282 NEON_ENCODE (INTEGER, inst);
14283 neon_two_same (0, 1, et.size / 2);
14284 }
14285
14286 static void
14287 do_neon_rshift_sat_narrow (void)
14288 {
14289 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14290 or unsigned. If operands are unsigned, results must also be unsigned. */
14291 struct neon_type_el et = neon_check_type (2, NS_DQI,
14292 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
14293 int imm = inst.operands[2].imm;
14294 /* This gets the bounds check, size encoding and immediate bits calculation
14295 right. */
14296 et.size /= 2;
14297
14298 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
14299 VQMOVN.I<size> <Dd>, <Qm>. */
14300 if (imm == 0)
14301 {
14302 inst.operands[2].present = 0;
14303 inst.instruction = N_MNEM_vqmovn;
14304 do_neon_qmovn ();
14305 return;
14306 }
14307
14308 constraint (imm < 1 || (unsigned)imm > et.size,
14309 _("immediate out of range"));
14310 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
14311 }
14312
14313 static void
14314 do_neon_rshift_sat_narrow_u (void)
14315 {
14316 /* FIXME: Types for narrowing. If operands are signed, results can be signed
14317 or unsigned. If operands are unsigned, results must also be unsigned. */
14318 struct neon_type_el et = neon_check_type (2, NS_DQI,
14319 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
14320 int imm = inst.operands[2].imm;
14321 /* This gets the bounds check, size encoding and immediate bits calculation
14322 right. */
14323 et.size /= 2;
14324
14325 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
14326 VQMOVUN.I<size> <Dd>, <Qm>. */
14327 if (imm == 0)
14328 {
14329 inst.operands[2].present = 0;
14330 inst.instruction = N_MNEM_vqmovun;
14331 do_neon_qmovun ();
14332 return;
14333 }
14334
14335 constraint (imm < 1 || (unsigned)imm > et.size,
14336 _("immediate out of range"));
14337 /* FIXME: The manual is kind of unclear about what value U should have in
14338 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
14339 must be 1. */
14340 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
14341 }
14342
14343 static void
14344 do_neon_movn (void)
14345 {
14346 struct neon_type_el et = neon_check_type (2, NS_DQ,
14347 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14348 NEON_ENCODE (INTEGER, inst);
14349 neon_two_same (0, 1, et.size / 2);
14350 }
14351
14352 static void
14353 do_neon_rshift_narrow (void)
14354 {
14355 struct neon_type_el et = neon_check_type (2, NS_DQI,
14356 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
14357 int imm = inst.operands[2].imm;
14358 /* This gets the bounds check, size encoding and immediate bits calculation
14359 right. */
14360 et.size /= 2;
14361
14362 /* If immediate is zero then we are a pseudo-instruction for
14363 VMOVN.I<size> <Dd>, <Qm> */
14364 if (imm == 0)
14365 {
14366 inst.operands[2].present = 0;
14367 inst.instruction = N_MNEM_vmovn;
14368 do_neon_movn ();
14369 return;
14370 }
14371
14372 constraint (imm < 1 || (unsigned)imm > et.size,
14373 _("immediate out of range for narrowing operation"));
14374 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
14375 }
14376
14377 static void
14378 do_neon_shll (void)
14379 {
14380 /* FIXME: Type checking when lengthening. */
14381 struct neon_type_el et = neon_check_type (2, NS_QDI,
14382 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
14383 unsigned imm = inst.operands[2].imm;
14384
14385 if (imm == et.size)
14386 {
14387 /* Maximum shift variant. */
14388 NEON_ENCODE (INTEGER, inst);
14389 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14390 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14391 inst.instruction |= LOW4 (inst.operands[1].reg);
14392 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14393 inst.instruction |= neon_logbits (et.size) << 18;
14394
14395 neon_dp_fixup (&inst);
14396 }
14397 else
14398 {
14399 /* A more-specific type check for non-max versions. */
14400 et = neon_check_type (2, NS_QDI,
14401 N_EQK | N_DBL, N_SU_32 | N_KEY);
14402 NEON_ENCODE (IMMED, inst);
14403 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
14404 }
14405 }
14406
14407 /* Check the various types for the VCVT instruction, and return which version
14408 the current instruction is. */
14409
14410 static int
14411 neon_cvt_flavour (enum neon_shape rs)
14412 {
14413 #define CVT_VAR(C,X,Y) \
14414 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
14415 if (et.type != NT_invtype) \
14416 { \
14417 inst.error = NULL; \
14418 return (C); \
14419 }
14420 struct neon_type_el et;
14421 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
14422 || rs == NS_FF) ? N_VFP : 0;
14423 /* The instruction versions which take an immediate take one register
14424 argument, which is extended to the width of the full register. Thus the
14425 "source" and "destination" registers must have the same width. Hack that
14426 here by making the size equal to the key (wider, in this case) operand. */
14427 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
14428
14429 CVT_VAR (0, N_S32, N_F32);
14430 CVT_VAR (1, N_U32, N_F32);
14431 CVT_VAR (2, N_F32, N_S32);
14432 CVT_VAR (3, N_F32, N_U32);
14433 /* Half-precision conversions. */
14434 CVT_VAR (4, N_F32, N_F16);
14435 CVT_VAR (5, N_F16, N_F32);
14436
14437 whole_reg = N_VFP;
14438
14439 /* VFP instructions. */
14440 CVT_VAR (6, N_F32, N_F64);
14441 CVT_VAR (7, N_F64, N_F32);
14442 CVT_VAR (8, N_S32, N_F64 | key);
14443 CVT_VAR (9, N_U32, N_F64 | key);
14444 CVT_VAR (10, N_F64 | key, N_S32);
14445 CVT_VAR (11, N_F64 | key, N_U32);
14446 /* VFP instructions with bitshift. */
14447 CVT_VAR (12, N_F32 | key, N_S16);
14448 CVT_VAR (13, N_F32 | key, N_U16);
14449 CVT_VAR (14, N_F64 | key, N_S16);
14450 CVT_VAR (15, N_F64 | key, N_U16);
14451 CVT_VAR (16, N_S16, N_F32 | key);
14452 CVT_VAR (17, N_U16, N_F32 | key);
14453 CVT_VAR (18, N_S16, N_F64 | key);
14454 CVT_VAR (19, N_U16, N_F64 | key);
14455
14456 return -1;
14457 #undef CVT_VAR
14458 }
14459
14460 /* Neon-syntax VFP conversions. */
14461
14462 static void
14463 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
14464 {
14465 const char *opname = 0;
14466
14467 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
14468 {
14469 /* Conversions with immediate bitshift. */
14470 const char *enc[] =
14471 {
14472 "ftosls",
14473 "ftouls",
14474 "fsltos",
14475 "fultos",
14476 NULL,
14477 NULL,
14478 NULL,
14479 NULL,
14480 "ftosld",
14481 "ftould",
14482 "fsltod",
14483 "fultod",
14484 "fshtos",
14485 "fuhtos",
14486 "fshtod",
14487 "fuhtod",
14488 "ftoshs",
14489 "ftouhs",
14490 "ftoshd",
14491 "ftouhd"
14492 };
14493
14494 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14495 {
14496 opname = enc[flavour];
14497 constraint (inst.operands[0].reg != inst.operands[1].reg,
14498 _("operands 0 and 1 must be the same register"));
14499 inst.operands[1] = inst.operands[2];
14500 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
14501 }
14502 }
14503 else
14504 {
14505 /* Conversions without bitshift. */
14506 const char *enc[] =
14507 {
14508 "ftosis",
14509 "ftouis",
14510 "fsitos",
14511 "fuitos",
14512 "NULL",
14513 "NULL",
14514 "fcvtsd",
14515 "fcvtds",
14516 "ftosid",
14517 "ftouid",
14518 "fsitod",
14519 "fuitod"
14520 };
14521
14522 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
14523 opname = enc[flavour];
14524 }
14525
14526 if (opname)
14527 do_vfp_nsyn_opcode (opname);
14528 }
14529
14530 static void
14531 do_vfp_nsyn_cvtz (void)
14532 {
14533 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
14534 int flavour = neon_cvt_flavour (rs);
14535 const char *enc[] =
14536 {
14537 "ftosizs",
14538 "ftouizs",
14539 NULL,
14540 NULL,
14541 NULL,
14542 NULL,
14543 NULL,
14544 NULL,
14545 "ftosizd",
14546 "ftouizd"
14547 };
14548
14549 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
14550 do_vfp_nsyn_opcode (enc[flavour]);
14551 }
14552
14553 static void
14554 do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
14555 {
14556 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
14557 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
14558 int flavour = neon_cvt_flavour (rs);
14559
14560 /* PR11109: Handle round-to-zero for VCVT conversions. */
14561 if (round_to_zero
14562 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
14563 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
14564 && (rs == NS_FD || rs == NS_FF))
14565 {
14566 do_vfp_nsyn_cvtz ();
14567 return;
14568 }
14569
14570 /* VFP rather than Neon conversions. */
14571 if (flavour >= 6)
14572 {
14573 do_vfp_nsyn_cvt (rs, flavour);
14574 return;
14575 }
14576
14577 switch (rs)
14578 {
14579 case NS_DDI:
14580 case NS_QQI:
14581 {
14582 unsigned immbits;
14583 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
14584
14585 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14586 return;
14587
14588 /* Fixed-point conversion with #0 immediate is encoded as an
14589 integer conversion. */
14590 if (inst.operands[2].present && inst.operands[2].imm == 0)
14591 goto int_encode;
14592 immbits = 32 - inst.operands[2].imm;
14593 NEON_ENCODE (IMMED, inst);
14594 if (flavour != -1)
14595 inst.instruction |= enctab[flavour];
14596 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14597 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14598 inst.instruction |= LOW4 (inst.operands[1].reg);
14599 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14600 inst.instruction |= neon_quad (rs) << 6;
14601 inst.instruction |= 1 << 21;
14602 inst.instruction |= immbits << 16;
14603
14604 neon_dp_fixup (&inst);
14605 }
14606 break;
14607
14608 case NS_DD:
14609 case NS_QQ:
14610 int_encode:
14611 {
14612 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
14613
14614 NEON_ENCODE (INTEGER, inst);
14615
14616 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14617 return;
14618
14619 if (flavour != -1)
14620 inst.instruction |= enctab[flavour];
14621
14622 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14623 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14624 inst.instruction |= LOW4 (inst.operands[1].reg);
14625 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14626 inst.instruction |= neon_quad (rs) << 6;
14627 inst.instruction |= 2 << 18;
14628
14629 neon_dp_fixup (&inst);
14630 }
14631 break;
14632
14633 /* Half-precision conversions for Advanced SIMD -- neon. */
14634 case NS_QD:
14635 case NS_DQ:
14636
14637 if ((rs == NS_DQ)
14638 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
14639 {
14640 as_bad (_("operand size must match register width"));
14641 break;
14642 }
14643
14644 if ((rs == NS_QD)
14645 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
14646 {
14647 as_bad (_("operand size must match register width"));
14648 break;
14649 }
14650
14651 if (rs == NS_DQ)
14652 inst.instruction = 0x3b60600;
14653 else
14654 inst.instruction = 0x3b60700;
14655
14656 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14657 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14658 inst.instruction |= LOW4 (inst.operands[1].reg);
14659 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14660 neon_dp_fixup (&inst);
14661 break;
14662
14663 default:
14664 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
14665 do_vfp_nsyn_cvt (rs, flavour);
14666 }
14667 }
14668
14669 static void
14670 do_neon_cvtr (void)
14671 {
14672 do_neon_cvt_1 (FALSE);
14673 }
14674
14675 static void
14676 do_neon_cvt (void)
14677 {
14678 do_neon_cvt_1 (TRUE);
14679 }
14680
14681 static void
14682 do_neon_cvtb (void)
14683 {
14684 inst.instruction = 0xeb20a40;
14685
14686 /* The sizes are attached to the mnemonic. */
14687 if (inst.vectype.el[0].type != NT_invtype
14688 && inst.vectype.el[0].size == 16)
14689 inst.instruction |= 0x00010000;
14690
14691 /* Programmer's syntax: the sizes are attached to the operands. */
14692 else if (inst.operands[0].vectype.type != NT_invtype
14693 && inst.operands[0].vectype.size == 16)
14694 inst.instruction |= 0x00010000;
14695
14696 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14697 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14698 do_vfp_cond_or_thumb ();
14699 }
14700
14701
14702 static void
14703 do_neon_cvtt (void)
14704 {
14705 do_neon_cvtb ();
14706 inst.instruction |= 0x80;
14707 }
14708
14709 static void
14710 neon_move_immediate (void)
14711 {
14712 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14713 struct neon_type_el et = neon_check_type (2, rs,
14714 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14715 unsigned immlo, immhi = 0, immbits;
14716 int op, cmode, float_p;
14717
14718 constraint (et.type == NT_invtype,
14719 _("operand size must be specified for immediate VMOV"));
14720
14721 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14722 op = (inst.instruction & (1 << 5)) != 0;
14723
14724 immlo = inst.operands[1].imm;
14725 if (inst.operands[1].regisimm)
14726 immhi = inst.operands[1].reg;
14727
14728 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14729 _("immediate has bits set outside the operand size"));
14730
14731 float_p = inst.operands[1].immisfloat;
14732
14733 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
14734 et.size, et.type)) == FAIL)
14735 {
14736 /* Invert relevant bits only. */
14737 neon_invert_size (&immlo, &immhi, et.size);
14738 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14739 with one or the other; those cases are caught by
14740 neon_cmode_for_move_imm. */
14741 op = !op;
14742 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14743 &op, et.size, et.type)) == FAIL)
14744 {
14745 first_error (_("immediate out of range"));
14746 return;
14747 }
14748 }
14749
14750 inst.instruction &= ~(1 << 5);
14751 inst.instruction |= op << 5;
14752
14753 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14754 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14755 inst.instruction |= neon_quad (rs) << 6;
14756 inst.instruction |= cmode << 8;
14757
14758 neon_write_immbits (immbits);
14759 }
14760
14761 static void
14762 do_neon_mvn (void)
14763 {
14764 if (inst.operands[1].isreg)
14765 {
14766 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14767
14768 NEON_ENCODE (INTEGER, inst);
14769 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14770 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14771 inst.instruction |= LOW4 (inst.operands[1].reg);
14772 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14773 inst.instruction |= neon_quad (rs) << 6;
14774 }
14775 else
14776 {
14777 NEON_ENCODE (IMMED, inst);
14778 neon_move_immediate ();
14779 }
14780
14781 neon_dp_fixup (&inst);
14782 }
14783
14784 /* Encode instructions of form:
14785
14786 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14787 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
14788
14789 static void
14790 neon_mixed_length (struct neon_type_el et, unsigned size)
14791 {
14792 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14793 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14794 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14795 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14796 inst.instruction |= LOW4 (inst.operands[2].reg);
14797 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14798 inst.instruction |= (et.type == NT_unsigned) << 24;
14799 inst.instruction |= neon_logbits (size) << 20;
14800
14801 neon_dp_fixup (&inst);
14802 }
14803
14804 static void
14805 do_neon_dyadic_long (void)
14806 {
14807 /* FIXME: Type checking for lengthening op. */
14808 struct neon_type_el et = neon_check_type (3, NS_QDD,
14809 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14810 neon_mixed_length (et, et.size);
14811 }
14812
14813 static void
14814 do_neon_abal (void)
14815 {
14816 struct neon_type_el et = neon_check_type (3, NS_QDD,
14817 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14818 neon_mixed_length (et, et.size);
14819 }
14820
14821 static void
14822 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14823 {
14824 if (inst.operands[2].isscalar)
14825 {
14826 struct neon_type_el et = neon_check_type (3, NS_QDS,
14827 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
14828 NEON_ENCODE (SCALAR, inst);
14829 neon_mul_mac (et, et.type == NT_unsigned);
14830 }
14831 else
14832 {
14833 struct neon_type_el et = neon_check_type (3, NS_QDD,
14834 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
14835 NEON_ENCODE (INTEGER, inst);
14836 neon_mixed_length (et, et.size);
14837 }
14838 }
14839
14840 static void
14841 do_neon_mac_maybe_scalar_long (void)
14842 {
14843 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14844 }
14845
14846 static void
14847 do_neon_dyadic_wide (void)
14848 {
14849 struct neon_type_el et = neon_check_type (3, NS_QQD,
14850 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14851 neon_mixed_length (et, et.size);
14852 }
14853
14854 static void
14855 do_neon_dyadic_narrow (void)
14856 {
14857 struct neon_type_el et = neon_check_type (3, NS_QDD,
14858 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
14859 /* Operand sign is unimportant, and the U bit is part of the opcode,
14860 so force the operand type to integer. */
14861 et.type = NT_integer;
14862 neon_mixed_length (et, et.size / 2);
14863 }
14864
14865 static void
14866 do_neon_mul_sat_scalar_long (void)
14867 {
14868 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14869 }
14870
14871 static void
14872 do_neon_vmull (void)
14873 {
14874 if (inst.operands[2].isscalar)
14875 do_neon_mac_maybe_scalar_long ();
14876 else
14877 {
14878 struct neon_type_el et = neon_check_type (3, NS_QDD,
14879 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14880 if (et.type == NT_poly)
14881 NEON_ENCODE (POLY, inst);
14882 else
14883 NEON_ENCODE (INTEGER, inst);
14884 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14885 zero. Should be OK as-is. */
14886 neon_mixed_length (et, et.size);
14887 }
14888 }
14889
14890 static void
14891 do_neon_ext (void)
14892 {
14893 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
14894 struct neon_type_el et = neon_check_type (3, rs,
14895 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14896 unsigned imm = (inst.operands[3].imm * et.size) / 8;
14897
14898 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14899 _("shift out of range"));
14900 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14901 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14902 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14903 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14904 inst.instruction |= LOW4 (inst.operands[2].reg);
14905 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14906 inst.instruction |= neon_quad (rs) << 6;
14907 inst.instruction |= imm << 8;
14908
14909 neon_dp_fixup (&inst);
14910 }
14911
14912 static void
14913 do_neon_rev (void)
14914 {
14915 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14916 struct neon_type_el et = neon_check_type (2, rs,
14917 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14918 unsigned op = (inst.instruction >> 7) & 3;
14919 /* N (width of reversed regions) is encoded as part of the bitmask. We
14920 extract it here to check the elements to be reversed are smaller.
14921 Otherwise we'd get a reserved instruction. */
14922 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
14923 gas_assert (elsize != 0);
14924 constraint (et.size >= elsize,
14925 _("elements must be smaller than reversal region"));
14926 neon_two_same (neon_quad (rs), 1, et.size);
14927 }
14928
14929 static void
14930 do_neon_dup (void)
14931 {
14932 if (inst.operands[1].isscalar)
14933 {
14934 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
14935 struct neon_type_el et = neon_check_type (2, rs,
14936 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14937 unsigned sizebits = et.size >> 3;
14938 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
14939 int logsize = neon_logbits (et.size);
14940 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
14941
14942 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14943 return;
14944
14945 NEON_ENCODE (SCALAR, inst);
14946 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14947 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14948 inst.instruction |= LOW4 (dm);
14949 inst.instruction |= HI1 (dm) << 5;
14950 inst.instruction |= neon_quad (rs) << 6;
14951 inst.instruction |= x << 17;
14952 inst.instruction |= sizebits << 16;
14953
14954 neon_dp_fixup (&inst);
14955 }
14956 else
14957 {
14958 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14959 struct neon_type_el et = neon_check_type (2, rs,
14960 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14961 /* Duplicate ARM register to lanes of vector. */
14962 NEON_ENCODE (ARMREG, inst);
14963 switch (et.size)
14964 {
14965 case 8: inst.instruction |= 0x400000; break;
14966 case 16: inst.instruction |= 0x000020; break;
14967 case 32: inst.instruction |= 0x000000; break;
14968 default: break;
14969 }
14970 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14971 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14972 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
14973 inst.instruction |= neon_quad (rs) << 21;
14974 /* The encoding for this instruction is identical for the ARM and Thumb
14975 variants, except for the condition field. */
14976 do_vfp_cond_or_thumb ();
14977 }
14978 }
14979
14980 /* VMOV has particularly many variations. It can be one of:
14981 0. VMOV<c><q> <Qd>, <Qm>
14982 1. VMOV<c><q> <Dd>, <Dm>
14983 (Register operations, which are VORR with Rm = Rn.)
14984 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14985 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14986 (Immediate loads.)
14987 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14988 (ARM register to scalar.)
14989 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14990 (Two ARM registers to vector.)
14991 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14992 (Scalar to ARM register.)
14993 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14994 (Vector to two ARM registers.)
14995 8. VMOV.F32 <Sd>, <Sm>
14996 9. VMOV.F64 <Dd>, <Dm>
14997 (VFP register moves.)
14998 10. VMOV.F32 <Sd>, #imm
14999 11. VMOV.F64 <Dd>, #imm
15000 (VFP float immediate load.)
15001 12. VMOV <Rd>, <Sm>
15002 (VFP single to ARM reg.)
15003 13. VMOV <Sd>, <Rm>
15004 (ARM reg to VFP single.)
15005 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
15006 (Two ARM regs to two VFP singles.)
15007 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
15008 (Two VFP singles to two ARM regs.)
15009
15010 These cases can be disambiguated using neon_select_shape, except cases 1/9
15011 and 3/11 which depend on the operand type too.
15012
15013 All the encoded bits are hardcoded by this function.
15014
15015 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
15016 Cases 5, 7 may be used with VFPv2 and above.
15017
15018 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
15019 can specify a type where it doesn't make sense to, and is ignored). */
15020
15021 static void
15022 do_neon_mov (void)
15023 {
15024 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
15025 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
15026 NS_NULL);
15027 struct neon_type_el et;
15028 const char *ldconst = 0;
15029
15030 switch (rs)
15031 {
15032 case NS_DD: /* case 1/9. */
15033 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15034 /* It is not an error here if no type is given. */
15035 inst.error = NULL;
15036 if (et.type == NT_float && et.size == 64)
15037 {
15038 do_vfp_nsyn_opcode ("fcpyd");
15039 break;
15040 }
15041 /* fall through. */
15042
15043 case NS_QQ: /* case 0/1. */
15044 {
15045 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15046 return;
15047 /* The architecture manual I have doesn't explicitly state which
15048 value the U bit should have for register->register moves, but
15049 the equivalent VORR instruction has U = 0, so do that. */
15050 inst.instruction = 0x0200110;
15051 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15052 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15053 inst.instruction |= LOW4 (inst.operands[1].reg);
15054 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
15055 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15056 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15057 inst.instruction |= neon_quad (rs) << 6;
15058
15059 neon_dp_fixup (&inst);
15060 }
15061 break;
15062
15063 case NS_DI: /* case 3/11. */
15064 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
15065 inst.error = NULL;
15066 if (et.type == NT_float && et.size == 64)
15067 {
15068 /* case 11 (fconstd). */
15069 ldconst = "fconstd";
15070 goto encode_fconstd;
15071 }
15072 /* fall through. */
15073
15074 case NS_QI: /* case 2/3. */
15075 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
15076 return;
15077 inst.instruction = 0x0800010;
15078 neon_move_immediate ();
15079 neon_dp_fixup (&inst);
15080 break;
15081
15082 case NS_SR: /* case 4. */
15083 {
15084 unsigned bcdebits = 0;
15085 int logsize;
15086 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
15087 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
15088
15089 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
15090 logsize = neon_logbits (et.size);
15091
15092 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15093 _(BAD_FPU));
15094 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15095 && et.size != 32, _(BAD_FPU));
15096 constraint (et.type == NT_invtype, _("bad type for scalar"));
15097 constraint (x >= 64 / et.size, _("scalar index out of range"));
15098
15099 switch (et.size)
15100 {
15101 case 8: bcdebits = 0x8; break;
15102 case 16: bcdebits = 0x1; break;
15103 case 32: bcdebits = 0x0; break;
15104 default: ;
15105 }
15106
15107 bcdebits |= x << logsize;
15108
15109 inst.instruction = 0xe000b10;
15110 do_vfp_cond_or_thumb ();
15111 inst.instruction |= LOW4 (dn) << 16;
15112 inst.instruction |= HI1 (dn) << 7;
15113 inst.instruction |= inst.operands[1].reg << 12;
15114 inst.instruction |= (bcdebits & 3) << 5;
15115 inst.instruction |= (bcdebits >> 2) << 21;
15116 }
15117 break;
15118
15119 case NS_DRR: /* case 5 (fmdrr). */
15120 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15121 _(BAD_FPU));
15122
15123 inst.instruction = 0xc400b10;
15124 do_vfp_cond_or_thumb ();
15125 inst.instruction |= LOW4 (inst.operands[0].reg);
15126 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
15127 inst.instruction |= inst.operands[1].reg << 12;
15128 inst.instruction |= inst.operands[2].reg << 16;
15129 break;
15130
15131 case NS_RS: /* case 6. */
15132 {
15133 unsigned logsize;
15134 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
15135 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
15136 unsigned abcdebits = 0;
15137
15138 et = neon_check_type (2, NS_NULL,
15139 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
15140 logsize = neon_logbits (et.size);
15141
15142 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
15143 _(BAD_FPU));
15144 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
15145 && et.size != 32, _(BAD_FPU));
15146 constraint (et.type == NT_invtype, _("bad type for scalar"));
15147 constraint (x >= 64 / et.size, _("scalar index out of range"));
15148
15149 switch (et.size)
15150 {
15151 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
15152 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
15153 case 32: abcdebits = 0x00; break;
15154 default: ;
15155 }
15156
15157 abcdebits |= x << logsize;
15158 inst.instruction = 0xe100b10;
15159 do_vfp_cond_or_thumb ();
15160 inst.instruction |= LOW4 (dn) << 16;
15161 inst.instruction |= HI1 (dn) << 7;
15162 inst.instruction |= inst.operands[0].reg << 12;
15163 inst.instruction |= (abcdebits & 3) << 5;
15164 inst.instruction |= (abcdebits >> 2) << 21;
15165 }
15166 break;
15167
15168 case NS_RRD: /* case 7 (fmrrd). */
15169 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
15170 _(BAD_FPU));
15171
15172 inst.instruction = 0xc500b10;
15173 do_vfp_cond_or_thumb ();
15174 inst.instruction |= inst.operands[0].reg << 12;
15175 inst.instruction |= inst.operands[1].reg << 16;
15176 inst.instruction |= LOW4 (inst.operands[2].reg);
15177 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15178 break;
15179
15180 case NS_FF: /* case 8 (fcpys). */
15181 do_vfp_nsyn_opcode ("fcpys");
15182 break;
15183
15184 case NS_FI: /* case 10 (fconsts). */
15185 ldconst = "fconsts";
15186 encode_fconstd:
15187 if (is_quarter_float (inst.operands[1].imm))
15188 {
15189 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
15190 do_vfp_nsyn_opcode (ldconst);
15191 }
15192 else
15193 first_error (_("immediate out of range"));
15194 break;
15195
15196 case NS_RF: /* case 12 (fmrs). */
15197 do_vfp_nsyn_opcode ("fmrs");
15198 break;
15199
15200 case NS_FR: /* case 13 (fmsr). */
15201 do_vfp_nsyn_opcode ("fmsr");
15202 break;
15203
15204 /* The encoders for the fmrrs and fmsrr instructions expect three operands
15205 (one of which is a list), but we have parsed four. Do some fiddling to
15206 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
15207 expect. */
15208 case NS_RRFF: /* case 14 (fmrrs). */
15209 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
15210 _("VFP registers must be adjacent"));
15211 inst.operands[2].imm = 2;
15212 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15213 do_vfp_nsyn_opcode ("fmrrs");
15214 break;
15215
15216 case NS_FFRR: /* case 15 (fmsrr). */
15217 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
15218 _("VFP registers must be adjacent"));
15219 inst.operands[1] = inst.operands[2];
15220 inst.operands[2] = inst.operands[3];
15221 inst.operands[0].imm = 2;
15222 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
15223 do_vfp_nsyn_opcode ("fmsrr");
15224 break;
15225
15226 default:
15227 abort ();
15228 }
15229 }
15230
15231 static void
15232 do_neon_rshift_round_imm (void)
15233 {
15234 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
15235 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
15236 int imm = inst.operands[2].imm;
15237
15238 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
15239 if (imm == 0)
15240 {
15241 inst.operands[2].present = 0;
15242 do_neon_mov ();
15243 return;
15244 }
15245
15246 constraint (imm < 1 || (unsigned)imm > et.size,
15247 _("immediate out of range for shift"));
15248 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
15249 et.size - imm);
15250 }
15251
15252 static void
15253 do_neon_movl (void)
15254 {
15255 struct neon_type_el et = neon_check_type (2, NS_QD,
15256 N_EQK | N_DBL, N_SU_32 | N_KEY);
15257 unsigned sizebits = et.size >> 3;
15258 inst.instruction |= sizebits << 19;
15259 neon_two_same (0, et.type == NT_unsigned, -1);
15260 }
15261
15262 static void
15263 do_neon_trn (void)
15264 {
15265 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15266 struct neon_type_el et = neon_check_type (2, rs,
15267 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15268 NEON_ENCODE (INTEGER, inst);
15269 neon_two_same (neon_quad (rs), 1, et.size);
15270 }
15271
15272 static void
15273 do_neon_zip_uzp (void)
15274 {
15275 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15276 struct neon_type_el et = neon_check_type (2, rs,
15277 N_EQK, N_8 | N_16 | N_32 | N_KEY);
15278 if (rs == NS_DD && et.size == 32)
15279 {
15280 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
15281 inst.instruction = N_MNEM_vtrn;
15282 do_neon_trn ();
15283 return;
15284 }
15285 neon_two_same (neon_quad (rs), 1, et.size);
15286 }
15287
15288 static void
15289 do_neon_sat_abs_neg (void)
15290 {
15291 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15292 struct neon_type_el et = neon_check_type (2, rs,
15293 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15294 neon_two_same (neon_quad (rs), 1, et.size);
15295 }
15296
15297 static void
15298 do_neon_pair_long (void)
15299 {
15300 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15301 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
15302 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
15303 inst.instruction |= (et.type == NT_unsigned) << 7;
15304 neon_two_same (neon_quad (rs), 1, et.size);
15305 }
15306
15307 static void
15308 do_neon_recip_est (void)
15309 {
15310 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15311 struct neon_type_el et = neon_check_type (2, rs,
15312 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
15313 inst.instruction |= (et.type == NT_float) << 8;
15314 neon_two_same (neon_quad (rs), 1, et.size);
15315 }
15316
15317 static void
15318 do_neon_cls (void)
15319 {
15320 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15321 struct neon_type_el et = neon_check_type (2, rs,
15322 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
15323 neon_two_same (neon_quad (rs), 1, et.size);
15324 }
15325
15326 static void
15327 do_neon_clz (void)
15328 {
15329 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15330 struct neon_type_el et = neon_check_type (2, rs,
15331 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
15332 neon_two_same (neon_quad (rs), 1, et.size);
15333 }
15334
15335 static void
15336 do_neon_cnt (void)
15337 {
15338 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15339 struct neon_type_el et = neon_check_type (2, rs,
15340 N_EQK | N_INT, N_8 | N_KEY);
15341 neon_two_same (neon_quad (rs), 1, et.size);
15342 }
15343
15344 static void
15345 do_neon_swp (void)
15346 {
15347 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
15348 neon_two_same (neon_quad (rs), 1, -1);
15349 }
15350
15351 static void
15352 do_neon_tbl_tbx (void)
15353 {
15354 unsigned listlenbits;
15355 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
15356
15357 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
15358 {
15359 first_error (_("bad list length for table lookup"));
15360 return;
15361 }
15362
15363 listlenbits = inst.operands[1].imm - 1;
15364 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15365 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15366 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
15367 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
15368 inst.instruction |= LOW4 (inst.operands[2].reg);
15369 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
15370 inst.instruction |= listlenbits << 8;
15371
15372 neon_dp_fixup (&inst);
15373 }
15374
15375 static void
15376 do_neon_ldm_stm (void)
15377 {
15378 /* P, U and L bits are part of bitmask. */
15379 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
15380 unsigned offsetbits = inst.operands[1].imm * 2;
15381
15382 if (inst.operands[1].issingle)
15383 {
15384 do_vfp_nsyn_ldm_stm (is_dbmode);
15385 return;
15386 }
15387
15388 constraint (is_dbmode && !inst.operands[0].writeback,
15389 _("writeback (!) must be used for VLDMDB and VSTMDB"));
15390
15391 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
15392 _("register list must contain at least 1 and at most 16 "
15393 "registers"));
15394
15395 inst.instruction |= inst.operands[0].reg << 16;
15396 inst.instruction |= inst.operands[0].writeback << 21;
15397 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
15398 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
15399
15400 inst.instruction |= offsetbits;
15401
15402 do_vfp_cond_or_thumb ();
15403 }
15404
15405 static void
15406 do_neon_ldr_str (void)
15407 {
15408 int is_ldr = (inst.instruction & (1 << 20)) != 0;
15409
15410 /* Use of PC in vstr in ARM mode is deprecated in ARMv7.
15411 And is UNPREDICTABLE in thumb mode. */
15412 if (!is_ldr
15413 && inst.operands[1].reg == REG_PC
15414 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v7))
15415 {
15416 if (!thumb_mode && warn_on_deprecated)
15417 as_warn (_("Use of PC here is deprecated"));
15418 else
15419 inst.error = _("Use of PC here is UNPREDICTABLE");
15420 }
15421
15422 if (inst.operands[0].issingle)
15423 {
15424 if (is_ldr)
15425 do_vfp_nsyn_opcode ("flds");
15426 else
15427 do_vfp_nsyn_opcode ("fsts");
15428 }
15429 else
15430 {
15431 if (is_ldr)
15432 do_vfp_nsyn_opcode ("fldd");
15433 else
15434 do_vfp_nsyn_opcode ("fstd");
15435 }
15436 }
15437
15438 /* "interleave" version also handles non-interleaving register VLD1/VST1
15439 instructions. */
15440
15441 static void
15442 do_neon_ld_st_interleave (void)
15443 {
15444 struct neon_type_el et = neon_check_type (1, NS_NULL,
15445 N_8 | N_16 | N_32 | N_64);
15446 unsigned alignbits = 0;
15447 unsigned idx;
15448 /* The bits in this table go:
15449 0: register stride of one (0) or two (1)
15450 1,2: register list length, minus one (1, 2, 3, 4).
15451 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
15452 We use -1 for invalid entries. */
15453 const int typetable[] =
15454 {
15455 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
15456 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
15457 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
15458 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
15459 };
15460 int typebits;
15461
15462 if (et.type == NT_invtype)
15463 return;
15464
15465 if (inst.operands[1].immisalign)
15466 switch (inst.operands[1].imm >> 8)
15467 {
15468 case 64: alignbits = 1; break;
15469 case 128:
15470 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
15471 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15472 goto bad_alignment;
15473 alignbits = 2;
15474 break;
15475 case 256:
15476 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
15477 goto bad_alignment;
15478 alignbits = 3;
15479 break;
15480 default:
15481 bad_alignment:
15482 first_error (_("bad alignment"));
15483 return;
15484 }
15485
15486 inst.instruction |= alignbits << 4;
15487 inst.instruction |= neon_logbits (et.size) << 6;
15488
15489 /* Bits [4:6] of the immediate in a list specifier encode register stride
15490 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
15491 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
15492 up the right value for "type" in a table based on this value and the given
15493 list style, then stick it back. */
15494 idx = ((inst.operands[0].imm >> 4) & 7)
15495 | (((inst.instruction >> 8) & 3) << 3);
15496
15497 typebits = typetable[idx];
15498
15499 constraint (typebits == -1, _("bad list type for instruction"));
15500
15501 inst.instruction &= ~0xf00;
15502 inst.instruction |= typebits << 8;
15503 }
15504
15505 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
15506 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
15507 otherwise. The variable arguments are a list of pairs of legal (size, align)
15508 values, terminated with -1. */
15509
15510 static int
15511 neon_alignment_bit (int size, int align, int *do_align, ...)
15512 {
15513 va_list ap;
15514 int result = FAIL, thissize, thisalign;
15515
15516 if (!inst.operands[1].immisalign)
15517 {
15518 *do_align = 0;
15519 return SUCCESS;
15520 }
15521
15522 va_start (ap, do_align);
15523
15524 do
15525 {
15526 thissize = va_arg (ap, int);
15527 if (thissize == -1)
15528 break;
15529 thisalign = va_arg (ap, int);
15530
15531 if (size == thissize && align == thisalign)
15532 result = SUCCESS;
15533 }
15534 while (result != SUCCESS);
15535
15536 va_end (ap);
15537
15538 if (result == SUCCESS)
15539 *do_align = 1;
15540 else
15541 first_error (_("unsupported alignment for instruction"));
15542
15543 return result;
15544 }
15545
15546 static void
15547 do_neon_ld_st_lane (void)
15548 {
15549 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15550 int align_good, do_align = 0;
15551 int logsize = neon_logbits (et.size);
15552 int align = inst.operands[1].imm >> 8;
15553 int n = (inst.instruction >> 8) & 3;
15554 int max_el = 64 / et.size;
15555
15556 if (et.type == NT_invtype)
15557 return;
15558
15559 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
15560 _("bad list length"));
15561 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
15562 _("scalar index out of range"));
15563 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
15564 && et.size == 8,
15565 _("stride of 2 unavailable when element size is 8"));
15566
15567 switch (n)
15568 {
15569 case 0: /* VLD1 / VST1. */
15570 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
15571 32, 32, -1);
15572 if (align_good == FAIL)
15573 return;
15574 if (do_align)
15575 {
15576 unsigned alignbits = 0;
15577 switch (et.size)
15578 {
15579 case 16: alignbits = 0x1; break;
15580 case 32: alignbits = 0x3; break;
15581 default: ;
15582 }
15583 inst.instruction |= alignbits << 4;
15584 }
15585 break;
15586
15587 case 1: /* VLD2 / VST2. */
15588 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
15589 32, 64, -1);
15590 if (align_good == FAIL)
15591 return;
15592 if (do_align)
15593 inst.instruction |= 1 << 4;
15594 break;
15595
15596 case 2: /* VLD3 / VST3. */
15597 constraint (inst.operands[1].immisalign,
15598 _("can't use alignment with this instruction"));
15599 break;
15600
15601 case 3: /* VLD4 / VST4. */
15602 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15603 16, 64, 32, 64, 32, 128, -1);
15604 if (align_good == FAIL)
15605 return;
15606 if (do_align)
15607 {
15608 unsigned alignbits = 0;
15609 switch (et.size)
15610 {
15611 case 8: alignbits = 0x1; break;
15612 case 16: alignbits = 0x1; break;
15613 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
15614 default: ;
15615 }
15616 inst.instruction |= alignbits << 4;
15617 }
15618 break;
15619
15620 default: ;
15621 }
15622
15623 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
15624 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15625 inst.instruction |= 1 << (4 + logsize);
15626
15627 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
15628 inst.instruction |= logsize << 10;
15629 }
15630
15631 /* Encode single n-element structure to all lanes VLD<n> instructions. */
15632
15633 static void
15634 do_neon_ld_dup (void)
15635 {
15636 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
15637 int align_good, do_align = 0;
15638
15639 if (et.type == NT_invtype)
15640 return;
15641
15642 switch ((inst.instruction >> 8) & 3)
15643 {
15644 case 0: /* VLD1. */
15645 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
15646 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15647 &do_align, 16, 16, 32, 32, -1);
15648 if (align_good == FAIL)
15649 return;
15650 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
15651 {
15652 case 1: break;
15653 case 2: inst.instruction |= 1 << 5; break;
15654 default: first_error (_("bad list length")); return;
15655 }
15656 inst.instruction |= neon_logbits (et.size) << 6;
15657 break;
15658
15659 case 1: /* VLD2. */
15660 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
15661 &do_align, 8, 16, 16, 32, 32, 64, -1);
15662 if (align_good == FAIL)
15663 return;
15664 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
15665 _("bad list length"));
15666 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15667 inst.instruction |= 1 << 5;
15668 inst.instruction |= neon_logbits (et.size) << 6;
15669 break;
15670
15671 case 2: /* VLD3. */
15672 constraint (inst.operands[1].immisalign,
15673 _("can't use alignment with this instruction"));
15674 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
15675 _("bad list length"));
15676 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15677 inst.instruction |= 1 << 5;
15678 inst.instruction |= neon_logbits (et.size) << 6;
15679 break;
15680
15681 case 3: /* VLD4. */
15682 {
15683 int align = inst.operands[1].imm >> 8;
15684 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
15685 16, 64, 32, 64, 32, 128, -1);
15686 if (align_good == FAIL)
15687 return;
15688 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
15689 _("bad list length"));
15690 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
15691 inst.instruction |= 1 << 5;
15692 if (et.size == 32 && align == 128)
15693 inst.instruction |= 0x3 << 6;
15694 else
15695 inst.instruction |= neon_logbits (et.size) << 6;
15696 }
15697 break;
15698
15699 default: ;
15700 }
15701
15702 inst.instruction |= do_align << 4;
15703 }
15704
15705 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
15706 apart from bits [11:4]. */
15707
15708 static void
15709 do_neon_ldx_stx (void)
15710 {
15711 if (inst.operands[1].isreg)
15712 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15713
15714 switch (NEON_LANE (inst.operands[0].imm))
15715 {
15716 case NEON_INTERLEAVE_LANES:
15717 NEON_ENCODE (INTERLV, inst);
15718 do_neon_ld_st_interleave ();
15719 break;
15720
15721 case NEON_ALL_LANES:
15722 NEON_ENCODE (DUP, inst);
15723 do_neon_ld_dup ();
15724 break;
15725
15726 default:
15727 NEON_ENCODE (LANE, inst);
15728 do_neon_ld_st_lane ();
15729 }
15730
15731 /* L bit comes from bit mask. */
15732 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15733 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15734 inst.instruction |= inst.operands[1].reg << 16;
15735
15736 if (inst.operands[1].postind)
15737 {
15738 int postreg = inst.operands[1].imm & 0xf;
15739 constraint (!inst.operands[1].immisreg,
15740 _("post-index must be a register"));
15741 constraint (postreg == 0xd || postreg == 0xf,
15742 _("bad register for post-index"));
15743 inst.instruction |= postreg;
15744 }
15745 else if (inst.operands[1].writeback)
15746 {
15747 inst.instruction |= 0xd;
15748 }
15749 else
15750 inst.instruction |= 0xf;
15751
15752 if (thumb_mode)
15753 inst.instruction |= 0xf9000000;
15754 else
15755 inst.instruction |= 0xf4000000;
15756 }
15757 \f
15758 /* Overall per-instruction processing. */
15759
15760 /* We need to be able to fix up arbitrary expressions in some statements.
15761 This is so that we can handle symbols that are an arbitrary distance from
15762 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15763 which returns part of an address in a form which will be valid for
15764 a data instruction. We do this by pushing the expression into a symbol
15765 in the expr_section, and creating a fix for that. */
15766
15767 static void
15768 fix_new_arm (fragS * frag,
15769 int where,
15770 short int size,
15771 expressionS * exp,
15772 int pc_rel,
15773 int reloc)
15774 {
15775 fixS * new_fix;
15776
15777 switch (exp->X_op)
15778 {
15779 case O_constant:
15780 if (pc_rel)
15781 {
15782 /* Create an absolute valued symbol, so we have something to
15783 refer to in the object file. Unfortunately for us, gas's
15784 generic expression parsing will already have folded out
15785 any use of .set foo/.type foo %function that may have
15786 been used to set type information of the target location,
15787 that's being specified symbolically. We have to presume
15788 the user knows what they are doing. */
15789 char name[16 + 8];
15790 symbolS *symbol;
15791
15792 sprintf (name, "*ABS*0x%lx", (unsigned long)exp->X_add_number);
15793
15794 symbol = symbol_find_or_make (name);
15795 S_SET_SEGMENT (symbol, absolute_section);
15796 symbol_set_frag (symbol, &zero_address_frag);
15797 S_SET_VALUE (symbol, exp->X_add_number);
15798 exp->X_op = O_symbol;
15799 exp->X_add_symbol = symbol;
15800 exp->X_add_number = 0;
15801 }
15802 /* FALLTHROUGH */
15803 case O_symbol:
15804 case O_add:
15805 case O_subtract:
15806 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15807 (enum bfd_reloc_code_real) reloc);
15808 break;
15809
15810 default:
15811 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15812 pc_rel, (enum bfd_reloc_code_real) reloc);
15813 break;
15814 }
15815
15816 /* Mark whether the fix is to a THUMB instruction, or an ARM
15817 instruction. */
15818 new_fix->tc_fix_data = thumb_mode;
15819 }
15820
15821 /* Create a frg for an instruction requiring relaxation. */
15822 static void
15823 output_relax_insn (void)
15824 {
15825 char * to;
15826 symbolS *sym;
15827 int offset;
15828
15829 /* The size of the instruction is unknown, so tie the debug info to the
15830 start of the instruction. */
15831 dwarf2_emit_insn (0);
15832
15833 switch (inst.reloc.exp.X_op)
15834 {
15835 case O_symbol:
15836 sym = inst.reloc.exp.X_add_symbol;
15837 offset = inst.reloc.exp.X_add_number;
15838 break;
15839 case O_constant:
15840 sym = NULL;
15841 offset = inst.reloc.exp.X_add_number;
15842 break;
15843 default:
15844 sym = make_expr_symbol (&inst.reloc.exp);
15845 offset = 0;
15846 break;
15847 }
15848 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15849 inst.relax, sym, offset, NULL/*offset, opcode*/);
15850 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
15851 }
15852
15853 /* Write a 32-bit thumb instruction to buf. */
15854 static void
15855 put_thumb32_insn (char * buf, unsigned long insn)
15856 {
15857 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15858 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15859 }
15860
15861 static void
15862 output_inst (const char * str)
15863 {
15864 char * to = NULL;
15865
15866 if (inst.error)
15867 {
15868 as_bad ("%s -- `%s'", inst.error, str);
15869 return;
15870 }
15871 if (inst.relax)
15872 {
15873 output_relax_insn ();
15874 return;
15875 }
15876 if (inst.size == 0)
15877 return;
15878
15879 to = frag_more (inst.size);
15880 /* PR 9814: Record the thumb mode into the current frag so that we know
15881 what type of NOP padding to use, if necessary. We override any previous
15882 setting so that if the mode has changed then the NOPS that we use will
15883 match the encoding of the last instruction in the frag. */
15884 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
15885
15886 if (thumb_mode && (inst.size > THUMB_SIZE))
15887 {
15888 gas_assert (inst.size == (2 * THUMB_SIZE));
15889 put_thumb32_insn (to, inst.instruction);
15890 }
15891 else if (inst.size > INSN_SIZE)
15892 {
15893 gas_assert (inst.size == (2 * INSN_SIZE));
15894 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15895 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
15896 }
15897 else
15898 md_number_to_chars (to, inst.instruction, inst.size);
15899
15900 if (inst.reloc.type != BFD_RELOC_UNUSED)
15901 fix_new_arm (frag_now, to - frag_now->fr_literal,
15902 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15903 inst.reloc.type);
15904
15905 dwarf2_emit_insn (inst.size);
15906 }
15907
15908 static char *
15909 output_it_inst (int cond, int mask, char * to)
15910 {
15911 unsigned long instruction = 0xbf00;
15912
15913 mask &= 0xf;
15914 instruction |= mask;
15915 instruction |= cond << 4;
15916
15917 if (to == NULL)
15918 {
15919 to = frag_more (2);
15920 #ifdef OBJ_ELF
15921 dwarf2_emit_insn (2);
15922 #endif
15923 }
15924
15925 md_number_to_chars (to, instruction, 2);
15926
15927 return to;
15928 }
15929
15930 /* Tag values used in struct asm_opcode's tag field. */
15931 enum opcode_tag
15932 {
15933 OT_unconditional, /* Instruction cannot be conditionalized.
15934 The ARM condition field is still 0xE. */
15935 OT_unconditionalF, /* Instruction cannot be conditionalized
15936 and carries 0xF in its ARM condition field. */
15937 OT_csuffix, /* Instruction takes a conditional suffix. */
15938 OT_csuffixF, /* Some forms of the instruction take a conditional
15939 suffix, others place 0xF where the condition field
15940 would be. */
15941 OT_cinfix3, /* Instruction takes a conditional infix,
15942 beginning at character index 3. (In
15943 unified mode, it becomes a suffix.) */
15944 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15945 tsts, cmps, cmns, and teqs. */
15946 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15947 character index 3, even in unified mode. Used for
15948 legacy instructions where suffix and infix forms
15949 may be ambiguous. */
15950 OT_csuf_or_in3, /* Instruction takes either a conditional
15951 suffix or an infix at character index 3. */
15952 OT_odd_infix_unc, /* This is the unconditional variant of an
15953 instruction that takes a conditional infix
15954 at an unusual position. In unified mode,
15955 this variant will accept a suffix. */
15956 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15957 are the conditional variants of instructions that
15958 take conditional infixes in unusual positions.
15959 The infix appears at character index
15960 (tag - OT_odd_infix_0). These are not accepted
15961 in unified mode. */
15962 };
15963
15964 /* Subroutine of md_assemble, responsible for looking up the primary
15965 opcode from the mnemonic the user wrote. STR points to the
15966 beginning of the mnemonic.
15967
15968 This is not simply a hash table lookup, because of conditional
15969 variants. Most instructions have conditional variants, which are
15970 expressed with a _conditional affix_ to the mnemonic. If we were
15971 to encode each conditional variant as a literal string in the opcode
15972 table, it would have approximately 20,000 entries.
15973
15974 Most mnemonics take this affix as a suffix, and in unified syntax,
15975 'most' is upgraded to 'all'. However, in the divided syntax, some
15976 instructions take the affix as an infix, notably the s-variants of
15977 the arithmetic instructions. Of those instructions, all but six
15978 have the infix appear after the third character of the mnemonic.
15979
15980 Accordingly, the algorithm for looking up primary opcodes given
15981 an identifier is:
15982
15983 1. Look up the identifier in the opcode table.
15984 If we find a match, go to step U.
15985
15986 2. Look up the last two characters of the identifier in the
15987 conditions table. If we find a match, look up the first N-2
15988 characters of the identifier in the opcode table. If we
15989 find a match, go to step CE.
15990
15991 3. Look up the fourth and fifth characters of the identifier in
15992 the conditions table. If we find a match, extract those
15993 characters from the identifier, and look up the remaining
15994 characters in the opcode table. If we find a match, go
15995 to step CM.
15996
15997 4. Fail.
15998
15999 U. Examine the tag field of the opcode structure, in case this is
16000 one of the six instructions with its conditional infix in an
16001 unusual place. If it is, the tag tells us where to find the
16002 infix; look it up in the conditions table and set inst.cond
16003 accordingly. Otherwise, this is an unconditional instruction.
16004 Again set inst.cond accordingly. Return the opcode structure.
16005
16006 CE. Examine the tag field to make sure this is an instruction that
16007 should receive a conditional suffix. If it is not, fail.
16008 Otherwise, set inst.cond from the suffix we already looked up,
16009 and return the opcode structure.
16010
16011 CM. Examine the tag field to make sure this is an instruction that
16012 should receive a conditional infix after the third character.
16013 If it is not, fail. Otherwise, undo the edits to the current
16014 line of input and proceed as for case CE. */
16015
16016 static const struct asm_opcode *
16017 opcode_lookup (char **str)
16018 {
16019 char *end, *base;
16020 char *affix;
16021 const struct asm_opcode *opcode;
16022 const struct asm_cond *cond;
16023 char save[2];
16024
16025 /* Scan up to the end of the mnemonic, which must end in white space,
16026 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
16027 for (base = end = *str; *end != '\0'; end++)
16028 if (*end == ' ' || *end == '.')
16029 break;
16030
16031 if (end == base)
16032 return NULL;
16033
16034 /* Handle a possible width suffix and/or Neon type suffix. */
16035 if (end[0] == '.')
16036 {
16037 int offset = 2;
16038
16039 /* The .w and .n suffixes are only valid if the unified syntax is in
16040 use. */
16041 if (unified_syntax && end[1] == 'w')
16042 inst.size_req = 4;
16043 else if (unified_syntax && end[1] == 'n')
16044 inst.size_req = 2;
16045 else
16046 offset = 0;
16047
16048 inst.vectype.elems = 0;
16049
16050 *str = end + offset;
16051
16052 if (end[offset] == '.')
16053 {
16054 /* See if we have a Neon type suffix (possible in either unified or
16055 non-unified ARM syntax mode). */
16056 if (parse_neon_type (&inst.vectype, str) == FAIL)
16057 return NULL;
16058 }
16059 else if (end[offset] != '\0' && end[offset] != ' ')
16060 return NULL;
16061 }
16062 else
16063 *str = end;
16064
16065 /* Look for unaffixed or special-case affixed mnemonic. */
16066 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16067 end - base);
16068 if (opcode)
16069 {
16070 /* step U */
16071 if (opcode->tag < OT_odd_infix_0)
16072 {
16073 inst.cond = COND_ALWAYS;
16074 return opcode;
16075 }
16076
16077 if (warn_on_deprecated && unified_syntax)
16078 as_warn (_("conditional infixes are deprecated in unified syntax"));
16079 affix = base + (opcode->tag - OT_odd_infix_0);
16080 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16081 gas_assert (cond);
16082
16083 inst.cond = cond->value;
16084 return opcode;
16085 }
16086
16087 /* Cannot have a conditional suffix on a mnemonic of less than two
16088 characters. */
16089 if (end - base < 3)
16090 return NULL;
16091
16092 /* Look for suffixed mnemonic. */
16093 affix = end - 2;
16094 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16095 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16096 affix - base);
16097 if (opcode && cond)
16098 {
16099 /* step CE */
16100 switch (opcode->tag)
16101 {
16102 case OT_cinfix3_legacy:
16103 /* Ignore conditional suffixes matched on infix only mnemonics. */
16104 break;
16105
16106 case OT_cinfix3:
16107 case OT_cinfix3_deprecated:
16108 case OT_odd_infix_unc:
16109 if (!unified_syntax)
16110 return 0;
16111 /* else fall through */
16112
16113 case OT_csuffix:
16114 case OT_csuffixF:
16115 case OT_csuf_or_in3:
16116 inst.cond = cond->value;
16117 return opcode;
16118
16119 case OT_unconditional:
16120 case OT_unconditionalF:
16121 if (thumb_mode)
16122 inst.cond = cond->value;
16123 else
16124 {
16125 /* Delayed diagnostic. */
16126 inst.error = BAD_COND;
16127 inst.cond = COND_ALWAYS;
16128 }
16129 return opcode;
16130
16131 default:
16132 return NULL;
16133 }
16134 }
16135
16136 /* Cannot have a usual-position infix on a mnemonic of less than
16137 six characters (five would be a suffix). */
16138 if (end - base < 6)
16139 return NULL;
16140
16141 /* Look for infixed mnemonic in the usual position. */
16142 affix = base + 3;
16143 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
16144 if (!cond)
16145 return NULL;
16146
16147 memcpy (save, affix, 2);
16148 memmove (affix, affix + 2, (end - affix) - 2);
16149 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
16150 (end - base) - 2);
16151 memmove (affix + 2, affix, (end - affix) - 2);
16152 memcpy (affix, save, 2);
16153
16154 if (opcode
16155 && (opcode->tag == OT_cinfix3
16156 || opcode->tag == OT_cinfix3_deprecated
16157 || opcode->tag == OT_csuf_or_in3
16158 || opcode->tag == OT_cinfix3_legacy))
16159 {
16160 /* Step CM. */
16161 if (warn_on_deprecated && unified_syntax
16162 && (opcode->tag == OT_cinfix3
16163 || opcode->tag == OT_cinfix3_deprecated))
16164 as_warn (_("conditional infixes are deprecated in unified syntax"));
16165
16166 inst.cond = cond->value;
16167 return opcode;
16168 }
16169
16170 return NULL;
16171 }
16172
16173 /* This function generates an initial IT instruction, leaving its block
16174 virtually open for the new instructions. Eventually,
16175 the mask will be updated by now_it_add_mask () each time
16176 a new instruction needs to be included in the IT block.
16177 Finally, the block is closed with close_automatic_it_block ().
16178 The block closure can be requested either from md_assemble (),
16179 a tencode (), or due to a label hook. */
16180
16181 static void
16182 new_automatic_it_block (int cond)
16183 {
16184 now_it.state = AUTOMATIC_IT_BLOCK;
16185 now_it.mask = 0x18;
16186 now_it.cc = cond;
16187 now_it.block_length = 1;
16188 mapping_state (MAP_THUMB);
16189 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
16190 }
16191
16192 /* Close an automatic IT block.
16193 See comments in new_automatic_it_block (). */
16194
16195 static void
16196 close_automatic_it_block (void)
16197 {
16198 now_it.mask = 0x10;
16199 now_it.block_length = 0;
16200 }
16201
16202 /* Update the mask of the current automatically-generated IT
16203 instruction. See comments in new_automatic_it_block (). */
16204
16205 static void
16206 now_it_add_mask (int cond)
16207 {
16208 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
16209 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
16210 | ((bitvalue) << (nbit)))
16211 const int resulting_bit = (cond & 1);
16212
16213 now_it.mask &= 0xf;
16214 now_it.mask = SET_BIT_VALUE (now_it.mask,
16215 resulting_bit,
16216 (5 - now_it.block_length));
16217 now_it.mask = SET_BIT_VALUE (now_it.mask,
16218 1,
16219 ((5 - now_it.block_length) - 1) );
16220 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
16221
16222 #undef CLEAR_BIT
16223 #undef SET_BIT_VALUE
16224 }
16225
16226 /* The IT blocks handling machinery is accessed through the these functions:
16227 it_fsm_pre_encode () from md_assemble ()
16228 set_it_insn_type () optional, from the tencode functions
16229 set_it_insn_type_last () ditto
16230 in_it_block () ditto
16231 it_fsm_post_encode () from md_assemble ()
16232 force_automatic_it_block_close () from label habdling functions
16233
16234 Rationale:
16235 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
16236 initializing the IT insn type with a generic initial value depending
16237 on the inst.condition.
16238 2) During the tencode function, two things may happen:
16239 a) The tencode function overrides the IT insn type by
16240 calling either set_it_insn_type (type) or set_it_insn_type_last ().
16241 b) The tencode function queries the IT block state by
16242 calling in_it_block () (i.e. to determine narrow/not narrow mode).
16243
16244 Both set_it_insn_type and in_it_block run the internal FSM state
16245 handling function (handle_it_state), because: a) setting the IT insn
16246 type may incur in an invalid state (exiting the function),
16247 and b) querying the state requires the FSM to be updated.
16248 Specifically we want to avoid creating an IT block for conditional
16249 branches, so it_fsm_pre_encode is actually a guess and we can't
16250 determine whether an IT block is required until the tencode () routine
16251 has decided what type of instruction this actually it.
16252 Because of this, if set_it_insn_type and in_it_block have to be used,
16253 set_it_insn_type has to be called first.
16254
16255 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
16256 determines the insn IT type depending on the inst.cond code.
16257 When a tencode () routine encodes an instruction that can be
16258 either outside an IT block, or, in the case of being inside, has to be
16259 the last one, set_it_insn_type_last () will determine the proper
16260 IT instruction type based on the inst.cond code. Otherwise,
16261 set_it_insn_type can be called for overriding that logic or
16262 for covering other cases.
16263
16264 Calling handle_it_state () may not transition the IT block state to
16265 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
16266 still queried. Instead, if the FSM determines that the state should
16267 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
16268 after the tencode () function: that's what it_fsm_post_encode () does.
16269
16270 Since in_it_block () calls the state handling function to get an
16271 updated state, an error may occur (due to invalid insns combination).
16272 In that case, inst.error is set.
16273 Therefore, inst.error has to be checked after the execution of
16274 the tencode () routine.
16275
16276 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
16277 any pending state change (if any) that didn't take place in
16278 handle_it_state () as explained above. */
16279
16280 static void
16281 it_fsm_pre_encode (void)
16282 {
16283 if (inst.cond != COND_ALWAYS)
16284 inst.it_insn_type = INSIDE_IT_INSN;
16285 else
16286 inst.it_insn_type = OUTSIDE_IT_INSN;
16287
16288 now_it.state_handled = 0;
16289 }
16290
16291 /* IT state FSM handling function. */
16292
16293 static int
16294 handle_it_state (void)
16295 {
16296 now_it.state_handled = 1;
16297
16298 switch (now_it.state)
16299 {
16300 case OUTSIDE_IT_BLOCK:
16301 switch (inst.it_insn_type)
16302 {
16303 case OUTSIDE_IT_INSN:
16304 break;
16305
16306 case INSIDE_IT_INSN:
16307 case INSIDE_IT_LAST_INSN:
16308 if (thumb_mode == 0)
16309 {
16310 if (unified_syntax
16311 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
16312 as_tsktsk (_("Warning: conditional outside an IT block"\
16313 " for Thumb."));
16314 }
16315 else
16316 {
16317 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
16318 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
16319 {
16320 /* Automatically generate the IT instruction. */
16321 new_automatic_it_block (inst.cond);
16322 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
16323 close_automatic_it_block ();
16324 }
16325 else
16326 {
16327 inst.error = BAD_OUT_IT;
16328 return FAIL;
16329 }
16330 }
16331 break;
16332
16333 case IF_INSIDE_IT_LAST_INSN:
16334 case NEUTRAL_IT_INSN:
16335 break;
16336
16337 case IT_INSN:
16338 now_it.state = MANUAL_IT_BLOCK;
16339 now_it.block_length = 0;
16340 break;
16341 }
16342 break;
16343
16344 case AUTOMATIC_IT_BLOCK:
16345 /* Three things may happen now:
16346 a) We should increment current it block size;
16347 b) We should close current it block (closing insn or 4 insns);
16348 c) We should close current it block and start a new one (due
16349 to incompatible conditions or
16350 4 insns-length block reached). */
16351
16352 switch (inst.it_insn_type)
16353 {
16354 case OUTSIDE_IT_INSN:
16355 /* The closure of the block shall happen immediatelly,
16356 so any in_it_block () call reports the block as closed. */
16357 force_automatic_it_block_close ();
16358 break;
16359
16360 case INSIDE_IT_INSN:
16361 case INSIDE_IT_LAST_INSN:
16362 case IF_INSIDE_IT_LAST_INSN:
16363 now_it.block_length++;
16364
16365 if (now_it.block_length > 4
16366 || !now_it_compatible (inst.cond))
16367 {
16368 force_automatic_it_block_close ();
16369 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
16370 new_automatic_it_block (inst.cond);
16371 }
16372 else
16373 {
16374 now_it_add_mask (inst.cond);
16375 }
16376
16377 if (now_it.state == AUTOMATIC_IT_BLOCK
16378 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
16379 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
16380 close_automatic_it_block ();
16381 break;
16382
16383 case NEUTRAL_IT_INSN:
16384 now_it.block_length++;
16385
16386 if (now_it.block_length > 4)
16387 force_automatic_it_block_close ();
16388 else
16389 now_it_add_mask (now_it.cc & 1);
16390 break;
16391
16392 case IT_INSN:
16393 close_automatic_it_block ();
16394 now_it.state = MANUAL_IT_BLOCK;
16395 break;
16396 }
16397 break;
16398
16399 case MANUAL_IT_BLOCK:
16400 {
16401 /* Check conditional suffixes. */
16402 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
16403 int is_last;
16404 now_it.mask <<= 1;
16405 now_it.mask &= 0x1f;
16406 is_last = (now_it.mask == 0x10);
16407
16408 switch (inst.it_insn_type)
16409 {
16410 case OUTSIDE_IT_INSN:
16411 inst.error = BAD_NOT_IT;
16412 return FAIL;
16413
16414 case INSIDE_IT_INSN:
16415 if (cond != inst.cond)
16416 {
16417 inst.error = BAD_IT_COND;
16418 return FAIL;
16419 }
16420 break;
16421
16422 case INSIDE_IT_LAST_INSN:
16423 case IF_INSIDE_IT_LAST_INSN:
16424 if (cond != inst.cond)
16425 {
16426 inst.error = BAD_IT_COND;
16427 return FAIL;
16428 }
16429 if (!is_last)
16430 {
16431 inst.error = BAD_BRANCH;
16432 return FAIL;
16433 }
16434 break;
16435
16436 case NEUTRAL_IT_INSN:
16437 /* The BKPT instruction is unconditional even in an IT block. */
16438 break;
16439
16440 case IT_INSN:
16441 inst.error = BAD_IT_IT;
16442 return FAIL;
16443 }
16444 }
16445 break;
16446 }
16447
16448 return SUCCESS;
16449 }
16450
16451 static void
16452 it_fsm_post_encode (void)
16453 {
16454 int is_last;
16455
16456 if (!now_it.state_handled)
16457 handle_it_state ();
16458
16459 is_last = (now_it.mask == 0x10);
16460 if (is_last)
16461 {
16462 now_it.state = OUTSIDE_IT_BLOCK;
16463 now_it.mask = 0;
16464 }
16465 }
16466
16467 static void
16468 force_automatic_it_block_close (void)
16469 {
16470 if (now_it.state == AUTOMATIC_IT_BLOCK)
16471 {
16472 close_automatic_it_block ();
16473 now_it.state = OUTSIDE_IT_BLOCK;
16474 now_it.mask = 0;
16475 }
16476 }
16477
16478 static int
16479 in_it_block (void)
16480 {
16481 if (!now_it.state_handled)
16482 handle_it_state ();
16483
16484 return now_it.state != OUTSIDE_IT_BLOCK;
16485 }
16486
16487 void
16488 md_assemble (char *str)
16489 {
16490 char *p = str;
16491 const struct asm_opcode * opcode;
16492
16493 /* Align the previous label if needed. */
16494 if (last_label_seen != NULL)
16495 {
16496 symbol_set_frag (last_label_seen, frag_now);
16497 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
16498 S_SET_SEGMENT (last_label_seen, now_seg);
16499 }
16500
16501 memset (&inst, '\0', sizeof (inst));
16502 inst.reloc.type = BFD_RELOC_UNUSED;
16503
16504 opcode = opcode_lookup (&p);
16505 if (!opcode)
16506 {
16507 /* It wasn't an instruction, but it might be a register alias of
16508 the form alias .req reg, or a Neon .dn/.qn directive. */
16509 if (! create_register_alias (str, p)
16510 && ! create_neon_reg_alias (str, p))
16511 as_bad (_("bad instruction `%s'"), str);
16512
16513 return;
16514 }
16515
16516 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
16517 as_warn (_("s suffix on comparison instruction is deprecated"));
16518
16519 /* The value which unconditional instructions should have in place of the
16520 condition field. */
16521 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
16522
16523 if (thumb_mode)
16524 {
16525 arm_feature_set variant;
16526
16527 variant = cpu_variant;
16528 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
16529 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
16530 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
16531 /* Check that this instruction is supported for this CPU. */
16532 if (!opcode->tvariant
16533 || (thumb_mode == 1
16534 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
16535 {
16536 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
16537 return;
16538 }
16539 if (inst.cond != COND_ALWAYS && !unified_syntax
16540 && opcode->tencode != do_t_branch)
16541 {
16542 as_bad (_("Thumb does not support conditional execution"));
16543 return;
16544 }
16545
16546 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
16547 {
16548 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
16549 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
16550 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
16551 {
16552 /* Two things are addressed here.
16553 1) Implicit require narrow instructions on Thumb-1.
16554 This avoids relaxation accidentally introducing Thumb-2
16555 instructions.
16556 2) Reject wide instructions in non Thumb-2 cores. */
16557 if (inst.size_req == 0)
16558 inst.size_req = 2;
16559 else if (inst.size_req == 4)
16560 {
16561 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
16562 return;
16563 }
16564 }
16565 }
16566
16567 inst.instruction = opcode->tvalue;
16568
16569 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
16570 {
16571 /* Prepare the it_insn_type for those encodings that don't set
16572 it. */
16573 it_fsm_pre_encode ();
16574
16575 opcode->tencode ();
16576
16577 it_fsm_post_encode ();
16578 }
16579
16580 if (!(inst.error || inst.relax))
16581 {
16582 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
16583 inst.size = (inst.instruction > 0xffff ? 4 : 2);
16584 if (inst.size_req && inst.size_req != inst.size)
16585 {
16586 as_bad (_("cannot honor width suffix -- `%s'"), str);
16587 return;
16588 }
16589 }
16590
16591 /* Something has gone badly wrong if we try to relax a fixed size
16592 instruction. */
16593 gas_assert (inst.size_req == 0 || !inst.relax);
16594
16595 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16596 *opcode->tvariant);
16597 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
16598 set those bits when Thumb-2 32-bit instructions are seen. ie.
16599 anything other than bl/blx and v6-M instructions.
16600 This is overly pessimistic for relaxable instructions. */
16601 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
16602 || inst.relax)
16603 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
16604 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
16605 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
16606 arm_ext_v6t2);
16607
16608 check_neon_suffixes;
16609
16610 if (!inst.error)
16611 {
16612 mapping_state (MAP_THUMB);
16613 }
16614 }
16615 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
16616 {
16617 bfd_boolean is_bx;
16618
16619 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
16620 is_bx = (opcode->aencode == do_bx);
16621
16622 /* Check that this instruction is supported for this CPU. */
16623 if (!(is_bx && fix_v4bx)
16624 && !(opcode->avariant &&
16625 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
16626 {
16627 as_bad (_("selected processor does not support ARM mode `%s'"), str);
16628 return;
16629 }
16630 if (inst.size_req)
16631 {
16632 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
16633 return;
16634 }
16635
16636 inst.instruction = opcode->avalue;
16637 if (opcode->tag == OT_unconditionalF)
16638 inst.instruction |= 0xF << 28;
16639 else
16640 inst.instruction |= inst.cond << 28;
16641 inst.size = INSN_SIZE;
16642 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
16643 {
16644 it_fsm_pre_encode ();
16645 opcode->aencode ();
16646 it_fsm_post_encode ();
16647 }
16648 /* Arm mode bx is marked as both v4T and v5 because it's still required
16649 on a hypothetical non-thumb v5 core. */
16650 if (is_bx)
16651 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
16652 else
16653 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
16654 *opcode->avariant);
16655
16656 check_neon_suffixes;
16657
16658 if (!inst.error)
16659 {
16660 mapping_state (MAP_ARM);
16661 }
16662 }
16663 else
16664 {
16665 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
16666 "-- `%s'"), str);
16667 return;
16668 }
16669 output_inst (str);
16670 }
16671
16672 static void
16673 check_it_blocks_finished (void)
16674 {
16675 #ifdef OBJ_ELF
16676 asection *sect;
16677
16678 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
16679 if (seg_info (sect)->tc_segment_info_data.current_it.state
16680 == MANUAL_IT_BLOCK)
16681 {
16682 as_warn (_("section '%s' finished with an open IT block."),
16683 sect->name);
16684 }
16685 #else
16686 if (now_it.state == MANUAL_IT_BLOCK)
16687 as_warn (_("file finished with an open IT block."));
16688 #endif
16689 }
16690
16691 /* Various frobbings of labels and their addresses. */
16692
16693 void
16694 arm_start_line_hook (void)
16695 {
16696 last_label_seen = NULL;
16697 }
16698
16699 void
16700 arm_frob_label (symbolS * sym)
16701 {
16702 last_label_seen = sym;
16703
16704 ARM_SET_THUMB (sym, thumb_mode);
16705
16706 #if defined OBJ_COFF || defined OBJ_ELF
16707 ARM_SET_INTERWORK (sym, support_interwork);
16708 #endif
16709
16710 force_automatic_it_block_close ();
16711
16712 /* Note - do not allow local symbols (.Lxxx) to be labelled
16713 as Thumb functions. This is because these labels, whilst
16714 they exist inside Thumb code, are not the entry points for
16715 possible ARM->Thumb calls. Also, these labels can be used
16716 as part of a computed goto or switch statement. eg gcc
16717 can generate code that looks like this:
16718
16719 ldr r2, [pc, .Laaa]
16720 lsl r3, r3, #2
16721 ldr r2, [r3, r2]
16722 mov pc, r2
16723
16724 .Lbbb: .word .Lxxx
16725 .Lccc: .word .Lyyy
16726 ..etc...
16727 .Laaa: .word Lbbb
16728
16729 The first instruction loads the address of the jump table.
16730 The second instruction converts a table index into a byte offset.
16731 The third instruction gets the jump address out of the table.
16732 The fourth instruction performs the jump.
16733
16734 If the address stored at .Laaa is that of a symbol which has the
16735 Thumb_Func bit set, then the linker will arrange for this address
16736 to have the bottom bit set, which in turn would mean that the
16737 address computation performed by the third instruction would end
16738 up with the bottom bit set. Since the ARM is capable of unaligned
16739 word loads, the instruction would then load the incorrect address
16740 out of the jump table, and chaos would ensue. */
16741 if (label_is_thumb_function_name
16742 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16743 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
16744 {
16745 /* When the address of a Thumb function is taken the bottom
16746 bit of that address should be set. This will allow
16747 interworking between Arm and Thumb functions to work
16748 correctly. */
16749
16750 THUMB_SET_FUNC (sym, 1);
16751
16752 label_is_thumb_function_name = FALSE;
16753 }
16754
16755 dwarf2_emit_label (sym);
16756 }
16757
16758 bfd_boolean
16759 arm_data_in_code (void)
16760 {
16761 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
16762 {
16763 *input_line_pointer = '/';
16764 input_line_pointer += 5;
16765 *input_line_pointer = 0;
16766 return TRUE;
16767 }
16768
16769 return FALSE;
16770 }
16771
16772 char *
16773 arm_canonicalize_symbol_name (char * name)
16774 {
16775 int len;
16776
16777 if (thumb_mode && (len = strlen (name)) > 5
16778 && streq (name + len - 5, "/data"))
16779 *(name + len - 5) = 0;
16780
16781 return name;
16782 }
16783 \f
16784 /* Table of all register names defined by default. The user can
16785 define additional names with .req. Note that all register names
16786 should appear in both upper and lowercase variants. Some registers
16787 also have mixed-case names. */
16788
16789 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
16790 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
16791 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
16792 #define REGSET(p,t) \
16793 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16794 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16795 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16796 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
16797 #define REGSETH(p,t) \
16798 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16799 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16800 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16801 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16802 #define REGSET2(p,t) \
16803 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16804 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16805 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16806 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
16807 #define SPLRBANK(base,bank,t) \
16808 REGDEF(lr_##bank, 768|((base+0)<<16), t), \
16809 REGDEF(sp_##bank, 768|((base+1)<<16), t), \
16810 REGDEF(spsr_##bank, 768|(base<<16)|SPSR_BIT, t), \
16811 REGDEF(LR_##bank, 768|((base+0)<<16), t), \
16812 REGDEF(SP_##bank, 768|((base+1)<<16), t), \
16813 REGDEF(SPSR_##bank, 768|(base<<16)|SPSR_BIT, t)
16814
16815 static const struct reg_entry reg_names[] =
16816 {
16817 /* ARM integer registers. */
16818 REGSET(r, RN), REGSET(R, RN),
16819
16820 /* ATPCS synonyms. */
16821 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16822 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16823 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
16824
16825 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16826 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16827 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
16828
16829 /* Well-known aliases. */
16830 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16831 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16832
16833 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16834 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16835
16836 /* Coprocessor numbers. */
16837 REGSET(p, CP), REGSET(P, CP),
16838
16839 /* Coprocessor register numbers. The "cr" variants are for backward
16840 compatibility. */
16841 REGSET(c, CN), REGSET(C, CN),
16842 REGSET(cr, CN), REGSET(CR, CN),
16843
16844 /* ARM banked registers. */
16845 REGDEF(R8_usr,512|(0<<16),RNB), REGDEF(r8_usr,512|(0<<16),RNB),
16846 REGDEF(R9_usr,512|(1<<16),RNB), REGDEF(r9_usr,512|(1<<16),RNB),
16847 REGDEF(R10_usr,512|(2<<16),RNB), REGDEF(r10_usr,512|(2<<16),RNB),
16848 REGDEF(R11_usr,512|(3<<16),RNB), REGDEF(r11_usr,512|(3<<16),RNB),
16849 REGDEF(R12_usr,512|(4<<16),RNB), REGDEF(r12_usr,512|(4<<16),RNB),
16850 REGDEF(SP_usr,512|(5<<16),RNB), REGDEF(sp_usr,512|(5<<16),RNB),
16851 REGDEF(LR_usr,512|(6<<16),RNB), REGDEF(lr_usr,512|(6<<16),RNB),
16852
16853 REGDEF(R8_fiq,512|(8<<16),RNB), REGDEF(r8_fiq,512|(8<<16),RNB),
16854 REGDEF(R9_fiq,512|(9<<16),RNB), REGDEF(r9_fiq,512|(9<<16),RNB),
16855 REGDEF(R10_fiq,512|(10<<16),RNB), REGDEF(r10_fiq,512|(10<<16),RNB),
16856 REGDEF(R11_fiq,512|(11<<16),RNB), REGDEF(r11_fiq,512|(11<<16),RNB),
16857 REGDEF(R12_fiq,512|(12<<16),RNB), REGDEF(r12_fiq,512|(12<<16),RNB),
16858 REGDEF(SP_fiq,512|(13<<16),RNB), REGDEF(SP_fiq,512|(13<<16),RNB),
16859 REGDEF(LR_fiq,512|(14<<16),RNB), REGDEF(lr_fiq,512|(14<<16),RNB),
16860 REGDEF(SPSR_fiq,512|(14<<16)|SPSR_BIT,RNB), REGDEF(spsr_fiq,512|(14<<16)|SPSR_BIT,RNB),
16861
16862 SPLRBANK(0,IRQ,RNB), SPLRBANK(0,irq,RNB),
16863 SPLRBANK(2,SVC,RNB), SPLRBANK(2,svc,RNB),
16864 SPLRBANK(4,ABT,RNB), SPLRBANK(4,abt,RNB),
16865 SPLRBANK(6,UND,RNB), SPLRBANK(6,und,RNB),
16866 SPLRBANK(12,MON,RNB), SPLRBANK(12,mon,RNB),
16867 REGDEF(elr_hyp,768|(14<<16),RNB), REGDEF(ELR_hyp,768|(14<<16),RNB),
16868 REGDEF(sp_hyp,768|(15<<16),RNB), REGDEF(SP_hyp,768|(15<<16),RNB),
16869 REGDEF(spsr_hyp,768|(14<<16)|SPSR_BIT,RNB),
16870 REGDEF(SPSR_hyp,768|(14<<16)|SPSR_BIT,RNB),
16871
16872 /* FPA registers. */
16873 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16874 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16875
16876 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16877 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16878
16879 /* VFP SP registers. */
16880 REGSET(s,VFS), REGSET(S,VFS),
16881 REGSETH(s,VFS), REGSETH(S,VFS),
16882
16883 /* VFP DP Registers. */
16884 REGSET(d,VFD), REGSET(D,VFD),
16885 /* Extra Neon DP registers. */
16886 REGSETH(d,VFD), REGSETH(D,VFD),
16887
16888 /* Neon QP registers. */
16889 REGSET2(q,NQ), REGSET2(Q,NQ),
16890
16891 /* VFP control registers. */
16892 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16893 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
16894 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16895 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16896 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16897 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
16898
16899 /* Maverick DSP coprocessor registers. */
16900 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16901 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16902
16903 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16904 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16905 REGDEF(dspsc,0,DSPSC),
16906
16907 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16908 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16909 REGDEF(DSPSC,0,DSPSC),
16910
16911 /* iWMMXt data registers - p0, c0-15. */
16912 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16913
16914 /* iWMMXt control registers - p1, c0-3. */
16915 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16916 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16917 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16918 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16919
16920 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16921 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16922 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16923 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16924 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16925
16926 /* XScale accumulator registers. */
16927 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16928 };
16929 #undef REGDEF
16930 #undef REGNUM
16931 #undef REGSET
16932
16933 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16934 within psr_required_here. */
16935 static const struct asm_psr psrs[] =
16936 {
16937 /* Backward compatibility notation. Note that "all" is no longer
16938 truly all possible PSR bits. */
16939 {"all", PSR_c | PSR_f},
16940 {"flg", PSR_f},
16941 {"ctl", PSR_c},
16942
16943 /* Individual flags. */
16944 {"f", PSR_f},
16945 {"c", PSR_c},
16946 {"x", PSR_x},
16947 {"s", PSR_s},
16948
16949 /* Combinations of flags. */
16950 {"fs", PSR_f | PSR_s},
16951 {"fx", PSR_f | PSR_x},
16952 {"fc", PSR_f | PSR_c},
16953 {"sf", PSR_s | PSR_f},
16954 {"sx", PSR_s | PSR_x},
16955 {"sc", PSR_s | PSR_c},
16956 {"xf", PSR_x | PSR_f},
16957 {"xs", PSR_x | PSR_s},
16958 {"xc", PSR_x | PSR_c},
16959 {"cf", PSR_c | PSR_f},
16960 {"cs", PSR_c | PSR_s},
16961 {"cx", PSR_c | PSR_x},
16962 {"fsx", PSR_f | PSR_s | PSR_x},
16963 {"fsc", PSR_f | PSR_s | PSR_c},
16964 {"fxs", PSR_f | PSR_x | PSR_s},
16965 {"fxc", PSR_f | PSR_x | PSR_c},
16966 {"fcs", PSR_f | PSR_c | PSR_s},
16967 {"fcx", PSR_f | PSR_c | PSR_x},
16968 {"sfx", PSR_s | PSR_f | PSR_x},
16969 {"sfc", PSR_s | PSR_f | PSR_c},
16970 {"sxf", PSR_s | PSR_x | PSR_f},
16971 {"sxc", PSR_s | PSR_x | PSR_c},
16972 {"scf", PSR_s | PSR_c | PSR_f},
16973 {"scx", PSR_s | PSR_c | PSR_x},
16974 {"xfs", PSR_x | PSR_f | PSR_s},
16975 {"xfc", PSR_x | PSR_f | PSR_c},
16976 {"xsf", PSR_x | PSR_s | PSR_f},
16977 {"xsc", PSR_x | PSR_s | PSR_c},
16978 {"xcf", PSR_x | PSR_c | PSR_f},
16979 {"xcs", PSR_x | PSR_c | PSR_s},
16980 {"cfs", PSR_c | PSR_f | PSR_s},
16981 {"cfx", PSR_c | PSR_f | PSR_x},
16982 {"csf", PSR_c | PSR_s | PSR_f},
16983 {"csx", PSR_c | PSR_s | PSR_x},
16984 {"cxf", PSR_c | PSR_x | PSR_f},
16985 {"cxs", PSR_c | PSR_x | PSR_s},
16986 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16987 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16988 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16989 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16990 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16991 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16992 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16993 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16994 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16995 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16996 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16997 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16998 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16999 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
17000 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
17001 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
17002 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
17003 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
17004 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
17005 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
17006 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
17007 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
17008 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
17009 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
17010 };
17011
17012 /* Table of V7M psr names. */
17013 static const struct asm_psr v7m_psrs[] =
17014 {
17015 {"apsr", 0 }, {"APSR", 0 },
17016 {"iapsr", 1 }, {"IAPSR", 1 },
17017 {"eapsr", 2 }, {"EAPSR", 2 },
17018 {"psr", 3 }, {"PSR", 3 },
17019 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
17020 {"ipsr", 5 }, {"IPSR", 5 },
17021 {"epsr", 6 }, {"EPSR", 6 },
17022 {"iepsr", 7 }, {"IEPSR", 7 },
17023 {"msp", 8 }, {"MSP", 8 },
17024 {"psp", 9 }, {"PSP", 9 },
17025 {"primask", 16}, {"PRIMASK", 16},
17026 {"basepri", 17}, {"BASEPRI", 17},
17027 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
17028 {"basepri_max", 18}, {"BASEPRI_MASK", 18}, /* Typo, preserved for backwards compatibility. */
17029 {"faultmask", 19}, {"FAULTMASK", 19},
17030 {"control", 20}, {"CONTROL", 20}
17031 };
17032
17033 /* Table of all shift-in-operand names. */
17034 static const struct asm_shift_name shift_names [] =
17035 {
17036 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
17037 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
17038 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
17039 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
17040 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
17041 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
17042 };
17043
17044 /* Table of all explicit relocation names. */
17045 #ifdef OBJ_ELF
17046 static struct reloc_entry reloc_names[] =
17047 {
17048 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
17049 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
17050 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
17051 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
17052 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
17053 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
17054 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
17055 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
17056 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
17057 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
17058 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
17059 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL},
17060 { "tlsdesc", BFD_RELOC_ARM_TLS_GOTDESC},
17061 { "TLSDESC", BFD_RELOC_ARM_TLS_GOTDESC},
17062 { "tlscall", BFD_RELOC_ARM_TLS_CALL},
17063 { "TLSCALL", BFD_RELOC_ARM_TLS_CALL},
17064 { "tlsdescseq", BFD_RELOC_ARM_TLS_DESCSEQ},
17065 { "TLSDESCSEQ", BFD_RELOC_ARM_TLS_DESCSEQ}
17066 };
17067 #endif
17068
17069 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
17070 static const struct asm_cond conds[] =
17071 {
17072 {"eq", 0x0},
17073 {"ne", 0x1},
17074 {"cs", 0x2}, {"hs", 0x2},
17075 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
17076 {"mi", 0x4},
17077 {"pl", 0x5},
17078 {"vs", 0x6},
17079 {"vc", 0x7},
17080 {"hi", 0x8},
17081 {"ls", 0x9},
17082 {"ge", 0xa},
17083 {"lt", 0xb},
17084 {"gt", 0xc},
17085 {"le", 0xd},
17086 {"al", 0xe}
17087 };
17088
17089 static struct asm_barrier_opt barrier_opt_names[] =
17090 {
17091 { "sy", 0xf }, { "SY", 0xf },
17092 { "un", 0x7 }, { "UN", 0x7 },
17093 { "st", 0xe }, { "ST", 0xe },
17094 { "unst", 0x6 }, { "UNST", 0x6 },
17095 { "ish", 0xb }, { "ISH", 0xb },
17096 { "sh", 0xb }, { "SH", 0xb },
17097 { "ishst", 0xa }, { "ISHST", 0xa },
17098 { "shst", 0xa }, { "SHST", 0xa },
17099 { "nsh", 0x7 }, { "NSH", 0x7 },
17100 { "nshst", 0x6 }, { "NSHST", 0x6 },
17101 { "osh", 0x3 }, { "OSH", 0x3 },
17102 { "oshst", 0x2 }, { "OSHST", 0x2 }
17103 };
17104
17105 /* Table of ARM-format instructions. */
17106
17107 /* Macros for gluing together operand strings. N.B. In all cases
17108 other than OPS0, the trailing OP_stop comes from default
17109 zero-initialization of the unspecified elements of the array. */
17110 #define OPS0() { OP_stop, }
17111 #define OPS1(a) { OP_##a, }
17112 #define OPS2(a,b) { OP_##a,OP_##b, }
17113 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
17114 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
17115 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
17116 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
17117
17118 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
17119 This is useful when mixing operands for ARM and THUMB, i.e. using the
17120 MIX_ARM_THUMB_OPERANDS macro.
17121 In order to use these macros, prefix the number of operands with _
17122 e.g. _3. */
17123 #define OPS_1(a) { a, }
17124 #define OPS_2(a,b) { a,b, }
17125 #define OPS_3(a,b,c) { a,b,c, }
17126 #define OPS_4(a,b,c,d) { a,b,c,d, }
17127 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
17128 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
17129
17130 /* These macros abstract out the exact format of the mnemonic table and
17131 save some repeated characters. */
17132
17133 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
17134 #define TxCE(mnem, op, top, nops, ops, ae, te) \
17135 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
17136 THUMB_VARIANT, do_##ae, do_##te }
17137
17138 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
17139 a T_MNEM_xyz enumerator. */
17140 #define TCE(mnem, aop, top, nops, ops, ae, te) \
17141 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
17142 #define tCE(mnem, aop, top, nops, ops, ae, te) \
17143 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17144
17145 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
17146 infix after the third character. */
17147 #define TxC3(mnem, op, top, nops, ops, ae, te) \
17148 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
17149 THUMB_VARIANT, do_##ae, do_##te }
17150 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
17151 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
17152 THUMB_VARIANT, do_##ae, do_##te }
17153 #define TC3(mnem, aop, top, nops, ops, ae, te) \
17154 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
17155 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
17156 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
17157 #define tC3(mnem, aop, top, nops, ops, ae, te) \
17158 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17159 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
17160 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
17161
17162 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
17163 appear in the condition table. */
17164 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
17165 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
17166 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
17167
17168 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
17169 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
17170 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
17171 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
17172 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
17173 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
17174 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
17175 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
17176 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
17177 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
17178 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
17179 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
17180 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
17181 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
17182 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
17183 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
17184 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
17185 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
17186 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
17187 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
17188
17189 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
17190 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
17191 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
17192 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
17193
17194 /* Mnemonic that cannot be conditionalized. The ARM condition-code
17195 field is still 0xE. Many of the Thumb variants can be executed
17196 conditionally, so this is checked separately. */
17197 #define TUE(mnem, op, top, nops, ops, ae, te) \
17198 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
17199 THUMB_VARIANT, do_##ae, do_##te }
17200
17201 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
17202 condition code field. */
17203 #define TUF(mnem, op, top, nops, ops, ae, te) \
17204 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
17205 THUMB_VARIANT, do_##ae, do_##te }
17206
17207 /* ARM-only variants of all the above. */
17208 #define CE(mnem, op, nops, ops, ae) \
17209 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17210
17211 #define C3(mnem, op, nops, ops, ae) \
17212 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17213
17214 /* Legacy mnemonics that always have conditional infix after the third
17215 character. */
17216 #define CL(mnem, op, nops, ops, ae) \
17217 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
17218 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17219
17220 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
17221 #define cCE(mnem, op, nops, ops, ae) \
17222 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17223
17224 /* Legacy coprocessor instructions where conditional infix and conditional
17225 suffix are ambiguous. For consistency this includes all FPA instructions,
17226 not just the potentially ambiguous ones. */
17227 #define cCL(mnem, op, nops, ops, ae) \
17228 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
17229 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17230
17231 /* Coprocessor, takes either a suffix or a position-3 infix
17232 (for an FPA corner case). */
17233 #define C3E(mnem, op, nops, ops, ae) \
17234 { mnem, OPS##nops ops, OT_csuf_or_in3, \
17235 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
17236
17237 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
17238 { m1 #m2 m3, OPS##nops ops, \
17239 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
17240 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
17241
17242 #define CM(m1, m2, op, nops, ops, ae) \
17243 xCM_ (m1, , m2, op, nops, ops, ae), \
17244 xCM_ (m1, eq, m2, op, nops, ops, ae), \
17245 xCM_ (m1, ne, m2, op, nops, ops, ae), \
17246 xCM_ (m1, cs, m2, op, nops, ops, ae), \
17247 xCM_ (m1, hs, m2, op, nops, ops, ae), \
17248 xCM_ (m1, cc, m2, op, nops, ops, ae), \
17249 xCM_ (m1, ul, m2, op, nops, ops, ae), \
17250 xCM_ (m1, lo, m2, op, nops, ops, ae), \
17251 xCM_ (m1, mi, m2, op, nops, ops, ae), \
17252 xCM_ (m1, pl, m2, op, nops, ops, ae), \
17253 xCM_ (m1, vs, m2, op, nops, ops, ae), \
17254 xCM_ (m1, vc, m2, op, nops, ops, ae), \
17255 xCM_ (m1, hi, m2, op, nops, ops, ae), \
17256 xCM_ (m1, ls, m2, op, nops, ops, ae), \
17257 xCM_ (m1, ge, m2, op, nops, ops, ae), \
17258 xCM_ (m1, lt, m2, op, nops, ops, ae), \
17259 xCM_ (m1, gt, m2, op, nops, ops, ae), \
17260 xCM_ (m1, le, m2, op, nops, ops, ae), \
17261 xCM_ (m1, al, m2, op, nops, ops, ae)
17262
17263 #define UE(mnem, op, nops, ops, ae) \
17264 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17265
17266 #define UF(mnem, op, nops, ops, ae) \
17267 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
17268
17269 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
17270 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
17271 use the same encoding function for each. */
17272 #define NUF(mnem, op, nops, ops, enc) \
17273 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
17274 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17275
17276 /* Neon data processing, version which indirects through neon_enc_tab for
17277 the various overloaded versions of opcodes. */
17278 #define nUF(mnem, op, nops, ops, enc) \
17279 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
17280 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17281
17282 /* Neon insn with conditional suffix for the ARM version, non-overloaded
17283 version. */
17284 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
17285 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
17286 THUMB_VARIANT, do_##enc, do_##enc }
17287
17288 #define NCE(mnem, op, nops, ops, enc) \
17289 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17290
17291 #define NCEF(mnem, op, nops, ops, enc) \
17292 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17293
17294 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
17295 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
17296 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
17297 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
17298
17299 #define nCE(mnem, op, nops, ops, enc) \
17300 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
17301
17302 #define nCEF(mnem, op, nops, ops, enc) \
17303 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
17304
17305 #define do_0 0
17306
17307 static const struct asm_opcode insns[] =
17308 {
17309 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
17310 #define THUMB_VARIANT &arm_ext_v4t
17311 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
17312 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
17313 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
17314 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
17315 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
17316 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
17317 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
17318 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
17319 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
17320 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
17321 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
17322 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
17323 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
17324 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
17325 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
17326 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
17327
17328 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
17329 for setting PSR flag bits. They are obsolete in V6 and do not
17330 have Thumb equivalents. */
17331 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17332 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
17333 CL("tstp", 110f000, 2, (RR, SH), cmp),
17334 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17335 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
17336 CL("cmpp", 150f000, 2, (RR, SH), cmp),
17337 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17338 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
17339 CL("cmnp", 170f000, 2, (RR, SH), cmp),
17340
17341 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
17342 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
17343 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
17344 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
17345
17346 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
17347 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17348 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
17349 OP_RRnpc),
17350 OP_ADDRGLDR),ldst, t_ldst),
17351 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
17352
17353 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17354 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17355 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17356 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17357 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17358 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17359
17360 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
17361 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
17362 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
17363 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
17364
17365 /* Pseudo ops. */
17366 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
17367 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
17368 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
17369
17370 /* Thumb-compatibility pseudo ops. */
17371 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
17372 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
17373 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
17374 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
17375 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
17376 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
17377 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
17378 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
17379 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
17380 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
17381 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
17382 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
17383
17384 /* These may simplify to neg. */
17385 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
17386 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
17387
17388 #undef THUMB_VARIANT
17389 #define THUMB_VARIANT & arm_ext_v6
17390
17391 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
17392
17393 /* V1 instructions with no Thumb analogue prior to V6T2. */
17394 #undef THUMB_VARIANT
17395 #define THUMB_VARIANT & arm_ext_v6t2
17396
17397 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17398 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
17399 CL("teqp", 130f000, 2, (RR, SH), cmp),
17400
17401 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17402 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17403 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
17404 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
17405
17406 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17407 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17408
17409 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17410 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
17411
17412 /* V1 instructions with no Thumb analogue at all. */
17413 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
17414 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
17415
17416 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
17417 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
17418 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
17419 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
17420 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
17421 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
17422 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
17423 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
17424
17425 #undef ARM_VARIANT
17426 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
17427 #undef THUMB_VARIANT
17428 #define THUMB_VARIANT & arm_ext_v4t
17429
17430 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17431 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
17432
17433 #undef THUMB_VARIANT
17434 #define THUMB_VARIANT & arm_ext_v6t2
17435
17436 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17437 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
17438
17439 /* Generic coprocessor instructions. */
17440 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17441 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17442 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17443 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17444 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17445 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17446 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, APSR_RR, RCN, RCN, oI7b), co_reg, co_reg),
17447
17448 #undef ARM_VARIANT
17449 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
17450
17451 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17452 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
17453
17454 #undef ARM_VARIANT
17455 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
17456 #undef THUMB_VARIANT
17457 #define THUMB_VARIANT & arm_ext_msr
17458
17459 TCE("mrs", 1000000, f3e08000, 2, (RRnpc, rPSR), mrs, t_mrs),
17460 TCE("msr", 120f000, f3808000, 2, (wPSR, RR_EXi), msr, t_msr),
17461
17462 #undef ARM_VARIANT
17463 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
17464 #undef THUMB_VARIANT
17465 #define THUMB_VARIANT & arm_ext_v6t2
17466
17467 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17468 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17469 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17470 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17471 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17472 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17473 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
17474 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
17475
17476 #undef ARM_VARIANT
17477 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
17478 #undef THUMB_VARIANT
17479 #define THUMB_VARIANT & arm_ext_v4t
17480
17481 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17482 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17483 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17484 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17485 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17486 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
17487
17488 #undef ARM_VARIANT
17489 #define ARM_VARIANT & arm_ext_v4t_5
17490
17491 /* ARM Architecture 4T. */
17492 /* Note: bx (and blx) are required on V5, even if the processor does
17493 not support Thumb. */
17494 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
17495
17496 #undef ARM_VARIANT
17497 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
17498 #undef THUMB_VARIANT
17499 #define THUMB_VARIANT & arm_ext_v5t
17500
17501 /* Note: blx has 2 variants; the .value coded here is for
17502 BLX(2). Only this variant has conditional execution. */
17503 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
17504 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
17505
17506 #undef THUMB_VARIANT
17507 #define THUMB_VARIANT & arm_ext_v6t2
17508
17509 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
17510 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17511 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17512 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17513 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
17514 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
17515 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17516 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
17517
17518 #undef ARM_VARIANT
17519 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
17520 #undef THUMB_VARIANT
17521 #define THUMB_VARIANT &arm_ext_v5exp
17522
17523 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17524 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17525 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17526 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17527
17528 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17529 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
17530
17531 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17532 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17533 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17534 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
17535
17536 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17537 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17538 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17539 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17540
17541 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17542 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17543
17544 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17545 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17546 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17547 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
17548
17549 #undef ARM_VARIANT
17550 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
17551 #undef THUMB_VARIANT
17552 #define THUMB_VARIANT &arm_ext_v6t2
17553
17554 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
17555 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
17556 ldrd, t_ldstd),
17557 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
17558 ADDRGLDRS), ldrd, t_ldstd),
17559
17560 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17561 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17562
17563 #undef ARM_VARIANT
17564 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
17565
17566 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
17567
17568 #undef ARM_VARIANT
17569 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
17570 #undef THUMB_VARIANT
17571 #define THUMB_VARIANT & arm_ext_v6
17572
17573 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
17574 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
17575 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17576 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17577 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
17578 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17579 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17580 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17581 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17582 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
17583
17584 #undef THUMB_VARIANT
17585 #define THUMB_VARIANT & arm_ext_v6t2
17586
17587 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
17588 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17589 strex, t_strex),
17590 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17591 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
17592
17593 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
17594 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
17595
17596 /* ARM V6 not included in V7M. */
17597 #undef THUMB_VARIANT
17598 #define THUMB_VARIANT & arm_ext_v6_notm
17599 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17600 UF(rfeib, 9900a00, 1, (RRw), rfe),
17601 UF(rfeda, 8100a00, 1, (RRw), rfe),
17602 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17603 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
17604 UF(rfefa, 9900a00, 1, (RRw), rfe),
17605 UF(rfeea, 8100a00, 1, (RRw), rfe),
17606 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
17607 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
17608 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
17609 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
17610 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
17611
17612 /* ARM V6 not included in V7M (eg. integer SIMD). */
17613 #undef THUMB_VARIANT
17614 #define THUMB_VARIANT & arm_ext_v6_dsp
17615 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
17616 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
17617 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
17618 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17619 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17620 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17621 /* Old name for QASX. */
17622 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17623 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17624 /* Old name for QSAX. */
17625 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17626 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17627 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17628 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17629 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17630 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17631 /* Old name for SASX. */
17632 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17633 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17634 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17635 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17636 /* Old name for SHASX. */
17637 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17638 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17639 /* Old name for SHSAX. */
17640 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17641 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17642 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17643 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17644 /* Old name for SSAX. */
17645 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17646 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17647 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17648 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17649 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17650 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17651 /* Old name for UASX. */
17652 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17653 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17654 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17655 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17656 /* Old name for UHASX. */
17657 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17658 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17659 /* Old name for UHSAX. */
17660 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17661 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17662 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17663 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17664 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17665 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17666 /* Old name for UQASX. */
17667 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17668 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17669 /* Old name for UQSAX. */
17670 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17671 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17672 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17673 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17674 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17675 /* Old name for USAX. */
17676 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17677 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17678 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17679 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17680 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17681 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17682 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17683 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17684 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
17685 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
17686 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
17687 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17688 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17689 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17690 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17691 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17692 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17693 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17694 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
17695 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17696 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17697 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17698 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17699 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17700 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17701 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17702 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17703 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17704 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17705 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
17706 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
17707 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
17708 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
17709 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
17710
17711 #undef ARM_VARIANT
17712 #define ARM_VARIANT & arm_ext_v6k
17713 #undef THUMB_VARIANT
17714 #define THUMB_VARIANT & arm_ext_v6k
17715
17716 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
17717 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
17718 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
17719 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
17720
17721 #undef THUMB_VARIANT
17722 #define THUMB_VARIANT & arm_ext_v6_notm
17723 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
17724 ldrexd, t_ldrexd),
17725 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
17726 RRnpcb), strexd, t_strexd),
17727
17728 #undef THUMB_VARIANT
17729 #define THUMB_VARIANT & arm_ext_v6t2
17730 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
17731 rd_rn, rd_rn),
17732 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
17733 rd_rn, rd_rn),
17734 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17735 strex, t_strexbh),
17736 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
17737 strex, t_strexbh),
17738 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
17739
17740 #undef ARM_VARIANT
17741 #define ARM_VARIANT & arm_ext_sec
17742 #undef THUMB_VARIANT
17743 #define THUMB_VARIANT & arm_ext_sec
17744
17745 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
17746
17747 #undef ARM_VARIANT
17748 #define ARM_VARIANT & arm_ext_virt
17749 #undef THUMB_VARIANT
17750 #define THUMB_VARIANT & arm_ext_virt
17751
17752 TCE("hvc", 1400070, f7e08000, 1, (EXPi), hvc, t_hvc),
17753 TCE("eret", 160006e, f3de8f00, 0, (), noargs, noargs),
17754
17755 #undef ARM_VARIANT
17756 #define ARM_VARIANT & arm_ext_v6t2
17757 #undef THUMB_VARIANT
17758 #define THUMB_VARIANT & arm_ext_v6t2
17759
17760 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
17761 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
17762 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17763 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
17764
17765 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
17766 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
17767 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
17768 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
17769
17770 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17771 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17772 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17773 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
17774
17775 /* Thumb-only instructions. */
17776 #undef ARM_VARIANT
17777 #define ARM_VARIANT NULL
17778 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
17779 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
17780
17781 /* ARM does not really have an IT instruction, so always allow it.
17782 The opcode is copied from Thumb in order to allow warnings in
17783 -mimplicit-it=[never | arm] modes. */
17784 #undef ARM_VARIANT
17785 #define ARM_VARIANT & arm_ext_v1
17786
17787 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17788 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17789 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17790 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17791 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17792 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17793 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17794 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17795 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17796 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17797 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17798 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17799 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17800 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17801 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
17802 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
17803 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17804 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
17805
17806 /* Thumb2 only instructions. */
17807 #undef ARM_VARIANT
17808 #define ARM_VARIANT NULL
17809
17810 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17811 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17812 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17813 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17814 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17815 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
17816
17817 /* Hardware division instructions. */
17818 #undef ARM_VARIANT
17819 #define ARM_VARIANT & arm_ext_adiv
17820 #undef THUMB_VARIANT
17821 #define THUMB_VARIANT & arm_ext_div
17822
17823 TCE("sdiv", 710f010, fb90f0f0, 3, (RR, oRR, RR), div, t_div),
17824 TCE("udiv", 730f010, fbb0f0f0, 3, (RR, oRR, RR), div, t_div),
17825
17826 /* ARM V6M/V7 instructions. */
17827 #undef ARM_VARIANT
17828 #define ARM_VARIANT & arm_ext_barrier
17829 #undef THUMB_VARIANT
17830 #define THUMB_VARIANT & arm_ext_barrier
17831
17832 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17833 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17834 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
17835
17836 /* ARM V7 instructions. */
17837 #undef ARM_VARIANT
17838 #define ARM_VARIANT & arm_ext_v7
17839 #undef THUMB_VARIANT
17840 #define THUMB_VARIANT & arm_ext_v7
17841
17842 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17843 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
17844
17845 #undef ARM_VARIANT
17846 #define ARM_VARIANT & arm_ext_mp
17847 #undef THUMB_VARIANT
17848 #define THUMB_VARIANT & arm_ext_mp
17849
17850 TUF("pldw", 410f000, f830f000, 1, (ADDR), pld, t_pld),
17851
17852 #undef ARM_VARIANT
17853 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17854
17855 cCE("wfs", e200110, 1, (RR), rd),
17856 cCE("rfs", e300110, 1, (RR), rd),
17857 cCE("wfc", e400110, 1, (RR), rd),
17858 cCE("rfc", e500110, 1, (RR), rd),
17859
17860 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17861 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17862 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17863 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17864
17865 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17866 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17867 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17868 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17869
17870 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17871 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17872 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17873 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17874 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17875 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17876 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17877 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17878 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17879 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17880 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17881 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17882
17883 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17884 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17885 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17886 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17887 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17888 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17889 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17890 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17891 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17892 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17893 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17894 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17895
17896 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17897 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17898 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17899 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17900 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17901 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17902 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17903 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17904 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17905 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17906 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17907 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17908
17909 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17910 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17911 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17912 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17913 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17914 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17915 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17916 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17917 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17918 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17919 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17920 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17921
17922 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17923 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17924 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17925 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17926 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17927 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17928 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17929 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17930 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17931 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17932 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17933 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17934
17935 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17936 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17937 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17938 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17939 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17940 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17941 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17942 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17943 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17944 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17945 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17946 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17947
17948 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17949 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17950 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17951 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17952 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17953 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17954 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17955 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17956 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17957 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17958 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17959 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17960
17961 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17962 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17963 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17964 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17965 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17966 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17967 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17968 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17969 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17970 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17971 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17972 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17973
17974 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17975 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17976 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17977 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17978 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17979 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17980 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17981 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17982 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17983 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17984 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17985 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17986
17987 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17988 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17989 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17990 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17991 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17992 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17993 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17994 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17995 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17996 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17997 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17998 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17999
18000 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
18001 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
18002 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
18003 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
18004 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
18005 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
18006 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
18007 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
18008 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
18009 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
18010 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
18011 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
18012
18013 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
18014 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
18015 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
18016 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
18017 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
18018 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
18019 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
18020 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
18021 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
18022 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
18023 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
18024 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
18025
18026 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
18027 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
18028 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
18029 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
18030 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
18031 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
18032 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
18033 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
18034 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
18035 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
18036 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
18037 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
18038
18039 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
18040 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
18041 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
18042 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
18043 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
18044 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
18045 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
18046 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
18047 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
18048 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
18049 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
18050 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
18051
18052 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
18053 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
18054 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
18055 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
18056 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
18057 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
18058 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
18059 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
18060 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
18061 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
18062 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
18063 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
18064
18065 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
18066 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
18067 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
18068 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
18069 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
18070 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
18071 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
18072 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
18073 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
18074 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
18075 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
18076 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
18077
18078 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
18079 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
18080 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
18081 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
18082 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
18083 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18084 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18085 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18086 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
18087 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
18088 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
18089 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
18090
18091 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
18092 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
18093 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
18094 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
18095 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
18096 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18097 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18098 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18099 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
18100 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
18101 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
18102 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
18103
18104 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
18105 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
18106 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
18107 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
18108 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
18109 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18110 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18111 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18112 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
18113 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
18114 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
18115 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
18116
18117 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
18118 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
18119 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
18120 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
18121 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
18122 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18123 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18124 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18125 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
18126 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
18127 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
18128 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
18129
18130 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
18131 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
18132 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
18133 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
18134 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
18135 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18136 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18137 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18138 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
18139 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
18140 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
18141 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
18142
18143 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
18144 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
18145 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
18146 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
18147 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
18148 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18149 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18150 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18151 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
18152 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
18153 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
18154 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
18155
18156 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
18157 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
18158 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
18159 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
18160 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
18161 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18162 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18163 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18164 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
18165 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
18166 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
18167 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
18168
18169 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
18170 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
18171 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
18172 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
18173 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
18174 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18175 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18176 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18177 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
18178 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
18179 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
18180 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
18181
18182 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
18183 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
18184 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
18185 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
18186 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
18187 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18188 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18189 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18190 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
18191 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
18192 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
18193 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
18194
18195 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
18196 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
18197 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
18198 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
18199 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
18200 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18201 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18202 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18203 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
18204 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
18205 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
18206 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
18207
18208 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18209 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18210 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18211 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18212 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18213 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18214 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18215 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18216 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18217 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18218 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18219 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18220
18221 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18222 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18223 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18224 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18225 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18226 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18227 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18228 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18229 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18230 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18231 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18232 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18233
18234 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
18235 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
18236 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
18237 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
18238 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
18239 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
18240 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
18241 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
18242 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
18243 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
18244 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
18245 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
18246
18247 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
18248 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
18249 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
18250 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
18251
18252 cCL("flts", e000110, 2, (RF, RR), rn_rd),
18253 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
18254 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
18255 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
18256 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
18257 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
18258 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
18259 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
18260 cCL("flte", e080110, 2, (RF, RR), rn_rd),
18261 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
18262 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
18263 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
18264
18265 /* The implementation of the FIX instruction is broken on some
18266 assemblers, in that it accepts a precision specifier as well as a
18267 rounding specifier, despite the fact that this is meaningless.
18268 To be more compatible, we accept it as well, though of course it
18269 does not set any bits. */
18270 cCE("fix", e100110, 2, (RR, RF), rd_rm),
18271 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
18272 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
18273 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
18274 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
18275 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
18276 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
18277 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
18278 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
18279 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
18280 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
18281 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
18282 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
18283
18284 /* Instructions that were new with the real FPA, call them V2. */
18285 #undef ARM_VARIANT
18286 #define ARM_VARIANT & fpu_fpa_ext_v2
18287
18288 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18289 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18290 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18291 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18292 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18293 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
18294
18295 #undef ARM_VARIANT
18296 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
18297
18298 /* Moves and type conversions. */
18299 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
18300 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
18301 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
18302 cCE("fmstat", ef1fa10, 0, (), noargs),
18303 cCE("vmrs", ef00a10, 2, (APSR_RR, RVC), vmrs),
18304 cCE("vmsr", ee00a10, 2, (RVC, RR), vmsr),
18305 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
18306 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
18307 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
18308 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18309 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
18310 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
18311 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
18312 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
18313
18314 /* Memory operations. */
18315 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18316 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
18317 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18318 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18319 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18320 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18321 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18322 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18323 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18324 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18325 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18326 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
18327 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18328 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
18329 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18330 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
18331 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18332 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
18333
18334 /* Monadic operations. */
18335 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
18336 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
18337 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
18338
18339 /* Dyadic operations. */
18340 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18341 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18342 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18343 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18344 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18345 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18346 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18347 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18348 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18349
18350 /* Comparisons. */
18351 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
18352 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
18353 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
18354 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
18355
18356 /* Double precision load/store are still present on single precision
18357 implementations. */
18358 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18359 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
18360 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18361 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18362 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18363 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18364 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18365 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
18366 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18367 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
18368
18369 #undef ARM_VARIANT
18370 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
18371
18372 /* Moves and type conversions. */
18373 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18374 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18375 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18376 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
18377 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
18378 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
18379 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
18380 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
18381 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
18382 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18383 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18384 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
18385 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
18386
18387 /* Monadic operations. */
18388 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18389 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18390 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18391
18392 /* Dyadic operations. */
18393 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18394 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18395 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18396 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18397 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18398 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18399 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18400 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18401 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18402
18403 /* Comparisons. */
18404 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
18405 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
18406 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
18407 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
18408
18409 #undef ARM_VARIANT
18410 #define ARM_VARIANT & fpu_vfp_ext_v2
18411
18412 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
18413 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
18414 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
18415 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
18416
18417 /* Instructions which may belong to either the Neon or VFP instruction sets.
18418 Individual encoder functions perform additional architecture checks. */
18419 #undef ARM_VARIANT
18420 #define ARM_VARIANT & fpu_vfp_ext_v1xd
18421 #undef THUMB_VARIANT
18422 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
18423
18424 /* These mnemonics are unique to VFP. */
18425 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
18426 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
18427 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18428 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18429 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18430 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18431 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
18432 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
18433 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
18434 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
18435
18436 /* Mnemonics shared by Neon and VFP. */
18437 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
18438 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18439 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
18440
18441 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18442 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
18443
18444 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18445 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
18446
18447 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18448 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18449 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18450 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18451 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18452 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
18453 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18454 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
18455
18456 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32z), neon_cvt),
18457 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
18458 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
18459 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
18460
18461
18462 /* NOTE: All VMOV encoding is special-cased! */
18463 NCE(vmov, 0, 1, (VMOV), neon_mov),
18464 NCE(vmovq, 0, 1, (VMOV), neon_mov),
18465
18466 #undef THUMB_VARIANT
18467 #define THUMB_VARIANT & fpu_neon_ext_v1
18468 #undef ARM_VARIANT
18469 #define ARM_VARIANT & fpu_neon_ext_v1
18470
18471 /* Data processing with three registers of the same length. */
18472 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
18473 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
18474 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
18475 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18476 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18477 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18478 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18479 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
18480 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
18481 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
18482 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18483 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18484 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
18485 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
18486 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18487 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18488 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
18489 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
18490 /* If not immediate, fall back to neon_dyadic_i64_su.
18491 shl_imm should accept I8 I16 I32 I64,
18492 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
18493 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
18494 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
18495 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
18496 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
18497 /* Logic ops, types optional & ignored. */
18498 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18499 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18500 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18501 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18502 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18503 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18504 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
18505 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
18506 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
18507 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
18508 /* Bitfield ops, untyped. */
18509 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18510 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18511 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18512 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18513 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
18514 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
18515 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
18516 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18517 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18518 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18519 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18520 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
18521 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
18522 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
18523 back to neon_dyadic_if_su. */
18524 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18525 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18526 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
18527 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
18528 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18529 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18530 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
18531 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
18532 /* Comparison. Type I8 I16 I32 F32. */
18533 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
18534 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
18535 /* As above, D registers only. */
18536 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18537 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
18538 /* Int and float variants, signedness unimportant. */
18539 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18540 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
18541 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
18542 /* Add/sub take types I8 I16 I32 I64 F32. */
18543 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18544 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
18545 /* vtst takes sizes 8, 16, 32. */
18546 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
18547 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
18548 /* VMUL takes I8 I16 I32 F32 P8. */
18549 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
18550 /* VQD{R}MULH takes S16 S32. */
18551 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18552 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18553 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
18554 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
18555 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18556 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18557 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
18558 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
18559 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18560 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18561 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
18562 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
18563 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18564 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18565 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
18566 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
18567
18568 /* Two address, int/float. Types S8 S16 S32 F32. */
18569 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
18570 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
18571
18572 /* Data processing with two registers and a shift amount. */
18573 /* Right shifts, and variants with rounding.
18574 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
18575 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18576 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18577 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
18578 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
18579 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18580 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18581 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
18582 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
18583 /* Shift and insert. Sizes accepted 8 16 32 64. */
18584 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
18585 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
18586 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
18587 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
18588 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
18589 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
18590 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
18591 /* Right shift immediate, saturating & narrowing, with rounding variants.
18592 Types accepted S16 S32 S64 U16 U32 U64. */
18593 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18594 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
18595 /* As above, unsigned. Types accepted S16 S32 S64. */
18596 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18597 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
18598 /* Right shift narrowing. Types accepted I16 I32 I64. */
18599 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18600 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
18601 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
18602 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
18603 /* CVT with optional immediate for fixed-point variant. */
18604 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
18605
18606 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
18607 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
18608
18609 /* Data processing, three registers of different lengths. */
18610 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
18611 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
18612 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
18613 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
18614 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
18615 /* If not scalar, fall back to neon_dyadic_long.
18616 Vector types as above, scalar types S16 S32 U16 U32. */
18617 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18618 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
18619 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
18620 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18621 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
18622 /* Dyadic, narrowing insns. Types I16 I32 I64. */
18623 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18624 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18625 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18626 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
18627 /* Saturating doubling multiplies. Types S16 S32. */
18628 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18629 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18630 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
18631 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
18632 S16 S32 U16 U32. */
18633 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
18634
18635 /* Extract. Size 8. */
18636 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
18637 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
18638
18639 /* Two registers, miscellaneous. */
18640 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
18641 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
18642 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
18643 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
18644 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
18645 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
18646 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
18647 /* Vector replicate. Sizes 8 16 32. */
18648 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
18649 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
18650 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
18651 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
18652 /* VMOVN. Types I16 I32 I64. */
18653 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
18654 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
18655 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
18656 /* VQMOVUN. Types S16 S32 S64. */
18657 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
18658 /* VZIP / VUZP. Sizes 8 16 32. */
18659 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
18660 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
18661 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
18662 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
18663 /* VQABS / VQNEG. Types S8 S16 S32. */
18664 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18665 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
18666 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
18667 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
18668 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
18669 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
18670 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
18671 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
18672 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
18673 /* Reciprocal estimates. Types U32 F32. */
18674 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
18675 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
18676 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
18677 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
18678 /* VCLS. Types S8 S16 S32. */
18679 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
18680 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
18681 /* VCLZ. Types I8 I16 I32. */
18682 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
18683 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
18684 /* VCNT. Size 8. */
18685 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
18686 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
18687 /* Two address, untyped. */
18688 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
18689 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
18690 /* VTRN. Sizes 8 16 32. */
18691 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
18692 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
18693
18694 /* Table lookup. Size 8. */
18695 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18696 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
18697
18698 #undef THUMB_VARIANT
18699 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
18700 #undef ARM_VARIANT
18701 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
18702
18703 /* Neon element/structure load/store. */
18704 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18705 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
18706 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18707 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
18708 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18709 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
18710 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18711 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
18712
18713 #undef THUMB_VARIANT
18714 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
18715 #undef ARM_VARIANT
18716 #define ARM_VARIANT &fpu_vfp_ext_v3xd
18717 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
18718 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18719 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18720 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18721 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18722 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18723 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18724 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
18725 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
18726
18727 #undef THUMB_VARIANT
18728 #define THUMB_VARIANT & fpu_vfp_ext_v3
18729 #undef ARM_VARIANT
18730 #define ARM_VARIANT & fpu_vfp_ext_v3
18731
18732 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
18733 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18734 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18735 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18736 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18737 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18738 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18739 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
18740 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
18741
18742 #undef ARM_VARIANT
18743 #define ARM_VARIANT &fpu_vfp_ext_fma
18744 #undef THUMB_VARIANT
18745 #define THUMB_VARIANT &fpu_vfp_ext_fma
18746 /* Mnemonics shared by Neon and VFP. These are included in the
18747 VFP FMA variant; NEON and VFP FMA always includes the NEON
18748 FMA instructions. */
18749 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18750 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
18751 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
18752 the v form should always be used. */
18753 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18754 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
18755 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18756 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
18757 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18758 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
18759
18760 #undef THUMB_VARIANT
18761 #undef ARM_VARIANT
18762 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
18763
18764 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18765 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18766 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18767 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18768 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18769 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
18770 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
18771 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
18772
18773 #undef ARM_VARIANT
18774 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
18775
18776 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
18777 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
18778 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
18779 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
18780 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
18781 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
18782 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
18783 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
18784 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
18785 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18786 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18787 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
18788 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18789 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18790 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
18791 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18792 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18793 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18794 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18795 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18796 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18797 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18798 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18799 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18800 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18801 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18802 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18803 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18804 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18805 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18806 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18807 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18808 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18809 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18810 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18811 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18812 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18813 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18814 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18815 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18816 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18817 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18818 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18819 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18820 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18821 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18822 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18823 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18824 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18825 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18826 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18827 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18828 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18829 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18830 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18831 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18832 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18833 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18834 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18835 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18836 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18837 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18838 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18839 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18840 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18841 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18842 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18843 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18844 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18845 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18846 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18847 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18848 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18849 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18850 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18851 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18852 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18853 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18854 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18855 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18856 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18857 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18858 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18859 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18860 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18861 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18862 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18863 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18864 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18865 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18866 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18867 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18868 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18869 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18870 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18871 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18872 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18873 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18874 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18875 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18876 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18877 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18878 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18879 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18880 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18881 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18882 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18883 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18884 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18885 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18886 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18887 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18888 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18889 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18890 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18891 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18892 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18893 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18894 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18895 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18896 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18897 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18898 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18899 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18900 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18901 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18902 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18903 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18904 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18905 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18906 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18907 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18908 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18909 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18910 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18911 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18912 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18913 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18914 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18915 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18916 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18917 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18918 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18919 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18920 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18921 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18922 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18923 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18924 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18925 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18926 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18927 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18928 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18929 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18930 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18931 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18932 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18933 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18934 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18935 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18936 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18937 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
18938
18939 #undef ARM_VARIANT
18940 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18941
18942 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18943 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18944 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18945 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18946 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18947 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18948 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18949 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18950 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18951 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18952 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18953 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18954 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18955 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18956 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18957 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18958 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18959 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18960 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18961 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18962 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18963 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18964 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18965 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18966 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18967 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18968 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18969 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18970 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18971 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18972 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18973 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18974 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18975 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18976 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18977 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18978 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18979 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18980 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18981 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18982 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18983 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18984 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18985 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18986 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18987 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18988 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18989 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18990 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18991 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18992 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18993 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18994 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18995 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18996 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18997 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18998 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18999
19000 #undef ARM_VARIANT
19001 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
19002
19003 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19004 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19005 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19006 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19007 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
19008 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
19009 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
19010 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
19011 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
19012 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
19013 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
19014 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
19015 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
19016 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
19017 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
19018 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
19019 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
19020 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
19021 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
19022 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
19023 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
19024 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
19025 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
19026 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
19027 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
19028 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
19029 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
19030 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
19031 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
19032 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
19033 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
19034 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
19035 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
19036 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
19037 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
19038 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
19039 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
19040 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
19041 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
19042 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
19043 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
19044 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
19045 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
19046 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
19047 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
19048 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
19049 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
19050 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
19051 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
19052 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
19053 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
19054 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
19055 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
19056 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
19057 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
19058 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
19059 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
19060 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
19061 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
19062 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
19063 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
19064 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
19065 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
19066 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
19067 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19068 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19069 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19070 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19071 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19072 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
19073 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19074 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
19075 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19076 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
19077 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
19078 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
19079 };
19080 #undef ARM_VARIANT
19081 #undef THUMB_VARIANT
19082 #undef TCE
19083 #undef TCM
19084 #undef TUE
19085 #undef TUF
19086 #undef TCC
19087 #undef cCE
19088 #undef cCL
19089 #undef C3E
19090 #undef CE
19091 #undef CM
19092 #undef UE
19093 #undef UF
19094 #undef UT
19095 #undef NUF
19096 #undef nUF
19097 #undef NCE
19098 #undef nCE
19099 #undef OPS0
19100 #undef OPS1
19101 #undef OPS2
19102 #undef OPS3
19103 #undef OPS4
19104 #undef OPS5
19105 #undef OPS6
19106 #undef do_0
19107 \f
19108 /* MD interface: bits in the object file. */
19109
19110 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
19111 for use in the a.out file, and stores them in the array pointed to by buf.
19112 This knows about the endian-ness of the target machine and does
19113 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
19114 2 (short) and 4 (long) Floating numbers are put out as a series of
19115 LITTLENUMS (shorts, here at least). */
19116
19117 void
19118 md_number_to_chars (char * buf, valueT val, int n)
19119 {
19120 if (target_big_endian)
19121 number_to_chars_bigendian (buf, val, n);
19122 else
19123 number_to_chars_littleendian (buf, val, n);
19124 }
19125
19126 static valueT
19127 md_chars_to_number (char * buf, int n)
19128 {
19129 valueT result = 0;
19130 unsigned char * where = (unsigned char *) buf;
19131
19132 if (target_big_endian)
19133 {
19134 while (n--)
19135 {
19136 result <<= 8;
19137 result |= (*where++ & 255);
19138 }
19139 }
19140 else
19141 {
19142 while (n--)
19143 {
19144 result <<= 8;
19145 result |= (where[n] & 255);
19146 }
19147 }
19148
19149 return result;
19150 }
19151
19152 /* MD interface: Sections. */
19153
19154 /* Calculate the maximum variable size (i.e., excluding fr_fix)
19155 that an rs_machine_dependent frag may reach. */
19156
19157 unsigned int
19158 arm_frag_max_var (fragS *fragp)
19159 {
19160 /* We only use rs_machine_dependent for variable-size Thumb instructions,
19161 which are either THUMB_SIZE (2) or INSN_SIZE (4).
19162
19163 Note that we generate relaxable instructions even for cases that don't
19164 really need it, like an immediate that's a trivial constant. So we're
19165 overestimating the instruction size for some of those cases. Rather
19166 than putting more intelligence here, it would probably be better to
19167 avoid generating a relaxation frag in the first place when it can be
19168 determined up front that a short instruction will suffice. */
19169
19170 gas_assert (fragp->fr_type == rs_machine_dependent);
19171 return INSN_SIZE;
19172 }
19173
19174 /* Estimate the size of a frag before relaxing. Assume everything fits in
19175 2 bytes. */
19176
19177 int
19178 md_estimate_size_before_relax (fragS * fragp,
19179 segT segtype ATTRIBUTE_UNUSED)
19180 {
19181 fragp->fr_var = 2;
19182 return 2;
19183 }
19184
19185 /* Convert a machine dependent frag. */
19186
19187 void
19188 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
19189 {
19190 unsigned long insn;
19191 unsigned long old_op;
19192 char *buf;
19193 expressionS exp;
19194 fixS *fixp;
19195 int reloc_type;
19196 int pc_rel;
19197 int opcode;
19198
19199 buf = fragp->fr_literal + fragp->fr_fix;
19200
19201 old_op = bfd_get_16(abfd, buf);
19202 if (fragp->fr_symbol)
19203 {
19204 exp.X_op = O_symbol;
19205 exp.X_add_symbol = fragp->fr_symbol;
19206 }
19207 else
19208 {
19209 exp.X_op = O_constant;
19210 }
19211 exp.X_add_number = fragp->fr_offset;
19212 opcode = fragp->fr_subtype;
19213 switch (opcode)
19214 {
19215 case T_MNEM_ldr_pc:
19216 case T_MNEM_ldr_pc2:
19217 case T_MNEM_ldr_sp:
19218 case T_MNEM_str_sp:
19219 case T_MNEM_ldr:
19220 case T_MNEM_ldrb:
19221 case T_MNEM_ldrh:
19222 case T_MNEM_str:
19223 case T_MNEM_strb:
19224 case T_MNEM_strh:
19225 if (fragp->fr_var == 4)
19226 {
19227 insn = THUMB_OP32 (opcode);
19228 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
19229 {
19230 insn |= (old_op & 0x700) << 4;
19231 }
19232 else
19233 {
19234 insn |= (old_op & 7) << 12;
19235 insn |= (old_op & 0x38) << 13;
19236 }
19237 insn |= 0x00000c00;
19238 put_thumb32_insn (buf, insn);
19239 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
19240 }
19241 else
19242 {
19243 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
19244 }
19245 pc_rel = (opcode == T_MNEM_ldr_pc2);
19246 break;
19247 case T_MNEM_adr:
19248 if (fragp->fr_var == 4)
19249 {
19250 insn = THUMB_OP32 (opcode);
19251 insn |= (old_op & 0xf0) << 4;
19252 put_thumb32_insn (buf, insn);
19253 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
19254 }
19255 else
19256 {
19257 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19258 exp.X_add_number -= 4;
19259 }
19260 pc_rel = 1;
19261 break;
19262 case T_MNEM_mov:
19263 case T_MNEM_movs:
19264 case T_MNEM_cmp:
19265 case T_MNEM_cmn:
19266 if (fragp->fr_var == 4)
19267 {
19268 int r0off = (opcode == T_MNEM_mov
19269 || opcode == T_MNEM_movs) ? 0 : 8;
19270 insn = THUMB_OP32 (opcode);
19271 insn = (insn & 0xe1ffffff) | 0x10000000;
19272 insn |= (old_op & 0x700) << r0off;
19273 put_thumb32_insn (buf, insn);
19274 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19275 }
19276 else
19277 {
19278 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
19279 }
19280 pc_rel = 0;
19281 break;
19282 case T_MNEM_b:
19283 if (fragp->fr_var == 4)
19284 {
19285 insn = THUMB_OP32(opcode);
19286 put_thumb32_insn (buf, insn);
19287 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
19288 }
19289 else
19290 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
19291 pc_rel = 1;
19292 break;
19293 case T_MNEM_bcond:
19294 if (fragp->fr_var == 4)
19295 {
19296 insn = THUMB_OP32(opcode);
19297 insn |= (old_op & 0xf00) << 14;
19298 put_thumb32_insn (buf, insn);
19299 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
19300 }
19301 else
19302 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
19303 pc_rel = 1;
19304 break;
19305 case T_MNEM_add_sp:
19306 case T_MNEM_add_pc:
19307 case T_MNEM_inc_sp:
19308 case T_MNEM_dec_sp:
19309 if (fragp->fr_var == 4)
19310 {
19311 /* ??? Choose between add and addw. */
19312 insn = THUMB_OP32 (opcode);
19313 insn |= (old_op & 0xf0) << 4;
19314 put_thumb32_insn (buf, insn);
19315 if (opcode == T_MNEM_add_pc)
19316 reloc_type = BFD_RELOC_ARM_T32_IMM12;
19317 else
19318 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19319 }
19320 else
19321 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19322 pc_rel = 0;
19323 break;
19324
19325 case T_MNEM_addi:
19326 case T_MNEM_addis:
19327 case T_MNEM_subi:
19328 case T_MNEM_subis:
19329 if (fragp->fr_var == 4)
19330 {
19331 insn = THUMB_OP32 (opcode);
19332 insn |= (old_op & 0xf0) << 4;
19333 insn |= (old_op & 0xf) << 16;
19334 put_thumb32_insn (buf, insn);
19335 if (insn & (1 << 20))
19336 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
19337 else
19338 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
19339 }
19340 else
19341 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
19342 pc_rel = 0;
19343 break;
19344 default:
19345 abort ();
19346 }
19347 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
19348 (enum bfd_reloc_code_real) reloc_type);
19349 fixp->fx_file = fragp->fr_file;
19350 fixp->fx_line = fragp->fr_line;
19351 fragp->fr_fix += fragp->fr_var;
19352 }
19353
19354 /* Return the size of a relaxable immediate operand instruction.
19355 SHIFT and SIZE specify the form of the allowable immediate. */
19356 static int
19357 relax_immediate (fragS *fragp, int size, int shift)
19358 {
19359 offsetT offset;
19360 offsetT mask;
19361 offsetT low;
19362
19363 /* ??? Should be able to do better than this. */
19364 if (fragp->fr_symbol)
19365 return 4;
19366
19367 low = (1 << shift) - 1;
19368 mask = (1 << (shift + size)) - (1 << shift);
19369 offset = fragp->fr_offset;
19370 /* Force misaligned offsets to 32-bit variant. */
19371 if (offset & low)
19372 return 4;
19373 if (offset & ~mask)
19374 return 4;
19375 return 2;
19376 }
19377
19378 /* Get the address of a symbol during relaxation. */
19379 static addressT
19380 relaxed_symbol_addr (fragS *fragp, long stretch)
19381 {
19382 fragS *sym_frag;
19383 addressT addr;
19384 symbolS *sym;
19385
19386 sym = fragp->fr_symbol;
19387 sym_frag = symbol_get_frag (sym);
19388 know (S_GET_SEGMENT (sym) != absolute_section
19389 || sym_frag == &zero_address_frag);
19390 addr = S_GET_VALUE (sym) + fragp->fr_offset;
19391
19392 /* If frag has yet to be reached on this pass, assume it will
19393 move by STRETCH just as we did. If this is not so, it will
19394 be because some frag between grows, and that will force
19395 another pass. */
19396
19397 if (stretch != 0
19398 && sym_frag->relax_marker != fragp->relax_marker)
19399 {
19400 fragS *f;
19401
19402 /* Adjust stretch for any alignment frag. Note that if have
19403 been expanding the earlier code, the symbol may be
19404 defined in what appears to be an earlier frag. FIXME:
19405 This doesn't handle the fr_subtype field, which specifies
19406 a maximum number of bytes to skip when doing an
19407 alignment. */
19408 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
19409 {
19410 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
19411 {
19412 if (stretch < 0)
19413 stretch = - ((- stretch)
19414 & ~ ((1 << (int) f->fr_offset) - 1));
19415 else
19416 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
19417 if (stretch == 0)
19418 break;
19419 }
19420 }
19421 if (f != NULL)
19422 addr += stretch;
19423 }
19424
19425 return addr;
19426 }
19427
19428 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
19429 load. */
19430 static int
19431 relax_adr (fragS *fragp, asection *sec, long stretch)
19432 {
19433 addressT addr;
19434 offsetT val;
19435
19436 /* Assume worst case for symbols not known to be in the same section. */
19437 if (fragp->fr_symbol == NULL
19438 || !S_IS_DEFINED (fragp->fr_symbol)
19439 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19440 || S_IS_WEAK (fragp->fr_symbol))
19441 return 4;
19442
19443 val = relaxed_symbol_addr (fragp, stretch);
19444 addr = fragp->fr_address + fragp->fr_fix;
19445 addr = (addr + 4) & ~3;
19446 /* Force misaligned targets to 32-bit variant. */
19447 if (val & 3)
19448 return 4;
19449 val -= addr;
19450 if (val < 0 || val > 1020)
19451 return 4;
19452 return 2;
19453 }
19454
19455 /* Return the size of a relaxable add/sub immediate instruction. */
19456 static int
19457 relax_addsub (fragS *fragp, asection *sec)
19458 {
19459 char *buf;
19460 int op;
19461
19462 buf = fragp->fr_literal + fragp->fr_fix;
19463 op = bfd_get_16(sec->owner, buf);
19464 if ((op & 0xf) == ((op >> 4) & 0xf))
19465 return relax_immediate (fragp, 8, 0);
19466 else
19467 return relax_immediate (fragp, 3, 0);
19468 }
19469
19470
19471 /* Return the size of a relaxable branch instruction. BITS is the
19472 size of the offset field in the narrow instruction. */
19473
19474 static int
19475 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
19476 {
19477 addressT addr;
19478 offsetT val;
19479 offsetT limit;
19480
19481 /* Assume worst case for symbols not known to be in the same section. */
19482 if (!S_IS_DEFINED (fragp->fr_symbol)
19483 || sec != S_GET_SEGMENT (fragp->fr_symbol)
19484 || S_IS_WEAK (fragp->fr_symbol))
19485 return 4;
19486
19487 #ifdef OBJ_ELF
19488 if (S_IS_DEFINED (fragp->fr_symbol)
19489 && ARM_IS_FUNC (fragp->fr_symbol))
19490 return 4;
19491
19492 /* PR 12532. Global symbols with default visibility might
19493 be preempted, so do not relax relocations to them. */
19494 if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragp->fr_symbol)) == STV_DEFAULT)
19495 && (! S_IS_LOCAL (fragp->fr_symbol)))
19496 return 4;
19497 #endif
19498
19499 val = relaxed_symbol_addr (fragp, stretch);
19500 addr = fragp->fr_address + fragp->fr_fix + 4;
19501 val -= addr;
19502
19503 /* Offset is a signed value *2 */
19504 limit = 1 << bits;
19505 if (val >= limit || val < -limit)
19506 return 4;
19507 return 2;
19508 }
19509
19510
19511 /* Relax a machine dependent frag. This returns the amount by which
19512 the current size of the frag should change. */
19513
19514 int
19515 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
19516 {
19517 int oldsize;
19518 int newsize;
19519
19520 oldsize = fragp->fr_var;
19521 switch (fragp->fr_subtype)
19522 {
19523 case T_MNEM_ldr_pc2:
19524 newsize = relax_adr (fragp, sec, stretch);
19525 break;
19526 case T_MNEM_ldr_pc:
19527 case T_MNEM_ldr_sp:
19528 case T_MNEM_str_sp:
19529 newsize = relax_immediate (fragp, 8, 2);
19530 break;
19531 case T_MNEM_ldr:
19532 case T_MNEM_str:
19533 newsize = relax_immediate (fragp, 5, 2);
19534 break;
19535 case T_MNEM_ldrh:
19536 case T_MNEM_strh:
19537 newsize = relax_immediate (fragp, 5, 1);
19538 break;
19539 case T_MNEM_ldrb:
19540 case T_MNEM_strb:
19541 newsize = relax_immediate (fragp, 5, 0);
19542 break;
19543 case T_MNEM_adr:
19544 newsize = relax_adr (fragp, sec, stretch);
19545 break;
19546 case T_MNEM_mov:
19547 case T_MNEM_movs:
19548 case T_MNEM_cmp:
19549 case T_MNEM_cmn:
19550 newsize = relax_immediate (fragp, 8, 0);
19551 break;
19552 case T_MNEM_b:
19553 newsize = relax_branch (fragp, sec, 11, stretch);
19554 break;
19555 case T_MNEM_bcond:
19556 newsize = relax_branch (fragp, sec, 8, stretch);
19557 break;
19558 case T_MNEM_add_sp:
19559 case T_MNEM_add_pc:
19560 newsize = relax_immediate (fragp, 8, 2);
19561 break;
19562 case T_MNEM_inc_sp:
19563 case T_MNEM_dec_sp:
19564 newsize = relax_immediate (fragp, 7, 2);
19565 break;
19566 case T_MNEM_addi:
19567 case T_MNEM_addis:
19568 case T_MNEM_subi:
19569 case T_MNEM_subis:
19570 newsize = relax_addsub (fragp, sec);
19571 break;
19572 default:
19573 abort ();
19574 }
19575
19576 fragp->fr_var = newsize;
19577 /* Freeze wide instructions that are at or before the same location as
19578 in the previous pass. This avoids infinite loops.
19579 Don't freeze them unconditionally because targets may be artificially
19580 misaligned by the expansion of preceding frags. */
19581 if (stretch <= 0 && newsize > 2)
19582 {
19583 md_convert_frag (sec->owner, sec, fragp);
19584 frag_wane (fragp);
19585 }
19586
19587 return newsize - oldsize;
19588 }
19589
19590 /* Round up a section size to the appropriate boundary. */
19591
19592 valueT
19593 md_section_align (segT segment ATTRIBUTE_UNUSED,
19594 valueT size)
19595 {
19596 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
19597 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
19598 {
19599 /* For a.out, force the section size to be aligned. If we don't do
19600 this, BFD will align it for us, but it will not write out the
19601 final bytes of the section. This may be a bug in BFD, but it is
19602 easier to fix it here since that is how the other a.out targets
19603 work. */
19604 int align;
19605
19606 align = bfd_get_section_alignment (stdoutput, segment);
19607 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
19608 }
19609 #endif
19610
19611 return size;
19612 }
19613
19614 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
19615 of an rs_align_code fragment. */
19616
19617 void
19618 arm_handle_align (fragS * fragP)
19619 {
19620 static char const arm_noop[2][2][4] =
19621 {
19622 { /* ARMv1 */
19623 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
19624 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
19625 },
19626 { /* ARMv6k */
19627 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
19628 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
19629 },
19630 };
19631 static char const thumb_noop[2][2][2] =
19632 {
19633 { /* Thumb-1 */
19634 {0xc0, 0x46}, /* LE */
19635 {0x46, 0xc0}, /* BE */
19636 },
19637 { /* Thumb-2 */
19638 {0x00, 0xbf}, /* LE */
19639 {0xbf, 0x00} /* BE */
19640 }
19641 };
19642 static char const wide_thumb_noop[2][4] =
19643 { /* Wide Thumb-2 */
19644 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
19645 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
19646 };
19647
19648 unsigned bytes, fix, noop_size;
19649 char * p;
19650 const char * noop;
19651 const char *narrow_noop = NULL;
19652 #ifdef OBJ_ELF
19653 enum mstate state;
19654 #endif
19655
19656 if (fragP->fr_type != rs_align_code)
19657 return;
19658
19659 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
19660 p = fragP->fr_literal + fragP->fr_fix;
19661 fix = 0;
19662
19663 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
19664 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
19665
19666 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
19667
19668 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
19669 {
19670 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
19671 {
19672 narrow_noop = thumb_noop[1][target_big_endian];
19673 noop = wide_thumb_noop[target_big_endian];
19674 }
19675 else
19676 noop = thumb_noop[0][target_big_endian];
19677 noop_size = 2;
19678 #ifdef OBJ_ELF
19679 state = MAP_THUMB;
19680 #endif
19681 }
19682 else
19683 {
19684 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
19685 [target_big_endian];
19686 noop_size = 4;
19687 #ifdef OBJ_ELF
19688 state = MAP_ARM;
19689 #endif
19690 }
19691
19692 fragP->fr_var = noop_size;
19693
19694 if (bytes & (noop_size - 1))
19695 {
19696 fix = bytes & (noop_size - 1);
19697 #ifdef OBJ_ELF
19698 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
19699 #endif
19700 memset (p, 0, fix);
19701 p += fix;
19702 bytes -= fix;
19703 }
19704
19705 if (narrow_noop)
19706 {
19707 if (bytes & noop_size)
19708 {
19709 /* Insert a narrow noop. */
19710 memcpy (p, narrow_noop, noop_size);
19711 p += noop_size;
19712 bytes -= noop_size;
19713 fix += noop_size;
19714 }
19715
19716 /* Use wide noops for the remainder */
19717 noop_size = 4;
19718 }
19719
19720 while (bytes >= noop_size)
19721 {
19722 memcpy (p, noop, noop_size);
19723 p += noop_size;
19724 bytes -= noop_size;
19725 fix += noop_size;
19726 }
19727
19728 fragP->fr_fix += fix;
19729 }
19730
19731 /* Called from md_do_align. Used to create an alignment
19732 frag in a code section. */
19733
19734 void
19735 arm_frag_align_code (int n, int max)
19736 {
19737 char * p;
19738
19739 /* We assume that there will never be a requirement
19740 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
19741 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
19742 {
19743 char err_msg[128];
19744
19745 sprintf (err_msg,
19746 _("alignments greater than %d bytes not supported in .text sections."),
19747 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
19748 as_fatal ("%s", err_msg);
19749 }
19750
19751 p = frag_var (rs_align_code,
19752 MAX_MEM_FOR_RS_ALIGN_CODE,
19753 1,
19754 (relax_substateT) max,
19755 (symbolS *) NULL,
19756 (offsetT) n,
19757 (char *) NULL);
19758 *p = 0;
19759 }
19760
19761 /* Perform target specific initialisation of a frag.
19762 Note - despite the name this initialisation is not done when the frag
19763 is created, but only when its type is assigned. A frag can be created
19764 and used a long time before its type is set, so beware of assuming that
19765 this initialisationis performed first. */
19766
19767 #ifndef OBJ_ELF
19768 void
19769 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
19770 {
19771 /* Record whether this frag is in an ARM or a THUMB area. */
19772 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19773 }
19774
19775 #else /* OBJ_ELF is defined. */
19776 void
19777 arm_init_frag (fragS * fragP, int max_chars)
19778 {
19779 /* If the current ARM vs THUMB mode has not already
19780 been recorded into this frag then do so now. */
19781 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
19782 {
19783 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
19784
19785 /* Record a mapping symbol for alignment frags. We will delete this
19786 later if the alignment ends up empty. */
19787 switch (fragP->fr_type)
19788 {
19789 case rs_align:
19790 case rs_align_test:
19791 case rs_fill:
19792 mapping_state_2 (MAP_DATA, max_chars);
19793 break;
19794 case rs_align_code:
19795 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
19796 break;
19797 default:
19798 break;
19799 }
19800 }
19801 }
19802
19803 /* When we change sections we need to issue a new mapping symbol. */
19804
19805 void
19806 arm_elf_change_section (void)
19807 {
19808 /* Link an unlinked unwind index table section to the .text section. */
19809 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
19810 && elf_linked_to_section (now_seg) == NULL)
19811 elf_linked_to_section (now_seg) = text_section;
19812 }
19813
19814 int
19815 arm_elf_section_type (const char * str, size_t len)
19816 {
19817 if (len == 5 && strncmp (str, "exidx", 5) == 0)
19818 return SHT_ARM_EXIDX;
19819
19820 return -1;
19821 }
19822 \f
19823 /* Code to deal with unwinding tables. */
19824
19825 static void add_unwind_adjustsp (offsetT);
19826
19827 /* Generate any deferred unwind frame offset. */
19828
19829 static void
19830 flush_pending_unwind (void)
19831 {
19832 offsetT offset;
19833
19834 offset = unwind.pending_offset;
19835 unwind.pending_offset = 0;
19836 if (offset != 0)
19837 add_unwind_adjustsp (offset);
19838 }
19839
19840 /* Add an opcode to this list for this function. Two-byte opcodes should
19841 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19842 order. */
19843
19844 static void
19845 add_unwind_opcode (valueT op, int length)
19846 {
19847 /* Add any deferred stack adjustment. */
19848 if (unwind.pending_offset)
19849 flush_pending_unwind ();
19850
19851 unwind.sp_restored = 0;
19852
19853 if (unwind.opcode_count + length > unwind.opcode_alloc)
19854 {
19855 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19856 if (unwind.opcodes)
19857 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19858 unwind.opcode_alloc);
19859 else
19860 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
19861 }
19862 while (length > 0)
19863 {
19864 length--;
19865 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19866 op >>= 8;
19867 unwind.opcode_count++;
19868 }
19869 }
19870
19871 /* Add unwind opcodes to adjust the stack pointer. */
19872
19873 static void
19874 add_unwind_adjustsp (offsetT offset)
19875 {
19876 valueT op;
19877
19878 if (offset > 0x200)
19879 {
19880 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19881 char bytes[5];
19882 int n;
19883 valueT o;
19884
19885 /* Long form: 0xb2, uleb128. */
19886 /* This might not fit in a word so add the individual bytes,
19887 remembering the list is built in reverse order. */
19888 o = (valueT) ((offset - 0x204) >> 2);
19889 if (o == 0)
19890 add_unwind_opcode (0, 1);
19891
19892 /* Calculate the uleb128 encoding of the offset. */
19893 n = 0;
19894 while (o)
19895 {
19896 bytes[n] = o & 0x7f;
19897 o >>= 7;
19898 if (o)
19899 bytes[n] |= 0x80;
19900 n++;
19901 }
19902 /* Add the insn. */
19903 for (; n; n--)
19904 add_unwind_opcode (bytes[n - 1], 1);
19905 add_unwind_opcode (0xb2, 1);
19906 }
19907 else if (offset > 0x100)
19908 {
19909 /* Two short opcodes. */
19910 add_unwind_opcode (0x3f, 1);
19911 op = (offset - 0x104) >> 2;
19912 add_unwind_opcode (op, 1);
19913 }
19914 else if (offset > 0)
19915 {
19916 /* Short opcode. */
19917 op = (offset - 4) >> 2;
19918 add_unwind_opcode (op, 1);
19919 }
19920 else if (offset < 0)
19921 {
19922 offset = -offset;
19923 while (offset > 0x100)
19924 {
19925 add_unwind_opcode (0x7f, 1);
19926 offset -= 0x100;
19927 }
19928 op = ((offset - 4) >> 2) | 0x40;
19929 add_unwind_opcode (op, 1);
19930 }
19931 }
19932
19933 /* Finish the list of unwind opcodes for this function. */
19934 static void
19935 finish_unwind_opcodes (void)
19936 {
19937 valueT op;
19938
19939 if (unwind.fp_used)
19940 {
19941 /* Adjust sp as necessary. */
19942 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19943 flush_pending_unwind ();
19944
19945 /* After restoring sp from the frame pointer. */
19946 op = 0x90 | unwind.fp_reg;
19947 add_unwind_opcode (op, 1);
19948 }
19949 else
19950 flush_pending_unwind ();
19951 }
19952
19953
19954 /* Start an exception table entry. If idx is nonzero this is an index table
19955 entry. */
19956
19957 static void
19958 start_unwind_section (const segT text_seg, int idx)
19959 {
19960 const char * text_name;
19961 const char * prefix;
19962 const char * prefix_once;
19963 const char * group_name;
19964 size_t prefix_len;
19965 size_t text_len;
19966 char * sec_name;
19967 size_t sec_name_len;
19968 int type;
19969 int flags;
19970 int linkonce;
19971
19972 if (idx)
19973 {
19974 prefix = ELF_STRING_ARM_unwind;
19975 prefix_once = ELF_STRING_ARM_unwind_once;
19976 type = SHT_ARM_EXIDX;
19977 }
19978 else
19979 {
19980 prefix = ELF_STRING_ARM_unwind_info;
19981 prefix_once = ELF_STRING_ARM_unwind_info_once;
19982 type = SHT_PROGBITS;
19983 }
19984
19985 text_name = segment_name (text_seg);
19986 if (streq (text_name, ".text"))
19987 text_name = "";
19988
19989 if (strncmp (text_name, ".gnu.linkonce.t.",
19990 strlen (".gnu.linkonce.t.")) == 0)
19991 {
19992 prefix = prefix_once;
19993 text_name += strlen (".gnu.linkonce.t.");
19994 }
19995
19996 prefix_len = strlen (prefix);
19997 text_len = strlen (text_name);
19998 sec_name_len = prefix_len + text_len;
19999 sec_name = (char *) xmalloc (sec_name_len + 1);
20000 memcpy (sec_name, prefix, prefix_len);
20001 memcpy (sec_name + prefix_len, text_name, text_len);
20002 sec_name[prefix_len + text_len] = '\0';
20003
20004 flags = SHF_ALLOC;
20005 linkonce = 0;
20006 group_name = 0;
20007
20008 /* Handle COMDAT group. */
20009 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
20010 {
20011 group_name = elf_group_name (text_seg);
20012 if (group_name == NULL)
20013 {
20014 as_bad (_("Group section `%s' has no group signature"),
20015 segment_name (text_seg));
20016 ignore_rest_of_line ();
20017 return;
20018 }
20019 flags |= SHF_GROUP;
20020 linkonce = 1;
20021 }
20022
20023 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
20024
20025 /* Set the section link for index tables. */
20026 if (idx)
20027 elf_linked_to_section (now_seg) = text_seg;
20028 }
20029
20030
20031 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
20032 personality routine data. Returns zero, or the index table value for
20033 and inline entry. */
20034
20035 static valueT
20036 create_unwind_entry (int have_data)
20037 {
20038 int size;
20039 addressT where;
20040 char *ptr;
20041 /* The current word of data. */
20042 valueT data;
20043 /* The number of bytes left in this word. */
20044 int n;
20045
20046 finish_unwind_opcodes ();
20047
20048 /* Remember the current text section. */
20049 unwind.saved_seg = now_seg;
20050 unwind.saved_subseg = now_subseg;
20051
20052 start_unwind_section (now_seg, 0);
20053
20054 if (unwind.personality_routine == NULL)
20055 {
20056 if (unwind.personality_index == -2)
20057 {
20058 if (have_data)
20059 as_bad (_("handlerdata in cantunwind frame"));
20060 return 1; /* EXIDX_CANTUNWIND. */
20061 }
20062
20063 /* Use a default personality routine if none is specified. */
20064 if (unwind.personality_index == -1)
20065 {
20066 if (unwind.opcode_count > 3)
20067 unwind.personality_index = 1;
20068 else
20069 unwind.personality_index = 0;
20070 }
20071
20072 /* Space for the personality routine entry. */
20073 if (unwind.personality_index == 0)
20074 {
20075 if (unwind.opcode_count > 3)
20076 as_bad (_("too many unwind opcodes for personality routine 0"));
20077
20078 if (!have_data)
20079 {
20080 /* All the data is inline in the index table. */
20081 data = 0x80;
20082 n = 3;
20083 while (unwind.opcode_count > 0)
20084 {
20085 unwind.opcode_count--;
20086 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20087 n--;
20088 }
20089
20090 /* Pad with "finish" opcodes. */
20091 while (n--)
20092 data = (data << 8) | 0xb0;
20093
20094 return data;
20095 }
20096 size = 0;
20097 }
20098 else
20099 /* We get two opcodes "free" in the first word. */
20100 size = unwind.opcode_count - 2;
20101 }
20102 else
20103 {
20104 gas_assert (unwind.personality_index == -1);
20105
20106 /* An extra byte is required for the opcode count. */
20107 size = unwind.opcode_count + 1;
20108 }
20109
20110 size = (size + 3) >> 2;
20111 if (size > 0xff)
20112 as_bad (_("too many unwind opcodes"));
20113
20114 frag_align (2, 0, 0);
20115 record_alignment (now_seg, 2);
20116 unwind.table_entry = expr_build_dot ();
20117
20118 /* Allocate the table entry. */
20119 ptr = frag_more ((size << 2) + 4);
20120 /* PR 13449: Zero the table entries in case some of them are not used. */
20121 memset (ptr, 0, (size << 2) + 4);
20122 where = frag_now_fix () - ((size << 2) + 4);
20123
20124 switch (unwind.personality_index)
20125 {
20126 case -1:
20127 /* ??? Should this be a PLT generating relocation? */
20128 /* Custom personality routine. */
20129 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
20130 BFD_RELOC_ARM_PREL31);
20131
20132 where += 4;
20133 ptr += 4;
20134
20135 /* Set the first byte to the number of additional words. */
20136 data = size > 0 ? size - 1 : 0;
20137 n = 3;
20138 break;
20139
20140 /* ABI defined personality routines. */
20141 case 0:
20142 /* Three opcodes bytes are packed into the first word. */
20143 data = 0x80;
20144 n = 3;
20145 break;
20146
20147 case 1:
20148 case 2:
20149 /* The size and first two opcode bytes go in the first word. */
20150 data = ((0x80 + unwind.personality_index) << 8) | size;
20151 n = 2;
20152 break;
20153
20154 default:
20155 /* Should never happen. */
20156 abort ();
20157 }
20158
20159 /* Pack the opcodes into words (MSB first), reversing the list at the same
20160 time. */
20161 while (unwind.opcode_count > 0)
20162 {
20163 if (n == 0)
20164 {
20165 md_number_to_chars (ptr, data, 4);
20166 ptr += 4;
20167 n = 4;
20168 data = 0;
20169 }
20170 unwind.opcode_count--;
20171 n--;
20172 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
20173 }
20174
20175 /* Finish off the last word. */
20176 if (n < 4)
20177 {
20178 /* Pad with "finish" opcodes. */
20179 while (n--)
20180 data = (data << 8) | 0xb0;
20181
20182 md_number_to_chars (ptr, data, 4);
20183 }
20184
20185 if (!have_data)
20186 {
20187 /* Add an empty descriptor if there is no user-specified data. */
20188 ptr = frag_more (4);
20189 md_number_to_chars (ptr, 0, 4);
20190 }
20191
20192 return 0;
20193 }
20194
20195
20196 /* Initialize the DWARF-2 unwind information for this procedure. */
20197
20198 void
20199 tc_arm_frame_initial_instructions (void)
20200 {
20201 cfi_add_CFA_def_cfa (REG_SP, 0);
20202 }
20203 #endif /* OBJ_ELF */
20204
20205 /* Convert REGNAME to a DWARF-2 register number. */
20206
20207 int
20208 tc_arm_regname_to_dw2regnum (char *regname)
20209 {
20210 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
20211
20212 if (reg == FAIL)
20213 return -1;
20214
20215 return reg;
20216 }
20217
20218 #ifdef TE_PE
20219 void
20220 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
20221 {
20222 expressionS exp;
20223
20224 exp.X_op = O_secrel;
20225 exp.X_add_symbol = symbol;
20226 exp.X_add_number = 0;
20227 emit_expr (&exp, size);
20228 }
20229 #endif
20230
20231 /* MD interface: Symbol and relocation handling. */
20232
20233 /* Return the address within the segment that a PC-relative fixup is
20234 relative to. For ARM, PC-relative fixups applied to instructions
20235 are generally relative to the location of the fixup plus 8 bytes.
20236 Thumb branches are offset by 4, and Thumb loads relative to PC
20237 require special handling. */
20238
20239 long
20240 md_pcrel_from_section (fixS * fixP, segT seg)
20241 {
20242 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
20243
20244 /* If this is pc-relative and we are going to emit a relocation
20245 then we just want to put out any pipeline compensation that the linker
20246 will need. Otherwise we want to use the calculated base.
20247 For WinCE we skip the bias for externals as well, since this
20248 is how the MS ARM-CE assembler behaves and we want to be compatible. */
20249 if (fixP->fx_pcrel
20250 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
20251 || (arm_force_relocation (fixP)
20252 #ifdef TE_WINCE
20253 && !S_IS_EXTERNAL (fixP->fx_addsy)
20254 #endif
20255 )))
20256 base = 0;
20257
20258
20259 switch (fixP->fx_r_type)
20260 {
20261 /* PC relative addressing on the Thumb is slightly odd as the
20262 bottom two bits of the PC are forced to zero for the
20263 calculation. This happens *after* application of the
20264 pipeline offset. However, Thumb adrl already adjusts for
20265 this, so we need not do it again. */
20266 case BFD_RELOC_ARM_THUMB_ADD:
20267 return base & ~3;
20268
20269 case BFD_RELOC_ARM_THUMB_OFFSET:
20270 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20271 case BFD_RELOC_ARM_T32_ADD_PC12:
20272 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20273 return (base + 4) & ~3;
20274
20275 /* Thumb branches are simply offset by +4. */
20276 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20277 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20278 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20279 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20280 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20281 return base + 4;
20282
20283 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20284 if (fixP->fx_addsy
20285 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20286 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20287 && ARM_IS_FUNC (fixP->fx_addsy)
20288 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20289 base = fixP->fx_where + fixP->fx_frag->fr_address;
20290 return base + 4;
20291
20292 /* BLX is like branches above, but forces the low two bits of PC to
20293 zero. */
20294 case BFD_RELOC_THUMB_PCREL_BLX:
20295 if (fixP->fx_addsy
20296 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20297 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20298 && THUMB_IS_FUNC (fixP->fx_addsy)
20299 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20300 base = fixP->fx_where + fixP->fx_frag->fr_address;
20301 return (base + 4) & ~3;
20302
20303 /* ARM mode branches are offset by +8. However, the Windows CE
20304 loader expects the relocation not to take this into account. */
20305 case BFD_RELOC_ARM_PCREL_BLX:
20306 if (fixP->fx_addsy
20307 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20308 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20309 && ARM_IS_FUNC (fixP->fx_addsy)
20310 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20311 base = fixP->fx_where + fixP->fx_frag->fr_address;
20312 return base + 8;
20313
20314 case BFD_RELOC_ARM_PCREL_CALL:
20315 if (fixP->fx_addsy
20316 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20317 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
20318 && THUMB_IS_FUNC (fixP->fx_addsy)
20319 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20320 base = fixP->fx_where + fixP->fx_frag->fr_address;
20321 return base + 8;
20322
20323 case BFD_RELOC_ARM_PCREL_BRANCH:
20324 case BFD_RELOC_ARM_PCREL_JUMP:
20325 case BFD_RELOC_ARM_PLT32:
20326 #ifdef TE_WINCE
20327 /* When handling fixups immediately, because we have already
20328 discovered the value of a symbol, or the address of the frag involved
20329 we must account for the offset by +8, as the OS loader will never see the reloc.
20330 see fixup_segment() in write.c
20331 The S_IS_EXTERNAL test handles the case of global symbols.
20332 Those need the calculated base, not just the pipe compensation the linker will need. */
20333 if (fixP->fx_pcrel
20334 && fixP->fx_addsy != NULL
20335 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20336 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
20337 return base + 8;
20338 return base;
20339 #else
20340 return base + 8;
20341 #endif
20342
20343
20344 /* ARM mode loads relative to PC are also offset by +8. Unlike
20345 branches, the Windows CE loader *does* expect the relocation
20346 to take this into account. */
20347 case BFD_RELOC_ARM_OFFSET_IMM:
20348 case BFD_RELOC_ARM_OFFSET_IMM8:
20349 case BFD_RELOC_ARM_HWLITERAL:
20350 case BFD_RELOC_ARM_LITERAL:
20351 case BFD_RELOC_ARM_CP_OFF_IMM:
20352 return base + 8;
20353
20354
20355 /* Other PC-relative relocations are un-offset. */
20356 default:
20357 return base;
20358 }
20359 }
20360
20361 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
20362 Otherwise we have no need to default values of symbols. */
20363
20364 symbolS *
20365 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
20366 {
20367 #ifdef OBJ_ELF
20368 if (name[0] == '_' && name[1] == 'G'
20369 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
20370 {
20371 if (!GOT_symbol)
20372 {
20373 if (symbol_find (name))
20374 as_bad (_("GOT already in the symbol table"));
20375
20376 GOT_symbol = symbol_new (name, undefined_section,
20377 (valueT) 0, & zero_address_frag);
20378 }
20379
20380 return GOT_symbol;
20381 }
20382 #endif
20383
20384 return NULL;
20385 }
20386
20387 /* Subroutine of md_apply_fix. Check to see if an immediate can be
20388 computed as two separate immediate values, added together. We
20389 already know that this value cannot be computed by just one ARM
20390 instruction. */
20391
20392 static unsigned int
20393 validate_immediate_twopart (unsigned int val,
20394 unsigned int * highpart)
20395 {
20396 unsigned int a;
20397 unsigned int i;
20398
20399 for (i = 0; i < 32; i += 2)
20400 if (((a = rotate_left (val, i)) & 0xff) != 0)
20401 {
20402 if (a & 0xff00)
20403 {
20404 if (a & ~ 0xffff)
20405 continue;
20406 * highpart = (a >> 8) | ((i + 24) << 7);
20407 }
20408 else if (a & 0xff0000)
20409 {
20410 if (a & 0xff000000)
20411 continue;
20412 * highpart = (a >> 16) | ((i + 16) << 7);
20413 }
20414 else
20415 {
20416 gas_assert (a & 0xff000000);
20417 * highpart = (a >> 24) | ((i + 8) << 7);
20418 }
20419
20420 return (a & 0xff) | (i << 7);
20421 }
20422
20423 return FAIL;
20424 }
20425
20426 static int
20427 validate_offset_imm (unsigned int val, int hwse)
20428 {
20429 if ((hwse && val > 255) || val > 4095)
20430 return FAIL;
20431 return val;
20432 }
20433
20434 /* Subroutine of md_apply_fix. Do those data_ops which can take a
20435 negative immediate constant by altering the instruction. A bit of
20436 a hack really.
20437 MOV <-> MVN
20438 AND <-> BIC
20439 ADC <-> SBC
20440 by inverting the second operand, and
20441 ADD <-> SUB
20442 CMP <-> CMN
20443 by negating the second operand. */
20444
20445 static int
20446 negate_data_op (unsigned long * instruction,
20447 unsigned long value)
20448 {
20449 int op, new_inst;
20450 unsigned long negated, inverted;
20451
20452 negated = encode_arm_immediate (-value);
20453 inverted = encode_arm_immediate (~value);
20454
20455 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
20456 switch (op)
20457 {
20458 /* First negates. */
20459 case OPCODE_SUB: /* ADD <-> SUB */
20460 new_inst = OPCODE_ADD;
20461 value = negated;
20462 break;
20463
20464 case OPCODE_ADD:
20465 new_inst = OPCODE_SUB;
20466 value = negated;
20467 break;
20468
20469 case OPCODE_CMP: /* CMP <-> CMN */
20470 new_inst = OPCODE_CMN;
20471 value = negated;
20472 break;
20473
20474 case OPCODE_CMN:
20475 new_inst = OPCODE_CMP;
20476 value = negated;
20477 break;
20478
20479 /* Now Inverted ops. */
20480 case OPCODE_MOV: /* MOV <-> MVN */
20481 new_inst = OPCODE_MVN;
20482 value = inverted;
20483 break;
20484
20485 case OPCODE_MVN:
20486 new_inst = OPCODE_MOV;
20487 value = inverted;
20488 break;
20489
20490 case OPCODE_AND: /* AND <-> BIC */
20491 new_inst = OPCODE_BIC;
20492 value = inverted;
20493 break;
20494
20495 case OPCODE_BIC:
20496 new_inst = OPCODE_AND;
20497 value = inverted;
20498 break;
20499
20500 case OPCODE_ADC: /* ADC <-> SBC */
20501 new_inst = OPCODE_SBC;
20502 value = inverted;
20503 break;
20504
20505 case OPCODE_SBC:
20506 new_inst = OPCODE_ADC;
20507 value = inverted;
20508 break;
20509
20510 /* We cannot do anything. */
20511 default:
20512 return FAIL;
20513 }
20514
20515 if (value == (unsigned) FAIL)
20516 return FAIL;
20517
20518 *instruction &= OPCODE_MASK;
20519 *instruction |= new_inst << DATA_OP_SHIFT;
20520 return value;
20521 }
20522
20523 /* Like negate_data_op, but for Thumb-2. */
20524
20525 static unsigned int
20526 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
20527 {
20528 int op, new_inst;
20529 int rd;
20530 unsigned int negated, inverted;
20531
20532 negated = encode_thumb32_immediate (-value);
20533 inverted = encode_thumb32_immediate (~value);
20534
20535 rd = (*instruction >> 8) & 0xf;
20536 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
20537 switch (op)
20538 {
20539 /* ADD <-> SUB. Includes CMP <-> CMN. */
20540 case T2_OPCODE_SUB:
20541 new_inst = T2_OPCODE_ADD;
20542 value = negated;
20543 break;
20544
20545 case T2_OPCODE_ADD:
20546 new_inst = T2_OPCODE_SUB;
20547 value = negated;
20548 break;
20549
20550 /* ORR <-> ORN. Includes MOV <-> MVN. */
20551 case T2_OPCODE_ORR:
20552 new_inst = T2_OPCODE_ORN;
20553 value = inverted;
20554 break;
20555
20556 case T2_OPCODE_ORN:
20557 new_inst = T2_OPCODE_ORR;
20558 value = inverted;
20559 break;
20560
20561 /* AND <-> BIC. TST has no inverted equivalent. */
20562 case T2_OPCODE_AND:
20563 new_inst = T2_OPCODE_BIC;
20564 if (rd == 15)
20565 value = FAIL;
20566 else
20567 value = inverted;
20568 break;
20569
20570 case T2_OPCODE_BIC:
20571 new_inst = T2_OPCODE_AND;
20572 value = inverted;
20573 break;
20574
20575 /* ADC <-> SBC */
20576 case T2_OPCODE_ADC:
20577 new_inst = T2_OPCODE_SBC;
20578 value = inverted;
20579 break;
20580
20581 case T2_OPCODE_SBC:
20582 new_inst = T2_OPCODE_ADC;
20583 value = inverted;
20584 break;
20585
20586 /* We cannot do anything. */
20587 default:
20588 return FAIL;
20589 }
20590
20591 if (value == (unsigned int)FAIL)
20592 return FAIL;
20593
20594 *instruction &= T2_OPCODE_MASK;
20595 *instruction |= new_inst << T2_DATA_OP_SHIFT;
20596 return value;
20597 }
20598
20599 /* Read a 32-bit thumb instruction from buf. */
20600 static unsigned long
20601 get_thumb32_insn (char * buf)
20602 {
20603 unsigned long insn;
20604 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
20605 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20606
20607 return insn;
20608 }
20609
20610
20611 /* We usually want to set the low bit on the address of thumb function
20612 symbols. In particular .word foo - . should have the low bit set.
20613 Generic code tries to fold the difference of two symbols to
20614 a constant. Prevent this and force a relocation when the first symbols
20615 is a thumb function. */
20616
20617 bfd_boolean
20618 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
20619 {
20620 if (op == O_subtract
20621 && l->X_op == O_symbol
20622 && r->X_op == O_symbol
20623 && THUMB_IS_FUNC (l->X_add_symbol))
20624 {
20625 l->X_op = O_subtract;
20626 l->X_op_symbol = r->X_add_symbol;
20627 l->X_add_number -= r->X_add_number;
20628 return TRUE;
20629 }
20630
20631 /* Process as normal. */
20632 return FALSE;
20633 }
20634
20635 /* Encode Thumb2 unconditional branches and calls. The encoding
20636 for the 2 are identical for the immediate values. */
20637
20638 static void
20639 encode_thumb2_b_bl_offset (char * buf, offsetT value)
20640 {
20641 #define T2I1I2MASK ((1 << 13) | (1 << 11))
20642 offsetT newval;
20643 offsetT newval2;
20644 addressT S, I1, I2, lo, hi;
20645
20646 S = (value >> 24) & 0x01;
20647 I1 = (value >> 23) & 0x01;
20648 I2 = (value >> 22) & 0x01;
20649 hi = (value >> 12) & 0x3ff;
20650 lo = (value >> 1) & 0x7ff;
20651 newval = md_chars_to_number (buf, THUMB_SIZE);
20652 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20653 newval |= (S << 10) | hi;
20654 newval2 &= ~T2I1I2MASK;
20655 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
20656 md_number_to_chars (buf, newval, THUMB_SIZE);
20657 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20658 }
20659
20660 void
20661 md_apply_fix (fixS * fixP,
20662 valueT * valP,
20663 segT seg)
20664 {
20665 offsetT value = * valP;
20666 offsetT newval;
20667 unsigned int newimm;
20668 unsigned long temp;
20669 int sign;
20670 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
20671
20672 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
20673
20674 /* Note whether this will delete the relocation. */
20675
20676 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
20677 fixP->fx_done = 1;
20678
20679 /* On a 64-bit host, silently truncate 'value' to 32 bits for
20680 consistency with the behaviour on 32-bit hosts. Remember value
20681 for emit_reloc. */
20682 value &= 0xffffffff;
20683 value ^= 0x80000000;
20684 value -= 0x80000000;
20685
20686 *valP = value;
20687 fixP->fx_addnumber = value;
20688
20689 /* Same treatment for fixP->fx_offset. */
20690 fixP->fx_offset &= 0xffffffff;
20691 fixP->fx_offset ^= 0x80000000;
20692 fixP->fx_offset -= 0x80000000;
20693
20694 switch (fixP->fx_r_type)
20695 {
20696 case BFD_RELOC_NONE:
20697 /* This will need to go in the object file. */
20698 fixP->fx_done = 0;
20699 break;
20700
20701 case BFD_RELOC_ARM_IMMEDIATE:
20702 /* We claim that this fixup has been processed here,
20703 even if in fact we generate an error because we do
20704 not have a reloc for it, so tc_gen_reloc will reject it. */
20705 fixP->fx_done = 1;
20706
20707 if (fixP->fx_addsy)
20708 {
20709 const char *msg = 0;
20710
20711 if (! S_IS_DEFINED (fixP->fx_addsy))
20712 msg = _("undefined symbol %s used as an immediate value");
20713 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20714 msg = _("symbol %s is in a different section");
20715 else if (S_IS_WEAK (fixP->fx_addsy))
20716 msg = _("symbol %s is weak and may be overridden later");
20717
20718 if (msg)
20719 {
20720 as_bad_where (fixP->fx_file, fixP->fx_line,
20721 msg, S_GET_NAME (fixP->fx_addsy));
20722 break;
20723 }
20724 }
20725
20726 temp = md_chars_to_number (buf, INSN_SIZE);
20727
20728 /* If the offset is negative, we should use encoding A2 for ADR. */
20729 if ((temp & 0xfff0000) == 0x28f0000 && value < 0)
20730 newimm = negate_data_op (&temp, value);
20731 else
20732 {
20733 newimm = encode_arm_immediate (value);
20734
20735 /* If the instruction will fail, see if we can fix things up by
20736 changing the opcode. */
20737 if (newimm == (unsigned int) FAIL)
20738 newimm = negate_data_op (&temp, value);
20739 }
20740
20741 if (newimm == (unsigned int) FAIL)
20742 {
20743 as_bad_where (fixP->fx_file, fixP->fx_line,
20744 _("invalid constant (%lx) after fixup"),
20745 (unsigned long) value);
20746 break;
20747 }
20748
20749 newimm |= (temp & 0xfffff000);
20750 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20751 break;
20752
20753 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20754 {
20755 unsigned int highpart = 0;
20756 unsigned int newinsn = 0xe1a00000; /* nop. */
20757
20758 if (fixP->fx_addsy)
20759 {
20760 const char *msg = 0;
20761
20762 if (! S_IS_DEFINED (fixP->fx_addsy))
20763 msg = _("undefined symbol %s used as an immediate value");
20764 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
20765 msg = _("symbol %s is in a different section");
20766 else if (S_IS_WEAK (fixP->fx_addsy))
20767 msg = _("symbol %s is weak and may be overridden later");
20768
20769 if (msg)
20770 {
20771 as_bad_where (fixP->fx_file, fixP->fx_line,
20772 msg, S_GET_NAME (fixP->fx_addsy));
20773 break;
20774 }
20775 }
20776
20777 newimm = encode_arm_immediate (value);
20778 temp = md_chars_to_number (buf, INSN_SIZE);
20779
20780 /* If the instruction will fail, see if we can fix things up by
20781 changing the opcode. */
20782 if (newimm == (unsigned int) FAIL
20783 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
20784 {
20785 /* No ? OK - try using two ADD instructions to generate
20786 the value. */
20787 newimm = validate_immediate_twopart (value, & highpart);
20788
20789 /* Yes - then make sure that the second instruction is
20790 also an add. */
20791 if (newimm != (unsigned int) FAIL)
20792 newinsn = temp;
20793 /* Still No ? Try using a negated value. */
20794 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
20795 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
20796 /* Otherwise - give up. */
20797 else
20798 {
20799 as_bad_where (fixP->fx_file, fixP->fx_line,
20800 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
20801 (long) value);
20802 break;
20803 }
20804
20805 /* Replace the first operand in the 2nd instruction (which
20806 is the PC) with the destination register. We have
20807 already added in the PC in the first instruction and we
20808 do not want to do it again. */
20809 newinsn &= ~ 0xf0000;
20810 newinsn |= ((newinsn & 0x0f000) << 4);
20811 }
20812
20813 newimm |= (temp & 0xfffff000);
20814 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
20815
20816 highpart |= (newinsn & 0xfffff000);
20817 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
20818 }
20819 break;
20820
20821 case BFD_RELOC_ARM_OFFSET_IMM:
20822 if (!fixP->fx_done && seg->use_rela_p)
20823 value = 0;
20824
20825 case BFD_RELOC_ARM_LITERAL:
20826 sign = value > 0;
20827
20828 if (value < 0)
20829 value = - value;
20830
20831 if (validate_offset_imm (value, 0) == FAIL)
20832 {
20833 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
20834 as_bad_where (fixP->fx_file, fixP->fx_line,
20835 _("invalid literal constant: pool needs to be closer"));
20836 else
20837 as_bad_where (fixP->fx_file, fixP->fx_line,
20838 _("bad immediate value for offset (%ld)"),
20839 (long) value);
20840 break;
20841 }
20842
20843 newval = md_chars_to_number (buf, INSN_SIZE);
20844 if (value == 0)
20845 newval &= 0xfffff000;
20846 else
20847 {
20848 newval &= 0xff7ff000;
20849 newval |= value | (sign ? INDEX_UP : 0);
20850 }
20851 md_number_to_chars (buf, newval, INSN_SIZE);
20852 break;
20853
20854 case BFD_RELOC_ARM_OFFSET_IMM8:
20855 case BFD_RELOC_ARM_HWLITERAL:
20856 sign = value > 0;
20857
20858 if (value < 0)
20859 value = - value;
20860
20861 if (validate_offset_imm (value, 1) == FAIL)
20862 {
20863 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20864 as_bad_where (fixP->fx_file, fixP->fx_line,
20865 _("invalid literal constant: pool needs to be closer"));
20866 else
20867 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
20868 (long) value);
20869 break;
20870 }
20871
20872 newval = md_chars_to_number (buf, INSN_SIZE);
20873 if (value == 0)
20874 newval &= 0xfffff0f0;
20875 else
20876 {
20877 newval &= 0xff7ff0f0;
20878 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20879 }
20880 md_number_to_chars (buf, newval, INSN_SIZE);
20881 break;
20882
20883 case BFD_RELOC_ARM_T32_OFFSET_U8:
20884 if (value < 0 || value > 1020 || value % 4 != 0)
20885 as_bad_where (fixP->fx_file, fixP->fx_line,
20886 _("bad immediate value for offset (%ld)"), (long) value);
20887 value /= 4;
20888
20889 newval = md_chars_to_number (buf+2, THUMB_SIZE);
20890 newval |= value;
20891 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20892 break;
20893
20894 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20895 /* This is a complicated relocation used for all varieties of Thumb32
20896 load/store instruction with immediate offset:
20897
20898 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20899 *4, optional writeback(W)
20900 (doubleword load/store)
20901
20902 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20903 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20904 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20905 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20906 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20907
20908 Uppercase letters indicate bits that are already encoded at
20909 this point. Lowercase letters are our problem. For the
20910 second block of instructions, the secondary opcode nybble
20911 (bits 8..11) is present, and bit 23 is zero, even if this is
20912 a PC-relative operation. */
20913 newval = md_chars_to_number (buf, THUMB_SIZE);
20914 newval <<= 16;
20915 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
20916
20917 if ((newval & 0xf0000000) == 0xe0000000)
20918 {
20919 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20920 if (value >= 0)
20921 newval |= (1 << 23);
20922 else
20923 value = -value;
20924 if (value % 4 != 0)
20925 {
20926 as_bad_where (fixP->fx_file, fixP->fx_line,
20927 _("offset not a multiple of 4"));
20928 break;
20929 }
20930 value /= 4;
20931 if (value > 0xff)
20932 {
20933 as_bad_where (fixP->fx_file, fixP->fx_line,
20934 _("offset out of range"));
20935 break;
20936 }
20937 newval &= ~0xff;
20938 }
20939 else if ((newval & 0x000f0000) == 0x000f0000)
20940 {
20941 /* PC-relative, 12-bit offset. */
20942 if (value >= 0)
20943 newval |= (1 << 23);
20944 else
20945 value = -value;
20946 if (value > 0xfff)
20947 {
20948 as_bad_where (fixP->fx_file, fixP->fx_line,
20949 _("offset out of range"));
20950 break;
20951 }
20952 newval &= ~0xfff;
20953 }
20954 else if ((newval & 0x00000100) == 0x00000100)
20955 {
20956 /* Writeback: 8-bit, +/- offset. */
20957 if (value >= 0)
20958 newval |= (1 << 9);
20959 else
20960 value = -value;
20961 if (value > 0xff)
20962 {
20963 as_bad_where (fixP->fx_file, fixP->fx_line,
20964 _("offset out of range"));
20965 break;
20966 }
20967 newval &= ~0xff;
20968 }
20969 else if ((newval & 0x00000f00) == 0x00000e00)
20970 {
20971 /* T-instruction: positive 8-bit offset. */
20972 if (value < 0 || value > 0xff)
20973 {
20974 as_bad_where (fixP->fx_file, fixP->fx_line,
20975 _("offset out of range"));
20976 break;
20977 }
20978 newval &= ~0xff;
20979 newval |= value;
20980 }
20981 else
20982 {
20983 /* Positive 12-bit or negative 8-bit offset. */
20984 int limit;
20985 if (value >= 0)
20986 {
20987 newval |= (1 << 23);
20988 limit = 0xfff;
20989 }
20990 else
20991 {
20992 value = -value;
20993 limit = 0xff;
20994 }
20995 if (value > limit)
20996 {
20997 as_bad_where (fixP->fx_file, fixP->fx_line,
20998 _("offset out of range"));
20999 break;
21000 }
21001 newval &= ~limit;
21002 }
21003
21004 newval |= value;
21005 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
21006 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
21007 break;
21008
21009 case BFD_RELOC_ARM_SHIFT_IMM:
21010 newval = md_chars_to_number (buf, INSN_SIZE);
21011 if (((unsigned long) value) > 32
21012 || (value == 32
21013 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
21014 {
21015 as_bad_where (fixP->fx_file, fixP->fx_line,
21016 _("shift expression is too large"));
21017 break;
21018 }
21019
21020 if (value == 0)
21021 /* Shifts of zero must be done as lsl. */
21022 newval &= ~0x60;
21023 else if (value == 32)
21024 value = 0;
21025 newval &= 0xfffff07f;
21026 newval |= (value & 0x1f) << 7;
21027 md_number_to_chars (buf, newval, INSN_SIZE);
21028 break;
21029
21030 case BFD_RELOC_ARM_T32_IMMEDIATE:
21031 case BFD_RELOC_ARM_T32_ADD_IMM:
21032 case BFD_RELOC_ARM_T32_IMM12:
21033 case BFD_RELOC_ARM_T32_ADD_PC12:
21034 /* We claim that this fixup has been processed here,
21035 even if in fact we generate an error because we do
21036 not have a reloc for it, so tc_gen_reloc will reject it. */
21037 fixP->fx_done = 1;
21038
21039 if (fixP->fx_addsy
21040 && ! S_IS_DEFINED (fixP->fx_addsy))
21041 {
21042 as_bad_where (fixP->fx_file, fixP->fx_line,
21043 _("undefined symbol %s used as an immediate value"),
21044 S_GET_NAME (fixP->fx_addsy));
21045 break;
21046 }
21047
21048 newval = md_chars_to_number (buf, THUMB_SIZE);
21049 newval <<= 16;
21050 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
21051
21052 newimm = FAIL;
21053 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21054 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
21055 {
21056 newimm = encode_thumb32_immediate (value);
21057 if (newimm == (unsigned int) FAIL)
21058 newimm = thumb32_negate_data_op (&newval, value);
21059 }
21060 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
21061 && newimm == (unsigned int) FAIL)
21062 {
21063 /* Turn add/sum into addw/subw. */
21064 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
21065 newval = (newval & 0xfeffffff) | 0x02000000;
21066 /* No flat 12-bit imm encoding for addsw/subsw. */
21067 if ((newval & 0x00100000) == 0)
21068 {
21069 /* 12 bit immediate for addw/subw. */
21070 if (value < 0)
21071 {
21072 value = -value;
21073 newval ^= 0x00a00000;
21074 }
21075 if (value > 0xfff)
21076 newimm = (unsigned int) FAIL;
21077 else
21078 newimm = value;
21079 }
21080 }
21081
21082 if (newimm == (unsigned int)FAIL)
21083 {
21084 as_bad_where (fixP->fx_file, fixP->fx_line,
21085 _("invalid constant (%lx) after fixup"),
21086 (unsigned long) value);
21087 break;
21088 }
21089
21090 newval |= (newimm & 0x800) << 15;
21091 newval |= (newimm & 0x700) << 4;
21092 newval |= (newimm & 0x0ff);
21093
21094 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
21095 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
21096 break;
21097
21098 case BFD_RELOC_ARM_SMC:
21099 if (((unsigned long) value) > 0xffff)
21100 as_bad_where (fixP->fx_file, fixP->fx_line,
21101 _("invalid smc expression"));
21102 newval = md_chars_to_number (buf, INSN_SIZE);
21103 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21104 md_number_to_chars (buf, newval, INSN_SIZE);
21105 break;
21106
21107 case BFD_RELOC_ARM_HVC:
21108 if (((unsigned long) value) > 0xffff)
21109 as_bad_where (fixP->fx_file, fixP->fx_line,
21110 _("invalid hvc expression"));
21111 newval = md_chars_to_number (buf, INSN_SIZE);
21112 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
21113 md_number_to_chars (buf, newval, INSN_SIZE);
21114 break;
21115
21116 case BFD_RELOC_ARM_SWI:
21117 if (fixP->tc_fix_data != 0)
21118 {
21119 if (((unsigned long) value) > 0xff)
21120 as_bad_where (fixP->fx_file, fixP->fx_line,
21121 _("invalid swi expression"));
21122 newval = md_chars_to_number (buf, THUMB_SIZE);
21123 newval |= value;
21124 md_number_to_chars (buf, newval, THUMB_SIZE);
21125 }
21126 else
21127 {
21128 if (((unsigned long) value) > 0x00ffffff)
21129 as_bad_where (fixP->fx_file, fixP->fx_line,
21130 _("invalid swi expression"));
21131 newval = md_chars_to_number (buf, INSN_SIZE);
21132 newval |= value;
21133 md_number_to_chars (buf, newval, INSN_SIZE);
21134 }
21135 break;
21136
21137 case BFD_RELOC_ARM_MULTI:
21138 if (((unsigned long) value) > 0xffff)
21139 as_bad_where (fixP->fx_file, fixP->fx_line,
21140 _("invalid expression in load/store multiple"));
21141 newval = value | md_chars_to_number (buf, INSN_SIZE);
21142 md_number_to_chars (buf, newval, INSN_SIZE);
21143 break;
21144
21145 #ifdef OBJ_ELF
21146 case BFD_RELOC_ARM_PCREL_CALL:
21147
21148 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21149 && fixP->fx_addsy
21150 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21151 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21152 && THUMB_IS_FUNC (fixP->fx_addsy))
21153 /* Flip the bl to blx. This is a simple flip
21154 bit here because we generate PCREL_CALL for
21155 unconditional bls. */
21156 {
21157 newval = md_chars_to_number (buf, INSN_SIZE);
21158 newval = newval | 0x10000000;
21159 md_number_to_chars (buf, newval, INSN_SIZE);
21160 temp = 1;
21161 fixP->fx_done = 1;
21162 }
21163 else
21164 temp = 3;
21165 goto arm_branch_common;
21166
21167 case BFD_RELOC_ARM_PCREL_JUMP:
21168 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21169 && fixP->fx_addsy
21170 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21171 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21172 && THUMB_IS_FUNC (fixP->fx_addsy))
21173 {
21174 /* This would map to a bl<cond>, b<cond>,
21175 b<always> to a Thumb function. We
21176 need to force a relocation for this particular
21177 case. */
21178 newval = md_chars_to_number (buf, INSN_SIZE);
21179 fixP->fx_done = 0;
21180 }
21181
21182 case BFD_RELOC_ARM_PLT32:
21183 #endif
21184 case BFD_RELOC_ARM_PCREL_BRANCH:
21185 temp = 3;
21186 goto arm_branch_common;
21187
21188 case BFD_RELOC_ARM_PCREL_BLX:
21189
21190 temp = 1;
21191 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21192 && fixP->fx_addsy
21193 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21194 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21195 && ARM_IS_FUNC (fixP->fx_addsy))
21196 {
21197 /* Flip the blx to a bl and warn. */
21198 const char *name = S_GET_NAME (fixP->fx_addsy);
21199 newval = 0xeb000000;
21200 as_warn_where (fixP->fx_file, fixP->fx_line,
21201 _("blx to '%s' an ARM ISA state function changed to bl"),
21202 name);
21203 md_number_to_chars (buf, newval, INSN_SIZE);
21204 temp = 3;
21205 fixP->fx_done = 1;
21206 }
21207
21208 #ifdef OBJ_ELF
21209 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21210 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
21211 #endif
21212
21213 arm_branch_common:
21214 /* We are going to store value (shifted right by two) in the
21215 instruction, in a 24 bit, signed field. Bits 26 through 32 either
21216 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
21217 also be be clear. */
21218 if (value & temp)
21219 as_bad_where (fixP->fx_file, fixP->fx_line,
21220 _("misaligned branch destination"));
21221 if ((value & (offsetT)0xfe000000) != (offsetT)0
21222 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
21223 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21224
21225 if (fixP->fx_done || !seg->use_rela_p)
21226 {
21227 newval = md_chars_to_number (buf, INSN_SIZE);
21228 newval |= (value >> 2) & 0x00ffffff;
21229 /* Set the H bit on BLX instructions. */
21230 if (temp == 1)
21231 {
21232 if (value & 2)
21233 newval |= 0x01000000;
21234 else
21235 newval &= ~0x01000000;
21236 }
21237 md_number_to_chars (buf, newval, INSN_SIZE);
21238 }
21239 break;
21240
21241 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
21242 /* CBZ can only branch forward. */
21243
21244 /* Attempts to use CBZ to branch to the next instruction
21245 (which, strictly speaking, are prohibited) will be turned into
21246 no-ops.
21247
21248 FIXME: It may be better to remove the instruction completely and
21249 perform relaxation. */
21250 if (value == -2)
21251 {
21252 newval = md_chars_to_number (buf, THUMB_SIZE);
21253 newval = 0xbf00; /* NOP encoding T1 */
21254 md_number_to_chars (buf, newval, THUMB_SIZE);
21255 }
21256 else
21257 {
21258 if (value & ~0x7e)
21259 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21260
21261 if (fixP->fx_done || !seg->use_rela_p)
21262 {
21263 newval = md_chars_to_number (buf, THUMB_SIZE);
21264 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
21265 md_number_to_chars (buf, newval, THUMB_SIZE);
21266 }
21267 }
21268 break;
21269
21270 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
21271 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
21272 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21273
21274 if (fixP->fx_done || !seg->use_rela_p)
21275 {
21276 newval = md_chars_to_number (buf, THUMB_SIZE);
21277 newval |= (value & 0x1ff) >> 1;
21278 md_number_to_chars (buf, newval, THUMB_SIZE);
21279 }
21280 break;
21281
21282 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
21283 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
21284 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21285
21286 if (fixP->fx_done || !seg->use_rela_p)
21287 {
21288 newval = md_chars_to_number (buf, THUMB_SIZE);
21289 newval |= (value & 0xfff) >> 1;
21290 md_number_to_chars (buf, newval, THUMB_SIZE);
21291 }
21292 break;
21293
21294 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21295 if (fixP->fx_addsy
21296 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21297 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21298 && ARM_IS_FUNC (fixP->fx_addsy)
21299 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21300 {
21301 /* Force a relocation for a branch 20 bits wide. */
21302 fixP->fx_done = 0;
21303 }
21304 if ((value & ~0x1fffff) && ((value & ~0x0fffff) != ~0x0fffff))
21305 as_bad_where (fixP->fx_file, fixP->fx_line,
21306 _("conditional branch out of range"));
21307
21308 if (fixP->fx_done || !seg->use_rela_p)
21309 {
21310 offsetT newval2;
21311 addressT S, J1, J2, lo, hi;
21312
21313 S = (value & 0x00100000) >> 20;
21314 J2 = (value & 0x00080000) >> 19;
21315 J1 = (value & 0x00040000) >> 18;
21316 hi = (value & 0x0003f000) >> 12;
21317 lo = (value & 0x00000ffe) >> 1;
21318
21319 newval = md_chars_to_number (buf, THUMB_SIZE);
21320 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21321 newval |= (S << 10) | hi;
21322 newval2 |= (J1 << 13) | (J2 << 11) | lo;
21323 md_number_to_chars (buf, newval, THUMB_SIZE);
21324 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
21325 }
21326 break;
21327
21328 case BFD_RELOC_THUMB_PCREL_BLX:
21329 /* If there is a blx from a thumb state function to
21330 another thumb function flip this to a bl and warn
21331 about it. */
21332
21333 if (fixP->fx_addsy
21334 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21335 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21336 && THUMB_IS_FUNC (fixP->fx_addsy))
21337 {
21338 const char *name = S_GET_NAME (fixP->fx_addsy);
21339 as_warn_where (fixP->fx_file, fixP->fx_line,
21340 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
21341 name);
21342 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21343 newval = newval | 0x1000;
21344 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21345 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21346 fixP->fx_done = 1;
21347 }
21348
21349
21350 goto thumb_bl_common;
21351
21352 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21353 /* A bl from Thumb state ISA to an internal ARM state function
21354 is converted to a blx. */
21355 if (fixP->fx_addsy
21356 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
21357 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE)
21358 && ARM_IS_FUNC (fixP->fx_addsy)
21359 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
21360 {
21361 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
21362 newval = newval & ~0x1000;
21363 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
21364 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
21365 fixP->fx_done = 1;
21366 }
21367
21368 thumb_bl_common:
21369
21370 #ifdef OBJ_ELF
21371 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4
21372 && fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21373 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
21374 #endif
21375
21376 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
21377 /* For a BLX instruction, make sure that the relocation is rounded up
21378 to a word boundary. This follows the semantics of the instruction
21379 which specifies that bit 1 of the target address will come from bit
21380 1 of the base address. */
21381 value = (value + 1) & ~ 1;
21382
21383 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
21384 {
21385 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
21386 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21387 else if ((value & ~0x1ffffff)
21388 && ((value & ~0x1ffffff) != ~0x1ffffff))
21389 as_bad_where (fixP->fx_file, fixP->fx_line,
21390 _("Thumb2 branch out of range"));
21391 }
21392
21393 if (fixP->fx_done || !seg->use_rela_p)
21394 encode_thumb2_b_bl_offset (buf, value);
21395
21396 break;
21397
21398 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21399 if ((value & ~0x0ffffff) && ((value & ~0x0ffffff) != ~0x0ffffff))
21400 as_bad_where (fixP->fx_file, fixP->fx_line, BAD_RANGE);
21401
21402 if (fixP->fx_done || !seg->use_rela_p)
21403 encode_thumb2_b_bl_offset (buf, value);
21404
21405 break;
21406
21407 case BFD_RELOC_8:
21408 if (fixP->fx_done || !seg->use_rela_p)
21409 md_number_to_chars (buf, value, 1);
21410 break;
21411
21412 case BFD_RELOC_16:
21413 if (fixP->fx_done || !seg->use_rela_p)
21414 md_number_to_chars (buf, value, 2);
21415 break;
21416
21417 #ifdef OBJ_ELF
21418 case BFD_RELOC_ARM_TLS_CALL:
21419 case BFD_RELOC_ARM_THM_TLS_CALL:
21420 case BFD_RELOC_ARM_TLS_DESCSEQ:
21421 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
21422 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21423 break;
21424
21425 case BFD_RELOC_ARM_TLS_GOTDESC:
21426 case BFD_RELOC_ARM_TLS_GD32:
21427 case BFD_RELOC_ARM_TLS_LE32:
21428 case BFD_RELOC_ARM_TLS_IE32:
21429 case BFD_RELOC_ARM_TLS_LDM32:
21430 case BFD_RELOC_ARM_TLS_LDO32:
21431 S_SET_THREAD_LOCAL (fixP->fx_addsy);
21432 /* fall through */
21433
21434 case BFD_RELOC_ARM_GOT32:
21435 case BFD_RELOC_ARM_GOTOFF:
21436 if (fixP->fx_done || !seg->use_rela_p)
21437 md_number_to_chars (buf, 0, 4);
21438 break;
21439
21440 case BFD_RELOC_ARM_GOT_PREL:
21441 if (fixP->fx_done || !seg->use_rela_p)
21442 md_number_to_chars (buf, value, 4);
21443 break;
21444
21445 case BFD_RELOC_ARM_TARGET2:
21446 /* TARGET2 is not partial-inplace, so we need to write the
21447 addend here for REL targets, because it won't be written out
21448 during reloc processing later. */
21449 if (fixP->fx_done || !seg->use_rela_p)
21450 md_number_to_chars (buf, fixP->fx_offset, 4);
21451 break;
21452 #endif
21453
21454 case BFD_RELOC_RVA:
21455 case BFD_RELOC_32:
21456 case BFD_RELOC_ARM_TARGET1:
21457 case BFD_RELOC_ARM_ROSEGREL32:
21458 case BFD_RELOC_ARM_SBREL32:
21459 case BFD_RELOC_32_PCREL:
21460 #ifdef TE_PE
21461 case BFD_RELOC_32_SECREL:
21462 #endif
21463 if (fixP->fx_done || !seg->use_rela_p)
21464 #ifdef TE_WINCE
21465 /* For WinCE we only do this for pcrel fixups. */
21466 if (fixP->fx_done || fixP->fx_pcrel)
21467 #endif
21468 md_number_to_chars (buf, value, 4);
21469 break;
21470
21471 #ifdef OBJ_ELF
21472 case BFD_RELOC_ARM_PREL31:
21473 if (fixP->fx_done || !seg->use_rela_p)
21474 {
21475 newval = md_chars_to_number (buf, 4) & 0x80000000;
21476 if ((value ^ (value >> 1)) & 0x40000000)
21477 {
21478 as_bad_where (fixP->fx_file, fixP->fx_line,
21479 _("rel31 relocation overflow"));
21480 }
21481 newval |= value & 0x7fffffff;
21482 md_number_to_chars (buf, newval, 4);
21483 }
21484 break;
21485 #endif
21486
21487 case BFD_RELOC_ARM_CP_OFF_IMM:
21488 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
21489 if (value < -1023 || value > 1023 || (value & 3))
21490 as_bad_where (fixP->fx_file, fixP->fx_line,
21491 _("co-processor offset out of range"));
21492 cp_off_common:
21493 sign = value > 0;
21494 if (value < 0)
21495 value = -value;
21496 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21497 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21498 newval = md_chars_to_number (buf, INSN_SIZE);
21499 else
21500 newval = get_thumb32_insn (buf);
21501 if (value == 0)
21502 newval &= 0xffffff00;
21503 else
21504 {
21505 newval &= 0xff7fff00;
21506 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
21507 }
21508 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
21509 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
21510 md_number_to_chars (buf, newval, INSN_SIZE);
21511 else
21512 put_thumb32_insn (buf, newval);
21513 break;
21514
21515 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
21516 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
21517 if (value < -255 || value > 255)
21518 as_bad_where (fixP->fx_file, fixP->fx_line,
21519 _("co-processor offset out of range"));
21520 value *= 4;
21521 goto cp_off_common;
21522
21523 case BFD_RELOC_ARM_THUMB_OFFSET:
21524 newval = md_chars_to_number (buf, THUMB_SIZE);
21525 /* Exactly what ranges, and where the offset is inserted depends
21526 on the type of instruction, we can establish this from the
21527 top 4 bits. */
21528 switch (newval >> 12)
21529 {
21530 case 4: /* PC load. */
21531 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
21532 forced to zero for these loads; md_pcrel_from has already
21533 compensated for this. */
21534 if (value & 3)
21535 as_bad_where (fixP->fx_file, fixP->fx_line,
21536 _("invalid offset, target not word aligned (0x%08lX)"),
21537 (((unsigned long) fixP->fx_frag->fr_address
21538 + (unsigned long) fixP->fx_where) & ~3)
21539 + (unsigned long) value);
21540
21541 if (value & ~0x3fc)
21542 as_bad_where (fixP->fx_file, fixP->fx_line,
21543 _("invalid offset, value too big (0x%08lX)"),
21544 (long) value);
21545
21546 newval |= value >> 2;
21547 break;
21548
21549 case 9: /* SP load/store. */
21550 if (value & ~0x3fc)
21551 as_bad_where (fixP->fx_file, fixP->fx_line,
21552 _("invalid offset, value too big (0x%08lX)"),
21553 (long) value);
21554 newval |= value >> 2;
21555 break;
21556
21557 case 6: /* Word load/store. */
21558 if (value & ~0x7c)
21559 as_bad_where (fixP->fx_file, fixP->fx_line,
21560 _("invalid offset, value too big (0x%08lX)"),
21561 (long) value);
21562 newval |= value << 4; /* 6 - 2. */
21563 break;
21564
21565 case 7: /* Byte load/store. */
21566 if (value & ~0x1f)
21567 as_bad_where (fixP->fx_file, fixP->fx_line,
21568 _("invalid offset, value too big (0x%08lX)"),
21569 (long) value);
21570 newval |= value << 6;
21571 break;
21572
21573 case 8: /* Halfword load/store. */
21574 if (value & ~0x3e)
21575 as_bad_where (fixP->fx_file, fixP->fx_line,
21576 _("invalid offset, value too big (0x%08lX)"),
21577 (long) value);
21578 newval |= value << 5; /* 6 - 1. */
21579 break;
21580
21581 default:
21582 as_bad_where (fixP->fx_file, fixP->fx_line,
21583 "Unable to process relocation for thumb opcode: %lx",
21584 (unsigned long) newval);
21585 break;
21586 }
21587 md_number_to_chars (buf, newval, THUMB_SIZE);
21588 break;
21589
21590 case BFD_RELOC_ARM_THUMB_ADD:
21591 /* This is a complicated relocation, since we use it for all of
21592 the following immediate relocations:
21593
21594 3bit ADD/SUB
21595 8bit ADD/SUB
21596 9bit ADD/SUB SP word-aligned
21597 10bit ADD PC/SP word-aligned
21598
21599 The type of instruction being processed is encoded in the
21600 instruction field:
21601
21602 0x8000 SUB
21603 0x00F0 Rd
21604 0x000F Rs
21605 */
21606 newval = md_chars_to_number (buf, THUMB_SIZE);
21607 {
21608 int rd = (newval >> 4) & 0xf;
21609 int rs = newval & 0xf;
21610 int subtract = !!(newval & 0x8000);
21611
21612 /* Check for HI regs, only very restricted cases allowed:
21613 Adjusting SP, and using PC or SP to get an address. */
21614 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
21615 || (rs > 7 && rs != REG_SP && rs != REG_PC))
21616 as_bad_where (fixP->fx_file, fixP->fx_line,
21617 _("invalid Hi register with immediate"));
21618
21619 /* If value is negative, choose the opposite instruction. */
21620 if (value < 0)
21621 {
21622 value = -value;
21623 subtract = !subtract;
21624 if (value < 0)
21625 as_bad_where (fixP->fx_file, fixP->fx_line,
21626 _("immediate value out of range"));
21627 }
21628
21629 if (rd == REG_SP)
21630 {
21631 if (value & ~0x1fc)
21632 as_bad_where (fixP->fx_file, fixP->fx_line,
21633 _("invalid immediate for stack address calculation"));
21634 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
21635 newval |= value >> 2;
21636 }
21637 else if (rs == REG_PC || rs == REG_SP)
21638 {
21639 if (subtract || value & ~0x3fc)
21640 as_bad_where (fixP->fx_file, fixP->fx_line,
21641 _("invalid immediate for address calculation (value = 0x%08lX)"),
21642 (unsigned long) value);
21643 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
21644 newval |= rd << 8;
21645 newval |= value >> 2;
21646 }
21647 else if (rs == rd)
21648 {
21649 if (value & ~0xff)
21650 as_bad_where (fixP->fx_file, fixP->fx_line,
21651 _("immediate value out of range"));
21652 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
21653 newval |= (rd << 8) | value;
21654 }
21655 else
21656 {
21657 if (value & ~0x7)
21658 as_bad_where (fixP->fx_file, fixP->fx_line,
21659 _("immediate value out of range"));
21660 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
21661 newval |= rd | (rs << 3) | (value << 6);
21662 }
21663 }
21664 md_number_to_chars (buf, newval, THUMB_SIZE);
21665 break;
21666
21667 case BFD_RELOC_ARM_THUMB_IMM:
21668 newval = md_chars_to_number (buf, THUMB_SIZE);
21669 if (value < 0 || value > 255)
21670 as_bad_where (fixP->fx_file, fixP->fx_line,
21671 _("invalid immediate: %ld is out of range"),
21672 (long) value);
21673 newval |= value;
21674 md_number_to_chars (buf, newval, THUMB_SIZE);
21675 break;
21676
21677 case BFD_RELOC_ARM_THUMB_SHIFT:
21678 /* 5bit shift value (0..32). LSL cannot take 32. */
21679 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
21680 temp = newval & 0xf800;
21681 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
21682 as_bad_where (fixP->fx_file, fixP->fx_line,
21683 _("invalid shift value: %ld"), (long) value);
21684 /* Shifts of zero must be encoded as LSL. */
21685 if (value == 0)
21686 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
21687 /* Shifts of 32 are encoded as zero. */
21688 else if (value == 32)
21689 value = 0;
21690 newval |= value << 6;
21691 md_number_to_chars (buf, newval, THUMB_SIZE);
21692 break;
21693
21694 case BFD_RELOC_VTABLE_INHERIT:
21695 case BFD_RELOC_VTABLE_ENTRY:
21696 fixP->fx_done = 0;
21697 return;
21698
21699 case BFD_RELOC_ARM_MOVW:
21700 case BFD_RELOC_ARM_MOVT:
21701 case BFD_RELOC_ARM_THUMB_MOVW:
21702 case BFD_RELOC_ARM_THUMB_MOVT:
21703 if (fixP->fx_done || !seg->use_rela_p)
21704 {
21705 /* REL format relocations are limited to a 16-bit addend. */
21706 if (!fixP->fx_done)
21707 {
21708 if (value < -0x8000 || value > 0x7fff)
21709 as_bad_where (fixP->fx_file, fixP->fx_line,
21710 _("offset out of range"));
21711 }
21712 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21713 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21714 {
21715 value >>= 16;
21716 }
21717
21718 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21719 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
21720 {
21721 newval = get_thumb32_insn (buf);
21722 newval &= 0xfbf08f00;
21723 newval |= (value & 0xf000) << 4;
21724 newval |= (value & 0x0800) << 15;
21725 newval |= (value & 0x0700) << 4;
21726 newval |= (value & 0x00ff);
21727 put_thumb32_insn (buf, newval);
21728 }
21729 else
21730 {
21731 newval = md_chars_to_number (buf, 4);
21732 newval &= 0xfff0f000;
21733 newval |= value & 0x0fff;
21734 newval |= (value & 0xf000) << 4;
21735 md_number_to_chars (buf, newval, 4);
21736 }
21737 }
21738 return;
21739
21740 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21741 case BFD_RELOC_ARM_ALU_PC_G0:
21742 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21743 case BFD_RELOC_ARM_ALU_PC_G1:
21744 case BFD_RELOC_ARM_ALU_PC_G2:
21745 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21746 case BFD_RELOC_ARM_ALU_SB_G0:
21747 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21748 case BFD_RELOC_ARM_ALU_SB_G1:
21749 case BFD_RELOC_ARM_ALU_SB_G2:
21750 gas_assert (!fixP->fx_done);
21751 if (!seg->use_rela_p)
21752 {
21753 bfd_vma insn;
21754 bfd_vma encoded_addend;
21755 bfd_vma addend_abs = abs (value);
21756
21757 /* Check that the absolute value of the addend can be
21758 expressed as an 8-bit constant plus a rotation. */
21759 encoded_addend = encode_arm_immediate (addend_abs);
21760 if (encoded_addend == (unsigned int) FAIL)
21761 as_bad_where (fixP->fx_file, fixP->fx_line,
21762 _("the offset 0x%08lX is not representable"),
21763 (unsigned long) addend_abs);
21764
21765 /* Extract the instruction. */
21766 insn = md_chars_to_number (buf, INSN_SIZE);
21767
21768 /* If the addend is positive, use an ADD instruction.
21769 Otherwise use a SUB. Take care not to destroy the S bit. */
21770 insn &= 0xff1fffff;
21771 if (value < 0)
21772 insn |= 1 << 22;
21773 else
21774 insn |= 1 << 23;
21775
21776 /* Place the encoded addend into the first 12 bits of the
21777 instruction. */
21778 insn &= 0xfffff000;
21779 insn |= encoded_addend;
21780
21781 /* Update the instruction. */
21782 md_number_to_chars (buf, insn, INSN_SIZE);
21783 }
21784 break;
21785
21786 case BFD_RELOC_ARM_LDR_PC_G0:
21787 case BFD_RELOC_ARM_LDR_PC_G1:
21788 case BFD_RELOC_ARM_LDR_PC_G2:
21789 case BFD_RELOC_ARM_LDR_SB_G0:
21790 case BFD_RELOC_ARM_LDR_SB_G1:
21791 case BFD_RELOC_ARM_LDR_SB_G2:
21792 gas_assert (!fixP->fx_done);
21793 if (!seg->use_rela_p)
21794 {
21795 bfd_vma insn;
21796 bfd_vma addend_abs = abs (value);
21797
21798 /* Check that the absolute value of the addend can be
21799 encoded in 12 bits. */
21800 if (addend_abs >= 0x1000)
21801 as_bad_where (fixP->fx_file, fixP->fx_line,
21802 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
21803 (unsigned long) addend_abs);
21804
21805 /* Extract the instruction. */
21806 insn = md_chars_to_number (buf, INSN_SIZE);
21807
21808 /* If the addend is negative, clear bit 23 of the instruction.
21809 Otherwise set it. */
21810 if (value < 0)
21811 insn &= ~(1 << 23);
21812 else
21813 insn |= 1 << 23;
21814
21815 /* Place the absolute value of the addend into the first 12 bits
21816 of the instruction. */
21817 insn &= 0xfffff000;
21818 insn |= addend_abs;
21819
21820 /* Update the instruction. */
21821 md_number_to_chars (buf, insn, INSN_SIZE);
21822 }
21823 break;
21824
21825 case BFD_RELOC_ARM_LDRS_PC_G0:
21826 case BFD_RELOC_ARM_LDRS_PC_G1:
21827 case BFD_RELOC_ARM_LDRS_PC_G2:
21828 case BFD_RELOC_ARM_LDRS_SB_G0:
21829 case BFD_RELOC_ARM_LDRS_SB_G1:
21830 case BFD_RELOC_ARM_LDRS_SB_G2:
21831 gas_assert (!fixP->fx_done);
21832 if (!seg->use_rela_p)
21833 {
21834 bfd_vma insn;
21835 bfd_vma addend_abs = abs (value);
21836
21837 /* Check that the absolute value of the addend can be
21838 encoded in 8 bits. */
21839 if (addend_abs >= 0x100)
21840 as_bad_where (fixP->fx_file, fixP->fx_line,
21841 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
21842 (unsigned long) addend_abs);
21843
21844 /* Extract the instruction. */
21845 insn = md_chars_to_number (buf, INSN_SIZE);
21846
21847 /* If the addend is negative, clear bit 23 of the instruction.
21848 Otherwise set it. */
21849 if (value < 0)
21850 insn &= ~(1 << 23);
21851 else
21852 insn |= 1 << 23;
21853
21854 /* Place the first four bits of the absolute value of the addend
21855 into the first 4 bits of the instruction, and the remaining
21856 four into bits 8 .. 11. */
21857 insn &= 0xfffff0f0;
21858 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
21859
21860 /* Update the instruction. */
21861 md_number_to_chars (buf, insn, INSN_SIZE);
21862 }
21863 break;
21864
21865 case BFD_RELOC_ARM_LDC_PC_G0:
21866 case BFD_RELOC_ARM_LDC_PC_G1:
21867 case BFD_RELOC_ARM_LDC_PC_G2:
21868 case BFD_RELOC_ARM_LDC_SB_G0:
21869 case BFD_RELOC_ARM_LDC_SB_G1:
21870 case BFD_RELOC_ARM_LDC_SB_G2:
21871 gas_assert (!fixP->fx_done);
21872 if (!seg->use_rela_p)
21873 {
21874 bfd_vma insn;
21875 bfd_vma addend_abs = abs (value);
21876
21877 /* Check that the absolute value of the addend is a multiple of
21878 four and, when divided by four, fits in 8 bits. */
21879 if (addend_abs & 0x3)
21880 as_bad_where (fixP->fx_file, fixP->fx_line,
21881 _("bad offset 0x%08lX (must be word-aligned)"),
21882 (unsigned long) addend_abs);
21883
21884 if ((addend_abs >> 2) > 0xff)
21885 as_bad_where (fixP->fx_file, fixP->fx_line,
21886 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
21887 (unsigned long) addend_abs);
21888
21889 /* Extract the instruction. */
21890 insn = md_chars_to_number (buf, INSN_SIZE);
21891
21892 /* If the addend is negative, clear bit 23 of the instruction.
21893 Otherwise set it. */
21894 if (value < 0)
21895 insn &= ~(1 << 23);
21896 else
21897 insn |= 1 << 23;
21898
21899 /* Place the addend (divided by four) into the first eight
21900 bits of the instruction. */
21901 insn &= 0xfffffff0;
21902 insn |= addend_abs >> 2;
21903
21904 /* Update the instruction. */
21905 md_number_to_chars (buf, insn, INSN_SIZE);
21906 }
21907 break;
21908
21909 case BFD_RELOC_ARM_V4BX:
21910 /* This will need to go in the object file. */
21911 fixP->fx_done = 0;
21912 break;
21913
21914 case BFD_RELOC_UNUSED:
21915 default:
21916 as_bad_where (fixP->fx_file, fixP->fx_line,
21917 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21918 }
21919 }
21920
21921 /* Translate internal representation of relocation info to BFD target
21922 format. */
21923
21924 arelent *
21925 tc_gen_reloc (asection *section, fixS *fixp)
21926 {
21927 arelent * reloc;
21928 bfd_reloc_code_real_type code;
21929
21930 reloc = (arelent *) xmalloc (sizeof (arelent));
21931
21932 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
21933 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21934 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
21935
21936 if (fixp->fx_pcrel)
21937 {
21938 if (section->use_rela_p)
21939 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21940 else
21941 fixp->fx_offset = reloc->address;
21942 }
21943 reloc->addend = fixp->fx_offset;
21944
21945 switch (fixp->fx_r_type)
21946 {
21947 case BFD_RELOC_8:
21948 if (fixp->fx_pcrel)
21949 {
21950 code = BFD_RELOC_8_PCREL;
21951 break;
21952 }
21953
21954 case BFD_RELOC_16:
21955 if (fixp->fx_pcrel)
21956 {
21957 code = BFD_RELOC_16_PCREL;
21958 break;
21959 }
21960
21961 case BFD_RELOC_32:
21962 if (fixp->fx_pcrel)
21963 {
21964 code = BFD_RELOC_32_PCREL;
21965 break;
21966 }
21967
21968 case BFD_RELOC_ARM_MOVW:
21969 if (fixp->fx_pcrel)
21970 {
21971 code = BFD_RELOC_ARM_MOVW_PCREL;
21972 break;
21973 }
21974
21975 case BFD_RELOC_ARM_MOVT:
21976 if (fixp->fx_pcrel)
21977 {
21978 code = BFD_RELOC_ARM_MOVT_PCREL;
21979 break;
21980 }
21981
21982 case BFD_RELOC_ARM_THUMB_MOVW:
21983 if (fixp->fx_pcrel)
21984 {
21985 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21986 break;
21987 }
21988
21989 case BFD_RELOC_ARM_THUMB_MOVT:
21990 if (fixp->fx_pcrel)
21991 {
21992 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21993 break;
21994 }
21995
21996 case BFD_RELOC_NONE:
21997 case BFD_RELOC_ARM_PCREL_BRANCH:
21998 case BFD_RELOC_ARM_PCREL_BLX:
21999 case BFD_RELOC_RVA:
22000 case BFD_RELOC_THUMB_PCREL_BRANCH7:
22001 case BFD_RELOC_THUMB_PCREL_BRANCH9:
22002 case BFD_RELOC_THUMB_PCREL_BRANCH12:
22003 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22004 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22005 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22006 case BFD_RELOC_VTABLE_ENTRY:
22007 case BFD_RELOC_VTABLE_INHERIT:
22008 #ifdef TE_PE
22009 case BFD_RELOC_32_SECREL:
22010 #endif
22011 code = fixp->fx_r_type;
22012 break;
22013
22014 case BFD_RELOC_THUMB_PCREL_BLX:
22015 #ifdef OBJ_ELF
22016 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
22017 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
22018 else
22019 #endif
22020 code = BFD_RELOC_THUMB_PCREL_BLX;
22021 break;
22022
22023 case BFD_RELOC_ARM_LITERAL:
22024 case BFD_RELOC_ARM_HWLITERAL:
22025 /* If this is called then the a literal has
22026 been referenced across a section boundary. */
22027 as_bad_where (fixp->fx_file, fixp->fx_line,
22028 _("literal referenced across section boundary"));
22029 return NULL;
22030
22031 #ifdef OBJ_ELF
22032 case BFD_RELOC_ARM_TLS_CALL:
22033 case BFD_RELOC_ARM_THM_TLS_CALL:
22034 case BFD_RELOC_ARM_TLS_DESCSEQ:
22035 case BFD_RELOC_ARM_THM_TLS_DESCSEQ:
22036 case BFD_RELOC_ARM_GOT32:
22037 case BFD_RELOC_ARM_GOTOFF:
22038 case BFD_RELOC_ARM_GOT_PREL:
22039 case BFD_RELOC_ARM_PLT32:
22040 case BFD_RELOC_ARM_TARGET1:
22041 case BFD_RELOC_ARM_ROSEGREL32:
22042 case BFD_RELOC_ARM_SBREL32:
22043 case BFD_RELOC_ARM_PREL31:
22044 case BFD_RELOC_ARM_TARGET2:
22045 case BFD_RELOC_ARM_TLS_LE32:
22046 case BFD_RELOC_ARM_TLS_LDO32:
22047 case BFD_RELOC_ARM_PCREL_CALL:
22048 case BFD_RELOC_ARM_PCREL_JUMP:
22049 case BFD_RELOC_ARM_ALU_PC_G0_NC:
22050 case BFD_RELOC_ARM_ALU_PC_G0:
22051 case BFD_RELOC_ARM_ALU_PC_G1_NC:
22052 case BFD_RELOC_ARM_ALU_PC_G1:
22053 case BFD_RELOC_ARM_ALU_PC_G2:
22054 case BFD_RELOC_ARM_LDR_PC_G0:
22055 case BFD_RELOC_ARM_LDR_PC_G1:
22056 case BFD_RELOC_ARM_LDR_PC_G2:
22057 case BFD_RELOC_ARM_LDRS_PC_G0:
22058 case BFD_RELOC_ARM_LDRS_PC_G1:
22059 case BFD_RELOC_ARM_LDRS_PC_G2:
22060 case BFD_RELOC_ARM_LDC_PC_G0:
22061 case BFD_RELOC_ARM_LDC_PC_G1:
22062 case BFD_RELOC_ARM_LDC_PC_G2:
22063 case BFD_RELOC_ARM_ALU_SB_G0_NC:
22064 case BFD_RELOC_ARM_ALU_SB_G0:
22065 case BFD_RELOC_ARM_ALU_SB_G1_NC:
22066 case BFD_RELOC_ARM_ALU_SB_G1:
22067 case BFD_RELOC_ARM_ALU_SB_G2:
22068 case BFD_RELOC_ARM_LDR_SB_G0:
22069 case BFD_RELOC_ARM_LDR_SB_G1:
22070 case BFD_RELOC_ARM_LDR_SB_G2:
22071 case BFD_RELOC_ARM_LDRS_SB_G0:
22072 case BFD_RELOC_ARM_LDRS_SB_G1:
22073 case BFD_RELOC_ARM_LDRS_SB_G2:
22074 case BFD_RELOC_ARM_LDC_SB_G0:
22075 case BFD_RELOC_ARM_LDC_SB_G1:
22076 case BFD_RELOC_ARM_LDC_SB_G2:
22077 case BFD_RELOC_ARM_V4BX:
22078 code = fixp->fx_r_type;
22079 break;
22080
22081 case BFD_RELOC_ARM_TLS_GOTDESC:
22082 case BFD_RELOC_ARM_TLS_GD32:
22083 case BFD_RELOC_ARM_TLS_IE32:
22084 case BFD_RELOC_ARM_TLS_LDM32:
22085 /* BFD will include the symbol's address in the addend.
22086 But we don't want that, so subtract it out again here. */
22087 if (!S_IS_COMMON (fixp->fx_addsy))
22088 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
22089 code = fixp->fx_r_type;
22090 break;
22091 #endif
22092
22093 case BFD_RELOC_ARM_IMMEDIATE:
22094 as_bad_where (fixp->fx_file, fixp->fx_line,
22095 _("internal relocation (type: IMMEDIATE) not fixed up"));
22096 return NULL;
22097
22098 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
22099 as_bad_where (fixp->fx_file, fixp->fx_line,
22100 _("ADRL used for a symbol not defined in the same file"));
22101 return NULL;
22102
22103 case BFD_RELOC_ARM_OFFSET_IMM:
22104 if (section->use_rela_p)
22105 {
22106 code = fixp->fx_r_type;
22107 break;
22108 }
22109
22110 if (fixp->fx_addsy != NULL
22111 && !S_IS_DEFINED (fixp->fx_addsy)
22112 && S_IS_LOCAL (fixp->fx_addsy))
22113 {
22114 as_bad_where (fixp->fx_file, fixp->fx_line,
22115 _("undefined local label `%s'"),
22116 S_GET_NAME (fixp->fx_addsy));
22117 return NULL;
22118 }
22119
22120 as_bad_where (fixp->fx_file, fixp->fx_line,
22121 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
22122 return NULL;
22123
22124 default:
22125 {
22126 char * type;
22127
22128 switch (fixp->fx_r_type)
22129 {
22130 case BFD_RELOC_NONE: type = "NONE"; break;
22131 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
22132 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
22133 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
22134 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
22135 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
22136 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
22137 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
22138 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
22139 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
22140 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
22141 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
22142 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
22143 default: type = _("<unknown>"); break;
22144 }
22145 as_bad_where (fixp->fx_file, fixp->fx_line,
22146 _("cannot represent %s relocation in this object file format"),
22147 type);
22148 return NULL;
22149 }
22150 }
22151
22152 #ifdef OBJ_ELF
22153 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
22154 && GOT_symbol
22155 && fixp->fx_addsy == GOT_symbol)
22156 {
22157 code = BFD_RELOC_ARM_GOTPC;
22158 reloc->addend = fixp->fx_offset = reloc->address;
22159 }
22160 #endif
22161
22162 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
22163
22164 if (reloc->howto == NULL)
22165 {
22166 as_bad_where (fixp->fx_file, fixp->fx_line,
22167 _("cannot represent %s relocation in this object file format"),
22168 bfd_get_reloc_code_name (code));
22169 return NULL;
22170 }
22171
22172 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
22173 vtable entry to be used in the relocation's section offset. */
22174 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22175 reloc->address = fixp->fx_offset;
22176
22177 return reloc;
22178 }
22179
22180 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
22181
22182 void
22183 cons_fix_new_arm (fragS * frag,
22184 int where,
22185 int size,
22186 expressionS * exp)
22187 {
22188 bfd_reloc_code_real_type type;
22189 int pcrel = 0;
22190
22191 /* Pick a reloc.
22192 FIXME: @@ Should look at CPU word size. */
22193 switch (size)
22194 {
22195 case 1:
22196 type = BFD_RELOC_8;
22197 break;
22198 case 2:
22199 type = BFD_RELOC_16;
22200 break;
22201 case 4:
22202 default:
22203 type = BFD_RELOC_32;
22204 break;
22205 case 8:
22206 type = BFD_RELOC_64;
22207 break;
22208 }
22209
22210 #ifdef TE_PE
22211 if (exp->X_op == O_secrel)
22212 {
22213 exp->X_op = O_symbol;
22214 type = BFD_RELOC_32_SECREL;
22215 }
22216 #endif
22217
22218 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
22219 }
22220
22221 #if defined (OBJ_COFF)
22222 void
22223 arm_validate_fix (fixS * fixP)
22224 {
22225 /* If the destination of the branch is a defined symbol which does not have
22226 the THUMB_FUNC attribute, then we must be calling a function which has
22227 the (interfacearm) attribute. We look for the Thumb entry point to that
22228 function and change the branch to refer to that function instead. */
22229 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
22230 && fixP->fx_addsy != NULL
22231 && S_IS_DEFINED (fixP->fx_addsy)
22232 && ! THUMB_IS_FUNC (fixP->fx_addsy))
22233 {
22234 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
22235 }
22236 }
22237 #endif
22238
22239
22240 int
22241 arm_force_relocation (struct fix * fixp)
22242 {
22243 #if defined (OBJ_COFF) && defined (TE_PE)
22244 if (fixp->fx_r_type == BFD_RELOC_RVA)
22245 return 1;
22246 #endif
22247
22248 /* In case we have a call or a branch to a function in ARM ISA mode from
22249 a thumb function or vice-versa force the relocation. These relocations
22250 are cleared off for some cores that might have blx and simple transformations
22251 are possible. */
22252
22253 #ifdef OBJ_ELF
22254 switch (fixp->fx_r_type)
22255 {
22256 case BFD_RELOC_ARM_PCREL_JUMP:
22257 case BFD_RELOC_ARM_PCREL_CALL:
22258 case BFD_RELOC_THUMB_PCREL_BLX:
22259 if (THUMB_IS_FUNC (fixp->fx_addsy))
22260 return 1;
22261 break;
22262
22263 case BFD_RELOC_ARM_PCREL_BLX:
22264 case BFD_RELOC_THUMB_PCREL_BRANCH25:
22265 case BFD_RELOC_THUMB_PCREL_BRANCH20:
22266 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22267 if (ARM_IS_FUNC (fixp->fx_addsy))
22268 return 1;
22269 break;
22270
22271 default:
22272 break;
22273 }
22274 #endif
22275
22276 /* Resolve these relocations even if the symbol is extern or weak.
22277 Technically this is probably wrong due to symbol preemption.
22278 In practice these relocations do not have enough range to be useful
22279 at dynamic link time, and some code (e.g. in the Linux kernel)
22280 expects these references to be resolved. */
22281 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
22282 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
22283 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM8
22284 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
22285 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
22286 || fixp->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2
22287 || fixp->fx_r_type == BFD_RELOC_ARM_THUMB_OFFSET
22288 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
22289 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
22290 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
22291 || fixp->fx_r_type == BFD_RELOC_ARM_T32_OFFSET_IMM
22292 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12
22293 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM
22294 || fixp->fx_r_type == BFD_RELOC_ARM_T32_CP_OFF_IMM_S2)
22295 return 0;
22296
22297 /* Always leave these relocations for the linker. */
22298 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22299 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22300 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22301 return 1;
22302
22303 /* Always generate relocations against function symbols. */
22304 if (fixp->fx_r_type == BFD_RELOC_32
22305 && fixp->fx_addsy
22306 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
22307 return 1;
22308
22309 return generic_force_reloc (fixp);
22310 }
22311
22312 #if defined (OBJ_ELF) || defined (OBJ_COFF)
22313 /* Relocations against function names must be left unadjusted,
22314 so that the linker can use this information to generate interworking
22315 stubs. The MIPS version of this function
22316 also prevents relocations that are mips-16 specific, but I do not
22317 know why it does this.
22318
22319 FIXME:
22320 There is one other problem that ought to be addressed here, but
22321 which currently is not: Taking the address of a label (rather
22322 than a function) and then later jumping to that address. Such
22323 addresses also ought to have their bottom bit set (assuming that
22324 they reside in Thumb code), but at the moment they will not. */
22325
22326 bfd_boolean
22327 arm_fix_adjustable (fixS * fixP)
22328 {
22329 if (fixP->fx_addsy == NULL)
22330 return 1;
22331
22332 /* Preserve relocations against symbols with function type. */
22333 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
22334 return FALSE;
22335
22336 if (THUMB_IS_FUNC (fixP->fx_addsy)
22337 && fixP->fx_subsy == NULL)
22338 return FALSE;
22339
22340 /* We need the symbol name for the VTABLE entries. */
22341 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
22342 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
22343 return FALSE;
22344
22345 /* Don't allow symbols to be discarded on GOT related relocs. */
22346 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
22347 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
22348 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
22349 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
22350 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
22351 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
22352 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
22353 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
22354 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GOTDESC
22355 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_CALL
22356 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_CALL
22357 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_DESCSEQ
22358 || fixP->fx_r_type == BFD_RELOC_ARM_THM_TLS_DESCSEQ
22359 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
22360 return FALSE;
22361
22362 /* Similarly for group relocations. */
22363 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
22364 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
22365 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
22366 return FALSE;
22367
22368 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
22369 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
22370 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
22371 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
22372 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
22373 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
22374 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
22375 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
22376 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
22377 return FALSE;
22378
22379 return TRUE;
22380 }
22381 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
22382
22383 #ifdef OBJ_ELF
22384
22385 const char *
22386 elf32_arm_target_format (void)
22387 {
22388 #ifdef TE_SYMBIAN
22389 return (target_big_endian
22390 ? "elf32-bigarm-symbian"
22391 : "elf32-littlearm-symbian");
22392 #elif defined (TE_VXWORKS)
22393 return (target_big_endian
22394 ? "elf32-bigarm-vxworks"
22395 : "elf32-littlearm-vxworks");
22396 #elif defined (TE_NACL)
22397 return (target_big_endian
22398 ? "elf32-bigarm-nacl"
22399 : "elf32-littlearm-nacl");
22400 #else
22401 if (target_big_endian)
22402 return "elf32-bigarm";
22403 else
22404 return "elf32-littlearm";
22405 #endif
22406 }
22407
22408 void
22409 armelf_frob_symbol (symbolS * symp,
22410 int * puntp)
22411 {
22412 elf_frob_symbol (symp, puntp);
22413 }
22414 #endif
22415
22416 /* MD interface: Finalization. */
22417
22418 void
22419 arm_cleanup (void)
22420 {
22421 literal_pool * pool;
22422
22423 /* Ensure that all the IT blocks are properly closed. */
22424 check_it_blocks_finished ();
22425
22426 for (pool = list_of_pools; pool; pool = pool->next)
22427 {
22428 /* Put it at the end of the relevant section. */
22429 subseg_set (pool->section, pool->sub_section);
22430 #ifdef OBJ_ELF
22431 arm_elf_change_section ();
22432 #endif
22433 s_ltorg (0);
22434 }
22435 }
22436
22437 #ifdef OBJ_ELF
22438 /* Remove any excess mapping symbols generated for alignment frags in
22439 SEC. We may have created a mapping symbol before a zero byte
22440 alignment; remove it if there's a mapping symbol after the
22441 alignment. */
22442 static void
22443 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
22444 void *dummy ATTRIBUTE_UNUSED)
22445 {
22446 segment_info_type *seginfo = seg_info (sec);
22447 fragS *fragp;
22448
22449 if (seginfo == NULL || seginfo->frchainP == NULL)
22450 return;
22451
22452 for (fragp = seginfo->frchainP->frch_root;
22453 fragp != NULL;
22454 fragp = fragp->fr_next)
22455 {
22456 symbolS *sym = fragp->tc_frag_data.last_map;
22457 fragS *next = fragp->fr_next;
22458
22459 /* Variable-sized frags have been converted to fixed size by
22460 this point. But if this was variable-sized to start with,
22461 there will be a fixed-size frag after it. So don't handle
22462 next == NULL. */
22463 if (sym == NULL || next == NULL)
22464 continue;
22465
22466 if (S_GET_VALUE (sym) < next->fr_address)
22467 /* Not at the end of this frag. */
22468 continue;
22469 know (S_GET_VALUE (sym) == next->fr_address);
22470
22471 do
22472 {
22473 if (next->tc_frag_data.first_map != NULL)
22474 {
22475 /* Next frag starts with a mapping symbol. Discard this
22476 one. */
22477 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22478 break;
22479 }
22480
22481 if (next->fr_next == NULL)
22482 {
22483 /* This mapping symbol is at the end of the section. Discard
22484 it. */
22485 know (next->fr_fix == 0 && next->fr_var == 0);
22486 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
22487 break;
22488 }
22489
22490 /* As long as we have empty frags without any mapping symbols,
22491 keep looking. */
22492 /* If the next frag is non-empty and does not start with a
22493 mapping symbol, then this mapping symbol is required. */
22494 if (next->fr_address != next->fr_next->fr_address)
22495 break;
22496
22497 next = next->fr_next;
22498 }
22499 while (next != NULL);
22500 }
22501 }
22502 #endif
22503
22504 /* Adjust the symbol table. This marks Thumb symbols as distinct from
22505 ARM ones. */
22506
22507 void
22508 arm_adjust_symtab (void)
22509 {
22510 #ifdef OBJ_COFF
22511 symbolS * sym;
22512
22513 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22514 {
22515 if (ARM_IS_THUMB (sym))
22516 {
22517 if (THUMB_IS_FUNC (sym))
22518 {
22519 /* Mark the symbol as a Thumb function. */
22520 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
22521 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
22522 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
22523
22524 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
22525 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
22526 else
22527 as_bad (_("%s: unexpected function type: %d"),
22528 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
22529 }
22530 else switch (S_GET_STORAGE_CLASS (sym))
22531 {
22532 case C_EXT:
22533 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
22534 break;
22535 case C_STAT:
22536 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
22537 break;
22538 case C_LABEL:
22539 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
22540 break;
22541 default:
22542 /* Do nothing. */
22543 break;
22544 }
22545 }
22546
22547 if (ARM_IS_INTERWORK (sym))
22548 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
22549 }
22550 #endif
22551 #ifdef OBJ_ELF
22552 symbolS * sym;
22553 char bind;
22554
22555 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
22556 {
22557 if (ARM_IS_THUMB (sym))
22558 {
22559 elf_symbol_type * elf_sym;
22560
22561 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
22562 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
22563
22564 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
22565 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
22566 {
22567 /* If it's a .thumb_func, declare it as so,
22568 otherwise tag label as .code 16. */
22569 if (THUMB_IS_FUNC (sym))
22570 elf_sym->internal_elf_sym.st_target_internal
22571 = ST_BRANCH_TO_THUMB;
22572 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22573 elf_sym->internal_elf_sym.st_info =
22574 ELF_ST_INFO (bind, STT_ARM_16BIT);
22575 }
22576 }
22577 }
22578
22579 /* Remove any overlapping mapping symbols generated by alignment frags. */
22580 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
22581 /* Now do generic ELF adjustments. */
22582 elf_adjust_symtab ();
22583 #endif
22584 }
22585
22586 /* MD interface: Initialization. */
22587
22588 static void
22589 set_constant_flonums (void)
22590 {
22591 int i;
22592
22593 for (i = 0; i < NUM_FLOAT_VALS; i++)
22594 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
22595 abort ();
22596 }
22597
22598 /* Auto-select Thumb mode if it's the only available instruction set for the
22599 given architecture. */
22600
22601 static void
22602 autoselect_thumb_from_cpu_variant (void)
22603 {
22604 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
22605 opcode_select (16);
22606 }
22607
22608 void
22609 md_begin (void)
22610 {
22611 unsigned mach;
22612 unsigned int i;
22613
22614 if ( (arm_ops_hsh = hash_new ()) == NULL
22615 || (arm_cond_hsh = hash_new ()) == NULL
22616 || (arm_shift_hsh = hash_new ()) == NULL
22617 || (arm_psr_hsh = hash_new ()) == NULL
22618 || (arm_v7m_psr_hsh = hash_new ()) == NULL
22619 || (arm_reg_hsh = hash_new ()) == NULL
22620 || (arm_reloc_hsh = hash_new ()) == NULL
22621 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
22622 as_fatal (_("virtual memory exhausted"));
22623
22624 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
22625 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
22626 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
22627 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
22628 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
22629 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
22630 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
22631 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
22632 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
22633 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
22634 (void *) (v7m_psrs + i));
22635 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
22636 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
22637 for (i = 0;
22638 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
22639 i++)
22640 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
22641 (void *) (barrier_opt_names + i));
22642 #ifdef OBJ_ELF
22643 for (i = 0; i < ARRAY_SIZE (reloc_names); i++)
22644 {
22645 struct reloc_entry * entry = reloc_names + i;
22646
22647 if (arm_is_eabi() && entry->reloc == BFD_RELOC_ARM_PLT32)
22648 /* This makes encode_branch() use the EABI versions of this relocation. */
22649 entry->reloc = BFD_RELOC_UNUSED;
22650
22651 hash_insert (arm_reloc_hsh, entry->name, (void *) entry);
22652 }
22653 #endif
22654
22655 set_constant_flonums ();
22656
22657 /* Set the cpu variant based on the command-line options. We prefer
22658 -mcpu= over -march= if both are set (as for GCC); and we prefer
22659 -mfpu= over any other way of setting the floating point unit.
22660 Use of legacy options with new options are faulted. */
22661 if (legacy_cpu)
22662 {
22663 if (mcpu_cpu_opt || march_cpu_opt)
22664 as_bad (_("use of old and new-style options to set CPU type"));
22665
22666 mcpu_cpu_opt = legacy_cpu;
22667 }
22668 else if (!mcpu_cpu_opt)
22669 mcpu_cpu_opt = march_cpu_opt;
22670
22671 if (legacy_fpu)
22672 {
22673 if (mfpu_opt)
22674 as_bad (_("use of old and new-style options to set FPU type"));
22675
22676 mfpu_opt = legacy_fpu;
22677 }
22678 else if (!mfpu_opt)
22679 {
22680 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
22681 || defined (TE_NetBSD) || defined (TE_VXWORKS))
22682 /* Some environments specify a default FPU. If they don't, infer it
22683 from the processor. */
22684 if (mcpu_fpu_opt)
22685 mfpu_opt = mcpu_fpu_opt;
22686 else
22687 mfpu_opt = march_fpu_opt;
22688 #else
22689 mfpu_opt = &fpu_default;
22690 #endif
22691 }
22692
22693 if (!mfpu_opt)
22694 {
22695 if (mcpu_cpu_opt != NULL)
22696 mfpu_opt = &fpu_default;
22697 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
22698 mfpu_opt = &fpu_arch_vfp_v2;
22699 else
22700 mfpu_opt = &fpu_arch_fpa;
22701 }
22702
22703 #ifdef CPU_DEFAULT
22704 if (!mcpu_cpu_opt)
22705 {
22706 mcpu_cpu_opt = &cpu_default;
22707 selected_cpu = cpu_default;
22708 }
22709 #else
22710 if (mcpu_cpu_opt)
22711 selected_cpu = *mcpu_cpu_opt;
22712 else
22713 mcpu_cpu_opt = &arm_arch_any;
22714 #endif
22715
22716 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22717
22718 autoselect_thumb_from_cpu_variant ();
22719
22720 arm_arch_used = thumb_arch_used = arm_arch_none;
22721
22722 #if defined OBJ_COFF || defined OBJ_ELF
22723 {
22724 unsigned int flags = 0;
22725
22726 #if defined OBJ_ELF
22727 flags = meabi_flags;
22728
22729 switch (meabi_flags)
22730 {
22731 case EF_ARM_EABI_UNKNOWN:
22732 #endif
22733 /* Set the flags in the private structure. */
22734 if (uses_apcs_26) flags |= F_APCS26;
22735 if (support_interwork) flags |= F_INTERWORK;
22736 if (uses_apcs_float) flags |= F_APCS_FLOAT;
22737 if (pic_code) flags |= F_PIC;
22738 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
22739 flags |= F_SOFT_FLOAT;
22740
22741 switch (mfloat_abi_opt)
22742 {
22743 case ARM_FLOAT_ABI_SOFT:
22744 case ARM_FLOAT_ABI_SOFTFP:
22745 flags |= F_SOFT_FLOAT;
22746 break;
22747
22748 case ARM_FLOAT_ABI_HARD:
22749 if (flags & F_SOFT_FLOAT)
22750 as_bad (_("hard-float conflicts with specified fpu"));
22751 break;
22752 }
22753
22754 /* Using pure-endian doubles (even if soft-float). */
22755 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
22756 flags |= F_VFP_FLOAT;
22757
22758 #if defined OBJ_ELF
22759 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
22760 flags |= EF_ARM_MAVERICK_FLOAT;
22761 break;
22762
22763 case EF_ARM_EABI_VER4:
22764 case EF_ARM_EABI_VER5:
22765 /* No additional flags to set. */
22766 break;
22767
22768 default:
22769 abort ();
22770 }
22771 #endif
22772 bfd_set_private_flags (stdoutput, flags);
22773
22774 /* We have run out flags in the COFF header to encode the
22775 status of ATPCS support, so instead we create a dummy,
22776 empty, debug section called .arm.atpcs. */
22777 if (atpcs)
22778 {
22779 asection * sec;
22780
22781 sec = bfd_make_section (stdoutput, ".arm.atpcs");
22782
22783 if (sec != NULL)
22784 {
22785 bfd_set_section_flags
22786 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
22787 bfd_set_section_size (stdoutput, sec, 0);
22788 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
22789 }
22790 }
22791 }
22792 #endif
22793
22794 /* Record the CPU type as well. */
22795 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
22796 mach = bfd_mach_arm_iWMMXt2;
22797 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
22798 mach = bfd_mach_arm_iWMMXt;
22799 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
22800 mach = bfd_mach_arm_XScale;
22801 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
22802 mach = bfd_mach_arm_ep9312;
22803 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
22804 mach = bfd_mach_arm_5TE;
22805 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
22806 {
22807 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
22808 mach = bfd_mach_arm_5T;
22809 else
22810 mach = bfd_mach_arm_5;
22811 }
22812 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
22813 {
22814 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
22815 mach = bfd_mach_arm_4T;
22816 else
22817 mach = bfd_mach_arm_4;
22818 }
22819 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
22820 mach = bfd_mach_arm_3M;
22821 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
22822 mach = bfd_mach_arm_3;
22823 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
22824 mach = bfd_mach_arm_2a;
22825 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
22826 mach = bfd_mach_arm_2;
22827 else
22828 mach = bfd_mach_arm_unknown;
22829
22830 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
22831 }
22832
22833 /* Command line processing. */
22834
22835 /* md_parse_option
22836 Invocation line includes a switch not recognized by the base assembler.
22837 See if it's a processor-specific option.
22838
22839 This routine is somewhat complicated by the need for backwards
22840 compatibility (since older releases of gcc can't be changed).
22841 The new options try to make the interface as compatible as
22842 possible with GCC.
22843
22844 New options (supported) are:
22845
22846 -mcpu=<cpu name> Assemble for selected processor
22847 -march=<architecture name> Assemble for selected architecture
22848 -mfpu=<fpu architecture> Assemble for selected FPU.
22849 -EB/-mbig-endian Big-endian
22850 -EL/-mlittle-endian Little-endian
22851 -k Generate PIC code
22852 -mthumb Start in Thumb mode
22853 -mthumb-interwork Code supports ARM/Thumb interworking
22854
22855 -m[no-]warn-deprecated Warn about deprecated features
22856
22857 For now we will also provide support for:
22858
22859 -mapcs-32 32-bit Program counter
22860 -mapcs-26 26-bit Program counter
22861 -macps-float Floats passed in FP registers
22862 -mapcs-reentrant Reentrant code
22863 -matpcs
22864 (sometime these will probably be replaced with -mapcs=<list of options>
22865 and -matpcs=<list of options>)
22866
22867 The remaining options are only supported for back-wards compatibility.
22868 Cpu variants, the arm part is optional:
22869 -m[arm]1 Currently not supported.
22870 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
22871 -m[arm]3 Arm 3 processor
22872 -m[arm]6[xx], Arm 6 processors
22873 -m[arm]7[xx][t][[d]m] Arm 7 processors
22874 -m[arm]8[10] Arm 8 processors
22875 -m[arm]9[20][tdmi] Arm 9 processors
22876 -mstrongarm[110[0]] StrongARM processors
22877 -mxscale XScale processors
22878 -m[arm]v[2345[t[e]]] Arm architectures
22879 -mall All (except the ARM1)
22880 FP variants:
22881 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
22882 -mfpe-old (No float load/store multiples)
22883 -mvfpxd VFP Single precision
22884 -mvfp All VFP
22885 -mno-fpu Disable all floating point instructions
22886
22887 The following CPU names are recognized:
22888 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22889 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22890 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22891 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22892 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22893 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22894 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
22895
22896 */
22897
22898 const char * md_shortopts = "m:k";
22899
22900 #ifdef ARM_BI_ENDIAN
22901 #define OPTION_EB (OPTION_MD_BASE + 0)
22902 #define OPTION_EL (OPTION_MD_BASE + 1)
22903 #else
22904 #if TARGET_BYTES_BIG_ENDIAN
22905 #define OPTION_EB (OPTION_MD_BASE + 0)
22906 #else
22907 #define OPTION_EL (OPTION_MD_BASE + 1)
22908 #endif
22909 #endif
22910 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
22911
22912 struct option md_longopts[] =
22913 {
22914 #ifdef OPTION_EB
22915 {"EB", no_argument, NULL, OPTION_EB},
22916 #endif
22917 #ifdef OPTION_EL
22918 {"EL", no_argument, NULL, OPTION_EL},
22919 #endif
22920 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
22921 {NULL, no_argument, NULL, 0}
22922 };
22923
22924 size_t md_longopts_size = sizeof (md_longopts);
22925
22926 struct arm_option_table
22927 {
22928 char *option; /* Option name to match. */
22929 char *help; /* Help information. */
22930 int *var; /* Variable to change. */
22931 int value; /* What to change it to. */
22932 char *deprecated; /* If non-null, print this message. */
22933 };
22934
22935 struct arm_option_table arm_opts[] =
22936 {
22937 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22938 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22939 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22940 &support_interwork, 1, NULL},
22941 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22942 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22943 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22944 1, NULL},
22945 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22946 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22947 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22948 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22949 NULL},
22950
22951 /* These are recognized by the assembler, but have no affect on code. */
22952 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22953 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
22954
22955 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22956 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22957 &warn_on_deprecated, 0, NULL},
22958 {NULL, NULL, NULL, 0, NULL}
22959 };
22960
22961 struct arm_legacy_option_table
22962 {
22963 char *option; /* Option name to match. */
22964 const arm_feature_set **var; /* Variable to change. */
22965 const arm_feature_set value; /* What to change it to. */
22966 char *deprecated; /* If non-null, print this message. */
22967 };
22968
22969 const struct arm_legacy_option_table arm_legacy_opts[] =
22970 {
22971 /* DON'T add any new processors to this list -- we want the whole list
22972 to go away... Add them to the processors table instead. */
22973 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22974 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22975 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22976 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22977 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22978 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22979 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22980 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22981 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22982 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22983 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22984 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22985 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22986 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22987 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22988 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22989 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22990 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22991 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22992 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22993 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22994 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22995 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22996 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22997 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22998 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22999 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23000 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
23001 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23002 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
23003 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23004 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
23005 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23006 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
23007 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23008 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
23009 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23010 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
23011 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23012 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
23013 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23014 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
23015 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23016 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
23017 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23018 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
23019 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23020 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23021 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23022 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
23023 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23024 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
23025 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23026 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
23027 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23028 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
23029 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
23030 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
23031 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
23032 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
23033 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
23034 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
23035 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
23036 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
23037 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
23038 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
23039 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
23040 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
23041 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
23042 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
23043 N_("use -mcpu=strongarm110")},
23044 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
23045 N_("use -mcpu=strongarm1100")},
23046 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
23047 N_("use -mcpu=strongarm1110")},
23048 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
23049 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
23050 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
23051
23052 /* Architecture variants -- don't add any more to this list either. */
23053 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
23054 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
23055 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
23056 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
23057 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23058 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
23059 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23060 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
23061 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23062 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
23063 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23064 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
23065 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23066 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
23067 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23068 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
23069 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
23070 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
23071
23072 /* Floating point variants -- don't add any more to this list either. */
23073 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
23074 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
23075 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
23076 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
23077 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
23078
23079 {NULL, NULL, ARM_ARCH_NONE, NULL}
23080 };
23081
23082 struct arm_cpu_option_table
23083 {
23084 char *name;
23085 size_t name_len;
23086 const arm_feature_set value;
23087 /* For some CPUs we assume an FPU unless the user explicitly sets
23088 -mfpu=... */
23089 const arm_feature_set default_fpu;
23090 /* The canonical name of the CPU, or NULL to use NAME converted to upper
23091 case. */
23092 const char *canonical_name;
23093 };
23094
23095 /* This list should, at a minimum, contain all the cpu names
23096 recognized by GCC. */
23097 #define ARM_CPU_OPT(N, V, DF, CN) { N, sizeof (N) - 1, V, DF, CN }
23098 static const struct arm_cpu_option_table arm_cpus[] =
23099 {
23100 ARM_CPU_OPT ("all", ARM_ANY, FPU_ARCH_FPA, NULL),
23101 ARM_CPU_OPT ("arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL),
23102 ARM_CPU_OPT ("arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL),
23103 ARM_CPU_OPT ("arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23104 ARM_CPU_OPT ("arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL),
23105 ARM_CPU_OPT ("arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23106 ARM_CPU_OPT ("arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23107 ARM_CPU_OPT ("arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23108 ARM_CPU_OPT ("arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23109 ARM_CPU_OPT ("arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23110 ARM_CPU_OPT ("arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23111 ARM_CPU_OPT ("arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23112 ARM_CPU_OPT ("arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23113 ARM_CPU_OPT ("arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23114 ARM_CPU_OPT ("arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23115 ARM_CPU_OPT ("arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL),
23116 ARM_CPU_OPT ("arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23117 ARM_CPU_OPT ("arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23118 ARM_CPU_OPT ("arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23119 ARM_CPU_OPT ("arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23120 ARM_CPU_OPT ("arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23121 ARM_CPU_OPT ("arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23122 ARM_CPU_OPT ("arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23123 ARM_CPU_OPT ("arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23124 ARM_CPU_OPT ("arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23125 ARM_CPU_OPT ("arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23126 ARM_CPU_OPT ("arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23127 ARM_CPU_OPT ("arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL),
23128 ARM_CPU_OPT ("arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23129 ARM_CPU_OPT ("arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23130 ARM_CPU_OPT ("arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23131 ARM_CPU_OPT ("arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23132 ARM_CPU_OPT ("arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23133 ARM_CPU_OPT ("strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23134 ARM_CPU_OPT ("strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23135 ARM_CPU_OPT ("strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23136 ARM_CPU_OPT ("strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23137 ARM_CPU_OPT ("strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23138 ARM_CPU_OPT ("arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23139 ARM_CPU_OPT ("arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"),
23140 ARM_CPU_OPT ("arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23141 ARM_CPU_OPT ("arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23142 ARM_CPU_OPT ("arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23143 ARM_CPU_OPT ("arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL),
23144 ARM_CPU_OPT ("fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23145 ARM_CPU_OPT ("fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL),
23146 /* For V5 or later processors we default to using VFP; but the user
23147 should really set the FPU type explicitly. */
23148 ARM_CPU_OPT ("arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23149 ARM_CPU_OPT ("arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23150 ARM_CPU_OPT ("arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23151 ARM_CPU_OPT ("arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"),
23152 ARM_CPU_OPT ("arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23153 ARM_CPU_OPT ("arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23154 ARM_CPU_OPT ("arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"),
23155 ARM_CPU_OPT ("arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23156 ARM_CPU_OPT ("arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL),
23157 ARM_CPU_OPT ("arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"),
23158 ARM_CPU_OPT ("arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23159 ARM_CPU_OPT ("arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23160 ARM_CPU_OPT ("arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23161 ARM_CPU_OPT ("arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23162 ARM_CPU_OPT ("arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23163 ARM_CPU_OPT ("arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"),
23164 ARM_CPU_OPT ("arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL),
23165 ARM_CPU_OPT ("arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23166 ARM_CPU_OPT ("arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23167 ARM_CPU_OPT ("arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2,
23168 "ARM1026EJ-S"),
23169 ARM_CPU_OPT ("arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL),
23170 ARM_CPU_OPT ("fa606te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23171 ARM_CPU_OPT ("fa616te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23172 ARM_CPU_OPT ("fa626te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23173 ARM_CPU_OPT ("fmp626", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23174 ARM_CPU_OPT ("fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL),
23175 ARM_CPU_OPT ("arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"),
23176 ARM_CPU_OPT ("arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL),
23177 ARM_CPU_OPT ("arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2,
23178 "ARM1136JF-S"),
23179 ARM_CPU_OPT ("arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL),
23180 ARM_CPU_OPT ("mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, "MPCore"),
23181 ARM_CPU_OPT ("mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, "MPCore"),
23182 ARM_CPU_OPT ("arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL),
23183 ARM_CPU_OPT ("arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL),
23184 ARM_CPU_OPT ("arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL),
23185 ARM_CPU_OPT ("arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL),
23186 ARM_CPU_OPT ("cortex-a5", ARM_ARCH_V7A_MP_SEC,
23187 FPU_NONE, "Cortex-A5"),
23188 ARM_CPU_OPT ("cortex-a7", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23189 FPU_ARCH_NEON_VFP_V4,
23190 "Cortex-A7"),
23191 ARM_CPU_OPT ("cortex-a8", ARM_ARCH_V7A_SEC,
23192 ARM_FEATURE (0, FPU_VFP_V3
23193 | FPU_NEON_EXT_V1),
23194 "Cortex-A8"),
23195 ARM_CPU_OPT ("cortex-a9", ARM_ARCH_V7A_MP_SEC,
23196 ARM_FEATURE (0, FPU_VFP_V3
23197 | FPU_NEON_EXT_V1),
23198 "Cortex-A9"),
23199 ARM_CPU_OPT ("cortex-a15", ARM_ARCH_V7A_IDIV_MP_SEC_VIRT,
23200 FPU_ARCH_NEON_VFP_V4,
23201 "Cortex-A15"),
23202 ARM_CPU_OPT ("cortex-r4", ARM_ARCH_V7R, FPU_NONE, "Cortex-R4"),
23203 ARM_CPU_OPT ("cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16,
23204 "Cortex-R4F"),
23205 ARM_CPU_OPT ("cortex-r5", ARM_ARCH_V7R_IDIV,
23206 FPU_NONE, "Cortex-R5"),
23207 ARM_CPU_OPT ("cortex-m4", ARM_ARCH_V7EM, FPU_NONE, "Cortex-M4"),
23208 ARM_CPU_OPT ("cortex-m3", ARM_ARCH_V7M, FPU_NONE, "Cortex-M3"),
23209 ARM_CPU_OPT ("cortex-m1", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M1"),
23210 ARM_CPU_OPT ("cortex-m0", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0"),
23211 ARM_CPU_OPT ("cortex-m0plus", ARM_ARCH_V6SM, FPU_NONE, "Cortex-M0+"),
23212 /* ??? XSCALE is really an architecture. */
23213 ARM_CPU_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
23214 /* ??? iwmmxt is not a processor. */
23215 ARM_CPU_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL),
23216 ARM_CPU_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL),
23217 ARM_CPU_OPT ("i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL),
23218 /* Maverick */
23219 ARM_CPU_OPT ("ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK),
23220 FPU_ARCH_MAVERICK,
23221 "ARM920T"),
23222 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL }
23223 };
23224 #undef ARM_CPU_OPT
23225
23226 struct arm_arch_option_table
23227 {
23228 char *name;
23229 size_t name_len;
23230 const arm_feature_set value;
23231 const arm_feature_set default_fpu;
23232 };
23233
23234 /* This list should, at a minimum, contain all the architecture names
23235 recognized by GCC. */
23236 #define ARM_ARCH_OPT(N, V, DF) { N, sizeof (N) - 1, V, DF }
23237 static const struct arm_arch_option_table arm_archs[] =
23238 {
23239 ARM_ARCH_OPT ("all", ARM_ANY, FPU_ARCH_FPA),
23240 ARM_ARCH_OPT ("armv1", ARM_ARCH_V1, FPU_ARCH_FPA),
23241 ARM_ARCH_OPT ("armv2", ARM_ARCH_V2, FPU_ARCH_FPA),
23242 ARM_ARCH_OPT ("armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA),
23243 ARM_ARCH_OPT ("armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA),
23244 ARM_ARCH_OPT ("armv3", ARM_ARCH_V3, FPU_ARCH_FPA),
23245 ARM_ARCH_OPT ("armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA),
23246 ARM_ARCH_OPT ("armv4", ARM_ARCH_V4, FPU_ARCH_FPA),
23247 ARM_ARCH_OPT ("armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA),
23248 ARM_ARCH_OPT ("armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA),
23249 ARM_ARCH_OPT ("armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA),
23250 ARM_ARCH_OPT ("armv5", ARM_ARCH_V5, FPU_ARCH_VFP),
23251 ARM_ARCH_OPT ("armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP),
23252 ARM_ARCH_OPT ("armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP),
23253 ARM_ARCH_OPT ("armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP),
23254 ARM_ARCH_OPT ("armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP),
23255 ARM_ARCH_OPT ("armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP),
23256 ARM_ARCH_OPT ("armv6", ARM_ARCH_V6, FPU_ARCH_VFP),
23257 ARM_ARCH_OPT ("armv6j", ARM_ARCH_V6, FPU_ARCH_VFP),
23258 ARM_ARCH_OPT ("armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP),
23259 ARM_ARCH_OPT ("armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP),
23260 ARM_ARCH_OPT ("armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP),
23261 ARM_ARCH_OPT ("armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP),
23262 ARM_ARCH_OPT ("armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP),
23263 ARM_ARCH_OPT ("armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP),
23264 ARM_ARCH_OPT ("armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP),
23265 ARM_ARCH_OPT ("armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP),
23266 ARM_ARCH_OPT ("armv6s-m", ARM_ARCH_V6SM, FPU_ARCH_VFP),
23267 ARM_ARCH_OPT ("armv7", ARM_ARCH_V7, FPU_ARCH_VFP),
23268 /* The official spelling of the ARMv7 profile variants is the dashed form.
23269 Accept the non-dashed form for compatibility with old toolchains. */
23270 ARM_ARCH_OPT ("armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23271 ARM_ARCH_OPT ("armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23272 ARM_ARCH_OPT ("armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23273 ARM_ARCH_OPT ("armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP),
23274 ARM_ARCH_OPT ("armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP),
23275 ARM_ARCH_OPT ("armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP),
23276 ARM_ARCH_OPT ("armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP),
23277 ARM_ARCH_OPT ("armv8-a", ARM_ARCH_V8A, FPU_ARCH_VFP),
23278 ARM_ARCH_OPT ("xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP),
23279 ARM_ARCH_OPT ("iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP),
23280 ARM_ARCH_OPT ("iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP),
23281 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
23282 };
23283 #undef ARM_ARCH_OPT
23284
23285 /* ISA extensions in the co-processor and main instruction set space. */
23286 struct arm_option_extension_value_table
23287 {
23288 char *name;
23289 size_t name_len;
23290 const arm_feature_set value;
23291 const arm_feature_set allowed_archs;
23292 };
23293
23294 /* The following table must be in alphabetical order with a NULL last entry.
23295 */
23296 #define ARM_EXT_OPT(N, V, AA) { N, sizeof (N) - 1, V, AA }
23297 static const struct arm_option_extension_value_table arm_extensions[] =
23298 {
23299 ARM_EXT_OPT ("crypto", FPU_ARCH_CRYPTO_NEON_VFP_ARMV8,
23300 ARM_FEATURE (ARM_EXT_V8, 0)),
23301 ARM_EXT_OPT ("fp", FPU_ARCH_VFP_ARMV8,
23302 ARM_FEATURE (ARM_EXT_V8, 0)),
23303 ARM_EXT_OPT ("idiv", ARM_FEATURE (ARM_EXT_ADIV | ARM_EXT_DIV, 0),
23304 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23305 ARM_EXT_OPT ("iwmmxt",ARM_FEATURE (0, ARM_CEXT_IWMMXT), ARM_ANY),
23306 ARM_EXT_OPT ("iwmmxt2",
23307 ARM_FEATURE (0, ARM_CEXT_IWMMXT2), ARM_ANY),
23308 ARM_EXT_OPT ("maverick",
23309 ARM_FEATURE (0, ARM_CEXT_MAVERICK), ARM_ANY),
23310 ARM_EXT_OPT ("mp", ARM_FEATURE (ARM_EXT_MP, 0),
23311 ARM_FEATURE (ARM_EXT_V7A | ARM_EXT_V7R, 0)),
23312 ARM_EXT_OPT ("simd", FPU_ARCH_NEON_VFP_ARMV8,
23313 ARM_FEATURE (ARM_EXT_V8, 0)),
23314 ARM_EXT_OPT ("os", ARM_FEATURE (ARM_EXT_OS, 0),
23315 ARM_FEATURE (ARM_EXT_V6M, 0)),
23316 ARM_EXT_OPT ("sec", ARM_FEATURE (ARM_EXT_SEC, 0),
23317 ARM_FEATURE (ARM_EXT_V6K | ARM_EXT_V7A, 0)),
23318 ARM_EXT_OPT ("virt", ARM_FEATURE (ARM_EXT_VIRT | ARM_EXT_ADIV
23319 | ARM_EXT_DIV, 0),
23320 ARM_FEATURE (ARM_EXT_V7A, 0)),
23321 ARM_EXT_OPT ("xscale",ARM_FEATURE (0, ARM_CEXT_XSCALE), ARM_ANY),
23322 { NULL, 0, ARM_ARCH_NONE, ARM_ARCH_NONE }
23323 };
23324 #undef ARM_EXT_OPT
23325
23326 /* ISA floating-point and Advanced SIMD extensions. */
23327 struct arm_option_fpu_value_table
23328 {
23329 char *name;
23330 const arm_feature_set value;
23331 };
23332
23333 /* This list should, at a minimum, contain all the fpu names
23334 recognized by GCC. */
23335 static const struct arm_option_fpu_value_table arm_fpus[] =
23336 {
23337 {"softfpa", FPU_NONE},
23338 {"fpe", FPU_ARCH_FPE},
23339 {"fpe2", FPU_ARCH_FPE},
23340 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
23341 {"fpa", FPU_ARCH_FPA},
23342 {"fpa10", FPU_ARCH_FPA},
23343 {"fpa11", FPU_ARCH_FPA},
23344 {"arm7500fe", FPU_ARCH_FPA},
23345 {"softvfp", FPU_ARCH_VFP},
23346 {"softvfp+vfp", FPU_ARCH_VFP_V2},
23347 {"vfp", FPU_ARCH_VFP_V2},
23348 {"vfp9", FPU_ARCH_VFP_V2},
23349 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
23350 {"vfp10", FPU_ARCH_VFP_V2},
23351 {"vfp10-r0", FPU_ARCH_VFP_V1},
23352 {"vfpxd", FPU_ARCH_VFP_V1xD},
23353 {"vfpv2", FPU_ARCH_VFP_V2},
23354 {"vfpv3", FPU_ARCH_VFP_V3},
23355 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
23356 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
23357 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
23358 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
23359 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
23360 {"arm1020t", FPU_ARCH_VFP_V1},
23361 {"arm1020e", FPU_ARCH_VFP_V2},
23362 {"arm1136jfs", FPU_ARCH_VFP_V2},
23363 {"arm1136jf-s", FPU_ARCH_VFP_V2},
23364 {"maverick", FPU_ARCH_MAVERICK},
23365 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
23366 {"neon-fp16", FPU_ARCH_NEON_FP16},
23367 {"vfpv4", FPU_ARCH_VFP_V4},
23368 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
23369 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
23370 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
23371 {"fp-armv8", FPU_ARCH_VFP_ARMV8},
23372 {"neon-fp-armv8", FPU_ARCH_NEON_VFP_ARMV8},
23373 {"crypto-neon-fp-armv8",
23374 FPU_ARCH_CRYPTO_NEON_VFP_ARMV8},
23375 {NULL, ARM_ARCH_NONE}
23376 };
23377
23378 struct arm_option_value_table
23379 {
23380 char *name;
23381 long value;
23382 };
23383
23384 static const struct arm_option_value_table arm_float_abis[] =
23385 {
23386 {"hard", ARM_FLOAT_ABI_HARD},
23387 {"softfp", ARM_FLOAT_ABI_SOFTFP},
23388 {"soft", ARM_FLOAT_ABI_SOFT},
23389 {NULL, 0}
23390 };
23391
23392 #ifdef OBJ_ELF
23393 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
23394 static const struct arm_option_value_table arm_eabis[] =
23395 {
23396 {"gnu", EF_ARM_EABI_UNKNOWN},
23397 {"4", EF_ARM_EABI_VER4},
23398 {"5", EF_ARM_EABI_VER5},
23399 {NULL, 0}
23400 };
23401 #endif
23402
23403 struct arm_long_option_table
23404 {
23405 char * option; /* Substring to match. */
23406 char * help; /* Help information. */
23407 int (* func) (char * subopt); /* Function to decode sub-option. */
23408 char * deprecated; /* If non-null, print this message. */
23409 };
23410
23411 static bfd_boolean
23412 arm_parse_extension (char *str, const arm_feature_set **opt_p)
23413 {
23414 arm_feature_set *ext_set = (arm_feature_set *)
23415 xmalloc (sizeof (arm_feature_set));
23416
23417 /* We insist on extensions being specified in alphabetical order, and with
23418 extensions being added before being removed. We achieve this by having
23419 the global ARM_EXTENSIONS table in alphabetical order, and using the
23420 ADDING_VALUE variable to indicate whether we are adding an extension (1)
23421 or removing it (0) and only allowing it to change in the order
23422 -1 -> 1 -> 0. */
23423 const struct arm_option_extension_value_table * opt = NULL;
23424 int adding_value = -1;
23425
23426 /* Copy the feature set, so that we can modify it. */
23427 *ext_set = **opt_p;
23428 *opt_p = ext_set;
23429
23430 while (str != NULL && *str != 0)
23431 {
23432 char *ext;
23433 size_t len;
23434
23435 if (*str != '+')
23436 {
23437 as_bad (_("invalid architectural extension"));
23438 return FALSE;
23439 }
23440
23441 str++;
23442 ext = strchr (str, '+');
23443
23444 if (ext != NULL)
23445 len = ext - str;
23446 else
23447 len = strlen (str);
23448
23449 if (len >= 2 && strncmp (str, "no", 2) == 0)
23450 {
23451 if (adding_value != 0)
23452 {
23453 adding_value = 0;
23454 opt = arm_extensions;
23455 }
23456
23457 len -= 2;
23458 str += 2;
23459 }
23460 else if (len > 0)
23461 {
23462 if (adding_value == -1)
23463 {
23464 adding_value = 1;
23465 opt = arm_extensions;
23466 }
23467 else if (adding_value != 1)
23468 {
23469 as_bad (_("must specify extensions to add before specifying "
23470 "those to remove"));
23471 return FALSE;
23472 }
23473 }
23474
23475 if (len == 0)
23476 {
23477 as_bad (_("missing architectural extension"));
23478 return FALSE;
23479 }
23480
23481 gas_assert (adding_value != -1);
23482 gas_assert (opt != NULL);
23483
23484 /* Scan over the options table trying to find an exact match. */
23485 for (; opt->name != NULL; opt++)
23486 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
23487 {
23488 /* Check we can apply the extension to this architecture. */
23489 if (!ARM_CPU_HAS_FEATURE (*ext_set, opt->allowed_archs))
23490 {
23491 as_bad (_("extension does not apply to the base architecture"));
23492 return FALSE;
23493 }
23494
23495 /* Add or remove the extension. */
23496 if (adding_value)
23497 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
23498 else
23499 ARM_CLEAR_FEATURE (*ext_set, *ext_set, opt->value);
23500
23501 break;
23502 }
23503
23504 if (opt->name == NULL)
23505 {
23506 /* Did we fail to find an extension because it wasn't specified in
23507 alphabetical order, or because it does not exist? */
23508
23509 for (opt = arm_extensions; opt->name != NULL; opt++)
23510 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
23511 break;
23512
23513 if (opt->name == NULL)
23514 as_bad (_("unknown architectural extension `%s'"), str);
23515 else
23516 as_bad (_("architectural extensions must be specified in "
23517 "alphabetical order"));
23518
23519 return FALSE;
23520 }
23521 else
23522 {
23523 /* We should skip the extension we've just matched the next time
23524 round. */
23525 opt++;
23526 }
23527
23528 str = ext;
23529 };
23530
23531 return TRUE;
23532 }
23533
23534 static bfd_boolean
23535 arm_parse_cpu (char *str)
23536 {
23537 const struct arm_cpu_option_table *opt;
23538 char *ext = strchr (str, '+');
23539 size_t len;
23540
23541 if (ext != NULL)
23542 len = ext - str;
23543 else
23544 len = strlen (str);
23545
23546 if (len == 0)
23547 {
23548 as_bad (_("missing cpu name `%s'"), str);
23549 return FALSE;
23550 }
23551
23552 for (opt = arm_cpus; opt->name != NULL; opt++)
23553 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
23554 {
23555 mcpu_cpu_opt = &opt->value;
23556 mcpu_fpu_opt = &opt->default_fpu;
23557 if (opt->canonical_name)
23558 strcpy (selected_cpu_name, opt->canonical_name);
23559 else
23560 {
23561 size_t i;
23562
23563 for (i = 0; i < len; i++)
23564 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23565 selected_cpu_name[i] = 0;
23566 }
23567
23568 if (ext != NULL)
23569 return arm_parse_extension (ext, &mcpu_cpu_opt);
23570
23571 return TRUE;
23572 }
23573
23574 as_bad (_("unknown cpu `%s'"), str);
23575 return FALSE;
23576 }
23577
23578 static bfd_boolean
23579 arm_parse_arch (char *str)
23580 {
23581 const struct arm_arch_option_table *opt;
23582 char *ext = strchr (str, '+');
23583 size_t len;
23584
23585 if (ext != NULL)
23586 len = ext - str;
23587 else
23588 len = strlen (str);
23589
23590 if (len == 0)
23591 {
23592 as_bad (_("missing architecture name `%s'"), str);
23593 return FALSE;
23594 }
23595
23596 for (opt = arm_archs; opt->name != NULL; opt++)
23597 if (opt->name_len == len && strncmp (opt->name, str, len) == 0)
23598 {
23599 march_cpu_opt = &opt->value;
23600 march_fpu_opt = &opt->default_fpu;
23601 strcpy (selected_cpu_name, opt->name);
23602
23603 if (ext != NULL)
23604 return arm_parse_extension (ext, &march_cpu_opt);
23605
23606 return TRUE;
23607 }
23608
23609 as_bad (_("unknown architecture `%s'\n"), str);
23610 return FALSE;
23611 }
23612
23613 static bfd_boolean
23614 arm_parse_fpu (char * str)
23615 {
23616 const struct arm_option_fpu_value_table * opt;
23617
23618 for (opt = arm_fpus; opt->name != NULL; opt++)
23619 if (streq (opt->name, str))
23620 {
23621 mfpu_opt = &opt->value;
23622 return TRUE;
23623 }
23624
23625 as_bad (_("unknown floating point format `%s'\n"), str);
23626 return FALSE;
23627 }
23628
23629 static bfd_boolean
23630 arm_parse_float_abi (char * str)
23631 {
23632 const struct arm_option_value_table * opt;
23633
23634 for (opt = arm_float_abis; opt->name != NULL; opt++)
23635 if (streq (opt->name, str))
23636 {
23637 mfloat_abi_opt = opt->value;
23638 return TRUE;
23639 }
23640
23641 as_bad (_("unknown floating point abi `%s'\n"), str);
23642 return FALSE;
23643 }
23644
23645 #ifdef OBJ_ELF
23646 static bfd_boolean
23647 arm_parse_eabi (char * str)
23648 {
23649 const struct arm_option_value_table *opt;
23650
23651 for (opt = arm_eabis; opt->name != NULL; opt++)
23652 if (streq (opt->name, str))
23653 {
23654 meabi_flags = opt->value;
23655 return TRUE;
23656 }
23657 as_bad (_("unknown EABI `%s'\n"), str);
23658 return FALSE;
23659 }
23660 #endif
23661
23662 static bfd_boolean
23663 arm_parse_it_mode (char * str)
23664 {
23665 bfd_boolean ret = TRUE;
23666
23667 if (streq ("arm", str))
23668 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
23669 else if (streq ("thumb", str))
23670 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
23671 else if (streq ("always", str))
23672 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
23673 else if (streq ("never", str))
23674 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
23675 else
23676 {
23677 as_bad (_("unknown implicit IT mode `%s', should be "\
23678 "arm, thumb, always, or never."), str);
23679 ret = FALSE;
23680 }
23681
23682 return ret;
23683 }
23684
23685 struct arm_long_option_table arm_long_opts[] =
23686 {
23687 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
23688 arm_parse_cpu, NULL},
23689 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
23690 arm_parse_arch, NULL},
23691 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
23692 arm_parse_fpu, NULL},
23693 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
23694 arm_parse_float_abi, NULL},
23695 #ifdef OBJ_ELF
23696 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
23697 arm_parse_eabi, NULL},
23698 #endif
23699 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
23700 arm_parse_it_mode, NULL},
23701 {NULL, NULL, 0, NULL}
23702 };
23703
23704 int
23705 md_parse_option (int c, char * arg)
23706 {
23707 struct arm_option_table *opt;
23708 const struct arm_legacy_option_table *fopt;
23709 struct arm_long_option_table *lopt;
23710
23711 switch (c)
23712 {
23713 #ifdef OPTION_EB
23714 case OPTION_EB:
23715 target_big_endian = 1;
23716 break;
23717 #endif
23718
23719 #ifdef OPTION_EL
23720 case OPTION_EL:
23721 target_big_endian = 0;
23722 break;
23723 #endif
23724
23725 case OPTION_FIX_V4BX:
23726 fix_v4bx = TRUE;
23727 break;
23728
23729 case 'a':
23730 /* Listing option. Just ignore these, we don't support additional
23731 ones. */
23732 return 0;
23733
23734 default:
23735 for (opt = arm_opts; opt->option != NULL; opt++)
23736 {
23737 if (c == opt->option[0]
23738 && ((arg == NULL && opt->option[1] == 0)
23739 || streq (arg, opt->option + 1)))
23740 {
23741 /* If the option is deprecated, tell the user. */
23742 if (warn_on_deprecated && opt->deprecated != NULL)
23743 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23744 arg ? arg : "", _(opt->deprecated));
23745
23746 if (opt->var != NULL)
23747 *opt->var = opt->value;
23748
23749 return 1;
23750 }
23751 }
23752
23753 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
23754 {
23755 if (c == fopt->option[0]
23756 && ((arg == NULL && fopt->option[1] == 0)
23757 || streq (arg, fopt->option + 1)))
23758 {
23759 /* If the option is deprecated, tell the user. */
23760 if (warn_on_deprecated && fopt->deprecated != NULL)
23761 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
23762 arg ? arg : "", _(fopt->deprecated));
23763
23764 if (fopt->var != NULL)
23765 *fopt->var = &fopt->value;
23766
23767 return 1;
23768 }
23769 }
23770
23771 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23772 {
23773 /* These options are expected to have an argument. */
23774 if (c == lopt->option[0]
23775 && arg != NULL
23776 && strncmp (arg, lopt->option + 1,
23777 strlen (lopt->option + 1)) == 0)
23778 {
23779 /* If the option is deprecated, tell the user. */
23780 if (warn_on_deprecated && lopt->deprecated != NULL)
23781 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
23782 _(lopt->deprecated));
23783
23784 /* Call the sup-option parser. */
23785 return lopt->func (arg + strlen (lopt->option) - 1);
23786 }
23787 }
23788
23789 return 0;
23790 }
23791
23792 return 1;
23793 }
23794
23795 void
23796 md_show_usage (FILE * fp)
23797 {
23798 struct arm_option_table *opt;
23799 struct arm_long_option_table *lopt;
23800
23801 fprintf (fp, _(" ARM-specific assembler options:\n"));
23802
23803 for (opt = arm_opts; opt->option != NULL; opt++)
23804 if (opt->help != NULL)
23805 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
23806
23807 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
23808 if (lopt->help != NULL)
23809 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
23810
23811 #ifdef OPTION_EB
23812 fprintf (fp, _("\
23813 -EB assemble code for a big-endian cpu\n"));
23814 #endif
23815
23816 #ifdef OPTION_EL
23817 fprintf (fp, _("\
23818 -EL assemble code for a little-endian cpu\n"));
23819 #endif
23820
23821 fprintf (fp, _("\
23822 --fix-v4bx Allow BX in ARMv4 code\n"));
23823 }
23824
23825
23826 #ifdef OBJ_ELF
23827 typedef struct
23828 {
23829 int val;
23830 arm_feature_set flags;
23831 } cpu_arch_ver_table;
23832
23833 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
23834 least features first. */
23835 static const cpu_arch_ver_table cpu_arch_ver[] =
23836 {
23837 {1, ARM_ARCH_V4},
23838 {2, ARM_ARCH_V4T},
23839 {3, ARM_ARCH_V5},
23840 {3, ARM_ARCH_V5T},
23841 {4, ARM_ARCH_V5TE},
23842 {5, ARM_ARCH_V5TEJ},
23843 {6, ARM_ARCH_V6},
23844 {9, ARM_ARCH_V6K},
23845 {7, ARM_ARCH_V6Z},
23846 {11, ARM_ARCH_V6M},
23847 {12, ARM_ARCH_V6SM},
23848 {8, ARM_ARCH_V6T2},
23849 {10, ARM_ARCH_V7A_IDIV_MP_SEC_VIRT},
23850 {10, ARM_ARCH_V7R},
23851 {10, ARM_ARCH_V7M},
23852 {14, ARM_ARCH_V8A},
23853 {0, ARM_ARCH_NONE}
23854 };
23855
23856 /* Set an attribute if it has not already been set by the user. */
23857 static void
23858 aeabi_set_attribute_int (int tag, int value)
23859 {
23860 if (tag < 1
23861 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23862 || !attributes_set_explicitly[tag])
23863 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
23864 }
23865
23866 static void
23867 aeabi_set_attribute_string (int tag, const char *value)
23868 {
23869 if (tag < 1
23870 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
23871 || !attributes_set_explicitly[tag])
23872 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
23873 }
23874
23875 /* Set the public EABI object attributes. */
23876 static void
23877 aeabi_set_public_attributes (void)
23878 {
23879 int arch;
23880 char profile;
23881 int virt_sec = 0;
23882 int fp16_optional = 0;
23883 arm_feature_set flags;
23884 arm_feature_set tmp;
23885 const cpu_arch_ver_table *p;
23886
23887 /* Choose the architecture based on the capabilities of the requested cpu
23888 (if any) and/or the instructions actually used. */
23889 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
23890 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
23891 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
23892
23893 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any))
23894 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v1);
23895
23896 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_any))
23897 ARM_MERGE_FEATURE_SETS (flags, flags, arm_ext_v4t);
23898
23899 /* Allow the user to override the reported architecture. */
23900 if (object_arch)
23901 {
23902 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
23903 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
23904 }
23905
23906 /* We need to make sure that the attributes do not identify us as v6S-M
23907 when the only v6S-M feature in use is the Operating System Extensions. */
23908 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_os))
23909 if (!ARM_CPU_HAS_FEATURE (flags, arm_arch_v6m_only))
23910 ARM_CLEAR_FEATURE (flags, flags, arm_ext_os);
23911
23912 tmp = flags;
23913 arch = 0;
23914 for (p = cpu_arch_ver; p->val; p++)
23915 {
23916 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
23917 {
23918 arch = p->val;
23919 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
23920 }
23921 }
23922
23923 /* The table lookup above finds the last architecture to contribute
23924 a new feature. Unfortunately, Tag13 is a subset of the union of
23925 v6T2 and v7-M, so it is never seen as contributing a new feature.
23926 We can not search for the last entry which is entirely used,
23927 because if no CPU is specified we build up only those flags
23928 actually used. Perhaps we should separate out the specified
23929 and implicit cases. Avoid taking this path for -march=all by
23930 checking for contradictory v7-A / v7-M features. */
23931 if (arch == 10
23932 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
23933 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
23934 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
23935 arch = 13;
23936
23937 /* Tag_CPU_name. */
23938 if (selected_cpu_name[0])
23939 {
23940 char *q;
23941
23942 q = selected_cpu_name;
23943 if (strncmp (q, "armv", 4) == 0)
23944 {
23945 int i;
23946
23947 q += 4;
23948 for (i = 0; q[i]; i++)
23949 q[i] = TOUPPER (q[i]);
23950 }
23951 aeabi_set_attribute_string (Tag_CPU_name, q);
23952 }
23953
23954 /* Tag_CPU_arch. */
23955 aeabi_set_attribute_int (Tag_CPU_arch, arch);
23956
23957 /* Tag_CPU_arch_profile. */
23958 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
23959 profile = 'A';
23960 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
23961 profile = 'R';
23962 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
23963 profile = 'M';
23964 else
23965 profile = '\0';
23966
23967 if (profile != '\0')
23968 aeabi_set_attribute_int (Tag_CPU_arch_profile, profile);
23969
23970 /* Tag_ARM_ISA_use. */
23971 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
23972 || arch == 0)
23973 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
23974
23975 /* Tag_THUMB_ISA_use. */
23976 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
23977 || arch == 0)
23978 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
23979 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
23980
23981 /* Tag_VFP_arch. */
23982 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_armv8))
23983 aeabi_set_attribute_int (Tag_VFP_arch, 7);
23984 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
23985 aeabi_set_attribute_int (Tag_VFP_arch,
23986 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
23987 ? 5 : 6);
23988 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
23989 {
23990 fp16_optional = 1;
23991 aeabi_set_attribute_int (Tag_VFP_arch, 3);
23992 }
23993 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
23994 {
23995 aeabi_set_attribute_int (Tag_VFP_arch, 4);
23996 fp16_optional = 1;
23997 }
23998 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
23999 aeabi_set_attribute_int (Tag_VFP_arch, 2);
24000 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
24001 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
24002 aeabi_set_attribute_int (Tag_VFP_arch, 1);
24003
24004 /* Tag_ABI_HardFP_use. */
24005 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
24006 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
24007 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
24008
24009 /* Tag_WMMX_arch. */
24010 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
24011 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
24012 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
24013 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
24014
24015 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
24016 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_armv8))
24017 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 3);
24018 else if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
24019 {
24020 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma))
24021 {
24022 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 2);
24023 }
24024 else
24025 {
24026 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
24027 fp16_optional = 1;
24028 }
24029 }
24030
24031 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
24032 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16) && fp16_optional)
24033 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
24034
24035 /* Tag_DIV_use.
24036
24037 We set Tag_DIV_use to two when integer divide instructions have been used
24038 in ARM state, or when Thumb integer divide instructions have been used,
24039 but we have no architecture profile set, nor have we any ARM instructions.
24040
24041 For ARMv8 we set the tag to 0 as integer divide is implied by the base
24042 architecture.
24043
24044 For new architectures we will have to check these tests. */
24045 gas_assert (arch <= TAG_CPU_ARCH_V8);
24046 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v8))
24047 aeabi_set_attribute_int (Tag_DIV_use, 0);
24048 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_adiv)
24049 || (profile == '\0'
24050 && ARM_CPU_HAS_FEATURE (flags, arm_ext_div)
24051 && !ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_any)))
24052 aeabi_set_attribute_int (Tag_DIV_use, 2);
24053
24054 /* Tag_MP_extension_use. */
24055 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_mp))
24056 aeabi_set_attribute_int (Tag_MPextension_use, 1);
24057
24058 /* Tag Virtualization_use. */
24059 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_sec))
24060 virt_sec |= 1;
24061 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_virt))
24062 virt_sec |= 2;
24063 if (virt_sec != 0)
24064 aeabi_set_attribute_int (Tag_Virtualization_use, virt_sec);
24065 }
24066
24067 /* Add the default contents for the .ARM.attributes section. */
24068 void
24069 arm_md_end (void)
24070 {
24071 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
24072 return;
24073
24074 aeabi_set_public_attributes ();
24075 }
24076 #endif /* OBJ_ELF */
24077
24078
24079 /* Parse a .cpu directive. */
24080
24081 static void
24082 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
24083 {
24084 const struct arm_cpu_option_table *opt;
24085 char *name;
24086 char saved_char;
24087
24088 name = input_line_pointer;
24089 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24090 input_line_pointer++;
24091 saved_char = *input_line_pointer;
24092 *input_line_pointer = 0;
24093
24094 /* Skip the first "all" entry. */
24095 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
24096 if (streq (opt->name, name))
24097 {
24098 mcpu_cpu_opt = &opt->value;
24099 selected_cpu = opt->value;
24100 if (opt->canonical_name)
24101 strcpy (selected_cpu_name, opt->canonical_name);
24102 else
24103 {
24104 int i;
24105 for (i = 0; opt->name[i]; i++)
24106 selected_cpu_name[i] = TOUPPER (opt->name[i]);
24107
24108 selected_cpu_name[i] = 0;
24109 }
24110 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24111 *input_line_pointer = saved_char;
24112 demand_empty_rest_of_line ();
24113 return;
24114 }
24115 as_bad (_("unknown cpu `%s'"), name);
24116 *input_line_pointer = saved_char;
24117 ignore_rest_of_line ();
24118 }
24119
24120
24121 /* Parse a .arch directive. */
24122
24123 static void
24124 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
24125 {
24126 const struct arm_arch_option_table *opt;
24127 char saved_char;
24128 char *name;
24129
24130 name = input_line_pointer;
24131 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24132 input_line_pointer++;
24133 saved_char = *input_line_pointer;
24134 *input_line_pointer = 0;
24135
24136 /* Skip the first "all" entry. */
24137 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24138 if (streq (opt->name, name))
24139 {
24140 mcpu_cpu_opt = &opt->value;
24141 selected_cpu = opt->value;
24142 strcpy (selected_cpu_name, opt->name);
24143 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24144 *input_line_pointer = saved_char;
24145 demand_empty_rest_of_line ();
24146 return;
24147 }
24148
24149 as_bad (_("unknown architecture `%s'\n"), name);
24150 *input_line_pointer = saved_char;
24151 ignore_rest_of_line ();
24152 }
24153
24154
24155 /* Parse a .object_arch directive. */
24156
24157 static void
24158 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
24159 {
24160 const struct arm_arch_option_table *opt;
24161 char saved_char;
24162 char *name;
24163
24164 name = input_line_pointer;
24165 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24166 input_line_pointer++;
24167 saved_char = *input_line_pointer;
24168 *input_line_pointer = 0;
24169
24170 /* Skip the first "all" entry. */
24171 for (opt = arm_archs + 1; opt->name != NULL; opt++)
24172 if (streq (opt->name, name))
24173 {
24174 object_arch = &opt->value;
24175 *input_line_pointer = saved_char;
24176 demand_empty_rest_of_line ();
24177 return;
24178 }
24179
24180 as_bad (_("unknown architecture `%s'\n"), name);
24181 *input_line_pointer = saved_char;
24182 ignore_rest_of_line ();
24183 }
24184
24185 /* Parse a .arch_extension directive. */
24186
24187 static void
24188 s_arm_arch_extension (int ignored ATTRIBUTE_UNUSED)
24189 {
24190 const struct arm_option_extension_value_table *opt;
24191 char saved_char;
24192 char *name;
24193 int adding_value = 1;
24194
24195 name = input_line_pointer;
24196 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24197 input_line_pointer++;
24198 saved_char = *input_line_pointer;
24199 *input_line_pointer = 0;
24200
24201 if (strlen (name) >= 2
24202 && strncmp (name, "no", 2) == 0)
24203 {
24204 adding_value = 0;
24205 name += 2;
24206 }
24207
24208 for (opt = arm_extensions; opt->name != NULL; opt++)
24209 if (streq (opt->name, name))
24210 {
24211 if (!ARM_CPU_HAS_FEATURE (*mcpu_cpu_opt, opt->allowed_archs))
24212 {
24213 as_bad (_("architectural extension `%s' is not allowed for the "
24214 "current base architecture"), name);
24215 break;
24216 }
24217
24218 if (adding_value)
24219 ARM_MERGE_FEATURE_SETS (selected_cpu, selected_cpu, opt->value);
24220 else
24221 ARM_CLEAR_FEATURE (selected_cpu, selected_cpu, opt->value);
24222
24223 mcpu_cpu_opt = &selected_cpu;
24224 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24225 *input_line_pointer = saved_char;
24226 demand_empty_rest_of_line ();
24227 return;
24228 }
24229
24230 if (opt->name == NULL)
24231 as_bad (_("unknown architecture `%s'\n"), name);
24232
24233 *input_line_pointer = saved_char;
24234 ignore_rest_of_line ();
24235 }
24236
24237 /* Parse a .fpu directive. */
24238
24239 static void
24240 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
24241 {
24242 const struct arm_option_fpu_value_table *opt;
24243 char saved_char;
24244 char *name;
24245
24246 name = input_line_pointer;
24247 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
24248 input_line_pointer++;
24249 saved_char = *input_line_pointer;
24250 *input_line_pointer = 0;
24251
24252 for (opt = arm_fpus; opt->name != NULL; opt++)
24253 if (streq (opt->name, name))
24254 {
24255 mfpu_opt = &opt->value;
24256 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
24257 *input_line_pointer = saved_char;
24258 demand_empty_rest_of_line ();
24259 return;
24260 }
24261
24262 as_bad (_("unknown floating point format `%s'\n"), name);
24263 *input_line_pointer = saved_char;
24264 ignore_rest_of_line ();
24265 }
24266
24267 /* Copy symbol information. */
24268
24269 void
24270 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
24271 {
24272 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
24273 }
24274
24275 #ifdef OBJ_ELF
24276 /* Given a symbolic attribute NAME, return the proper integer value.
24277 Returns -1 if the attribute is not known. */
24278
24279 int
24280 arm_convert_symbolic_attribute (const char *name)
24281 {
24282 static const struct
24283 {
24284 const char * name;
24285 const int tag;
24286 }
24287 attribute_table[] =
24288 {
24289 /* When you modify this table you should
24290 also modify the list in doc/c-arm.texi. */
24291 #define T(tag) {#tag, tag}
24292 T (Tag_CPU_raw_name),
24293 T (Tag_CPU_name),
24294 T (Tag_CPU_arch),
24295 T (Tag_CPU_arch_profile),
24296 T (Tag_ARM_ISA_use),
24297 T (Tag_THUMB_ISA_use),
24298 T (Tag_FP_arch),
24299 T (Tag_VFP_arch),
24300 T (Tag_WMMX_arch),
24301 T (Tag_Advanced_SIMD_arch),
24302 T (Tag_PCS_config),
24303 T (Tag_ABI_PCS_R9_use),
24304 T (Tag_ABI_PCS_RW_data),
24305 T (Tag_ABI_PCS_RO_data),
24306 T (Tag_ABI_PCS_GOT_use),
24307 T (Tag_ABI_PCS_wchar_t),
24308 T (Tag_ABI_FP_rounding),
24309 T (Tag_ABI_FP_denormal),
24310 T (Tag_ABI_FP_exceptions),
24311 T (Tag_ABI_FP_user_exceptions),
24312 T (Tag_ABI_FP_number_model),
24313 T (Tag_ABI_align_needed),
24314 T (Tag_ABI_align8_needed),
24315 T (Tag_ABI_align_preserved),
24316 T (Tag_ABI_align8_preserved),
24317 T (Tag_ABI_enum_size),
24318 T (Tag_ABI_HardFP_use),
24319 T (Tag_ABI_VFP_args),
24320 T (Tag_ABI_WMMX_args),
24321 T (Tag_ABI_optimization_goals),
24322 T (Tag_ABI_FP_optimization_goals),
24323 T (Tag_compatibility),
24324 T (Tag_CPU_unaligned_access),
24325 T (Tag_FP_HP_extension),
24326 T (Tag_VFP_HP_extension),
24327 T (Tag_ABI_FP_16bit_format),
24328 T (Tag_MPextension_use),
24329 T (Tag_DIV_use),
24330 T (Tag_nodefaults),
24331 T (Tag_also_compatible_with),
24332 T (Tag_conformance),
24333 T (Tag_T2EE_use),
24334 T (Tag_Virtualization_use),
24335 /* We deliberately do not include Tag_MPextension_use_legacy. */
24336 #undef T
24337 };
24338 unsigned int i;
24339
24340 if (name == NULL)
24341 return -1;
24342
24343 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
24344 if (streq (name, attribute_table[i].name))
24345 return attribute_table[i].tag;
24346
24347 return -1;
24348 }
24349
24350
24351 /* Apply sym value for relocations only in the case that
24352 they are for local symbols and you have the respective
24353 architectural feature for blx and simple switches. */
24354 int
24355 arm_apply_sym_value (struct fix * fixP)
24356 {
24357 if (fixP->fx_addsy
24358 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
24359 && !S_FORCE_RELOC (fixP->fx_addsy, TRUE))
24360 {
24361 switch (fixP->fx_r_type)
24362 {
24363 case BFD_RELOC_ARM_PCREL_BLX:
24364 case BFD_RELOC_THUMB_PCREL_BRANCH23:
24365 if (ARM_IS_FUNC (fixP->fx_addsy))
24366 return 1;
24367 break;
24368
24369 case BFD_RELOC_ARM_PCREL_CALL:
24370 case BFD_RELOC_THUMB_PCREL_BLX:
24371 if (THUMB_IS_FUNC (fixP->fx_addsy))
24372 return 1;
24373 break;
24374
24375 default:
24376 break;
24377 }
24378
24379 }
24380 return 0;
24381 }
24382 #endif /* OBJ_ELF */