2010-07-08 Tejas Belagod <tejas.belagod@arm.com>
[deliverable/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
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
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_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
188 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 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_m =
199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
200
201 static const arm_feature_set arm_arch_any = ARM_ANY;
202 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
203 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
204 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
205
206 static const arm_feature_set arm_cext_iwmmxt2 =
207 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
208 static const arm_feature_set arm_cext_iwmmxt =
209 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
210 static const arm_feature_set arm_cext_xscale =
211 ARM_FEATURE (0, ARM_CEXT_XSCALE);
212 static const arm_feature_set arm_cext_maverick =
213 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
214 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
215 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
216 static const arm_feature_set fpu_vfp_ext_v1xd =
217 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
218 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
219 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
220 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
221 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
222 static const arm_feature_set fpu_vfp_ext_d32 =
223 ARM_FEATURE (0, FPU_VFP_EXT_D32);
224 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
225 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
226 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
227 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
228 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
229 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
230
231 static int mfloat_abi_opt = -1;
232 /* Record user cpu selection for object attributes. */
233 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
234 /* Must be long enough to hold any of the names in arm_cpus. */
235 static char selected_cpu_name[16];
236 #ifdef OBJ_ELF
237 # ifdef EABI_DEFAULT
238 static int meabi_flags = EABI_DEFAULT;
239 # else
240 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
241 # endif
242
243 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
244
245 bfd_boolean
246 arm_is_eabi (void)
247 {
248 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
249 }
250 #endif
251
252 #ifdef OBJ_ELF
253 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
254 symbolS * GOT_symbol;
255 #endif
256
257 /* 0: assemble for ARM,
258 1: assemble for Thumb,
259 2: assemble for Thumb even though target CPU does not support thumb
260 instructions. */
261 static int thumb_mode = 0;
262 /* A value distinct from the possible values for thumb_mode that we
263 can use to record whether thumb_mode has been copied into the
264 tc_frag_data field of a frag. */
265 #define MODE_RECORDED (1 << 4)
266
267 /* Specifies the intrinsic IT insn behavior mode. */
268 enum implicit_it_mode
269 {
270 IMPLICIT_IT_MODE_NEVER = 0x00,
271 IMPLICIT_IT_MODE_ARM = 0x01,
272 IMPLICIT_IT_MODE_THUMB = 0x02,
273 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
274 };
275 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
276
277 /* If unified_syntax is true, we are processing the new unified
278 ARM/Thumb syntax. Important differences from the old ARM mode:
279
280 - Immediate operands do not require a # prefix.
281 - Conditional affixes always appear at the end of the
282 instruction. (For backward compatibility, those instructions
283 that formerly had them in the middle, continue to accept them
284 there.)
285 - The IT instruction may appear, and if it does is validated
286 against subsequent conditional affixes. It does not generate
287 machine code.
288
289 Important differences from the old Thumb mode:
290
291 - Immediate operands do not require a # prefix.
292 - Most of the V6T2 instructions are only available in unified mode.
293 - The .N and .W suffixes are recognized and honored (it is an error
294 if they cannot be honored).
295 - All instructions set the flags if and only if they have an 's' affix.
296 - Conditional affixes may be used. They are validated against
297 preceding IT instructions. Unlike ARM mode, you cannot use a
298 conditional affix except in the scope of an IT instruction. */
299
300 static bfd_boolean unified_syntax = FALSE;
301
302 enum neon_el_type
303 {
304 NT_invtype,
305 NT_untyped,
306 NT_integer,
307 NT_float,
308 NT_poly,
309 NT_signed,
310 NT_unsigned
311 };
312
313 struct neon_type_el
314 {
315 enum neon_el_type type;
316 unsigned size;
317 };
318
319 #define NEON_MAX_TYPE_ELS 4
320
321 struct neon_type
322 {
323 struct neon_type_el el[NEON_MAX_TYPE_ELS];
324 unsigned elems;
325 };
326
327 enum it_instruction_type
328 {
329 OUTSIDE_IT_INSN,
330 INSIDE_IT_INSN,
331 INSIDE_IT_LAST_INSN,
332 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
333 if inside, should be the last one. */
334 NEUTRAL_IT_INSN, /* This could be either inside or outside,
335 i.e. BKPT and NOP. */
336 IT_INSN /* The IT insn has been parsed. */
337 };
338
339 struct arm_it
340 {
341 const char * error;
342 unsigned long instruction;
343 int size;
344 int size_req;
345 int cond;
346 /* "uncond_value" is set to the value in place of the conditional field in
347 unconditional versions of the instruction, or -1 if nothing is
348 appropriate. */
349 int uncond_value;
350 struct neon_type vectype;
351 /* This does not indicate an actual NEON instruction, only that
352 the mnemonic accepts neon-style type suffixes. */
353 int is_neon;
354 /* Set to the opcode if the instruction needs relaxation.
355 Zero if the instruction is not relaxed. */
356 unsigned long relax;
357 struct
358 {
359 bfd_reloc_code_real_type type;
360 expressionS exp;
361 int pc_rel;
362 } reloc;
363
364 enum it_instruction_type it_insn_type;
365
366 struct
367 {
368 unsigned reg;
369 signed int imm;
370 struct neon_type_el vectype;
371 unsigned present : 1; /* Operand present. */
372 unsigned isreg : 1; /* Operand was a register. */
373 unsigned immisreg : 1; /* .imm field is a second register. */
374 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
375 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
376 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
377 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
378 instructions. This allows us to disambiguate ARM <-> vector insns. */
379 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
380 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
381 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
382 unsigned issingle : 1; /* Operand is VFP single-precision register. */
383 unsigned hasreloc : 1; /* Operand has relocation suffix. */
384 unsigned writeback : 1; /* Operand has trailing ! */
385 unsigned preind : 1; /* Preindexed address. */
386 unsigned postind : 1; /* Postindexed address. */
387 unsigned negative : 1; /* Index register was negated. */
388 unsigned shifted : 1; /* Shift applied to operation. */
389 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
390 } operands[6];
391 };
392
393 static struct arm_it inst;
394
395 #define NUM_FLOAT_VALS 8
396
397 const char * fp_const[] =
398 {
399 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
400 };
401
402 /* Number of littlenums required to hold an extended precision number. */
403 #define MAX_LITTLENUMS 6
404
405 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
406
407 #define FAIL (-1)
408 #define SUCCESS (0)
409
410 #define SUFF_S 1
411 #define SUFF_D 2
412 #define SUFF_E 3
413 #define SUFF_P 4
414
415 #define CP_T_X 0x00008000
416 #define CP_T_Y 0x00400000
417
418 #define CONDS_BIT 0x00100000
419 #define LOAD_BIT 0x00100000
420
421 #define DOUBLE_LOAD_FLAG 0x00000001
422
423 struct asm_cond
424 {
425 const char * template_name;
426 unsigned long value;
427 };
428
429 #define COND_ALWAYS 0xE
430
431 struct asm_psr
432 {
433 const char * template_name;
434 unsigned long field;
435 };
436
437 struct asm_barrier_opt
438 {
439 const char * template_name;
440 unsigned long value;
441 };
442
443 /* The bit that distinguishes CPSR and SPSR. */
444 #define SPSR_BIT (1 << 22)
445
446 /* The individual PSR flag bits. */
447 #define PSR_c (1 << 16)
448 #define PSR_x (1 << 17)
449 #define PSR_s (1 << 18)
450 #define PSR_f (1 << 19)
451
452 struct reloc_entry
453 {
454 char * name;
455 bfd_reloc_code_real_type reloc;
456 };
457
458 enum vfp_reg_pos
459 {
460 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
461 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
462 };
463
464 enum vfp_ldstm_type
465 {
466 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
467 };
468
469 /* Bits for DEFINED field in neon_typed_alias. */
470 #define NTA_HASTYPE 1
471 #define NTA_HASINDEX 2
472
473 struct neon_typed_alias
474 {
475 unsigned char defined;
476 unsigned char index;
477 struct neon_type_el eltype;
478 };
479
480 /* ARM register categories. This includes coprocessor numbers and various
481 architecture extensions' registers. */
482 enum arm_reg_type
483 {
484 REG_TYPE_RN,
485 REG_TYPE_CP,
486 REG_TYPE_CN,
487 REG_TYPE_FN,
488 REG_TYPE_VFS,
489 REG_TYPE_VFD,
490 REG_TYPE_NQ,
491 REG_TYPE_VFSD,
492 REG_TYPE_NDQ,
493 REG_TYPE_NSDQ,
494 REG_TYPE_VFC,
495 REG_TYPE_MVF,
496 REG_TYPE_MVD,
497 REG_TYPE_MVFX,
498 REG_TYPE_MVDX,
499 REG_TYPE_MVAX,
500 REG_TYPE_DSPSC,
501 REG_TYPE_MMXWR,
502 REG_TYPE_MMXWC,
503 REG_TYPE_MMXWCG,
504 REG_TYPE_XSCALE,
505 };
506
507 /* Structure for a hash table entry for a register.
508 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
509 information which states whether a vector type or index is specified (for a
510 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
511 struct reg_entry
512 {
513 const char * name;
514 unsigned char number;
515 unsigned char type;
516 unsigned char builtin;
517 struct neon_typed_alias * neon;
518 };
519
520 /* Diagnostics used when we don't get a register of the expected type. */
521 const char * const reg_expected_msgs[] =
522 {
523 N_("ARM register expected"),
524 N_("bad or missing co-processor number"),
525 N_("co-processor register expected"),
526 N_("FPA register expected"),
527 N_("VFP single precision register expected"),
528 N_("VFP/Neon double precision register expected"),
529 N_("Neon quad precision register expected"),
530 N_("VFP single or double precision register expected"),
531 N_("Neon double or quad precision register expected"),
532 N_("VFP single, double or Neon quad precision register expected"),
533 N_("VFP system register expected"),
534 N_("Maverick MVF register expected"),
535 N_("Maverick MVD register expected"),
536 N_("Maverick MVFX register expected"),
537 N_("Maverick MVDX register expected"),
538 N_("Maverick MVAX register expected"),
539 N_("Maverick DSPSC register expected"),
540 N_("iWMMXt data register expected"),
541 N_("iWMMXt control register expected"),
542 N_("iWMMXt scalar register expected"),
543 N_("XScale accumulator register expected"),
544 };
545
546 /* Some well known registers that we refer to directly elsewhere. */
547 #define REG_SP 13
548 #define REG_LR 14
549 #define REG_PC 15
550
551 /* ARM instructions take 4bytes in the object file, Thumb instructions
552 take 2: */
553 #define INSN_SIZE 4
554
555 struct asm_opcode
556 {
557 /* Basic string to match. */
558 const char * template_name;
559
560 /* Parameters to instruction. */
561 unsigned int operands[8];
562
563 /* Conditional tag - see opcode_lookup. */
564 unsigned int tag : 4;
565
566 /* Basic instruction code. */
567 unsigned int avalue : 28;
568
569 /* Thumb-format instruction code. */
570 unsigned int tvalue;
571
572 /* Which architecture variant provides this instruction. */
573 const arm_feature_set * avariant;
574 const arm_feature_set * tvariant;
575
576 /* Function to call to encode instruction in ARM format. */
577 void (* aencode) (void);
578
579 /* Function to call to encode instruction in Thumb format. */
580 void (* tencode) (void);
581 };
582
583 /* Defines for various bits that we will want to toggle. */
584 #define INST_IMMEDIATE 0x02000000
585 #define OFFSET_REG 0x02000000
586 #define HWOFFSET_IMM 0x00400000
587 #define SHIFT_BY_REG 0x00000010
588 #define PRE_INDEX 0x01000000
589 #define INDEX_UP 0x00800000
590 #define WRITE_BACK 0x00200000
591 #define LDM_TYPE_2_OR_3 0x00400000
592 #define CPSI_MMOD 0x00020000
593
594 #define LITERAL_MASK 0xf000f000
595 #define OPCODE_MASK 0xfe1fffff
596 #define V4_STR_BIT 0x00000020
597
598 #define T2_SUBS_PC_LR 0xf3de8f00
599
600 #define DATA_OP_SHIFT 21
601
602 #define T2_OPCODE_MASK 0xfe1fffff
603 #define T2_DATA_OP_SHIFT 21
604
605 /* Codes to distinguish the arithmetic instructions. */
606 #define OPCODE_AND 0
607 #define OPCODE_EOR 1
608 #define OPCODE_SUB 2
609 #define OPCODE_RSB 3
610 #define OPCODE_ADD 4
611 #define OPCODE_ADC 5
612 #define OPCODE_SBC 6
613 #define OPCODE_RSC 7
614 #define OPCODE_TST 8
615 #define OPCODE_TEQ 9
616 #define OPCODE_CMP 10
617 #define OPCODE_CMN 11
618 #define OPCODE_ORR 12
619 #define OPCODE_MOV 13
620 #define OPCODE_BIC 14
621 #define OPCODE_MVN 15
622
623 #define T2_OPCODE_AND 0
624 #define T2_OPCODE_BIC 1
625 #define T2_OPCODE_ORR 2
626 #define T2_OPCODE_ORN 3
627 #define T2_OPCODE_EOR 4
628 #define T2_OPCODE_ADD 8
629 #define T2_OPCODE_ADC 10
630 #define T2_OPCODE_SBC 11
631 #define T2_OPCODE_SUB 13
632 #define T2_OPCODE_RSB 14
633
634 #define T_OPCODE_MUL 0x4340
635 #define T_OPCODE_TST 0x4200
636 #define T_OPCODE_CMN 0x42c0
637 #define T_OPCODE_NEG 0x4240
638 #define T_OPCODE_MVN 0x43c0
639
640 #define T_OPCODE_ADD_R3 0x1800
641 #define T_OPCODE_SUB_R3 0x1a00
642 #define T_OPCODE_ADD_HI 0x4400
643 #define T_OPCODE_ADD_ST 0xb000
644 #define T_OPCODE_SUB_ST 0xb080
645 #define T_OPCODE_ADD_SP 0xa800
646 #define T_OPCODE_ADD_PC 0xa000
647 #define T_OPCODE_ADD_I8 0x3000
648 #define T_OPCODE_SUB_I8 0x3800
649 #define T_OPCODE_ADD_I3 0x1c00
650 #define T_OPCODE_SUB_I3 0x1e00
651
652 #define T_OPCODE_ASR_R 0x4100
653 #define T_OPCODE_LSL_R 0x4080
654 #define T_OPCODE_LSR_R 0x40c0
655 #define T_OPCODE_ROR_R 0x41c0
656 #define T_OPCODE_ASR_I 0x1000
657 #define T_OPCODE_LSL_I 0x0000
658 #define T_OPCODE_LSR_I 0x0800
659
660 #define T_OPCODE_MOV_I8 0x2000
661 #define T_OPCODE_CMP_I8 0x2800
662 #define T_OPCODE_CMP_LR 0x4280
663 #define T_OPCODE_MOV_HR 0x4600
664 #define T_OPCODE_CMP_HR 0x4500
665
666 #define T_OPCODE_LDR_PC 0x4800
667 #define T_OPCODE_LDR_SP 0x9800
668 #define T_OPCODE_STR_SP 0x9000
669 #define T_OPCODE_LDR_IW 0x6800
670 #define T_OPCODE_STR_IW 0x6000
671 #define T_OPCODE_LDR_IH 0x8800
672 #define T_OPCODE_STR_IH 0x8000
673 #define T_OPCODE_LDR_IB 0x7800
674 #define T_OPCODE_STR_IB 0x7000
675 #define T_OPCODE_LDR_RW 0x5800
676 #define T_OPCODE_STR_RW 0x5000
677 #define T_OPCODE_LDR_RH 0x5a00
678 #define T_OPCODE_STR_RH 0x5200
679 #define T_OPCODE_LDR_RB 0x5c00
680 #define T_OPCODE_STR_RB 0x5400
681
682 #define T_OPCODE_PUSH 0xb400
683 #define T_OPCODE_POP 0xbc00
684
685 #define T_OPCODE_BRANCH 0xe000
686
687 #define THUMB_SIZE 2 /* Size of thumb instruction. */
688 #define THUMB_PP_PC_LR 0x0100
689 #define THUMB_LOAD_BIT 0x0800
690 #define THUMB2_LOAD_BIT 0x00100000
691
692 #define BAD_ARGS _("bad arguments to instruction")
693 #define BAD_SP _("r13 not allowed here")
694 #define BAD_PC _("r15 not allowed here")
695 #define BAD_COND _("instruction cannot be conditional")
696 #define BAD_OVERLAP _("registers may not be the same")
697 #define BAD_HIREG _("lo register required")
698 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
699 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
700 #define BAD_BRANCH _("branch must be last instruction in IT block")
701 #define BAD_NOT_IT _("instruction not allowed in IT block")
702 #define BAD_FPU _("selected FPU does not support instruction")
703 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
704 #define BAD_IT_COND _("incorrect condition in IT block")
705 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
706 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
707 #define BAD_PC_ADDRESSING \
708 _("cannot use register index with PC-relative addressing")
709 #define BAD_PC_WRITEBACK \
710 _("cannot use writeback with PC-relative addressing")
711
712 static struct hash_control * arm_ops_hsh;
713 static struct hash_control * arm_cond_hsh;
714 static struct hash_control * arm_shift_hsh;
715 static struct hash_control * arm_psr_hsh;
716 static struct hash_control * arm_v7m_psr_hsh;
717 static struct hash_control * arm_reg_hsh;
718 static struct hash_control * arm_reloc_hsh;
719 static struct hash_control * arm_barrier_opt_hsh;
720
721 /* Stuff needed to resolve the label ambiguity
722 As:
723 ...
724 label: <insn>
725 may differ from:
726 ...
727 label:
728 <insn> */
729
730 symbolS * last_label_seen;
731 static int label_is_thumb_function_name = FALSE;
732
733 /* Literal pool structure. Held on a per-section
734 and per-sub-section basis. */
735
736 #define MAX_LITERAL_POOL_SIZE 1024
737 typedef struct literal_pool
738 {
739 expressionS literals [MAX_LITERAL_POOL_SIZE];
740 unsigned int next_free_entry;
741 unsigned int id;
742 symbolS * symbol;
743 segT section;
744 subsegT sub_section;
745 struct literal_pool * next;
746 } literal_pool;
747
748 /* Pointer to a linked list of literal pools. */
749 literal_pool * list_of_pools = NULL;
750
751 #ifdef OBJ_ELF
752 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
753 #else
754 static struct current_it now_it;
755 #endif
756
757 static inline int
758 now_it_compatible (int cond)
759 {
760 return (cond & ~1) == (now_it.cc & ~1);
761 }
762
763 static inline int
764 conditional_insn (void)
765 {
766 return inst.cond != COND_ALWAYS;
767 }
768
769 static int in_it_block (void);
770
771 static int handle_it_state (void);
772
773 static void force_automatic_it_block_close (void);
774
775 static void it_fsm_post_encode (void);
776
777 #define set_it_insn_type(type) \
778 do \
779 { \
780 inst.it_insn_type = type; \
781 if (handle_it_state () == FAIL) \
782 return; \
783 } \
784 while (0)
785
786 #define set_it_insn_type_nonvoid(type, failret) \
787 do \
788 { \
789 inst.it_insn_type = type; \
790 if (handle_it_state () == FAIL) \
791 return failret; \
792 } \
793 while(0)
794
795 #define set_it_insn_type_last() \
796 do \
797 { \
798 if (inst.cond == COND_ALWAYS) \
799 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
800 else \
801 set_it_insn_type (INSIDE_IT_LAST_INSN); \
802 } \
803 while (0)
804
805 /* Pure syntax. */
806
807 /* This array holds the chars that always start a comment. If the
808 pre-processor is disabled, these aren't very useful. */
809 const char comment_chars[] = "@";
810
811 /* This array holds the chars that only start a comment at the beginning of
812 a line. If the line seems to have the form '# 123 filename'
813 .line and .file directives will appear in the pre-processed output. */
814 /* Note that input_file.c hand checks for '#' at the beginning of the
815 first line of the input file. This is because the compiler outputs
816 #NO_APP at the beginning of its output. */
817 /* Also note that comments like this one will always work. */
818 const char line_comment_chars[] = "#";
819
820 const char line_separator_chars[] = ";";
821
822 /* Chars that can be used to separate mant
823 from exp in floating point numbers. */
824 const char EXP_CHARS[] = "eE";
825
826 /* Chars that mean this number is a floating point constant. */
827 /* As in 0f12.456 */
828 /* or 0d1.2345e12 */
829
830 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
831
832 /* Prefix characters that indicate the start of an immediate
833 value. */
834 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
835
836 /* Separator character handling. */
837
838 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
839
840 static inline int
841 skip_past_char (char ** str, char c)
842 {
843 if (**str == c)
844 {
845 (*str)++;
846 return SUCCESS;
847 }
848 else
849 return FAIL;
850 }
851
852 #define skip_past_comma(str) skip_past_char (str, ',')
853
854 /* Arithmetic expressions (possibly involving symbols). */
855
856 /* Return TRUE if anything in the expression is a bignum. */
857
858 static int
859 walk_no_bignums (symbolS * sp)
860 {
861 if (symbol_get_value_expression (sp)->X_op == O_big)
862 return 1;
863
864 if (symbol_get_value_expression (sp)->X_add_symbol)
865 {
866 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
867 || (symbol_get_value_expression (sp)->X_op_symbol
868 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
869 }
870
871 return 0;
872 }
873
874 static int in_my_get_expression = 0;
875
876 /* Third argument to my_get_expression. */
877 #define GE_NO_PREFIX 0
878 #define GE_IMM_PREFIX 1
879 #define GE_OPT_PREFIX 2
880 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
881 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
882 #define GE_OPT_PREFIX_BIG 3
883
884 static int
885 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
886 {
887 char * save_in;
888 segT seg;
889
890 /* In unified syntax, all prefixes are optional. */
891 if (unified_syntax)
892 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
893 : GE_OPT_PREFIX;
894
895 switch (prefix_mode)
896 {
897 case GE_NO_PREFIX: break;
898 case GE_IMM_PREFIX:
899 if (!is_immediate_prefix (**str))
900 {
901 inst.error = _("immediate expression requires a # prefix");
902 return FAIL;
903 }
904 (*str)++;
905 break;
906 case GE_OPT_PREFIX:
907 case GE_OPT_PREFIX_BIG:
908 if (is_immediate_prefix (**str))
909 (*str)++;
910 break;
911 default: abort ();
912 }
913
914 memset (ep, 0, sizeof (expressionS));
915
916 save_in = input_line_pointer;
917 input_line_pointer = *str;
918 in_my_get_expression = 1;
919 seg = expression (ep);
920 in_my_get_expression = 0;
921
922 if (ep->X_op == O_illegal || ep->X_op == O_absent)
923 {
924 /* We found a bad or missing expression in md_operand(). */
925 *str = input_line_pointer;
926 input_line_pointer = save_in;
927 if (inst.error == NULL)
928 inst.error = (ep->X_op == O_absent
929 ? _("missing expression") :_("bad expression"));
930 return 1;
931 }
932
933 #ifdef OBJ_AOUT
934 if (seg != absolute_section
935 && seg != text_section
936 && seg != data_section
937 && seg != bss_section
938 && seg != undefined_section)
939 {
940 inst.error = _("bad segment");
941 *str = input_line_pointer;
942 input_line_pointer = save_in;
943 return 1;
944 }
945 #else
946 (void) seg;
947 #endif
948
949 /* Get rid of any bignums now, so that we don't generate an error for which
950 we can't establish a line number later on. Big numbers are never valid
951 in instructions, which is where this routine is always called. */
952 if (prefix_mode != GE_OPT_PREFIX_BIG
953 && (ep->X_op == O_big
954 || (ep->X_add_symbol
955 && (walk_no_bignums (ep->X_add_symbol)
956 || (ep->X_op_symbol
957 && walk_no_bignums (ep->X_op_symbol))))))
958 {
959 inst.error = _("invalid constant");
960 *str = input_line_pointer;
961 input_line_pointer = save_in;
962 return 1;
963 }
964
965 *str = input_line_pointer;
966 input_line_pointer = save_in;
967 return 0;
968 }
969
970 /* Turn a string in input_line_pointer into a floating point constant
971 of type TYPE, and store the appropriate bytes in *LITP. The number
972 of LITTLENUMS emitted is stored in *SIZEP. An error message is
973 returned, or NULL on OK.
974
975 Note that fp constants aren't represent in the normal way on the ARM.
976 In big endian mode, things are as expected. However, in little endian
977 mode fp constants are big-endian word-wise, and little-endian byte-wise
978 within the words. For example, (double) 1.1 in big endian mode is
979 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
980 the byte sequence 99 99 f1 3f 9a 99 99 99.
981
982 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
983
984 char *
985 md_atof (int type, char * litP, int * sizeP)
986 {
987 int prec;
988 LITTLENUM_TYPE words[MAX_LITTLENUMS];
989 char *t;
990 int i;
991
992 switch (type)
993 {
994 case 'f':
995 case 'F':
996 case 's':
997 case 'S':
998 prec = 2;
999 break;
1000
1001 case 'd':
1002 case 'D':
1003 case 'r':
1004 case 'R':
1005 prec = 4;
1006 break;
1007
1008 case 'x':
1009 case 'X':
1010 prec = 5;
1011 break;
1012
1013 case 'p':
1014 case 'P':
1015 prec = 5;
1016 break;
1017
1018 default:
1019 *sizeP = 0;
1020 return _("Unrecognized or unsupported floating point constant");
1021 }
1022
1023 t = atof_ieee (input_line_pointer, type, words);
1024 if (t)
1025 input_line_pointer = t;
1026 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1027
1028 if (target_big_endian)
1029 {
1030 for (i = 0; i < prec; i++)
1031 {
1032 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1033 litP += sizeof (LITTLENUM_TYPE);
1034 }
1035 }
1036 else
1037 {
1038 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1039 for (i = prec - 1; i >= 0; i--)
1040 {
1041 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1042 litP += sizeof (LITTLENUM_TYPE);
1043 }
1044 else
1045 /* For a 4 byte float the order of elements in `words' is 1 0.
1046 For an 8 byte float the order is 1 0 3 2. */
1047 for (i = 0; i < prec; i += 2)
1048 {
1049 md_number_to_chars (litP, (valueT) words[i + 1],
1050 sizeof (LITTLENUM_TYPE));
1051 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1052 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1053 litP += 2 * sizeof (LITTLENUM_TYPE);
1054 }
1055 }
1056
1057 return NULL;
1058 }
1059
1060 /* We handle all bad expressions here, so that we can report the faulty
1061 instruction in the error message. */
1062 void
1063 md_operand (expressionS * exp)
1064 {
1065 if (in_my_get_expression)
1066 exp->X_op = O_illegal;
1067 }
1068
1069 /* Immediate values. */
1070
1071 /* Generic immediate-value read function for use in directives.
1072 Accepts anything that 'expression' can fold to a constant.
1073 *val receives the number. */
1074 #ifdef OBJ_ELF
1075 static int
1076 immediate_for_directive (int *val)
1077 {
1078 expressionS exp;
1079 exp.X_op = O_illegal;
1080
1081 if (is_immediate_prefix (*input_line_pointer))
1082 {
1083 input_line_pointer++;
1084 expression (&exp);
1085 }
1086
1087 if (exp.X_op != O_constant)
1088 {
1089 as_bad (_("expected #constant"));
1090 ignore_rest_of_line ();
1091 return FAIL;
1092 }
1093 *val = exp.X_add_number;
1094 return SUCCESS;
1095 }
1096 #endif
1097
1098 /* Register parsing. */
1099
1100 /* Generic register parser. CCP points to what should be the
1101 beginning of a register name. If it is indeed a valid register
1102 name, advance CCP over it and return the reg_entry structure;
1103 otherwise return NULL. Does not issue diagnostics. */
1104
1105 static struct reg_entry *
1106 arm_reg_parse_multi (char **ccp)
1107 {
1108 char *start = *ccp;
1109 char *p;
1110 struct reg_entry *reg;
1111
1112 #ifdef REGISTER_PREFIX
1113 if (*start != REGISTER_PREFIX)
1114 return NULL;
1115 start++;
1116 #endif
1117 #ifdef OPTIONAL_REGISTER_PREFIX
1118 if (*start == OPTIONAL_REGISTER_PREFIX)
1119 start++;
1120 #endif
1121
1122 p = start;
1123 if (!ISALPHA (*p) || !is_name_beginner (*p))
1124 return NULL;
1125
1126 do
1127 p++;
1128 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1129
1130 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1131
1132 if (!reg)
1133 return NULL;
1134
1135 *ccp = p;
1136 return reg;
1137 }
1138
1139 static int
1140 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1141 enum arm_reg_type type)
1142 {
1143 /* Alternative syntaxes are accepted for a few register classes. */
1144 switch (type)
1145 {
1146 case REG_TYPE_MVF:
1147 case REG_TYPE_MVD:
1148 case REG_TYPE_MVFX:
1149 case REG_TYPE_MVDX:
1150 /* Generic coprocessor register names are allowed for these. */
1151 if (reg && reg->type == REG_TYPE_CN)
1152 return reg->number;
1153 break;
1154
1155 case REG_TYPE_CP:
1156 /* For backward compatibility, a bare number is valid here. */
1157 {
1158 unsigned long processor = strtoul (start, ccp, 10);
1159 if (*ccp != start && processor <= 15)
1160 return processor;
1161 }
1162
1163 case REG_TYPE_MMXWC:
1164 /* WC includes WCG. ??? I'm not sure this is true for all
1165 instructions that take WC registers. */
1166 if (reg && reg->type == REG_TYPE_MMXWCG)
1167 return reg->number;
1168 break;
1169
1170 default:
1171 break;
1172 }
1173
1174 return FAIL;
1175 }
1176
1177 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1178 return value is the register number or FAIL. */
1179
1180 static int
1181 arm_reg_parse (char **ccp, enum arm_reg_type type)
1182 {
1183 char *start = *ccp;
1184 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1185 int ret;
1186
1187 /* Do not allow a scalar (reg+index) to parse as a register. */
1188 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1189 return FAIL;
1190
1191 if (reg && reg->type == type)
1192 return reg->number;
1193
1194 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1195 return ret;
1196
1197 *ccp = start;
1198 return FAIL;
1199 }
1200
1201 /* Parse a Neon type specifier. *STR should point at the leading '.'
1202 character. Does no verification at this stage that the type fits the opcode
1203 properly. E.g.,
1204
1205 .i32.i32.s16
1206 .s32.f32
1207 .u16
1208
1209 Can all be legally parsed by this function.
1210
1211 Fills in neon_type struct pointer with parsed information, and updates STR
1212 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1213 type, FAIL if not. */
1214
1215 static int
1216 parse_neon_type (struct neon_type *type, char **str)
1217 {
1218 char *ptr = *str;
1219
1220 if (type)
1221 type->elems = 0;
1222
1223 while (type->elems < NEON_MAX_TYPE_ELS)
1224 {
1225 enum neon_el_type thistype = NT_untyped;
1226 unsigned thissize = -1u;
1227
1228 if (*ptr != '.')
1229 break;
1230
1231 ptr++;
1232
1233 /* Just a size without an explicit type. */
1234 if (ISDIGIT (*ptr))
1235 goto parsesize;
1236
1237 switch (TOLOWER (*ptr))
1238 {
1239 case 'i': thistype = NT_integer; break;
1240 case 'f': thistype = NT_float; break;
1241 case 'p': thistype = NT_poly; break;
1242 case 's': thistype = NT_signed; break;
1243 case 'u': thistype = NT_unsigned; break;
1244 case 'd':
1245 thistype = NT_float;
1246 thissize = 64;
1247 ptr++;
1248 goto done;
1249 default:
1250 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1251 return FAIL;
1252 }
1253
1254 ptr++;
1255
1256 /* .f is an abbreviation for .f32. */
1257 if (thistype == NT_float && !ISDIGIT (*ptr))
1258 thissize = 32;
1259 else
1260 {
1261 parsesize:
1262 thissize = strtoul (ptr, &ptr, 10);
1263
1264 if (thissize != 8 && thissize != 16 && thissize != 32
1265 && thissize != 64)
1266 {
1267 as_bad (_("bad size %d in type specifier"), thissize);
1268 return FAIL;
1269 }
1270 }
1271
1272 done:
1273 if (type)
1274 {
1275 type->el[type->elems].type = thistype;
1276 type->el[type->elems].size = thissize;
1277 type->elems++;
1278 }
1279 }
1280
1281 /* Empty/missing type is not a successful parse. */
1282 if (type->elems == 0)
1283 return FAIL;
1284
1285 *str = ptr;
1286
1287 return SUCCESS;
1288 }
1289
1290 /* Errors may be set multiple times during parsing or bit encoding
1291 (particularly in the Neon bits), but usually the earliest error which is set
1292 will be the most meaningful. Avoid overwriting it with later (cascading)
1293 errors by calling this function. */
1294
1295 static void
1296 first_error (const char *err)
1297 {
1298 if (!inst.error)
1299 inst.error = err;
1300 }
1301
1302 /* Parse a single type, e.g. ".s32", leading period included. */
1303 static int
1304 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1305 {
1306 char *str = *ccp;
1307 struct neon_type optype;
1308
1309 if (*str == '.')
1310 {
1311 if (parse_neon_type (&optype, &str) == SUCCESS)
1312 {
1313 if (optype.elems == 1)
1314 *vectype = optype.el[0];
1315 else
1316 {
1317 first_error (_("only one type should be specified for operand"));
1318 return FAIL;
1319 }
1320 }
1321 else
1322 {
1323 first_error (_("vector type expected"));
1324 return FAIL;
1325 }
1326 }
1327 else
1328 return FAIL;
1329
1330 *ccp = str;
1331
1332 return SUCCESS;
1333 }
1334
1335 /* Special meanings for indices (which have a range of 0-7), which will fit into
1336 a 4-bit integer. */
1337
1338 #define NEON_ALL_LANES 15
1339 #define NEON_INTERLEAVE_LANES 14
1340
1341 /* Parse either a register or a scalar, with an optional type. Return the
1342 register number, and optionally fill in the actual type of the register
1343 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1344 type/index information in *TYPEINFO. */
1345
1346 static int
1347 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1348 enum arm_reg_type *rtype,
1349 struct neon_typed_alias *typeinfo)
1350 {
1351 char *str = *ccp;
1352 struct reg_entry *reg = arm_reg_parse_multi (&str);
1353 struct neon_typed_alias atype;
1354 struct neon_type_el parsetype;
1355
1356 atype.defined = 0;
1357 atype.index = -1;
1358 atype.eltype.type = NT_invtype;
1359 atype.eltype.size = -1;
1360
1361 /* Try alternate syntax for some types of register. Note these are mutually
1362 exclusive with the Neon syntax extensions. */
1363 if (reg == NULL)
1364 {
1365 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1366 if (altreg != FAIL)
1367 *ccp = str;
1368 if (typeinfo)
1369 *typeinfo = atype;
1370 return altreg;
1371 }
1372
1373 /* Undo polymorphism when a set of register types may be accepted. */
1374 if ((type == REG_TYPE_NDQ
1375 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1376 || (type == REG_TYPE_VFSD
1377 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1378 || (type == REG_TYPE_NSDQ
1379 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1380 || reg->type == REG_TYPE_NQ))
1381 || (type == REG_TYPE_MMXWC
1382 && (reg->type == REG_TYPE_MMXWCG)))
1383 type = (enum arm_reg_type) reg->type;
1384
1385 if (type != reg->type)
1386 return FAIL;
1387
1388 if (reg->neon)
1389 atype = *reg->neon;
1390
1391 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1392 {
1393 if ((atype.defined & NTA_HASTYPE) != 0)
1394 {
1395 first_error (_("can't redefine type for operand"));
1396 return FAIL;
1397 }
1398 atype.defined |= NTA_HASTYPE;
1399 atype.eltype = parsetype;
1400 }
1401
1402 if (skip_past_char (&str, '[') == SUCCESS)
1403 {
1404 if (type != REG_TYPE_VFD)
1405 {
1406 first_error (_("only D registers may be indexed"));
1407 return FAIL;
1408 }
1409
1410 if ((atype.defined & NTA_HASINDEX) != 0)
1411 {
1412 first_error (_("can't change index for operand"));
1413 return FAIL;
1414 }
1415
1416 atype.defined |= NTA_HASINDEX;
1417
1418 if (skip_past_char (&str, ']') == SUCCESS)
1419 atype.index = NEON_ALL_LANES;
1420 else
1421 {
1422 expressionS exp;
1423
1424 my_get_expression (&exp, &str, GE_NO_PREFIX);
1425
1426 if (exp.X_op != O_constant)
1427 {
1428 first_error (_("constant expression required"));
1429 return FAIL;
1430 }
1431
1432 if (skip_past_char (&str, ']') == FAIL)
1433 return FAIL;
1434
1435 atype.index = exp.X_add_number;
1436 }
1437 }
1438
1439 if (typeinfo)
1440 *typeinfo = atype;
1441
1442 if (rtype)
1443 *rtype = type;
1444
1445 *ccp = str;
1446
1447 return reg->number;
1448 }
1449
1450 /* Like arm_reg_parse, but allow allow the following extra features:
1451 - If RTYPE is non-zero, return the (possibly restricted) type of the
1452 register (e.g. Neon double or quad reg when either has been requested).
1453 - If this is a Neon vector type with additional type information, fill
1454 in the struct pointed to by VECTYPE (if non-NULL).
1455 This function will fault on encountering a scalar. */
1456
1457 static int
1458 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1459 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1460 {
1461 struct neon_typed_alias atype;
1462 char *str = *ccp;
1463 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1464
1465 if (reg == FAIL)
1466 return FAIL;
1467
1468 /* Do not allow a scalar (reg+index) to parse as a register. */
1469 if ((atype.defined & NTA_HASINDEX) != 0)
1470 {
1471 first_error (_("register operand expected, but got scalar"));
1472 return FAIL;
1473 }
1474
1475 if (vectype)
1476 *vectype = atype.eltype;
1477
1478 *ccp = str;
1479
1480 return reg;
1481 }
1482
1483 #define NEON_SCALAR_REG(X) ((X) >> 4)
1484 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1485
1486 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1487 have enough information to be able to do a good job bounds-checking. So, we
1488 just do easy checks here, and do further checks later. */
1489
1490 static int
1491 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1492 {
1493 int reg;
1494 char *str = *ccp;
1495 struct neon_typed_alias atype;
1496
1497 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1498
1499 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1500 return FAIL;
1501
1502 if (atype.index == NEON_ALL_LANES)
1503 {
1504 first_error (_("scalar must have an index"));
1505 return FAIL;
1506 }
1507 else if (atype.index >= 64 / elsize)
1508 {
1509 first_error (_("scalar index out of range"));
1510 return FAIL;
1511 }
1512
1513 if (type)
1514 *type = atype.eltype;
1515
1516 *ccp = str;
1517
1518 return reg * 16 + atype.index;
1519 }
1520
1521 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1522
1523 static long
1524 parse_reg_list (char ** strp)
1525 {
1526 char * str = * strp;
1527 long range = 0;
1528 int another_range;
1529
1530 /* We come back here if we get ranges concatenated by '+' or '|'. */
1531 do
1532 {
1533 another_range = 0;
1534
1535 if (*str == '{')
1536 {
1537 int in_range = 0;
1538 int cur_reg = -1;
1539
1540 str++;
1541 do
1542 {
1543 int reg;
1544
1545 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1546 {
1547 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1548 return FAIL;
1549 }
1550
1551 if (in_range)
1552 {
1553 int i;
1554
1555 if (reg <= cur_reg)
1556 {
1557 first_error (_("bad range in register list"));
1558 return FAIL;
1559 }
1560
1561 for (i = cur_reg + 1; i < reg; i++)
1562 {
1563 if (range & (1 << i))
1564 as_tsktsk
1565 (_("Warning: duplicated register (r%d) in register list"),
1566 i);
1567 else
1568 range |= 1 << i;
1569 }
1570 in_range = 0;
1571 }
1572
1573 if (range & (1 << reg))
1574 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1575 reg);
1576 else if (reg <= cur_reg)
1577 as_tsktsk (_("Warning: register range not in ascending order"));
1578
1579 range |= 1 << reg;
1580 cur_reg = reg;
1581 }
1582 while (skip_past_comma (&str) != FAIL
1583 || (in_range = 1, *str++ == '-'));
1584 str--;
1585
1586 if (*str++ != '}')
1587 {
1588 first_error (_("missing `}'"));
1589 return FAIL;
1590 }
1591 }
1592 else
1593 {
1594 expressionS exp;
1595
1596 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1597 return FAIL;
1598
1599 if (exp.X_op == O_constant)
1600 {
1601 if (exp.X_add_number
1602 != (exp.X_add_number & 0x0000ffff))
1603 {
1604 inst.error = _("invalid register mask");
1605 return FAIL;
1606 }
1607
1608 if ((range & exp.X_add_number) != 0)
1609 {
1610 int regno = range & exp.X_add_number;
1611
1612 regno &= -regno;
1613 regno = (1 << regno) - 1;
1614 as_tsktsk
1615 (_("Warning: duplicated register (r%d) in register list"),
1616 regno);
1617 }
1618
1619 range |= exp.X_add_number;
1620 }
1621 else
1622 {
1623 if (inst.reloc.type != 0)
1624 {
1625 inst.error = _("expression too complex");
1626 return FAIL;
1627 }
1628
1629 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1630 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1631 inst.reloc.pc_rel = 0;
1632 }
1633 }
1634
1635 if (*str == '|' || *str == '+')
1636 {
1637 str++;
1638 another_range = 1;
1639 }
1640 }
1641 while (another_range);
1642
1643 *strp = str;
1644 return range;
1645 }
1646
1647 /* Types of registers in a list. */
1648
1649 enum reg_list_els
1650 {
1651 REGLIST_VFP_S,
1652 REGLIST_VFP_D,
1653 REGLIST_NEON_D
1654 };
1655
1656 /* Parse a VFP register list. If the string is invalid return FAIL.
1657 Otherwise return the number of registers, and set PBASE to the first
1658 register. Parses registers of type ETYPE.
1659 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1660 - Q registers can be used to specify pairs of D registers
1661 - { } can be omitted from around a singleton register list
1662 FIXME: This is not implemented, as it would require backtracking in
1663 some cases, e.g.:
1664 vtbl.8 d3,d4,d5
1665 This could be done (the meaning isn't really ambiguous), but doesn't
1666 fit in well with the current parsing framework.
1667 - 32 D registers may be used (also true for VFPv3).
1668 FIXME: Types are ignored in these register lists, which is probably a
1669 bug. */
1670
1671 static int
1672 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1673 {
1674 char *str = *ccp;
1675 int base_reg;
1676 int new_base;
1677 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1678 int max_regs = 0;
1679 int count = 0;
1680 int warned = 0;
1681 unsigned long mask = 0;
1682 int i;
1683
1684 if (*str != '{')
1685 {
1686 inst.error = _("expecting {");
1687 return FAIL;
1688 }
1689
1690 str++;
1691
1692 switch (etype)
1693 {
1694 case REGLIST_VFP_S:
1695 regtype = REG_TYPE_VFS;
1696 max_regs = 32;
1697 break;
1698
1699 case REGLIST_VFP_D:
1700 regtype = REG_TYPE_VFD;
1701 break;
1702
1703 case REGLIST_NEON_D:
1704 regtype = REG_TYPE_NDQ;
1705 break;
1706 }
1707
1708 if (etype != REGLIST_VFP_S)
1709 {
1710 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1711 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1712 {
1713 max_regs = 32;
1714 if (thumb_mode)
1715 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1716 fpu_vfp_ext_d32);
1717 else
1718 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1719 fpu_vfp_ext_d32);
1720 }
1721 else
1722 max_regs = 16;
1723 }
1724
1725 base_reg = max_regs;
1726
1727 do
1728 {
1729 int setmask = 1, addregs = 1;
1730
1731 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1732
1733 if (new_base == FAIL)
1734 {
1735 first_error (_(reg_expected_msgs[regtype]));
1736 return FAIL;
1737 }
1738
1739 if (new_base >= max_regs)
1740 {
1741 first_error (_("register out of range in list"));
1742 return FAIL;
1743 }
1744
1745 /* Note: a value of 2 * n is returned for the register Q<n>. */
1746 if (regtype == REG_TYPE_NQ)
1747 {
1748 setmask = 3;
1749 addregs = 2;
1750 }
1751
1752 if (new_base < base_reg)
1753 base_reg = new_base;
1754
1755 if (mask & (setmask << new_base))
1756 {
1757 first_error (_("invalid register list"));
1758 return FAIL;
1759 }
1760
1761 if ((mask >> new_base) != 0 && ! warned)
1762 {
1763 as_tsktsk (_("register list not in ascending order"));
1764 warned = 1;
1765 }
1766
1767 mask |= setmask << new_base;
1768 count += addregs;
1769
1770 if (*str == '-') /* We have the start of a range expression */
1771 {
1772 int high_range;
1773
1774 str++;
1775
1776 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1777 == FAIL)
1778 {
1779 inst.error = gettext (reg_expected_msgs[regtype]);
1780 return FAIL;
1781 }
1782
1783 if (high_range >= max_regs)
1784 {
1785 first_error (_("register out of range in list"));
1786 return FAIL;
1787 }
1788
1789 if (regtype == REG_TYPE_NQ)
1790 high_range = high_range + 1;
1791
1792 if (high_range <= new_base)
1793 {
1794 inst.error = _("register range not in ascending order");
1795 return FAIL;
1796 }
1797
1798 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1799 {
1800 if (mask & (setmask << new_base))
1801 {
1802 inst.error = _("invalid register list");
1803 return FAIL;
1804 }
1805
1806 mask |= setmask << new_base;
1807 count += addregs;
1808 }
1809 }
1810 }
1811 while (skip_past_comma (&str) != FAIL);
1812
1813 str++;
1814
1815 /* Sanity check -- should have raised a parse error above. */
1816 if (count == 0 || count > max_regs)
1817 abort ();
1818
1819 *pbase = base_reg;
1820
1821 /* Final test -- the registers must be consecutive. */
1822 mask >>= base_reg;
1823 for (i = 0; i < count; i++)
1824 {
1825 if ((mask & (1u << i)) == 0)
1826 {
1827 inst.error = _("non-contiguous register range");
1828 return FAIL;
1829 }
1830 }
1831
1832 *ccp = str;
1833
1834 return count;
1835 }
1836
1837 /* True if two alias types are the same. */
1838
1839 static bfd_boolean
1840 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1841 {
1842 if (!a && !b)
1843 return TRUE;
1844
1845 if (!a || !b)
1846 return FALSE;
1847
1848 if (a->defined != b->defined)
1849 return FALSE;
1850
1851 if ((a->defined & NTA_HASTYPE) != 0
1852 && (a->eltype.type != b->eltype.type
1853 || a->eltype.size != b->eltype.size))
1854 return FALSE;
1855
1856 if ((a->defined & NTA_HASINDEX) != 0
1857 && (a->index != b->index))
1858 return FALSE;
1859
1860 return TRUE;
1861 }
1862
1863 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1864 The base register is put in *PBASE.
1865 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1866 the return value.
1867 The register stride (minus one) is put in bit 4 of the return value.
1868 Bits [6:5] encode the list length (minus one).
1869 The type of the list elements is put in *ELTYPE, if non-NULL. */
1870
1871 #define NEON_LANE(X) ((X) & 0xf)
1872 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1873 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1874
1875 static int
1876 parse_neon_el_struct_list (char **str, unsigned *pbase,
1877 struct neon_type_el *eltype)
1878 {
1879 char *ptr = *str;
1880 int base_reg = -1;
1881 int reg_incr = -1;
1882 int count = 0;
1883 int lane = -1;
1884 int leading_brace = 0;
1885 enum arm_reg_type rtype = REG_TYPE_NDQ;
1886 const char *const incr_error = _("register stride must be 1 or 2");
1887 const char *const type_error = _("mismatched element/structure types in list");
1888 struct neon_typed_alias firsttype;
1889
1890 if (skip_past_char (&ptr, '{') == SUCCESS)
1891 leading_brace = 1;
1892
1893 do
1894 {
1895 struct neon_typed_alias atype;
1896 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1897
1898 if (getreg == FAIL)
1899 {
1900 first_error (_(reg_expected_msgs[rtype]));
1901 return FAIL;
1902 }
1903
1904 if (base_reg == -1)
1905 {
1906 base_reg = getreg;
1907 if (rtype == REG_TYPE_NQ)
1908 {
1909 reg_incr = 1;
1910 }
1911 firsttype = atype;
1912 }
1913 else if (reg_incr == -1)
1914 {
1915 reg_incr = getreg - base_reg;
1916 if (reg_incr < 1 || reg_incr > 2)
1917 {
1918 first_error (_(incr_error));
1919 return FAIL;
1920 }
1921 }
1922 else if (getreg != base_reg + reg_incr * count)
1923 {
1924 first_error (_(incr_error));
1925 return FAIL;
1926 }
1927
1928 if (! neon_alias_types_same (&atype, &firsttype))
1929 {
1930 first_error (_(type_error));
1931 return FAIL;
1932 }
1933
1934 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1935 modes. */
1936 if (ptr[0] == '-')
1937 {
1938 struct neon_typed_alias htype;
1939 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1940 if (lane == -1)
1941 lane = NEON_INTERLEAVE_LANES;
1942 else if (lane != NEON_INTERLEAVE_LANES)
1943 {
1944 first_error (_(type_error));
1945 return FAIL;
1946 }
1947 if (reg_incr == -1)
1948 reg_incr = 1;
1949 else if (reg_incr != 1)
1950 {
1951 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1952 return FAIL;
1953 }
1954 ptr++;
1955 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1956 if (hireg == FAIL)
1957 {
1958 first_error (_(reg_expected_msgs[rtype]));
1959 return FAIL;
1960 }
1961 if (! neon_alias_types_same (&htype, &firsttype))
1962 {
1963 first_error (_(type_error));
1964 return FAIL;
1965 }
1966 count += hireg + dregs - getreg;
1967 continue;
1968 }
1969
1970 /* If we're using Q registers, we can't use [] or [n] syntax. */
1971 if (rtype == REG_TYPE_NQ)
1972 {
1973 count += 2;
1974 continue;
1975 }
1976
1977 if ((atype.defined & NTA_HASINDEX) != 0)
1978 {
1979 if (lane == -1)
1980 lane = atype.index;
1981 else if (lane != atype.index)
1982 {
1983 first_error (_(type_error));
1984 return FAIL;
1985 }
1986 }
1987 else if (lane == -1)
1988 lane = NEON_INTERLEAVE_LANES;
1989 else if (lane != NEON_INTERLEAVE_LANES)
1990 {
1991 first_error (_(type_error));
1992 return FAIL;
1993 }
1994 count++;
1995 }
1996 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1997
1998 /* No lane set by [x]. We must be interleaving structures. */
1999 if (lane == -1)
2000 lane = NEON_INTERLEAVE_LANES;
2001
2002 /* Sanity check. */
2003 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2004 || (count > 1 && reg_incr == -1))
2005 {
2006 first_error (_("error parsing element/structure list"));
2007 return FAIL;
2008 }
2009
2010 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2011 {
2012 first_error (_("expected }"));
2013 return FAIL;
2014 }
2015
2016 if (reg_incr == -1)
2017 reg_incr = 1;
2018
2019 if (eltype)
2020 *eltype = firsttype.eltype;
2021
2022 *pbase = base_reg;
2023 *str = ptr;
2024
2025 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2026 }
2027
2028 /* Parse an explicit relocation suffix on an expression. This is
2029 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2030 arm_reloc_hsh contains no entries, so this function can only
2031 succeed if there is no () after the word. Returns -1 on error,
2032 BFD_RELOC_UNUSED if there wasn't any suffix. */
2033 static int
2034 parse_reloc (char **str)
2035 {
2036 struct reloc_entry *r;
2037 char *p, *q;
2038
2039 if (**str != '(')
2040 return BFD_RELOC_UNUSED;
2041
2042 p = *str + 1;
2043 q = p;
2044
2045 while (*q && *q != ')' && *q != ',')
2046 q++;
2047 if (*q != ')')
2048 return -1;
2049
2050 if ((r = (struct reloc_entry *)
2051 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2052 return -1;
2053
2054 *str = q + 1;
2055 return r->reloc;
2056 }
2057
2058 /* Directives: register aliases. */
2059
2060 static struct reg_entry *
2061 insert_reg_alias (char *str, int number, int type)
2062 {
2063 struct reg_entry *new_reg;
2064 const char *name;
2065
2066 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2067 {
2068 if (new_reg->builtin)
2069 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2070
2071 /* Only warn about a redefinition if it's not defined as the
2072 same register. */
2073 else if (new_reg->number != number || new_reg->type != type)
2074 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2075
2076 return NULL;
2077 }
2078
2079 name = xstrdup (str);
2080 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2081
2082 new_reg->name = name;
2083 new_reg->number = number;
2084 new_reg->type = type;
2085 new_reg->builtin = FALSE;
2086 new_reg->neon = NULL;
2087
2088 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2089 abort ();
2090
2091 return new_reg;
2092 }
2093
2094 static void
2095 insert_neon_reg_alias (char *str, int number, int type,
2096 struct neon_typed_alias *atype)
2097 {
2098 struct reg_entry *reg = insert_reg_alias (str, number, type);
2099
2100 if (!reg)
2101 {
2102 first_error (_("attempt to redefine typed alias"));
2103 return;
2104 }
2105
2106 if (atype)
2107 {
2108 reg->neon = (struct neon_typed_alias *)
2109 xmalloc (sizeof (struct neon_typed_alias));
2110 *reg->neon = *atype;
2111 }
2112 }
2113
2114 /* Look for the .req directive. This is of the form:
2115
2116 new_register_name .req existing_register_name
2117
2118 If we find one, or if it looks sufficiently like one that we want to
2119 handle any error here, return TRUE. Otherwise return FALSE. */
2120
2121 static bfd_boolean
2122 create_register_alias (char * newname, char *p)
2123 {
2124 struct reg_entry *old;
2125 char *oldname, *nbuf;
2126 size_t nlen;
2127
2128 /* The input scrubber ensures that whitespace after the mnemonic is
2129 collapsed to single spaces. */
2130 oldname = p;
2131 if (strncmp (oldname, " .req ", 6) != 0)
2132 return FALSE;
2133
2134 oldname += 6;
2135 if (*oldname == '\0')
2136 return FALSE;
2137
2138 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2139 if (!old)
2140 {
2141 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2142 return TRUE;
2143 }
2144
2145 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2146 the desired alias name, and p points to its end. If not, then
2147 the desired alias name is in the global original_case_string. */
2148 #ifdef TC_CASE_SENSITIVE
2149 nlen = p - newname;
2150 #else
2151 newname = original_case_string;
2152 nlen = strlen (newname);
2153 #endif
2154
2155 nbuf = (char *) alloca (nlen + 1);
2156 memcpy (nbuf, newname, nlen);
2157 nbuf[nlen] = '\0';
2158
2159 /* Create aliases under the new name as stated; an all-lowercase
2160 version of the new name; and an all-uppercase version of the new
2161 name. */
2162 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2163 {
2164 for (p = nbuf; *p; p++)
2165 *p = TOUPPER (*p);
2166
2167 if (strncmp (nbuf, newname, nlen))
2168 {
2169 /* If this attempt to create an additional alias fails, do not bother
2170 trying to create the all-lower case alias. We will fail and issue
2171 a second, duplicate error message. This situation arises when the
2172 programmer does something like:
2173 foo .req r0
2174 Foo .req r1
2175 The second .req creates the "Foo" alias but then fails to create
2176 the artificial FOO alias because it has already been created by the
2177 first .req. */
2178 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2179 return TRUE;
2180 }
2181
2182 for (p = nbuf; *p; p++)
2183 *p = TOLOWER (*p);
2184
2185 if (strncmp (nbuf, newname, nlen))
2186 insert_reg_alias (nbuf, old->number, old->type);
2187 }
2188
2189 return TRUE;
2190 }
2191
2192 /* Create a Neon typed/indexed register alias using directives, e.g.:
2193 X .dn d5.s32[1]
2194 Y .qn 6.s16
2195 Z .dn d7
2196 T .dn Z[0]
2197 These typed registers can be used instead of the types specified after the
2198 Neon mnemonic, so long as all operands given have types. Types can also be
2199 specified directly, e.g.:
2200 vadd d0.s32, d1.s32, d2.s32 */
2201
2202 static bfd_boolean
2203 create_neon_reg_alias (char *newname, char *p)
2204 {
2205 enum arm_reg_type basetype;
2206 struct reg_entry *basereg;
2207 struct reg_entry mybasereg;
2208 struct neon_type ntype;
2209 struct neon_typed_alias typeinfo;
2210 char *namebuf, *nameend;
2211 int namelen;
2212
2213 typeinfo.defined = 0;
2214 typeinfo.eltype.type = NT_invtype;
2215 typeinfo.eltype.size = -1;
2216 typeinfo.index = -1;
2217
2218 nameend = p;
2219
2220 if (strncmp (p, " .dn ", 5) == 0)
2221 basetype = REG_TYPE_VFD;
2222 else if (strncmp (p, " .qn ", 5) == 0)
2223 basetype = REG_TYPE_NQ;
2224 else
2225 return FALSE;
2226
2227 p += 5;
2228
2229 if (*p == '\0')
2230 return FALSE;
2231
2232 basereg = arm_reg_parse_multi (&p);
2233
2234 if (basereg && basereg->type != basetype)
2235 {
2236 as_bad (_("bad type for register"));
2237 return FALSE;
2238 }
2239
2240 if (basereg == NULL)
2241 {
2242 expressionS exp;
2243 /* Try parsing as an integer. */
2244 my_get_expression (&exp, &p, GE_NO_PREFIX);
2245 if (exp.X_op != O_constant)
2246 {
2247 as_bad (_("expression must be constant"));
2248 return FALSE;
2249 }
2250 basereg = &mybasereg;
2251 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2252 : exp.X_add_number;
2253 basereg->neon = 0;
2254 }
2255
2256 if (basereg->neon)
2257 typeinfo = *basereg->neon;
2258
2259 if (parse_neon_type (&ntype, &p) == SUCCESS)
2260 {
2261 /* We got a type. */
2262 if (typeinfo.defined & NTA_HASTYPE)
2263 {
2264 as_bad (_("can't redefine the type of a register alias"));
2265 return FALSE;
2266 }
2267
2268 typeinfo.defined |= NTA_HASTYPE;
2269 if (ntype.elems != 1)
2270 {
2271 as_bad (_("you must specify a single type only"));
2272 return FALSE;
2273 }
2274 typeinfo.eltype = ntype.el[0];
2275 }
2276
2277 if (skip_past_char (&p, '[') == SUCCESS)
2278 {
2279 expressionS exp;
2280 /* We got a scalar index. */
2281
2282 if (typeinfo.defined & NTA_HASINDEX)
2283 {
2284 as_bad (_("can't redefine the index of a scalar alias"));
2285 return FALSE;
2286 }
2287
2288 my_get_expression (&exp, &p, GE_NO_PREFIX);
2289
2290 if (exp.X_op != O_constant)
2291 {
2292 as_bad (_("scalar index must be constant"));
2293 return FALSE;
2294 }
2295
2296 typeinfo.defined |= NTA_HASINDEX;
2297 typeinfo.index = exp.X_add_number;
2298
2299 if (skip_past_char (&p, ']') == FAIL)
2300 {
2301 as_bad (_("expecting ]"));
2302 return FALSE;
2303 }
2304 }
2305
2306 namelen = nameend - newname;
2307 namebuf = (char *) alloca (namelen + 1);
2308 strncpy (namebuf, newname, namelen);
2309 namebuf[namelen] = '\0';
2310
2311 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2312 typeinfo.defined != 0 ? &typeinfo : NULL);
2313
2314 /* Insert name in all uppercase. */
2315 for (p = namebuf; *p; p++)
2316 *p = TOUPPER (*p);
2317
2318 if (strncmp (namebuf, newname, namelen))
2319 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2320 typeinfo.defined != 0 ? &typeinfo : NULL);
2321
2322 /* Insert name in all lowercase. */
2323 for (p = namebuf; *p; p++)
2324 *p = TOLOWER (*p);
2325
2326 if (strncmp (namebuf, newname, namelen))
2327 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2328 typeinfo.defined != 0 ? &typeinfo : NULL);
2329
2330 return TRUE;
2331 }
2332
2333 /* Should never be called, as .req goes between the alias and the
2334 register name, not at the beginning of the line. */
2335
2336 static void
2337 s_req (int a ATTRIBUTE_UNUSED)
2338 {
2339 as_bad (_("invalid syntax for .req directive"));
2340 }
2341
2342 static void
2343 s_dn (int a ATTRIBUTE_UNUSED)
2344 {
2345 as_bad (_("invalid syntax for .dn directive"));
2346 }
2347
2348 static void
2349 s_qn (int a ATTRIBUTE_UNUSED)
2350 {
2351 as_bad (_("invalid syntax for .qn directive"));
2352 }
2353
2354 /* The .unreq directive deletes an alias which was previously defined
2355 by .req. For example:
2356
2357 my_alias .req r11
2358 .unreq my_alias */
2359
2360 static void
2361 s_unreq (int a ATTRIBUTE_UNUSED)
2362 {
2363 char * name;
2364 char saved_char;
2365
2366 name = input_line_pointer;
2367
2368 while (*input_line_pointer != 0
2369 && *input_line_pointer != ' '
2370 && *input_line_pointer != '\n')
2371 ++input_line_pointer;
2372
2373 saved_char = *input_line_pointer;
2374 *input_line_pointer = 0;
2375
2376 if (!*name)
2377 as_bad (_("invalid syntax for .unreq directive"));
2378 else
2379 {
2380 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2381 name);
2382
2383 if (!reg)
2384 as_bad (_("unknown register alias '%s'"), name);
2385 else if (reg->builtin)
2386 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2387 name);
2388 else
2389 {
2390 char * p;
2391 char * nbuf;
2392
2393 hash_delete (arm_reg_hsh, name, FALSE);
2394 free ((char *) reg->name);
2395 if (reg->neon)
2396 free (reg->neon);
2397 free (reg);
2398
2399 /* Also locate the all upper case and all lower case versions.
2400 Do not complain if we cannot find one or the other as it
2401 was probably deleted above. */
2402
2403 nbuf = strdup (name);
2404 for (p = nbuf; *p; p++)
2405 *p = TOUPPER (*p);
2406 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2407 if (reg)
2408 {
2409 hash_delete (arm_reg_hsh, nbuf, FALSE);
2410 free ((char *) reg->name);
2411 if (reg->neon)
2412 free (reg->neon);
2413 free (reg);
2414 }
2415
2416 for (p = nbuf; *p; p++)
2417 *p = TOLOWER (*p);
2418 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2419 if (reg)
2420 {
2421 hash_delete (arm_reg_hsh, nbuf, FALSE);
2422 free ((char *) reg->name);
2423 if (reg->neon)
2424 free (reg->neon);
2425 free (reg);
2426 }
2427
2428 free (nbuf);
2429 }
2430 }
2431
2432 *input_line_pointer = saved_char;
2433 demand_empty_rest_of_line ();
2434 }
2435
2436 /* Directives: Instruction set selection. */
2437
2438 #ifdef OBJ_ELF
2439 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2440 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2441 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2442 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2443
2444 /* Create a new mapping symbol for the transition to STATE. */
2445
2446 static void
2447 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2448 {
2449 symbolS * symbolP;
2450 const char * symname;
2451 int type;
2452
2453 switch (state)
2454 {
2455 case MAP_DATA:
2456 symname = "$d";
2457 type = BSF_NO_FLAGS;
2458 break;
2459 case MAP_ARM:
2460 symname = "$a";
2461 type = BSF_NO_FLAGS;
2462 break;
2463 case MAP_THUMB:
2464 symname = "$t";
2465 type = BSF_NO_FLAGS;
2466 break;
2467 default:
2468 abort ();
2469 }
2470
2471 symbolP = symbol_new (symname, now_seg, value, frag);
2472 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2473
2474 switch (state)
2475 {
2476 case MAP_ARM:
2477 THUMB_SET_FUNC (symbolP, 0);
2478 ARM_SET_THUMB (symbolP, 0);
2479 ARM_SET_INTERWORK (symbolP, support_interwork);
2480 break;
2481
2482 case MAP_THUMB:
2483 THUMB_SET_FUNC (symbolP, 1);
2484 ARM_SET_THUMB (symbolP, 1);
2485 ARM_SET_INTERWORK (symbolP, support_interwork);
2486 break;
2487
2488 case MAP_DATA:
2489 default:
2490 break;
2491 }
2492
2493 /* Save the mapping symbols for future reference. Also check that
2494 we do not place two mapping symbols at the same offset within a
2495 frag. We'll handle overlap between frags in
2496 check_mapping_symbols.
2497
2498 If .fill or other data filling directive generates zero sized data,
2499 the mapping symbol for the following code will have the same value
2500 as the one generated for the data filling directive. In this case,
2501 we replace the old symbol with the new one at the same address. */
2502 if (value == 0)
2503 {
2504 if (frag->tc_frag_data.first_map != NULL)
2505 {
2506 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2507 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2508 }
2509 frag->tc_frag_data.first_map = symbolP;
2510 }
2511 if (frag->tc_frag_data.last_map != NULL)
2512 {
2513 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2514 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2515 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2516 }
2517 frag->tc_frag_data.last_map = symbolP;
2518 }
2519
2520 /* We must sometimes convert a region marked as code to data during
2521 code alignment, if an odd number of bytes have to be padded. The
2522 code mapping symbol is pushed to an aligned address. */
2523
2524 static void
2525 insert_data_mapping_symbol (enum mstate state,
2526 valueT value, fragS *frag, offsetT bytes)
2527 {
2528 /* If there was already a mapping symbol, remove it. */
2529 if (frag->tc_frag_data.last_map != NULL
2530 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2531 {
2532 symbolS *symp = frag->tc_frag_data.last_map;
2533
2534 if (value == 0)
2535 {
2536 know (frag->tc_frag_data.first_map == symp);
2537 frag->tc_frag_data.first_map = NULL;
2538 }
2539 frag->tc_frag_data.last_map = NULL;
2540 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2541 }
2542
2543 make_mapping_symbol (MAP_DATA, value, frag);
2544 make_mapping_symbol (state, value + bytes, frag);
2545 }
2546
2547 static void mapping_state_2 (enum mstate state, int max_chars);
2548
2549 /* Set the mapping state to STATE. Only call this when about to
2550 emit some STATE bytes to the file. */
2551
2552 void
2553 mapping_state (enum mstate state)
2554 {
2555 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2556
2557 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2558
2559 if (mapstate == state)
2560 /* The mapping symbol has already been emitted.
2561 There is nothing else to do. */
2562 return;
2563 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2564 /* This case will be evaluated later in the next else. */
2565 return;
2566 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2567 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2568 {
2569 /* Only add the symbol if the offset is > 0:
2570 if we're at the first frag, check it's size > 0;
2571 if we're not at the first frag, then for sure
2572 the offset is > 0. */
2573 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2574 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2575
2576 if (add_symbol)
2577 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2578 }
2579
2580 mapping_state_2 (state, 0);
2581 #undef TRANSITION
2582 }
2583
2584 /* Same as mapping_state, but MAX_CHARS bytes have already been
2585 allocated. Put the mapping symbol that far back. */
2586
2587 static void
2588 mapping_state_2 (enum mstate state, int max_chars)
2589 {
2590 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2591
2592 if (!SEG_NORMAL (now_seg))
2593 return;
2594
2595 if (mapstate == state)
2596 /* The mapping symbol has already been emitted.
2597 There is nothing else to do. */
2598 return;
2599
2600 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2601 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2602 }
2603 #else
2604 #define mapping_state(x) ((void)0)
2605 #define mapping_state_2(x, y) ((void)0)
2606 #endif
2607
2608 /* Find the real, Thumb encoded start of a Thumb function. */
2609
2610 #ifdef OBJ_COFF
2611 static symbolS *
2612 find_real_start (symbolS * symbolP)
2613 {
2614 char * real_start;
2615 const char * name = S_GET_NAME (symbolP);
2616 symbolS * new_target;
2617
2618 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2619 #define STUB_NAME ".real_start_of"
2620
2621 if (name == NULL)
2622 abort ();
2623
2624 /* The compiler may generate BL instructions to local labels because
2625 it needs to perform a branch to a far away location. These labels
2626 do not have a corresponding ".real_start_of" label. We check
2627 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2628 the ".real_start_of" convention for nonlocal branches. */
2629 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2630 return symbolP;
2631
2632 real_start = ACONCAT ((STUB_NAME, name, NULL));
2633 new_target = symbol_find (real_start);
2634
2635 if (new_target == NULL)
2636 {
2637 as_warn (_("Failed to find real start of function: %s\n"), name);
2638 new_target = symbolP;
2639 }
2640
2641 return new_target;
2642 }
2643 #endif
2644
2645 static void
2646 opcode_select (int width)
2647 {
2648 switch (width)
2649 {
2650 case 16:
2651 if (! thumb_mode)
2652 {
2653 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2654 as_bad (_("selected processor does not support THUMB opcodes"));
2655
2656 thumb_mode = 1;
2657 /* No need to force the alignment, since we will have been
2658 coming from ARM mode, which is word-aligned. */
2659 record_alignment (now_seg, 1);
2660 }
2661 break;
2662
2663 case 32:
2664 if (thumb_mode)
2665 {
2666 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2667 as_bad (_("selected processor does not support ARM opcodes"));
2668
2669 thumb_mode = 0;
2670
2671 if (!need_pass_2)
2672 frag_align (2, 0, 0);
2673
2674 record_alignment (now_seg, 1);
2675 }
2676 break;
2677
2678 default:
2679 as_bad (_("invalid instruction size selected (%d)"), width);
2680 }
2681 }
2682
2683 static void
2684 s_arm (int ignore ATTRIBUTE_UNUSED)
2685 {
2686 opcode_select (32);
2687 demand_empty_rest_of_line ();
2688 }
2689
2690 static void
2691 s_thumb (int ignore ATTRIBUTE_UNUSED)
2692 {
2693 opcode_select (16);
2694 demand_empty_rest_of_line ();
2695 }
2696
2697 static void
2698 s_code (int unused ATTRIBUTE_UNUSED)
2699 {
2700 int temp;
2701
2702 temp = get_absolute_expression ();
2703 switch (temp)
2704 {
2705 case 16:
2706 case 32:
2707 opcode_select (temp);
2708 break;
2709
2710 default:
2711 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2712 }
2713 }
2714
2715 static void
2716 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2717 {
2718 /* If we are not already in thumb mode go into it, EVEN if
2719 the target processor does not support thumb instructions.
2720 This is used by gcc/config/arm/lib1funcs.asm for example
2721 to compile interworking support functions even if the
2722 target processor should not support interworking. */
2723 if (! thumb_mode)
2724 {
2725 thumb_mode = 2;
2726 record_alignment (now_seg, 1);
2727 }
2728
2729 demand_empty_rest_of_line ();
2730 }
2731
2732 static void
2733 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2734 {
2735 s_thumb (0);
2736
2737 /* The following label is the name/address of the start of a Thumb function.
2738 We need to know this for the interworking support. */
2739 label_is_thumb_function_name = TRUE;
2740 }
2741
2742 /* Perform a .set directive, but also mark the alias as
2743 being a thumb function. */
2744
2745 static void
2746 s_thumb_set (int equiv)
2747 {
2748 /* XXX the following is a duplicate of the code for s_set() in read.c
2749 We cannot just call that code as we need to get at the symbol that
2750 is created. */
2751 char * name;
2752 char delim;
2753 char * end_name;
2754 symbolS * symbolP;
2755
2756 /* Especial apologies for the random logic:
2757 This just grew, and could be parsed much more simply!
2758 Dean - in haste. */
2759 name = input_line_pointer;
2760 delim = get_symbol_end ();
2761 end_name = input_line_pointer;
2762 *end_name = delim;
2763
2764 if (*input_line_pointer != ',')
2765 {
2766 *end_name = 0;
2767 as_bad (_("expected comma after name \"%s\""), name);
2768 *end_name = delim;
2769 ignore_rest_of_line ();
2770 return;
2771 }
2772
2773 input_line_pointer++;
2774 *end_name = 0;
2775
2776 if (name[0] == '.' && name[1] == '\0')
2777 {
2778 /* XXX - this should not happen to .thumb_set. */
2779 abort ();
2780 }
2781
2782 if ((symbolP = symbol_find (name)) == NULL
2783 && (symbolP = md_undefined_symbol (name)) == NULL)
2784 {
2785 #ifndef NO_LISTING
2786 /* When doing symbol listings, play games with dummy fragments living
2787 outside the normal fragment chain to record the file and line info
2788 for this symbol. */
2789 if (listing & LISTING_SYMBOLS)
2790 {
2791 extern struct list_info_struct * listing_tail;
2792 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2793
2794 memset (dummy_frag, 0, sizeof (fragS));
2795 dummy_frag->fr_type = rs_fill;
2796 dummy_frag->line = listing_tail;
2797 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2798 dummy_frag->fr_symbol = symbolP;
2799 }
2800 else
2801 #endif
2802 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2803
2804 #ifdef OBJ_COFF
2805 /* "set" symbols are local unless otherwise specified. */
2806 SF_SET_LOCAL (symbolP);
2807 #endif /* OBJ_COFF */
2808 } /* Make a new symbol. */
2809
2810 symbol_table_insert (symbolP);
2811
2812 * end_name = delim;
2813
2814 if (equiv
2815 && S_IS_DEFINED (symbolP)
2816 && S_GET_SEGMENT (symbolP) != reg_section)
2817 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2818
2819 pseudo_set (symbolP);
2820
2821 demand_empty_rest_of_line ();
2822
2823 /* XXX Now we come to the Thumb specific bit of code. */
2824
2825 THUMB_SET_FUNC (symbolP, 1);
2826 ARM_SET_THUMB (symbolP, 1);
2827 #if defined OBJ_ELF || defined OBJ_COFF
2828 ARM_SET_INTERWORK (symbolP, support_interwork);
2829 #endif
2830 }
2831
2832 /* Directives: Mode selection. */
2833
2834 /* .syntax [unified|divided] - choose the new unified syntax
2835 (same for Arm and Thumb encoding, modulo slight differences in what
2836 can be represented) or the old divergent syntax for each mode. */
2837 static void
2838 s_syntax (int unused ATTRIBUTE_UNUSED)
2839 {
2840 char *name, delim;
2841
2842 name = input_line_pointer;
2843 delim = get_symbol_end ();
2844
2845 if (!strcasecmp (name, "unified"))
2846 unified_syntax = TRUE;
2847 else if (!strcasecmp (name, "divided"))
2848 unified_syntax = FALSE;
2849 else
2850 {
2851 as_bad (_("unrecognized syntax mode \"%s\""), name);
2852 return;
2853 }
2854 *input_line_pointer = delim;
2855 demand_empty_rest_of_line ();
2856 }
2857
2858 /* Directives: sectioning and alignment. */
2859
2860 /* Same as s_align_ptwo but align 0 => align 2. */
2861
2862 static void
2863 s_align (int unused ATTRIBUTE_UNUSED)
2864 {
2865 int temp;
2866 bfd_boolean fill_p;
2867 long temp_fill;
2868 long max_alignment = 15;
2869
2870 temp = get_absolute_expression ();
2871 if (temp > max_alignment)
2872 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2873 else if (temp < 0)
2874 {
2875 as_bad (_("alignment negative. 0 assumed."));
2876 temp = 0;
2877 }
2878
2879 if (*input_line_pointer == ',')
2880 {
2881 input_line_pointer++;
2882 temp_fill = get_absolute_expression ();
2883 fill_p = TRUE;
2884 }
2885 else
2886 {
2887 fill_p = FALSE;
2888 temp_fill = 0;
2889 }
2890
2891 if (!temp)
2892 temp = 2;
2893
2894 /* Only make a frag if we HAVE to. */
2895 if (temp && !need_pass_2)
2896 {
2897 if (!fill_p && subseg_text_p (now_seg))
2898 frag_align_code (temp, 0);
2899 else
2900 frag_align (temp, (int) temp_fill, 0);
2901 }
2902 demand_empty_rest_of_line ();
2903
2904 record_alignment (now_seg, temp);
2905 }
2906
2907 static void
2908 s_bss (int ignore ATTRIBUTE_UNUSED)
2909 {
2910 /* We don't support putting frags in the BSS segment, we fake it by
2911 marking in_bss, then looking at s_skip for clues. */
2912 subseg_set (bss_section, 0);
2913 demand_empty_rest_of_line ();
2914
2915 #ifdef md_elf_section_change_hook
2916 md_elf_section_change_hook ();
2917 #endif
2918 }
2919
2920 static void
2921 s_even (int ignore ATTRIBUTE_UNUSED)
2922 {
2923 /* Never make frag if expect extra pass. */
2924 if (!need_pass_2)
2925 frag_align (1, 0, 0);
2926
2927 record_alignment (now_seg, 1);
2928
2929 demand_empty_rest_of_line ();
2930 }
2931
2932 /* Directives: Literal pools. */
2933
2934 static literal_pool *
2935 find_literal_pool (void)
2936 {
2937 literal_pool * pool;
2938
2939 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2940 {
2941 if (pool->section == now_seg
2942 && pool->sub_section == now_subseg)
2943 break;
2944 }
2945
2946 return pool;
2947 }
2948
2949 static literal_pool *
2950 find_or_make_literal_pool (void)
2951 {
2952 /* Next literal pool ID number. */
2953 static unsigned int latest_pool_num = 1;
2954 literal_pool * pool;
2955
2956 pool = find_literal_pool ();
2957
2958 if (pool == NULL)
2959 {
2960 /* Create a new pool. */
2961 pool = (literal_pool *) xmalloc (sizeof (* pool));
2962 if (! pool)
2963 return NULL;
2964
2965 pool->next_free_entry = 0;
2966 pool->section = now_seg;
2967 pool->sub_section = now_subseg;
2968 pool->next = list_of_pools;
2969 pool->symbol = NULL;
2970
2971 /* Add it to the list. */
2972 list_of_pools = pool;
2973 }
2974
2975 /* New pools, and emptied pools, will have a NULL symbol. */
2976 if (pool->symbol == NULL)
2977 {
2978 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2979 (valueT) 0, &zero_address_frag);
2980 pool->id = latest_pool_num ++;
2981 }
2982
2983 /* Done. */
2984 return pool;
2985 }
2986
2987 /* Add the literal in the global 'inst'
2988 structure to the relevant literal pool. */
2989
2990 static int
2991 add_to_lit_pool (void)
2992 {
2993 literal_pool * pool;
2994 unsigned int entry;
2995
2996 pool = find_or_make_literal_pool ();
2997
2998 /* Check if this literal value is already in the pool. */
2999 for (entry = 0; entry < pool->next_free_entry; entry ++)
3000 {
3001 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3002 && (inst.reloc.exp.X_op == O_constant)
3003 && (pool->literals[entry].X_add_number
3004 == inst.reloc.exp.X_add_number)
3005 && (pool->literals[entry].X_unsigned
3006 == inst.reloc.exp.X_unsigned))
3007 break;
3008
3009 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3010 && (inst.reloc.exp.X_op == O_symbol)
3011 && (pool->literals[entry].X_add_number
3012 == inst.reloc.exp.X_add_number)
3013 && (pool->literals[entry].X_add_symbol
3014 == inst.reloc.exp.X_add_symbol)
3015 && (pool->literals[entry].X_op_symbol
3016 == inst.reloc.exp.X_op_symbol))
3017 break;
3018 }
3019
3020 /* Do we need to create a new entry? */
3021 if (entry == pool->next_free_entry)
3022 {
3023 if (entry >= MAX_LITERAL_POOL_SIZE)
3024 {
3025 inst.error = _("literal pool overflow");
3026 return FAIL;
3027 }
3028
3029 pool->literals[entry] = inst.reloc.exp;
3030 pool->next_free_entry += 1;
3031 }
3032
3033 inst.reloc.exp.X_op = O_symbol;
3034 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3035 inst.reloc.exp.X_add_symbol = pool->symbol;
3036
3037 return SUCCESS;
3038 }
3039
3040 /* Can't use symbol_new here, so have to create a symbol and then at
3041 a later date assign it a value. Thats what these functions do. */
3042
3043 static void
3044 symbol_locate (symbolS * symbolP,
3045 const char * name, /* It is copied, the caller can modify. */
3046 segT segment, /* Segment identifier (SEG_<something>). */
3047 valueT valu, /* Symbol value. */
3048 fragS * frag) /* Associated fragment. */
3049 {
3050 unsigned int name_length;
3051 char * preserved_copy_of_name;
3052
3053 name_length = strlen (name) + 1; /* +1 for \0. */
3054 obstack_grow (&notes, name, name_length);
3055 preserved_copy_of_name = (char *) obstack_finish (&notes);
3056
3057 #ifdef tc_canonicalize_symbol_name
3058 preserved_copy_of_name =
3059 tc_canonicalize_symbol_name (preserved_copy_of_name);
3060 #endif
3061
3062 S_SET_NAME (symbolP, preserved_copy_of_name);
3063
3064 S_SET_SEGMENT (symbolP, segment);
3065 S_SET_VALUE (symbolP, valu);
3066 symbol_clear_list_pointers (symbolP);
3067
3068 symbol_set_frag (symbolP, frag);
3069
3070 /* Link to end of symbol chain. */
3071 {
3072 extern int symbol_table_frozen;
3073
3074 if (symbol_table_frozen)
3075 abort ();
3076 }
3077
3078 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3079
3080 obj_symbol_new_hook (symbolP);
3081
3082 #ifdef tc_symbol_new_hook
3083 tc_symbol_new_hook (symbolP);
3084 #endif
3085
3086 #ifdef DEBUG_SYMS
3087 verify_symbol_chain (symbol_rootP, symbol_lastP);
3088 #endif /* DEBUG_SYMS */
3089 }
3090
3091
3092 static void
3093 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3094 {
3095 unsigned int entry;
3096 literal_pool * pool;
3097 char sym_name[20];
3098
3099 pool = find_literal_pool ();
3100 if (pool == NULL
3101 || pool->symbol == NULL
3102 || pool->next_free_entry == 0)
3103 return;
3104
3105 mapping_state (MAP_DATA);
3106
3107 /* Align pool as you have word accesses.
3108 Only make a frag if we have to. */
3109 if (!need_pass_2)
3110 frag_align (2, 0, 0);
3111
3112 record_alignment (now_seg, 2);
3113
3114 sprintf (sym_name, "$$lit_\002%x", pool->id);
3115
3116 symbol_locate (pool->symbol, sym_name, now_seg,
3117 (valueT) frag_now_fix (), frag_now);
3118 symbol_table_insert (pool->symbol);
3119
3120 ARM_SET_THUMB (pool->symbol, thumb_mode);
3121
3122 #if defined OBJ_COFF || defined OBJ_ELF
3123 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3124 #endif
3125
3126 for (entry = 0; entry < pool->next_free_entry; entry ++)
3127 /* First output the expression in the instruction to the pool. */
3128 emit_expr (&(pool->literals[entry]), 4); /* .word */
3129
3130 /* Mark the pool as empty. */
3131 pool->next_free_entry = 0;
3132 pool->symbol = NULL;
3133 }
3134
3135 #ifdef OBJ_ELF
3136 /* Forward declarations for functions below, in the MD interface
3137 section. */
3138 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3139 static valueT create_unwind_entry (int);
3140 static void start_unwind_section (const segT, int);
3141 static void add_unwind_opcode (valueT, int);
3142 static void flush_pending_unwind (void);
3143
3144 /* Directives: Data. */
3145
3146 static void
3147 s_arm_elf_cons (int nbytes)
3148 {
3149 expressionS exp;
3150
3151 #ifdef md_flush_pending_output
3152 md_flush_pending_output ();
3153 #endif
3154
3155 if (is_it_end_of_statement ())
3156 {
3157 demand_empty_rest_of_line ();
3158 return;
3159 }
3160
3161 #ifdef md_cons_align
3162 md_cons_align (nbytes);
3163 #endif
3164
3165 mapping_state (MAP_DATA);
3166 do
3167 {
3168 int reloc;
3169 char *base = input_line_pointer;
3170
3171 expression (& exp);
3172
3173 if (exp.X_op != O_symbol)
3174 emit_expr (&exp, (unsigned int) nbytes);
3175 else
3176 {
3177 char *before_reloc = input_line_pointer;
3178 reloc = parse_reloc (&input_line_pointer);
3179 if (reloc == -1)
3180 {
3181 as_bad (_("unrecognized relocation suffix"));
3182 ignore_rest_of_line ();
3183 return;
3184 }
3185 else if (reloc == BFD_RELOC_UNUSED)
3186 emit_expr (&exp, (unsigned int) nbytes);
3187 else
3188 {
3189 reloc_howto_type *howto = (reloc_howto_type *)
3190 bfd_reloc_type_lookup (stdoutput,
3191 (bfd_reloc_code_real_type) reloc);
3192 int size = bfd_get_reloc_size (howto);
3193
3194 if (reloc == BFD_RELOC_ARM_PLT32)
3195 {
3196 as_bad (_("(plt) is only valid on branch targets"));
3197 reloc = BFD_RELOC_UNUSED;
3198 size = 0;
3199 }
3200
3201 if (size > nbytes)
3202 as_bad (_("%s relocations do not fit in %d bytes"),
3203 howto->name, nbytes);
3204 else
3205 {
3206 /* We've parsed an expression stopping at O_symbol.
3207 But there may be more expression left now that we
3208 have parsed the relocation marker. Parse it again.
3209 XXX Surely there is a cleaner way to do this. */
3210 char *p = input_line_pointer;
3211 int offset;
3212 char *save_buf = (char *) alloca (input_line_pointer - base);
3213 memcpy (save_buf, base, input_line_pointer - base);
3214 memmove (base + (input_line_pointer - before_reloc),
3215 base, before_reloc - base);
3216
3217 input_line_pointer = base + (input_line_pointer-before_reloc);
3218 expression (&exp);
3219 memcpy (base, save_buf, p - base);
3220
3221 offset = nbytes - size;
3222 p = frag_more ((int) nbytes);
3223 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3224 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3225 }
3226 }
3227 }
3228 }
3229 while (*input_line_pointer++ == ',');
3230
3231 /* Put terminator back into stream. */
3232 input_line_pointer --;
3233 demand_empty_rest_of_line ();
3234 }
3235
3236 /* Emit an expression containing a 32-bit thumb instruction.
3237 Implementation based on put_thumb32_insn. */
3238
3239 static void
3240 emit_thumb32_expr (expressionS * exp)
3241 {
3242 expressionS exp_high = *exp;
3243
3244 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3245 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3246 exp->X_add_number &= 0xffff;
3247 emit_expr (exp, (unsigned int) THUMB_SIZE);
3248 }
3249
3250 /* Guess the instruction size based on the opcode. */
3251
3252 static int
3253 thumb_insn_size (int opcode)
3254 {
3255 if ((unsigned int) opcode < 0xe800u)
3256 return 2;
3257 else if ((unsigned int) opcode >= 0xe8000000u)
3258 return 4;
3259 else
3260 return 0;
3261 }
3262
3263 static bfd_boolean
3264 emit_insn (expressionS *exp, int nbytes)
3265 {
3266 int size = 0;
3267
3268 if (exp->X_op == O_constant)
3269 {
3270 size = nbytes;
3271
3272 if (size == 0)
3273 size = thumb_insn_size (exp->X_add_number);
3274
3275 if (size != 0)
3276 {
3277 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3278 {
3279 as_bad (_(".inst.n operand too big. "\
3280 "Use .inst.w instead"));
3281 size = 0;
3282 }
3283 else
3284 {
3285 if (now_it.state == AUTOMATIC_IT_BLOCK)
3286 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3287 else
3288 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3289
3290 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3291 emit_thumb32_expr (exp);
3292 else
3293 emit_expr (exp, (unsigned int) size);
3294
3295 it_fsm_post_encode ();
3296 }
3297 }
3298 else
3299 as_bad (_("cannot determine Thumb instruction size. " \
3300 "Use .inst.n/.inst.w instead"));
3301 }
3302 else
3303 as_bad (_("constant expression required"));
3304
3305 return (size != 0);
3306 }
3307
3308 /* Like s_arm_elf_cons but do not use md_cons_align and
3309 set the mapping state to MAP_ARM/MAP_THUMB. */
3310
3311 static void
3312 s_arm_elf_inst (int nbytes)
3313 {
3314 if (is_it_end_of_statement ())
3315 {
3316 demand_empty_rest_of_line ();
3317 return;
3318 }
3319
3320 /* Calling mapping_state () here will not change ARM/THUMB,
3321 but will ensure not to be in DATA state. */
3322
3323 if (thumb_mode)
3324 mapping_state (MAP_THUMB);
3325 else
3326 {
3327 if (nbytes != 0)
3328 {
3329 as_bad (_("width suffixes are invalid in ARM mode"));
3330 ignore_rest_of_line ();
3331 return;
3332 }
3333
3334 nbytes = 4;
3335
3336 mapping_state (MAP_ARM);
3337 }
3338
3339 do
3340 {
3341 expressionS exp;
3342
3343 expression (& exp);
3344
3345 if (! emit_insn (& exp, nbytes))
3346 {
3347 ignore_rest_of_line ();
3348 return;
3349 }
3350 }
3351 while (*input_line_pointer++ == ',');
3352
3353 /* Put terminator back into stream. */
3354 input_line_pointer --;
3355 demand_empty_rest_of_line ();
3356 }
3357
3358 /* Parse a .rel31 directive. */
3359
3360 static void
3361 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3362 {
3363 expressionS exp;
3364 char *p;
3365 valueT highbit;
3366
3367 highbit = 0;
3368 if (*input_line_pointer == '1')
3369 highbit = 0x80000000;
3370 else if (*input_line_pointer != '0')
3371 as_bad (_("expected 0 or 1"));
3372
3373 input_line_pointer++;
3374 if (*input_line_pointer != ',')
3375 as_bad (_("missing comma"));
3376 input_line_pointer++;
3377
3378 #ifdef md_flush_pending_output
3379 md_flush_pending_output ();
3380 #endif
3381
3382 #ifdef md_cons_align
3383 md_cons_align (4);
3384 #endif
3385
3386 mapping_state (MAP_DATA);
3387
3388 expression (&exp);
3389
3390 p = frag_more (4);
3391 md_number_to_chars (p, highbit, 4);
3392 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3393 BFD_RELOC_ARM_PREL31);
3394
3395 demand_empty_rest_of_line ();
3396 }
3397
3398 /* Directives: AEABI stack-unwind tables. */
3399
3400 /* Parse an unwind_fnstart directive. Simply records the current location. */
3401
3402 static void
3403 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3404 {
3405 demand_empty_rest_of_line ();
3406 if (unwind.proc_start)
3407 {
3408 as_bad (_("duplicate .fnstart directive"));
3409 return;
3410 }
3411
3412 /* Mark the start of the function. */
3413 unwind.proc_start = expr_build_dot ();
3414
3415 /* Reset the rest of the unwind info. */
3416 unwind.opcode_count = 0;
3417 unwind.table_entry = NULL;
3418 unwind.personality_routine = NULL;
3419 unwind.personality_index = -1;
3420 unwind.frame_size = 0;
3421 unwind.fp_offset = 0;
3422 unwind.fp_reg = REG_SP;
3423 unwind.fp_used = 0;
3424 unwind.sp_restored = 0;
3425 }
3426
3427
3428 /* Parse a handlerdata directive. Creates the exception handling table entry
3429 for the function. */
3430
3431 static void
3432 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3433 {
3434 demand_empty_rest_of_line ();
3435 if (!unwind.proc_start)
3436 as_bad (MISSING_FNSTART);
3437
3438 if (unwind.table_entry)
3439 as_bad (_("duplicate .handlerdata directive"));
3440
3441 create_unwind_entry (1);
3442 }
3443
3444 /* Parse an unwind_fnend directive. Generates the index table entry. */
3445
3446 static void
3447 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3448 {
3449 long where;
3450 char *ptr;
3451 valueT val;
3452 unsigned int marked_pr_dependency;
3453
3454 demand_empty_rest_of_line ();
3455
3456 if (!unwind.proc_start)
3457 {
3458 as_bad (_(".fnend directive without .fnstart"));
3459 return;
3460 }
3461
3462 /* Add eh table entry. */
3463 if (unwind.table_entry == NULL)
3464 val = create_unwind_entry (0);
3465 else
3466 val = 0;
3467
3468 /* Add index table entry. This is two words. */
3469 start_unwind_section (unwind.saved_seg, 1);
3470 frag_align (2, 0, 0);
3471 record_alignment (now_seg, 2);
3472
3473 ptr = frag_more (8);
3474 where = frag_now_fix () - 8;
3475
3476 /* Self relative offset of the function start. */
3477 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3478 BFD_RELOC_ARM_PREL31);
3479
3480 /* Indicate dependency on EHABI-defined personality routines to the
3481 linker, if it hasn't been done already. */
3482 marked_pr_dependency
3483 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3484 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3485 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3486 {
3487 static const char *const name[] =
3488 {
3489 "__aeabi_unwind_cpp_pr0",
3490 "__aeabi_unwind_cpp_pr1",
3491 "__aeabi_unwind_cpp_pr2"
3492 };
3493 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3494 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3495 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3496 |= 1 << unwind.personality_index;
3497 }
3498
3499 if (val)
3500 /* Inline exception table entry. */
3501 md_number_to_chars (ptr + 4, val, 4);
3502 else
3503 /* Self relative offset of the table entry. */
3504 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3505 BFD_RELOC_ARM_PREL31);
3506
3507 /* Restore the original section. */
3508 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3509
3510 unwind.proc_start = NULL;
3511 }
3512
3513
3514 /* Parse an unwind_cantunwind directive. */
3515
3516 static void
3517 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3518 {
3519 demand_empty_rest_of_line ();
3520 if (!unwind.proc_start)
3521 as_bad (MISSING_FNSTART);
3522
3523 if (unwind.personality_routine || unwind.personality_index != -1)
3524 as_bad (_("personality routine specified for cantunwind frame"));
3525
3526 unwind.personality_index = -2;
3527 }
3528
3529
3530 /* Parse a personalityindex directive. */
3531
3532 static void
3533 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3534 {
3535 expressionS exp;
3536
3537 if (!unwind.proc_start)
3538 as_bad (MISSING_FNSTART);
3539
3540 if (unwind.personality_routine || unwind.personality_index != -1)
3541 as_bad (_("duplicate .personalityindex directive"));
3542
3543 expression (&exp);
3544
3545 if (exp.X_op != O_constant
3546 || exp.X_add_number < 0 || exp.X_add_number > 15)
3547 {
3548 as_bad (_("bad personality routine number"));
3549 ignore_rest_of_line ();
3550 return;
3551 }
3552
3553 unwind.personality_index = exp.X_add_number;
3554
3555 demand_empty_rest_of_line ();
3556 }
3557
3558
3559 /* Parse a personality directive. */
3560
3561 static void
3562 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3563 {
3564 char *name, *p, c;
3565
3566 if (!unwind.proc_start)
3567 as_bad (MISSING_FNSTART);
3568
3569 if (unwind.personality_routine || unwind.personality_index != -1)
3570 as_bad (_("duplicate .personality directive"));
3571
3572 name = input_line_pointer;
3573 c = get_symbol_end ();
3574 p = input_line_pointer;
3575 unwind.personality_routine = symbol_find_or_make (name);
3576 *p = c;
3577 demand_empty_rest_of_line ();
3578 }
3579
3580
3581 /* Parse a directive saving core registers. */
3582
3583 static void
3584 s_arm_unwind_save_core (void)
3585 {
3586 valueT op;
3587 long range;
3588 int n;
3589
3590 range = parse_reg_list (&input_line_pointer);
3591 if (range == FAIL)
3592 {
3593 as_bad (_("expected register list"));
3594 ignore_rest_of_line ();
3595 return;
3596 }
3597
3598 demand_empty_rest_of_line ();
3599
3600 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3601 into .unwind_save {..., sp...}. We aren't bothered about the value of
3602 ip because it is clobbered by calls. */
3603 if (unwind.sp_restored && unwind.fp_reg == 12
3604 && (range & 0x3000) == 0x1000)
3605 {
3606 unwind.opcode_count--;
3607 unwind.sp_restored = 0;
3608 range = (range | 0x2000) & ~0x1000;
3609 unwind.pending_offset = 0;
3610 }
3611
3612 /* Pop r4-r15. */
3613 if (range & 0xfff0)
3614 {
3615 /* See if we can use the short opcodes. These pop a block of up to 8
3616 registers starting with r4, plus maybe r14. */
3617 for (n = 0; n < 8; n++)
3618 {
3619 /* Break at the first non-saved register. */
3620 if ((range & (1 << (n + 4))) == 0)
3621 break;
3622 }
3623 /* See if there are any other bits set. */
3624 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3625 {
3626 /* Use the long form. */
3627 op = 0x8000 | ((range >> 4) & 0xfff);
3628 add_unwind_opcode (op, 2);
3629 }
3630 else
3631 {
3632 /* Use the short form. */
3633 if (range & 0x4000)
3634 op = 0xa8; /* Pop r14. */
3635 else
3636 op = 0xa0; /* Do not pop r14. */
3637 op |= (n - 1);
3638 add_unwind_opcode (op, 1);
3639 }
3640 }
3641
3642 /* Pop r0-r3. */
3643 if (range & 0xf)
3644 {
3645 op = 0xb100 | (range & 0xf);
3646 add_unwind_opcode (op, 2);
3647 }
3648
3649 /* Record the number of bytes pushed. */
3650 for (n = 0; n < 16; n++)
3651 {
3652 if (range & (1 << n))
3653 unwind.frame_size += 4;
3654 }
3655 }
3656
3657
3658 /* Parse a directive saving FPA registers. */
3659
3660 static void
3661 s_arm_unwind_save_fpa (int reg)
3662 {
3663 expressionS exp;
3664 int num_regs;
3665 valueT op;
3666
3667 /* Get Number of registers to transfer. */
3668 if (skip_past_comma (&input_line_pointer) != FAIL)
3669 expression (&exp);
3670 else
3671 exp.X_op = O_illegal;
3672
3673 if (exp.X_op != O_constant)
3674 {
3675 as_bad (_("expected , <constant>"));
3676 ignore_rest_of_line ();
3677 return;
3678 }
3679
3680 num_regs = exp.X_add_number;
3681
3682 if (num_regs < 1 || num_regs > 4)
3683 {
3684 as_bad (_("number of registers must be in the range [1:4]"));
3685 ignore_rest_of_line ();
3686 return;
3687 }
3688
3689 demand_empty_rest_of_line ();
3690
3691 if (reg == 4)
3692 {
3693 /* Short form. */
3694 op = 0xb4 | (num_regs - 1);
3695 add_unwind_opcode (op, 1);
3696 }
3697 else
3698 {
3699 /* Long form. */
3700 op = 0xc800 | (reg << 4) | (num_regs - 1);
3701 add_unwind_opcode (op, 2);
3702 }
3703 unwind.frame_size += num_regs * 12;
3704 }
3705
3706
3707 /* Parse a directive saving VFP registers for ARMv6 and above. */
3708
3709 static void
3710 s_arm_unwind_save_vfp_armv6 (void)
3711 {
3712 int count;
3713 unsigned int start;
3714 valueT op;
3715 int num_vfpv3_regs = 0;
3716 int num_regs_below_16;
3717
3718 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3719 if (count == FAIL)
3720 {
3721 as_bad (_("expected register list"));
3722 ignore_rest_of_line ();
3723 return;
3724 }
3725
3726 demand_empty_rest_of_line ();
3727
3728 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3729 than FSTMX/FLDMX-style ones). */
3730
3731 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3732 if (start >= 16)
3733 num_vfpv3_regs = count;
3734 else if (start + count > 16)
3735 num_vfpv3_regs = start + count - 16;
3736
3737 if (num_vfpv3_regs > 0)
3738 {
3739 int start_offset = start > 16 ? start - 16 : 0;
3740 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3741 add_unwind_opcode (op, 2);
3742 }
3743
3744 /* Generate opcode for registers numbered in the range 0 .. 15. */
3745 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3746 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3747 if (num_regs_below_16 > 0)
3748 {
3749 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3750 add_unwind_opcode (op, 2);
3751 }
3752
3753 unwind.frame_size += count * 8;
3754 }
3755
3756
3757 /* Parse a directive saving VFP registers for pre-ARMv6. */
3758
3759 static void
3760 s_arm_unwind_save_vfp (void)
3761 {
3762 int count;
3763 unsigned int reg;
3764 valueT op;
3765
3766 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3767 if (count == FAIL)
3768 {
3769 as_bad (_("expected register list"));
3770 ignore_rest_of_line ();
3771 return;
3772 }
3773
3774 demand_empty_rest_of_line ();
3775
3776 if (reg == 8)
3777 {
3778 /* Short form. */
3779 op = 0xb8 | (count - 1);
3780 add_unwind_opcode (op, 1);
3781 }
3782 else
3783 {
3784 /* Long form. */
3785 op = 0xb300 | (reg << 4) | (count - 1);
3786 add_unwind_opcode (op, 2);
3787 }
3788 unwind.frame_size += count * 8 + 4;
3789 }
3790
3791
3792 /* Parse a directive saving iWMMXt data registers. */
3793
3794 static void
3795 s_arm_unwind_save_mmxwr (void)
3796 {
3797 int reg;
3798 int hi_reg;
3799 int i;
3800 unsigned mask = 0;
3801 valueT op;
3802
3803 if (*input_line_pointer == '{')
3804 input_line_pointer++;
3805
3806 do
3807 {
3808 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3809
3810 if (reg == FAIL)
3811 {
3812 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3813 goto error;
3814 }
3815
3816 if (mask >> reg)
3817 as_tsktsk (_("register list not in ascending order"));
3818 mask |= 1 << reg;
3819
3820 if (*input_line_pointer == '-')
3821 {
3822 input_line_pointer++;
3823 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3824 if (hi_reg == FAIL)
3825 {
3826 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3827 goto error;
3828 }
3829 else if (reg >= hi_reg)
3830 {
3831 as_bad (_("bad register range"));
3832 goto error;
3833 }
3834 for (; reg < hi_reg; reg++)
3835 mask |= 1 << reg;
3836 }
3837 }
3838 while (skip_past_comma (&input_line_pointer) != FAIL);
3839
3840 if (*input_line_pointer == '}')
3841 input_line_pointer++;
3842
3843 demand_empty_rest_of_line ();
3844
3845 /* Generate any deferred opcodes because we're going to be looking at
3846 the list. */
3847 flush_pending_unwind ();
3848
3849 for (i = 0; i < 16; i++)
3850 {
3851 if (mask & (1 << i))
3852 unwind.frame_size += 8;
3853 }
3854
3855 /* Attempt to combine with a previous opcode. We do this because gcc
3856 likes to output separate unwind directives for a single block of
3857 registers. */
3858 if (unwind.opcode_count > 0)
3859 {
3860 i = unwind.opcodes[unwind.opcode_count - 1];
3861 if ((i & 0xf8) == 0xc0)
3862 {
3863 i &= 7;
3864 /* Only merge if the blocks are contiguous. */
3865 if (i < 6)
3866 {
3867 if ((mask & 0xfe00) == (1 << 9))
3868 {
3869 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3870 unwind.opcode_count--;
3871 }
3872 }
3873 else if (i == 6 && unwind.opcode_count >= 2)
3874 {
3875 i = unwind.opcodes[unwind.opcode_count - 2];
3876 reg = i >> 4;
3877 i &= 0xf;
3878
3879 op = 0xffff << (reg - 1);
3880 if (reg > 0
3881 && ((mask & op) == (1u << (reg - 1))))
3882 {
3883 op = (1 << (reg + i + 1)) - 1;
3884 op &= ~((1 << reg) - 1);
3885 mask |= op;
3886 unwind.opcode_count -= 2;
3887 }
3888 }
3889 }
3890 }
3891
3892 hi_reg = 15;
3893 /* We want to generate opcodes in the order the registers have been
3894 saved, ie. descending order. */
3895 for (reg = 15; reg >= -1; reg--)
3896 {
3897 /* Save registers in blocks. */
3898 if (reg < 0
3899 || !(mask & (1 << reg)))
3900 {
3901 /* We found an unsaved reg. Generate opcodes to save the
3902 preceding block. */
3903 if (reg != hi_reg)
3904 {
3905 if (reg == 9)
3906 {
3907 /* Short form. */
3908 op = 0xc0 | (hi_reg - 10);
3909 add_unwind_opcode (op, 1);
3910 }
3911 else
3912 {
3913 /* Long form. */
3914 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3915 add_unwind_opcode (op, 2);
3916 }
3917 }
3918 hi_reg = reg - 1;
3919 }
3920 }
3921
3922 return;
3923 error:
3924 ignore_rest_of_line ();
3925 }
3926
3927 static void
3928 s_arm_unwind_save_mmxwcg (void)
3929 {
3930 int reg;
3931 int hi_reg;
3932 unsigned mask = 0;
3933 valueT op;
3934
3935 if (*input_line_pointer == '{')
3936 input_line_pointer++;
3937
3938 do
3939 {
3940 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3941
3942 if (reg == FAIL)
3943 {
3944 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3945 goto error;
3946 }
3947
3948 reg -= 8;
3949 if (mask >> reg)
3950 as_tsktsk (_("register list not in ascending order"));
3951 mask |= 1 << reg;
3952
3953 if (*input_line_pointer == '-')
3954 {
3955 input_line_pointer++;
3956 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3957 if (hi_reg == FAIL)
3958 {
3959 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3960 goto error;
3961 }
3962 else if (reg >= hi_reg)
3963 {
3964 as_bad (_("bad register range"));
3965 goto error;
3966 }
3967 for (; reg < hi_reg; reg++)
3968 mask |= 1 << reg;
3969 }
3970 }
3971 while (skip_past_comma (&input_line_pointer) != FAIL);
3972
3973 if (*input_line_pointer == '}')
3974 input_line_pointer++;
3975
3976 demand_empty_rest_of_line ();
3977
3978 /* Generate any deferred opcodes because we're going to be looking at
3979 the list. */
3980 flush_pending_unwind ();
3981
3982 for (reg = 0; reg < 16; reg++)
3983 {
3984 if (mask & (1 << reg))
3985 unwind.frame_size += 4;
3986 }
3987 op = 0xc700 | mask;
3988 add_unwind_opcode (op, 2);
3989 return;
3990 error:
3991 ignore_rest_of_line ();
3992 }
3993
3994
3995 /* Parse an unwind_save directive.
3996 If the argument is non-zero, this is a .vsave directive. */
3997
3998 static void
3999 s_arm_unwind_save (int arch_v6)
4000 {
4001 char *peek;
4002 struct reg_entry *reg;
4003 bfd_boolean had_brace = FALSE;
4004
4005 if (!unwind.proc_start)
4006 as_bad (MISSING_FNSTART);
4007
4008 /* Figure out what sort of save we have. */
4009 peek = input_line_pointer;
4010
4011 if (*peek == '{')
4012 {
4013 had_brace = TRUE;
4014 peek++;
4015 }
4016
4017 reg = arm_reg_parse_multi (&peek);
4018
4019 if (!reg)
4020 {
4021 as_bad (_("register expected"));
4022 ignore_rest_of_line ();
4023 return;
4024 }
4025
4026 switch (reg->type)
4027 {
4028 case REG_TYPE_FN:
4029 if (had_brace)
4030 {
4031 as_bad (_("FPA .unwind_save does not take a register list"));
4032 ignore_rest_of_line ();
4033 return;
4034 }
4035 input_line_pointer = peek;
4036 s_arm_unwind_save_fpa (reg->number);
4037 return;
4038
4039 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4040 case REG_TYPE_VFD:
4041 if (arch_v6)
4042 s_arm_unwind_save_vfp_armv6 ();
4043 else
4044 s_arm_unwind_save_vfp ();
4045 return;
4046 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4047 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4048
4049 default:
4050 as_bad (_(".unwind_save does not support this kind of register"));
4051 ignore_rest_of_line ();
4052 }
4053 }
4054
4055
4056 /* Parse an unwind_movsp directive. */
4057
4058 static void
4059 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4060 {
4061 int reg;
4062 valueT op;
4063 int offset;
4064
4065 if (!unwind.proc_start)
4066 as_bad (MISSING_FNSTART);
4067
4068 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4069 if (reg == FAIL)
4070 {
4071 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4072 ignore_rest_of_line ();
4073 return;
4074 }
4075
4076 /* Optional constant. */
4077 if (skip_past_comma (&input_line_pointer) != FAIL)
4078 {
4079 if (immediate_for_directive (&offset) == FAIL)
4080 return;
4081 }
4082 else
4083 offset = 0;
4084
4085 demand_empty_rest_of_line ();
4086
4087 if (reg == REG_SP || reg == REG_PC)
4088 {
4089 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4090 return;
4091 }
4092
4093 if (unwind.fp_reg != REG_SP)
4094 as_bad (_("unexpected .unwind_movsp directive"));
4095
4096 /* Generate opcode to restore the value. */
4097 op = 0x90 | reg;
4098 add_unwind_opcode (op, 1);
4099
4100 /* Record the information for later. */
4101 unwind.fp_reg = reg;
4102 unwind.fp_offset = unwind.frame_size - offset;
4103 unwind.sp_restored = 1;
4104 }
4105
4106 /* Parse an unwind_pad directive. */
4107
4108 static void
4109 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4110 {
4111 int offset;
4112
4113 if (!unwind.proc_start)
4114 as_bad (MISSING_FNSTART);
4115
4116 if (immediate_for_directive (&offset) == FAIL)
4117 return;
4118
4119 if (offset & 3)
4120 {
4121 as_bad (_("stack increment must be multiple of 4"));
4122 ignore_rest_of_line ();
4123 return;
4124 }
4125
4126 /* Don't generate any opcodes, just record the details for later. */
4127 unwind.frame_size += offset;
4128 unwind.pending_offset += offset;
4129
4130 demand_empty_rest_of_line ();
4131 }
4132
4133 /* Parse an unwind_setfp directive. */
4134
4135 static void
4136 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4137 {
4138 int sp_reg;
4139 int fp_reg;
4140 int offset;
4141
4142 if (!unwind.proc_start)
4143 as_bad (MISSING_FNSTART);
4144
4145 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4146 if (skip_past_comma (&input_line_pointer) == FAIL)
4147 sp_reg = FAIL;
4148 else
4149 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4150
4151 if (fp_reg == FAIL || sp_reg == FAIL)
4152 {
4153 as_bad (_("expected <reg>, <reg>"));
4154 ignore_rest_of_line ();
4155 return;
4156 }
4157
4158 /* Optional constant. */
4159 if (skip_past_comma (&input_line_pointer) != FAIL)
4160 {
4161 if (immediate_for_directive (&offset) == FAIL)
4162 return;
4163 }
4164 else
4165 offset = 0;
4166
4167 demand_empty_rest_of_line ();
4168
4169 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4170 {
4171 as_bad (_("register must be either sp or set by a previous"
4172 "unwind_movsp directive"));
4173 return;
4174 }
4175
4176 /* Don't generate any opcodes, just record the information for later. */
4177 unwind.fp_reg = fp_reg;
4178 unwind.fp_used = 1;
4179 if (sp_reg == REG_SP)
4180 unwind.fp_offset = unwind.frame_size - offset;
4181 else
4182 unwind.fp_offset -= offset;
4183 }
4184
4185 /* Parse an unwind_raw directive. */
4186
4187 static void
4188 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4189 {
4190 expressionS exp;
4191 /* This is an arbitrary limit. */
4192 unsigned char op[16];
4193 int count;
4194
4195 if (!unwind.proc_start)
4196 as_bad (MISSING_FNSTART);
4197
4198 expression (&exp);
4199 if (exp.X_op == O_constant
4200 && skip_past_comma (&input_line_pointer) != FAIL)
4201 {
4202 unwind.frame_size += exp.X_add_number;
4203 expression (&exp);
4204 }
4205 else
4206 exp.X_op = O_illegal;
4207
4208 if (exp.X_op != O_constant)
4209 {
4210 as_bad (_("expected <offset>, <opcode>"));
4211 ignore_rest_of_line ();
4212 return;
4213 }
4214
4215 count = 0;
4216
4217 /* Parse the opcode. */
4218 for (;;)
4219 {
4220 if (count >= 16)
4221 {
4222 as_bad (_("unwind opcode too long"));
4223 ignore_rest_of_line ();
4224 }
4225 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4226 {
4227 as_bad (_("invalid unwind opcode"));
4228 ignore_rest_of_line ();
4229 return;
4230 }
4231 op[count++] = exp.X_add_number;
4232
4233 /* Parse the next byte. */
4234 if (skip_past_comma (&input_line_pointer) == FAIL)
4235 break;
4236
4237 expression (&exp);
4238 }
4239
4240 /* Add the opcode bytes in reverse order. */
4241 while (count--)
4242 add_unwind_opcode (op[count], 1);
4243
4244 demand_empty_rest_of_line ();
4245 }
4246
4247
4248 /* Parse a .eabi_attribute directive. */
4249
4250 static void
4251 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4252 {
4253 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4254
4255 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4256 attributes_set_explicitly[tag] = 1;
4257 }
4258 #endif /* OBJ_ELF */
4259
4260 static void s_arm_arch (int);
4261 static void s_arm_object_arch (int);
4262 static void s_arm_cpu (int);
4263 static void s_arm_fpu (int);
4264
4265 #ifdef TE_PE
4266
4267 static void
4268 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4269 {
4270 expressionS exp;
4271
4272 do
4273 {
4274 expression (&exp);
4275 if (exp.X_op == O_symbol)
4276 exp.X_op = O_secrel;
4277
4278 emit_expr (&exp, 4);
4279 }
4280 while (*input_line_pointer++ == ',');
4281
4282 input_line_pointer--;
4283 demand_empty_rest_of_line ();
4284 }
4285 #endif /* TE_PE */
4286
4287 /* This table describes all the machine specific pseudo-ops the assembler
4288 has to support. The fields are:
4289 pseudo-op name without dot
4290 function to call to execute this pseudo-op
4291 Integer arg to pass to the function. */
4292
4293 const pseudo_typeS md_pseudo_table[] =
4294 {
4295 /* Never called because '.req' does not start a line. */
4296 { "req", s_req, 0 },
4297 /* Following two are likewise never called. */
4298 { "dn", s_dn, 0 },
4299 { "qn", s_qn, 0 },
4300 { "unreq", s_unreq, 0 },
4301 { "bss", s_bss, 0 },
4302 { "align", s_align, 0 },
4303 { "arm", s_arm, 0 },
4304 { "thumb", s_thumb, 0 },
4305 { "code", s_code, 0 },
4306 { "force_thumb", s_force_thumb, 0 },
4307 { "thumb_func", s_thumb_func, 0 },
4308 { "thumb_set", s_thumb_set, 0 },
4309 { "even", s_even, 0 },
4310 { "ltorg", s_ltorg, 0 },
4311 { "pool", s_ltorg, 0 },
4312 { "syntax", s_syntax, 0 },
4313 { "cpu", s_arm_cpu, 0 },
4314 { "arch", s_arm_arch, 0 },
4315 { "object_arch", s_arm_object_arch, 0 },
4316 { "fpu", s_arm_fpu, 0 },
4317 #ifdef OBJ_ELF
4318 { "word", s_arm_elf_cons, 4 },
4319 { "long", s_arm_elf_cons, 4 },
4320 { "inst.n", s_arm_elf_inst, 2 },
4321 { "inst.w", s_arm_elf_inst, 4 },
4322 { "inst", s_arm_elf_inst, 0 },
4323 { "rel31", s_arm_rel31, 0 },
4324 { "fnstart", s_arm_unwind_fnstart, 0 },
4325 { "fnend", s_arm_unwind_fnend, 0 },
4326 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4327 { "personality", s_arm_unwind_personality, 0 },
4328 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4329 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4330 { "save", s_arm_unwind_save, 0 },
4331 { "vsave", s_arm_unwind_save, 1 },
4332 { "movsp", s_arm_unwind_movsp, 0 },
4333 { "pad", s_arm_unwind_pad, 0 },
4334 { "setfp", s_arm_unwind_setfp, 0 },
4335 { "unwind_raw", s_arm_unwind_raw, 0 },
4336 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4337 #else
4338 { "word", cons, 4},
4339
4340 /* These are used for dwarf. */
4341 {"2byte", cons, 2},
4342 {"4byte", cons, 4},
4343 {"8byte", cons, 8},
4344 /* These are used for dwarf2. */
4345 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4346 { "loc", dwarf2_directive_loc, 0 },
4347 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4348 #endif
4349 { "extend", float_cons, 'x' },
4350 { "ldouble", float_cons, 'x' },
4351 { "packed", float_cons, 'p' },
4352 #ifdef TE_PE
4353 {"secrel32", pe_directive_secrel, 0},
4354 #endif
4355 { 0, 0, 0 }
4356 };
4357 \f
4358 /* Parser functions used exclusively in instruction operands. */
4359
4360 /* Generic immediate-value read function for use in insn parsing.
4361 STR points to the beginning of the immediate (the leading #);
4362 VAL receives the value; if the value is outside [MIN, MAX]
4363 issue an error. PREFIX_OPT is true if the immediate prefix is
4364 optional. */
4365
4366 static int
4367 parse_immediate (char **str, int *val, int min, int max,
4368 bfd_boolean prefix_opt)
4369 {
4370 expressionS exp;
4371 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4372 if (exp.X_op != O_constant)
4373 {
4374 inst.error = _("constant expression required");
4375 return FAIL;
4376 }
4377
4378 if (exp.X_add_number < min || exp.X_add_number > max)
4379 {
4380 inst.error = _("immediate value out of range");
4381 return FAIL;
4382 }
4383
4384 *val = exp.X_add_number;
4385 return SUCCESS;
4386 }
4387
4388 /* Less-generic immediate-value read function with the possibility of loading a
4389 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4390 instructions. Puts the result directly in inst.operands[i]. */
4391
4392 static int
4393 parse_big_immediate (char **str, int i)
4394 {
4395 expressionS exp;
4396 char *ptr = *str;
4397
4398 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4399
4400 if (exp.X_op == O_constant)
4401 {
4402 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4403 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4404 O_constant. We have to be careful not to break compilation for
4405 32-bit X_add_number, though. */
4406 if ((exp.X_add_number & ~0xffffffffl) != 0)
4407 {
4408 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4409 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4410 inst.operands[i].regisimm = 1;
4411 }
4412 }
4413 else if (exp.X_op == O_big
4414 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4415 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4416 {
4417 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4418 /* Bignums have their least significant bits in
4419 generic_bignum[0]. Make sure we put 32 bits in imm and
4420 32 bits in reg, in a (hopefully) portable way. */
4421 gas_assert (parts != 0);
4422 inst.operands[i].imm = 0;
4423 for (j = 0; j < parts; j++, idx++)
4424 inst.operands[i].imm |= generic_bignum[idx]
4425 << (LITTLENUM_NUMBER_OF_BITS * j);
4426 inst.operands[i].reg = 0;
4427 for (j = 0; j < parts; j++, idx++)
4428 inst.operands[i].reg |= generic_bignum[idx]
4429 << (LITTLENUM_NUMBER_OF_BITS * j);
4430 inst.operands[i].regisimm = 1;
4431 }
4432 else
4433 return FAIL;
4434
4435 *str = ptr;
4436
4437 return SUCCESS;
4438 }
4439
4440 /* Returns the pseudo-register number of an FPA immediate constant,
4441 or FAIL if there isn't a valid constant here. */
4442
4443 static int
4444 parse_fpa_immediate (char ** str)
4445 {
4446 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4447 char * save_in;
4448 expressionS exp;
4449 int i;
4450 int j;
4451
4452 /* First try and match exact strings, this is to guarantee
4453 that some formats will work even for cross assembly. */
4454
4455 for (i = 0; fp_const[i]; i++)
4456 {
4457 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4458 {
4459 char *start = *str;
4460
4461 *str += strlen (fp_const[i]);
4462 if (is_end_of_line[(unsigned char) **str])
4463 return i + 8;
4464 *str = start;
4465 }
4466 }
4467
4468 /* Just because we didn't get a match doesn't mean that the constant
4469 isn't valid, just that it is in a format that we don't
4470 automatically recognize. Try parsing it with the standard
4471 expression routines. */
4472
4473 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4474
4475 /* Look for a raw floating point number. */
4476 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4477 && is_end_of_line[(unsigned char) *save_in])
4478 {
4479 for (i = 0; i < NUM_FLOAT_VALS; i++)
4480 {
4481 for (j = 0; j < MAX_LITTLENUMS; j++)
4482 {
4483 if (words[j] != fp_values[i][j])
4484 break;
4485 }
4486
4487 if (j == MAX_LITTLENUMS)
4488 {
4489 *str = save_in;
4490 return i + 8;
4491 }
4492 }
4493 }
4494
4495 /* Try and parse a more complex expression, this will probably fail
4496 unless the code uses a floating point prefix (eg "0f"). */
4497 save_in = input_line_pointer;
4498 input_line_pointer = *str;
4499 if (expression (&exp) == absolute_section
4500 && exp.X_op == O_big
4501 && exp.X_add_number < 0)
4502 {
4503 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4504 Ditto for 15. */
4505 if (gen_to_words (words, 5, (long) 15) == 0)
4506 {
4507 for (i = 0; i < NUM_FLOAT_VALS; i++)
4508 {
4509 for (j = 0; j < MAX_LITTLENUMS; j++)
4510 {
4511 if (words[j] != fp_values[i][j])
4512 break;
4513 }
4514
4515 if (j == MAX_LITTLENUMS)
4516 {
4517 *str = input_line_pointer;
4518 input_line_pointer = save_in;
4519 return i + 8;
4520 }
4521 }
4522 }
4523 }
4524
4525 *str = input_line_pointer;
4526 input_line_pointer = save_in;
4527 inst.error = _("invalid FPA immediate expression");
4528 return FAIL;
4529 }
4530
4531 /* Returns 1 if a number has "quarter-precision" float format
4532 0baBbbbbbc defgh000 00000000 00000000. */
4533
4534 static int
4535 is_quarter_float (unsigned imm)
4536 {
4537 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4538 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4539 }
4540
4541 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4542 0baBbbbbbc defgh000 00000000 00000000.
4543 The zero and minus-zero cases need special handling, since they can't be
4544 encoded in the "quarter-precision" float format, but can nonetheless be
4545 loaded as integer constants. */
4546
4547 static unsigned
4548 parse_qfloat_immediate (char **ccp, int *immed)
4549 {
4550 char *str = *ccp;
4551 char *fpnum;
4552 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4553 int found_fpchar = 0;
4554
4555 skip_past_char (&str, '#');
4556
4557 /* We must not accidentally parse an integer as a floating-point number. Make
4558 sure that the value we parse is not an integer by checking for special
4559 characters '.' or 'e'.
4560 FIXME: This is a horrible hack, but doing better is tricky because type
4561 information isn't in a very usable state at parse time. */
4562 fpnum = str;
4563 skip_whitespace (fpnum);
4564
4565 if (strncmp (fpnum, "0x", 2) == 0)
4566 return FAIL;
4567 else
4568 {
4569 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4570 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4571 {
4572 found_fpchar = 1;
4573 break;
4574 }
4575
4576 if (!found_fpchar)
4577 return FAIL;
4578 }
4579
4580 if ((str = atof_ieee (str, 's', words)) != NULL)
4581 {
4582 unsigned fpword = 0;
4583 int i;
4584
4585 /* Our FP word must be 32 bits (single-precision FP). */
4586 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4587 {
4588 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4589 fpword |= words[i];
4590 }
4591
4592 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4593 *immed = fpword;
4594 else
4595 return FAIL;
4596
4597 *ccp = str;
4598
4599 return SUCCESS;
4600 }
4601
4602 return FAIL;
4603 }
4604
4605 /* Shift operands. */
4606 enum shift_kind
4607 {
4608 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4609 };
4610
4611 struct asm_shift_name
4612 {
4613 const char *name;
4614 enum shift_kind kind;
4615 };
4616
4617 /* Third argument to parse_shift. */
4618 enum parse_shift_mode
4619 {
4620 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4621 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4622 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4623 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4624 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4625 };
4626
4627 /* Parse a <shift> specifier on an ARM data processing instruction.
4628 This has three forms:
4629
4630 (LSL|LSR|ASL|ASR|ROR) Rs
4631 (LSL|LSR|ASL|ASR|ROR) #imm
4632 RRX
4633
4634 Note that ASL is assimilated to LSL in the instruction encoding, and
4635 RRX to ROR #0 (which cannot be written as such). */
4636
4637 static int
4638 parse_shift (char **str, int i, enum parse_shift_mode mode)
4639 {
4640 const struct asm_shift_name *shift_name;
4641 enum shift_kind shift;
4642 char *s = *str;
4643 char *p = s;
4644 int reg;
4645
4646 for (p = *str; ISALPHA (*p); p++)
4647 ;
4648
4649 if (p == *str)
4650 {
4651 inst.error = _("shift expression expected");
4652 return FAIL;
4653 }
4654
4655 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4656 p - *str);
4657
4658 if (shift_name == NULL)
4659 {
4660 inst.error = _("shift expression expected");
4661 return FAIL;
4662 }
4663
4664 shift = shift_name->kind;
4665
4666 switch (mode)
4667 {
4668 case NO_SHIFT_RESTRICT:
4669 case SHIFT_IMMEDIATE: break;
4670
4671 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4672 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4673 {
4674 inst.error = _("'LSL' or 'ASR' required");
4675 return FAIL;
4676 }
4677 break;
4678
4679 case SHIFT_LSL_IMMEDIATE:
4680 if (shift != SHIFT_LSL)
4681 {
4682 inst.error = _("'LSL' required");
4683 return FAIL;
4684 }
4685 break;
4686
4687 case SHIFT_ASR_IMMEDIATE:
4688 if (shift != SHIFT_ASR)
4689 {
4690 inst.error = _("'ASR' required");
4691 return FAIL;
4692 }
4693 break;
4694
4695 default: abort ();
4696 }
4697
4698 if (shift != SHIFT_RRX)
4699 {
4700 /* Whitespace can appear here if the next thing is a bare digit. */
4701 skip_whitespace (p);
4702
4703 if (mode == NO_SHIFT_RESTRICT
4704 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4705 {
4706 inst.operands[i].imm = reg;
4707 inst.operands[i].immisreg = 1;
4708 }
4709 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4710 return FAIL;
4711 }
4712 inst.operands[i].shift_kind = shift;
4713 inst.operands[i].shifted = 1;
4714 *str = p;
4715 return SUCCESS;
4716 }
4717
4718 /* Parse a <shifter_operand> for an ARM data processing instruction:
4719
4720 #<immediate>
4721 #<immediate>, <rotate>
4722 <Rm>
4723 <Rm>, <shift>
4724
4725 where <shift> is defined by parse_shift above, and <rotate> is a
4726 multiple of 2 between 0 and 30. Validation of immediate operands
4727 is deferred to md_apply_fix. */
4728
4729 static int
4730 parse_shifter_operand (char **str, int i)
4731 {
4732 int value;
4733 expressionS exp;
4734
4735 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4736 {
4737 inst.operands[i].reg = value;
4738 inst.operands[i].isreg = 1;
4739
4740 /* parse_shift will override this if appropriate */
4741 inst.reloc.exp.X_op = O_constant;
4742 inst.reloc.exp.X_add_number = 0;
4743
4744 if (skip_past_comma (str) == FAIL)
4745 return SUCCESS;
4746
4747 /* Shift operation on register. */
4748 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4749 }
4750
4751 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4752 return FAIL;
4753
4754 if (skip_past_comma (str) == SUCCESS)
4755 {
4756 /* #x, y -- ie explicit rotation by Y. */
4757 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4758 return FAIL;
4759
4760 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4761 {
4762 inst.error = _("constant expression expected");
4763 return FAIL;
4764 }
4765
4766 value = exp.X_add_number;
4767 if (value < 0 || value > 30 || value % 2 != 0)
4768 {
4769 inst.error = _("invalid rotation");
4770 return FAIL;
4771 }
4772 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4773 {
4774 inst.error = _("invalid constant");
4775 return FAIL;
4776 }
4777
4778 /* Convert to decoded value. md_apply_fix will put it back. */
4779 inst.reloc.exp.X_add_number
4780 = (((inst.reloc.exp.X_add_number << (32 - value))
4781 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4782 }
4783
4784 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4785 inst.reloc.pc_rel = 0;
4786 return SUCCESS;
4787 }
4788
4789 /* Group relocation information. Each entry in the table contains the
4790 textual name of the relocation as may appear in assembler source
4791 and must end with a colon.
4792 Along with this textual name are the relocation codes to be used if
4793 the corresponding instruction is an ALU instruction (ADD or SUB only),
4794 an LDR, an LDRS, or an LDC. */
4795
4796 struct group_reloc_table_entry
4797 {
4798 const char *name;
4799 int alu_code;
4800 int ldr_code;
4801 int ldrs_code;
4802 int ldc_code;
4803 };
4804
4805 typedef enum
4806 {
4807 /* Varieties of non-ALU group relocation. */
4808
4809 GROUP_LDR,
4810 GROUP_LDRS,
4811 GROUP_LDC
4812 } group_reloc_type;
4813
4814 static struct group_reloc_table_entry group_reloc_table[] =
4815 { /* Program counter relative: */
4816 { "pc_g0_nc",
4817 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4818 0, /* LDR */
4819 0, /* LDRS */
4820 0 }, /* LDC */
4821 { "pc_g0",
4822 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4823 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4824 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4825 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4826 { "pc_g1_nc",
4827 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4828 0, /* LDR */
4829 0, /* LDRS */
4830 0 }, /* LDC */
4831 { "pc_g1",
4832 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4833 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4834 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4835 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4836 { "pc_g2",
4837 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4838 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4839 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4840 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4841 /* Section base relative */
4842 { "sb_g0_nc",
4843 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4844 0, /* LDR */
4845 0, /* LDRS */
4846 0 }, /* LDC */
4847 { "sb_g0",
4848 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4849 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4850 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4851 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4852 { "sb_g1_nc",
4853 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4854 0, /* LDR */
4855 0, /* LDRS */
4856 0 }, /* LDC */
4857 { "sb_g1",
4858 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4859 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4860 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4861 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4862 { "sb_g2",
4863 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4864 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4865 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4866 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4867
4868 /* Given the address of a pointer pointing to the textual name of a group
4869 relocation as may appear in assembler source, attempt to find its details
4870 in group_reloc_table. The pointer will be updated to the character after
4871 the trailing colon. On failure, FAIL will be returned; SUCCESS
4872 otherwise. On success, *entry will be updated to point at the relevant
4873 group_reloc_table entry. */
4874
4875 static int
4876 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4877 {
4878 unsigned int i;
4879 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4880 {
4881 int length = strlen (group_reloc_table[i].name);
4882
4883 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4884 && (*str)[length] == ':')
4885 {
4886 *out = &group_reloc_table[i];
4887 *str += (length + 1);
4888 return SUCCESS;
4889 }
4890 }
4891
4892 return FAIL;
4893 }
4894
4895 /* Parse a <shifter_operand> for an ARM data processing instruction
4896 (as for parse_shifter_operand) where group relocations are allowed:
4897
4898 #<immediate>
4899 #<immediate>, <rotate>
4900 #:<group_reloc>:<expression>
4901 <Rm>
4902 <Rm>, <shift>
4903
4904 where <group_reloc> is one of the strings defined in group_reloc_table.
4905 The hashes are optional.
4906
4907 Everything else is as for parse_shifter_operand. */
4908
4909 static parse_operand_result
4910 parse_shifter_operand_group_reloc (char **str, int i)
4911 {
4912 /* Determine if we have the sequence of characters #: or just :
4913 coming next. If we do, then we check for a group relocation.
4914 If we don't, punt the whole lot to parse_shifter_operand. */
4915
4916 if (((*str)[0] == '#' && (*str)[1] == ':')
4917 || (*str)[0] == ':')
4918 {
4919 struct group_reloc_table_entry *entry;
4920
4921 if ((*str)[0] == '#')
4922 (*str) += 2;
4923 else
4924 (*str)++;
4925
4926 /* Try to parse a group relocation. Anything else is an error. */
4927 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4928 {
4929 inst.error = _("unknown group relocation");
4930 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4931 }
4932
4933 /* We now have the group relocation table entry corresponding to
4934 the name in the assembler source. Next, we parse the expression. */
4935 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4936 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4937
4938 /* Record the relocation type (always the ALU variant here). */
4939 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
4940 gas_assert (inst.reloc.type != 0);
4941
4942 return PARSE_OPERAND_SUCCESS;
4943 }
4944 else
4945 return parse_shifter_operand (str, i) == SUCCESS
4946 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4947
4948 /* Never reached. */
4949 }
4950
4951 /* Parse a Neon alignment expression. Information is written to
4952 inst.operands[i]. We assume the initial ':' has been skipped.
4953
4954 align .imm = align << 8, .immisalign=1, .preind=0 */
4955 static parse_operand_result
4956 parse_neon_alignment (char **str, int i)
4957 {
4958 char *p = *str;
4959 expressionS exp;
4960
4961 my_get_expression (&exp, &p, GE_NO_PREFIX);
4962
4963 if (exp.X_op != O_constant)
4964 {
4965 inst.error = _("alignment must be constant");
4966 return PARSE_OPERAND_FAIL;
4967 }
4968
4969 inst.operands[i].imm = exp.X_add_number << 8;
4970 inst.operands[i].immisalign = 1;
4971 /* Alignments are not pre-indexes. */
4972 inst.operands[i].preind = 0;
4973
4974 *str = p;
4975 return PARSE_OPERAND_SUCCESS;
4976 }
4977
4978 /* Parse all forms of an ARM address expression. Information is written
4979 to inst.operands[i] and/or inst.reloc.
4980
4981 Preindexed addressing (.preind=1):
4982
4983 [Rn, #offset] .reg=Rn .reloc.exp=offset
4984 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4985 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4986 .shift_kind=shift .reloc.exp=shift_imm
4987
4988 These three may have a trailing ! which causes .writeback to be set also.
4989
4990 Postindexed addressing (.postind=1, .writeback=1):
4991
4992 [Rn], #offset .reg=Rn .reloc.exp=offset
4993 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4994 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4995 .shift_kind=shift .reloc.exp=shift_imm
4996
4997 Unindexed addressing (.preind=0, .postind=0):
4998
4999 [Rn], {option} .reg=Rn .imm=option .immisreg=0
5000
5001 Other:
5002
5003 [Rn]{!} shorthand for [Rn,#0]{!}
5004 =immediate .isreg=0 .reloc.exp=immediate
5005 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
5006
5007 It is the caller's responsibility to check for addressing modes not
5008 supported by the instruction, and to set inst.reloc.type. */
5009
5010 static parse_operand_result
5011 parse_address_main (char **str, int i, int group_relocations,
5012 group_reloc_type group_type)
5013 {
5014 char *p = *str;
5015 int reg;
5016
5017 if (skip_past_char (&p, '[') == FAIL)
5018 {
5019 if (skip_past_char (&p, '=') == FAIL)
5020 {
5021 /* Bare address - translate to PC-relative offset. */
5022 inst.reloc.pc_rel = 1;
5023 inst.operands[i].reg = REG_PC;
5024 inst.operands[i].isreg = 1;
5025 inst.operands[i].preind = 1;
5026 }
5027 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
5028
5029 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5030 return PARSE_OPERAND_FAIL;
5031
5032 *str = p;
5033 return PARSE_OPERAND_SUCCESS;
5034 }
5035
5036 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5037 {
5038 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5039 return PARSE_OPERAND_FAIL;
5040 }
5041 inst.operands[i].reg = reg;
5042 inst.operands[i].isreg = 1;
5043
5044 if (skip_past_comma (&p) == SUCCESS)
5045 {
5046 inst.operands[i].preind = 1;
5047
5048 if (*p == '+') p++;
5049 else if (*p == '-') p++, inst.operands[i].negative = 1;
5050
5051 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5052 {
5053 inst.operands[i].imm = reg;
5054 inst.operands[i].immisreg = 1;
5055
5056 if (skip_past_comma (&p) == SUCCESS)
5057 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5058 return PARSE_OPERAND_FAIL;
5059 }
5060 else if (skip_past_char (&p, ':') == SUCCESS)
5061 {
5062 /* FIXME: '@' should be used here, but it's filtered out by generic
5063 code before we get to see it here. This may be subject to
5064 change. */
5065 parse_operand_result result = parse_neon_alignment (&p, i);
5066
5067 if (result != PARSE_OPERAND_SUCCESS)
5068 return result;
5069 }
5070 else
5071 {
5072 if (inst.operands[i].negative)
5073 {
5074 inst.operands[i].negative = 0;
5075 p--;
5076 }
5077
5078 if (group_relocations
5079 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5080 {
5081 struct group_reloc_table_entry *entry;
5082
5083 /* Skip over the #: or : sequence. */
5084 if (*p == '#')
5085 p += 2;
5086 else
5087 p++;
5088
5089 /* Try to parse a group relocation. Anything else is an
5090 error. */
5091 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5092 {
5093 inst.error = _("unknown group relocation");
5094 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5095 }
5096
5097 /* We now have the group relocation table entry corresponding to
5098 the name in the assembler source. Next, we parse the
5099 expression. */
5100 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5101 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5102
5103 /* Record the relocation type. */
5104 switch (group_type)
5105 {
5106 case GROUP_LDR:
5107 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5108 break;
5109
5110 case GROUP_LDRS:
5111 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5112 break;
5113
5114 case GROUP_LDC:
5115 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5116 break;
5117
5118 default:
5119 gas_assert (0);
5120 }
5121
5122 if (inst.reloc.type == 0)
5123 {
5124 inst.error = _("this group relocation is not allowed on this instruction");
5125 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5126 }
5127 }
5128 else
5129 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5130 return PARSE_OPERAND_FAIL;
5131 }
5132 }
5133 else if (skip_past_char (&p, ':') == SUCCESS)
5134 {
5135 /* FIXME: '@' should be used here, but it's filtered out by generic code
5136 before we get to see it here. This may be subject to change. */
5137 parse_operand_result result = parse_neon_alignment (&p, i);
5138
5139 if (result != PARSE_OPERAND_SUCCESS)
5140 return result;
5141 }
5142
5143 if (skip_past_char (&p, ']') == FAIL)
5144 {
5145 inst.error = _("']' expected");
5146 return PARSE_OPERAND_FAIL;
5147 }
5148
5149 if (skip_past_char (&p, '!') == SUCCESS)
5150 inst.operands[i].writeback = 1;
5151
5152 else if (skip_past_comma (&p) == SUCCESS)
5153 {
5154 if (skip_past_char (&p, '{') == SUCCESS)
5155 {
5156 /* [Rn], {expr} - unindexed, with option */
5157 if (parse_immediate (&p, &inst.operands[i].imm,
5158 0, 255, TRUE) == FAIL)
5159 return PARSE_OPERAND_FAIL;
5160
5161 if (skip_past_char (&p, '}') == FAIL)
5162 {
5163 inst.error = _("'}' expected at end of 'option' field");
5164 return PARSE_OPERAND_FAIL;
5165 }
5166 if (inst.operands[i].preind)
5167 {
5168 inst.error = _("cannot combine index with option");
5169 return PARSE_OPERAND_FAIL;
5170 }
5171 *str = p;
5172 return PARSE_OPERAND_SUCCESS;
5173 }
5174 else
5175 {
5176 inst.operands[i].postind = 1;
5177 inst.operands[i].writeback = 1;
5178
5179 if (inst.operands[i].preind)
5180 {
5181 inst.error = _("cannot combine pre- and post-indexing");
5182 return PARSE_OPERAND_FAIL;
5183 }
5184
5185 if (*p == '+') p++;
5186 else if (*p == '-') p++, inst.operands[i].negative = 1;
5187
5188 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5189 {
5190 /* We might be using the immediate for alignment already. If we
5191 are, OR the register number into the low-order bits. */
5192 if (inst.operands[i].immisalign)
5193 inst.operands[i].imm |= reg;
5194 else
5195 inst.operands[i].imm = reg;
5196 inst.operands[i].immisreg = 1;
5197
5198 if (skip_past_comma (&p) == SUCCESS)
5199 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5200 return PARSE_OPERAND_FAIL;
5201 }
5202 else
5203 {
5204 if (inst.operands[i].negative)
5205 {
5206 inst.operands[i].negative = 0;
5207 p--;
5208 }
5209 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5210 return PARSE_OPERAND_FAIL;
5211 }
5212 }
5213 }
5214
5215 /* If at this point neither .preind nor .postind is set, we have a
5216 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5217 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5218 {
5219 inst.operands[i].preind = 1;
5220 inst.reloc.exp.X_op = O_constant;
5221 inst.reloc.exp.X_add_number = 0;
5222 }
5223 *str = p;
5224 return PARSE_OPERAND_SUCCESS;
5225 }
5226
5227 static int
5228 parse_address (char **str, int i)
5229 {
5230 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5231 ? SUCCESS : FAIL;
5232 }
5233
5234 static parse_operand_result
5235 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5236 {
5237 return parse_address_main (str, i, 1, type);
5238 }
5239
5240 /* Parse an operand for a MOVW or MOVT instruction. */
5241 static int
5242 parse_half (char **str)
5243 {
5244 char * p;
5245
5246 p = *str;
5247 skip_past_char (&p, '#');
5248 if (strncasecmp (p, ":lower16:", 9) == 0)
5249 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5250 else if (strncasecmp (p, ":upper16:", 9) == 0)
5251 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5252
5253 if (inst.reloc.type != BFD_RELOC_UNUSED)
5254 {
5255 p += 9;
5256 skip_whitespace (p);
5257 }
5258
5259 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5260 return FAIL;
5261
5262 if (inst.reloc.type == BFD_RELOC_UNUSED)
5263 {
5264 if (inst.reloc.exp.X_op != O_constant)
5265 {
5266 inst.error = _("constant expression expected");
5267 return FAIL;
5268 }
5269 if (inst.reloc.exp.X_add_number < 0
5270 || inst.reloc.exp.X_add_number > 0xffff)
5271 {
5272 inst.error = _("immediate value out of range");
5273 return FAIL;
5274 }
5275 }
5276 *str = p;
5277 return SUCCESS;
5278 }
5279
5280 /* Miscellaneous. */
5281
5282 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5283 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5284 static int
5285 parse_psr (char **str)
5286 {
5287 char *p;
5288 unsigned long psr_field;
5289 const struct asm_psr *psr;
5290 char *start;
5291
5292 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5293 feature for ease of use and backwards compatibility. */
5294 p = *str;
5295 if (strncasecmp (p, "SPSR", 4) == 0)
5296 psr_field = SPSR_BIT;
5297 else if (strncasecmp (p, "CPSR", 4) == 0)
5298 psr_field = 0;
5299 else
5300 {
5301 start = p;
5302 do
5303 p++;
5304 while (ISALNUM (*p) || *p == '_');
5305
5306 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5307 p - start);
5308 if (!psr)
5309 return FAIL;
5310
5311 *str = p;
5312 return psr->field;
5313 }
5314
5315 p += 4;
5316 if (*p == '_')
5317 {
5318 /* A suffix follows. */
5319 p++;
5320 start = p;
5321
5322 do
5323 p++;
5324 while (ISALNUM (*p) || *p == '_');
5325
5326 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5327 p - start);
5328 if (!psr)
5329 goto error;
5330
5331 psr_field |= psr->field;
5332 }
5333 else
5334 {
5335 if (ISALNUM (*p))
5336 goto error; /* Garbage after "[CS]PSR". */
5337
5338 psr_field |= (PSR_c | PSR_f);
5339 }
5340 *str = p;
5341 return psr_field;
5342
5343 error:
5344 inst.error = _("flag for {c}psr instruction expected");
5345 return FAIL;
5346 }
5347
5348 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5349 value suitable for splatting into the AIF field of the instruction. */
5350
5351 static int
5352 parse_cps_flags (char **str)
5353 {
5354 int val = 0;
5355 int saw_a_flag = 0;
5356 char *s = *str;
5357
5358 for (;;)
5359 switch (*s++)
5360 {
5361 case '\0': case ',':
5362 goto done;
5363
5364 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5365 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5366 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5367
5368 default:
5369 inst.error = _("unrecognized CPS flag");
5370 return FAIL;
5371 }
5372
5373 done:
5374 if (saw_a_flag == 0)
5375 {
5376 inst.error = _("missing CPS flags");
5377 return FAIL;
5378 }
5379
5380 *str = s - 1;
5381 return val;
5382 }
5383
5384 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5385 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5386
5387 static int
5388 parse_endian_specifier (char **str)
5389 {
5390 int little_endian;
5391 char *s = *str;
5392
5393 if (strncasecmp (s, "BE", 2))
5394 little_endian = 0;
5395 else if (strncasecmp (s, "LE", 2))
5396 little_endian = 1;
5397 else
5398 {
5399 inst.error = _("valid endian specifiers are be or le");
5400 return FAIL;
5401 }
5402
5403 if (ISALNUM (s[2]) || s[2] == '_')
5404 {
5405 inst.error = _("valid endian specifiers are be or le");
5406 return FAIL;
5407 }
5408
5409 *str = s + 2;
5410 return little_endian;
5411 }
5412
5413 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5414 value suitable for poking into the rotate field of an sxt or sxta
5415 instruction, or FAIL on error. */
5416
5417 static int
5418 parse_ror (char **str)
5419 {
5420 int rot;
5421 char *s = *str;
5422
5423 if (strncasecmp (s, "ROR", 3) == 0)
5424 s += 3;
5425 else
5426 {
5427 inst.error = _("missing rotation field after comma");
5428 return FAIL;
5429 }
5430
5431 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5432 return FAIL;
5433
5434 switch (rot)
5435 {
5436 case 0: *str = s; return 0x0;
5437 case 8: *str = s; return 0x1;
5438 case 16: *str = s; return 0x2;
5439 case 24: *str = s; return 0x3;
5440
5441 default:
5442 inst.error = _("rotation can only be 0, 8, 16, or 24");
5443 return FAIL;
5444 }
5445 }
5446
5447 /* Parse a conditional code (from conds[] below). The value returned is in the
5448 range 0 .. 14, or FAIL. */
5449 static int
5450 parse_cond (char **str)
5451 {
5452 char *q;
5453 const struct asm_cond *c;
5454 int n;
5455 /* Condition codes are always 2 characters, so matching up to
5456 3 characters is sufficient. */
5457 char cond[3];
5458
5459 q = *str;
5460 n = 0;
5461 while (ISALPHA (*q) && n < 3)
5462 {
5463 cond[n] = TOLOWER (*q);
5464 q++;
5465 n++;
5466 }
5467
5468 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5469 if (!c)
5470 {
5471 inst.error = _("condition required");
5472 return FAIL;
5473 }
5474
5475 *str = q;
5476 return c->value;
5477 }
5478
5479 /* Parse an option for a barrier instruction. Returns the encoding for the
5480 option, or FAIL. */
5481 static int
5482 parse_barrier (char **str)
5483 {
5484 char *p, *q;
5485 const struct asm_barrier_opt *o;
5486
5487 p = q = *str;
5488 while (ISALPHA (*q))
5489 q++;
5490
5491 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5492 q - p);
5493 if (!o)
5494 return FAIL;
5495
5496 *str = q;
5497 return o->value;
5498 }
5499
5500 /* Parse the operands of a table branch instruction. Similar to a memory
5501 operand. */
5502 static int
5503 parse_tb (char **str)
5504 {
5505 char * p = *str;
5506 int reg;
5507
5508 if (skip_past_char (&p, '[') == FAIL)
5509 {
5510 inst.error = _("'[' expected");
5511 return FAIL;
5512 }
5513
5514 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5515 {
5516 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5517 return FAIL;
5518 }
5519 inst.operands[0].reg = reg;
5520
5521 if (skip_past_comma (&p) == FAIL)
5522 {
5523 inst.error = _("',' expected");
5524 return FAIL;
5525 }
5526
5527 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5528 {
5529 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5530 return FAIL;
5531 }
5532 inst.operands[0].imm = reg;
5533
5534 if (skip_past_comma (&p) == SUCCESS)
5535 {
5536 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5537 return FAIL;
5538 if (inst.reloc.exp.X_add_number != 1)
5539 {
5540 inst.error = _("invalid shift");
5541 return FAIL;
5542 }
5543 inst.operands[0].shifted = 1;
5544 }
5545
5546 if (skip_past_char (&p, ']') == FAIL)
5547 {
5548 inst.error = _("']' expected");
5549 return FAIL;
5550 }
5551 *str = p;
5552 return SUCCESS;
5553 }
5554
5555 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5556 information on the types the operands can take and how they are encoded.
5557 Up to four operands may be read; this function handles setting the
5558 ".present" field for each read operand itself.
5559 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5560 else returns FAIL. */
5561
5562 static int
5563 parse_neon_mov (char **str, int *which_operand)
5564 {
5565 int i = *which_operand, val;
5566 enum arm_reg_type rtype;
5567 char *ptr = *str;
5568 struct neon_type_el optype;
5569
5570 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5571 {
5572 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5573 inst.operands[i].reg = val;
5574 inst.operands[i].isscalar = 1;
5575 inst.operands[i].vectype = optype;
5576 inst.operands[i++].present = 1;
5577
5578 if (skip_past_comma (&ptr) == FAIL)
5579 goto wanted_comma;
5580
5581 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5582 goto wanted_arm;
5583
5584 inst.operands[i].reg = val;
5585 inst.operands[i].isreg = 1;
5586 inst.operands[i].present = 1;
5587 }
5588 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5589 != FAIL)
5590 {
5591 /* Cases 0, 1, 2, 3, 5 (D only). */
5592 if (skip_past_comma (&ptr) == FAIL)
5593 goto wanted_comma;
5594
5595 inst.operands[i].reg = val;
5596 inst.operands[i].isreg = 1;
5597 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5598 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5599 inst.operands[i].isvec = 1;
5600 inst.operands[i].vectype = optype;
5601 inst.operands[i++].present = 1;
5602
5603 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5604 {
5605 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5606 Case 13: VMOV <Sd>, <Rm> */
5607 inst.operands[i].reg = val;
5608 inst.operands[i].isreg = 1;
5609 inst.operands[i].present = 1;
5610
5611 if (rtype == REG_TYPE_NQ)
5612 {
5613 first_error (_("can't use Neon quad register here"));
5614 return FAIL;
5615 }
5616 else if (rtype != REG_TYPE_VFS)
5617 {
5618 i++;
5619 if (skip_past_comma (&ptr) == FAIL)
5620 goto wanted_comma;
5621 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5622 goto wanted_arm;
5623 inst.operands[i].reg = val;
5624 inst.operands[i].isreg = 1;
5625 inst.operands[i].present = 1;
5626 }
5627 }
5628 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5629 &optype)) != FAIL)
5630 {
5631 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5632 Case 1: VMOV<c><q> <Dd>, <Dm>
5633 Case 8: VMOV.F32 <Sd>, <Sm>
5634 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5635
5636 inst.operands[i].reg = val;
5637 inst.operands[i].isreg = 1;
5638 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5639 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5640 inst.operands[i].isvec = 1;
5641 inst.operands[i].vectype = optype;
5642 inst.operands[i].present = 1;
5643
5644 if (skip_past_comma (&ptr) == SUCCESS)
5645 {
5646 /* Case 15. */
5647 i++;
5648
5649 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5650 goto wanted_arm;
5651
5652 inst.operands[i].reg = val;
5653 inst.operands[i].isreg = 1;
5654 inst.operands[i++].present = 1;
5655
5656 if (skip_past_comma (&ptr) == FAIL)
5657 goto wanted_comma;
5658
5659 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5660 goto wanted_arm;
5661
5662 inst.operands[i].reg = val;
5663 inst.operands[i].isreg = 1;
5664 inst.operands[i++].present = 1;
5665 }
5666 }
5667 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5668 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5669 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5670 Case 10: VMOV.F32 <Sd>, #<imm>
5671 Case 11: VMOV.F64 <Dd>, #<imm> */
5672 inst.operands[i].immisfloat = 1;
5673 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5674 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5675 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5676 ;
5677 else
5678 {
5679 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5680 return FAIL;
5681 }
5682 }
5683 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5684 {
5685 /* Cases 6, 7. */
5686 inst.operands[i].reg = val;
5687 inst.operands[i].isreg = 1;
5688 inst.operands[i++].present = 1;
5689
5690 if (skip_past_comma (&ptr) == FAIL)
5691 goto wanted_comma;
5692
5693 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5694 {
5695 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5696 inst.operands[i].reg = val;
5697 inst.operands[i].isscalar = 1;
5698 inst.operands[i].present = 1;
5699 inst.operands[i].vectype = optype;
5700 }
5701 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5702 {
5703 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5704 inst.operands[i].reg = val;
5705 inst.operands[i].isreg = 1;
5706 inst.operands[i++].present = 1;
5707
5708 if (skip_past_comma (&ptr) == FAIL)
5709 goto wanted_comma;
5710
5711 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5712 == FAIL)
5713 {
5714 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5715 return FAIL;
5716 }
5717
5718 inst.operands[i].reg = val;
5719 inst.operands[i].isreg = 1;
5720 inst.operands[i].isvec = 1;
5721 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5722 inst.operands[i].vectype = optype;
5723 inst.operands[i].present = 1;
5724
5725 if (rtype == REG_TYPE_VFS)
5726 {
5727 /* Case 14. */
5728 i++;
5729 if (skip_past_comma (&ptr) == FAIL)
5730 goto wanted_comma;
5731 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5732 &optype)) == FAIL)
5733 {
5734 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5735 return FAIL;
5736 }
5737 inst.operands[i].reg = val;
5738 inst.operands[i].isreg = 1;
5739 inst.operands[i].isvec = 1;
5740 inst.operands[i].issingle = 1;
5741 inst.operands[i].vectype = optype;
5742 inst.operands[i].present = 1;
5743 }
5744 }
5745 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5746 != FAIL)
5747 {
5748 /* Case 13. */
5749 inst.operands[i].reg = val;
5750 inst.operands[i].isreg = 1;
5751 inst.operands[i].isvec = 1;
5752 inst.operands[i].issingle = 1;
5753 inst.operands[i].vectype = optype;
5754 inst.operands[i++].present = 1;
5755 }
5756 }
5757 else
5758 {
5759 first_error (_("parse error"));
5760 return FAIL;
5761 }
5762
5763 /* Successfully parsed the operands. Update args. */
5764 *which_operand = i;
5765 *str = ptr;
5766 return SUCCESS;
5767
5768 wanted_comma:
5769 first_error (_("expected comma"));
5770 return FAIL;
5771
5772 wanted_arm:
5773 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5774 return FAIL;
5775 }
5776
5777 /* Use this macro when the operand constraints are different
5778 for ARM and THUMB (e.g. ldrd). */
5779 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5780 ((arm_operand) | ((thumb_operand) << 16))
5781
5782 /* Matcher codes for parse_operands. */
5783 enum operand_parse_code
5784 {
5785 OP_stop, /* end of line */
5786
5787 OP_RR, /* ARM register */
5788 OP_RRnpc, /* ARM register, not r15 */
5789 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
5790 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5791 OP_RRnpctw, /* ARM register, not r15 in Thumb-state or with writeback,
5792 optional trailing ! */
5793 OP_RRw, /* ARM register, not r15, optional trailing ! */
5794 OP_RCP, /* Coprocessor number */
5795 OP_RCN, /* Coprocessor register */
5796 OP_RF, /* FPA register */
5797 OP_RVS, /* VFP single precision register */
5798 OP_RVD, /* VFP double precision register (0..15) */
5799 OP_RND, /* Neon double precision register (0..31) */
5800 OP_RNQ, /* Neon quad precision register */
5801 OP_RVSD, /* VFP single or double precision register */
5802 OP_RNDQ, /* Neon double or quad precision register */
5803 OP_RNSDQ, /* Neon single, double or quad precision register */
5804 OP_RNSC, /* Neon scalar D[X] */
5805 OP_RVC, /* VFP control register */
5806 OP_RMF, /* Maverick F register */
5807 OP_RMD, /* Maverick D register */
5808 OP_RMFX, /* Maverick FX register */
5809 OP_RMDX, /* Maverick DX register */
5810 OP_RMAX, /* Maverick AX register */
5811 OP_RMDS, /* Maverick DSPSC register */
5812 OP_RIWR, /* iWMMXt wR register */
5813 OP_RIWC, /* iWMMXt wC register */
5814 OP_RIWG, /* iWMMXt wCG register */
5815 OP_RXA, /* XScale accumulator register */
5816
5817 OP_REGLST, /* ARM register list */
5818 OP_VRSLST, /* VFP single-precision register list */
5819 OP_VRDLST, /* VFP double-precision register list */
5820 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5821 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5822 OP_NSTRLST, /* Neon element/structure list */
5823
5824 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5825 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5826 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5827 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5828 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5829 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5830 OP_VMOV, /* Neon VMOV operands. */
5831 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5832 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5833 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5834
5835 OP_I0, /* immediate zero */
5836 OP_I7, /* immediate value 0 .. 7 */
5837 OP_I15, /* 0 .. 15 */
5838 OP_I16, /* 1 .. 16 */
5839 OP_I16z, /* 0 .. 16 */
5840 OP_I31, /* 0 .. 31 */
5841 OP_I31w, /* 0 .. 31, optional trailing ! */
5842 OP_I32, /* 1 .. 32 */
5843 OP_I32z, /* 0 .. 32 */
5844 OP_I63, /* 0 .. 63 */
5845 OP_I63s, /* -64 .. 63 */
5846 OP_I64, /* 1 .. 64 */
5847 OP_I64z, /* 0 .. 64 */
5848 OP_I255, /* 0 .. 255 */
5849
5850 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5851 OP_I7b, /* 0 .. 7 */
5852 OP_I15b, /* 0 .. 15 */
5853 OP_I31b, /* 0 .. 31 */
5854
5855 OP_SH, /* shifter operand */
5856 OP_SHG, /* shifter operand with possible group relocation */
5857 OP_ADDR, /* Memory address expression (any mode) */
5858 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5859 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5860 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5861 OP_EXP, /* arbitrary expression */
5862 OP_EXPi, /* same, with optional immediate prefix */
5863 OP_EXPr, /* same, with optional relocation suffix */
5864 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5865
5866 OP_CPSF, /* CPS flags */
5867 OP_ENDI, /* Endianness specifier */
5868 OP_PSR, /* CPSR/SPSR mask for msr */
5869 OP_COND, /* conditional code */
5870 OP_TB, /* Table branch. */
5871
5872 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5873 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5874
5875 OP_RRnpc_I0, /* ARM register or literal 0 */
5876 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5877 OP_RR_EXi, /* ARM register or expression with imm prefix */
5878 OP_RF_IF, /* FPA register or immediate */
5879 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5880 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5881
5882 /* Optional operands. */
5883 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5884 OP_oI31b, /* 0 .. 31 */
5885 OP_oI32b, /* 1 .. 32 */
5886 OP_oIffffb, /* 0 .. 65535 */
5887 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5888
5889 OP_oRR, /* ARM register */
5890 OP_oRRnpc, /* ARM register, not the PC */
5891 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
5892 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5893 OP_oRND, /* Optional Neon double precision register */
5894 OP_oRNQ, /* Optional Neon quad precision register */
5895 OP_oRNDQ, /* Optional Neon double or quad precision register */
5896 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5897 OP_oSHll, /* LSL immediate */
5898 OP_oSHar, /* ASR immediate */
5899 OP_oSHllar, /* LSL or ASR immediate */
5900 OP_oROR, /* ROR 0/8/16/24 */
5901 OP_oBARRIER_I15, /* Option argument for a barrier instruction. */
5902
5903 /* Some pre-defined mixed (ARM/THUMB) operands. */
5904 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5905 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5906 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5907
5908 OP_FIRST_OPTIONAL = OP_oI7b
5909 };
5910
5911 /* Generic instruction operand parser. This does no encoding and no
5912 semantic validation; it merely squirrels values away in the inst
5913 structure. Returns SUCCESS or FAIL depending on whether the
5914 specified grammar matched. */
5915 static int
5916 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
5917 {
5918 unsigned const int *upat = pattern;
5919 char *backtrack_pos = 0;
5920 const char *backtrack_error = 0;
5921 int i, val, backtrack_index = 0;
5922 enum arm_reg_type rtype;
5923 parse_operand_result result;
5924 unsigned int op_parse_code;
5925
5926 #define po_char_or_fail(chr) \
5927 do \
5928 { \
5929 if (skip_past_char (&str, chr) == FAIL) \
5930 goto bad_args; \
5931 } \
5932 while (0)
5933
5934 #define po_reg_or_fail(regtype) \
5935 do \
5936 { \
5937 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5938 & inst.operands[i].vectype); \
5939 if (val == FAIL) \
5940 { \
5941 first_error (_(reg_expected_msgs[regtype])); \
5942 goto failure; \
5943 } \
5944 inst.operands[i].reg = val; \
5945 inst.operands[i].isreg = 1; \
5946 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5947 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5948 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5949 || rtype == REG_TYPE_VFD \
5950 || rtype == REG_TYPE_NQ); \
5951 } \
5952 while (0)
5953
5954 #define po_reg_or_goto(regtype, label) \
5955 do \
5956 { \
5957 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5958 & inst.operands[i].vectype); \
5959 if (val == FAIL) \
5960 goto label; \
5961 \
5962 inst.operands[i].reg = val; \
5963 inst.operands[i].isreg = 1; \
5964 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5965 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5966 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5967 || rtype == REG_TYPE_VFD \
5968 || rtype == REG_TYPE_NQ); \
5969 } \
5970 while (0)
5971
5972 #define po_imm_or_fail(min, max, popt) \
5973 do \
5974 { \
5975 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5976 goto failure; \
5977 inst.operands[i].imm = val; \
5978 } \
5979 while (0)
5980
5981 #define po_scalar_or_goto(elsz, label) \
5982 do \
5983 { \
5984 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5985 if (val == FAIL) \
5986 goto label; \
5987 inst.operands[i].reg = val; \
5988 inst.operands[i].isscalar = 1; \
5989 } \
5990 while (0)
5991
5992 #define po_misc_or_fail(expr) \
5993 do \
5994 { \
5995 if (expr) \
5996 goto failure; \
5997 } \
5998 while (0)
5999
6000 #define po_misc_or_fail_no_backtrack(expr) \
6001 do \
6002 { \
6003 result = expr; \
6004 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
6005 backtrack_pos = 0; \
6006 if (result != PARSE_OPERAND_SUCCESS) \
6007 goto failure; \
6008 } \
6009 while (0)
6010
6011 #define po_barrier_or_imm(str) \
6012 do \
6013 { \
6014 val = parse_barrier (&str); \
6015 if (val == FAIL) \
6016 { \
6017 if (ISALPHA (*str)) \
6018 goto failure; \
6019 else \
6020 goto immediate; \
6021 } \
6022 else \
6023 { \
6024 if ((inst.instruction & 0xf0) == 0x60 \
6025 && val != 0xf) \
6026 { \
6027 /* ISB can only take SY as an option. */ \
6028 inst.error = _("invalid barrier type"); \
6029 goto failure; \
6030 } \
6031 } \
6032 } \
6033 while (0)
6034
6035 skip_whitespace (str);
6036
6037 for (i = 0; upat[i] != OP_stop; i++)
6038 {
6039 op_parse_code = upat[i];
6040 if (op_parse_code >= 1<<16)
6041 op_parse_code = thumb ? (op_parse_code >> 16)
6042 : (op_parse_code & ((1<<16)-1));
6043
6044 if (op_parse_code >= OP_FIRST_OPTIONAL)
6045 {
6046 /* Remember where we are in case we need to backtrack. */
6047 gas_assert (!backtrack_pos);
6048 backtrack_pos = str;
6049 backtrack_error = inst.error;
6050 backtrack_index = i;
6051 }
6052
6053 if (i > 0 && (i > 1 || inst.operands[0].present))
6054 po_char_or_fail (',');
6055
6056 switch (op_parse_code)
6057 {
6058 /* Registers */
6059 case OP_oRRnpc:
6060 case OP_oRRnpcsp:
6061 case OP_RRnpc:
6062 case OP_RRnpcsp:
6063 case OP_oRR:
6064 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6065 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6066 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6067 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6068 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6069 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6070 case OP_oRND:
6071 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6072 case OP_RVC:
6073 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6074 break;
6075 /* Also accept generic coprocessor regs for unknown registers. */
6076 coproc_reg:
6077 po_reg_or_fail (REG_TYPE_CN);
6078 break;
6079 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6080 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6081 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6082 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6083 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6084 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6085 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6086 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6087 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6088 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6089 case OP_oRNQ:
6090 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6091 case OP_oRNDQ:
6092 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6093 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6094 case OP_oRNSDQ:
6095 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6096
6097 /* Neon scalar. Using an element size of 8 means that some invalid
6098 scalars are accepted here, so deal with those in later code. */
6099 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6100
6101 case OP_RNDQ_I0:
6102 {
6103 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6104 break;
6105 try_imm0:
6106 po_imm_or_fail (0, 0, TRUE);
6107 }
6108 break;
6109
6110 case OP_RVSD_I0:
6111 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6112 break;
6113
6114 case OP_RR_RNSC:
6115 {
6116 po_scalar_or_goto (8, try_rr);
6117 break;
6118 try_rr:
6119 po_reg_or_fail (REG_TYPE_RN);
6120 }
6121 break;
6122
6123 case OP_RNSDQ_RNSC:
6124 {
6125 po_scalar_or_goto (8, try_nsdq);
6126 break;
6127 try_nsdq:
6128 po_reg_or_fail (REG_TYPE_NSDQ);
6129 }
6130 break;
6131
6132 case OP_RNDQ_RNSC:
6133 {
6134 po_scalar_or_goto (8, try_ndq);
6135 break;
6136 try_ndq:
6137 po_reg_or_fail (REG_TYPE_NDQ);
6138 }
6139 break;
6140
6141 case OP_RND_RNSC:
6142 {
6143 po_scalar_or_goto (8, try_vfd);
6144 break;
6145 try_vfd:
6146 po_reg_or_fail (REG_TYPE_VFD);
6147 }
6148 break;
6149
6150 case OP_VMOV:
6151 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6152 not careful then bad things might happen. */
6153 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6154 break;
6155
6156 case OP_RNDQ_Ibig:
6157 {
6158 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6159 break;
6160 try_immbig:
6161 /* There's a possibility of getting a 64-bit immediate here, so
6162 we need special handling. */
6163 if (parse_big_immediate (&str, i) == FAIL)
6164 {
6165 inst.error = _("immediate value is out of range");
6166 goto failure;
6167 }
6168 }
6169 break;
6170
6171 case OP_RNDQ_I63b:
6172 {
6173 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6174 break;
6175 try_shimm:
6176 po_imm_or_fail (0, 63, TRUE);
6177 }
6178 break;
6179
6180 case OP_RRnpcb:
6181 po_char_or_fail ('[');
6182 po_reg_or_fail (REG_TYPE_RN);
6183 po_char_or_fail (']');
6184 break;
6185
6186 case OP_RRnpctw:
6187 case OP_RRw:
6188 case OP_oRRw:
6189 po_reg_or_fail (REG_TYPE_RN);
6190 if (skip_past_char (&str, '!') == SUCCESS)
6191 inst.operands[i].writeback = 1;
6192 break;
6193
6194 /* Immediates */
6195 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6196 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6197 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6198 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6199 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6200 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6201 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6202 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6203 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6204 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6205 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6206 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6207
6208 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6209 case OP_oI7b:
6210 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6211 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6212 case OP_oI31b:
6213 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6214 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6215 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6216
6217 /* Immediate variants */
6218 case OP_oI255c:
6219 po_char_or_fail ('{');
6220 po_imm_or_fail (0, 255, TRUE);
6221 po_char_or_fail ('}');
6222 break;
6223
6224 case OP_I31w:
6225 /* The expression parser chokes on a trailing !, so we have
6226 to find it first and zap it. */
6227 {
6228 char *s = str;
6229 while (*s && *s != ',')
6230 s++;
6231 if (s[-1] == '!')
6232 {
6233 s[-1] = '\0';
6234 inst.operands[i].writeback = 1;
6235 }
6236 po_imm_or_fail (0, 31, TRUE);
6237 if (str == s - 1)
6238 str = s;
6239 }
6240 break;
6241
6242 /* Expressions */
6243 case OP_EXPi: EXPi:
6244 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6245 GE_OPT_PREFIX));
6246 break;
6247
6248 case OP_EXP:
6249 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6250 GE_NO_PREFIX));
6251 break;
6252
6253 case OP_EXPr: EXPr:
6254 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6255 GE_NO_PREFIX));
6256 if (inst.reloc.exp.X_op == O_symbol)
6257 {
6258 val = parse_reloc (&str);
6259 if (val == -1)
6260 {
6261 inst.error = _("unrecognized relocation suffix");
6262 goto failure;
6263 }
6264 else if (val != BFD_RELOC_UNUSED)
6265 {
6266 inst.operands[i].imm = val;
6267 inst.operands[i].hasreloc = 1;
6268 }
6269 }
6270 break;
6271
6272 /* Operand for MOVW or MOVT. */
6273 case OP_HALF:
6274 po_misc_or_fail (parse_half (&str));
6275 break;
6276
6277 /* Register or expression. */
6278 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6279 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6280
6281 /* Register or immediate. */
6282 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6283 I0: po_imm_or_fail (0, 0, FALSE); break;
6284
6285 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6286 IF:
6287 if (!is_immediate_prefix (*str))
6288 goto bad_args;
6289 str++;
6290 val = parse_fpa_immediate (&str);
6291 if (val == FAIL)
6292 goto failure;
6293 /* FPA immediates are encoded as registers 8-15.
6294 parse_fpa_immediate has already applied the offset. */
6295 inst.operands[i].reg = val;
6296 inst.operands[i].isreg = 1;
6297 break;
6298
6299 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6300 I32z: po_imm_or_fail (0, 32, FALSE); break;
6301
6302 /* Two kinds of register. */
6303 case OP_RIWR_RIWC:
6304 {
6305 struct reg_entry *rege = arm_reg_parse_multi (&str);
6306 if (!rege
6307 || (rege->type != REG_TYPE_MMXWR
6308 && rege->type != REG_TYPE_MMXWC
6309 && rege->type != REG_TYPE_MMXWCG))
6310 {
6311 inst.error = _("iWMMXt data or control register expected");
6312 goto failure;
6313 }
6314 inst.operands[i].reg = rege->number;
6315 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6316 }
6317 break;
6318
6319 case OP_RIWC_RIWG:
6320 {
6321 struct reg_entry *rege = arm_reg_parse_multi (&str);
6322 if (!rege
6323 || (rege->type != REG_TYPE_MMXWC
6324 && rege->type != REG_TYPE_MMXWCG))
6325 {
6326 inst.error = _("iWMMXt control register expected");
6327 goto failure;
6328 }
6329 inst.operands[i].reg = rege->number;
6330 inst.operands[i].isreg = 1;
6331 }
6332 break;
6333
6334 /* Misc */
6335 case OP_CPSF: val = parse_cps_flags (&str); break;
6336 case OP_ENDI: val = parse_endian_specifier (&str); break;
6337 case OP_oROR: val = parse_ror (&str); break;
6338 case OP_PSR: val = parse_psr (&str); break;
6339 case OP_COND: val = parse_cond (&str); break;
6340 case OP_oBARRIER_I15:
6341 po_barrier_or_imm (str); break;
6342 immediate:
6343 if (parse_immediate (&str, &val, 0, 15, TRUE) == FAIL)
6344 goto failure;
6345 break;
6346
6347 case OP_RVC_PSR:
6348 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6349 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6350 break;
6351 try_psr:
6352 val = parse_psr (&str);
6353 break;
6354
6355 case OP_APSR_RR:
6356 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6357 break;
6358 try_apsr:
6359 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6360 instruction). */
6361 if (strncasecmp (str, "APSR_", 5) == 0)
6362 {
6363 unsigned found = 0;
6364 str += 5;
6365 while (found < 15)
6366 switch (*str++)
6367 {
6368 case 'c': found = (found & 1) ? 16 : found | 1; break;
6369 case 'n': found = (found & 2) ? 16 : found | 2; break;
6370 case 'z': found = (found & 4) ? 16 : found | 4; break;
6371 case 'v': found = (found & 8) ? 16 : found | 8; break;
6372 default: found = 16;
6373 }
6374 if (found != 15)
6375 goto failure;
6376 inst.operands[i].isvec = 1;
6377 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6378 inst.operands[i].reg = REG_PC;
6379 }
6380 else
6381 goto failure;
6382 break;
6383
6384 case OP_TB:
6385 po_misc_or_fail (parse_tb (&str));
6386 break;
6387
6388 /* Register lists. */
6389 case OP_REGLST:
6390 val = parse_reg_list (&str);
6391 if (*str == '^')
6392 {
6393 inst.operands[1].writeback = 1;
6394 str++;
6395 }
6396 break;
6397
6398 case OP_VRSLST:
6399 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6400 break;
6401
6402 case OP_VRDLST:
6403 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6404 break;
6405
6406 case OP_VRSDLST:
6407 /* Allow Q registers too. */
6408 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6409 REGLIST_NEON_D);
6410 if (val == FAIL)
6411 {
6412 inst.error = NULL;
6413 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6414 REGLIST_VFP_S);
6415 inst.operands[i].issingle = 1;
6416 }
6417 break;
6418
6419 case OP_NRDLST:
6420 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6421 REGLIST_NEON_D);
6422 break;
6423
6424 case OP_NSTRLST:
6425 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6426 &inst.operands[i].vectype);
6427 break;
6428
6429 /* Addressing modes */
6430 case OP_ADDR:
6431 po_misc_or_fail (parse_address (&str, i));
6432 break;
6433
6434 case OP_ADDRGLDR:
6435 po_misc_or_fail_no_backtrack (
6436 parse_address_group_reloc (&str, i, GROUP_LDR));
6437 break;
6438
6439 case OP_ADDRGLDRS:
6440 po_misc_or_fail_no_backtrack (
6441 parse_address_group_reloc (&str, i, GROUP_LDRS));
6442 break;
6443
6444 case OP_ADDRGLDC:
6445 po_misc_or_fail_no_backtrack (
6446 parse_address_group_reloc (&str, i, GROUP_LDC));
6447 break;
6448
6449 case OP_SH:
6450 po_misc_or_fail (parse_shifter_operand (&str, i));
6451 break;
6452
6453 case OP_SHG:
6454 po_misc_or_fail_no_backtrack (
6455 parse_shifter_operand_group_reloc (&str, i));
6456 break;
6457
6458 case OP_oSHll:
6459 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6460 break;
6461
6462 case OP_oSHar:
6463 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6464 break;
6465
6466 case OP_oSHllar:
6467 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6468 break;
6469
6470 default:
6471 as_fatal (_("unhandled operand code %d"), op_parse_code);
6472 }
6473
6474 /* Various value-based sanity checks and shared operations. We
6475 do not signal immediate failures for the register constraints;
6476 this allows a syntax error to take precedence. */
6477 switch (op_parse_code)
6478 {
6479 case OP_oRRnpc:
6480 case OP_RRnpc:
6481 case OP_RRnpcb:
6482 case OP_RRw:
6483 case OP_oRRw:
6484 case OP_RRnpc_I0:
6485 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6486 inst.error = BAD_PC;
6487 break;
6488
6489 case OP_oRRnpcsp:
6490 case OP_RRnpcsp:
6491 if (inst.operands[i].isreg)
6492 {
6493 if (inst.operands[i].reg == REG_PC)
6494 inst.error = BAD_PC;
6495 else if (inst.operands[i].reg == REG_SP)
6496 inst.error = BAD_SP;
6497 }
6498 break;
6499
6500 case OP_RRnpctw:
6501 if (inst.operands[i].isreg
6502 && inst.operands[i].reg == REG_PC
6503 && (inst.operands[i].writeback || thumb))
6504 inst.error = BAD_PC;
6505 break;
6506
6507 case OP_CPSF:
6508 case OP_ENDI:
6509 case OP_oROR:
6510 case OP_PSR:
6511 case OP_RVC_PSR:
6512 case OP_COND:
6513 case OP_oBARRIER_I15:
6514 case OP_REGLST:
6515 case OP_VRSLST:
6516 case OP_VRDLST:
6517 case OP_VRSDLST:
6518 case OP_NRDLST:
6519 case OP_NSTRLST:
6520 if (val == FAIL)
6521 goto failure;
6522 inst.operands[i].imm = val;
6523 break;
6524
6525 default:
6526 break;
6527 }
6528
6529 /* If we get here, this operand was successfully parsed. */
6530 inst.operands[i].present = 1;
6531 continue;
6532
6533 bad_args:
6534 inst.error = BAD_ARGS;
6535
6536 failure:
6537 if (!backtrack_pos)
6538 {
6539 /* The parse routine should already have set inst.error, but set a
6540 default here just in case. */
6541 if (!inst.error)
6542 inst.error = _("syntax error");
6543 return FAIL;
6544 }
6545
6546 /* Do not backtrack over a trailing optional argument that
6547 absorbed some text. We will only fail again, with the
6548 'garbage following instruction' error message, which is
6549 probably less helpful than the current one. */
6550 if (backtrack_index == i && backtrack_pos != str
6551 && upat[i+1] == OP_stop)
6552 {
6553 if (!inst.error)
6554 inst.error = _("syntax error");
6555 return FAIL;
6556 }
6557
6558 /* Try again, skipping the optional argument at backtrack_pos. */
6559 str = backtrack_pos;
6560 inst.error = backtrack_error;
6561 inst.operands[backtrack_index].present = 0;
6562 i = backtrack_index;
6563 backtrack_pos = 0;
6564 }
6565
6566 /* Check that we have parsed all the arguments. */
6567 if (*str != '\0' && !inst.error)
6568 inst.error = _("garbage following instruction");
6569
6570 return inst.error ? FAIL : SUCCESS;
6571 }
6572
6573 #undef po_char_or_fail
6574 #undef po_reg_or_fail
6575 #undef po_reg_or_goto
6576 #undef po_imm_or_fail
6577 #undef po_scalar_or_fail
6578 #undef po_barrier_or_imm
6579
6580 /* Shorthand macro for instruction encoding functions issuing errors. */
6581 #define constraint(expr, err) \
6582 do \
6583 { \
6584 if (expr) \
6585 { \
6586 inst.error = err; \
6587 return; \
6588 } \
6589 } \
6590 while (0)
6591
6592 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6593 instructions are unpredictable if these registers are used. This
6594 is the BadReg predicate in ARM's Thumb-2 documentation. */
6595 #define reject_bad_reg(reg) \
6596 do \
6597 if (reg == REG_SP || reg == REG_PC) \
6598 { \
6599 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6600 return; \
6601 } \
6602 while (0)
6603
6604 /* If REG is R13 (the stack pointer), warn that its use is
6605 deprecated. */
6606 #define warn_deprecated_sp(reg) \
6607 do \
6608 if (warn_on_deprecated && reg == REG_SP) \
6609 as_warn (_("use of r13 is deprecated")); \
6610 while (0)
6611
6612 /* Functions for operand encoding. ARM, then Thumb. */
6613
6614 #define rotate_left(v, n) (v << n | v >> (32 - n))
6615
6616 /* If VAL can be encoded in the immediate field of an ARM instruction,
6617 return the encoded form. Otherwise, return FAIL. */
6618
6619 static unsigned int
6620 encode_arm_immediate (unsigned int val)
6621 {
6622 unsigned int a, i;
6623
6624 for (i = 0; i < 32; i += 2)
6625 if ((a = rotate_left (val, i)) <= 0xff)
6626 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6627
6628 return FAIL;
6629 }
6630
6631 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6632 return the encoded form. Otherwise, return FAIL. */
6633 static unsigned int
6634 encode_thumb32_immediate (unsigned int val)
6635 {
6636 unsigned int a, i;
6637
6638 if (val <= 0xff)
6639 return val;
6640
6641 for (i = 1; i <= 24; i++)
6642 {
6643 a = val >> i;
6644 if ((val & ~(0xff << i)) == 0)
6645 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6646 }
6647
6648 a = val & 0xff;
6649 if (val == ((a << 16) | a))
6650 return 0x100 | a;
6651 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6652 return 0x300 | a;
6653
6654 a = val & 0xff00;
6655 if (val == ((a << 16) | a))
6656 return 0x200 | (a >> 8);
6657
6658 return FAIL;
6659 }
6660 /* Encode a VFP SP or DP register number into inst.instruction. */
6661
6662 static void
6663 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6664 {
6665 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6666 && reg > 15)
6667 {
6668 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6669 {
6670 if (thumb_mode)
6671 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6672 fpu_vfp_ext_d32);
6673 else
6674 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6675 fpu_vfp_ext_d32);
6676 }
6677 else
6678 {
6679 first_error (_("D register out of range for selected VFP version"));
6680 return;
6681 }
6682 }
6683
6684 switch (pos)
6685 {
6686 case VFP_REG_Sd:
6687 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6688 break;
6689
6690 case VFP_REG_Sn:
6691 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6692 break;
6693
6694 case VFP_REG_Sm:
6695 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6696 break;
6697
6698 case VFP_REG_Dd:
6699 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6700 break;
6701
6702 case VFP_REG_Dn:
6703 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6704 break;
6705
6706 case VFP_REG_Dm:
6707 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6708 break;
6709
6710 default:
6711 abort ();
6712 }
6713 }
6714
6715 /* Encode a <shift> in an ARM-format instruction. The immediate,
6716 if any, is handled by md_apply_fix. */
6717 static void
6718 encode_arm_shift (int i)
6719 {
6720 if (inst.operands[i].shift_kind == SHIFT_RRX)
6721 inst.instruction |= SHIFT_ROR << 5;
6722 else
6723 {
6724 inst.instruction |= inst.operands[i].shift_kind << 5;
6725 if (inst.operands[i].immisreg)
6726 {
6727 inst.instruction |= SHIFT_BY_REG;
6728 inst.instruction |= inst.operands[i].imm << 8;
6729 }
6730 else
6731 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6732 }
6733 }
6734
6735 static void
6736 encode_arm_shifter_operand (int i)
6737 {
6738 if (inst.operands[i].isreg)
6739 {
6740 inst.instruction |= inst.operands[i].reg;
6741 encode_arm_shift (i);
6742 }
6743 else
6744 inst.instruction |= INST_IMMEDIATE;
6745 }
6746
6747 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6748 static void
6749 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6750 {
6751 gas_assert (inst.operands[i].isreg);
6752 inst.instruction |= inst.operands[i].reg << 16;
6753
6754 if (inst.operands[i].preind)
6755 {
6756 if (is_t)
6757 {
6758 inst.error = _("instruction does not accept preindexed addressing");
6759 return;
6760 }
6761 inst.instruction |= PRE_INDEX;
6762 if (inst.operands[i].writeback)
6763 inst.instruction |= WRITE_BACK;
6764
6765 }
6766 else if (inst.operands[i].postind)
6767 {
6768 gas_assert (inst.operands[i].writeback);
6769 if (is_t)
6770 inst.instruction |= WRITE_BACK;
6771 }
6772 else /* unindexed - only for coprocessor */
6773 {
6774 inst.error = _("instruction does not accept unindexed addressing");
6775 return;
6776 }
6777
6778 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6779 && (((inst.instruction & 0x000f0000) >> 16)
6780 == ((inst.instruction & 0x0000f000) >> 12)))
6781 as_warn ((inst.instruction & LOAD_BIT)
6782 ? _("destination register same as write-back base")
6783 : _("source register same as write-back base"));
6784 }
6785
6786 /* inst.operands[i] was set up by parse_address. Encode it into an
6787 ARM-format mode 2 load or store instruction. If is_t is true,
6788 reject forms that cannot be used with a T instruction (i.e. not
6789 post-indexed). */
6790 static void
6791 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6792 {
6793 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6794
6795 encode_arm_addr_mode_common (i, is_t);
6796
6797 if (inst.operands[i].immisreg)
6798 {
6799 constraint ((inst.operands[i].imm == REG_PC
6800 || (is_pc && inst.operands[i].writeback)),
6801 BAD_PC_ADDRESSING);
6802 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6803 inst.instruction |= inst.operands[i].imm;
6804 if (!inst.operands[i].negative)
6805 inst.instruction |= INDEX_UP;
6806 if (inst.operands[i].shifted)
6807 {
6808 if (inst.operands[i].shift_kind == SHIFT_RRX)
6809 inst.instruction |= SHIFT_ROR << 5;
6810 else
6811 {
6812 inst.instruction |= inst.operands[i].shift_kind << 5;
6813 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6814 }
6815 }
6816 }
6817 else /* immediate offset in inst.reloc */
6818 {
6819 if (is_pc && !inst.reloc.pc_rel)
6820 {
6821 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
6822 /* BAD_PC_ADDRESSING Condition =
6823 is_load => is_t
6824 which becomes !is_load || is_t. */
6825 constraint ((!is_load || is_t),
6826 BAD_PC_ADDRESSING);
6827 }
6828
6829 if (inst.reloc.type == BFD_RELOC_UNUSED)
6830 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6831 }
6832 }
6833
6834 /* inst.operands[i] was set up by parse_address. Encode it into an
6835 ARM-format mode 3 load or store instruction. Reject forms that
6836 cannot be used with such instructions. If is_t is true, reject
6837 forms that cannot be used with a T instruction (i.e. not
6838 post-indexed). */
6839 static void
6840 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6841 {
6842 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6843 {
6844 inst.error = _("instruction does not accept scaled register index");
6845 return;
6846 }
6847
6848 encode_arm_addr_mode_common (i, is_t);
6849
6850 if (inst.operands[i].immisreg)
6851 {
6852 constraint ((inst.operands[i].imm == REG_PC
6853 || inst.operands[i].reg == REG_PC),
6854 BAD_PC_ADDRESSING);
6855 inst.instruction |= inst.operands[i].imm;
6856 if (!inst.operands[i].negative)
6857 inst.instruction |= INDEX_UP;
6858 }
6859 else /* immediate offset in inst.reloc */
6860 {
6861 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6862 && inst.operands[i].writeback),
6863 BAD_PC_WRITEBACK);
6864 inst.instruction |= HWOFFSET_IMM;
6865 if (inst.reloc.type == BFD_RELOC_UNUSED)
6866 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6867 }
6868 }
6869
6870 /* inst.operands[i] was set up by parse_address. Encode it into an
6871 ARM-format instruction. Reject all forms which cannot be encoded
6872 into a coprocessor load/store instruction. If wb_ok is false,
6873 reject use of writeback; if unind_ok is false, reject use of
6874 unindexed addressing. If reloc_override is not 0, use it instead
6875 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6876 (in which case it is preserved). */
6877
6878 static int
6879 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6880 {
6881 inst.instruction |= inst.operands[i].reg << 16;
6882
6883 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
6884
6885 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6886 {
6887 gas_assert (!inst.operands[i].writeback);
6888 if (!unind_ok)
6889 {
6890 inst.error = _("instruction does not support unindexed addressing");
6891 return FAIL;
6892 }
6893 inst.instruction |= inst.operands[i].imm;
6894 inst.instruction |= INDEX_UP;
6895 return SUCCESS;
6896 }
6897
6898 if (inst.operands[i].preind)
6899 inst.instruction |= PRE_INDEX;
6900
6901 if (inst.operands[i].writeback)
6902 {
6903 if (inst.operands[i].reg == REG_PC)
6904 {
6905 inst.error = _("pc may not be used with write-back");
6906 return FAIL;
6907 }
6908 if (!wb_ok)
6909 {
6910 inst.error = _("instruction does not support writeback");
6911 return FAIL;
6912 }
6913 inst.instruction |= WRITE_BACK;
6914 }
6915
6916 if (reloc_override)
6917 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
6918 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6919 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6920 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6921 {
6922 if (thumb_mode)
6923 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6924 else
6925 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6926 }
6927
6928 return SUCCESS;
6929 }
6930
6931 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6932 Determine whether it can be performed with a move instruction; if
6933 it can, convert inst.instruction to that move instruction and
6934 return TRUE; if it can't, convert inst.instruction to a literal-pool
6935 load and return FALSE. If this is not a valid thing to do in the
6936 current context, set inst.error and return TRUE.
6937
6938 inst.operands[i] describes the destination register. */
6939
6940 static bfd_boolean
6941 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6942 {
6943 unsigned long tbit;
6944
6945 if (thumb_p)
6946 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6947 else
6948 tbit = LOAD_BIT;
6949
6950 if ((inst.instruction & tbit) == 0)
6951 {
6952 inst.error = _("invalid pseudo operation");
6953 return TRUE;
6954 }
6955 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6956 {
6957 inst.error = _("constant expression expected");
6958 return TRUE;
6959 }
6960 if (inst.reloc.exp.X_op == O_constant)
6961 {
6962 if (thumb_p)
6963 {
6964 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6965 {
6966 /* This can be done with a mov(1) instruction. */
6967 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6968 inst.instruction |= inst.reloc.exp.X_add_number;
6969 return TRUE;
6970 }
6971 }
6972 else
6973 {
6974 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6975 if (value != FAIL)
6976 {
6977 /* This can be done with a mov instruction. */
6978 inst.instruction &= LITERAL_MASK;
6979 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6980 inst.instruction |= value & 0xfff;
6981 return TRUE;
6982 }
6983
6984 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6985 if (value != FAIL)
6986 {
6987 /* This can be done with a mvn instruction. */
6988 inst.instruction &= LITERAL_MASK;
6989 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6990 inst.instruction |= value & 0xfff;
6991 return TRUE;
6992 }
6993 }
6994 }
6995
6996 if (add_to_lit_pool () == FAIL)
6997 {
6998 inst.error = _("literal pool insertion failed");
6999 return TRUE;
7000 }
7001 inst.operands[1].reg = REG_PC;
7002 inst.operands[1].isreg = 1;
7003 inst.operands[1].preind = 1;
7004 inst.reloc.pc_rel = 1;
7005 inst.reloc.type = (thumb_p
7006 ? BFD_RELOC_ARM_THUMB_OFFSET
7007 : (mode_3
7008 ? BFD_RELOC_ARM_HWLITERAL
7009 : BFD_RELOC_ARM_LITERAL));
7010 return FALSE;
7011 }
7012
7013 /* Functions for instruction encoding, sorted by sub-architecture.
7014 First some generics; their names are taken from the conventional
7015 bit positions for register arguments in ARM format instructions. */
7016
7017 static void
7018 do_noargs (void)
7019 {
7020 }
7021
7022 static void
7023 do_rd (void)
7024 {
7025 inst.instruction |= inst.operands[0].reg << 12;
7026 }
7027
7028 static void
7029 do_rd_rm (void)
7030 {
7031 inst.instruction |= inst.operands[0].reg << 12;
7032 inst.instruction |= inst.operands[1].reg;
7033 }
7034
7035 static void
7036 do_rd_rn (void)
7037 {
7038 inst.instruction |= inst.operands[0].reg << 12;
7039 inst.instruction |= inst.operands[1].reg << 16;
7040 }
7041
7042 static void
7043 do_rn_rd (void)
7044 {
7045 inst.instruction |= inst.operands[0].reg << 16;
7046 inst.instruction |= inst.operands[1].reg << 12;
7047 }
7048
7049 static void
7050 do_rd_rm_rn (void)
7051 {
7052 unsigned Rn = inst.operands[2].reg;
7053 /* Enforce restrictions on SWP instruction. */
7054 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
7055 {
7056 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
7057 _("Rn must not overlap other operands"));
7058
7059 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
7060 if (warn_on_deprecated
7061 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7062 as_warn (_("swp{b} use is deprecated for this architecture"));
7063
7064 }
7065 inst.instruction |= inst.operands[0].reg << 12;
7066 inst.instruction |= inst.operands[1].reg;
7067 inst.instruction |= Rn << 16;
7068 }
7069
7070 static void
7071 do_rd_rn_rm (void)
7072 {
7073 inst.instruction |= inst.operands[0].reg << 12;
7074 inst.instruction |= inst.operands[1].reg << 16;
7075 inst.instruction |= inst.operands[2].reg;
7076 }
7077
7078 static void
7079 do_rm_rd_rn (void)
7080 {
7081 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7082 constraint (((inst.reloc.exp.X_op != O_constant
7083 && inst.reloc.exp.X_op != O_illegal)
7084 || inst.reloc.exp.X_add_number != 0),
7085 BAD_ADDR_MODE);
7086 inst.instruction |= inst.operands[0].reg;
7087 inst.instruction |= inst.operands[1].reg << 12;
7088 inst.instruction |= inst.operands[2].reg << 16;
7089 }
7090
7091 static void
7092 do_imm0 (void)
7093 {
7094 inst.instruction |= inst.operands[0].imm;
7095 }
7096
7097 static void
7098 do_rd_cpaddr (void)
7099 {
7100 inst.instruction |= inst.operands[0].reg << 12;
7101 encode_arm_cp_address (1, TRUE, TRUE, 0);
7102 }
7103
7104 /* ARM instructions, in alphabetical order by function name (except
7105 that wrapper functions appear immediately after the function they
7106 wrap). */
7107
7108 /* This is a pseudo-op of the form "adr rd, label" to be converted
7109 into a relative address of the form "add rd, pc, #label-.-8". */
7110
7111 static void
7112 do_adr (void)
7113 {
7114 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7115
7116 /* Frag hacking will turn this into a sub instruction if the offset turns
7117 out to be negative. */
7118 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7119 inst.reloc.pc_rel = 1;
7120 inst.reloc.exp.X_add_number -= 8;
7121 }
7122
7123 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7124 into a relative address of the form:
7125 add rd, pc, #low(label-.-8)"
7126 add rd, rd, #high(label-.-8)" */
7127
7128 static void
7129 do_adrl (void)
7130 {
7131 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7132
7133 /* Frag hacking will turn this into a sub instruction if the offset turns
7134 out to be negative. */
7135 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7136 inst.reloc.pc_rel = 1;
7137 inst.size = INSN_SIZE * 2;
7138 inst.reloc.exp.X_add_number -= 8;
7139 }
7140
7141 static void
7142 do_arit (void)
7143 {
7144 if (!inst.operands[1].present)
7145 inst.operands[1].reg = inst.operands[0].reg;
7146 inst.instruction |= inst.operands[0].reg << 12;
7147 inst.instruction |= inst.operands[1].reg << 16;
7148 encode_arm_shifter_operand (2);
7149 }
7150
7151 static void
7152 do_barrier (void)
7153 {
7154 if (inst.operands[0].present)
7155 {
7156 constraint ((inst.instruction & 0xf0) != 0x40
7157 && inst.operands[0].imm > 0xf
7158 && inst.operands[0].imm < 0x0,
7159 _("bad barrier type"));
7160 inst.instruction |= inst.operands[0].imm;
7161 }
7162 else
7163 inst.instruction |= 0xf;
7164 }
7165
7166 static void
7167 do_bfc (void)
7168 {
7169 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7170 constraint (msb > 32, _("bit-field extends past end of register"));
7171 /* The instruction encoding stores the LSB and MSB,
7172 not the LSB and width. */
7173 inst.instruction |= inst.operands[0].reg << 12;
7174 inst.instruction |= inst.operands[1].imm << 7;
7175 inst.instruction |= (msb - 1) << 16;
7176 }
7177
7178 static void
7179 do_bfi (void)
7180 {
7181 unsigned int msb;
7182
7183 /* #0 in second position is alternative syntax for bfc, which is
7184 the same instruction but with REG_PC in the Rm field. */
7185 if (!inst.operands[1].isreg)
7186 inst.operands[1].reg = REG_PC;
7187
7188 msb = inst.operands[2].imm + inst.operands[3].imm;
7189 constraint (msb > 32, _("bit-field extends past end of register"));
7190 /* The instruction encoding stores the LSB and MSB,
7191 not the LSB and width. */
7192 inst.instruction |= inst.operands[0].reg << 12;
7193 inst.instruction |= inst.operands[1].reg;
7194 inst.instruction |= inst.operands[2].imm << 7;
7195 inst.instruction |= (msb - 1) << 16;
7196 }
7197
7198 static void
7199 do_bfx (void)
7200 {
7201 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7202 _("bit-field extends past end of register"));
7203 inst.instruction |= inst.operands[0].reg << 12;
7204 inst.instruction |= inst.operands[1].reg;
7205 inst.instruction |= inst.operands[2].imm << 7;
7206 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7207 }
7208
7209 /* ARM V5 breakpoint instruction (argument parse)
7210 BKPT <16 bit unsigned immediate>
7211 Instruction is not conditional.
7212 The bit pattern given in insns[] has the COND_ALWAYS condition,
7213 and it is an error if the caller tried to override that. */
7214
7215 static void
7216 do_bkpt (void)
7217 {
7218 /* Top 12 of 16 bits to bits 19:8. */
7219 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7220
7221 /* Bottom 4 of 16 bits to bits 3:0. */
7222 inst.instruction |= inst.operands[0].imm & 0xf;
7223 }
7224
7225 static void
7226 encode_branch (int default_reloc)
7227 {
7228 if (inst.operands[0].hasreloc)
7229 {
7230 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7231 _("the only suffix valid here is '(plt)'"));
7232 inst.reloc.type = BFD_RELOC_ARM_PLT32;
7233 }
7234 else
7235 {
7236 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7237 }
7238 inst.reloc.pc_rel = 1;
7239 }
7240
7241 static void
7242 do_branch (void)
7243 {
7244 #ifdef OBJ_ELF
7245 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7246 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7247 else
7248 #endif
7249 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7250 }
7251
7252 static void
7253 do_bl (void)
7254 {
7255 #ifdef OBJ_ELF
7256 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7257 {
7258 if (inst.cond == COND_ALWAYS)
7259 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7260 else
7261 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7262 }
7263 else
7264 #endif
7265 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7266 }
7267
7268 /* ARM V5 branch-link-exchange instruction (argument parse)
7269 BLX <target_addr> ie BLX(1)
7270 BLX{<condition>} <Rm> ie BLX(2)
7271 Unfortunately, there are two different opcodes for this mnemonic.
7272 So, the insns[].value is not used, and the code here zaps values
7273 into inst.instruction.
7274 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7275
7276 static void
7277 do_blx (void)
7278 {
7279 if (inst.operands[0].isreg)
7280 {
7281 /* Arg is a register; the opcode provided by insns[] is correct.
7282 It is not illegal to do "blx pc", just useless. */
7283 if (inst.operands[0].reg == REG_PC)
7284 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7285
7286 inst.instruction |= inst.operands[0].reg;
7287 }
7288 else
7289 {
7290 /* Arg is an address; this instruction cannot be executed
7291 conditionally, and the opcode must be adjusted.
7292 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7293 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7294 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7295 inst.instruction = 0xfa000000;
7296 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7297 }
7298 }
7299
7300 static void
7301 do_bx (void)
7302 {
7303 bfd_boolean want_reloc;
7304
7305 if (inst.operands[0].reg == REG_PC)
7306 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7307
7308 inst.instruction |= inst.operands[0].reg;
7309 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7310 it is for ARMv4t or earlier. */
7311 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7312 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7313 want_reloc = TRUE;
7314
7315 #ifdef OBJ_ELF
7316 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7317 #endif
7318 want_reloc = FALSE;
7319
7320 if (want_reloc)
7321 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7322 }
7323
7324
7325 /* ARM v5TEJ. Jump to Jazelle code. */
7326
7327 static void
7328 do_bxj (void)
7329 {
7330 if (inst.operands[0].reg == REG_PC)
7331 as_tsktsk (_("use of r15 in bxj is not really useful"));
7332
7333 inst.instruction |= inst.operands[0].reg;
7334 }
7335
7336 /* Co-processor data operation:
7337 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7338 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7339 static void
7340 do_cdp (void)
7341 {
7342 inst.instruction |= inst.operands[0].reg << 8;
7343 inst.instruction |= inst.operands[1].imm << 20;
7344 inst.instruction |= inst.operands[2].reg << 12;
7345 inst.instruction |= inst.operands[3].reg << 16;
7346 inst.instruction |= inst.operands[4].reg;
7347 inst.instruction |= inst.operands[5].imm << 5;
7348 }
7349
7350 static void
7351 do_cmp (void)
7352 {
7353 inst.instruction |= inst.operands[0].reg << 16;
7354 encode_arm_shifter_operand (1);
7355 }
7356
7357 /* Transfer between coprocessor and ARM registers.
7358 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7359 MRC2
7360 MCR{cond}
7361 MCR2
7362
7363 No special properties. */
7364
7365 static void
7366 do_co_reg (void)
7367 {
7368 unsigned Rd;
7369
7370 Rd = inst.operands[2].reg;
7371 if (thumb_mode)
7372 {
7373 if (inst.instruction == 0xee000010
7374 || inst.instruction == 0xfe000010)
7375 /* MCR, MCR2 */
7376 reject_bad_reg (Rd);
7377 else
7378 /* MRC, MRC2 */
7379 constraint (Rd == REG_SP, BAD_SP);
7380 }
7381 else
7382 {
7383 /* MCR */
7384 if (inst.instruction == 0xe000010)
7385 constraint (Rd == REG_PC, BAD_PC);
7386 }
7387
7388
7389 inst.instruction |= inst.operands[0].reg << 8;
7390 inst.instruction |= inst.operands[1].imm << 21;
7391 inst.instruction |= Rd << 12;
7392 inst.instruction |= inst.operands[3].reg << 16;
7393 inst.instruction |= inst.operands[4].reg;
7394 inst.instruction |= inst.operands[5].imm << 5;
7395 }
7396
7397 /* Transfer between coprocessor register and pair of ARM registers.
7398 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7399 MCRR2
7400 MRRC{cond}
7401 MRRC2
7402
7403 Two XScale instructions are special cases of these:
7404
7405 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7406 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7407
7408 Result unpredictable if Rd or Rn is R15. */
7409
7410 static void
7411 do_co_reg2c (void)
7412 {
7413 unsigned Rd, Rn;
7414
7415 Rd = inst.operands[2].reg;
7416 Rn = inst.operands[3].reg;
7417
7418 if (thumb_mode)
7419 {
7420 reject_bad_reg (Rd);
7421 reject_bad_reg (Rn);
7422 }
7423 else
7424 {
7425 constraint (Rd == REG_PC, BAD_PC);
7426 constraint (Rn == REG_PC, BAD_PC);
7427 }
7428
7429 inst.instruction |= inst.operands[0].reg << 8;
7430 inst.instruction |= inst.operands[1].imm << 4;
7431 inst.instruction |= Rd << 12;
7432 inst.instruction |= Rn << 16;
7433 inst.instruction |= inst.operands[4].reg;
7434 }
7435
7436 static void
7437 do_cpsi (void)
7438 {
7439 inst.instruction |= inst.operands[0].imm << 6;
7440 if (inst.operands[1].present)
7441 {
7442 inst.instruction |= CPSI_MMOD;
7443 inst.instruction |= inst.operands[1].imm;
7444 }
7445 }
7446
7447 static void
7448 do_dbg (void)
7449 {
7450 inst.instruction |= inst.operands[0].imm;
7451 }
7452
7453 static void
7454 do_it (void)
7455 {
7456 /* There is no IT instruction in ARM mode. We
7457 process it to do the validation as if in
7458 thumb mode, just in case the code gets
7459 assembled for thumb using the unified syntax. */
7460
7461 inst.size = 0;
7462 if (unified_syntax)
7463 {
7464 set_it_insn_type (IT_INSN);
7465 now_it.mask = (inst.instruction & 0xf) | 0x10;
7466 now_it.cc = inst.operands[0].imm;
7467 }
7468 }
7469
7470 static void
7471 do_ldmstm (void)
7472 {
7473 int base_reg = inst.operands[0].reg;
7474 int range = inst.operands[1].imm;
7475
7476 inst.instruction |= base_reg << 16;
7477 inst.instruction |= range;
7478
7479 if (inst.operands[1].writeback)
7480 inst.instruction |= LDM_TYPE_2_OR_3;
7481
7482 if (inst.operands[0].writeback)
7483 {
7484 inst.instruction |= WRITE_BACK;
7485 /* Check for unpredictable uses of writeback. */
7486 if (inst.instruction & LOAD_BIT)
7487 {
7488 /* Not allowed in LDM type 2. */
7489 if ((inst.instruction & LDM_TYPE_2_OR_3)
7490 && ((range & (1 << REG_PC)) == 0))
7491 as_warn (_("writeback of base register is UNPREDICTABLE"));
7492 /* Only allowed if base reg not in list for other types. */
7493 else if (range & (1 << base_reg))
7494 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7495 }
7496 else /* STM. */
7497 {
7498 /* Not allowed for type 2. */
7499 if (inst.instruction & LDM_TYPE_2_OR_3)
7500 as_warn (_("writeback of base register is UNPREDICTABLE"));
7501 /* Only allowed if base reg not in list, or first in list. */
7502 else if ((range & (1 << base_reg))
7503 && (range & ((1 << base_reg) - 1)))
7504 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7505 }
7506 }
7507 }
7508
7509 /* ARMv5TE load-consecutive (argument parse)
7510 Mode is like LDRH.
7511
7512 LDRccD R, mode
7513 STRccD R, mode. */
7514
7515 static void
7516 do_ldrd (void)
7517 {
7518 constraint (inst.operands[0].reg % 2 != 0,
7519 _("first destination register must be even"));
7520 constraint (inst.operands[1].present
7521 && inst.operands[1].reg != inst.operands[0].reg + 1,
7522 _("can only load two consecutive registers"));
7523 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7524 constraint (!inst.operands[2].isreg, _("'[' expected"));
7525
7526 if (!inst.operands[1].present)
7527 inst.operands[1].reg = inst.operands[0].reg + 1;
7528
7529 if (inst.instruction & LOAD_BIT)
7530 {
7531 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7532 register and the first register written; we have to diagnose
7533 overlap between the base and the second register written here. */
7534
7535 if (inst.operands[2].reg == inst.operands[1].reg
7536 && (inst.operands[2].writeback || inst.operands[2].postind))
7537 as_warn (_("base register written back, and overlaps "
7538 "second destination register"));
7539
7540 /* For an index-register load, the index register must not overlap the
7541 destination (even if not write-back). */
7542 else if (inst.operands[2].immisreg
7543 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7544 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7545 as_warn (_("index register overlaps destination register"));
7546 }
7547
7548 inst.instruction |= inst.operands[0].reg << 12;
7549 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7550 }
7551
7552 static void
7553 do_ldrex (void)
7554 {
7555 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7556 || inst.operands[1].postind || inst.operands[1].writeback
7557 || inst.operands[1].immisreg || inst.operands[1].shifted
7558 || inst.operands[1].negative
7559 /* This can arise if the programmer has written
7560 strex rN, rM, foo
7561 or if they have mistakenly used a register name as the last
7562 operand, eg:
7563 strex rN, rM, rX
7564 It is very difficult to distinguish between these two cases
7565 because "rX" might actually be a label. ie the register
7566 name has been occluded by a symbol of the same name. So we
7567 just generate a general 'bad addressing mode' type error
7568 message and leave it up to the programmer to discover the
7569 true cause and fix their mistake. */
7570 || (inst.operands[1].reg == REG_PC),
7571 BAD_ADDR_MODE);
7572
7573 constraint (inst.reloc.exp.X_op != O_constant
7574 || inst.reloc.exp.X_add_number != 0,
7575 _("offset must be zero in ARM encoding"));
7576
7577 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7578
7579 inst.instruction |= inst.operands[0].reg << 12;
7580 inst.instruction |= inst.operands[1].reg << 16;
7581 inst.reloc.type = BFD_RELOC_UNUSED;
7582 }
7583
7584 static void
7585 do_ldrexd (void)
7586 {
7587 constraint (inst.operands[0].reg % 2 != 0,
7588 _("even register required"));
7589 constraint (inst.operands[1].present
7590 && inst.operands[1].reg != inst.operands[0].reg + 1,
7591 _("can only load two consecutive registers"));
7592 /* If op 1 were present and equal to PC, this function wouldn't
7593 have been called in the first place. */
7594 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7595
7596 inst.instruction |= inst.operands[0].reg << 12;
7597 inst.instruction |= inst.operands[2].reg << 16;
7598 }
7599
7600 static void
7601 do_ldst (void)
7602 {
7603 inst.instruction |= inst.operands[0].reg << 12;
7604 if (!inst.operands[1].isreg)
7605 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7606 return;
7607 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7608 }
7609
7610 static void
7611 do_ldstt (void)
7612 {
7613 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7614 reject [Rn,...]. */
7615 if (inst.operands[1].preind)
7616 {
7617 constraint (inst.reloc.exp.X_op != O_constant
7618 || inst.reloc.exp.X_add_number != 0,
7619 _("this instruction requires a post-indexed address"));
7620
7621 inst.operands[1].preind = 0;
7622 inst.operands[1].postind = 1;
7623 inst.operands[1].writeback = 1;
7624 }
7625 inst.instruction |= inst.operands[0].reg << 12;
7626 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7627 }
7628
7629 /* Halfword and signed-byte load/store operations. */
7630
7631 static void
7632 do_ldstv4 (void)
7633 {
7634 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7635 inst.instruction |= inst.operands[0].reg << 12;
7636 if (!inst.operands[1].isreg)
7637 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7638 return;
7639 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7640 }
7641
7642 static void
7643 do_ldsttv4 (void)
7644 {
7645 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7646 reject [Rn,...]. */
7647 if (inst.operands[1].preind)
7648 {
7649 constraint (inst.reloc.exp.X_op != O_constant
7650 || inst.reloc.exp.X_add_number != 0,
7651 _("this instruction requires a post-indexed address"));
7652
7653 inst.operands[1].preind = 0;
7654 inst.operands[1].postind = 1;
7655 inst.operands[1].writeback = 1;
7656 }
7657 inst.instruction |= inst.operands[0].reg << 12;
7658 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7659 }
7660
7661 /* Co-processor register load/store.
7662 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7663 static void
7664 do_lstc (void)
7665 {
7666 inst.instruction |= inst.operands[0].reg << 8;
7667 inst.instruction |= inst.operands[1].reg << 12;
7668 encode_arm_cp_address (2, TRUE, TRUE, 0);
7669 }
7670
7671 static void
7672 do_mlas (void)
7673 {
7674 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7675 if (inst.operands[0].reg == inst.operands[1].reg
7676 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7677 && !(inst.instruction & 0x00400000))
7678 as_tsktsk (_("Rd and Rm should be different in mla"));
7679
7680 inst.instruction |= inst.operands[0].reg << 16;
7681 inst.instruction |= inst.operands[1].reg;
7682 inst.instruction |= inst.operands[2].reg << 8;
7683 inst.instruction |= inst.operands[3].reg << 12;
7684 }
7685
7686 static void
7687 do_mov (void)
7688 {
7689 inst.instruction |= inst.operands[0].reg << 12;
7690 encode_arm_shifter_operand (1);
7691 }
7692
7693 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7694 static void
7695 do_mov16 (void)
7696 {
7697 bfd_vma imm;
7698 bfd_boolean top;
7699
7700 top = (inst.instruction & 0x00400000) != 0;
7701 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7702 _(":lower16: not allowed this instruction"));
7703 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7704 _(":upper16: not allowed instruction"));
7705 inst.instruction |= inst.operands[0].reg << 12;
7706 if (inst.reloc.type == BFD_RELOC_UNUSED)
7707 {
7708 imm = inst.reloc.exp.X_add_number;
7709 /* The value is in two pieces: 0:11, 16:19. */
7710 inst.instruction |= (imm & 0x00000fff);
7711 inst.instruction |= (imm & 0x0000f000) << 4;
7712 }
7713 }
7714
7715 static void do_vfp_nsyn_opcode (const char *);
7716
7717 static int
7718 do_vfp_nsyn_mrs (void)
7719 {
7720 if (inst.operands[0].isvec)
7721 {
7722 if (inst.operands[1].reg != 1)
7723 first_error (_("operand 1 must be FPSCR"));
7724 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7725 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7726 do_vfp_nsyn_opcode ("fmstat");
7727 }
7728 else if (inst.operands[1].isvec)
7729 do_vfp_nsyn_opcode ("fmrx");
7730 else
7731 return FAIL;
7732
7733 return SUCCESS;
7734 }
7735
7736 static int
7737 do_vfp_nsyn_msr (void)
7738 {
7739 if (inst.operands[0].isvec)
7740 do_vfp_nsyn_opcode ("fmxr");
7741 else
7742 return FAIL;
7743
7744 return SUCCESS;
7745 }
7746
7747 static void
7748 do_vmrs (void)
7749 {
7750 unsigned Rt = inst.operands[0].reg;
7751
7752 if (thumb_mode && inst.operands[0].reg == REG_SP)
7753 {
7754 inst.error = BAD_SP;
7755 return;
7756 }
7757
7758 /* APSR_ sets isvec. All other refs to PC are illegal. */
7759 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7760 {
7761 inst.error = BAD_PC;
7762 return;
7763 }
7764
7765 if (inst.operands[1].reg != 1)
7766 first_error (_("operand 1 must be FPSCR"));
7767
7768 inst.instruction |= (Rt << 12);
7769 }
7770
7771 static void
7772 do_vmsr (void)
7773 {
7774 unsigned Rt = inst.operands[1].reg;
7775
7776 if (thumb_mode)
7777 reject_bad_reg (Rt);
7778 else if (Rt == REG_PC)
7779 {
7780 inst.error = BAD_PC;
7781 return;
7782 }
7783
7784 if (inst.operands[0].reg != 1)
7785 first_error (_("operand 0 must be FPSCR"));
7786
7787 inst.instruction |= (Rt << 12);
7788 }
7789
7790 static void
7791 do_mrs (void)
7792 {
7793 if (do_vfp_nsyn_mrs () == SUCCESS)
7794 return;
7795
7796 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7797 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7798 != (PSR_c|PSR_f),
7799 _("'CPSR' or 'SPSR' expected"));
7800 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7801 inst.instruction |= inst.operands[0].reg << 12;
7802 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7803 }
7804
7805 /* Two possible forms:
7806 "{C|S}PSR_<field>, Rm",
7807 "{C|S}PSR_f, #expression". */
7808
7809 static void
7810 do_msr (void)
7811 {
7812 if (do_vfp_nsyn_msr () == SUCCESS)
7813 return;
7814
7815 inst.instruction |= inst.operands[0].imm;
7816 if (inst.operands[1].isreg)
7817 inst.instruction |= inst.operands[1].reg;
7818 else
7819 {
7820 inst.instruction |= INST_IMMEDIATE;
7821 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7822 inst.reloc.pc_rel = 0;
7823 }
7824 }
7825
7826 static void
7827 do_mul (void)
7828 {
7829 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7830
7831 if (!inst.operands[2].present)
7832 inst.operands[2].reg = inst.operands[0].reg;
7833 inst.instruction |= inst.operands[0].reg << 16;
7834 inst.instruction |= inst.operands[1].reg;
7835 inst.instruction |= inst.operands[2].reg << 8;
7836
7837 if (inst.operands[0].reg == inst.operands[1].reg
7838 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7839 as_tsktsk (_("Rd and Rm should be different in mul"));
7840 }
7841
7842 /* Long Multiply Parser
7843 UMULL RdLo, RdHi, Rm, Rs
7844 SMULL RdLo, RdHi, Rm, Rs
7845 UMLAL RdLo, RdHi, Rm, Rs
7846 SMLAL RdLo, RdHi, Rm, Rs. */
7847
7848 static void
7849 do_mull (void)
7850 {
7851 inst.instruction |= inst.operands[0].reg << 12;
7852 inst.instruction |= inst.operands[1].reg << 16;
7853 inst.instruction |= inst.operands[2].reg;
7854 inst.instruction |= inst.operands[3].reg << 8;
7855
7856 /* rdhi and rdlo must be different. */
7857 if (inst.operands[0].reg == inst.operands[1].reg)
7858 as_tsktsk (_("rdhi and rdlo must be different"));
7859
7860 /* rdhi, rdlo and rm must all be different before armv6. */
7861 if ((inst.operands[0].reg == inst.operands[2].reg
7862 || inst.operands[1].reg == inst.operands[2].reg)
7863 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7864 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7865 }
7866
7867 static void
7868 do_nop (void)
7869 {
7870 if (inst.operands[0].present
7871 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
7872 {
7873 /* Architectural NOP hints are CPSR sets with no bits selected. */
7874 inst.instruction &= 0xf0000000;
7875 inst.instruction |= 0x0320f000;
7876 if (inst.operands[0].present)
7877 inst.instruction |= inst.operands[0].imm;
7878 }
7879 }
7880
7881 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7882 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7883 Condition defaults to COND_ALWAYS.
7884 Error if Rd, Rn or Rm are R15. */
7885
7886 static void
7887 do_pkhbt (void)
7888 {
7889 inst.instruction |= inst.operands[0].reg << 12;
7890 inst.instruction |= inst.operands[1].reg << 16;
7891 inst.instruction |= inst.operands[2].reg;
7892 if (inst.operands[3].present)
7893 encode_arm_shift (3);
7894 }
7895
7896 /* ARM V6 PKHTB (Argument Parse). */
7897
7898 static void
7899 do_pkhtb (void)
7900 {
7901 if (!inst.operands[3].present)
7902 {
7903 /* If the shift specifier is omitted, turn the instruction
7904 into pkhbt rd, rm, rn. */
7905 inst.instruction &= 0xfff00010;
7906 inst.instruction |= inst.operands[0].reg << 12;
7907 inst.instruction |= inst.operands[1].reg;
7908 inst.instruction |= inst.operands[2].reg << 16;
7909 }
7910 else
7911 {
7912 inst.instruction |= inst.operands[0].reg << 12;
7913 inst.instruction |= inst.operands[1].reg << 16;
7914 inst.instruction |= inst.operands[2].reg;
7915 encode_arm_shift (3);
7916 }
7917 }
7918
7919 /* ARMv5TE: Preload-Cache
7920
7921 PLD <addr_mode>
7922
7923 Syntactically, like LDR with B=1, W=0, L=1. */
7924
7925 static void
7926 do_pld (void)
7927 {
7928 constraint (!inst.operands[0].isreg,
7929 _("'[' expected after PLD mnemonic"));
7930 constraint (inst.operands[0].postind,
7931 _("post-indexed expression used in preload instruction"));
7932 constraint (inst.operands[0].writeback,
7933 _("writeback used in preload instruction"));
7934 constraint (!inst.operands[0].preind,
7935 _("unindexed addressing used in preload instruction"));
7936 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7937 }
7938
7939 /* ARMv7: PLI <addr_mode> */
7940 static void
7941 do_pli (void)
7942 {
7943 constraint (!inst.operands[0].isreg,
7944 _("'[' expected after PLI mnemonic"));
7945 constraint (inst.operands[0].postind,
7946 _("post-indexed expression used in preload instruction"));
7947 constraint (inst.operands[0].writeback,
7948 _("writeback used in preload instruction"));
7949 constraint (!inst.operands[0].preind,
7950 _("unindexed addressing used in preload instruction"));
7951 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7952 inst.instruction &= ~PRE_INDEX;
7953 }
7954
7955 static void
7956 do_push_pop (void)
7957 {
7958 inst.operands[1] = inst.operands[0];
7959 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7960 inst.operands[0].isreg = 1;
7961 inst.operands[0].writeback = 1;
7962 inst.operands[0].reg = REG_SP;
7963 do_ldmstm ();
7964 }
7965
7966 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7967 word at the specified address and the following word
7968 respectively.
7969 Unconditionally executed.
7970 Error if Rn is R15. */
7971
7972 static void
7973 do_rfe (void)
7974 {
7975 inst.instruction |= inst.operands[0].reg << 16;
7976 if (inst.operands[0].writeback)
7977 inst.instruction |= WRITE_BACK;
7978 }
7979
7980 /* ARM V6 ssat (argument parse). */
7981
7982 static void
7983 do_ssat (void)
7984 {
7985 inst.instruction |= inst.operands[0].reg << 12;
7986 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7987 inst.instruction |= inst.operands[2].reg;
7988
7989 if (inst.operands[3].present)
7990 encode_arm_shift (3);
7991 }
7992
7993 /* ARM V6 usat (argument parse). */
7994
7995 static void
7996 do_usat (void)
7997 {
7998 inst.instruction |= inst.operands[0].reg << 12;
7999 inst.instruction |= inst.operands[1].imm << 16;
8000 inst.instruction |= inst.operands[2].reg;
8001
8002 if (inst.operands[3].present)
8003 encode_arm_shift (3);
8004 }
8005
8006 /* ARM V6 ssat16 (argument parse). */
8007
8008 static void
8009 do_ssat16 (void)
8010 {
8011 inst.instruction |= inst.operands[0].reg << 12;
8012 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
8013 inst.instruction |= inst.operands[2].reg;
8014 }
8015
8016 static void
8017 do_usat16 (void)
8018 {
8019 inst.instruction |= inst.operands[0].reg << 12;
8020 inst.instruction |= inst.operands[1].imm << 16;
8021 inst.instruction |= inst.operands[2].reg;
8022 }
8023
8024 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
8025 preserving the other bits.
8026
8027 setend <endian_specifier>, where <endian_specifier> is either
8028 BE or LE. */
8029
8030 static void
8031 do_setend (void)
8032 {
8033 if (inst.operands[0].imm)
8034 inst.instruction |= 0x200;
8035 }
8036
8037 static void
8038 do_shift (void)
8039 {
8040 unsigned int Rm = (inst.operands[1].present
8041 ? inst.operands[1].reg
8042 : inst.operands[0].reg);
8043
8044 inst.instruction |= inst.operands[0].reg << 12;
8045 inst.instruction |= Rm;
8046 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
8047 {
8048 inst.instruction |= inst.operands[2].reg << 8;
8049 inst.instruction |= SHIFT_BY_REG;
8050 }
8051 else
8052 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
8053 }
8054
8055 static void
8056 do_smc (void)
8057 {
8058 inst.reloc.type = BFD_RELOC_ARM_SMC;
8059 inst.reloc.pc_rel = 0;
8060 }
8061
8062 static void
8063 do_swi (void)
8064 {
8065 inst.reloc.type = BFD_RELOC_ARM_SWI;
8066 inst.reloc.pc_rel = 0;
8067 }
8068
8069 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8070 SMLAxy{cond} Rd,Rm,Rs,Rn
8071 SMLAWy{cond} Rd,Rm,Rs,Rn
8072 Error if any register is R15. */
8073
8074 static void
8075 do_smla (void)
8076 {
8077 inst.instruction |= inst.operands[0].reg << 16;
8078 inst.instruction |= inst.operands[1].reg;
8079 inst.instruction |= inst.operands[2].reg << 8;
8080 inst.instruction |= inst.operands[3].reg << 12;
8081 }
8082
8083 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8084 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8085 Error if any register is R15.
8086 Warning if Rdlo == Rdhi. */
8087
8088 static void
8089 do_smlal (void)
8090 {
8091 inst.instruction |= inst.operands[0].reg << 12;
8092 inst.instruction |= inst.operands[1].reg << 16;
8093 inst.instruction |= inst.operands[2].reg;
8094 inst.instruction |= inst.operands[3].reg << 8;
8095
8096 if (inst.operands[0].reg == inst.operands[1].reg)
8097 as_tsktsk (_("rdhi and rdlo must be different"));
8098 }
8099
8100 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8101 SMULxy{cond} Rd,Rm,Rs
8102 Error if any register is R15. */
8103
8104 static void
8105 do_smul (void)
8106 {
8107 inst.instruction |= inst.operands[0].reg << 16;
8108 inst.instruction |= inst.operands[1].reg;
8109 inst.instruction |= inst.operands[2].reg << 8;
8110 }
8111
8112 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8113 the same for both ARM and Thumb-2. */
8114
8115 static void
8116 do_srs (void)
8117 {
8118 int reg;
8119
8120 if (inst.operands[0].present)
8121 {
8122 reg = inst.operands[0].reg;
8123 constraint (reg != REG_SP, _("SRS base register must be r13"));
8124 }
8125 else
8126 reg = REG_SP;
8127
8128 inst.instruction |= reg << 16;
8129 inst.instruction |= inst.operands[1].imm;
8130 if (inst.operands[0].writeback || inst.operands[1].writeback)
8131 inst.instruction |= WRITE_BACK;
8132 }
8133
8134 /* ARM V6 strex (argument parse). */
8135
8136 static void
8137 do_strex (void)
8138 {
8139 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8140 || inst.operands[2].postind || inst.operands[2].writeback
8141 || inst.operands[2].immisreg || inst.operands[2].shifted
8142 || inst.operands[2].negative
8143 /* See comment in do_ldrex(). */
8144 || (inst.operands[2].reg == REG_PC),
8145 BAD_ADDR_MODE);
8146
8147 constraint (inst.operands[0].reg == inst.operands[1].reg
8148 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8149
8150 constraint (inst.reloc.exp.X_op != O_constant
8151 || inst.reloc.exp.X_add_number != 0,
8152 _("offset must be zero in ARM encoding"));
8153
8154 inst.instruction |= inst.operands[0].reg << 12;
8155 inst.instruction |= inst.operands[1].reg;
8156 inst.instruction |= inst.operands[2].reg << 16;
8157 inst.reloc.type = BFD_RELOC_UNUSED;
8158 }
8159
8160 static void
8161 do_strexd (void)
8162 {
8163 constraint (inst.operands[1].reg % 2 != 0,
8164 _("even register required"));
8165 constraint (inst.operands[2].present
8166 && inst.operands[2].reg != inst.operands[1].reg + 1,
8167 _("can only store two consecutive registers"));
8168 /* If op 2 were present and equal to PC, this function wouldn't
8169 have been called in the first place. */
8170 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8171
8172 constraint (inst.operands[0].reg == inst.operands[1].reg
8173 || inst.operands[0].reg == inst.operands[1].reg + 1
8174 || inst.operands[0].reg == inst.operands[3].reg,
8175 BAD_OVERLAP);
8176
8177 inst.instruction |= inst.operands[0].reg << 12;
8178 inst.instruction |= inst.operands[1].reg;
8179 inst.instruction |= inst.operands[3].reg << 16;
8180 }
8181
8182 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8183 extends it to 32-bits, and adds the result to a value in another
8184 register. You can specify a rotation by 0, 8, 16, or 24 bits
8185 before extracting the 16-bit value.
8186 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8187 Condition defaults to COND_ALWAYS.
8188 Error if any register uses R15. */
8189
8190 static void
8191 do_sxtah (void)
8192 {
8193 inst.instruction |= inst.operands[0].reg << 12;
8194 inst.instruction |= inst.operands[1].reg << 16;
8195 inst.instruction |= inst.operands[2].reg;
8196 inst.instruction |= inst.operands[3].imm << 10;
8197 }
8198
8199 /* ARM V6 SXTH.
8200
8201 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8202 Condition defaults to COND_ALWAYS.
8203 Error if any register uses R15. */
8204
8205 static void
8206 do_sxth (void)
8207 {
8208 inst.instruction |= inst.operands[0].reg << 12;
8209 inst.instruction |= inst.operands[1].reg;
8210 inst.instruction |= inst.operands[2].imm << 10;
8211 }
8212 \f
8213 /* VFP instructions. In a logical order: SP variant first, monad
8214 before dyad, arithmetic then move then load/store. */
8215
8216 static void
8217 do_vfp_sp_monadic (void)
8218 {
8219 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8220 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8221 }
8222
8223 static void
8224 do_vfp_sp_dyadic (void)
8225 {
8226 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8227 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8228 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8229 }
8230
8231 static void
8232 do_vfp_sp_compare_z (void)
8233 {
8234 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8235 }
8236
8237 static void
8238 do_vfp_dp_sp_cvt (void)
8239 {
8240 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8241 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8242 }
8243
8244 static void
8245 do_vfp_sp_dp_cvt (void)
8246 {
8247 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8248 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8249 }
8250
8251 static void
8252 do_vfp_reg_from_sp (void)
8253 {
8254 inst.instruction |= inst.operands[0].reg << 12;
8255 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8256 }
8257
8258 static void
8259 do_vfp_reg2_from_sp2 (void)
8260 {
8261 constraint (inst.operands[2].imm != 2,
8262 _("only two consecutive VFP SP registers allowed here"));
8263 inst.instruction |= inst.operands[0].reg << 12;
8264 inst.instruction |= inst.operands[1].reg << 16;
8265 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8266 }
8267
8268 static void
8269 do_vfp_sp_from_reg (void)
8270 {
8271 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8272 inst.instruction |= inst.operands[1].reg << 12;
8273 }
8274
8275 static void
8276 do_vfp_sp2_from_reg2 (void)
8277 {
8278 constraint (inst.operands[0].imm != 2,
8279 _("only two consecutive VFP SP registers allowed here"));
8280 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8281 inst.instruction |= inst.operands[1].reg << 12;
8282 inst.instruction |= inst.operands[2].reg << 16;
8283 }
8284
8285 static void
8286 do_vfp_sp_ldst (void)
8287 {
8288 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8289 encode_arm_cp_address (1, FALSE, TRUE, 0);
8290 }
8291
8292 static void
8293 do_vfp_dp_ldst (void)
8294 {
8295 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8296 encode_arm_cp_address (1, FALSE, TRUE, 0);
8297 }
8298
8299
8300 static void
8301 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8302 {
8303 if (inst.operands[0].writeback)
8304 inst.instruction |= WRITE_BACK;
8305 else
8306 constraint (ldstm_type != VFP_LDSTMIA,
8307 _("this addressing mode requires base-register writeback"));
8308 inst.instruction |= inst.operands[0].reg << 16;
8309 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8310 inst.instruction |= inst.operands[1].imm;
8311 }
8312
8313 static void
8314 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8315 {
8316 int count;
8317
8318 if (inst.operands[0].writeback)
8319 inst.instruction |= WRITE_BACK;
8320 else
8321 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8322 _("this addressing mode requires base-register writeback"));
8323
8324 inst.instruction |= inst.operands[0].reg << 16;
8325 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8326
8327 count = inst.operands[1].imm << 1;
8328 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8329 count += 1;
8330
8331 inst.instruction |= count;
8332 }
8333
8334 static void
8335 do_vfp_sp_ldstmia (void)
8336 {
8337 vfp_sp_ldstm (VFP_LDSTMIA);
8338 }
8339
8340 static void
8341 do_vfp_sp_ldstmdb (void)
8342 {
8343 vfp_sp_ldstm (VFP_LDSTMDB);
8344 }
8345
8346 static void
8347 do_vfp_dp_ldstmia (void)
8348 {
8349 vfp_dp_ldstm (VFP_LDSTMIA);
8350 }
8351
8352 static void
8353 do_vfp_dp_ldstmdb (void)
8354 {
8355 vfp_dp_ldstm (VFP_LDSTMDB);
8356 }
8357
8358 static void
8359 do_vfp_xp_ldstmia (void)
8360 {
8361 vfp_dp_ldstm (VFP_LDSTMIAX);
8362 }
8363
8364 static void
8365 do_vfp_xp_ldstmdb (void)
8366 {
8367 vfp_dp_ldstm (VFP_LDSTMDBX);
8368 }
8369
8370 static void
8371 do_vfp_dp_rd_rm (void)
8372 {
8373 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8374 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8375 }
8376
8377 static void
8378 do_vfp_dp_rn_rd (void)
8379 {
8380 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8381 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8382 }
8383
8384 static void
8385 do_vfp_dp_rd_rn (void)
8386 {
8387 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8388 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8389 }
8390
8391 static void
8392 do_vfp_dp_rd_rn_rm (void)
8393 {
8394 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8395 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8396 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8397 }
8398
8399 static void
8400 do_vfp_dp_rd (void)
8401 {
8402 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8403 }
8404
8405 static void
8406 do_vfp_dp_rm_rd_rn (void)
8407 {
8408 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8409 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8410 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8411 }
8412
8413 /* VFPv3 instructions. */
8414 static void
8415 do_vfp_sp_const (void)
8416 {
8417 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8418 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8419 inst.instruction |= (inst.operands[1].imm & 0x0f);
8420 }
8421
8422 static void
8423 do_vfp_dp_const (void)
8424 {
8425 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8426 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8427 inst.instruction |= (inst.operands[1].imm & 0x0f);
8428 }
8429
8430 static void
8431 vfp_conv (int srcsize)
8432 {
8433 unsigned immbits = srcsize - inst.operands[1].imm;
8434 inst.instruction |= (immbits & 1) << 5;
8435 inst.instruction |= (immbits >> 1);
8436 }
8437
8438 static void
8439 do_vfp_sp_conv_16 (void)
8440 {
8441 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8442 vfp_conv (16);
8443 }
8444
8445 static void
8446 do_vfp_dp_conv_16 (void)
8447 {
8448 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8449 vfp_conv (16);
8450 }
8451
8452 static void
8453 do_vfp_sp_conv_32 (void)
8454 {
8455 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8456 vfp_conv (32);
8457 }
8458
8459 static void
8460 do_vfp_dp_conv_32 (void)
8461 {
8462 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8463 vfp_conv (32);
8464 }
8465 \f
8466 /* FPA instructions. Also in a logical order. */
8467
8468 static void
8469 do_fpa_cmp (void)
8470 {
8471 inst.instruction |= inst.operands[0].reg << 16;
8472 inst.instruction |= inst.operands[1].reg;
8473 }
8474
8475 static void
8476 do_fpa_ldmstm (void)
8477 {
8478 inst.instruction |= inst.operands[0].reg << 12;
8479 switch (inst.operands[1].imm)
8480 {
8481 case 1: inst.instruction |= CP_T_X; break;
8482 case 2: inst.instruction |= CP_T_Y; break;
8483 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8484 case 4: break;
8485 default: abort ();
8486 }
8487
8488 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8489 {
8490 /* The instruction specified "ea" or "fd", so we can only accept
8491 [Rn]{!}. The instruction does not really support stacking or
8492 unstacking, so we have to emulate these by setting appropriate
8493 bits and offsets. */
8494 constraint (inst.reloc.exp.X_op != O_constant
8495 || inst.reloc.exp.X_add_number != 0,
8496 _("this instruction does not support indexing"));
8497
8498 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8499 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
8500
8501 if (!(inst.instruction & INDEX_UP))
8502 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
8503
8504 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8505 {
8506 inst.operands[2].preind = 0;
8507 inst.operands[2].postind = 1;
8508 }
8509 }
8510
8511 encode_arm_cp_address (2, TRUE, TRUE, 0);
8512 }
8513 \f
8514 /* iWMMXt instructions: strictly in alphabetical order. */
8515
8516 static void
8517 do_iwmmxt_tandorc (void)
8518 {
8519 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8520 }
8521
8522 static void
8523 do_iwmmxt_textrc (void)
8524 {
8525 inst.instruction |= inst.operands[0].reg << 12;
8526 inst.instruction |= inst.operands[1].imm;
8527 }
8528
8529 static void
8530 do_iwmmxt_textrm (void)
8531 {
8532 inst.instruction |= inst.operands[0].reg << 12;
8533 inst.instruction |= inst.operands[1].reg << 16;
8534 inst.instruction |= inst.operands[2].imm;
8535 }
8536
8537 static void
8538 do_iwmmxt_tinsr (void)
8539 {
8540 inst.instruction |= inst.operands[0].reg << 16;
8541 inst.instruction |= inst.operands[1].reg << 12;
8542 inst.instruction |= inst.operands[2].imm;
8543 }
8544
8545 static void
8546 do_iwmmxt_tmia (void)
8547 {
8548 inst.instruction |= inst.operands[0].reg << 5;
8549 inst.instruction |= inst.operands[1].reg;
8550 inst.instruction |= inst.operands[2].reg << 12;
8551 }
8552
8553 static void
8554 do_iwmmxt_waligni (void)
8555 {
8556 inst.instruction |= inst.operands[0].reg << 12;
8557 inst.instruction |= inst.operands[1].reg << 16;
8558 inst.instruction |= inst.operands[2].reg;
8559 inst.instruction |= inst.operands[3].imm << 20;
8560 }
8561
8562 static void
8563 do_iwmmxt_wmerge (void)
8564 {
8565 inst.instruction |= inst.operands[0].reg << 12;
8566 inst.instruction |= inst.operands[1].reg << 16;
8567 inst.instruction |= inst.operands[2].reg;
8568 inst.instruction |= inst.operands[3].imm << 21;
8569 }
8570
8571 static void
8572 do_iwmmxt_wmov (void)
8573 {
8574 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8575 inst.instruction |= inst.operands[0].reg << 12;
8576 inst.instruction |= inst.operands[1].reg << 16;
8577 inst.instruction |= inst.operands[1].reg;
8578 }
8579
8580 static void
8581 do_iwmmxt_wldstbh (void)
8582 {
8583 int reloc;
8584 inst.instruction |= inst.operands[0].reg << 12;
8585 if (thumb_mode)
8586 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8587 else
8588 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8589 encode_arm_cp_address (1, TRUE, FALSE, reloc);
8590 }
8591
8592 static void
8593 do_iwmmxt_wldstw (void)
8594 {
8595 /* RIWR_RIWC clears .isreg for a control register. */
8596 if (!inst.operands[0].isreg)
8597 {
8598 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8599 inst.instruction |= 0xf0000000;
8600 }
8601
8602 inst.instruction |= inst.operands[0].reg << 12;
8603 encode_arm_cp_address (1, TRUE, TRUE, 0);
8604 }
8605
8606 static void
8607 do_iwmmxt_wldstd (void)
8608 {
8609 inst.instruction |= inst.operands[0].reg << 12;
8610 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8611 && inst.operands[1].immisreg)
8612 {
8613 inst.instruction &= ~0x1a000ff;
8614 inst.instruction |= (0xf << 28);
8615 if (inst.operands[1].preind)
8616 inst.instruction |= PRE_INDEX;
8617 if (!inst.operands[1].negative)
8618 inst.instruction |= INDEX_UP;
8619 if (inst.operands[1].writeback)
8620 inst.instruction |= WRITE_BACK;
8621 inst.instruction |= inst.operands[1].reg << 16;
8622 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8623 inst.instruction |= inst.operands[1].imm;
8624 }
8625 else
8626 encode_arm_cp_address (1, TRUE, FALSE, 0);
8627 }
8628
8629 static void
8630 do_iwmmxt_wshufh (void)
8631 {
8632 inst.instruction |= inst.operands[0].reg << 12;
8633 inst.instruction |= inst.operands[1].reg << 16;
8634 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8635 inst.instruction |= (inst.operands[2].imm & 0x0f);
8636 }
8637
8638 static void
8639 do_iwmmxt_wzero (void)
8640 {
8641 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8642 inst.instruction |= inst.operands[0].reg;
8643 inst.instruction |= inst.operands[0].reg << 12;
8644 inst.instruction |= inst.operands[0].reg << 16;
8645 }
8646
8647 static void
8648 do_iwmmxt_wrwrwr_or_imm5 (void)
8649 {
8650 if (inst.operands[2].isreg)
8651 do_rd_rn_rm ();
8652 else {
8653 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8654 _("immediate operand requires iWMMXt2"));
8655 do_rd_rn ();
8656 if (inst.operands[2].imm == 0)
8657 {
8658 switch ((inst.instruction >> 20) & 0xf)
8659 {
8660 case 4:
8661 case 5:
8662 case 6:
8663 case 7:
8664 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8665 inst.operands[2].imm = 16;
8666 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8667 break;
8668 case 8:
8669 case 9:
8670 case 10:
8671 case 11:
8672 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8673 inst.operands[2].imm = 32;
8674 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8675 break;
8676 case 12:
8677 case 13:
8678 case 14:
8679 case 15:
8680 {
8681 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8682 unsigned long wrn;
8683 wrn = (inst.instruction >> 16) & 0xf;
8684 inst.instruction &= 0xff0fff0f;
8685 inst.instruction |= wrn;
8686 /* Bail out here; the instruction is now assembled. */
8687 return;
8688 }
8689 }
8690 }
8691 /* Map 32 -> 0, etc. */
8692 inst.operands[2].imm &= 0x1f;
8693 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8694 }
8695 }
8696 \f
8697 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8698 operations first, then control, shift, and load/store. */
8699
8700 /* Insns like "foo X,Y,Z". */
8701
8702 static void
8703 do_mav_triple (void)
8704 {
8705 inst.instruction |= inst.operands[0].reg << 16;
8706 inst.instruction |= inst.operands[1].reg;
8707 inst.instruction |= inst.operands[2].reg << 12;
8708 }
8709
8710 /* Insns like "foo W,X,Y,Z".
8711 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8712
8713 static void
8714 do_mav_quad (void)
8715 {
8716 inst.instruction |= inst.operands[0].reg << 5;
8717 inst.instruction |= inst.operands[1].reg << 12;
8718 inst.instruction |= inst.operands[2].reg << 16;
8719 inst.instruction |= inst.operands[3].reg;
8720 }
8721
8722 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8723 static void
8724 do_mav_dspsc (void)
8725 {
8726 inst.instruction |= inst.operands[1].reg << 12;
8727 }
8728
8729 /* Maverick shift immediate instructions.
8730 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8731 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8732
8733 static void
8734 do_mav_shift (void)
8735 {
8736 int imm = inst.operands[2].imm;
8737
8738 inst.instruction |= inst.operands[0].reg << 12;
8739 inst.instruction |= inst.operands[1].reg << 16;
8740
8741 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8742 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8743 Bit 4 should be 0. */
8744 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8745
8746 inst.instruction |= imm;
8747 }
8748 \f
8749 /* XScale instructions. Also sorted arithmetic before move. */
8750
8751 /* Xscale multiply-accumulate (argument parse)
8752 MIAcc acc0,Rm,Rs
8753 MIAPHcc acc0,Rm,Rs
8754 MIAxycc acc0,Rm,Rs. */
8755
8756 static void
8757 do_xsc_mia (void)
8758 {
8759 inst.instruction |= inst.operands[1].reg;
8760 inst.instruction |= inst.operands[2].reg << 12;
8761 }
8762
8763 /* Xscale move-accumulator-register (argument parse)
8764
8765 MARcc acc0,RdLo,RdHi. */
8766
8767 static void
8768 do_xsc_mar (void)
8769 {
8770 inst.instruction |= inst.operands[1].reg << 12;
8771 inst.instruction |= inst.operands[2].reg << 16;
8772 }
8773
8774 /* Xscale move-register-accumulator (argument parse)
8775
8776 MRAcc RdLo,RdHi,acc0. */
8777
8778 static void
8779 do_xsc_mra (void)
8780 {
8781 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8782 inst.instruction |= inst.operands[0].reg << 12;
8783 inst.instruction |= inst.operands[1].reg << 16;
8784 }
8785 \f
8786 /* Encoding functions relevant only to Thumb. */
8787
8788 /* inst.operands[i] is a shifted-register operand; encode
8789 it into inst.instruction in the format used by Thumb32. */
8790
8791 static void
8792 encode_thumb32_shifted_operand (int i)
8793 {
8794 unsigned int value = inst.reloc.exp.X_add_number;
8795 unsigned int shift = inst.operands[i].shift_kind;
8796
8797 constraint (inst.operands[i].immisreg,
8798 _("shift by register not allowed in thumb mode"));
8799 inst.instruction |= inst.operands[i].reg;
8800 if (shift == SHIFT_RRX)
8801 inst.instruction |= SHIFT_ROR << 4;
8802 else
8803 {
8804 constraint (inst.reloc.exp.X_op != O_constant,
8805 _("expression too complex"));
8806
8807 constraint (value > 32
8808 || (value == 32 && (shift == SHIFT_LSL
8809 || shift == SHIFT_ROR)),
8810 _("shift expression is too large"));
8811
8812 if (value == 0)
8813 shift = SHIFT_LSL;
8814 else if (value == 32)
8815 value = 0;
8816
8817 inst.instruction |= shift << 4;
8818 inst.instruction |= (value & 0x1c) << 10;
8819 inst.instruction |= (value & 0x03) << 6;
8820 }
8821 }
8822
8823
8824 /* inst.operands[i] was set up by parse_address. Encode it into a
8825 Thumb32 format load or store instruction. Reject forms that cannot
8826 be used with such instructions. If is_t is true, reject forms that
8827 cannot be used with a T instruction; if is_d is true, reject forms
8828 that cannot be used with a D instruction. If it is a store insn,
8829 reject PC in Rn. */
8830
8831 static void
8832 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8833 {
8834 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8835
8836 constraint (!inst.operands[i].isreg,
8837 _("Instruction does not support =N addresses"));
8838
8839 inst.instruction |= inst.operands[i].reg << 16;
8840 if (inst.operands[i].immisreg)
8841 {
8842 constraint (is_pc, BAD_PC_ADDRESSING);
8843 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8844 constraint (inst.operands[i].negative,
8845 _("Thumb does not support negative register indexing"));
8846 constraint (inst.operands[i].postind,
8847 _("Thumb does not support register post-indexing"));
8848 constraint (inst.operands[i].writeback,
8849 _("Thumb does not support register indexing with writeback"));
8850 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8851 _("Thumb supports only LSL in shifted register indexing"));
8852
8853 inst.instruction |= inst.operands[i].imm;
8854 if (inst.operands[i].shifted)
8855 {
8856 constraint (inst.reloc.exp.X_op != O_constant,
8857 _("expression too complex"));
8858 constraint (inst.reloc.exp.X_add_number < 0
8859 || inst.reloc.exp.X_add_number > 3,
8860 _("shift out of range"));
8861 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8862 }
8863 inst.reloc.type = BFD_RELOC_UNUSED;
8864 }
8865 else if (inst.operands[i].preind)
8866 {
8867 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
8868 constraint (is_t && inst.operands[i].writeback,
8869 _("cannot use writeback with this instruction"));
8870 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8871 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
8872
8873 if (is_d)
8874 {
8875 inst.instruction |= 0x01000000;
8876 if (inst.operands[i].writeback)
8877 inst.instruction |= 0x00200000;
8878 }
8879 else
8880 {
8881 inst.instruction |= 0x00000c00;
8882 if (inst.operands[i].writeback)
8883 inst.instruction |= 0x00000100;
8884 }
8885 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8886 }
8887 else if (inst.operands[i].postind)
8888 {
8889 gas_assert (inst.operands[i].writeback);
8890 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8891 constraint (is_t, _("cannot use post-indexing with this instruction"));
8892
8893 if (is_d)
8894 inst.instruction |= 0x00200000;
8895 else
8896 inst.instruction |= 0x00000900;
8897 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8898 }
8899 else /* unindexed - only for coprocessor */
8900 inst.error = _("instruction does not accept unindexed addressing");
8901 }
8902
8903 /* Table of Thumb instructions which exist in both 16- and 32-bit
8904 encodings (the latter only in post-V6T2 cores). The index is the
8905 value used in the insns table below. When there is more than one
8906 possible 16-bit encoding for the instruction, this table always
8907 holds variant (1).
8908 Also contains several pseudo-instructions used during relaxation. */
8909 #define T16_32_TAB \
8910 X(_adc, 4140, eb400000), \
8911 X(_adcs, 4140, eb500000), \
8912 X(_add, 1c00, eb000000), \
8913 X(_adds, 1c00, eb100000), \
8914 X(_addi, 0000, f1000000), \
8915 X(_addis, 0000, f1100000), \
8916 X(_add_pc,000f, f20f0000), \
8917 X(_add_sp,000d, f10d0000), \
8918 X(_adr, 000f, f20f0000), \
8919 X(_and, 4000, ea000000), \
8920 X(_ands, 4000, ea100000), \
8921 X(_asr, 1000, fa40f000), \
8922 X(_asrs, 1000, fa50f000), \
8923 X(_b, e000, f000b000), \
8924 X(_bcond, d000, f0008000), \
8925 X(_bic, 4380, ea200000), \
8926 X(_bics, 4380, ea300000), \
8927 X(_cmn, 42c0, eb100f00), \
8928 X(_cmp, 2800, ebb00f00), \
8929 X(_cpsie, b660, f3af8400), \
8930 X(_cpsid, b670, f3af8600), \
8931 X(_cpy, 4600, ea4f0000), \
8932 X(_dec_sp,80dd, f1ad0d00), \
8933 X(_eor, 4040, ea800000), \
8934 X(_eors, 4040, ea900000), \
8935 X(_inc_sp,00dd, f10d0d00), \
8936 X(_ldmia, c800, e8900000), \
8937 X(_ldr, 6800, f8500000), \
8938 X(_ldrb, 7800, f8100000), \
8939 X(_ldrh, 8800, f8300000), \
8940 X(_ldrsb, 5600, f9100000), \
8941 X(_ldrsh, 5e00, f9300000), \
8942 X(_ldr_pc,4800, f85f0000), \
8943 X(_ldr_pc2,4800, f85f0000), \
8944 X(_ldr_sp,9800, f85d0000), \
8945 X(_lsl, 0000, fa00f000), \
8946 X(_lsls, 0000, fa10f000), \
8947 X(_lsr, 0800, fa20f000), \
8948 X(_lsrs, 0800, fa30f000), \
8949 X(_mov, 2000, ea4f0000), \
8950 X(_movs, 2000, ea5f0000), \
8951 X(_mul, 4340, fb00f000), \
8952 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8953 X(_mvn, 43c0, ea6f0000), \
8954 X(_mvns, 43c0, ea7f0000), \
8955 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8956 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8957 X(_orr, 4300, ea400000), \
8958 X(_orrs, 4300, ea500000), \
8959 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8960 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8961 X(_rev, ba00, fa90f080), \
8962 X(_rev16, ba40, fa90f090), \
8963 X(_revsh, bac0, fa90f0b0), \
8964 X(_ror, 41c0, fa60f000), \
8965 X(_rors, 41c0, fa70f000), \
8966 X(_sbc, 4180, eb600000), \
8967 X(_sbcs, 4180, eb700000), \
8968 X(_stmia, c000, e8800000), \
8969 X(_str, 6000, f8400000), \
8970 X(_strb, 7000, f8000000), \
8971 X(_strh, 8000, f8200000), \
8972 X(_str_sp,9000, f84d0000), \
8973 X(_sub, 1e00, eba00000), \
8974 X(_subs, 1e00, ebb00000), \
8975 X(_subi, 8000, f1a00000), \
8976 X(_subis, 8000, f1b00000), \
8977 X(_sxtb, b240, fa4ff080), \
8978 X(_sxth, b200, fa0ff080), \
8979 X(_tst, 4200, ea100f00), \
8980 X(_uxtb, b2c0, fa5ff080), \
8981 X(_uxth, b280, fa1ff080), \
8982 X(_nop, bf00, f3af8000), \
8983 X(_yield, bf10, f3af8001), \
8984 X(_wfe, bf20, f3af8002), \
8985 X(_wfi, bf30, f3af8003), \
8986 X(_sev, bf40, f3af8004),
8987
8988 /* To catch errors in encoding functions, the codes are all offset by
8989 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8990 as 16-bit instructions. */
8991 #define X(a,b,c) T_MNEM##a
8992 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8993 #undef X
8994
8995 #define X(a,b,c) 0x##b
8996 static const unsigned short thumb_op16[] = { T16_32_TAB };
8997 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8998 #undef X
8999
9000 #define X(a,b,c) 0x##c
9001 static const unsigned int thumb_op32[] = { T16_32_TAB };
9002 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
9003 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
9004 #undef X
9005 #undef T16_32_TAB
9006
9007 /* Thumb instruction encoders, in alphabetical order. */
9008
9009 /* ADDW or SUBW. */
9010
9011 static void
9012 do_t_add_sub_w (void)
9013 {
9014 int Rd, Rn;
9015
9016 Rd = inst.operands[0].reg;
9017 Rn = inst.operands[1].reg;
9018
9019 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
9020 is the SP-{plus,minus}-immediate form of the instruction. */
9021 if (Rn == REG_SP)
9022 constraint (Rd == REG_PC, BAD_PC);
9023 else
9024 reject_bad_reg (Rd);
9025
9026 inst.instruction |= (Rn << 16) | (Rd << 8);
9027 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9028 }
9029
9030 /* Parse an add or subtract instruction. We get here with inst.instruction
9031 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
9032
9033 static void
9034 do_t_add_sub (void)
9035 {
9036 int Rd, Rs, Rn;
9037
9038 Rd = inst.operands[0].reg;
9039 Rs = (inst.operands[1].present
9040 ? inst.operands[1].reg /* Rd, Rs, foo */
9041 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9042
9043 if (Rd == REG_PC)
9044 set_it_insn_type_last ();
9045
9046 if (unified_syntax)
9047 {
9048 bfd_boolean flags;
9049 bfd_boolean narrow;
9050 int opcode;
9051
9052 flags = (inst.instruction == T_MNEM_adds
9053 || inst.instruction == T_MNEM_subs);
9054 if (flags)
9055 narrow = !in_it_block ();
9056 else
9057 narrow = in_it_block ();
9058 if (!inst.operands[2].isreg)
9059 {
9060 int add;
9061
9062 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9063
9064 add = (inst.instruction == T_MNEM_add
9065 || inst.instruction == T_MNEM_adds);
9066 opcode = 0;
9067 if (inst.size_req != 4)
9068 {
9069 /* Attempt to use a narrow opcode, with relaxation if
9070 appropriate. */
9071 if (Rd == REG_SP && Rs == REG_SP && !flags)
9072 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9073 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9074 opcode = T_MNEM_add_sp;
9075 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9076 opcode = T_MNEM_add_pc;
9077 else if (Rd <= 7 && Rs <= 7 && narrow)
9078 {
9079 if (flags)
9080 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9081 else
9082 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9083 }
9084 if (opcode)
9085 {
9086 inst.instruction = THUMB_OP16(opcode);
9087 inst.instruction |= (Rd << 4) | Rs;
9088 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9089 if (inst.size_req != 2)
9090 inst.relax = opcode;
9091 }
9092 else
9093 constraint (inst.size_req == 2, BAD_HIREG);
9094 }
9095 if (inst.size_req == 4
9096 || (inst.size_req != 2 && !opcode))
9097 {
9098 if (Rd == REG_PC)
9099 {
9100 constraint (add, BAD_PC);
9101 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9102 _("only SUBS PC, LR, #const allowed"));
9103 constraint (inst.reloc.exp.X_op != O_constant,
9104 _("expression too complex"));
9105 constraint (inst.reloc.exp.X_add_number < 0
9106 || inst.reloc.exp.X_add_number > 0xff,
9107 _("immediate value out of range"));
9108 inst.instruction = T2_SUBS_PC_LR
9109 | inst.reloc.exp.X_add_number;
9110 inst.reloc.type = BFD_RELOC_UNUSED;
9111 return;
9112 }
9113 else if (Rs == REG_PC)
9114 {
9115 /* Always use addw/subw. */
9116 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9117 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9118 }
9119 else
9120 {
9121 inst.instruction = THUMB_OP32 (inst.instruction);
9122 inst.instruction = (inst.instruction & 0xe1ffffff)
9123 | 0x10000000;
9124 if (flags)
9125 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9126 else
9127 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9128 }
9129 inst.instruction |= Rd << 8;
9130 inst.instruction |= Rs << 16;
9131 }
9132 }
9133 else
9134 {
9135 Rn = inst.operands[2].reg;
9136 /* See if we can do this with a 16-bit instruction. */
9137 if (!inst.operands[2].shifted && inst.size_req != 4)
9138 {
9139 if (Rd > 7 || Rs > 7 || Rn > 7)
9140 narrow = FALSE;
9141
9142 if (narrow)
9143 {
9144 inst.instruction = ((inst.instruction == T_MNEM_adds
9145 || inst.instruction == T_MNEM_add)
9146 ? T_OPCODE_ADD_R3
9147 : T_OPCODE_SUB_R3);
9148 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9149 return;
9150 }
9151
9152 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9153 {
9154 /* Thumb-1 cores (except v6-M) require at least one high
9155 register in a narrow non flag setting add. */
9156 if (Rd > 7 || Rn > 7
9157 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9158 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9159 {
9160 if (Rd == Rn)
9161 {
9162 Rn = Rs;
9163 Rs = Rd;
9164 }
9165 inst.instruction = T_OPCODE_ADD_HI;
9166 inst.instruction |= (Rd & 8) << 4;
9167 inst.instruction |= (Rd & 7);
9168 inst.instruction |= Rn << 3;
9169 return;
9170 }
9171 }
9172 }
9173
9174 constraint (Rd == REG_PC, BAD_PC);
9175 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9176 constraint (Rs == REG_PC, BAD_PC);
9177 reject_bad_reg (Rn);
9178
9179 /* If we get here, it can't be done in 16 bits. */
9180 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9181 _("shift must be constant"));
9182 inst.instruction = THUMB_OP32 (inst.instruction);
9183 inst.instruction |= Rd << 8;
9184 inst.instruction |= Rs << 16;
9185 encode_thumb32_shifted_operand (2);
9186 }
9187 }
9188 else
9189 {
9190 constraint (inst.instruction == T_MNEM_adds
9191 || inst.instruction == T_MNEM_subs,
9192 BAD_THUMB32);
9193
9194 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9195 {
9196 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9197 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9198 BAD_HIREG);
9199
9200 inst.instruction = (inst.instruction == T_MNEM_add
9201 ? 0x0000 : 0x8000);
9202 inst.instruction |= (Rd << 4) | Rs;
9203 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9204 return;
9205 }
9206
9207 Rn = inst.operands[2].reg;
9208 constraint (inst.operands[2].shifted, _("unshifted register required"));
9209
9210 /* We now have Rd, Rs, and Rn set to registers. */
9211 if (Rd > 7 || Rs > 7 || Rn > 7)
9212 {
9213 /* Can't do this for SUB. */
9214 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9215 inst.instruction = T_OPCODE_ADD_HI;
9216 inst.instruction |= (Rd & 8) << 4;
9217 inst.instruction |= (Rd & 7);
9218 if (Rs == Rd)
9219 inst.instruction |= Rn << 3;
9220 else if (Rn == Rd)
9221 inst.instruction |= Rs << 3;
9222 else
9223 constraint (1, _("dest must overlap one source register"));
9224 }
9225 else
9226 {
9227 inst.instruction = (inst.instruction == T_MNEM_add
9228 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9229 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9230 }
9231 }
9232 }
9233
9234 static void
9235 do_t_adr (void)
9236 {
9237 unsigned Rd;
9238
9239 Rd = inst.operands[0].reg;
9240 reject_bad_reg (Rd);
9241
9242 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9243 {
9244 /* Defer to section relaxation. */
9245 inst.relax = inst.instruction;
9246 inst.instruction = THUMB_OP16 (inst.instruction);
9247 inst.instruction |= Rd << 4;
9248 }
9249 else if (unified_syntax && inst.size_req != 2)
9250 {
9251 /* Generate a 32-bit opcode. */
9252 inst.instruction = THUMB_OP32 (inst.instruction);
9253 inst.instruction |= Rd << 8;
9254 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9255 inst.reloc.pc_rel = 1;
9256 }
9257 else
9258 {
9259 /* Generate a 16-bit opcode. */
9260 inst.instruction = THUMB_OP16 (inst.instruction);
9261 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9262 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9263 inst.reloc.pc_rel = 1;
9264
9265 inst.instruction |= Rd << 4;
9266 }
9267 }
9268
9269 /* Arithmetic instructions for which there is just one 16-bit
9270 instruction encoding, and it allows only two low registers.
9271 For maximal compatibility with ARM syntax, we allow three register
9272 operands even when Thumb-32 instructions are not available, as long
9273 as the first two are identical. For instance, both "sbc r0,r1" and
9274 "sbc r0,r0,r1" are allowed. */
9275 static void
9276 do_t_arit3 (void)
9277 {
9278 int Rd, Rs, Rn;
9279
9280 Rd = inst.operands[0].reg;
9281 Rs = (inst.operands[1].present
9282 ? inst.operands[1].reg /* Rd, Rs, foo */
9283 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9284 Rn = inst.operands[2].reg;
9285
9286 reject_bad_reg (Rd);
9287 reject_bad_reg (Rs);
9288 if (inst.operands[2].isreg)
9289 reject_bad_reg (Rn);
9290
9291 if (unified_syntax)
9292 {
9293 if (!inst.operands[2].isreg)
9294 {
9295 /* For an immediate, we always generate a 32-bit opcode;
9296 section relaxation will shrink it later if possible. */
9297 inst.instruction = THUMB_OP32 (inst.instruction);
9298 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9299 inst.instruction |= Rd << 8;
9300 inst.instruction |= Rs << 16;
9301 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9302 }
9303 else
9304 {
9305 bfd_boolean narrow;
9306
9307 /* See if we can do this with a 16-bit instruction. */
9308 if (THUMB_SETS_FLAGS (inst.instruction))
9309 narrow = !in_it_block ();
9310 else
9311 narrow = in_it_block ();
9312
9313 if (Rd > 7 || Rn > 7 || Rs > 7)
9314 narrow = FALSE;
9315 if (inst.operands[2].shifted)
9316 narrow = FALSE;
9317 if (inst.size_req == 4)
9318 narrow = FALSE;
9319
9320 if (narrow
9321 && Rd == Rs)
9322 {
9323 inst.instruction = THUMB_OP16 (inst.instruction);
9324 inst.instruction |= Rd;
9325 inst.instruction |= Rn << 3;
9326 return;
9327 }
9328
9329 /* If we get here, it can't be done in 16 bits. */
9330 constraint (inst.operands[2].shifted
9331 && inst.operands[2].immisreg,
9332 _("shift must be constant"));
9333 inst.instruction = THUMB_OP32 (inst.instruction);
9334 inst.instruction |= Rd << 8;
9335 inst.instruction |= Rs << 16;
9336 encode_thumb32_shifted_operand (2);
9337 }
9338 }
9339 else
9340 {
9341 /* On its face this is a lie - the instruction does set the
9342 flags. However, the only supported mnemonic in this mode
9343 says it doesn't. */
9344 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9345
9346 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9347 _("unshifted register required"));
9348 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9349 constraint (Rd != Rs,
9350 _("dest and source1 must be the same register"));
9351
9352 inst.instruction = THUMB_OP16 (inst.instruction);
9353 inst.instruction |= Rd;
9354 inst.instruction |= Rn << 3;
9355 }
9356 }
9357
9358 /* Similarly, but for instructions where the arithmetic operation is
9359 commutative, so we can allow either of them to be different from
9360 the destination operand in a 16-bit instruction. For instance, all
9361 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9362 accepted. */
9363 static void
9364 do_t_arit3c (void)
9365 {
9366 int Rd, Rs, Rn;
9367
9368 Rd = inst.operands[0].reg;
9369 Rs = (inst.operands[1].present
9370 ? inst.operands[1].reg /* Rd, Rs, foo */
9371 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9372 Rn = inst.operands[2].reg;
9373
9374 reject_bad_reg (Rd);
9375 reject_bad_reg (Rs);
9376 if (inst.operands[2].isreg)
9377 reject_bad_reg (Rn);
9378
9379 if (unified_syntax)
9380 {
9381 if (!inst.operands[2].isreg)
9382 {
9383 /* For an immediate, we always generate a 32-bit opcode;
9384 section relaxation will shrink it later if possible. */
9385 inst.instruction = THUMB_OP32 (inst.instruction);
9386 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9387 inst.instruction |= Rd << 8;
9388 inst.instruction |= Rs << 16;
9389 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9390 }
9391 else
9392 {
9393 bfd_boolean narrow;
9394
9395 /* See if we can do this with a 16-bit instruction. */
9396 if (THUMB_SETS_FLAGS (inst.instruction))
9397 narrow = !in_it_block ();
9398 else
9399 narrow = in_it_block ();
9400
9401 if (Rd > 7 || Rn > 7 || Rs > 7)
9402 narrow = FALSE;
9403 if (inst.operands[2].shifted)
9404 narrow = FALSE;
9405 if (inst.size_req == 4)
9406 narrow = FALSE;
9407
9408 if (narrow)
9409 {
9410 if (Rd == Rs)
9411 {
9412 inst.instruction = THUMB_OP16 (inst.instruction);
9413 inst.instruction |= Rd;
9414 inst.instruction |= Rn << 3;
9415 return;
9416 }
9417 if (Rd == Rn)
9418 {
9419 inst.instruction = THUMB_OP16 (inst.instruction);
9420 inst.instruction |= Rd;
9421 inst.instruction |= Rs << 3;
9422 return;
9423 }
9424 }
9425
9426 /* If we get here, it can't be done in 16 bits. */
9427 constraint (inst.operands[2].shifted
9428 && inst.operands[2].immisreg,
9429 _("shift must be constant"));
9430 inst.instruction = THUMB_OP32 (inst.instruction);
9431 inst.instruction |= Rd << 8;
9432 inst.instruction |= Rs << 16;
9433 encode_thumb32_shifted_operand (2);
9434 }
9435 }
9436 else
9437 {
9438 /* On its face this is a lie - the instruction does set the
9439 flags. However, the only supported mnemonic in this mode
9440 says it doesn't. */
9441 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9442
9443 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9444 _("unshifted register required"));
9445 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9446
9447 inst.instruction = THUMB_OP16 (inst.instruction);
9448 inst.instruction |= Rd;
9449
9450 if (Rd == Rs)
9451 inst.instruction |= Rn << 3;
9452 else if (Rd == Rn)
9453 inst.instruction |= Rs << 3;
9454 else
9455 constraint (1, _("dest must overlap one source register"));
9456 }
9457 }
9458
9459 static void
9460 do_t_barrier (void)
9461 {
9462 if (inst.operands[0].present)
9463 {
9464 constraint ((inst.instruction & 0xf0) != 0x40
9465 && inst.operands[0].imm > 0xf
9466 && inst.operands[0].imm < 0x0,
9467 _("bad barrier type"));
9468 inst.instruction |= inst.operands[0].imm;
9469 }
9470 else
9471 inst.instruction |= 0xf;
9472 }
9473
9474 static void
9475 do_t_bfc (void)
9476 {
9477 unsigned Rd;
9478 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9479 constraint (msb > 32, _("bit-field extends past end of register"));
9480 /* The instruction encoding stores the LSB and MSB,
9481 not the LSB and width. */
9482 Rd = inst.operands[0].reg;
9483 reject_bad_reg (Rd);
9484 inst.instruction |= Rd << 8;
9485 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9486 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9487 inst.instruction |= msb - 1;
9488 }
9489
9490 static void
9491 do_t_bfi (void)
9492 {
9493 int Rd, Rn;
9494 unsigned int msb;
9495
9496 Rd = inst.operands[0].reg;
9497 reject_bad_reg (Rd);
9498
9499 /* #0 in second position is alternative syntax for bfc, which is
9500 the same instruction but with REG_PC in the Rm field. */
9501 if (!inst.operands[1].isreg)
9502 Rn = REG_PC;
9503 else
9504 {
9505 Rn = inst.operands[1].reg;
9506 reject_bad_reg (Rn);
9507 }
9508
9509 msb = inst.operands[2].imm + inst.operands[3].imm;
9510 constraint (msb > 32, _("bit-field extends past end of register"));
9511 /* The instruction encoding stores the LSB and MSB,
9512 not the LSB and width. */
9513 inst.instruction |= Rd << 8;
9514 inst.instruction |= Rn << 16;
9515 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9516 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9517 inst.instruction |= msb - 1;
9518 }
9519
9520 static void
9521 do_t_bfx (void)
9522 {
9523 unsigned Rd, Rn;
9524
9525 Rd = inst.operands[0].reg;
9526 Rn = inst.operands[1].reg;
9527
9528 reject_bad_reg (Rd);
9529 reject_bad_reg (Rn);
9530
9531 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9532 _("bit-field extends past end of register"));
9533 inst.instruction |= Rd << 8;
9534 inst.instruction |= Rn << 16;
9535 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9536 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9537 inst.instruction |= inst.operands[3].imm - 1;
9538 }
9539
9540 /* ARM V5 Thumb BLX (argument parse)
9541 BLX <target_addr> which is BLX(1)
9542 BLX <Rm> which is BLX(2)
9543 Unfortunately, there are two different opcodes for this mnemonic.
9544 So, the insns[].value is not used, and the code here zaps values
9545 into inst.instruction.
9546
9547 ??? How to take advantage of the additional two bits of displacement
9548 available in Thumb32 mode? Need new relocation? */
9549
9550 static void
9551 do_t_blx (void)
9552 {
9553 set_it_insn_type_last ();
9554
9555 if (inst.operands[0].isreg)
9556 {
9557 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9558 /* We have a register, so this is BLX(2). */
9559 inst.instruction |= inst.operands[0].reg << 3;
9560 }
9561 else
9562 {
9563 /* No register. This must be BLX(1). */
9564 inst.instruction = 0xf000e800;
9565 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
9566 inst.reloc.pc_rel = 1;
9567 }
9568 }
9569
9570 static void
9571 do_t_branch (void)
9572 {
9573 int opcode;
9574 int cond;
9575
9576 cond = inst.cond;
9577 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9578
9579 if (in_it_block ())
9580 {
9581 /* Conditional branches inside IT blocks are encoded as unconditional
9582 branches. */
9583 cond = COND_ALWAYS;
9584 }
9585 else
9586 cond = inst.cond;
9587
9588 if (cond != COND_ALWAYS)
9589 opcode = T_MNEM_bcond;
9590 else
9591 opcode = inst.instruction;
9592
9593 if (unified_syntax && inst.size_req == 4)
9594 {
9595 inst.instruction = THUMB_OP32(opcode);
9596 if (cond == COND_ALWAYS)
9597 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
9598 else
9599 {
9600 gas_assert (cond != 0xF);
9601 inst.instruction |= cond << 22;
9602 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9603 }
9604 }
9605 else
9606 {
9607 inst.instruction = THUMB_OP16(opcode);
9608 if (cond == COND_ALWAYS)
9609 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9610 else
9611 {
9612 inst.instruction |= cond << 8;
9613 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
9614 }
9615 /* Allow section relaxation. */
9616 if (unified_syntax && inst.size_req != 2)
9617 inst.relax = opcode;
9618 }
9619
9620 inst.reloc.pc_rel = 1;
9621 }
9622
9623 static void
9624 do_t_bkpt (void)
9625 {
9626 constraint (inst.cond != COND_ALWAYS,
9627 _("instruction is always unconditional"));
9628 if (inst.operands[0].present)
9629 {
9630 constraint (inst.operands[0].imm > 255,
9631 _("immediate value out of range"));
9632 inst.instruction |= inst.operands[0].imm;
9633 set_it_insn_type (NEUTRAL_IT_INSN);
9634 }
9635 }
9636
9637 static void
9638 do_t_branch23 (void)
9639 {
9640 set_it_insn_type_last ();
9641 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9642 inst.reloc.pc_rel = 1;
9643
9644 #if defined(OBJ_COFF)
9645 /* If the destination of the branch is a defined symbol which does not have
9646 the THUMB_FUNC attribute, then we must be calling a function which has
9647 the (interfacearm) attribute. We look for the Thumb entry point to that
9648 function and change the branch to refer to that function instead. */
9649 if ( inst.reloc.exp.X_op == O_symbol
9650 && inst.reloc.exp.X_add_symbol != NULL
9651 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9652 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9653 inst.reloc.exp.X_add_symbol =
9654 find_real_start (inst.reloc.exp.X_add_symbol);
9655 #endif
9656 }
9657
9658 static void
9659 do_t_bx (void)
9660 {
9661 set_it_insn_type_last ();
9662 inst.instruction |= inst.operands[0].reg << 3;
9663 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9664 should cause the alignment to be checked once it is known. This is
9665 because BX PC only works if the instruction is word aligned. */
9666 }
9667
9668 static void
9669 do_t_bxj (void)
9670 {
9671 int Rm;
9672
9673 set_it_insn_type_last ();
9674 Rm = inst.operands[0].reg;
9675 reject_bad_reg (Rm);
9676 inst.instruction |= Rm << 16;
9677 }
9678
9679 static void
9680 do_t_clz (void)
9681 {
9682 unsigned Rd;
9683 unsigned Rm;
9684
9685 Rd = inst.operands[0].reg;
9686 Rm = inst.operands[1].reg;
9687
9688 reject_bad_reg (Rd);
9689 reject_bad_reg (Rm);
9690
9691 inst.instruction |= Rd << 8;
9692 inst.instruction |= Rm << 16;
9693 inst.instruction |= Rm;
9694 }
9695
9696 static void
9697 do_t_cps (void)
9698 {
9699 set_it_insn_type (OUTSIDE_IT_INSN);
9700 inst.instruction |= inst.operands[0].imm;
9701 }
9702
9703 static void
9704 do_t_cpsi (void)
9705 {
9706 set_it_insn_type (OUTSIDE_IT_INSN);
9707 if (unified_syntax
9708 && (inst.operands[1].present || inst.size_req == 4)
9709 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9710 {
9711 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9712 inst.instruction = 0xf3af8000;
9713 inst.instruction |= imod << 9;
9714 inst.instruction |= inst.operands[0].imm << 5;
9715 if (inst.operands[1].present)
9716 inst.instruction |= 0x100 | inst.operands[1].imm;
9717 }
9718 else
9719 {
9720 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9721 && (inst.operands[0].imm & 4),
9722 _("selected processor does not support 'A' form "
9723 "of this instruction"));
9724 constraint (inst.operands[1].present || inst.size_req == 4,
9725 _("Thumb does not support the 2-argument "
9726 "form of this instruction"));
9727 inst.instruction |= inst.operands[0].imm;
9728 }
9729 }
9730
9731 /* THUMB CPY instruction (argument parse). */
9732
9733 static void
9734 do_t_cpy (void)
9735 {
9736 if (inst.size_req == 4)
9737 {
9738 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9739 inst.instruction |= inst.operands[0].reg << 8;
9740 inst.instruction |= inst.operands[1].reg;
9741 }
9742 else
9743 {
9744 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9745 inst.instruction |= (inst.operands[0].reg & 0x7);
9746 inst.instruction |= inst.operands[1].reg << 3;
9747 }
9748 }
9749
9750 static void
9751 do_t_cbz (void)
9752 {
9753 set_it_insn_type (OUTSIDE_IT_INSN);
9754 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9755 inst.instruction |= inst.operands[0].reg;
9756 inst.reloc.pc_rel = 1;
9757 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9758 }
9759
9760 static void
9761 do_t_dbg (void)
9762 {
9763 inst.instruction |= inst.operands[0].imm;
9764 }
9765
9766 static void
9767 do_t_div (void)
9768 {
9769 unsigned Rd, Rn, Rm;
9770
9771 Rd = inst.operands[0].reg;
9772 Rn = (inst.operands[1].present
9773 ? inst.operands[1].reg : Rd);
9774 Rm = inst.operands[2].reg;
9775
9776 reject_bad_reg (Rd);
9777 reject_bad_reg (Rn);
9778 reject_bad_reg (Rm);
9779
9780 inst.instruction |= Rd << 8;
9781 inst.instruction |= Rn << 16;
9782 inst.instruction |= Rm;
9783 }
9784
9785 static void
9786 do_t_hint (void)
9787 {
9788 if (unified_syntax && inst.size_req == 4)
9789 inst.instruction = THUMB_OP32 (inst.instruction);
9790 else
9791 inst.instruction = THUMB_OP16 (inst.instruction);
9792 }
9793
9794 static void
9795 do_t_it (void)
9796 {
9797 unsigned int cond = inst.operands[0].imm;
9798
9799 set_it_insn_type (IT_INSN);
9800 now_it.mask = (inst.instruction & 0xf) | 0x10;
9801 now_it.cc = cond;
9802
9803 /* If the condition is a negative condition, invert the mask. */
9804 if ((cond & 0x1) == 0x0)
9805 {
9806 unsigned int mask = inst.instruction & 0x000f;
9807
9808 if ((mask & 0x7) == 0)
9809 /* no conversion needed */;
9810 else if ((mask & 0x3) == 0)
9811 mask ^= 0x8;
9812 else if ((mask & 0x1) == 0)
9813 mask ^= 0xC;
9814 else
9815 mask ^= 0xE;
9816
9817 inst.instruction &= 0xfff0;
9818 inst.instruction |= mask;
9819 }
9820
9821 inst.instruction |= cond << 4;
9822 }
9823
9824 /* Helper function used for both push/pop and ldm/stm. */
9825 static void
9826 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9827 {
9828 bfd_boolean load;
9829
9830 load = (inst.instruction & (1 << 20)) != 0;
9831
9832 if (mask & (1 << 13))
9833 inst.error = _("SP not allowed in register list");
9834
9835 if ((mask & (1 << base)) != 0
9836 && writeback)
9837 inst.error = _("having the base register in the register list when "
9838 "using write back is UNPREDICTABLE");
9839
9840 if (load)
9841 {
9842 if (mask & (1 << 15))
9843 {
9844 if (mask & (1 << 14))
9845 inst.error = _("LR and PC should not both be in register list");
9846 else
9847 set_it_insn_type_last ();
9848 }
9849 }
9850 else
9851 {
9852 if (mask & (1 << 15))
9853 inst.error = _("PC not allowed in register list");
9854 }
9855
9856 if ((mask & (mask - 1)) == 0)
9857 {
9858 /* Single register transfers implemented as str/ldr. */
9859 if (writeback)
9860 {
9861 if (inst.instruction & (1 << 23))
9862 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9863 else
9864 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9865 }
9866 else
9867 {
9868 if (inst.instruction & (1 << 23))
9869 inst.instruction = 0x00800000; /* ia -> [base] */
9870 else
9871 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9872 }
9873
9874 inst.instruction |= 0xf8400000;
9875 if (load)
9876 inst.instruction |= 0x00100000;
9877
9878 mask = ffs (mask) - 1;
9879 mask <<= 12;
9880 }
9881 else if (writeback)
9882 inst.instruction |= WRITE_BACK;
9883
9884 inst.instruction |= mask;
9885 inst.instruction |= base << 16;
9886 }
9887
9888 static void
9889 do_t_ldmstm (void)
9890 {
9891 /* This really doesn't seem worth it. */
9892 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9893 _("expression too complex"));
9894 constraint (inst.operands[1].writeback,
9895 _("Thumb load/store multiple does not support {reglist}^"));
9896
9897 if (unified_syntax)
9898 {
9899 bfd_boolean narrow;
9900 unsigned mask;
9901
9902 narrow = FALSE;
9903 /* See if we can use a 16-bit instruction. */
9904 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9905 && inst.size_req != 4
9906 && !(inst.operands[1].imm & ~0xff))
9907 {
9908 mask = 1 << inst.operands[0].reg;
9909
9910 if (inst.operands[0].reg <= 7
9911 && (inst.instruction == T_MNEM_stmia
9912 ? inst.operands[0].writeback
9913 : (inst.operands[0].writeback
9914 == !(inst.operands[1].imm & mask))))
9915 {
9916 if (inst.instruction == T_MNEM_stmia
9917 && (inst.operands[1].imm & mask)
9918 && (inst.operands[1].imm & (mask - 1)))
9919 as_warn (_("value stored for r%d is UNKNOWN"),
9920 inst.operands[0].reg);
9921
9922 inst.instruction = THUMB_OP16 (inst.instruction);
9923 inst.instruction |= inst.operands[0].reg << 8;
9924 inst.instruction |= inst.operands[1].imm;
9925 narrow = TRUE;
9926 }
9927 else if (inst.operands[0] .reg == REG_SP
9928 && inst.operands[0].writeback)
9929 {
9930 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9931 ? T_MNEM_push : T_MNEM_pop);
9932 inst.instruction |= inst.operands[1].imm;
9933 narrow = TRUE;
9934 }
9935 }
9936
9937 if (!narrow)
9938 {
9939 if (inst.instruction < 0xffff)
9940 inst.instruction = THUMB_OP32 (inst.instruction);
9941
9942 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9943 inst.operands[0].writeback);
9944 }
9945 }
9946 else
9947 {
9948 constraint (inst.operands[0].reg > 7
9949 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9950 constraint (inst.instruction != T_MNEM_ldmia
9951 && inst.instruction != T_MNEM_stmia,
9952 _("Thumb-2 instruction only valid in unified syntax"));
9953 if (inst.instruction == T_MNEM_stmia)
9954 {
9955 if (!inst.operands[0].writeback)
9956 as_warn (_("this instruction will write back the base register"));
9957 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9958 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9959 as_warn (_("value stored for r%d is UNKNOWN"),
9960 inst.operands[0].reg);
9961 }
9962 else
9963 {
9964 if (!inst.operands[0].writeback
9965 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9966 as_warn (_("this instruction will write back the base register"));
9967 else if (inst.operands[0].writeback
9968 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9969 as_warn (_("this instruction will not write back the base register"));
9970 }
9971
9972 inst.instruction = THUMB_OP16 (inst.instruction);
9973 inst.instruction |= inst.operands[0].reg << 8;
9974 inst.instruction |= inst.operands[1].imm;
9975 }
9976 }
9977
9978 static void
9979 do_t_ldrex (void)
9980 {
9981 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9982 || inst.operands[1].postind || inst.operands[1].writeback
9983 || inst.operands[1].immisreg || inst.operands[1].shifted
9984 || inst.operands[1].negative,
9985 BAD_ADDR_MODE);
9986
9987 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9988
9989 inst.instruction |= inst.operands[0].reg << 12;
9990 inst.instruction |= inst.operands[1].reg << 16;
9991 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9992 }
9993
9994 static void
9995 do_t_ldrexd (void)
9996 {
9997 if (!inst.operands[1].present)
9998 {
9999 constraint (inst.operands[0].reg == REG_LR,
10000 _("r14 not allowed as first register "
10001 "when second register is omitted"));
10002 inst.operands[1].reg = inst.operands[0].reg + 1;
10003 }
10004 constraint (inst.operands[0].reg == inst.operands[1].reg,
10005 BAD_OVERLAP);
10006
10007 inst.instruction |= inst.operands[0].reg << 12;
10008 inst.instruction |= inst.operands[1].reg << 8;
10009 inst.instruction |= inst.operands[2].reg << 16;
10010 }
10011
10012 static void
10013 do_t_ldst (void)
10014 {
10015 unsigned long opcode;
10016 int Rn;
10017
10018 if (inst.operands[0].isreg
10019 && !inst.operands[0].preind
10020 && inst.operands[0].reg == REG_PC)
10021 set_it_insn_type_last ();
10022
10023 opcode = inst.instruction;
10024 if (unified_syntax)
10025 {
10026 if (!inst.operands[1].isreg)
10027 {
10028 if (opcode <= 0xffff)
10029 inst.instruction = THUMB_OP32 (opcode);
10030 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10031 return;
10032 }
10033 if (inst.operands[1].isreg
10034 && !inst.operands[1].writeback
10035 && !inst.operands[1].shifted && !inst.operands[1].postind
10036 && !inst.operands[1].negative && inst.operands[0].reg <= 7
10037 && opcode <= 0xffff
10038 && inst.size_req != 4)
10039 {
10040 /* Insn may have a 16-bit form. */
10041 Rn = inst.operands[1].reg;
10042 if (inst.operands[1].immisreg)
10043 {
10044 inst.instruction = THUMB_OP16 (opcode);
10045 /* [Rn, Rik] */
10046 if (Rn <= 7 && inst.operands[1].imm <= 7)
10047 goto op16;
10048 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
10049 reject_bad_reg (inst.operands[1].imm);
10050 }
10051 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
10052 && opcode != T_MNEM_ldrsb)
10053 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
10054 || (Rn == REG_SP && opcode == T_MNEM_str))
10055 {
10056 /* [Rn, #const] */
10057 if (Rn > 7)
10058 {
10059 if (Rn == REG_PC)
10060 {
10061 if (inst.reloc.pc_rel)
10062 opcode = T_MNEM_ldr_pc2;
10063 else
10064 opcode = T_MNEM_ldr_pc;
10065 }
10066 else
10067 {
10068 if (opcode == T_MNEM_ldr)
10069 opcode = T_MNEM_ldr_sp;
10070 else
10071 opcode = T_MNEM_str_sp;
10072 }
10073 inst.instruction = inst.operands[0].reg << 8;
10074 }
10075 else
10076 {
10077 inst.instruction = inst.operands[0].reg;
10078 inst.instruction |= inst.operands[1].reg << 3;
10079 }
10080 inst.instruction |= THUMB_OP16 (opcode);
10081 if (inst.size_req == 2)
10082 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10083 else
10084 inst.relax = opcode;
10085 return;
10086 }
10087 }
10088 /* Definitely a 32-bit variant. */
10089
10090 /* Do some validations regarding addressing modes. */
10091 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10092 && opcode != T_MNEM_str)
10093 reject_bad_reg (inst.operands[1].imm);
10094
10095 inst.instruction = THUMB_OP32 (opcode);
10096 inst.instruction |= inst.operands[0].reg << 12;
10097 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10098 return;
10099 }
10100
10101 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10102
10103 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10104 {
10105 /* Only [Rn,Rm] is acceptable. */
10106 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10107 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10108 || inst.operands[1].postind || inst.operands[1].shifted
10109 || inst.operands[1].negative,
10110 _("Thumb does not support this addressing mode"));
10111 inst.instruction = THUMB_OP16 (inst.instruction);
10112 goto op16;
10113 }
10114
10115 inst.instruction = THUMB_OP16 (inst.instruction);
10116 if (!inst.operands[1].isreg)
10117 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10118 return;
10119
10120 constraint (!inst.operands[1].preind
10121 || inst.operands[1].shifted
10122 || inst.operands[1].writeback,
10123 _("Thumb does not support this addressing mode"));
10124 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10125 {
10126 constraint (inst.instruction & 0x0600,
10127 _("byte or halfword not valid for base register"));
10128 constraint (inst.operands[1].reg == REG_PC
10129 && !(inst.instruction & THUMB_LOAD_BIT),
10130 _("r15 based store not allowed"));
10131 constraint (inst.operands[1].immisreg,
10132 _("invalid base register for register offset"));
10133
10134 if (inst.operands[1].reg == REG_PC)
10135 inst.instruction = T_OPCODE_LDR_PC;
10136 else if (inst.instruction & THUMB_LOAD_BIT)
10137 inst.instruction = T_OPCODE_LDR_SP;
10138 else
10139 inst.instruction = T_OPCODE_STR_SP;
10140
10141 inst.instruction |= inst.operands[0].reg << 8;
10142 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10143 return;
10144 }
10145
10146 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10147 if (!inst.operands[1].immisreg)
10148 {
10149 /* Immediate offset. */
10150 inst.instruction |= inst.operands[0].reg;
10151 inst.instruction |= inst.operands[1].reg << 3;
10152 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10153 return;
10154 }
10155
10156 /* Register offset. */
10157 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10158 constraint (inst.operands[1].negative,
10159 _("Thumb does not support this addressing mode"));
10160
10161 op16:
10162 switch (inst.instruction)
10163 {
10164 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10165 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10166 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10167 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10168 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10169 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10170 case 0x5600 /* ldrsb */:
10171 case 0x5e00 /* ldrsh */: break;
10172 default: abort ();
10173 }
10174
10175 inst.instruction |= inst.operands[0].reg;
10176 inst.instruction |= inst.operands[1].reg << 3;
10177 inst.instruction |= inst.operands[1].imm << 6;
10178 }
10179
10180 static void
10181 do_t_ldstd (void)
10182 {
10183 if (!inst.operands[1].present)
10184 {
10185 inst.operands[1].reg = inst.operands[0].reg + 1;
10186 constraint (inst.operands[0].reg == REG_LR,
10187 _("r14 not allowed here"));
10188 }
10189 inst.instruction |= inst.operands[0].reg << 12;
10190 inst.instruction |= inst.operands[1].reg << 8;
10191 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10192 }
10193
10194 static void
10195 do_t_ldstt (void)
10196 {
10197 inst.instruction |= inst.operands[0].reg << 12;
10198 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10199 }
10200
10201 static void
10202 do_t_mla (void)
10203 {
10204 unsigned Rd, Rn, Rm, Ra;
10205
10206 Rd = inst.operands[0].reg;
10207 Rn = inst.operands[1].reg;
10208 Rm = inst.operands[2].reg;
10209 Ra = inst.operands[3].reg;
10210
10211 reject_bad_reg (Rd);
10212 reject_bad_reg (Rn);
10213 reject_bad_reg (Rm);
10214 reject_bad_reg (Ra);
10215
10216 inst.instruction |= Rd << 8;
10217 inst.instruction |= Rn << 16;
10218 inst.instruction |= Rm;
10219 inst.instruction |= Ra << 12;
10220 }
10221
10222 static void
10223 do_t_mlal (void)
10224 {
10225 unsigned RdLo, RdHi, Rn, Rm;
10226
10227 RdLo = inst.operands[0].reg;
10228 RdHi = inst.operands[1].reg;
10229 Rn = inst.operands[2].reg;
10230 Rm = inst.operands[3].reg;
10231
10232 reject_bad_reg (RdLo);
10233 reject_bad_reg (RdHi);
10234 reject_bad_reg (Rn);
10235 reject_bad_reg (Rm);
10236
10237 inst.instruction |= RdLo << 12;
10238 inst.instruction |= RdHi << 8;
10239 inst.instruction |= Rn << 16;
10240 inst.instruction |= Rm;
10241 }
10242
10243 static void
10244 do_t_mov_cmp (void)
10245 {
10246 unsigned Rn, Rm;
10247
10248 Rn = inst.operands[0].reg;
10249 Rm = inst.operands[1].reg;
10250
10251 if (Rn == REG_PC)
10252 set_it_insn_type_last ();
10253
10254 if (unified_syntax)
10255 {
10256 int r0off = (inst.instruction == T_MNEM_mov
10257 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10258 unsigned long opcode;
10259 bfd_boolean narrow;
10260 bfd_boolean low_regs;
10261
10262 low_regs = (Rn <= 7 && Rm <= 7);
10263 opcode = inst.instruction;
10264 if (in_it_block ())
10265 narrow = opcode != T_MNEM_movs;
10266 else
10267 narrow = opcode != T_MNEM_movs || low_regs;
10268 if (inst.size_req == 4
10269 || inst.operands[1].shifted)
10270 narrow = FALSE;
10271
10272 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10273 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10274 && !inst.operands[1].shifted
10275 && Rn == REG_PC
10276 && Rm == REG_LR)
10277 {
10278 inst.instruction = T2_SUBS_PC_LR;
10279 return;
10280 }
10281
10282 if (opcode == T_MNEM_cmp)
10283 {
10284 constraint (Rn == REG_PC, BAD_PC);
10285 if (narrow)
10286 {
10287 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10288 but valid. */
10289 warn_deprecated_sp (Rm);
10290 /* R15 was documented as a valid choice for Rm in ARMv6,
10291 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10292 tools reject R15, so we do too. */
10293 constraint (Rm == REG_PC, BAD_PC);
10294 }
10295 else
10296 reject_bad_reg (Rm);
10297 }
10298 else if (opcode == T_MNEM_mov
10299 || opcode == T_MNEM_movs)
10300 {
10301 if (inst.operands[1].isreg)
10302 {
10303 if (opcode == T_MNEM_movs)
10304 {
10305 reject_bad_reg (Rn);
10306 reject_bad_reg (Rm);
10307 }
10308 else if (narrow)
10309 {
10310 /* This is mov.n. */
10311 if ((Rn == REG_SP || Rn == REG_PC)
10312 && (Rm == REG_SP || Rm == REG_PC))
10313 {
10314 as_warn (_("Use of r%u as a source register is "
10315 "deprecated when r%u is the destination "
10316 "register."), Rm, Rn);
10317 }
10318 }
10319 else
10320 {
10321 /* This is mov.w. */
10322 constraint (Rn == REG_PC, BAD_PC);
10323 constraint (Rm == REG_PC, BAD_PC);
10324 constraint (Rn == REG_SP && Rm == REG_SP, BAD_SP);
10325 }
10326 }
10327 else
10328 reject_bad_reg (Rn);
10329 }
10330
10331 if (!inst.operands[1].isreg)
10332 {
10333 /* Immediate operand. */
10334 if (!in_it_block () && opcode == T_MNEM_mov)
10335 narrow = 0;
10336 if (low_regs && narrow)
10337 {
10338 inst.instruction = THUMB_OP16 (opcode);
10339 inst.instruction |= Rn << 8;
10340 if (inst.size_req == 2)
10341 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10342 else
10343 inst.relax = opcode;
10344 }
10345 else
10346 {
10347 inst.instruction = THUMB_OP32 (inst.instruction);
10348 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10349 inst.instruction |= Rn << r0off;
10350 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10351 }
10352 }
10353 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10354 && (inst.instruction == T_MNEM_mov
10355 || inst.instruction == T_MNEM_movs))
10356 {
10357 /* Register shifts are encoded as separate shift instructions. */
10358 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10359
10360 if (in_it_block ())
10361 narrow = !flags;
10362 else
10363 narrow = flags;
10364
10365 if (inst.size_req == 4)
10366 narrow = FALSE;
10367
10368 if (!low_regs || inst.operands[1].imm > 7)
10369 narrow = FALSE;
10370
10371 if (Rn != Rm)
10372 narrow = FALSE;
10373
10374 switch (inst.operands[1].shift_kind)
10375 {
10376 case SHIFT_LSL:
10377 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10378 break;
10379 case SHIFT_ASR:
10380 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10381 break;
10382 case SHIFT_LSR:
10383 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10384 break;
10385 case SHIFT_ROR:
10386 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10387 break;
10388 default:
10389 abort ();
10390 }
10391
10392 inst.instruction = opcode;
10393 if (narrow)
10394 {
10395 inst.instruction |= Rn;
10396 inst.instruction |= inst.operands[1].imm << 3;
10397 }
10398 else
10399 {
10400 if (flags)
10401 inst.instruction |= CONDS_BIT;
10402
10403 inst.instruction |= Rn << 8;
10404 inst.instruction |= Rm << 16;
10405 inst.instruction |= inst.operands[1].imm;
10406 }
10407 }
10408 else if (!narrow)
10409 {
10410 /* Some mov with immediate shift have narrow variants.
10411 Register shifts are handled above. */
10412 if (low_regs && inst.operands[1].shifted
10413 && (inst.instruction == T_MNEM_mov
10414 || inst.instruction == T_MNEM_movs))
10415 {
10416 if (in_it_block ())
10417 narrow = (inst.instruction == T_MNEM_mov);
10418 else
10419 narrow = (inst.instruction == T_MNEM_movs);
10420 }
10421
10422 if (narrow)
10423 {
10424 switch (inst.operands[1].shift_kind)
10425 {
10426 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10427 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10428 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10429 default: narrow = FALSE; break;
10430 }
10431 }
10432
10433 if (narrow)
10434 {
10435 inst.instruction |= Rn;
10436 inst.instruction |= Rm << 3;
10437 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10438 }
10439 else
10440 {
10441 inst.instruction = THUMB_OP32 (inst.instruction);
10442 inst.instruction |= Rn << r0off;
10443 encode_thumb32_shifted_operand (1);
10444 }
10445 }
10446 else
10447 switch (inst.instruction)
10448 {
10449 case T_MNEM_mov:
10450 inst.instruction = T_OPCODE_MOV_HR;
10451 inst.instruction |= (Rn & 0x8) << 4;
10452 inst.instruction |= (Rn & 0x7);
10453 inst.instruction |= Rm << 3;
10454 break;
10455
10456 case T_MNEM_movs:
10457 /* We know we have low registers at this point.
10458 Generate LSLS Rd, Rs, #0. */
10459 inst.instruction = T_OPCODE_LSL_I;
10460 inst.instruction |= Rn;
10461 inst.instruction |= Rm << 3;
10462 break;
10463
10464 case T_MNEM_cmp:
10465 if (low_regs)
10466 {
10467 inst.instruction = T_OPCODE_CMP_LR;
10468 inst.instruction |= Rn;
10469 inst.instruction |= Rm << 3;
10470 }
10471 else
10472 {
10473 inst.instruction = T_OPCODE_CMP_HR;
10474 inst.instruction |= (Rn & 0x8) << 4;
10475 inst.instruction |= (Rn & 0x7);
10476 inst.instruction |= Rm << 3;
10477 }
10478 break;
10479 }
10480 return;
10481 }
10482
10483 inst.instruction = THUMB_OP16 (inst.instruction);
10484
10485 /* PR 10443: Do not silently ignore shifted operands. */
10486 constraint (inst.operands[1].shifted,
10487 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10488
10489 if (inst.operands[1].isreg)
10490 {
10491 if (Rn < 8 && Rm < 8)
10492 {
10493 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10494 since a MOV instruction produces unpredictable results. */
10495 if (inst.instruction == T_OPCODE_MOV_I8)
10496 inst.instruction = T_OPCODE_ADD_I3;
10497 else
10498 inst.instruction = T_OPCODE_CMP_LR;
10499
10500 inst.instruction |= Rn;
10501 inst.instruction |= Rm << 3;
10502 }
10503 else
10504 {
10505 if (inst.instruction == T_OPCODE_MOV_I8)
10506 inst.instruction = T_OPCODE_MOV_HR;
10507 else
10508 inst.instruction = T_OPCODE_CMP_HR;
10509 do_t_cpy ();
10510 }
10511 }
10512 else
10513 {
10514 constraint (Rn > 7,
10515 _("only lo regs allowed with immediate"));
10516 inst.instruction |= Rn << 8;
10517 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10518 }
10519 }
10520
10521 static void
10522 do_t_mov16 (void)
10523 {
10524 unsigned Rd;
10525 bfd_vma imm;
10526 bfd_boolean top;
10527
10528 top = (inst.instruction & 0x00800000) != 0;
10529 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10530 {
10531 constraint (top, _(":lower16: not allowed this instruction"));
10532 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10533 }
10534 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10535 {
10536 constraint (!top, _(":upper16: not allowed this instruction"));
10537 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10538 }
10539
10540 Rd = inst.operands[0].reg;
10541 reject_bad_reg (Rd);
10542
10543 inst.instruction |= Rd << 8;
10544 if (inst.reloc.type == BFD_RELOC_UNUSED)
10545 {
10546 imm = inst.reloc.exp.X_add_number;
10547 inst.instruction |= (imm & 0xf000) << 4;
10548 inst.instruction |= (imm & 0x0800) << 15;
10549 inst.instruction |= (imm & 0x0700) << 4;
10550 inst.instruction |= (imm & 0x00ff);
10551 }
10552 }
10553
10554 static void
10555 do_t_mvn_tst (void)
10556 {
10557 unsigned Rn, Rm;
10558
10559 Rn = inst.operands[0].reg;
10560 Rm = inst.operands[1].reg;
10561
10562 if (inst.instruction == T_MNEM_cmp
10563 || inst.instruction == T_MNEM_cmn)
10564 constraint (Rn == REG_PC, BAD_PC);
10565 else
10566 reject_bad_reg (Rn);
10567 reject_bad_reg (Rm);
10568
10569 if (unified_syntax)
10570 {
10571 int r0off = (inst.instruction == T_MNEM_mvn
10572 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
10573 bfd_boolean narrow;
10574
10575 if (inst.size_req == 4
10576 || inst.instruction > 0xffff
10577 || inst.operands[1].shifted
10578 || Rn > 7 || Rm > 7)
10579 narrow = FALSE;
10580 else if (inst.instruction == T_MNEM_cmn)
10581 narrow = TRUE;
10582 else if (THUMB_SETS_FLAGS (inst.instruction))
10583 narrow = !in_it_block ();
10584 else
10585 narrow = in_it_block ();
10586
10587 if (!inst.operands[1].isreg)
10588 {
10589 /* For an immediate, we always generate a 32-bit opcode;
10590 section relaxation will shrink it later if possible. */
10591 if (inst.instruction < 0xffff)
10592 inst.instruction = THUMB_OP32 (inst.instruction);
10593 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10594 inst.instruction |= Rn << r0off;
10595 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10596 }
10597 else
10598 {
10599 /* See if we can do this with a 16-bit instruction. */
10600 if (narrow)
10601 {
10602 inst.instruction = THUMB_OP16 (inst.instruction);
10603 inst.instruction |= Rn;
10604 inst.instruction |= Rm << 3;
10605 }
10606 else
10607 {
10608 constraint (inst.operands[1].shifted
10609 && inst.operands[1].immisreg,
10610 _("shift must be constant"));
10611 if (inst.instruction < 0xffff)
10612 inst.instruction = THUMB_OP32 (inst.instruction);
10613 inst.instruction |= Rn << r0off;
10614 encode_thumb32_shifted_operand (1);
10615 }
10616 }
10617 }
10618 else
10619 {
10620 constraint (inst.instruction > 0xffff
10621 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10622 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10623 _("unshifted register required"));
10624 constraint (Rn > 7 || Rm > 7,
10625 BAD_HIREG);
10626
10627 inst.instruction = THUMB_OP16 (inst.instruction);
10628 inst.instruction |= Rn;
10629 inst.instruction |= Rm << 3;
10630 }
10631 }
10632
10633 static void
10634 do_t_mrs (void)
10635 {
10636 unsigned Rd;
10637 int flags;
10638
10639 if (do_vfp_nsyn_mrs () == SUCCESS)
10640 return;
10641
10642 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10643 if (flags == 0)
10644 {
10645 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10646 _("selected processor does not support "
10647 "requested special purpose register"));
10648 }
10649 else
10650 {
10651 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10652 _("selected processor does not support "
10653 "requested special purpose register"));
10654 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10655 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10656 _("'CPSR' or 'SPSR' expected"));
10657 }
10658
10659 Rd = inst.operands[0].reg;
10660 reject_bad_reg (Rd);
10661
10662 inst.instruction |= Rd << 8;
10663 inst.instruction |= (flags & SPSR_BIT) >> 2;
10664 inst.instruction |= inst.operands[1].imm & 0xff;
10665 }
10666
10667 static void
10668 do_t_msr (void)
10669 {
10670 int flags;
10671 unsigned Rn;
10672
10673 if (do_vfp_nsyn_msr () == SUCCESS)
10674 return;
10675
10676 constraint (!inst.operands[1].isreg,
10677 _("Thumb encoding does not support an immediate here"));
10678 flags = inst.operands[0].imm;
10679 if (flags & ~0xff)
10680 {
10681 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10682 _("selected processor does not support "
10683 "requested special purpose register"));
10684 }
10685 else
10686 {
10687 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10688 _("selected processor does not support "
10689 "requested special purpose register"));
10690 flags |= PSR_f;
10691 }
10692
10693 Rn = inst.operands[1].reg;
10694 reject_bad_reg (Rn);
10695
10696 inst.instruction |= (flags & SPSR_BIT) >> 2;
10697 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10698 inst.instruction |= (flags & 0xff);
10699 inst.instruction |= Rn << 16;
10700 }
10701
10702 static void
10703 do_t_mul (void)
10704 {
10705 bfd_boolean narrow;
10706 unsigned Rd, Rn, Rm;
10707
10708 if (!inst.operands[2].present)
10709 inst.operands[2].reg = inst.operands[0].reg;
10710
10711 Rd = inst.operands[0].reg;
10712 Rn = inst.operands[1].reg;
10713 Rm = inst.operands[2].reg;
10714
10715 if (unified_syntax)
10716 {
10717 if (inst.size_req == 4
10718 || (Rd != Rn
10719 && Rd != Rm)
10720 || Rn > 7
10721 || Rm > 7)
10722 narrow = FALSE;
10723 else if (inst.instruction == T_MNEM_muls)
10724 narrow = !in_it_block ();
10725 else
10726 narrow = in_it_block ();
10727 }
10728 else
10729 {
10730 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
10731 constraint (Rn > 7 || Rm > 7,
10732 BAD_HIREG);
10733 narrow = TRUE;
10734 }
10735
10736 if (narrow)
10737 {
10738 /* 16-bit MULS/Conditional MUL. */
10739 inst.instruction = THUMB_OP16 (inst.instruction);
10740 inst.instruction |= Rd;
10741
10742 if (Rd == Rn)
10743 inst.instruction |= Rm << 3;
10744 else if (Rd == Rm)
10745 inst.instruction |= Rn << 3;
10746 else
10747 constraint (1, _("dest must overlap one source register"));
10748 }
10749 else
10750 {
10751 constraint (inst.instruction != T_MNEM_mul,
10752 _("Thumb-2 MUL must not set flags"));
10753 /* 32-bit MUL. */
10754 inst.instruction = THUMB_OP32 (inst.instruction);
10755 inst.instruction |= Rd << 8;
10756 inst.instruction |= Rn << 16;
10757 inst.instruction |= Rm << 0;
10758
10759 reject_bad_reg (Rd);
10760 reject_bad_reg (Rn);
10761 reject_bad_reg (Rm);
10762 }
10763 }
10764
10765 static void
10766 do_t_mull (void)
10767 {
10768 unsigned RdLo, RdHi, Rn, Rm;
10769
10770 RdLo = inst.operands[0].reg;
10771 RdHi = inst.operands[1].reg;
10772 Rn = inst.operands[2].reg;
10773 Rm = inst.operands[3].reg;
10774
10775 reject_bad_reg (RdLo);
10776 reject_bad_reg (RdHi);
10777 reject_bad_reg (Rn);
10778 reject_bad_reg (Rm);
10779
10780 inst.instruction |= RdLo << 12;
10781 inst.instruction |= RdHi << 8;
10782 inst.instruction |= Rn << 16;
10783 inst.instruction |= Rm;
10784
10785 if (RdLo == RdHi)
10786 as_tsktsk (_("rdhi and rdlo must be different"));
10787 }
10788
10789 static void
10790 do_t_nop (void)
10791 {
10792 set_it_insn_type (NEUTRAL_IT_INSN);
10793
10794 if (unified_syntax)
10795 {
10796 if (inst.size_req == 4 || inst.operands[0].imm > 15)
10797 {
10798 inst.instruction = THUMB_OP32 (inst.instruction);
10799 inst.instruction |= inst.operands[0].imm;
10800 }
10801 else
10802 {
10803 /* PR9722: Check for Thumb2 availability before
10804 generating a thumb2 nop instruction. */
10805 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
10806 {
10807 inst.instruction = THUMB_OP16 (inst.instruction);
10808 inst.instruction |= inst.operands[0].imm << 4;
10809 }
10810 else
10811 inst.instruction = 0x46c0;
10812 }
10813 }
10814 else
10815 {
10816 constraint (inst.operands[0].present,
10817 _("Thumb does not support NOP with hints"));
10818 inst.instruction = 0x46c0;
10819 }
10820 }
10821
10822 static void
10823 do_t_neg (void)
10824 {
10825 if (unified_syntax)
10826 {
10827 bfd_boolean narrow;
10828
10829 if (THUMB_SETS_FLAGS (inst.instruction))
10830 narrow = !in_it_block ();
10831 else
10832 narrow = in_it_block ();
10833 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10834 narrow = FALSE;
10835 if (inst.size_req == 4)
10836 narrow = FALSE;
10837
10838 if (!narrow)
10839 {
10840 inst.instruction = THUMB_OP32 (inst.instruction);
10841 inst.instruction |= inst.operands[0].reg << 8;
10842 inst.instruction |= inst.operands[1].reg << 16;
10843 }
10844 else
10845 {
10846 inst.instruction = THUMB_OP16 (inst.instruction);
10847 inst.instruction |= inst.operands[0].reg;
10848 inst.instruction |= inst.operands[1].reg << 3;
10849 }
10850 }
10851 else
10852 {
10853 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10854 BAD_HIREG);
10855 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10856
10857 inst.instruction = THUMB_OP16 (inst.instruction);
10858 inst.instruction |= inst.operands[0].reg;
10859 inst.instruction |= inst.operands[1].reg << 3;
10860 }
10861 }
10862
10863 static void
10864 do_t_orn (void)
10865 {
10866 unsigned Rd, Rn;
10867
10868 Rd = inst.operands[0].reg;
10869 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10870
10871 reject_bad_reg (Rd);
10872 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10873 reject_bad_reg (Rn);
10874
10875 inst.instruction |= Rd << 8;
10876 inst.instruction |= Rn << 16;
10877
10878 if (!inst.operands[2].isreg)
10879 {
10880 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10881 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10882 }
10883 else
10884 {
10885 unsigned Rm;
10886
10887 Rm = inst.operands[2].reg;
10888 reject_bad_reg (Rm);
10889
10890 constraint (inst.operands[2].shifted
10891 && inst.operands[2].immisreg,
10892 _("shift must be constant"));
10893 encode_thumb32_shifted_operand (2);
10894 }
10895 }
10896
10897 static void
10898 do_t_pkhbt (void)
10899 {
10900 unsigned Rd, Rn, Rm;
10901
10902 Rd = inst.operands[0].reg;
10903 Rn = inst.operands[1].reg;
10904 Rm = inst.operands[2].reg;
10905
10906 reject_bad_reg (Rd);
10907 reject_bad_reg (Rn);
10908 reject_bad_reg (Rm);
10909
10910 inst.instruction |= Rd << 8;
10911 inst.instruction |= Rn << 16;
10912 inst.instruction |= Rm;
10913 if (inst.operands[3].present)
10914 {
10915 unsigned int val = inst.reloc.exp.X_add_number;
10916 constraint (inst.reloc.exp.X_op != O_constant,
10917 _("expression too complex"));
10918 inst.instruction |= (val & 0x1c) << 10;
10919 inst.instruction |= (val & 0x03) << 6;
10920 }
10921 }
10922
10923 static void
10924 do_t_pkhtb (void)
10925 {
10926 if (!inst.operands[3].present)
10927 {
10928 unsigned Rtmp;
10929
10930 inst.instruction &= ~0x00000020;
10931
10932 /* PR 10168. Swap the Rm and Rn registers. */
10933 Rtmp = inst.operands[1].reg;
10934 inst.operands[1].reg = inst.operands[2].reg;
10935 inst.operands[2].reg = Rtmp;
10936 }
10937 do_t_pkhbt ();
10938 }
10939
10940 static void
10941 do_t_pld (void)
10942 {
10943 if (inst.operands[0].immisreg)
10944 reject_bad_reg (inst.operands[0].imm);
10945
10946 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10947 }
10948
10949 static void
10950 do_t_push_pop (void)
10951 {
10952 unsigned mask;
10953
10954 constraint (inst.operands[0].writeback,
10955 _("push/pop do not support {reglist}^"));
10956 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10957 _("expression too complex"));
10958
10959 mask = inst.operands[0].imm;
10960 if ((mask & ~0xff) == 0)
10961 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10962 else if ((inst.instruction == T_MNEM_push
10963 && (mask & ~0xff) == 1 << REG_LR)
10964 || (inst.instruction == T_MNEM_pop
10965 && (mask & ~0xff) == 1 << REG_PC))
10966 {
10967 inst.instruction = THUMB_OP16 (inst.instruction);
10968 inst.instruction |= THUMB_PP_PC_LR;
10969 inst.instruction |= mask & 0xff;
10970 }
10971 else if (unified_syntax)
10972 {
10973 inst.instruction = THUMB_OP32 (inst.instruction);
10974 encode_thumb2_ldmstm (13, mask, TRUE);
10975 }
10976 else
10977 {
10978 inst.error = _("invalid register list to push/pop instruction");
10979 return;
10980 }
10981 }
10982
10983 static void
10984 do_t_rbit (void)
10985 {
10986 unsigned Rd, Rm;
10987
10988 Rd = inst.operands[0].reg;
10989 Rm = inst.operands[1].reg;
10990
10991 reject_bad_reg (Rd);
10992 reject_bad_reg (Rm);
10993
10994 inst.instruction |= Rd << 8;
10995 inst.instruction |= Rm << 16;
10996 inst.instruction |= Rm;
10997 }
10998
10999 static void
11000 do_t_rev (void)
11001 {
11002 unsigned Rd, Rm;
11003
11004 Rd = inst.operands[0].reg;
11005 Rm = inst.operands[1].reg;
11006
11007 reject_bad_reg (Rd);
11008 reject_bad_reg (Rm);
11009
11010 if (Rd <= 7 && Rm <= 7
11011 && inst.size_req != 4)
11012 {
11013 inst.instruction = THUMB_OP16 (inst.instruction);
11014 inst.instruction |= Rd;
11015 inst.instruction |= Rm << 3;
11016 }
11017 else if (unified_syntax)
11018 {
11019 inst.instruction = THUMB_OP32 (inst.instruction);
11020 inst.instruction |= Rd << 8;
11021 inst.instruction |= Rm << 16;
11022 inst.instruction |= Rm;
11023 }
11024 else
11025 inst.error = BAD_HIREG;
11026 }
11027
11028 static void
11029 do_t_rrx (void)
11030 {
11031 unsigned Rd, Rm;
11032
11033 Rd = inst.operands[0].reg;
11034 Rm = inst.operands[1].reg;
11035
11036 reject_bad_reg (Rd);
11037 reject_bad_reg (Rm);
11038
11039 inst.instruction |= Rd << 8;
11040 inst.instruction |= Rm;
11041 }
11042
11043 static void
11044 do_t_rsb (void)
11045 {
11046 unsigned Rd, Rs;
11047
11048 Rd = inst.operands[0].reg;
11049 Rs = (inst.operands[1].present
11050 ? inst.operands[1].reg /* Rd, Rs, foo */
11051 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
11052
11053 reject_bad_reg (Rd);
11054 reject_bad_reg (Rs);
11055 if (inst.operands[2].isreg)
11056 reject_bad_reg (inst.operands[2].reg);
11057
11058 inst.instruction |= Rd << 8;
11059 inst.instruction |= Rs << 16;
11060 if (!inst.operands[2].isreg)
11061 {
11062 bfd_boolean narrow;
11063
11064 if ((inst.instruction & 0x00100000) != 0)
11065 narrow = !in_it_block ();
11066 else
11067 narrow = in_it_block ();
11068
11069 if (Rd > 7 || Rs > 7)
11070 narrow = FALSE;
11071
11072 if (inst.size_req == 4 || !unified_syntax)
11073 narrow = FALSE;
11074
11075 if (inst.reloc.exp.X_op != O_constant
11076 || inst.reloc.exp.X_add_number != 0)
11077 narrow = FALSE;
11078
11079 /* Turn rsb #0 into 16-bit neg. We should probably do this via
11080 relaxation, but it doesn't seem worth the hassle. */
11081 if (narrow)
11082 {
11083 inst.reloc.type = BFD_RELOC_UNUSED;
11084 inst.instruction = THUMB_OP16 (T_MNEM_negs);
11085 inst.instruction |= Rs << 3;
11086 inst.instruction |= Rd;
11087 }
11088 else
11089 {
11090 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11091 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11092 }
11093 }
11094 else
11095 encode_thumb32_shifted_operand (2);
11096 }
11097
11098 static void
11099 do_t_setend (void)
11100 {
11101 set_it_insn_type (OUTSIDE_IT_INSN);
11102 if (inst.operands[0].imm)
11103 inst.instruction |= 0x8;
11104 }
11105
11106 static void
11107 do_t_shift (void)
11108 {
11109 if (!inst.operands[1].present)
11110 inst.operands[1].reg = inst.operands[0].reg;
11111
11112 if (unified_syntax)
11113 {
11114 bfd_boolean narrow;
11115 int shift_kind;
11116
11117 switch (inst.instruction)
11118 {
11119 case T_MNEM_asr:
11120 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11121 case T_MNEM_lsl:
11122 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11123 case T_MNEM_lsr:
11124 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11125 case T_MNEM_ror:
11126 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11127 default: abort ();
11128 }
11129
11130 if (THUMB_SETS_FLAGS (inst.instruction))
11131 narrow = !in_it_block ();
11132 else
11133 narrow = in_it_block ();
11134 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11135 narrow = FALSE;
11136 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11137 narrow = FALSE;
11138 if (inst.operands[2].isreg
11139 && (inst.operands[1].reg != inst.operands[0].reg
11140 || inst.operands[2].reg > 7))
11141 narrow = FALSE;
11142 if (inst.size_req == 4)
11143 narrow = FALSE;
11144
11145 reject_bad_reg (inst.operands[0].reg);
11146 reject_bad_reg (inst.operands[1].reg);
11147
11148 if (!narrow)
11149 {
11150 if (inst.operands[2].isreg)
11151 {
11152 reject_bad_reg (inst.operands[2].reg);
11153 inst.instruction = THUMB_OP32 (inst.instruction);
11154 inst.instruction |= inst.operands[0].reg << 8;
11155 inst.instruction |= inst.operands[1].reg << 16;
11156 inst.instruction |= inst.operands[2].reg;
11157 }
11158 else
11159 {
11160 inst.operands[1].shifted = 1;
11161 inst.operands[1].shift_kind = shift_kind;
11162 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11163 ? T_MNEM_movs : T_MNEM_mov);
11164 inst.instruction |= inst.operands[0].reg << 8;
11165 encode_thumb32_shifted_operand (1);
11166 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11167 inst.reloc.type = BFD_RELOC_UNUSED;
11168 }
11169 }
11170 else
11171 {
11172 if (inst.operands[2].isreg)
11173 {
11174 switch (shift_kind)
11175 {
11176 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11177 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11178 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11179 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11180 default: abort ();
11181 }
11182
11183 inst.instruction |= inst.operands[0].reg;
11184 inst.instruction |= inst.operands[2].reg << 3;
11185 }
11186 else
11187 {
11188 switch (shift_kind)
11189 {
11190 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11191 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11192 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11193 default: abort ();
11194 }
11195 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11196 inst.instruction |= inst.operands[0].reg;
11197 inst.instruction |= inst.operands[1].reg << 3;
11198 }
11199 }
11200 }
11201 else
11202 {
11203 constraint (inst.operands[0].reg > 7
11204 || inst.operands[1].reg > 7, BAD_HIREG);
11205 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11206
11207 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11208 {
11209 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11210 constraint (inst.operands[0].reg != inst.operands[1].reg,
11211 _("source1 and dest must be same register"));
11212
11213 switch (inst.instruction)
11214 {
11215 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11216 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11217 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11218 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11219 default: abort ();
11220 }
11221
11222 inst.instruction |= inst.operands[0].reg;
11223 inst.instruction |= inst.operands[2].reg << 3;
11224 }
11225 else
11226 {
11227 switch (inst.instruction)
11228 {
11229 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11230 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11231 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11232 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11233 default: abort ();
11234 }
11235 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11236 inst.instruction |= inst.operands[0].reg;
11237 inst.instruction |= inst.operands[1].reg << 3;
11238 }
11239 }
11240 }
11241
11242 static void
11243 do_t_simd (void)
11244 {
11245 unsigned Rd, Rn, Rm;
11246
11247 Rd = inst.operands[0].reg;
11248 Rn = inst.operands[1].reg;
11249 Rm = inst.operands[2].reg;
11250
11251 reject_bad_reg (Rd);
11252 reject_bad_reg (Rn);
11253 reject_bad_reg (Rm);
11254
11255 inst.instruction |= Rd << 8;
11256 inst.instruction |= Rn << 16;
11257 inst.instruction |= Rm;
11258 }
11259
11260 static void
11261 do_t_simd2 (void)
11262 {
11263 unsigned Rd, Rn, Rm;
11264
11265 Rd = inst.operands[0].reg;
11266 Rm = inst.operands[1].reg;
11267 Rn = inst.operands[2].reg;
11268
11269 reject_bad_reg (Rd);
11270 reject_bad_reg (Rn);
11271 reject_bad_reg (Rm);
11272
11273 inst.instruction |= Rd << 8;
11274 inst.instruction |= Rn << 16;
11275 inst.instruction |= Rm;
11276 }
11277
11278 static void
11279 do_t_smc (void)
11280 {
11281 unsigned int value = inst.reloc.exp.X_add_number;
11282 constraint (inst.reloc.exp.X_op != O_constant,
11283 _("expression too complex"));
11284 inst.reloc.type = BFD_RELOC_UNUSED;
11285 inst.instruction |= (value & 0xf000) >> 12;
11286 inst.instruction |= (value & 0x0ff0);
11287 inst.instruction |= (value & 0x000f) << 16;
11288 }
11289
11290 static void
11291 do_t_ssat_usat (int bias)
11292 {
11293 unsigned Rd, Rn;
11294
11295 Rd = inst.operands[0].reg;
11296 Rn = inst.operands[2].reg;
11297
11298 reject_bad_reg (Rd);
11299 reject_bad_reg (Rn);
11300
11301 inst.instruction |= Rd << 8;
11302 inst.instruction |= inst.operands[1].imm - bias;
11303 inst.instruction |= Rn << 16;
11304
11305 if (inst.operands[3].present)
11306 {
11307 offsetT shift_amount = inst.reloc.exp.X_add_number;
11308
11309 inst.reloc.type = BFD_RELOC_UNUSED;
11310
11311 constraint (inst.reloc.exp.X_op != O_constant,
11312 _("expression too complex"));
11313
11314 if (shift_amount != 0)
11315 {
11316 constraint (shift_amount > 31,
11317 _("shift expression is too large"));
11318
11319 if (inst.operands[3].shift_kind == SHIFT_ASR)
11320 inst.instruction |= 0x00200000; /* sh bit. */
11321
11322 inst.instruction |= (shift_amount & 0x1c) << 10;
11323 inst.instruction |= (shift_amount & 0x03) << 6;
11324 }
11325 }
11326 }
11327
11328 static void
11329 do_t_ssat (void)
11330 {
11331 do_t_ssat_usat (1);
11332 }
11333
11334 static void
11335 do_t_ssat16 (void)
11336 {
11337 unsigned Rd, Rn;
11338
11339 Rd = inst.operands[0].reg;
11340 Rn = inst.operands[2].reg;
11341
11342 reject_bad_reg (Rd);
11343 reject_bad_reg (Rn);
11344
11345 inst.instruction |= Rd << 8;
11346 inst.instruction |= inst.operands[1].imm - 1;
11347 inst.instruction |= Rn << 16;
11348 }
11349
11350 static void
11351 do_t_strex (void)
11352 {
11353 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11354 || inst.operands[2].postind || inst.operands[2].writeback
11355 || inst.operands[2].immisreg || inst.operands[2].shifted
11356 || inst.operands[2].negative,
11357 BAD_ADDR_MODE);
11358
11359 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11360
11361 inst.instruction |= inst.operands[0].reg << 8;
11362 inst.instruction |= inst.operands[1].reg << 12;
11363 inst.instruction |= inst.operands[2].reg << 16;
11364 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11365 }
11366
11367 static void
11368 do_t_strexd (void)
11369 {
11370 if (!inst.operands[2].present)
11371 inst.operands[2].reg = inst.operands[1].reg + 1;
11372
11373 constraint (inst.operands[0].reg == inst.operands[1].reg
11374 || inst.operands[0].reg == inst.operands[2].reg
11375 || inst.operands[0].reg == inst.operands[3].reg,
11376 BAD_OVERLAP);
11377
11378 inst.instruction |= inst.operands[0].reg;
11379 inst.instruction |= inst.operands[1].reg << 12;
11380 inst.instruction |= inst.operands[2].reg << 8;
11381 inst.instruction |= inst.operands[3].reg << 16;
11382 }
11383
11384 static void
11385 do_t_sxtah (void)
11386 {
11387 unsigned Rd, Rn, Rm;
11388
11389 Rd = inst.operands[0].reg;
11390 Rn = inst.operands[1].reg;
11391 Rm = inst.operands[2].reg;
11392
11393 reject_bad_reg (Rd);
11394 reject_bad_reg (Rn);
11395 reject_bad_reg (Rm);
11396
11397 inst.instruction |= Rd << 8;
11398 inst.instruction |= Rn << 16;
11399 inst.instruction |= Rm;
11400 inst.instruction |= inst.operands[3].imm << 4;
11401 }
11402
11403 static void
11404 do_t_sxth (void)
11405 {
11406 unsigned Rd, Rm;
11407
11408 Rd = inst.operands[0].reg;
11409 Rm = inst.operands[1].reg;
11410
11411 reject_bad_reg (Rd);
11412 reject_bad_reg (Rm);
11413
11414 if (inst.instruction <= 0xffff
11415 && inst.size_req != 4
11416 && Rd <= 7 && Rm <= 7
11417 && (!inst.operands[2].present || inst.operands[2].imm == 0))
11418 {
11419 inst.instruction = THUMB_OP16 (inst.instruction);
11420 inst.instruction |= Rd;
11421 inst.instruction |= Rm << 3;
11422 }
11423 else if (unified_syntax)
11424 {
11425 if (inst.instruction <= 0xffff)
11426 inst.instruction = THUMB_OP32 (inst.instruction);
11427 inst.instruction |= Rd << 8;
11428 inst.instruction |= Rm;
11429 inst.instruction |= inst.operands[2].imm << 4;
11430 }
11431 else
11432 {
11433 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11434 _("Thumb encoding does not support rotation"));
11435 constraint (1, BAD_HIREG);
11436 }
11437 }
11438
11439 static void
11440 do_t_swi (void)
11441 {
11442 inst.reloc.type = BFD_RELOC_ARM_SWI;
11443 }
11444
11445 static void
11446 do_t_tb (void)
11447 {
11448 unsigned Rn, Rm;
11449 int half;
11450
11451 half = (inst.instruction & 0x10) != 0;
11452 set_it_insn_type_last ();
11453 constraint (inst.operands[0].immisreg,
11454 _("instruction requires register index"));
11455
11456 Rn = inst.operands[0].reg;
11457 Rm = inst.operands[0].imm;
11458
11459 constraint (Rn == REG_SP, BAD_SP);
11460 reject_bad_reg (Rm);
11461
11462 constraint (!half && inst.operands[0].shifted,
11463 _("instruction does not allow shifted index"));
11464 inst.instruction |= (Rn << 16) | Rm;
11465 }
11466
11467 static void
11468 do_t_usat (void)
11469 {
11470 do_t_ssat_usat (0);
11471 }
11472
11473 static void
11474 do_t_usat16 (void)
11475 {
11476 unsigned Rd, Rn;
11477
11478 Rd = inst.operands[0].reg;
11479 Rn = inst.operands[2].reg;
11480
11481 reject_bad_reg (Rd);
11482 reject_bad_reg (Rn);
11483
11484 inst.instruction |= Rd << 8;
11485 inst.instruction |= inst.operands[1].imm;
11486 inst.instruction |= Rn << 16;
11487 }
11488
11489 /* Neon instruction encoder helpers. */
11490
11491 /* Encodings for the different types for various Neon opcodes. */
11492
11493 /* An "invalid" code for the following tables. */
11494 #define N_INV -1u
11495
11496 struct neon_tab_entry
11497 {
11498 unsigned integer;
11499 unsigned float_or_poly;
11500 unsigned scalar_or_imm;
11501 };
11502
11503 /* Map overloaded Neon opcodes to their respective encodings. */
11504 #define NEON_ENC_TAB \
11505 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11506 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11507 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11508 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11509 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11510 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11511 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11512 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11513 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11514 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11515 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11516 /* Register variants of the following two instructions are encoded as
11517 vcge / vcgt with the operands reversed. */ \
11518 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11519 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
11520 X(vfma, N_INV, 0x0000c10, N_INV), \
11521 X(vfms, N_INV, 0x0200c10, N_INV), \
11522 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11523 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11524 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11525 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11526 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11527 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11528 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11529 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11530 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11531 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11532 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11533 X(vshl, 0x0000400, N_INV, 0x0800510), \
11534 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11535 X(vand, 0x0000110, N_INV, 0x0800030), \
11536 X(vbic, 0x0100110, N_INV, 0x0800030), \
11537 X(veor, 0x1000110, N_INV, N_INV), \
11538 X(vorn, 0x0300110, N_INV, 0x0800010), \
11539 X(vorr, 0x0200110, N_INV, 0x0800010), \
11540 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11541 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11542 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11543 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11544 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11545 X(vst1, 0x0000000, 0x0800000, N_INV), \
11546 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11547 X(vst2, 0x0000100, 0x0800100, N_INV), \
11548 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11549 X(vst3, 0x0000200, 0x0800200, N_INV), \
11550 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11551 X(vst4, 0x0000300, 0x0800300, N_INV), \
11552 X(vmovn, 0x1b20200, N_INV, N_INV), \
11553 X(vtrn, 0x1b20080, N_INV, N_INV), \
11554 X(vqmovn, 0x1b20200, N_INV, N_INV), \
11555 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11556 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
11557 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11558 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
11559 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11560 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
11561 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11562 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11563 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11564 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
11565
11566 enum neon_opc
11567 {
11568 #define X(OPC,I,F,S) N_MNEM_##OPC
11569 NEON_ENC_TAB
11570 #undef X
11571 };
11572
11573 static const struct neon_tab_entry neon_enc_tab[] =
11574 {
11575 #define X(OPC,I,F,S) { (I), (F), (S) }
11576 NEON_ENC_TAB
11577 #undef X
11578 };
11579
11580 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
11581 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11582 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11583 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11584 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11585 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11586 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11587 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11588 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11589 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11590 #define NEON_ENC_SINGLE_(X) \
11591 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
11592 #define NEON_ENC_DOUBLE_(X) \
11593 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
11594
11595 #define NEON_ENCODE(type, inst) \
11596 do \
11597 { \
11598 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11599 inst.is_neon = 1; \
11600 } \
11601 while (0)
11602
11603 #define check_neon_suffixes \
11604 do \
11605 { \
11606 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11607 { \
11608 as_bad (_("invalid neon suffix for non neon instruction")); \
11609 return; \
11610 } \
11611 } \
11612 while (0)
11613
11614 /* Define shapes for instruction operands. The following mnemonic characters
11615 are used in this table:
11616
11617 F - VFP S<n> register
11618 D - Neon D<n> register
11619 Q - Neon Q<n> register
11620 I - Immediate
11621 S - Scalar
11622 R - ARM register
11623 L - D<n> register list
11624
11625 This table is used to generate various data:
11626 - enumerations of the form NS_DDR to be used as arguments to
11627 neon_select_shape.
11628 - a table classifying shapes into single, double, quad, mixed.
11629 - a table used to drive neon_select_shape. */
11630
11631 #define NEON_SHAPE_DEF \
11632 X(3, (D, D, D), DOUBLE), \
11633 X(3, (Q, Q, Q), QUAD), \
11634 X(3, (D, D, I), DOUBLE), \
11635 X(3, (Q, Q, I), QUAD), \
11636 X(3, (D, D, S), DOUBLE), \
11637 X(3, (Q, Q, S), QUAD), \
11638 X(2, (D, D), DOUBLE), \
11639 X(2, (Q, Q), QUAD), \
11640 X(2, (D, S), DOUBLE), \
11641 X(2, (Q, S), QUAD), \
11642 X(2, (D, R), DOUBLE), \
11643 X(2, (Q, R), QUAD), \
11644 X(2, (D, I), DOUBLE), \
11645 X(2, (Q, I), QUAD), \
11646 X(3, (D, L, D), DOUBLE), \
11647 X(2, (D, Q), MIXED), \
11648 X(2, (Q, D), MIXED), \
11649 X(3, (D, Q, I), MIXED), \
11650 X(3, (Q, D, I), MIXED), \
11651 X(3, (Q, D, D), MIXED), \
11652 X(3, (D, Q, Q), MIXED), \
11653 X(3, (Q, Q, D), MIXED), \
11654 X(3, (Q, D, S), MIXED), \
11655 X(3, (D, Q, S), MIXED), \
11656 X(4, (D, D, D, I), DOUBLE), \
11657 X(4, (Q, Q, Q, I), QUAD), \
11658 X(2, (F, F), SINGLE), \
11659 X(3, (F, F, F), SINGLE), \
11660 X(2, (F, I), SINGLE), \
11661 X(2, (F, D), MIXED), \
11662 X(2, (D, F), MIXED), \
11663 X(3, (F, F, I), MIXED), \
11664 X(4, (R, R, F, F), SINGLE), \
11665 X(4, (F, F, R, R), SINGLE), \
11666 X(3, (D, R, R), DOUBLE), \
11667 X(3, (R, R, D), DOUBLE), \
11668 X(2, (S, R), SINGLE), \
11669 X(2, (R, S), SINGLE), \
11670 X(2, (F, R), SINGLE), \
11671 X(2, (R, F), SINGLE)
11672
11673 #define S2(A,B) NS_##A##B
11674 #define S3(A,B,C) NS_##A##B##C
11675 #define S4(A,B,C,D) NS_##A##B##C##D
11676
11677 #define X(N, L, C) S##N L
11678
11679 enum neon_shape
11680 {
11681 NEON_SHAPE_DEF,
11682 NS_NULL
11683 };
11684
11685 #undef X
11686 #undef S2
11687 #undef S3
11688 #undef S4
11689
11690 enum neon_shape_class
11691 {
11692 SC_SINGLE,
11693 SC_DOUBLE,
11694 SC_QUAD,
11695 SC_MIXED
11696 };
11697
11698 #define X(N, L, C) SC_##C
11699
11700 static enum neon_shape_class neon_shape_class[] =
11701 {
11702 NEON_SHAPE_DEF
11703 };
11704
11705 #undef X
11706
11707 enum neon_shape_el
11708 {
11709 SE_F,
11710 SE_D,
11711 SE_Q,
11712 SE_I,
11713 SE_S,
11714 SE_R,
11715 SE_L
11716 };
11717
11718 /* Register widths of above. */
11719 static unsigned neon_shape_el_size[] =
11720 {
11721 32,
11722 64,
11723 128,
11724 0,
11725 32,
11726 32,
11727 0
11728 };
11729
11730 struct neon_shape_info
11731 {
11732 unsigned els;
11733 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11734 };
11735
11736 #define S2(A,B) { SE_##A, SE_##B }
11737 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11738 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11739
11740 #define X(N, L, C) { N, S##N L }
11741
11742 static struct neon_shape_info neon_shape_tab[] =
11743 {
11744 NEON_SHAPE_DEF
11745 };
11746
11747 #undef X
11748 #undef S2
11749 #undef S3
11750 #undef S4
11751
11752 /* Bit masks used in type checking given instructions.
11753 'N_EQK' means the type must be the same as (or based on in some way) the key
11754 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11755 set, various other bits can be set as well in order to modify the meaning of
11756 the type constraint. */
11757
11758 enum neon_type_mask
11759 {
11760 N_S8 = 0x0000001,
11761 N_S16 = 0x0000002,
11762 N_S32 = 0x0000004,
11763 N_S64 = 0x0000008,
11764 N_U8 = 0x0000010,
11765 N_U16 = 0x0000020,
11766 N_U32 = 0x0000040,
11767 N_U64 = 0x0000080,
11768 N_I8 = 0x0000100,
11769 N_I16 = 0x0000200,
11770 N_I32 = 0x0000400,
11771 N_I64 = 0x0000800,
11772 N_8 = 0x0001000,
11773 N_16 = 0x0002000,
11774 N_32 = 0x0004000,
11775 N_64 = 0x0008000,
11776 N_P8 = 0x0010000,
11777 N_P16 = 0x0020000,
11778 N_F16 = 0x0040000,
11779 N_F32 = 0x0080000,
11780 N_F64 = 0x0100000,
11781 N_KEY = 0x1000000, /* Key element (main type specifier). */
11782 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
11783 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11784 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11785 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11786 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11787 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11788 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11789 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11790 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
11791 N_UTYP = 0,
11792 N_MAX_NONSPECIAL = N_F64
11793 };
11794
11795 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11796
11797 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11798 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11799 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11800 #define N_SUF_32 (N_SU_32 | N_F32)
11801 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11802 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11803
11804 /* Pass this as the first type argument to neon_check_type to ignore types
11805 altogether. */
11806 #define N_IGNORE_TYPE (N_KEY | N_EQK)
11807
11808 /* Select a "shape" for the current instruction (describing register types or
11809 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11810 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11811 function of operand parsing, so this function doesn't need to be called.
11812 Shapes should be listed in order of decreasing length. */
11813
11814 static enum neon_shape
11815 neon_select_shape (enum neon_shape shape, ...)
11816 {
11817 va_list ap;
11818 enum neon_shape first_shape = shape;
11819
11820 /* Fix missing optional operands. FIXME: we don't know at this point how
11821 many arguments we should have, so this makes the assumption that we have
11822 > 1. This is true of all current Neon opcodes, I think, but may not be
11823 true in the future. */
11824 if (!inst.operands[1].present)
11825 inst.operands[1] = inst.operands[0];
11826
11827 va_start (ap, shape);
11828
11829 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
11830 {
11831 unsigned j;
11832 int matches = 1;
11833
11834 for (j = 0; j < neon_shape_tab[shape].els; j++)
11835 {
11836 if (!inst.operands[j].present)
11837 {
11838 matches = 0;
11839 break;
11840 }
11841
11842 switch (neon_shape_tab[shape].el[j])
11843 {
11844 case SE_F:
11845 if (!(inst.operands[j].isreg
11846 && inst.operands[j].isvec
11847 && inst.operands[j].issingle
11848 && !inst.operands[j].isquad))
11849 matches = 0;
11850 break;
11851
11852 case SE_D:
11853 if (!(inst.operands[j].isreg
11854 && inst.operands[j].isvec
11855 && !inst.operands[j].isquad
11856 && !inst.operands[j].issingle))
11857 matches = 0;
11858 break;
11859
11860 case SE_R:
11861 if (!(inst.operands[j].isreg
11862 && !inst.operands[j].isvec))
11863 matches = 0;
11864 break;
11865
11866 case SE_Q:
11867 if (!(inst.operands[j].isreg
11868 && inst.operands[j].isvec
11869 && inst.operands[j].isquad
11870 && !inst.operands[j].issingle))
11871 matches = 0;
11872 break;
11873
11874 case SE_I:
11875 if (!(!inst.operands[j].isreg
11876 && !inst.operands[j].isscalar))
11877 matches = 0;
11878 break;
11879
11880 case SE_S:
11881 if (!(!inst.operands[j].isreg
11882 && inst.operands[j].isscalar))
11883 matches = 0;
11884 break;
11885
11886 case SE_L:
11887 break;
11888 }
11889 if (!matches)
11890 break;
11891 }
11892 if (matches)
11893 break;
11894 }
11895
11896 va_end (ap);
11897
11898 if (shape == NS_NULL && first_shape != NS_NULL)
11899 first_error (_("invalid instruction shape"));
11900
11901 return shape;
11902 }
11903
11904 /* True if SHAPE is predominantly a quadword operation (most of the time, this
11905 means the Q bit should be set). */
11906
11907 static int
11908 neon_quad (enum neon_shape shape)
11909 {
11910 return neon_shape_class[shape] == SC_QUAD;
11911 }
11912
11913 static void
11914 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11915 unsigned *g_size)
11916 {
11917 /* Allow modification to be made to types which are constrained to be
11918 based on the key element, based on bits set alongside N_EQK. */
11919 if ((typebits & N_EQK) != 0)
11920 {
11921 if ((typebits & N_HLF) != 0)
11922 *g_size /= 2;
11923 else if ((typebits & N_DBL) != 0)
11924 *g_size *= 2;
11925 if ((typebits & N_SGN) != 0)
11926 *g_type = NT_signed;
11927 else if ((typebits & N_UNS) != 0)
11928 *g_type = NT_unsigned;
11929 else if ((typebits & N_INT) != 0)
11930 *g_type = NT_integer;
11931 else if ((typebits & N_FLT) != 0)
11932 *g_type = NT_float;
11933 else if ((typebits & N_SIZ) != 0)
11934 *g_type = NT_untyped;
11935 }
11936 }
11937
11938 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11939 operand type, i.e. the single type specified in a Neon instruction when it
11940 is the only one given. */
11941
11942 static struct neon_type_el
11943 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11944 {
11945 struct neon_type_el dest = *key;
11946
11947 gas_assert ((thisarg & N_EQK) != 0);
11948
11949 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11950
11951 return dest;
11952 }
11953
11954 /* Convert Neon type and size into compact bitmask representation. */
11955
11956 static enum neon_type_mask
11957 type_chk_of_el_type (enum neon_el_type type, unsigned size)
11958 {
11959 switch (type)
11960 {
11961 case NT_untyped:
11962 switch (size)
11963 {
11964 case 8: return N_8;
11965 case 16: return N_16;
11966 case 32: return N_32;
11967 case 64: return N_64;
11968 default: ;
11969 }
11970 break;
11971
11972 case NT_integer:
11973 switch (size)
11974 {
11975 case 8: return N_I8;
11976 case 16: return N_I16;
11977 case 32: return N_I32;
11978 case 64: return N_I64;
11979 default: ;
11980 }
11981 break;
11982
11983 case NT_float:
11984 switch (size)
11985 {
11986 case 16: return N_F16;
11987 case 32: return N_F32;
11988 case 64: return N_F64;
11989 default: ;
11990 }
11991 break;
11992
11993 case NT_poly:
11994 switch (size)
11995 {
11996 case 8: return N_P8;
11997 case 16: return N_P16;
11998 default: ;
11999 }
12000 break;
12001
12002 case NT_signed:
12003 switch (size)
12004 {
12005 case 8: return N_S8;
12006 case 16: return N_S16;
12007 case 32: return N_S32;
12008 case 64: return N_S64;
12009 default: ;
12010 }
12011 break;
12012
12013 case NT_unsigned:
12014 switch (size)
12015 {
12016 case 8: return N_U8;
12017 case 16: return N_U16;
12018 case 32: return N_U32;
12019 case 64: return N_U64;
12020 default: ;
12021 }
12022 break;
12023
12024 default: ;
12025 }
12026
12027 return N_UTYP;
12028 }
12029
12030 /* Convert compact Neon bitmask type representation to a type and size. Only
12031 handles the case where a single bit is set in the mask. */
12032
12033 static int
12034 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
12035 enum neon_type_mask mask)
12036 {
12037 if ((mask & N_EQK) != 0)
12038 return FAIL;
12039
12040 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
12041 *size = 8;
12042 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
12043 *size = 16;
12044 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
12045 *size = 32;
12046 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
12047 *size = 64;
12048 else
12049 return FAIL;
12050
12051 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
12052 *type = NT_signed;
12053 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
12054 *type = NT_unsigned;
12055 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
12056 *type = NT_integer;
12057 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
12058 *type = NT_untyped;
12059 else if ((mask & (N_P8 | N_P16)) != 0)
12060 *type = NT_poly;
12061 else if ((mask & (N_F32 | N_F64)) != 0)
12062 *type = NT_float;
12063 else
12064 return FAIL;
12065
12066 return SUCCESS;
12067 }
12068
12069 /* Modify a bitmask of allowed types. This is only needed for type
12070 relaxation. */
12071
12072 static unsigned
12073 modify_types_allowed (unsigned allowed, unsigned mods)
12074 {
12075 unsigned size;
12076 enum neon_el_type type;
12077 unsigned destmask;
12078 int i;
12079
12080 destmask = 0;
12081
12082 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
12083 {
12084 if (el_type_of_type_chk (&type, &size,
12085 (enum neon_type_mask) (allowed & i)) == SUCCESS)
12086 {
12087 neon_modify_type_size (mods, &type, &size);
12088 destmask |= type_chk_of_el_type (type, size);
12089 }
12090 }
12091
12092 return destmask;
12093 }
12094
12095 /* Check type and return type classification.
12096 The manual states (paraphrase): If one datatype is given, it indicates the
12097 type given in:
12098 - the second operand, if there is one
12099 - the operand, if there is no second operand
12100 - the result, if there are no operands.
12101 This isn't quite good enough though, so we use a concept of a "key" datatype
12102 which is set on a per-instruction basis, which is the one which matters when
12103 only one data type is written.
12104 Note: this function has side-effects (e.g. filling in missing operands). All
12105 Neon instructions should call it before performing bit encoding. */
12106
12107 static struct neon_type_el
12108 neon_check_type (unsigned els, enum neon_shape ns, ...)
12109 {
12110 va_list ap;
12111 unsigned i, pass, key_el = 0;
12112 unsigned types[NEON_MAX_TYPE_ELS];
12113 enum neon_el_type k_type = NT_invtype;
12114 unsigned k_size = -1u;
12115 struct neon_type_el badtype = {NT_invtype, -1};
12116 unsigned key_allowed = 0;
12117
12118 /* Optional registers in Neon instructions are always (not) in operand 1.
12119 Fill in the missing operand here, if it was omitted. */
12120 if (els > 1 && !inst.operands[1].present)
12121 inst.operands[1] = inst.operands[0];
12122
12123 /* Suck up all the varargs. */
12124 va_start (ap, ns);
12125 for (i = 0; i < els; i++)
12126 {
12127 unsigned thisarg = va_arg (ap, unsigned);
12128 if (thisarg == N_IGNORE_TYPE)
12129 {
12130 va_end (ap);
12131 return badtype;
12132 }
12133 types[i] = thisarg;
12134 if ((thisarg & N_KEY) != 0)
12135 key_el = i;
12136 }
12137 va_end (ap);
12138
12139 if (inst.vectype.elems > 0)
12140 for (i = 0; i < els; i++)
12141 if (inst.operands[i].vectype.type != NT_invtype)
12142 {
12143 first_error (_("types specified in both the mnemonic and operands"));
12144 return badtype;
12145 }
12146
12147 /* Duplicate inst.vectype elements here as necessary.
12148 FIXME: No idea if this is exactly the same as the ARM assembler,
12149 particularly when an insn takes one register and one non-register
12150 operand. */
12151 if (inst.vectype.elems == 1 && els > 1)
12152 {
12153 unsigned j;
12154 inst.vectype.elems = els;
12155 inst.vectype.el[key_el] = inst.vectype.el[0];
12156 for (j = 0; j < els; j++)
12157 if (j != key_el)
12158 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12159 types[j]);
12160 }
12161 else if (inst.vectype.elems == 0 && els > 0)
12162 {
12163 unsigned j;
12164 /* No types were given after the mnemonic, so look for types specified
12165 after each operand. We allow some flexibility here; as long as the
12166 "key" operand has a type, we can infer the others. */
12167 for (j = 0; j < els; j++)
12168 if (inst.operands[j].vectype.type != NT_invtype)
12169 inst.vectype.el[j] = inst.operands[j].vectype;
12170
12171 if (inst.operands[key_el].vectype.type != NT_invtype)
12172 {
12173 for (j = 0; j < els; j++)
12174 if (inst.operands[j].vectype.type == NT_invtype)
12175 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12176 types[j]);
12177 }
12178 else
12179 {
12180 first_error (_("operand types can't be inferred"));
12181 return badtype;
12182 }
12183 }
12184 else if (inst.vectype.elems != els)
12185 {
12186 first_error (_("type specifier has the wrong number of parts"));
12187 return badtype;
12188 }
12189
12190 for (pass = 0; pass < 2; pass++)
12191 {
12192 for (i = 0; i < els; i++)
12193 {
12194 unsigned thisarg = types[i];
12195 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12196 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12197 enum neon_el_type g_type = inst.vectype.el[i].type;
12198 unsigned g_size = inst.vectype.el[i].size;
12199
12200 /* Decay more-specific signed & unsigned types to sign-insensitive
12201 integer types if sign-specific variants are unavailable. */
12202 if ((g_type == NT_signed || g_type == NT_unsigned)
12203 && (types_allowed & N_SU_ALL) == 0)
12204 g_type = NT_integer;
12205
12206 /* If only untyped args are allowed, decay any more specific types to
12207 them. Some instructions only care about signs for some element
12208 sizes, so handle that properly. */
12209 if ((g_size == 8 && (types_allowed & N_8) != 0)
12210 || (g_size == 16 && (types_allowed & N_16) != 0)
12211 || (g_size == 32 && (types_allowed & N_32) != 0)
12212 || (g_size == 64 && (types_allowed & N_64) != 0))
12213 g_type = NT_untyped;
12214
12215 if (pass == 0)
12216 {
12217 if ((thisarg & N_KEY) != 0)
12218 {
12219 k_type = g_type;
12220 k_size = g_size;
12221 key_allowed = thisarg & ~N_KEY;
12222 }
12223 }
12224 else
12225 {
12226 if ((thisarg & N_VFP) != 0)
12227 {
12228 enum neon_shape_el regshape;
12229 unsigned regwidth, match;
12230
12231 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12232 if (ns == NS_NULL)
12233 {
12234 first_error (_("invalid instruction shape"));
12235 return badtype;
12236 }
12237 regshape = neon_shape_tab[ns].el[i];
12238 regwidth = neon_shape_el_size[regshape];
12239
12240 /* In VFP mode, operands must match register widths. If we
12241 have a key operand, use its width, else use the width of
12242 the current operand. */
12243 if (k_size != -1u)
12244 match = k_size;
12245 else
12246 match = g_size;
12247
12248 if (regwidth != match)
12249 {
12250 first_error (_("operand size must match register width"));
12251 return badtype;
12252 }
12253 }
12254
12255 if ((thisarg & N_EQK) == 0)
12256 {
12257 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12258
12259 if ((given_type & types_allowed) == 0)
12260 {
12261 first_error (_("bad type in Neon instruction"));
12262 return badtype;
12263 }
12264 }
12265 else
12266 {
12267 enum neon_el_type mod_k_type = k_type;
12268 unsigned mod_k_size = k_size;
12269 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12270 if (g_type != mod_k_type || g_size != mod_k_size)
12271 {
12272 first_error (_("inconsistent types in Neon instruction"));
12273 return badtype;
12274 }
12275 }
12276 }
12277 }
12278 }
12279
12280 return inst.vectype.el[key_el];
12281 }
12282
12283 /* Neon-style VFP instruction forwarding. */
12284
12285 /* Thumb VFP instructions have 0xE in the condition field. */
12286
12287 static void
12288 do_vfp_cond_or_thumb (void)
12289 {
12290 inst.is_neon = 1;
12291
12292 if (thumb_mode)
12293 inst.instruction |= 0xe0000000;
12294 else
12295 inst.instruction |= inst.cond << 28;
12296 }
12297
12298 /* Look up and encode a simple mnemonic, for use as a helper function for the
12299 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12300 etc. It is assumed that operand parsing has already been done, and that the
12301 operands are in the form expected by the given opcode (this isn't necessarily
12302 the same as the form in which they were parsed, hence some massaging must
12303 take place before this function is called).
12304 Checks current arch version against that in the looked-up opcode. */
12305
12306 static void
12307 do_vfp_nsyn_opcode (const char *opname)
12308 {
12309 const struct asm_opcode *opcode;
12310
12311 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
12312
12313 if (!opcode)
12314 abort ();
12315
12316 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12317 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12318 _(BAD_FPU));
12319
12320 inst.is_neon = 1;
12321
12322 if (thumb_mode)
12323 {
12324 inst.instruction = opcode->tvalue;
12325 opcode->tencode ();
12326 }
12327 else
12328 {
12329 inst.instruction = (inst.cond << 28) | opcode->avalue;
12330 opcode->aencode ();
12331 }
12332 }
12333
12334 static void
12335 do_vfp_nsyn_add_sub (enum neon_shape rs)
12336 {
12337 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12338
12339 if (rs == NS_FFF)
12340 {
12341 if (is_add)
12342 do_vfp_nsyn_opcode ("fadds");
12343 else
12344 do_vfp_nsyn_opcode ("fsubs");
12345 }
12346 else
12347 {
12348 if (is_add)
12349 do_vfp_nsyn_opcode ("faddd");
12350 else
12351 do_vfp_nsyn_opcode ("fsubd");
12352 }
12353 }
12354
12355 /* Check operand types to see if this is a VFP instruction, and if so call
12356 PFN (). */
12357
12358 static int
12359 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12360 {
12361 enum neon_shape rs;
12362 struct neon_type_el et;
12363
12364 switch (args)
12365 {
12366 case 2:
12367 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12368 et = neon_check_type (2, rs,
12369 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12370 break;
12371
12372 case 3:
12373 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12374 et = neon_check_type (3, rs,
12375 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12376 break;
12377
12378 default:
12379 abort ();
12380 }
12381
12382 if (et.type != NT_invtype)
12383 {
12384 pfn (rs);
12385 return SUCCESS;
12386 }
12387
12388 inst.error = NULL;
12389 return FAIL;
12390 }
12391
12392 static void
12393 do_vfp_nsyn_mla_mls (enum neon_shape rs)
12394 {
12395 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
12396
12397 if (rs == NS_FFF)
12398 {
12399 if (is_mla)
12400 do_vfp_nsyn_opcode ("fmacs");
12401 else
12402 do_vfp_nsyn_opcode ("fnmacs");
12403 }
12404 else
12405 {
12406 if (is_mla)
12407 do_vfp_nsyn_opcode ("fmacd");
12408 else
12409 do_vfp_nsyn_opcode ("fnmacd");
12410 }
12411 }
12412
12413 static void
12414 do_vfp_nsyn_fma_fms (enum neon_shape rs)
12415 {
12416 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12417
12418 if (rs == NS_FFF)
12419 {
12420 if (is_fma)
12421 do_vfp_nsyn_opcode ("ffmas");
12422 else
12423 do_vfp_nsyn_opcode ("ffnmas");
12424 }
12425 else
12426 {
12427 if (is_fma)
12428 do_vfp_nsyn_opcode ("ffmad");
12429 else
12430 do_vfp_nsyn_opcode ("ffnmad");
12431 }
12432 }
12433
12434 static void
12435 do_vfp_nsyn_mul (enum neon_shape rs)
12436 {
12437 if (rs == NS_FFF)
12438 do_vfp_nsyn_opcode ("fmuls");
12439 else
12440 do_vfp_nsyn_opcode ("fmuld");
12441 }
12442
12443 static void
12444 do_vfp_nsyn_abs_neg (enum neon_shape rs)
12445 {
12446 int is_neg = (inst.instruction & 0x80) != 0;
12447 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12448
12449 if (rs == NS_FF)
12450 {
12451 if (is_neg)
12452 do_vfp_nsyn_opcode ("fnegs");
12453 else
12454 do_vfp_nsyn_opcode ("fabss");
12455 }
12456 else
12457 {
12458 if (is_neg)
12459 do_vfp_nsyn_opcode ("fnegd");
12460 else
12461 do_vfp_nsyn_opcode ("fabsd");
12462 }
12463 }
12464
12465 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12466 insns belong to Neon, and are handled elsewhere. */
12467
12468 static void
12469 do_vfp_nsyn_ldm_stm (int is_dbmode)
12470 {
12471 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12472 if (is_ldm)
12473 {
12474 if (is_dbmode)
12475 do_vfp_nsyn_opcode ("fldmdbs");
12476 else
12477 do_vfp_nsyn_opcode ("fldmias");
12478 }
12479 else
12480 {
12481 if (is_dbmode)
12482 do_vfp_nsyn_opcode ("fstmdbs");
12483 else
12484 do_vfp_nsyn_opcode ("fstmias");
12485 }
12486 }
12487
12488 static void
12489 do_vfp_nsyn_sqrt (void)
12490 {
12491 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12492 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12493
12494 if (rs == NS_FF)
12495 do_vfp_nsyn_opcode ("fsqrts");
12496 else
12497 do_vfp_nsyn_opcode ("fsqrtd");
12498 }
12499
12500 static void
12501 do_vfp_nsyn_div (void)
12502 {
12503 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12504 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12505 N_F32 | N_F64 | N_KEY | N_VFP);
12506
12507 if (rs == NS_FFF)
12508 do_vfp_nsyn_opcode ("fdivs");
12509 else
12510 do_vfp_nsyn_opcode ("fdivd");
12511 }
12512
12513 static void
12514 do_vfp_nsyn_nmul (void)
12515 {
12516 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12517 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12518 N_F32 | N_F64 | N_KEY | N_VFP);
12519
12520 if (rs == NS_FFF)
12521 {
12522 NEON_ENCODE (SINGLE, inst);
12523 do_vfp_sp_dyadic ();
12524 }
12525 else
12526 {
12527 NEON_ENCODE (DOUBLE, inst);
12528 do_vfp_dp_rd_rn_rm ();
12529 }
12530 do_vfp_cond_or_thumb ();
12531 }
12532
12533 static void
12534 do_vfp_nsyn_cmp (void)
12535 {
12536 if (inst.operands[1].isreg)
12537 {
12538 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12539 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12540
12541 if (rs == NS_FF)
12542 {
12543 NEON_ENCODE (SINGLE, inst);
12544 do_vfp_sp_monadic ();
12545 }
12546 else
12547 {
12548 NEON_ENCODE (DOUBLE, inst);
12549 do_vfp_dp_rd_rm ();
12550 }
12551 }
12552 else
12553 {
12554 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12555 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12556
12557 switch (inst.instruction & 0x0fffffff)
12558 {
12559 case N_MNEM_vcmp:
12560 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12561 break;
12562 case N_MNEM_vcmpe:
12563 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12564 break;
12565 default:
12566 abort ();
12567 }
12568
12569 if (rs == NS_FI)
12570 {
12571 NEON_ENCODE (SINGLE, inst);
12572 do_vfp_sp_compare_z ();
12573 }
12574 else
12575 {
12576 NEON_ENCODE (DOUBLE, inst);
12577 do_vfp_dp_rd ();
12578 }
12579 }
12580 do_vfp_cond_or_thumb ();
12581 }
12582
12583 static void
12584 nsyn_insert_sp (void)
12585 {
12586 inst.operands[1] = inst.operands[0];
12587 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
12588 inst.operands[0].reg = REG_SP;
12589 inst.operands[0].isreg = 1;
12590 inst.operands[0].writeback = 1;
12591 inst.operands[0].present = 1;
12592 }
12593
12594 static void
12595 do_vfp_nsyn_push (void)
12596 {
12597 nsyn_insert_sp ();
12598 if (inst.operands[1].issingle)
12599 do_vfp_nsyn_opcode ("fstmdbs");
12600 else
12601 do_vfp_nsyn_opcode ("fstmdbd");
12602 }
12603
12604 static void
12605 do_vfp_nsyn_pop (void)
12606 {
12607 nsyn_insert_sp ();
12608 if (inst.operands[1].issingle)
12609 do_vfp_nsyn_opcode ("fldmias");
12610 else
12611 do_vfp_nsyn_opcode ("fldmiad");
12612 }
12613
12614 /* Fix up Neon data-processing instructions, ORing in the correct bits for
12615 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12616
12617 static void
12618 neon_dp_fixup (struct arm_it* insn)
12619 {
12620 unsigned int i = insn->instruction;
12621 insn->is_neon = 1;
12622
12623 if (thumb_mode)
12624 {
12625 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12626 if (i & (1 << 24))
12627 i |= 1 << 28;
12628
12629 i &= ~(1 << 24);
12630
12631 i |= 0xef000000;
12632 }
12633 else
12634 i |= 0xf2000000;
12635
12636 insn->instruction = i;
12637 }
12638
12639 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12640 (0, 1, 2, 3). */
12641
12642 static unsigned
12643 neon_logbits (unsigned x)
12644 {
12645 return ffs (x) - 4;
12646 }
12647
12648 #define LOW4(R) ((R) & 0xf)
12649 #define HI1(R) (((R) >> 4) & 1)
12650
12651 /* Encode insns with bit pattern:
12652
12653 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12654 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
12655
12656 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12657 different meaning for some instruction. */
12658
12659 static void
12660 neon_three_same (int isquad, int ubit, int size)
12661 {
12662 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12663 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12664 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12665 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12666 inst.instruction |= LOW4 (inst.operands[2].reg);
12667 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12668 inst.instruction |= (isquad != 0) << 6;
12669 inst.instruction |= (ubit != 0) << 24;
12670 if (size != -1)
12671 inst.instruction |= neon_logbits (size) << 20;
12672
12673 neon_dp_fixup (&inst);
12674 }
12675
12676 /* Encode instructions of the form:
12677
12678 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12679 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
12680
12681 Don't write size if SIZE == -1. */
12682
12683 static void
12684 neon_two_same (int qbit, int ubit, int size)
12685 {
12686 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12687 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12688 inst.instruction |= LOW4 (inst.operands[1].reg);
12689 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12690 inst.instruction |= (qbit != 0) << 6;
12691 inst.instruction |= (ubit != 0) << 24;
12692
12693 if (size != -1)
12694 inst.instruction |= neon_logbits (size) << 18;
12695
12696 neon_dp_fixup (&inst);
12697 }
12698
12699 /* Neon instruction encoders, in approximate order of appearance. */
12700
12701 static void
12702 do_neon_dyadic_i_su (void)
12703 {
12704 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12705 struct neon_type_el et = neon_check_type (3, rs,
12706 N_EQK, N_EQK, N_SU_32 | N_KEY);
12707 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12708 }
12709
12710 static void
12711 do_neon_dyadic_i64_su (void)
12712 {
12713 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12714 struct neon_type_el et = neon_check_type (3, rs,
12715 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12716 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12717 }
12718
12719 static void
12720 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12721 unsigned immbits)
12722 {
12723 unsigned size = et.size >> 3;
12724 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12725 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12726 inst.instruction |= LOW4 (inst.operands[1].reg);
12727 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12728 inst.instruction |= (isquad != 0) << 6;
12729 inst.instruction |= immbits << 16;
12730 inst.instruction |= (size >> 3) << 7;
12731 inst.instruction |= (size & 0x7) << 19;
12732 if (write_ubit)
12733 inst.instruction |= (uval != 0) << 24;
12734
12735 neon_dp_fixup (&inst);
12736 }
12737
12738 static void
12739 do_neon_shl_imm (void)
12740 {
12741 if (!inst.operands[2].isreg)
12742 {
12743 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12744 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12745 NEON_ENCODE (IMMED, inst);
12746 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
12747 }
12748 else
12749 {
12750 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12751 struct neon_type_el et = neon_check_type (3, rs,
12752 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12753 unsigned int tmp;
12754
12755 /* VSHL/VQSHL 3-register variants have syntax such as:
12756 vshl.xx Dd, Dm, Dn
12757 whereas other 3-register operations encoded by neon_three_same have
12758 syntax like:
12759 vadd.xx Dd, Dn, Dm
12760 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12761 here. */
12762 tmp = inst.operands[2].reg;
12763 inst.operands[2].reg = inst.operands[1].reg;
12764 inst.operands[1].reg = tmp;
12765 NEON_ENCODE (INTEGER, inst);
12766 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12767 }
12768 }
12769
12770 static void
12771 do_neon_qshl_imm (void)
12772 {
12773 if (!inst.operands[2].isreg)
12774 {
12775 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12776 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12777
12778 NEON_ENCODE (IMMED, inst);
12779 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12780 inst.operands[2].imm);
12781 }
12782 else
12783 {
12784 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12785 struct neon_type_el et = neon_check_type (3, rs,
12786 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12787 unsigned int tmp;
12788
12789 /* See note in do_neon_shl_imm. */
12790 tmp = inst.operands[2].reg;
12791 inst.operands[2].reg = inst.operands[1].reg;
12792 inst.operands[1].reg = tmp;
12793 NEON_ENCODE (INTEGER, inst);
12794 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12795 }
12796 }
12797
12798 static void
12799 do_neon_rshl (void)
12800 {
12801 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12802 struct neon_type_el et = neon_check_type (3, rs,
12803 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12804 unsigned int tmp;
12805
12806 tmp = inst.operands[2].reg;
12807 inst.operands[2].reg = inst.operands[1].reg;
12808 inst.operands[1].reg = tmp;
12809 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12810 }
12811
12812 static int
12813 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12814 {
12815 /* Handle .I8 pseudo-instructions. */
12816 if (size == 8)
12817 {
12818 /* Unfortunately, this will make everything apart from zero out-of-range.
12819 FIXME is this the intended semantics? There doesn't seem much point in
12820 accepting .I8 if so. */
12821 immediate |= immediate << 8;
12822 size = 16;
12823 }
12824
12825 if (size >= 32)
12826 {
12827 if (immediate == (immediate & 0x000000ff))
12828 {
12829 *immbits = immediate;
12830 return 0x1;
12831 }
12832 else if (immediate == (immediate & 0x0000ff00))
12833 {
12834 *immbits = immediate >> 8;
12835 return 0x3;
12836 }
12837 else if (immediate == (immediate & 0x00ff0000))
12838 {
12839 *immbits = immediate >> 16;
12840 return 0x5;
12841 }
12842 else if (immediate == (immediate & 0xff000000))
12843 {
12844 *immbits = immediate >> 24;
12845 return 0x7;
12846 }
12847 if ((immediate & 0xffff) != (immediate >> 16))
12848 goto bad_immediate;
12849 immediate &= 0xffff;
12850 }
12851
12852 if (immediate == (immediate & 0x000000ff))
12853 {
12854 *immbits = immediate;
12855 return 0x9;
12856 }
12857 else if (immediate == (immediate & 0x0000ff00))
12858 {
12859 *immbits = immediate >> 8;
12860 return 0xb;
12861 }
12862
12863 bad_immediate:
12864 first_error (_("immediate value out of range"));
12865 return FAIL;
12866 }
12867
12868 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12869 A, B, C, D. */
12870
12871 static int
12872 neon_bits_same_in_bytes (unsigned imm)
12873 {
12874 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12875 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12876 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12877 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12878 }
12879
12880 /* For immediate of above form, return 0bABCD. */
12881
12882 static unsigned
12883 neon_squash_bits (unsigned imm)
12884 {
12885 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12886 | ((imm & 0x01000000) >> 21);
12887 }
12888
12889 /* Compress quarter-float representation to 0b...000 abcdefgh. */
12890
12891 static unsigned
12892 neon_qfloat_bits (unsigned imm)
12893 {
12894 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
12895 }
12896
12897 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12898 the instruction. *OP is passed as the initial value of the op field, and
12899 may be set to a different value depending on the constant (i.e.
12900 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
12901 MVN). If the immediate looks like a repeated pattern then also
12902 try smaller element sizes. */
12903
12904 static int
12905 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12906 unsigned *immbits, int *op, int size,
12907 enum neon_el_type type)
12908 {
12909 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12910 float. */
12911 if (type == NT_float && !float_p)
12912 return FAIL;
12913
12914 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12915 {
12916 if (size != 32 || *op == 1)
12917 return FAIL;
12918 *immbits = neon_qfloat_bits (immlo);
12919 return 0xf;
12920 }
12921
12922 if (size == 64)
12923 {
12924 if (neon_bits_same_in_bytes (immhi)
12925 && neon_bits_same_in_bytes (immlo))
12926 {
12927 if (*op == 1)
12928 return FAIL;
12929 *immbits = (neon_squash_bits (immhi) << 4)
12930 | neon_squash_bits (immlo);
12931 *op = 1;
12932 return 0xe;
12933 }
12934
12935 if (immhi != immlo)
12936 return FAIL;
12937 }
12938
12939 if (size >= 32)
12940 {
12941 if (immlo == (immlo & 0x000000ff))
12942 {
12943 *immbits = immlo;
12944 return 0x0;
12945 }
12946 else if (immlo == (immlo & 0x0000ff00))
12947 {
12948 *immbits = immlo >> 8;
12949 return 0x2;
12950 }
12951 else if (immlo == (immlo & 0x00ff0000))
12952 {
12953 *immbits = immlo >> 16;
12954 return 0x4;
12955 }
12956 else if (immlo == (immlo & 0xff000000))
12957 {
12958 *immbits = immlo >> 24;
12959 return 0x6;
12960 }
12961 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12962 {
12963 *immbits = (immlo >> 8) & 0xff;
12964 return 0xc;
12965 }
12966 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12967 {
12968 *immbits = (immlo >> 16) & 0xff;
12969 return 0xd;
12970 }
12971
12972 if ((immlo & 0xffff) != (immlo >> 16))
12973 return FAIL;
12974 immlo &= 0xffff;
12975 }
12976
12977 if (size >= 16)
12978 {
12979 if (immlo == (immlo & 0x000000ff))
12980 {
12981 *immbits = immlo;
12982 return 0x8;
12983 }
12984 else if (immlo == (immlo & 0x0000ff00))
12985 {
12986 *immbits = immlo >> 8;
12987 return 0xa;
12988 }
12989
12990 if ((immlo & 0xff) != (immlo >> 8))
12991 return FAIL;
12992 immlo &= 0xff;
12993 }
12994
12995 if (immlo == (immlo & 0x000000ff))
12996 {
12997 /* Don't allow MVN with 8-bit immediate. */
12998 if (*op == 1)
12999 return FAIL;
13000 *immbits = immlo;
13001 return 0xe;
13002 }
13003
13004 return FAIL;
13005 }
13006
13007 /* Write immediate bits [7:0] to the following locations:
13008
13009 |28/24|23 19|18 16|15 4|3 0|
13010 | 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|
13011
13012 This function is used by VMOV/VMVN/VORR/VBIC. */
13013
13014 static void
13015 neon_write_immbits (unsigned immbits)
13016 {
13017 inst.instruction |= immbits & 0xf;
13018 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
13019 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
13020 }
13021
13022 /* Invert low-order SIZE bits of XHI:XLO. */
13023
13024 static void
13025 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
13026 {
13027 unsigned immlo = xlo ? *xlo : 0;
13028 unsigned immhi = xhi ? *xhi : 0;
13029
13030 switch (size)
13031 {
13032 case 8:
13033 immlo = (~immlo) & 0xff;
13034 break;
13035
13036 case 16:
13037 immlo = (~immlo) & 0xffff;
13038 break;
13039
13040 case 64:
13041 immhi = (~immhi) & 0xffffffff;
13042 /* fall through. */
13043
13044 case 32:
13045 immlo = (~immlo) & 0xffffffff;
13046 break;
13047
13048 default:
13049 abort ();
13050 }
13051
13052 if (xlo)
13053 *xlo = immlo;
13054
13055 if (xhi)
13056 *xhi = immhi;
13057 }
13058
13059 static void
13060 do_neon_logic (void)
13061 {
13062 if (inst.operands[2].present && inst.operands[2].isreg)
13063 {
13064 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13065 neon_check_type (3, rs, N_IGNORE_TYPE);
13066 /* U bit and size field were set as part of the bitmask. */
13067 NEON_ENCODE (INTEGER, inst);
13068 neon_three_same (neon_quad (rs), 0, -1);
13069 }
13070 else
13071 {
13072 const int three_ops_form = (inst.operands[2].present
13073 && !inst.operands[2].isreg);
13074 const int immoperand = (three_ops_form ? 2 : 1);
13075 enum neon_shape rs = (three_ops_form
13076 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
13077 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
13078 struct neon_type_el et = neon_check_type (2, rs,
13079 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13080 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
13081 unsigned immbits;
13082 int cmode;
13083
13084 if (et.type == NT_invtype)
13085 return;
13086
13087 if (three_ops_form)
13088 constraint (inst.operands[0].reg != inst.operands[1].reg,
13089 _("first and second operands shall be the same register"));
13090
13091 NEON_ENCODE (IMMED, inst);
13092
13093 immbits = inst.operands[immoperand].imm;
13094 if (et.size == 64)
13095 {
13096 /* .i64 is a pseudo-op, so the immediate must be a repeating
13097 pattern. */
13098 if (immbits != (inst.operands[immoperand].regisimm ?
13099 inst.operands[immoperand].reg : 0))
13100 {
13101 /* Set immbits to an invalid constant. */
13102 immbits = 0xdeadbeef;
13103 }
13104 }
13105
13106 switch (opcode)
13107 {
13108 case N_MNEM_vbic:
13109 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13110 break;
13111
13112 case N_MNEM_vorr:
13113 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13114 break;
13115
13116 case N_MNEM_vand:
13117 /* Pseudo-instruction for VBIC. */
13118 neon_invert_size (&immbits, 0, et.size);
13119 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13120 break;
13121
13122 case N_MNEM_vorn:
13123 /* Pseudo-instruction for VORR. */
13124 neon_invert_size (&immbits, 0, et.size);
13125 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13126 break;
13127
13128 default:
13129 abort ();
13130 }
13131
13132 if (cmode == FAIL)
13133 return;
13134
13135 inst.instruction |= neon_quad (rs) << 6;
13136 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13137 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13138 inst.instruction |= cmode << 8;
13139 neon_write_immbits (immbits);
13140
13141 neon_dp_fixup (&inst);
13142 }
13143 }
13144
13145 static void
13146 do_neon_bitfield (void)
13147 {
13148 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13149 neon_check_type (3, rs, N_IGNORE_TYPE);
13150 neon_three_same (neon_quad (rs), 0, -1);
13151 }
13152
13153 static void
13154 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13155 unsigned destbits)
13156 {
13157 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13158 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13159 types | N_KEY);
13160 if (et.type == NT_float)
13161 {
13162 NEON_ENCODE (FLOAT, inst);
13163 neon_three_same (neon_quad (rs), 0, -1);
13164 }
13165 else
13166 {
13167 NEON_ENCODE (INTEGER, inst);
13168 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13169 }
13170 }
13171
13172 static void
13173 do_neon_dyadic_if_su (void)
13174 {
13175 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13176 }
13177
13178 static void
13179 do_neon_dyadic_if_su_d (void)
13180 {
13181 /* This version only allow D registers, but that constraint is enforced during
13182 operand parsing so we don't need to do anything extra here. */
13183 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13184 }
13185
13186 static void
13187 do_neon_dyadic_if_i_d (void)
13188 {
13189 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13190 affected if we specify unsigned args. */
13191 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13192 }
13193
13194 enum vfp_or_neon_is_neon_bits
13195 {
13196 NEON_CHECK_CC = 1,
13197 NEON_CHECK_ARCH = 2
13198 };
13199
13200 /* Call this function if an instruction which may have belonged to the VFP or
13201 Neon instruction sets, but turned out to be a Neon instruction (due to the
13202 operand types involved, etc.). We have to check and/or fix-up a couple of
13203 things:
13204
13205 - Make sure the user hasn't attempted to make a Neon instruction
13206 conditional.
13207 - Alter the value in the condition code field if necessary.
13208 - Make sure that the arch supports Neon instructions.
13209
13210 Which of these operations take place depends on bits from enum
13211 vfp_or_neon_is_neon_bits.
13212
13213 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13214 current instruction's condition is COND_ALWAYS, the condition field is
13215 changed to inst.uncond_value. This is necessary because instructions shared
13216 between VFP and Neon may be conditional for the VFP variants only, and the
13217 unconditional Neon version must have, e.g., 0xF in the condition field. */
13218
13219 static int
13220 vfp_or_neon_is_neon (unsigned check)
13221 {
13222 /* Conditions are always legal in Thumb mode (IT blocks). */
13223 if (!thumb_mode && (check & NEON_CHECK_CC))
13224 {
13225 if (inst.cond != COND_ALWAYS)
13226 {
13227 first_error (_(BAD_COND));
13228 return FAIL;
13229 }
13230 if (inst.uncond_value != -1)
13231 inst.instruction |= inst.uncond_value << 28;
13232 }
13233
13234 if ((check & NEON_CHECK_ARCH)
13235 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13236 {
13237 first_error (_(BAD_FPU));
13238 return FAIL;
13239 }
13240
13241 return SUCCESS;
13242 }
13243
13244 static void
13245 do_neon_addsub_if_i (void)
13246 {
13247 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13248 return;
13249
13250 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13251 return;
13252
13253 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13254 affected if we specify unsigned args. */
13255 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
13256 }
13257
13258 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13259 result to be:
13260 V<op> A,B (A is operand 0, B is operand 2)
13261 to mean:
13262 V<op> A,B,A
13263 not:
13264 V<op> A,B,B
13265 so handle that case specially. */
13266
13267 static void
13268 neon_exchange_operands (void)
13269 {
13270 void *scratch = alloca (sizeof (inst.operands[0]));
13271 if (inst.operands[1].present)
13272 {
13273 /* Swap operands[1] and operands[2]. */
13274 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13275 inst.operands[1] = inst.operands[2];
13276 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13277 }
13278 else
13279 {
13280 inst.operands[1] = inst.operands[2];
13281 inst.operands[2] = inst.operands[0];
13282 }
13283 }
13284
13285 static void
13286 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13287 {
13288 if (inst.operands[2].isreg)
13289 {
13290 if (invert)
13291 neon_exchange_operands ();
13292 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
13293 }
13294 else
13295 {
13296 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13297 struct neon_type_el et = neon_check_type (2, rs,
13298 N_EQK | N_SIZ, immtypes | N_KEY);
13299
13300 NEON_ENCODE (IMMED, inst);
13301 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13302 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13303 inst.instruction |= LOW4 (inst.operands[1].reg);
13304 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13305 inst.instruction |= neon_quad (rs) << 6;
13306 inst.instruction |= (et.type == NT_float) << 10;
13307 inst.instruction |= neon_logbits (et.size) << 18;
13308
13309 neon_dp_fixup (&inst);
13310 }
13311 }
13312
13313 static void
13314 do_neon_cmp (void)
13315 {
13316 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13317 }
13318
13319 static void
13320 do_neon_cmp_inv (void)
13321 {
13322 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13323 }
13324
13325 static void
13326 do_neon_ceq (void)
13327 {
13328 neon_compare (N_IF_32, N_IF_32, FALSE);
13329 }
13330
13331 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
13332 scalars, which are encoded in 5 bits, M : Rm.
13333 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13334 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13335 index in M. */
13336
13337 static unsigned
13338 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13339 {
13340 unsigned regno = NEON_SCALAR_REG (scalar);
13341 unsigned elno = NEON_SCALAR_INDEX (scalar);
13342
13343 switch (elsize)
13344 {
13345 case 16:
13346 if (regno > 7 || elno > 3)
13347 goto bad_scalar;
13348 return regno | (elno << 3);
13349
13350 case 32:
13351 if (regno > 15 || elno > 1)
13352 goto bad_scalar;
13353 return regno | (elno << 4);
13354
13355 default:
13356 bad_scalar:
13357 first_error (_("scalar out of range for multiply instruction"));
13358 }
13359
13360 return 0;
13361 }
13362
13363 /* Encode multiply / multiply-accumulate scalar instructions. */
13364
13365 static void
13366 neon_mul_mac (struct neon_type_el et, int ubit)
13367 {
13368 unsigned scalar;
13369
13370 /* Give a more helpful error message if we have an invalid type. */
13371 if (et.type == NT_invtype)
13372 return;
13373
13374 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
13375 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13376 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13377 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13378 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13379 inst.instruction |= LOW4 (scalar);
13380 inst.instruction |= HI1 (scalar) << 5;
13381 inst.instruction |= (et.type == NT_float) << 8;
13382 inst.instruction |= neon_logbits (et.size) << 20;
13383 inst.instruction |= (ubit != 0) << 24;
13384
13385 neon_dp_fixup (&inst);
13386 }
13387
13388 static void
13389 do_neon_mac_maybe_scalar (void)
13390 {
13391 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13392 return;
13393
13394 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13395 return;
13396
13397 if (inst.operands[2].isscalar)
13398 {
13399 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13400 struct neon_type_el et = neon_check_type (3, rs,
13401 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
13402 NEON_ENCODE (SCALAR, inst);
13403 neon_mul_mac (et, neon_quad (rs));
13404 }
13405 else
13406 {
13407 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13408 affected if we specify unsigned args. */
13409 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13410 }
13411 }
13412
13413 static void
13414 do_neon_fmac (void)
13415 {
13416 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13417 return;
13418
13419 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13420 return;
13421
13422 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13423 }
13424
13425 static void
13426 do_neon_tst (void)
13427 {
13428 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13429 struct neon_type_el et = neon_check_type (3, rs,
13430 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
13431 neon_three_same (neon_quad (rs), 0, et.size);
13432 }
13433
13434 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
13435 same types as the MAC equivalents. The polynomial type for this instruction
13436 is encoded the same as the integer type. */
13437
13438 static void
13439 do_neon_mul (void)
13440 {
13441 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13442 return;
13443
13444 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13445 return;
13446
13447 if (inst.operands[2].isscalar)
13448 do_neon_mac_maybe_scalar ();
13449 else
13450 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
13451 }
13452
13453 static void
13454 do_neon_qdmulh (void)
13455 {
13456 if (inst.operands[2].isscalar)
13457 {
13458 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13459 struct neon_type_el et = neon_check_type (3, rs,
13460 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13461 NEON_ENCODE (SCALAR, inst);
13462 neon_mul_mac (et, neon_quad (rs));
13463 }
13464 else
13465 {
13466 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13467 struct neon_type_el et = neon_check_type (3, rs,
13468 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13469 NEON_ENCODE (INTEGER, inst);
13470 /* The U bit (rounding) comes from bit mask. */
13471 neon_three_same (neon_quad (rs), 0, et.size);
13472 }
13473 }
13474
13475 static void
13476 do_neon_fcmp_absolute (void)
13477 {
13478 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13479 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13480 /* Size field comes from bit mask. */
13481 neon_three_same (neon_quad (rs), 1, -1);
13482 }
13483
13484 static void
13485 do_neon_fcmp_absolute_inv (void)
13486 {
13487 neon_exchange_operands ();
13488 do_neon_fcmp_absolute ();
13489 }
13490
13491 static void
13492 do_neon_step (void)
13493 {
13494 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13495 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13496 neon_three_same (neon_quad (rs), 0, -1);
13497 }
13498
13499 static void
13500 do_neon_abs_neg (void)
13501 {
13502 enum neon_shape rs;
13503 struct neon_type_el et;
13504
13505 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13506 return;
13507
13508 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13509 return;
13510
13511 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13512 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
13513
13514 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13515 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13516 inst.instruction |= LOW4 (inst.operands[1].reg);
13517 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13518 inst.instruction |= neon_quad (rs) << 6;
13519 inst.instruction |= (et.type == NT_float) << 10;
13520 inst.instruction |= neon_logbits (et.size) << 18;
13521
13522 neon_dp_fixup (&inst);
13523 }
13524
13525 static void
13526 do_neon_sli (void)
13527 {
13528 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13529 struct neon_type_el et = neon_check_type (2, rs,
13530 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13531 int imm = inst.operands[2].imm;
13532 constraint (imm < 0 || (unsigned)imm >= et.size,
13533 _("immediate out of range for insert"));
13534 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13535 }
13536
13537 static void
13538 do_neon_sri (void)
13539 {
13540 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13541 struct neon_type_el et = neon_check_type (2, rs,
13542 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13543 int imm = inst.operands[2].imm;
13544 constraint (imm < 1 || (unsigned)imm > et.size,
13545 _("immediate out of range for insert"));
13546 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
13547 }
13548
13549 static void
13550 do_neon_qshlu_imm (void)
13551 {
13552 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13553 struct neon_type_el et = neon_check_type (2, rs,
13554 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13555 int imm = inst.operands[2].imm;
13556 constraint (imm < 0 || (unsigned)imm >= et.size,
13557 _("immediate out of range for shift"));
13558 /* Only encodes the 'U present' variant of the instruction.
13559 In this case, signed types have OP (bit 8) set to 0.
13560 Unsigned types have OP set to 1. */
13561 inst.instruction |= (et.type == NT_unsigned) << 8;
13562 /* The rest of the bits are the same as other immediate shifts. */
13563 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13564 }
13565
13566 static void
13567 do_neon_qmovn (void)
13568 {
13569 struct neon_type_el et = neon_check_type (2, NS_DQ,
13570 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13571 /* Saturating move where operands can be signed or unsigned, and the
13572 destination has the same signedness. */
13573 NEON_ENCODE (INTEGER, inst);
13574 if (et.type == NT_unsigned)
13575 inst.instruction |= 0xc0;
13576 else
13577 inst.instruction |= 0x80;
13578 neon_two_same (0, 1, et.size / 2);
13579 }
13580
13581 static void
13582 do_neon_qmovun (void)
13583 {
13584 struct neon_type_el et = neon_check_type (2, NS_DQ,
13585 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13586 /* Saturating move with unsigned results. Operands must be signed. */
13587 NEON_ENCODE (INTEGER, inst);
13588 neon_two_same (0, 1, et.size / 2);
13589 }
13590
13591 static void
13592 do_neon_rshift_sat_narrow (void)
13593 {
13594 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13595 or unsigned. If operands are unsigned, results must also be unsigned. */
13596 struct neon_type_el et = neon_check_type (2, NS_DQI,
13597 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13598 int imm = inst.operands[2].imm;
13599 /* This gets the bounds check, size encoding and immediate bits calculation
13600 right. */
13601 et.size /= 2;
13602
13603 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13604 VQMOVN.I<size> <Dd>, <Qm>. */
13605 if (imm == 0)
13606 {
13607 inst.operands[2].present = 0;
13608 inst.instruction = N_MNEM_vqmovn;
13609 do_neon_qmovn ();
13610 return;
13611 }
13612
13613 constraint (imm < 1 || (unsigned)imm > et.size,
13614 _("immediate out of range"));
13615 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13616 }
13617
13618 static void
13619 do_neon_rshift_sat_narrow_u (void)
13620 {
13621 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13622 or unsigned. If operands are unsigned, results must also be unsigned. */
13623 struct neon_type_el et = neon_check_type (2, NS_DQI,
13624 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13625 int imm = inst.operands[2].imm;
13626 /* This gets the bounds check, size encoding and immediate bits calculation
13627 right. */
13628 et.size /= 2;
13629
13630 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13631 VQMOVUN.I<size> <Dd>, <Qm>. */
13632 if (imm == 0)
13633 {
13634 inst.operands[2].present = 0;
13635 inst.instruction = N_MNEM_vqmovun;
13636 do_neon_qmovun ();
13637 return;
13638 }
13639
13640 constraint (imm < 1 || (unsigned)imm > et.size,
13641 _("immediate out of range"));
13642 /* FIXME: The manual is kind of unclear about what value U should have in
13643 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13644 must be 1. */
13645 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13646 }
13647
13648 static void
13649 do_neon_movn (void)
13650 {
13651 struct neon_type_el et = neon_check_type (2, NS_DQ,
13652 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13653 NEON_ENCODE (INTEGER, inst);
13654 neon_two_same (0, 1, et.size / 2);
13655 }
13656
13657 static void
13658 do_neon_rshift_narrow (void)
13659 {
13660 struct neon_type_el et = neon_check_type (2, NS_DQI,
13661 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13662 int imm = inst.operands[2].imm;
13663 /* This gets the bounds check, size encoding and immediate bits calculation
13664 right. */
13665 et.size /= 2;
13666
13667 /* If immediate is zero then we are a pseudo-instruction for
13668 VMOVN.I<size> <Dd>, <Qm> */
13669 if (imm == 0)
13670 {
13671 inst.operands[2].present = 0;
13672 inst.instruction = N_MNEM_vmovn;
13673 do_neon_movn ();
13674 return;
13675 }
13676
13677 constraint (imm < 1 || (unsigned)imm > et.size,
13678 _("immediate out of range for narrowing operation"));
13679 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13680 }
13681
13682 static void
13683 do_neon_shll (void)
13684 {
13685 /* FIXME: Type checking when lengthening. */
13686 struct neon_type_el et = neon_check_type (2, NS_QDI,
13687 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13688 unsigned imm = inst.operands[2].imm;
13689
13690 if (imm == et.size)
13691 {
13692 /* Maximum shift variant. */
13693 NEON_ENCODE (INTEGER, inst);
13694 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13695 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13696 inst.instruction |= LOW4 (inst.operands[1].reg);
13697 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13698 inst.instruction |= neon_logbits (et.size) << 18;
13699
13700 neon_dp_fixup (&inst);
13701 }
13702 else
13703 {
13704 /* A more-specific type check for non-max versions. */
13705 et = neon_check_type (2, NS_QDI,
13706 N_EQK | N_DBL, N_SU_32 | N_KEY);
13707 NEON_ENCODE (IMMED, inst);
13708 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13709 }
13710 }
13711
13712 /* Check the various types for the VCVT instruction, and return which version
13713 the current instruction is. */
13714
13715 static int
13716 neon_cvt_flavour (enum neon_shape rs)
13717 {
13718 #define CVT_VAR(C,X,Y) \
13719 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13720 if (et.type != NT_invtype) \
13721 { \
13722 inst.error = NULL; \
13723 return (C); \
13724 }
13725 struct neon_type_el et;
13726 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13727 || rs == NS_FF) ? N_VFP : 0;
13728 /* The instruction versions which take an immediate take one register
13729 argument, which is extended to the width of the full register. Thus the
13730 "source" and "destination" registers must have the same width. Hack that
13731 here by making the size equal to the key (wider, in this case) operand. */
13732 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
13733
13734 CVT_VAR (0, N_S32, N_F32);
13735 CVT_VAR (1, N_U32, N_F32);
13736 CVT_VAR (2, N_F32, N_S32);
13737 CVT_VAR (3, N_F32, N_U32);
13738 /* Half-precision conversions. */
13739 CVT_VAR (4, N_F32, N_F16);
13740 CVT_VAR (5, N_F16, N_F32);
13741
13742 whole_reg = N_VFP;
13743
13744 /* VFP instructions. */
13745 CVT_VAR (6, N_F32, N_F64);
13746 CVT_VAR (7, N_F64, N_F32);
13747 CVT_VAR (8, N_S32, N_F64 | key);
13748 CVT_VAR (9, N_U32, N_F64 | key);
13749 CVT_VAR (10, N_F64 | key, N_S32);
13750 CVT_VAR (11, N_F64 | key, N_U32);
13751 /* VFP instructions with bitshift. */
13752 CVT_VAR (12, N_F32 | key, N_S16);
13753 CVT_VAR (13, N_F32 | key, N_U16);
13754 CVT_VAR (14, N_F64 | key, N_S16);
13755 CVT_VAR (15, N_F64 | key, N_U16);
13756 CVT_VAR (16, N_S16, N_F32 | key);
13757 CVT_VAR (17, N_U16, N_F32 | key);
13758 CVT_VAR (18, N_S16, N_F64 | key);
13759 CVT_VAR (19, N_U16, N_F64 | key);
13760
13761 return -1;
13762 #undef CVT_VAR
13763 }
13764
13765 /* Neon-syntax VFP conversions. */
13766
13767 static void
13768 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
13769 {
13770 const char *opname = 0;
13771
13772 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
13773 {
13774 /* Conversions with immediate bitshift. */
13775 const char *enc[] =
13776 {
13777 "ftosls",
13778 "ftouls",
13779 "fsltos",
13780 "fultos",
13781 NULL,
13782 NULL,
13783 NULL,
13784 NULL,
13785 "ftosld",
13786 "ftould",
13787 "fsltod",
13788 "fultod",
13789 "fshtos",
13790 "fuhtos",
13791 "fshtod",
13792 "fuhtod",
13793 "ftoshs",
13794 "ftouhs",
13795 "ftoshd",
13796 "ftouhd"
13797 };
13798
13799 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13800 {
13801 opname = enc[flavour];
13802 constraint (inst.operands[0].reg != inst.operands[1].reg,
13803 _("operands 0 and 1 must be the same register"));
13804 inst.operands[1] = inst.operands[2];
13805 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13806 }
13807 }
13808 else
13809 {
13810 /* Conversions without bitshift. */
13811 const char *enc[] =
13812 {
13813 "ftosis",
13814 "ftouis",
13815 "fsitos",
13816 "fuitos",
13817 "NULL",
13818 "NULL",
13819 "fcvtsd",
13820 "fcvtds",
13821 "ftosid",
13822 "ftouid",
13823 "fsitod",
13824 "fuitod"
13825 };
13826
13827 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13828 opname = enc[flavour];
13829 }
13830
13831 if (opname)
13832 do_vfp_nsyn_opcode (opname);
13833 }
13834
13835 static void
13836 do_vfp_nsyn_cvtz (void)
13837 {
13838 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13839 int flavour = neon_cvt_flavour (rs);
13840 const char *enc[] =
13841 {
13842 "ftosizs",
13843 "ftouizs",
13844 NULL,
13845 NULL,
13846 NULL,
13847 NULL,
13848 NULL,
13849 NULL,
13850 "ftosizd",
13851 "ftouizd"
13852 };
13853
13854 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13855 do_vfp_nsyn_opcode (enc[flavour]);
13856 }
13857
13858 static void
13859 do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
13860 {
13861 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
13862 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
13863 int flavour = neon_cvt_flavour (rs);
13864
13865 /* PR11109: Handle round-to-zero for VCVT conversions. */
13866 if (round_to_zero
13867 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
13868 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
13869 && (rs == NS_FD || rs == NS_FF))
13870 {
13871 do_vfp_nsyn_cvtz ();
13872 return;
13873 }
13874
13875 /* VFP rather than Neon conversions. */
13876 if (flavour >= 6)
13877 {
13878 do_vfp_nsyn_cvt (rs, flavour);
13879 return;
13880 }
13881
13882 switch (rs)
13883 {
13884 case NS_DDI:
13885 case NS_QQI:
13886 {
13887 unsigned immbits;
13888 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13889
13890 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13891 return;
13892
13893 /* Fixed-point conversion with #0 immediate is encoded as an
13894 integer conversion. */
13895 if (inst.operands[2].present && inst.operands[2].imm == 0)
13896 goto int_encode;
13897 immbits = 32 - inst.operands[2].imm;
13898 NEON_ENCODE (IMMED, inst);
13899 if (flavour != -1)
13900 inst.instruction |= enctab[flavour];
13901 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13902 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13903 inst.instruction |= LOW4 (inst.operands[1].reg);
13904 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13905 inst.instruction |= neon_quad (rs) << 6;
13906 inst.instruction |= 1 << 21;
13907 inst.instruction |= immbits << 16;
13908
13909 neon_dp_fixup (&inst);
13910 }
13911 break;
13912
13913 case NS_DD:
13914 case NS_QQ:
13915 int_encode:
13916 {
13917 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13918
13919 NEON_ENCODE (INTEGER, inst);
13920
13921 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13922 return;
13923
13924 if (flavour != -1)
13925 inst.instruction |= enctab[flavour];
13926
13927 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13928 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13929 inst.instruction |= LOW4 (inst.operands[1].reg);
13930 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13931 inst.instruction |= neon_quad (rs) << 6;
13932 inst.instruction |= 2 << 18;
13933
13934 neon_dp_fixup (&inst);
13935 }
13936 break;
13937
13938 /* Half-precision conversions for Advanced SIMD -- neon. */
13939 case NS_QD:
13940 case NS_DQ:
13941
13942 if ((rs == NS_DQ)
13943 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13944 {
13945 as_bad (_("operand size must match register width"));
13946 break;
13947 }
13948
13949 if ((rs == NS_QD)
13950 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13951 {
13952 as_bad (_("operand size must match register width"));
13953 break;
13954 }
13955
13956 if (rs == NS_DQ)
13957 inst.instruction = 0x3b60600;
13958 else
13959 inst.instruction = 0x3b60700;
13960
13961 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13962 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13963 inst.instruction |= LOW4 (inst.operands[1].reg);
13964 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13965 neon_dp_fixup (&inst);
13966 break;
13967
13968 default:
13969 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13970 do_vfp_nsyn_cvt (rs, flavour);
13971 }
13972 }
13973
13974 static void
13975 do_neon_cvtr (void)
13976 {
13977 do_neon_cvt_1 (FALSE);
13978 }
13979
13980 static void
13981 do_neon_cvt (void)
13982 {
13983 do_neon_cvt_1 (TRUE);
13984 }
13985
13986 static void
13987 do_neon_cvtb (void)
13988 {
13989 inst.instruction = 0xeb20a40;
13990
13991 /* The sizes are attached to the mnemonic. */
13992 if (inst.vectype.el[0].type != NT_invtype
13993 && inst.vectype.el[0].size == 16)
13994 inst.instruction |= 0x00010000;
13995
13996 /* Programmer's syntax: the sizes are attached to the operands. */
13997 else if (inst.operands[0].vectype.type != NT_invtype
13998 && inst.operands[0].vectype.size == 16)
13999 inst.instruction |= 0x00010000;
14000
14001 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
14002 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
14003 do_vfp_cond_or_thumb ();
14004 }
14005
14006
14007 static void
14008 do_neon_cvtt (void)
14009 {
14010 do_neon_cvtb ();
14011 inst.instruction |= 0x80;
14012 }
14013
14014 static void
14015 neon_move_immediate (void)
14016 {
14017 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
14018 struct neon_type_el et = neon_check_type (2, rs,
14019 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
14020 unsigned immlo, immhi = 0, immbits;
14021 int op, cmode, float_p;
14022
14023 constraint (et.type == NT_invtype,
14024 _("operand size must be specified for immediate VMOV"));
14025
14026 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
14027 op = (inst.instruction & (1 << 5)) != 0;
14028
14029 immlo = inst.operands[1].imm;
14030 if (inst.operands[1].regisimm)
14031 immhi = inst.operands[1].reg;
14032
14033 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
14034 _("immediate has bits set outside the operand size"));
14035
14036 float_p = inst.operands[1].immisfloat;
14037
14038 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
14039 et.size, et.type)) == FAIL)
14040 {
14041 /* Invert relevant bits only. */
14042 neon_invert_size (&immlo, &immhi, et.size);
14043 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
14044 with one or the other; those cases are caught by
14045 neon_cmode_for_move_imm. */
14046 op = !op;
14047 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
14048 &op, et.size, et.type)) == FAIL)
14049 {
14050 first_error (_("immediate out of range"));
14051 return;
14052 }
14053 }
14054
14055 inst.instruction &= ~(1 << 5);
14056 inst.instruction |= op << 5;
14057
14058 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14059 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14060 inst.instruction |= neon_quad (rs) << 6;
14061 inst.instruction |= cmode << 8;
14062
14063 neon_write_immbits (immbits);
14064 }
14065
14066 static void
14067 do_neon_mvn (void)
14068 {
14069 if (inst.operands[1].isreg)
14070 {
14071 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14072
14073 NEON_ENCODE (INTEGER, inst);
14074 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14075 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14076 inst.instruction |= LOW4 (inst.operands[1].reg);
14077 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14078 inst.instruction |= neon_quad (rs) << 6;
14079 }
14080 else
14081 {
14082 NEON_ENCODE (IMMED, inst);
14083 neon_move_immediate ();
14084 }
14085
14086 neon_dp_fixup (&inst);
14087 }
14088
14089 /* Encode instructions of form:
14090
14091 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14092 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
14093
14094 static void
14095 neon_mixed_length (struct neon_type_el et, unsigned size)
14096 {
14097 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14098 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14099 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14100 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14101 inst.instruction |= LOW4 (inst.operands[2].reg);
14102 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14103 inst.instruction |= (et.type == NT_unsigned) << 24;
14104 inst.instruction |= neon_logbits (size) << 20;
14105
14106 neon_dp_fixup (&inst);
14107 }
14108
14109 static void
14110 do_neon_dyadic_long (void)
14111 {
14112 /* FIXME: Type checking for lengthening op. */
14113 struct neon_type_el et = neon_check_type (3, NS_QDD,
14114 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14115 neon_mixed_length (et, et.size);
14116 }
14117
14118 static void
14119 do_neon_abal (void)
14120 {
14121 struct neon_type_el et = neon_check_type (3, NS_QDD,
14122 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14123 neon_mixed_length (et, et.size);
14124 }
14125
14126 static void
14127 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14128 {
14129 if (inst.operands[2].isscalar)
14130 {
14131 struct neon_type_el et = neon_check_type (3, NS_QDS,
14132 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
14133 NEON_ENCODE (SCALAR, inst);
14134 neon_mul_mac (et, et.type == NT_unsigned);
14135 }
14136 else
14137 {
14138 struct neon_type_el et = neon_check_type (3, NS_QDD,
14139 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
14140 NEON_ENCODE (INTEGER, inst);
14141 neon_mixed_length (et, et.size);
14142 }
14143 }
14144
14145 static void
14146 do_neon_mac_maybe_scalar_long (void)
14147 {
14148 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14149 }
14150
14151 static void
14152 do_neon_dyadic_wide (void)
14153 {
14154 struct neon_type_el et = neon_check_type (3, NS_QQD,
14155 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14156 neon_mixed_length (et, et.size);
14157 }
14158
14159 static void
14160 do_neon_dyadic_narrow (void)
14161 {
14162 struct neon_type_el et = neon_check_type (3, NS_QDD,
14163 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
14164 /* Operand sign is unimportant, and the U bit is part of the opcode,
14165 so force the operand type to integer. */
14166 et.type = NT_integer;
14167 neon_mixed_length (et, et.size / 2);
14168 }
14169
14170 static void
14171 do_neon_mul_sat_scalar_long (void)
14172 {
14173 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14174 }
14175
14176 static void
14177 do_neon_vmull (void)
14178 {
14179 if (inst.operands[2].isscalar)
14180 do_neon_mac_maybe_scalar_long ();
14181 else
14182 {
14183 struct neon_type_el et = neon_check_type (3, NS_QDD,
14184 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14185 if (et.type == NT_poly)
14186 NEON_ENCODE (POLY, inst);
14187 else
14188 NEON_ENCODE (INTEGER, inst);
14189 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14190 zero. Should be OK as-is. */
14191 neon_mixed_length (et, et.size);
14192 }
14193 }
14194
14195 static void
14196 do_neon_ext (void)
14197 {
14198 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
14199 struct neon_type_el et = neon_check_type (3, rs,
14200 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14201 unsigned imm = (inst.operands[3].imm * et.size) / 8;
14202
14203 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14204 _("shift out of range"));
14205 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14206 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14207 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14208 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14209 inst.instruction |= LOW4 (inst.operands[2].reg);
14210 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14211 inst.instruction |= neon_quad (rs) << 6;
14212 inst.instruction |= imm << 8;
14213
14214 neon_dp_fixup (&inst);
14215 }
14216
14217 static void
14218 do_neon_rev (void)
14219 {
14220 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14221 struct neon_type_el et = neon_check_type (2, rs,
14222 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14223 unsigned op = (inst.instruction >> 7) & 3;
14224 /* N (width of reversed regions) is encoded as part of the bitmask. We
14225 extract it here to check the elements to be reversed are smaller.
14226 Otherwise we'd get a reserved instruction. */
14227 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
14228 gas_assert (elsize != 0);
14229 constraint (et.size >= elsize,
14230 _("elements must be smaller than reversal region"));
14231 neon_two_same (neon_quad (rs), 1, et.size);
14232 }
14233
14234 static void
14235 do_neon_dup (void)
14236 {
14237 if (inst.operands[1].isscalar)
14238 {
14239 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
14240 struct neon_type_el et = neon_check_type (2, rs,
14241 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14242 unsigned sizebits = et.size >> 3;
14243 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
14244 int logsize = neon_logbits (et.size);
14245 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
14246
14247 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14248 return;
14249
14250 NEON_ENCODE (SCALAR, inst);
14251 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14252 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14253 inst.instruction |= LOW4 (dm);
14254 inst.instruction |= HI1 (dm) << 5;
14255 inst.instruction |= neon_quad (rs) << 6;
14256 inst.instruction |= x << 17;
14257 inst.instruction |= sizebits << 16;
14258
14259 neon_dp_fixup (&inst);
14260 }
14261 else
14262 {
14263 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14264 struct neon_type_el et = neon_check_type (2, rs,
14265 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14266 /* Duplicate ARM register to lanes of vector. */
14267 NEON_ENCODE (ARMREG, inst);
14268 switch (et.size)
14269 {
14270 case 8: inst.instruction |= 0x400000; break;
14271 case 16: inst.instruction |= 0x000020; break;
14272 case 32: inst.instruction |= 0x000000; break;
14273 default: break;
14274 }
14275 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14276 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14277 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
14278 inst.instruction |= neon_quad (rs) << 21;
14279 /* The encoding for this instruction is identical for the ARM and Thumb
14280 variants, except for the condition field. */
14281 do_vfp_cond_or_thumb ();
14282 }
14283 }
14284
14285 /* VMOV has particularly many variations. It can be one of:
14286 0. VMOV<c><q> <Qd>, <Qm>
14287 1. VMOV<c><q> <Dd>, <Dm>
14288 (Register operations, which are VORR with Rm = Rn.)
14289 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14290 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14291 (Immediate loads.)
14292 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14293 (ARM register to scalar.)
14294 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14295 (Two ARM registers to vector.)
14296 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14297 (Scalar to ARM register.)
14298 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14299 (Vector to two ARM registers.)
14300 8. VMOV.F32 <Sd>, <Sm>
14301 9. VMOV.F64 <Dd>, <Dm>
14302 (VFP register moves.)
14303 10. VMOV.F32 <Sd>, #imm
14304 11. VMOV.F64 <Dd>, #imm
14305 (VFP float immediate load.)
14306 12. VMOV <Rd>, <Sm>
14307 (VFP single to ARM reg.)
14308 13. VMOV <Sd>, <Rm>
14309 (ARM reg to VFP single.)
14310 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14311 (Two ARM regs to two VFP singles.)
14312 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14313 (Two VFP singles to two ARM regs.)
14314
14315 These cases can be disambiguated using neon_select_shape, except cases 1/9
14316 and 3/11 which depend on the operand type too.
14317
14318 All the encoded bits are hardcoded by this function.
14319
14320 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14321 Cases 5, 7 may be used with VFPv2 and above.
14322
14323 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
14324 can specify a type where it doesn't make sense to, and is ignored). */
14325
14326 static void
14327 do_neon_mov (void)
14328 {
14329 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14330 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14331 NS_NULL);
14332 struct neon_type_el et;
14333 const char *ldconst = 0;
14334
14335 switch (rs)
14336 {
14337 case NS_DD: /* case 1/9. */
14338 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14339 /* It is not an error here if no type is given. */
14340 inst.error = NULL;
14341 if (et.type == NT_float && et.size == 64)
14342 {
14343 do_vfp_nsyn_opcode ("fcpyd");
14344 break;
14345 }
14346 /* fall through. */
14347
14348 case NS_QQ: /* case 0/1. */
14349 {
14350 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14351 return;
14352 /* The architecture manual I have doesn't explicitly state which
14353 value the U bit should have for register->register moves, but
14354 the equivalent VORR instruction has U = 0, so do that. */
14355 inst.instruction = 0x0200110;
14356 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14357 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14358 inst.instruction |= LOW4 (inst.operands[1].reg);
14359 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14360 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14361 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14362 inst.instruction |= neon_quad (rs) << 6;
14363
14364 neon_dp_fixup (&inst);
14365 }
14366 break;
14367
14368 case NS_DI: /* case 3/11. */
14369 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14370 inst.error = NULL;
14371 if (et.type == NT_float && et.size == 64)
14372 {
14373 /* case 11 (fconstd). */
14374 ldconst = "fconstd";
14375 goto encode_fconstd;
14376 }
14377 /* fall through. */
14378
14379 case NS_QI: /* case 2/3. */
14380 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14381 return;
14382 inst.instruction = 0x0800010;
14383 neon_move_immediate ();
14384 neon_dp_fixup (&inst);
14385 break;
14386
14387 case NS_SR: /* case 4. */
14388 {
14389 unsigned bcdebits = 0;
14390 int logsize;
14391 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14392 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14393
14394 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14395 logsize = neon_logbits (et.size);
14396
14397 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14398 _(BAD_FPU));
14399 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14400 && et.size != 32, _(BAD_FPU));
14401 constraint (et.type == NT_invtype, _("bad type for scalar"));
14402 constraint (x >= 64 / et.size, _("scalar index out of range"));
14403
14404 switch (et.size)
14405 {
14406 case 8: bcdebits = 0x8; break;
14407 case 16: bcdebits = 0x1; break;
14408 case 32: bcdebits = 0x0; break;
14409 default: ;
14410 }
14411
14412 bcdebits |= x << logsize;
14413
14414 inst.instruction = 0xe000b10;
14415 do_vfp_cond_or_thumb ();
14416 inst.instruction |= LOW4 (dn) << 16;
14417 inst.instruction |= HI1 (dn) << 7;
14418 inst.instruction |= inst.operands[1].reg << 12;
14419 inst.instruction |= (bcdebits & 3) << 5;
14420 inst.instruction |= (bcdebits >> 2) << 21;
14421 }
14422 break;
14423
14424 case NS_DRR: /* case 5 (fmdrr). */
14425 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14426 _(BAD_FPU));
14427
14428 inst.instruction = 0xc400b10;
14429 do_vfp_cond_or_thumb ();
14430 inst.instruction |= LOW4 (inst.operands[0].reg);
14431 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14432 inst.instruction |= inst.operands[1].reg << 12;
14433 inst.instruction |= inst.operands[2].reg << 16;
14434 break;
14435
14436 case NS_RS: /* case 6. */
14437 {
14438 unsigned logsize;
14439 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14440 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14441 unsigned abcdebits = 0;
14442
14443 et = neon_check_type (2, NS_NULL,
14444 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14445 logsize = neon_logbits (et.size);
14446
14447 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14448 _(BAD_FPU));
14449 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14450 && et.size != 32, _(BAD_FPU));
14451 constraint (et.type == NT_invtype, _("bad type for scalar"));
14452 constraint (x >= 64 / et.size, _("scalar index out of range"));
14453
14454 switch (et.size)
14455 {
14456 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14457 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14458 case 32: abcdebits = 0x00; break;
14459 default: ;
14460 }
14461
14462 abcdebits |= x << logsize;
14463 inst.instruction = 0xe100b10;
14464 do_vfp_cond_or_thumb ();
14465 inst.instruction |= LOW4 (dn) << 16;
14466 inst.instruction |= HI1 (dn) << 7;
14467 inst.instruction |= inst.operands[0].reg << 12;
14468 inst.instruction |= (abcdebits & 3) << 5;
14469 inst.instruction |= (abcdebits >> 2) << 21;
14470 }
14471 break;
14472
14473 case NS_RRD: /* case 7 (fmrrd). */
14474 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14475 _(BAD_FPU));
14476
14477 inst.instruction = 0xc500b10;
14478 do_vfp_cond_or_thumb ();
14479 inst.instruction |= inst.operands[0].reg << 12;
14480 inst.instruction |= inst.operands[1].reg << 16;
14481 inst.instruction |= LOW4 (inst.operands[2].reg);
14482 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14483 break;
14484
14485 case NS_FF: /* case 8 (fcpys). */
14486 do_vfp_nsyn_opcode ("fcpys");
14487 break;
14488
14489 case NS_FI: /* case 10 (fconsts). */
14490 ldconst = "fconsts";
14491 encode_fconstd:
14492 if (is_quarter_float (inst.operands[1].imm))
14493 {
14494 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14495 do_vfp_nsyn_opcode (ldconst);
14496 }
14497 else
14498 first_error (_("immediate out of range"));
14499 break;
14500
14501 case NS_RF: /* case 12 (fmrs). */
14502 do_vfp_nsyn_opcode ("fmrs");
14503 break;
14504
14505 case NS_FR: /* case 13 (fmsr). */
14506 do_vfp_nsyn_opcode ("fmsr");
14507 break;
14508
14509 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14510 (one of which is a list), but we have parsed four. Do some fiddling to
14511 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14512 expect. */
14513 case NS_RRFF: /* case 14 (fmrrs). */
14514 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14515 _("VFP registers must be adjacent"));
14516 inst.operands[2].imm = 2;
14517 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14518 do_vfp_nsyn_opcode ("fmrrs");
14519 break;
14520
14521 case NS_FFRR: /* case 15 (fmsrr). */
14522 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14523 _("VFP registers must be adjacent"));
14524 inst.operands[1] = inst.operands[2];
14525 inst.operands[2] = inst.operands[3];
14526 inst.operands[0].imm = 2;
14527 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14528 do_vfp_nsyn_opcode ("fmsrr");
14529 break;
14530
14531 default:
14532 abort ();
14533 }
14534 }
14535
14536 static void
14537 do_neon_rshift_round_imm (void)
14538 {
14539 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14540 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14541 int imm = inst.operands[2].imm;
14542
14543 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14544 if (imm == 0)
14545 {
14546 inst.operands[2].present = 0;
14547 do_neon_mov ();
14548 return;
14549 }
14550
14551 constraint (imm < 1 || (unsigned)imm > et.size,
14552 _("immediate out of range for shift"));
14553 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
14554 et.size - imm);
14555 }
14556
14557 static void
14558 do_neon_movl (void)
14559 {
14560 struct neon_type_el et = neon_check_type (2, NS_QD,
14561 N_EQK | N_DBL, N_SU_32 | N_KEY);
14562 unsigned sizebits = et.size >> 3;
14563 inst.instruction |= sizebits << 19;
14564 neon_two_same (0, et.type == NT_unsigned, -1);
14565 }
14566
14567 static void
14568 do_neon_trn (void)
14569 {
14570 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14571 struct neon_type_el et = neon_check_type (2, rs,
14572 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14573 NEON_ENCODE (INTEGER, inst);
14574 neon_two_same (neon_quad (rs), 1, et.size);
14575 }
14576
14577 static void
14578 do_neon_zip_uzp (void)
14579 {
14580 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14581 struct neon_type_el et = neon_check_type (2, rs,
14582 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14583 if (rs == NS_DD && et.size == 32)
14584 {
14585 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14586 inst.instruction = N_MNEM_vtrn;
14587 do_neon_trn ();
14588 return;
14589 }
14590 neon_two_same (neon_quad (rs), 1, et.size);
14591 }
14592
14593 static void
14594 do_neon_sat_abs_neg (void)
14595 {
14596 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14597 struct neon_type_el et = neon_check_type (2, rs,
14598 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14599 neon_two_same (neon_quad (rs), 1, et.size);
14600 }
14601
14602 static void
14603 do_neon_pair_long (void)
14604 {
14605 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14606 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14607 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14608 inst.instruction |= (et.type == NT_unsigned) << 7;
14609 neon_two_same (neon_quad (rs), 1, et.size);
14610 }
14611
14612 static void
14613 do_neon_recip_est (void)
14614 {
14615 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14616 struct neon_type_el et = neon_check_type (2, rs,
14617 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14618 inst.instruction |= (et.type == NT_float) << 8;
14619 neon_two_same (neon_quad (rs), 1, et.size);
14620 }
14621
14622 static void
14623 do_neon_cls (void)
14624 {
14625 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14626 struct neon_type_el et = neon_check_type (2, rs,
14627 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14628 neon_two_same (neon_quad (rs), 1, et.size);
14629 }
14630
14631 static void
14632 do_neon_clz (void)
14633 {
14634 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14635 struct neon_type_el et = neon_check_type (2, rs,
14636 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
14637 neon_two_same (neon_quad (rs), 1, et.size);
14638 }
14639
14640 static void
14641 do_neon_cnt (void)
14642 {
14643 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14644 struct neon_type_el et = neon_check_type (2, rs,
14645 N_EQK | N_INT, N_8 | N_KEY);
14646 neon_two_same (neon_quad (rs), 1, et.size);
14647 }
14648
14649 static void
14650 do_neon_swp (void)
14651 {
14652 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14653 neon_two_same (neon_quad (rs), 1, -1);
14654 }
14655
14656 static void
14657 do_neon_tbl_tbx (void)
14658 {
14659 unsigned listlenbits;
14660 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
14661
14662 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14663 {
14664 first_error (_("bad list length for table lookup"));
14665 return;
14666 }
14667
14668 listlenbits = inst.operands[1].imm - 1;
14669 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14670 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14671 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14672 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14673 inst.instruction |= LOW4 (inst.operands[2].reg);
14674 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14675 inst.instruction |= listlenbits << 8;
14676
14677 neon_dp_fixup (&inst);
14678 }
14679
14680 static void
14681 do_neon_ldm_stm (void)
14682 {
14683 /* P, U and L bits are part of bitmask. */
14684 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14685 unsigned offsetbits = inst.operands[1].imm * 2;
14686
14687 if (inst.operands[1].issingle)
14688 {
14689 do_vfp_nsyn_ldm_stm (is_dbmode);
14690 return;
14691 }
14692
14693 constraint (is_dbmode && !inst.operands[0].writeback,
14694 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14695
14696 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14697 _("register list must contain at least 1 and at most 16 "
14698 "registers"));
14699
14700 inst.instruction |= inst.operands[0].reg << 16;
14701 inst.instruction |= inst.operands[0].writeback << 21;
14702 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14703 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14704
14705 inst.instruction |= offsetbits;
14706
14707 do_vfp_cond_or_thumb ();
14708 }
14709
14710 static void
14711 do_neon_ldr_str (void)
14712 {
14713 int is_ldr = (inst.instruction & (1 << 20)) != 0;
14714
14715 if (inst.operands[0].issingle)
14716 {
14717 if (is_ldr)
14718 do_vfp_nsyn_opcode ("flds");
14719 else
14720 do_vfp_nsyn_opcode ("fsts");
14721 }
14722 else
14723 {
14724 if (is_ldr)
14725 do_vfp_nsyn_opcode ("fldd");
14726 else
14727 do_vfp_nsyn_opcode ("fstd");
14728 }
14729 }
14730
14731 /* "interleave" version also handles non-interleaving register VLD1/VST1
14732 instructions. */
14733
14734 static void
14735 do_neon_ld_st_interleave (void)
14736 {
14737 struct neon_type_el et = neon_check_type (1, NS_NULL,
14738 N_8 | N_16 | N_32 | N_64);
14739 unsigned alignbits = 0;
14740 unsigned idx;
14741 /* The bits in this table go:
14742 0: register stride of one (0) or two (1)
14743 1,2: register list length, minus one (1, 2, 3, 4).
14744 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14745 We use -1 for invalid entries. */
14746 const int typetable[] =
14747 {
14748 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14749 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14750 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14751 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14752 };
14753 int typebits;
14754
14755 if (et.type == NT_invtype)
14756 return;
14757
14758 if (inst.operands[1].immisalign)
14759 switch (inst.operands[1].imm >> 8)
14760 {
14761 case 64: alignbits = 1; break;
14762 case 128:
14763 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14764 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
14765 goto bad_alignment;
14766 alignbits = 2;
14767 break;
14768 case 256:
14769 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
14770 goto bad_alignment;
14771 alignbits = 3;
14772 break;
14773 default:
14774 bad_alignment:
14775 first_error (_("bad alignment"));
14776 return;
14777 }
14778
14779 inst.instruction |= alignbits << 4;
14780 inst.instruction |= neon_logbits (et.size) << 6;
14781
14782 /* Bits [4:6] of the immediate in a list specifier encode register stride
14783 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14784 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14785 up the right value for "type" in a table based on this value and the given
14786 list style, then stick it back. */
14787 idx = ((inst.operands[0].imm >> 4) & 7)
14788 | (((inst.instruction >> 8) & 3) << 3);
14789
14790 typebits = typetable[idx];
14791
14792 constraint (typebits == -1, _("bad list type for instruction"));
14793
14794 inst.instruction &= ~0xf00;
14795 inst.instruction |= typebits << 8;
14796 }
14797
14798 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14799 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14800 otherwise. The variable arguments are a list of pairs of legal (size, align)
14801 values, terminated with -1. */
14802
14803 static int
14804 neon_alignment_bit (int size, int align, int *do_align, ...)
14805 {
14806 va_list ap;
14807 int result = FAIL, thissize, thisalign;
14808
14809 if (!inst.operands[1].immisalign)
14810 {
14811 *do_align = 0;
14812 return SUCCESS;
14813 }
14814
14815 va_start (ap, do_align);
14816
14817 do
14818 {
14819 thissize = va_arg (ap, int);
14820 if (thissize == -1)
14821 break;
14822 thisalign = va_arg (ap, int);
14823
14824 if (size == thissize && align == thisalign)
14825 result = SUCCESS;
14826 }
14827 while (result != SUCCESS);
14828
14829 va_end (ap);
14830
14831 if (result == SUCCESS)
14832 *do_align = 1;
14833 else
14834 first_error (_("unsupported alignment for instruction"));
14835
14836 return result;
14837 }
14838
14839 static void
14840 do_neon_ld_st_lane (void)
14841 {
14842 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14843 int align_good, do_align = 0;
14844 int logsize = neon_logbits (et.size);
14845 int align = inst.operands[1].imm >> 8;
14846 int n = (inst.instruction >> 8) & 3;
14847 int max_el = 64 / et.size;
14848
14849 if (et.type == NT_invtype)
14850 return;
14851
14852 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14853 _("bad list length"));
14854 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14855 _("scalar index out of range"));
14856 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14857 && et.size == 8,
14858 _("stride of 2 unavailable when element size is 8"));
14859
14860 switch (n)
14861 {
14862 case 0: /* VLD1 / VST1. */
14863 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14864 32, 32, -1);
14865 if (align_good == FAIL)
14866 return;
14867 if (do_align)
14868 {
14869 unsigned alignbits = 0;
14870 switch (et.size)
14871 {
14872 case 16: alignbits = 0x1; break;
14873 case 32: alignbits = 0x3; break;
14874 default: ;
14875 }
14876 inst.instruction |= alignbits << 4;
14877 }
14878 break;
14879
14880 case 1: /* VLD2 / VST2. */
14881 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14882 32, 64, -1);
14883 if (align_good == FAIL)
14884 return;
14885 if (do_align)
14886 inst.instruction |= 1 << 4;
14887 break;
14888
14889 case 2: /* VLD3 / VST3. */
14890 constraint (inst.operands[1].immisalign,
14891 _("can't use alignment with this instruction"));
14892 break;
14893
14894 case 3: /* VLD4 / VST4. */
14895 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14896 16, 64, 32, 64, 32, 128, -1);
14897 if (align_good == FAIL)
14898 return;
14899 if (do_align)
14900 {
14901 unsigned alignbits = 0;
14902 switch (et.size)
14903 {
14904 case 8: alignbits = 0x1; break;
14905 case 16: alignbits = 0x1; break;
14906 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14907 default: ;
14908 }
14909 inst.instruction |= alignbits << 4;
14910 }
14911 break;
14912
14913 default: ;
14914 }
14915
14916 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14917 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14918 inst.instruction |= 1 << (4 + logsize);
14919
14920 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14921 inst.instruction |= logsize << 10;
14922 }
14923
14924 /* Encode single n-element structure to all lanes VLD<n> instructions. */
14925
14926 static void
14927 do_neon_ld_dup (void)
14928 {
14929 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14930 int align_good, do_align = 0;
14931
14932 if (et.type == NT_invtype)
14933 return;
14934
14935 switch ((inst.instruction >> 8) & 3)
14936 {
14937 case 0: /* VLD1. */
14938 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
14939 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14940 &do_align, 16, 16, 32, 32, -1);
14941 if (align_good == FAIL)
14942 return;
14943 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14944 {
14945 case 1: break;
14946 case 2: inst.instruction |= 1 << 5; break;
14947 default: first_error (_("bad list length")); return;
14948 }
14949 inst.instruction |= neon_logbits (et.size) << 6;
14950 break;
14951
14952 case 1: /* VLD2. */
14953 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14954 &do_align, 8, 16, 16, 32, 32, 64, -1);
14955 if (align_good == FAIL)
14956 return;
14957 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14958 _("bad list length"));
14959 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14960 inst.instruction |= 1 << 5;
14961 inst.instruction |= neon_logbits (et.size) << 6;
14962 break;
14963
14964 case 2: /* VLD3. */
14965 constraint (inst.operands[1].immisalign,
14966 _("can't use alignment with this instruction"));
14967 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14968 _("bad list length"));
14969 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14970 inst.instruction |= 1 << 5;
14971 inst.instruction |= neon_logbits (et.size) << 6;
14972 break;
14973
14974 case 3: /* VLD4. */
14975 {
14976 int align = inst.operands[1].imm >> 8;
14977 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14978 16, 64, 32, 64, 32, 128, -1);
14979 if (align_good == FAIL)
14980 return;
14981 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14982 _("bad list length"));
14983 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14984 inst.instruction |= 1 << 5;
14985 if (et.size == 32 && align == 128)
14986 inst.instruction |= 0x3 << 6;
14987 else
14988 inst.instruction |= neon_logbits (et.size) << 6;
14989 }
14990 break;
14991
14992 default: ;
14993 }
14994
14995 inst.instruction |= do_align << 4;
14996 }
14997
14998 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14999 apart from bits [11:4]. */
15000
15001 static void
15002 do_neon_ldx_stx (void)
15003 {
15004 if (inst.operands[1].isreg)
15005 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
15006
15007 switch (NEON_LANE (inst.operands[0].imm))
15008 {
15009 case NEON_INTERLEAVE_LANES:
15010 NEON_ENCODE (INTERLV, inst);
15011 do_neon_ld_st_interleave ();
15012 break;
15013
15014 case NEON_ALL_LANES:
15015 NEON_ENCODE (DUP, inst);
15016 do_neon_ld_dup ();
15017 break;
15018
15019 default:
15020 NEON_ENCODE (LANE, inst);
15021 do_neon_ld_st_lane ();
15022 }
15023
15024 /* L bit comes from bit mask. */
15025 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
15026 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
15027 inst.instruction |= inst.operands[1].reg << 16;
15028
15029 if (inst.operands[1].postind)
15030 {
15031 int postreg = inst.operands[1].imm & 0xf;
15032 constraint (!inst.operands[1].immisreg,
15033 _("post-index must be a register"));
15034 constraint (postreg == 0xd || postreg == 0xf,
15035 _("bad register for post-index"));
15036 inst.instruction |= postreg;
15037 }
15038 else if (inst.operands[1].writeback)
15039 {
15040 inst.instruction |= 0xd;
15041 }
15042 else
15043 inst.instruction |= 0xf;
15044
15045 if (thumb_mode)
15046 inst.instruction |= 0xf9000000;
15047 else
15048 inst.instruction |= 0xf4000000;
15049 }
15050 \f
15051 /* Overall per-instruction processing. */
15052
15053 /* We need to be able to fix up arbitrary expressions in some statements.
15054 This is so that we can handle symbols that are an arbitrary distance from
15055 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
15056 which returns part of an address in a form which will be valid for
15057 a data instruction. We do this by pushing the expression into a symbol
15058 in the expr_section, and creating a fix for that. */
15059
15060 static void
15061 fix_new_arm (fragS * frag,
15062 int where,
15063 short int size,
15064 expressionS * exp,
15065 int pc_rel,
15066 int reloc)
15067 {
15068 fixS * new_fix;
15069
15070 switch (exp->X_op)
15071 {
15072 case O_constant:
15073 case O_symbol:
15074 case O_add:
15075 case O_subtract:
15076 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
15077 (enum bfd_reloc_code_real) reloc);
15078 break;
15079
15080 default:
15081 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
15082 pc_rel, (enum bfd_reloc_code_real) reloc);
15083 break;
15084 }
15085
15086 /* Mark whether the fix is to a THUMB instruction, or an ARM
15087 instruction. */
15088 new_fix->tc_fix_data = thumb_mode;
15089 }
15090
15091 /* Create a frg for an instruction requiring relaxation. */
15092 static void
15093 output_relax_insn (void)
15094 {
15095 char * to;
15096 symbolS *sym;
15097 int offset;
15098
15099 /* The size of the instruction is unknown, so tie the debug info to the
15100 start of the instruction. */
15101 dwarf2_emit_insn (0);
15102
15103 switch (inst.reloc.exp.X_op)
15104 {
15105 case O_symbol:
15106 sym = inst.reloc.exp.X_add_symbol;
15107 offset = inst.reloc.exp.X_add_number;
15108 break;
15109 case O_constant:
15110 sym = NULL;
15111 offset = inst.reloc.exp.X_add_number;
15112 break;
15113 default:
15114 sym = make_expr_symbol (&inst.reloc.exp);
15115 offset = 0;
15116 break;
15117 }
15118 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15119 inst.relax, sym, offset, NULL/*offset, opcode*/);
15120 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
15121 }
15122
15123 /* Write a 32-bit thumb instruction to buf. */
15124 static void
15125 put_thumb32_insn (char * buf, unsigned long insn)
15126 {
15127 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15128 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15129 }
15130
15131 static void
15132 output_inst (const char * str)
15133 {
15134 char * to = NULL;
15135
15136 if (inst.error)
15137 {
15138 as_bad ("%s -- `%s'", inst.error, str);
15139 return;
15140 }
15141 if (inst.relax)
15142 {
15143 output_relax_insn ();
15144 return;
15145 }
15146 if (inst.size == 0)
15147 return;
15148
15149 to = frag_more (inst.size);
15150 /* PR 9814: Record the thumb mode into the current frag so that we know
15151 what type of NOP padding to use, if necessary. We override any previous
15152 setting so that if the mode has changed then the NOPS that we use will
15153 match the encoding of the last instruction in the frag. */
15154 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
15155
15156 if (thumb_mode && (inst.size > THUMB_SIZE))
15157 {
15158 gas_assert (inst.size == (2 * THUMB_SIZE));
15159 put_thumb32_insn (to, inst.instruction);
15160 }
15161 else if (inst.size > INSN_SIZE)
15162 {
15163 gas_assert (inst.size == (2 * INSN_SIZE));
15164 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15165 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
15166 }
15167 else
15168 md_number_to_chars (to, inst.instruction, inst.size);
15169
15170 if (inst.reloc.type != BFD_RELOC_UNUSED)
15171 fix_new_arm (frag_now, to - frag_now->fr_literal,
15172 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15173 inst.reloc.type);
15174
15175 dwarf2_emit_insn (inst.size);
15176 }
15177
15178 static char *
15179 output_it_inst (int cond, int mask, char * to)
15180 {
15181 unsigned long instruction = 0xbf00;
15182
15183 mask &= 0xf;
15184 instruction |= mask;
15185 instruction |= cond << 4;
15186
15187 if (to == NULL)
15188 {
15189 to = frag_more (2);
15190 #ifdef OBJ_ELF
15191 dwarf2_emit_insn (2);
15192 #endif
15193 }
15194
15195 md_number_to_chars (to, instruction, 2);
15196
15197 return to;
15198 }
15199
15200 /* Tag values used in struct asm_opcode's tag field. */
15201 enum opcode_tag
15202 {
15203 OT_unconditional, /* Instruction cannot be conditionalized.
15204 The ARM condition field is still 0xE. */
15205 OT_unconditionalF, /* Instruction cannot be conditionalized
15206 and carries 0xF in its ARM condition field. */
15207 OT_csuffix, /* Instruction takes a conditional suffix. */
15208 OT_csuffixF, /* Some forms of the instruction take a conditional
15209 suffix, others place 0xF where the condition field
15210 would be. */
15211 OT_cinfix3, /* Instruction takes a conditional infix,
15212 beginning at character index 3. (In
15213 unified mode, it becomes a suffix.) */
15214 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15215 tsts, cmps, cmns, and teqs. */
15216 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15217 character index 3, even in unified mode. Used for
15218 legacy instructions where suffix and infix forms
15219 may be ambiguous. */
15220 OT_csuf_or_in3, /* Instruction takes either a conditional
15221 suffix or an infix at character index 3. */
15222 OT_odd_infix_unc, /* This is the unconditional variant of an
15223 instruction that takes a conditional infix
15224 at an unusual position. In unified mode,
15225 this variant will accept a suffix. */
15226 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15227 are the conditional variants of instructions that
15228 take conditional infixes in unusual positions.
15229 The infix appears at character index
15230 (tag - OT_odd_infix_0). These are not accepted
15231 in unified mode. */
15232 };
15233
15234 /* Subroutine of md_assemble, responsible for looking up the primary
15235 opcode from the mnemonic the user wrote. STR points to the
15236 beginning of the mnemonic.
15237
15238 This is not simply a hash table lookup, because of conditional
15239 variants. Most instructions have conditional variants, which are
15240 expressed with a _conditional affix_ to the mnemonic. If we were
15241 to encode each conditional variant as a literal string in the opcode
15242 table, it would have approximately 20,000 entries.
15243
15244 Most mnemonics take this affix as a suffix, and in unified syntax,
15245 'most' is upgraded to 'all'. However, in the divided syntax, some
15246 instructions take the affix as an infix, notably the s-variants of
15247 the arithmetic instructions. Of those instructions, all but six
15248 have the infix appear after the third character of the mnemonic.
15249
15250 Accordingly, the algorithm for looking up primary opcodes given
15251 an identifier is:
15252
15253 1. Look up the identifier in the opcode table.
15254 If we find a match, go to step U.
15255
15256 2. Look up the last two characters of the identifier in the
15257 conditions table. If we find a match, look up the first N-2
15258 characters of the identifier in the opcode table. If we
15259 find a match, go to step CE.
15260
15261 3. Look up the fourth and fifth characters of the identifier in
15262 the conditions table. If we find a match, extract those
15263 characters from the identifier, and look up the remaining
15264 characters in the opcode table. If we find a match, go
15265 to step CM.
15266
15267 4. Fail.
15268
15269 U. Examine the tag field of the opcode structure, in case this is
15270 one of the six instructions with its conditional infix in an
15271 unusual place. If it is, the tag tells us where to find the
15272 infix; look it up in the conditions table and set inst.cond
15273 accordingly. Otherwise, this is an unconditional instruction.
15274 Again set inst.cond accordingly. Return the opcode structure.
15275
15276 CE. Examine the tag field to make sure this is an instruction that
15277 should receive a conditional suffix. If it is not, fail.
15278 Otherwise, set inst.cond from the suffix we already looked up,
15279 and return the opcode structure.
15280
15281 CM. Examine the tag field to make sure this is an instruction that
15282 should receive a conditional infix after the third character.
15283 If it is not, fail. Otherwise, undo the edits to the current
15284 line of input and proceed as for case CE. */
15285
15286 static const struct asm_opcode *
15287 opcode_lookup (char **str)
15288 {
15289 char *end, *base;
15290 char *affix;
15291 const struct asm_opcode *opcode;
15292 const struct asm_cond *cond;
15293 char save[2];
15294
15295 /* Scan up to the end of the mnemonic, which must end in white space,
15296 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
15297 for (base = end = *str; *end != '\0'; end++)
15298 if (*end == ' ' || *end == '.')
15299 break;
15300
15301 if (end == base)
15302 return NULL;
15303
15304 /* Handle a possible width suffix and/or Neon type suffix. */
15305 if (end[0] == '.')
15306 {
15307 int offset = 2;
15308
15309 /* The .w and .n suffixes are only valid if the unified syntax is in
15310 use. */
15311 if (unified_syntax && end[1] == 'w')
15312 inst.size_req = 4;
15313 else if (unified_syntax && end[1] == 'n')
15314 inst.size_req = 2;
15315 else
15316 offset = 0;
15317
15318 inst.vectype.elems = 0;
15319
15320 *str = end + offset;
15321
15322 if (end[offset] == '.')
15323 {
15324 /* See if we have a Neon type suffix (possible in either unified or
15325 non-unified ARM syntax mode). */
15326 if (parse_neon_type (&inst.vectype, str) == FAIL)
15327 return NULL;
15328 }
15329 else if (end[offset] != '\0' && end[offset] != ' ')
15330 return NULL;
15331 }
15332 else
15333 *str = end;
15334
15335 /* Look for unaffixed or special-case affixed mnemonic. */
15336 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15337 end - base);
15338 if (opcode)
15339 {
15340 /* step U */
15341 if (opcode->tag < OT_odd_infix_0)
15342 {
15343 inst.cond = COND_ALWAYS;
15344 return opcode;
15345 }
15346
15347 if (warn_on_deprecated && unified_syntax)
15348 as_warn (_("conditional infixes are deprecated in unified syntax"));
15349 affix = base + (opcode->tag - OT_odd_infix_0);
15350 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15351 gas_assert (cond);
15352
15353 inst.cond = cond->value;
15354 return opcode;
15355 }
15356
15357 /* Cannot have a conditional suffix on a mnemonic of less than two
15358 characters. */
15359 if (end - base < 3)
15360 return NULL;
15361
15362 /* Look for suffixed mnemonic. */
15363 affix = end - 2;
15364 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15365 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15366 affix - base);
15367 if (opcode && cond)
15368 {
15369 /* step CE */
15370 switch (opcode->tag)
15371 {
15372 case OT_cinfix3_legacy:
15373 /* Ignore conditional suffixes matched on infix only mnemonics. */
15374 break;
15375
15376 case OT_cinfix3:
15377 case OT_cinfix3_deprecated:
15378 case OT_odd_infix_unc:
15379 if (!unified_syntax)
15380 return 0;
15381 /* else fall through */
15382
15383 case OT_csuffix:
15384 case OT_csuffixF:
15385 case OT_csuf_or_in3:
15386 inst.cond = cond->value;
15387 return opcode;
15388
15389 case OT_unconditional:
15390 case OT_unconditionalF:
15391 if (thumb_mode)
15392 inst.cond = cond->value;
15393 else
15394 {
15395 /* Delayed diagnostic. */
15396 inst.error = BAD_COND;
15397 inst.cond = COND_ALWAYS;
15398 }
15399 return opcode;
15400
15401 default:
15402 return NULL;
15403 }
15404 }
15405
15406 /* Cannot have a usual-position infix on a mnemonic of less than
15407 six characters (five would be a suffix). */
15408 if (end - base < 6)
15409 return NULL;
15410
15411 /* Look for infixed mnemonic in the usual position. */
15412 affix = base + 3;
15413 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15414 if (!cond)
15415 return NULL;
15416
15417 memcpy (save, affix, 2);
15418 memmove (affix, affix + 2, (end - affix) - 2);
15419 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15420 (end - base) - 2);
15421 memmove (affix + 2, affix, (end - affix) - 2);
15422 memcpy (affix, save, 2);
15423
15424 if (opcode
15425 && (opcode->tag == OT_cinfix3
15426 || opcode->tag == OT_cinfix3_deprecated
15427 || opcode->tag == OT_csuf_or_in3
15428 || opcode->tag == OT_cinfix3_legacy))
15429 {
15430 /* Step CM. */
15431 if (warn_on_deprecated && unified_syntax
15432 && (opcode->tag == OT_cinfix3
15433 || opcode->tag == OT_cinfix3_deprecated))
15434 as_warn (_("conditional infixes are deprecated in unified syntax"));
15435
15436 inst.cond = cond->value;
15437 return opcode;
15438 }
15439
15440 return NULL;
15441 }
15442
15443 /* This function generates an initial IT instruction, leaving its block
15444 virtually open for the new instructions. Eventually,
15445 the mask will be updated by now_it_add_mask () each time
15446 a new instruction needs to be included in the IT block.
15447 Finally, the block is closed with close_automatic_it_block ().
15448 The block closure can be requested either from md_assemble (),
15449 a tencode (), or due to a label hook. */
15450
15451 static void
15452 new_automatic_it_block (int cond)
15453 {
15454 now_it.state = AUTOMATIC_IT_BLOCK;
15455 now_it.mask = 0x18;
15456 now_it.cc = cond;
15457 now_it.block_length = 1;
15458 mapping_state (MAP_THUMB);
15459 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15460 }
15461
15462 /* Close an automatic IT block.
15463 See comments in new_automatic_it_block (). */
15464
15465 static void
15466 close_automatic_it_block (void)
15467 {
15468 now_it.mask = 0x10;
15469 now_it.block_length = 0;
15470 }
15471
15472 /* Update the mask of the current automatically-generated IT
15473 instruction. See comments in new_automatic_it_block (). */
15474
15475 static void
15476 now_it_add_mask (int cond)
15477 {
15478 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15479 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15480 | ((bitvalue) << (nbit)))
15481 const int resulting_bit = (cond & 1);
15482
15483 now_it.mask &= 0xf;
15484 now_it.mask = SET_BIT_VALUE (now_it.mask,
15485 resulting_bit,
15486 (5 - now_it.block_length));
15487 now_it.mask = SET_BIT_VALUE (now_it.mask,
15488 1,
15489 ((5 - now_it.block_length) - 1) );
15490 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15491
15492 #undef CLEAR_BIT
15493 #undef SET_BIT_VALUE
15494 }
15495
15496 /* The IT blocks handling machinery is accessed through the these functions:
15497 it_fsm_pre_encode () from md_assemble ()
15498 set_it_insn_type () optional, from the tencode functions
15499 set_it_insn_type_last () ditto
15500 in_it_block () ditto
15501 it_fsm_post_encode () from md_assemble ()
15502 force_automatic_it_block_close () from label habdling functions
15503
15504 Rationale:
15505 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15506 initializing the IT insn type with a generic initial value depending
15507 on the inst.condition.
15508 2) During the tencode function, two things may happen:
15509 a) The tencode function overrides the IT insn type by
15510 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15511 b) The tencode function queries the IT block state by
15512 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15513
15514 Both set_it_insn_type and in_it_block run the internal FSM state
15515 handling function (handle_it_state), because: a) setting the IT insn
15516 type may incur in an invalid state (exiting the function),
15517 and b) querying the state requires the FSM to be updated.
15518 Specifically we want to avoid creating an IT block for conditional
15519 branches, so it_fsm_pre_encode is actually a guess and we can't
15520 determine whether an IT block is required until the tencode () routine
15521 has decided what type of instruction this actually it.
15522 Because of this, if set_it_insn_type and in_it_block have to be used,
15523 set_it_insn_type has to be called first.
15524
15525 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15526 determines the insn IT type depending on the inst.cond code.
15527 When a tencode () routine encodes an instruction that can be
15528 either outside an IT block, or, in the case of being inside, has to be
15529 the last one, set_it_insn_type_last () will determine the proper
15530 IT instruction type based on the inst.cond code. Otherwise,
15531 set_it_insn_type can be called for overriding that logic or
15532 for covering other cases.
15533
15534 Calling handle_it_state () may not transition the IT block state to
15535 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15536 still queried. Instead, if the FSM determines that the state should
15537 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15538 after the tencode () function: that's what it_fsm_post_encode () does.
15539
15540 Since in_it_block () calls the state handling function to get an
15541 updated state, an error may occur (due to invalid insns combination).
15542 In that case, inst.error is set.
15543 Therefore, inst.error has to be checked after the execution of
15544 the tencode () routine.
15545
15546 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15547 any pending state change (if any) that didn't take place in
15548 handle_it_state () as explained above. */
15549
15550 static void
15551 it_fsm_pre_encode (void)
15552 {
15553 if (inst.cond != COND_ALWAYS)
15554 inst.it_insn_type = INSIDE_IT_INSN;
15555 else
15556 inst.it_insn_type = OUTSIDE_IT_INSN;
15557
15558 now_it.state_handled = 0;
15559 }
15560
15561 /* IT state FSM handling function. */
15562
15563 static int
15564 handle_it_state (void)
15565 {
15566 now_it.state_handled = 1;
15567
15568 switch (now_it.state)
15569 {
15570 case OUTSIDE_IT_BLOCK:
15571 switch (inst.it_insn_type)
15572 {
15573 case OUTSIDE_IT_INSN:
15574 break;
15575
15576 case INSIDE_IT_INSN:
15577 case INSIDE_IT_LAST_INSN:
15578 if (thumb_mode == 0)
15579 {
15580 if (unified_syntax
15581 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15582 as_tsktsk (_("Warning: conditional outside an IT block"\
15583 " for Thumb."));
15584 }
15585 else
15586 {
15587 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15588 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15589 {
15590 /* Automatically generate the IT instruction. */
15591 new_automatic_it_block (inst.cond);
15592 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15593 close_automatic_it_block ();
15594 }
15595 else
15596 {
15597 inst.error = BAD_OUT_IT;
15598 return FAIL;
15599 }
15600 }
15601 break;
15602
15603 case IF_INSIDE_IT_LAST_INSN:
15604 case NEUTRAL_IT_INSN:
15605 break;
15606
15607 case IT_INSN:
15608 now_it.state = MANUAL_IT_BLOCK;
15609 now_it.block_length = 0;
15610 break;
15611 }
15612 break;
15613
15614 case AUTOMATIC_IT_BLOCK:
15615 /* Three things may happen now:
15616 a) We should increment current it block size;
15617 b) We should close current it block (closing insn or 4 insns);
15618 c) We should close current it block and start a new one (due
15619 to incompatible conditions or
15620 4 insns-length block reached). */
15621
15622 switch (inst.it_insn_type)
15623 {
15624 case OUTSIDE_IT_INSN:
15625 /* The closure of the block shall happen immediatelly,
15626 so any in_it_block () call reports the block as closed. */
15627 force_automatic_it_block_close ();
15628 break;
15629
15630 case INSIDE_IT_INSN:
15631 case INSIDE_IT_LAST_INSN:
15632 case IF_INSIDE_IT_LAST_INSN:
15633 now_it.block_length++;
15634
15635 if (now_it.block_length > 4
15636 || !now_it_compatible (inst.cond))
15637 {
15638 force_automatic_it_block_close ();
15639 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15640 new_automatic_it_block (inst.cond);
15641 }
15642 else
15643 {
15644 now_it_add_mask (inst.cond);
15645 }
15646
15647 if (now_it.state == AUTOMATIC_IT_BLOCK
15648 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15649 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15650 close_automatic_it_block ();
15651 break;
15652
15653 case NEUTRAL_IT_INSN:
15654 now_it.block_length++;
15655
15656 if (now_it.block_length > 4)
15657 force_automatic_it_block_close ();
15658 else
15659 now_it_add_mask (now_it.cc & 1);
15660 break;
15661
15662 case IT_INSN:
15663 close_automatic_it_block ();
15664 now_it.state = MANUAL_IT_BLOCK;
15665 break;
15666 }
15667 break;
15668
15669 case MANUAL_IT_BLOCK:
15670 {
15671 /* Check conditional suffixes. */
15672 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15673 int is_last;
15674 now_it.mask <<= 1;
15675 now_it.mask &= 0x1f;
15676 is_last = (now_it.mask == 0x10);
15677
15678 switch (inst.it_insn_type)
15679 {
15680 case OUTSIDE_IT_INSN:
15681 inst.error = BAD_NOT_IT;
15682 return FAIL;
15683
15684 case INSIDE_IT_INSN:
15685 if (cond != inst.cond)
15686 {
15687 inst.error = BAD_IT_COND;
15688 return FAIL;
15689 }
15690 break;
15691
15692 case INSIDE_IT_LAST_INSN:
15693 case IF_INSIDE_IT_LAST_INSN:
15694 if (cond != inst.cond)
15695 {
15696 inst.error = BAD_IT_COND;
15697 return FAIL;
15698 }
15699 if (!is_last)
15700 {
15701 inst.error = BAD_BRANCH;
15702 return FAIL;
15703 }
15704 break;
15705
15706 case NEUTRAL_IT_INSN:
15707 /* The BKPT instruction is unconditional even in an IT block. */
15708 break;
15709
15710 case IT_INSN:
15711 inst.error = BAD_IT_IT;
15712 return FAIL;
15713 }
15714 }
15715 break;
15716 }
15717
15718 return SUCCESS;
15719 }
15720
15721 static void
15722 it_fsm_post_encode (void)
15723 {
15724 int is_last;
15725
15726 if (!now_it.state_handled)
15727 handle_it_state ();
15728
15729 is_last = (now_it.mask == 0x10);
15730 if (is_last)
15731 {
15732 now_it.state = OUTSIDE_IT_BLOCK;
15733 now_it.mask = 0;
15734 }
15735 }
15736
15737 static void
15738 force_automatic_it_block_close (void)
15739 {
15740 if (now_it.state == AUTOMATIC_IT_BLOCK)
15741 {
15742 close_automatic_it_block ();
15743 now_it.state = OUTSIDE_IT_BLOCK;
15744 now_it.mask = 0;
15745 }
15746 }
15747
15748 static int
15749 in_it_block (void)
15750 {
15751 if (!now_it.state_handled)
15752 handle_it_state ();
15753
15754 return now_it.state != OUTSIDE_IT_BLOCK;
15755 }
15756
15757 void
15758 md_assemble (char *str)
15759 {
15760 char *p = str;
15761 const struct asm_opcode * opcode;
15762
15763 /* Align the previous label if needed. */
15764 if (last_label_seen != NULL)
15765 {
15766 symbol_set_frag (last_label_seen, frag_now);
15767 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15768 S_SET_SEGMENT (last_label_seen, now_seg);
15769 }
15770
15771 memset (&inst, '\0', sizeof (inst));
15772 inst.reloc.type = BFD_RELOC_UNUSED;
15773
15774 opcode = opcode_lookup (&p);
15775 if (!opcode)
15776 {
15777 /* It wasn't an instruction, but it might be a register alias of
15778 the form alias .req reg, or a Neon .dn/.qn directive. */
15779 if (! create_register_alias (str, p)
15780 && ! create_neon_reg_alias (str, p))
15781 as_bad (_("bad instruction `%s'"), str);
15782
15783 return;
15784 }
15785
15786 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
15787 as_warn (_("s suffix on comparison instruction is deprecated"));
15788
15789 /* The value which unconditional instructions should have in place of the
15790 condition field. */
15791 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15792
15793 if (thumb_mode)
15794 {
15795 arm_feature_set variant;
15796
15797 variant = cpu_variant;
15798 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
15799 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15800 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
15801 /* Check that this instruction is supported for this CPU. */
15802 if (!opcode->tvariant
15803 || (thumb_mode == 1
15804 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
15805 {
15806 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
15807 return;
15808 }
15809 if (inst.cond != COND_ALWAYS && !unified_syntax
15810 && opcode->tencode != do_t_branch)
15811 {
15812 as_bad (_("Thumb does not support conditional execution"));
15813 return;
15814 }
15815
15816 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
15817 {
15818 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
15819 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15820 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15821 {
15822 /* Two things are addressed here.
15823 1) Implicit require narrow instructions on Thumb-1.
15824 This avoids relaxation accidentally introducing Thumb-2
15825 instructions.
15826 2) Reject wide instructions in non Thumb-2 cores. */
15827 if (inst.size_req == 0)
15828 inst.size_req = 2;
15829 else if (inst.size_req == 4)
15830 {
15831 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
15832 return;
15833 }
15834 }
15835 }
15836
15837 inst.instruction = opcode->tvalue;
15838
15839 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
15840 {
15841 /* Prepare the it_insn_type for those encodings that don't set
15842 it. */
15843 it_fsm_pre_encode ();
15844
15845 opcode->tencode ();
15846
15847 it_fsm_post_encode ();
15848 }
15849
15850 if (!(inst.error || inst.relax))
15851 {
15852 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
15853 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15854 if (inst.size_req && inst.size_req != inst.size)
15855 {
15856 as_bad (_("cannot honor width suffix -- `%s'"), str);
15857 return;
15858 }
15859 }
15860
15861 /* Something has gone badly wrong if we try to relax a fixed size
15862 instruction. */
15863 gas_assert (inst.size_req == 0 || !inst.relax);
15864
15865 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15866 *opcode->tvariant);
15867 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
15868 set those bits when Thumb-2 32-bit instructions are seen. ie.
15869 anything other than bl/blx and v6-M instructions.
15870 This is overly pessimistic for relaxable instructions. */
15871 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15872 || inst.relax)
15873 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15874 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
15875 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15876 arm_ext_v6t2);
15877
15878 check_neon_suffixes;
15879
15880 if (!inst.error)
15881 {
15882 mapping_state (MAP_THUMB);
15883 }
15884 }
15885 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
15886 {
15887 bfd_boolean is_bx;
15888
15889 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15890 is_bx = (opcode->aencode == do_bx);
15891
15892 /* Check that this instruction is supported for this CPU. */
15893 if (!(is_bx && fix_v4bx)
15894 && !(opcode->avariant &&
15895 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
15896 {
15897 as_bad (_("selected processor does not support ARM mode `%s'"), str);
15898 return;
15899 }
15900 if (inst.size_req)
15901 {
15902 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15903 return;
15904 }
15905
15906 inst.instruction = opcode->avalue;
15907 if (opcode->tag == OT_unconditionalF)
15908 inst.instruction |= 0xF << 28;
15909 else
15910 inst.instruction |= inst.cond << 28;
15911 inst.size = INSN_SIZE;
15912 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
15913 {
15914 it_fsm_pre_encode ();
15915 opcode->aencode ();
15916 it_fsm_post_encode ();
15917 }
15918 /* Arm mode bx is marked as both v4T and v5 because it's still required
15919 on a hypothetical non-thumb v5 core. */
15920 if (is_bx)
15921 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
15922 else
15923 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15924 *opcode->avariant);
15925
15926 check_neon_suffixes;
15927
15928 if (!inst.error)
15929 {
15930 mapping_state (MAP_ARM);
15931 }
15932 }
15933 else
15934 {
15935 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15936 "-- `%s'"), str);
15937 return;
15938 }
15939 output_inst (str);
15940 }
15941
15942 static void
15943 check_it_blocks_finished (void)
15944 {
15945 #ifdef OBJ_ELF
15946 asection *sect;
15947
15948 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15949 if (seg_info (sect)->tc_segment_info_data.current_it.state
15950 == MANUAL_IT_BLOCK)
15951 {
15952 as_warn (_("section '%s' finished with an open IT block."),
15953 sect->name);
15954 }
15955 #else
15956 if (now_it.state == MANUAL_IT_BLOCK)
15957 as_warn (_("file finished with an open IT block."));
15958 #endif
15959 }
15960
15961 /* Various frobbings of labels and their addresses. */
15962
15963 void
15964 arm_start_line_hook (void)
15965 {
15966 last_label_seen = NULL;
15967 }
15968
15969 void
15970 arm_frob_label (symbolS * sym)
15971 {
15972 last_label_seen = sym;
15973
15974 ARM_SET_THUMB (sym, thumb_mode);
15975
15976 #if defined OBJ_COFF || defined OBJ_ELF
15977 ARM_SET_INTERWORK (sym, support_interwork);
15978 #endif
15979
15980 force_automatic_it_block_close ();
15981
15982 /* Note - do not allow local symbols (.Lxxx) to be labelled
15983 as Thumb functions. This is because these labels, whilst
15984 they exist inside Thumb code, are not the entry points for
15985 possible ARM->Thumb calls. Also, these labels can be used
15986 as part of a computed goto or switch statement. eg gcc
15987 can generate code that looks like this:
15988
15989 ldr r2, [pc, .Laaa]
15990 lsl r3, r3, #2
15991 ldr r2, [r3, r2]
15992 mov pc, r2
15993
15994 .Lbbb: .word .Lxxx
15995 .Lccc: .word .Lyyy
15996 ..etc...
15997 .Laaa: .word Lbbb
15998
15999 The first instruction loads the address of the jump table.
16000 The second instruction converts a table index into a byte offset.
16001 The third instruction gets the jump address out of the table.
16002 The fourth instruction performs the jump.
16003
16004 If the address stored at .Laaa is that of a symbol which has the
16005 Thumb_Func bit set, then the linker will arrange for this address
16006 to have the bottom bit set, which in turn would mean that the
16007 address computation performed by the third instruction would end
16008 up with the bottom bit set. Since the ARM is capable of unaligned
16009 word loads, the instruction would then load the incorrect address
16010 out of the jump table, and chaos would ensue. */
16011 if (label_is_thumb_function_name
16012 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
16013 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
16014 {
16015 /* When the address of a Thumb function is taken the bottom
16016 bit of that address should be set. This will allow
16017 interworking between Arm and Thumb functions to work
16018 correctly. */
16019
16020 THUMB_SET_FUNC (sym, 1);
16021
16022 label_is_thumb_function_name = FALSE;
16023 }
16024
16025 dwarf2_emit_label (sym);
16026 }
16027
16028 bfd_boolean
16029 arm_data_in_code (void)
16030 {
16031 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
16032 {
16033 *input_line_pointer = '/';
16034 input_line_pointer += 5;
16035 *input_line_pointer = 0;
16036 return TRUE;
16037 }
16038
16039 return FALSE;
16040 }
16041
16042 char *
16043 arm_canonicalize_symbol_name (char * name)
16044 {
16045 int len;
16046
16047 if (thumb_mode && (len = strlen (name)) > 5
16048 && streq (name + len - 5, "/data"))
16049 *(name + len - 5) = 0;
16050
16051 return name;
16052 }
16053 \f
16054 /* Table of all register names defined by default. The user can
16055 define additional names with .req. Note that all register names
16056 should appear in both upper and lowercase variants. Some registers
16057 also have mixed-case names. */
16058
16059 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
16060 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
16061 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
16062 #define REGSET(p,t) \
16063 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
16064 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
16065 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
16066 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
16067 #define REGSETH(p,t) \
16068 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
16069 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
16070 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
16071 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
16072 #define REGSET2(p,t) \
16073 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
16074 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
16075 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
16076 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
16077
16078 static const struct reg_entry reg_names[] =
16079 {
16080 /* ARM integer registers. */
16081 REGSET(r, RN), REGSET(R, RN),
16082
16083 /* ATPCS synonyms. */
16084 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
16085 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16086 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
16087
16088 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16089 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16090 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
16091
16092 /* Well-known aliases. */
16093 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16094 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16095
16096 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16097 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16098
16099 /* Coprocessor numbers. */
16100 REGSET(p, CP), REGSET(P, CP),
16101
16102 /* Coprocessor register numbers. The "cr" variants are for backward
16103 compatibility. */
16104 REGSET(c, CN), REGSET(C, CN),
16105 REGSET(cr, CN), REGSET(CR, CN),
16106
16107 /* FPA registers. */
16108 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16109 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16110
16111 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16112 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16113
16114 /* VFP SP registers. */
16115 REGSET(s,VFS), REGSET(S,VFS),
16116 REGSETH(s,VFS), REGSETH(S,VFS),
16117
16118 /* VFP DP Registers. */
16119 REGSET(d,VFD), REGSET(D,VFD),
16120 /* Extra Neon DP registers. */
16121 REGSETH(d,VFD), REGSETH(D,VFD),
16122
16123 /* Neon QP registers. */
16124 REGSET2(q,NQ), REGSET2(Q,NQ),
16125
16126 /* VFP control registers. */
16127 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16128 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
16129 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16130 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16131 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16132 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
16133
16134 /* Maverick DSP coprocessor registers. */
16135 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16136 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16137
16138 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16139 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16140 REGDEF(dspsc,0,DSPSC),
16141
16142 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16143 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16144 REGDEF(DSPSC,0,DSPSC),
16145
16146 /* iWMMXt data registers - p0, c0-15. */
16147 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16148
16149 /* iWMMXt control registers - p1, c0-3. */
16150 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16151 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16152 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16153 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16154
16155 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16156 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16157 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16158 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16159 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16160
16161 /* XScale accumulator registers. */
16162 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16163 };
16164 #undef REGDEF
16165 #undef REGNUM
16166 #undef REGSET
16167
16168 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16169 within psr_required_here. */
16170 static const struct asm_psr psrs[] =
16171 {
16172 /* Backward compatibility notation. Note that "all" is no longer
16173 truly all possible PSR bits. */
16174 {"all", PSR_c | PSR_f},
16175 {"flg", PSR_f},
16176 {"ctl", PSR_c},
16177
16178 /* Individual flags. */
16179 {"f", PSR_f},
16180 {"c", PSR_c},
16181 {"x", PSR_x},
16182 {"s", PSR_s},
16183 /* Combinations of flags. */
16184 {"fs", PSR_f | PSR_s},
16185 {"fx", PSR_f | PSR_x},
16186 {"fc", PSR_f | PSR_c},
16187 {"sf", PSR_s | PSR_f},
16188 {"sx", PSR_s | PSR_x},
16189 {"sc", PSR_s | PSR_c},
16190 {"xf", PSR_x | PSR_f},
16191 {"xs", PSR_x | PSR_s},
16192 {"xc", PSR_x | PSR_c},
16193 {"cf", PSR_c | PSR_f},
16194 {"cs", PSR_c | PSR_s},
16195 {"cx", PSR_c | PSR_x},
16196 {"fsx", PSR_f | PSR_s | PSR_x},
16197 {"fsc", PSR_f | PSR_s | PSR_c},
16198 {"fxs", PSR_f | PSR_x | PSR_s},
16199 {"fxc", PSR_f | PSR_x | PSR_c},
16200 {"fcs", PSR_f | PSR_c | PSR_s},
16201 {"fcx", PSR_f | PSR_c | PSR_x},
16202 {"sfx", PSR_s | PSR_f | PSR_x},
16203 {"sfc", PSR_s | PSR_f | PSR_c},
16204 {"sxf", PSR_s | PSR_x | PSR_f},
16205 {"sxc", PSR_s | PSR_x | PSR_c},
16206 {"scf", PSR_s | PSR_c | PSR_f},
16207 {"scx", PSR_s | PSR_c | PSR_x},
16208 {"xfs", PSR_x | PSR_f | PSR_s},
16209 {"xfc", PSR_x | PSR_f | PSR_c},
16210 {"xsf", PSR_x | PSR_s | PSR_f},
16211 {"xsc", PSR_x | PSR_s | PSR_c},
16212 {"xcf", PSR_x | PSR_c | PSR_f},
16213 {"xcs", PSR_x | PSR_c | PSR_s},
16214 {"cfs", PSR_c | PSR_f | PSR_s},
16215 {"cfx", PSR_c | PSR_f | PSR_x},
16216 {"csf", PSR_c | PSR_s | PSR_f},
16217 {"csx", PSR_c | PSR_s | PSR_x},
16218 {"cxf", PSR_c | PSR_x | PSR_f},
16219 {"cxs", PSR_c | PSR_x | PSR_s},
16220 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16221 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16222 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16223 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16224 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16225 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16226 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16227 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16228 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16229 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16230 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16231 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16232 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16233 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16234 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16235 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16236 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16237 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16238 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16239 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16240 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16241 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16242 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16243 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16244 };
16245
16246 /* Table of V7M psr names. */
16247 static const struct asm_psr v7m_psrs[] =
16248 {
16249 {"apsr", 0 }, {"APSR", 0 },
16250 {"iapsr", 1 }, {"IAPSR", 1 },
16251 {"eapsr", 2 }, {"EAPSR", 2 },
16252 {"psr", 3 }, {"PSR", 3 },
16253 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16254 {"ipsr", 5 }, {"IPSR", 5 },
16255 {"epsr", 6 }, {"EPSR", 6 },
16256 {"iepsr", 7 }, {"IEPSR", 7 },
16257 {"msp", 8 }, {"MSP", 8 },
16258 {"psp", 9 }, {"PSP", 9 },
16259 {"primask", 16}, {"PRIMASK", 16},
16260 {"basepri", 17}, {"BASEPRI", 17},
16261 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16262 {"faultmask", 19}, {"FAULTMASK", 19},
16263 {"control", 20}, {"CONTROL", 20}
16264 };
16265
16266 /* Table of all shift-in-operand names. */
16267 static const struct asm_shift_name shift_names [] =
16268 {
16269 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16270 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16271 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16272 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16273 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16274 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16275 };
16276
16277 /* Table of all explicit relocation names. */
16278 #ifdef OBJ_ELF
16279 static struct reloc_entry reloc_names[] =
16280 {
16281 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16282 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16283 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16284 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16285 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16286 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16287 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16288 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16289 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16290 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16291 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16292 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}
16293 };
16294 #endif
16295
16296 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
16297 static const struct asm_cond conds[] =
16298 {
16299 {"eq", 0x0},
16300 {"ne", 0x1},
16301 {"cs", 0x2}, {"hs", 0x2},
16302 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16303 {"mi", 0x4},
16304 {"pl", 0x5},
16305 {"vs", 0x6},
16306 {"vc", 0x7},
16307 {"hi", 0x8},
16308 {"ls", 0x9},
16309 {"ge", 0xa},
16310 {"lt", 0xb},
16311 {"gt", 0xc},
16312 {"le", 0xd},
16313 {"al", 0xe}
16314 };
16315
16316 static struct asm_barrier_opt barrier_opt_names[] =
16317 {
16318 { "sy", 0xf }, { "SY", 0xf },
16319 { "un", 0x7 }, { "UN", 0x7 },
16320 { "st", 0xe }, { "ST", 0xe },
16321 { "unst", 0x6 }, { "UNST", 0x6 },
16322 { "ish", 0xb }, { "ISH", 0xb },
16323 { "sh", 0xb }, { "SH", 0xb },
16324 { "ishst", 0xa }, { "ISHST", 0xa },
16325 { "shst", 0xa }, { "SHST", 0xa },
16326 { "nsh", 0x7 }, { "NSH", 0x7 },
16327 { "nshst", 0x6 }, { "NSHST", 0x6 },
16328 { "osh", 0x3 }, { "OSH", 0x3 },
16329 { "oshst", 0x2 }, { "OSHST", 0x2 }
16330 };
16331
16332 /* Table of ARM-format instructions. */
16333
16334 /* Macros for gluing together operand strings. N.B. In all cases
16335 other than OPS0, the trailing OP_stop comes from default
16336 zero-initialization of the unspecified elements of the array. */
16337 #define OPS0() { OP_stop, }
16338 #define OPS1(a) { OP_##a, }
16339 #define OPS2(a,b) { OP_##a,OP_##b, }
16340 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16341 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16342 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16343 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16344
16345 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16346 This is useful when mixing operands for ARM and THUMB, i.e. using the
16347 MIX_ARM_THUMB_OPERANDS macro.
16348 In order to use these macros, prefix the number of operands with _
16349 e.g. _3. */
16350 #define OPS_1(a) { a, }
16351 #define OPS_2(a,b) { a,b, }
16352 #define OPS_3(a,b,c) { a,b,c, }
16353 #define OPS_4(a,b,c,d) { a,b,c,d, }
16354 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16355 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16356
16357 /* These macros abstract out the exact format of the mnemonic table and
16358 save some repeated characters. */
16359
16360 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16361 #define TxCE(mnem, op, top, nops, ops, ae, te) \
16362 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
16363 THUMB_VARIANT, do_##ae, do_##te }
16364
16365 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16366 a T_MNEM_xyz enumerator. */
16367 #define TCE(mnem, aop, top, nops, ops, ae, te) \
16368 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
16369 #define tCE(mnem, aop, top, nops, ops, ae, te) \
16370 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16371
16372 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16373 infix after the third character. */
16374 #define TxC3(mnem, op, top, nops, ops, ae, te) \
16375 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
16376 THUMB_VARIANT, do_##ae, do_##te }
16377 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
16378 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
16379 THUMB_VARIANT, do_##ae, do_##te }
16380 #define TC3(mnem, aop, top, nops, ops, ae, te) \
16381 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
16382 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
16383 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
16384 #define tC3(mnem, aop, top, nops, ops, ae, te) \
16385 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16386 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
16387 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16388
16389 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16390 appear in the condition table. */
16391 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
16392 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16393 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
16394
16395 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
16396 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16397 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16398 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16399 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16400 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16401 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16402 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16403 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16404 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16405 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16406 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16407 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16408 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16409 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16410 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16411 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16412 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16413 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16414 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
16415
16416 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
16417 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16418 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
16419 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
16420
16421 /* Mnemonic that cannot be conditionalized. The ARM condition-code
16422 field is still 0xE. Many of the Thumb variants can be executed
16423 conditionally, so this is checked separately. */
16424 #define TUE(mnem, op, top, nops, ops, ae, te) \
16425 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
16426 THUMB_VARIANT, do_##ae, do_##te }
16427
16428 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16429 condition code field. */
16430 #define TUF(mnem, op, top, nops, ops, ae, te) \
16431 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
16432 THUMB_VARIANT, do_##ae, do_##te }
16433
16434 /* ARM-only variants of all the above. */
16435 #define CE(mnem, op, nops, ops, ae) \
16436 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16437
16438 #define C3(mnem, op, nops, ops, ae) \
16439 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16440
16441 /* Legacy mnemonics that always have conditional infix after the third
16442 character. */
16443 #define CL(mnem, op, nops, ops, ae) \
16444 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16445 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16446
16447 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16448 #define cCE(mnem, op, nops, ops, ae) \
16449 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16450
16451 /* Legacy coprocessor instructions where conditional infix and conditional
16452 suffix are ambiguous. For consistency this includes all FPA instructions,
16453 not just the potentially ambiguous ones. */
16454 #define cCL(mnem, op, nops, ops, ae) \
16455 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16456 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16457
16458 /* Coprocessor, takes either a suffix or a position-3 infix
16459 (for an FPA corner case). */
16460 #define C3E(mnem, op, nops, ops, ae) \
16461 { mnem, OPS##nops ops, OT_csuf_or_in3, \
16462 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16463
16464 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
16465 { m1 #m2 m3, OPS##nops ops, \
16466 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16467 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16468
16469 #define CM(m1, m2, op, nops, ops, ae) \
16470 xCM_ (m1, , m2, op, nops, ops, ae), \
16471 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16472 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16473 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16474 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16475 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16476 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16477 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16478 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16479 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16480 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16481 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16482 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16483 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16484 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16485 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16486 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16487 xCM_ (m1, le, m2, op, nops, ops, ae), \
16488 xCM_ (m1, al, m2, op, nops, ops, ae)
16489
16490 #define UE(mnem, op, nops, ops, ae) \
16491 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16492
16493 #define UF(mnem, op, nops, ops, ae) \
16494 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16495
16496 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
16497 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16498 use the same encoding function for each. */
16499 #define NUF(mnem, op, nops, ops, enc) \
16500 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16501 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16502
16503 /* Neon data processing, version which indirects through neon_enc_tab for
16504 the various overloaded versions of opcodes. */
16505 #define nUF(mnem, op, nops, ops, enc) \
16506 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
16507 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16508
16509 /* Neon insn with conditional suffix for the ARM version, non-overloaded
16510 version. */
16511 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
16512 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
16513 THUMB_VARIANT, do_##enc, do_##enc }
16514
16515 #define NCE(mnem, op, nops, ops, enc) \
16516 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16517
16518 #define NCEF(mnem, op, nops, ops, enc) \
16519 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16520
16521 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
16522 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
16523 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
16524 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16525
16526 #define nCE(mnem, op, nops, ops, enc) \
16527 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16528
16529 #define nCEF(mnem, op, nops, ops, enc) \
16530 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16531
16532 #define do_0 0
16533
16534 static const struct asm_opcode insns[] =
16535 {
16536 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16537 #define THUMB_VARIANT &arm_ext_v4t
16538 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16539 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16540 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16541 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16542 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16543 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16544 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16545 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16546 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16547 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16548 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16549 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16550 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16551 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16552 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16553 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
16554
16555 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16556 for setting PSR flag bits. They are obsolete in V6 and do not
16557 have Thumb equivalents. */
16558 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16559 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16560 CL("tstp", 110f000, 2, (RR, SH), cmp),
16561 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16562 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16563 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16564 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16565 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16566 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16567
16568 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16569 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16570 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16571 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16572
16573 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
16574 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16575 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16576 OP_RRnpc),
16577 OP_ADDRGLDR),ldst, t_ldst),
16578 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16579
16580 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16581 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16582 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16583 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16584 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16585 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16586
16587 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16588 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16589 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16590 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
16591
16592 /* Pseudo ops. */
16593 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
16594 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
16595 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
16596
16597 /* Thumb-compatibility pseudo ops. */
16598 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16599 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16600 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16601 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16602 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16603 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16604 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16605 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16606 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16607 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16608 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16609 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
16610
16611 /* These may simplify to neg. */
16612 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16613 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16614
16615 #undef THUMB_VARIANT
16616 #define THUMB_VARIANT & arm_ext_v6
16617
16618 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
16619
16620 /* V1 instructions with no Thumb analogue prior to V6T2. */
16621 #undef THUMB_VARIANT
16622 #define THUMB_VARIANT & arm_ext_v6t2
16623
16624 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16625 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16626 CL("teqp", 130f000, 2, (RR, SH), cmp),
16627
16628 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16629 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16630 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16631 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16632
16633 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16634 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16635
16636 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16637 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16638
16639 /* V1 instructions with no Thumb analogue at all. */
16640 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
16641 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16642
16643 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16644 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16645 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16646 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16647 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16648 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16649 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16650 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16651
16652 #undef ARM_VARIANT
16653 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16654 #undef THUMB_VARIANT
16655 #define THUMB_VARIANT & arm_ext_v4t
16656
16657 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16658 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16659
16660 #undef THUMB_VARIANT
16661 #define THUMB_VARIANT & arm_ext_v6t2
16662
16663 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16664 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16665
16666 /* Generic coprocessor instructions. */
16667 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16668 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16669 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16670 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16671 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16672 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16673 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16674
16675 #undef ARM_VARIANT
16676 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16677
16678 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16679 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16680
16681 #undef ARM_VARIANT
16682 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16683 #undef THUMB_VARIANT
16684 #define THUMB_VARIANT & arm_ext_msr
16685
16686 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16687 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
16688
16689 #undef ARM_VARIANT
16690 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16691 #undef THUMB_VARIANT
16692 #define THUMB_VARIANT & arm_ext_v6t2
16693
16694 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16695 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16696 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16697 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16698 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16699 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16700 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16701 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16702
16703 #undef ARM_VARIANT
16704 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16705 #undef THUMB_VARIANT
16706 #define THUMB_VARIANT & arm_ext_v4t
16707
16708 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16709 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16710 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16711 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16712 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16713 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16714
16715 #undef ARM_VARIANT
16716 #define ARM_VARIANT & arm_ext_v4t_5
16717
16718 /* ARM Architecture 4T. */
16719 /* Note: bx (and blx) are required on V5, even if the processor does
16720 not support Thumb. */
16721 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
16722
16723 #undef ARM_VARIANT
16724 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16725 #undef THUMB_VARIANT
16726 #define THUMB_VARIANT & arm_ext_v5t
16727
16728 /* Note: blx has 2 variants; the .value coded here is for
16729 BLX(2). Only this variant has conditional execution. */
16730 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16731 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
16732
16733 #undef THUMB_VARIANT
16734 #define THUMB_VARIANT & arm_ext_v6t2
16735
16736 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16737 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16738 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16739 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16740 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16741 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16742 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16743 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16744
16745 #undef ARM_VARIANT
16746 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
16747 #undef THUMB_VARIANT
16748 #define THUMB_VARIANT &arm_ext_v5exp
16749
16750 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16751 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16752 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16753 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16754
16755 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16756 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16757
16758 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16759 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16760 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16761 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16762
16763 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16764 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16765 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16766 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16767
16768 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16769 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16770
16771 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16772 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16773 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16774 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16775
16776 #undef ARM_VARIANT
16777 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
16778 #undef THUMB_VARIANT
16779 #define THUMB_VARIANT &arm_ext_v6t2
16780
16781 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
16782 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16783 ldrd, t_ldstd),
16784 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16785 ADDRGLDRS), ldrd, t_ldstd),
16786
16787 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16788 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16789
16790 #undef ARM_VARIANT
16791 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16792
16793 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
16794
16795 #undef ARM_VARIANT
16796 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16797 #undef THUMB_VARIANT
16798 #define THUMB_VARIANT & arm_ext_v6
16799
16800 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16801 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16802 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16803 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16804 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16805 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16806 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16807 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16808 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16809 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
16810
16811 #undef THUMB_VARIANT
16812 #define THUMB_VARIANT & arm_ext_v6t2
16813
16814 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
16815 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16816 strex, t_strex),
16817 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16818 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16819
16820 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16821 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
16822
16823 /* ARM V6 not included in V7M. */
16824 #undef THUMB_VARIANT
16825 #define THUMB_VARIANT & arm_ext_v6_notm
16826 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16827 UF(rfeib, 9900a00, 1, (RRw), rfe),
16828 UF(rfeda, 8100a00, 1, (RRw), rfe),
16829 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16830 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16831 UF(rfefa, 9900a00, 1, (RRw), rfe),
16832 UF(rfeea, 8100a00, 1, (RRw), rfe),
16833 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16834 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16835 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16836 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16837 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
16838
16839 /* ARM V6 not included in V7M (eg. integer SIMD). */
16840 #undef THUMB_VARIANT
16841 #define THUMB_VARIANT & arm_ext_v6_dsp
16842 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16843 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16844 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16845 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16846 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16847 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16848 /* Old name for QASX. */
16849 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16850 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16851 /* Old name for QSAX. */
16852 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16853 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16854 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16855 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16856 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16857 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16858 /* Old name for SASX. */
16859 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16860 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16861 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16862 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16863 /* Old name for SHASX. */
16864 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16865 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16866 /* Old name for SHSAX. */
16867 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16868 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16869 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16870 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16871 /* Old name for SSAX. */
16872 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16873 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16874 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16875 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16876 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16877 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16878 /* Old name for UASX. */
16879 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16880 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16881 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16882 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16883 /* Old name for UHASX. */
16884 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16885 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16886 /* Old name for UHSAX. */
16887 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16888 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16889 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16890 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16891 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16892 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16893 /* Old name for UQASX. */
16894 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16895 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16896 /* Old name for UQSAX. */
16897 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16898 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16899 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16900 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16901 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16902 /* Old name for USAX. */
16903 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16904 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16905 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16906 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16907 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16908 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16909 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16910 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16911 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16912 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16913 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16914 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16915 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16916 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16917 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16918 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16919 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16920 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16921 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16922 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16923 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16924 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16925 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16926 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16927 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16928 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16929 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16930 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16931 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16932 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16933 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16934 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16935 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16936 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
16937
16938 #undef ARM_VARIANT
16939 #define ARM_VARIANT & arm_ext_v6k
16940 #undef THUMB_VARIANT
16941 #define THUMB_VARIANT & arm_ext_v6k
16942
16943 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16944 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16945 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16946 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
16947
16948 #undef THUMB_VARIANT
16949 #define THUMB_VARIANT & arm_ext_v6_notm
16950 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
16951 ldrexd, t_ldrexd),
16952 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
16953 RRnpcb), strexd, t_strexd),
16954
16955 #undef THUMB_VARIANT
16956 #define THUMB_VARIANT & arm_ext_v6t2
16957 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
16958 rd_rn, rd_rn),
16959 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
16960 rd_rn, rd_rn),
16961 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16962 strex, rm_rd_rn),
16963 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16964 strex, rm_rd_rn),
16965 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
16966
16967 #undef ARM_VARIANT
16968 #define ARM_VARIANT & arm_ext_v6z
16969
16970 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
16971
16972 #undef ARM_VARIANT
16973 #define ARM_VARIANT & arm_ext_v6t2
16974
16975 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16976 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16977 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16978 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16979
16980 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16981 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16982 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16983 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
16984
16985 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16986 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16987 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16988 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16989
16990 /* Thumb-only instructions. */
16991 #undef ARM_VARIANT
16992 #define ARM_VARIANT NULL
16993 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
16994 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
16995
16996 /* ARM does not really have an IT instruction, so always allow it.
16997 The opcode is copied from Thumb in order to allow warnings in
16998 -mimplicit-it=[never | arm] modes. */
16999 #undef ARM_VARIANT
17000 #define ARM_VARIANT & arm_ext_v1
17001
17002 TUE("it", bf08, bf08, 1, (COND), it, t_it),
17003 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
17004 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
17005 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
17006 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
17007 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
17008 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
17009 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
17010 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
17011 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
17012 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
17013 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
17014 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
17015 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
17016 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
17017 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
17018 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
17019 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
17020
17021 /* Thumb2 only instructions. */
17022 #undef ARM_VARIANT
17023 #define ARM_VARIANT NULL
17024
17025 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17026 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
17027 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
17028 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
17029 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
17030 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
17031
17032 /* Thumb-2 hardware division instructions (R and M profiles only). */
17033 #undef THUMB_VARIANT
17034 #define THUMB_VARIANT & arm_ext_div
17035
17036 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
17037 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
17038
17039 /* ARM V6M/V7 instructions. */
17040 #undef ARM_VARIANT
17041 #define ARM_VARIANT & arm_ext_barrier
17042 #undef THUMB_VARIANT
17043 #define THUMB_VARIANT & arm_ext_barrier
17044
17045 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER_I15), barrier, t_barrier),
17046 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER_I15), barrier, t_barrier),
17047 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER_I15), barrier, t_barrier),
17048
17049 /* ARM V7 instructions. */
17050 #undef ARM_VARIANT
17051 #define ARM_VARIANT & arm_ext_v7
17052 #undef THUMB_VARIANT
17053 #define THUMB_VARIANT & arm_ext_v7
17054
17055 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
17056 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
17057
17058 #undef ARM_VARIANT
17059 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
17060
17061 cCE("wfs", e200110, 1, (RR), rd),
17062 cCE("rfs", e300110, 1, (RR), rd),
17063 cCE("wfc", e400110, 1, (RR), rd),
17064 cCE("rfc", e500110, 1, (RR), rd),
17065
17066 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
17067 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
17068 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
17069 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
17070
17071 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
17072 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
17073 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
17074 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
17075
17076 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
17077 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
17078 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
17079 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
17080 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
17081 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
17082 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
17083 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
17084 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
17085 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
17086 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
17087 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
17088
17089 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
17090 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
17091 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
17092 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
17093 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17094 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17095 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17096 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17097 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17098 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17099 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17100 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17101
17102 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17103 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17104 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17105 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17106 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17107 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17108 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17109 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17110 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17111 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17112 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17113 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17114
17115 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17116 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17117 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17118 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17119 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17120 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17121 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17122 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17123 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17124 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17125 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17126 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17127
17128 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17129 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17130 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17131 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17132 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17133 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17134 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17135 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17136 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17137 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17138 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17139 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17140
17141 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17142 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17143 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17144 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17145 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17146 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17147 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17148 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17149 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17150 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17151 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17152 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17153
17154 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17155 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17156 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17157 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17158 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17159 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17160 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17161 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17162 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17163 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17164 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17165 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17166
17167 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17168 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17169 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17170 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17171 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17172 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17173 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17174 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17175 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17176 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17177 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17178 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17179
17180 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17181 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17182 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17183 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17184 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17185 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17186 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17187 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17188 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17189 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17190 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17191 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17192
17193 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17194 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17195 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17196 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17197 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17198 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17199 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17200 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17201 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17202 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17203 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17204 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17205
17206 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17207 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17208 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17209 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17210 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17211 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17212 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17213 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17214 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17215 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17216 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17217 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17218
17219 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17220 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17221 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17222 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17223 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17224 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17225 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17226 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17227 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17228 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17229 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17230 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17231
17232 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17233 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17234 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17235 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17236 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17237 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17238 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17239 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17240 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17241 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17242 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17243 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17244
17245 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17246 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17247 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17248 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17249 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17250 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17251 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17252 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17253 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17254 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17255 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17256 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17257
17258 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17259 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17260 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17261 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17262 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17263 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17264 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17265 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17266 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17267 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17268 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17269 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17270
17271 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17272 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17273 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17274 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17275 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17276 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17277 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17278 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17279 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17280 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17281 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17282 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17283
17284 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17285 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17286 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17287 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17288 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17289 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17290 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17291 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17292 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17293 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17294 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17295 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17296
17297 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17298 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17299 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17300 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17301 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17302 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17303 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17304 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17305 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17306 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17307 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17308 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17309
17310 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17311 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17312 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17313 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17314 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17315 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17316 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17317 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17318 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17319 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17320 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17321 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17322
17323 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17324 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17325 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17326 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17327 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17328 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17329 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17330 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17331 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17332 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17333 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17334 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17335
17336 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17337 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17338 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17339 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17340 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17341 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17342 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17343 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17344 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17345 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17346 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17347 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17348
17349 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17350 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17351 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17352 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17353 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17354 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17355 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17356 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17357 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17358 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17359 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17360 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17361
17362 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17363 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17364 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17365 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17366 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17367 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17368 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17369 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17370 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17371 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17372 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17373 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17374
17375 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17376 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17377 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17378 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17379 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17380 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17381 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17382 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17383 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17384 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17385 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17386 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17387
17388 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17389 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17390 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17391 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17392 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17393 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17394 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17395 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17396 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17397 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17398 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17399 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17400
17401 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17402 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17403 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17404 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17405 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17406 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17407 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17408 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17409 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17410 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17411 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17412 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17413
17414 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17415 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17416 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17417 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17418 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17419 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17420 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17421 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17422 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17423 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17424 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17425 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17426
17427 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17428 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17429 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17430 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17431 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17432 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17433 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17434 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17435 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17436 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17437 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17438 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17439
17440 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17441 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17442 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17443 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17444 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17445 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17446 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17447 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17448 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17449 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17450 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17451 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17452
17453 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17454 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17455 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17456 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17457
17458 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17459 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17460 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17461 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17462 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17463 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17464 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17465 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17466 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17467 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17468 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17469 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
17470
17471 /* The implementation of the FIX instruction is broken on some
17472 assemblers, in that it accepts a precision specifier as well as a
17473 rounding specifier, despite the fact that this is meaningless.
17474 To be more compatible, we accept it as well, though of course it
17475 does not set any bits. */
17476 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17477 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17478 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17479 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17480 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17481 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17482 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17483 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17484 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17485 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17486 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17487 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17488 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
17489
17490 /* Instructions that were new with the real FPA, call them V2. */
17491 #undef ARM_VARIANT
17492 #define ARM_VARIANT & fpu_fpa_ext_v2
17493
17494 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17495 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17496 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17497 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17498 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17499 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17500
17501 #undef ARM_VARIANT
17502 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17503
17504 /* Moves and type conversions. */
17505 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17506 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17507 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17508 cCE("fmstat", ef1fa10, 0, (), noargs),
17509 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17510 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
17511 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17512 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17513 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17514 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17515 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17516 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17517 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17518 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
17519
17520 /* Memory operations. */
17521 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17522 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17523 cCE("fldmias", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17524 cCE("fldmfds", c900a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17525 cCE("fldmdbs", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17526 cCE("fldmeas", d300a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17527 cCE("fldmiax", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17528 cCE("fldmfdx", c900b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17529 cCE("fldmdbx", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17530 cCE("fldmeax", d300b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17531 cCE("fstmias", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17532 cCE("fstmeas", c800a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmia),
17533 cCE("fstmdbs", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17534 cCE("fstmfds", d200a00, 2, (RRnpctw, VRSLST), vfp_sp_ldstmdb),
17535 cCE("fstmiax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17536 cCE("fstmeax", c800b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmia),
17537 cCE("fstmdbx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17538 cCE("fstmfdx", d200b00, 2, (RRnpctw, VRDLST), vfp_xp_ldstmdb),
17539
17540 /* Monadic operations. */
17541 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17542 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17543 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
17544
17545 /* Dyadic operations. */
17546 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17547 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17548 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17549 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17550 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17551 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17552 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17553 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17554 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17555
17556 /* Comparisons. */
17557 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17558 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17559 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17560 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
17561
17562 /* Double precision load/store are still present on single precision
17563 implementations. */
17564 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17565 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17566 cCE("fldmiad", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17567 cCE("fldmfdd", c900b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17568 cCE("fldmdbd", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17569 cCE("fldmead", d300b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17570 cCE("fstmiad", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17571 cCE("fstmead", c800b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmia),
17572 cCE("fstmdbd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17573 cCE("fstmfdd", d200b00, 2, (RRnpctw, VRDLST), vfp_dp_ldstmdb),
17574
17575 #undef ARM_VARIANT
17576 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17577
17578 /* Moves and type conversions. */
17579 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17580 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17581 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17582 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17583 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17584 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17585 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17586 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17587 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17588 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17589 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17590 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17591 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17592
17593 /* Monadic operations. */
17594 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17595 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17596 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17597
17598 /* Dyadic operations. */
17599 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17600 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17601 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17602 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17603 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17604 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17605 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17606 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17607 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17608
17609 /* Comparisons. */
17610 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17611 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17612 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17613 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
17614
17615 #undef ARM_VARIANT
17616 #define ARM_VARIANT & fpu_vfp_ext_v2
17617
17618 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17619 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17620 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17621 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
17622
17623 /* Instructions which may belong to either the Neon or VFP instruction sets.
17624 Individual encoder functions perform additional architecture checks. */
17625 #undef ARM_VARIANT
17626 #define ARM_VARIANT & fpu_vfp_ext_v1xd
17627 #undef THUMB_VARIANT
17628 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
17629
17630 /* These mnemonics are unique to VFP. */
17631 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17632 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
17633 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17634 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17635 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17636 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17637 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17638 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17639 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17640 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17641
17642 /* Mnemonics shared by Neon and VFP. */
17643 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17644 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17645 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17646
17647 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17648 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17649
17650 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17651 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17652
17653 NCE(vldm, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17654 NCE(vldmia, c900b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17655 NCE(vldmdb, d100b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17656 NCE(vstm, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17657 NCE(vstmia, c800b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17658 NCE(vstmdb, d000b00, 2, (RRnpctw, VRSDLST), neon_ldm_stm),
17659 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17660 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17661
17662 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17663 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
17664 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17665 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
17666
17667
17668 /* NOTE: All VMOV encoding is special-cased! */
17669 NCE(vmov, 0, 1, (VMOV), neon_mov),
17670 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17671
17672 #undef THUMB_VARIANT
17673 #define THUMB_VARIANT & fpu_neon_ext_v1
17674 #undef ARM_VARIANT
17675 #define ARM_VARIANT & fpu_neon_ext_v1
17676
17677 /* Data processing with three registers of the same length. */
17678 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17679 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17680 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17681 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17682 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17683 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17684 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17685 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17686 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17687 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17688 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17689 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17690 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17691 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17692 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17693 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17694 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17695 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17696 /* If not immediate, fall back to neon_dyadic_i64_su.
17697 shl_imm should accept I8 I16 I32 I64,
17698 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
17699 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17700 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17701 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17702 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
17703 /* Logic ops, types optional & ignored. */
17704 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17705 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17706 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17707 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17708 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17709 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17710 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17711 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17712 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17713 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
17714 /* Bitfield ops, untyped. */
17715 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17716 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17717 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17718 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17719 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17720 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17721 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
17722 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17723 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17724 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17725 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17726 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17727 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17728 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17729 back to neon_dyadic_if_su. */
17730 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17731 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17732 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17733 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17734 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17735 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17736 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17737 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17738 /* Comparison. Type I8 I16 I32 F32. */
17739 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17740 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
17741 /* As above, D registers only. */
17742 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17743 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17744 /* Int and float variants, signedness unimportant. */
17745 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17746 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17747 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
17748 /* Add/sub take types I8 I16 I32 I64 F32. */
17749 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17750 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17751 /* vtst takes sizes 8, 16, 32. */
17752 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17753 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17754 /* VMUL takes I8 I16 I32 F32 P8. */
17755 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
17756 /* VQD{R}MULH takes S16 S32. */
17757 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17758 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17759 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17760 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17761 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17762 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17763 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17764 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17765 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17766 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17767 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17768 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17769 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17770 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17771 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17772 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17773
17774 /* Two address, int/float. Types S8 S16 S32 F32. */
17775 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
17776 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17777
17778 /* Data processing with two registers and a shift amount. */
17779 /* Right shifts, and variants with rounding.
17780 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17781 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17782 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17783 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17784 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17785 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17786 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17787 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17788 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17789 /* Shift and insert. Sizes accepted 8 16 32 64. */
17790 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17791 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17792 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17793 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17794 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17795 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17796 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17797 /* Right shift immediate, saturating & narrowing, with rounding variants.
17798 Types accepted S16 S32 S64 U16 U32 U64. */
17799 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17800 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17801 /* As above, unsigned. Types accepted S16 S32 S64. */
17802 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17803 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17804 /* Right shift narrowing. Types accepted I16 I32 I64. */
17805 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17806 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17807 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
17808 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
17809 /* CVT with optional immediate for fixed-point variant. */
17810 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
17811
17812 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17813 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
17814
17815 /* Data processing, three registers of different lengths. */
17816 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17817 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17818 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17819 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17820 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17821 /* If not scalar, fall back to neon_dyadic_long.
17822 Vector types as above, scalar types S16 S32 U16 U32. */
17823 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17824 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17825 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17826 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17827 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17828 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17829 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17830 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17831 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17832 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17833 /* Saturating doubling multiplies. Types S16 S32. */
17834 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17835 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17836 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17837 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17838 S16 S32 U16 U32. */
17839 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
17840
17841 /* Extract. Size 8. */
17842 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17843 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
17844
17845 /* Two registers, miscellaneous. */
17846 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17847 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17848 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17849 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17850 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17851 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17852 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17853 /* Vector replicate. Sizes 8 16 32. */
17854 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17855 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
17856 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17857 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17858 /* VMOVN. Types I16 I32 I64. */
17859 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
17860 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
17861 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
17862 /* VQMOVUN. Types S16 S32 S64. */
17863 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
17864 /* VZIP / VUZP. Sizes 8 16 32. */
17865 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17866 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17867 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17868 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17869 /* VQABS / VQNEG. Types S8 S16 S32. */
17870 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17871 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17872 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17873 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17874 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17875 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17876 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17877 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17878 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17879 /* Reciprocal estimates. Types U32 F32. */
17880 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17881 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17882 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17883 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17884 /* VCLS. Types S8 S16 S32. */
17885 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17886 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17887 /* VCLZ. Types I8 I16 I32. */
17888 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17889 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17890 /* VCNT. Size 8. */
17891 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17892 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17893 /* Two address, untyped. */
17894 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17895 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17896 /* VTRN. Sizes 8 16 32. */
17897 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17898 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
17899
17900 /* Table lookup. Size 8. */
17901 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17902 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17903
17904 #undef THUMB_VARIANT
17905 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17906 #undef ARM_VARIANT
17907 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17908
17909 /* Neon element/structure load/store. */
17910 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17911 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17912 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17913 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17914 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17915 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17916 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17917 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17918
17919 #undef THUMB_VARIANT
17920 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
17921 #undef ARM_VARIANT
17922 #define ARM_VARIANT &fpu_vfp_ext_v3xd
17923 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17924 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17925 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17926 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17927 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17928 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17929 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17930 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17931 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17932
17933 #undef THUMB_VARIANT
17934 #define THUMB_VARIANT & fpu_vfp_ext_v3
17935 #undef ARM_VARIANT
17936 #define ARM_VARIANT & fpu_vfp_ext_v3
17937
17938 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
17939 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17940 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17941 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17942 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17943 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17944 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17945 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17946 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17947
17948 #undef ARM_VARIANT
17949 #define ARM_VARIANT &fpu_vfp_ext_fma
17950 #undef THUMB_VARIANT
17951 #define THUMB_VARIANT &fpu_vfp_ext_fma
17952 /* Mnemonics shared by Neon and VFP. These are included in the
17953 VFP FMA variant; NEON and VFP FMA always includes the NEON
17954 FMA instructions. */
17955 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17956 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17957 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17958 the v form should always be used. */
17959 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17960 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17961 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17962 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17963 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17964 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17965
17966 #undef THUMB_VARIANT
17967 #undef ARM_VARIANT
17968 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17969
17970 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17971 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17972 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17973 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17974 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17975 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17976 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17977 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
17978
17979 #undef ARM_VARIANT
17980 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17981
17982 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17983 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17984 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17985 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17986 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17987 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17988 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17989 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17990 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17991 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17992 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17993 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17994 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17995 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17996 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17997 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17998 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17999 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
18000 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
18001 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
18002 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18003 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18004 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18005 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18006 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18007 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
18008 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
18009 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
18010 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
18011 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
18012 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
18013 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
18014 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
18015 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
18016 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
18017 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
18018 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
18019 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18020 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18021 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18022 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18023 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18024 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18025 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18026 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18027 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18028 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
18029 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18030 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18031 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18032 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18033 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18034 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18035 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18036 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18037 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18038 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18039 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18040 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18041 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18042 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18043 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18044 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18045 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18046 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18047 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18048 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18049 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18050 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18051 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18052 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18053 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18054 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18055 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18056 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18057 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18058 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18059 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18060 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18061 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18062 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18063 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18064 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18065 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18066 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18067 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18068 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18069 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18070 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
18071 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18072 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18073 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18074 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18075 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18076 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18077 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18078 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18079 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18080 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18081 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18082 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18083 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18084 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18085 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18086 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18087 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18088 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18089 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18090 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18091 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18092 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
18093 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18094 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18095 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18096 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18097 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18098 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18099 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18100 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18101 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18102 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18103 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18104 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18105 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18106 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18107 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18108 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18109 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18110 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18111 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18112 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18113 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18114 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18115 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18116 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18117 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18118 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18119 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18120 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18121 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18122 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18123 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18124 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18125 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18126 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18127 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18128 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18129 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18130 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18131 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18132 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18133 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18134 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18135 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18136 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18137 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18138 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18139 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18140 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18141 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18142 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18143 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
18144
18145 #undef ARM_VARIANT
18146 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18147
18148 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18149 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18150 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18151 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18152 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18153 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18154 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18155 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18156 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18157 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18158 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18159 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18160 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18161 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18162 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18163 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18164 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18165 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18166 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18167 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18168 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18169 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18170 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18171 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18172 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18173 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18174 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18175 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18176 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18177 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18178 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18179 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18180 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18181 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18182 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18183 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18184 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18185 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18186 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18187 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18188 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18189 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18190 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18191 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18192 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18193 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18194 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18195 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18196 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18197 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18198 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18199 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18200 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18201 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18202 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18203 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18204 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18205
18206 #undef ARM_VARIANT
18207 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18208
18209 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18210 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18211 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18212 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18213 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18214 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18215 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18216 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18217 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18218 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18219 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18220 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18221 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18222 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18223 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18224 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18225 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18226 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18227 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18228 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18229 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18230 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18231 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18232 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18233 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18234 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18235 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18236 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18237 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18238 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18239 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18240 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18241 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18242 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18243 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18244 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18245 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18246 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18247 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18248 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18249 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18250 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18251 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18252 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18253 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18254 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18255 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18256 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18257 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18258 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18259 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18260 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18261 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18262 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18263 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18264 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18265 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18266 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18267 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18268 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18269 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18270 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18271 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18272 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18273 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18274 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18275 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18276 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18277 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18278 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18279 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18280 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18281 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18282 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18283 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18284 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18285 };
18286 #undef ARM_VARIANT
18287 #undef THUMB_VARIANT
18288 #undef TCE
18289 #undef TCM
18290 #undef TUE
18291 #undef TUF
18292 #undef TCC
18293 #undef cCE
18294 #undef cCL
18295 #undef C3E
18296 #undef CE
18297 #undef CM
18298 #undef UE
18299 #undef UF
18300 #undef UT
18301 #undef NUF
18302 #undef nUF
18303 #undef NCE
18304 #undef nCE
18305 #undef OPS0
18306 #undef OPS1
18307 #undef OPS2
18308 #undef OPS3
18309 #undef OPS4
18310 #undef OPS5
18311 #undef OPS6
18312 #undef do_0
18313 \f
18314 /* MD interface: bits in the object file. */
18315
18316 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18317 for use in the a.out file, and stores them in the array pointed to by buf.
18318 This knows about the endian-ness of the target machine and does
18319 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18320 2 (short) and 4 (long) Floating numbers are put out as a series of
18321 LITTLENUMS (shorts, here at least). */
18322
18323 void
18324 md_number_to_chars (char * buf, valueT val, int n)
18325 {
18326 if (target_big_endian)
18327 number_to_chars_bigendian (buf, val, n);
18328 else
18329 number_to_chars_littleendian (buf, val, n);
18330 }
18331
18332 static valueT
18333 md_chars_to_number (char * buf, int n)
18334 {
18335 valueT result = 0;
18336 unsigned char * where = (unsigned char *) buf;
18337
18338 if (target_big_endian)
18339 {
18340 while (n--)
18341 {
18342 result <<= 8;
18343 result |= (*where++ & 255);
18344 }
18345 }
18346 else
18347 {
18348 while (n--)
18349 {
18350 result <<= 8;
18351 result |= (where[n] & 255);
18352 }
18353 }
18354
18355 return result;
18356 }
18357
18358 /* MD interface: Sections. */
18359
18360 /* Estimate the size of a frag before relaxing. Assume everything fits in
18361 2 bytes. */
18362
18363 int
18364 md_estimate_size_before_relax (fragS * fragp,
18365 segT segtype ATTRIBUTE_UNUSED)
18366 {
18367 fragp->fr_var = 2;
18368 return 2;
18369 }
18370
18371 /* Convert a machine dependent frag. */
18372
18373 void
18374 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18375 {
18376 unsigned long insn;
18377 unsigned long old_op;
18378 char *buf;
18379 expressionS exp;
18380 fixS *fixp;
18381 int reloc_type;
18382 int pc_rel;
18383 int opcode;
18384
18385 buf = fragp->fr_literal + fragp->fr_fix;
18386
18387 old_op = bfd_get_16(abfd, buf);
18388 if (fragp->fr_symbol)
18389 {
18390 exp.X_op = O_symbol;
18391 exp.X_add_symbol = fragp->fr_symbol;
18392 }
18393 else
18394 {
18395 exp.X_op = O_constant;
18396 }
18397 exp.X_add_number = fragp->fr_offset;
18398 opcode = fragp->fr_subtype;
18399 switch (opcode)
18400 {
18401 case T_MNEM_ldr_pc:
18402 case T_MNEM_ldr_pc2:
18403 case T_MNEM_ldr_sp:
18404 case T_MNEM_str_sp:
18405 case T_MNEM_ldr:
18406 case T_MNEM_ldrb:
18407 case T_MNEM_ldrh:
18408 case T_MNEM_str:
18409 case T_MNEM_strb:
18410 case T_MNEM_strh:
18411 if (fragp->fr_var == 4)
18412 {
18413 insn = THUMB_OP32 (opcode);
18414 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18415 {
18416 insn |= (old_op & 0x700) << 4;
18417 }
18418 else
18419 {
18420 insn |= (old_op & 7) << 12;
18421 insn |= (old_op & 0x38) << 13;
18422 }
18423 insn |= 0x00000c00;
18424 put_thumb32_insn (buf, insn);
18425 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18426 }
18427 else
18428 {
18429 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18430 }
18431 pc_rel = (opcode == T_MNEM_ldr_pc2);
18432 break;
18433 case T_MNEM_adr:
18434 if (fragp->fr_var == 4)
18435 {
18436 insn = THUMB_OP32 (opcode);
18437 insn |= (old_op & 0xf0) << 4;
18438 put_thumb32_insn (buf, insn);
18439 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18440 }
18441 else
18442 {
18443 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18444 exp.X_add_number -= 4;
18445 }
18446 pc_rel = 1;
18447 break;
18448 case T_MNEM_mov:
18449 case T_MNEM_movs:
18450 case T_MNEM_cmp:
18451 case T_MNEM_cmn:
18452 if (fragp->fr_var == 4)
18453 {
18454 int r0off = (opcode == T_MNEM_mov
18455 || opcode == T_MNEM_movs) ? 0 : 8;
18456 insn = THUMB_OP32 (opcode);
18457 insn = (insn & 0xe1ffffff) | 0x10000000;
18458 insn |= (old_op & 0x700) << r0off;
18459 put_thumb32_insn (buf, insn);
18460 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18461 }
18462 else
18463 {
18464 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18465 }
18466 pc_rel = 0;
18467 break;
18468 case T_MNEM_b:
18469 if (fragp->fr_var == 4)
18470 {
18471 insn = THUMB_OP32(opcode);
18472 put_thumb32_insn (buf, insn);
18473 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18474 }
18475 else
18476 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18477 pc_rel = 1;
18478 break;
18479 case T_MNEM_bcond:
18480 if (fragp->fr_var == 4)
18481 {
18482 insn = THUMB_OP32(opcode);
18483 insn |= (old_op & 0xf00) << 14;
18484 put_thumb32_insn (buf, insn);
18485 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18486 }
18487 else
18488 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18489 pc_rel = 1;
18490 break;
18491 case T_MNEM_add_sp:
18492 case T_MNEM_add_pc:
18493 case T_MNEM_inc_sp:
18494 case T_MNEM_dec_sp:
18495 if (fragp->fr_var == 4)
18496 {
18497 /* ??? Choose between add and addw. */
18498 insn = THUMB_OP32 (opcode);
18499 insn |= (old_op & 0xf0) << 4;
18500 put_thumb32_insn (buf, insn);
18501 if (opcode == T_MNEM_add_pc)
18502 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18503 else
18504 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18505 }
18506 else
18507 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18508 pc_rel = 0;
18509 break;
18510
18511 case T_MNEM_addi:
18512 case T_MNEM_addis:
18513 case T_MNEM_subi:
18514 case T_MNEM_subis:
18515 if (fragp->fr_var == 4)
18516 {
18517 insn = THUMB_OP32 (opcode);
18518 insn |= (old_op & 0xf0) << 4;
18519 insn |= (old_op & 0xf) << 16;
18520 put_thumb32_insn (buf, insn);
18521 if (insn & (1 << 20))
18522 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18523 else
18524 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18525 }
18526 else
18527 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18528 pc_rel = 0;
18529 break;
18530 default:
18531 abort ();
18532 }
18533 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
18534 (enum bfd_reloc_code_real) reloc_type);
18535 fixp->fx_file = fragp->fr_file;
18536 fixp->fx_line = fragp->fr_line;
18537 fragp->fr_fix += fragp->fr_var;
18538 }
18539
18540 /* Return the size of a relaxable immediate operand instruction.
18541 SHIFT and SIZE specify the form of the allowable immediate. */
18542 static int
18543 relax_immediate (fragS *fragp, int size, int shift)
18544 {
18545 offsetT offset;
18546 offsetT mask;
18547 offsetT low;
18548
18549 /* ??? Should be able to do better than this. */
18550 if (fragp->fr_symbol)
18551 return 4;
18552
18553 low = (1 << shift) - 1;
18554 mask = (1 << (shift + size)) - (1 << shift);
18555 offset = fragp->fr_offset;
18556 /* Force misaligned offsets to 32-bit variant. */
18557 if (offset & low)
18558 return 4;
18559 if (offset & ~mask)
18560 return 4;
18561 return 2;
18562 }
18563
18564 /* Get the address of a symbol during relaxation. */
18565 static addressT
18566 relaxed_symbol_addr (fragS *fragp, long stretch)
18567 {
18568 fragS *sym_frag;
18569 addressT addr;
18570 symbolS *sym;
18571
18572 sym = fragp->fr_symbol;
18573 sym_frag = symbol_get_frag (sym);
18574 know (S_GET_SEGMENT (sym) != absolute_section
18575 || sym_frag == &zero_address_frag);
18576 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18577
18578 /* If frag has yet to be reached on this pass, assume it will
18579 move by STRETCH just as we did. If this is not so, it will
18580 be because some frag between grows, and that will force
18581 another pass. */
18582
18583 if (stretch != 0
18584 && sym_frag->relax_marker != fragp->relax_marker)
18585 {
18586 fragS *f;
18587
18588 /* Adjust stretch for any alignment frag. Note that if have
18589 been expanding the earlier code, the symbol may be
18590 defined in what appears to be an earlier frag. FIXME:
18591 This doesn't handle the fr_subtype field, which specifies
18592 a maximum number of bytes to skip when doing an
18593 alignment. */
18594 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18595 {
18596 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18597 {
18598 if (stretch < 0)
18599 stretch = - ((- stretch)
18600 & ~ ((1 << (int) f->fr_offset) - 1));
18601 else
18602 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18603 if (stretch == 0)
18604 break;
18605 }
18606 }
18607 if (f != NULL)
18608 addr += stretch;
18609 }
18610
18611 return addr;
18612 }
18613
18614 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
18615 load. */
18616 static int
18617 relax_adr (fragS *fragp, asection *sec, long stretch)
18618 {
18619 addressT addr;
18620 offsetT val;
18621
18622 /* Assume worst case for symbols not known to be in the same section. */
18623 if (fragp->fr_symbol == NULL
18624 || !S_IS_DEFINED (fragp->fr_symbol)
18625 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18626 || S_IS_WEAK (fragp->fr_symbol))
18627 return 4;
18628
18629 val = relaxed_symbol_addr (fragp, stretch);
18630 addr = fragp->fr_address + fragp->fr_fix;
18631 addr = (addr + 4) & ~3;
18632 /* Force misaligned targets to 32-bit variant. */
18633 if (val & 3)
18634 return 4;
18635 val -= addr;
18636 if (val < 0 || val > 1020)
18637 return 4;
18638 return 2;
18639 }
18640
18641 /* Return the size of a relaxable add/sub immediate instruction. */
18642 static int
18643 relax_addsub (fragS *fragp, asection *sec)
18644 {
18645 char *buf;
18646 int op;
18647
18648 buf = fragp->fr_literal + fragp->fr_fix;
18649 op = bfd_get_16(sec->owner, buf);
18650 if ((op & 0xf) == ((op >> 4) & 0xf))
18651 return relax_immediate (fragp, 8, 0);
18652 else
18653 return relax_immediate (fragp, 3, 0);
18654 }
18655
18656
18657 /* Return the size of a relaxable branch instruction. BITS is the
18658 size of the offset field in the narrow instruction. */
18659
18660 static int
18661 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
18662 {
18663 addressT addr;
18664 offsetT val;
18665 offsetT limit;
18666
18667 /* Assume worst case for symbols not known to be in the same section. */
18668 if (!S_IS_DEFINED (fragp->fr_symbol)
18669 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18670 || S_IS_WEAK (fragp->fr_symbol))
18671 return 4;
18672
18673 #ifdef OBJ_ELF
18674 if (S_IS_DEFINED (fragp->fr_symbol)
18675 && ARM_IS_FUNC (fragp->fr_symbol))
18676 return 4;
18677 #endif
18678
18679 val = relaxed_symbol_addr (fragp, stretch);
18680 addr = fragp->fr_address + fragp->fr_fix + 4;
18681 val -= addr;
18682
18683 /* Offset is a signed value *2 */
18684 limit = 1 << bits;
18685 if (val >= limit || val < -limit)
18686 return 4;
18687 return 2;
18688 }
18689
18690
18691 /* Relax a machine dependent frag. This returns the amount by which
18692 the current size of the frag should change. */
18693
18694 int
18695 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
18696 {
18697 int oldsize;
18698 int newsize;
18699
18700 oldsize = fragp->fr_var;
18701 switch (fragp->fr_subtype)
18702 {
18703 case T_MNEM_ldr_pc2:
18704 newsize = relax_adr (fragp, sec, stretch);
18705 break;
18706 case T_MNEM_ldr_pc:
18707 case T_MNEM_ldr_sp:
18708 case T_MNEM_str_sp:
18709 newsize = relax_immediate (fragp, 8, 2);
18710 break;
18711 case T_MNEM_ldr:
18712 case T_MNEM_str:
18713 newsize = relax_immediate (fragp, 5, 2);
18714 break;
18715 case T_MNEM_ldrh:
18716 case T_MNEM_strh:
18717 newsize = relax_immediate (fragp, 5, 1);
18718 break;
18719 case T_MNEM_ldrb:
18720 case T_MNEM_strb:
18721 newsize = relax_immediate (fragp, 5, 0);
18722 break;
18723 case T_MNEM_adr:
18724 newsize = relax_adr (fragp, sec, stretch);
18725 break;
18726 case T_MNEM_mov:
18727 case T_MNEM_movs:
18728 case T_MNEM_cmp:
18729 case T_MNEM_cmn:
18730 newsize = relax_immediate (fragp, 8, 0);
18731 break;
18732 case T_MNEM_b:
18733 newsize = relax_branch (fragp, sec, 11, stretch);
18734 break;
18735 case T_MNEM_bcond:
18736 newsize = relax_branch (fragp, sec, 8, stretch);
18737 break;
18738 case T_MNEM_add_sp:
18739 case T_MNEM_add_pc:
18740 newsize = relax_immediate (fragp, 8, 2);
18741 break;
18742 case T_MNEM_inc_sp:
18743 case T_MNEM_dec_sp:
18744 newsize = relax_immediate (fragp, 7, 2);
18745 break;
18746 case T_MNEM_addi:
18747 case T_MNEM_addis:
18748 case T_MNEM_subi:
18749 case T_MNEM_subis:
18750 newsize = relax_addsub (fragp, sec);
18751 break;
18752 default:
18753 abort ();
18754 }
18755
18756 fragp->fr_var = newsize;
18757 /* Freeze wide instructions that are at or before the same location as
18758 in the previous pass. This avoids infinite loops.
18759 Don't freeze them unconditionally because targets may be artificially
18760 misaligned by the expansion of preceding frags. */
18761 if (stretch <= 0 && newsize > 2)
18762 {
18763 md_convert_frag (sec->owner, sec, fragp);
18764 frag_wane (fragp);
18765 }
18766
18767 return newsize - oldsize;
18768 }
18769
18770 /* Round up a section size to the appropriate boundary. */
18771
18772 valueT
18773 md_section_align (segT segment ATTRIBUTE_UNUSED,
18774 valueT size)
18775 {
18776 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18777 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18778 {
18779 /* For a.out, force the section size to be aligned. If we don't do
18780 this, BFD will align it for us, but it will not write out the
18781 final bytes of the section. This may be a bug in BFD, but it is
18782 easier to fix it here since that is how the other a.out targets
18783 work. */
18784 int align;
18785
18786 align = bfd_get_section_alignment (stdoutput, segment);
18787 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18788 }
18789 #endif
18790
18791 return size;
18792 }
18793
18794 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18795 of an rs_align_code fragment. */
18796
18797 void
18798 arm_handle_align (fragS * fragP)
18799 {
18800 static char const arm_noop[2][2][4] =
18801 {
18802 { /* ARMv1 */
18803 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18804 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18805 },
18806 { /* ARMv6k */
18807 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18808 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18809 },
18810 };
18811 static char const thumb_noop[2][2][2] =
18812 {
18813 { /* Thumb-1 */
18814 {0xc0, 0x46}, /* LE */
18815 {0x46, 0xc0}, /* BE */
18816 },
18817 { /* Thumb-2 */
18818 {0x00, 0xbf}, /* LE */
18819 {0xbf, 0x00} /* BE */
18820 }
18821 };
18822 static char const wide_thumb_noop[2][4] =
18823 { /* Wide Thumb-2 */
18824 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18825 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18826 };
18827
18828 unsigned bytes, fix, noop_size;
18829 char * p;
18830 const char * noop;
18831 const char *narrow_noop = NULL;
18832 #ifdef OBJ_ELF
18833 enum mstate state;
18834 #endif
18835
18836 if (fragP->fr_type != rs_align_code)
18837 return;
18838
18839 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18840 p = fragP->fr_literal + fragP->fr_fix;
18841 fix = 0;
18842
18843 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18844 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
18845
18846 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
18847
18848 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
18849 {
18850 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18851 {
18852 narrow_noop = thumb_noop[1][target_big_endian];
18853 noop = wide_thumb_noop[target_big_endian];
18854 }
18855 else
18856 noop = thumb_noop[0][target_big_endian];
18857 noop_size = 2;
18858 #ifdef OBJ_ELF
18859 state = MAP_THUMB;
18860 #endif
18861 }
18862 else
18863 {
18864 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18865 [target_big_endian];
18866 noop_size = 4;
18867 #ifdef OBJ_ELF
18868 state = MAP_ARM;
18869 #endif
18870 }
18871
18872 fragP->fr_var = noop_size;
18873
18874 if (bytes & (noop_size - 1))
18875 {
18876 fix = bytes & (noop_size - 1);
18877 #ifdef OBJ_ELF
18878 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18879 #endif
18880 memset (p, 0, fix);
18881 p += fix;
18882 bytes -= fix;
18883 }
18884
18885 if (narrow_noop)
18886 {
18887 if (bytes & noop_size)
18888 {
18889 /* Insert a narrow noop. */
18890 memcpy (p, narrow_noop, noop_size);
18891 p += noop_size;
18892 bytes -= noop_size;
18893 fix += noop_size;
18894 }
18895
18896 /* Use wide noops for the remainder */
18897 noop_size = 4;
18898 }
18899
18900 while (bytes >= noop_size)
18901 {
18902 memcpy (p, noop, noop_size);
18903 p += noop_size;
18904 bytes -= noop_size;
18905 fix += noop_size;
18906 }
18907
18908 fragP->fr_fix += fix;
18909 }
18910
18911 /* Called from md_do_align. Used to create an alignment
18912 frag in a code section. */
18913
18914 void
18915 arm_frag_align_code (int n, int max)
18916 {
18917 char * p;
18918
18919 /* We assume that there will never be a requirement
18920 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
18921 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
18922 {
18923 char err_msg[128];
18924
18925 sprintf (err_msg,
18926 _("alignments greater than %d bytes not supported in .text sections."),
18927 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
18928 as_fatal ("%s", err_msg);
18929 }
18930
18931 p = frag_var (rs_align_code,
18932 MAX_MEM_FOR_RS_ALIGN_CODE,
18933 1,
18934 (relax_substateT) max,
18935 (symbolS *) NULL,
18936 (offsetT) n,
18937 (char *) NULL);
18938 *p = 0;
18939 }
18940
18941 /* Perform target specific initialisation of a frag.
18942 Note - despite the name this initialisation is not done when the frag
18943 is created, but only when its type is assigned. A frag can be created
18944 and used a long time before its type is set, so beware of assuming that
18945 this initialisationis performed first. */
18946
18947 #ifndef OBJ_ELF
18948 void
18949 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18950 {
18951 /* Record whether this frag is in an ARM or a THUMB area. */
18952 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18953 }
18954
18955 #else /* OBJ_ELF is defined. */
18956 void
18957 arm_init_frag (fragS * fragP, int max_chars)
18958 {
18959 /* If the current ARM vs THUMB mode has not already
18960 been recorded into this frag then do so now. */
18961 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18962 {
18963 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18964
18965 /* Record a mapping symbol for alignment frags. We will delete this
18966 later if the alignment ends up empty. */
18967 switch (fragP->fr_type)
18968 {
18969 case rs_align:
18970 case rs_align_test:
18971 case rs_fill:
18972 mapping_state_2 (MAP_DATA, max_chars);
18973 break;
18974 case rs_align_code:
18975 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18976 break;
18977 default:
18978 break;
18979 }
18980 }
18981 }
18982
18983 /* When we change sections we need to issue a new mapping symbol. */
18984
18985 void
18986 arm_elf_change_section (void)
18987 {
18988 /* Link an unlinked unwind index table section to the .text section. */
18989 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18990 && elf_linked_to_section (now_seg) == NULL)
18991 elf_linked_to_section (now_seg) = text_section;
18992 }
18993
18994 int
18995 arm_elf_section_type (const char * str, size_t len)
18996 {
18997 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18998 return SHT_ARM_EXIDX;
18999
19000 return -1;
19001 }
19002 \f
19003 /* Code to deal with unwinding tables. */
19004
19005 static void add_unwind_adjustsp (offsetT);
19006
19007 /* Generate any deferred unwind frame offset. */
19008
19009 static void
19010 flush_pending_unwind (void)
19011 {
19012 offsetT offset;
19013
19014 offset = unwind.pending_offset;
19015 unwind.pending_offset = 0;
19016 if (offset != 0)
19017 add_unwind_adjustsp (offset);
19018 }
19019
19020 /* Add an opcode to this list for this function. Two-byte opcodes should
19021 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
19022 order. */
19023
19024 static void
19025 add_unwind_opcode (valueT op, int length)
19026 {
19027 /* Add any deferred stack adjustment. */
19028 if (unwind.pending_offset)
19029 flush_pending_unwind ();
19030
19031 unwind.sp_restored = 0;
19032
19033 if (unwind.opcode_count + length > unwind.opcode_alloc)
19034 {
19035 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
19036 if (unwind.opcodes)
19037 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
19038 unwind.opcode_alloc);
19039 else
19040 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
19041 }
19042 while (length > 0)
19043 {
19044 length--;
19045 unwind.opcodes[unwind.opcode_count] = op & 0xff;
19046 op >>= 8;
19047 unwind.opcode_count++;
19048 }
19049 }
19050
19051 /* Add unwind opcodes to adjust the stack pointer. */
19052
19053 static void
19054 add_unwind_adjustsp (offsetT offset)
19055 {
19056 valueT op;
19057
19058 if (offset > 0x200)
19059 {
19060 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
19061 char bytes[5];
19062 int n;
19063 valueT o;
19064
19065 /* Long form: 0xb2, uleb128. */
19066 /* This might not fit in a word so add the individual bytes,
19067 remembering the list is built in reverse order. */
19068 o = (valueT) ((offset - 0x204) >> 2);
19069 if (o == 0)
19070 add_unwind_opcode (0, 1);
19071
19072 /* Calculate the uleb128 encoding of the offset. */
19073 n = 0;
19074 while (o)
19075 {
19076 bytes[n] = o & 0x7f;
19077 o >>= 7;
19078 if (o)
19079 bytes[n] |= 0x80;
19080 n++;
19081 }
19082 /* Add the insn. */
19083 for (; n; n--)
19084 add_unwind_opcode (bytes[n - 1], 1);
19085 add_unwind_opcode (0xb2, 1);
19086 }
19087 else if (offset > 0x100)
19088 {
19089 /* Two short opcodes. */
19090 add_unwind_opcode (0x3f, 1);
19091 op = (offset - 0x104) >> 2;
19092 add_unwind_opcode (op, 1);
19093 }
19094 else if (offset > 0)
19095 {
19096 /* Short opcode. */
19097 op = (offset - 4) >> 2;
19098 add_unwind_opcode (op, 1);
19099 }
19100 else if (offset < 0)
19101 {
19102 offset = -offset;
19103 while (offset > 0x100)
19104 {
19105 add_unwind_opcode (0x7f, 1);
19106 offset -= 0x100;
19107 }
19108 op = ((offset - 4) >> 2) | 0x40;
19109 add_unwind_opcode (op, 1);
19110 }
19111 }
19112
19113 /* Finish the list of unwind opcodes for this function. */
19114 static void
19115 finish_unwind_opcodes (void)
19116 {
19117 valueT op;
19118
19119 if (unwind.fp_used)
19120 {
19121 /* Adjust sp as necessary. */
19122 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19123 flush_pending_unwind ();
19124
19125 /* After restoring sp from the frame pointer. */
19126 op = 0x90 | unwind.fp_reg;
19127 add_unwind_opcode (op, 1);
19128 }
19129 else
19130 flush_pending_unwind ();
19131 }
19132
19133
19134 /* Start an exception table entry. If idx is nonzero this is an index table
19135 entry. */
19136
19137 static void
19138 start_unwind_section (const segT text_seg, int idx)
19139 {
19140 const char * text_name;
19141 const char * prefix;
19142 const char * prefix_once;
19143 const char * group_name;
19144 size_t prefix_len;
19145 size_t text_len;
19146 char * sec_name;
19147 size_t sec_name_len;
19148 int type;
19149 int flags;
19150 int linkonce;
19151
19152 if (idx)
19153 {
19154 prefix = ELF_STRING_ARM_unwind;
19155 prefix_once = ELF_STRING_ARM_unwind_once;
19156 type = SHT_ARM_EXIDX;
19157 }
19158 else
19159 {
19160 prefix = ELF_STRING_ARM_unwind_info;
19161 prefix_once = ELF_STRING_ARM_unwind_info_once;
19162 type = SHT_PROGBITS;
19163 }
19164
19165 text_name = segment_name (text_seg);
19166 if (streq (text_name, ".text"))
19167 text_name = "";
19168
19169 if (strncmp (text_name, ".gnu.linkonce.t.",
19170 strlen (".gnu.linkonce.t.")) == 0)
19171 {
19172 prefix = prefix_once;
19173 text_name += strlen (".gnu.linkonce.t.");
19174 }
19175
19176 prefix_len = strlen (prefix);
19177 text_len = strlen (text_name);
19178 sec_name_len = prefix_len + text_len;
19179 sec_name = (char *) xmalloc (sec_name_len + 1);
19180 memcpy (sec_name, prefix, prefix_len);
19181 memcpy (sec_name + prefix_len, text_name, text_len);
19182 sec_name[prefix_len + text_len] = '\0';
19183
19184 flags = SHF_ALLOC;
19185 linkonce = 0;
19186 group_name = 0;
19187
19188 /* Handle COMDAT group. */
19189 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
19190 {
19191 group_name = elf_group_name (text_seg);
19192 if (group_name == NULL)
19193 {
19194 as_bad (_("Group section `%s' has no group signature"),
19195 segment_name (text_seg));
19196 ignore_rest_of_line ();
19197 return;
19198 }
19199 flags |= SHF_GROUP;
19200 linkonce = 1;
19201 }
19202
19203 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
19204
19205 /* Set the section link for index tables. */
19206 if (idx)
19207 elf_linked_to_section (now_seg) = text_seg;
19208 }
19209
19210
19211 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19212 personality routine data. Returns zero, or the index table value for
19213 and inline entry. */
19214
19215 static valueT
19216 create_unwind_entry (int have_data)
19217 {
19218 int size;
19219 addressT where;
19220 char *ptr;
19221 /* The current word of data. */
19222 valueT data;
19223 /* The number of bytes left in this word. */
19224 int n;
19225
19226 finish_unwind_opcodes ();
19227
19228 /* Remember the current text section. */
19229 unwind.saved_seg = now_seg;
19230 unwind.saved_subseg = now_subseg;
19231
19232 start_unwind_section (now_seg, 0);
19233
19234 if (unwind.personality_routine == NULL)
19235 {
19236 if (unwind.personality_index == -2)
19237 {
19238 if (have_data)
19239 as_bad (_("handlerdata in cantunwind frame"));
19240 return 1; /* EXIDX_CANTUNWIND. */
19241 }
19242
19243 /* Use a default personality routine if none is specified. */
19244 if (unwind.personality_index == -1)
19245 {
19246 if (unwind.opcode_count > 3)
19247 unwind.personality_index = 1;
19248 else
19249 unwind.personality_index = 0;
19250 }
19251
19252 /* Space for the personality routine entry. */
19253 if (unwind.personality_index == 0)
19254 {
19255 if (unwind.opcode_count > 3)
19256 as_bad (_("too many unwind opcodes for personality routine 0"));
19257
19258 if (!have_data)
19259 {
19260 /* All the data is inline in the index table. */
19261 data = 0x80;
19262 n = 3;
19263 while (unwind.opcode_count > 0)
19264 {
19265 unwind.opcode_count--;
19266 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19267 n--;
19268 }
19269
19270 /* Pad with "finish" opcodes. */
19271 while (n--)
19272 data = (data << 8) | 0xb0;
19273
19274 return data;
19275 }
19276 size = 0;
19277 }
19278 else
19279 /* We get two opcodes "free" in the first word. */
19280 size = unwind.opcode_count - 2;
19281 }
19282 else
19283 /* An extra byte is required for the opcode count. */
19284 size = unwind.opcode_count + 1;
19285
19286 size = (size + 3) >> 2;
19287 if (size > 0xff)
19288 as_bad (_("too many unwind opcodes"));
19289
19290 frag_align (2, 0, 0);
19291 record_alignment (now_seg, 2);
19292 unwind.table_entry = expr_build_dot ();
19293
19294 /* Allocate the table entry. */
19295 ptr = frag_more ((size << 2) + 4);
19296 where = frag_now_fix () - ((size << 2) + 4);
19297
19298 switch (unwind.personality_index)
19299 {
19300 case -1:
19301 /* ??? Should this be a PLT generating relocation? */
19302 /* Custom personality routine. */
19303 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19304 BFD_RELOC_ARM_PREL31);
19305
19306 where += 4;
19307 ptr += 4;
19308
19309 /* Set the first byte to the number of additional words. */
19310 data = size - 1;
19311 n = 3;
19312 break;
19313
19314 /* ABI defined personality routines. */
19315 case 0:
19316 /* Three opcodes bytes are packed into the first word. */
19317 data = 0x80;
19318 n = 3;
19319 break;
19320
19321 case 1:
19322 case 2:
19323 /* The size and first two opcode bytes go in the first word. */
19324 data = ((0x80 + unwind.personality_index) << 8) | size;
19325 n = 2;
19326 break;
19327
19328 default:
19329 /* Should never happen. */
19330 abort ();
19331 }
19332
19333 /* Pack the opcodes into words (MSB first), reversing the list at the same
19334 time. */
19335 while (unwind.opcode_count > 0)
19336 {
19337 if (n == 0)
19338 {
19339 md_number_to_chars (ptr, data, 4);
19340 ptr += 4;
19341 n = 4;
19342 data = 0;
19343 }
19344 unwind.opcode_count--;
19345 n--;
19346 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19347 }
19348
19349 /* Finish off the last word. */
19350 if (n < 4)
19351 {
19352 /* Pad with "finish" opcodes. */
19353 while (n--)
19354 data = (data << 8) | 0xb0;
19355
19356 md_number_to_chars (ptr, data, 4);
19357 }
19358
19359 if (!have_data)
19360 {
19361 /* Add an empty descriptor if there is no user-specified data. */
19362 ptr = frag_more (4);
19363 md_number_to_chars (ptr, 0, 4);
19364 }
19365
19366 return 0;
19367 }
19368
19369
19370 /* Initialize the DWARF-2 unwind information for this procedure. */
19371
19372 void
19373 tc_arm_frame_initial_instructions (void)
19374 {
19375 cfi_add_CFA_def_cfa (REG_SP, 0);
19376 }
19377 #endif /* OBJ_ELF */
19378
19379 /* Convert REGNAME to a DWARF-2 register number. */
19380
19381 int
19382 tc_arm_regname_to_dw2regnum (char *regname)
19383 {
19384 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
19385
19386 if (reg == FAIL)
19387 return -1;
19388
19389 return reg;
19390 }
19391
19392 #ifdef TE_PE
19393 void
19394 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
19395 {
19396 expressionS exp;
19397
19398 exp.X_op = O_secrel;
19399 exp.X_add_symbol = symbol;
19400 exp.X_add_number = 0;
19401 emit_expr (&exp, size);
19402 }
19403 #endif
19404
19405 /* MD interface: Symbol and relocation handling. */
19406
19407 /* Return the address within the segment that a PC-relative fixup is
19408 relative to. For ARM, PC-relative fixups applied to instructions
19409 are generally relative to the location of the fixup plus 8 bytes.
19410 Thumb branches are offset by 4, and Thumb loads relative to PC
19411 require special handling. */
19412
19413 long
19414 md_pcrel_from_section (fixS * fixP, segT seg)
19415 {
19416 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19417
19418 /* If this is pc-relative and we are going to emit a relocation
19419 then we just want to put out any pipeline compensation that the linker
19420 will need. Otherwise we want to use the calculated base.
19421 For WinCE we skip the bias for externals as well, since this
19422 is how the MS ARM-CE assembler behaves and we want to be compatible. */
19423 if (fixP->fx_pcrel
19424 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19425 || (arm_force_relocation (fixP)
19426 #ifdef TE_WINCE
19427 && !S_IS_EXTERNAL (fixP->fx_addsy)
19428 #endif
19429 )))
19430 base = 0;
19431
19432
19433 switch (fixP->fx_r_type)
19434 {
19435 /* PC relative addressing on the Thumb is slightly odd as the
19436 bottom two bits of the PC are forced to zero for the
19437 calculation. This happens *after* application of the
19438 pipeline offset. However, Thumb adrl already adjusts for
19439 this, so we need not do it again. */
19440 case BFD_RELOC_ARM_THUMB_ADD:
19441 return base & ~3;
19442
19443 case BFD_RELOC_ARM_THUMB_OFFSET:
19444 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19445 case BFD_RELOC_ARM_T32_ADD_PC12:
19446 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
19447 return (base + 4) & ~3;
19448
19449 /* Thumb branches are simply offset by +4. */
19450 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19451 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19452 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19453 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19454 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19455 return base + 4;
19456
19457 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19458 if (fixP->fx_addsy
19459 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19460 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19461 && ARM_IS_FUNC (fixP->fx_addsy)
19462 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19463 base = fixP->fx_where + fixP->fx_frag->fr_address;
19464 return base + 4;
19465
19466 /* BLX is like branches above, but forces the low two bits of PC to
19467 zero. */
19468 case BFD_RELOC_THUMB_PCREL_BLX:
19469 if (fixP->fx_addsy
19470 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19471 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19472 && THUMB_IS_FUNC (fixP->fx_addsy)
19473 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19474 base = fixP->fx_where + fixP->fx_frag->fr_address;
19475 return (base + 4) & ~3;
19476
19477 /* ARM mode branches are offset by +8. However, the Windows CE
19478 loader expects the relocation not to take this into account. */
19479 case BFD_RELOC_ARM_PCREL_BLX:
19480 if (fixP->fx_addsy
19481 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19482 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19483 && ARM_IS_FUNC (fixP->fx_addsy)
19484 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19485 base = fixP->fx_where + fixP->fx_frag->fr_address;
19486 return base + 8;
19487
19488 case BFD_RELOC_ARM_PCREL_CALL:
19489 if (fixP->fx_addsy
19490 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19491 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19492 && THUMB_IS_FUNC (fixP->fx_addsy)
19493 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19494 base = fixP->fx_where + fixP->fx_frag->fr_address;
19495 return base + 8;
19496
19497 case BFD_RELOC_ARM_PCREL_BRANCH:
19498 case BFD_RELOC_ARM_PCREL_JUMP:
19499 case BFD_RELOC_ARM_PLT32:
19500 #ifdef TE_WINCE
19501 /* When handling fixups immediately, because we have already
19502 discovered the value of a symbol, or the address of the frag involved
19503 we must account for the offset by +8, as the OS loader will never see the reloc.
19504 see fixup_segment() in write.c
19505 The S_IS_EXTERNAL test handles the case of global symbols.
19506 Those need the calculated base, not just the pipe compensation the linker will need. */
19507 if (fixP->fx_pcrel
19508 && fixP->fx_addsy != NULL
19509 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19510 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19511 return base + 8;
19512 return base;
19513 #else
19514 return base + 8;
19515 #endif
19516
19517
19518 /* ARM mode loads relative to PC are also offset by +8. Unlike
19519 branches, the Windows CE loader *does* expect the relocation
19520 to take this into account. */
19521 case BFD_RELOC_ARM_OFFSET_IMM:
19522 case BFD_RELOC_ARM_OFFSET_IMM8:
19523 case BFD_RELOC_ARM_HWLITERAL:
19524 case BFD_RELOC_ARM_LITERAL:
19525 case BFD_RELOC_ARM_CP_OFF_IMM:
19526 return base + 8;
19527
19528
19529 /* Other PC-relative relocations are un-offset. */
19530 default:
19531 return base;
19532 }
19533 }
19534
19535 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19536 Otherwise we have no need to default values of symbols. */
19537
19538 symbolS *
19539 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
19540 {
19541 #ifdef OBJ_ELF
19542 if (name[0] == '_' && name[1] == 'G'
19543 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19544 {
19545 if (!GOT_symbol)
19546 {
19547 if (symbol_find (name))
19548 as_bad (_("GOT already in the symbol table"));
19549
19550 GOT_symbol = symbol_new (name, undefined_section,
19551 (valueT) 0, & zero_address_frag);
19552 }
19553
19554 return GOT_symbol;
19555 }
19556 #endif
19557
19558 return NULL;
19559 }
19560
19561 /* Subroutine of md_apply_fix. Check to see if an immediate can be
19562 computed as two separate immediate values, added together. We
19563 already know that this value cannot be computed by just one ARM
19564 instruction. */
19565
19566 static unsigned int
19567 validate_immediate_twopart (unsigned int val,
19568 unsigned int * highpart)
19569 {
19570 unsigned int a;
19571 unsigned int i;
19572
19573 for (i = 0; i < 32; i += 2)
19574 if (((a = rotate_left (val, i)) & 0xff) != 0)
19575 {
19576 if (a & 0xff00)
19577 {
19578 if (a & ~ 0xffff)
19579 continue;
19580 * highpart = (a >> 8) | ((i + 24) << 7);
19581 }
19582 else if (a & 0xff0000)
19583 {
19584 if (a & 0xff000000)
19585 continue;
19586 * highpart = (a >> 16) | ((i + 16) << 7);
19587 }
19588 else
19589 {
19590 gas_assert (a & 0xff000000);
19591 * highpart = (a >> 24) | ((i + 8) << 7);
19592 }
19593
19594 return (a & 0xff) | (i << 7);
19595 }
19596
19597 return FAIL;
19598 }
19599
19600 static int
19601 validate_offset_imm (unsigned int val, int hwse)
19602 {
19603 if ((hwse && val > 255) || val > 4095)
19604 return FAIL;
19605 return val;
19606 }
19607
19608 /* Subroutine of md_apply_fix. Do those data_ops which can take a
19609 negative immediate constant by altering the instruction. A bit of
19610 a hack really.
19611 MOV <-> MVN
19612 AND <-> BIC
19613 ADC <-> SBC
19614 by inverting the second operand, and
19615 ADD <-> SUB
19616 CMP <-> CMN
19617 by negating the second operand. */
19618
19619 static int
19620 negate_data_op (unsigned long * instruction,
19621 unsigned long value)
19622 {
19623 int op, new_inst;
19624 unsigned long negated, inverted;
19625
19626 negated = encode_arm_immediate (-value);
19627 inverted = encode_arm_immediate (~value);
19628
19629 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19630 switch (op)
19631 {
19632 /* First negates. */
19633 case OPCODE_SUB: /* ADD <-> SUB */
19634 new_inst = OPCODE_ADD;
19635 value = negated;
19636 break;
19637
19638 case OPCODE_ADD:
19639 new_inst = OPCODE_SUB;
19640 value = negated;
19641 break;
19642
19643 case OPCODE_CMP: /* CMP <-> CMN */
19644 new_inst = OPCODE_CMN;
19645 value = negated;
19646 break;
19647
19648 case OPCODE_CMN:
19649 new_inst = OPCODE_CMP;
19650 value = negated;
19651 break;
19652
19653 /* Now Inverted ops. */
19654 case OPCODE_MOV: /* MOV <-> MVN */
19655 new_inst = OPCODE_MVN;
19656 value = inverted;
19657 break;
19658
19659 case OPCODE_MVN:
19660 new_inst = OPCODE_MOV;
19661 value = inverted;
19662 break;
19663
19664 case OPCODE_AND: /* AND <-> BIC */
19665 new_inst = OPCODE_BIC;
19666 value = inverted;
19667 break;
19668
19669 case OPCODE_BIC:
19670 new_inst = OPCODE_AND;
19671 value = inverted;
19672 break;
19673
19674 case OPCODE_ADC: /* ADC <-> SBC */
19675 new_inst = OPCODE_SBC;
19676 value = inverted;
19677 break;
19678
19679 case OPCODE_SBC:
19680 new_inst = OPCODE_ADC;
19681 value = inverted;
19682 break;
19683
19684 /* We cannot do anything. */
19685 default:
19686 return FAIL;
19687 }
19688
19689 if (value == (unsigned) FAIL)
19690 return FAIL;
19691
19692 *instruction &= OPCODE_MASK;
19693 *instruction |= new_inst << DATA_OP_SHIFT;
19694 return value;
19695 }
19696
19697 /* Like negate_data_op, but for Thumb-2. */
19698
19699 static unsigned int
19700 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
19701 {
19702 int op, new_inst;
19703 int rd;
19704 unsigned int negated, inverted;
19705
19706 negated = encode_thumb32_immediate (-value);
19707 inverted = encode_thumb32_immediate (~value);
19708
19709 rd = (*instruction >> 8) & 0xf;
19710 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19711 switch (op)
19712 {
19713 /* ADD <-> SUB. Includes CMP <-> CMN. */
19714 case T2_OPCODE_SUB:
19715 new_inst = T2_OPCODE_ADD;
19716 value = negated;
19717 break;
19718
19719 case T2_OPCODE_ADD:
19720 new_inst = T2_OPCODE_SUB;
19721 value = negated;
19722 break;
19723
19724 /* ORR <-> ORN. Includes MOV <-> MVN. */
19725 case T2_OPCODE_ORR:
19726 new_inst = T2_OPCODE_ORN;
19727 value = inverted;
19728 break;
19729
19730 case T2_OPCODE_ORN:
19731 new_inst = T2_OPCODE_ORR;
19732 value = inverted;
19733 break;
19734
19735 /* AND <-> BIC. TST has no inverted equivalent. */
19736 case T2_OPCODE_AND:
19737 new_inst = T2_OPCODE_BIC;
19738 if (rd == 15)
19739 value = FAIL;
19740 else
19741 value = inverted;
19742 break;
19743
19744 case T2_OPCODE_BIC:
19745 new_inst = T2_OPCODE_AND;
19746 value = inverted;
19747 break;
19748
19749 /* ADC <-> SBC */
19750 case T2_OPCODE_ADC:
19751 new_inst = T2_OPCODE_SBC;
19752 value = inverted;
19753 break;
19754
19755 case T2_OPCODE_SBC:
19756 new_inst = T2_OPCODE_ADC;
19757 value = inverted;
19758 break;
19759
19760 /* We cannot do anything. */
19761 default:
19762 return FAIL;
19763 }
19764
19765 if (value == (unsigned int)FAIL)
19766 return FAIL;
19767
19768 *instruction &= T2_OPCODE_MASK;
19769 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19770 return value;
19771 }
19772
19773 /* Read a 32-bit thumb instruction from buf. */
19774 static unsigned long
19775 get_thumb32_insn (char * buf)
19776 {
19777 unsigned long insn;
19778 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19779 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19780
19781 return insn;
19782 }
19783
19784
19785 /* We usually want to set the low bit on the address of thumb function
19786 symbols. In particular .word foo - . should have the low bit set.
19787 Generic code tries to fold the difference of two symbols to
19788 a constant. Prevent this and force a relocation when the first symbols
19789 is a thumb function. */
19790
19791 bfd_boolean
19792 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19793 {
19794 if (op == O_subtract
19795 && l->X_op == O_symbol
19796 && r->X_op == O_symbol
19797 && THUMB_IS_FUNC (l->X_add_symbol))
19798 {
19799 l->X_op = O_subtract;
19800 l->X_op_symbol = r->X_add_symbol;
19801 l->X_add_number -= r->X_add_number;
19802 return TRUE;
19803 }
19804
19805 /* Process as normal. */
19806 return FALSE;
19807 }
19808
19809 /* Encode Thumb2 unconditional branches and calls. The encoding
19810 for the 2 are identical for the immediate values. */
19811
19812 static void
19813 encode_thumb2_b_bl_offset (char * buf, offsetT value)
19814 {
19815 #define T2I1I2MASK ((1 << 13) | (1 << 11))
19816 offsetT newval;
19817 offsetT newval2;
19818 addressT S, I1, I2, lo, hi;
19819
19820 S = (value >> 24) & 0x01;
19821 I1 = (value >> 23) & 0x01;
19822 I2 = (value >> 22) & 0x01;
19823 hi = (value >> 12) & 0x3ff;
19824 lo = (value >> 1) & 0x7ff;
19825 newval = md_chars_to_number (buf, THUMB_SIZE);
19826 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19827 newval |= (S << 10) | hi;
19828 newval2 &= ~T2I1I2MASK;
19829 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19830 md_number_to_chars (buf, newval, THUMB_SIZE);
19831 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19832 }
19833
19834 void
19835 md_apply_fix (fixS * fixP,
19836 valueT * valP,
19837 segT seg)
19838 {
19839 offsetT value = * valP;
19840 offsetT newval;
19841 unsigned int newimm;
19842 unsigned long temp;
19843 int sign;
19844 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
19845
19846 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
19847
19848 /* Note whether this will delete the relocation. */
19849
19850 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19851 fixP->fx_done = 1;
19852
19853 /* On a 64-bit host, silently truncate 'value' to 32 bits for
19854 consistency with the behaviour on 32-bit hosts. Remember value
19855 for emit_reloc. */
19856 value &= 0xffffffff;
19857 value ^= 0x80000000;
19858 value -= 0x80000000;
19859
19860 *valP = value;
19861 fixP->fx_addnumber = value;
19862
19863 /* Same treatment for fixP->fx_offset. */
19864 fixP->fx_offset &= 0xffffffff;
19865 fixP->fx_offset ^= 0x80000000;
19866 fixP->fx_offset -= 0x80000000;
19867
19868 switch (fixP->fx_r_type)
19869 {
19870 case BFD_RELOC_NONE:
19871 /* This will need to go in the object file. */
19872 fixP->fx_done = 0;
19873 break;
19874
19875 case BFD_RELOC_ARM_IMMEDIATE:
19876 /* We claim that this fixup has been processed here,
19877 even if in fact we generate an error because we do
19878 not have a reloc for it, so tc_gen_reloc will reject it. */
19879 fixP->fx_done = 1;
19880
19881 if (fixP->fx_addsy)
19882 {
19883 const char *msg = 0;
19884
19885 if (! S_IS_DEFINED (fixP->fx_addsy))
19886 msg = _("undefined symbol %s used as an immediate value");
19887 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19888 msg = _("symbol %s is in a different section");
19889 else if (S_IS_WEAK (fixP->fx_addsy))
19890 msg = _("symbol %s is weak and may be overridden later");
19891
19892 if (msg)
19893 {
19894 as_bad_where (fixP->fx_file, fixP->fx_line,
19895 msg, S_GET_NAME (fixP->fx_addsy));
19896 break;
19897 }
19898 }
19899
19900 newimm = encode_arm_immediate (value);
19901 temp = md_chars_to_number (buf, INSN_SIZE);
19902
19903 /* If the instruction will fail, see if we can fix things up by
19904 changing the opcode. */
19905 if (newimm == (unsigned int) FAIL
19906 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
19907 {
19908 as_bad_where (fixP->fx_file, fixP->fx_line,
19909 _("invalid constant (%lx) after fixup"),
19910 (unsigned long) value);
19911 break;
19912 }
19913
19914 newimm |= (temp & 0xfffff000);
19915 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19916 break;
19917
19918 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19919 {
19920 unsigned int highpart = 0;
19921 unsigned int newinsn = 0xe1a00000; /* nop. */
19922
19923 if (fixP->fx_addsy)
19924 {
19925 const char *msg = 0;
19926
19927 if (! S_IS_DEFINED (fixP->fx_addsy))
19928 msg = _("undefined symbol %s used as an immediate value");
19929 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19930 msg = _("symbol %s is in a different section");
19931 else if (S_IS_WEAK (fixP->fx_addsy))
19932 msg = _("symbol %s is weak and may be overridden later");
19933
19934 if (msg)
19935 {
19936 as_bad_where (fixP->fx_file, fixP->fx_line,
19937 msg, S_GET_NAME (fixP->fx_addsy));
19938 break;
19939 }
19940 }
19941
19942 newimm = encode_arm_immediate (value);
19943 temp = md_chars_to_number (buf, INSN_SIZE);
19944
19945 /* If the instruction will fail, see if we can fix things up by
19946 changing the opcode. */
19947 if (newimm == (unsigned int) FAIL
19948 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19949 {
19950 /* No ? OK - try using two ADD instructions to generate
19951 the value. */
19952 newimm = validate_immediate_twopart (value, & highpart);
19953
19954 /* Yes - then make sure that the second instruction is
19955 also an add. */
19956 if (newimm != (unsigned int) FAIL)
19957 newinsn = temp;
19958 /* Still No ? Try using a negated value. */
19959 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19960 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19961 /* Otherwise - give up. */
19962 else
19963 {
19964 as_bad_where (fixP->fx_file, fixP->fx_line,
19965 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19966 (long) value);
19967 break;
19968 }
19969
19970 /* Replace the first operand in the 2nd instruction (which
19971 is the PC) with the destination register. We have
19972 already added in the PC in the first instruction and we
19973 do not want to do it again. */
19974 newinsn &= ~ 0xf0000;
19975 newinsn |= ((newinsn & 0x0f000) << 4);
19976 }
19977
19978 newimm |= (temp & 0xfffff000);
19979 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19980
19981 highpart |= (newinsn & 0xfffff000);
19982 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19983 }
19984 break;
19985
19986 case BFD_RELOC_ARM_OFFSET_IMM:
19987 if (!fixP->fx_done && seg->use_rela_p)
19988 value = 0;
19989
19990 case BFD_RELOC_ARM_LITERAL:
19991 sign = value >= 0;
19992
19993 if (value < 0)
19994 value = - value;
19995
19996 if (validate_offset_imm (value, 0) == FAIL)
19997 {
19998 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19999 as_bad_where (fixP->fx_file, fixP->fx_line,
20000 _("invalid literal constant: pool needs to be closer"));
20001 else
20002 as_bad_where (fixP->fx_file, fixP->fx_line,
20003 _("bad immediate value for offset (%ld)"),
20004 (long) value);
20005 break;
20006 }
20007
20008 newval = md_chars_to_number (buf, INSN_SIZE);
20009 newval &= 0xff7ff000;
20010 newval |= value | (sign ? INDEX_UP : 0);
20011 md_number_to_chars (buf, newval, INSN_SIZE);
20012 break;
20013
20014 case BFD_RELOC_ARM_OFFSET_IMM8:
20015 case BFD_RELOC_ARM_HWLITERAL:
20016 sign = value >= 0;
20017
20018 if (value < 0)
20019 value = - value;
20020
20021 if (validate_offset_imm (value, 1) == FAIL)
20022 {
20023 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
20024 as_bad_where (fixP->fx_file, fixP->fx_line,
20025 _("invalid literal constant: pool needs to be closer"));
20026 else
20027 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
20028 (long) value);
20029 break;
20030 }
20031
20032 newval = md_chars_to_number (buf, INSN_SIZE);
20033 newval &= 0xff7ff0f0;
20034 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
20035 md_number_to_chars (buf, newval, INSN_SIZE);
20036 break;
20037
20038 case BFD_RELOC_ARM_T32_OFFSET_U8:
20039 if (value < 0 || value > 1020 || value % 4 != 0)
20040 as_bad_where (fixP->fx_file, fixP->fx_line,
20041 _("bad immediate value for offset (%ld)"), (long) value);
20042 value /= 4;
20043
20044 newval = md_chars_to_number (buf+2, THUMB_SIZE);
20045 newval |= value;
20046 md_number_to_chars (buf+2, newval, THUMB_SIZE);
20047 break;
20048
20049 case BFD_RELOC_ARM_T32_OFFSET_IMM:
20050 /* This is a complicated relocation used for all varieties of Thumb32
20051 load/store instruction with immediate offset:
20052
20053 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
20054 *4, optional writeback(W)
20055 (doubleword load/store)
20056
20057 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
20058 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
20059 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
20060 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
20061 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
20062
20063 Uppercase letters indicate bits that are already encoded at
20064 this point. Lowercase letters are our problem. For the
20065 second block of instructions, the secondary opcode nybble
20066 (bits 8..11) is present, and bit 23 is zero, even if this is
20067 a PC-relative operation. */
20068 newval = md_chars_to_number (buf, THUMB_SIZE);
20069 newval <<= 16;
20070 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
20071
20072 if ((newval & 0xf0000000) == 0xe0000000)
20073 {
20074 /* Doubleword load/store: 8-bit offset, scaled by 4. */
20075 if (value >= 0)
20076 newval |= (1 << 23);
20077 else
20078 value = -value;
20079 if (value % 4 != 0)
20080 {
20081 as_bad_where (fixP->fx_file, fixP->fx_line,
20082 _("offset not a multiple of 4"));
20083 break;
20084 }
20085 value /= 4;
20086 if (value > 0xff)
20087 {
20088 as_bad_where (fixP->fx_file, fixP->fx_line,
20089 _("offset out of range"));
20090 break;
20091 }
20092 newval &= ~0xff;
20093 }
20094 else if ((newval & 0x000f0000) == 0x000f0000)
20095 {
20096 /* PC-relative, 12-bit offset. */
20097 if (value >= 0)
20098 newval |= (1 << 23);
20099 else
20100 value = -value;
20101 if (value > 0xfff)
20102 {
20103 as_bad_where (fixP->fx_file, fixP->fx_line,
20104 _("offset out of range"));
20105 break;
20106 }
20107 newval &= ~0xfff;
20108 }
20109 else if ((newval & 0x00000100) == 0x00000100)
20110 {
20111 /* Writeback: 8-bit, +/- offset. */
20112 if (value >= 0)
20113 newval |= (1 << 9);
20114 else
20115 value = -value;
20116 if (value > 0xff)
20117 {
20118 as_bad_where (fixP->fx_file, fixP->fx_line,
20119 _("offset out of range"));
20120 break;
20121 }
20122 newval &= ~0xff;
20123 }
20124 else if ((newval & 0x00000f00) == 0x00000e00)
20125 {
20126 /* T-instruction: positive 8-bit offset. */
20127 if (value < 0 || value > 0xff)
20128 {
20129 as_bad_where (fixP->fx_file, fixP->fx_line,
20130 _("offset out of range"));
20131 break;
20132 }
20133 newval &= ~0xff;
20134 newval |= value;
20135 }
20136 else
20137 {
20138 /* Positive 12-bit or negative 8-bit offset. */
20139 int limit;
20140 if (value >= 0)
20141 {
20142 newval |= (1 << 23);
20143 limit = 0xfff;
20144 }
20145 else
20146 {
20147 value = -value;
20148 limit = 0xff;
20149 }
20150 if (value > limit)
20151 {
20152 as_bad_where (fixP->fx_file, fixP->fx_line,
20153 _("offset out of range"));
20154 break;
20155 }
20156 newval &= ~limit;
20157 }
20158
20159 newval |= value;
20160 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20161 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20162 break;
20163
20164 case BFD_RELOC_ARM_SHIFT_IMM:
20165 newval = md_chars_to_number (buf, INSN_SIZE);
20166 if (((unsigned long) value) > 32
20167 || (value == 32
20168 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20169 {
20170 as_bad_where (fixP->fx_file, fixP->fx_line,
20171 _("shift expression is too large"));
20172 break;
20173 }
20174
20175 if (value == 0)
20176 /* Shifts of zero must be done as lsl. */
20177 newval &= ~0x60;
20178 else if (value == 32)
20179 value = 0;
20180 newval &= 0xfffff07f;
20181 newval |= (value & 0x1f) << 7;
20182 md_number_to_chars (buf, newval, INSN_SIZE);
20183 break;
20184
20185 case BFD_RELOC_ARM_T32_IMMEDIATE:
20186 case BFD_RELOC_ARM_T32_ADD_IMM:
20187 case BFD_RELOC_ARM_T32_IMM12:
20188 case BFD_RELOC_ARM_T32_ADD_PC12:
20189 /* We claim that this fixup has been processed here,
20190 even if in fact we generate an error because we do
20191 not have a reloc for it, so tc_gen_reloc will reject it. */
20192 fixP->fx_done = 1;
20193
20194 if (fixP->fx_addsy
20195 && ! S_IS_DEFINED (fixP->fx_addsy))
20196 {
20197 as_bad_where (fixP->fx_file, fixP->fx_line,
20198 _("undefined symbol %s used as an immediate value"),
20199 S_GET_NAME (fixP->fx_addsy));
20200 break;
20201 }
20202
20203 newval = md_chars_to_number (buf, THUMB_SIZE);
20204 newval <<= 16;
20205 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
20206
20207 newimm = FAIL;
20208 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20209 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20210 {
20211 newimm = encode_thumb32_immediate (value);
20212 if (newimm == (unsigned int) FAIL)
20213 newimm = thumb32_negate_data_op (&newval, value);
20214 }
20215 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20216 && newimm == (unsigned int) FAIL)
20217 {
20218 /* Turn add/sum into addw/subw. */
20219 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20220 newval = (newval & 0xfeffffff) | 0x02000000;
20221
20222 /* 12 bit immediate for addw/subw. */
20223 if (value < 0)
20224 {
20225 value = -value;
20226 newval ^= 0x00a00000;
20227 }
20228 if (value > 0xfff)
20229 newimm = (unsigned int) FAIL;
20230 else
20231 newimm = value;
20232 }
20233
20234 if (newimm == (unsigned int)FAIL)
20235 {
20236 as_bad_where (fixP->fx_file, fixP->fx_line,
20237 _("invalid constant (%lx) after fixup"),
20238 (unsigned long) value);
20239 break;
20240 }
20241
20242 newval |= (newimm & 0x800) << 15;
20243 newval |= (newimm & 0x700) << 4;
20244 newval |= (newimm & 0x0ff);
20245
20246 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20247 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20248 break;
20249
20250 case BFD_RELOC_ARM_SMC:
20251 if (((unsigned long) value) > 0xffff)
20252 as_bad_where (fixP->fx_file, fixP->fx_line,
20253 _("invalid smc expression"));
20254 newval = md_chars_to_number (buf, INSN_SIZE);
20255 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20256 md_number_to_chars (buf, newval, INSN_SIZE);
20257 break;
20258
20259 case BFD_RELOC_ARM_SWI:
20260 if (fixP->tc_fix_data != 0)
20261 {
20262 if (((unsigned long) value) > 0xff)
20263 as_bad_where (fixP->fx_file, fixP->fx_line,
20264 _("invalid swi expression"));
20265 newval = md_chars_to_number (buf, THUMB_SIZE);
20266 newval |= value;
20267 md_number_to_chars (buf, newval, THUMB_SIZE);
20268 }
20269 else
20270 {
20271 if (((unsigned long) value) > 0x00ffffff)
20272 as_bad_where (fixP->fx_file, fixP->fx_line,
20273 _("invalid swi expression"));
20274 newval = md_chars_to_number (buf, INSN_SIZE);
20275 newval |= value;
20276 md_number_to_chars (buf, newval, INSN_SIZE);
20277 }
20278 break;
20279
20280 case BFD_RELOC_ARM_MULTI:
20281 if (((unsigned long) value) > 0xffff)
20282 as_bad_where (fixP->fx_file, fixP->fx_line,
20283 _("invalid expression in load/store multiple"));
20284 newval = value | md_chars_to_number (buf, INSN_SIZE);
20285 md_number_to_chars (buf, newval, INSN_SIZE);
20286 break;
20287
20288 #ifdef OBJ_ELF
20289 case BFD_RELOC_ARM_PCREL_CALL:
20290
20291 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20292 && fixP->fx_addsy
20293 && !S_IS_EXTERNAL (fixP->fx_addsy)
20294 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20295 && THUMB_IS_FUNC (fixP->fx_addsy))
20296 /* Flip the bl to blx. This is a simple flip
20297 bit here because we generate PCREL_CALL for
20298 unconditional bls. */
20299 {
20300 newval = md_chars_to_number (buf, INSN_SIZE);
20301 newval = newval | 0x10000000;
20302 md_number_to_chars (buf, newval, INSN_SIZE);
20303 temp = 1;
20304 fixP->fx_done = 1;
20305 }
20306 else
20307 temp = 3;
20308 goto arm_branch_common;
20309
20310 case BFD_RELOC_ARM_PCREL_JUMP:
20311 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20312 && fixP->fx_addsy
20313 && !S_IS_EXTERNAL (fixP->fx_addsy)
20314 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20315 && THUMB_IS_FUNC (fixP->fx_addsy))
20316 {
20317 /* This would map to a bl<cond>, b<cond>,
20318 b<always> to a Thumb function. We
20319 need to force a relocation for this particular
20320 case. */
20321 newval = md_chars_to_number (buf, INSN_SIZE);
20322 fixP->fx_done = 0;
20323 }
20324
20325 case BFD_RELOC_ARM_PLT32:
20326 #endif
20327 case BFD_RELOC_ARM_PCREL_BRANCH:
20328 temp = 3;
20329 goto arm_branch_common;
20330
20331 case BFD_RELOC_ARM_PCREL_BLX:
20332
20333 temp = 1;
20334 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20335 && fixP->fx_addsy
20336 && !S_IS_EXTERNAL (fixP->fx_addsy)
20337 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20338 && ARM_IS_FUNC (fixP->fx_addsy))
20339 {
20340 /* Flip the blx to a bl and warn. */
20341 const char *name = S_GET_NAME (fixP->fx_addsy);
20342 newval = 0xeb000000;
20343 as_warn_where (fixP->fx_file, fixP->fx_line,
20344 _("blx to '%s' an ARM ISA state function changed to bl"),
20345 name);
20346 md_number_to_chars (buf, newval, INSN_SIZE);
20347 temp = 3;
20348 fixP->fx_done = 1;
20349 }
20350
20351 #ifdef OBJ_ELF
20352 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20353 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20354 #endif
20355
20356 arm_branch_common:
20357 /* We are going to store value (shifted right by two) in the
20358 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20359 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20360 also be be clear. */
20361 if (value & temp)
20362 as_bad_where (fixP->fx_file, fixP->fx_line,
20363 _("misaligned branch destination"));
20364 if ((value & (offsetT)0xfe000000) != (offsetT)0
20365 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20366 as_bad_where (fixP->fx_file, fixP->fx_line,
20367 _("branch out of range"));
20368
20369 if (fixP->fx_done || !seg->use_rela_p)
20370 {
20371 newval = md_chars_to_number (buf, INSN_SIZE);
20372 newval |= (value >> 2) & 0x00ffffff;
20373 /* Set the H bit on BLX instructions. */
20374 if (temp == 1)
20375 {
20376 if (value & 2)
20377 newval |= 0x01000000;
20378 else
20379 newval &= ~0x01000000;
20380 }
20381 md_number_to_chars (buf, newval, INSN_SIZE);
20382 }
20383 break;
20384
20385 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20386 /* CBZ can only branch forward. */
20387
20388 /* Attempts to use CBZ to branch to the next instruction
20389 (which, strictly speaking, are prohibited) will be turned into
20390 no-ops.
20391
20392 FIXME: It may be better to remove the instruction completely and
20393 perform relaxation. */
20394 if (value == -2)
20395 {
20396 newval = md_chars_to_number (buf, THUMB_SIZE);
20397 newval = 0xbf00; /* NOP encoding T1 */
20398 md_number_to_chars (buf, newval, THUMB_SIZE);
20399 }
20400 else
20401 {
20402 if (value & ~0x7e)
20403 as_bad_where (fixP->fx_file, fixP->fx_line,
20404 _("branch out of range"));
20405
20406 if (fixP->fx_done || !seg->use_rela_p)
20407 {
20408 newval = md_chars_to_number (buf, THUMB_SIZE);
20409 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20410 md_number_to_chars (buf, newval, THUMB_SIZE);
20411 }
20412 }
20413 break;
20414
20415 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
20416 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20417 as_bad_where (fixP->fx_file, fixP->fx_line,
20418 _("branch out of range"));
20419
20420 if (fixP->fx_done || !seg->use_rela_p)
20421 {
20422 newval = md_chars_to_number (buf, THUMB_SIZE);
20423 newval |= (value & 0x1ff) >> 1;
20424 md_number_to_chars (buf, newval, THUMB_SIZE);
20425 }
20426 break;
20427
20428 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
20429 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20430 as_bad_where (fixP->fx_file, fixP->fx_line,
20431 _("branch out of range"));
20432
20433 if (fixP->fx_done || !seg->use_rela_p)
20434 {
20435 newval = md_chars_to_number (buf, THUMB_SIZE);
20436 newval |= (value & 0xfff) >> 1;
20437 md_number_to_chars (buf, newval, THUMB_SIZE);
20438 }
20439 break;
20440
20441 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20442 if (fixP->fx_addsy
20443 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20444 && !S_IS_EXTERNAL (fixP->fx_addsy)
20445 && S_IS_DEFINED (fixP->fx_addsy)
20446 && ARM_IS_FUNC (fixP->fx_addsy)
20447 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20448 {
20449 /* Force a relocation for a branch 20 bits wide. */
20450 fixP->fx_done = 0;
20451 }
20452 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20453 as_bad_where (fixP->fx_file, fixP->fx_line,
20454 _("conditional branch out of range"));
20455
20456 if (fixP->fx_done || !seg->use_rela_p)
20457 {
20458 offsetT newval2;
20459 addressT S, J1, J2, lo, hi;
20460
20461 S = (value & 0x00100000) >> 20;
20462 J2 = (value & 0x00080000) >> 19;
20463 J1 = (value & 0x00040000) >> 18;
20464 hi = (value & 0x0003f000) >> 12;
20465 lo = (value & 0x00000ffe) >> 1;
20466
20467 newval = md_chars_to_number (buf, THUMB_SIZE);
20468 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20469 newval |= (S << 10) | hi;
20470 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20471 md_number_to_chars (buf, newval, THUMB_SIZE);
20472 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20473 }
20474 break;
20475
20476 case BFD_RELOC_THUMB_PCREL_BLX:
20477
20478 /* If there is a blx from a thumb state function to
20479 another thumb function flip this to a bl and warn
20480 about it. */
20481
20482 if (fixP->fx_addsy
20483 && S_IS_DEFINED (fixP->fx_addsy)
20484 && !S_IS_EXTERNAL (fixP->fx_addsy)
20485 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20486 && THUMB_IS_FUNC (fixP->fx_addsy))
20487 {
20488 const char *name = S_GET_NAME (fixP->fx_addsy);
20489 as_warn_where (fixP->fx_file, fixP->fx_line,
20490 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20491 name);
20492 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20493 newval = newval | 0x1000;
20494 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20495 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20496 fixP->fx_done = 1;
20497 }
20498
20499
20500 goto thumb_bl_common;
20501
20502 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20503
20504 /* A bl from Thumb state ISA to an internal ARM state function
20505 is converted to a blx. */
20506 if (fixP->fx_addsy
20507 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20508 && !S_IS_EXTERNAL (fixP->fx_addsy)
20509 && S_IS_DEFINED (fixP->fx_addsy)
20510 && ARM_IS_FUNC (fixP->fx_addsy)
20511 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20512 {
20513 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20514 newval = newval & ~0x1000;
20515 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20516 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20517 fixP->fx_done = 1;
20518 }
20519
20520 thumb_bl_common:
20521
20522 #ifdef OBJ_ELF
20523 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20524 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20525 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20526 #endif
20527
20528 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20529 /* For a BLX instruction, make sure that the relocation is rounded up
20530 to a word boundary. This follows the semantics of the instruction
20531 which specifies that bit 1 of the target address will come from bit
20532 1 of the base address. */
20533 value = (value + 1) & ~ 1;
20534
20535
20536 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20537 {
20538 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20539 {
20540 as_bad_where (fixP->fx_file, fixP->fx_line,
20541 _("branch out of range"));
20542 }
20543 else if ((value & ~0x1ffffff)
20544 && ((value & ~0x1ffffff) != ~0x1ffffff))
20545 {
20546 as_bad_where (fixP->fx_file, fixP->fx_line,
20547 _("Thumb2 branch out of range"));
20548 }
20549 }
20550
20551 if (fixP->fx_done || !seg->use_rela_p)
20552 encode_thumb2_b_bl_offset (buf, value);
20553
20554 break;
20555
20556 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20557 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20558 as_bad_where (fixP->fx_file, fixP->fx_line,
20559 _("branch out of range"));
20560
20561 if (fixP->fx_done || !seg->use_rela_p)
20562 encode_thumb2_b_bl_offset (buf, value);
20563
20564 break;
20565
20566 case BFD_RELOC_8:
20567 if (fixP->fx_done || !seg->use_rela_p)
20568 md_number_to_chars (buf, value, 1);
20569 break;
20570
20571 case BFD_RELOC_16:
20572 if (fixP->fx_done || !seg->use_rela_p)
20573 md_number_to_chars (buf, value, 2);
20574 break;
20575
20576 #ifdef OBJ_ELF
20577 case BFD_RELOC_ARM_TLS_GD32:
20578 case BFD_RELOC_ARM_TLS_LE32:
20579 case BFD_RELOC_ARM_TLS_IE32:
20580 case BFD_RELOC_ARM_TLS_LDM32:
20581 case BFD_RELOC_ARM_TLS_LDO32:
20582 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20583 /* fall through */
20584
20585 case BFD_RELOC_ARM_GOT32:
20586 case BFD_RELOC_ARM_GOTOFF:
20587 if (fixP->fx_done || !seg->use_rela_p)
20588 md_number_to_chars (buf, 0, 4);
20589 break;
20590
20591 case BFD_RELOC_ARM_GOT_PREL:
20592 if (fixP->fx_done || !seg->use_rela_p)
20593 md_number_to_chars (buf, value, 4);
20594 break;
20595
20596 case BFD_RELOC_ARM_TARGET2:
20597 /* TARGET2 is not partial-inplace, so we need to write the
20598 addend here for REL targets, because it won't be written out
20599 during reloc processing later. */
20600 if (fixP->fx_done || !seg->use_rela_p)
20601 md_number_to_chars (buf, fixP->fx_offset, 4);
20602 break;
20603 #endif
20604
20605 case BFD_RELOC_RVA:
20606 case BFD_RELOC_32:
20607 case BFD_RELOC_ARM_TARGET1:
20608 case BFD_RELOC_ARM_ROSEGREL32:
20609 case BFD_RELOC_ARM_SBREL32:
20610 case BFD_RELOC_32_PCREL:
20611 #ifdef TE_PE
20612 case BFD_RELOC_32_SECREL:
20613 #endif
20614 if (fixP->fx_done || !seg->use_rela_p)
20615 #ifdef TE_WINCE
20616 /* For WinCE we only do this for pcrel fixups. */
20617 if (fixP->fx_done || fixP->fx_pcrel)
20618 #endif
20619 md_number_to_chars (buf, value, 4);
20620 break;
20621
20622 #ifdef OBJ_ELF
20623 case BFD_RELOC_ARM_PREL31:
20624 if (fixP->fx_done || !seg->use_rela_p)
20625 {
20626 newval = md_chars_to_number (buf, 4) & 0x80000000;
20627 if ((value ^ (value >> 1)) & 0x40000000)
20628 {
20629 as_bad_where (fixP->fx_file, fixP->fx_line,
20630 _("rel31 relocation overflow"));
20631 }
20632 newval |= value & 0x7fffffff;
20633 md_number_to_chars (buf, newval, 4);
20634 }
20635 break;
20636 #endif
20637
20638 case BFD_RELOC_ARM_CP_OFF_IMM:
20639 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20640 if (value < -1023 || value > 1023 || (value & 3))
20641 as_bad_where (fixP->fx_file, fixP->fx_line,
20642 _("co-processor offset out of range"));
20643 cp_off_common:
20644 sign = value >= 0;
20645 if (value < 0)
20646 value = -value;
20647 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20648 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20649 newval = md_chars_to_number (buf, INSN_SIZE);
20650 else
20651 newval = get_thumb32_insn (buf);
20652 newval &= 0xff7fff00;
20653 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
20654 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20655 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20656 md_number_to_chars (buf, newval, INSN_SIZE);
20657 else
20658 put_thumb32_insn (buf, newval);
20659 break;
20660
20661 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
20662 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
20663 if (value < -255 || value > 255)
20664 as_bad_where (fixP->fx_file, fixP->fx_line,
20665 _("co-processor offset out of range"));
20666 value *= 4;
20667 goto cp_off_common;
20668
20669 case BFD_RELOC_ARM_THUMB_OFFSET:
20670 newval = md_chars_to_number (buf, THUMB_SIZE);
20671 /* Exactly what ranges, and where the offset is inserted depends
20672 on the type of instruction, we can establish this from the
20673 top 4 bits. */
20674 switch (newval >> 12)
20675 {
20676 case 4: /* PC load. */
20677 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20678 forced to zero for these loads; md_pcrel_from has already
20679 compensated for this. */
20680 if (value & 3)
20681 as_bad_where (fixP->fx_file, fixP->fx_line,
20682 _("invalid offset, target not word aligned (0x%08lX)"),
20683 (((unsigned long) fixP->fx_frag->fr_address
20684 + (unsigned long) fixP->fx_where) & ~3)
20685 + (unsigned long) value);
20686
20687 if (value & ~0x3fc)
20688 as_bad_where (fixP->fx_file, fixP->fx_line,
20689 _("invalid offset, value too big (0x%08lX)"),
20690 (long) value);
20691
20692 newval |= value >> 2;
20693 break;
20694
20695 case 9: /* SP load/store. */
20696 if (value & ~0x3fc)
20697 as_bad_where (fixP->fx_file, fixP->fx_line,
20698 _("invalid offset, value too big (0x%08lX)"),
20699 (long) value);
20700 newval |= value >> 2;
20701 break;
20702
20703 case 6: /* Word load/store. */
20704 if (value & ~0x7c)
20705 as_bad_where (fixP->fx_file, fixP->fx_line,
20706 _("invalid offset, value too big (0x%08lX)"),
20707 (long) value);
20708 newval |= value << 4; /* 6 - 2. */
20709 break;
20710
20711 case 7: /* Byte load/store. */
20712 if (value & ~0x1f)
20713 as_bad_where (fixP->fx_file, fixP->fx_line,
20714 _("invalid offset, value too big (0x%08lX)"),
20715 (long) value);
20716 newval |= value << 6;
20717 break;
20718
20719 case 8: /* Halfword load/store. */
20720 if (value & ~0x3e)
20721 as_bad_where (fixP->fx_file, fixP->fx_line,
20722 _("invalid offset, value too big (0x%08lX)"),
20723 (long) value);
20724 newval |= value << 5; /* 6 - 1. */
20725 break;
20726
20727 default:
20728 as_bad_where (fixP->fx_file, fixP->fx_line,
20729 "Unable to process relocation for thumb opcode: %lx",
20730 (unsigned long) newval);
20731 break;
20732 }
20733 md_number_to_chars (buf, newval, THUMB_SIZE);
20734 break;
20735
20736 case BFD_RELOC_ARM_THUMB_ADD:
20737 /* This is a complicated relocation, since we use it for all of
20738 the following immediate relocations:
20739
20740 3bit ADD/SUB
20741 8bit ADD/SUB
20742 9bit ADD/SUB SP word-aligned
20743 10bit ADD PC/SP word-aligned
20744
20745 The type of instruction being processed is encoded in the
20746 instruction field:
20747
20748 0x8000 SUB
20749 0x00F0 Rd
20750 0x000F Rs
20751 */
20752 newval = md_chars_to_number (buf, THUMB_SIZE);
20753 {
20754 int rd = (newval >> 4) & 0xf;
20755 int rs = newval & 0xf;
20756 int subtract = !!(newval & 0x8000);
20757
20758 /* Check for HI regs, only very restricted cases allowed:
20759 Adjusting SP, and using PC or SP to get an address. */
20760 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20761 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20762 as_bad_where (fixP->fx_file, fixP->fx_line,
20763 _("invalid Hi register with immediate"));
20764
20765 /* If value is negative, choose the opposite instruction. */
20766 if (value < 0)
20767 {
20768 value = -value;
20769 subtract = !subtract;
20770 if (value < 0)
20771 as_bad_where (fixP->fx_file, fixP->fx_line,
20772 _("immediate value out of range"));
20773 }
20774
20775 if (rd == REG_SP)
20776 {
20777 if (value & ~0x1fc)
20778 as_bad_where (fixP->fx_file, fixP->fx_line,
20779 _("invalid immediate for stack address calculation"));
20780 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20781 newval |= value >> 2;
20782 }
20783 else if (rs == REG_PC || rs == REG_SP)
20784 {
20785 if (subtract || value & ~0x3fc)
20786 as_bad_where (fixP->fx_file, fixP->fx_line,
20787 _("invalid immediate for address calculation (value = 0x%08lX)"),
20788 (unsigned long) value);
20789 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20790 newval |= rd << 8;
20791 newval |= value >> 2;
20792 }
20793 else if (rs == rd)
20794 {
20795 if (value & ~0xff)
20796 as_bad_where (fixP->fx_file, fixP->fx_line,
20797 _("immediate value out of range"));
20798 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20799 newval |= (rd << 8) | value;
20800 }
20801 else
20802 {
20803 if (value & ~0x7)
20804 as_bad_where (fixP->fx_file, fixP->fx_line,
20805 _("immediate value out of range"));
20806 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20807 newval |= rd | (rs << 3) | (value << 6);
20808 }
20809 }
20810 md_number_to_chars (buf, newval, THUMB_SIZE);
20811 break;
20812
20813 case BFD_RELOC_ARM_THUMB_IMM:
20814 newval = md_chars_to_number (buf, THUMB_SIZE);
20815 if (value < 0 || value > 255)
20816 as_bad_where (fixP->fx_file, fixP->fx_line,
20817 _("invalid immediate: %ld is out of range"),
20818 (long) value);
20819 newval |= value;
20820 md_number_to_chars (buf, newval, THUMB_SIZE);
20821 break;
20822
20823 case BFD_RELOC_ARM_THUMB_SHIFT:
20824 /* 5bit shift value (0..32). LSL cannot take 32. */
20825 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20826 temp = newval & 0xf800;
20827 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20828 as_bad_where (fixP->fx_file, fixP->fx_line,
20829 _("invalid shift value: %ld"), (long) value);
20830 /* Shifts of zero must be encoded as LSL. */
20831 if (value == 0)
20832 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20833 /* Shifts of 32 are encoded as zero. */
20834 else if (value == 32)
20835 value = 0;
20836 newval |= value << 6;
20837 md_number_to_chars (buf, newval, THUMB_SIZE);
20838 break;
20839
20840 case BFD_RELOC_VTABLE_INHERIT:
20841 case BFD_RELOC_VTABLE_ENTRY:
20842 fixP->fx_done = 0;
20843 return;
20844
20845 case BFD_RELOC_ARM_MOVW:
20846 case BFD_RELOC_ARM_MOVT:
20847 case BFD_RELOC_ARM_THUMB_MOVW:
20848 case BFD_RELOC_ARM_THUMB_MOVT:
20849 if (fixP->fx_done || !seg->use_rela_p)
20850 {
20851 /* REL format relocations are limited to a 16-bit addend. */
20852 if (!fixP->fx_done)
20853 {
20854 if (value < -0x8000 || value > 0x7fff)
20855 as_bad_where (fixP->fx_file, fixP->fx_line,
20856 _("offset out of range"));
20857 }
20858 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20859 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20860 {
20861 value >>= 16;
20862 }
20863
20864 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20865 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20866 {
20867 newval = get_thumb32_insn (buf);
20868 newval &= 0xfbf08f00;
20869 newval |= (value & 0xf000) << 4;
20870 newval |= (value & 0x0800) << 15;
20871 newval |= (value & 0x0700) << 4;
20872 newval |= (value & 0x00ff);
20873 put_thumb32_insn (buf, newval);
20874 }
20875 else
20876 {
20877 newval = md_chars_to_number (buf, 4);
20878 newval &= 0xfff0f000;
20879 newval |= value & 0x0fff;
20880 newval |= (value & 0xf000) << 4;
20881 md_number_to_chars (buf, newval, 4);
20882 }
20883 }
20884 return;
20885
20886 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20887 case BFD_RELOC_ARM_ALU_PC_G0:
20888 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20889 case BFD_RELOC_ARM_ALU_PC_G1:
20890 case BFD_RELOC_ARM_ALU_PC_G2:
20891 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20892 case BFD_RELOC_ARM_ALU_SB_G0:
20893 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20894 case BFD_RELOC_ARM_ALU_SB_G1:
20895 case BFD_RELOC_ARM_ALU_SB_G2:
20896 gas_assert (!fixP->fx_done);
20897 if (!seg->use_rela_p)
20898 {
20899 bfd_vma insn;
20900 bfd_vma encoded_addend;
20901 bfd_vma addend_abs = abs (value);
20902
20903 /* Check that the absolute value of the addend can be
20904 expressed as an 8-bit constant plus a rotation. */
20905 encoded_addend = encode_arm_immediate (addend_abs);
20906 if (encoded_addend == (unsigned int) FAIL)
20907 as_bad_where (fixP->fx_file, fixP->fx_line,
20908 _("the offset 0x%08lX is not representable"),
20909 (unsigned long) addend_abs);
20910
20911 /* Extract the instruction. */
20912 insn = md_chars_to_number (buf, INSN_SIZE);
20913
20914 /* If the addend is positive, use an ADD instruction.
20915 Otherwise use a SUB. Take care not to destroy the S bit. */
20916 insn &= 0xff1fffff;
20917 if (value < 0)
20918 insn |= 1 << 22;
20919 else
20920 insn |= 1 << 23;
20921
20922 /* Place the encoded addend into the first 12 bits of the
20923 instruction. */
20924 insn &= 0xfffff000;
20925 insn |= encoded_addend;
20926
20927 /* Update the instruction. */
20928 md_number_to_chars (buf, insn, INSN_SIZE);
20929 }
20930 break;
20931
20932 case BFD_RELOC_ARM_LDR_PC_G0:
20933 case BFD_RELOC_ARM_LDR_PC_G1:
20934 case BFD_RELOC_ARM_LDR_PC_G2:
20935 case BFD_RELOC_ARM_LDR_SB_G0:
20936 case BFD_RELOC_ARM_LDR_SB_G1:
20937 case BFD_RELOC_ARM_LDR_SB_G2:
20938 gas_assert (!fixP->fx_done);
20939 if (!seg->use_rela_p)
20940 {
20941 bfd_vma insn;
20942 bfd_vma addend_abs = abs (value);
20943
20944 /* Check that the absolute value of the addend can be
20945 encoded in 12 bits. */
20946 if (addend_abs >= 0x1000)
20947 as_bad_where (fixP->fx_file, fixP->fx_line,
20948 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
20949 (unsigned long) addend_abs);
20950
20951 /* Extract the instruction. */
20952 insn = md_chars_to_number (buf, INSN_SIZE);
20953
20954 /* If the addend is negative, clear bit 23 of the instruction.
20955 Otherwise set it. */
20956 if (value < 0)
20957 insn &= ~(1 << 23);
20958 else
20959 insn |= 1 << 23;
20960
20961 /* Place the absolute value of the addend into the first 12 bits
20962 of the instruction. */
20963 insn &= 0xfffff000;
20964 insn |= addend_abs;
20965
20966 /* Update the instruction. */
20967 md_number_to_chars (buf, insn, INSN_SIZE);
20968 }
20969 break;
20970
20971 case BFD_RELOC_ARM_LDRS_PC_G0:
20972 case BFD_RELOC_ARM_LDRS_PC_G1:
20973 case BFD_RELOC_ARM_LDRS_PC_G2:
20974 case BFD_RELOC_ARM_LDRS_SB_G0:
20975 case BFD_RELOC_ARM_LDRS_SB_G1:
20976 case BFD_RELOC_ARM_LDRS_SB_G2:
20977 gas_assert (!fixP->fx_done);
20978 if (!seg->use_rela_p)
20979 {
20980 bfd_vma insn;
20981 bfd_vma addend_abs = abs (value);
20982
20983 /* Check that the absolute value of the addend can be
20984 encoded in 8 bits. */
20985 if (addend_abs >= 0x100)
20986 as_bad_where (fixP->fx_file, fixP->fx_line,
20987 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
20988 (unsigned long) addend_abs);
20989
20990 /* Extract the instruction. */
20991 insn = md_chars_to_number (buf, INSN_SIZE);
20992
20993 /* If the addend is negative, clear bit 23 of the instruction.
20994 Otherwise set it. */
20995 if (value < 0)
20996 insn &= ~(1 << 23);
20997 else
20998 insn |= 1 << 23;
20999
21000 /* Place the first four bits of the absolute value of the addend
21001 into the first 4 bits of the instruction, and the remaining
21002 four into bits 8 .. 11. */
21003 insn &= 0xfffff0f0;
21004 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
21005
21006 /* Update the instruction. */
21007 md_number_to_chars (buf, insn, INSN_SIZE);
21008 }
21009 break;
21010
21011 case BFD_RELOC_ARM_LDC_PC_G0:
21012 case BFD_RELOC_ARM_LDC_PC_G1:
21013 case BFD_RELOC_ARM_LDC_PC_G2:
21014 case BFD_RELOC_ARM_LDC_SB_G0:
21015 case BFD_RELOC_ARM_LDC_SB_G1:
21016 case BFD_RELOC_ARM_LDC_SB_G2:
21017 gas_assert (!fixP->fx_done);
21018 if (!seg->use_rela_p)
21019 {
21020 bfd_vma insn;
21021 bfd_vma addend_abs = abs (value);
21022
21023 /* Check that the absolute value of the addend is a multiple of
21024 four and, when divided by four, fits in 8 bits. */
21025 if (addend_abs & 0x3)
21026 as_bad_where (fixP->fx_file, fixP->fx_line,
21027 _("bad offset 0x%08lX (must be word-aligned)"),
21028 (unsigned long) addend_abs);
21029
21030 if ((addend_abs >> 2) > 0xff)
21031 as_bad_where (fixP->fx_file, fixP->fx_line,
21032 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
21033 (unsigned long) addend_abs);
21034
21035 /* Extract the instruction. */
21036 insn = md_chars_to_number (buf, INSN_SIZE);
21037
21038 /* If the addend is negative, clear bit 23 of the instruction.
21039 Otherwise set it. */
21040 if (value < 0)
21041 insn &= ~(1 << 23);
21042 else
21043 insn |= 1 << 23;
21044
21045 /* Place the addend (divided by four) into the first eight
21046 bits of the instruction. */
21047 insn &= 0xfffffff0;
21048 insn |= addend_abs >> 2;
21049
21050 /* Update the instruction. */
21051 md_number_to_chars (buf, insn, INSN_SIZE);
21052 }
21053 break;
21054
21055 case BFD_RELOC_ARM_V4BX:
21056 /* This will need to go in the object file. */
21057 fixP->fx_done = 0;
21058 break;
21059
21060 case BFD_RELOC_UNUSED:
21061 default:
21062 as_bad_where (fixP->fx_file, fixP->fx_line,
21063 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
21064 }
21065 }
21066
21067 /* Translate internal representation of relocation info to BFD target
21068 format. */
21069
21070 arelent *
21071 tc_gen_reloc (asection *section, fixS *fixp)
21072 {
21073 arelent * reloc;
21074 bfd_reloc_code_real_type code;
21075
21076 reloc = (arelent *) xmalloc (sizeof (arelent));
21077
21078 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
21079 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
21080 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
21081
21082 if (fixp->fx_pcrel)
21083 {
21084 if (section->use_rela_p)
21085 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
21086 else
21087 fixp->fx_offset = reloc->address;
21088 }
21089 reloc->addend = fixp->fx_offset;
21090
21091 switch (fixp->fx_r_type)
21092 {
21093 case BFD_RELOC_8:
21094 if (fixp->fx_pcrel)
21095 {
21096 code = BFD_RELOC_8_PCREL;
21097 break;
21098 }
21099
21100 case BFD_RELOC_16:
21101 if (fixp->fx_pcrel)
21102 {
21103 code = BFD_RELOC_16_PCREL;
21104 break;
21105 }
21106
21107 case BFD_RELOC_32:
21108 if (fixp->fx_pcrel)
21109 {
21110 code = BFD_RELOC_32_PCREL;
21111 break;
21112 }
21113
21114 case BFD_RELOC_ARM_MOVW:
21115 if (fixp->fx_pcrel)
21116 {
21117 code = BFD_RELOC_ARM_MOVW_PCREL;
21118 break;
21119 }
21120
21121 case BFD_RELOC_ARM_MOVT:
21122 if (fixp->fx_pcrel)
21123 {
21124 code = BFD_RELOC_ARM_MOVT_PCREL;
21125 break;
21126 }
21127
21128 case BFD_RELOC_ARM_THUMB_MOVW:
21129 if (fixp->fx_pcrel)
21130 {
21131 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21132 break;
21133 }
21134
21135 case BFD_RELOC_ARM_THUMB_MOVT:
21136 if (fixp->fx_pcrel)
21137 {
21138 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21139 break;
21140 }
21141
21142 case BFD_RELOC_NONE:
21143 case BFD_RELOC_ARM_PCREL_BRANCH:
21144 case BFD_RELOC_ARM_PCREL_BLX:
21145 case BFD_RELOC_RVA:
21146 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21147 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21148 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21149 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21150 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21151 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21152 case BFD_RELOC_VTABLE_ENTRY:
21153 case BFD_RELOC_VTABLE_INHERIT:
21154 #ifdef TE_PE
21155 case BFD_RELOC_32_SECREL:
21156 #endif
21157 code = fixp->fx_r_type;
21158 break;
21159
21160 case BFD_RELOC_THUMB_PCREL_BLX:
21161 #ifdef OBJ_ELF
21162 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21163 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21164 else
21165 #endif
21166 code = BFD_RELOC_THUMB_PCREL_BLX;
21167 break;
21168
21169 case BFD_RELOC_ARM_LITERAL:
21170 case BFD_RELOC_ARM_HWLITERAL:
21171 /* If this is called then the a literal has
21172 been referenced across a section boundary. */
21173 as_bad_where (fixp->fx_file, fixp->fx_line,
21174 _("literal referenced across section boundary"));
21175 return NULL;
21176
21177 #ifdef OBJ_ELF
21178 case BFD_RELOC_ARM_GOT32:
21179 case BFD_RELOC_ARM_GOTOFF:
21180 case BFD_RELOC_ARM_GOT_PREL:
21181 case BFD_RELOC_ARM_PLT32:
21182 case BFD_RELOC_ARM_TARGET1:
21183 case BFD_RELOC_ARM_ROSEGREL32:
21184 case BFD_RELOC_ARM_SBREL32:
21185 case BFD_RELOC_ARM_PREL31:
21186 case BFD_RELOC_ARM_TARGET2:
21187 case BFD_RELOC_ARM_TLS_LE32:
21188 case BFD_RELOC_ARM_TLS_LDO32:
21189 case BFD_RELOC_ARM_PCREL_CALL:
21190 case BFD_RELOC_ARM_PCREL_JUMP:
21191 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21192 case BFD_RELOC_ARM_ALU_PC_G0:
21193 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21194 case BFD_RELOC_ARM_ALU_PC_G1:
21195 case BFD_RELOC_ARM_ALU_PC_G2:
21196 case BFD_RELOC_ARM_LDR_PC_G0:
21197 case BFD_RELOC_ARM_LDR_PC_G1:
21198 case BFD_RELOC_ARM_LDR_PC_G2:
21199 case BFD_RELOC_ARM_LDRS_PC_G0:
21200 case BFD_RELOC_ARM_LDRS_PC_G1:
21201 case BFD_RELOC_ARM_LDRS_PC_G2:
21202 case BFD_RELOC_ARM_LDC_PC_G0:
21203 case BFD_RELOC_ARM_LDC_PC_G1:
21204 case BFD_RELOC_ARM_LDC_PC_G2:
21205 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21206 case BFD_RELOC_ARM_ALU_SB_G0:
21207 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21208 case BFD_RELOC_ARM_ALU_SB_G1:
21209 case BFD_RELOC_ARM_ALU_SB_G2:
21210 case BFD_RELOC_ARM_LDR_SB_G0:
21211 case BFD_RELOC_ARM_LDR_SB_G1:
21212 case BFD_RELOC_ARM_LDR_SB_G2:
21213 case BFD_RELOC_ARM_LDRS_SB_G0:
21214 case BFD_RELOC_ARM_LDRS_SB_G1:
21215 case BFD_RELOC_ARM_LDRS_SB_G2:
21216 case BFD_RELOC_ARM_LDC_SB_G0:
21217 case BFD_RELOC_ARM_LDC_SB_G1:
21218 case BFD_RELOC_ARM_LDC_SB_G2:
21219 case BFD_RELOC_ARM_V4BX:
21220 code = fixp->fx_r_type;
21221 break;
21222
21223 case BFD_RELOC_ARM_TLS_GD32:
21224 case BFD_RELOC_ARM_TLS_IE32:
21225 case BFD_RELOC_ARM_TLS_LDM32:
21226 /* BFD will include the symbol's address in the addend.
21227 But we don't want that, so subtract it out again here. */
21228 if (!S_IS_COMMON (fixp->fx_addsy))
21229 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21230 code = fixp->fx_r_type;
21231 break;
21232 #endif
21233
21234 case BFD_RELOC_ARM_IMMEDIATE:
21235 as_bad_where (fixp->fx_file, fixp->fx_line,
21236 _("internal relocation (type: IMMEDIATE) not fixed up"));
21237 return NULL;
21238
21239 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21240 as_bad_where (fixp->fx_file, fixp->fx_line,
21241 _("ADRL used for a symbol not defined in the same file"));
21242 return NULL;
21243
21244 case BFD_RELOC_ARM_OFFSET_IMM:
21245 if (section->use_rela_p)
21246 {
21247 code = fixp->fx_r_type;
21248 break;
21249 }
21250
21251 if (fixp->fx_addsy != NULL
21252 && !S_IS_DEFINED (fixp->fx_addsy)
21253 && S_IS_LOCAL (fixp->fx_addsy))
21254 {
21255 as_bad_where (fixp->fx_file, fixp->fx_line,
21256 _("undefined local label `%s'"),
21257 S_GET_NAME (fixp->fx_addsy));
21258 return NULL;
21259 }
21260
21261 as_bad_where (fixp->fx_file, fixp->fx_line,
21262 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21263 return NULL;
21264
21265 default:
21266 {
21267 char * type;
21268
21269 switch (fixp->fx_r_type)
21270 {
21271 case BFD_RELOC_NONE: type = "NONE"; break;
21272 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21273 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
21274 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
21275 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21276 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21277 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
21278 case BFD_RELOC_ARM_T32_OFFSET_IMM: type = "T32_OFFSET_IMM"; break;
21279 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
21280 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21281 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21282 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21283 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21284 default: type = _("<unknown>"); break;
21285 }
21286 as_bad_where (fixp->fx_file, fixp->fx_line,
21287 _("cannot represent %s relocation in this object file format"),
21288 type);
21289 return NULL;
21290 }
21291 }
21292
21293 #ifdef OBJ_ELF
21294 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21295 && GOT_symbol
21296 && fixp->fx_addsy == GOT_symbol)
21297 {
21298 code = BFD_RELOC_ARM_GOTPC;
21299 reloc->addend = fixp->fx_offset = reloc->address;
21300 }
21301 #endif
21302
21303 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
21304
21305 if (reloc->howto == NULL)
21306 {
21307 as_bad_where (fixp->fx_file, fixp->fx_line,
21308 _("cannot represent %s relocation in this object file format"),
21309 bfd_get_reloc_code_name (code));
21310 return NULL;
21311 }
21312
21313 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21314 vtable entry to be used in the relocation's section offset. */
21315 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21316 reloc->address = fixp->fx_offset;
21317
21318 return reloc;
21319 }
21320
21321 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
21322
21323 void
21324 cons_fix_new_arm (fragS * frag,
21325 int where,
21326 int size,
21327 expressionS * exp)
21328 {
21329 bfd_reloc_code_real_type type;
21330 int pcrel = 0;
21331
21332 /* Pick a reloc.
21333 FIXME: @@ Should look at CPU word size. */
21334 switch (size)
21335 {
21336 case 1:
21337 type = BFD_RELOC_8;
21338 break;
21339 case 2:
21340 type = BFD_RELOC_16;
21341 break;
21342 case 4:
21343 default:
21344 type = BFD_RELOC_32;
21345 break;
21346 case 8:
21347 type = BFD_RELOC_64;
21348 break;
21349 }
21350
21351 #ifdef TE_PE
21352 if (exp->X_op == O_secrel)
21353 {
21354 exp->X_op = O_symbol;
21355 type = BFD_RELOC_32_SECREL;
21356 }
21357 #endif
21358
21359 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21360 }
21361
21362 #if defined (OBJ_COFF)
21363 void
21364 arm_validate_fix (fixS * fixP)
21365 {
21366 /* If the destination of the branch is a defined symbol which does not have
21367 the THUMB_FUNC attribute, then we must be calling a function which has
21368 the (interfacearm) attribute. We look for the Thumb entry point to that
21369 function and change the branch to refer to that function instead. */
21370 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21371 && fixP->fx_addsy != NULL
21372 && S_IS_DEFINED (fixP->fx_addsy)
21373 && ! THUMB_IS_FUNC (fixP->fx_addsy))
21374 {
21375 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
21376 }
21377 }
21378 #endif
21379
21380
21381 int
21382 arm_force_relocation (struct fix * fixp)
21383 {
21384 #if defined (OBJ_COFF) && defined (TE_PE)
21385 if (fixp->fx_r_type == BFD_RELOC_RVA)
21386 return 1;
21387 #endif
21388
21389 /* In case we have a call or a branch to a function in ARM ISA mode from
21390 a thumb function or vice-versa force the relocation. These relocations
21391 are cleared off for some cores that might have blx and simple transformations
21392 are possible. */
21393
21394 #ifdef OBJ_ELF
21395 switch (fixp->fx_r_type)
21396 {
21397 case BFD_RELOC_ARM_PCREL_JUMP:
21398 case BFD_RELOC_ARM_PCREL_CALL:
21399 case BFD_RELOC_THUMB_PCREL_BLX:
21400 if (THUMB_IS_FUNC (fixp->fx_addsy))
21401 return 1;
21402 break;
21403
21404 case BFD_RELOC_ARM_PCREL_BLX:
21405 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21406 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21407 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21408 if (ARM_IS_FUNC (fixp->fx_addsy))
21409 return 1;
21410 break;
21411
21412 default:
21413 break;
21414 }
21415 #endif
21416
21417 /* Resolve these relocations even if the symbol is extern or weak. */
21418 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21419 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
21420 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
21421 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
21422 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21423 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21424 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
21425 return 0;
21426
21427 /* Always leave these relocations for the linker. */
21428 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21429 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21430 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21431 return 1;
21432
21433 /* Always generate relocations against function symbols. */
21434 if (fixp->fx_r_type == BFD_RELOC_32
21435 && fixp->fx_addsy
21436 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21437 return 1;
21438
21439 return generic_force_reloc (fixp);
21440 }
21441
21442 #if defined (OBJ_ELF) || defined (OBJ_COFF)
21443 /* Relocations against function names must be left unadjusted,
21444 so that the linker can use this information to generate interworking
21445 stubs. The MIPS version of this function
21446 also prevents relocations that are mips-16 specific, but I do not
21447 know why it does this.
21448
21449 FIXME:
21450 There is one other problem that ought to be addressed here, but
21451 which currently is not: Taking the address of a label (rather
21452 than a function) and then later jumping to that address. Such
21453 addresses also ought to have their bottom bit set (assuming that
21454 they reside in Thumb code), but at the moment they will not. */
21455
21456 bfd_boolean
21457 arm_fix_adjustable (fixS * fixP)
21458 {
21459 if (fixP->fx_addsy == NULL)
21460 return 1;
21461
21462 /* Preserve relocations against symbols with function type. */
21463 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
21464 return FALSE;
21465
21466 if (THUMB_IS_FUNC (fixP->fx_addsy)
21467 && fixP->fx_subsy == NULL)
21468 return FALSE;
21469
21470 /* We need the symbol name for the VTABLE entries. */
21471 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21472 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21473 return FALSE;
21474
21475 /* Don't allow symbols to be discarded on GOT related relocs. */
21476 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21477 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21478 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21479 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21480 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21481 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21482 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21483 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21484 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
21485 return FALSE;
21486
21487 /* Similarly for group relocations. */
21488 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21489 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21490 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21491 return FALSE;
21492
21493 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21494 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21495 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21496 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21497 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21498 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21499 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21500 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21501 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
21502 return FALSE;
21503
21504 return TRUE;
21505 }
21506 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21507
21508 #ifdef OBJ_ELF
21509
21510 const char *
21511 elf32_arm_target_format (void)
21512 {
21513 #ifdef TE_SYMBIAN
21514 return (target_big_endian
21515 ? "elf32-bigarm-symbian"
21516 : "elf32-littlearm-symbian");
21517 #elif defined (TE_VXWORKS)
21518 return (target_big_endian
21519 ? "elf32-bigarm-vxworks"
21520 : "elf32-littlearm-vxworks");
21521 #else
21522 if (target_big_endian)
21523 return "elf32-bigarm";
21524 else
21525 return "elf32-littlearm";
21526 #endif
21527 }
21528
21529 void
21530 armelf_frob_symbol (symbolS * symp,
21531 int * puntp)
21532 {
21533 elf_frob_symbol (symp, puntp);
21534 }
21535 #endif
21536
21537 /* MD interface: Finalization. */
21538
21539 void
21540 arm_cleanup (void)
21541 {
21542 literal_pool * pool;
21543
21544 /* Ensure that all the IT blocks are properly closed. */
21545 check_it_blocks_finished ();
21546
21547 for (pool = list_of_pools; pool; pool = pool->next)
21548 {
21549 /* Put it at the end of the relevant section. */
21550 subseg_set (pool->section, pool->sub_section);
21551 #ifdef OBJ_ELF
21552 arm_elf_change_section ();
21553 #endif
21554 s_ltorg (0);
21555 }
21556 }
21557
21558 #ifdef OBJ_ELF
21559 /* Remove any excess mapping symbols generated for alignment frags in
21560 SEC. We may have created a mapping symbol before a zero byte
21561 alignment; remove it if there's a mapping symbol after the
21562 alignment. */
21563 static void
21564 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21565 void *dummy ATTRIBUTE_UNUSED)
21566 {
21567 segment_info_type *seginfo = seg_info (sec);
21568 fragS *fragp;
21569
21570 if (seginfo == NULL || seginfo->frchainP == NULL)
21571 return;
21572
21573 for (fragp = seginfo->frchainP->frch_root;
21574 fragp != NULL;
21575 fragp = fragp->fr_next)
21576 {
21577 symbolS *sym = fragp->tc_frag_data.last_map;
21578 fragS *next = fragp->fr_next;
21579
21580 /* Variable-sized frags have been converted to fixed size by
21581 this point. But if this was variable-sized to start with,
21582 there will be a fixed-size frag after it. So don't handle
21583 next == NULL. */
21584 if (sym == NULL || next == NULL)
21585 continue;
21586
21587 if (S_GET_VALUE (sym) < next->fr_address)
21588 /* Not at the end of this frag. */
21589 continue;
21590 know (S_GET_VALUE (sym) == next->fr_address);
21591
21592 do
21593 {
21594 if (next->tc_frag_data.first_map != NULL)
21595 {
21596 /* Next frag starts with a mapping symbol. Discard this
21597 one. */
21598 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21599 break;
21600 }
21601
21602 if (next->fr_next == NULL)
21603 {
21604 /* This mapping symbol is at the end of the section. Discard
21605 it. */
21606 know (next->fr_fix == 0 && next->fr_var == 0);
21607 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21608 break;
21609 }
21610
21611 /* As long as we have empty frags without any mapping symbols,
21612 keep looking. */
21613 /* If the next frag is non-empty and does not start with a
21614 mapping symbol, then this mapping symbol is required. */
21615 if (next->fr_address != next->fr_next->fr_address)
21616 break;
21617
21618 next = next->fr_next;
21619 }
21620 while (next != NULL);
21621 }
21622 }
21623 #endif
21624
21625 /* Adjust the symbol table. This marks Thumb symbols as distinct from
21626 ARM ones. */
21627
21628 void
21629 arm_adjust_symtab (void)
21630 {
21631 #ifdef OBJ_COFF
21632 symbolS * sym;
21633
21634 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21635 {
21636 if (ARM_IS_THUMB (sym))
21637 {
21638 if (THUMB_IS_FUNC (sym))
21639 {
21640 /* Mark the symbol as a Thumb function. */
21641 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21642 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21643 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
21644
21645 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21646 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21647 else
21648 as_bad (_("%s: unexpected function type: %d"),
21649 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21650 }
21651 else switch (S_GET_STORAGE_CLASS (sym))
21652 {
21653 case C_EXT:
21654 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21655 break;
21656 case C_STAT:
21657 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21658 break;
21659 case C_LABEL:
21660 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21661 break;
21662 default:
21663 /* Do nothing. */
21664 break;
21665 }
21666 }
21667
21668 if (ARM_IS_INTERWORK (sym))
21669 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
21670 }
21671 #endif
21672 #ifdef OBJ_ELF
21673 symbolS * sym;
21674 char bind;
21675
21676 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21677 {
21678 if (ARM_IS_THUMB (sym))
21679 {
21680 elf_symbol_type * elf_sym;
21681
21682 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21683 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
21684
21685 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21686 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
21687 {
21688 /* If it's a .thumb_func, declare it as so,
21689 otherwise tag label as .code 16. */
21690 if (THUMB_IS_FUNC (sym))
21691 elf_sym->internal_elf_sym.st_info =
21692 ELF_ST_INFO (bind, STT_ARM_TFUNC);
21693 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21694 elf_sym->internal_elf_sym.st_info =
21695 ELF_ST_INFO (bind, STT_ARM_16BIT);
21696 }
21697 }
21698 }
21699
21700 /* Remove any overlapping mapping symbols generated by alignment frags. */
21701 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
21702 #endif
21703 }
21704
21705 /* MD interface: Initialization. */
21706
21707 static void
21708 set_constant_flonums (void)
21709 {
21710 int i;
21711
21712 for (i = 0; i < NUM_FLOAT_VALS; i++)
21713 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21714 abort ();
21715 }
21716
21717 /* Auto-select Thumb mode if it's the only available instruction set for the
21718 given architecture. */
21719
21720 static void
21721 autoselect_thumb_from_cpu_variant (void)
21722 {
21723 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21724 opcode_select (16);
21725 }
21726
21727 void
21728 md_begin (void)
21729 {
21730 unsigned mach;
21731 unsigned int i;
21732
21733 if ( (arm_ops_hsh = hash_new ()) == NULL
21734 || (arm_cond_hsh = hash_new ()) == NULL
21735 || (arm_shift_hsh = hash_new ()) == NULL
21736 || (arm_psr_hsh = hash_new ()) == NULL
21737 || (arm_v7m_psr_hsh = hash_new ()) == NULL
21738 || (arm_reg_hsh = hash_new ()) == NULL
21739 || (arm_reloc_hsh = hash_new ()) == NULL
21740 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
21741 as_fatal (_("virtual memory exhausted"));
21742
21743 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
21744 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
21745 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
21746 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
21747 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
21748 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
21749 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
21750 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
21751 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
21752 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21753 (void *) (v7m_psrs + i));
21754 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
21755 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
21756 for (i = 0;
21757 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21758 i++)
21759 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
21760 (void *) (barrier_opt_names + i));
21761 #ifdef OBJ_ELF
21762 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
21763 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
21764 #endif
21765
21766 set_constant_flonums ();
21767
21768 /* Set the cpu variant based on the command-line options. We prefer
21769 -mcpu= over -march= if both are set (as for GCC); and we prefer
21770 -mfpu= over any other way of setting the floating point unit.
21771 Use of legacy options with new options are faulted. */
21772 if (legacy_cpu)
21773 {
21774 if (mcpu_cpu_opt || march_cpu_opt)
21775 as_bad (_("use of old and new-style options to set CPU type"));
21776
21777 mcpu_cpu_opt = legacy_cpu;
21778 }
21779 else if (!mcpu_cpu_opt)
21780 mcpu_cpu_opt = march_cpu_opt;
21781
21782 if (legacy_fpu)
21783 {
21784 if (mfpu_opt)
21785 as_bad (_("use of old and new-style options to set FPU type"));
21786
21787 mfpu_opt = legacy_fpu;
21788 }
21789 else if (!mfpu_opt)
21790 {
21791 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21792 || defined (TE_NetBSD) || defined (TE_VXWORKS))
21793 /* Some environments specify a default FPU. If they don't, infer it
21794 from the processor. */
21795 if (mcpu_fpu_opt)
21796 mfpu_opt = mcpu_fpu_opt;
21797 else
21798 mfpu_opt = march_fpu_opt;
21799 #else
21800 mfpu_opt = &fpu_default;
21801 #endif
21802 }
21803
21804 if (!mfpu_opt)
21805 {
21806 if (mcpu_cpu_opt != NULL)
21807 mfpu_opt = &fpu_default;
21808 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
21809 mfpu_opt = &fpu_arch_vfp_v2;
21810 else
21811 mfpu_opt = &fpu_arch_fpa;
21812 }
21813
21814 #ifdef CPU_DEFAULT
21815 if (!mcpu_cpu_opt)
21816 {
21817 mcpu_cpu_opt = &cpu_default;
21818 selected_cpu = cpu_default;
21819 }
21820 #else
21821 if (mcpu_cpu_opt)
21822 selected_cpu = *mcpu_cpu_opt;
21823 else
21824 mcpu_cpu_opt = &arm_arch_any;
21825 #endif
21826
21827 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21828
21829 autoselect_thumb_from_cpu_variant ();
21830
21831 arm_arch_used = thumb_arch_used = arm_arch_none;
21832
21833 #if defined OBJ_COFF || defined OBJ_ELF
21834 {
21835 unsigned int flags = 0;
21836
21837 #if defined OBJ_ELF
21838 flags = meabi_flags;
21839
21840 switch (meabi_flags)
21841 {
21842 case EF_ARM_EABI_UNKNOWN:
21843 #endif
21844 /* Set the flags in the private structure. */
21845 if (uses_apcs_26) flags |= F_APCS26;
21846 if (support_interwork) flags |= F_INTERWORK;
21847 if (uses_apcs_float) flags |= F_APCS_FLOAT;
21848 if (pic_code) flags |= F_PIC;
21849 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
21850 flags |= F_SOFT_FLOAT;
21851
21852 switch (mfloat_abi_opt)
21853 {
21854 case ARM_FLOAT_ABI_SOFT:
21855 case ARM_FLOAT_ABI_SOFTFP:
21856 flags |= F_SOFT_FLOAT;
21857 break;
21858
21859 case ARM_FLOAT_ABI_HARD:
21860 if (flags & F_SOFT_FLOAT)
21861 as_bad (_("hard-float conflicts with specified fpu"));
21862 break;
21863 }
21864
21865 /* Using pure-endian doubles (even if soft-float). */
21866 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
21867 flags |= F_VFP_FLOAT;
21868
21869 #if defined OBJ_ELF
21870 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
21871 flags |= EF_ARM_MAVERICK_FLOAT;
21872 break;
21873
21874 case EF_ARM_EABI_VER4:
21875 case EF_ARM_EABI_VER5:
21876 /* No additional flags to set. */
21877 break;
21878
21879 default:
21880 abort ();
21881 }
21882 #endif
21883 bfd_set_private_flags (stdoutput, flags);
21884
21885 /* We have run out flags in the COFF header to encode the
21886 status of ATPCS support, so instead we create a dummy,
21887 empty, debug section called .arm.atpcs. */
21888 if (atpcs)
21889 {
21890 asection * sec;
21891
21892 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21893
21894 if (sec != NULL)
21895 {
21896 bfd_set_section_flags
21897 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21898 bfd_set_section_size (stdoutput, sec, 0);
21899 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21900 }
21901 }
21902 }
21903 #endif
21904
21905 /* Record the CPU type as well. */
21906 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21907 mach = bfd_mach_arm_iWMMXt2;
21908 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
21909 mach = bfd_mach_arm_iWMMXt;
21910 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
21911 mach = bfd_mach_arm_XScale;
21912 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
21913 mach = bfd_mach_arm_ep9312;
21914 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
21915 mach = bfd_mach_arm_5TE;
21916 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
21917 {
21918 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21919 mach = bfd_mach_arm_5T;
21920 else
21921 mach = bfd_mach_arm_5;
21922 }
21923 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
21924 {
21925 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21926 mach = bfd_mach_arm_4T;
21927 else
21928 mach = bfd_mach_arm_4;
21929 }
21930 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
21931 mach = bfd_mach_arm_3M;
21932 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21933 mach = bfd_mach_arm_3;
21934 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21935 mach = bfd_mach_arm_2a;
21936 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21937 mach = bfd_mach_arm_2;
21938 else
21939 mach = bfd_mach_arm_unknown;
21940
21941 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21942 }
21943
21944 /* Command line processing. */
21945
21946 /* md_parse_option
21947 Invocation line includes a switch not recognized by the base assembler.
21948 See if it's a processor-specific option.
21949
21950 This routine is somewhat complicated by the need for backwards
21951 compatibility (since older releases of gcc can't be changed).
21952 The new options try to make the interface as compatible as
21953 possible with GCC.
21954
21955 New options (supported) are:
21956
21957 -mcpu=<cpu name> Assemble for selected processor
21958 -march=<architecture name> Assemble for selected architecture
21959 -mfpu=<fpu architecture> Assemble for selected FPU.
21960 -EB/-mbig-endian Big-endian
21961 -EL/-mlittle-endian Little-endian
21962 -k Generate PIC code
21963 -mthumb Start in Thumb mode
21964 -mthumb-interwork Code supports ARM/Thumb interworking
21965
21966 -m[no-]warn-deprecated Warn about deprecated features
21967
21968 For now we will also provide support for:
21969
21970 -mapcs-32 32-bit Program counter
21971 -mapcs-26 26-bit Program counter
21972 -macps-float Floats passed in FP registers
21973 -mapcs-reentrant Reentrant code
21974 -matpcs
21975 (sometime these will probably be replaced with -mapcs=<list of options>
21976 and -matpcs=<list of options>)
21977
21978 The remaining options are only supported for back-wards compatibility.
21979 Cpu variants, the arm part is optional:
21980 -m[arm]1 Currently not supported.
21981 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21982 -m[arm]3 Arm 3 processor
21983 -m[arm]6[xx], Arm 6 processors
21984 -m[arm]7[xx][t][[d]m] Arm 7 processors
21985 -m[arm]8[10] Arm 8 processors
21986 -m[arm]9[20][tdmi] Arm 9 processors
21987 -mstrongarm[110[0]] StrongARM processors
21988 -mxscale XScale processors
21989 -m[arm]v[2345[t[e]]] Arm architectures
21990 -mall All (except the ARM1)
21991 FP variants:
21992 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21993 -mfpe-old (No float load/store multiples)
21994 -mvfpxd VFP Single precision
21995 -mvfp All VFP
21996 -mno-fpu Disable all floating point instructions
21997
21998 The following CPU names are recognized:
21999 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
22000 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
22001 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
22002 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
22003 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
22004 arm10t arm10e, arm1020t, arm1020e, arm10200e,
22005 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
22006
22007 */
22008
22009 const char * md_shortopts = "m:k";
22010
22011 #ifdef ARM_BI_ENDIAN
22012 #define OPTION_EB (OPTION_MD_BASE + 0)
22013 #define OPTION_EL (OPTION_MD_BASE + 1)
22014 #else
22015 #if TARGET_BYTES_BIG_ENDIAN
22016 #define OPTION_EB (OPTION_MD_BASE + 0)
22017 #else
22018 #define OPTION_EL (OPTION_MD_BASE + 1)
22019 #endif
22020 #endif
22021 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
22022
22023 struct option md_longopts[] =
22024 {
22025 #ifdef OPTION_EB
22026 {"EB", no_argument, NULL, OPTION_EB},
22027 #endif
22028 #ifdef OPTION_EL
22029 {"EL", no_argument, NULL, OPTION_EL},
22030 #endif
22031 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
22032 {NULL, no_argument, NULL, 0}
22033 };
22034
22035 size_t md_longopts_size = sizeof (md_longopts);
22036
22037 struct arm_option_table
22038 {
22039 char *option; /* Option name to match. */
22040 char *help; /* Help information. */
22041 int *var; /* Variable to change. */
22042 int value; /* What to change it to. */
22043 char *deprecated; /* If non-null, print this message. */
22044 };
22045
22046 struct arm_option_table arm_opts[] =
22047 {
22048 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
22049 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
22050 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
22051 &support_interwork, 1, NULL},
22052 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
22053 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
22054 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
22055 1, NULL},
22056 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
22057 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
22058 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
22059 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
22060 NULL},
22061
22062 /* These are recognized by the assembler, but have no affect on code. */
22063 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
22064 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
22065
22066 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
22067 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
22068 &warn_on_deprecated, 0, NULL},
22069 {NULL, NULL, NULL, 0, NULL}
22070 };
22071
22072 struct arm_legacy_option_table
22073 {
22074 char *option; /* Option name to match. */
22075 const arm_feature_set **var; /* Variable to change. */
22076 const arm_feature_set value; /* What to change it to. */
22077 char *deprecated; /* If non-null, print this message. */
22078 };
22079
22080 const struct arm_legacy_option_table arm_legacy_opts[] =
22081 {
22082 /* DON'T add any new processors to this list -- we want the whole list
22083 to go away... Add them to the processors table instead. */
22084 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22085 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
22086 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22087 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
22088 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22089 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
22090 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22091 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
22092 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22093 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
22094 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22095 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22096 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22097 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22098 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22099 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22100 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22101 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22102 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22103 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22104 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22105 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22106 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22107 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22108 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22109 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22110 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22111 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22112 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22113 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22114 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22115 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22116 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22117 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22118 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22119 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22120 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22121 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22122 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22123 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22124 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22125 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22126 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22127 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22128 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22129 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22130 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22131 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22132 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22133 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22134 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22135 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22136 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22137 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22138 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22139 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22140 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22141 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22142 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22143 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22144 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22145 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22146 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22147 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22148 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22149 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22150 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22151 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22152 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22153 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
22154 N_("use -mcpu=strongarm110")},
22155 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
22156 N_("use -mcpu=strongarm1100")},
22157 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
22158 N_("use -mcpu=strongarm1110")},
22159 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22160 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22161 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
22162
22163 /* Architecture variants -- don't add any more to this list either. */
22164 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22165 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22166 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22167 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22168 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22169 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22170 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22171 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22172 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22173 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22174 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22175 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22176 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22177 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22178 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22179 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22180 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22181 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22182
22183 /* Floating point variants -- don't add any more to this list either. */
22184 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22185 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22186 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22187 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
22188 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
22189
22190 {NULL, NULL, ARM_ARCH_NONE, NULL}
22191 };
22192
22193 struct arm_cpu_option_table
22194 {
22195 char *name;
22196 const arm_feature_set value;
22197 /* For some CPUs we assume an FPU unless the user explicitly sets
22198 -mfpu=... */
22199 const arm_feature_set default_fpu;
22200 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22201 case. */
22202 const char *canonical_name;
22203 };
22204
22205 /* This list should, at a minimum, contain all the cpu names
22206 recognized by GCC. */
22207 static const struct arm_cpu_option_table arm_cpus[] =
22208 {
22209 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22210 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22211 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22212 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22213 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22214 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22215 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22216 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22217 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22218 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22219 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22220 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22221 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22222 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22223 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22224 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22225 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22226 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22227 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22228 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22229 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22230 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22231 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22232 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22233 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22234 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22235 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22236 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22237 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22238 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22239 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22240 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22241 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22242 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22243 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22244 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22245 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22246 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22247 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22248 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22249 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22250 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22251 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22252 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22253 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22254 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22255 /* For V5 or later processors we default to using VFP; but the user
22256 should really set the FPU type explicitly. */
22257 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22258 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22259 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22260 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22261 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22262 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22263 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22264 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22265 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22266 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22267 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22268 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22269 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22270 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22271 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22272 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22273 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22274 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22275 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22276 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22277 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22278 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22279 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22280 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22281 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22282 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22283 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22284 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
22285 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
22286 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22287 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22288 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22289 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
22290 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
22291 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
22292 | FPU_NEON_EXT_V1),
22293 NULL},
22294 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
22295 | FPU_NEON_EXT_V1),
22296 NULL},
22297 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
22298 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
22299 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, NULL},
22300 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
22301 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
22302 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
22303 /* ??? XSCALE is really an architecture. */
22304 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22305 /* ??? iwmmxt is not a processor. */
22306 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
22307 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
22308 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22309 /* Maverick */
22310 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
22311 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
22312 };
22313
22314 struct arm_arch_option_table
22315 {
22316 char *name;
22317 const arm_feature_set value;
22318 const arm_feature_set default_fpu;
22319 };
22320
22321 /* This list should, at a minimum, contain all the architecture names
22322 recognized by GCC. */
22323 static const struct arm_arch_option_table arm_archs[] =
22324 {
22325 {"all", ARM_ANY, FPU_ARCH_FPA},
22326 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22327 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22328 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22329 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22330 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22331 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22332 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22333 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22334 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22335 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22336 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22337 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22338 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22339 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22340 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22341 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22342 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22343 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22344 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22345 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22346 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22347 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22348 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22349 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22350 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
22351 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
22352 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
22353 /* The official spelling of the ARMv7 profile variants is the dashed form.
22354 Accept the non-dashed form for compatibility with old toolchains. */
22355 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22356 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22357 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22358 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22359 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22360 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22361 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
22362 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22363 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
22364 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
22365 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
22366 };
22367
22368 /* ISA extensions in the co-processor space. */
22369 struct arm_option_cpu_value_table
22370 {
22371 char *name;
22372 const arm_feature_set value;
22373 };
22374
22375 static const struct arm_option_cpu_value_table arm_extensions[] =
22376 {
22377 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22378 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22379 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
22380 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
22381 {NULL, ARM_ARCH_NONE}
22382 };
22383
22384 /* This list should, at a minimum, contain all the fpu names
22385 recognized by GCC. */
22386 static const struct arm_option_cpu_value_table arm_fpus[] =
22387 {
22388 {"softfpa", FPU_NONE},
22389 {"fpe", FPU_ARCH_FPE},
22390 {"fpe2", FPU_ARCH_FPE},
22391 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22392 {"fpa", FPU_ARCH_FPA},
22393 {"fpa10", FPU_ARCH_FPA},
22394 {"fpa11", FPU_ARCH_FPA},
22395 {"arm7500fe", FPU_ARCH_FPA},
22396 {"softvfp", FPU_ARCH_VFP},
22397 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22398 {"vfp", FPU_ARCH_VFP_V2},
22399 {"vfp9", FPU_ARCH_VFP_V2},
22400 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
22401 {"vfp10", FPU_ARCH_VFP_V2},
22402 {"vfp10-r0", FPU_ARCH_VFP_V1},
22403 {"vfpxd", FPU_ARCH_VFP_V1xD},
22404 {"vfpv2", FPU_ARCH_VFP_V2},
22405 {"vfpv3", FPU_ARCH_VFP_V3},
22406 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
22407 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
22408 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22409 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22410 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
22411 {"arm1020t", FPU_ARCH_VFP_V1},
22412 {"arm1020e", FPU_ARCH_VFP_V2},
22413 {"arm1136jfs", FPU_ARCH_VFP_V2},
22414 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22415 {"maverick", FPU_ARCH_MAVERICK},
22416 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
22417 {"neon-fp16", FPU_ARCH_NEON_FP16},
22418 {"vfpv4", FPU_ARCH_VFP_V4},
22419 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
22420 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
22421 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
22422 {NULL, ARM_ARCH_NONE}
22423 };
22424
22425 struct arm_option_value_table
22426 {
22427 char *name;
22428 long value;
22429 };
22430
22431 static const struct arm_option_value_table arm_float_abis[] =
22432 {
22433 {"hard", ARM_FLOAT_ABI_HARD},
22434 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22435 {"soft", ARM_FLOAT_ABI_SOFT},
22436 {NULL, 0}
22437 };
22438
22439 #ifdef OBJ_ELF
22440 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
22441 static const struct arm_option_value_table arm_eabis[] =
22442 {
22443 {"gnu", EF_ARM_EABI_UNKNOWN},
22444 {"4", EF_ARM_EABI_VER4},
22445 {"5", EF_ARM_EABI_VER5},
22446 {NULL, 0}
22447 };
22448 #endif
22449
22450 struct arm_long_option_table
22451 {
22452 char * option; /* Substring to match. */
22453 char * help; /* Help information. */
22454 int (* func) (char * subopt); /* Function to decode sub-option. */
22455 char * deprecated; /* If non-null, print this message. */
22456 };
22457
22458 static bfd_boolean
22459 arm_parse_extension (char * str, const arm_feature_set **opt_p)
22460 {
22461 arm_feature_set *ext_set = (arm_feature_set *)
22462 xmalloc (sizeof (arm_feature_set));
22463
22464 /* Copy the feature set, so that we can modify it. */
22465 *ext_set = **opt_p;
22466 *opt_p = ext_set;
22467
22468 while (str != NULL && *str != 0)
22469 {
22470 const struct arm_option_cpu_value_table * opt;
22471 char * ext;
22472 int optlen;
22473
22474 if (*str != '+')
22475 {
22476 as_bad (_("invalid architectural extension"));
22477 return FALSE;
22478 }
22479
22480 str++;
22481 ext = strchr (str, '+');
22482
22483 if (ext != NULL)
22484 optlen = ext - str;
22485 else
22486 optlen = strlen (str);
22487
22488 if (optlen == 0)
22489 {
22490 as_bad (_("missing architectural extension"));
22491 return FALSE;
22492 }
22493
22494 for (opt = arm_extensions; opt->name != NULL; opt++)
22495 if (strncmp (opt->name, str, optlen) == 0)
22496 {
22497 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
22498 break;
22499 }
22500
22501 if (opt->name == NULL)
22502 {
22503 as_bad (_("unknown architectural extension `%s'"), str);
22504 return FALSE;
22505 }
22506
22507 str = ext;
22508 };
22509
22510 return TRUE;
22511 }
22512
22513 static bfd_boolean
22514 arm_parse_cpu (char * str)
22515 {
22516 const struct arm_cpu_option_table * opt;
22517 char * ext = strchr (str, '+');
22518 int optlen;
22519
22520 if (ext != NULL)
22521 optlen = ext - str;
22522 else
22523 optlen = strlen (str);
22524
22525 if (optlen == 0)
22526 {
22527 as_bad (_("missing cpu name `%s'"), str);
22528 return FALSE;
22529 }
22530
22531 for (opt = arm_cpus; opt->name != NULL; opt++)
22532 if (strncmp (opt->name, str, optlen) == 0)
22533 {
22534 mcpu_cpu_opt = &opt->value;
22535 mcpu_fpu_opt = &opt->default_fpu;
22536 if (opt->canonical_name)
22537 strcpy (selected_cpu_name, opt->canonical_name);
22538 else
22539 {
22540 int i;
22541
22542 for (i = 0; i < optlen; i++)
22543 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22544 selected_cpu_name[i] = 0;
22545 }
22546
22547 if (ext != NULL)
22548 return arm_parse_extension (ext, &mcpu_cpu_opt);
22549
22550 return TRUE;
22551 }
22552
22553 as_bad (_("unknown cpu `%s'"), str);
22554 return FALSE;
22555 }
22556
22557 static bfd_boolean
22558 arm_parse_arch (char * str)
22559 {
22560 const struct arm_arch_option_table *opt;
22561 char *ext = strchr (str, '+');
22562 int optlen;
22563
22564 if (ext != NULL)
22565 optlen = ext - str;
22566 else
22567 optlen = strlen (str);
22568
22569 if (optlen == 0)
22570 {
22571 as_bad (_("missing architecture name `%s'"), str);
22572 return FALSE;
22573 }
22574
22575 for (opt = arm_archs; opt->name != NULL; opt++)
22576 if (streq (opt->name, str))
22577 {
22578 march_cpu_opt = &opt->value;
22579 march_fpu_opt = &opt->default_fpu;
22580 strcpy (selected_cpu_name, opt->name);
22581
22582 if (ext != NULL)
22583 return arm_parse_extension (ext, &march_cpu_opt);
22584
22585 return TRUE;
22586 }
22587
22588 as_bad (_("unknown architecture `%s'\n"), str);
22589 return FALSE;
22590 }
22591
22592 static bfd_boolean
22593 arm_parse_fpu (char * str)
22594 {
22595 const struct arm_option_cpu_value_table * opt;
22596
22597 for (opt = arm_fpus; opt->name != NULL; opt++)
22598 if (streq (opt->name, str))
22599 {
22600 mfpu_opt = &opt->value;
22601 return TRUE;
22602 }
22603
22604 as_bad (_("unknown floating point format `%s'\n"), str);
22605 return FALSE;
22606 }
22607
22608 static bfd_boolean
22609 arm_parse_float_abi (char * str)
22610 {
22611 const struct arm_option_value_table * opt;
22612
22613 for (opt = arm_float_abis; opt->name != NULL; opt++)
22614 if (streq (opt->name, str))
22615 {
22616 mfloat_abi_opt = opt->value;
22617 return TRUE;
22618 }
22619
22620 as_bad (_("unknown floating point abi `%s'\n"), str);
22621 return FALSE;
22622 }
22623
22624 #ifdef OBJ_ELF
22625 static bfd_boolean
22626 arm_parse_eabi (char * str)
22627 {
22628 const struct arm_option_value_table *opt;
22629
22630 for (opt = arm_eabis; opt->name != NULL; opt++)
22631 if (streq (opt->name, str))
22632 {
22633 meabi_flags = opt->value;
22634 return TRUE;
22635 }
22636 as_bad (_("unknown EABI `%s'\n"), str);
22637 return FALSE;
22638 }
22639 #endif
22640
22641 static bfd_boolean
22642 arm_parse_it_mode (char * str)
22643 {
22644 bfd_boolean ret = TRUE;
22645
22646 if (streq ("arm", str))
22647 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22648 else if (streq ("thumb", str))
22649 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22650 else if (streq ("always", str))
22651 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22652 else if (streq ("never", str))
22653 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22654 else
22655 {
22656 as_bad (_("unknown implicit IT mode `%s', should be "\
22657 "arm, thumb, always, or never."), str);
22658 ret = FALSE;
22659 }
22660
22661 return ret;
22662 }
22663
22664 struct arm_long_option_table arm_long_opts[] =
22665 {
22666 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22667 arm_parse_cpu, NULL},
22668 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22669 arm_parse_arch, NULL},
22670 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22671 arm_parse_fpu, NULL},
22672 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22673 arm_parse_float_abi, NULL},
22674 #ifdef OBJ_ELF
22675 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
22676 arm_parse_eabi, NULL},
22677 #endif
22678 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22679 arm_parse_it_mode, NULL},
22680 {NULL, NULL, 0, NULL}
22681 };
22682
22683 int
22684 md_parse_option (int c, char * arg)
22685 {
22686 struct arm_option_table *opt;
22687 const struct arm_legacy_option_table *fopt;
22688 struct arm_long_option_table *lopt;
22689
22690 switch (c)
22691 {
22692 #ifdef OPTION_EB
22693 case OPTION_EB:
22694 target_big_endian = 1;
22695 break;
22696 #endif
22697
22698 #ifdef OPTION_EL
22699 case OPTION_EL:
22700 target_big_endian = 0;
22701 break;
22702 #endif
22703
22704 case OPTION_FIX_V4BX:
22705 fix_v4bx = TRUE;
22706 break;
22707
22708 case 'a':
22709 /* Listing option. Just ignore these, we don't support additional
22710 ones. */
22711 return 0;
22712
22713 default:
22714 for (opt = arm_opts; opt->option != NULL; opt++)
22715 {
22716 if (c == opt->option[0]
22717 && ((arg == NULL && opt->option[1] == 0)
22718 || streq (arg, opt->option + 1)))
22719 {
22720 /* If the option is deprecated, tell the user. */
22721 if (warn_on_deprecated && opt->deprecated != NULL)
22722 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22723 arg ? arg : "", _(opt->deprecated));
22724
22725 if (opt->var != NULL)
22726 *opt->var = opt->value;
22727
22728 return 1;
22729 }
22730 }
22731
22732 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22733 {
22734 if (c == fopt->option[0]
22735 && ((arg == NULL && fopt->option[1] == 0)
22736 || streq (arg, fopt->option + 1)))
22737 {
22738 /* If the option is deprecated, tell the user. */
22739 if (warn_on_deprecated && fopt->deprecated != NULL)
22740 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22741 arg ? arg : "", _(fopt->deprecated));
22742
22743 if (fopt->var != NULL)
22744 *fopt->var = &fopt->value;
22745
22746 return 1;
22747 }
22748 }
22749
22750 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22751 {
22752 /* These options are expected to have an argument. */
22753 if (c == lopt->option[0]
22754 && arg != NULL
22755 && strncmp (arg, lopt->option + 1,
22756 strlen (lopt->option + 1)) == 0)
22757 {
22758 /* If the option is deprecated, tell the user. */
22759 if (warn_on_deprecated && lopt->deprecated != NULL)
22760 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22761 _(lopt->deprecated));
22762
22763 /* Call the sup-option parser. */
22764 return lopt->func (arg + strlen (lopt->option) - 1);
22765 }
22766 }
22767
22768 return 0;
22769 }
22770
22771 return 1;
22772 }
22773
22774 void
22775 md_show_usage (FILE * fp)
22776 {
22777 struct arm_option_table *opt;
22778 struct arm_long_option_table *lopt;
22779
22780 fprintf (fp, _(" ARM-specific assembler options:\n"));
22781
22782 for (opt = arm_opts; opt->option != NULL; opt++)
22783 if (opt->help != NULL)
22784 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
22785
22786 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22787 if (lopt->help != NULL)
22788 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
22789
22790 #ifdef OPTION_EB
22791 fprintf (fp, _("\
22792 -EB assemble code for a big-endian cpu\n"));
22793 #endif
22794
22795 #ifdef OPTION_EL
22796 fprintf (fp, _("\
22797 -EL assemble code for a little-endian cpu\n"));
22798 #endif
22799
22800 fprintf (fp, _("\
22801 --fix-v4bx Allow BX in ARMv4 code\n"));
22802 }
22803
22804
22805 #ifdef OBJ_ELF
22806 typedef struct
22807 {
22808 int val;
22809 arm_feature_set flags;
22810 } cpu_arch_ver_table;
22811
22812 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22813 least features first. */
22814 static const cpu_arch_ver_table cpu_arch_ver[] =
22815 {
22816 {1, ARM_ARCH_V4},
22817 {2, ARM_ARCH_V4T},
22818 {3, ARM_ARCH_V5},
22819 {3, ARM_ARCH_V5T},
22820 {4, ARM_ARCH_V5TE},
22821 {5, ARM_ARCH_V5TEJ},
22822 {6, ARM_ARCH_V6},
22823 {7, ARM_ARCH_V6Z},
22824 {9, ARM_ARCH_V6K},
22825 {11, ARM_ARCH_V6M},
22826 {8, ARM_ARCH_V6T2},
22827 {10, ARM_ARCH_V7A},
22828 {10, ARM_ARCH_V7R},
22829 {10, ARM_ARCH_V7M},
22830 {0, ARM_ARCH_NONE}
22831 };
22832
22833 /* Set an attribute if it has not already been set by the user. */
22834 static void
22835 aeabi_set_attribute_int (int tag, int value)
22836 {
22837 if (tag < 1
22838 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22839 || !attributes_set_explicitly[tag])
22840 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22841 }
22842
22843 static void
22844 aeabi_set_attribute_string (int tag, const char *value)
22845 {
22846 if (tag < 1
22847 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22848 || !attributes_set_explicitly[tag])
22849 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22850 }
22851
22852 /* Set the public EABI object attributes. */
22853 static void
22854 aeabi_set_public_attributes (void)
22855 {
22856 int arch;
22857 arm_feature_set flags;
22858 arm_feature_set tmp;
22859 const cpu_arch_ver_table *p;
22860
22861 /* Choose the architecture based on the capabilities of the requested cpu
22862 (if any) and/or the instructions actually used. */
22863 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22864 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22865 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
22866 /*Allow the user to override the reported architecture. */
22867 if (object_arch)
22868 {
22869 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22870 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22871 }
22872
22873 tmp = flags;
22874 arch = 0;
22875 for (p = cpu_arch_ver; p->val; p++)
22876 {
22877 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22878 {
22879 arch = p->val;
22880 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22881 }
22882 }
22883
22884 /* The table lookup above finds the last architecture to contribute
22885 a new feature. Unfortunately, Tag13 is a subset of the union of
22886 v6T2 and v7-M, so it is never seen as contributing a new feature.
22887 We can not search for the last entry which is entirely used,
22888 because if no CPU is specified we build up only those flags
22889 actually used. Perhaps we should separate out the specified
22890 and implicit cases. Avoid taking this path for -march=all by
22891 checking for contradictory v7-A / v7-M features. */
22892 if (arch == 10
22893 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22894 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22895 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22896 arch = 13;
22897
22898 /* Tag_CPU_name. */
22899 if (selected_cpu_name[0])
22900 {
22901 char *q;
22902
22903 q = selected_cpu_name;
22904 if (strncmp (q, "armv", 4) == 0)
22905 {
22906 int i;
22907
22908 q += 4;
22909 for (i = 0; q[i]; i++)
22910 q[i] = TOUPPER (q[i]);
22911 }
22912 aeabi_set_attribute_string (Tag_CPU_name, q);
22913 }
22914
22915 /* Tag_CPU_arch. */
22916 aeabi_set_attribute_int (Tag_CPU_arch, arch);
22917
22918 /* Tag_CPU_arch_profile. */
22919 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
22920 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
22921 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
22922 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
22923 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
22924 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
22925
22926 /* Tag_ARM_ISA_use. */
22927 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22928 || arch == 0)
22929 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
22930
22931 /* Tag_THUMB_ISA_use. */
22932 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22933 || arch == 0)
22934 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22935 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
22936
22937 /* Tag_VFP_arch. */
22938 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22939 aeabi_set_attribute_int (Tag_VFP_arch,
22940 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22941 ? 5 : 6);
22942 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
22943 aeabi_set_attribute_int (Tag_VFP_arch, 3);
22944 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
22945 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22946 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22947 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22948 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22949 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22950 aeabi_set_attribute_int (Tag_VFP_arch, 1);
22951
22952 /* Tag_ABI_HardFP_use. */
22953 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
22954 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
22955 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
22956
22957 /* Tag_WMMX_arch. */
22958 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22959 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22960 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22961 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
22962
22963 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
22964 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
22965 aeabi_set_attribute_int
22966 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22967 ? 2 : 1));
22968
22969 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
22970 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
22971 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
22972
22973 /* Tag_DIV_use. */
22974 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
22975 aeabi_set_attribute_int (Tag_DIV_use, 0);
22976 /* Fill this in when gas supports v7a sdiv/udiv.
22977 else if (... v7a with div extension used ...)
22978 aeabi_set_attribute_int (Tag_DIV_use, 2); */
22979 else
22980 aeabi_set_attribute_int (Tag_DIV_use, 1);
22981 }
22982
22983 /* Add the default contents for the .ARM.attributes section. */
22984 void
22985 arm_md_end (void)
22986 {
22987 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22988 return;
22989
22990 aeabi_set_public_attributes ();
22991 }
22992 #endif /* OBJ_ELF */
22993
22994
22995 /* Parse a .cpu directive. */
22996
22997 static void
22998 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22999 {
23000 const struct arm_cpu_option_table *opt;
23001 char *name;
23002 char saved_char;
23003
23004 name = input_line_pointer;
23005 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23006 input_line_pointer++;
23007 saved_char = *input_line_pointer;
23008 *input_line_pointer = 0;
23009
23010 /* Skip the first "all" entry. */
23011 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
23012 if (streq (opt->name, name))
23013 {
23014 mcpu_cpu_opt = &opt->value;
23015 selected_cpu = opt->value;
23016 if (opt->canonical_name)
23017 strcpy (selected_cpu_name, opt->canonical_name);
23018 else
23019 {
23020 int i;
23021 for (i = 0; opt->name[i]; i++)
23022 selected_cpu_name[i] = TOUPPER (opt->name[i]);
23023 selected_cpu_name[i] = 0;
23024 }
23025 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23026 *input_line_pointer = saved_char;
23027 demand_empty_rest_of_line ();
23028 return;
23029 }
23030 as_bad (_("unknown cpu `%s'"), name);
23031 *input_line_pointer = saved_char;
23032 ignore_rest_of_line ();
23033 }
23034
23035
23036 /* Parse a .arch directive. */
23037
23038 static void
23039 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
23040 {
23041 const struct arm_arch_option_table *opt;
23042 char saved_char;
23043 char *name;
23044
23045 name = input_line_pointer;
23046 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23047 input_line_pointer++;
23048 saved_char = *input_line_pointer;
23049 *input_line_pointer = 0;
23050
23051 /* Skip the first "all" entry. */
23052 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23053 if (streq (opt->name, name))
23054 {
23055 mcpu_cpu_opt = &opt->value;
23056 selected_cpu = opt->value;
23057 strcpy (selected_cpu_name, opt->name);
23058 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23059 *input_line_pointer = saved_char;
23060 demand_empty_rest_of_line ();
23061 return;
23062 }
23063
23064 as_bad (_("unknown architecture `%s'\n"), name);
23065 *input_line_pointer = saved_char;
23066 ignore_rest_of_line ();
23067 }
23068
23069
23070 /* Parse a .object_arch directive. */
23071
23072 static void
23073 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
23074 {
23075 const struct arm_arch_option_table *opt;
23076 char saved_char;
23077 char *name;
23078
23079 name = input_line_pointer;
23080 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23081 input_line_pointer++;
23082 saved_char = *input_line_pointer;
23083 *input_line_pointer = 0;
23084
23085 /* Skip the first "all" entry. */
23086 for (opt = arm_archs + 1; opt->name != NULL; opt++)
23087 if (streq (opt->name, name))
23088 {
23089 object_arch = &opt->value;
23090 *input_line_pointer = saved_char;
23091 demand_empty_rest_of_line ();
23092 return;
23093 }
23094
23095 as_bad (_("unknown architecture `%s'\n"), name);
23096 *input_line_pointer = saved_char;
23097 ignore_rest_of_line ();
23098 }
23099
23100 /* Parse a .fpu directive. */
23101
23102 static void
23103 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23104 {
23105 const struct arm_option_cpu_value_table *opt;
23106 char saved_char;
23107 char *name;
23108
23109 name = input_line_pointer;
23110 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23111 input_line_pointer++;
23112 saved_char = *input_line_pointer;
23113 *input_line_pointer = 0;
23114
23115 for (opt = arm_fpus; opt->name != NULL; opt++)
23116 if (streq (opt->name, name))
23117 {
23118 mfpu_opt = &opt->value;
23119 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23120 *input_line_pointer = saved_char;
23121 demand_empty_rest_of_line ();
23122 return;
23123 }
23124
23125 as_bad (_("unknown floating point format `%s'\n"), name);
23126 *input_line_pointer = saved_char;
23127 ignore_rest_of_line ();
23128 }
23129
23130 /* Copy symbol information. */
23131
23132 void
23133 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23134 {
23135 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23136 }
23137
23138 #ifdef OBJ_ELF
23139 /* Given a symbolic attribute NAME, return the proper integer value.
23140 Returns -1 if the attribute is not known. */
23141
23142 int
23143 arm_convert_symbolic_attribute (const char *name)
23144 {
23145 static const struct
23146 {
23147 const char * name;
23148 const int tag;
23149 }
23150 attribute_table[] =
23151 {
23152 /* When you modify this table you should
23153 also modify the list in doc/c-arm.texi. */
23154 #define T(tag) {#tag, tag}
23155 T (Tag_CPU_raw_name),
23156 T (Tag_CPU_name),
23157 T (Tag_CPU_arch),
23158 T (Tag_CPU_arch_profile),
23159 T (Tag_ARM_ISA_use),
23160 T (Tag_THUMB_ISA_use),
23161 T (Tag_FP_arch),
23162 T (Tag_VFP_arch),
23163 T (Tag_WMMX_arch),
23164 T (Tag_Advanced_SIMD_arch),
23165 T (Tag_PCS_config),
23166 T (Tag_ABI_PCS_R9_use),
23167 T (Tag_ABI_PCS_RW_data),
23168 T (Tag_ABI_PCS_RO_data),
23169 T (Tag_ABI_PCS_GOT_use),
23170 T (Tag_ABI_PCS_wchar_t),
23171 T (Tag_ABI_FP_rounding),
23172 T (Tag_ABI_FP_denormal),
23173 T (Tag_ABI_FP_exceptions),
23174 T (Tag_ABI_FP_user_exceptions),
23175 T (Tag_ABI_FP_number_model),
23176 T (Tag_ABI_align_needed),
23177 T (Tag_ABI_align8_needed),
23178 T (Tag_ABI_align_preserved),
23179 T (Tag_ABI_align8_preserved),
23180 T (Tag_ABI_enum_size),
23181 T (Tag_ABI_HardFP_use),
23182 T (Tag_ABI_VFP_args),
23183 T (Tag_ABI_WMMX_args),
23184 T (Tag_ABI_optimization_goals),
23185 T (Tag_ABI_FP_optimization_goals),
23186 T (Tag_compatibility),
23187 T (Tag_CPU_unaligned_access),
23188 T (Tag_FP_HP_extension),
23189 T (Tag_VFP_HP_extension),
23190 T (Tag_ABI_FP_16bit_format),
23191 T (Tag_MPextension_use),
23192 T (Tag_DIV_use),
23193 T (Tag_nodefaults),
23194 T (Tag_also_compatible_with),
23195 T (Tag_conformance),
23196 T (Tag_T2EE_use),
23197 T (Tag_Virtualization_use),
23198 /* We deliberately do not include Tag_MPextension_use_legacy. */
23199 #undef T
23200 };
23201 unsigned int i;
23202
23203 if (name == NULL)
23204 return -1;
23205
23206 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
23207 if (streq (name, attribute_table[i].name))
23208 return attribute_table[i].tag;
23209
23210 return -1;
23211 }
23212
23213
23214 /* Apply sym value for relocations only in the case that
23215 they are for local symbols and you have the respective
23216 architectural feature for blx and simple switches. */
23217 int
23218 arm_apply_sym_value (struct fix * fixP)
23219 {
23220 if (fixP->fx_addsy
23221 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23222 && !S_IS_EXTERNAL (fixP->fx_addsy))
23223 {
23224 switch (fixP->fx_r_type)
23225 {
23226 case BFD_RELOC_ARM_PCREL_BLX:
23227 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23228 if (ARM_IS_FUNC (fixP->fx_addsy))
23229 return 1;
23230 break;
23231
23232 case BFD_RELOC_ARM_PCREL_CALL:
23233 case BFD_RELOC_THUMB_PCREL_BLX:
23234 if (THUMB_IS_FUNC (fixP->fx_addsy))
23235 return 1;
23236 break;
23237
23238 default:
23239 break;
23240 }
23241
23242 }
23243 return 0;
23244 }
23245 #endif /* OBJ_ELF */
This page took 1.030081 seconds and 5 git commands to generate.