2009-04-01 Ramana Radhakrishnan <ramana.radhakrishnan@arm.com>
[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
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 <limits.h>
29 #include <stdarg.h>
30 #define NO_RELOC 0
31 #include "as.h"
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 /* Bit N indicates that an R_ARM_NONE relocation has been output for
81 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
82 emitted only once per section, to save unnecessary bloat. */
83 static unsigned int marked_pr_dependency = 0;
84
85 #endif /* OBJ_ELF */
86
87 /* Results from operand parsing worker functions. */
88
89 typedef enum
90 {
91 PARSE_OPERAND_SUCCESS,
92 PARSE_OPERAND_FAIL,
93 PARSE_OPERAND_FAIL_NO_BACKTRACK
94 } parse_operand_result;
95
96 enum arm_float_abi
97 {
98 ARM_FLOAT_ABI_HARD,
99 ARM_FLOAT_ABI_SOFTFP,
100 ARM_FLOAT_ABI_SOFT
101 };
102
103 /* Types of processor to assemble for. */
104 #ifndef CPU_DEFAULT
105 #if defined __XSCALE__
106 #define CPU_DEFAULT ARM_ARCH_XSCALE
107 #else
108 #if defined __thumb__
109 #define CPU_DEFAULT ARM_ARCH_V5T
110 #endif
111 #endif
112 #endif
113
114 #ifndef FPU_DEFAULT
115 # ifdef TE_LINUX
116 # define FPU_DEFAULT FPU_ARCH_FPA
117 # elif defined (TE_NetBSD)
118 # ifdef OBJ_ELF
119 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
120 # else
121 /* Legacy a.out format. */
122 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
123 # endif
124 # elif defined (TE_VXWORKS)
125 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
126 # else
127 /* For backwards compatibility, default to FPA. */
128 # define FPU_DEFAULT FPU_ARCH_FPA
129 # endif
130 #endif /* ifndef FPU_DEFAULT */
131
132 #define streq(a, b) (strcmp (a, b) == 0)
133
134 static arm_feature_set cpu_variant;
135 static arm_feature_set arm_arch_used;
136 static arm_feature_set thumb_arch_used;
137
138 /* Flags stored in private area of BFD structure. */
139 static int uses_apcs_26 = FALSE;
140 static int atpcs = FALSE;
141 static int support_interwork = FALSE;
142 static int uses_apcs_float = FALSE;
143 static int pic_code = FALSE;
144 static int fix_v4bx = FALSE;
145 /* Warn on using deprecated features. */
146 static int warn_on_deprecated = TRUE;
147
148
149 /* Variables that we set while parsing command-line options. Once all
150 options have been read we re-process these values to set the real
151 assembly flags. */
152 static const arm_feature_set *legacy_cpu = NULL;
153 static const arm_feature_set *legacy_fpu = NULL;
154
155 static const arm_feature_set *mcpu_cpu_opt = NULL;
156 static const arm_feature_set *mcpu_fpu_opt = NULL;
157 static const arm_feature_set *march_cpu_opt = NULL;
158 static const arm_feature_set *march_fpu_opt = NULL;
159 static const arm_feature_set *mfpu_opt = NULL;
160 static const arm_feature_set *object_arch = NULL;
161
162 /* Constants for known architecture features. */
163 static const arm_feature_set fpu_default = FPU_DEFAULT;
164 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
165 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
166 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
167 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
168 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
169 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
170 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
171 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
172
173 #ifdef CPU_DEFAULT
174 static const arm_feature_set cpu_default = CPU_DEFAULT;
175 #endif
176
177 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
178 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
179 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
180 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
181 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
182 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
183 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
184 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
185 static const arm_feature_set arm_ext_v4t_5 =
186 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
187 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
188 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
189 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
190 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
191 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
192 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
193 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
194 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
195 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
196 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
197 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
198 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
199 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
200 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
201 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
202 static const arm_feature_set arm_ext_m =
203 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
204
205 static const arm_feature_set arm_arch_any = ARM_ANY;
206 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
207 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
208 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
209
210 static const arm_feature_set arm_cext_iwmmxt2 =
211 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
212 static const arm_feature_set arm_cext_iwmmxt =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
214 static const arm_feature_set arm_cext_xscale =
215 ARM_FEATURE (0, ARM_CEXT_XSCALE);
216 static const arm_feature_set arm_cext_maverick =
217 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
218 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
219 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
220 static const arm_feature_set fpu_vfp_ext_v1xd =
221 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
222 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
223 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
224 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
225 static const arm_feature_set fpu_vfp_ext_d32 =
226 ARM_FEATURE (0, FPU_VFP_EXT_D32);
227 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
228 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
229 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
230 static const arm_feature_set fpu_neon_fp16 = ARM_FEATURE (0, FPU_NEON_FP16);
231
232 static int mfloat_abi_opt = -1;
233 /* Record user cpu selection for object attributes. */
234 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
235 /* Must be long enough to hold any of the names in arm_cpus. */
236 static char selected_cpu_name[16];
237 #ifdef OBJ_ELF
238 # ifdef EABI_DEFAULT
239 static int meabi_flags = EABI_DEFAULT;
240 # else
241 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
242 # endif
243
244 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
245
246 bfd_boolean
247 arm_is_eabi (void)
248 {
249 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
250 }
251 #endif
252
253 #ifdef OBJ_ELF
254 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
255 symbolS * GOT_symbol;
256 #endif
257
258 /* 0: assemble for ARM,
259 1: assemble for Thumb,
260 2: assemble for Thumb even though target CPU does not support thumb
261 instructions. */
262 static int thumb_mode = 0;
263 /* A value distinct from the possible values for thumb_mode that we
264 can use to record whether thumb_mode has been copied into the
265 tc_frag_data field of a frag. */
266 #define MODE_RECORDED (1 << 4)
267
268 /* If unified_syntax is true, we are processing the new unified
269 ARM/Thumb syntax. Important differences from the old ARM mode:
270
271 - Immediate operands do not require a # prefix.
272 - Conditional affixes always appear at the end of the
273 instruction. (For backward compatibility, those instructions
274 that formerly had them in the middle, continue to accept them
275 there.)
276 - The IT instruction may appear, and if it does is validated
277 against subsequent conditional affixes. It does not generate
278 machine code.
279
280 Important differences from the old Thumb mode:
281
282 - Immediate operands do not require a # prefix.
283 - Most of the V6T2 instructions are only available in unified mode.
284 - The .N and .W suffixes are recognized and honored (it is an error
285 if they cannot be honored).
286 - All instructions set the flags if and only if they have an 's' affix.
287 - Conditional affixes may be used. They are validated against
288 preceding IT instructions. Unlike ARM mode, you cannot use a
289 conditional affix except in the scope of an IT instruction. */
290
291 static bfd_boolean unified_syntax = FALSE;
292
293 enum neon_el_type
294 {
295 NT_invtype,
296 NT_untyped,
297 NT_integer,
298 NT_float,
299 NT_poly,
300 NT_signed,
301 NT_unsigned
302 };
303
304 struct neon_type_el
305 {
306 enum neon_el_type type;
307 unsigned size;
308 };
309
310 #define NEON_MAX_TYPE_ELS 4
311
312 struct neon_type
313 {
314 struct neon_type_el el[NEON_MAX_TYPE_ELS];
315 unsigned elems;
316 };
317
318 struct arm_it
319 {
320 const char * error;
321 unsigned long instruction;
322 int size;
323 int size_req;
324 int cond;
325 /* "uncond_value" is set to the value in place of the conditional field in
326 unconditional versions of the instruction, or -1 if nothing is
327 appropriate. */
328 int uncond_value;
329 struct neon_type vectype;
330 /* Set to the opcode if the instruction needs relaxation.
331 Zero if the instruction is not relaxed. */
332 unsigned long relax;
333 struct
334 {
335 bfd_reloc_code_real_type type;
336 expressionS exp;
337 int pc_rel;
338 } reloc;
339
340 struct
341 {
342 unsigned reg;
343 signed int imm;
344 struct neon_type_el vectype;
345 unsigned present : 1; /* Operand present. */
346 unsigned isreg : 1; /* Operand was a register. */
347 unsigned immisreg : 1; /* .imm field is a second register. */
348 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
349 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
350 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
351 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
352 instructions. This allows us to disambiguate ARM <-> vector insns. */
353 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
354 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
355 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
356 unsigned issingle : 1; /* Operand is VFP single-precision register. */
357 unsigned hasreloc : 1; /* Operand has relocation suffix. */
358 unsigned writeback : 1; /* Operand has trailing ! */
359 unsigned preind : 1; /* Preindexed address. */
360 unsigned postind : 1; /* Postindexed address. */
361 unsigned negative : 1; /* Index register was negated. */
362 unsigned shifted : 1; /* Shift applied to operation. */
363 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
364 } operands[6];
365 };
366
367 static struct arm_it inst;
368
369 #define NUM_FLOAT_VALS 8
370
371 const char * fp_const[] =
372 {
373 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
374 };
375
376 /* Number of littlenums required to hold an extended precision number. */
377 #define MAX_LITTLENUMS 6
378
379 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
380
381 #define FAIL (-1)
382 #define SUCCESS (0)
383
384 #define SUFF_S 1
385 #define SUFF_D 2
386 #define SUFF_E 3
387 #define SUFF_P 4
388
389 #define CP_T_X 0x00008000
390 #define CP_T_Y 0x00400000
391
392 #define CONDS_BIT 0x00100000
393 #define LOAD_BIT 0x00100000
394
395 #define DOUBLE_LOAD_FLAG 0x00000001
396
397 struct asm_cond
398 {
399 const char * template;
400 unsigned long value;
401 };
402
403 #define COND_ALWAYS 0xE
404
405 struct asm_psr
406 {
407 const char *template;
408 unsigned long field;
409 };
410
411 struct asm_barrier_opt
412 {
413 const char *template;
414 unsigned long value;
415 };
416
417 /* The bit that distinguishes CPSR and SPSR. */
418 #define SPSR_BIT (1 << 22)
419
420 /* The individual PSR flag bits. */
421 #define PSR_c (1 << 16)
422 #define PSR_x (1 << 17)
423 #define PSR_s (1 << 18)
424 #define PSR_f (1 << 19)
425
426 struct reloc_entry
427 {
428 char *name;
429 bfd_reloc_code_real_type reloc;
430 };
431
432 enum vfp_reg_pos
433 {
434 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
435 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
436 };
437
438 enum vfp_ldstm_type
439 {
440 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
441 };
442
443 /* Bits for DEFINED field in neon_typed_alias. */
444 #define NTA_HASTYPE 1
445 #define NTA_HASINDEX 2
446
447 struct neon_typed_alias
448 {
449 unsigned char defined;
450 unsigned char index;
451 struct neon_type_el eltype;
452 };
453
454 /* ARM register categories. This includes coprocessor numbers and various
455 architecture extensions' registers. */
456 enum arm_reg_type
457 {
458 REG_TYPE_RN,
459 REG_TYPE_CP,
460 REG_TYPE_CN,
461 REG_TYPE_FN,
462 REG_TYPE_VFS,
463 REG_TYPE_VFD,
464 REG_TYPE_NQ,
465 REG_TYPE_VFSD,
466 REG_TYPE_NDQ,
467 REG_TYPE_NSDQ,
468 REG_TYPE_VFC,
469 REG_TYPE_MVF,
470 REG_TYPE_MVD,
471 REG_TYPE_MVFX,
472 REG_TYPE_MVDX,
473 REG_TYPE_MVAX,
474 REG_TYPE_DSPSC,
475 REG_TYPE_MMXWR,
476 REG_TYPE_MMXWC,
477 REG_TYPE_MMXWCG,
478 REG_TYPE_XSCALE,
479 };
480
481 /* Structure for a hash table entry for a register.
482 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
483 information which states whether a vector type or index is specified (for a
484 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
485 struct reg_entry
486 {
487 const char *name;
488 unsigned char number;
489 unsigned char type;
490 unsigned char builtin;
491 struct neon_typed_alias *neon;
492 };
493
494 /* Diagnostics used when we don't get a register of the expected type. */
495 const char *const reg_expected_msgs[] =
496 {
497 N_("ARM register expected"),
498 N_("bad or missing co-processor number"),
499 N_("co-processor register expected"),
500 N_("FPA register expected"),
501 N_("VFP single precision register expected"),
502 N_("VFP/Neon double precision register expected"),
503 N_("Neon quad precision register expected"),
504 N_("VFP single or double precision register expected"),
505 N_("Neon double or quad precision register expected"),
506 N_("VFP single, double or Neon quad precision register expected"),
507 N_("VFP system register expected"),
508 N_("Maverick MVF register expected"),
509 N_("Maverick MVD register expected"),
510 N_("Maverick MVFX register expected"),
511 N_("Maverick MVDX register expected"),
512 N_("Maverick MVAX register expected"),
513 N_("Maverick DSPSC register expected"),
514 N_("iWMMXt data register expected"),
515 N_("iWMMXt control register expected"),
516 N_("iWMMXt scalar register expected"),
517 N_("XScale accumulator register expected"),
518 };
519
520 /* Some well known registers that we refer to directly elsewhere. */
521 #define REG_SP 13
522 #define REG_LR 14
523 #define REG_PC 15
524
525 /* ARM instructions take 4bytes in the object file, Thumb instructions
526 take 2: */
527 #define INSN_SIZE 4
528
529 struct asm_opcode
530 {
531 /* Basic string to match. */
532 const char *template;
533
534 /* Parameters to instruction. */
535 unsigned char operands[8];
536
537 /* Conditional tag - see opcode_lookup. */
538 unsigned int tag : 4;
539
540 /* Basic instruction code. */
541 unsigned int avalue : 28;
542
543 /* Thumb-format instruction code. */
544 unsigned int tvalue;
545
546 /* Which architecture variant provides this instruction. */
547 const arm_feature_set *avariant;
548 const arm_feature_set *tvariant;
549
550 /* Function to call to encode instruction in ARM format. */
551 void (* aencode) (void);
552
553 /* Function to call to encode instruction in Thumb format. */
554 void (* tencode) (void);
555 };
556
557 /* Defines for various bits that we will want to toggle. */
558 #define INST_IMMEDIATE 0x02000000
559 #define OFFSET_REG 0x02000000
560 #define HWOFFSET_IMM 0x00400000
561 #define SHIFT_BY_REG 0x00000010
562 #define PRE_INDEX 0x01000000
563 #define INDEX_UP 0x00800000
564 #define WRITE_BACK 0x00200000
565 #define LDM_TYPE_2_OR_3 0x00400000
566 #define CPSI_MMOD 0x00020000
567
568 #define LITERAL_MASK 0xf000f000
569 #define OPCODE_MASK 0xfe1fffff
570 #define V4_STR_BIT 0x00000020
571
572 #define T2_SUBS_PC_LR 0xf3de8f00
573
574 #define DATA_OP_SHIFT 21
575
576 #define T2_OPCODE_MASK 0xfe1fffff
577 #define T2_DATA_OP_SHIFT 21
578
579 /* Codes to distinguish the arithmetic instructions. */
580 #define OPCODE_AND 0
581 #define OPCODE_EOR 1
582 #define OPCODE_SUB 2
583 #define OPCODE_RSB 3
584 #define OPCODE_ADD 4
585 #define OPCODE_ADC 5
586 #define OPCODE_SBC 6
587 #define OPCODE_RSC 7
588 #define OPCODE_TST 8
589 #define OPCODE_TEQ 9
590 #define OPCODE_CMP 10
591 #define OPCODE_CMN 11
592 #define OPCODE_ORR 12
593 #define OPCODE_MOV 13
594 #define OPCODE_BIC 14
595 #define OPCODE_MVN 15
596
597 #define T2_OPCODE_AND 0
598 #define T2_OPCODE_BIC 1
599 #define T2_OPCODE_ORR 2
600 #define T2_OPCODE_ORN 3
601 #define T2_OPCODE_EOR 4
602 #define T2_OPCODE_ADD 8
603 #define T2_OPCODE_ADC 10
604 #define T2_OPCODE_SBC 11
605 #define T2_OPCODE_SUB 13
606 #define T2_OPCODE_RSB 14
607
608 #define T_OPCODE_MUL 0x4340
609 #define T_OPCODE_TST 0x4200
610 #define T_OPCODE_CMN 0x42c0
611 #define T_OPCODE_NEG 0x4240
612 #define T_OPCODE_MVN 0x43c0
613
614 #define T_OPCODE_ADD_R3 0x1800
615 #define T_OPCODE_SUB_R3 0x1a00
616 #define T_OPCODE_ADD_HI 0x4400
617 #define T_OPCODE_ADD_ST 0xb000
618 #define T_OPCODE_SUB_ST 0xb080
619 #define T_OPCODE_ADD_SP 0xa800
620 #define T_OPCODE_ADD_PC 0xa000
621 #define T_OPCODE_ADD_I8 0x3000
622 #define T_OPCODE_SUB_I8 0x3800
623 #define T_OPCODE_ADD_I3 0x1c00
624 #define T_OPCODE_SUB_I3 0x1e00
625
626 #define T_OPCODE_ASR_R 0x4100
627 #define T_OPCODE_LSL_R 0x4080
628 #define T_OPCODE_LSR_R 0x40c0
629 #define T_OPCODE_ROR_R 0x41c0
630 #define T_OPCODE_ASR_I 0x1000
631 #define T_OPCODE_LSL_I 0x0000
632 #define T_OPCODE_LSR_I 0x0800
633
634 #define T_OPCODE_MOV_I8 0x2000
635 #define T_OPCODE_CMP_I8 0x2800
636 #define T_OPCODE_CMP_LR 0x4280
637 #define T_OPCODE_MOV_HR 0x4600
638 #define T_OPCODE_CMP_HR 0x4500
639
640 #define T_OPCODE_LDR_PC 0x4800
641 #define T_OPCODE_LDR_SP 0x9800
642 #define T_OPCODE_STR_SP 0x9000
643 #define T_OPCODE_LDR_IW 0x6800
644 #define T_OPCODE_STR_IW 0x6000
645 #define T_OPCODE_LDR_IH 0x8800
646 #define T_OPCODE_STR_IH 0x8000
647 #define T_OPCODE_LDR_IB 0x7800
648 #define T_OPCODE_STR_IB 0x7000
649 #define T_OPCODE_LDR_RW 0x5800
650 #define T_OPCODE_STR_RW 0x5000
651 #define T_OPCODE_LDR_RH 0x5a00
652 #define T_OPCODE_STR_RH 0x5200
653 #define T_OPCODE_LDR_RB 0x5c00
654 #define T_OPCODE_STR_RB 0x5400
655
656 #define T_OPCODE_PUSH 0xb400
657 #define T_OPCODE_POP 0xbc00
658
659 #define T_OPCODE_BRANCH 0xe000
660
661 #define THUMB_SIZE 2 /* Size of thumb instruction. */
662 #define THUMB_PP_PC_LR 0x0100
663 #define THUMB_LOAD_BIT 0x0800
664 #define THUMB2_LOAD_BIT 0x00100000
665
666 #define BAD_ARGS _("bad arguments to instruction")
667 #define BAD_SP _("r13 not allowed here")
668 #define BAD_PC _("r15 not allowed here")
669 #define BAD_COND _("instruction cannot be conditional")
670 #define BAD_OVERLAP _("registers may not be the same")
671 #define BAD_HIREG _("lo register required")
672 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
673 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
674 #define BAD_BRANCH _("branch must be last instruction in IT block")
675 #define BAD_NOT_IT _("instruction not allowed in IT block")
676 #define BAD_FPU _("selected FPU does not support instruction")
677
678 static struct hash_control *arm_ops_hsh;
679 static struct hash_control *arm_cond_hsh;
680 static struct hash_control *arm_shift_hsh;
681 static struct hash_control *arm_psr_hsh;
682 static struct hash_control *arm_v7m_psr_hsh;
683 static struct hash_control *arm_reg_hsh;
684 static struct hash_control *arm_reloc_hsh;
685 static struct hash_control *arm_barrier_opt_hsh;
686
687 /* Stuff needed to resolve the label ambiguity
688 As:
689 ...
690 label: <insn>
691 may differ from:
692 ...
693 label:
694 <insn> */
695
696 symbolS * last_label_seen;
697 static int label_is_thumb_function_name = FALSE;
698 \f
699 /* Literal pool structure. Held on a per-section
700 and per-sub-section basis. */
701
702 #define MAX_LITERAL_POOL_SIZE 1024
703 typedef struct literal_pool
704 {
705 expressionS literals [MAX_LITERAL_POOL_SIZE];
706 unsigned int next_free_entry;
707 unsigned int id;
708 symbolS * symbol;
709 segT section;
710 subsegT sub_section;
711 struct literal_pool * next;
712 } literal_pool;
713
714 /* Pointer to a linked list of literal pools. */
715 literal_pool * list_of_pools = NULL;
716
717 /* State variables for IT block handling. */
718 static bfd_boolean current_it_mask = 0;
719 static int current_cc;
720 \f
721 /* Pure syntax. */
722
723 /* This array holds the chars that always start a comment. If the
724 pre-processor is disabled, these aren't very useful. */
725 const char comment_chars[] = "@";
726
727 /* This array holds the chars that only start a comment at the beginning of
728 a line. If the line seems to have the form '# 123 filename'
729 .line and .file directives will appear in the pre-processed output. */
730 /* Note that input_file.c hand checks for '#' at the beginning of the
731 first line of the input file. This is because the compiler outputs
732 #NO_APP at the beginning of its output. */
733 /* Also note that comments like this one will always work. */
734 const char line_comment_chars[] = "#";
735
736 const char line_separator_chars[] = ";";
737
738 /* Chars that can be used to separate mant
739 from exp in floating point numbers. */
740 const char EXP_CHARS[] = "eE";
741
742 /* Chars that mean this number is a floating point constant. */
743 /* As in 0f12.456 */
744 /* or 0d1.2345e12 */
745
746 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
747
748 /* Prefix characters that indicate the start of an immediate
749 value. */
750 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
751
752 /* Separator character handling. */
753
754 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
755
756 static inline int
757 skip_past_char (char ** str, char c)
758 {
759 if (**str == c)
760 {
761 (*str)++;
762 return SUCCESS;
763 }
764 else
765 return FAIL;
766 }
767 #define skip_past_comma(str) skip_past_char (str, ',')
768
769 /* Arithmetic expressions (possibly involving symbols). */
770
771 /* Return TRUE if anything in the expression is a bignum. */
772
773 static int
774 walk_no_bignums (symbolS * sp)
775 {
776 if (symbol_get_value_expression (sp)->X_op == O_big)
777 return 1;
778
779 if (symbol_get_value_expression (sp)->X_add_symbol)
780 {
781 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
782 || (symbol_get_value_expression (sp)->X_op_symbol
783 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
784 }
785
786 return 0;
787 }
788
789 static int in_my_get_expression = 0;
790
791 /* Third argument to my_get_expression. */
792 #define GE_NO_PREFIX 0
793 #define GE_IMM_PREFIX 1
794 #define GE_OPT_PREFIX 2
795 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
796 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
797 #define GE_OPT_PREFIX_BIG 3
798
799 static int
800 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
801 {
802 char * save_in;
803 segT seg;
804
805 /* In unified syntax, all prefixes are optional. */
806 if (unified_syntax)
807 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
808 : GE_OPT_PREFIX;
809
810 switch (prefix_mode)
811 {
812 case GE_NO_PREFIX: break;
813 case GE_IMM_PREFIX:
814 if (!is_immediate_prefix (**str))
815 {
816 inst.error = _("immediate expression requires a # prefix");
817 return FAIL;
818 }
819 (*str)++;
820 break;
821 case GE_OPT_PREFIX:
822 case GE_OPT_PREFIX_BIG:
823 if (is_immediate_prefix (**str))
824 (*str)++;
825 break;
826 default: abort ();
827 }
828
829 memset (ep, 0, sizeof (expressionS));
830
831 save_in = input_line_pointer;
832 input_line_pointer = *str;
833 in_my_get_expression = 1;
834 seg = expression (ep);
835 in_my_get_expression = 0;
836
837 if (ep->X_op == O_illegal)
838 {
839 /* We found a bad expression in md_operand(). */
840 *str = input_line_pointer;
841 input_line_pointer = save_in;
842 if (inst.error == NULL)
843 inst.error = _("bad expression");
844 return 1;
845 }
846
847 #ifdef OBJ_AOUT
848 if (seg != absolute_section
849 && seg != text_section
850 && seg != data_section
851 && seg != bss_section
852 && seg != undefined_section)
853 {
854 inst.error = _("bad segment");
855 *str = input_line_pointer;
856 input_line_pointer = save_in;
857 return 1;
858 }
859 #endif
860
861 /* Get rid of any bignums now, so that we don't generate an error for which
862 we can't establish a line number later on. Big numbers are never valid
863 in instructions, which is where this routine is always called. */
864 if (prefix_mode != GE_OPT_PREFIX_BIG
865 && (ep->X_op == O_big
866 || (ep->X_add_symbol
867 && (walk_no_bignums (ep->X_add_symbol)
868 || (ep->X_op_symbol
869 && walk_no_bignums (ep->X_op_symbol))))))
870 {
871 inst.error = _("invalid constant");
872 *str = input_line_pointer;
873 input_line_pointer = save_in;
874 return 1;
875 }
876
877 *str = input_line_pointer;
878 input_line_pointer = save_in;
879 return 0;
880 }
881
882 /* Turn a string in input_line_pointer into a floating point constant
883 of type TYPE, and store the appropriate bytes in *LITP. The number
884 of LITTLENUMS emitted is stored in *SIZEP. An error message is
885 returned, or NULL on OK.
886
887 Note that fp constants aren't represent in the normal way on the ARM.
888 In big endian mode, things are as expected. However, in little endian
889 mode fp constants are big-endian word-wise, and little-endian byte-wise
890 within the words. For example, (double) 1.1 in big endian mode is
891 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
892 the byte sequence 99 99 f1 3f 9a 99 99 99.
893
894 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
895
896 char *
897 md_atof (int type, char * litP, int * sizeP)
898 {
899 int prec;
900 LITTLENUM_TYPE words[MAX_LITTLENUMS];
901 char *t;
902 int i;
903
904 switch (type)
905 {
906 case 'f':
907 case 'F':
908 case 's':
909 case 'S':
910 prec = 2;
911 break;
912
913 case 'd':
914 case 'D':
915 case 'r':
916 case 'R':
917 prec = 4;
918 break;
919
920 case 'x':
921 case 'X':
922 prec = 5;
923 break;
924
925 case 'p':
926 case 'P':
927 prec = 5;
928 break;
929
930 default:
931 *sizeP = 0;
932 return _("Unrecognized or unsupported floating point constant");
933 }
934
935 t = atof_ieee (input_line_pointer, type, words);
936 if (t)
937 input_line_pointer = t;
938 *sizeP = prec * sizeof (LITTLENUM_TYPE);
939
940 if (target_big_endian)
941 {
942 for (i = 0; i < prec; i++)
943 {
944 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
945 litP += sizeof (LITTLENUM_TYPE);
946 }
947 }
948 else
949 {
950 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
951 for (i = prec - 1; i >= 0; i--)
952 {
953 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
954 litP += sizeof (LITTLENUM_TYPE);
955 }
956 else
957 /* For a 4 byte float the order of elements in `words' is 1 0.
958 For an 8 byte float the order is 1 0 3 2. */
959 for (i = 0; i < prec; i += 2)
960 {
961 md_number_to_chars (litP, (valueT) words[i + 1],
962 sizeof (LITTLENUM_TYPE));
963 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
964 (valueT) words[i], sizeof (LITTLENUM_TYPE));
965 litP += 2 * sizeof (LITTLENUM_TYPE);
966 }
967 }
968
969 return NULL;
970 }
971
972 /* We handle all bad expressions here, so that we can report the faulty
973 instruction in the error message. */
974 void
975 md_operand (expressionS * expr)
976 {
977 if (in_my_get_expression)
978 expr->X_op = O_illegal;
979 }
980
981 /* Immediate values. */
982
983 /* Generic immediate-value read function for use in directives.
984 Accepts anything that 'expression' can fold to a constant.
985 *val receives the number. */
986 #ifdef OBJ_ELF
987 static int
988 immediate_for_directive (int *val)
989 {
990 expressionS exp;
991 exp.X_op = O_illegal;
992
993 if (is_immediate_prefix (*input_line_pointer))
994 {
995 input_line_pointer++;
996 expression (&exp);
997 }
998
999 if (exp.X_op != O_constant)
1000 {
1001 as_bad (_("expected #constant"));
1002 ignore_rest_of_line ();
1003 return FAIL;
1004 }
1005 *val = exp.X_add_number;
1006 return SUCCESS;
1007 }
1008 #endif
1009
1010 /* Register parsing. */
1011
1012 /* Generic register parser. CCP points to what should be the
1013 beginning of a register name. If it is indeed a valid register
1014 name, advance CCP over it and return the reg_entry structure;
1015 otherwise return NULL. Does not issue diagnostics. */
1016
1017 static struct reg_entry *
1018 arm_reg_parse_multi (char **ccp)
1019 {
1020 char *start = *ccp;
1021 char *p;
1022 struct reg_entry *reg;
1023
1024 #ifdef REGISTER_PREFIX
1025 if (*start != REGISTER_PREFIX)
1026 return NULL;
1027 start++;
1028 #endif
1029 #ifdef OPTIONAL_REGISTER_PREFIX
1030 if (*start == OPTIONAL_REGISTER_PREFIX)
1031 start++;
1032 #endif
1033
1034 p = start;
1035 if (!ISALPHA (*p) || !is_name_beginner (*p))
1036 return NULL;
1037
1038 do
1039 p++;
1040 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1041
1042 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1043
1044 if (!reg)
1045 return NULL;
1046
1047 *ccp = p;
1048 return reg;
1049 }
1050
1051 static int
1052 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1053 enum arm_reg_type type)
1054 {
1055 /* Alternative syntaxes are accepted for a few register classes. */
1056 switch (type)
1057 {
1058 case REG_TYPE_MVF:
1059 case REG_TYPE_MVD:
1060 case REG_TYPE_MVFX:
1061 case REG_TYPE_MVDX:
1062 /* Generic coprocessor register names are allowed for these. */
1063 if (reg && reg->type == REG_TYPE_CN)
1064 return reg->number;
1065 break;
1066
1067 case REG_TYPE_CP:
1068 /* For backward compatibility, a bare number is valid here. */
1069 {
1070 unsigned long processor = strtoul (start, ccp, 10);
1071 if (*ccp != start && processor <= 15)
1072 return processor;
1073 }
1074
1075 case REG_TYPE_MMXWC:
1076 /* WC includes WCG. ??? I'm not sure this is true for all
1077 instructions that take WC registers. */
1078 if (reg && reg->type == REG_TYPE_MMXWCG)
1079 return reg->number;
1080 break;
1081
1082 default:
1083 break;
1084 }
1085
1086 return FAIL;
1087 }
1088
1089 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1090 return value is the register number or FAIL. */
1091
1092 static int
1093 arm_reg_parse (char **ccp, enum arm_reg_type type)
1094 {
1095 char *start = *ccp;
1096 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1097 int ret;
1098
1099 /* Do not allow a scalar (reg+index) to parse as a register. */
1100 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1101 return FAIL;
1102
1103 if (reg && reg->type == type)
1104 return reg->number;
1105
1106 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1107 return ret;
1108
1109 *ccp = start;
1110 return FAIL;
1111 }
1112
1113 /* Parse a Neon type specifier. *STR should point at the leading '.'
1114 character. Does no verification at this stage that the type fits the opcode
1115 properly. E.g.,
1116
1117 .i32.i32.s16
1118 .s32.f32
1119 .u16
1120
1121 Can all be legally parsed by this function.
1122
1123 Fills in neon_type struct pointer with parsed information, and updates STR
1124 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1125 type, FAIL if not. */
1126
1127 static int
1128 parse_neon_type (struct neon_type *type, char **str)
1129 {
1130 char *ptr = *str;
1131
1132 if (type)
1133 type->elems = 0;
1134
1135 while (type->elems < NEON_MAX_TYPE_ELS)
1136 {
1137 enum neon_el_type thistype = NT_untyped;
1138 unsigned thissize = -1u;
1139
1140 if (*ptr != '.')
1141 break;
1142
1143 ptr++;
1144
1145 /* Just a size without an explicit type. */
1146 if (ISDIGIT (*ptr))
1147 goto parsesize;
1148
1149 switch (TOLOWER (*ptr))
1150 {
1151 case 'i': thistype = NT_integer; break;
1152 case 'f': thistype = NT_float; break;
1153 case 'p': thistype = NT_poly; break;
1154 case 's': thistype = NT_signed; break;
1155 case 'u': thistype = NT_unsigned; break;
1156 case 'd':
1157 thistype = NT_float;
1158 thissize = 64;
1159 ptr++;
1160 goto done;
1161 default:
1162 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1163 return FAIL;
1164 }
1165
1166 ptr++;
1167
1168 /* .f is an abbreviation for .f32. */
1169 if (thistype == NT_float && !ISDIGIT (*ptr))
1170 thissize = 32;
1171 else
1172 {
1173 parsesize:
1174 thissize = strtoul (ptr, &ptr, 10);
1175
1176 if (thissize != 8 && thissize != 16 && thissize != 32
1177 && thissize != 64)
1178 {
1179 as_bad (_("bad size %d in type specifier"), thissize);
1180 return FAIL;
1181 }
1182 }
1183
1184 done:
1185 if (type)
1186 {
1187 type->el[type->elems].type = thistype;
1188 type->el[type->elems].size = thissize;
1189 type->elems++;
1190 }
1191 }
1192
1193 /* Empty/missing type is not a successful parse. */
1194 if (type->elems == 0)
1195 return FAIL;
1196
1197 *str = ptr;
1198
1199 return SUCCESS;
1200 }
1201
1202 /* Errors may be set multiple times during parsing or bit encoding
1203 (particularly in the Neon bits), but usually the earliest error which is set
1204 will be the most meaningful. Avoid overwriting it with later (cascading)
1205 errors by calling this function. */
1206
1207 static void
1208 first_error (const char *err)
1209 {
1210 if (!inst.error)
1211 inst.error = err;
1212 }
1213
1214 /* Parse a single type, e.g. ".s32", leading period included. */
1215 static int
1216 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1217 {
1218 char *str = *ccp;
1219 struct neon_type optype;
1220
1221 if (*str == '.')
1222 {
1223 if (parse_neon_type (&optype, &str) == SUCCESS)
1224 {
1225 if (optype.elems == 1)
1226 *vectype = optype.el[0];
1227 else
1228 {
1229 first_error (_("only one type should be specified for operand"));
1230 return FAIL;
1231 }
1232 }
1233 else
1234 {
1235 first_error (_("vector type expected"));
1236 return FAIL;
1237 }
1238 }
1239 else
1240 return FAIL;
1241
1242 *ccp = str;
1243
1244 return SUCCESS;
1245 }
1246
1247 /* Special meanings for indices (which have a range of 0-7), which will fit into
1248 a 4-bit integer. */
1249
1250 #define NEON_ALL_LANES 15
1251 #define NEON_INTERLEAVE_LANES 14
1252
1253 /* Parse either a register or a scalar, with an optional type. Return the
1254 register number, and optionally fill in the actual type of the register
1255 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1256 type/index information in *TYPEINFO. */
1257
1258 static int
1259 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1260 enum arm_reg_type *rtype,
1261 struct neon_typed_alias *typeinfo)
1262 {
1263 char *str = *ccp;
1264 struct reg_entry *reg = arm_reg_parse_multi (&str);
1265 struct neon_typed_alias atype;
1266 struct neon_type_el parsetype;
1267
1268 atype.defined = 0;
1269 atype.index = -1;
1270 atype.eltype.type = NT_invtype;
1271 atype.eltype.size = -1;
1272
1273 /* Try alternate syntax for some types of register. Note these are mutually
1274 exclusive with the Neon syntax extensions. */
1275 if (reg == NULL)
1276 {
1277 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1278 if (altreg != FAIL)
1279 *ccp = str;
1280 if (typeinfo)
1281 *typeinfo = atype;
1282 return altreg;
1283 }
1284
1285 /* Undo polymorphism when a set of register types may be accepted. */
1286 if ((type == REG_TYPE_NDQ
1287 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1288 || (type == REG_TYPE_VFSD
1289 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1290 || (type == REG_TYPE_NSDQ
1291 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1292 || reg->type == REG_TYPE_NQ))
1293 || (type == REG_TYPE_MMXWC
1294 && (reg->type == REG_TYPE_MMXWCG)))
1295 type = reg->type;
1296
1297 if (type != reg->type)
1298 return FAIL;
1299
1300 if (reg->neon)
1301 atype = *reg->neon;
1302
1303 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1304 {
1305 if ((atype.defined & NTA_HASTYPE) != 0)
1306 {
1307 first_error (_("can't redefine type for operand"));
1308 return FAIL;
1309 }
1310 atype.defined |= NTA_HASTYPE;
1311 atype.eltype = parsetype;
1312 }
1313
1314 if (skip_past_char (&str, '[') == SUCCESS)
1315 {
1316 if (type != REG_TYPE_VFD)
1317 {
1318 first_error (_("only D registers may be indexed"));
1319 return FAIL;
1320 }
1321
1322 if ((atype.defined & NTA_HASINDEX) != 0)
1323 {
1324 first_error (_("can't change index for operand"));
1325 return FAIL;
1326 }
1327
1328 atype.defined |= NTA_HASINDEX;
1329
1330 if (skip_past_char (&str, ']') == SUCCESS)
1331 atype.index = NEON_ALL_LANES;
1332 else
1333 {
1334 expressionS exp;
1335
1336 my_get_expression (&exp, &str, GE_NO_PREFIX);
1337
1338 if (exp.X_op != O_constant)
1339 {
1340 first_error (_("constant expression required"));
1341 return FAIL;
1342 }
1343
1344 if (skip_past_char (&str, ']') == FAIL)
1345 return FAIL;
1346
1347 atype.index = exp.X_add_number;
1348 }
1349 }
1350
1351 if (typeinfo)
1352 *typeinfo = atype;
1353
1354 if (rtype)
1355 *rtype = type;
1356
1357 *ccp = str;
1358
1359 return reg->number;
1360 }
1361
1362 /* Like arm_reg_parse, but allow allow the following extra features:
1363 - If RTYPE is non-zero, return the (possibly restricted) type of the
1364 register (e.g. Neon double or quad reg when either has been requested).
1365 - If this is a Neon vector type with additional type information, fill
1366 in the struct pointed to by VECTYPE (if non-NULL).
1367 This function will fault on encountering a scalar. */
1368
1369 static int
1370 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1371 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1372 {
1373 struct neon_typed_alias atype;
1374 char *str = *ccp;
1375 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1376
1377 if (reg == FAIL)
1378 return FAIL;
1379
1380 /* Do not allow a scalar (reg+index) to parse as a register. */
1381 if ((atype.defined & NTA_HASINDEX) != 0)
1382 {
1383 first_error (_("register operand expected, but got scalar"));
1384 return FAIL;
1385 }
1386
1387 if (vectype)
1388 *vectype = atype.eltype;
1389
1390 *ccp = str;
1391
1392 return reg;
1393 }
1394
1395 #define NEON_SCALAR_REG(X) ((X) >> 4)
1396 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1397
1398 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1399 have enough information to be able to do a good job bounds-checking. So, we
1400 just do easy checks here, and do further checks later. */
1401
1402 static int
1403 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1404 {
1405 int reg;
1406 char *str = *ccp;
1407 struct neon_typed_alias atype;
1408
1409 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1410
1411 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1412 return FAIL;
1413
1414 if (atype.index == NEON_ALL_LANES)
1415 {
1416 first_error (_("scalar must have an index"));
1417 return FAIL;
1418 }
1419 else if (atype.index >= 64 / elsize)
1420 {
1421 first_error (_("scalar index out of range"));
1422 return FAIL;
1423 }
1424
1425 if (type)
1426 *type = atype.eltype;
1427
1428 *ccp = str;
1429
1430 return reg * 16 + atype.index;
1431 }
1432
1433 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1434 static long
1435 parse_reg_list (char ** strp)
1436 {
1437 char * str = * strp;
1438 long range = 0;
1439 int another_range;
1440
1441 /* We come back here if we get ranges concatenated by '+' or '|'. */
1442 do
1443 {
1444 another_range = 0;
1445
1446 if (*str == '{')
1447 {
1448 int in_range = 0;
1449 int cur_reg = -1;
1450
1451 str++;
1452 do
1453 {
1454 int reg;
1455
1456 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1457 {
1458 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1459 return FAIL;
1460 }
1461
1462 if (in_range)
1463 {
1464 int i;
1465
1466 if (reg <= cur_reg)
1467 {
1468 first_error (_("bad range in register list"));
1469 return FAIL;
1470 }
1471
1472 for (i = cur_reg + 1; i < reg; i++)
1473 {
1474 if (range & (1 << i))
1475 as_tsktsk
1476 (_("Warning: duplicated register (r%d) in register list"),
1477 i);
1478 else
1479 range |= 1 << i;
1480 }
1481 in_range = 0;
1482 }
1483
1484 if (range & (1 << reg))
1485 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1486 reg);
1487 else if (reg <= cur_reg)
1488 as_tsktsk (_("Warning: register range not in ascending order"));
1489
1490 range |= 1 << reg;
1491 cur_reg = reg;
1492 }
1493 while (skip_past_comma (&str) != FAIL
1494 || (in_range = 1, *str++ == '-'));
1495 str--;
1496
1497 if (*str++ != '}')
1498 {
1499 first_error (_("missing `}'"));
1500 return FAIL;
1501 }
1502 }
1503 else
1504 {
1505 expressionS expr;
1506
1507 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1508 return FAIL;
1509
1510 if (expr.X_op == O_constant)
1511 {
1512 if (expr.X_add_number
1513 != (expr.X_add_number & 0x0000ffff))
1514 {
1515 inst.error = _("invalid register mask");
1516 return FAIL;
1517 }
1518
1519 if ((range & expr.X_add_number) != 0)
1520 {
1521 int regno = range & expr.X_add_number;
1522
1523 regno &= -regno;
1524 regno = (1 << regno) - 1;
1525 as_tsktsk
1526 (_("Warning: duplicated register (r%d) in register list"),
1527 regno);
1528 }
1529
1530 range |= expr.X_add_number;
1531 }
1532 else
1533 {
1534 if (inst.reloc.type != 0)
1535 {
1536 inst.error = _("expression too complex");
1537 return FAIL;
1538 }
1539
1540 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1541 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1542 inst.reloc.pc_rel = 0;
1543 }
1544 }
1545
1546 if (*str == '|' || *str == '+')
1547 {
1548 str++;
1549 another_range = 1;
1550 }
1551 }
1552 while (another_range);
1553
1554 *strp = str;
1555 return range;
1556 }
1557
1558 /* Types of registers in a list. */
1559
1560 enum reg_list_els
1561 {
1562 REGLIST_VFP_S,
1563 REGLIST_VFP_D,
1564 REGLIST_NEON_D
1565 };
1566
1567 /* Parse a VFP register list. If the string is invalid return FAIL.
1568 Otherwise return the number of registers, and set PBASE to the first
1569 register. Parses registers of type ETYPE.
1570 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1571 - Q registers can be used to specify pairs of D registers
1572 - { } can be omitted from around a singleton register list
1573 FIXME: This is not implemented, as it would require backtracking in
1574 some cases, e.g.:
1575 vtbl.8 d3,d4,d5
1576 This could be done (the meaning isn't really ambiguous), but doesn't
1577 fit in well with the current parsing framework.
1578 - 32 D registers may be used (also true for VFPv3).
1579 FIXME: Types are ignored in these register lists, which is probably a
1580 bug. */
1581
1582 static int
1583 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1584 {
1585 char *str = *ccp;
1586 int base_reg;
1587 int new_base;
1588 enum arm_reg_type regtype = 0;
1589 int max_regs = 0;
1590 int count = 0;
1591 int warned = 0;
1592 unsigned long mask = 0;
1593 int i;
1594
1595 if (*str != '{')
1596 {
1597 inst.error = _("expecting {");
1598 return FAIL;
1599 }
1600
1601 str++;
1602
1603 switch (etype)
1604 {
1605 case REGLIST_VFP_S:
1606 regtype = REG_TYPE_VFS;
1607 max_regs = 32;
1608 break;
1609
1610 case REGLIST_VFP_D:
1611 regtype = REG_TYPE_VFD;
1612 break;
1613
1614 case REGLIST_NEON_D:
1615 regtype = REG_TYPE_NDQ;
1616 break;
1617 }
1618
1619 if (etype != REGLIST_VFP_S)
1620 {
1621 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1622 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1623 {
1624 max_regs = 32;
1625 if (thumb_mode)
1626 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1627 fpu_vfp_ext_d32);
1628 else
1629 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1630 fpu_vfp_ext_d32);
1631 }
1632 else
1633 max_regs = 16;
1634 }
1635
1636 base_reg = max_regs;
1637
1638 do
1639 {
1640 int setmask = 1, addregs = 1;
1641
1642 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1643
1644 if (new_base == FAIL)
1645 {
1646 first_error (_(reg_expected_msgs[regtype]));
1647 return FAIL;
1648 }
1649
1650 if (new_base >= max_regs)
1651 {
1652 first_error (_("register out of range in list"));
1653 return FAIL;
1654 }
1655
1656 /* Note: a value of 2 * n is returned for the register Q<n>. */
1657 if (regtype == REG_TYPE_NQ)
1658 {
1659 setmask = 3;
1660 addregs = 2;
1661 }
1662
1663 if (new_base < base_reg)
1664 base_reg = new_base;
1665
1666 if (mask & (setmask << new_base))
1667 {
1668 first_error (_("invalid register list"));
1669 return FAIL;
1670 }
1671
1672 if ((mask >> new_base) != 0 && ! warned)
1673 {
1674 as_tsktsk (_("register list not in ascending order"));
1675 warned = 1;
1676 }
1677
1678 mask |= setmask << new_base;
1679 count += addregs;
1680
1681 if (*str == '-') /* We have the start of a range expression */
1682 {
1683 int high_range;
1684
1685 str++;
1686
1687 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1688 == FAIL)
1689 {
1690 inst.error = gettext (reg_expected_msgs[regtype]);
1691 return FAIL;
1692 }
1693
1694 if (high_range >= max_regs)
1695 {
1696 first_error (_("register out of range in list"));
1697 return FAIL;
1698 }
1699
1700 if (regtype == REG_TYPE_NQ)
1701 high_range = high_range + 1;
1702
1703 if (high_range <= new_base)
1704 {
1705 inst.error = _("register range not in ascending order");
1706 return FAIL;
1707 }
1708
1709 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1710 {
1711 if (mask & (setmask << new_base))
1712 {
1713 inst.error = _("invalid register list");
1714 return FAIL;
1715 }
1716
1717 mask |= setmask << new_base;
1718 count += addregs;
1719 }
1720 }
1721 }
1722 while (skip_past_comma (&str) != FAIL);
1723
1724 str++;
1725
1726 /* Sanity check -- should have raised a parse error above. */
1727 if (count == 0 || count > max_regs)
1728 abort ();
1729
1730 *pbase = base_reg;
1731
1732 /* Final test -- the registers must be consecutive. */
1733 mask >>= base_reg;
1734 for (i = 0; i < count; i++)
1735 {
1736 if ((mask & (1u << i)) == 0)
1737 {
1738 inst.error = _("non-contiguous register range");
1739 return FAIL;
1740 }
1741 }
1742
1743 *ccp = str;
1744
1745 return count;
1746 }
1747
1748 /* True if two alias types are the same. */
1749
1750 static int
1751 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1752 {
1753 if (!a && !b)
1754 return 1;
1755
1756 if (!a || !b)
1757 return 0;
1758
1759 if (a->defined != b->defined)
1760 return 0;
1761
1762 if ((a->defined & NTA_HASTYPE) != 0
1763 && (a->eltype.type != b->eltype.type
1764 || a->eltype.size != b->eltype.size))
1765 return 0;
1766
1767 if ((a->defined & NTA_HASINDEX) != 0
1768 && (a->index != b->index))
1769 return 0;
1770
1771 return 1;
1772 }
1773
1774 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1775 The base register is put in *PBASE.
1776 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1777 the return value.
1778 The register stride (minus one) is put in bit 4 of the return value.
1779 Bits [6:5] encode the list length (minus one).
1780 The type of the list elements is put in *ELTYPE, if non-NULL. */
1781
1782 #define NEON_LANE(X) ((X) & 0xf)
1783 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1784 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1785
1786 static int
1787 parse_neon_el_struct_list (char **str, unsigned *pbase,
1788 struct neon_type_el *eltype)
1789 {
1790 char *ptr = *str;
1791 int base_reg = -1;
1792 int reg_incr = -1;
1793 int count = 0;
1794 int lane = -1;
1795 int leading_brace = 0;
1796 enum arm_reg_type rtype = REG_TYPE_NDQ;
1797 int addregs = 1;
1798 const char *const incr_error = "register stride must be 1 or 2";
1799 const char *const type_error = "mismatched element/structure types in list";
1800 struct neon_typed_alias firsttype;
1801
1802 if (skip_past_char (&ptr, '{') == SUCCESS)
1803 leading_brace = 1;
1804
1805 do
1806 {
1807 struct neon_typed_alias atype;
1808 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1809
1810 if (getreg == FAIL)
1811 {
1812 first_error (_(reg_expected_msgs[rtype]));
1813 return FAIL;
1814 }
1815
1816 if (base_reg == -1)
1817 {
1818 base_reg = getreg;
1819 if (rtype == REG_TYPE_NQ)
1820 {
1821 reg_incr = 1;
1822 addregs = 2;
1823 }
1824 firsttype = atype;
1825 }
1826 else if (reg_incr == -1)
1827 {
1828 reg_incr = getreg - base_reg;
1829 if (reg_incr < 1 || reg_incr > 2)
1830 {
1831 first_error (_(incr_error));
1832 return FAIL;
1833 }
1834 }
1835 else if (getreg != base_reg + reg_incr * count)
1836 {
1837 first_error (_(incr_error));
1838 return FAIL;
1839 }
1840
1841 if (!neon_alias_types_same (&atype, &firsttype))
1842 {
1843 first_error (_(type_error));
1844 return FAIL;
1845 }
1846
1847 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1848 modes. */
1849 if (ptr[0] == '-')
1850 {
1851 struct neon_typed_alias htype;
1852 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1853 if (lane == -1)
1854 lane = NEON_INTERLEAVE_LANES;
1855 else if (lane != NEON_INTERLEAVE_LANES)
1856 {
1857 first_error (_(type_error));
1858 return FAIL;
1859 }
1860 if (reg_incr == -1)
1861 reg_incr = 1;
1862 else if (reg_incr != 1)
1863 {
1864 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1865 return FAIL;
1866 }
1867 ptr++;
1868 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1869 if (hireg == FAIL)
1870 {
1871 first_error (_(reg_expected_msgs[rtype]));
1872 return FAIL;
1873 }
1874 if (!neon_alias_types_same (&htype, &firsttype))
1875 {
1876 first_error (_(type_error));
1877 return FAIL;
1878 }
1879 count += hireg + dregs - getreg;
1880 continue;
1881 }
1882
1883 /* If we're using Q registers, we can't use [] or [n] syntax. */
1884 if (rtype == REG_TYPE_NQ)
1885 {
1886 count += 2;
1887 continue;
1888 }
1889
1890 if ((atype.defined & NTA_HASINDEX) != 0)
1891 {
1892 if (lane == -1)
1893 lane = atype.index;
1894 else if (lane != atype.index)
1895 {
1896 first_error (_(type_error));
1897 return FAIL;
1898 }
1899 }
1900 else if (lane == -1)
1901 lane = NEON_INTERLEAVE_LANES;
1902 else if (lane != NEON_INTERLEAVE_LANES)
1903 {
1904 first_error (_(type_error));
1905 return FAIL;
1906 }
1907 count++;
1908 }
1909 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1910
1911 /* No lane set by [x]. We must be interleaving structures. */
1912 if (lane == -1)
1913 lane = NEON_INTERLEAVE_LANES;
1914
1915 /* Sanity check. */
1916 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1917 || (count > 1 && reg_incr == -1))
1918 {
1919 first_error (_("error parsing element/structure list"));
1920 return FAIL;
1921 }
1922
1923 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1924 {
1925 first_error (_("expected }"));
1926 return FAIL;
1927 }
1928
1929 if (reg_incr == -1)
1930 reg_incr = 1;
1931
1932 if (eltype)
1933 *eltype = firsttype.eltype;
1934
1935 *pbase = base_reg;
1936 *str = ptr;
1937
1938 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1939 }
1940
1941 /* Parse an explicit relocation suffix on an expression. This is
1942 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1943 arm_reloc_hsh contains no entries, so this function can only
1944 succeed if there is no () after the word. Returns -1 on error,
1945 BFD_RELOC_UNUSED if there wasn't any suffix. */
1946 static int
1947 parse_reloc (char **str)
1948 {
1949 struct reloc_entry *r;
1950 char *p, *q;
1951
1952 if (**str != '(')
1953 return BFD_RELOC_UNUSED;
1954
1955 p = *str + 1;
1956 q = p;
1957
1958 while (*q && *q != ')' && *q != ',')
1959 q++;
1960 if (*q != ')')
1961 return -1;
1962
1963 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1964 return -1;
1965
1966 *str = q + 1;
1967 return r->reloc;
1968 }
1969
1970 /* Directives: register aliases. */
1971
1972 static struct reg_entry *
1973 insert_reg_alias (char *str, int number, int type)
1974 {
1975 struct reg_entry *new;
1976 const char *name;
1977
1978 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1979 {
1980 if (new->builtin)
1981 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
1982
1983 /* Only warn about a redefinition if it's not defined as the
1984 same register. */
1985 else if (new->number != number || new->type != type)
1986 as_warn (_("ignoring redefinition of register alias '%s'"), str);
1987
1988 return NULL;
1989 }
1990
1991 name = xstrdup (str);
1992 new = xmalloc (sizeof (struct reg_entry));
1993
1994 new->name = name;
1995 new->number = number;
1996 new->type = type;
1997 new->builtin = FALSE;
1998 new->neon = NULL;
1999
2000 if (hash_insert (arm_reg_hsh, name, (void *) new))
2001 abort ();
2002
2003 return new;
2004 }
2005
2006 static void
2007 insert_neon_reg_alias (char *str, int number, int type,
2008 struct neon_typed_alias *atype)
2009 {
2010 struct reg_entry *reg = insert_reg_alias (str, number, type);
2011
2012 if (!reg)
2013 {
2014 first_error (_("attempt to redefine typed alias"));
2015 return;
2016 }
2017
2018 if (atype)
2019 {
2020 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2021 *reg->neon = *atype;
2022 }
2023 }
2024
2025 /* Look for the .req directive. This is of the form:
2026
2027 new_register_name .req existing_register_name
2028
2029 If we find one, or if it looks sufficiently like one that we want to
2030 handle any error here, return TRUE. Otherwise return FALSE. */
2031
2032 static bfd_boolean
2033 create_register_alias (char * newname, char *p)
2034 {
2035 struct reg_entry *old;
2036 char *oldname, *nbuf;
2037 size_t nlen;
2038
2039 /* The input scrubber ensures that whitespace after the mnemonic is
2040 collapsed to single spaces. */
2041 oldname = p;
2042 if (strncmp (oldname, " .req ", 6) != 0)
2043 return FALSE;
2044
2045 oldname += 6;
2046 if (*oldname == '\0')
2047 return FALSE;
2048
2049 old = hash_find (arm_reg_hsh, oldname);
2050 if (!old)
2051 {
2052 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2053 return TRUE;
2054 }
2055
2056 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2057 the desired alias name, and p points to its end. If not, then
2058 the desired alias name is in the global original_case_string. */
2059 #ifdef TC_CASE_SENSITIVE
2060 nlen = p - newname;
2061 #else
2062 newname = original_case_string;
2063 nlen = strlen (newname);
2064 #endif
2065
2066 nbuf = alloca (nlen + 1);
2067 memcpy (nbuf, newname, nlen);
2068 nbuf[nlen] = '\0';
2069
2070 /* Create aliases under the new name as stated; an all-lowercase
2071 version of the new name; and an all-uppercase version of the new
2072 name. */
2073 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2074 {
2075 for (p = nbuf; *p; p++)
2076 *p = TOUPPER (*p);
2077
2078 if (strncmp (nbuf, newname, nlen))
2079 {
2080 /* If this attempt to create an additional alias fails, do not bother
2081 trying to create the all-lower case alias. We will fail and issue
2082 a second, duplicate error message. This situation arises when the
2083 programmer does something like:
2084 foo .req r0
2085 Foo .req r1
2086 The second .req creates the "Foo" alias but then fails to create
2087 the artificial FOO alias because it has already been created by the
2088 first .req. */
2089 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2090 return TRUE;
2091 }
2092
2093 for (p = nbuf; *p; p++)
2094 *p = TOLOWER (*p);
2095
2096 if (strncmp (nbuf, newname, nlen))
2097 insert_reg_alias (nbuf, old->number, old->type);
2098 }
2099
2100 return TRUE;
2101 }
2102
2103 /* Create a Neon typed/indexed register alias using directives, e.g.:
2104 X .dn d5.s32[1]
2105 Y .qn 6.s16
2106 Z .dn d7
2107 T .dn Z[0]
2108 These typed registers can be used instead of the types specified after the
2109 Neon mnemonic, so long as all operands given have types. Types can also be
2110 specified directly, e.g.:
2111 vadd d0.s32, d1.s32, d2.s32 */
2112
2113 static int
2114 create_neon_reg_alias (char *newname, char *p)
2115 {
2116 enum arm_reg_type basetype;
2117 struct reg_entry *basereg;
2118 struct reg_entry mybasereg;
2119 struct neon_type ntype;
2120 struct neon_typed_alias typeinfo;
2121 char *namebuf, *nameend;
2122 int namelen;
2123
2124 typeinfo.defined = 0;
2125 typeinfo.eltype.type = NT_invtype;
2126 typeinfo.eltype.size = -1;
2127 typeinfo.index = -1;
2128
2129 nameend = p;
2130
2131 if (strncmp (p, " .dn ", 5) == 0)
2132 basetype = REG_TYPE_VFD;
2133 else if (strncmp (p, " .qn ", 5) == 0)
2134 basetype = REG_TYPE_NQ;
2135 else
2136 return 0;
2137
2138 p += 5;
2139
2140 if (*p == '\0')
2141 return 0;
2142
2143 basereg = arm_reg_parse_multi (&p);
2144
2145 if (basereg && basereg->type != basetype)
2146 {
2147 as_bad (_("bad type for register"));
2148 return 0;
2149 }
2150
2151 if (basereg == NULL)
2152 {
2153 expressionS exp;
2154 /* Try parsing as an integer. */
2155 my_get_expression (&exp, &p, GE_NO_PREFIX);
2156 if (exp.X_op != O_constant)
2157 {
2158 as_bad (_("expression must be constant"));
2159 return 0;
2160 }
2161 basereg = &mybasereg;
2162 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2163 : exp.X_add_number;
2164 basereg->neon = 0;
2165 }
2166
2167 if (basereg->neon)
2168 typeinfo = *basereg->neon;
2169
2170 if (parse_neon_type (&ntype, &p) == SUCCESS)
2171 {
2172 /* We got a type. */
2173 if (typeinfo.defined & NTA_HASTYPE)
2174 {
2175 as_bad (_("can't redefine the type of a register alias"));
2176 return 0;
2177 }
2178
2179 typeinfo.defined |= NTA_HASTYPE;
2180 if (ntype.elems != 1)
2181 {
2182 as_bad (_("you must specify a single type only"));
2183 return 0;
2184 }
2185 typeinfo.eltype = ntype.el[0];
2186 }
2187
2188 if (skip_past_char (&p, '[') == SUCCESS)
2189 {
2190 expressionS exp;
2191 /* We got a scalar index. */
2192
2193 if (typeinfo.defined & NTA_HASINDEX)
2194 {
2195 as_bad (_("can't redefine the index of a scalar alias"));
2196 return 0;
2197 }
2198
2199 my_get_expression (&exp, &p, GE_NO_PREFIX);
2200
2201 if (exp.X_op != O_constant)
2202 {
2203 as_bad (_("scalar index must be constant"));
2204 return 0;
2205 }
2206
2207 typeinfo.defined |= NTA_HASINDEX;
2208 typeinfo.index = exp.X_add_number;
2209
2210 if (skip_past_char (&p, ']') == FAIL)
2211 {
2212 as_bad (_("expecting ]"));
2213 return 0;
2214 }
2215 }
2216
2217 namelen = nameend - newname;
2218 namebuf = alloca (namelen + 1);
2219 strncpy (namebuf, newname, namelen);
2220 namebuf[namelen] = '\0';
2221
2222 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2223 typeinfo.defined != 0 ? &typeinfo : NULL);
2224
2225 /* Insert name in all uppercase. */
2226 for (p = namebuf; *p; p++)
2227 *p = TOUPPER (*p);
2228
2229 if (strncmp (namebuf, newname, namelen))
2230 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2231 typeinfo.defined != 0 ? &typeinfo : NULL);
2232
2233 /* Insert name in all lowercase. */
2234 for (p = namebuf; *p; p++)
2235 *p = TOLOWER (*p);
2236
2237 if (strncmp (namebuf, newname, namelen))
2238 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2239 typeinfo.defined != 0 ? &typeinfo : NULL);
2240
2241 return 1;
2242 }
2243
2244 /* Should never be called, as .req goes between the alias and the
2245 register name, not at the beginning of the line. */
2246 static void
2247 s_req (int a ATTRIBUTE_UNUSED)
2248 {
2249 as_bad (_("invalid syntax for .req directive"));
2250 }
2251
2252 static void
2253 s_dn (int a ATTRIBUTE_UNUSED)
2254 {
2255 as_bad (_("invalid syntax for .dn directive"));
2256 }
2257
2258 static void
2259 s_qn (int a ATTRIBUTE_UNUSED)
2260 {
2261 as_bad (_("invalid syntax for .qn directive"));
2262 }
2263
2264 /* The .unreq directive deletes an alias which was previously defined
2265 by .req. For example:
2266
2267 my_alias .req r11
2268 .unreq my_alias */
2269
2270 static void
2271 s_unreq (int a ATTRIBUTE_UNUSED)
2272 {
2273 char * name;
2274 char saved_char;
2275
2276 name = input_line_pointer;
2277
2278 while (*input_line_pointer != 0
2279 && *input_line_pointer != ' '
2280 && *input_line_pointer != '\n')
2281 ++input_line_pointer;
2282
2283 saved_char = *input_line_pointer;
2284 *input_line_pointer = 0;
2285
2286 if (!*name)
2287 as_bad (_("invalid syntax for .unreq directive"));
2288 else
2289 {
2290 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2291
2292 if (!reg)
2293 as_bad (_("unknown register alias '%s'"), name);
2294 else if (reg->builtin)
2295 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2296 name);
2297 else
2298 {
2299 char * p;
2300 char * nbuf;
2301
2302 hash_delete (arm_reg_hsh, name, FALSE);
2303 free ((char *) reg->name);
2304 if (reg->neon)
2305 free (reg->neon);
2306 free (reg);
2307
2308 /* Also locate the all upper case and all lower case versions.
2309 Do not complain if we cannot find one or the other as it
2310 was probably deleted above. */
2311
2312 nbuf = strdup (name);
2313 for (p = nbuf; *p; p++)
2314 *p = TOUPPER (*p);
2315 reg = hash_find (arm_reg_hsh, nbuf);
2316 if (reg)
2317 {
2318 hash_delete (arm_reg_hsh, nbuf, FALSE);
2319 free ((char *) reg->name);
2320 if (reg->neon)
2321 free (reg->neon);
2322 free (reg);
2323 }
2324
2325 for (p = nbuf; *p; p++)
2326 *p = TOLOWER (*p);
2327 reg = hash_find (arm_reg_hsh, nbuf);
2328 if (reg)
2329 {
2330 hash_delete (arm_reg_hsh, nbuf, FALSE);
2331 free ((char *) reg->name);
2332 if (reg->neon)
2333 free (reg->neon);
2334 free (reg);
2335 }
2336
2337 free (nbuf);
2338 }
2339 }
2340
2341 *input_line_pointer = saved_char;
2342 demand_empty_rest_of_line ();
2343 }
2344
2345 /* Directives: Instruction set selection. */
2346
2347 #ifdef OBJ_ELF
2348 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2349 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2350 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2351 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2352
2353 static enum mstate mapstate = MAP_UNDEFINED;
2354
2355 void
2356 mapping_state (enum mstate state)
2357 {
2358 symbolS * symbolP;
2359 const char * symname;
2360 int type;
2361
2362 if (mapstate == state)
2363 /* The mapping symbol has already been emitted.
2364 There is nothing else to do. */
2365 return;
2366
2367 mapstate = state;
2368
2369 switch (state)
2370 {
2371 case MAP_DATA:
2372 symname = "$d";
2373 type = BSF_NO_FLAGS;
2374 break;
2375 case MAP_ARM:
2376 symname = "$a";
2377 type = BSF_NO_FLAGS;
2378 break;
2379 case MAP_THUMB:
2380 symname = "$t";
2381 type = BSF_NO_FLAGS;
2382 break;
2383 case MAP_UNDEFINED:
2384 return;
2385 default:
2386 abort ();
2387 }
2388
2389 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2390
2391 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2392 symbol_table_insert (symbolP);
2393 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2394
2395 switch (state)
2396 {
2397 case MAP_ARM:
2398 THUMB_SET_FUNC (symbolP, 0);
2399 ARM_SET_THUMB (symbolP, 0);
2400 ARM_SET_INTERWORK (symbolP, support_interwork);
2401 break;
2402
2403 case MAP_THUMB:
2404 THUMB_SET_FUNC (symbolP, 1);
2405 ARM_SET_THUMB (symbolP, 1);
2406 ARM_SET_INTERWORK (symbolP, support_interwork);
2407 break;
2408
2409 case MAP_DATA:
2410 default:
2411 return;
2412 }
2413 }
2414 #else
2415 #define mapping_state(x) /* nothing */
2416 #endif
2417
2418 /* Find the real, Thumb encoded start of a Thumb function. */
2419
2420 #ifdef OBJ_COFF
2421 static symbolS *
2422 find_real_start (symbolS * symbolP)
2423 {
2424 char * real_start;
2425 const char * name = S_GET_NAME (symbolP);
2426 symbolS * new_target;
2427
2428 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2429 #define STUB_NAME ".real_start_of"
2430
2431 if (name == NULL)
2432 abort ();
2433
2434 /* The compiler may generate BL instructions to local labels because
2435 it needs to perform a branch to a far away location. These labels
2436 do not have a corresponding ".real_start_of" label. We check
2437 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2438 the ".real_start_of" convention for nonlocal branches. */
2439 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2440 return symbolP;
2441
2442 real_start = ACONCAT ((STUB_NAME, name, NULL));
2443 new_target = symbol_find (real_start);
2444
2445 if (new_target == NULL)
2446 {
2447 as_warn (_("Failed to find real start of function: %s\n"), name);
2448 new_target = symbolP;
2449 }
2450
2451 return new_target;
2452 }
2453 #endif
2454
2455 static void
2456 opcode_select (int width)
2457 {
2458 switch (width)
2459 {
2460 case 16:
2461 if (! thumb_mode)
2462 {
2463 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2464 as_bad (_("selected processor does not support THUMB opcodes"));
2465
2466 thumb_mode = 1;
2467 /* No need to force the alignment, since we will have been
2468 coming from ARM mode, which is word-aligned. */
2469 record_alignment (now_seg, 1);
2470 }
2471 mapping_state (MAP_THUMB);
2472 break;
2473
2474 case 32:
2475 if (thumb_mode)
2476 {
2477 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2478 as_bad (_("selected processor does not support ARM opcodes"));
2479
2480 thumb_mode = 0;
2481
2482 if (!need_pass_2)
2483 frag_align (2, 0, 0);
2484
2485 record_alignment (now_seg, 1);
2486 }
2487 mapping_state (MAP_ARM);
2488 break;
2489
2490 default:
2491 as_bad (_("invalid instruction size selected (%d)"), width);
2492 }
2493 }
2494
2495 static void
2496 s_arm (int ignore ATTRIBUTE_UNUSED)
2497 {
2498 opcode_select (32);
2499 demand_empty_rest_of_line ();
2500 }
2501
2502 static void
2503 s_thumb (int ignore ATTRIBUTE_UNUSED)
2504 {
2505 opcode_select (16);
2506 demand_empty_rest_of_line ();
2507 }
2508
2509 static void
2510 s_code (int unused ATTRIBUTE_UNUSED)
2511 {
2512 int temp;
2513
2514 temp = get_absolute_expression ();
2515 switch (temp)
2516 {
2517 case 16:
2518 case 32:
2519 opcode_select (temp);
2520 break;
2521
2522 default:
2523 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2524 }
2525 }
2526
2527 static void
2528 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2529 {
2530 /* If we are not already in thumb mode go into it, EVEN if
2531 the target processor does not support thumb instructions.
2532 This is used by gcc/config/arm/lib1funcs.asm for example
2533 to compile interworking support functions even if the
2534 target processor should not support interworking. */
2535 if (! thumb_mode)
2536 {
2537 thumb_mode = 2;
2538 record_alignment (now_seg, 1);
2539 }
2540
2541 demand_empty_rest_of_line ();
2542 }
2543
2544 static void
2545 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2546 {
2547 s_thumb (0);
2548
2549 /* The following label is the name/address of the start of a Thumb function.
2550 We need to know this for the interworking support. */
2551 label_is_thumb_function_name = TRUE;
2552 }
2553
2554 /* Perform a .set directive, but also mark the alias as
2555 being a thumb function. */
2556
2557 static void
2558 s_thumb_set (int equiv)
2559 {
2560 /* XXX the following is a duplicate of the code for s_set() in read.c
2561 We cannot just call that code as we need to get at the symbol that
2562 is created. */
2563 char * name;
2564 char delim;
2565 char * end_name;
2566 symbolS * symbolP;
2567
2568 /* Especial apologies for the random logic:
2569 This just grew, and could be parsed much more simply!
2570 Dean - in haste. */
2571 name = input_line_pointer;
2572 delim = get_symbol_end ();
2573 end_name = input_line_pointer;
2574 *end_name = delim;
2575
2576 if (*input_line_pointer != ',')
2577 {
2578 *end_name = 0;
2579 as_bad (_("expected comma after name \"%s\""), name);
2580 *end_name = delim;
2581 ignore_rest_of_line ();
2582 return;
2583 }
2584
2585 input_line_pointer++;
2586 *end_name = 0;
2587
2588 if (name[0] == '.' && name[1] == '\0')
2589 {
2590 /* XXX - this should not happen to .thumb_set. */
2591 abort ();
2592 }
2593
2594 if ((symbolP = symbol_find (name)) == NULL
2595 && (symbolP = md_undefined_symbol (name)) == NULL)
2596 {
2597 #ifndef NO_LISTING
2598 /* When doing symbol listings, play games with dummy fragments living
2599 outside the normal fragment chain to record the file and line info
2600 for this symbol. */
2601 if (listing & LISTING_SYMBOLS)
2602 {
2603 extern struct list_info_struct * listing_tail;
2604 fragS * dummy_frag = xmalloc (sizeof (fragS));
2605
2606 memset (dummy_frag, 0, sizeof (fragS));
2607 dummy_frag->fr_type = rs_fill;
2608 dummy_frag->line = listing_tail;
2609 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2610 dummy_frag->fr_symbol = symbolP;
2611 }
2612 else
2613 #endif
2614 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2615
2616 #ifdef OBJ_COFF
2617 /* "set" symbols are local unless otherwise specified. */
2618 SF_SET_LOCAL (symbolP);
2619 #endif /* OBJ_COFF */
2620 } /* Make a new symbol. */
2621
2622 symbol_table_insert (symbolP);
2623
2624 * end_name = delim;
2625
2626 if (equiv
2627 && S_IS_DEFINED (symbolP)
2628 && S_GET_SEGMENT (symbolP) != reg_section)
2629 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2630
2631 pseudo_set (symbolP);
2632
2633 demand_empty_rest_of_line ();
2634
2635 /* XXX Now we come to the Thumb specific bit of code. */
2636
2637 THUMB_SET_FUNC (symbolP, 1);
2638 ARM_SET_THUMB (symbolP, 1);
2639 #if defined OBJ_ELF || defined OBJ_COFF
2640 ARM_SET_INTERWORK (symbolP, support_interwork);
2641 #endif
2642 }
2643
2644 /* Directives: Mode selection. */
2645
2646 /* .syntax [unified|divided] - choose the new unified syntax
2647 (same for Arm and Thumb encoding, modulo slight differences in what
2648 can be represented) or the old divergent syntax for each mode. */
2649 static void
2650 s_syntax (int unused ATTRIBUTE_UNUSED)
2651 {
2652 char *name, delim;
2653
2654 name = input_line_pointer;
2655 delim = get_symbol_end ();
2656
2657 if (!strcasecmp (name, "unified"))
2658 unified_syntax = TRUE;
2659 else if (!strcasecmp (name, "divided"))
2660 unified_syntax = FALSE;
2661 else
2662 {
2663 as_bad (_("unrecognized syntax mode \"%s\""), name);
2664 return;
2665 }
2666 *input_line_pointer = delim;
2667 demand_empty_rest_of_line ();
2668 }
2669
2670 /* Directives: sectioning and alignment. */
2671
2672 /* Same as s_align_ptwo but align 0 => align 2. */
2673
2674 static void
2675 s_align (int unused ATTRIBUTE_UNUSED)
2676 {
2677 int temp;
2678 bfd_boolean fill_p;
2679 long temp_fill;
2680 long max_alignment = 15;
2681
2682 temp = get_absolute_expression ();
2683 if (temp > max_alignment)
2684 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2685 else if (temp < 0)
2686 {
2687 as_bad (_("alignment negative. 0 assumed."));
2688 temp = 0;
2689 }
2690
2691 if (*input_line_pointer == ',')
2692 {
2693 input_line_pointer++;
2694 temp_fill = get_absolute_expression ();
2695 fill_p = TRUE;
2696 }
2697 else
2698 {
2699 fill_p = FALSE;
2700 temp_fill = 0;
2701 }
2702
2703 if (!temp)
2704 temp = 2;
2705
2706 /* Only make a frag if we HAVE to. */
2707 if (temp && !need_pass_2)
2708 {
2709 if (!fill_p && subseg_text_p (now_seg))
2710 frag_align_code (temp, 0);
2711 else
2712 frag_align (temp, (int) temp_fill, 0);
2713 }
2714 demand_empty_rest_of_line ();
2715
2716 record_alignment (now_seg, temp);
2717 }
2718
2719 static void
2720 s_bss (int ignore ATTRIBUTE_UNUSED)
2721 {
2722 /* We don't support putting frags in the BSS segment, we fake it by
2723 marking in_bss, then looking at s_skip for clues. */
2724 subseg_set (bss_section, 0);
2725 demand_empty_rest_of_line ();
2726 mapping_state (MAP_DATA);
2727 }
2728
2729 static void
2730 s_even (int ignore ATTRIBUTE_UNUSED)
2731 {
2732 /* Never make frag if expect extra pass. */
2733 if (!need_pass_2)
2734 frag_align (1, 0, 0);
2735
2736 record_alignment (now_seg, 1);
2737
2738 demand_empty_rest_of_line ();
2739 }
2740
2741 /* Directives: Literal pools. */
2742
2743 static literal_pool *
2744 find_literal_pool (void)
2745 {
2746 literal_pool * pool;
2747
2748 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2749 {
2750 if (pool->section == now_seg
2751 && pool->sub_section == now_subseg)
2752 break;
2753 }
2754
2755 return pool;
2756 }
2757
2758 static literal_pool *
2759 find_or_make_literal_pool (void)
2760 {
2761 /* Next literal pool ID number. */
2762 static unsigned int latest_pool_num = 1;
2763 literal_pool * pool;
2764
2765 pool = find_literal_pool ();
2766
2767 if (pool == NULL)
2768 {
2769 /* Create a new pool. */
2770 pool = xmalloc (sizeof (* pool));
2771 if (! pool)
2772 return NULL;
2773
2774 pool->next_free_entry = 0;
2775 pool->section = now_seg;
2776 pool->sub_section = now_subseg;
2777 pool->next = list_of_pools;
2778 pool->symbol = NULL;
2779
2780 /* Add it to the list. */
2781 list_of_pools = pool;
2782 }
2783
2784 /* New pools, and emptied pools, will have a NULL symbol. */
2785 if (pool->symbol == NULL)
2786 {
2787 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2788 (valueT) 0, &zero_address_frag);
2789 pool->id = latest_pool_num ++;
2790 }
2791
2792 /* Done. */
2793 return pool;
2794 }
2795
2796 /* Add the literal in the global 'inst'
2797 structure to the relevant literal pool. */
2798
2799 static int
2800 add_to_lit_pool (void)
2801 {
2802 literal_pool * pool;
2803 unsigned int entry;
2804
2805 pool = find_or_make_literal_pool ();
2806
2807 /* Check if this literal value is already in the pool. */
2808 for (entry = 0; entry < pool->next_free_entry; entry ++)
2809 {
2810 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2811 && (inst.reloc.exp.X_op == O_constant)
2812 && (pool->literals[entry].X_add_number
2813 == inst.reloc.exp.X_add_number)
2814 && (pool->literals[entry].X_unsigned
2815 == inst.reloc.exp.X_unsigned))
2816 break;
2817
2818 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2819 && (inst.reloc.exp.X_op == O_symbol)
2820 && (pool->literals[entry].X_add_number
2821 == inst.reloc.exp.X_add_number)
2822 && (pool->literals[entry].X_add_symbol
2823 == inst.reloc.exp.X_add_symbol)
2824 && (pool->literals[entry].X_op_symbol
2825 == inst.reloc.exp.X_op_symbol))
2826 break;
2827 }
2828
2829 /* Do we need to create a new entry? */
2830 if (entry == pool->next_free_entry)
2831 {
2832 if (entry >= MAX_LITERAL_POOL_SIZE)
2833 {
2834 inst.error = _("literal pool overflow");
2835 return FAIL;
2836 }
2837
2838 pool->literals[entry] = inst.reloc.exp;
2839 pool->next_free_entry += 1;
2840 }
2841
2842 inst.reloc.exp.X_op = O_symbol;
2843 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2844 inst.reloc.exp.X_add_symbol = pool->symbol;
2845
2846 return SUCCESS;
2847 }
2848
2849 /* Can't use symbol_new here, so have to create a symbol and then at
2850 a later date assign it a value. Thats what these functions do. */
2851
2852 static void
2853 symbol_locate (symbolS * symbolP,
2854 const char * name, /* It is copied, the caller can modify. */
2855 segT segment, /* Segment identifier (SEG_<something>). */
2856 valueT valu, /* Symbol value. */
2857 fragS * frag) /* Associated fragment. */
2858 {
2859 unsigned int name_length;
2860 char * preserved_copy_of_name;
2861
2862 name_length = strlen (name) + 1; /* +1 for \0. */
2863 obstack_grow (&notes, name, name_length);
2864 preserved_copy_of_name = obstack_finish (&notes);
2865
2866 #ifdef tc_canonicalize_symbol_name
2867 preserved_copy_of_name =
2868 tc_canonicalize_symbol_name (preserved_copy_of_name);
2869 #endif
2870
2871 S_SET_NAME (symbolP, preserved_copy_of_name);
2872
2873 S_SET_SEGMENT (symbolP, segment);
2874 S_SET_VALUE (symbolP, valu);
2875 symbol_clear_list_pointers (symbolP);
2876
2877 symbol_set_frag (symbolP, frag);
2878
2879 /* Link to end of symbol chain. */
2880 {
2881 extern int symbol_table_frozen;
2882
2883 if (symbol_table_frozen)
2884 abort ();
2885 }
2886
2887 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2888
2889 obj_symbol_new_hook (symbolP);
2890
2891 #ifdef tc_symbol_new_hook
2892 tc_symbol_new_hook (symbolP);
2893 #endif
2894
2895 #ifdef DEBUG_SYMS
2896 verify_symbol_chain (symbol_rootP, symbol_lastP);
2897 #endif /* DEBUG_SYMS */
2898 }
2899
2900
2901 static void
2902 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2903 {
2904 unsigned int entry;
2905 literal_pool * pool;
2906 char sym_name[20];
2907
2908 pool = find_literal_pool ();
2909 if (pool == NULL
2910 || pool->symbol == NULL
2911 || pool->next_free_entry == 0)
2912 return;
2913
2914 mapping_state (MAP_DATA);
2915
2916 /* Align pool as you have word accesses.
2917 Only make a frag if we have to. */
2918 if (!need_pass_2)
2919 frag_align (2, 0, 0);
2920
2921 record_alignment (now_seg, 2);
2922
2923 sprintf (sym_name, "$$lit_\002%x", pool->id);
2924
2925 symbol_locate (pool->symbol, sym_name, now_seg,
2926 (valueT) frag_now_fix (), frag_now);
2927 symbol_table_insert (pool->symbol);
2928
2929 ARM_SET_THUMB (pool->symbol, thumb_mode);
2930
2931 #if defined OBJ_COFF || defined OBJ_ELF
2932 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2933 #endif
2934
2935 for (entry = 0; entry < pool->next_free_entry; entry ++)
2936 /* First output the expression in the instruction to the pool. */
2937 emit_expr (&(pool->literals[entry]), 4); /* .word */
2938
2939 /* Mark the pool as empty. */
2940 pool->next_free_entry = 0;
2941 pool->symbol = NULL;
2942 }
2943
2944 #ifdef OBJ_ELF
2945 /* Forward declarations for functions below, in the MD interface
2946 section. */
2947 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2948 static valueT create_unwind_entry (int);
2949 static void start_unwind_section (const segT, int);
2950 static void add_unwind_opcode (valueT, int);
2951 static void flush_pending_unwind (void);
2952
2953 /* Directives: Data. */
2954
2955 static void
2956 s_arm_elf_cons (int nbytes)
2957 {
2958 expressionS exp;
2959
2960 #ifdef md_flush_pending_output
2961 md_flush_pending_output ();
2962 #endif
2963
2964 if (is_it_end_of_statement ())
2965 {
2966 demand_empty_rest_of_line ();
2967 return;
2968 }
2969
2970 #ifdef md_cons_align
2971 md_cons_align (nbytes);
2972 #endif
2973
2974 mapping_state (MAP_DATA);
2975 do
2976 {
2977 int reloc;
2978 char *base = input_line_pointer;
2979
2980 expression (& exp);
2981
2982 if (exp.X_op != O_symbol)
2983 emit_expr (&exp, (unsigned int) nbytes);
2984 else
2985 {
2986 char *before_reloc = input_line_pointer;
2987 reloc = parse_reloc (&input_line_pointer);
2988 if (reloc == -1)
2989 {
2990 as_bad (_("unrecognized relocation suffix"));
2991 ignore_rest_of_line ();
2992 return;
2993 }
2994 else if (reloc == BFD_RELOC_UNUSED)
2995 emit_expr (&exp, (unsigned int) nbytes);
2996 else
2997 {
2998 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2999 int size = bfd_get_reloc_size (howto);
3000
3001 if (reloc == BFD_RELOC_ARM_PLT32)
3002 {
3003 as_bad (_("(plt) is only valid on branch targets"));
3004 reloc = BFD_RELOC_UNUSED;
3005 size = 0;
3006 }
3007
3008 if (size > nbytes)
3009 as_bad (_("%s relocations do not fit in %d bytes"),
3010 howto->name, nbytes);
3011 else
3012 {
3013 /* We've parsed an expression stopping at O_symbol.
3014 But there may be more expression left now that we
3015 have parsed the relocation marker. Parse it again.
3016 XXX Surely there is a cleaner way to do this. */
3017 char *p = input_line_pointer;
3018 int offset;
3019 char *save_buf = alloca (input_line_pointer - base);
3020 memcpy (save_buf, base, input_line_pointer - base);
3021 memmove (base + (input_line_pointer - before_reloc),
3022 base, before_reloc - base);
3023
3024 input_line_pointer = base + (input_line_pointer-before_reloc);
3025 expression (&exp);
3026 memcpy (base, save_buf, p - base);
3027
3028 offset = nbytes - size;
3029 p = frag_more ((int) nbytes);
3030 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3031 size, &exp, 0, reloc);
3032 }
3033 }
3034 }
3035 }
3036 while (*input_line_pointer++ == ',');
3037
3038 /* Put terminator back into stream. */
3039 input_line_pointer --;
3040 demand_empty_rest_of_line ();
3041 }
3042
3043
3044 /* Parse a .rel31 directive. */
3045
3046 static void
3047 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3048 {
3049 expressionS exp;
3050 char *p;
3051 valueT highbit;
3052
3053 highbit = 0;
3054 if (*input_line_pointer == '1')
3055 highbit = 0x80000000;
3056 else if (*input_line_pointer != '0')
3057 as_bad (_("expected 0 or 1"));
3058
3059 input_line_pointer++;
3060 if (*input_line_pointer != ',')
3061 as_bad (_("missing comma"));
3062 input_line_pointer++;
3063
3064 #ifdef md_flush_pending_output
3065 md_flush_pending_output ();
3066 #endif
3067
3068 #ifdef md_cons_align
3069 md_cons_align (4);
3070 #endif
3071
3072 mapping_state (MAP_DATA);
3073
3074 expression (&exp);
3075
3076 p = frag_more (4);
3077 md_number_to_chars (p, highbit, 4);
3078 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3079 BFD_RELOC_ARM_PREL31);
3080
3081 demand_empty_rest_of_line ();
3082 }
3083
3084 /* Directives: AEABI stack-unwind tables. */
3085
3086 /* Parse an unwind_fnstart directive. Simply records the current location. */
3087
3088 static void
3089 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3090 {
3091 demand_empty_rest_of_line ();
3092 /* Mark the start of the function. */
3093 unwind.proc_start = expr_build_dot ();
3094
3095 /* Reset the rest of the unwind info. */
3096 unwind.opcode_count = 0;
3097 unwind.table_entry = NULL;
3098 unwind.personality_routine = NULL;
3099 unwind.personality_index = -1;
3100 unwind.frame_size = 0;
3101 unwind.fp_offset = 0;
3102 unwind.fp_reg = REG_SP;
3103 unwind.fp_used = 0;
3104 unwind.sp_restored = 0;
3105 }
3106
3107
3108 /* Parse a handlerdata directive. Creates the exception handling table entry
3109 for the function. */
3110
3111 static void
3112 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3113 {
3114 demand_empty_rest_of_line ();
3115 if (unwind.table_entry)
3116 as_bad (_("duplicate .handlerdata directive"));
3117
3118 create_unwind_entry (1);
3119 }
3120
3121 /* Parse an unwind_fnend directive. Generates the index table entry. */
3122
3123 static void
3124 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3125 {
3126 long where;
3127 char *ptr;
3128 valueT val;
3129
3130 demand_empty_rest_of_line ();
3131
3132 /* Add eh table entry. */
3133 if (unwind.table_entry == NULL)
3134 val = create_unwind_entry (0);
3135 else
3136 val = 0;
3137
3138 /* Add index table entry. This is two words. */
3139 start_unwind_section (unwind.saved_seg, 1);
3140 frag_align (2, 0, 0);
3141 record_alignment (now_seg, 2);
3142
3143 ptr = frag_more (8);
3144 where = frag_now_fix () - 8;
3145
3146 /* Self relative offset of the function start. */
3147 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3148 BFD_RELOC_ARM_PREL31);
3149
3150 /* Indicate dependency on EHABI-defined personality routines to the
3151 linker, if it hasn't been done already. */
3152 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3153 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3154 {
3155 static const char *const name[] =
3156 {
3157 "__aeabi_unwind_cpp_pr0",
3158 "__aeabi_unwind_cpp_pr1",
3159 "__aeabi_unwind_cpp_pr2"
3160 };
3161 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3162 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3163 marked_pr_dependency |= 1 << unwind.personality_index;
3164 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3165 = marked_pr_dependency;
3166 }
3167
3168 if (val)
3169 /* Inline exception table entry. */
3170 md_number_to_chars (ptr + 4, val, 4);
3171 else
3172 /* Self relative offset of the table entry. */
3173 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3174 BFD_RELOC_ARM_PREL31);
3175
3176 /* Restore the original section. */
3177 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3178 }
3179
3180
3181 /* Parse an unwind_cantunwind directive. */
3182
3183 static void
3184 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3185 {
3186 demand_empty_rest_of_line ();
3187 if (unwind.personality_routine || unwind.personality_index != -1)
3188 as_bad (_("personality routine specified for cantunwind frame"));
3189
3190 unwind.personality_index = -2;
3191 }
3192
3193
3194 /* Parse a personalityindex directive. */
3195
3196 static void
3197 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3198 {
3199 expressionS exp;
3200
3201 if (unwind.personality_routine || unwind.personality_index != -1)
3202 as_bad (_("duplicate .personalityindex directive"));
3203
3204 expression (&exp);
3205
3206 if (exp.X_op != O_constant
3207 || exp.X_add_number < 0 || exp.X_add_number > 15)
3208 {
3209 as_bad (_("bad personality routine number"));
3210 ignore_rest_of_line ();
3211 return;
3212 }
3213
3214 unwind.personality_index = exp.X_add_number;
3215
3216 demand_empty_rest_of_line ();
3217 }
3218
3219
3220 /* Parse a personality directive. */
3221
3222 static void
3223 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3224 {
3225 char *name, *p, c;
3226
3227 if (unwind.personality_routine || unwind.personality_index != -1)
3228 as_bad (_("duplicate .personality directive"));
3229
3230 name = input_line_pointer;
3231 c = get_symbol_end ();
3232 p = input_line_pointer;
3233 unwind.personality_routine = symbol_find_or_make (name);
3234 *p = c;
3235 demand_empty_rest_of_line ();
3236 }
3237
3238
3239 /* Parse a directive saving core registers. */
3240
3241 static void
3242 s_arm_unwind_save_core (void)
3243 {
3244 valueT op;
3245 long range;
3246 int n;
3247
3248 range = parse_reg_list (&input_line_pointer);
3249 if (range == FAIL)
3250 {
3251 as_bad (_("expected register list"));
3252 ignore_rest_of_line ();
3253 return;
3254 }
3255
3256 demand_empty_rest_of_line ();
3257
3258 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3259 into .unwind_save {..., sp...}. We aren't bothered about the value of
3260 ip because it is clobbered by calls. */
3261 if (unwind.sp_restored && unwind.fp_reg == 12
3262 && (range & 0x3000) == 0x1000)
3263 {
3264 unwind.opcode_count--;
3265 unwind.sp_restored = 0;
3266 range = (range | 0x2000) & ~0x1000;
3267 unwind.pending_offset = 0;
3268 }
3269
3270 /* Pop r4-r15. */
3271 if (range & 0xfff0)
3272 {
3273 /* See if we can use the short opcodes. These pop a block of up to 8
3274 registers starting with r4, plus maybe r14. */
3275 for (n = 0; n < 8; n++)
3276 {
3277 /* Break at the first non-saved register. */
3278 if ((range & (1 << (n + 4))) == 0)
3279 break;
3280 }
3281 /* See if there are any other bits set. */
3282 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3283 {
3284 /* Use the long form. */
3285 op = 0x8000 | ((range >> 4) & 0xfff);
3286 add_unwind_opcode (op, 2);
3287 }
3288 else
3289 {
3290 /* Use the short form. */
3291 if (range & 0x4000)
3292 op = 0xa8; /* Pop r14. */
3293 else
3294 op = 0xa0; /* Do not pop r14. */
3295 op |= (n - 1);
3296 add_unwind_opcode (op, 1);
3297 }
3298 }
3299
3300 /* Pop r0-r3. */
3301 if (range & 0xf)
3302 {
3303 op = 0xb100 | (range & 0xf);
3304 add_unwind_opcode (op, 2);
3305 }
3306
3307 /* Record the number of bytes pushed. */
3308 for (n = 0; n < 16; n++)
3309 {
3310 if (range & (1 << n))
3311 unwind.frame_size += 4;
3312 }
3313 }
3314
3315
3316 /* Parse a directive saving FPA registers. */
3317
3318 static void
3319 s_arm_unwind_save_fpa (int reg)
3320 {
3321 expressionS exp;
3322 int num_regs;
3323 valueT op;
3324
3325 /* Get Number of registers to transfer. */
3326 if (skip_past_comma (&input_line_pointer) != FAIL)
3327 expression (&exp);
3328 else
3329 exp.X_op = O_illegal;
3330
3331 if (exp.X_op != O_constant)
3332 {
3333 as_bad (_("expected , <constant>"));
3334 ignore_rest_of_line ();
3335 return;
3336 }
3337
3338 num_regs = exp.X_add_number;
3339
3340 if (num_regs < 1 || num_regs > 4)
3341 {
3342 as_bad (_("number of registers must be in the range [1:4]"));
3343 ignore_rest_of_line ();
3344 return;
3345 }
3346
3347 demand_empty_rest_of_line ();
3348
3349 if (reg == 4)
3350 {
3351 /* Short form. */
3352 op = 0xb4 | (num_regs - 1);
3353 add_unwind_opcode (op, 1);
3354 }
3355 else
3356 {
3357 /* Long form. */
3358 op = 0xc800 | (reg << 4) | (num_regs - 1);
3359 add_unwind_opcode (op, 2);
3360 }
3361 unwind.frame_size += num_regs * 12;
3362 }
3363
3364
3365 /* Parse a directive saving VFP registers for ARMv6 and above. */
3366
3367 static void
3368 s_arm_unwind_save_vfp_armv6 (void)
3369 {
3370 int count;
3371 unsigned int start;
3372 valueT op;
3373 int num_vfpv3_regs = 0;
3374 int num_regs_below_16;
3375
3376 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3377 if (count == FAIL)
3378 {
3379 as_bad (_("expected register list"));
3380 ignore_rest_of_line ();
3381 return;
3382 }
3383
3384 demand_empty_rest_of_line ();
3385
3386 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3387 than FSTMX/FLDMX-style ones). */
3388
3389 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3390 if (start >= 16)
3391 num_vfpv3_regs = count;
3392 else if (start + count > 16)
3393 num_vfpv3_regs = start + count - 16;
3394
3395 if (num_vfpv3_regs > 0)
3396 {
3397 int start_offset = start > 16 ? start - 16 : 0;
3398 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3399 add_unwind_opcode (op, 2);
3400 }
3401
3402 /* Generate opcode for registers numbered in the range 0 .. 15. */
3403 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3404 assert (num_regs_below_16 + num_vfpv3_regs == count);
3405 if (num_regs_below_16 > 0)
3406 {
3407 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3408 add_unwind_opcode (op, 2);
3409 }
3410
3411 unwind.frame_size += count * 8;
3412 }
3413
3414
3415 /* Parse a directive saving VFP registers for pre-ARMv6. */
3416
3417 static void
3418 s_arm_unwind_save_vfp (void)
3419 {
3420 int count;
3421 unsigned int reg;
3422 valueT op;
3423
3424 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3425 if (count == FAIL)
3426 {
3427 as_bad (_("expected register list"));
3428 ignore_rest_of_line ();
3429 return;
3430 }
3431
3432 demand_empty_rest_of_line ();
3433
3434 if (reg == 8)
3435 {
3436 /* Short form. */
3437 op = 0xb8 | (count - 1);
3438 add_unwind_opcode (op, 1);
3439 }
3440 else
3441 {
3442 /* Long form. */
3443 op = 0xb300 | (reg << 4) | (count - 1);
3444 add_unwind_opcode (op, 2);
3445 }
3446 unwind.frame_size += count * 8 + 4;
3447 }
3448
3449
3450 /* Parse a directive saving iWMMXt data registers. */
3451
3452 static void
3453 s_arm_unwind_save_mmxwr (void)
3454 {
3455 int reg;
3456 int hi_reg;
3457 int i;
3458 unsigned mask = 0;
3459 valueT op;
3460
3461 if (*input_line_pointer == '{')
3462 input_line_pointer++;
3463
3464 do
3465 {
3466 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3467
3468 if (reg == FAIL)
3469 {
3470 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3471 goto error;
3472 }
3473
3474 if (mask >> reg)
3475 as_tsktsk (_("register list not in ascending order"));
3476 mask |= 1 << reg;
3477
3478 if (*input_line_pointer == '-')
3479 {
3480 input_line_pointer++;
3481 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3482 if (hi_reg == FAIL)
3483 {
3484 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3485 goto error;
3486 }
3487 else if (reg >= hi_reg)
3488 {
3489 as_bad (_("bad register range"));
3490 goto error;
3491 }
3492 for (; reg < hi_reg; reg++)
3493 mask |= 1 << reg;
3494 }
3495 }
3496 while (skip_past_comma (&input_line_pointer) != FAIL);
3497
3498 if (*input_line_pointer == '}')
3499 input_line_pointer++;
3500
3501 demand_empty_rest_of_line ();
3502
3503 /* Generate any deferred opcodes because we're going to be looking at
3504 the list. */
3505 flush_pending_unwind ();
3506
3507 for (i = 0; i < 16; i++)
3508 {
3509 if (mask & (1 << i))
3510 unwind.frame_size += 8;
3511 }
3512
3513 /* Attempt to combine with a previous opcode. We do this because gcc
3514 likes to output separate unwind directives for a single block of
3515 registers. */
3516 if (unwind.opcode_count > 0)
3517 {
3518 i = unwind.opcodes[unwind.opcode_count - 1];
3519 if ((i & 0xf8) == 0xc0)
3520 {
3521 i &= 7;
3522 /* Only merge if the blocks are contiguous. */
3523 if (i < 6)
3524 {
3525 if ((mask & 0xfe00) == (1 << 9))
3526 {
3527 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3528 unwind.opcode_count--;
3529 }
3530 }
3531 else if (i == 6 && unwind.opcode_count >= 2)
3532 {
3533 i = unwind.opcodes[unwind.opcode_count - 2];
3534 reg = i >> 4;
3535 i &= 0xf;
3536
3537 op = 0xffff << (reg - 1);
3538 if (reg > 0
3539 && ((mask & op) == (1u << (reg - 1))))
3540 {
3541 op = (1 << (reg + i + 1)) - 1;
3542 op &= ~((1 << reg) - 1);
3543 mask |= op;
3544 unwind.opcode_count -= 2;
3545 }
3546 }
3547 }
3548 }
3549
3550 hi_reg = 15;
3551 /* We want to generate opcodes in the order the registers have been
3552 saved, ie. descending order. */
3553 for (reg = 15; reg >= -1; reg--)
3554 {
3555 /* Save registers in blocks. */
3556 if (reg < 0
3557 || !(mask & (1 << reg)))
3558 {
3559 /* We found an unsaved reg. Generate opcodes to save the
3560 preceding block. */
3561 if (reg != hi_reg)
3562 {
3563 if (reg == 9)
3564 {
3565 /* Short form. */
3566 op = 0xc0 | (hi_reg - 10);
3567 add_unwind_opcode (op, 1);
3568 }
3569 else
3570 {
3571 /* Long form. */
3572 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3573 add_unwind_opcode (op, 2);
3574 }
3575 }
3576 hi_reg = reg - 1;
3577 }
3578 }
3579
3580 return;
3581 error:
3582 ignore_rest_of_line ();
3583 }
3584
3585 static void
3586 s_arm_unwind_save_mmxwcg (void)
3587 {
3588 int reg;
3589 int hi_reg;
3590 unsigned mask = 0;
3591 valueT op;
3592
3593 if (*input_line_pointer == '{')
3594 input_line_pointer++;
3595
3596 do
3597 {
3598 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3599
3600 if (reg == FAIL)
3601 {
3602 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3603 goto error;
3604 }
3605
3606 reg -= 8;
3607 if (mask >> reg)
3608 as_tsktsk (_("register list not in ascending order"));
3609 mask |= 1 << reg;
3610
3611 if (*input_line_pointer == '-')
3612 {
3613 input_line_pointer++;
3614 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3615 if (hi_reg == FAIL)
3616 {
3617 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3618 goto error;
3619 }
3620 else if (reg >= hi_reg)
3621 {
3622 as_bad (_("bad register range"));
3623 goto error;
3624 }
3625 for (; reg < hi_reg; reg++)
3626 mask |= 1 << reg;
3627 }
3628 }
3629 while (skip_past_comma (&input_line_pointer) != FAIL);
3630
3631 if (*input_line_pointer == '}')
3632 input_line_pointer++;
3633
3634 demand_empty_rest_of_line ();
3635
3636 /* Generate any deferred opcodes because we're going to be looking at
3637 the list. */
3638 flush_pending_unwind ();
3639
3640 for (reg = 0; reg < 16; reg++)
3641 {
3642 if (mask & (1 << reg))
3643 unwind.frame_size += 4;
3644 }
3645 op = 0xc700 | mask;
3646 add_unwind_opcode (op, 2);
3647 return;
3648 error:
3649 ignore_rest_of_line ();
3650 }
3651
3652
3653 /* Parse an unwind_save directive.
3654 If the argument is non-zero, this is a .vsave directive. */
3655
3656 static void
3657 s_arm_unwind_save (int arch_v6)
3658 {
3659 char *peek;
3660 struct reg_entry *reg;
3661 bfd_boolean had_brace = FALSE;
3662
3663 /* Figure out what sort of save we have. */
3664 peek = input_line_pointer;
3665
3666 if (*peek == '{')
3667 {
3668 had_brace = TRUE;
3669 peek++;
3670 }
3671
3672 reg = arm_reg_parse_multi (&peek);
3673
3674 if (!reg)
3675 {
3676 as_bad (_("register expected"));
3677 ignore_rest_of_line ();
3678 return;
3679 }
3680
3681 switch (reg->type)
3682 {
3683 case REG_TYPE_FN:
3684 if (had_brace)
3685 {
3686 as_bad (_("FPA .unwind_save does not take a register list"));
3687 ignore_rest_of_line ();
3688 return;
3689 }
3690 input_line_pointer = peek;
3691 s_arm_unwind_save_fpa (reg->number);
3692 return;
3693
3694 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
3695 case REG_TYPE_VFD:
3696 if (arch_v6)
3697 s_arm_unwind_save_vfp_armv6 ();
3698 else
3699 s_arm_unwind_save_vfp ();
3700 return;
3701 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3702 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3703
3704 default:
3705 as_bad (_(".unwind_save does not support this kind of register"));
3706 ignore_rest_of_line ();
3707 }
3708 }
3709
3710
3711 /* Parse an unwind_movsp directive. */
3712
3713 static void
3714 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3715 {
3716 int reg;
3717 valueT op;
3718 int offset;
3719
3720 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3721 if (reg == FAIL)
3722 {
3723 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
3724 ignore_rest_of_line ();
3725 return;
3726 }
3727
3728 /* Optional constant. */
3729 if (skip_past_comma (&input_line_pointer) != FAIL)
3730 {
3731 if (immediate_for_directive (&offset) == FAIL)
3732 return;
3733 }
3734 else
3735 offset = 0;
3736
3737 demand_empty_rest_of_line ();
3738
3739 if (reg == REG_SP || reg == REG_PC)
3740 {
3741 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3742 return;
3743 }
3744
3745 if (unwind.fp_reg != REG_SP)
3746 as_bad (_("unexpected .unwind_movsp directive"));
3747
3748 /* Generate opcode to restore the value. */
3749 op = 0x90 | reg;
3750 add_unwind_opcode (op, 1);
3751
3752 /* Record the information for later. */
3753 unwind.fp_reg = reg;
3754 unwind.fp_offset = unwind.frame_size - offset;
3755 unwind.sp_restored = 1;
3756 }
3757
3758 /* Parse an unwind_pad directive. */
3759
3760 static void
3761 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3762 {
3763 int offset;
3764
3765 if (immediate_for_directive (&offset) == FAIL)
3766 return;
3767
3768 if (offset & 3)
3769 {
3770 as_bad (_("stack increment must be multiple of 4"));
3771 ignore_rest_of_line ();
3772 return;
3773 }
3774
3775 /* Don't generate any opcodes, just record the details for later. */
3776 unwind.frame_size += offset;
3777 unwind.pending_offset += offset;
3778
3779 demand_empty_rest_of_line ();
3780 }
3781
3782 /* Parse an unwind_setfp directive. */
3783
3784 static void
3785 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3786 {
3787 int sp_reg;
3788 int fp_reg;
3789 int offset;
3790
3791 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3792 if (skip_past_comma (&input_line_pointer) == FAIL)
3793 sp_reg = FAIL;
3794 else
3795 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3796
3797 if (fp_reg == FAIL || sp_reg == FAIL)
3798 {
3799 as_bad (_("expected <reg>, <reg>"));
3800 ignore_rest_of_line ();
3801 return;
3802 }
3803
3804 /* Optional constant. */
3805 if (skip_past_comma (&input_line_pointer) != FAIL)
3806 {
3807 if (immediate_for_directive (&offset) == FAIL)
3808 return;
3809 }
3810 else
3811 offset = 0;
3812
3813 demand_empty_rest_of_line ();
3814
3815 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
3816 {
3817 as_bad (_("register must be either sp or set by a previous"
3818 "unwind_movsp directive"));
3819 return;
3820 }
3821
3822 /* Don't generate any opcodes, just record the information for later. */
3823 unwind.fp_reg = fp_reg;
3824 unwind.fp_used = 1;
3825 if (sp_reg == REG_SP)
3826 unwind.fp_offset = unwind.frame_size - offset;
3827 else
3828 unwind.fp_offset -= offset;
3829 }
3830
3831 /* Parse an unwind_raw directive. */
3832
3833 static void
3834 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3835 {
3836 expressionS exp;
3837 /* This is an arbitrary limit. */
3838 unsigned char op[16];
3839 int count;
3840
3841 expression (&exp);
3842 if (exp.X_op == O_constant
3843 && skip_past_comma (&input_line_pointer) != FAIL)
3844 {
3845 unwind.frame_size += exp.X_add_number;
3846 expression (&exp);
3847 }
3848 else
3849 exp.X_op = O_illegal;
3850
3851 if (exp.X_op != O_constant)
3852 {
3853 as_bad (_("expected <offset>, <opcode>"));
3854 ignore_rest_of_line ();
3855 return;
3856 }
3857
3858 count = 0;
3859
3860 /* Parse the opcode. */
3861 for (;;)
3862 {
3863 if (count >= 16)
3864 {
3865 as_bad (_("unwind opcode too long"));
3866 ignore_rest_of_line ();
3867 }
3868 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3869 {
3870 as_bad (_("invalid unwind opcode"));
3871 ignore_rest_of_line ();
3872 return;
3873 }
3874 op[count++] = exp.X_add_number;
3875
3876 /* Parse the next byte. */
3877 if (skip_past_comma (&input_line_pointer) == FAIL)
3878 break;
3879
3880 expression (&exp);
3881 }
3882
3883 /* Add the opcode bytes in reverse order. */
3884 while (count--)
3885 add_unwind_opcode (op[count], 1);
3886
3887 demand_empty_rest_of_line ();
3888 }
3889
3890
3891 /* Parse a .eabi_attribute directive. */
3892
3893 static void
3894 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3895 {
3896 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
3897
3898 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
3899 attributes_set_explicitly[tag] = 1;
3900 }
3901 #endif /* OBJ_ELF */
3902
3903 static void s_arm_arch (int);
3904 static void s_arm_object_arch (int);
3905 static void s_arm_cpu (int);
3906 static void s_arm_fpu (int);
3907
3908 #ifdef TE_PE
3909
3910 static void
3911 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3912 {
3913 expressionS exp;
3914
3915 do
3916 {
3917 expression (&exp);
3918 if (exp.X_op == O_symbol)
3919 exp.X_op = O_secrel;
3920
3921 emit_expr (&exp, 4);
3922 }
3923 while (*input_line_pointer++ == ',');
3924
3925 input_line_pointer--;
3926 demand_empty_rest_of_line ();
3927 }
3928 #endif /* TE_PE */
3929
3930 /* This table describes all the machine specific pseudo-ops the assembler
3931 has to support. The fields are:
3932 pseudo-op name without dot
3933 function to call to execute this pseudo-op
3934 Integer arg to pass to the function. */
3935
3936 const pseudo_typeS md_pseudo_table[] =
3937 {
3938 /* Never called because '.req' does not start a line. */
3939 { "req", s_req, 0 },
3940 /* Following two are likewise never called. */
3941 { "dn", s_dn, 0 },
3942 { "qn", s_qn, 0 },
3943 { "unreq", s_unreq, 0 },
3944 { "bss", s_bss, 0 },
3945 { "align", s_align, 0 },
3946 { "arm", s_arm, 0 },
3947 { "thumb", s_thumb, 0 },
3948 { "code", s_code, 0 },
3949 { "force_thumb", s_force_thumb, 0 },
3950 { "thumb_func", s_thumb_func, 0 },
3951 { "thumb_set", s_thumb_set, 0 },
3952 { "even", s_even, 0 },
3953 { "ltorg", s_ltorg, 0 },
3954 { "pool", s_ltorg, 0 },
3955 { "syntax", s_syntax, 0 },
3956 { "cpu", s_arm_cpu, 0 },
3957 { "arch", s_arm_arch, 0 },
3958 { "object_arch", s_arm_object_arch, 0 },
3959 { "fpu", s_arm_fpu, 0 },
3960 #ifdef OBJ_ELF
3961 { "word", s_arm_elf_cons, 4 },
3962 { "long", s_arm_elf_cons, 4 },
3963 { "rel31", s_arm_rel31, 0 },
3964 { "fnstart", s_arm_unwind_fnstart, 0 },
3965 { "fnend", s_arm_unwind_fnend, 0 },
3966 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3967 { "personality", s_arm_unwind_personality, 0 },
3968 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3969 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3970 { "save", s_arm_unwind_save, 0 },
3971 { "vsave", s_arm_unwind_save, 1 },
3972 { "movsp", s_arm_unwind_movsp, 0 },
3973 { "pad", s_arm_unwind_pad, 0 },
3974 { "setfp", s_arm_unwind_setfp, 0 },
3975 { "unwind_raw", s_arm_unwind_raw, 0 },
3976 { "eabi_attribute", s_arm_eabi_attribute, 0 },
3977 #else
3978 { "word", cons, 4},
3979
3980 /* These are used for dwarf. */
3981 {"2byte", cons, 2},
3982 {"4byte", cons, 4},
3983 {"8byte", cons, 8},
3984 /* These are used for dwarf2. */
3985 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3986 { "loc", dwarf2_directive_loc, 0 },
3987 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
3988 #endif
3989 { "extend", float_cons, 'x' },
3990 { "ldouble", float_cons, 'x' },
3991 { "packed", float_cons, 'p' },
3992 #ifdef TE_PE
3993 {"secrel32", pe_directive_secrel, 0},
3994 #endif
3995 { 0, 0, 0 }
3996 };
3997 \f
3998 /* Parser functions used exclusively in instruction operands. */
3999
4000 /* Generic immediate-value read function for use in insn parsing.
4001 STR points to the beginning of the immediate (the leading #);
4002 VAL receives the value; if the value is outside [MIN, MAX]
4003 issue an error. PREFIX_OPT is true if the immediate prefix is
4004 optional. */
4005
4006 static int
4007 parse_immediate (char **str, int *val, int min, int max,
4008 bfd_boolean prefix_opt)
4009 {
4010 expressionS exp;
4011 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4012 if (exp.X_op != O_constant)
4013 {
4014 inst.error = _("constant expression required");
4015 return FAIL;
4016 }
4017
4018 if (exp.X_add_number < min || exp.X_add_number > max)
4019 {
4020 inst.error = _("immediate value out of range");
4021 return FAIL;
4022 }
4023
4024 *val = exp.X_add_number;
4025 return SUCCESS;
4026 }
4027
4028 /* Less-generic immediate-value read function with the possibility of loading a
4029 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4030 instructions. Puts the result directly in inst.operands[i]. */
4031
4032 static int
4033 parse_big_immediate (char **str, int i)
4034 {
4035 expressionS exp;
4036 char *ptr = *str;
4037
4038 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4039
4040 if (exp.X_op == O_constant)
4041 {
4042 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4043 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4044 O_constant. We have to be careful not to break compilation for
4045 32-bit X_add_number, though. */
4046 if ((exp.X_add_number & ~0xffffffffl) != 0)
4047 {
4048 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4049 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4050 inst.operands[i].regisimm = 1;
4051 }
4052 }
4053 else if (exp.X_op == O_big
4054 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4055 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4056 {
4057 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4058 /* Bignums have their least significant bits in
4059 generic_bignum[0]. Make sure we put 32 bits in imm and
4060 32 bits in reg, in a (hopefully) portable way. */
4061 assert (parts != 0);
4062 inst.operands[i].imm = 0;
4063 for (j = 0; j < parts; j++, idx++)
4064 inst.operands[i].imm |= generic_bignum[idx]
4065 << (LITTLENUM_NUMBER_OF_BITS * j);
4066 inst.operands[i].reg = 0;
4067 for (j = 0; j < parts; j++, idx++)
4068 inst.operands[i].reg |= generic_bignum[idx]
4069 << (LITTLENUM_NUMBER_OF_BITS * j);
4070 inst.operands[i].regisimm = 1;
4071 }
4072 else
4073 return FAIL;
4074
4075 *str = ptr;
4076
4077 return SUCCESS;
4078 }
4079
4080 /* Returns the pseudo-register number of an FPA immediate constant,
4081 or FAIL if there isn't a valid constant here. */
4082
4083 static int
4084 parse_fpa_immediate (char ** str)
4085 {
4086 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4087 char * save_in;
4088 expressionS exp;
4089 int i;
4090 int j;
4091
4092 /* First try and match exact strings, this is to guarantee
4093 that some formats will work even for cross assembly. */
4094
4095 for (i = 0; fp_const[i]; i++)
4096 {
4097 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4098 {
4099 char *start = *str;
4100
4101 *str += strlen (fp_const[i]);
4102 if (is_end_of_line[(unsigned char) **str])
4103 return i + 8;
4104 *str = start;
4105 }
4106 }
4107
4108 /* Just because we didn't get a match doesn't mean that the constant
4109 isn't valid, just that it is in a format that we don't
4110 automatically recognize. Try parsing it with the standard
4111 expression routines. */
4112
4113 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4114
4115 /* Look for a raw floating point number. */
4116 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4117 && is_end_of_line[(unsigned char) *save_in])
4118 {
4119 for (i = 0; i < NUM_FLOAT_VALS; i++)
4120 {
4121 for (j = 0; j < MAX_LITTLENUMS; j++)
4122 {
4123 if (words[j] != fp_values[i][j])
4124 break;
4125 }
4126
4127 if (j == MAX_LITTLENUMS)
4128 {
4129 *str = save_in;
4130 return i + 8;
4131 }
4132 }
4133 }
4134
4135 /* Try and parse a more complex expression, this will probably fail
4136 unless the code uses a floating point prefix (eg "0f"). */
4137 save_in = input_line_pointer;
4138 input_line_pointer = *str;
4139 if (expression (&exp) == absolute_section
4140 && exp.X_op == O_big
4141 && exp.X_add_number < 0)
4142 {
4143 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4144 Ditto for 15. */
4145 if (gen_to_words (words, 5, (long) 15) == 0)
4146 {
4147 for (i = 0; i < NUM_FLOAT_VALS; i++)
4148 {
4149 for (j = 0; j < MAX_LITTLENUMS; j++)
4150 {
4151 if (words[j] != fp_values[i][j])
4152 break;
4153 }
4154
4155 if (j == MAX_LITTLENUMS)
4156 {
4157 *str = input_line_pointer;
4158 input_line_pointer = save_in;
4159 return i + 8;
4160 }
4161 }
4162 }
4163 }
4164
4165 *str = input_line_pointer;
4166 input_line_pointer = save_in;
4167 inst.error = _("invalid FPA immediate expression");
4168 return FAIL;
4169 }
4170
4171 /* Returns 1 if a number has "quarter-precision" float format
4172 0baBbbbbbc defgh000 00000000 00000000. */
4173
4174 static int
4175 is_quarter_float (unsigned imm)
4176 {
4177 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4178 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4179 }
4180
4181 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4182 0baBbbbbbc defgh000 00000000 00000000.
4183 The zero and minus-zero cases need special handling, since they can't be
4184 encoded in the "quarter-precision" float format, but can nonetheless be
4185 loaded as integer constants. */
4186
4187 static unsigned
4188 parse_qfloat_immediate (char **ccp, int *immed)
4189 {
4190 char *str = *ccp;
4191 char *fpnum;
4192 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4193 int found_fpchar = 0;
4194
4195 skip_past_char (&str, '#');
4196
4197 /* We must not accidentally parse an integer as a floating-point number. Make
4198 sure that the value we parse is not an integer by checking for special
4199 characters '.' or 'e'.
4200 FIXME: This is a horrible hack, but doing better is tricky because type
4201 information isn't in a very usable state at parse time. */
4202 fpnum = str;
4203 skip_whitespace (fpnum);
4204
4205 if (strncmp (fpnum, "0x", 2) == 0)
4206 return FAIL;
4207 else
4208 {
4209 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4210 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4211 {
4212 found_fpchar = 1;
4213 break;
4214 }
4215
4216 if (!found_fpchar)
4217 return FAIL;
4218 }
4219
4220 if ((str = atof_ieee (str, 's', words)) != NULL)
4221 {
4222 unsigned fpword = 0;
4223 int i;
4224
4225 /* Our FP word must be 32 bits (single-precision FP). */
4226 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4227 {
4228 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4229 fpword |= words[i];
4230 }
4231
4232 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4233 *immed = fpword;
4234 else
4235 return FAIL;
4236
4237 *ccp = str;
4238
4239 return SUCCESS;
4240 }
4241
4242 return FAIL;
4243 }
4244
4245 /* Shift operands. */
4246 enum shift_kind
4247 {
4248 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4249 };
4250
4251 struct asm_shift_name
4252 {
4253 const char *name;
4254 enum shift_kind kind;
4255 };
4256
4257 /* Third argument to parse_shift. */
4258 enum parse_shift_mode
4259 {
4260 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4261 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4262 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4263 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4264 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4265 };
4266
4267 /* Parse a <shift> specifier on an ARM data processing instruction.
4268 This has three forms:
4269
4270 (LSL|LSR|ASL|ASR|ROR) Rs
4271 (LSL|LSR|ASL|ASR|ROR) #imm
4272 RRX
4273
4274 Note that ASL is assimilated to LSL in the instruction encoding, and
4275 RRX to ROR #0 (which cannot be written as such). */
4276
4277 static int
4278 parse_shift (char **str, int i, enum parse_shift_mode mode)
4279 {
4280 const struct asm_shift_name *shift_name;
4281 enum shift_kind shift;
4282 char *s = *str;
4283 char *p = s;
4284 int reg;
4285
4286 for (p = *str; ISALPHA (*p); p++)
4287 ;
4288
4289 if (p == *str)
4290 {
4291 inst.error = _("shift expression expected");
4292 return FAIL;
4293 }
4294
4295 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4296
4297 if (shift_name == NULL)
4298 {
4299 inst.error = _("shift expression expected");
4300 return FAIL;
4301 }
4302
4303 shift = shift_name->kind;
4304
4305 switch (mode)
4306 {
4307 case NO_SHIFT_RESTRICT:
4308 case SHIFT_IMMEDIATE: break;
4309
4310 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4311 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4312 {
4313 inst.error = _("'LSL' or 'ASR' required");
4314 return FAIL;
4315 }
4316 break;
4317
4318 case SHIFT_LSL_IMMEDIATE:
4319 if (shift != SHIFT_LSL)
4320 {
4321 inst.error = _("'LSL' required");
4322 return FAIL;
4323 }
4324 break;
4325
4326 case SHIFT_ASR_IMMEDIATE:
4327 if (shift != SHIFT_ASR)
4328 {
4329 inst.error = _("'ASR' required");
4330 return FAIL;
4331 }
4332 break;
4333
4334 default: abort ();
4335 }
4336
4337 if (shift != SHIFT_RRX)
4338 {
4339 /* Whitespace can appear here if the next thing is a bare digit. */
4340 skip_whitespace (p);
4341
4342 if (mode == NO_SHIFT_RESTRICT
4343 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4344 {
4345 inst.operands[i].imm = reg;
4346 inst.operands[i].immisreg = 1;
4347 }
4348 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4349 return FAIL;
4350 }
4351 inst.operands[i].shift_kind = shift;
4352 inst.operands[i].shifted = 1;
4353 *str = p;
4354 return SUCCESS;
4355 }
4356
4357 /* Parse a <shifter_operand> for an ARM data processing instruction:
4358
4359 #<immediate>
4360 #<immediate>, <rotate>
4361 <Rm>
4362 <Rm>, <shift>
4363
4364 where <shift> is defined by parse_shift above, and <rotate> is a
4365 multiple of 2 between 0 and 30. Validation of immediate operands
4366 is deferred to md_apply_fix. */
4367
4368 static int
4369 parse_shifter_operand (char **str, int i)
4370 {
4371 int value;
4372 expressionS expr;
4373
4374 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4375 {
4376 inst.operands[i].reg = value;
4377 inst.operands[i].isreg = 1;
4378
4379 /* parse_shift will override this if appropriate */
4380 inst.reloc.exp.X_op = O_constant;
4381 inst.reloc.exp.X_add_number = 0;
4382
4383 if (skip_past_comma (str) == FAIL)
4384 return SUCCESS;
4385
4386 /* Shift operation on register. */
4387 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4388 }
4389
4390 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4391 return FAIL;
4392
4393 if (skip_past_comma (str) == SUCCESS)
4394 {
4395 /* #x, y -- ie explicit rotation by Y. */
4396 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4397 return FAIL;
4398
4399 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4400 {
4401 inst.error = _("constant expression expected");
4402 return FAIL;
4403 }
4404
4405 value = expr.X_add_number;
4406 if (value < 0 || value > 30 || value % 2 != 0)
4407 {
4408 inst.error = _("invalid rotation");
4409 return FAIL;
4410 }
4411 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4412 {
4413 inst.error = _("invalid constant");
4414 return FAIL;
4415 }
4416
4417 /* Convert to decoded value. md_apply_fix will put it back. */
4418 inst.reloc.exp.X_add_number
4419 = (((inst.reloc.exp.X_add_number << (32 - value))
4420 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4421 }
4422
4423 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4424 inst.reloc.pc_rel = 0;
4425 return SUCCESS;
4426 }
4427
4428 /* Group relocation information. Each entry in the table contains the
4429 textual name of the relocation as may appear in assembler source
4430 and must end with a colon.
4431 Along with this textual name are the relocation codes to be used if
4432 the corresponding instruction is an ALU instruction (ADD or SUB only),
4433 an LDR, an LDRS, or an LDC. */
4434
4435 struct group_reloc_table_entry
4436 {
4437 const char *name;
4438 int alu_code;
4439 int ldr_code;
4440 int ldrs_code;
4441 int ldc_code;
4442 };
4443
4444 typedef enum
4445 {
4446 /* Varieties of non-ALU group relocation. */
4447
4448 GROUP_LDR,
4449 GROUP_LDRS,
4450 GROUP_LDC
4451 } group_reloc_type;
4452
4453 static struct group_reloc_table_entry group_reloc_table[] =
4454 { /* Program counter relative: */
4455 { "pc_g0_nc",
4456 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4457 0, /* LDR */
4458 0, /* LDRS */
4459 0 }, /* LDC */
4460 { "pc_g0",
4461 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4462 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4463 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4464 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4465 { "pc_g1_nc",
4466 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4467 0, /* LDR */
4468 0, /* LDRS */
4469 0 }, /* LDC */
4470 { "pc_g1",
4471 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4472 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4473 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4474 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4475 { "pc_g2",
4476 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4477 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4478 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4479 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4480 /* Section base relative */
4481 { "sb_g0_nc",
4482 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4483 0, /* LDR */
4484 0, /* LDRS */
4485 0 }, /* LDC */
4486 { "sb_g0",
4487 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4488 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4489 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4490 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4491 { "sb_g1_nc",
4492 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4493 0, /* LDR */
4494 0, /* LDRS */
4495 0 }, /* LDC */
4496 { "sb_g1",
4497 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4498 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4499 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4500 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4501 { "sb_g2",
4502 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4503 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4504 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4505 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4506
4507 /* Given the address of a pointer pointing to the textual name of a group
4508 relocation as may appear in assembler source, attempt to find its details
4509 in group_reloc_table. The pointer will be updated to the character after
4510 the trailing colon. On failure, FAIL will be returned; SUCCESS
4511 otherwise. On success, *entry will be updated to point at the relevant
4512 group_reloc_table entry. */
4513
4514 static int
4515 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4516 {
4517 unsigned int i;
4518 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4519 {
4520 int length = strlen (group_reloc_table[i].name);
4521
4522 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4523 && (*str)[length] == ':')
4524 {
4525 *out = &group_reloc_table[i];
4526 *str += (length + 1);
4527 return SUCCESS;
4528 }
4529 }
4530
4531 return FAIL;
4532 }
4533
4534 /* Parse a <shifter_operand> for an ARM data processing instruction
4535 (as for parse_shifter_operand) where group relocations are allowed:
4536
4537 #<immediate>
4538 #<immediate>, <rotate>
4539 #:<group_reloc>:<expression>
4540 <Rm>
4541 <Rm>, <shift>
4542
4543 where <group_reloc> is one of the strings defined in group_reloc_table.
4544 The hashes are optional.
4545
4546 Everything else is as for parse_shifter_operand. */
4547
4548 static parse_operand_result
4549 parse_shifter_operand_group_reloc (char **str, int i)
4550 {
4551 /* Determine if we have the sequence of characters #: or just :
4552 coming next. If we do, then we check for a group relocation.
4553 If we don't, punt the whole lot to parse_shifter_operand. */
4554
4555 if (((*str)[0] == '#' && (*str)[1] == ':')
4556 || (*str)[0] == ':')
4557 {
4558 struct group_reloc_table_entry *entry;
4559
4560 if ((*str)[0] == '#')
4561 (*str) += 2;
4562 else
4563 (*str)++;
4564
4565 /* Try to parse a group relocation. Anything else is an error. */
4566 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4567 {
4568 inst.error = _("unknown group relocation");
4569 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4570 }
4571
4572 /* We now have the group relocation table entry corresponding to
4573 the name in the assembler source. Next, we parse the expression. */
4574 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4575 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4576
4577 /* Record the relocation type (always the ALU variant here). */
4578 inst.reloc.type = entry->alu_code;
4579 assert (inst.reloc.type != 0);
4580
4581 return PARSE_OPERAND_SUCCESS;
4582 }
4583 else
4584 return parse_shifter_operand (str, i) == SUCCESS
4585 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4586
4587 /* Never reached. */
4588 }
4589
4590 /* Parse all forms of an ARM address expression. Information is written
4591 to inst.operands[i] and/or inst.reloc.
4592
4593 Preindexed addressing (.preind=1):
4594
4595 [Rn, #offset] .reg=Rn .reloc.exp=offset
4596 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4597 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4598 .shift_kind=shift .reloc.exp=shift_imm
4599
4600 These three may have a trailing ! which causes .writeback to be set also.
4601
4602 Postindexed addressing (.postind=1, .writeback=1):
4603
4604 [Rn], #offset .reg=Rn .reloc.exp=offset
4605 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4606 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4607 .shift_kind=shift .reloc.exp=shift_imm
4608
4609 Unindexed addressing (.preind=0, .postind=0):
4610
4611 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4612
4613 Other:
4614
4615 [Rn]{!} shorthand for [Rn,#0]{!}
4616 =immediate .isreg=0 .reloc.exp=immediate
4617 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4618
4619 It is the caller's responsibility to check for addressing modes not
4620 supported by the instruction, and to set inst.reloc.type. */
4621
4622 static parse_operand_result
4623 parse_address_main (char **str, int i, int group_relocations,
4624 group_reloc_type group_type)
4625 {
4626 char *p = *str;
4627 int reg;
4628
4629 if (skip_past_char (&p, '[') == FAIL)
4630 {
4631 if (skip_past_char (&p, '=') == FAIL)
4632 {
4633 /* bare address - translate to PC-relative offset */
4634 inst.reloc.pc_rel = 1;
4635 inst.operands[i].reg = REG_PC;
4636 inst.operands[i].isreg = 1;
4637 inst.operands[i].preind = 1;
4638 }
4639 /* else a load-constant pseudo op, no special treatment needed here */
4640
4641 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4642 return PARSE_OPERAND_FAIL;
4643
4644 *str = p;
4645 return PARSE_OPERAND_SUCCESS;
4646 }
4647
4648 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4649 {
4650 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4651 return PARSE_OPERAND_FAIL;
4652 }
4653 inst.operands[i].reg = reg;
4654 inst.operands[i].isreg = 1;
4655
4656 if (skip_past_comma (&p) == SUCCESS)
4657 {
4658 inst.operands[i].preind = 1;
4659
4660 if (*p == '+') p++;
4661 else if (*p == '-') p++, inst.operands[i].negative = 1;
4662
4663 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4664 {
4665 inst.operands[i].imm = reg;
4666 inst.operands[i].immisreg = 1;
4667
4668 if (skip_past_comma (&p) == SUCCESS)
4669 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4670 return PARSE_OPERAND_FAIL;
4671 }
4672 else if (skip_past_char (&p, ':') == SUCCESS)
4673 {
4674 /* FIXME: '@' should be used here, but it's filtered out by generic
4675 code before we get to see it here. This may be subject to
4676 change. */
4677 expressionS exp;
4678 my_get_expression (&exp, &p, GE_NO_PREFIX);
4679 if (exp.X_op != O_constant)
4680 {
4681 inst.error = _("alignment must be constant");
4682 return PARSE_OPERAND_FAIL;
4683 }
4684 inst.operands[i].imm = exp.X_add_number << 8;
4685 inst.operands[i].immisalign = 1;
4686 /* Alignments are not pre-indexes. */
4687 inst.operands[i].preind = 0;
4688 }
4689 else
4690 {
4691 if (inst.operands[i].negative)
4692 {
4693 inst.operands[i].negative = 0;
4694 p--;
4695 }
4696
4697 if (group_relocations
4698 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4699 {
4700 struct group_reloc_table_entry *entry;
4701
4702 /* Skip over the #: or : sequence. */
4703 if (*p == '#')
4704 p += 2;
4705 else
4706 p++;
4707
4708 /* Try to parse a group relocation. Anything else is an
4709 error. */
4710 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4711 {
4712 inst.error = _("unknown group relocation");
4713 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4714 }
4715
4716 /* We now have the group relocation table entry corresponding to
4717 the name in the assembler source. Next, we parse the
4718 expression. */
4719 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4720 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4721
4722 /* Record the relocation type. */
4723 switch (group_type)
4724 {
4725 case GROUP_LDR:
4726 inst.reloc.type = entry->ldr_code;
4727 break;
4728
4729 case GROUP_LDRS:
4730 inst.reloc.type = entry->ldrs_code;
4731 break;
4732
4733 case GROUP_LDC:
4734 inst.reloc.type = entry->ldc_code;
4735 break;
4736
4737 default:
4738 assert (0);
4739 }
4740
4741 if (inst.reloc.type == 0)
4742 {
4743 inst.error = _("this group relocation is not allowed on this instruction");
4744 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4745 }
4746 }
4747 else
4748 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4749 return PARSE_OPERAND_FAIL;
4750 }
4751 }
4752
4753 if (skip_past_char (&p, ']') == FAIL)
4754 {
4755 inst.error = _("']' expected");
4756 return PARSE_OPERAND_FAIL;
4757 }
4758
4759 if (skip_past_char (&p, '!') == SUCCESS)
4760 inst.operands[i].writeback = 1;
4761
4762 else if (skip_past_comma (&p) == SUCCESS)
4763 {
4764 if (skip_past_char (&p, '{') == SUCCESS)
4765 {
4766 /* [Rn], {expr} - unindexed, with option */
4767 if (parse_immediate (&p, &inst.operands[i].imm,
4768 0, 255, TRUE) == FAIL)
4769 return PARSE_OPERAND_FAIL;
4770
4771 if (skip_past_char (&p, '}') == FAIL)
4772 {
4773 inst.error = _("'}' expected at end of 'option' field");
4774 return PARSE_OPERAND_FAIL;
4775 }
4776 if (inst.operands[i].preind)
4777 {
4778 inst.error = _("cannot combine index with option");
4779 return PARSE_OPERAND_FAIL;
4780 }
4781 *str = p;
4782 return PARSE_OPERAND_SUCCESS;
4783 }
4784 else
4785 {
4786 inst.operands[i].postind = 1;
4787 inst.operands[i].writeback = 1;
4788
4789 if (inst.operands[i].preind)
4790 {
4791 inst.error = _("cannot combine pre- and post-indexing");
4792 return PARSE_OPERAND_FAIL;
4793 }
4794
4795 if (*p == '+') p++;
4796 else if (*p == '-') p++, inst.operands[i].negative = 1;
4797
4798 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4799 {
4800 /* We might be using the immediate for alignment already. If we
4801 are, OR the register number into the low-order bits. */
4802 if (inst.operands[i].immisalign)
4803 inst.operands[i].imm |= reg;
4804 else
4805 inst.operands[i].imm = reg;
4806 inst.operands[i].immisreg = 1;
4807
4808 if (skip_past_comma (&p) == SUCCESS)
4809 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4810 return PARSE_OPERAND_FAIL;
4811 }
4812 else
4813 {
4814 if (inst.operands[i].negative)
4815 {
4816 inst.operands[i].negative = 0;
4817 p--;
4818 }
4819 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4820 return PARSE_OPERAND_FAIL;
4821 }
4822 }
4823 }
4824
4825 /* If at this point neither .preind nor .postind is set, we have a
4826 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4827 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4828 {
4829 inst.operands[i].preind = 1;
4830 inst.reloc.exp.X_op = O_constant;
4831 inst.reloc.exp.X_add_number = 0;
4832 }
4833 *str = p;
4834 return PARSE_OPERAND_SUCCESS;
4835 }
4836
4837 static int
4838 parse_address (char **str, int i)
4839 {
4840 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4841 ? SUCCESS : FAIL;
4842 }
4843
4844 static parse_operand_result
4845 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4846 {
4847 return parse_address_main (str, i, 1, type);
4848 }
4849
4850 /* Parse an operand for a MOVW or MOVT instruction. */
4851 static int
4852 parse_half (char **str)
4853 {
4854 char * p;
4855
4856 p = *str;
4857 skip_past_char (&p, '#');
4858 if (strncasecmp (p, ":lower16:", 9) == 0)
4859 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4860 else if (strncasecmp (p, ":upper16:", 9) == 0)
4861 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4862
4863 if (inst.reloc.type != BFD_RELOC_UNUSED)
4864 {
4865 p += 9;
4866 skip_whitespace (p);
4867 }
4868
4869 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4870 return FAIL;
4871
4872 if (inst.reloc.type == BFD_RELOC_UNUSED)
4873 {
4874 if (inst.reloc.exp.X_op != O_constant)
4875 {
4876 inst.error = _("constant expression expected");
4877 return FAIL;
4878 }
4879 if (inst.reloc.exp.X_add_number < 0
4880 || inst.reloc.exp.X_add_number > 0xffff)
4881 {
4882 inst.error = _("immediate value out of range");
4883 return FAIL;
4884 }
4885 }
4886 *str = p;
4887 return SUCCESS;
4888 }
4889
4890 /* Miscellaneous. */
4891
4892 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4893 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4894 static int
4895 parse_psr (char **str)
4896 {
4897 char *p;
4898 unsigned long psr_field;
4899 const struct asm_psr *psr;
4900 char *start;
4901
4902 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4903 feature for ease of use and backwards compatibility. */
4904 p = *str;
4905 if (strncasecmp (p, "SPSR", 4) == 0)
4906 psr_field = SPSR_BIT;
4907 else if (strncasecmp (p, "CPSR", 4) == 0)
4908 psr_field = 0;
4909 else
4910 {
4911 start = p;
4912 do
4913 p++;
4914 while (ISALNUM (*p) || *p == '_');
4915
4916 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4917 if (!psr)
4918 return FAIL;
4919
4920 *str = p;
4921 return psr->field;
4922 }
4923
4924 p += 4;
4925 if (*p == '_')
4926 {
4927 /* A suffix follows. */
4928 p++;
4929 start = p;
4930
4931 do
4932 p++;
4933 while (ISALNUM (*p) || *p == '_');
4934
4935 psr = hash_find_n (arm_psr_hsh, start, p - start);
4936 if (!psr)
4937 goto error;
4938
4939 psr_field |= psr->field;
4940 }
4941 else
4942 {
4943 if (ISALNUM (*p))
4944 goto error; /* Garbage after "[CS]PSR". */
4945
4946 psr_field |= (PSR_c | PSR_f);
4947 }
4948 *str = p;
4949 return psr_field;
4950
4951 error:
4952 inst.error = _("flag for {c}psr instruction expected");
4953 return FAIL;
4954 }
4955
4956 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4957 value suitable for splatting into the AIF field of the instruction. */
4958
4959 static int
4960 parse_cps_flags (char **str)
4961 {
4962 int val = 0;
4963 int saw_a_flag = 0;
4964 char *s = *str;
4965
4966 for (;;)
4967 switch (*s++)
4968 {
4969 case '\0': case ',':
4970 goto done;
4971
4972 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4973 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4974 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
4975
4976 default:
4977 inst.error = _("unrecognized CPS flag");
4978 return FAIL;
4979 }
4980
4981 done:
4982 if (saw_a_flag == 0)
4983 {
4984 inst.error = _("missing CPS flags");
4985 return FAIL;
4986 }
4987
4988 *str = s - 1;
4989 return val;
4990 }
4991
4992 /* Parse an endian specifier ("BE" or "LE", case insensitive);
4993 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
4994
4995 static int
4996 parse_endian_specifier (char **str)
4997 {
4998 int little_endian;
4999 char *s = *str;
5000
5001 if (strncasecmp (s, "BE", 2))
5002 little_endian = 0;
5003 else if (strncasecmp (s, "LE", 2))
5004 little_endian = 1;
5005 else
5006 {
5007 inst.error = _("valid endian specifiers are be or le");
5008 return FAIL;
5009 }
5010
5011 if (ISALNUM (s[2]) || s[2] == '_')
5012 {
5013 inst.error = _("valid endian specifiers are be or le");
5014 return FAIL;
5015 }
5016
5017 *str = s + 2;
5018 return little_endian;
5019 }
5020
5021 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5022 value suitable for poking into the rotate field of an sxt or sxta
5023 instruction, or FAIL on error. */
5024
5025 static int
5026 parse_ror (char **str)
5027 {
5028 int rot;
5029 char *s = *str;
5030
5031 if (strncasecmp (s, "ROR", 3) == 0)
5032 s += 3;
5033 else
5034 {
5035 inst.error = _("missing rotation field after comma");
5036 return FAIL;
5037 }
5038
5039 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5040 return FAIL;
5041
5042 switch (rot)
5043 {
5044 case 0: *str = s; return 0x0;
5045 case 8: *str = s; return 0x1;
5046 case 16: *str = s; return 0x2;
5047 case 24: *str = s; return 0x3;
5048
5049 default:
5050 inst.error = _("rotation can only be 0, 8, 16, or 24");
5051 return FAIL;
5052 }
5053 }
5054
5055 /* Parse a conditional code (from conds[] below). The value returned is in the
5056 range 0 .. 14, or FAIL. */
5057 static int
5058 parse_cond (char **str)
5059 {
5060 char *q;
5061 const struct asm_cond *c;
5062 int n;
5063 /* Condition codes are always 2 characters, so matching up to
5064 3 characters is sufficient. */
5065 char cond[3];
5066
5067 q = *str;
5068 n = 0;
5069 while (ISALPHA (*q) && n < 3)
5070 {
5071 cond[n] = TOLOWER(*q);
5072 q++;
5073 n++;
5074 }
5075
5076 c = hash_find_n (arm_cond_hsh, cond, n);
5077 if (!c)
5078 {
5079 inst.error = _("condition required");
5080 return FAIL;
5081 }
5082
5083 *str = q;
5084 return c->value;
5085 }
5086
5087 /* Parse an option for a barrier instruction. Returns the encoding for the
5088 option, or FAIL. */
5089 static int
5090 parse_barrier (char **str)
5091 {
5092 char *p, *q;
5093 const struct asm_barrier_opt *o;
5094
5095 p = q = *str;
5096 while (ISALPHA (*q))
5097 q++;
5098
5099 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5100 if (!o)
5101 return FAIL;
5102
5103 *str = q;
5104 return o->value;
5105 }
5106
5107 /* Parse the operands of a table branch instruction. Similar to a memory
5108 operand. */
5109 static int
5110 parse_tb (char **str)
5111 {
5112 char * p = *str;
5113 int reg;
5114
5115 if (skip_past_char (&p, '[') == FAIL)
5116 {
5117 inst.error = _("'[' expected");
5118 return FAIL;
5119 }
5120
5121 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5122 {
5123 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5124 return FAIL;
5125 }
5126 inst.operands[0].reg = reg;
5127
5128 if (skip_past_comma (&p) == FAIL)
5129 {
5130 inst.error = _("',' expected");
5131 return FAIL;
5132 }
5133
5134 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5135 {
5136 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5137 return FAIL;
5138 }
5139 inst.operands[0].imm = reg;
5140
5141 if (skip_past_comma (&p) == SUCCESS)
5142 {
5143 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5144 return FAIL;
5145 if (inst.reloc.exp.X_add_number != 1)
5146 {
5147 inst.error = _("invalid shift");
5148 return FAIL;
5149 }
5150 inst.operands[0].shifted = 1;
5151 }
5152
5153 if (skip_past_char (&p, ']') == FAIL)
5154 {
5155 inst.error = _("']' expected");
5156 return FAIL;
5157 }
5158 *str = p;
5159 return SUCCESS;
5160 }
5161
5162 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5163 information on the types the operands can take and how they are encoded.
5164 Up to four operands may be read; this function handles setting the
5165 ".present" field for each read operand itself.
5166 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5167 else returns FAIL. */
5168
5169 static int
5170 parse_neon_mov (char **str, int *which_operand)
5171 {
5172 int i = *which_operand, val;
5173 enum arm_reg_type rtype;
5174 char *ptr = *str;
5175 struct neon_type_el optype;
5176
5177 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5178 {
5179 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5180 inst.operands[i].reg = val;
5181 inst.operands[i].isscalar = 1;
5182 inst.operands[i].vectype = optype;
5183 inst.operands[i++].present = 1;
5184
5185 if (skip_past_comma (&ptr) == FAIL)
5186 goto wanted_comma;
5187
5188 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5189 goto wanted_arm;
5190
5191 inst.operands[i].reg = val;
5192 inst.operands[i].isreg = 1;
5193 inst.operands[i].present = 1;
5194 }
5195 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5196 != FAIL)
5197 {
5198 /* Cases 0, 1, 2, 3, 5 (D only). */
5199 if (skip_past_comma (&ptr) == FAIL)
5200 goto wanted_comma;
5201
5202 inst.operands[i].reg = val;
5203 inst.operands[i].isreg = 1;
5204 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5205 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5206 inst.operands[i].isvec = 1;
5207 inst.operands[i].vectype = optype;
5208 inst.operands[i++].present = 1;
5209
5210 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5211 {
5212 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5213 Case 13: VMOV <Sd>, <Rm> */
5214 inst.operands[i].reg = val;
5215 inst.operands[i].isreg = 1;
5216 inst.operands[i].present = 1;
5217
5218 if (rtype == REG_TYPE_NQ)
5219 {
5220 first_error (_("can't use Neon quad register here"));
5221 return FAIL;
5222 }
5223 else if (rtype != REG_TYPE_VFS)
5224 {
5225 i++;
5226 if (skip_past_comma (&ptr) == FAIL)
5227 goto wanted_comma;
5228 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5229 goto wanted_arm;
5230 inst.operands[i].reg = val;
5231 inst.operands[i].isreg = 1;
5232 inst.operands[i].present = 1;
5233 }
5234 }
5235 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5236 &optype)) != FAIL)
5237 {
5238 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5239 Case 1: VMOV<c><q> <Dd>, <Dm>
5240 Case 8: VMOV.F32 <Sd>, <Sm>
5241 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5242
5243 inst.operands[i].reg = val;
5244 inst.operands[i].isreg = 1;
5245 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5246 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5247 inst.operands[i].isvec = 1;
5248 inst.operands[i].vectype = optype;
5249 inst.operands[i].present = 1;
5250
5251 if (skip_past_comma (&ptr) == SUCCESS)
5252 {
5253 /* Case 15. */
5254 i++;
5255
5256 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5257 goto wanted_arm;
5258
5259 inst.operands[i].reg = val;
5260 inst.operands[i].isreg = 1;
5261 inst.operands[i++].present = 1;
5262
5263 if (skip_past_comma (&ptr) == FAIL)
5264 goto wanted_comma;
5265
5266 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5267 goto wanted_arm;
5268
5269 inst.operands[i].reg = val;
5270 inst.operands[i].isreg = 1;
5271 inst.operands[i++].present = 1;
5272 }
5273 }
5274 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5275 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5276 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5277 Case 10: VMOV.F32 <Sd>, #<imm>
5278 Case 11: VMOV.F64 <Dd>, #<imm> */
5279 inst.operands[i].immisfloat = 1;
5280 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5281 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5282 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5283 ;
5284 else
5285 {
5286 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287 return FAIL;
5288 }
5289 }
5290 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5291 {
5292 /* Cases 6, 7. */
5293 inst.operands[i].reg = val;
5294 inst.operands[i].isreg = 1;
5295 inst.operands[i++].present = 1;
5296
5297 if (skip_past_comma (&ptr) == FAIL)
5298 goto wanted_comma;
5299
5300 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5301 {
5302 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5303 inst.operands[i].reg = val;
5304 inst.operands[i].isscalar = 1;
5305 inst.operands[i].present = 1;
5306 inst.operands[i].vectype = optype;
5307 }
5308 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5309 {
5310 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5311 inst.operands[i].reg = val;
5312 inst.operands[i].isreg = 1;
5313 inst.operands[i++].present = 1;
5314
5315 if (skip_past_comma (&ptr) == FAIL)
5316 goto wanted_comma;
5317
5318 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5319 == FAIL)
5320 {
5321 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5322 return FAIL;
5323 }
5324
5325 inst.operands[i].reg = val;
5326 inst.operands[i].isreg = 1;
5327 inst.operands[i].isvec = 1;
5328 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5329 inst.operands[i].vectype = optype;
5330 inst.operands[i].present = 1;
5331
5332 if (rtype == REG_TYPE_VFS)
5333 {
5334 /* Case 14. */
5335 i++;
5336 if (skip_past_comma (&ptr) == FAIL)
5337 goto wanted_comma;
5338 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5339 &optype)) == FAIL)
5340 {
5341 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5342 return FAIL;
5343 }
5344 inst.operands[i].reg = val;
5345 inst.operands[i].isreg = 1;
5346 inst.operands[i].isvec = 1;
5347 inst.operands[i].issingle = 1;
5348 inst.operands[i].vectype = optype;
5349 inst.operands[i].present = 1;
5350 }
5351 }
5352 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5353 != FAIL)
5354 {
5355 /* Case 13. */
5356 inst.operands[i].reg = val;
5357 inst.operands[i].isreg = 1;
5358 inst.operands[i].isvec = 1;
5359 inst.operands[i].issingle = 1;
5360 inst.operands[i].vectype = optype;
5361 inst.operands[i++].present = 1;
5362 }
5363 }
5364 else
5365 {
5366 first_error (_("parse error"));
5367 return FAIL;
5368 }
5369
5370 /* Successfully parsed the operands. Update args. */
5371 *which_operand = i;
5372 *str = ptr;
5373 return SUCCESS;
5374
5375 wanted_comma:
5376 first_error (_("expected comma"));
5377 return FAIL;
5378
5379 wanted_arm:
5380 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5381 return FAIL;
5382 }
5383
5384 /* Matcher codes for parse_operands. */
5385 enum operand_parse_code
5386 {
5387 OP_stop, /* end of line */
5388
5389 OP_RR, /* ARM register */
5390 OP_RRnpc, /* ARM register, not r15 */
5391 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5392 OP_RRw, /* ARM register, not r15, optional trailing ! */
5393 OP_RCP, /* Coprocessor number */
5394 OP_RCN, /* Coprocessor register */
5395 OP_RF, /* FPA register */
5396 OP_RVS, /* VFP single precision register */
5397 OP_RVD, /* VFP double precision register (0..15) */
5398 OP_RND, /* Neon double precision register (0..31) */
5399 OP_RNQ, /* Neon quad precision register */
5400 OP_RVSD, /* VFP single or double precision register */
5401 OP_RNDQ, /* Neon double or quad precision register */
5402 OP_RNSDQ, /* Neon single, double or quad precision register */
5403 OP_RNSC, /* Neon scalar D[X] */
5404 OP_RVC, /* VFP control register */
5405 OP_RMF, /* Maverick F register */
5406 OP_RMD, /* Maverick D register */
5407 OP_RMFX, /* Maverick FX register */
5408 OP_RMDX, /* Maverick DX register */
5409 OP_RMAX, /* Maverick AX register */
5410 OP_RMDS, /* Maverick DSPSC register */
5411 OP_RIWR, /* iWMMXt wR register */
5412 OP_RIWC, /* iWMMXt wC register */
5413 OP_RIWG, /* iWMMXt wCG register */
5414 OP_RXA, /* XScale accumulator register */
5415
5416 OP_REGLST, /* ARM register list */
5417 OP_VRSLST, /* VFP single-precision register list */
5418 OP_VRDLST, /* VFP double-precision register list */
5419 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5420 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5421 OP_NSTRLST, /* Neon element/structure list */
5422
5423 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5424 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5425 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5426 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5427 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5428 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5429 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5430 OP_VMOV, /* Neon VMOV operands. */
5431 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5432 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5433 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5434
5435 OP_I0, /* immediate zero */
5436 OP_I7, /* immediate value 0 .. 7 */
5437 OP_I15, /* 0 .. 15 */
5438 OP_I16, /* 1 .. 16 */
5439 OP_I16z, /* 0 .. 16 */
5440 OP_I31, /* 0 .. 31 */
5441 OP_I31w, /* 0 .. 31, optional trailing ! */
5442 OP_I32, /* 1 .. 32 */
5443 OP_I32z, /* 0 .. 32 */
5444 OP_I63, /* 0 .. 63 */
5445 OP_I63s, /* -64 .. 63 */
5446 OP_I64, /* 1 .. 64 */
5447 OP_I64z, /* 0 .. 64 */
5448 OP_I255, /* 0 .. 255 */
5449
5450 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5451 OP_I7b, /* 0 .. 7 */
5452 OP_I15b, /* 0 .. 15 */
5453 OP_I31b, /* 0 .. 31 */
5454
5455 OP_SH, /* shifter operand */
5456 OP_SHG, /* shifter operand with possible group relocation */
5457 OP_ADDR, /* Memory address expression (any mode) */
5458 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5459 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5460 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5461 OP_EXP, /* arbitrary expression */
5462 OP_EXPi, /* same, with optional immediate prefix */
5463 OP_EXPr, /* same, with optional relocation suffix */
5464 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5465
5466 OP_CPSF, /* CPS flags */
5467 OP_ENDI, /* Endianness specifier */
5468 OP_PSR, /* CPSR/SPSR mask for msr */
5469 OP_COND, /* conditional code */
5470 OP_TB, /* Table branch. */
5471
5472 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5473 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5474
5475 OP_RRnpc_I0, /* ARM register or literal 0 */
5476 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5477 OP_RR_EXi, /* ARM register or expression with imm prefix */
5478 OP_RF_IF, /* FPA register or immediate */
5479 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5480 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5481
5482 /* Optional operands. */
5483 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5484 OP_oI31b, /* 0 .. 31 */
5485 OP_oI32b, /* 1 .. 32 */
5486 OP_oIffffb, /* 0 .. 65535 */
5487 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5488
5489 OP_oRR, /* ARM register */
5490 OP_oRRnpc, /* ARM register, not the PC */
5491 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5492 OP_oRND, /* Optional Neon double precision register */
5493 OP_oRNQ, /* Optional Neon quad precision register */
5494 OP_oRNDQ, /* Optional Neon double or quad precision register */
5495 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5496 OP_oSHll, /* LSL immediate */
5497 OP_oSHar, /* ASR immediate */
5498 OP_oSHllar, /* LSL or ASR immediate */
5499 OP_oROR, /* ROR 0/8/16/24 */
5500 OP_oBARRIER, /* Option argument for a barrier instruction. */
5501
5502 OP_FIRST_OPTIONAL = OP_oI7b
5503 };
5504
5505 /* Generic instruction operand parser. This does no encoding and no
5506 semantic validation; it merely squirrels values away in the inst
5507 structure. Returns SUCCESS or FAIL depending on whether the
5508 specified grammar matched. */
5509 static int
5510 parse_operands (char *str, const unsigned char *pattern)
5511 {
5512 unsigned const char *upat = pattern;
5513 char *backtrack_pos = 0;
5514 const char *backtrack_error = 0;
5515 int i, val, backtrack_index = 0;
5516 enum arm_reg_type rtype;
5517 parse_operand_result result;
5518
5519 #define po_char_or_fail(chr) do { \
5520 if (skip_past_char (&str, chr) == FAIL) \
5521 goto bad_args; \
5522 } while (0)
5523
5524 #define po_reg_or_fail(regtype) do { \
5525 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5526 &inst.operands[i].vectype); \
5527 if (val == FAIL) \
5528 { \
5529 first_error (_(reg_expected_msgs[regtype])); \
5530 goto failure; \
5531 } \
5532 inst.operands[i].reg = val; \
5533 inst.operands[i].isreg = 1; \
5534 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5535 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5536 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5537 || rtype == REG_TYPE_VFD \
5538 || rtype == REG_TYPE_NQ); \
5539 } while (0)
5540
5541 #define po_reg_or_goto(regtype, label) do { \
5542 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5543 &inst.operands[i].vectype); \
5544 if (val == FAIL) \
5545 goto label; \
5546 \
5547 inst.operands[i].reg = val; \
5548 inst.operands[i].isreg = 1; \
5549 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5550 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5551 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5552 || rtype == REG_TYPE_VFD \
5553 || rtype == REG_TYPE_NQ); \
5554 } while (0)
5555
5556 #define po_imm_or_fail(min, max, popt) do { \
5557 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5558 goto failure; \
5559 inst.operands[i].imm = val; \
5560 } while (0)
5561
5562 #define po_scalar_or_goto(elsz, label) do { \
5563 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5564 if (val == FAIL) \
5565 goto label; \
5566 inst.operands[i].reg = val; \
5567 inst.operands[i].isscalar = 1; \
5568 } while (0)
5569
5570 #define po_misc_or_fail(expr) do { \
5571 if (expr) \
5572 goto failure; \
5573 } while (0)
5574
5575 #define po_misc_or_fail_no_backtrack(expr) do { \
5576 result = expr; \
5577 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5578 backtrack_pos = 0; \
5579 if (result != PARSE_OPERAND_SUCCESS) \
5580 goto failure; \
5581 } while (0)
5582
5583 skip_whitespace (str);
5584
5585 for (i = 0; upat[i] != OP_stop; i++)
5586 {
5587 if (upat[i] >= OP_FIRST_OPTIONAL)
5588 {
5589 /* Remember where we are in case we need to backtrack. */
5590 assert (!backtrack_pos);
5591 backtrack_pos = str;
5592 backtrack_error = inst.error;
5593 backtrack_index = i;
5594 }
5595
5596 if (i > 0 && (i > 1 || inst.operands[0].present))
5597 po_char_or_fail (',');
5598
5599 switch (upat[i])
5600 {
5601 /* Registers */
5602 case OP_oRRnpc:
5603 case OP_RRnpc:
5604 case OP_oRR:
5605 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5606 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5607 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5608 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5609 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5610 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5611 case OP_oRND:
5612 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
5613 case OP_RVC:
5614 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5615 break;
5616 /* Also accept generic coprocessor regs for unknown registers. */
5617 coproc_reg:
5618 po_reg_or_fail (REG_TYPE_CN);
5619 break;
5620 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5621 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5622 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5623 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5624 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5625 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5626 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5627 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5628 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5629 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5630 case OP_oRNQ:
5631 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5632 case OP_oRNDQ:
5633 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
5634 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5635 case OP_oRNSDQ:
5636 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5637
5638 /* Neon scalar. Using an element size of 8 means that some invalid
5639 scalars are accepted here, so deal with those in later code. */
5640 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5641
5642 /* WARNING: We can expand to two operands here. This has the potential
5643 to totally confuse the backtracking mechanism! It will be OK at
5644 least as long as we don't try to use optional args as well,
5645 though. */
5646 case OP_NILO:
5647 {
5648 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5649 inst.operands[i].present = 1;
5650 i++;
5651 skip_past_comma (&str);
5652 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5653 break;
5654 one_reg_only:
5655 /* Optional register operand was omitted. Unfortunately, it's in
5656 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5657 here (this is a bit grotty). */
5658 inst.operands[i] = inst.operands[i-1];
5659 inst.operands[i-1].present = 0;
5660 break;
5661 try_imm:
5662 /* There's a possibility of getting a 64-bit immediate here, so
5663 we need special handling. */
5664 if (parse_big_immediate (&str, i) == FAIL)
5665 {
5666 inst.error = _("immediate value is out of range");
5667 goto failure;
5668 }
5669 }
5670 break;
5671
5672 case OP_RNDQ_I0:
5673 {
5674 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5675 break;
5676 try_imm0:
5677 po_imm_or_fail (0, 0, TRUE);
5678 }
5679 break;
5680
5681 case OP_RVSD_I0:
5682 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5683 break;
5684
5685 case OP_RR_RNSC:
5686 {
5687 po_scalar_or_goto (8, try_rr);
5688 break;
5689 try_rr:
5690 po_reg_or_fail (REG_TYPE_RN);
5691 }
5692 break;
5693
5694 case OP_RNSDQ_RNSC:
5695 {
5696 po_scalar_or_goto (8, try_nsdq);
5697 break;
5698 try_nsdq:
5699 po_reg_or_fail (REG_TYPE_NSDQ);
5700 }
5701 break;
5702
5703 case OP_RNDQ_RNSC:
5704 {
5705 po_scalar_or_goto (8, try_ndq);
5706 break;
5707 try_ndq:
5708 po_reg_or_fail (REG_TYPE_NDQ);
5709 }
5710 break;
5711
5712 case OP_RND_RNSC:
5713 {
5714 po_scalar_or_goto (8, try_vfd);
5715 break;
5716 try_vfd:
5717 po_reg_or_fail (REG_TYPE_VFD);
5718 }
5719 break;
5720
5721 case OP_VMOV:
5722 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5723 not careful then bad things might happen. */
5724 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5725 break;
5726
5727 case OP_RNDQ_IMVNb:
5728 {
5729 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5730 break;
5731 try_mvnimm:
5732 /* There's a possibility of getting a 64-bit immediate here, so
5733 we need special handling. */
5734 if (parse_big_immediate (&str, i) == FAIL)
5735 {
5736 inst.error = _("immediate value is out of range");
5737 goto failure;
5738 }
5739 }
5740 break;
5741
5742 case OP_RNDQ_I63b:
5743 {
5744 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5745 break;
5746 try_shimm:
5747 po_imm_or_fail (0, 63, TRUE);
5748 }
5749 break;
5750
5751 case OP_RRnpcb:
5752 po_char_or_fail ('[');
5753 po_reg_or_fail (REG_TYPE_RN);
5754 po_char_or_fail (']');
5755 break;
5756
5757 case OP_RRw:
5758 case OP_oRRw:
5759 po_reg_or_fail (REG_TYPE_RN);
5760 if (skip_past_char (&str, '!') == SUCCESS)
5761 inst.operands[i].writeback = 1;
5762 break;
5763
5764 /* Immediates */
5765 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5766 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5767 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5768 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5769 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5770 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5771 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5772 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5773 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5774 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5775 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
5776 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
5777
5778 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5779 case OP_oI7b:
5780 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5781 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5782 case OP_oI31b:
5783 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5784 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5785 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5786
5787 /* Immediate variants */
5788 case OP_oI255c:
5789 po_char_or_fail ('{');
5790 po_imm_or_fail (0, 255, TRUE);
5791 po_char_or_fail ('}');
5792 break;
5793
5794 case OP_I31w:
5795 /* The expression parser chokes on a trailing !, so we have
5796 to find it first and zap it. */
5797 {
5798 char *s = str;
5799 while (*s && *s != ',')
5800 s++;
5801 if (s[-1] == '!')
5802 {
5803 s[-1] = '\0';
5804 inst.operands[i].writeback = 1;
5805 }
5806 po_imm_or_fail (0, 31, TRUE);
5807 if (str == s - 1)
5808 str = s;
5809 }
5810 break;
5811
5812 /* Expressions */
5813 case OP_EXPi: EXPi:
5814 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5815 GE_OPT_PREFIX));
5816 break;
5817
5818 case OP_EXP:
5819 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5820 GE_NO_PREFIX));
5821 break;
5822
5823 case OP_EXPr: EXPr:
5824 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5825 GE_NO_PREFIX));
5826 if (inst.reloc.exp.X_op == O_symbol)
5827 {
5828 val = parse_reloc (&str);
5829 if (val == -1)
5830 {
5831 inst.error = _("unrecognized relocation suffix");
5832 goto failure;
5833 }
5834 else if (val != BFD_RELOC_UNUSED)
5835 {
5836 inst.operands[i].imm = val;
5837 inst.operands[i].hasreloc = 1;
5838 }
5839 }
5840 break;
5841
5842 /* Operand for MOVW or MOVT. */
5843 case OP_HALF:
5844 po_misc_or_fail (parse_half (&str));
5845 break;
5846
5847 /* Register or expression */
5848 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5849 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
5850
5851 /* Register or immediate */
5852 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5853 I0: po_imm_or_fail (0, 0, FALSE); break;
5854
5855 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5856 IF:
5857 if (!is_immediate_prefix (*str))
5858 goto bad_args;
5859 str++;
5860 val = parse_fpa_immediate (&str);
5861 if (val == FAIL)
5862 goto failure;
5863 /* FPA immediates are encoded as registers 8-15.
5864 parse_fpa_immediate has already applied the offset. */
5865 inst.operands[i].reg = val;
5866 inst.operands[i].isreg = 1;
5867 break;
5868
5869 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5870 I32z: po_imm_or_fail (0, 32, FALSE); break;
5871
5872 /* Two kinds of register */
5873 case OP_RIWR_RIWC:
5874 {
5875 struct reg_entry *rege = arm_reg_parse_multi (&str);
5876 if (!rege
5877 || (rege->type != REG_TYPE_MMXWR
5878 && rege->type != REG_TYPE_MMXWC
5879 && rege->type != REG_TYPE_MMXWCG))
5880 {
5881 inst.error = _("iWMMXt data or control register expected");
5882 goto failure;
5883 }
5884 inst.operands[i].reg = rege->number;
5885 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5886 }
5887 break;
5888
5889 case OP_RIWC_RIWG:
5890 {
5891 struct reg_entry *rege = arm_reg_parse_multi (&str);
5892 if (!rege
5893 || (rege->type != REG_TYPE_MMXWC
5894 && rege->type != REG_TYPE_MMXWCG))
5895 {
5896 inst.error = _("iWMMXt control register expected");
5897 goto failure;
5898 }
5899 inst.operands[i].reg = rege->number;
5900 inst.operands[i].isreg = 1;
5901 }
5902 break;
5903
5904 /* Misc */
5905 case OP_CPSF: val = parse_cps_flags (&str); break;
5906 case OP_ENDI: val = parse_endian_specifier (&str); break;
5907 case OP_oROR: val = parse_ror (&str); break;
5908 case OP_PSR: val = parse_psr (&str); break;
5909 case OP_COND: val = parse_cond (&str); break;
5910 case OP_oBARRIER:val = parse_barrier (&str); break;
5911
5912 case OP_RVC_PSR:
5913 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5914 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5915 break;
5916 try_psr:
5917 val = parse_psr (&str);
5918 break;
5919
5920 case OP_APSR_RR:
5921 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5922 break;
5923 try_apsr:
5924 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5925 instruction). */
5926 if (strncasecmp (str, "APSR_", 5) == 0)
5927 {
5928 unsigned found = 0;
5929 str += 5;
5930 while (found < 15)
5931 switch (*str++)
5932 {
5933 case 'c': found = (found & 1) ? 16 : found | 1; break;
5934 case 'n': found = (found & 2) ? 16 : found | 2; break;
5935 case 'z': found = (found & 4) ? 16 : found | 4; break;
5936 case 'v': found = (found & 8) ? 16 : found | 8; break;
5937 default: found = 16;
5938 }
5939 if (found != 15)
5940 goto failure;
5941 inst.operands[i].isvec = 1;
5942 }
5943 else
5944 goto failure;
5945 break;
5946
5947 case OP_TB:
5948 po_misc_or_fail (parse_tb (&str));
5949 break;
5950
5951 /* Register lists */
5952 case OP_REGLST:
5953 val = parse_reg_list (&str);
5954 if (*str == '^')
5955 {
5956 inst.operands[1].writeback = 1;
5957 str++;
5958 }
5959 break;
5960
5961 case OP_VRSLST:
5962 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
5963 break;
5964
5965 case OP_VRDLST:
5966 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
5967 break;
5968
5969 case OP_VRSDLST:
5970 /* Allow Q registers too. */
5971 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5972 REGLIST_NEON_D);
5973 if (val == FAIL)
5974 {
5975 inst.error = NULL;
5976 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5977 REGLIST_VFP_S);
5978 inst.operands[i].issingle = 1;
5979 }
5980 break;
5981
5982 case OP_NRDLST:
5983 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5984 REGLIST_NEON_D);
5985 break;
5986
5987 case OP_NSTRLST:
5988 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5989 &inst.operands[i].vectype);
5990 break;
5991
5992 /* Addressing modes */
5993 case OP_ADDR:
5994 po_misc_or_fail (parse_address (&str, i));
5995 break;
5996
5997 case OP_ADDRGLDR:
5998 po_misc_or_fail_no_backtrack (
5999 parse_address_group_reloc (&str, i, GROUP_LDR));
6000 break;
6001
6002 case OP_ADDRGLDRS:
6003 po_misc_or_fail_no_backtrack (
6004 parse_address_group_reloc (&str, i, GROUP_LDRS));
6005 break;
6006
6007 case OP_ADDRGLDC:
6008 po_misc_or_fail_no_backtrack (
6009 parse_address_group_reloc (&str, i, GROUP_LDC));
6010 break;
6011
6012 case OP_SH:
6013 po_misc_or_fail (parse_shifter_operand (&str, i));
6014 break;
6015
6016 case OP_SHG:
6017 po_misc_or_fail_no_backtrack (
6018 parse_shifter_operand_group_reloc (&str, i));
6019 break;
6020
6021 case OP_oSHll:
6022 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6023 break;
6024
6025 case OP_oSHar:
6026 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6027 break;
6028
6029 case OP_oSHllar:
6030 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6031 break;
6032
6033 default:
6034 as_fatal (_("unhandled operand code %d"), upat[i]);
6035 }
6036
6037 /* Various value-based sanity checks and shared operations. We
6038 do not signal immediate failures for the register constraints;
6039 this allows a syntax error to take precedence. */
6040 switch (upat[i])
6041 {
6042 case OP_oRRnpc:
6043 case OP_RRnpc:
6044 case OP_RRnpcb:
6045 case OP_RRw:
6046 case OP_oRRw:
6047 case OP_RRnpc_I0:
6048 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6049 inst.error = BAD_PC;
6050 break;
6051
6052 case OP_CPSF:
6053 case OP_ENDI:
6054 case OP_oROR:
6055 case OP_PSR:
6056 case OP_RVC_PSR:
6057 case OP_COND:
6058 case OP_oBARRIER:
6059 case OP_REGLST:
6060 case OP_VRSLST:
6061 case OP_VRDLST:
6062 case OP_VRSDLST:
6063 case OP_NRDLST:
6064 case OP_NSTRLST:
6065 if (val == FAIL)
6066 goto failure;
6067 inst.operands[i].imm = val;
6068 break;
6069
6070 default:
6071 break;
6072 }
6073
6074 /* If we get here, this operand was successfully parsed. */
6075 inst.operands[i].present = 1;
6076 continue;
6077
6078 bad_args:
6079 inst.error = BAD_ARGS;
6080
6081 failure:
6082 if (!backtrack_pos)
6083 {
6084 /* The parse routine should already have set inst.error, but set a
6085 default here just in case. */
6086 if (!inst.error)
6087 inst.error = _("syntax error");
6088 return FAIL;
6089 }
6090
6091 /* Do not backtrack over a trailing optional argument that
6092 absorbed some text. We will only fail again, with the
6093 'garbage following instruction' error message, which is
6094 probably less helpful than the current one. */
6095 if (backtrack_index == i && backtrack_pos != str
6096 && upat[i+1] == OP_stop)
6097 {
6098 if (!inst.error)
6099 inst.error = _("syntax error");
6100 return FAIL;
6101 }
6102
6103 /* Try again, skipping the optional argument at backtrack_pos. */
6104 str = backtrack_pos;
6105 inst.error = backtrack_error;
6106 inst.operands[backtrack_index].present = 0;
6107 i = backtrack_index;
6108 backtrack_pos = 0;
6109 }
6110
6111 /* Check that we have parsed all the arguments. */
6112 if (*str != '\0' && !inst.error)
6113 inst.error = _("garbage following instruction");
6114
6115 return inst.error ? FAIL : SUCCESS;
6116 }
6117
6118 #undef po_char_or_fail
6119 #undef po_reg_or_fail
6120 #undef po_reg_or_goto
6121 #undef po_imm_or_fail
6122 #undef po_scalar_or_fail
6123 \f
6124 /* Shorthand macro for instruction encoding functions issuing errors. */
6125 #define constraint(expr, err) do { \
6126 if (expr) \
6127 { \
6128 inst.error = err; \
6129 return; \
6130 } \
6131 } while (0)
6132
6133 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6134 instructions are unpredictable if these registers are used. This
6135 is the BadReg predicate in ARM's Thumb-2 documentation. */
6136 #define reject_bad_reg(reg) \
6137 do \
6138 if (reg == REG_SP || reg == REG_PC) \
6139 { \
6140 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6141 return; \
6142 } \
6143 while (0)
6144
6145 /* If REG is R13 (the stack pointer), warn that its use is
6146 deprecated. */
6147 #define warn_deprecated_sp(reg) \
6148 do \
6149 if (warn_on_deprecated && reg == REG_SP) \
6150 as_warn (_("use of r13 is deprecated")); \
6151 while (0)
6152
6153 /* Functions for operand encoding. ARM, then Thumb. */
6154
6155 #define rotate_left(v, n) (v << n | v >> (32 - n))
6156
6157 /* If VAL can be encoded in the immediate field of an ARM instruction,
6158 return the encoded form. Otherwise, return FAIL. */
6159
6160 static unsigned int
6161 encode_arm_immediate (unsigned int val)
6162 {
6163 unsigned int a, i;
6164
6165 for (i = 0; i < 32; i += 2)
6166 if ((a = rotate_left (val, i)) <= 0xff)
6167 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6168
6169 return FAIL;
6170 }
6171
6172 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6173 return the encoded form. Otherwise, return FAIL. */
6174 static unsigned int
6175 encode_thumb32_immediate (unsigned int val)
6176 {
6177 unsigned int a, i;
6178
6179 if (val <= 0xff)
6180 return val;
6181
6182 for (i = 1; i <= 24; i++)
6183 {
6184 a = val >> i;
6185 if ((val & ~(0xff << i)) == 0)
6186 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6187 }
6188
6189 a = val & 0xff;
6190 if (val == ((a << 16) | a))
6191 return 0x100 | a;
6192 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6193 return 0x300 | a;
6194
6195 a = val & 0xff00;
6196 if (val == ((a << 16) | a))
6197 return 0x200 | (a >> 8);
6198
6199 return FAIL;
6200 }
6201 /* Encode a VFP SP or DP register number into inst.instruction. */
6202
6203 static void
6204 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6205 {
6206 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6207 && reg > 15)
6208 {
6209 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6210 {
6211 if (thumb_mode)
6212 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6213 fpu_vfp_ext_d32);
6214 else
6215 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6216 fpu_vfp_ext_d32);
6217 }
6218 else
6219 {
6220 first_error (_("D register out of range for selected VFP version"));
6221 return;
6222 }
6223 }
6224
6225 switch (pos)
6226 {
6227 case VFP_REG_Sd:
6228 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6229 break;
6230
6231 case VFP_REG_Sn:
6232 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6233 break;
6234
6235 case VFP_REG_Sm:
6236 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6237 break;
6238
6239 case VFP_REG_Dd:
6240 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6241 break;
6242
6243 case VFP_REG_Dn:
6244 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6245 break;
6246
6247 case VFP_REG_Dm:
6248 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6249 break;
6250
6251 default:
6252 abort ();
6253 }
6254 }
6255
6256 /* Encode a <shift> in an ARM-format instruction. The immediate,
6257 if any, is handled by md_apply_fix. */
6258 static void
6259 encode_arm_shift (int i)
6260 {
6261 if (inst.operands[i].shift_kind == SHIFT_RRX)
6262 inst.instruction |= SHIFT_ROR << 5;
6263 else
6264 {
6265 inst.instruction |= inst.operands[i].shift_kind << 5;
6266 if (inst.operands[i].immisreg)
6267 {
6268 inst.instruction |= SHIFT_BY_REG;
6269 inst.instruction |= inst.operands[i].imm << 8;
6270 }
6271 else
6272 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6273 }
6274 }
6275
6276 static void
6277 encode_arm_shifter_operand (int i)
6278 {
6279 if (inst.operands[i].isreg)
6280 {
6281 inst.instruction |= inst.operands[i].reg;
6282 encode_arm_shift (i);
6283 }
6284 else
6285 inst.instruction |= INST_IMMEDIATE;
6286 }
6287
6288 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6289 static void
6290 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6291 {
6292 assert (inst.operands[i].isreg);
6293 inst.instruction |= inst.operands[i].reg << 16;
6294
6295 if (inst.operands[i].preind)
6296 {
6297 if (is_t)
6298 {
6299 inst.error = _("instruction does not accept preindexed addressing");
6300 return;
6301 }
6302 inst.instruction |= PRE_INDEX;
6303 if (inst.operands[i].writeback)
6304 inst.instruction |= WRITE_BACK;
6305
6306 }
6307 else if (inst.operands[i].postind)
6308 {
6309 assert (inst.operands[i].writeback);
6310 if (is_t)
6311 inst.instruction |= WRITE_BACK;
6312 }
6313 else /* unindexed - only for coprocessor */
6314 {
6315 inst.error = _("instruction does not accept unindexed addressing");
6316 return;
6317 }
6318
6319 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6320 && (((inst.instruction & 0x000f0000) >> 16)
6321 == ((inst.instruction & 0x0000f000) >> 12)))
6322 as_warn ((inst.instruction & LOAD_BIT)
6323 ? _("destination register same as write-back base")
6324 : _("source register same as write-back base"));
6325 }
6326
6327 /* inst.operands[i] was set up by parse_address. Encode it into an
6328 ARM-format mode 2 load or store instruction. If is_t is true,
6329 reject forms that cannot be used with a T instruction (i.e. not
6330 post-indexed). */
6331 static void
6332 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6333 {
6334 encode_arm_addr_mode_common (i, is_t);
6335
6336 if (inst.operands[i].immisreg)
6337 {
6338 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6339 inst.instruction |= inst.operands[i].imm;
6340 if (!inst.operands[i].negative)
6341 inst.instruction |= INDEX_UP;
6342 if (inst.operands[i].shifted)
6343 {
6344 if (inst.operands[i].shift_kind == SHIFT_RRX)
6345 inst.instruction |= SHIFT_ROR << 5;
6346 else
6347 {
6348 inst.instruction |= inst.operands[i].shift_kind << 5;
6349 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6350 }
6351 }
6352 }
6353 else /* immediate offset in inst.reloc */
6354 {
6355 if (inst.reloc.type == BFD_RELOC_UNUSED)
6356 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6357 }
6358 }
6359
6360 /* inst.operands[i] was set up by parse_address. Encode it into an
6361 ARM-format mode 3 load or store instruction. Reject forms that
6362 cannot be used with such instructions. If is_t is true, reject
6363 forms that cannot be used with a T instruction (i.e. not
6364 post-indexed). */
6365 static void
6366 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6367 {
6368 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6369 {
6370 inst.error = _("instruction does not accept scaled register index");
6371 return;
6372 }
6373
6374 encode_arm_addr_mode_common (i, is_t);
6375
6376 if (inst.operands[i].immisreg)
6377 {
6378 inst.instruction |= inst.operands[i].imm;
6379 if (!inst.operands[i].negative)
6380 inst.instruction |= INDEX_UP;
6381 }
6382 else /* immediate offset in inst.reloc */
6383 {
6384 inst.instruction |= HWOFFSET_IMM;
6385 if (inst.reloc.type == BFD_RELOC_UNUSED)
6386 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6387 }
6388 }
6389
6390 /* inst.operands[i] was set up by parse_address. Encode it into an
6391 ARM-format instruction. Reject all forms which cannot be encoded
6392 into a coprocessor load/store instruction. If wb_ok is false,
6393 reject use of writeback; if unind_ok is false, reject use of
6394 unindexed addressing. If reloc_override is not 0, use it instead
6395 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6396 (in which case it is preserved). */
6397
6398 static int
6399 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6400 {
6401 inst.instruction |= inst.operands[i].reg << 16;
6402
6403 assert (!(inst.operands[i].preind && inst.operands[i].postind));
6404
6405 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6406 {
6407 assert (!inst.operands[i].writeback);
6408 if (!unind_ok)
6409 {
6410 inst.error = _("instruction does not support unindexed addressing");
6411 return FAIL;
6412 }
6413 inst.instruction |= inst.operands[i].imm;
6414 inst.instruction |= INDEX_UP;
6415 return SUCCESS;
6416 }
6417
6418 if (inst.operands[i].preind)
6419 inst.instruction |= PRE_INDEX;
6420
6421 if (inst.operands[i].writeback)
6422 {
6423 if (inst.operands[i].reg == REG_PC)
6424 {
6425 inst.error = _("pc may not be used with write-back");
6426 return FAIL;
6427 }
6428 if (!wb_ok)
6429 {
6430 inst.error = _("instruction does not support writeback");
6431 return FAIL;
6432 }
6433 inst.instruction |= WRITE_BACK;
6434 }
6435
6436 if (reloc_override)
6437 inst.reloc.type = reloc_override;
6438 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6439 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6440 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6441 {
6442 if (thumb_mode)
6443 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6444 else
6445 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6446 }
6447
6448 return SUCCESS;
6449 }
6450
6451 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6452 Determine whether it can be performed with a move instruction; if
6453 it can, convert inst.instruction to that move instruction and
6454 return 1; if it can't, convert inst.instruction to a literal-pool
6455 load and return 0. If this is not a valid thing to do in the
6456 current context, set inst.error and return 1.
6457
6458 inst.operands[i] describes the destination register. */
6459
6460 static int
6461 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6462 {
6463 unsigned long tbit;
6464
6465 if (thumb_p)
6466 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6467 else
6468 tbit = LOAD_BIT;
6469
6470 if ((inst.instruction & tbit) == 0)
6471 {
6472 inst.error = _("invalid pseudo operation");
6473 return 1;
6474 }
6475 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6476 {
6477 inst.error = _("constant expression expected");
6478 return 1;
6479 }
6480 if (inst.reloc.exp.X_op == O_constant)
6481 {
6482 if (thumb_p)
6483 {
6484 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6485 {
6486 /* This can be done with a mov(1) instruction. */
6487 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6488 inst.instruction |= inst.reloc.exp.X_add_number;
6489 return 1;
6490 }
6491 }
6492 else
6493 {
6494 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6495 if (value != FAIL)
6496 {
6497 /* This can be done with a mov instruction. */
6498 inst.instruction &= LITERAL_MASK;
6499 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6500 inst.instruction |= value & 0xfff;
6501 return 1;
6502 }
6503
6504 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6505 if (value != FAIL)
6506 {
6507 /* This can be done with a mvn instruction. */
6508 inst.instruction &= LITERAL_MASK;
6509 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6510 inst.instruction |= value & 0xfff;
6511 return 1;
6512 }
6513 }
6514 }
6515
6516 if (add_to_lit_pool () == FAIL)
6517 {
6518 inst.error = _("literal pool insertion failed");
6519 return 1;
6520 }
6521 inst.operands[1].reg = REG_PC;
6522 inst.operands[1].isreg = 1;
6523 inst.operands[1].preind = 1;
6524 inst.reloc.pc_rel = 1;
6525 inst.reloc.type = (thumb_p
6526 ? BFD_RELOC_ARM_THUMB_OFFSET
6527 : (mode_3
6528 ? BFD_RELOC_ARM_HWLITERAL
6529 : BFD_RELOC_ARM_LITERAL));
6530 return 0;
6531 }
6532
6533 /* Functions for instruction encoding, sorted by sub-architecture.
6534 First some generics; their names are taken from the conventional
6535 bit positions for register arguments in ARM format instructions. */
6536
6537 static void
6538 do_noargs (void)
6539 {
6540 }
6541
6542 static void
6543 do_rd (void)
6544 {
6545 inst.instruction |= inst.operands[0].reg << 12;
6546 }
6547
6548 static void
6549 do_rd_rm (void)
6550 {
6551 inst.instruction |= inst.operands[0].reg << 12;
6552 inst.instruction |= inst.operands[1].reg;
6553 }
6554
6555 static void
6556 do_rd_rn (void)
6557 {
6558 inst.instruction |= inst.operands[0].reg << 12;
6559 inst.instruction |= inst.operands[1].reg << 16;
6560 }
6561
6562 static void
6563 do_rn_rd (void)
6564 {
6565 inst.instruction |= inst.operands[0].reg << 16;
6566 inst.instruction |= inst.operands[1].reg << 12;
6567 }
6568
6569 static void
6570 do_rd_rm_rn (void)
6571 {
6572 unsigned Rn = inst.operands[2].reg;
6573 /* Enforce restrictions on SWP instruction. */
6574 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6575 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6576 _("Rn must not overlap other operands"));
6577 inst.instruction |= inst.operands[0].reg << 12;
6578 inst.instruction |= inst.operands[1].reg;
6579 inst.instruction |= Rn << 16;
6580 }
6581
6582 static void
6583 do_rd_rn_rm (void)
6584 {
6585 inst.instruction |= inst.operands[0].reg << 12;
6586 inst.instruction |= inst.operands[1].reg << 16;
6587 inst.instruction |= inst.operands[2].reg;
6588 }
6589
6590 static void
6591 do_rm_rd_rn (void)
6592 {
6593 inst.instruction |= inst.operands[0].reg;
6594 inst.instruction |= inst.operands[1].reg << 12;
6595 inst.instruction |= inst.operands[2].reg << 16;
6596 }
6597
6598 static void
6599 do_imm0 (void)
6600 {
6601 inst.instruction |= inst.operands[0].imm;
6602 }
6603
6604 static void
6605 do_rd_cpaddr (void)
6606 {
6607 inst.instruction |= inst.operands[0].reg << 12;
6608 encode_arm_cp_address (1, TRUE, TRUE, 0);
6609 }
6610
6611 /* ARM instructions, in alphabetical order by function name (except
6612 that wrapper functions appear immediately after the function they
6613 wrap). */
6614
6615 /* This is a pseudo-op of the form "adr rd, label" to be converted
6616 into a relative address of the form "add rd, pc, #label-.-8". */
6617
6618 static void
6619 do_adr (void)
6620 {
6621 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6622
6623 /* Frag hacking will turn this into a sub instruction if the offset turns
6624 out to be negative. */
6625 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
6626 inst.reloc.pc_rel = 1;
6627 inst.reloc.exp.X_add_number -= 8;
6628 }
6629
6630 /* This is a pseudo-op of the form "adrl rd, label" to be converted
6631 into a relative address of the form:
6632 add rd, pc, #low(label-.-8)"
6633 add rd, rd, #high(label-.-8)" */
6634
6635 static void
6636 do_adrl (void)
6637 {
6638 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
6639
6640 /* Frag hacking will turn this into a sub instruction if the offset turns
6641 out to be negative. */
6642 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
6643 inst.reloc.pc_rel = 1;
6644 inst.size = INSN_SIZE * 2;
6645 inst.reloc.exp.X_add_number -= 8;
6646 }
6647
6648 static void
6649 do_arit (void)
6650 {
6651 if (!inst.operands[1].present)
6652 inst.operands[1].reg = inst.operands[0].reg;
6653 inst.instruction |= inst.operands[0].reg << 12;
6654 inst.instruction |= inst.operands[1].reg << 16;
6655 encode_arm_shifter_operand (2);
6656 }
6657
6658 static void
6659 do_barrier (void)
6660 {
6661 if (inst.operands[0].present)
6662 {
6663 constraint ((inst.instruction & 0xf0) != 0x40
6664 && inst.operands[0].imm != 0xf,
6665 _("bad barrier type"));
6666 inst.instruction |= inst.operands[0].imm;
6667 }
6668 else
6669 inst.instruction |= 0xf;
6670 }
6671
6672 static void
6673 do_bfc (void)
6674 {
6675 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6676 constraint (msb > 32, _("bit-field extends past end of register"));
6677 /* The instruction encoding stores the LSB and MSB,
6678 not the LSB and width. */
6679 inst.instruction |= inst.operands[0].reg << 12;
6680 inst.instruction |= inst.operands[1].imm << 7;
6681 inst.instruction |= (msb - 1) << 16;
6682 }
6683
6684 static void
6685 do_bfi (void)
6686 {
6687 unsigned int msb;
6688
6689 /* #0 in second position is alternative syntax for bfc, which is
6690 the same instruction but with REG_PC in the Rm field. */
6691 if (!inst.operands[1].isreg)
6692 inst.operands[1].reg = REG_PC;
6693
6694 msb = inst.operands[2].imm + inst.operands[3].imm;
6695 constraint (msb > 32, _("bit-field extends past end of register"));
6696 /* The instruction encoding stores the LSB and MSB,
6697 not the LSB and width. */
6698 inst.instruction |= inst.operands[0].reg << 12;
6699 inst.instruction |= inst.operands[1].reg;
6700 inst.instruction |= inst.operands[2].imm << 7;
6701 inst.instruction |= (msb - 1) << 16;
6702 }
6703
6704 static void
6705 do_bfx (void)
6706 {
6707 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6708 _("bit-field extends past end of register"));
6709 inst.instruction |= inst.operands[0].reg << 12;
6710 inst.instruction |= inst.operands[1].reg;
6711 inst.instruction |= inst.operands[2].imm << 7;
6712 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6713 }
6714
6715 /* ARM V5 breakpoint instruction (argument parse)
6716 BKPT <16 bit unsigned immediate>
6717 Instruction is not conditional.
6718 The bit pattern given in insns[] has the COND_ALWAYS condition,
6719 and it is an error if the caller tried to override that. */
6720
6721 static void
6722 do_bkpt (void)
6723 {
6724 /* Top 12 of 16 bits to bits 19:8. */
6725 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6726
6727 /* Bottom 4 of 16 bits to bits 3:0. */
6728 inst.instruction |= inst.operands[0].imm & 0xf;
6729 }
6730
6731 static void
6732 encode_branch (int default_reloc)
6733 {
6734 if (inst.operands[0].hasreloc)
6735 {
6736 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6737 _("the only suffix valid here is '(plt)'"));
6738 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6739 }
6740 else
6741 {
6742 inst.reloc.type = default_reloc;
6743 }
6744 inst.reloc.pc_rel = 1;
6745 }
6746
6747 static void
6748 do_branch (void)
6749 {
6750 #ifdef OBJ_ELF
6751 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6752 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6753 else
6754 #endif
6755 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6756 }
6757
6758 static void
6759 do_bl (void)
6760 {
6761 #ifdef OBJ_ELF
6762 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6763 {
6764 if (inst.cond == COND_ALWAYS)
6765 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6766 else
6767 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6768 }
6769 else
6770 #endif
6771 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6772 }
6773
6774 /* ARM V5 branch-link-exchange instruction (argument parse)
6775 BLX <target_addr> ie BLX(1)
6776 BLX{<condition>} <Rm> ie BLX(2)
6777 Unfortunately, there are two different opcodes for this mnemonic.
6778 So, the insns[].value is not used, and the code here zaps values
6779 into inst.instruction.
6780 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
6781
6782 static void
6783 do_blx (void)
6784 {
6785 if (inst.operands[0].isreg)
6786 {
6787 /* Arg is a register; the opcode provided by insns[] is correct.
6788 It is not illegal to do "blx pc", just useless. */
6789 if (inst.operands[0].reg == REG_PC)
6790 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
6791
6792 inst.instruction |= inst.operands[0].reg;
6793 }
6794 else
6795 {
6796 /* Arg is an address; this instruction cannot be executed
6797 conditionally, and the opcode must be adjusted. */
6798 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6799 inst.instruction = 0xfa000000;
6800 #ifdef OBJ_ELF
6801 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6802 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6803 else
6804 #endif
6805 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6806 }
6807 }
6808
6809 static void
6810 do_bx (void)
6811 {
6812 bfd_boolean want_reloc;
6813
6814 if (inst.operands[0].reg == REG_PC)
6815 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6816
6817 inst.instruction |= inst.operands[0].reg;
6818 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6819 it is for ARMv4t or earlier. */
6820 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6821 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6822 want_reloc = TRUE;
6823
6824 #ifdef OBJ_ELF
6825 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
6826 #endif
6827 want_reloc = FALSE;
6828
6829 if (want_reloc)
6830 inst.reloc.type = BFD_RELOC_ARM_V4BX;
6831 }
6832
6833
6834 /* ARM v5TEJ. Jump to Jazelle code. */
6835
6836 static void
6837 do_bxj (void)
6838 {
6839 if (inst.operands[0].reg == REG_PC)
6840 as_tsktsk (_("use of r15 in bxj is not really useful"));
6841
6842 inst.instruction |= inst.operands[0].reg;
6843 }
6844
6845 /* Co-processor data operation:
6846 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6847 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6848 static void
6849 do_cdp (void)
6850 {
6851 inst.instruction |= inst.operands[0].reg << 8;
6852 inst.instruction |= inst.operands[1].imm << 20;
6853 inst.instruction |= inst.operands[2].reg << 12;
6854 inst.instruction |= inst.operands[3].reg << 16;
6855 inst.instruction |= inst.operands[4].reg;
6856 inst.instruction |= inst.operands[5].imm << 5;
6857 }
6858
6859 static void
6860 do_cmp (void)
6861 {
6862 inst.instruction |= inst.operands[0].reg << 16;
6863 encode_arm_shifter_operand (1);
6864 }
6865
6866 /* Transfer between coprocessor and ARM registers.
6867 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6868 MRC2
6869 MCR{cond}
6870 MCR2
6871
6872 No special properties. */
6873
6874 static void
6875 do_co_reg (void)
6876 {
6877 unsigned Rd;
6878
6879 Rd = inst.operands[2].reg;
6880 if (thumb_mode)
6881 {
6882 if (inst.instruction == 0xee000010
6883 || inst.instruction == 0xfe000010)
6884 /* MCR, MCR2 */
6885 reject_bad_reg (Rd);
6886 else
6887 /* MRC, MRC2 */
6888 constraint (Rd == REG_SP, BAD_SP);
6889 }
6890 else
6891 {
6892 /* MCR */
6893 if (inst.instruction == 0xe000010)
6894 constraint (Rd == REG_PC, BAD_PC);
6895 }
6896
6897
6898 inst.instruction |= inst.operands[0].reg << 8;
6899 inst.instruction |= inst.operands[1].imm << 21;
6900 inst.instruction |= Rd << 12;
6901 inst.instruction |= inst.operands[3].reg << 16;
6902 inst.instruction |= inst.operands[4].reg;
6903 inst.instruction |= inst.operands[5].imm << 5;
6904 }
6905
6906 /* Transfer between coprocessor register and pair of ARM registers.
6907 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6908 MCRR2
6909 MRRC{cond}
6910 MRRC2
6911
6912 Two XScale instructions are special cases of these:
6913
6914 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6915 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
6916
6917 Result unpredictable if Rd or Rn is R15. */
6918
6919 static void
6920 do_co_reg2c (void)
6921 {
6922 unsigned Rd, Rn;
6923
6924 Rd = inst.operands[2].reg;
6925 Rn = inst.operands[3].reg;
6926
6927 if (thumb_mode)
6928 {
6929 reject_bad_reg (Rd);
6930 reject_bad_reg (Rn);
6931 }
6932 else
6933 {
6934 constraint (Rd == REG_PC, BAD_PC);
6935 constraint (Rn == REG_PC, BAD_PC);
6936 }
6937
6938 inst.instruction |= inst.operands[0].reg << 8;
6939 inst.instruction |= inst.operands[1].imm << 4;
6940 inst.instruction |= Rd << 12;
6941 inst.instruction |= Rn << 16;
6942 inst.instruction |= inst.operands[4].reg;
6943 }
6944
6945 static void
6946 do_cpsi (void)
6947 {
6948 inst.instruction |= inst.operands[0].imm << 6;
6949 if (inst.operands[1].present)
6950 {
6951 inst.instruction |= CPSI_MMOD;
6952 inst.instruction |= inst.operands[1].imm;
6953 }
6954 }
6955
6956 static void
6957 do_dbg (void)
6958 {
6959 inst.instruction |= inst.operands[0].imm;
6960 }
6961
6962 static void
6963 do_it (void)
6964 {
6965 /* There is no IT instruction in ARM mode. We
6966 process it but do not generate code for it. */
6967 inst.size = 0;
6968 }
6969
6970 static void
6971 do_ldmstm (void)
6972 {
6973 int base_reg = inst.operands[0].reg;
6974 int range = inst.operands[1].imm;
6975
6976 inst.instruction |= base_reg << 16;
6977 inst.instruction |= range;
6978
6979 if (inst.operands[1].writeback)
6980 inst.instruction |= LDM_TYPE_2_OR_3;
6981
6982 if (inst.operands[0].writeback)
6983 {
6984 inst.instruction |= WRITE_BACK;
6985 /* Check for unpredictable uses of writeback. */
6986 if (inst.instruction & LOAD_BIT)
6987 {
6988 /* Not allowed in LDM type 2. */
6989 if ((inst.instruction & LDM_TYPE_2_OR_3)
6990 && ((range & (1 << REG_PC)) == 0))
6991 as_warn (_("writeback of base register is UNPREDICTABLE"));
6992 /* Only allowed if base reg not in list for other types. */
6993 else if (range & (1 << base_reg))
6994 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6995 }
6996 else /* STM. */
6997 {
6998 /* Not allowed for type 2. */
6999 if (inst.instruction & LDM_TYPE_2_OR_3)
7000 as_warn (_("writeback of base register is UNPREDICTABLE"));
7001 /* Only allowed if base reg not in list, or first in list. */
7002 else if ((range & (1 << base_reg))
7003 && (range & ((1 << base_reg) - 1)))
7004 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7005 }
7006 }
7007 }
7008
7009 /* ARMv5TE load-consecutive (argument parse)
7010 Mode is like LDRH.
7011
7012 LDRccD R, mode
7013 STRccD R, mode. */
7014
7015 static void
7016 do_ldrd (void)
7017 {
7018 constraint (inst.operands[0].reg % 2 != 0,
7019 _("first destination register must be even"));
7020 constraint (inst.operands[1].present
7021 && inst.operands[1].reg != inst.operands[0].reg + 1,
7022 _("can only load two consecutive registers"));
7023 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7024 constraint (!inst.operands[2].isreg, _("'[' expected"));
7025
7026 if (!inst.operands[1].present)
7027 inst.operands[1].reg = inst.operands[0].reg + 1;
7028
7029 if (inst.instruction & LOAD_BIT)
7030 {
7031 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7032 register and the first register written; we have to diagnose
7033 overlap between the base and the second register written here. */
7034
7035 if (inst.operands[2].reg == inst.operands[1].reg
7036 && (inst.operands[2].writeback || inst.operands[2].postind))
7037 as_warn (_("base register written back, and overlaps "
7038 "second destination register"));
7039
7040 /* For an index-register load, the index register must not overlap the
7041 destination (even if not write-back). */
7042 else if (inst.operands[2].immisreg
7043 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7044 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7045 as_warn (_("index register overlaps destination register"));
7046 }
7047
7048 inst.instruction |= inst.operands[0].reg << 12;
7049 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7050 }
7051
7052 static void
7053 do_ldrex (void)
7054 {
7055 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7056 || inst.operands[1].postind || inst.operands[1].writeback
7057 || inst.operands[1].immisreg || inst.operands[1].shifted
7058 || inst.operands[1].negative
7059 /* This can arise if the programmer has written
7060 strex rN, rM, foo
7061 or if they have mistakenly used a register name as the last
7062 operand, eg:
7063 strex rN, rM, rX
7064 It is very difficult to distinguish between these two cases
7065 because "rX" might actually be a label. ie the register
7066 name has been occluded by a symbol of the same name. So we
7067 just generate a general 'bad addressing mode' type error
7068 message and leave it up to the programmer to discover the
7069 true cause and fix their mistake. */
7070 || (inst.operands[1].reg == REG_PC),
7071 BAD_ADDR_MODE);
7072
7073 constraint (inst.reloc.exp.X_op != O_constant
7074 || inst.reloc.exp.X_add_number != 0,
7075 _("offset must be zero in ARM encoding"));
7076
7077 inst.instruction |= inst.operands[0].reg << 12;
7078 inst.instruction |= inst.operands[1].reg << 16;
7079 inst.reloc.type = BFD_RELOC_UNUSED;
7080 }
7081
7082 static void
7083 do_ldrexd (void)
7084 {
7085 constraint (inst.operands[0].reg % 2 != 0,
7086 _("even register required"));
7087 constraint (inst.operands[1].present
7088 && inst.operands[1].reg != inst.operands[0].reg + 1,
7089 _("can only load two consecutive registers"));
7090 /* If op 1 were present and equal to PC, this function wouldn't
7091 have been called in the first place. */
7092 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7093
7094 inst.instruction |= inst.operands[0].reg << 12;
7095 inst.instruction |= inst.operands[2].reg << 16;
7096 }
7097
7098 static void
7099 do_ldst (void)
7100 {
7101 inst.instruction |= inst.operands[0].reg << 12;
7102 if (!inst.operands[1].isreg)
7103 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7104 return;
7105 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7106 }
7107
7108 static void
7109 do_ldstt (void)
7110 {
7111 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7112 reject [Rn,...]. */
7113 if (inst.operands[1].preind)
7114 {
7115 constraint (inst.reloc.exp.X_op != O_constant
7116 || inst.reloc.exp.X_add_number != 0,
7117 _("this instruction requires a post-indexed address"));
7118
7119 inst.operands[1].preind = 0;
7120 inst.operands[1].postind = 1;
7121 inst.operands[1].writeback = 1;
7122 }
7123 inst.instruction |= inst.operands[0].reg << 12;
7124 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7125 }
7126
7127 /* Halfword and signed-byte load/store operations. */
7128
7129 static void
7130 do_ldstv4 (void)
7131 {
7132 inst.instruction |= inst.operands[0].reg << 12;
7133 if (!inst.operands[1].isreg)
7134 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7135 return;
7136 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7137 }
7138
7139 static void
7140 do_ldsttv4 (void)
7141 {
7142 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7143 reject [Rn,...]. */
7144 if (inst.operands[1].preind)
7145 {
7146 constraint (inst.reloc.exp.X_op != O_constant
7147 || inst.reloc.exp.X_add_number != 0,
7148 _("this instruction requires a post-indexed address"));
7149
7150 inst.operands[1].preind = 0;
7151 inst.operands[1].postind = 1;
7152 inst.operands[1].writeback = 1;
7153 }
7154 inst.instruction |= inst.operands[0].reg << 12;
7155 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7156 }
7157
7158 /* Co-processor register load/store.
7159 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7160 static void
7161 do_lstc (void)
7162 {
7163 inst.instruction |= inst.operands[0].reg << 8;
7164 inst.instruction |= inst.operands[1].reg << 12;
7165 encode_arm_cp_address (2, TRUE, TRUE, 0);
7166 }
7167
7168 static void
7169 do_mlas (void)
7170 {
7171 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7172 if (inst.operands[0].reg == inst.operands[1].reg
7173 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7174 && !(inst.instruction & 0x00400000))
7175 as_tsktsk (_("Rd and Rm should be different in mla"));
7176
7177 inst.instruction |= inst.operands[0].reg << 16;
7178 inst.instruction |= inst.operands[1].reg;
7179 inst.instruction |= inst.operands[2].reg << 8;
7180 inst.instruction |= inst.operands[3].reg << 12;
7181 }
7182
7183 static void
7184 do_mov (void)
7185 {
7186 inst.instruction |= inst.operands[0].reg << 12;
7187 encode_arm_shifter_operand (1);
7188 }
7189
7190 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7191 static void
7192 do_mov16 (void)
7193 {
7194 bfd_vma imm;
7195 bfd_boolean top;
7196
7197 top = (inst.instruction & 0x00400000) != 0;
7198 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7199 _(":lower16: not allowed this instruction"));
7200 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7201 _(":upper16: not allowed instruction"));
7202 inst.instruction |= inst.operands[0].reg << 12;
7203 if (inst.reloc.type == BFD_RELOC_UNUSED)
7204 {
7205 imm = inst.reloc.exp.X_add_number;
7206 /* The value is in two pieces: 0:11, 16:19. */
7207 inst.instruction |= (imm & 0x00000fff);
7208 inst.instruction |= (imm & 0x0000f000) << 4;
7209 }
7210 }
7211
7212 static void do_vfp_nsyn_opcode (const char *);
7213
7214 static int
7215 do_vfp_nsyn_mrs (void)
7216 {
7217 if (inst.operands[0].isvec)
7218 {
7219 if (inst.operands[1].reg != 1)
7220 first_error (_("operand 1 must be FPSCR"));
7221 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7222 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7223 do_vfp_nsyn_opcode ("fmstat");
7224 }
7225 else if (inst.operands[1].isvec)
7226 do_vfp_nsyn_opcode ("fmrx");
7227 else
7228 return FAIL;
7229
7230 return SUCCESS;
7231 }
7232
7233 static int
7234 do_vfp_nsyn_msr (void)
7235 {
7236 if (inst.operands[0].isvec)
7237 do_vfp_nsyn_opcode ("fmxr");
7238 else
7239 return FAIL;
7240
7241 return SUCCESS;
7242 }
7243
7244 static void
7245 do_mrs (void)
7246 {
7247 if (do_vfp_nsyn_mrs () == SUCCESS)
7248 return;
7249
7250 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7251 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7252 != (PSR_c|PSR_f),
7253 _("'CPSR' or 'SPSR' expected"));
7254 inst.instruction |= inst.operands[0].reg << 12;
7255 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7256 }
7257
7258 /* Two possible forms:
7259 "{C|S}PSR_<field>, Rm",
7260 "{C|S}PSR_f, #expression". */
7261
7262 static void
7263 do_msr (void)
7264 {
7265 if (do_vfp_nsyn_msr () == SUCCESS)
7266 return;
7267
7268 inst.instruction |= inst.operands[0].imm;
7269 if (inst.operands[1].isreg)
7270 inst.instruction |= inst.operands[1].reg;
7271 else
7272 {
7273 inst.instruction |= INST_IMMEDIATE;
7274 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7275 inst.reloc.pc_rel = 0;
7276 }
7277 }
7278
7279 static void
7280 do_mul (void)
7281 {
7282 if (!inst.operands[2].present)
7283 inst.operands[2].reg = inst.operands[0].reg;
7284 inst.instruction |= inst.operands[0].reg << 16;
7285 inst.instruction |= inst.operands[1].reg;
7286 inst.instruction |= inst.operands[2].reg << 8;
7287
7288 if (inst.operands[0].reg == inst.operands[1].reg
7289 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7290 as_tsktsk (_("Rd and Rm should be different in mul"));
7291 }
7292
7293 /* Long Multiply Parser
7294 UMULL RdLo, RdHi, Rm, Rs
7295 SMULL RdLo, RdHi, Rm, Rs
7296 UMLAL RdLo, RdHi, Rm, Rs
7297 SMLAL RdLo, RdHi, Rm, Rs. */
7298
7299 static void
7300 do_mull (void)
7301 {
7302 inst.instruction |= inst.operands[0].reg << 12;
7303 inst.instruction |= inst.operands[1].reg << 16;
7304 inst.instruction |= inst.operands[2].reg;
7305 inst.instruction |= inst.operands[3].reg << 8;
7306
7307 /* rdhi and rdlo must be different. */
7308 if (inst.operands[0].reg == inst.operands[1].reg)
7309 as_tsktsk (_("rdhi and rdlo must be different"));
7310
7311 /* rdhi, rdlo and rm must all be different before armv6. */
7312 if ((inst.operands[0].reg == inst.operands[2].reg
7313 || inst.operands[1].reg == inst.operands[2].reg)
7314 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7315 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7316 }
7317
7318 static void
7319 do_nop (void)
7320 {
7321 if (inst.operands[0].present
7322 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
7323 {
7324 /* Architectural NOP hints are CPSR sets with no bits selected. */
7325 inst.instruction &= 0xf0000000;
7326 inst.instruction |= 0x0320f000;
7327 if (inst.operands[0].present)
7328 inst.instruction |= inst.operands[0].imm;
7329 }
7330 }
7331
7332 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7333 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7334 Condition defaults to COND_ALWAYS.
7335 Error if Rd, Rn or Rm are R15. */
7336
7337 static void
7338 do_pkhbt (void)
7339 {
7340 inst.instruction |= inst.operands[0].reg << 12;
7341 inst.instruction |= inst.operands[1].reg << 16;
7342 inst.instruction |= inst.operands[2].reg;
7343 if (inst.operands[3].present)
7344 encode_arm_shift (3);
7345 }
7346
7347 /* ARM V6 PKHTB (Argument Parse). */
7348
7349 static void
7350 do_pkhtb (void)
7351 {
7352 if (!inst.operands[3].present)
7353 {
7354 /* If the shift specifier is omitted, turn the instruction
7355 into pkhbt rd, rm, rn. */
7356 inst.instruction &= 0xfff00010;
7357 inst.instruction |= inst.operands[0].reg << 12;
7358 inst.instruction |= inst.operands[1].reg;
7359 inst.instruction |= inst.operands[2].reg << 16;
7360 }
7361 else
7362 {
7363 inst.instruction |= inst.operands[0].reg << 12;
7364 inst.instruction |= inst.operands[1].reg << 16;
7365 inst.instruction |= inst.operands[2].reg;
7366 encode_arm_shift (3);
7367 }
7368 }
7369
7370 /* ARMv5TE: Preload-Cache
7371
7372 PLD <addr_mode>
7373
7374 Syntactically, like LDR with B=1, W=0, L=1. */
7375
7376 static void
7377 do_pld (void)
7378 {
7379 constraint (!inst.operands[0].isreg,
7380 _("'[' expected after PLD mnemonic"));
7381 constraint (inst.operands[0].postind,
7382 _("post-indexed expression used in preload instruction"));
7383 constraint (inst.operands[0].writeback,
7384 _("writeback used in preload instruction"));
7385 constraint (!inst.operands[0].preind,
7386 _("unindexed addressing used in preload instruction"));
7387 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7388 }
7389
7390 /* ARMv7: PLI <addr_mode> */
7391 static void
7392 do_pli (void)
7393 {
7394 constraint (!inst.operands[0].isreg,
7395 _("'[' expected after PLI mnemonic"));
7396 constraint (inst.operands[0].postind,
7397 _("post-indexed expression used in preload instruction"));
7398 constraint (inst.operands[0].writeback,
7399 _("writeback used in preload instruction"));
7400 constraint (!inst.operands[0].preind,
7401 _("unindexed addressing used in preload instruction"));
7402 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7403 inst.instruction &= ~PRE_INDEX;
7404 }
7405
7406 static void
7407 do_push_pop (void)
7408 {
7409 inst.operands[1] = inst.operands[0];
7410 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7411 inst.operands[0].isreg = 1;
7412 inst.operands[0].writeback = 1;
7413 inst.operands[0].reg = REG_SP;
7414 do_ldmstm ();
7415 }
7416
7417 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7418 word at the specified address and the following word
7419 respectively.
7420 Unconditionally executed.
7421 Error if Rn is R15. */
7422
7423 static void
7424 do_rfe (void)
7425 {
7426 inst.instruction |= inst.operands[0].reg << 16;
7427 if (inst.operands[0].writeback)
7428 inst.instruction |= WRITE_BACK;
7429 }
7430
7431 /* ARM V6 ssat (argument parse). */
7432
7433 static void
7434 do_ssat (void)
7435 {
7436 inst.instruction |= inst.operands[0].reg << 12;
7437 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7438 inst.instruction |= inst.operands[2].reg;
7439
7440 if (inst.operands[3].present)
7441 encode_arm_shift (3);
7442 }
7443
7444 /* ARM V6 usat (argument parse). */
7445
7446 static void
7447 do_usat (void)
7448 {
7449 inst.instruction |= inst.operands[0].reg << 12;
7450 inst.instruction |= inst.operands[1].imm << 16;
7451 inst.instruction |= inst.operands[2].reg;
7452
7453 if (inst.operands[3].present)
7454 encode_arm_shift (3);
7455 }
7456
7457 /* ARM V6 ssat16 (argument parse). */
7458
7459 static void
7460 do_ssat16 (void)
7461 {
7462 inst.instruction |= inst.operands[0].reg << 12;
7463 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7464 inst.instruction |= inst.operands[2].reg;
7465 }
7466
7467 static void
7468 do_usat16 (void)
7469 {
7470 inst.instruction |= inst.operands[0].reg << 12;
7471 inst.instruction |= inst.operands[1].imm << 16;
7472 inst.instruction |= inst.operands[2].reg;
7473 }
7474
7475 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7476 preserving the other bits.
7477
7478 setend <endian_specifier>, where <endian_specifier> is either
7479 BE or LE. */
7480
7481 static void
7482 do_setend (void)
7483 {
7484 if (inst.operands[0].imm)
7485 inst.instruction |= 0x200;
7486 }
7487
7488 static void
7489 do_shift (void)
7490 {
7491 unsigned int Rm = (inst.operands[1].present
7492 ? inst.operands[1].reg
7493 : inst.operands[0].reg);
7494
7495 inst.instruction |= inst.operands[0].reg << 12;
7496 inst.instruction |= Rm;
7497 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7498 {
7499 inst.instruction |= inst.operands[2].reg << 8;
7500 inst.instruction |= SHIFT_BY_REG;
7501 }
7502 else
7503 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7504 }
7505
7506 static void
7507 do_smc (void)
7508 {
7509 inst.reloc.type = BFD_RELOC_ARM_SMC;
7510 inst.reloc.pc_rel = 0;
7511 }
7512
7513 static void
7514 do_swi (void)
7515 {
7516 inst.reloc.type = BFD_RELOC_ARM_SWI;
7517 inst.reloc.pc_rel = 0;
7518 }
7519
7520 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7521 SMLAxy{cond} Rd,Rm,Rs,Rn
7522 SMLAWy{cond} Rd,Rm,Rs,Rn
7523 Error if any register is R15. */
7524
7525 static void
7526 do_smla (void)
7527 {
7528 inst.instruction |= inst.operands[0].reg << 16;
7529 inst.instruction |= inst.operands[1].reg;
7530 inst.instruction |= inst.operands[2].reg << 8;
7531 inst.instruction |= inst.operands[3].reg << 12;
7532 }
7533
7534 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7535 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7536 Error if any register is R15.
7537 Warning if Rdlo == Rdhi. */
7538
7539 static void
7540 do_smlal (void)
7541 {
7542 inst.instruction |= inst.operands[0].reg << 12;
7543 inst.instruction |= inst.operands[1].reg << 16;
7544 inst.instruction |= inst.operands[2].reg;
7545 inst.instruction |= inst.operands[3].reg << 8;
7546
7547 if (inst.operands[0].reg == inst.operands[1].reg)
7548 as_tsktsk (_("rdhi and rdlo must be different"));
7549 }
7550
7551 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7552 SMULxy{cond} Rd,Rm,Rs
7553 Error if any register is R15. */
7554
7555 static void
7556 do_smul (void)
7557 {
7558 inst.instruction |= inst.operands[0].reg << 16;
7559 inst.instruction |= inst.operands[1].reg;
7560 inst.instruction |= inst.operands[2].reg << 8;
7561 }
7562
7563 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7564 the same for both ARM and Thumb-2. */
7565
7566 static void
7567 do_srs (void)
7568 {
7569 int reg;
7570
7571 if (inst.operands[0].present)
7572 {
7573 reg = inst.operands[0].reg;
7574 constraint (reg != REG_SP, _("SRS base register must be r13"));
7575 }
7576 else
7577 reg = REG_SP;
7578
7579 inst.instruction |= reg << 16;
7580 inst.instruction |= inst.operands[1].imm;
7581 if (inst.operands[0].writeback || inst.operands[1].writeback)
7582 inst.instruction |= WRITE_BACK;
7583 }
7584
7585 /* ARM V6 strex (argument parse). */
7586
7587 static void
7588 do_strex (void)
7589 {
7590 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7591 || inst.operands[2].postind || inst.operands[2].writeback
7592 || inst.operands[2].immisreg || inst.operands[2].shifted
7593 || inst.operands[2].negative
7594 /* See comment in do_ldrex(). */
7595 || (inst.operands[2].reg == REG_PC),
7596 BAD_ADDR_MODE);
7597
7598 constraint (inst.operands[0].reg == inst.operands[1].reg
7599 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
7600
7601 constraint (inst.reloc.exp.X_op != O_constant
7602 || inst.reloc.exp.X_add_number != 0,
7603 _("offset must be zero in ARM encoding"));
7604
7605 inst.instruction |= inst.operands[0].reg << 12;
7606 inst.instruction |= inst.operands[1].reg;
7607 inst.instruction |= inst.operands[2].reg << 16;
7608 inst.reloc.type = BFD_RELOC_UNUSED;
7609 }
7610
7611 static void
7612 do_strexd (void)
7613 {
7614 constraint (inst.operands[1].reg % 2 != 0,
7615 _("even register required"));
7616 constraint (inst.operands[2].present
7617 && inst.operands[2].reg != inst.operands[1].reg + 1,
7618 _("can only store two consecutive registers"));
7619 /* If op 2 were present and equal to PC, this function wouldn't
7620 have been called in the first place. */
7621 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
7622
7623 constraint (inst.operands[0].reg == inst.operands[1].reg
7624 || inst.operands[0].reg == inst.operands[1].reg + 1
7625 || inst.operands[0].reg == inst.operands[3].reg,
7626 BAD_OVERLAP);
7627
7628 inst.instruction |= inst.operands[0].reg << 12;
7629 inst.instruction |= inst.operands[1].reg;
7630 inst.instruction |= inst.operands[3].reg << 16;
7631 }
7632
7633 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7634 extends it to 32-bits, and adds the result to a value in another
7635 register. You can specify a rotation by 0, 8, 16, or 24 bits
7636 before extracting the 16-bit value.
7637 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7638 Condition defaults to COND_ALWAYS.
7639 Error if any register uses R15. */
7640
7641 static void
7642 do_sxtah (void)
7643 {
7644 inst.instruction |= inst.operands[0].reg << 12;
7645 inst.instruction |= inst.operands[1].reg << 16;
7646 inst.instruction |= inst.operands[2].reg;
7647 inst.instruction |= inst.operands[3].imm << 10;
7648 }
7649
7650 /* ARM V6 SXTH.
7651
7652 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7653 Condition defaults to COND_ALWAYS.
7654 Error if any register uses R15. */
7655
7656 static void
7657 do_sxth (void)
7658 {
7659 inst.instruction |= inst.operands[0].reg << 12;
7660 inst.instruction |= inst.operands[1].reg;
7661 inst.instruction |= inst.operands[2].imm << 10;
7662 }
7663 \f
7664 /* VFP instructions. In a logical order: SP variant first, monad
7665 before dyad, arithmetic then move then load/store. */
7666
7667 static void
7668 do_vfp_sp_monadic (void)
7669 {
7670 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7671 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7672 }
7673
7674 static void
7675 do_vfp_sp_dyadic (void)
7676 {
7677 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7678 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7679 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7680 }
7681
7682 static void
7683 do_vfp_sp_compare_z (void)
7684 {
7685 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7686 }
7687
7688 static void
7689 do_vfp_dp_sp_cvt (void)
7690 {
7691 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7692 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7693 }
7694
7695 static void
7696 do_vfp_sp_dp_cvt (void)
7697 {
7698 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7699 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7700 }
7701
7702 static void
7703 do_vfp_reg_from_sp (void)
7704 {
7705 inst.instruction |= inst.operands[0].reg << 12;
7706 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7707 }
7708
7709 static void
7710 do_vfp_reg2_from_sp2 (void)
7711 {
7712 constraint (inst.operands[2].imm != 2,
7713 _("only two consecutive VFP SP registers allowed here"));
7714 inst.instruction |= inst.operands[0].reg << 12;
7715 inst.instruction |= inst.operands[1].reg << 16;
7716 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7717 }
7718
7719 static void
7720 do_vfp_sp_from_reg (void)
7721 {
7722 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7723 inst.instruction |= inst.operands[1].reg << 12;
7724 }
7725
7726 static void
7727 do_vfp_sp2_from_reg2 (void)
7728 {
7729 constraint (inst.operands[0].imm != 2,
7730 _("only two consecutive VFP SP registers allowed here"));
7731 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7732 inst.instruction |= inst.operands[1].reg << 12;
7733 inst.instruction |= inst.operands[2].reg << 16;
7734 }
7735
7736 static void
7737 do_vfp_sp_ldst (void)
7738 {
7739 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7740 encode_arm_cp_address (1, FALSE, TRUE, 0);
7741 }
7742
7743 static void
7744 do_vfp_dp_ldst (void)
7745 {
7746 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7747 encode_arm_cp_address (1, FALSE, TRUE, 0);
7748 }
7749
7750
7751 static void
7752 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
7753 {
7754 if (inst.operands[0].writeback)
7755 inst.instruction |= WRITE_BACK;
7756 else
7757 constraint (ldstm_type != VFP_LDSTMIA,
7758 _("this addressing mode requires base-register writeback"));
7759 inst.instruction |= inst.operands[0].reg << 16;
7760 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7761 inst.instruction |= inst.operands[1].imm;
7762 }
7763
7764 static void
7765 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7766 {
7767 int count;
7768
7769 if (inst.operands[0].writeback)
7770 inst.instruction |= WRITE_BACK;
7771 else
7772 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7773 _("this addressing mode requires base-register writeback"));
7774
7775 inst.instruction |= inst.operands[0].reg << 16;
7776 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7777
7778 count = inst.operands[1].imm << 1;
7779 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7780 count += 1;
7781
7782 inst.instruction |= count;
7783 }
7784
7785 static void
7786 do_vfp_sp_ldstmia (void)
7787 {
7788 vfp_sp_ldstm (VFP_LDSTMIA);
7789 }
7790
7791 static void
7792 do_vfp_sp_ldstmdb (void)
7793 {
7794 vfp_sp_ldstm (VFP_LDSTMDB);
7795 }
7796
7797 static void
7798 do_vfp_dp_ldstmia (void)
7799 {
7800 vfp_dp_ldstm (VFP_LDSTMIA);
7801 }
7802
7803 static void
7804 do_vfp_dp_ldstmdb (void)
7805 {
7806 vfp_dp_ldstm (VFP_LDSTMDB);
7807 }
7808
7809 static void
7810 do_vfp_xp_ldstmia (void)
7811 {
7812 vfp_dp_ldstm (VFP_LDSTMIAX);
7813 }
7814
7815 static void
7816 do_vfp_xp_ldstmdb (void)
7817 {
7818 vfp_dp_ldstm (VFP_LDSTMDBX);
7819 }
7820
7821 static void
7822 do_vfp_dp_rd_rm (void)
7823 {
7824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7825 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7826 }
7827
7828 static void
7829 do_vfp_dp_rn_rd (void)
7830 {
7831 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7832 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7833 }
7834
7835 static void
7836 do_vfp_dp_rd_rn (void)
7837 {
7838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7839 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7840 }
7841
7842 static void
7843 do_vfp_dp_rd_rn_rm (void)
7844 {
7845 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7846 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7847 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7848 }
7849
7850 static void
7851 do_vfp_dp_rd (void)
7852 {
7853 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7854 }
7855
7856 static void
7857 do_vfp_dp_rm_rd_rn (void)
7858 {
7859 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7860 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7861 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7862 }
7863
7864 /* VFPv3 instructions. */
7865 static void
7866 do_vfp_sp_const (void)
7867 {
7868 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7869 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7870 inst.instruction |= (inst.operands[1].imm & 0x0f);
7871 }
7872
7873 static void
7874 do_vfp_dp_const (void)
7875 {
7876 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7877 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7878 inst.instruction |= (inst.operands[1].imm & 0x0f);
7879 }
7880
7881 static void
7882 vfp_conv (int srcsize)
7883 {
7884 unsigned immbits = srcsize - inst.operands[1].imm;
7885 inst.instruction |= (immbits & 1) << 5;
7886 inst.instruction |= (immbits >> 1);
7887 }
7888
7889 static void
7890 do_vfp_sp_conv_16 (void)
7891 {
7892 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7893 vfp_conv (16);
7894 }
7895
7896 static void
7897 do_vfp_dp_conv_16 (void)
7898 {
7899 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7900 vfp_conv (16);
7901 }
7902
7903 static void
7904 do_vfp_sp_conv_32 (void)
7905 {
7906 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7907 vfp_conv (32);
7908 }
7909
7910 static void
7911 do_vfp_dp_conv_32 (void)
7912 {
7913 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7914 vfp_conv (32);
7915 }
7916 \f
7917 /* FPA instructions. Also in a logical order. */
7918
7919 static void
7920 do_fpa_cmp (void)
7921 {
7922 inst.instruction |= inst.operands[0].reg << 16;
7923 inst.instruction |= inst.operands[1].reg;
7924 }
7925
7926 static void
7927 do_fpa_ldmstm (void)
7928 {
7929 inst.instruction |= inst.operands[0].reg << 12;
7930 switch (inst.operands[1].imm)
7931 {
7932 case 1: inst.instruction |= CP_T_X; break;
7933 case 2: inst.instruction |= CP_T_Y; break;
7934 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7935 case 4: break;
7936 default: abort ();
7937 }
7938
7939 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7940 {
7941 /* The instruction specified "ea" or "fd", so we can only accept
7942 [Rn]{!}. The instruction does not really support stacking or
7943 unstacking, so we have to emulate these by setting appropriate
7944 bits and offsets. */
7945 constraint (inst.reloc.exp.X_op != O_constant
7946 || inst.reloc.exp.X_add_number != 0,
7947 _("this instruction does not support indexing"));
7948
7949 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7950 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
7951
7952 if (!(inst.instruction & INDEX_UP))
7953 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
7954
7955 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7956 {
7957 inst.operands[2].preind = 0;
7958 inst.operands[2].postind = 1;
7959 }
7960 }
7961
7962 encode_arm_cp_address (2, TRUE, TRUE, 0);
7963 }
7964 \f
7965 /* iWMMXt instructions: strictly in alphabetical order. */
7966
7967 static void
7968 do_iwmmxt_tandorc (void)
7969 {
7970 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7971 }
7972
7973 static void
7974 do_iwmmxt_textrc (void)
7975 {
7976 inst.instruction |= inst.operands[0].reg << 12;
7977 inst.instruction |= inst.operands[1].imm;
7978 }
7979
7980 static void
7981 do_iwmmxt_textrm (void)
7982 {
7983 inst.instruction |= inst.operands[0].reg << 12;
7984 inst.instruction |= inst.operands[1].reg << 16;
7985 inst.instruction |= inst.operands[2].imm;
7986 }
7987
7988 static void
7989 do_iwmmxt_tinsr (void)
7990 {
7991 inst.instruction |= inst.operands[0].reg << 16;
7992 inst.instruction |= inst.operands[1].reg << 12;
7993 inst.instruction |= inst.operands[2].imm;
7994 }
7995
7996 static void
7997 do_iwmmxt_tmia (void)
7998 {
7999 inst.instruction |= inst.operands[0].reg << 5;
8000 inst.instruction |= inst.operands[1].reg;
8001 inst.instruction |= inst.operands[2].reg << 12;
8002 }
8003
8004 static void
8005 do_iwmmxt_waligni (void)
8006 {
8007 inst.instruction |= inst.operands[0].reg << 12;
8008 inst.instruction |= inst.operands[1].reg << 16;
8009 inst.instruction |= inst.operands[2].reg;
8010 inst.instruction |= inst.operands[3].imm << 20;
8011 }
8012
8013 static void
8014 do_iwmmxt_wmerge (void)
8015 {
8016 inst.instruction |= inst.operands[0].reg << 12;
8017 inst.instruction |= inst.operands[1].reg << 16;
8018 inst.instruction |= inst.operands[2].reg;
8019 inst.instruction |= inst.operands[3].imm << 21;
8020 }
8021
8022 static void
8023 do_iwmmxt_wmov (void)
8024 {
8025 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8026 inst.instruction |= inst.operands[0].reg << 12;
8027 inst.instruction |= inst.operands[1].reg << 16;
8028 inst.instruction |= inst.operands[1].reg;
8029 }
8030
8031 static void
8032 do_iwmmxt_wldstbh (void)
8033 {
8034 int reloc;
8035 inst.instruction |= inst.operands[0].reg << 12;
8036 if (thumb_mode)
8037 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8038 else
8039 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8040 encode_arm_cp_address (1, TRUE, FALSE, reloc);
8041 }
8042
8043 static void
8044 do_iwmmxt_wldstw (void)
8045 {
8046 /* RIWR_RIWC clears .isreg for a control register. */
8047 if (!inst.operands[0].isreg)
8048 {
8049 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8050 inst.instruction |= 0xf0000000;
8051 }
8052
8053 inst.instruction |= inst.operands[0].reg << 12;
8054 encode_arm_cp_address (1, TRUE, TRUE, 0);
8055 }
8056
8057 static void
8058 do_iwmmxt_wldstd (void)
8059 {
8060 inst.instruction |= inst.operands[0].reg << 12;
8061 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8062 && inst.operands[1].immisreg)
8063 {
8064 inst.instruction &= ~0x1a000ff;
8065 inst.instruction |= (0xf << 28);
8066 if (inst.operands[1].preind)
8067 inst.instruction |= PRE_INDEX;
8068 if (!inst.operands[1].negative)
8069 inst.instruction |= INDEX_UP;
8070 if (inst.operands[1].writeback)
8071 inst.instruction |= WRITE_BACK;
8072 inst.instruction |= inst.operands[1].reg << 16;
8073 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8074 inst.instruction |= inst.operands[1].imm;
8075 }
8076 else
8077 encode_arm_cp_address (1, TRUE, FALSE, 0);
8078 }
8079
8080 static void
8081 do_iwmmxt_wshufh (void)
8082 {
8083 inst.instruction |= inst.operands[0].reg << 12;
8084 inst.instruction |= inst.operands[1].reg << 16;
8085 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8086 inst.instruction |= (inst.operands[2].imm & 0x0f);
8087 }
8088
8089 static void
8090 do_iwmmxt_wzero (void)
8091 {
8092 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8093 inst.instruction |= inst.operands[0].reg;
8094 inst.instruction |= inst.operands[0].reg << 12;
8095 inst.instruction |= inst.operands[0].reg << 16;
8096 }
8097
8098 static void
8099 do_iwmmxt_wrwrwr_or_imm5 (void)
8100 {
8101 if (inst.operands[2].isreg)
8102 do_rd_rn_rm ();
8103 else {
8104 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8105 _("immediate operand requires iWMMXt2"));
8106 do_rd_rn ();
8107 if (inst.operands[2].imm == 0)
8108 {
8109 switch ((inst.instruction >> 20) & 0xf)
8110 {
8111 case 4:
8112 case 5:
8113 case 6:
8114 case 7:
8115 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8116 inst.operands[2].imm = 16;
8117 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8118 break;
8119 case 8:
8120 case 9:
8121 case 10:
8122 case 11:
8123 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8124 inst.operands[2].imm = 32;
8125 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8126 break;
8127 case 12:
8128 case 13:
8129 case 14:
8130 case 15:
8131 {
8132 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8133 unsigned long wrn;
8134 wrn = (inst.instruction >> 16) & 0xf;
8135 inst.instruction &= 0xff0fff0f;
8136 inst.instruction |= wrn;
8137 /* Bail out here; the instruction is now assembled. */
8138 return;
8139 }
8140 }
8141 }
8142 /* Map 32 -> 0, etc. */
8143 inst.operands[2].imm &= 0x1f;
8144 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8145 }
8146 }
8147 \f
8148 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8149 operations first, then control, shift, and load/store. */
8150
8151 /* Insns like "foo X,Y,Z". */
8152
8153 static void
8154 do_mav_triple (void)
8155 {
8156 inst.instruction |= inst.operands[0].reg << 16;
8157 inst.instruction |= inst.operands[1].reg;
8158 inst.instruction |= inst.operands[2].reg << 12;
8159 }
8160
8161 /* Insns like "foo W,X,Y,Z".
8162 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8163
8164 static void
8165 do_mav_quad (void)
8166 {
8167 inst.instruction |= inst.operands[0].reg << 5;
8168 inst.instruction |= inst.operands[1].reg << 12;
8169 inst.instruction |= inst.operands[2].reg << 16;
8170 inst.instruction |= inst.operands[3].reg;
8171 }
8172
8173 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8174 static void
8175 do_mav_dspsc (void)
8176 {
8177 inst.instruction |= inst.operands[1].reg << 12;
8178 }
8179
8180 /* Maverick shift immediate instructions.
8181 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8182 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8183
8184 static void
8185 do_mav_shift (void)
8186 {
8187 int imm = inst.operands[2].imm;
8188
8189 inst.instruction |= inst.operands[0].reg << 12;
8190 inst.instruction |= inst.operands[1].reg << 16;
8191
8192 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8193 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8194 Bit 4 should be 0. */
8195 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8196
8197 inst.instruction |= imm;
8198 }
8199 \f
8200 /* XScale instructions. Also sorted arithmetic before move. */
8201
8202 /* Xscale multiply-accumulate (argument parse)
8203 MIAcc acc0,Rm,Rs
8204 MIAPHcc acc0,Rm,Rs
8205 MIAxycc acc0,Rm,Rs. */
8206
8207 static void
8208 do_xsc_mia (void)
8209 {
8210 inst.instruction |= inst.operands[1].reg;
8211 inst.instruction |= inst.operands[2].reg << 12;
8212 }
8213
8214 /* Xscale move-accumulator-register (argument parse)
8215
8216 MARcc acc0,RdLo,RdHi. */
8217
8218 static void
8219 do_xsc_mar (void)
8220 {
8221 inst.instruction |= inst.operands[1].reg << 12;
8222 inst.instruction |= inst.operands[2].reg << 16;
8223 }
8224
8225 /* Xscale move-register-accumulator (argument parse)
8226
8227 MRAcc RdLo,RdHi,acc0. */
8228
8229 static void
8230 do_xsc_mra (void)
8231 {
8232 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8233 inst.instruction |= inst.operands[0].reg << 12;
8234 inst.instruction |= inst.operands[1].reg << 16;
8235 }
8236 \f
8237 /* Encoding functions relevant only to Thumb. */
8238
8239 /* inst.operands[i] is a shifted-register operand; encode
8240 it into inst.instruction in the format used by Thumb32. */
8241
8242 static void
8243 encode_thumb32_shifted_operand (int i)
8244 {
8245 unsigned int value = inst.reloc.exp.X_add_number;
8246 unsigned int shift = inst.operands[i].shift_kind;
8247
8248 constraint (inst.operands[i].immisreg,
8249 _("shift by register not allowed in thumb mode"));
8250 inst.instruction |= inst.operands[i].reg;
8251 if (shift == SHIFT_RRX)
8252 inst.instruction |= SHIFT_ROR << 4;
8253 else
8254 {
8255 constraint (inst.reloc.exp.X_op != O_constant,
8256 _("expression too complex"));
8257
8258 constraint (value > 32
8259 || (value == 32 && (shift == SHIFT_LSL
8260 || shift == SHIFT_ROR)),
8261 _("shift expression is too large"));
8262
8263 if (value == 0)
8264 shift = SHIFT_LSL;
8265 else if (value == 32)
8266 value = 0;
8267
8268 inst.instruction |= shift << 4;
8269 inst.instruction |= (value & 0x1c) << 10;
8270 inst.instruction |= (value & 0x03) << 6;
8271 }
8272 }
8273
8274
8275 /* inst.operands[i] was set up by parse_address. Encode it into a
8276 Thumb32 format load or store instruction. Reject forms that cannot
8277 be used with such instructions. If is_t is true, reject forms that
8278 cannot be used with a T instruction; if is_d is true, reject forms
8279 that cannot be used with a D instruction. */
8280
8281 static void
8282 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8283 {
8284 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8285
8286 constraint (!inst.operands[i].isreg,
8287 _("Instruction does not support =N addresses"));
8288
8289 inst.instruction |= inst.operands[i].reg << 16;
8290 if (inst.operands[i].immisreg)
8291 {
8292 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8293 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8294 constraint (inst.operands[i].negative,
8295 _("Thumb does not support negative register indexing"));
8296 constraint (inst.operands[i].postind,
8297 _("Thumb does not support register post-indexing"));
8298 constraint (inst.operands[i].writeback,
8299 _("Thumb does not support register indexing with writeback"));
8300 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8301 _("Thumb supports only LSL in shifted register indexing"));
8302
8303 inst.instruction |= inst.operands[i].imm;
8304 if (inst.operands[i].shifted)
8305 {
8306 constraint (inst.reloc.exp.X_op != O_constant,
8307 _("expression too complex"));
8308 constraint (inst.reloc.exp.X_add_number < 0
8309 || inst.reloc.exp.X_add_number > 3,
8310 _("shift out of range"));
8311 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8312 }
8313 inst.reloc.type = BFD_RELOC_UNUSED;
8314 }
8315 else if (inst.operands[i].preind)
8316 {
8317 constraint (is_pc && inst.operands[i].writeback,
8318 _("cannot use writeback with PC-relative addressing"));
8319 constraint (is_t && inst.operands[i].writeback,
8320 _("cannot use writeback with this instruction"));
8321
8322 if (is_d)
8323 {
8324 inst.instruction |= 0x01000000;
8325 if (inst.operands[i].writeback)
8326 inst.instruction |= 0x00200000;
8327 }
8328 else
8329 {
8330 inst.instruction |= 0x00000c00;
8331 if (inst.operands[i].writeback)
8332 inst.instruction |= 0x00000100;
8333 }
8334 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8335 }
8336 else if (inst.operands[i].postind)
8337 {
8338 assert (inst.operands[i].writeback);
8339 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8340 constraint (is_t, _("cannot use post-indexing with this instruction"));
8341
8342 if (is_d)
8343 inst.instruction |= 0x00200000;
8344 else
8345 inst.instruction |= 0x00000900;
8346 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8347 }
8348 else /* unindexed - only for coprocessor */
8349 inst.error = _("instruction does not accept unindexed addressing");
8350 }
8351
8352 /* Table of Thumb instructions which exist in both 16- and 32-bit
8353 encodings (the latter only in post-V6T2 cores). The index is the
8354 value used in the insns table below. When there is more than one
8355 possible 16-bit encoding for the instruction, this table always
8356 holds variant (1).
8357 Also contains several pseudo-instructions used during relaxation. */
8358 #define T16_32_TAB \
8359 X(adc, 4140, eb400000), \
8360 X(adcs, 4140, eb500000), \
8361 X(add, 1c00, eb000000), \
8362 X(adds, 1c00, eb100000), \
8363 X(addi, 0000, f1000000), \
8364 X(addis, 0000, f1100000), \
8365 X(add_pc,000f, f20f0000), \
8366 X(add_sp,000d, f10d0000), \
8367 X(adr, 000f, f20f0000), \
8368 X(and, 4000, ea000000), \
8369 X(ands, 4000, ea100000), \
8370 X(asr, 1000, fa40f000), \
8371 X(asrs, 1000, fa50f000), \
8372 X(b, e000, f000b000), \
8373 X(bcond, d000, f0008000), \
8374 X(bic, 4380, ea200000), \
8375 X(bics, 4380, ea300000), \
8376 X(cmn, 42c0, eb100f00), \
8377 X(cmp, 2800, ebb00f00), \
8378 X(cpsie, b660, f3af8400), \
8379 X(cpsid, b670, f3af8600), \
8380 X(cpy, 4600, ea4f0000), \
8381 X(dec_sp,80dd, f1ad0d00), \
8382 X(eor, 4040, ea800000), \
8383 X(eors, 4040, ea900000), \
8384 X(inc_sp,00dd, f10d0d00), \
8385 X(ldmia, c800, e8900000), \
8386 X(ldr, 6800, f8500000), \
8387 X(ldrb, 7800, f8100000), \
8388 X(ldrh, 8800, f8300000), \
8389 X(ldrsb, 5600, f9100000), \
8390 X(ldrsh, 5e00, f9300000), \
8391 X(ldr_pc,4800, f85f0000), \
8392 X(ldr_pc2,4800, f85f0000), \
8393 X(ldr_sp,9800, f85d0000), \
8394 X(lsl, 0000, fa00f000), \
8395 X(lsls, 0000, fa10f000), \
8396 X(lsr, 0800, fa20f000), \
8397 X(lsrs, 0800, fa30f000), \
8398 X(mov, 2000, ea4f0000), \
8399 X(movs, 2000, ea5f0000), \
8400 X(mul, 4340, fb00f000), \
8401 X(muls, 4340, ffffffff), /* no 32b muls */ \
8402 X(mvn, 43c0, ea6f0000), \
8403 X(mvns, 43c0, ea7f0000), \
8404 X(neg, 4240, f1c00000), /* rsb #0 */ \
8405 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8406 X(orr, 4300, ea400000), \
8407 X(orrs, 4300, ea500000), \
8408 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8409 X(push, b400, e92d0000), /* stmdb sp!,... */ \
8410 X(rev, ba00, fa90f080), \
8411 X(rev16, ba40, fa90f090), \
8412 X(revsh, bac0, fa90f0b0), \
8413 X(ror, 41c0, fa60f000), \
8414 X(rors, 41c0, fa70f000), \
8415 X(sbc, 4180, eb600000), \
8416 X(sbcs, 4180, eb700000), \
8417 X(stmia, c000, e8800000), \
8418 X(str, 6000, f8400000), \
8419 X(strb, 7000, f8000000), \
8420 X(strh, 8000, f8200000), \
8421 X(str_sp,9000, f84d0000), \
8422 X(sub, 1e00, eba00000), \
8423 X(subs, 1e00, ebb00000), \
8424 X(subi, 8000, f1a00000), \
8425 X(subis, 8000, f1b00000), \
8426 X(sxtb, b240, fa4ff080), \
8427 X(sxth, b200, fa0ff080), \
8428 X(tst, 4200, ea100f00), \
8429 X(uxtb, b2c0, fa5ff080), \
8430 X(uxth, b280, fa1ff080), \
8431 X(nop, bf00, f3af8000), \
8432 X(yield, bf10, f3af8001), \
8433 X(wfe, bf20, f3af8002), \
8434 X(wfi, bf30, f3af8003), \
8435 X(sev, bf40, f3af9004), /* typo, 8004? */
8436
8437 /* To catch errors in encoding functions, the codes are all offset by
8438 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8439 as 16-bit instructions. */
8440 #define X(a,b,c) T_MNEM_##a
8441 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8442 #undef X
8443
8444 #define X(a,b,c) 0x##b
8445 static const unsigned short thumb_op16[] = { T16_32_TAB };
8446 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8447 #undef X
8448
8449 #define X(a,b,c) 0x##c
8450 static const unsigned int thumb_op32[] = { T16_32_TAB };
8451 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8452 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8453 #undef X
8454 #undef T16_32_TAB
8455
8456 /* Thumb instruction encoders, in alphabetical order. */
8457
8458 /* ADDW or SUBW. */
8459 static void
8460 do_t_add_sub_w (void)
8461 {
8462 int Rd, Rn;
8463
8464 Rd = inst.operands[0].reg;
8465 Rn = inst.operands[1].reg;
8466
8467 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this is the
8468 SP-{plus,minute}-immediate form of the instruction. */
8469 reject_bad_reg (Rd);
8470
8471 inst.instruction |= (Rn << 16) | (Rd << 8);
8472 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8473 }
8474
8475 /* Parse an add or subtract instruction. We get here with inst.instruction
8476 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8477
8478 static void
8479 do_t_add_sub (void)
8480 {
8481 int Rd, Rs, Rn;
8482
8483 Rd = inst.operands[0].reg;
8484 Rs = (inst.operands[1].present
8485 ? inst.operands[1].reg /* Rd, Rs, foo */
8486 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8487
8488 if (unified_syntax)
8489 {
8490 bfd_boolean flags;
8491 bfd_boolean narrow;
8492 int opcode;
8493
8494 flags = (inst.instruction == T_MNEM_adds
8495 || inst.instruction == T_MNEM_subs);
8496 if (flags)
8497 narrow = (current_it_mask == 0);
8498 else
8499 narrow = (current_it_mask != 0);
8500 if (!inst.operands[2].isreg)
8501 {
8502 int add;
8503
8504 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8505
8506 add = (inst.instruction == T_MNEM_add
8507 || inst.instruction == T_MNEM_adds);
8508 opcode = 0;
8509 if (inst.size_req != 4)
8510 {
8511 /* Attempt to use a narrow opcode, with relaxation if
8512 appropriate. */
8513 if (Rd == REG_SP && Rs == REG_SP && !flags)
8514 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8515 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8516 opcode = T_MNEM_add_sp;
8517 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8518 opcode = T_MNEM_add_pc;
8519 else if (Rd <= 7 && Rs <= 7 && narrow)
8520 {
8521 if (flags)
8522 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8523 else
8524 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8525 }
8526 if (opcode)
8527 {
8528 inst.instruction = THUMB_OP16(opcode);
8529 inst.instruction |= (Rd << 4) | Rs;
8530 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8531 if (inst.size_req != 2)
8532 inst.relax = opcode;
8533 }
8534 else
8535 constraint (inst.size_req == 2, BAD_HIREG);
8536 }
8537 if (inst.size_req == 4
8538 || (inst.size_req != 2 && !opcode))
8539 {
8540 if (Rd == REG_PC)
8541 {
8542 constraint (add, BAD_PC);
8543 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8544 _("only SUBS PC, LR, #const allowed"));
8545 constraint (inst.reloc.exp.X_op != O_constant,
8546 _("expression too complex"));
8547 constraint (inst.reloc.exp.X_add_number < 0
8548 || inst.reloc.exp.X_add_number > 0xff,
8549 _("immediate value out of range"));
8550 inst.instruction = T2_SUBS_PC_LR
8551 | inst.reloc.exp.X_add_number;
8552 inst.reloc.type = BFD_RELOC_UNUSED;
8553 return;
8554 }
8555 else if (Rs == REG_PC)
8556 {
8557 /* Always use addw/subw. */
8558 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8559 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8560 }
8561 else
8562 {
8563 inst.instruction = THUMB_OP32 (inst.instruction);
8564 inst.instruction = (inst.instruction & 0xe1ffffff)
8565 | 0x10000000;
8566 if (flags)
8567 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8568 else
8569 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8570 }
8571 inst.instruction |= Rd << 8;
8572 inst.instruction |= Rs << 16;
8573 }
8574 }
8575 else
8576 {
8577 Rn = inst.operands[2].reg;
8578 /* See if we can do this with a 16-bit instruction. */
8579 if (!inst.operands[2].shifted && inst.size_req != 4)
8580 {
8581 if (Rd > 7 || Rs > 7 || Rn > 7)
8582 narrow = FALSE;
8583
8584 if (narrow)
8585 {
8586 inst.instruction = ((inst.instruction == T_MNEM_adds
8587 || inst.instruction == T_MNEM_add)
8588 ? T_OPCODE_ADD_R3
8589 : T_OPCODE_SUB_R3);
8590 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8591 return;
8592 }
8593
8594 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
8595 {
8596 /* Thumb-1 cores (except v6-M) require at least one high
8597 register in a narrow non flag setting add. */
8598 if (Rd > 7 || Rn > 7
8599 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8600 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
8601 {
8602 if (Rd == Rn)
8603 {
8604 Rn = Rs;
8605 Rs = Rd;
8606 }
8607 inst.instruction = T_OPCODE_ADD_HI;
8608 inst.instruction |= (Rd & 8) << 4;
8609 inst.instruction |= (Rd & 7);
8610 inst.instruction |= Rn << 3;
8611 return;
8612 }
8613 }
8614 }
8615
8616 constraint (Rd == REG_PC, BAD_PC);
8617 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8618 constraint (Rs == REG_PC, BAD_PC);
8619 reject_bad_reg (Rn);
8620
8621 /* If we get here, it can't be done in 16 bits. */
8622 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8623 _("shift must be constant"));
8624 inst.instruction = THUMB_OP32 (inst.instruction);
8625 inst.instruction |= Rd << 8;
8626 inst.instruction |= Rs << 16;
8627 encode_thumb32_shifted_operand (2);
8628 }
8629 }
8630 else
8631 {
8632 constraint (inst.instruction == T_MNEM_adds
8633 || inst.instruction == T_MNEM_subs,
8634 BAD_THUMB32);
8635
8636 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8637 {
8638 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8639 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8640 BAD_HIREG);
8641
8642 inst.instruction = (inst.instruction == T_MNEM_add
8643 ? 0x0000 : 0x8000);
8644 inst.instruction |= (Rd << 4) | Rs;
8645 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8646 return;
8647 }
8648
8649 Rn = inst.operands[2].reg;
8650 constraint (inst.operands[2].shifted, _("unshifted register required"));
8651
8652 /* We now have Rd, Rs, and Rn set to registers. */
8653 if (Rd > 7 || Rs > 7 || Rn > 7)
8654 {
8655 /* Can't do this for SUB. */
8656 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8657 inst.instruction = T_OPCODE_ADD_HI;
8658 inst.instruction |= (Rd & 8) << 4;
8659 inst.instruction |= (Rd & 7);
8660 if (Rs == Rd)
8661 inst.instruction |= Rn << 3;
8662 else if (Rn == Rd)
8663 inst.instruction |= Rs << 3;
8664 else
8665 constraint (1, _("dest must overlap one source register"));
8666 }
8667 else
8668 {
8669 inst.instruction = (inst.instruction == T_MNEM_add
8670 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8671 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8672 }
8673 }
8674 }
8675
8676 static void
8677 do_t_adr (void)
8678 {
8679 unsigned Rd;
8680
8681 Rd = inst.operands[0].reg;
8682 reject_bad_reg (Rd);
8683
8684 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
8685 {
8686 /* Defer to section relaxation. */
8687 inst.relax = inst.instruction;
8688 inst.instruction = THUMB_OP16 (inst.instruction);
8689 inst.instruction |= Rd << 4;
8690 }
8691 else if (unified_syntax && inst.size_req != 2)
8692 {
8693 /* Generate a 32-bit opcode. */
8694 inst.instruction = THUMB_OP32 (inst.instruction);
8695 inst.instruction |= Rd << 8;
8696 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8697 inst.reloc.pc_rel = 1;
8698 }
8699 else
8700 {
8701 /* Generate a 16-bit opcode. */
8702 inst.instruction = THUMB_OP16 (inst.instruction);
8703 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8704 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8705 inst.reloc.pc_rel = 1;
8706
8707 inst.instruction |= Rd << 4;
8708 }
8709 }
8710
8711 /* Arithmetic instructions for which there is just one 16-bit
8712 instruction encoding, and it allows only two low registers.
8713 For maximal compatibility with ARM syntax, we allow three register
8714 operands even when Thumb-32 instructions are not available, as long
8715 as the first two are identical. For instance, both "sbc r0,r1" and
8716 "sbc r0,r0,r1" are allowed. */
8717 static void
8718 do_t_arit3 (void)
8719 {
8720 int Rd, Rs, Rn;
8721
8722 Rd = inst.operands[0].reg;
8723 Rs = (inst.operands[1].present
8724 ? inst.operands[1].reg /* Rd, Rs, foo */
8725 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8726 Rn = inst.operands[2].reg;
8727
8728 reject_bad_reg (Rd);
8729 reject_bad_reg (Rs);
8730 if (inst.operands[2].isreg)
8731 reject_bad_reg (Rn);
8732
8733 if (unified_syntax)
8734 {
8735 if (!inst.operands[2].isreg)
8736 {
8737 /* For an immediate, we always generate a 32-bit opcode;
8738 section relaxation will shrink it later if possible. */
8739 inst.instruction = THUMB_OP32 (inst.instruction);
8740 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8741 inst.instruction |= Rd << 8;
8742 inst.instruction |= Rs << 16;
8743 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8744 }
8745 else
8746 {
8747 bfd_boolean narrow;
8748
8749 /* See if we can do this with a 16-bit instruction. */
8750 if (THUMB_SETS_FLAGS (inst.instruction))
8751 narrow = current_it_mask == 0;
8752 else
8753 narrow = current_it_mask != 0;
8754
8755 if (Rd > 7 || Rn > 7 || Rs > 7)
8756 narrow = FALSE;
8757 if (inst.operands[2].shifted)
8758 narrow = FALSE;
8759 if (inst.size_req == 4)
8760 narrow = FALSE;
8761
8762 if (narrow
8763 && Rd == Rs)
8764 {
8765 inst.instruction = THUMB_OP16 (inst.instruction);
8766 inst.instruction |= Rd;
8767 inst.instruction |= Rn << 3;
8768 return;
8769 }
8770
8771 /* If we get here, it can't be done in 16 bits. */
8772 constraint (inst.operands[2].shifted
8773 && inst.operands[2].immisreg,
8774 _("shift must be constant"));
8775 inst.instruction = THUMB_OP32 (inst.instruction);
8776 inst.instruction |= Rd << 8;
8777 inst.instruction |= Rs << 16;
8778 encode_thumb32_shifted_operand (2);
8779 }
8780 }
8781 else
8782 {
8783 /* On its face this is a lie - the instruction does set the
8784 flags. However, the only supported mnemonic in this mode
8785 says it doesn't. */
8786 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8787
8788 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8789 _("unshifted register required"));
8790 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8791 constraint (Rd != Rs,
8792 _("dest and source1 must be the same register"));
8793
8794 inst.instruction = THUMB_OP16 (inst.instruction);
8795 inst.instruction |= Rd;
8796 inst.instruction |= Rn << 3;
8797 }
8798 }
8799
8800 /* Similarly, but for instructions where the arithmetic operation is
8801 commutative, so we can allow either of them to be different from
8802 the destination operand in a 16-bit instruction. For instance, all
8803 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8804 accepted. */
8805 static void
8806 do_t_arit3c (void)
8807 {
8808 int Rd, Rs, Rn;
8809
8810 Rd = inst.operands[0].reg;
8811 Rs = (inst.operands[1].present
8812 ? inst.operands[1].reg /* Rd, Rs, foo */
8813 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8814 Rn = inst.operands[2].reg;
8815
8816 reject_bad_reg (Rd);
8817 reject_bad_reg (Rs);
8818 if (inst.operands[2].isreg)
8819 reject_bad_reg (Rn);
8820
8821 if (unified_syntax)
8822 {
8823 if (!inst.operands[2].isreg)
8824 {
8825 /* For an immediate, we always generate a 32-bit opcode;
8826 section relaxation will shrink it later if possible. */
8827 inst.instruction = THUMB_OP32 (inst.instruction);
8828 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8829 inst.instruction |= Rd << 8;
8830 inst.instruction |= Rs << 16;
8831 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8832 }
8833 else
8834 {
8835 bfd_boolean narrow;
8836
8837 /* See if we can do this with a 16-bit instruction. */
8838 if (THUMB_SETS_FLAGS (inst.instruction))
8839 narrow = current_it_mask == 0;
8840 else
8841 narrow = current_it_mask != 0;
8842
8843 if (Rd > 7 || Rn > 7 || Rs > 7)
8844 narrow = FALSE;
8845 if (inst.operands[2].shifted)
8846 narrow = FALSE;
8847 if (inst.size_req == 4)
8848 narrow = FALSE;
8849
8850 if (narrow)
8851 {
8852 if (Rd == Rs)
8853 {
8854 inst.instruction = THUMB_OP16 (inst.instruction);
8855 inst.instruction |= Rd;
8856 inst.instruction |= Rn << 3;
8857 return;
8858 }
8859 if (Rd == Rn)
8860 {
8861 inst.instruction = THUMB_OP16 (inst.instruction);
8862 inst.instruction |= Rd;
8863 inst.instruction |= Rs << 3;
8864 return;
8865 }
8866 }
8867
8868 /* If we get here, it can't be done in 16 bits. */
8869 constraint (inst.operands[2].shifted
8870 && inst.operands[2].immisreg,
8871 _("shift must be constant"));
8872 inst.instruction = THUMB_OP32 (inst.instruction);
8873 inst.instruction |= Rd << 8;
8874 inst.instruction |= Rs << 16;
8875 encode_thumb32_shifted_operand (2);
8876 }
8877 }
8878 else
8879 {
8880 /* On its face this is a lie - the instruction does set the
8881 flags. However, the only supported mnemonic in this mode
8882 says it doesn't. */
8883 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
8884
8885 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8886 _("unshifted register required"));
8887 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8888
8889 inst.instruction = THUMB_OP16 (inst.instruction);
8890 inst.instruction |= Rd;
8891
8892 if (Rd == Rs)
8893 inst.instruction |= Rn << 3;
8894 else if (Rd == Rn)
8895 inst.instruction |= Rs << 3;
8896 else
8897 constraint (1, _("dest must overlap one source register"));
8898 }
8899 }
8900
8901 static void
8902 do_t_barrier (void)
8903 {
8904 if (inst.operands[0].present)
8905 {
8906 constraint ((inst.instruction & 0xf0) != 0x40
8907 && inst.operands[0].imm != 0xf,
8908 _("bad barrier type"));
8909 inst.instruction |= inst.operands[0].imm;
8910 }
8911 else
8912 inst.instruction |= 0xf;
8913 }
8914
8915 static void
8916 do_t_bfc (void)
8917 {
8918 unsigned Rd;
8919 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8920 constraint (msb > 32, _("bit-field extends past end of register"));
8921 /* The instruction encoding stores the LSB and MSB,
8922 not the LSB and width. */
8923 Rd = inst.operands[0].reg;
8924 reject_bad_reg (Rd);
8925 inst.instruction |= Rd << 8;
8926 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8927 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8928 inst.instruction |= msb - 1;
8929 }
8930
8931 static void
8932 do_t_bfi (void)
8933 {
8934 int Rd, Rn;
8935 unsigned int msb;
8936
8937 Rd = inst.operands[0].reg;
8938 reject_bad_reg (Rd);
8939
8940 /* #0 in second position is alternative syntax for bfc, which is
8941 the same instruction but with REG_PC in the Rm field. */
8942 if (!inst.operands[1].isreg)
8943 Rn = REG_PC;
8944 else
8945 {
8946 Rn = inst.operands[1].reg;
8947 reject_bad_reg (Rn);
8948 }
8949
8950 msb = inst.operands[2].imm + inst.operands[3].imm;
8951 constraint (msb > 32, _("bit-field extends past end of register"));
8952 /* The instruction encoding stores the LSB and MSB,
8953 not the LSB and width. */
8954 inst.instruction |= Rd << 8;
8955 inst.instruction |= Rn << 16;
8956 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8957 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8958 inst.instruction |= msb - 1;
8959 }
8960
8961 static void
8962 do_t_bfx (void)
8963 {
8964 unsigned Rd, Rn;
8965
8966 Rd = inst.operands[0].reg;
8967 Rn = inst.operands[1].reg;
8968
8969 reject_bad_reg (Rd);
8970 reject_bad_reg (Rn);
8971
8972 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8973 _("bit-field extends past end of register"));
8974 inst.instruction |= Rd << 8;
8975 inst.instruction |= Rn << 16;
8976 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8977 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8978 inst.instruction |= inst.operands[3].imm - 1;
8979 }
8980
8981 /* ARM V5 Thumb BLX (argument parse)
8982 BLX <target_addr> which is BLX(1)
8983 BLX <Rm> which is BLX(2)
8984 Unfortunately, there are two different opcodes for this mnemonic.
8985 So, the insns[].value is not used, and the code here zaps values
8986 into inst.instruction.
8987
8988 ??? How to take advantage of the additional two bits of displacement
8989 available in Thumb32 mode? Need new relocation? */
8990
8991 static void
8992 do_t_blx (void)
8993 {
8994 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
8995 if (inst.operands[0].isreg)
8996 {
8997 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8998 /* We have a register, so this is BLX(2). */
8999 inst.instruction |= inst.operands[0].reg << 3;
9000 }
9001 else
9002 {
9003 /* No register. This must be BLX(1). */
9004 inst.instruction = 0xf000e800;
9005 #ifdef OBJ_ELF
9006 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
9007 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9008 else
9009 #endif
9010 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
9011 inst.reloc.pc_rel = 1;
9012 }
9013 }
9014
9015 static void
9016 do_t_branch (void)
9017 {
9018 int opcode;
9019 int cond;
9020
9021 if (current_it_mask)
9022 {
9023 /* Conditional branches inside IT blocks are encoded as unconditional
9024 branches. */
9025 cond = COND_ALWAYS;
9026 /* A branch must be the last instruction in an IT block. */
9027 constraint (current_it_mask != 0x10, BAD_BRANCH);
9028 }
9029 else
9030 cond = inst.cond;
9031
9032 if (cond != COND_ALWAYS)
9033 opcode = T_MNEM_bcond;
9034 else
9035 opcode = inst.instruction;
9036
9037 if (unified_syntax && inst.size_req == 4)
9038 {
9039 inst.instruction = THUMB_OP32(opcode);
9040 if (cond == COND_ALWAYS)
9041 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
9042 else
9043 {
9044 assert (cond != 0xF);
9045 inst.instruction |= cond << 22;
9046 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9047 }
9048 }
9049 else
9050 {
9051 inst.instruction = THUMB_OP16(opcode);
9052 if (cond == COND_ALWAYS)
9053 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9054 else
9055 {
9056 inst.instruction |= cond << 8;
9057 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
9058 }
9059 /* Allow section relaxation. */
9060 if (unified_syntax && inst.size_req != 2)
9061 inst.relax = opcode;
9062 }
9063
9064 inst.reloc.pc_rel = 1;
9065 }
9066
9067 static void
9068 do_t_bkpt (void)
9069 {
9070 constraint (inst.cond != COND_ALWAYS,
9071 _("instruction is always unconditional"));
9072 if (inst.operands[0].present)
9073 {
9074 constraint (inst.operands[0].imm > 255,
9075 _("immediate value out of range"));
9076 inst.instruction |= inst.operands[0].imm;
9077 }
9078 }
9079
9080 static void
9081 do_t_branch23 (void)
9082 {
9083 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9084 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9085 inst.reloc.pc_rel = 1;
9086
9087 #if defined(OBJ_COFF)
9088 /* If the destination of the branch is a defined symbol which does not have
9089 the THUMB_FUNC attribute, then we must be calling a function which has
9090 the (interfacearm) attribute. We look for the Thumb entry point to that
9091 function and change the branch to refer to that function instead. */
9092 if ( inst.reloc.exp.X_op == O_symbol
9093 && inst.reloc.exp.X_add_symbol != NULL
9094 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9095 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9096 inst.reloc.exp.X_add_symbol =
9097 find_real_start (inst.reloc.exp.X_add_symbol);
9098 #endif
9099 }
9100
9101 static void
9102 do_t_bx (void)
9103 {
9104 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9105 inst.instruction |= inst.operands[0].reg << 3;
9106 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9107 should cause the alignment to be checked once it is known. This is
9108 because BX PC only works if the instruction is word aligned. */
9109 }
9110
9111 static void
9112 do_t_bxj (void)
9113 {
9114 int Rm;
9115
9116 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9117 Rm = inst.operands[0].reg;
9118 reject_bad_reg (Rm);
9119 inst.instruction |= Rm << 16;
9120 }
9121
9122 static void
9123 do_t_clz (void)
9124 {
9125 unsigned Rd;
9126 unsigned Rm;
9127
9128 Rd = inst.operands[0].reg;
9129 Rm = inst.operands[1].reg;
9130
9131 reject_bad_reg (Rd);
9132 reject_bad_reg (Rm);
9133
9134 inst.instruction |= Rd << 8;
9135 inst.instruction |= Rm << 16;
9136 inst.instruction |= Rm;
9137 }
9138
9139 static void
9140 do_t_cps (void)
9141 {
9142 constraint (current_it_mask, BAD_NOT_IT);
9143 inst.instruction |= inst.operands[0].imm;
9144 }
9145
9146 static void
9147 do_t_cpsi (void)
9148 {
9149 constraint (current_it_mask, BAD_NOT_IT);
9150 if (unified_syntax
9151 && (inst.operands[1].present || inst.size_req == 4)
9152 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9153 {
9154 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9155 inst.instruction = 0xf3af8000;
9156 inst.instruction |= imod << 9;
9157 inst.instruction |= inst.operands[0].imm << 5;
9158 if (inst.operands[1].present)
9159 inst.instruction |= 0x100 | inst.operands[1].imm;
9160 }
9161 else
9162 {
9163 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9164 && (inst.operands[0].imm & 4),
9165 _("selected processor does not support 'A' form "
9166 "of this instruction"));
9167 constraint (inst.operands[1].present || inst.size_req == 4,
9168 _("Thumb does not support the 2-argument "
9169 "form of this instruction"));
9170 inst.instruction |= inst.operands[0].imm;
9171 }
9172 }
9173
9174 /* THUMB CPY instruction (argument parse). */
9175
9176 static void
9177 do_t_cpy (void)
9178 {
9179 if (inst.size_req == 4)
9180 {
9181 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9182 inst.instruction |= inst.operands[0].reg << 8;
9183 inst.instruction |= inst.operands[1].reg;
9184 }
9185 else
9186 {
9187 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9188 inst.instruction |= (inst.operands[0].reg & 0x7);
9189 inst.instruction |= inst.operands[1].reg << 3;
9190 }
9191 }
9192
9193 static void
9194 do_t_cbz (void)
9195 {
9196 constraint (current_it_mask, BAD_NOT_IT);
9197 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9198 inst.instruction |= inst.operands[0].reg;
9199 inst.reloc.pc_rel = 1;
9200 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9201 }
9202
9203 static void
9204 do_t_dbg (void)
9205 {
9206 inst.instruction |= inst.operands[0].imm;
9207 }
9208
9209 static void
9210 do_t_div (void)
9211 {
9212 unsigned Rd, Rn, Rm;
9213
9214 Rd = inst.operands[0].reg;
9215 Rn = (inst.operands[1].present
9216 ? inst.operands[1].reg : Rd);
9217 Rm = inst.operands[2].reg;
9218
9219 reject_bad_reg (Rd);
9220 reject_bad_reg (Rn);
9221 reject_bad_reg (Rm);
9222
9223 inst.instruction |= Rd << 8;
9224 inst.instruction |= Rn << 16;
9225 inst.instruction |= Rm;
9226 }
9227
9228 static void
9229 do_t_hint (void)
9230 {
9231 if (unified_syntax && inst.size_req == 4)
9232 inst.instruction = THUMB_OP32 (inst.instruction);
9233 else
9234 inst.instruction = THUMB_OP16 (inst.instruction);
9235 }
9236
9237 static void
9238 do_t_it (void)
9239 {
9240 unsigned int cond = inst.operands[0].imm;
9241
9242 constraint (current_it_mask, BAD_NOT_IT);
9243 current_it_mask = (inst.instruction & 0xf) | 0x10;
9244 current_cc = cond;
9245
9246 /* If the condition is a negative condition, invert the mask. */
9247 if ((cond & 0x1) == 0x0)
9248 {
9249 unsigned int mask = inst.instruction & 0x000f;
9250
9251 if ((mask & 0x7) == 0)
9252 /* no conversion needed */;
9253 else if ((mask & 0x3) == 0)
9254 mask ^= 0x8;
9255 else if ((mask & 0x1) == 0)
9256 mask ^= 0xC;
9257 else
9258 mask ^= 0xE;
9259
9260 inst.instruction &= 0xfff0;
9261 inst.instruction |= mask;
9262 }
9263
9264 inst.instruction |= cond << 4;
9265 }
9266
9267 /* Helper function used for both push/pop and ldm/stm. */
9268 static void
9269 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9270 {
9271 bfd_boolean load;
9272
9273 load = (inst.instruction & (1 << 20)) != 0;
9274
9275 if (mask & (1 << 13))
9276 inst.error = _("SP not allowed in register list");
9277 if (load)
9278 {
9279 if (mask & (1 << 14)
9280 && mask & (1 << 15))
9281 inst.error = _("LR and PC should not both be in register list");
9282
9283 if ((mask & (1 << base)) != 0
9284 && writeback)
9285 as_warn (_("base register should not be in register list "
9286 "when written back"));
9287 }
9288 else
9289 {
9290 if (mask & (1 << 15))
9291 inst.error = _("PC not allowed in register list");
9292
9293 if (mask & (1 << base))
9294 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9295 }
9296
9297 if ((mask & (mask - 1)) == 0)
9298 {
9299 /* Single register transfers implemented as str/ldr. */
9300 if (writeback)
9301 {
9302 if (inst.instruction & (1 << 23))
9303 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9304 else
9305 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9306 }
9307 else
9308 {
9309 if (inst.instruction & (1 << 23))
9310 inst.instruction = 0x00800000; /* ia -> [base] */
9311 else
9312 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9313 }
9314
9315 inst.instruction |= 0xf8400000;
9316 if (load)
9317 inst.instruction |= 0x00100000;
9318
9319 mask = ffs (mask) - 1;
9320 mask <<= 12;
9321 }
9322 else if (writeback)
9323 inst.instruction |= WRITE_BACK;
9324
9325 inst.instruction |= mask;
9326 inst.instruction |= base << 16;
9327 }
9328
9329 static void
9330 do_t_ldmstm (void)
9331 {
9332 /* This really doesn't seem worth it. */
9333 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9334 _("expression too complex"));
9335 constraint (inst.operands[1].writeback,
9336 _("Thumb load/store multiple does not support {reglist}^"));
9337
9338 if (unified_syntax)
9339 {
9340 bfd_boolean narrow;
9341 unsigned mask;
9342
9343 narrow = FALSE;
9344 /* See if we can use a 16-bit instruction. */
9345 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9346 && inst.size_req != 4
9347 && !(inst.operands[1].imm & ~0xff))
9348 {
9349 mask = 1 << inst.operands[0].reg;
9350
9351 if (inst.operands[0].reg <= 7
9352 && (inst.instruction == T_MNEM_stmia
9353 ? inst.operands[0].writeback
9354 : (inst.operands[0].writeback
9355 == !(inst.operands[1].imm & mask))))
9356 {
9357 if (inst.instruction == T_MNEM_stmia
9358 && (inst.operands[1].imm & mask)
9359 && (inst.operands[1].imm & (mask - 1)))
9360 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9361 inst.operands[0].reg);
9362
9363 inst.instruction = THUMB_OP16 (inst.instruction);
9364 inst.instruction |= inst.operands[0].reg << 8;
9365 inst.instruction |= inst.operands[1].imm;
9366 narrow = TRUE;
9367 }
9368 else if (inst.operands[0] .reg == REG_SP
9369 && inst.operands[0].writeback)
9370 {
9371 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9372 ? T_MNEM_push : T_MNEM_pop);
9373 inst.instruction |= inst.operands[1].imm;
9374 narrow = TRUE;
9375 }
9376 }
9377
9378 if (!narrow)
9379 {
9380 if (inst.instruction < 0xffff)
9381 inst.instruction = THUMB_OP32 (inst.instruction);
9382
9383 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9384 inst.operands[0].writeback);
9385 }
9386 }
9387 else
9388 {
9389 constraint (inst.operands[0].reg > 7
9390 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9391 constraint (inst.instruction != T_MNEM_ldmia
9392 && inst.instruction != T_MNEM_stmia,
9393 _("Thumb-2 instruction only valid in unified syntax"));
9394 if (inst.instruction == T_MNEM_stmia)
9395 {
9396 if (!inst.operands[0].writeback)
9397 as_warn (_("this instruction will write back the base register"));
9398 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9399 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9400 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9401 inst.operands[0].reg);
9402 }
9403 else
9404 {
9405 if (!inst.operands[0].writeback
9406 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9407 as_warn (_("this instruction will write back the base register"));
9408 else if (inst.operands[0].writeback
9409 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9410 as_warn (_("this instruction will not write back the base register"));
9411 }
9412
9413 inst.instruction = THUMB_OP16 (inst.instruction);
9414 inst.instruction |= inst.operands[0].reg << 8;
9415 inst.instruction |= inst.operands[1].imm;
9416 }
9417 }
9418
9419 static void
9420 do_t_ldrex (void)
9421 {
9422 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9423 || inst.operands[1].postind || inst.operands[1].writeback
9424 || inst.operands[1].immisreg || inst.operands[1].shifted
9425 || inst.operands[1].negative,
9426 BAD_ADDR_MODE);
9427
9428 inst.instruction |= inst.operands[0].reg << 12;
9429 inst.instruction |= inst.operands[1].reg << 16;
9430 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9431 }
9432
9433 static void
9434 do_t_ldrexd (void)
9435 {
9436 if (!inst.operands[1].present)
9437 {
9438 constraint (inst.operands[0].reg == REG_LR,
9439 _("r14 not allowed as first register "
9440 "when second register is omitted"));
9441 inst.operands[1].reg = inst.operands[0].reg + 1;
9442 }
9443 constraint (inst.operands[0].reg == inst.operands[1].reg,
9444 BAD_OVERLAP);
9445
9446 inst.instruction |= inst.operands[0].reg << 12;
9447 inst.instruction |= inst.operands[1].reg << 8;
9448 inst.instruction |= inst.operands[2].reg << 16;
9449 }
9450
9451 static void
9452 do_t_ldst (void)
9453 {
9454 unsigned long opcode;
9455 int Rn;
9456
9457 opcode = inst.instruction;
9458 if (unified_syntax)
9459 {
9460 if (!inst.operands[1].isreg)
9461 {
9462 if (opcode <= 0xffff)
9463 inst.instruction = THUMB_OP32 (opcode);
9464 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9465 return;
9466 }
9467 if (inst.operands[1].isreg
9468 && !inst.operands[1].writeback
9469 && !inst.operands[1].shifted && !inst.operands[1].postind
9470 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9471 && opcode <= 0xffff
9472 && inst.size_req != 4)
9473 {
9474 /* Insn may have a 16-bit form. */
9475 Rn = inst.operands[1].reg;
9476 if (inst.operands[1].immisreg)
9477 {
9478 inst.instruction = THUMB_OP16 (opcode);
9479 /* [Rn, Rik] */
9480 if (Rn <= 7 && inst.operands[1].imm <= 7)
9481 goto op16;
9482 }
9483 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9484 && opcode != T_MNEM_ldrsb)
9485 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9486 || (Rn == REG_SP && opcode == T_MNEM_str))
9487 {
9488 /* [Rn, #const] */
9489 if (Rn > 7)
9490 {
9491 if (Rn == REG_PC)
9492 {
9493 if (inst.reloc.pc_rel)
9494 opcode = T_MNEM_ldr_pc2;
9495 else
9496 opcode = T_MNEM_ldr_pc;
9497 }
9498 else
9499 {
9500 if (opcode == T_MNEM_ldr)
9501 opcode = T_MNEM_ldr_sp;
9502 else
9503 opcode = T_MNEM_str_sp;
9504 }
9505 inst.instruction = inst.operands[0].reg << 8;
9506 }
9507 else
9508 {
9509 inst.instruction = inst.operands[0].reg;
9510 inst.instruction |= inst.operands[1].reg << 3;
9511 }
9512 inst.instruction |= THUMB_OP16 (opcode);
9513 if (inst.size_req == 2)
9514 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9515 else
9516 inst.relax = opcode;
9517 return;
9518 }
9519 }
9520 /* Definitely a 32-bit variant. */
9521 inst.instruction = THUMB_OP32 (opcode);
9522 inst.instruction |= inst.operands[0].reg << 12;
9523 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9524 return;
9525 }
9526
9527 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9528
9529 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
9530 {
9531 /* Only [Rn,Rm] is acceptable. */
9532 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9533 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9534 || inst.operands[1].postind || inst.operands[1].shifted
9535 || inst.operands[1].negative,
9536 _("Thumb does not support this addressing mode"));
9537 inst.instruction = THUMB_OP16 (inst.instruction);
9538 goto op16;
9539 }
9540
9541 inst.instruction = THUMB_OP16 (inst.instruction);
9542 if (!inst.operands[1].isreg)
9543 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9544 return;
9545
9546 constraint (!inst.operands[1].preind
9547 || inst.operands[1].shifted
9548 || inst.operands[1].writeback,
9549 _("Thumb does not support this addressing mode"));
9550 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
9551 {
9552 constraint (inst.instruction & 0x0600,
9553 _("byte or halfword not valid for base register"));
9554 constraint (inst.operands[1].reg == REG_PC
9555 && !(inst.instruction & THUMB_LOAD_BIT),
9556 _("r15 based store not allowed"));
9557 constraint (inst.operands[1].immisreg,
9558 _("invalid base register for register offset"));
9559
9560 if (inst.operands[1].reg == REG_PC)
9561 inst.instruction = T_OPCODE_LDR_PC;
9562 else if (inst.instruction & THUMB_LOAD_BIT)
9563 inst.instruction = T_OPCODE_LDR_SP;
9564 else
9565 inst.instruction = T_OPCODE_STR_SP;
9566
9567 inst.instruction |= inst.operands[0].reg << 8;
9568 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9569 return;
9570 }
9571
9572 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9573 if (!inst.operands[1].immisreg)
9574 {
9575 /* Immediate offset. */
9576 inst.instruction |= inst.operands[0].reg;
9577 inst.instruction |= inst.operands[1].reg << 3;
9578 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9579 return;
9580 }
9581
9582 /* Register offset. */
9583 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9584 constraint (inst.operands[1].negative,
9585 _("Thumb does not support this addressing mode"));
9586
9587 op16:
9588 switch (inst.instruction)
9589 {
9590 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9591 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9592 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9593 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9594 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9595 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9596 case 0x5600 /* ldrsb */:
9597 case 0x5e00 /* ldrsh */: break;
9598 default: abort ();
9599 }
9600
9601 inst.instruction |= inst.operands[0].reg;
9602 inst.instruction |= inst.operands[1].reg << 3;
9603 inst.instruction |= inst.operands[1].imm << 6;
9604 }
9605
9606 static void
9607 do_t_ldstd (void)
9608 {
9609 if (!inst.operands[1].present)
9610 {
9611 inst.operands[1].reg = inst.operands[0].reg + 1;
9612 constraint (inst.operands[0].reg == REG_LR,
9613 _("r14 not allowed here"));
9614 }
9615 inst.instruction |= inst.operands[0].reg << 12;
9616 inst.instruction |= inst.operands[1].reg << 8;
9617 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9618 }
9619
9620 static void
9621 do_t_ldstt (void)
9622 {
9623 inst.instruction |= inst.operands[0].reg << 12;
9624 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9625 }
9626
9627 static void
9628 do_t_mla (void)
9629 {
9630 unsigned Rd, Rn, Rm, Ra;
9631
9632 Rd = inst.operands[0].reg;
9633 Rn = inst.operands[1].reg;
9634 Rm = inst.operands[2].reg;
9635 Ra = inst.operands[3].reg;
9636
9637 reject_bad_reg (Rd);
9638 reject_bad_reg (Rn);
9639 reject_bad_reg (Rm);
9640 reject_bad_reg (Ra);
9641
9642 inst.instruction |= Rd << 8;
9643 inst.instruction |= Rn << 16;
9644 inst.instruction |= Rm;
9645 inst.instruction |= Ra << 12;
9646 }
9647
9648 static void
9649 do_t_mlal (void)
9650 {
9651 unsigned RdLo, RdHi, Rn, Rm;
9652
9653 RdLo = inst.operands[0].reg;
9654 RdHi = inst.operands[1].reg;
9655 Rn = inst.operands[2].reg;
9656 Rm = inst.operands[3].reg;
9657
9658 reject_bad_reg (RdLo);
9659 reject_bad_reg (RdHi);
9660 reject_bad_reg (Rn);
9661 reject_bad_reg (Rm);
9662
9663 inst.instruction |= RdLo << 12;
9664 inst.instruction |= RdHi << 8;
9665 inst.instruction |= Rn << 16;
9666 inst.instruction |= Rm;
9667 }
9668
9669 static void
9670 do_t_mov_cmp (void)
9671 {
9672 unsigned Rn, Rm;
9673
9674 Rn = inst.operands[0].reg;
9675 Rm = inst.operands[1].reg;
9676
9677 if (unified_syntax)
9678 {
9679 int r0off = (inst.instruction == T_MNEM_mov
9680 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9681 unsigned long opcode;
9682 bfd_boolean narrow;
9683 bfd_boolean low_regs;
9684
9685 low_regs = (Rn <= 7 && Rm <= 7);
9686 opcode = inst.instruction;
9687 if (current_it_mask)
9688 narrow = opcode != T_MNEM_movs;
9689 else
9690 narrow = opcode != T_MNEM_movs || low_regs;
9691 if (inst.size_req == 4
9692 || inst.operands[1].shifted)
9693 narrow = FALSE;
9694
9695 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9696 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9697 && !inst.operands[1].shifted
9698 && Rn == REG_PC
9699 && Rm == REG_LR)
9700 {
9701 inst.instruction = T2_SUBS_PC_LR;
9702 return;
9703 }
9704
9705 if (opcode == T_MNEM_cmp)
9706 {
9707 constraint (Rn == REG_PC, BAD_PC);
9708 if (narrow)
9709 {
9710 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
9711 but valid. */
9712 warn_deprecated_sp (Rm);
9713 /* R15 was documented as a valid choice for Rm in ARMv6,
9714 but as UNPREDICTABLE in ARMv7. ARM's proprietary
9715 tools reject R15, so we do too. */
9716 constraint (Rm == REG_PC, BAD_PC);
9717 }
9718 else
9719 reject_bad_reg (Rm);
9720 }
9721 else if (opcode == T_MNEM_mov
9722 || opcode == T_MNEM_movs)
9723 {
9724 if (inst.operands[1].isreg)
9725 {
9726 if (opcode == T_MNEM_movs)
9727 {
9728 reject_bad_reg (Rn);
9729 reject_bad_reg (Rm);
9730 }
9731 else if ((Rn == REG_SP || Rn == REG_PC)
9732 && (Rm == REG_SP || Rm == REG_PC))
9733 reject_bad_reg (Rm);
9734 }
9735 else
9736 reject_bad_reg (Rn);
9737 }
9738
9739 if (!inst.operands[1].isreg)
9740 {
9741 /* Immediate operand. */
9742 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9743 narrow = 0;
9744 if (low_regs && narrow)
9745 {
9746 inst.instruction = THUMB_OP16 (opcode);
9747 inst.instruction |= Rn << 8;
9748 if (inst.size_req == 2)
9749 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9750 else
9751 inst.relax = opcode;
9752 }
9753 else
9754 {
9755 inst.instruction = THUMB_OP32 (inst.instruction);
9756 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9757 inst.instruction |= Rn << r0off;
9758 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9759 }
9760 }
9761 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9762 && (inst.instruction == T_MNEM_mov
9763 || inst.instruction == T_MNEM_movs))
9764 {
9765 /* Register shifts are encoded as separate shift instructions. */
9766 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9767
9768 if (current_it_mask)
9769 narrow = !flags;
9770 else
9771 narrow = flags;
9772
9773 if (inst.size_req == 4)
9774 narrow = FALSE;
9775
9776 if (!low_regs || inst.operands[1].imm > 7)
9777 narrow = FALSE;
9778
9779 if (Rn != Rm)
9780 narrow = FALSE;
9781
9782 switch (inst.operands[1].shift_kind)
9783 {
9784 case SHIFT_LSL:
9785 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9786 break;
9787 case SHIFT_ASR:
9788 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9789 break;
9790 case SHIFT_LSR:
9791 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9792 break;
9793 case SHIFT_ROR:
9794 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9795 break;
9796 default:
9797 abort ();
9798 }
9799
9800 inst.instruction = opcode;
9801 if (narrow)
9802 {
9803 inst.instruction |= Rn;
9804 inst.instruction |= inst.operands[1].imm << 3;
9805 }
9806 else
9807 {
9808 if (flags)
9809 inst.instruction |= CONDS_BIT;
9810
9811 inst.instruction |= Rn << 8;
9812 inst.instruction |= Rm << 16;
9813 inst.instruction |= inst.operands[1].imm;
9814 }
9815 }
9816 else if (!narrow)
9817 {
9818 /* Some mov with immediate shift have narrow variants.
9819 Register shifts are handled above. */
9820 if (low_regs && inst.operands[1].shifted
9821 && (inst.instruction == T_MNEM_mov
9822 || inst.instruction == T_MNEM_movs))
9823 {
9824 if (current_it_mask)
9825 narrow = (inst.instruction == T_MNEM_mov);
9826 else
9827 narrow = (inst.instruction == T_MNEM_movs);
9828 }
9829
9830 if (narrow)
9831 {
9832 switch (inst.operands[1].shift_kind)
9833 {
9834 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9835 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9836 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9837 default: narrow = FALSE; break;
9838 }
9839 }
9840
9841 if (narrow)
9842 {
9843 inst.instruction |= Rn;
9844 inst.instruction |= Rm << 3;
9845 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9846 }
9847 else
9848 {
9849 inst.instruction = THUMB_OP32 (inst.instruction);
9850 inst.instruction |= Rn << r0off;
9851 encode_thumb32_shifted_operand (1);
9852 }
9853 }
9854 else
9855 switch (inst.instruction)
9856 {
9857 case T_MNEM_mov:
9858 inst.instruction = T_OPCODE_MOV_HR;
9859 inst.instruction |= (Rn & 0x8) << 4;
9860 inst.instruction |= (Rn & 0x7);
9861 inst.instruction |= Rm << 3;
9862 break;
9863
9864 case T_MNEM_movs:
9865 /* We know we have low registers at this point.
9866 Generate ADD Rd, Rs, #0. */
9867 inst.instruction = T_OPCODE_ADD_I3;
9868 inst.instruction |= Rn;
9869 inst.instruction |= Rm << 3;
9870 break;
9871
9872 case T_MNEM_cmp:
9873 if (low_regs)
9874 {
9875 inst.instruction = T_OPCODE_CMP_LR;
9876 inst.instruction |= Rn;
9877 inst.instruction |= Rm << 3;
9878 }
9879 else
9880 {
9881 inst.instruction = T_OPCODE_CMP_HR;
9882 inst.instruction |= (Rn & 0x8) << 4;
9883 inst.instruction |= (Rn & 0x7);
9884 inst.instruction |= Rm << 3;
9885 }
9886 break;
9887 }
9888 return;
9889 }
9890
9891 inst.instruction = THUMB_OP16 (inst.instruction);
9892 if (inst.operands[1].isreg)
9893 {
9894 if (Rn < 8 && Rm < 8)
9895 {
9896 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9897 since a MOV instruction produces unpredictable results. */
9898 if (inst.instruction == T_OPCODE_MOV_I8)
9899 inst.instruction = T_OPCODE_ADD_I3;
9900 else
9901 inst.instruction = T_OPCODE_CMP_LR;
9902
9903 inst.instruction |= Rn;
9904 inst.instruction |= Rm << 3;
9905 }
9906 else
9907 {
9908 if (inst.instruction == T_OPCODE_MOV_I8)
9909 inst.instruction = T_OPCODE_MOV_HR;
9910 else
9911 inst.instruction = T_OPCODE_CMP_HR;
9912 do_t_cpy ();
9913 }
9914 }
9915 else
9916 {
9917 constraint (Rn > 7,
9918 _("only lo regs allowed with immediate"));
9919 inst.instruction |= Rn << 8;
9920 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9921 }
9922 }
9923
9924 static void
9925 do_t_mov16 (void)
9926 {
9927 unsigned Rd;
9928 bfd_vma imm;
9929 bfd_boolean top;
9930
9931 top = (inst.instruction & 0x00800000) != 0;
9932 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9933 {
9934 constraint (top, _(":lower16: not allowed this instruction"));
9935 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9936 }
9937 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9938 {
9939 constraint (!top, _(":upper16: not allowed this instruction"));
9940 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9941 }
9942
9943 Rd = inst.operands[0].reg;
9944 reject_bad_reg (Rd);
9945
9946 inst.instruction |= Rd << 8;
9947 if (inst.reloc.type == BFD_RELOC_UNUSED)
9948 {
9949 imm = inst.reloc.exp.X_add_number;
9950 inst.instruction |= (imm & 0xf000) << 4;
9951 inst.instruction |= (imm & 0x0800) << 15;
9952 inst.instruction |= (imm & 0x0700) << 4;
9953 inst.instruction |= (imm & 0x00ff);
9954 }
9955 }
9956
9957 static void
9958 do_t_mvn_tst (void)
9959 {
9960 unsigned Rn, Rm;
9961
9962 Rn = inst.operands[0].reg;
9963 Rm = inst.operands[1].reg;
9964
9965 if (inst.instruction == T_MNEM_cmp
9966 || inst.instruction == T_MNEM_cmn)
9967 constraint (Rn == REG_PC, BAD_PC);
9968 else
9969 reject_bad_reg (Rn);
9970 reject_bad_reg (Rm);
9971
9972 if (unified_syntax)
9973 {
9974 int r0off = (inst.instruction == T_MNEM_mvn
9975 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
9976 bfd_boolean narrow;
9977
9978 if (inst.size_req == 4
9979 || inst.instruction > 0xffff
9980 || inst.operands[1].shifted
9981 || Rn > 7 || Rm > 7)
9982 narrow = FALSE;
9983 else if (inst.instruction == T_MNEM_cmn)
9984 narrow = TRUE;
9985 else if (THUMB_SETS_FLAGS (inst.instruction))
9986 narrow = (current_it_mask == 0);
9987 else
9988 narrow = (current_it_mask != 0);
9989
9990 if (!inst.operands[1].isreg)
9991 {
9992 /* For an immediate, we always generate a 32-bit opcode;
9993 section relaxation will shrink it later if possible. */
9994 if (inst.instruction < 0xffff)
9995 inst.instruction = THUMB_OP32 (inst.instruction);
9996 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9997 inst.instruction |= Rn << r0off;
9998 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9999 }
10000 else
10001 {
10002 /* See if we can do this with a 16-bit instruction. */
10003 if (narrow)
10004 {
10005 inst.instruction = THUMB_OP16 (inst.instruction);
10006 inst.instruction |= Rn;
10007 inst.instruction |= Rm << 3;
10008 }
10009 else
10010 {
10011 constraint (inst.operands[1].shifted
10012 && inst.operands[1].immisreg,
10013 _("shift must be constant"));
10014 if (inst.instruction < 0xffff)
10015 inst.instruction = THUMB_OP32 (inst.instruction);
10016 inst.instruction |= Rn << r0off;
10017 encode_thumb32_shifted_operand (1);
10018 }
10019 }
10020 }
10021 else
10022 {
10023 constraint (inst.instruction > 0xffff
10024 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10025 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10026 _("unshifted register required"));
10027 constraint (Rn > 7 || Rm > 7,
10028 BAD_HIREG);
10029
10030 inst.instruction = THUMB_OP16 (inst.instruction);
10031 inst.instruction |= Rn;
10032 inst.instruction |= Rm << 3;
10033 }
10034 }
10035
10036 static void
10037 do_t_mrs (void)
10038 {
10039 unsigned Rd;
10040 int flags;
10041
10042 if (do_vfp_nsyn_mrs () == SUCCESS)
10043 return;
10044
10045 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10046 if (flags == 0)
10047 {
10048 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10049 _("selected processor does not support "
10050 "requested special purpose register"));
10051 }
10052 else
10053 {
10054 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10055 _("selected processor does not support "
10056 "requested special purpose register"));
10057 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10058 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10059 _("'CPSR' or 'SPSR' expected"));
10060 }
10061
10062 Rd = inst.operands[0].reg;
10063 reject_bad_reg (Rd);
10064
10065 inst.instruction |= Rd << 8;
10066 inst.instruction |= (flags & SPSR_BIT) >> 2;
10067 inst.instruction |= inst.operands[1].imm & 0xff;
10068 }
10069
10070 static void
10071 do_t_msr (void)
10072 {
10073 int flags;
10074 unsigned Rn;
10075
10076 if (do_vfp_nsyn_msr () == SUCCESS)
10077 return;
10078
10079 constraint (!inst.operands[1].isreg,
10080 _("Thumb encoding does not support an immediate here"));
10081 flags = inst.operands[0].imm;
10082 if (flags & ~0xff)
10083 {
10084 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10085 _("selected processor does not support "
10086 "requested special purpose register"));
10087 }
10088 else
10089 {
10090 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10091 _("selected processor does not support "
10092 "requested special purpose register"));
10093 flags |= PSR_f;
10094 }
10095
10096 Rn = inst.operands[1].reg;
10097 reject_bad_reg (Rn);
10098
10099 inst.instruction |= (flags & SPSR_BIT) >> 2;
10100 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10101 inst.instruction |= (flags & 0xff);
10102 inst.instruction |= Rn << 16;
10103 }
10104
10105 static void
10106 do_t_mul (void)
10107 {
10108 bfd_boolean narrow;
10109 unsigned Rd, Rn, Rm;
10110
10111 if (!inst.operands[2].present)
10112 inst.operands[2].reg = inst.operands[0].reg;
10113
10114 Rd = inst.operands[0].reg;
10115 Rn = inst.operands[1].reg;
10116 Rm = inst.operands[2].reg;
10117
10118 if (unified_syntax)
10119 {
10120 if (inst.size_req == 4
10121 || (Rd != Rn
10122 && Rd != Rm)
10123 || Rn > 7
10124 || Rm > 7)
10125 narrow = FALSE;
10126 else if (inst.instruction == T_MNEM_muls)
10127 narrow = (current_it_mask == 0);
10128 else
10129 narrow = (current_it_mask != 0);
10130 }
10131 else
10132 {
10133 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
10134 constraint (Rn > 7 || Rm > 7,
10135 BAD_HIREG);
10136 narrow = TRUE;
10137 }
10138
10139 if (narrow)
10140 {
10141 /* 16-bit MULS/Conditional MUL. */
10142 inst.instruction = THUMB_OP16 (inst.instruction);
10143 inst.instruction |= Rd;
10144
10145 if (Rd == Rn)
10146 inst.instruction |= Rm << 3;
10147 else if (Rd == Rm)
10148 inst.instruction |= Rn << 3;
10149 else
10150 constraint (1, _("dest must overlap one source register"));
10151 }
10152 else
10153 {
10154 constraint(inst.instruction != T_MNEM_mul,
10155 _("Thumb-2 MUL must not set flags"));
10156 /* 32-bit MUL. */
10157 inst.instruction = THUMB_OP32 (inst.instruction);
10158 inst.instruction |= Rd << 8;
10159 inst.instruction |= Rn << 16;
10160 inst.instruction |= Rm << 0;
10161
10162 reject_bad_reg (Rd);
10163 reject_bad_reg (Rn);
10164 reject_bad_reg (Rm);
10165 }
10166 }
10167
10168 static void
10169 do_t_mull (void)
10170 {
10171 unsigned RdLo, RdHi, Rn, Rm;
10172
10173 RdLo = inst.operands[0].reg;
10174 RdHi = inst.operands[1].reg;
10175 Rn = inst.operands[2].reg;
10176 Rm = inst.operands[3].reg;
10177
10178 reject_bad_reg (RdLo);
10179 reject_bad_reg (RdHi);
10180 reject_bad_reg (Rn);
10181 reject_bad_reg (Rm);
10182
10183 inst.instruction |= RdLo << 12;
10184 inst.instruction |= RdHi << 8;
10185 inst.instruction |= Rn << 16;
10186 inst.instruction |= Rm;
10187
10188 if (RdLo == RdHi)
10189 as_tsktsk (_("rdhi and rdlo must be different"));
10190 }
10191
10192 static void
10193 do_t_nop (void)
10194 {
10195 if (unified_syntax)
10196 {
10197 if (inst.size_req == 4 || inst.operands[0].imm > 15)
10198 {
10199 inst.instruction = THUMB_OP32 (inst.instruction);
10200 inst.instruction |= inst.operands[0].imm;
10201 }
10202 else
10203 {
10204 /* PR9722: Check for Thumb2 availability before
10205 generating a thumb2 nop instruction. */
10206 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10207 {
10208 inst.instruction = THUMB_OP16 (inst.instruction);
10209 inst.instruction |= inst.operands[0].imm << 4;
10210 }
10211 else
10212 inst.instruction = 0x46c0;
10213 }
10214 }
10215 else
10216 {
10217 constraint (inst.operands[0].present,
10218 _("Thumb does not support NOP with hints"));
10219 inst.instruction = 0x46c0;
10220 }
10221 }
10222
10223 static void
10224 do_t_neg (void)
10225 {
10226 if (unified_syntax)
10227 {
10228 bfd_boolean narrow;
10229
10230 if (THUMB_SETS_FLAGS (inst.instruction))
10231 narrow = (current_it_mask == 0);
10232 else
10233 narrow = (current_it_mask != 0);
10234 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10235 narrow = FALSE;
10236 if (inst.size_req == 4)
10237 narrow = FALSE;
10238
10239 if (!narrow)
10240 {
10241 inst.instruction = THUMB_OP32 (inst.instruction);
10242 inst.instruction |= inst.operands[0].reg << 8;
10243 inst.instruction |= inst.operands[1].reg << 16;
10244 }
10245 else
10246 {
10247 inst.instruction = THUMB_OP16 (inst.instruction);
10248 inst.instruction |= inst.operands[0].reg;
10249 inst.instruction |= inst.operands[1].reg << 3;
10250 }
10251 }
10252 else
10253 {
10254 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10255 BAD_HIREG);
10256 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10257
10258 inst.instruction = THUMB_OP16 (inst.instruction);
10259 inst.instruction |= inst.operands[0].reg;
10260 inst.instruction |= inst.operands[1].reg << 3;
10261 }
10262 }
10263
10264 static void
10265 do_t_orn (void)
10266 {
10267 unsigned Rd, Rn;
10268
10269 Rd = inst.operands[0].reg;
10270 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10271
10272 reject_bad_reg (Rd);
10273 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10274 reject_bad_reg (Rn);
10275
10276 inst.instruction |= Rd << 8;
10277 inst.instruction |= Rn << 16;
10278
10279 if (!inst.operands[2].isreg)
10280 {
10281 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10282 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10283 }
10284 else
10285 {
10286 unsigned Rm;
10287
10288 Rm = inst.operands[2].reg;
10289 reject_bad_reg (Rm);
10290
10291 constraint (inst.operands[2].shifted
10292 && inst.operands[2].immisreg,
10293 _("shift must be constant"));
10294 encode_thumb32_shifted_operand (2);
10295 }
10296 }
10297
10298 static void
10299 do_t_pkhbt (void)
10300 {
10301 unsigned Rd, Rn, Rm;
10302
10303 Rd = inst.operands[0].reg;
10304 Rn = inst.operands[1].reg;
10305 Rm = inst.operands[2].reg;
10306
10307 reject_bad_reg (Rd);
10308 reject_bad_reg (Rn);
10309 reject_bad_reg (Rm);
10310
10311 inst.instruction |= Rd << 8;
10312 inst.instruction |= Rn << 16;
10313 inst.instruction |= Rm;
10314 if (inst.operands[3].present)
10315 {
10316 unsigned int val = inst.reloc.exp.X_add_number;
10317 constraint (inst.reloc.exp.X_op != O_constant,
10318 _("expression too complex"));
10319 inst.instruction |= (val & 0x1c) << 10;
10320 inst.instruction |= (val & 0x03) << 6;
10321 }
10322 }
10323
10324 static void
10325 do_t_pkhtb (void)
10326 {
10327 if (!inst.operands[3].present)
10328 inst.instruction &= ~0x00000020;
10329 do_t_pkhbt ();
10330 }
10331
10332 static void
10333 do_t_pld (void)
10334 {
10335 if (inst.operands[0].immisreg)
10336 reject_bad_reg (inst.operands[0].imm);
10337
10338 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10339 }
10340
10341 static void
10342 do_t_push_pop (void)
10343 {
10344 unsigned mask;
10345
10346 constraint (inst.operands[0].writeback,
10347 _("push/pop do not support {reglist}^"));
10348 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10349 _("expression too complex"));
10350
10351 mask = inst.operands[0].imm;
10352 if ((mask & ~0xff) == 0)
10353 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10354 else if ((inst.instruction == T_MNEM_push
10355 && (mask & ~0xff) == 1 << REG_LR)
10356 || (inst.instruction == T_MNEM_pop
10357 && (mask & ~0xff) == 1 << REG_PC))
10358 {
10359 inst.instruction = THUMB_OP16 (inst.instruction);
10360 inst.instruction |= THUMB_PP_PC_LR;
10361 inst.instruction |= mask & 0xff;
10362 }
10363 else if (unified_syntax)
10364 {
10365 inst.instruction = THUMB_OP32 (inst.instruction);
10366 encode_thumb2_ldmstm (13, mask, TRUE);
10367 }
10368 else
10369 {
10370 inst.error = _("invalid register list to push/pop instruction");
10371 return;
10372 }
10373 }
10374
10375 static void
10376 do_t_rbit (void)
10377 {
10378 unsigned Rd, Rm;
10379
10380 Rd = inst.operands[0].reg;
10381 Rm = inst.operands[1].reg;
10382
10383 reject_bad_reg (Rd);
10384 reject_bad_reg (Rm);
10385
10386 inst.instruction |= Rd << 8;
10387 inst.instruction |= Rm << 16;
10388 inst.instruction |= Rm;
10389 }
10390
10391 static void
10392 do_t_rev (void)
10393 {
10394 unsigned Rd, Rm;
10395
10396 Rd = inst.operands[0].reg;
10397 Rm = inst.operands[1].reg;
10398
10399 reject_bad_reg (Rd);
10400 reject_bad_reg (Rm);
10401
10402 if (Rd <= 7 && Rm <= 7
10403 && inst.size_req != 4)
10404 {
10405 inst.instruction = THUMB_OP16 (inst.instruction);
10406 inst.instruction |= Rd;
10407 inst.instruction |= Rm << 3;
10408 }
10409 else if (unified_syntax)
10410 {
10411 inst.instruction = THUMB_OP32 (inst.instruction);
10412 inst.instruction |= Rd << 8;
10413 inst.instruction |= Rm << 16;
10414 inst.instruction |= Rm;
10415 }
10416 else
10417 inst.error = BAD_HIREG;
10418 }
10419
10420 static void
10421 do_t_rrx (void)
10422 {
10423 unsigned Rd, Rm;
10424
10425 Rd = inst.operands[0].reg;
10426 Rm = inst.operands[1].reg;
10427
10428 reject_bad_reg (Rd);
10429 reject_bad_reg (Rm);
10430
10431 inst.instruction |= Rd << 8;
10432 inst.instruction |= Rm;
10433 }
10434
10435 static void
10436 do_t_rsb (void)
10437 {
10438 unsigned Rd, Rs;
10439
10440 Rd = inst.operands[0].reg;
10441 Rs = (inst.operands[1].present
10442 ? inst.operands[1].reg /* Rd, Rs, foo */
10443 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10444
10445 reject_bad_reg (Rd);
10446 reject_bad_reg (Rs);
10447 if (inst.operands[2].isreg)
10448 reject_bad_reg (inst.operands[2].reg);
10449
10450 inst.instruction |= Rd << 8;
10451 inst.instruction |= Rs << 16;
10452 if (!inst.operands[2].isreg)
10453 {
10454 bfd_boolean narrow;
10455
10456 if ((inst.instruction & 0x00100000) != 0)
10457 narrow = (current_it_mask == 0);
10458 else
10459 narrow = (current_it_mask != 0);
10460
10461 if (Rd > 7 || Rs > 7)
10462 narrow = FALSE;
10463
10464 if (inst.size_req == 4 || !unified_syntax)
10465 narrow = FALSE;
10466
10467 if (inst.reloc.exp.X_op != O_constant
10468 || inst.reloc.exp.X_add_number != 0)
10469 narrow = FALSE;
10470
10471 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10472 relaxation, but it doesn't seem worth the hassle. */
10473 if (narrow)
10474 {
10475 inst.reloc.type = BFD_RELOC_UNUSED;
10476 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10477 inst.instruction |= Rs << 3;
10478 inst.instruction |= Rd;
10479 }
10480 else
10481 {
10482 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10483 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10484 }
10485 }
10486 else
10487 encode_thumb32_shifted_operand (2);
10488 }
10489
10490 static void
10491 do_t_setend (void)
10492 {
10493 constraint (current_it_mask, BAD_NOT_IT);
10494 if (inst.operands[0].imm)
10495 inst.instruction |= 0x8;
10496 }
10497
10498 static void
10499 do_t_shift (void)
10500 {
10501 if (!inst.operands[1].present)
10502 inst.operands[1].reg = inst.operands[0].reg;
10503
10504 if (unified_syntax)
10505 {
10506 bfd_boolean narrow;
10507 int shift_kind;
10508
10509 switch (inst.instruction)
10510 {
10511 case T_MNEM_asr:
10512 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10513 case T_MNEM_lsl:
10514 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10515 case T_MNEM_lsr:
10516 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10517 case T_MNEM_ror:
10518 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10519 default: abort ();
10520 }
10521
10522 if (THUMB_SETS_FLAGS (inst.instruction))
10523 narrow = (current_it_mask == 0);
10524 else
10525 narrow = (current_it_mask != 0);
10526 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10527 narrow = FALSE;
10528 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10529 narrow = FALSE;
10530 if (inst.operands[2].isreg
10531 && (inst.operands[1].reg != inst.operands[0].reg
10532 || inst.operands[2].reg > 7))
10533 narrow = FALSE;
10534 if (inst.size_req == 4)
10535 narrow = FALSE;
10536
10537 reject_bad_reg (inst.operands[0].reg);
10538 reject_bad_reg (inst.operands[1].reg);
10539
10540 if (!narrow)
10541 {
10542 if (inst.operands[2].isreg)
10543 {
10544 reject_bad_reg (inst.operands[2].reg);
10545 inst.instruction = THUMB_OP32 (inst.instruction);
10546 inst.instruction |= inst.operands[0].reg << 8;
10547 inst.instruction |= inst.operands[1].reg << 16;
10548 inst.instruction |= inst.operands[2].reg;
10549 }
10550 else
10551 {
10552 inst.operands[1].shifted = 1;
10553 inst.operands[1].shift_kind = shift_kind;
10554 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10555 ? T_MNEM_movs : T_MNEM_mov);
10556 inst.instruction |= inst.operands[0].reg << 8;
10557 encode_thumb32_shifted_operand (1);
10558 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10559 inst.reloc.type = BFD_RELOC_UNUSED;
10560 }
10561 }
10562 else
10563 {
10564 if (inst.operands[2].isreg)
10565 {
10566 switch (shift_kind)
10567 {
10568 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10569 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10570 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10571 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
10572 default: abort ();
10573 }
10574
10575 inst.instruction |= inst.operands[0].reg;
10576 inst.instruction |= inst.operands[2].reg << 3;
10577 }
10578 else
10579 {
10580 switch (shift_kind)
10581 {
10582 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10583 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10584 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10585 default: abort ();
10586 }
10587 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10588 inst.instruction |= inst.operands[0].reg;
10589 inst.instruction |= inst.operands[1].reg << 3;
10590 }
10591 }
10592 }
10593 else
10594 {
10595 constraint (inst.operands[0].reg > 7
10596 || inst.operands[1].reg > 7, BAD_HIREG);
10597 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10598
10599 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10600 {
10601 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10602 constraint (inst.operands[0].reg != inst.operands[1].reg,
10603 _("source1 and dest must be same register"));
10604
10605 switch (inst.instruction)
10606 {
10607 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10608 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10609 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10610 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10611 default: abort ();
10612 }
10613
10614 inst.instruction |= inst.operands[0].reg;
10615 inst.instruction |= inst.operands[2].reg << 3;
10616 }
10617 else
10618 {
10619 switch (inst.instruction)
10620 {
10621 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10622 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10623 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10624 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10625 default: abort ();
10626 }
10627 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10628 inst.instruction |= inst.operands[0].reg;
10629 inst.instruction |= inst.operands[1].reg << 3;
10630 }
10631 }
10632 }
10633
10634 static void
10635 do_t_simd (void)
10636 {
10637 unsigned Rd, Rn, Rm;
10638
10639 Rd = inst.operands[0].reg;
10640 Rn = inst.operands[1].reg;
10641 Rm = inst.operands[2].reg;
10642
10643 reject_bad_reg (Rd);
10644 reject_bad_reg (Rn);
10645 reject_bad_reg (Rm);
10646
10647 inst.instruction |= Rd << 8;
10648 inst.instruction |= Rn << 16;
10649 inst.instruction |= Rm;
10650 }
10651
10652 static void
10653 do_t_smc (void)
10654 {
10655 unsigned int value = inst.reloc.exp.X_add_number;
10656 constraint (inst.reloc.exp.X_op != O_constant,
10657 _("expression too complex"));
10658 inst.reloc.type = BFD_RELOC_UNUSED;
10659 inst.instruction |= (value & 0xf000) >> 12;
10660 inst.instruction |= (value & 0x0ff0);
10661 inst.instruction |= (value & 0x000f) << 16;
10662 }
10663
10664 static void
10665 do_t_ssat (void)
10666 {
10667 unsigned Rd, Rn;
10668
10669 Rd = inst.operands[0].reg;
10670 Rn = inst.operands[2].reg;
10671
10672 reject_bad_reg (Rd);
10673 reject_bad_reg (Rn);
10674
10675 inst.instruction |= Rd << 8;
10676 inst.instruction |= inst.operands[1].imm - 1;
10677 inst.instruction |= Rn << 16;
10678
10679 if (inst.operands[3].present)
10680 {
10681 constraint (inst.reloc.exp.X_op != O_constant,
10682 _("expression too complex"));
10683
10684 if (inst.reloc.exp.X_add_number != 0)
10685 {
10686 if (inst.operands[3].shift_kind == SHIFT_ASR)
10687 inst.instruction |= 0x00200000; /* sh bit */
10688 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10689 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10690 }
10691 inst.reloc.type = BFD_RELOC_UNUSED;
10692 }
10693 }
10694
10695 static void
10696 do_t_ssat16 (void)
10697 {
10698 unsigned Rd, Rn;
10699
10700 Rd = inst.operands[0].reg;
10701 Rn = inst.operands[2].reg;
10702
10703 reject_bad_reg (Rd);
10704 reject_bad_reg (Rn);
10705
10706 inst.instruction |= Rd << 8;
10707 inst.instruction |= inst.operands[1].imm - 1;
10708 inst.instruction |= Rn << 16;
10709 }
10710
10711 static void
10712 do_t_strex (void)
10713 {
10714 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10715 || inst.operands[2].postind || inst.operands[2].writeback
10716 || inst.operands[2].immisreg || inst.operands[2].shifted
10717 || inst.operands[2].negative,
10718 BAD_ADDR_MODE);
10719
10720 inst.instruction |= inst.operands[0].reg << 8;
10721 inst.instruction |= inst.operands[1].reg << 12;
10722 inst.instruction |= inst.operands[2].reg << 16;
10723 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
10724 }
10725
10726 static void
10727 do_t_strexd (void)
10728 {
10729 if (!inst.operands[2].present)
10730 inst.operands[2].reg = inst.operands[1].reg + 1;
10731
10732 constraint (inst.operands[0].reg == inst.operands[1].reg
10733 || inst.operands[0].reg == inst.operands[2].reg
10734 || inst.operands[0].reg == inst.operands[3].reg
10735 || inst.operands[1].reg == inst.operands[2].reg,
10736 BAD_OVERLAP);
10737
10738 inst.instruction |= inst.operands[0].reg;
10739 inst.instruction |= inst.operands[1].reg << 12;
10740 inst.instruction |= inst.operands[2].reg << 8;
10741 inst.instruction |= inst.operands[3].reg << 16;
10742 }
10743
10744 static void
10745 do_t_sxtah (void)
10746 {
10747 unsigned Rd, Rn, Rm;
10748
10749 Rd = inst.operands[0].reg;
10750 Rn = inst.operands[1].reg;
10751 Rm = inst.operands[2].reg;
10752
10753 reject_bad_reg (Rd);
10754 reject_bad_reg (Rn);
10755 reject_bad_reg (Rm);
10756
10757 inst.instruction |= Rd << 8;
10758 inst.instruction |= Rn << 16;
10759 inst.instruction |= Rm;
10760 inst.instruction |= inst.operands[3].imm << 4;
10761 }
10762
10763 static void
10764 do_t_sxth (void)
10765 {
10766 unsigned Rd, Rm;
10767
10768 Rd = inst.operands[0].reg;
10769 Rm = inst.operands[1].reg;
10770
10771 reject_bad_reg (Rd);
10772 reject_bad_reg (Rm);
10773
10774 if (inst.instruction <= 0xffff && inst.size_req != 4
10775 && Rd <= 7 && Rm <= 7
10776 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10777 {
10778 inst.instruction = THUMB_OP16 (inst.instruction);
10779 inst.instruction |= Rd;
10780 inst.instruction |= Rm << 3;
10781 }
10782 else if (unified_syntax)
10783 {
10784 if (inst.instruction <= 0xffff)
10785 inst.instruction = THUMB_OP32 (inst.instruction);
10786 inst.instruction |= Rd << 8;
10787 inst.instruction |= Rm;
10788 inst.instruction |= inst.operands[2].imm << 4;
10789 }
10790 else
10791 {
10792 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10793 _("Thumb encoding does not support rotation"));
10794 constraint (1, BAD_HIREG);
10795 }
10796 }
10797
10798 static void
10799 do_t_swi (void)
10800 {
10801 inst.reloc.type = BFD_RELOC_ARM_SWI;
10802 }
10803
10804 static void
10805 do_t_tb (void)
10806 {
10807 unsigned Rn, Rm;
10808 int half;
10809
10810 half = (inst.instruction & 0x10) != 0;
10811 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10812 constraint (inst.operands[0].immisreg,
10813 _("instruction requires register index"));
10814
10815 Rn = inst.operands[0].reg;
10816 Rm = inst.operands[0].imm;
10817
10818 constraint (Rn == REG_SP, BAD_SP);
10819 reject_bad_reg (Rm);
10820
10821 constraint (!half && inst.operands[0].shifted,
10822 _("instruction does not allow shifted index"));
10823 inst.instruction |= (Rn << 16) | Rm;
10824 }
10825
10826 static void
10827 do_t_usat (void)
10828 {
10829 unsigned Rd, Rn;
10830
10831 Rd = inst.operands[0].reg;
10832 Rn = inst.operands[2].reg;
10833
10834 reject_bad_reg (Rd);
10835 reject_bad_reg (Rn);
10836
10837 inst.instruction |= Rd << 8;
10838 inst.instruction |= inst.operands[1].imm;
10839 inst.instruction |= Rn << 16;
10840
10841 if (inst.operands[3].present)
10842 {
10843 constraint (inst.reloc.exp.X_op != O_constant,
10844 _("expression too complex"));
10845 if (inst.reloc.exp.X_add_number != 0)
10846 {
10847 if (inst.operands[3].shift_kind == SHIFT_ASR)
10848 inst.instruction |= 0x00200000; /* sh bit */
10849
10850 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10851 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10852 }
10853 inst.reloc.type = BFD_RELOC_UNUSED;
10854 }
10855 }
10856
10857 static void
10858 do_t_usat16 (void)
10859 {
10860 unsigned Rd, Rn;
10861
10862 Rd = inst.operands[0].reg;
10863 Rn = inst.operands[2].reg;
10864
10865 reject_bad_reg (Rd);
10866 reject_bad_reg (Rn);
10867
10868 inst.instruction |= Rd << 8;
10869 inst.instruction |= inst.operands[1].imm;
10870 inst.instruction |= Rn << 16;
10871 }
10872
10873 /* Neon instruction encoder helpers. */
10874
10875 /* Encodings for the different types for various Neon opcodes. */
10876
10877 /* An "invalid" code for the following tables. */
10878 #define N_INV -1u
10879
10880 struct neon_tab_entry
10881 {
10882 unsigned integer;
10883 unsigned float_or_poly;
10884 unsigned scalar_or_imm;
10885 };
10886
10887 /* Map overloaded Neon opcodes to their respective encodings. */
10888 #define NEON_ENC_TAB \
10889 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10890 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10891 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10892 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10893 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10894 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10895 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10896 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10897 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10898 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10899 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10900 /* Register variants of the following two instructions are encoded as
10901 vcge / vcgt with the operands reversed. */ \
10902 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10903 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
10904 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10905 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10906 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10907 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10908 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10909 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10910 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10911 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10912 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10913 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10914 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10915 X(vshl, 0x0000400, N_INV, 0x0800510), \
10916 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10917 X(vand, 0x0000110, N_INV, 0x0800030), \
10918 X(vbic, 0x0100110, N_INV, 0x0800030), \
10919 X(veor, 0x1000110, N_INV, N_INV), \
10920 X(vorn, 0x0300110, N_INV, 0x0800010), \
10921 X(vorr, 0x0200110, N_INV, 0x0800010), \
10922 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10923 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10924 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10925 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10926 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10927 X(vst1, 0x0000000, 0x0800000, N_INV), \
10928 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10929 X(vst2, 0x0000100, 0x0800100, N_INV), \
10930 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10931 X(vst3, 0x0000200, 0x0800200, N_INV), \
10932 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10933 X(vst4, 0x0000300, 0x0800300, N_INV), \
10934 X(vmovn, 0x1b20200, N_INV, N_INV), \
10935 X(vtrn, 0x1b20080, N_INV, N_INV), \
10936 X(vqmovn, 0x1b20200, N_INV, N_INV), \
10937 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10938 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10939 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10940 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10941 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10942 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10943 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10944 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
10945
10946 enum neon_opc
10947 {
10948 #define X(OPC,I,F,S) N_MNEM_##OPC
10949 NEON_ENC_TAB
10950 #undef X
10951 };
10952
10953 static const struct neon_tab_entry neon_enc_tab[] =
10954 {
10955 #define X(OPC,I,F,S) { (I), (F), (S) }
10956 NEON_ENC_TAB
10957 #undef X
10958 };
10959
10960 #define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10961 #define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10962 #define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10963 #define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10964 #define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10965 #define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10966 #define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10967 #define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10968 #define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10969 #define NEON_ENC_SINGLE(X) \
10970 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10971 #define NEON_ENC_DOUBLE(X) \
10972 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
10973
10974 /* Define shapes for instruction operands. The following mnemonic characters
10975 are used in this table:
10976
10977 F - VFP S<n> register
10978 D - Neon D<n> register
10979 Q - Neon Q<n> register
10980 I - Immediate
10981 S - Scalar
10982 R - ARM register
10983 L - D<n> register list
10984
10985 This table is used to generate various data:
10986 - enumerations of the form NS_DDR to be used as arguments to
10987 neon_select_shape.
10988 - a table classifying shapes into single, double, quad, mixed.
10989 - a table used to drive neon_select_shape. */
10990
10991 #define NEON_SHAPE_DEF \
10992 X(3, (D, D, D), DOUBLE), \
10993 X(3, (Q, Q, Q), QUAD), \
10994 X(3, (D, D, I), DOUBLE), \
10995 X(3, (Q, Q, I), QUAD), \
10996 X(3, (D, D, S), DOUBLE), \
10997 X(3, (Q, Q, S), QUAD), \
10998 X(2, (D, D), DOUBLE), \
10999 X(2, (Q, Q), QUAD), \
11000 X(2, (D, S), DOUBLE), \
11001 X(2, (Q, S), QUAD), \
11002 X(2, (D, R), DOUBLE), \
11003 X(2, (Q, R), QUAD), \
11004 X(2, (D, I), DOUBLE), \
11005 X(2, (Q, I), QUAD), \
11006 X(3, (D, L, D), DOUBLE), \
11007 X(2, (D, Q), MIXED), \
11008 X(2, (Q, D), MIXED), \
11009 X(3, (D, Q, I), MIXED), \
11010 X(3, (Q, D, I), MIXED), \
11011 X(3, (Q, D, D), MIXED), \
11012 X(3, (D, Q, Q), MIXED), \
11013 X(3, (Q, Q, D), MIXED), \
11014 X(3, (Q, D, S), MIXED), \
11015 X(3, (D, Q, S), MIXED), \
11016 X(4, (D, D, D, I), DOUBLE), \
11017 X(4, (Q, Q, Q, I), QUAD), \
11018 X(2, (F, F), SINGLE), \
11019 X(3, (F, F, F), SINGLE), \
11020 X(2, (F, I), SINGLE), \
11021 X(2, (F, D), MIXED), \
11022 X(2, (D, F), MIXED), \
11023 X(3, (F, F, I), MIXED), \
11024 X(4, (R, R, F, F), SINGLE), \
11025 X(4, (F, F, R, R), SINGLE), \
11026 X(3, (D, R, R), DOUBLE), \
11027 X(3, (R, R, D), DOUBLE), \
11028 X(2, (S, R), SINGLE), \
11029 X(2, (R, S), SINGLE), \
11030 X(2, (F, R), SINGLE), \
11031 X(2, (R, F), SINGLE)
11032
11033 #define S2(A,B) NS_##A##B
11034 #define S3(A,B,C) NS_##A##B##C
11035 #define S4(A,B,C,D) NS_##A##B##C##D
11036
11037 #define X(N, L, C) S##N L
11038
11039 enum neon_shape
11040 {
11041 NEON_SHAPE_DEF,
11042 NS_NULL
11043 };
11044
11045 #undef X
11046 #undef S2
11047 #undef S3
11048 #undef S4
11049
11050 enum neon_shape_class
11051 {
11052 SC_SINGLE,
11053 SC_DOUBLE,
11054 SC_QUAD,
11055 SC_MIXED
11056 };
11057
11058 #define X(N, L, C) SC_##C
11059
11060 static enum neon_shape_class neon_shape_class[] =
11061 {
11062 NEON_SHAPE_DEF
11063 };
11064
11065 #undef X
11066
11067 enum neon_shape_el
11068 {
11069 SE_F,
11070 SE_D,
11071 SE_Q,
11072 SE_I,
11073 SE_S,
11074 SE_R,
11075 SE_L
11076 };
11077
11078 /* Register widths of above. */
11079 static unsigned neon_shape_el_size[] =
11080 {
11081 32,
11082 64,
11083 128,
11084 0,
11085 32,
11086 32,
11087 0
11088 };
11089
11090 struct neon_shape_info
11091 {
11092 unsigned els;
11093 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11094 };
11095
11096 #define S2(A,B) { SE_##A, SE_##B }
11097 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11098 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11099
11100 #define X(N, L, C) { N, S##N L }
11101
11102 static struct neon_shape_info neon_shape_tab[] =
11103 {
11104 NEON_SHAPE_DEF
11105 };
11106
11107 #undef X
11108 #undef S2
11109 #undef S3
11110 #undef S4
11111
11112 /* Bit masks used in type checking given instructions.
11113 'N_EQK' means the type must be the same as (or based on in some way) the key
11114 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11115 set, various other bits can be set as well in order to modify the meaning of
11116 the type constraint. */
11117
11118 enum neon_type_mask
11119 {
11120 N_S8 = 0x0000001,
11121 N_S16 = 0x0000002,
11122 N_S32 = 0x0000004,
11123 N_S64 = 0x0000008,
11124 N_U8 = 0x0000010,
11125 N_U16 = 0x0000020,
11126 N_U32 = 0x0000040,
11127 N_U64 = 0x0000080,
11128 N_I8 = 0x0000100,
11129 N_I16 = 0x0000200,
11130 N_I32 = 0x0000400,
11131 N_I64 = 0x0000800,
11132 N_8 = 0x0001000,
11133 N_16 = 0x0002000,
11134 N_32 = 0x0004000,
11135 N_64 = 0x0008000,
11136 N_P8 = 0x0010000,
11137 N_P16 = 0x0020000,
11138 N_F16 = 0x0040000,
11139 N_F32 = 0x0080000,
11140 N_F64 = 0x0100000,
11141 N_KEY = 0x1000000, /* key element (main type specifier). */
11142 N_EQK = 0x2000000, /* given operand has the same type & size as the key. */
11143 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11144 N_DBL = 0x0000001, /* if N_EQK, this operand is twice the size. */
11145 N_HLF = 0x0000002, /* if N_EQK, this operand is half the size. */
11146 N_SGN = 0x0000004, /* if N_EQK, this operand is forced to be signed. */
11147 N_UNS = 0x0000008, /* if N_EQK, this operand is forced to be unsigned. */
11148 N_INT = 0x0000010, /* if N_EQK, this operand is forced to be integer. */
11149 N_FLT = 0x0000020, /* if N_EQK, this operand is forced to be float. */
11150 N_SIZ = 0x0000040, /* if N_EQK, this operand is forced to be size-only. */
11151 N_UTYP = 0,
11152 N_MAX_NONSPECIAL = N_F64
11153 };
11154
11155 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11156
11157 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11158 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11159 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11160 #define N_SUF_32 (N_SU_32 | N_F32)
11161 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11162 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11163
11164 /* Pass this as the first type argument to neon_check_type to ignore types
11165 altogether. */
11166 #define N_IGNORE_TYPE (N_KEY | N_EQK)
11167
11168 /* Select a "shape" for the current instruction (describing register types or
11169 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11170 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11171 function of operand parsing, so this function doesn't need to be called.
11172 Shapes should be listed in order of decreasing length. */
11173
11174 static enum neon_shape
11175 neon_select_shape (enum neon_shape shape, ...)
11176 {
11177 va_list ap;
11178 enum neon_shape first_shape = shape;
11179
11180 /* Fix missing optional operands. FIXME: we don't know at this point how
11181 many arguments we should have, so this makes the assumption that we have
11182 > 1. This is true of all current Neon opcodes, I think, but may not be
11183 true in the future. */
11184 if (!inst.operands[1].present)
11185 inst.operands[1] = inst.operands[0];
11186
11187 va_start (ap, shape);
11188
11189 for (; shape != NS_NULL; shape = va_arg (ap, int))
11190 {
11191 unsigned j;
11192 int matches = 1;
11193
11194 for (j = 0; j < neon_shape_tab[shape].els; j++)
11195 {
11196 if (!inst.operands[j].present)
11197 {
11198 matches = 0;
11199 break;
11200 }
11201
11202 switch (neon_shape_tab[shape].el[j])
11203 {
11204 case SE_F:
11205 if (!(inst.operands[j].isreg
11206 && inst.operands[j].isvec
11207 && inst.operands[j].issingle
11208 && !inst.operands[j].isquad))
11209 matches = 0;
11210 break;
11211
11212 case SE_D:
11213 if (!(inst.operands[j].isreg
11214 && inst.operands[j].isvec
11215 && !inst.operands[j].isquad
11216 && !inst.operands[j].issingle))
11217 matches = 0;
11218 break;
11219
11220 case SE_R:
11221 if (!(inst.operands[j].isreg
11222 && !inst.operands[j].isvec))
11223 matches = 0;
11224 break;
11225
11226 case SE_Q:
11227 if (!(inst.operands[j].isreg
11228 && inst.operands[j].isvec
11229 && inst.operands[j].isquad
11230 && !inst.operands[j].issingle))
11231 matches = 0;
11232 break;
11233
11234 case SE_I:
11235 if (!(!inst.operands[j].isreg
11236 && !inst.operands[j].isscalar))
11237 matches = 0;
11238 break;
11239
11240 case SE_S:
11241 if (!(!inst.operands[j].isreg
11242 && inst.operands[j].isscalar))
11243 matches = 0;
11244 break;
11245
11246 case SE_L:
11247 break;
11248 }
11249 }
11250 if (matches)
11251 break;
11252 }
11253
11254 va_end (ap);
11255
11256 if (shape == NS_NULL && first_shape != NS_NULL)
11257 first_error (_("invalid instruction shape"));
11258
11259 return shape;
11260 }
11261
11262 /* True if SHAPE is predominantly a quadword operation (most of the time, this
11263 means the Q bit should be set). */
11264
11265 static int
11266 neon_quad (enum neon_shape shape)
11267 {
11268 return neon_shape_class[shape] == SC_QUAD;
11269 }
11270
11271 static void
11272 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11273 unsigned *g_size)
11274 {
11275 /* Allow modification to be made to types which are constrained to be
11276 based on the key element, based on bits set alongside N_EQK. */
11277 if ((typebits & N_EQK) != 0)
11278 {
11279 if ((typebits & N_HLF) != 0)
11280 *g_size /= 2;
11281 else if ((typebits & N_DBL) != 0)
11282 *g_size *= 2;
11283 if ((typebits & N_SGN) != 0)
11284 *g_type = NT_signed;
11285 else if ((typebits & N_UNS) != 0)
11286 *g_type = NT_unsigned;
11287 else if ((typebits & N_INT) != 0)
11288 *g_type = NT_integer;
11289 else if ((typebits & N_FLT) != 0)
11290 *g_type = NT_float;
11291 else if ((typebits & N_SIZ) != 0)
11292 *g_type = NT_untyped;
11293 }
11294 }
11295
11296 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11297 operand type, i.e. the single type specified in a Neon instruction when it
11298 is the only one given. */
11299
11300 static struct neon_type_el
11301 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11302 {
11303 struct neon_type_el dest = *key;
11304
11305 assert ((thisarg & N_EQK) != 0);
11306
11307 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11308
11309 return dest;
11310 }
11311
11312 /* Convert Neon type and size into compact bitmask representation. */
11313
11314 static enum neon_type_mask
11315 type_chk_of_el_type (enum neon_el_type type, unsigned size)
11316 {
11317 switch (type)
11318 {
11319 case NT_untyped:
11320 switch (size)
11321 {
11322 case 8: return N_8;
11323 case 16: return N_16;
11324 case 32: return N_32;
11325 case 64: return N_64;
11326 default: ;
11327 }
11328 break;
11329
11330 case NT_integer:
11331 switch (size)
11332 {
11333 case 8: return N_I8;
11334 case 16: return N_I16;
11335 case 32: return N_I32;
11336 case 64: return N_I64;
11337 default: ;
11338 }
11339 break;
11340
11341 case NT_float:
11342 switch (size)
11343 {
11344 case 16: return N_F16;
11345 case 32: return N_F32;
11346 case 64: return N_F64;
11347 default: ;
11348 }
11349 break;
11350
11351 case NT_poly:
11352 switch (size)
11353 {
11354 case 8: return N_P8;
11355 case 16: return N_P16;
11356 default: ;
11357 }
11358 break;
11359
11360 case NT_signed:
11361 switch (size)
11362 {
11363 case 8: return N_S8;
11364 case 16: return N_S16;
11365 case 32: return N_S32;
11366 case 64: return N_S64;
11367 default: ;
11368 }
11369 break;
11370
11371 case NT_unsigned:
11372 switch (size)
11373 {
11374 case 8: return N_U8;
11375 case 16: return N_U16;
11376 case 32: return N_U32;
11377 case 64: return N_U64;
11378 default: ;
11379 }
11380 break;
11381
11382 default: ;
11383 }
11384
11385 return N_UTYP;
11386 }
11387
11388 /* Convert compact Neon bitmask type representation to a type and size. Only
11389 handles the case where a single bit is set in the mask. */
11390
11391 static int
11392 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11393 enum neon_type_mask mask)
11394 {
11395 if ((mask & N_EQK) != 0)
11396 return FAIL;
11397
11398 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11399 *size = 8;
11400 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
11401 *size = 16;
11402 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
11403 *size = 32;
11404 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
11405 *size = 64;
11406 else
11407 return FAIL;
11408
11409 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11410 *type = NT_signed;
11411 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
11412 *type = NT_unsigned;
11413 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
11414 *type = NT_integer;
11415 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
11416 *type = NT_untyped;
11417 else if ((mask & (N_P8 | N_P16)) != 0)
11418 *type = NT_poly;
11419 else if ((mask & (N_F32 | N_F64)) != 0)
11420 *type = NT_float;
11421 else
11422 return FAIL;
11423
11424 return SUCCESS;
11425 }
11426
11427 /* Modify a bitmask of allowed types. This is only needed for type
11428 relaxation. */
11429
11430 static unsigned
11431 modify_types_allowed (unsigned allowed, unsigned mods)
11432 {
11433 unsigned size;
11434 enum neon_el_type type;
11435 unsigned destmask;
11436 int i;
11437
11438 destmask = 0;
11439
11440 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11441 {
11442 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11443 {
11444 neon_modify_type_size (mods, &type, &size);
11445 destmask |= type_chk_of_el_type (type, size);
11446 }
11447 }
11448
11449 return destmask;
11450 }
11451
11452 /* Check type and return type classification.
11453 The manual states (paraphrase): If one datatype is given, it indicates the
11454 type given in:
11455 - the second operand, if there is one
11456 - the operand, if there is no second operand
11457 - the result, if there are no operands.
11458 This isn't quite good enough though, so we use a concept of a "key" datatype
11459 which is set on a per-instruction basis, which is the one which matters when
11460 only one data type is written.
11461 Note: this function has side-effects (e.g. filling in missing operands). All
11462 Neon instructions should call it before performing bit encoding. */
11463
11464 static struct neon_type_el
11465 neon_check_type (unsigned els, enum neon_shape ns, ...)
11466 {
11467 va_list ap;
11468 unsigned i, pass, key_el = 0;
11469 unsigned types[NEON_MAX_TYPE_ELS];
11470 enum neon_el_type k_type = NT_invtype;
11471 unsigned k_size = -1u;
11472 struct neon_type_el badtype = {NT_invtype, -1};
11473 unsigned key_allowed = 0;
11474
11475 /* Optional registers in Neon instructions are always (not) in operand 1.
11476 Fill in the missing operand here, if it was omitted. */
11477 if (els > 1 && !inst.operands[1].present)
11478 inst.operands[1] = inst.operands[0];
11479
11480 /* Suck up all the varargs. */
11481 va_start (ap, ns);
11482 for (i = 0; i < els; i++)
11483 {
11484 unsigned thisarg = va_arg (ap, unsigned);
11485 if (thisarg == N_IGNORE_TYPE)
11486 {
11487 va_end (ap);
11488 return badtype;
11489 }
11490 types[i] = thisarg;
11491 if ((thisarg & N_KEY) != 0)
11492 key_el = i;
11493 }
11494 va_end (ap);
11495
11496 if (inst.vectype.elems > 0)
11497 for (i = 0; i < els; i++)
11498 if (inst.operands[i].vectype.type != NT_invtype)
11499 {
11500 first_error (_("types specified in both the mnemonic and operands"));
11501 return badtype;
11502 }
11503
11504 /* Duplicate inst.vectype elements here as necessary.
11505 FIXME: No idea if this is exactly the same as the ARM assembler,
11506 particularly when an insn takes one register and one non-register
11507 operand. */
11508 if (inst.vectype.elems == 1 && els > 1)
11509 {
11510 unsigned j;
11511 inst.vectype.elems = els;
11512 inst.vectype.el[key_el] = inst.vectype.el[0];
11513 for (j = 0; j < els; j++)
11514 if (j != key_el)
11515 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11516 types[j]);
11517 }
11518 else if (inst.vectype.elems == 0 && els > 0)
11519 {
11520 unsigned j;
11521 /* No types were given after the mnemonic, so look for types specified
11522 after each operand. We allow some flexibility here; as long as the
11523 "key" operand has a type, we can infer the others. */
11524 for (j = 0; j < els; j++)
11525 if (inst.operands[j].vectype.type != NT_invtype)
11526 inst.vectype.el[j] = inst.operands[j].vectype;
11527
11528 if (inst.operands[key_el].vectype.type != NT_invtype)
11529 {
11530 for (j = 0; j < els; j++)
11531 if (inst.operands[j].vectype.type == NT_invtype)
11532 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11533 types[j]);
11534 }
11535 else
11536 {
11537 first_error (_("operand types can't be inferred"));
11538 return badtype;
11539 }
11540 }
11541 else if (inst.vectype.elems != els)
11542 {
11543 first_error (_("type specifier has the wrong number of parts"));
11544 return badtype;
11545 }
11546
11547 for (pass = 0; pass < 2; pass++)
11548 {
11549 for (i = 0; i < els; i++)
11550 {
11551 unsigned thisarg = types[i];
11552 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11553 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11554 enum neon_el_type g_type = inst.vectype.el[i].type;
11555 unsigned g_size = inst.vectype.el[i].size;
11556
11557 /* Decay more-specific signed & unsigned types to sign-insensitive
11558 integer types if sign-specific variants are unavailable. */
11559 if ((g_type == NT_signed || g_type == NT_unsigned)
11560 && (types_allowed & N_SU_ALL) == 0)
11561 g_type = NT_integer;
11562
11563 /* If only untyped args are allowed, decay any more specific types to
11564 them. Some instructions only care about signs for some element
11565 sizes, so handle that properly. */
11566 if ((g_size == 8 && (types_allowed & N_8) != 0)
11567 || (g_size == 16 && (types_allowed & N_16) != 0)
11568 || (g_size == 32 && (types_allowed & N_32) != 0)
11569 || (g_size == 64 && (types_allowed & N_64) != 0))
11570 g_type = NT_untyped;
11571
11572 if (pass == 0)
11573 {
11574 if ((thisarg & N_KEY) != 0)
11575 {
11576 k_type = g_type;
11577 k_size = g_size;
11578 key_allowed = thisarg & ~N_KEY;
11579 }
11580 }
11581 else
11582 {
11583 if ((thisarg & N_VFP) != 0)
11584 {
11585 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11586 unsigned regwidth = neon_shape_el_size[regshape], match;
11587
11588 /* In VFP mode, operands must match register widths. If we
11589 have a key operand, use its width, else use the width of
11590 the current operand. */
11591 if (k_size != -1u)
11592 match = k_size;
11593 else
11594 match = g_size;
11595
11596 if (regwidth != match)
11597 {
11598 first_error (_("operand size must match register width"));
11599 return badtype;
11600 }
11601 }
11602
11603 if ((thisarg & N_EQK) == 0)
11604 {
11605 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11606
11607 if ((given_type & types_allowed) == 0)
11608 {
11609 first_error (_("bad type in Neon instruction"));
11610 return badtype;
11611 }
11612 }
11613 else
11614 {
11615 enum neon_el_type mod_k_type = k_type;
11616 unsigned mod_k_size = k_size;
11617 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11618 if (g_type != mod_k_type || g_size != mod_k_size)
11619 {
11620 first_error (_("inconsistent types in Neon instruction"));
11621 return badtype;
11622 }
11623 }
11624 }
11625 }
11626 }
11627
11628 return inst.vectype.el[key_el];
11629 }
11630
11631 /* Neon-style VFP instruction forwarding. */
11632
11633 /* Thumb VFP instructions have 0xE in the condition field. */
11634
11635 static void
11636 do_vfp_cond_or_thumb (void)
11637 {
11638 if (thumb_mode)
11639 inst.instruction |= 0xe0000000;
11640 else
11641 inst.instruction |= inst.cond << 28;
11642 }
11643
11644 /* Look up and encode a simple mnemonic, for use as a helper function for the
11645 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11646 etc. It is assumed that operand parsing has already been done, and that the
11647 operands are in the form expected by the given opcode (this isn't necessarily
11648 the same as the form in which they were parsed, hence some massaging must
11649 take place before this function is called).
11650 Checks current arch version against that in the looked-up opcode. */
11651
11652 static void
11653 do_vfp_nsyn_opcode (const char *opname)
11654 {
11655 const struct asm_opcode *opcode;
11656
11657 opcode = hash_find (arm_ops_hsh, opname);
11658
11659 if (!opcode)
11660 abort ();
11661
11662 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11663 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11664 _(BAD_FPU));
11665
11666 if (thumb_mode)
11667 {
11668 inst.instruction = opcode->tvalue;
11669 opcode->tencode ();
11670 }
11671 else
11672 {
11673 inst.instruction = (inst.cond << 28) | opcode->avalue;
11674 opcode->aencode ();
11675 }
11676 }
11677
11678 static void
11679 do_vfp_nsyn_add_sub (enum neon_shape rs)
11680 {
11681 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11682
11683 if (rs == NS_FFF)
11684 {
11685 if (is_add)
11686 do_vfp_nsyn_opcode ("fadds");
11687 else
11688 do_vfp_nsyn_opcode ("fsubs");
11689 }
11690 else
11691 {
11692 if (is_add)
11693 do_vfp_nsyn_opcode ("faddd");
11694 else
11695 do_vfp_nsyn_opcode ("fsubd");
11696 }
11697 }
11698
11699 /* Check operand types to see if this is a VFP instruction, and if so call
11700 PFN (). */
11701
11702 static int
11703 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11704 {
11705 enum neon_shape rs;
11706 struct neon_type_el et;
11707
11708 switch (args)
11709 {
11710 case 2:
11711 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11712 et = neon_check_type (2, rs,
11713 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11714 break;
11715
11716 case 3:
11717 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11718 et = neon_check_type (3, rs,
11719 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11720 break;
11721
11722 default:
11723 abort ();
11724 }
11725
11726 if (et.type != NT_invtype)
11727 {
11728 pfn (rs);
11729 return SUCCESS;
11730 }
11731 else
11732 inst.error = NULL;
11733
11734 return FAIL;
11735 }
11736
11737 static void
11738 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11739 {
11740 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11741
11742 if (rs == NS_FFF)
11743 {
11744 if (is_mla)
11745 do_vfp_nsyn_opcode ("fmacs");
11746 else
11747 do_vfp_nsyn_opcode ("fmscs");
11748 }
11749 else
11750 {
11751 if (is_mla)
11752 do_vfp_nsyn_opcode ("fmacd");
11753 else
11754 do_vfp_nsyn_opcode ("fmscd");
11755 }
11756 }
11757
11758 static void
11759 do_vfp_nsyn_mul (enum neon_shape rs)
11760 {
11761 if (rs == NS_FFF)
11762 do_vfp_nsyn_opcode ("fmuls");
11763 else
11764 do_vfp_nsyn_opcode ("fmuld");
11765 }
11766
11767 static void
11768 do_vfp_nsyn_abs_neg (enum neon_shape rs)
11769 {
11770 int is_neg = (inst.instruction & 0x80) != 0;
11771 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11772
11773 if (rs == NS_FF)
11774 {
11775 if (is_neg)
11776 do_vfp_nsyn_opcode ("fnegs");
11777 else
11778 do_vfp_nsyn_opcode ("fabss");
11779 }
11780 else
11781 {
11782 if (is_neg)
11783 do_vfp_nsyn_opcode ("fnegd");
11784 else
11785 do_vfp_nsyn_opcode ("fabsd");
11786 }
11787 }
11788
11789 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11790 insns belong to Neon, and are handled elsewhere. */
11791
11792 static void
11793 do_vfp_nsyn_ldm_stm (int is_dbmode)
11794 {
11795 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11796 if (is_ldm)
11797 {
11798 if (is_dbmode)
11799 do_vfp_nsyn_opcode ("fldmdbs");
11800 else
11801 do_vfp_nsyn_opcode ("fldmias");
11802 }
11803 else
11804 {
11805 if (is_dbmode)
11806 do_vfp_nsyn_opcode ("fstmdbs");
11807 else
11808 do_vfp_nsyn_opcode ("fstmias");
11809 }
11810 }
11811
11812 static void
11813 do_vfp_nsyn_sqrt (void)
11814 {
11815 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11816 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11817
11818 if (rs == NS_FF)
11819 do_vfp_nsyn_opcode ("fsqrts");
11820 else
11821 do_vfp_nsyn_opcode ("fsqrtd");
11822 }
11823
11824 static void
11825 do_vfp_nsyn_div (void)
11826 {
11827 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11828 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11829 N_F32 | N_F64 | N_KEY | N_VFP);
11830
11831 if (rs == NS_FFF)
11832 do_vfp_nsyn_opcode ("fdivs");
11833 else
11834 do_vfp_nsyn_opcode ("fdivd");
11835 }
11836
11837 static void
11838 do_vfp_nsyn_nmul (void)
11839 {
11840 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11841 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11842 N_F32 | N_F64 | N_KEY | N_VFP);
11843
11844 if (rs == NS_FFF)
11845 {
11846 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11847 do_vfp_sp_dyadic ();
11848 }
11849 else
11850 {
11851 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11852 do_vfp_dp_rd_rn_rm ();
11853 }
11854 do_vfp_cond_or_thumb ();
11855 }
11856
11857 static void
11858 do_vfp_nsyn_cmp (void)
11859 {
11860 if (inst.operands[1].isreg)
11861 {
11862 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11863 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11864
11865 if (rs == NS_FF)
11866 {
11867 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11868 do_vfp_sp_monadic ();
11869 }
11870 else
11871 {
11872 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11873 do_vfp_dp_rd_rm ();
11874 }
11875 }
11876 else
11877 {
11878 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11879 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11880
11881 switch (inst.instruction & 0x0fffffff)
11882 {
11883 case N_MNEM_vcmp:
11884 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11885 break;
11886 case N_MNEM_vcmpe:
11887 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11888 break;
11889 default:
11890 abort ();
11891 }
11892
11893 if (rs == NS_FI)
11894 {
11895 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11896 do_vfp_sp_compare_z ();
11897 }
11898 else
11899 {
11900 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11901 do_vfp_dp_rd ();
11902 }
11903 }
11904 do_vfp_cond_or_thumb ();
11905 }
11906
11907 static void
11908 nsyn_insert_sp (void)
11909 {
11910 inst.operands[1] = inst.operands[0];
11911 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11912 inst.operands[0].reg = REG_SP;
11913 inst.operands[0].isreg = 1;
11914 inst.operands[0].writeback = 1;
11915 inst.operands[0].present = 1;
11916 }
11917
11918 static void
11919 do_vfp_nsyn_push (void)
11920 {
11921 nsyn_insert_sp ();
11922 if (inst.operands[1].issingle)
11923 do_vfp_nsyn_opcode ("fstmdbs");
11924 else
11925 do_vfp_nsyn_opcode ("fstmdbd");
11926 }
11927
11928 static void
11929 do_vfp_nsyn_pop (void)
11930 {
11931 nsyn_insert_sp ();
11932 if (inst.operands[1].issingle)
11933 do_vfp_nsyn_opcode ("fldmias");
11934 else
11935 do_vfp_nsyn_opcode ("fldmiad");
11936 }
11937
11938 /* Fix up Neon data-processing instructions, ORing in the correct bits for
11939 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11940
11941 static unsigned
11942 neon_dp_fixup (unsigned i)
11943 {
11944 if (thumb_mode)
11945 {
11946 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11947 if (i & (1 << 24))
11948 i |= 1 << 28;
11949
11950 i &= ~(1 << 24);
11951
11952 i |= 0xef000000;
11953 }
11954 else
11955 i |= 0xf2000000;
11956
11957 return i;
11958 }
11959
11960 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11961 (0, 1, 2, 3). */
11962
11963 static unsigned
11964 neon_logbits (unsigned x)
11965 {
11966 return ffs (x) - 4;
11967 }
11968
11969 #define LOW4(R) ((R) & 0xf)
11970 #define HI1(R) (((R) >> 4) & 1)
11971
11972 /* Encode insns with bit pattern:
11973
11974 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11975 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11976
11977 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11978 different meaning for some instruction. */
11979
11980 static void
11981 neon_three_same (int isquad, int ubit, int size)
11982 {
11983 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11984 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11985 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11986 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11987 inst.instruction |= LOW4 (inst.operands[2].reg);
11988 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11989 inst.instruction |= (isquad != 0) << 6;
11990 inst.instruction |= (ubit != 0) << 24;
11991 if (size != -1)
11992 inst.instruction |= neon_logbits (size) << 20;
11993
11994 inst.instruction = neon_dp_fixup (inst.instruction);
11995 }
11996
11997 /* Encode instructions of the form:
11998
11999 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12000 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
12001
12002 Don't write size if SIZE == -1. */
12003
12004 static void
12005 neon_two_same (int qbit, int ubit, int size)
12006 {
12007 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12008 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12009 inst.instruction |= LOW4 (inst.operands[1].reg);
12010 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12011 inst.instruction |= (qbit != 0) << 6;
12012 inst.instruction |= (ubit != 0) << 24;
12013
12014 if (size != -1)
12015 inst.instruction |= neon_logbits (size) << 18;
12016
12017 inst.instruction = neon_dp_fixup (inst.instruction);
12018 }
12019
12020 /* Neon instruction encoders, in approximate order of appearance. */
12021
12022 static void
12023 do_neon_dyadic_i_su (void)
12024 {
12025 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12026 struct neon_type_el et = neon_check_type (3, rs,
12027 N_EQK, N_EQK, N_SU_32 | N_KEY);
12028 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12029 }
12030
12031 static void
12032 do_neon_dyadic_i64_su (void)
12033 {
12034 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12035 struct neon_type_el et = neon_check_type (3, rs,
12036 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12037 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12038 }
12039
12040 static void
12041 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12042 unsigned immbits)
12043 {
12044 unsigned size = et.size >> 3;
12045 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12046 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12047 inst.instruction |= LOW4 (inst.operands[1].reg);
12048 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12049 inst.instruction |= (isquad != 0) << 6;
12050 inst.instruction |= immbits << 16;
12051 inst.instruction |= (size >> 3) << 7;
12052 inst.instruction |= (size & 0x7) << 19;
12053 if (write_ubit)
12054 inst.instruction |= (uval != 0) << 24;
12055
12056 inst.instruction = neon_dp_fixup (inst.instruction);
12057 }
12058
12059 static void
12060 do_neon_shl_imm (void)
12061 {
12062 if (!inst.operands[2].isreg)
12063 {
12064 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12065 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12066 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12067 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
12068 }
12069 else
12070 {
12071 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12072 struct neon_type_el et = neon_check_type (3, rs,
12073 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12074 unsigned int tmp;
12075
12076 /* VSHL/VQSHL 3-register variants have syntax such as:
12077 vshl.xx Dd, Dm, Dn
12078 whereas other 3-register operations encoded by neon_three_same have
12079 syntax like:
12080 vadd.xx Dd, Dn, Dm
12081 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12082 here. */
12083 tmp = inst.operands[2].reg;
12084 inst.operands[2].reg = inst.operands[1].reg;
12085 inst.operands[1].reg = tmp;
12086 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12087 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12088 }
12089 }
12090
12091 static void
12092 do_neon_qshl_imm (void)
12093 {
12094 if (!inst.operands[2].isreg)
12095 {
12096 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12097 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12098
12099 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12100 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12101 inst.operands[2].imm);
12102 }
12103 else
12104 {
12105 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12106 struct neon_type_el et = neon_check_type (3, rs,
12107 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12108 unsigned int tmp;
12109
12110 /* See note in do_neon_shl_imm. */
12111 tmp = inst.operands[2].reg;
12112 inst.operands[2].reg = inst.operands[1].reg;
12113 inst.operands[1].reg = tmp;
12114 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12115 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12116 }
12117 }
12118
12119 static void
12120 do_neon_rshl (void)
12121 {
12122 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12123 struct neon_type_el et = neon_check_type (3, rs,
12124 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12125 unsigned int tmp;
12126
12127 tmp = inst.operands[2].reg;
12128 inst.operands[2].reg = inst.operands[1].reg;
12129 inst.operands[1].reg = tmp;
12130 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12131 }
12132
12133 static int
12134 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12135 {
12136 /* Handle .I8 pseudo-instructions. */
12137 if (size == 8)
12138 {
12139 /* Unfortunately, this will make everything apart from zero out-of-range.
12140 FIXME is this the intended semantics? There doesn't seem much point in
12141 accepting .I8 if so. */
12142 immediate |= immediate << 8;
12143 size = 16;
12144 }
12145
12146 if (size >= 32)
12147 {
12148 if (immediate == (immediate & 0x000000ff))
12149 {
12150 *immbits = immediate;
12151 return 0x1;
12152 }
12153 else if (immediate == (immediate & 0x0000ff00))
12154 {
12155 *immbits = immediate >> 8;
12156 return 0x3;
12157 }
12158 else if (immediate == (immediate & 0x00ff0000))
12159 {
12160 *immbits = immediate >> 16;
12161 return 0x5;
12162 }
12163 else if (immediate == (immediate & 0xff000000))
12164 {
12165 *immbits = immediate >> 24;
12166 return 0x7;
12167 }
12168 if ((immediate & 0xffff) != (immediate >> 16))
12169 goto bad_immediate;
12170 immediate &= 0xffff;
12171 }
12172
12173 if (immediate == (immediate & 0x000000ff))
12174 {
12175 *immbits = immediate;
12176 return 0x9;
12177 }
12178 else if (immediate == (immediate & 0x0000ff00))
12179 {
12180 *immbits = immediate >> 8;
12181 return 0xb;
12182 }
12183
12184 bad_immediate:
12185 first_error (_("immediate value out of range"));
12186 return FAIL;
12187 }
12188
12189 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12190 A, B, C, D. */
12191
12192 static int
12193 neon_bits_same_in_bytes (unsigned imm)
12194 {
12195 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12196 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12197 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12198 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12199 }
12200
12201 /* For immediate of above form, return 0bABCD. */
12202
12203 static unsigned
12204 neon_squash_bits (unsigned imm)
12205 {
12206 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12207 | ((imm & 0x01000000) >> 21);
12208 }
12209
12210 /* Compress quarter-float representation to 0b...000 abcdefgh. */
12211
12212 static unsigned
12213 neon_qfloat_bits (unsigned imm)
12214 {
12215 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
12216 }
12217
12218 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12219 the instruction. *OP is passed as the initial value of the op field, and
12220 may be set to a different value depending on the constant (i.e.
12221 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
12222 MVN). If the immediate looks like a repeated pattern then also
12223 try smaller element sizes. */
12224
12225 static int
12226 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12227 unsigned *immbits, int *op, int size,
12228 enum neon_el_type type)
12229 {
12230 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12231 float. */
12232 if (type == NT_float && !float_p)
12233 return FAIL;
12234
12235 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12236 {
12237 if (size != 32 || *op == 1)
12238 return FAIL;
12239 *immbits = neon_qfloat_bits (immlo);
12240 return 0xf;
12241 }
12242
12243 if (size == 64)
12244 {
12245 if (neon_bits_same_in_bytes (immhi)
12246 && neon_bits_same_in_bytes (immlo))
12247 {
12248 if (*op == 1)
12249 return FAIL;
12250 *immbits = (neon_squash_bits (immhi) << 4)
12251 | neon_squash_bits (immlo);
12252 *op = 1;
12253 return 0xe;
12254 }
12255
12256 if (immhi != immlo)
12257 return FAIL;
12258 }
12259
12260 if (size >= 32)
12261 {
12262 if (immlo == (immlo & 0x000000ff))
12263 {
12264 *immbits = immlo;
12265 return 0x0;
12266 }
12267 else if (immlo == (immlo & 0x0000ff00))
12268 {
12269 *immbits = immlo >> 8;
12270 return 0x2;
12271 }
12272 else if (immlo == (immlo & 0x00ff0000))
12273 {
12274 *immbits = immlo >> 16;
12275 return 0x4;
12276 }
12277 else if (immlo == (immlo & 0xff000000))
12278 {
12279 *immbits = immlo >> 24;
12280 return 0x6;
12281 }
12282 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12283 {
12284 *immbits = (immlo >> 8) & 0xff;
12285 return 0xc;
12286 }
12287 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12288 {
12289 *immbits = (immlo >> 16) & 0xff;
12290 return 0xd;
12291 }
12292
12293 if ((immlo & 0xffff) != (immlo >> 16))
12294 return FAIL;
12295 immlo &= 0xffff;
12296 }
12297
12298 if (size >= 16)
12299 {
12300 if (immlo == (immlo & 0x000000ff))
12301 {
12302 *immbits = immlo;
12303 return 0x8;
12304 }
12305 else if (immlo == (immlo & 0x0000ff00))
12306 {
12307 *immbits = immlo >> 8;
12308 return 0xa;
12309 }
12310
12311 if ((immlo & 0xff) != (immlo >> 8))
12312 return FAIL;
12313 immlo &= 0xff;
12314 }
12315
12316 if (immlo == (immlo & 0x000000ff))
12317 {
12318 /* Don't allow MVN with 8-bit immediate. */
12319 if (*op == 1)
12320 return FAIL;
12321 *immbits = immlo;
12322 return 0xe;
12323 }
12324
12325 return FAIL;
12326 }
12327
12328 /* Write immediate bits [7:0] to the following locations:
12329
12330 |28/24|23 19|18 16|15 4|3 0|
12331 | 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|
12332
12333 This function is used by VMOV/VMVN/VORR/VBIC. */
12334
12335 static void
12336 neon_write_immbits (unsigned immbits)
12337 {
12338 inst.instruction |= immbits & 0xf;
12339 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12340 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12341 }
12342
12343 /* Invert low-order SIZE bits of XHI:XLO. */
12344
12345 static void
12346 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12347 {
12348 unsigned immlo = xlo ? *xlo : 0;
12349 unsigned immhi = xhi ? *xhi : 0;
12350
12351 switch (size)
12352 {
12353 case 8:
12354 immlo = (~immlo) & 0xff;
12355 break;
12356
12357 case 16:
12358 immlo = (~immlo) & 0xffff;
12359 break;
12360
12361 case 64:
12362 immhi = (~immhi) & 0xffffffff;
12363 /* fall through. */
12364
12365 case 32:
12366 immlo = (~immlo) & 0xffffffff;
12367 break;
12368
12369 default:
12370 abort ();
12371 }
12372
12373 if (xlo)
12374 *xlo = immlo;
12375
12376 if (xhi)
12377 *xhi = immhi;
12378 }
12379
12380 static void
12381 do_neon_logic (void)
12382 {
12383 if (inst.operands[2].present && inst.operands[2].isreg)
12384 {
12385 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12386 neon_check_type (3, rs, N_IGNORE_TYPE);
12387 /* U bit and size field were set as part of the bitmask. */
12388 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12389 neon_three_same (neon_quad (rs), 0, -1);
12390 }
12391 else
12392 {
12393 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12394 struct neon_type_el et = neon_check_type (2, rs,
12395 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12396 enum neon_opc opcode = inst.instruction & 0x0fffffff;
12397 unsigned immbits;
12398 int cmode;
12399
12400 if (et.type == NT_invtype)
12401 return;
12402
12403 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12404
12405 immbits = inst.operands[1].imm;
12406 if (et.size == 64)
12407 {
12408 /* .i64 is a pseudo-op, so the immediate must be a repeating
12409 pattern. */
12410 if (immbits != (inst.operands[1].regisimm ?
12411 inst.operands[1].reg : 0))
12412 {
12413 /* Set immbits to an invalid constant. */
12414 immbits = 0xdeadbeef;
12415 }
12416 }
12417
12418 switch (opcode)
12419 {
12420 case N_MNEM_vbic:
12421 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12422 break;
12423
12424 case N_MNEM_vorr:
12425 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12426 break;
12427
12428 case N_MNEM_vand:
12429 /* Pseudo-instruction for VBIC. */
12430 neon_invert_size (&immbits, 0, et.size);
12431 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12432 break;
12433
12434 case N_MNEM_vorn:
12435 /* Pseudo-instruction for VORR. */
12436 neon_invert_size (&immbits, 0, et.size);
12437 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12438 break;
12439
12440 default:
12441 abort ();
12442 }
12443
12444 if (cmode == FAIL)
12445 return;
12446
12447 inst.instruction |= neon_quad (rs) << 6;
12448 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12449 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12450 inst.instruction |= cmode << 8;
12451 neon_write_immbits (immbits);
12452
12453 inst.instruction = neon_dp_fixup (inst.instruction);
12454 }
12455 }
12456
12457 static void
12458 do_neon_bitfield (void)
12459 {
12460 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12461 neon_check_type (3, rs, N_IGNORE_TYPE);
12462 neon_three_same (neon_quad (rs), 0, -1);
12463 }
12464
12465 static void
12466 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12467 unsigned destbits)
12468 {
12469 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12470 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12471 types | N_KEY);
12472 if (et.type == NT_float)
12473 {
12474 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12475 neon_three_same (neon_quad (rs), 0, -1);
12476 }
12477 else
12478 {
12479 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12480 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12481 }
12482 }
12483
12484 static void
12485 do_neon_dyadic_if_su (void)
12486 {
12487 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12488 }
12489
12490 static void
12491 do_neon_dyadic_if_su_d (void)
12492 {
12493 /* This version only allow D registers, but that constraint is enforced during
12494 operand parsing so we don't need to do anything extra here. */
12495 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12496 }
12497
12498 static void
12499 do_neon_dyadic_if_i_d (void)
12500 {
12501 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12502 affected if we specify unsigned args. */
12503 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12504 }
12505
12506 enum vfp_or_neon_is_neon_bits
12507 {
12508 NEON_CHECK_CC = 1,
12509 NEON_CHECK_ARCH = 2
12510 };
12511
12512 /* Call this function if an instruction which may have belonged to the VFP or
12513 Neon instruction sets, but turned out to be a Neon instruction (due to the
12514 operand types involved, etc.). We have to check and/or fix-up a couple of
12515 things:
12516
12517 - Make sure the user hasn't attempted to make a Neon instruction
12518 conditional.
12519 - Alter the value in the condition code field if necessary.
12520 - Make sure that the arch supports Neon instructions.
12521
12522 Which of these operations take place depends on bits from enum
12523 vfp_or_neon_is_neon_bits.
12524
12525 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12526 current instruction's condition is COND_ALWAYS, the condition field is
12527 changed to inst.uncond_value. This is necessary because instructions shared
12528 between VFP and Neon may be conditional for the VFP variants only, and the
12529 unconditional Neon version must have, e.g., 0xF in the condition field. */
12530
12531 static int
12532 vfp_or_neon_is_neon (unsigned check)
12533 {
12534 /* Conditions are always legal in Thumb mode (IT blocks). */
12535 if (!thumb_mode && (check & NEON_CHECK_CC))
12536 {
12537 if (inst.cond != COND_ALWAYS)
12538 {
12539 first_error (_(BAD_COND));
12540 return FAIL;
12541 }
12542 if (inst.uncond_value != -1)
12543 inst.instruction |= inst.uncond_value << 28;
12544 }
12545
12546 if ((check & NEON_CHECK_ARCH)
12547 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12548 {
12549 first_error (_(BAD_FPU));
12550 return FAIL;
12551 }
12552
12553 return SUCCESS;
12554 }
12555
12556 static void
12557 do_neon_addsub_if_i (void)
12558 {
12559 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12560 return;
12561
12562 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12563 return;
12564
12565 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12566 affected if we specify unsigned args. */
12567 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
12568 }
12569
12570 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12571 result to be:
12572 V<op> A,B (A is operand 0, B is operand 2)
12573 to mean:
12574 V<op> A,B,A
12575 not:
12576 V<op> A,B,B
12577 so handle that case specially. */
12578
12579 static void
12580 neon_exchange_operands (void)
12581 {
12582 void *scratch = alloca (sizeof (inst.operands[0]));
12583 if (inst.operands[1].present)
12584 {
12585 /* Swap operands[1] and operands[2]. */
12586 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12587 inst.operands[1] = inst.operands[2];
12588 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12589 }
12590 else
12591 {
12592 inst.operands[1] = inst.operands[2];
12593 inst.operands[2] = inst.operands[0];
12594 }
12595 }
12596
12597 static void
12598 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12599 {
12600 if (inst.operands[2].isreg)
12601 {
12602 if (invert)
12603 neon_exchange_operands ();
12604 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12605 }
12606 else
12607 {
12608 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12609 struct neon_type_el et = neon_check_type (2, rs,
12610 N_EQK | N_SIZ, immtypes | N_KEY);
12611
12612 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12613 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12614 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12615 inst.instruction |= LOW4 (inst.operands[1].reg);
12616 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12617 inst.instruction |= neon_quad (rs) << 6;
12618 inst.instruction |= (et.type == NT_float) << 10;
12619 inst.instruction |= neon_logbits (et.size) << 18;
12620
12621 inst.instruction = neon_dp_fixup (inst.instruction);
12622 }
12623 }
12624
12625 static void
12626 do_neon_cmp (void)
12627 {
12628 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12629 }
12630
12631 static void
12632 do_neon_cmp_inv (void)
12633 {
12634 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12635 }
12636
12637 static void
12638 do_neon_ceq (void)
12639 {
12640 neon_compare (N_IF_32, N_IF_32, FALSE);
12641 }
12642
12643 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
12644 scalars, which are encoded in 5 bits, M : Rm.
12645 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12646 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12647 index in M. */
12648
12649 static unsigned
12650 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12651 {
12652 unsigned regno = NEON_SCALAR_REG (scalar);
12653 unsigned elno = NEON_SCALAR_INDEX (scalar);
12654
12655 switch (elsize)
12656 {
12657 case 16:
12658 if (regno > 7 || elno > 3)
12659 goto bad_scalar;
12660 return regno | (elno << 3);
12661
12662 case 32:
12663 if (regno > 15 || elno > 1)
12664 goto bad_scalar;
12665 return regno | (elno << 4);
12666
12667 default:
12668 bad_scalar:
12669 first_error (_("scalar out of range for multiply instruction"));
12670 }
12671
12672 return 0;
12673 }
12674
12675 /* Encode multiply / multiply-accumulate scalar instructions. */
12676
12677 static void
12678 neon_mul_mac (struct neon_type_el et, int ubit)
12679 {
12680 unsigned scalar;
12681
12682 /* Give a more helpful error message if we have an invalid type. */
12683 if (et.type == NT_invtype)
12684 return;
12685
12686 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
12687 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12688 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12689 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12690 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12691 inst.instruction |= LOW4 (scalar);
12692 inst.instruction |= HI1 (scalar) << 5;
12693 inst.instruction |= (et.type == NT_float) << 8;
12694 inst.instruction |= neon_logbits (et.size) << 20;
12695 inst.instruction |= (ubit != 0) << 24;
12696
12697 inst.instruction = neon_dp_fixup (inst.instruction);
12698 }
12699
12700 static void
12701 do_neon_mac_maybe_scalar (void)
12702 {
12703 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12704 return;
12705
12706 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12707 return;
12708
12709 if (inst.operands[2].isscalar)
12710 {
12711 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12712 struct neon_type_el et = neon_check_type (3, rs,
12713 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12714 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12715 neon_mul_mac (et, neon_quad (rs));
12716 }
12717 else
12718 {
12719 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12720 affected if we specify unsigned args. */
12721 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12722 }
12723 }
12724
12725 static void
12726 do_neon_tst (void)
12727 {
12728 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12729 struct neon_type_el et = neon_check_type (3, rs,
12730 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12731 neon_three_same (neon_quad (rs), 0, et.size);
12732 }
12733
12734 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
12735 same types as the MAC equivalents. The polynomial type for this instruction
12736 is encoded the same as the integer type. */
12737
12738 static void
12739 do_neon_mul (void)
12740 {
12741 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12742 return;
12743
12744 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12745 return;
12746
12747 if (inst.operands[2].isscalar)
12748 do_neon_mac_maybe_scalar ();
12749 else
12750 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12751 }
12752
12753 static void
12754 do_neon_qdmulh (void)
12755 {
12756 if (inst.operands[2].isscalar)
12757 {
12758 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
12759 struct neon_type_el et = neon_check_type (3, rs,
12760 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12761 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12762 neon_mul_mac (et, neon_quad (rs));
12763 }
12764 else
12765 {
12766 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12767 struct neon_type_el et = neon_check_type (3, rs,
12768 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12769 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12770 /* The U bit (rounding) comes from bit mask. */
12771 neon_three_same (neon_quad (rs), 0, et.size);
12772 }
12773 }
12774
12775 static void
12776 do_neon_fcmp_absolute (void)
12777 {
12778 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12779 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12780 /* Size field comes from bit mask. */
12781 neon_three_same (neon_quad (rs), 1, -1);
12782 }
12783
12784 static void
12785 do_neon_fcmp_absolute_inv (void)
12786 {
12787 neon_exchange_operands ();
12788 do_neon_fcmp_absolute ();
12789 }
12790
12791 static void
12792 do_neon_step (void)
12793 {
12794 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12795 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12796 neon_three_same (neon_quad (rs), 0, -1);
12797 }
12798
12799 static void
12800 do_neon_abs_neg (void)
12801 {
12802 enum neon_shape rs;
12803 struct neon_type_el et;
12804
12805 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12806 return;
12807
12808 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12809 return;
12810
12811 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12812 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12813
12814 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12815 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12816 inst.instruction |= LOW4 (inst.operands[1].reg);
12817 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12818 inst.instruction |= neon_quad (rs) << 6;
12819 inst.instruction |= (et.type == NT_float) << 10;
12820 inst.instruction |= neon_logbits (et.size) << 18;
12821
12822 inst.instruction = neon_dp_fixup (inst.instruction);
12823 }
12824
12825 static void
12826 do_neon_sli (void)
12827 {
12828 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12829 struct neon_type_el et = neon_check_type (2, rs,
12830 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12831 int imm = inst.operands[2].imm;
12832 constraint (imm < 0 || (unsigned)imm >= et.size,
12833 _("immediate out of range for insert"));
12834 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12835 }
12836
12837 static void
12838 do_neon_sri (void)
12839 {
12840 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12841 struct neon_type_el et = neon_check_type (2, rs,
12842 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12843 int imm = inst.operands[2].imm;
12844 constraint (imm < 1 || (unsigned)imm > et.size,
12845 _("immediate out of range for insert"));
12846 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
12847 }
12848
12849 static void
12850 do_neon_qshlu_imm (void)
12851 {
12852 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12853 struct neon_type_el et = neon_check_type (2, rs,
12854 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12855 int imm = inst.operands[2].imm;
12856 constraint (imm < 0 || (unsigned)imm >= et.size,
12857 _("immediate out of range for shift"));
12858 /* Only encodes the 'U present' variant of the instruction.
12859 In this case, signed types have OP (bit 8) set to 0.
12860 Unsigned types have OP set to 1. */
12861 inst.instruction |= (et.type == NT_unsigned) << 8;
12862 /* The rest of the bits are the same as other immediate shifts. */
12863 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12864 }
12865
12866 static void
12867 do_neon_qmovn (void)
12868 {
12869 struct neon_type_el et = neon_check_type (2, NS_DQ,
12870 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12871 /* Saturating move where operands can be signed or unsigned, and the
12872 destination has the same signedness. */
12873 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12874 if (et.type == NT_unsigned)
12875 inst.instruction |= 0xc0;
12876 else
12877 inst.instruction |= 0x80;
12878 neon_two_same (0, 1, et.size / 2);
12879 }
12880
12881 static void
12882 do_neon_qmovun (void)
12883 {
12884 struct neon_type_el et = neon_check_type (2, NS_DQ,
12885 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12886 /* Saturating move with unsigned results. Operands must be signed. */
12887 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12888 neon_two_same (0, 1, et.size / 2);
12889 }
12890
12891 static void
12892 do_neon_rshift_sat_narrow (void)
12893 {
12894 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12895 or unsigned. If operands are unsigned, results must also be unsigned. */
12896 struct neon_type_el et = neon_check_type (2, NS_DQI,
12897 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12898 int imm = inst.operands[2].imm;
12899 /* This gets the bounds check, size encoding and immediate bits calculation
12900 right. */
12901 et.size /= 2;
12902
12903 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12904 VQMOVN.I<size> <Dd>, <Qm>. */
12905 if (imm == 0)
12906 {
12907 inst.operands[2].present = 0;
12908 inst.instruction = N_MNEM_vqmovn;
12909 do_neon_qmovn ();
12910 return;
12911 }
12912
12913 constraint (imm < 1 || (unsigned)imm > et.size,
12914 _("immediate out of range"));
12915 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12916 }
12917
12918 static void
12919 do_neon_rshift_sat_narrow_u (void)
12920 {
12921 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12922 or unsigned. If operands are unsigned, results must also be unsigned. */
12923 struct neon_type_el et = neon_check_type (2, NS_DQI,
12924 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12925 int imm = inst.operands[2].imm;
12926 /* This gets the bounds check, size encoding and immediate bits calculation
12927 right. */
12928 et.size /= 2;
12929
12930 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12931 VQMOVUN.I<size> <Dd>, <Qm>. */
12932 if (imm == 0)
12933 {
12934 inst.operands[2].present = 0;
12935 inst.instruction = N_MNEM_vqmovun;
12936 do_neon_qmovun ();
12937 return;
12938 }
12939
12940 constraint (imm < 1 || (unsigned)imm > et.size,
12941 _("immediate out of range"));
12942 /* FIXME: The manual is kind of unclear about what value U should have in
12943 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12944 must be 1. */
12945 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12946 }
12947
12948 static void
12949 do_neon_movn (void)
12950 {
12951 struct neon_type_el et = neon_check_type (2, NS_DQ,
12952 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12953 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12954 neon_two_same (0, 1, et.size / 2);
12955 }
12956
12957 static void
12958 do_neon_rshift_narrow (void)
12959 {
12960 struct neon_type_el et = neon_check_type (2, NS_DQI,
12961 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12962 int imm = inst.operands[2].imm;
12963 /* This gets the bounds check, size encoding and immediate bits calculation
12964 right. */
12965 et.size /= 2;
12966
12967 /* If immediate is zero then we are a pseudo-instruction for
12968 VMOVN.I<size> <Dd>, <Qm> */
12969 if (imm == 0)
12970 {
12971 inst.operands[2].present = 0;
12972 inst.instruction = N_MNEM_vmovn;
12973 do_neon_movn ();
12974 return;
12975 }
12976
12977 constraint (imm < 1 || (unsigned)imm > et.size,
12978 _("immediate out of range for narrowing operation"));
12979 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12980 }
12981
12982 static void
12983 do_neon_shll (void)
12984 {
12985 /* FIXME: Type checking when lengthening. */
12986 struct neon_type_el et = neon_check_type (2, NS_QDI,
12987 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12988 unsigned imm = inst.operands[2].imm;
12989
12990 if (imm == et.size)
12991 {
12992 /* Maximum shift variant. */
12993 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12994 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12995 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12996 inst.instruction |= LOW4 (inst.operands[1].reg);
12997 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12998 inst.instruction |= neon_logbits (et.size) << 18;
12999
13000 inst.instruction = neon_dp_fixup (inst.instruction);
13001 }
13002 else
13003 {
13004 /* A more-specific type check for non-max versions. */
13005 et = neon_check_type (2, NS_QDI,
13006 N_EQK | N_DBL, N_SU_32 | N_KEY);
13007 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13008 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13009 }
13010 }
13011
13012 /* Check the various types for the VCVT instruction, and return which version
13013 the current instruction is. */
13014
13015 static int
13016 neon_cvt_flavour (enum neon_shape rs)
13017 {
13018 #define CVT_VAR(C,X,Y) \
13019 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13020 if (et.type != NT_invtype) \
13021 { \
13022 inst.error = NULL; \
13023 return (C); \
13024 }
13025 struct neon_type_el et;
13026 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13027 || rs == NS_FF) ? N_VFP : 0;
13028 /* The instruction versions which take an immediate take one register
13029 argument, which is extended to the width of the full register. Thus the
13030 "source" and "destination" registers must have the same width. Hack that
13031 here by making the size equal to the key (wider, in this case) operand. */
13032 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
13033
13034 CVT_VAR (0, N_S32, N_F32);
13035 CVT_VAR (1, N_U32, N_F32);
13036 CVT_VAR (2, N_F32, N_S32);
13037 CVT_VAR (3, N_F32, N_U32);
13038 /* Half-precision conversions. */
13039 CVT_VAR (4, N_F32, N_F16);
13040 CVT_VAR (5, N_F16, N_F32);
13041
13042 whole_reg = N_VFP;
13043
13044 /* VFP instructions. */
13045 CVT_VAR (6, N_F32, N_F64);
13046 CVT_VAR (7, N_F64, N_F32);
13047 CVT_VAR (8, N_S32, N_F64 | key);
13048 CVT_VAR (9, N_U32, N_F64 | key);
13049 CVT_VAR (10, N_F64 | key, N_S32);
13050 CVT_VAR (11, N_F64 | key, N_U32);
13051 /* VFP instructions with bitshift. */
13052 CVT_VAR (12, N_F32 | key, N_S16);
13053 CVT_VAR (13, N_F32 | key, N_U16);
13054 CVT_VAR (14, N_F64 | key, N_S16);
13055 CVT_VAR (15, N_F64 | key, N_U16);
13056 CVT_VAR (16, N_S16, N_F32 | key);
13057 CVT_VAR (17, N_U16, N_F32 | key);
13058 CVT_VAR (18, N_S16, N_F64 | key);
13059 CVT_VAR (19, N_U16, N_F64 | key);
13060
13061 return -1;
13062 #undef CVT_VAR
13063 }
13064
13065 /* Neon-syntax VFP conversions. */
13066
13067 static void
13068 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
13069 {
13070 const char *opname = 0;
13071
13072 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
13073 {
13074 /* Conversions with immediate bitshift. */
13075 const char *enc[] =
13076 {
13077 "ftosls",
13078 "ftouls",
13079 "fsltos",
13080 "fultos",
13081 NULL,
13082 NULL,
13083 NULL,
13084 NULL,
13085 "ftosld",
13086 "ftould",
13087 "fsltod",
13088 "fultod",
13089 "fshtos",
13090 "fuhtos",
13091 "fshtod",
13092 "fuhtod",
13093 "ftoshs",
13094 "ftouhs",
13095 "ftoshd",
13096 "ftouhd"
13097 };
13098
13099 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13100 {
13101 opname = enc[flavour];
13102 constraint (inst.operands[0].reg != inst.operands[1].reg,
13103 _("operands 0 and 1 must be the same register"));
13104 inst.operands[1] = inst.operands[2];
13105 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13106 }
13107 }
13108 else
13109 {
13110 /* Conversions without bitshift. */
13111 const char *enc[] =
13112 {
13113 "ftosis",
13114 "ftouis",
13115 "fsitos",
13116 "fuitos",
13117 "NULL",
13118 "NULL",
13119 "fcvtsd",
13120 "fcvtds",
13121 "ftosid",
13122 "ftouid",
13123 "fsitod",
13124 "fuitod"
13125 };
13126
13127 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13128 opname = enc[flavour];
13129 }
13130
13131 if (opname)
13132 do_vfp_nsyn_opcode (opname);
13133 }
13134
13135 static void
13136 do_vfp_nsyn_cvtz (void)
13137 {
13138 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13139 int flavour = neon_cvt_flavour (rs);
13140 const char *enc[] =
13141 {
13142 "ftosizs",
13143 "ftouizs",
13144 NULL,
13145 NULL,
13146 NULL,
13147 NULL,
13148 NULL,
13149 NULL,
13150 "ftosizd",
13151 "ftouizd"
13152 };
13153
13154 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13155 do_vfp_nsyn_opcode (enc[flavour]);
13156 }
13157
13158 static void
13159 do_neon_cvt (void)
13160 {
13161 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
13162 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
13163 int flavour = neon_cvt_flavour (rs);
13164
13165 /* VFP rather than Neon conversions. */
13166 if (flavour >= 6)
13167 {
13168 do_vfp_nsyn_cvt (rs, flavour);
13169 return;
13170 }
13171
13172 switch (rs)
13173 {
13174 case NS_DDI:
13175 case NS_QQI:
13176 {
13177 unsigned immbits;
13178 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13179
13180 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13181 return;
13182
13183 /* Fixed-point conversion with #0 immediate is encoded as an
13184 integer conversion. */
13185 if (inst.operands[2].present && inst.operands[2].imm == 0)
13186 goto int_encode;
13187 immbits = 32 - inst.operands[2].imm;
13188 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13189 if (flavour != -1)
13190 inst.instruction |= enctab[flavour];
13191 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13192 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13193 inst.instruction |= LOW4 (inst.operands[1].reg);
13194 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13195 inst.instruction |= neon_quad (rs) << 6;
13196 inst.instruction |= 1 << 21;
13197 inst.instruction |= immbits << 16;
13198
13199 inst.instruction = neon_dp_fixup (inst.instruction);
13200 }
13201 break;
13202
13203 case NS_DD:
13204 case NS_QQ:
13205 int_encode:
13206 {
13207 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13208
13209 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13210
13211 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13212 return;
13213
13214 if (flavour != -1)
13215 inst.instruction |= enctab[flavour];
13216
13217 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13218 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13219 inst.instruction |= LOW4 (inst.operands[1].reg);
13220 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13221 inst.instruction |= neon_quad (rs) << 6;
13222 inst.instruction |= 2 << 18;
13223
13224 inst.instruction = neon_dp_fixup (inst.instruction);
13225 }
13226 break;
13227
13228 /* Half-precision conversions for Advanced SIMD -- neon. */
13229 case NS_QD:
13230 case NS_DQ:
13231
13232 if ((rs == NS_DQ)
13233 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13234 {
13235 as_bad (_("operand size must match register width"));
13236 break;
13237 }
13238
13239 if ((rs == NS_QD)
13240 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13241 {
13242 as_bad (_("operand size must match register width"));
13243 break;
13244 }
13245
13246 if (rs == NS_DQ)
13247 inst.instruction = 0x3b60600;
13248 else
13249 inst.instruction = 0x3b60700;
13250
13251 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13252 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13253 inst.instruction |= LOW4 (inst.operands[1].reg);
13254 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13255 inst.instruction = neon_dp_fixup (inst.instruction);
13256 break;
13257
13258 default:
13259 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13260 do_vfp_nsyn_cvt (rs, flavour);
13261 }
13262 }
13263
13264 static void
13265 do_neon_cvtb (void)
13266 {
13267 inst.instruction = 0xeb20a40;
13268
13269 /* The sizes are attached to the mnemonic. */
13270 if (inst.vectype.el[0].type != NT_invtype
13271 && inst.vectype.el[0].size == 16)
13272 inst.instruction |= 0x00010000;
13273
13274 /* Programmer's syntax: the sizes are attached to the operands. */
13275 else if (inst.operands[0].vectype.type != NT_invtype
13276 && inst.operands[0].vectype.size == 16)
13277 inst.instruction |= 0x00010000;
13278
13279 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13280 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13281 do_vfp_cond_or_thumb ();
13282 }
13283
13284
13285 static void
13286 do_neon_cvtt (void)
13287 {
13288 do_neon_cvtb ();
13289 inst.instruction |= 0x80;
13290 }
13291
13292 static void
13293 neon_move_immediate (void)
13294 {
13295 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13296 struct neon_type_el et = neon_check_type (2, rs,
13297 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13298 unsigned immlo, immhi = 0, immbits;
13299 int op, cmode, float_p;
13300
13301 constraint (et.type == NT_invtype,
13302 _("operand size must be specified for immediate VMOV"));
13303
13304 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13305 op = (inst.instruction & (1 << 5)) != 0;
13306
13307 immlo = inst.operands[1].imm;
13308 if (inst.operands[1].regisimm)
13309 immhi = inst.operands[1].reg;
13310
13311 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13312 _("immediate has bits set outside the operand size"));
13313
13314 float_p = inst.operands[1].immisfloat;
13315
13316 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
13317 et.size, et.type)) == FAIL)
13318 {
13319 /* Invert relevant bits only. */
13320 neon_invert_size (&immlo, &immhi, et.size);
13321 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13322 with one or the other; those cases are caught by
13323 neon_cmode_for_move_imm. */
13324 op = !op;
13325 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13326 &op, et.size, et.type)) == FAIL)
13327 {
13328 first_error (_("immediate out of range"));
13329 return;
13330 }
13331 }
13332
13333 inst.instruction &= ~(1 << 5);
13334 inst.instruction |= op << 5;
13335
13336 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13337 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13338 inst.instruction |= neon_quad (rs) << 6;
13339 inst.instruction |= cmode << 8;
13340
13341 neon_write_immbits (immbits);
13342 }
13343
13344 static void
13345 do_neon_mvn (void)
13346 {
13347 if (inst.operands[1].isreg)
13348 {
13349 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13350
13351 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13352 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13353 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13354 inst.instruction |= LOW4 (inst.operands[1].reg);
13355 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13356 inst.instruction |= neon_quad (rs) << 6;
13357 }
13358 else
13359 {
13360 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13361 neon_move_immediate ();
13362 }
13363
13364 inst.instruction = neon_dp_fixup (inst.instruction);
13365 }
13366
13367 /* Encode instructions of form:
13368
13369 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13370 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
13371
13372 static void
13373 neon_mixed_length (struct neon_type_el et, unsigned size)
13374 {
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 (inst.operands[2].reg);
13380 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13381 inst.instruction |= (et.type == NT_unsigned) << 24;
13382 inst.instruction |= neon_logbits (size) << 20;
13383
13384 inst.instruction = neon_dp_fixup (inst.instruction);
13385 }
13386
13387 static void
13388 do_neon_dyadic_long (void)
13389 {
13390 /* FIXME: Type checking for lengthening op. */
13391 struct neon_type_el et = neon_check_type (3, NS_QDD,
13392 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13393 neon_mixed_length (et, et.size);
13394 }
13395
13396 static void
13397 do_neon_abal (void)
13398 {
13399 struct neon_type_el et = neon_check_type (3, NS_QDD,
13400 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13401 neon_mixed_length (et, et.size);
13402 }
13403
13404 static void
13405 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13406 {
13407 if (inst.operands[2].isscalar)
13408 {
13409 struct neon_type_el et = neon_check_type (3, NS_QDS,
13410 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
13411 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13412 neon_mul_mac (et, et.type == NT_unsigned);
13413 }
13414 else
13415 {
13416 struct neon_type_el et = neon_check_type (3, NS_QDD,
13417 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13418 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13419 neon_mixed_length (et, et.size);
13420 }
13421 }
13422
13423 static void
13424 do_neon_mac_maybe_scalar_long (void)
13425 {
13426 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13427 }
13428
13429 static void
13430 do_neon_dyadic_wide (void)
13431 {
13432 struct neon_type_el et = neon_check_type (3, NS_QQD,
13433 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13434 neon_mixed_length (et, et.size);
13435 }
13436
13437 static void
13438 do_neon_dyadic_narrow (void)
13439 {
13440 struct neon_type_el et = neon_check_type (3, NS_QDD,
13441 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
13442 /* Operand sign is unimportant, and the U bit is part of the opcode,
13443 so force the operand type to integer. */
13444 et.type = NT_integer;
13445 neon_mixed_length (et, et.size / 2);
13446 }
13447
13448 static void
13449 do_neon_mul_sat_scalar_long (void)
13450 {
13451 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13452 }
13453
13454 static void
13455 do_neon_vmull (void)
13456 {
13457 if (inst.operands[2].isscalar)
13458 do_neon_mac_maybe_scalar_long ();
13459 else
13460 {
13461 struct neon_type_el et = neon_check_type (3, NS_QDD,
13462 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13463 if (et.type == NT_poly)
13464 inst.instruction = NEON_ENC_POLY (inst.instruction);
13465 else
13466 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13467 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13468 zero. Should be OK as-is. */
13469 neon_mixed_length (et, et.size);
13470 }
13471 }
13472
13473 static void
13474 do_neon_ext (void)
13475 {
13476 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
13477 struct neon_type_el et = neon_check_type (3, rs,
13478 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13479 unsigned imm = (inst.operands[3].imm * et.size) / 8;
13480
13481 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13482 _("shift out of range"));
13483 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13484 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13485 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13486 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13487 inst.instruction |= LOW4 (inst.operands[2].reg);
13488 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13489 inst.instruction |= neon_quad (rs) << 6;
13490 inst.instruction |= imm << 8;
13491
13492 inst.instruction = neon_dp_fixup (inst.instruction);
13493 }
13494
13495 static void
13496 do_neon_rev (void)
13497 {
13498 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13499 struct neon_type_el et = neon_check_type (2, rs,
13500 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13501 unsigned op = (inst.instruction >> 7) & 3;
13502 /* N (width of reversed regions) is encoded as part of the bitmask. We
13503 extract it here to check the elements to be reversed are smaller.
13504 Otherwise we'd get a reserved instruction. */
13505 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
13506 assert (elsize != 0);
13507 constraint (et.size >= elsize,
13508 _("elements must be smaller than reversal region"));
13509 neon_two_same (neon_quad (rs), 1, et.size);
13510 }
13511
13512 static void
13513 do_neon_dup (void)
13514 {
13515 if (inst.operands[1].isscalar)
13516 {
13517 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
13518 struct neon_type_el et = neon_check_type (2, rs,
13519 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13520 unsigned sizebits = et.size >> 3;
13521 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
13522 int logsize = neon_logbits (et.size);
13523 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
13524
13525 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13526 return;
13527
13528 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13529 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13530 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13531 inst.instruction |= LOW4 (dm);
13532 inst.instruction |= HI1 (dm) << 5;
13533 inst.instruction |= neon_quad (rs) << 6;
13534 inst.instruction |= x << 17;
13535 inst.instruction |= sizebits << 16;
13536
13537 inst.instruction = neon_dp_fixup (inst.instruction);
13538 }
13539 else
13540 {
13541 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13542 struct neon_type_el et = neon_check_type (2, rs,
13543 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13544 /* Duplicate ARM register to lanes of vector. */
13545 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13546 switch (et.size)
13547 {
13548 case 8: inst.instruction |= 0x400000; break;
13549 case 16: inst.instruction |= 0x000020; break;
13550 case 32: inst.instruction |= 0x000000; break;
13551 default: break;
13552 }
13553 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13554 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13555 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
13556 inst.instruction |= neon_quad (rs) << 21;
13557 /* The encoding for this instruction is identical for the ARM and Thumb
13558 variants, except for the condition field. */
13559 do_vfp_cond_or_thumb ();
13560 }
13561 }
13562
13563 /* VMOV has particularly many variations. It can be one of:
13564 0. VMOV<c><q> <Qd>, <Qm>
13565 1. VMOV<c><q> <Dd>, <Dm>
13566 (Register operations, which are VORR with Rm = Rn.)
13567 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13568 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13569 (Immediate loads.)
13570 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13571 (ARM register to scalar.)
13572 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13573 (Two ARM registers to vector.)
13574 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13575 (Scalar to ARM register.)
13576 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13577 (Vector to two ARM registers.)
13578 8. VMOV.F32 <Sd>, <Sm>
13579 9. VMOV.F64 <Dd>, <Dm>
13580 (VFP register moves.)
13581 10. VMOV.F32 <Sd>, #imm
13582 11. VMOV.F64 <Dd>, #imm
13583 (VFP float immediate load.)
13584 12. VMOV <Rd>, <Sm>
13585 (VFP single to ARM reg.)
13586 13. VMOV <Sd>, <Rm>
13587 (ARM reg to VFP single.)
13588 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13589 (Two ARM regs to two VFP singles.)
13590 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13591 (Two VFP singles to two ARM regs.)
13592
13593 These cases can be disambiguated using neon_select_shape, except cases 1/9
13594 and 3/11 which depend on the operand type too.
13595
13596 All the encoded bits are hardcoded by this function.
13597
13598 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13599 Cases 5, 7 may be used with VFPv2 and above.
13600
13601 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13602 can specify a type where it doesn't make sense to, and is ignored). */
13603
13604 static void
13605 do_neon_mov (void)
13606 {
13607 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13608 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13609 NS_NULL);
13610 struct neon_type_el et;
13611 const char *ldconst = 0;
13612
13613 switch (rs)
13614 {
13615 case NS_DD: /* case 1/9. */
13616 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13617 /* It is not an error here if no type is given. */
13618 inst.error = NULL;
13619 if (et.type == NT_float && et.size == 64)
13620 {
13621 do_vfp_nsyn_opcode ("fcpyd");
13622 break;
13623 }
13624 /* fall through. */
13625
13626 case NS_QQ: /* case 0/1. */
13627 {
13628 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13629 return;
13630 /* The architecture manual I have doesn't explicitly state which
13631 value the U bit should have for register->register moves, but
13632 the equivalent VORR instruction has U = 0, so do that. */
13633 inst.instruction = 0x0200110;
13634 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13635 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13636 inst.instruction |= LOW4 (inst.operands[1].reg);
13637 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13638 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13639 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13640 inst.instruction |= neon_quad (rs) << 6;
13641
13642 inst.instruction = neon_dp_fixup (inst.instruction);
13643 }
13644 break;
13645
13646 case NS_DI: /* case 3/11. */
13647 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13648 inst.error = NULL;
13649 if (et.type == NT_float && et.size == 64)
13650 {
13651 /* case 11 (fconstd). */
13652 ldconst = "fconstd";
13653 goto encode_fconstd;
13654 }
13655 /* fall through. */
13656
13657 case NS_QI: /* case 2/3. */
13658 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13659 return;
13660 inst.instruction = 0x0800010;
13661 neon_move_immediate ();
13662 inst.instruction = neon_dp_fixup (inst.instruction);
13663 break;
13664
13665 case NS_SR: /* case 4. */
13666 {
13667 unsigned bcdebits = 0;
13668 struct neon_type_el et = neon_check_type (2, NS_NULL,
13669 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13670 int logsize = neon_logbits (et.size);
13671 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13672 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13673
13674 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13675 _(BAD_FPU));
13676 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13677 && et.size != 32, _(BAD_FPU));
13678 constraint (et.type == NT_invtype, _("bad type for scalar"));
13679 constraint (x >= 64 / et.size, _("scalar index out of range"));
13680
13681 switch (et.size)
13682 {
13683 case 8: bcdebits = 0x8; break;
13684 case 16: bcdebits = 0x1; break;
13685 case 32: bcdebits = 0x0; break;
13686 default: ;
13687 }
13688
13689 bcdebits |= x << logsize;
13690
13691 inst.instruction = 0xe000b10;
13692 do_vfp_cond_or_thumb ();
13693 inst.instruction |= LOW4 (dn) << 16;
13694 inst.instruction |= HI1 (dn) << 7;
13695 inst.instruction |= inst.operands[1].reg << 12;
13696 inst.instruction |= (bcdebits & 3) << 5;
13697 inst.instruction |= (bcdebits >> 2) << 21;
13698 }
13699 break;
13700
13701 case NS_DRR: /* case 5 (fmdrr). */
13702 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13703 _(BAD_FPU));
13704
13705 inst.instruction = 0xc400b10;
13706 do_vfp_cond_or_thumb ();
13707 inst.instruction |= LOW4 (inst.operands[0].reg);
13708 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13709 inst.instruction |= inst.operands[1].reg << 12;
13710 inst.instruction |= inst.operands[2].reg << 16;
13711 break;
13712
13713 case NS_RS: /* case 6. */
13714 {
13715 struct neon_type_el et = neon_check_type (2, NS_NULL,
13716 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13717 unsigned logsize = neon_logbits (et.size);
13718 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13719 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13720 unsigned abcdebits = 0;
13721
13722 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13723 _(BAD_FPU));
13724 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13725 && et.size != 32, _(BAD_FPU));
13726 constraint (et.type == NT_invtype, _("bad type for scalar"));
13727 constraint (x >= 64 / et.size, _("scalar index out of range"));
13728
13729 switch (et.size)
13730 {
13731 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13732 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13733 case 32: abcdebits = 0x00; break;
13734 default: ;
13735 }
13736
13737 abcdebits |= x << logsize;
13738 inst.instruction = 0xe100b10;
13739 do_vfp_cond_or_thumb ();
13740 inst.instruction |= LOW4 (dn) << 16;
13741 inst.instruction |= HI1 (dn) << 7;
13742 inst.instruction |= inst.operands[0].reg << 12;
13743 inst.instruction |= (abcdebits & 3) << 5;
13744 inst.instruction |= (abcdebits >> 2) << 21;
13745 }
13746 break;
13747
13748 case NS_RRD: /* case 7 (fmrrd). */
13749 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13750 _(BAD_FPU));
13751
13752 inst.instruction = 0xc500b10;
13753 do_vfp_cond_or_thumb ();
13754 inst.instruction |= inst.operands[0].reg << 12;
13755 inst.instruction |= inst.operands[1].reg << 16;
13756 inst.instruction |= LOW4 (inst.operands[2].reg);
13757 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13758 break;
13759
13760 case NS_FF: /* case 8 (fcpys). */
13761 do_vfp_nsyn_opcode ("fcpys");
13762 break;
13763
13764 case NS_FI: /* case 10 (fconsts). */
13765 ldconst = "fconsts";
13766 encode_fconstd:
13767 if (is_quarter_float (inst.operands[1].imm))
13768 {
13769 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13770 do_vfp_nsyn_opcode (ldconst);
13771 }
13772 else
13773 first_error (_("immediate out of range"));
13774 break;
13775
13776 case NS_RF: /* case 12 (fmrs). */
13777 do_vfp_nsyn_opcode ("fmrs");
13778 break;
13779
13780 case NS_FR: /* case 13 (fmsr). */
13781 do_vfp_nsyn_opcode ("fmsr");
13782 break;
13783
13784 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13785 (one of which is a list), but we have parsed four. Do some fiddling to
13786 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13787 expect. */
13788 case NS_RRFF: /* case 14 (fmrrs). */
13789 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13790 _("VFP registers must be adjacent"));
13791 inst.operands[2].imm = 2;
13792 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13793 do_vfp_nsyn_opcode ("fmrrs");
13794 break;
13795
13796 case NS_FFRR: /* case 15 (fmsrr). */
13797 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13798 _("VFP registers must be adjacent"));
13799 inst.operands[1] = inst.operands[2];
13800 inst.operands[2] = inst.operands[3];
13801 inst.operands[0].imm = 2;
13802 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13803 do_vfp_nsyn_opcode ("fmsrr");
13804 break;
13805
13806 default:
13807 abort ();
13808 }
13809 }
13810
13811 static void
13812 do_neon_rshift_round_imm (void)
13813 {
13814 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13815 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13816 int imm = inst.operands[2].imm;
13817
13818 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13819 if (imm == 0)
13820 {
13821 inst.operands[2].present = 0;
13822 do_neon_mov ();
13823 return;
13824 }
13825
13826 constraint (imm < 1 || (unsigned)imm > et.size,
13827 _("immediate out of range for shift"));
13828 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13829 et.size - imm);
13830 }
13831
13832 static void
13833 do_neon_movl (void)
13834 {
13835 struct neon_type_el et = neon_check_type (2, NS_QD,
13836 N_EQK | N_DBL, N_SU_32 | N_KEY);
13837 unsigned sizebits = et.size >> 3;
13838 inst.instruction |= sizebits << 19;
13839 neon_two_same (0, et.type == NT_unsigned, -1);
13840 }
13841
13842 static void
13843 do_neon_trn (void)
13844 {
13845 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13846 struct neon_type_el et = neon_check_type (2, rs,
13847 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13848 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13849 neon_two_same (neon_quad (rs), 1, et.size);
13850 }
13851
13852 static void
13853 do_neon_zip_uzp (void)
13854 {
13855 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13856 struct neon_type_el et = neon_check_type (2, rs,
13857 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13858 if (rs == NS_DD && et.size == 32)
13859 {
13860 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13861 inst.instruction = N_MNEM_vtrn;
13862 do_neon_trn ();
13863 return;
13864 }
13865 neon_two_same (neon_quad (rs), 1, et.size);
13866 }
13867
13868 static void
13869 do_neon_sat_abs_neg (void)
13870 {
13871 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13872 struct neon_type_el et = neon_check_type (2, rs,
13873 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13874 neon_two_same (neon_quad (rs), 1, et.size);
13875 }
13876
13877 static void
13878 do_neon_pair_long (void)
13879 {
13880 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13881 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13882 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13883 inst.instruction |= (et.type == NT_unsigned) << 7;
13884 neon_two_same (neon_quad (rs), 1, et.size);
13885 }
13886
13887 static void
13888 do_neon_recip_est (void)
13889 {
13890 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13891 struct neon_type_el et = neon_check_type (2, rs,
13892 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13893 inst.instruction |= (et.type == NT_float) << 8;
13894 neon_two_same (neon_quad (rs), 1, et.size);
13895 }
13896
13897 static void
13898 do_neon_cls (void)
13899 {
13900 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13901 struct neon_type_el et = neon_check_type (2, rs,
13902 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
13903 neon_two_same (neon_quad (rs), 1, et.size);
13904 }
13905
13906 static void
13907 do_neon_clz (void)
13908 {
13909 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13910 struct neon_type_el et = neon_check_type (2, rs,
13911 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
13912 neon_two_same (neon_quad (rs), 1, et.size);
13913 }
13914
13915 static void
13916 do_neon_cnt (void)
13917 {
13918 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13919 struct neon_type_el et = neon_check_type (2, rs,
13920 N_EQK | N_INT, N_8 | N_KEY);
13921 neon_two_same (neon_quad (rs), 1, et.size);
13922 }
13923
13924 static void
13925 do_neon_swp (void)
13926 {
13927 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13928 neon_two_same (neon_quad (rs), 1, -1);
13929 }
13930
13931 static void
13932 do_neon_tbl_tbx (void)
13933 {
13934 unsigned listlenbits;
13935 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
13936
13937 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13938 {
13939 first_error (_("bad list length for table lookup"));
13940 return;
13941 }
13942
13943 listlenbits = inst.operands[1].imm - 1;
13944 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13945 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13946 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13947 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13948 inst.instruction |= LOW4 (inst.operands[2].reg);
13949 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13950 inst.instruction |= listlenbits << 8;
13951
13952 inst.instruction = neon_dp_fixup (inst.instruction);
13953 }
13954
13955 static void
13956 do_neon_ldm_stm (void)
13957 {
13958 /* P, U and L bits are part of bitmask. */
13959 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13960 unsigned offsetbits = inst.operands[1].imm * 2;
13961
13962 if (inst.operands[1].issingle)
13963 {
13964 do_vfp_nsyn_ldm_stm (is_dbmode);
13965 return;
13966 }
13967
13968 constraint (is_dbmode && !inst.operands[0].writeback,
13969 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13970
13971 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13972 _("register list must contain at least 1 and at most 16 "
13973 "registers"));
13974
13975 inst.instruction |= inst.operands[0].reg << 16;
13976 inst.instruction |= inst.operands[0].writeback << 21;
13977 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13978 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13979
13980 inst.instruction |= offsetbits;
13981
13982 do_vfp_cond_or_thumb ();
13983 }
13984
13985 static void
13986 do_neon_ldr_str (void)
13987 {
13988 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13989
13990 if (inst.operands[0].issingle)
13991 {
13992 if (is_ldr)
13993 do_vfp_nsyn_opcode ("flds");
13994 else
13995 do_vfp_nsyn_opcode ("fsts");
13996 }
13997 else
13998 {
13999 if (is_ldr)
14000 do_vfp_nsyn_opcode ("fldd");
14001 else
14002 do_vfp_nsyn_opcode ("fstd");
14003 }
14004 }
14005
14006 /* "interleave" version also handles non-interleaving register VLD1/VST1
14007 instructions. */
14008
14009 static void
14010 do_neon_ld_st_interleave (void)
14011 {
14012 struct neon_type_el et = neon_check_type (1, NS_NULL,
14013 N_8 | N_16 | N_32 | N_64);
14014 unsigned alignbits = 0;
14015 unsigned idx;
14016 /* The bits in this table go:
14017 0: register stride of one (0) or two (1)
14018 1,2: register list length, minus one (1, 2, 3, 4).
14019 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14020 We use -1 for invalid entries. */
14021 const int typetable[] =
14022 {
14023 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14024 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14025 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14026 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14027 };
14028 int typebits;
14029
14030 if (et.type == NT_invtype)
14031 return;
14032
14033 if (inst.operands[1].immisalign)
14034 switch (inst.operands[1].imm >> 8)
14035 {
14036 case 64: alignbits = 1; break;
14037 case 128:
14038 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14039 goto bad_alignment;
14040 alignbits = 2;
14041 break;
14042 case 256:
14043 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14044 goto bad_alignment;
14045 alignbits = 3;
14046 break;
14047 default:
14048 bad_alignment:
14049 first_error (_("bad alignment"));
14050 return;
14051 }
14052
14053 inst.instruction |= alignbits << 4;
14054 inst.instruction |= neon_logbits (et.size) << 6;
14055
14056 /* Bits [4:6] of the immediate in a list specifier encode register stride
14057 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14058 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14059 up the right value for "type" in a table based on this value and the given
14060 list style, then stick it back. */
14061 idx = ((inst.operands[0].imm >> 4) & 7)
14062 | (((inst.instruction >> 8) & 3) << 3);
14063
14064 typebits = typetable[idx];
14065
14066 constraint (typebits == -1, _("bad list type for instruction"));
14067
14068 inst.instruction &= ~0xf00;
14069 inst.instruction |= typebits << 8;
14070 }
14071
14072 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14073 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14074 otherwise. The variable arguments are a list of pairs of legal (size, align)
14075 values, terminated with -1. */
14076
14077 static int
14078 neon_alignment_bit (int size, int align, int *do_align, ...)
14079 {
14080 va_list ap;
14081 int result = FAIL, thissize, thisalign;
14082
14083 if (!inst.operands[1].immisalign)
14084 {
14085 *do_align = 0;
14086 return SUCCESS;
14087 }
14088
14089 va_start (ap, do_align);
14090
14091 do
14092 {
14093 thissize = va_arg (ap, int);
14094 if (thissize == -1)
14095 break;
14096 thisalign = va_arg (ap, int);
14097
14098 if (size == thissize && align == thisalign)
14099 result = SUCCESS;
14100 }
14101 while (result != SUCCESS);
14102
14103 va_end (ap);
14104
14105 if (result == SUCCESS)
14106 *do_align = 1;
14107 else
14108 first_error (_("unsupported alignment for instruction"));
14109
14110 return result;
14111 }
14112
14113 static void
14114 do_neon_ld_st_lane (void)
14115 {
14116 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14117 int align_good, do_align = 0;
14118 int logsize = neon_logbits (et.size);
14119 int align = inst.operands[1].imm >> 8;
14120 int n = (inst.instruction >> 8) & 3;
14121 int max_el = 64 / et.size;
14122
14123 if (et.type == NT_invtype)
14124 return;
14125
14126 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14127 _("bad list length"));
14128 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14129 _("scalar index out of range"));
14130 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14131 && et.size == 8,
14132 _("stride of 2 unavailable when element size is 8"));
14133
14134 switch (n)
14135 {
14136 case 0: /* VLD1 / VST1. */
14137 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14138 32, 32, -1);
14139 if (align_good == FAIL)
14140 return;
14141 if (do_align)
14142 {
14143 unsigned alignbits = 0;
14144 switch (et.size)
14145 {
14146 case 16: alignbits = 0x1; break;
14147 case 32: alignbits = 0x3; break;
14148 default: ;
14149 }
14150 inst.instruction |= alignbits << 4;
14151 }
14152 break;
14153
14154 case 1: /* VLD2 / VST2. */
14155 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14156 32, 64, -1);
14157 if (align_good == FAIL)
14158 return;
14159 if (do_align)
14160 inst.instruction |= 1 << 4;
14161 break;
14162
14163 case 2: /* VLD3 / VST3. */
14164 constraint (inst.operands[1].immisalign,
14165 _("can't use alignment with this instruction"));
14166 break;
14167
14168 case 3: /* VLD4 / VST4. */
14169 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14170 16, 64, 32, 64, 32, 128, -1);
14171 if (align_good == FAIL)
14172 return;
14173 if (do_align)
14174 {
14175 unsigned alignbits = 0;
14176 switch (et.size)
14177 {
14178 case 8: alignbits = 0x1; break;
14179 case 16: alignbits = 0x1; break;
14180 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14181 default: ;
14182 }
14183 inst.instruction |= alignbits << 4;
14184 }
14185 break;
14186
14187 default: ;
14188 }
14189
14190 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14191 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14192 inst.instruction |= 1 << (4 + logsize);
14193
14194 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14195 inst.instruction |= logsize << 10;
14196 }
14197
14198 /* Encode single n-element structure to all lanes VLD<n> instructions. */
14199
14200 static void
14201 do_neon_ld_dup (void)
14202 {
14203 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14204 int align_good, do_align = 0;
14205
14206 if (et.type == NT_invtype)
14207 return;
14208
14209 switch ((inst.instruction >> 8) & 3)
14210 {
14211 case 0: /* VLD1. */
14212 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
14213 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14214 &do_align, 16, 16, 32, 32, -1);
14215 if (align_good == FAIL)
14216 return;
14217 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14218 {
14219 case 1: break;
14220 case 2: inst.instruction |= 1 << 5; break;
14221 default: first_error (_("bad list length")); return;
14222 }
14223 inst.instruction |= neon_logbits (et.size) << 6;
14224 break;
14225
14226 case 1: /* VLD2. */
14227 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14228 &do_align, 8, 16, 16, 32, 32, 64, -1);
14229 if (align_good == FAIL)
14230 return;
14231 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14232 _("bad list length"));
14233 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14234 inst.instruction |= 1 << 5;
14235 inst.instruction |= neon_logbits (et.size) << 6;
14236 break;
14237
14238 case 2: /* VLD3. */
14239 constraint (inst.operands[1].immisalign,
14240 _("can't use alignment with this instruction"));
14241 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14242 _("bad list length"));
14243 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14244 inst.instruction |= 1 << 5;
14245 inst.instruction |= neon_logbits (et.size) << 6;
14246 break;
14247
14248 case 3: /* VLD4. */
14249 {
14250 int align = inst.operands[1].imm >> 8;
14251 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14252 16, 64, 32, 64, 32, 128, -1);
14253 if (align_good == FAIL)
14254 return;
14255 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14256 _("bad list length"));
14257 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14258 inst.instruction |= 1 << 5;
14259 if (et.size == 32 && align == 128)
14260 inst.instruction |= 0x3 << 6;
14261 else
14262 inst.instruction |= neon_logbits (et.size) << 6;
14263 }
14264 break;
14265
14266 default: ;
14267 }
14268
14269 inst.instruction |= do_align << 4;
14270 }
14271
14272 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14273 apart from bits [11:4]. */
14274
14275 static void
14276 do_neon_ldx_stx (void)
14277 {
14278 switch (NEON_LANE (inst.operands[0].imm))
14279 {
14280 case NEON_INTERLEAVE_LANES:
14281 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14282 do_neon_ld_st_interleave ();
14283 break;
14284
14285 case NEON_ALL_LANES:
14286 inst.instruction = NEON_ENC_DUP (inst.instruction);
14287 do_neon_ld_dup ();
14288 break;
14289
14290 default:
14291 inst.instruction = NEON_ENC_LANE (inst.instruction);
14292 do_neon_ld_st_lane ();
14293 }
14294
14295 /* L bit comes from bit mask. */
14296 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14297 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14298 inst.instruction |= inst.operands[1].reg << 16;
14299
14300 if (inst.operands[1].postind)
14301 {
14302 int postreg = inst.operands[1].imm & 0xf;
14303 constraint (!inst.operands[1].immisreg,
14304 _("post-index must be a register"));
14305 constraint (postreg == 0xd || postreg == 0xf,
14306 _("bad register for post-index"));
14307 inst.instruction |= postreg;
14308 }
14309 else if (inst.operands[1].writeback)
14310 {
14311 inst.instruction |= 0xd;
14312 }
14313 else
14314 inst.instruction |= 0xf;
14315
14316 if (thumb_mode)
14317 inst.instruction |= 0xf9000000;
14318 else
14319 inst.instruction |= 0xf4000000;
14320 }
14321 \f
14322 /* Overall per-instruction processing. */
14323
14324 /* We need to be able to fix up arbitrary expressions in some statements.
14325 This is so that we can handle symbols that are an arbitrary distance from
14326 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14327 which returns part of an address in a form which will be valid for
14328 a data instruction. We do this by pushing the expression into a symbol
14329 in the expr_section, and creating a fix for that. */
14330
14331 static void
14332 fix_new_arm (fragS * frag,
14333 int where,
14334 short int size,
14335 expressionS * exp,
14336 int pc_rel,
14337 int reloc)
14338 {
14339 fixS * new_fix;
14340
14341 switch (exp->X_op)
14342 {
14343 case O_constant:
14344 case O_symbol:
14345 case O_add:
14346 case O_subtract:
14347 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
14348 break;
14349
14350 default:
14351 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
14352 pc_rel, reloc);
14353 break;
14354 }
14355
14356 /* Mark whether the fix is to a THUMB instruction, or an ARM
14357 instruction. */
14358 new_fix->tc_fix_data = thumb_mode;
14359 }
14360
14361 /* Create a frg for an instruction requiring relaxation. */
14362 static void
14363 output_relax_insn (void)
14364 {
14365 char * to;
14366 symbolS *sym;
14367 int offset;
14368
14369 /* The size of the instruction is unknown, so tie the debug info to the
14370 start of the instruction. */
14371 dwarf2_emit_insn (0);
14372
14373 switch (inst.reloc.exp.X_op)
14374 {
14375 case O_symbol:
14376 sym = inst.reloc.exp.X_add_symbol;
14377 offset = inst.reloc.exp.X_add_number;
14378 break;
14379 case O_constant:
14380 sym = NULL;
14381 offset = inst.reloc.exp.X_add_number;
14382 break;
14383 default:
14384 sym = make_expr_symbol (&inst.reloc.exp);
14385 offset = 0;
14386 break;
14387 }
14388 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14389 inst.relax, sym, offset, NULL/*offset, opcode*/);
14390 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
14391 }
14392
14393 /* Write a 32-bit thumb instruction to buf. */
14394 static void
14395 put_thumb32_insn (char * buf, unsigned long insn)
14396 {
14397 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14398 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14399 }
14400
14401 static void
14402 output_inst (const char * str)
14403 {
14404 char * to = NULL;
14405
14406 if (inst.error)
14407 {
14408 as_bad ("%s -- `%s'", inst.error, str);
14409 return;
14410 }
14411 if (inst.relax)
14412 {
14413 output_relax_insn ();
14414 return;
14415 }
14416 if (inst.size == 0)
14417 return;
14418
14419 to = frag_more (inst.size);
14420 /* PR 9814: Record the thumb mode into the current frag so that we know
14421 what type of NOP padding to use, if necessary. We override any previous
14422 setting so that if the mode has changed then the NOPS that we use will
14423 match the encoding of the last instruction in the frag. */
14424 frag_now->tc_frag_data = thumb_mode | MODE_RECORDED;
14425
14426 if (thumb_mode && (inst.size > THUMB_SIZE))
14427 {
14428 assert (inst.size == (2 * THUMB_SIZE));
14429 put_thumb32_insn (to, inst.instruction);
14430 }
14431 else if (inst.size > INSN_SIZE)
14432 {
14433 assert (inst.size == (2 * INSN_SIZE));
14434 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14435 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
14436 }
14437 else
14438 md_number_to_chars (to, inst.instruction, inst.size);
14439
14440 if (inst.reloc.type != BFD_RELOC_UNUSED)
14441 fix_new_arm (frag_now, to - frag_now->fr_literal,
14442 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14443 inst.reloc.type);
14444
14445 dwarf2_emit_insn (inst.size);
14446 }
14447
14448 /* Tag values used in struct asm_opcode's tag field. */
14449 enum opcode_tag
14450 {
14451 OT_unconditional, /* Instruction cannot be conditionalized.
14452 The ARM condition field is still 0xE. */
14453 OT_unconditionalF, /* Instruction cannot be conditionalized
14454 and carries 0xF in its ARM condition field. */
14455 OT_csuffix, /* Instruction takes a conditional suffix. */
14456 OT_csuffixF, /* Some forms of the instruction take a conditional
14457 suffix, others place 0xF where the condition field
14458 would be. */
14459 OT_cinfix3, /* Instruction takes a conditional infix,
14460 beginning at character index 3. (In
14461 unified mode, it becomes a suffix.) */
14462 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14463 tsts, cmps, cmns, and teqs. */
14464 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14465 character index 3, even in unified mode. Used for
14466 legacy instructions where suffix and infix forms
14467 may be ambiguous. */
14468 OT_csuf_or_in3, /* Instruction takes either a conditional
14469 suffix or an infix at character index 3. */
14470 OT_odd_infix_unc, /* This is the unconditional variant of an
14471 instruction that takes a conditional infix
14472 at an unusual position. In unified mode,
14473 this variant will accept a suffix. */
14474 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
14475 are the conditional variants of instructions that
14476 take conditional infixes in unusual positions.
14477 The infix appears at character index
14478 (tag - OT_odd_infix_0). These are not accepted
14479 in unified mode. */
14480 };
14481
14482 /* Subroutine of md_assemble, responsible for looking up the primary
14483 opcode from the mnemonic the user wrote. STR points to the
14484 beginning of the mnemonic.
14485
14486 This is not simply a hash table lookup, because of conditional
14487 variants. Most instructions have conditional variants, which are
14488 expressed with a _conditional affix_ to the mnemonic. If we were
14489 to encode each conditional variant as a literal string in the opcode
14490 table, it would have approximately 20,000 entries.
14491
14492 Most mnemonics take this affix as a suffix, and in unified syntax,
14493 'most' is upgraded to 'all'. However, in the divided syntax, some
14494 instructions take the affix as an infix, notably the s-variants of
14495 the arithmetic instructions. Of those instructions, all but six
14496 have the infix appear after the third character of the mnemonic.
14497
14498 Accordingly, the algorithm for looking up primary opcodes given
14499 an identifier is:
14500
14501 1. Look up the identifier in the opcode table.
14502 If we find a match, go to step U.
14503
14504 2. Look up the last two characters of the identifier in the
14505 conditions table. If we find a match, look up the first N-2
14506 characters of the identifier in the opcode table. If we
14507 find a match, go to step CE.
14508
14509 3. Look up the fourth and fifth characters of the identifier in
14510 the conditions table. If we find a match, extract those
14511 characters from the identifier, and look up the remaining
14512 characters in the opcode table. If we find a match, go
14513 to step CM.
14514
14515 4. Fail.
14516
14517 U. Examine the tag field of the opcode structure, in case this is
14518 one of the six instructions with its conditional infix in an
14519 unusual place. If it is, the tag tells us where to find the
14520 infix; look it up in the conditions table and set inst.cond
14521 accordingly. Otherwise, this is an unconditional instruction.
14522 Again set inst.cond accordingly. Return the opcode structure.
14523
14524 CE. Examine the tag field to make sure this is an instruction that
14525 should receive a conditional suffix. If it is not, fail.
14526 Otherwise, set inst.cond from the suffix we already looked up,
14527 and return the opcode structure.
14528
14529 CM. Examine the tag field to make sure this is an instruction that
14530 should receive a conditional infix after the third character.
14531 If it is not, fail. Otherwise, undo the edits to the current
14532 line of input and proceed as for case CE. */
14533
14534 static const struct asm_opcode *
14535 opcode_lookup (char **str)
14536 {
14537 char *end, *base;
14538 char *affix;
14539 const struct asm_opcode *opcode;
14540 const struct asm_cond *cond;
14541 char save[2];
14542 bfd_boolean neon_supported;
14543
14544 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14545
14546 /* Scan up to the end of the mnemonic, which must end in white space,
14547 '.' (in unified mode, or for Neon instructions), or end of string. */
14548 for (base = end = *str; *end != '\0'; end++)
14549 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14550 break;
14551
14552 if (end == base)
14553 return 0;
14554
14555 /* Handle a possible width suffix and/or Neon type suffix. */
14556 if (end[0] == '.')
14557 {
14558 int offset = 2;
14559
14560 /* The .w and .n suffixes are only valid if the unified syntax is in
14561 use. */
14562 if (unified_syntax && end[1] == 'w')
14563 inst.size_req = 4;
14564 else if (unified_syntax && end[1] == 'n')
14565 inst.size_req = 2;
14566 else
14567 offset = 0;
14568
14569 inst.vectype.elems = 0;
14570
14571 *str = end + offset;
14572
14573 if (end[offset] == '.')
14574 {
14575 /* See if we have a Neon type suffix (possible in either unified or
14576 non-unified ARM syntax mode). */
14577 if (parse_neon_type (&inst.vectype, str) == FAIL)
14578 return 0;
14579 }
14580 else if (end[offset] != '\0' && end[offset] != ' ')
14581 return 0;
14582 }
14583 else
14584 *str = end;
14585
14586 /* Look for unaffixed or special-case affixed mnemonic. */
14587 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14588 if (opcode)
14589 {
14590 /* step U */
14591 if (opcode->tag < OT_odd_infix_0)
14592 {
14593 inst.cond = COND_ALWAYS;
14594 return opcode;
14595 }
14596
14597 if (warn_on_deprecated && unified_syntax)
14598 as_warn (_("conditional infixes are deprecated in unified syntax"));
14599 affix = base + (opcode->tag - OT_odd_infix_0);
14600 cond = hash_find_n (arm_cond_hsh, affix, 2);
14601 assert (cond);
14602
14603 inst.cond = cond->value;
14604 return opcode;
14605 }
14606
14607 /* Cannot have a conditional suffix on a mnemonic of less than two
14608 characters. */
14609 if (end - base < 3)
14610 return 0;
14611
14612 /* Look for suffixed mnemonic. */
14613 affix = end - 2;
14614 cond = hash_find_n (arm_cond_hsh, affix, 2);
14615 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14616 if (opcode && cond)
14617 {
14618 /* step CE */
14619 switch (opcode->tag)
14620 {
14621 case OT_cinfix3_legacy:
14622 /* Ignore conditional suffixes matched on infix only mnemonics. */
14623 break;
14624
14625 case OT_cinfix3:
14626 case OT_cinfix3_deprecated:
14627 case OT_odd_infix_unc:
14628 if (!unified_syntax)
14629 return 0;
14630 /* else fall through */
14631
14632 case OT_csuffix:
14633 case OT_csuffixF:
14634 case OT_csuf_or_in3:
14635 inst.cond = cond->value;
14636 return opcode;
14637
14638 case OT_unconditional:
14639 case OT_unconditionalF:
14640 if (thumb_mode)
14641 {
14642 inst.cond = cond->value;
14643 }
14644 else
14645 {
14646 /* delayed diagnostic */
14647 inst.error = BAD_COND;
14648 inst.cond = COND_ALWAYS;
14649 }
14650 return opcode;
14651
14652 default:
14653 return 0;
14654 }
14655 }
14656
14657 /* Cannot have a usual-position infix on a mnemonic of less than
14658 six characters (five would be a suffix). */
14659 if (end - base < 6)
14660 return 0;
14661
14662 /* Look for infixed mnemonic in the usual position. */
14663 affix = base + 3;
14664 cond = hash_find_n (arm_cond_hsh, affix, 2);
14665 if (!cond)
14666 return 0;
14667
14668 memcpy (save, affix, 2);
14669 memmove (affix, affix + 2, (end - affix) - 2);
14670 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14671 memmove (affix + 2, affix, (end - affix) - 2);
14672 memcpy (affix, save, 2);
14673
14674 if (opcode
14675 && (opcode->tag == OT_cinfix3
14676 || opcode->tag == OT_cinfix3_deprecated
14677 || opcode->tag == OT_csuf_or_in3
14678 || opcode->tag == OT_cinfix3_legacy))
14679 {
14680 /* step CM */
14681 if (warn_on_deprecated && unified_syntax
14682 && (opcode->tag == OT_cinfix3
14683 || opcode->tag == OT_cinfix3_deprecated))
14684 as_warn (_("conditional infixes are deprecated in unified syntax"));
14685
14686 inst.cond = cond->value;
14687 return opcode;
14688 }
14689
14690 return 0;
14691 }
14692
14693 void
14694 md_assemble (char *str)
14695 {
14696 char *p = str;
14697 const struct asm_opcode * opcode;
14698
14699 /* Align the previous label if needed. */
14700 if (last_label_seen != NULL)
14701 {
14702 symbol_set_frag (last_label_seen, frag_now);
14703 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14704 S_SET_SEGMENT (last_label_seen, now_seg);
14705 }
14706
14707 memset (&inst, '\0', sizeof (inst));
14708 inst.reloc.type = BFD_RELOC_UNUSED;
14709
14710 opcode = opcode_lookup (&p);
14711 if (!opcode)
14712 {
14713 /* It wasn't an instruction, but it might be a register alias of
14714 the form alias .req reg, or a Neon .dn/.qn directive. */
14715 if (!create_register_alias (str, p)
14716 && !create_neon_reg_alias (str, p))
14717 as_bad (_("bad instruction `%s'"), str);
14718
14719 return;
14720 }
14721
14722 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
14723 as_warn (_("s suffix on comparison instruction is deprecated"));
14724
14725 /* The value which unconditional instructions should have in place of the
14726 condition field. */
14727 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14728
14729 if (thumb_mode)
14730 {
14731 arm_feature_set variant;
14732
14733 variant = cpu_variant;
14734 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
14735 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14736 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
14737 /* Check that this instruction is supported for this CPU. */
14738 if (!opcode->tvariant
14739 || (thumb_mode == 1
14740 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
14741 {
14742 as_bad (_("selected processor does not support `%s'"), str);
14743 return;
14744 }
14745 if (inst.cond != COND_ALWAYS && !unified_syntax
14746 && opcode->tencode != do_t_branch)
14747 {
14748 as_bad (_("Thumb does not support conditional execution"));
14749 return;
14750 }
14751
14752 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14753 {
14754 /* Implicit require narrow instructions on Thumb-1. This avoids
14755 relaxation accidentally introducing Thumb-2 instructions. */
14756 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14757 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
14758 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
14759 inst.size_req = 2;
14760 }
14761
14762 /* Check conditional suffixes. */
14763 if (current_it_mask)
14764 {
14765 int cond;
14766 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
14767 current_it_mask <<= 1;
14768 current_it_mask &= 0x1f;
14769 /* The BKPT instruction is unconditional even in an IT block. */
14770 if (!inst.error
14771 && cond != inst.cond && opcode->tencode != do_t_bkpt)
14772 {
14773 as_bad (_("incorrect condition in IT block"));
14774 return;
14775 }
14776 }
14777 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14778 {
14779 as_bad (_("thumb conditional instruction not in IT block"));
14780 return;
14781 }
14782
14783 mapping_state (MAP_THUMB);
14784 inst.instruction = opcode->tvalue;
14785
14786 if (!parse_operands (p, opcode->operands))
14787 opcode->tencode ();
14788
14789 /* Clear current_it_mask at the end of an IT block. */
14790 if (current_it_mask == 0x10)
14791 current_it_mask = 0;
14792
14793 if (!(inst.error || inst.relax))
14794 {
14795 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14796 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14797 if (inst.size_req && inst.size_req != inst.size)
14798 {
14799 as_bad (_("cannot honor width suffix -- `%s'"), str);
14800 return;
14801 }
14802 }
14803
14804 /* Something has gone badly wrong if we try to relax a fixed size
14805 instruction. */
14806 assert (inst.size_req == 0 || !inst.relax);
14807
14808 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14809 *opcode->tvariant);
14810 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
14811 set those bits when Thumb-2 32-bit instructions are seen. ie.
14812 anything other than bl/blx and v6-M instructions.
14813 This is overly pessimistic for relaxable instructions. */
14814 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14815 || inst.relax)
14816 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
14817 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
14818 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14819 arm_ext_v6t2);
14820 }
14821 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
14822 {
14823 bfd_boolean is_bx;
14824
14825 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14826 is_bx = (opcode->aencode == do_bx);
14827
14828 /* Check that this instruction is supported for this CPU. */
14829 if (!(is_bx && fix_v4bx)
14830 && !(opcode->avariant &&
14831 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
14832 {
14833 as_bad (_("selected processor does not support `%s'"), str);
14834 return;
14835 }
14836 if (inst.size_req)
14837 {
14838 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14839 return;
14840 }
14841
14842 mapping_state (MAP_ARM);
14843 inst.instruction = opcode->avalue;
14844 if (opcode->tag == OT_unconditionalF)
14845 inst.instruction |= 0xF << 28;
14846 else
14847 inst.instruction |= inst.cond << 28;
14848 inst.size = INSN_SIZE;
14849 if (!parse_operands (p, opcode->operands))
14850 opcode->aencode ();
14851 /* Arm mode bx is marked as both v4T and v5 because it's still required
14852 on a hypothetical non-thumb v5 core. */
14853 if (is_bx)
14854 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
14855 else
14856 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14857 *opcode->avariant);
14858 }
14859 else
14860 {
14861 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14862 "-- `%s'"), str);
14863 return;
14864 }
14865 output_inst (str);
14866 }
14867
14868 /* Various frobbings of labels and their addresses. */
14869
14870 void
14871 arm_start_line_hook (void)
14872 {
14873 last_label_seen = NULL;
14874 }
14875
14876 void
14877 arm_frob_label (symbolS * sym)
14878 {
14879 last_label_seen = sym;
14880
14881 ARM_SET_THUMB (sym, thumb_mode);
14882
14883 #if defined OBJ_COFF || defined OBJ_ELF
14884 ARM_SET_INTERWORK (sym, support_interwork);
14885 #endif
14886
14887 /* Note - do not allow local symbols (.Lxxx) to be labelled
14888 as Thumb functions. This is because these labels, whilst
14889 they exist inside Thumb code, are not the entry points for
14890 possible ARM->Thumb calls. Also, these labels can be used
14891 as part of a computed goto or switch statement. eg gcc
14892 can generate code that looks like this:
14893
14894 ldr r2, [pc, .Laaa]
14895 lsl r3, r3, #2
14896 ldr r2, [r3, r2]
14897 mov pc, r2
14898
14899 .Lbbb: .word .Lxxx
14900 .Lccc: .word .Lyyy
14901 ..etc...
14902 .Laaa: .word Lbbb
14903
14904 The first instruction loads the address of the jump table.
14905 The second instruction converts a table index into a byte offset.
14906 The third instruction gets the jump address out of the table.
14907 The fourth instruction performs the jump.
14908
14909 If the address stored at .Laaa is that of a symbol which has the
14910 Thumb_Func bit set, then the linker will arrange for this address
14911 to have the bottom bit set, which in turn would mean that the
14912 address computation performed by the third instruction would end
14913 up with the bottom bit set. Since the ARM is capable of unaligned
14914 word loads, the instruction would then load the incorrect address
14915 out of the jump table, and chaos would ensue. */
14916 if (label_is_thumb_function_name
14917 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14918 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
14919 {
14920 /* When the address of a Thumb function is taken the bottom
14921 bit of that address should be set. This will allow
14922 interworking between Arm and Thumb functions to work
14923 correctly. */
14924
14925 THUMB_SET_FUNC (sym, 1);
14926
14927 label_is_thumb_function_name = FALSE;
14928 }
14929
14930 dwarf2_emit_label (sym);
14931 }
14932
14933 int
14934 arm_data_in_code (void)
14935 {
14936 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
14937 {
14938 *input_line_pointer = '/';
14939 input_line_pointer += 5;
14940 *input_line_pointer = 0;
14941 return 1;
14942 }
14943
14944 return 0;
14945 }
14946
14947 char *
14948 arm_canonicalize_symbol_name (char * name)
14949 {
14950 int len;
14951
14952 if (thumb_mode && (len = strlen (name)) > 5
14953 && streq (name + len - 5, "/data"))
14954 *(name + len - 5) = 0;
14955
14956 return name;
14957 }
14958 \f
14959 /* Table of all register names defined by default. The user can
14960 define additional names with .req. Note that all register names
14961 should appear in both upper and lowercase variants. Some registers
14962 also have mixed-case names. */
14963
14964 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
14965 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
14966 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
14967 #define REGSET(p,t) \
14968 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14969 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14970 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14971 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
14972 #define REGSETH(p,t) \
14973 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14974 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14975 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14976 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14977 #define REGSET2(p,t) \
14978 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14979 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14980 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14981 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
14982
14983 static const struct reg_entry reg_names[] =
14984 {
14985 /* ARM integer registers. */
14986 REGSET(r, RN), REGSET(R, RN),
14987
14988 /* ATPCS synonyms. */
14989 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14990 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14991 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
14992
14993 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14994 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14995 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
14996
14997 /* Well-known aliases. */
14998 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14999 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
15000
15001 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
15002 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
15003
15004 /* Coprocessor numbers. */
15005 REGSET(p, CP), REGSET(P, CP),
15006
15007 /* Coprocessor register numbers. The "cr" variants are for backward
15008 compatibility. */
15009 REGSET(c, CN), REGSET(C, CN),
15010 REGSET(cr, CN), REGSET(CR, CN),
15011
15012 /* FPA registers. */
15013 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
15014 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
15015
15016 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
15017 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
15018
15019 /* VFP SP registers. */
15020 REGSET(s,VFS), REGSET(S,VFS),
15021 REGSETH(s,VFS), REGSETH(S,VFS),
15022
15023 /* VFP DP Registers. */
15024 REGSET(d,VFD), REGSET(D,VFD),
15025 /* Extra Neon DP registers. */
15026 REGSETH(d,VFD), REGSETH(D,VFD),
15027
15028 /* Neon QP registers. */
15029 REGSET2(q,NQ), REGSET2(Q,NQ),
15030
15031 /* VFP control registers. */
15032 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15033 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
15034 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15035 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15036 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15037 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
15038
15039 /* Maverick DSP coprocessor registers. */
15040 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15041 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15042
15043 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15044 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15045 REGDEF(dspsc,0,DSPSC),
15046
15047 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15048 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15049 REGDEF(DSPSC,0,DSPSC),
15050
15051 /* iWMMXt data registers - p0, c0-15. */
15052 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15053
15054 /* iWMMXt control registers - p1, c0-3. */
15055 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15056 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15057 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15058 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15059
15060 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15061 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15062 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15063 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15064 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15065
15066 /* XScale accumulator registers. */
15067 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15068 };
15069 #undef REGDEF
15070 #undef REGNUM
15071 #undef REGSET
15072
15073 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15074 within psr_required_here. */
15075 static const struct asm_psr psrs[] =
15076 {
15077 /* Backward compatibility notation. Note that "all" is no longer
15078 truly all possible PSR bits. */
15079 {"all", PSR_c | PSR_f},
15080 {"flg", PSR_f},
15081 {"ctl", PSR_c},
15082
15083 /* Individual flags. */
15084 {"f", PSR_f},
15085 {"c", PSR_c},
15086 {"x", PSR_x},
15087 {"s", PSR_s},
15088 /* Combinations of flags. */
15089 {"fs", PSR_f | PSR_s},
15090 {"fx", PSR_f | PSR_x},
15091 {"fc", PSR_f | PSR_c},
15092 {"sf", PSR_s | PSR_f},
15093 {"sx", PSR_s | PSR_x},
15094 {"sc", PSR_s | PSR_c},
15095 {"xf", PSR_x | PSR_f},
15096 {"xs", PSR_x | PSR_s},
15097 {"xc", PSR_x | PSR_c},
15098 {"cf", PSR_c | PSR_f},
15099 {"cs", PSR_c | PSR_s},
15100 {"cx", PSR_c | PSR_x},
15101 {"fsx", PSR_f | PSR_s | PSR_x},
15102 {"fsc", PSR_f | PSR_s | PSR_c},
15103 {"fxs", PSR_f | PSR_x | PSR_s},
15104 {"fxc", PSR_f | PSR_x | PSR_c},
15105 {"fcs", PSR_f | PSR_c | PSR_s},
15106 {"fcx", PSR_f | PSR_c | PSR_x},
15107 {"sfx", PSR_s | PSR_f | PSR_x},
15108 {"sfc", PSR_s | PSR_f | PSR_c},
15109 {"sxf", PSR_s | PSR_x | PSR_f},
15110 {"sxc", PSR_s | PSR_x | PSR_c},
15111 {"scf", PSR_s | PSR_c | PSR_f},
15112 {"scx", PSR_s | PSR_c | PSR_x},
15113 {"xfs", PSR_x | PSR_f | PSR_s},
15114 {"xfc", PSR_x | PSR_f | PSR_c},
15115 {"xsf", PSR_x | PSR_s | PSR_f},
15116 {"xsc", PSR_x | PSR_s | PSR_c},
15117 {"xcf", PSR_x | PSR_c | PSR_f},
15118 {"xcs", PSR_x | PSR_c | PSR_s},
15119 {"cfs", PSR_c | PSR_f | PSR_s},
15120 {"cfx", PSR_c | PSR_f | PSR_x},
15121 {"csf", PSR_c | PSR_s | PSR_f},
15122 {"csx", PSR_c | PSR_s | PSR_x},
15123 {"cxf", PSR_c | PSR_x | PSR_f},
15124 {"cxs", PSR_c | PSR_x | PSR_s},
15125 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
15126 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
15127 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
15128 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
15129 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
15130 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
15131 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
15132 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
15133 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
15134 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
15135 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
15136 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
15137 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
15138 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
15139 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
15140 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
15141 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
15142 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
15143 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
15144 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
15145 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
15146 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
15147 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
15148 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
15149 };
15150
15151 /* Table of V7M psr names. */
15152 static const struct asm_psr v7m_psrs[] =
15153 {
15154 {"apsr", 0 }, {"APSR", 0 },
15155 {"iapsr", 1 }, {"IAPSR", 1 },
15156 {"eapsr", 2 }, {"EAPSR", 2 },
15157 {"psr", 3 }, {"PSR", 3 },
15158 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
15159 {"ipsr", 5 }, {"IPSR", 5 },
15160 {"epsr", 6 }, {"EPSR", 6 },
15161 {"iepsr", 7 }, {"IEPSR", 7 },
15162 {"msp", 8 }, {"MSP", 8 },
15163 {"psp", 9 }, {"PSP", 9 },
15164 {"primask", 16}, {"PRIMASK", 16},
15165 {"basepri", 17}, {"BASEPRI", 17},
15166 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
15167 {"faultmask", 19}, {"FAULTMASK", 19},
15168 {"control", 20}, {"CONTROL", 20}
15169 };
15170
15171 /* Table of all shift-in-operand names. */
15172 static const struct asm_shift_name shift_names [] =
15173 {
15174 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
15175 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
15176 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
15177 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
15178 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
15179 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
15180 };
15181
15182 /* Table of all explicit relocation names. */
15183 #ifdef OBJ_ELF
15184 static struct reloc_entry reloc_names[] =
15185 {
15186 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
15187 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
15188 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
15189 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
15190 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
15191 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
15192 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
15193 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
15194 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
15195 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
15196 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
15197 };
15198 #endif
15199
15200 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
15201 static const struct asm_cond conds[] =
15202 {
15203 {"eq", 0x0},
15204 {"ne", 0x1},
15205 {"cs", 0x2}, {"hs", 0x2},
15206 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
15207 {"mi", 0x4},
15208 {"pl", 0x5},
15209 {"vs", 0x6},
15210 {"vc", 0x7},
15211 {"hi", 0x8},
15212 {"ls", 0x9},
15213 {"ge", 0xa},
15214 {"lt", 0xb},
15215 {"gt", 0xc},
15216 {"le", 0xd},
15217 {"al", 0xe}
15218 };
15219
15220 static struct asm_barrier_opt barrier_opt_names[] =
15221 {
15222 { "sy", 0xf },
15223 { "un", 0x7 },
15224 { "st", 0xe },
15225 { "unst", 0x6 }
15226 };
15227
15228 /* Table of ARM-format instructions. */
15229
15230 /* Macros for gluing together operand strings. N.B. In all cases
15231 other than OPS0, the trailing OP_stop comes from default
15232 zero-initialization of the unspecified elements of the array. */
15233 #define OPS0() { OP_stop, }
15234 #define OPS1(a) { OP_##a, }
15235 #define OPS2(a,b) { OP_##a,OP_##b, }
15236 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
15237 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
15238 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
15239 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
15240
15241 /* These macros abstract out the exact format of the mnemonic table and
15242 save some repeated characters. */
15243
15244 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
15245 #define TxCE(mnem, op, top, nops, ops, ae, te) \
15246 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
15247 THUMB_VARIANT, do_##ae, do_##te }
15248
15249 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
15250 a T_MNEM_xyz enumerator. */
15251 #define TCE(mnem, aop, top, nops, ops, ae, te) \
15252 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
15253 #define tCE(mnem, aop, top, nops, ops, ae, te) \
15254 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15255
15256 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
15257 infix after the third character. */
15258 #define TxC3(mnem, op, top, nops, ops, ae, te) \
15259 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
15260 THUMB_VARIANT, do_##ae, do_##te }
15261 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
15262 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
15263 THUMB_VARIANT, do_##ae, do_##te }
15264 #define TC3(mnem, aop, top, nops, ops, ae, te) \
15265 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
15266 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
15267 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
15268 #define tC3(mnem, aop, top, nops, ops, ae, te) \
15269 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15270 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
15271 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15272
15273 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
15274 appear in the condition table. */
15275 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
15276 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
15277 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
15278
15279 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
15280 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
15281 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
15282 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
15283 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
15284 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
15285 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
15286 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
15287 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
15288 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
15289 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
15290 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
15291 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
15292 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
15293 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
15294 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
15295 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
15296 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
15297 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
15298 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
15299
15300 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
15301 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
15302 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
15303 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
15304
15305 /* Mnemonic that cannot be conditionalized. The ARM condition-code
15306 field is still 0xE. Many of the Thumb variants can be executed
15307 conditionally, so this is checked separately. */
15308 #define TUE(mnem, op, top, nops, ops, ae, te) \
15309 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
15310 THUMB_VARIANT, do_##ae, do_##te }
15311
15312 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
15313 condition code field. */
15314 #define TUF(mnem, op, top, nops, ops, ae, te) \
15315 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
15316 THUMB_VARIANT, do_##ae, do_##te }
15317
15318 /* ARM-only variants of all the above. */
15319 #define CE(mnem, op, nops, ops, ae) \
15320 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15321
15322 #define C3(mnem, op, nops, ops, ae) \
15323 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15324
15325 /* Legacy mnemonics that always have conditional infix after the third
15326 character. */
15327 #define CL(mnem, op, nops, ops, ae) \
15328 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15329 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15330
15331 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
15332 #define cCE(mnem, op, nops, ops, ae) \
15333 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15334
15335 /* Legacy coprocessor instructions where conditional infix and conditional
15336 suffix are ambiguous. For consistency this includes all FPA instructions,
15337 not just the potentially ambiguous ones. */
15338 #define cCL(mnem, op, nops, ops, ae) \
15339 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15340 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15341
15342 /* Coprocessor, takes either a suffix or a position-3 infix
15343 (for an FPA corner case). */
15344 #define C3E(mnem, op, nops, ops, ae) \
15345 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
15346 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15347
15348 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
15349 { #m1 #m2 #m3, OPS##nops ops, \
15350 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
15351 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15352
15353 #define CM(m1, m2, op, nops, ops, ae) \
15354 xCM_(m1, , m2, op, nops, ops, ae), \
15355 xCM_(m1, eq, m2, op, nops, ops, ae), \
15356 xCM_(m1, ne, m2, op, nops, ops, ae), \
15357 xCM_(m1, cs, m2, op, nops, ops, ae), \
15358 xCM_(m1, hs, m2, op, nops, ops, ae), \
15359 xCM_(m1, cc, m2, op, nops, ops, ae), \
15360 xCM_(m1, ul, m2, op, nops, ops, ae), \
15361 xCM_(m1, lo, m2, op, nops, ops, ae), \
15362 xCM_(m1, mi, m2, op, nops, ops, ae), \
15363 xCM_(m1, pl, m2, op, nops, ops, ae), \
15364 xCM_(m1, vs, m2, op, nops, ops, ae), \
15365 xCM_(m1, vc, m2, op, nops, ops, ae), \
15366 xCM_(m1, hi, m2, op, nops, ops, ae), \
15367 xCM_(m1, ls, m2, op, nops, ops, ae), \
15368 xCM_(m1, ge, m2, op, nops, ops, ae), \
15369 xCM_(m1, lt, m2, op, nops, ops, ae), \
15370 xCM_(m1, gt, m2, op, nops, ops, ae), \
15371 xCM_(m1, le, m2, op, nops, ops, ae), \
15372 xCM_(m1, al, m2, op, nops, ops, ae)
15373
15374 #define UE(mnem, op, nops, ops, ae) \
15375 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15376
15377 #define UF(mnem, op, nops, ops, ae) \
15378 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15379
15380 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
15381 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
15382 use the same encoding function for each. */
15383 #define NUF(mnem, op, nops, ops, enc) \
15384 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
15385 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15386
15387 /* Neon data processing, version which indirects through neon_enc_tab for
15388 the various overloaded versions of opcodes. */
15389 #define nUF(mnem, op, nops, ops, enc) \
15390 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
15391 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15392
15393 /* Neon insn with conditional suffix for the ARM version, non-overloaded
15394 version. */
15395 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
15396 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
15397 THUMB_VARIANT, do_##enc, do_##enc }
15398
15399 #define NCE(mnem, op, nops, ops, enc) \
15400 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15401
15402 #define NCEF(mnem, op, nops, ops, enc) \
15403 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15404
15405 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
15406 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
15407 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
15408 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15409
15410 #define nCE(mnem, op, nops, ops, enc) \
15411 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15412
15413 #define nCEF(mnem, op, nops, ops, enc) \
15414 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15415
15416 #define do_0 0
15417
15418 /* Thumb-only, unconditional. */
15419 #define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
15420
15421 static const struct asm_opcode insns[] =
15422 {
15423 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
15424 #define THUMB_VARIANT &arm_ext_v4t
15425 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
15426 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
15427 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
15428 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
15429 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
15430 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
15431 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
15432 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
15433 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
15434 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
15435 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
15436 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
15437 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
15438 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
15439 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
15440 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
15441
15442 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
15443 for setting PSR flag bits. They are obsolete in V6 and do not
15444 have Thumb equivalents. */
15445 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
15446 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
15447 CL(tstp, 110f000, 2, (RR, SH), cmp),
15448 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
15449 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
15450 CL(cmpp, 150f000, 2, (RR, SH), cmp),
15451 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
15452 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
15453 CL(cmnp, 170f000, 2, (RR, SH), cmp),
15454
15455 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
15456 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
15457 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
15458 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
15459
15460 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
15461 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15462 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
15463 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15464
15465 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15466 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15467 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15468 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15469 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15470 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15471
15472 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
15473 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
15474 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
15475 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
15476
15477 /* Pseudo ops. */
15478 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
15479 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
15480 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
15481
15482 /* Thumb-compatibility pseudo ops. */
15483 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
15484 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
15485 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
15486 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
15487 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
15488 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
15489 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
15490 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
15491 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
15492 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
15493 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
15494 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
15495
15496 /* These may simplify to neg. */
15497 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
15498 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
15499
15500 #undef THUMB_VARIANT
15501 #define THUMB_VARIANT &arm_ext_v6
15502 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
15503
15504 /* V1 instructions with no Thumb analogue prior to V6T2. */
15505 #undef THUMB_VARIANT
15506 #define THUMB_VARIANT &arm_ext_v6t2
15507 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
15508 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
15509 CL(teqp, 130f000, 2, (RR, SH), cmp),
15510
15511 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
15512 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
15513 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
15514 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
15515
15516 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15517 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15518
15519 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15520 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15521
15522 /* V1 instructions with no Thumb analogue at all. */
15523 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15524 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15525
15526 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15527 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15528 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15529 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15530 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15531 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15532 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15533 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15534
15535 #undef ARM_VARIANT
15536 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
15537 #undef THUMB_VARIANT
15538 #define THUMB_VARIANT &arm_ext_v4t
15539 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15540 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15541
15542 #undef THUMB_VARIANT
15543 #define THUMB_VARIANT &arm_ext_v6t2
15544 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15545 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15546
15547 /* Generic coprocessor instructions. */
15548 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15549 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15550 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15551 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15552 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15553 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15554 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15555
15556 #undef ARM_VARIANT
15557 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
15558 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15559 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15560
15561 #undef ARM_VARIANT
15562 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
15563 #undef THUMB_VARIANT
15564 #define THUMB_VARIANT &arm_ext_msr
15565 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15566 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
15567
15568 #undef ARM_VARIANT
15569 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
15570 #undef THUMB_VARIANT
15571 #define THUMB_VARIANT &arm_ext_v6t2
15572 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15573 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15574 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15575 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15576 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15577 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15578 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15579 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15580
15581 #undef ARM_VARIANT
15582 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
15583 #undef THUMB_VARIANT
15584 #define THUMB_VARIANT &arm_ext_v4t
15585 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15586 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15587 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15588 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15589 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15590 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15591
15592 #undef ARM_VARIANT
15593 #define ARM_VARIANT &arm_ext_v4t_5
15594 /* ARM Architecture 4T. */
15595 /* Note: bx (and blx) are required on V5, even if the processor does
15596 not support Thumb. */
15597 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15598
15599 #undef ARM_VARIANT
15600 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
15601 #undef THUMB_VARIANT
15602 #define THUMB_VARIANT &arm_ext_v5t
15603 /* Note: blx has 2 variants; the .value coded here is for
15604 BLX(2). Only this variant has conditional execution. */
15605 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15606 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15607
15608 #undef THUMB_VARIANT
15609 #define THUMB_VARIANT &arm_ext_v6t2
15610 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
15611 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15612 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15613 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15614 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15615 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15616 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15617 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15618
15619 #undef ARM_VARIANT
15620 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
15621 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15622 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15623 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15624 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15625
15626 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15627 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15628
15629 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15630 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15631 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15632 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15633
15634 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15635 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15636 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15637 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15638
15639 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15640 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15641
15642 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15643 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15644 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15645 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15646
15647 #undef ARM_VARIANT
15648 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
15649 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
15650 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15651 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15652
15653 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15654 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15655
15656 #undef ARM_VARIANT
15657 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
15658 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15659
15660 #undef ARM_VARIANT
15661 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
15662 #undef THUMB_VARIANT
15663 #define THUMB_VARIANT &arm_ext_v6
15664 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15665 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15666 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15667 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15668 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15669 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15670 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15671 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15672 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15673 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15674
15675 #undef THUMB_VARIANT
15676 #define THUMB_VARIANT &arm_ext_v6t2
15677 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
15678 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
15679 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15680 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15681
15682 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15683 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15684
15685 /* ARM V6 not included in V7M (eg. integer SIMD). */
15686 #undef THUMB_VARIANT
15687 #define THUMB_VARIANT &arm_ext_v6_notm
15688 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
15689 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15690 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15691 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15692 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15693 TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15694 /* Old name for QASX. */
15695 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15696 TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15697 /* Old name for QSAX. */
15698 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15699 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15700 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15701 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15702 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15703 TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15704 /* Old name for SASX. */
15705 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15706 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15707 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15708 TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15709 /* Old name for SHASX. */
15710 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15711 TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15712 /* Old name for SHSAX. */
15713 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15714 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15715 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15716 TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15717 /* Old name for SSAX. */
15718 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15719 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15720 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15721 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15722 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15723 TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15724 /* Old name for UASX. */
15725 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15726 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15727 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15728 TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15729 /* Old name for UHASX. */
15730 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15731 TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15732 /* Old name for UHSAX. */
15733 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15734 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15735 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15736 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15737 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15738 TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15739 /* Old name for UQASX. */
15740 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15741 TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15742 /* Old name for UQSAX. */
15743 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15744 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15745 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15746 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15747 TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15748 /* Old name for USAX. */
15749 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15750 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15751 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15752 UF(rfeib, 9900a00, 1, (RRw), rfe),
15753 UF(rfeda, 8100a00, 1, (RRw), rfe),
15754 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15755 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15756 UF(rfefa, 9900a00, 1, (RRw), rfe),
15757 UF(rfeea, 8100a00, 1, (RRw), rfe),
15758 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15759 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15760 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15761 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15762 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15763 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15764 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15765 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15766 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15767 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15768 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15769 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15770 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15771 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15772 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15773 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15774 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15775 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15776 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15777 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15778 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15779 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15780 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15781 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15782 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15783 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15784 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15785 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15786 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15787 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15788 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15789 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
15790 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
15791 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15792 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15793 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15794 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15795
15796 #undef ARM_VARIANT
15797 #define ARM_VARIANT &arm_ext_v6k
15798 #undef THUMB_VARIANT
15799 #define THUMB_VARIANT &arm_ext_v6k
15800 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15801 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15802 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15803 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15804
15805 #undef THUMB_VARIANT
15806 #define THUMB_VARIANT &arm_ext_v6_notm
15807 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15808 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15809
15810 #undef THUMB_VARIANT
15811 #define THUMB_VARIANT &arm_ext_v6t2
15812 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15813 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15814 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15815 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15816 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15817
15818 #undef ARM_VARIANT
15819 #define ARM_VARIANT &arm_ext_v6z
15820 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
15821
15822 #undef ARM_VARIANT
15823 #define ARM_VARIANT &arm_ext_v6t2
15824 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15825 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15826 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15827 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15828
15829 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15830 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15831 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
15832 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
15833
15834 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15835 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15836 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15837 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15838
15839 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15840 UT(cbz, b100, 2, (RR, EXP), t_cbz),
15841 /* ARM does not really have an IT instruction, so always allow it. */
15842 #undef ARM_VARIANT
15843 #define ARM_VARIANT &arm_ext_v1
15844 TUE(it, 0, bf08, 1, (COND), it, t_it),
15845 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15846 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15847 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15848 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15849 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15850 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15851 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15852 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15853 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15854 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15855 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15856 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15857 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15858 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15859 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
15860 TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
15861 TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
15862
15863 /* Thumb2 only instructions. */
15864 #undef ARM_VARIANT
15865 #define ARM_VARIANT NULL
15866
15867 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15868 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15869 TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
15870 TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
15871 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15872 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15873
15874 /* Thumb-2 hardware division instructions (R and M profiles only). */
15875 #undef THUMB_VARIANT
15876 #define THUMB_VARIANT &arm_ext_div
15877 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15878 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15879
15880 /* ARM V6M/V7 instructions. */
15881 #undef ARM_VARIANT
15882 #define ARM_VARIANT &arm_ext_barrier
15883 #undef THUMB_VARIANT
15884 #define THUMB_VARIANT &arm_ext_barrier
15885 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15886 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15887 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15888
15889 /* ARM V7 instructions. */
15890 #undef ARM_VARIANT
15891 #define ARM_VARIANT &arm_ext_v7
15892 #undef THUMB_VARIANT
15893 #define THUMB_VARIANT &arm_ext_v7
15894 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15895 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15896
15897 #undef ARM_VARIANT
15898 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
15899 cCE(wfs, e200110, 1, (RR), rd),
15900 cCE(rfs, e300110, 1, (RR), rd),
15901 cCE(wfc, e400110, 1, (RR), rd),
15902 cCE(rfc, e500110, 1, (RR), rd),
15903
15904 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15905 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15906 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15907 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
15908
15909 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15910 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15911 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15912 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
15913
15914 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15915 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15916 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15917 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15918 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15919 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15920 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15921 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15922 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15923 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15924 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15925 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15926
15927 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15928 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15929 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15930 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15931 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15932 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15933 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15934 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15935 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15936 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15937 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15938 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15939
15940 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15941 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15942 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15943 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15944 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15945 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15946 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15947 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15948 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15949 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15950 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15951 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15952
15953 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15954 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15955 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15956 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15957 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15958 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15959 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15960 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15961 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15962 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15963 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15964 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15965
15966 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15967 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15968 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15969 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15970 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15971 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15972 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15973 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15974 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15975 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15976 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15977 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15978
15979 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15980 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15981 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15982 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15983 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15984 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15985 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15986 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15987 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15988 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15989 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15990 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15991
15992 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15993 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15994 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15995 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15996 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15997 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15998 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15999 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
16000 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
16001 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
16002 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
16003 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
16004
16005 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
16006 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
16007 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
16008 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
16009 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
16010 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
16011 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
16012 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
16013 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
16014 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
16015 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
16016 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
16017
16018 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
16019 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
16020 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
16021 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
16022 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
16023 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
16024 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
16025 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
16026 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
16027 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
16028 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
16029 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
16030
16031 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
16032 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
16033 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
16034 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
16035 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
16036 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
16037 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
16038 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
16039 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
16040 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
16041 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
16042 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
16043
16044 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
16045 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
16046 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
16047 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
16048 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
16049 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
16050 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
16051 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
16052 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
16053 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
16054 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
16055 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
16056
16057 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
16058 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
16059 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
16060 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
16061 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
16062 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
16063 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
16064 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
16065 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
16066 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
16067 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
16068 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
16069
16070 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
16071 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
16072 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
16073 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
16074 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
16075 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
16076 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
16077 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
16078 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
16079 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
16080 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
16081 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
16082
16083 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
16084 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
16085 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
16086 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
16087 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
16088 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
16089 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
16090 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
16091 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
16092 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
16093 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
16094 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
16095
16096 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
16097 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
16098 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
16099 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
16100 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
16101 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
16102 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
16103 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
16104 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
16105 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
16106 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
16107 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
16108
16109 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
16110 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
16111 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
16112 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
16113 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
16114 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
16115 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
16116 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
16117 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
16118 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
16119 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
16120 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
16121
16122 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
16123 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
16124 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
16125 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
16126 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
16127 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16128 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16129 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16130 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
16131 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
16132 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
16133 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
16134
16135 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
16136 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
16137 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
16138 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
16139 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
16140 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16141 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16142 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16143 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
16144 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
16145 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
16146 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
16147
16148 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
16149 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
16150 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
16151 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
16152 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
16153 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16154 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16155 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16156 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
16157 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
16158 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
16159 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
16160
16161 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
16162 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
16163 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
16164 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
16165 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
16166 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16167 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16168 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16169 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
16170 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
16171 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
16172 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
16173
16174 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
16175 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
16176 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
16177 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
16178 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
16179 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16180 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16181 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16182 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
16183 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
16184 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
16185 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
16186
16187 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
16188 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
16189 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
16190 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
16191 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
16192 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16193 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16194 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16195 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
16196 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
16197 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
16198 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
16199
16200 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
16201 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
16202 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
16203 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
16204 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
16205 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16206 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16207 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16208 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
16209 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
16210 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
16211 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
16212
16213 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
16214 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
16215 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
16216 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
16217 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
16218 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16219 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16220 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16221 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
16222 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
16223 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
16224 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
16225
16226 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
16227 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
16228 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
16229 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
16230 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
16231 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16232 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16233 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16234 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
16235 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
16236 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
16237 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
16238
16239 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
16240 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
16241 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
16242 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
16243 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
16244 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16245 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16246 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16247 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
16248 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
16249 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
16250 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
16251
16252 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16253 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16254 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16255 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16256 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16257 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16258 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16259 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16260 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16261 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16262 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16263 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16264
16265 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16266 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16267 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16268 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16269 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16270 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16271 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16272 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16273 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16274 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16275 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16276 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16277
16278 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16279 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16280 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16281 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16282 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16283 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16284 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16285 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16286 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16287 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16288 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16289 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16290
16291 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
16292 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
16293 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
16294 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
16295
16296 cCL(flts, e000110, 2, (RF, RR), rn_rd),
16297 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
16298 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
16299 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
16300 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
16301 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
16302 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
16303 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
16304 cCL(flte, e080110, 2, (RF, RR), rn_rd),
16305 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
16306 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
16307 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
16308
16309 /* The implementation of the FIX instruction is broken on some
16310 assemblers, in that it accepts a precision specifier as well as a
16311 rounding specifier, despite the fact that this is meaningless.
16312 To be more compatible, we accept it as well, though of course it
16313 does not set any bits. */
16314 cCE(fix, e100110, 2, (RR, RF), rd_rm),
16315 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
16316 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
16317 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
16318 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
16319 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
16320 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
16321 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
16322 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
16323 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
16324 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
16325 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
16326 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
16327
16328 /* Instructions that were new with the real FPA, call them V2. */
16329 #undef ARM_VARIANT
16330 #define ARM_VARIANT &fpu_fpa_ext_v2
16331 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16332 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16333 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16334 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16335 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16336 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16337
16338 #undef ARM_VARIANT
16339 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
16340 /* Moves and type conversions. */
16341 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
16342 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
16343 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
16344 cCE(fmstat, ef1fa10, 0, (), noargs),
16345 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
16346 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
16347 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
16348 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16349 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
16350 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16351 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
16352 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
16353
16354 /* Memory operations. */
16355 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16356 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16357 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16358 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16359 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16360 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16361 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16362 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16363 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16364 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16365 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16366 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16367 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16368 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16369 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16370 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16371 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16372 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16373
16374 /* Monadic operations. */
16375 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
16376 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
16377 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
16378
16379 /* Dyadic operations. */
16380 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16381 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16382 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16383 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16384 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16385 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16386 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16387 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16388 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16389
16390 /* Comparisons. */
16391 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
16392 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
16393 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
16394 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
16395
16396 #undef ARM_VARIANT
16397 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
16398 /* Moves and type conversions. */
16399 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16400 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16401 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16402 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
16403 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
16404 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
16405 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
16406 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16407 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
16408 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16409 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16410 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16411 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16412
16413 /* Memory operations. */
16414 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16415 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16416 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16417 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16418 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16419 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16420 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16421 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16422 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16423 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16424
16425 /* Monadic operations. */
16426 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16427 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16428 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16429
16430 /* Dyadic operations. */
16431 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16432 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16433 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16434 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16435 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16436 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16437 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16438 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16439 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16440
16441 /* Comparisons. */
16442 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16443 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
16444 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16445 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
16446
16447 #undef ARM_VARIANT
16448 #define ARM_VARIANT &fpu_vfp_ext_v2
16449 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
16450 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
16451 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
16452 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
16453
16454 /* Instructions which may belong to either the Neon or VFP instruction sets.
16455 Individual encoder functions perform additional architecture checks. */
16456 #undef ARM_VARIANT
16457 #define ARM_VARIANT &fpu_vfp_ext_v1xd
16458 #undef THUMB_VARIANT
16459 #define THUMB_VARIANT &fpu_vfp_ext_v1xd
16460 /* These mnemonics are unique to VFP. */
16461 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
16462 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
16463 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16464 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16465 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16466 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16467 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16468 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
16469 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
16470 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
16471
16472 /* Mnemonics shared by Neon and VFP. */
16473 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
16474 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16475 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16476
16477 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16478 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16479
16480 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16481 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16482
16483 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16484 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16485 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16486 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16487 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16488 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16489 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16490 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16491
16492 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
16493 nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb),
16494 nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt),
16495
16496
16497 /* NOTE: All VMOV encoding is special-cased! */
16498 NCE(vmov, 0, 1, (VMOV), neon_mov),
16499 NCE(vmovq, 0, 1, (VMOV), neon_mov),
16500
16501 #undef THUMB_VARIANT
16502 #define THUMB_VARIANT &fpu_neon_ext_v1
16503 #undef ARM_VARIANT
16504 #define ARM_VARIANT &fpu_neon_ext_v1
16505 /* Data processing with three registers of the same length. */
16506 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
16507 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
16508 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
16509 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16510 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16511 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16512 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16513 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16514 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16515 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
16516 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16517 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
16518 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16519 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
16520 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16521 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
16522 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16523 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
16524 /* If not immediate, fall back to neon_dyadic_i64_su.
16525 shl_imm should accept I8 I16 I32 I64,
16526 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
16527 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
16528 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
16529 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
16530 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
16531 /* Logic ops, types optional & ignored. */
16532 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
16533 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
16534 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
16535 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
16536 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
16537 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
16538 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
16539 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
16540 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
16541 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
16542 /* Bitfield ops, untyped. */
16543 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16544 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16545 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16546 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16547 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16548 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16549 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
16550 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16551 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16552 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16553 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16554 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16555 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16556 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16557 back to neon_dyadic_if_su. */
16558 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16559 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16560 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16561 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16562 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16563 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16564 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16565 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16566 /* Comparison. Type I8 I16 I32 F32. */
16567 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16568 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16569 /* As above, D registers only. */
16570 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16571 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16572 /* Int and float variants, signedness unimportant. */
16573 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16574 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16575 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16576 /* Add/sub take types I8 I16 I32 I64 F32. */
16577 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16578 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16579 /* vtst takes sizes 8, 16, 32. */
16580 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16581 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16582 /* VMUL takes I8 I16 I32 F32 P8. */
16583 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
16584 /* VQD{R}MULH takes S16 S32. */
16585 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16586 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16587 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16588 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16589 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16590 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16591 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16592 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16593 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16594 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16595 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16596 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16597 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16598 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16599 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16600 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16601
16602 /* Two address, int/float. Types S8 S16 S32 F32. */
16603 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
16604 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16605
16606 /* Data processing with two registers and a shift amount. */
16607 /* Right shifts, and variants with rounding.
16608 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16609 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16610 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16611 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16612 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16613 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16614 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16615 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16616 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16617 /* Shift and insert. Sizes accepted 8 16 32 64. */
16618 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16619 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16620 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16621 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16622 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16623 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16624 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16625 /* Right shift immediate, saturating & narrowing, with rounding variants.
16626 Types accepted S16 S32 S64 U16 U32 U64. */
16627 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16628 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16629 /* As above, unsigned. Types accepted S16 S32 S64. */
16630 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16631 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16632 /* Right shift narrowing. Types accepted I16 I32 I64. */
16633 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16634 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16635 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16636 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16637 /* CVT with optional immediate for fixed-point variant. */
16638 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
16639
16640 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16641 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16642
16643 /* Data processing, three registers of different lengths. */
16644 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16645 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16646 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16647 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16648 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16649 /* If not scalar, fall back to neon_dyadic_long.
16650 Vector types as above, scalar types S16 S32 U16 U32. */
16651 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16652 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16653 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16654 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16655 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16656 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16657 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16658 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16659 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16660 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16661 /* Saturating doubling multiplies. Types S16 S32. */
16662 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16663 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16664 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16665 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16666 S16 S32 U16 U32. */
16667 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16668
16669 /* Extract. Size 8. */
16670 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16671 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
16672
16673 /* Two registers, miscellaneous. */
16674 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16675 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16676 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16677 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16678 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16679 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16680 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16681 /* Vector replicate. Sizes 8 16 32. */
16682 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16683 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16684 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16685 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16686 /* VMOVN. Types I16 I32 I64. */
16687 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16688 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16689 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16690 /* VQMOVUN. Types S16 S32 S64. */
16691 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16692 /* VZIP / VUZP. Sizes 8 16 32. */
16693 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16694 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16695 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16696 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16697 /* VQABS / VQNEG. Types S8 S16 S32. */
16698 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16699 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16700 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16701 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16702 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16703 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16704 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16705 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16706 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16707 /* Reciprocal estimates. Types U32 F32. */
16708 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16709 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16710 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16711 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16712 /* VCLS. Types S8 S16 S32. */
16713 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16714 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16715 /* VCLZ. Types I8 I16 I32. */
16716 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16717 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16718 /* VCNT. Size 8. */
16719 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16720 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16721 /* Two address, untyped. */
16722 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16723 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16724 /* VTRN. Sizes 8 16 32. */
16725 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16726 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16727
16728 /* Table lookup. Size 8. */
16729 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16730 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16731
16732 #undef THUMB_VARIANT
16733 #define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16734 #undef ARM_VARIANT
16735 #define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
16736 /* Neon element/structure load/store. */
16737 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16738 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16739 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16740 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16741 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16742 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16743 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16744 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16745
16746 #undef THUMB_VARIANT
16747 #define THUMB_VARIANT &fpu_vfp_ext_v3
16748 #undef ARM_VARIANT
16749 #define ARM_VARIANT &fpu_vfp_ext_v3
16750 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16751 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16752 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16753 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16754 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16755 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16756 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16757 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16758 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16759 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16760 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16761 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16762 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16763 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16764 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16765 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16766 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16767 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16768
16769 #undef THUMB_VARIANT
16770 #undef ARM_VARIANT
16771 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
16772 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16773 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16774 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16775 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16776 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16777 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16778 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16779 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
16780
16781 #undef ARM_VARIANT
16782 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
16783 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16784 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16785 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16786 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16787 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16788 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16789 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16790 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16791 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16792 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16793 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16794 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16795 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16796 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16797 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16798 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16799 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16800 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16801 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
16802 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16803 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16804 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16805 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16806 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16807 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16808 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16809 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16810 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16811 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
16812 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
16813 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16814 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16815 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16816 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16817 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16818 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16819 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16820 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16821 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16822 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16823 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16824 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16825 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16826 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16827 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16828 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16829 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16830 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16831 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16832 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16833 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16834 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16835 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16836 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16837 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16838 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16839 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16840 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16841 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16842 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16843 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16844 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16845 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16846 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16847 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16848 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16849 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16850 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16851 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16852 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16853 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16854 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16855 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16856 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16857 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16858 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16859 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16860 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16861 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16862 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16863 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16864 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16865 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16866 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16867 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16868 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16869 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16870 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16871 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16872 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16873 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16874 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16875 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16876 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16877 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16878 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16879 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16880 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16881 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16882 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16883 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16884 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16885 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16886 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16887 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16888 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16889 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16890 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16891 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16892 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16893 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
16894 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16895 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16896 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16897 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16898 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16899 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16900 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16901 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16902 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16903 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16904 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16905 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16906 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16907 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16908 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16909 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16910 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
16911 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16912 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16913 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16914 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16915 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16916 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16917 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16918 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16919 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16920 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16921 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16922 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16923 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16924 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16925 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16926 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16927 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16928 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16929 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16930 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16931 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16932 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16933 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16934 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16935 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16936 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16937 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16938 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16939 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16940 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16941 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16942 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16943 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16944 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
16945
16946 #undef ARM_VARIANT
16947 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16948 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16949 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16950 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16951 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16952 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16953 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16954 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16955 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16956 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16957 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16958 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16959 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16960 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16961 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16962 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16963 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16964 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16965 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16966 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16967 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16968 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16969 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16970 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16971 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16972 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16973 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16974 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16975 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16976 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16977 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16978 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16979 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16980 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16981 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16982 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16983 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16984 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16985 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16986 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16987 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16988 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16989 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16990 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16991 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16992 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16993 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16994 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16995 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16996 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16997 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16998 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16999 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17000 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17001 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17002 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17003 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17004 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17005
17006 #undef ARM_VARIANT
17007 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
17008 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17009 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17010 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17011 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17012 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17013 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17014 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17015 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17016 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
17017 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
17018 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
17019 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
17020 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
17021 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
17022 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
17023 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
17024 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
17025 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
17026 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
17027 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
17028 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
17029 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
17030 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
17031 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
17032 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
17033 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
17034 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
17035 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
17036 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17037 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
17038 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
17039 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
17040 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
17041 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
17042 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
17043 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
17044 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
17045 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
17046 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
17047 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
17048 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
17049 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
17050 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
17051 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
17052 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
17053 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
17054 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
17055 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
17056 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
17057 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
17058 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
17059 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
17060 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
17061 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
17062 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
17063 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
17064 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
17065 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
17066 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
17067 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
17068 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
17069 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
17070 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
17071 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
17072 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17073 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17074 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17075 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17076 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17077 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17078 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17079 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17080 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17081 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17082 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17083 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17084 };
17085 #undef ARM_VARIANT
17086 #undef THUMB_VARIANT
17087 #undef TCE
17088 #undef TCM
17089 #undef TUE
17090 #undef TUF
17091 #undef TCC
17092 #undef cCE
17093 #undef cCL
17094 #undef C3E
17095 #undef CE
17096 #undef CM
17097 #undef UE
17098 #undef UF
17099 #undef UT
17100 #undef NUF
17101 #undef nUF
17102 #undef NCE
17103 #undef nCE
17104 #undef OPS0
17105 #undef OPS1
17106 #undef OPS2
17107 #undef OPS3
17108 #undef OPS4
17109 #undef OPS5
17110 #undef OPS6
17111 #undef do_0
17112 \f
17113 /* MD interface: bits in the object file. */
17114
17115 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
17116 for use in the a.out file, and stores them in the array pointed to by buf.
17117 This knows about the endian-ness of the target machine and does
17118 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
17119 2 (short) and 4 (long) Floating numbers are put out as a series of
17120 LITTLENUMS (shorts, here at least). */
17121
17122 void
17123 md_number_to_chars (char * buf, valueT val, int n)
17124 {
17125 if (target_big_endian)
17126 number_to_chars_bigendian (buf, val, n);
17127 else
17128 number_to_chars_littleendian (buf, val, n);
17129 }
17130
17131 static valueT
17132 md_chars_to_number (char * buf, int n)
17133 {
17134 valueT result = 0;
17135 unsigned char * where = (unsigned char *) buf;
17136
17137 if (target_big_endian)
17138 {
17139 while (n--)
17140 {
17141 result <<= 8;
17142 result |= (*where++ & 255);
17143 }
17144 }
17145 else
17146 {
17147 while (n--)
17148 {
17149 result <<= 8;
17150 result |= (where[n] & 255);
17151 }
17152 }
17153
17154 return result;
17155 }
17156
17157 /* MD interface: Sections. */
17158
17159 /* Estimate the size of a frag before relaxing. Assume everything fits in
17160 2 bytes. */
17161
17162 int
17163 md_estimate_size_before_relax (fragS * fragp,
17164 segT segtype ATTRIBUTE_UNUSED)
17165 {
17166 fragp->fr_var = 2;
17167 return 2;
17168 }
17169
17170 /* Convert a machine dependent frag. */
17171
17172 void
17173 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
17174 {
17175 unsigned long insn;
17176 unsigned long old_op;
17177 char *buf;
17178 expressionS exp;
17179 fixS *fixp;
17180 int reloc_type;
17181 int pc_rel;
17182 int opcode;
17183
17184 buf = fragp->fr_literal + fragp->fr_fix;
17185
17186 old_op = bfd_get_16(abfd, buf);
17187 if (fragp->fr_symbol)
17188 {
17189 exp.X_op = O_symbol;
17190 exp.X_add_symbol = fragp->fr_symbol;
17191 }
17192 else
17193 {
17194 exp.X_op = O_constant;
17195 }
17196 exp.X_add_number = fragp->fr_offset;
17197 opcode = fragp->fr_subtype;
17198 switch (opcode)
17199 {
17200 case T_MNEM_ldr_pc:
17201 case T_MNEM_ldr_pc2:
17202 case T_MNEM_ldr_sp:
17203 case T_MNEM_str_sp:
17204 case T_MNEM_ldr:
17205 case T_MNEM_ldrb:
17206 case T_MNEM_ldrh:
17207 case T_MNEM_str:
17208 case T_MNEM_strb:
17209 case T_MNEM_strh:
17210 if (fragp->fr_var == 4)
17211 {
17212 insn = THUMB_OP32 (opcode);
17213 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
17214 {
17215 insn |= (old_op & 0x700) << 4;
17216 }
17217 else
17218 {
17219 insn |= (old_op & 7) << 12;
17220 insn |= (old_op & 0x38) << 13;
17221 }
17222 insn |= 0x00000c00;
17223 put_thumb32_insn (buf, insn);
17224 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
17225 }
17226 else
17227 {
17228 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
17229 }
17230 pc_rel = (opcode == T_MNEM_ldr_pc2);
17231 break;
17232 case T_MNEM_adr:
17233 if (fragp->fr_var == 4)
17234 {
17235 insn = THUMB_OP32 (opcode);
17236 insn |= (old_op & 0xf0) << 4;
17237 put_thumb32_insn (buf, insn);
17238 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
17239 }
17240 else
17241 {
17242 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17243 exp.X_add_number -= 4;
17244 }
17245 pc_rel = 1;
17246 break;
17247 case T_MNEM_mov:
17248 case T_MNEM_movs:
17249 case T_MNEM_cmp:
17250 case T_MNEM_cmn:
17251 if (fragp->fr_var == 4)
17252 {
17253 int r0off = (opcode == T_MNEM_mov
17254 || opcode == T_MNEM_movs) ? 0 : 8;
17255 insn = THUMB_OP32 (opcode);
17256 insn = (insn & 0xe1ffffff) | 0x10000000;
17257 insn |= (old_op & 0x700) << r0off;
17258 put_thumb32_insn (buf, insn);
17259 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17260 }
17261 else
17262 {
17263 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
17264 }
17265 pc_rel = 0;
17266 break;
17267 case T_MNEM_b:
17268 if (fragp->fr_var == 4)
17269 {
17270 insn = THUMB_OP32(opcode);
17271 put_thumb32_insn (buf, insn);
17272 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
17273 }
17274 else
17275 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
17276 pc_rel = 1;
17277 break;
17278 case T_MNEM_bcond:
17279 if (fragp->fr_var == 4)
17280 {
17281 insn = THUMB_OP32(opcode);
17282 insn |= (old_op & 0xf00) << 14;
17283 put_thumb32_insn (buf, insn);
17284 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
17285 }
17286 else
17287 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
17288 pc_rel = 1;
17289 break;
17290 case T_MNEM_add_sp:
17291 case T_MNEM_add_pc:
17292 case T_MNEM_inc_sp:
17293 case T_MNEM_dec_sp:
17294 if (fragp->fr_var == 4)
17295 {
17296 /* ??? Choose between add and addw. */
17297 insn = THUMB_OP32 (opcode);
17298 insn |= (old_op & 0xf0) << 4;
17299 put_thumb32_insn (buf, insn);
17300 if (opcode == T_MNEM_add_pc)
17301 reloc_type = BFD_RELOC_ARM_T32_IMM12;
17302 else
17303 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17304 }
17305 else
17306 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17307 pc_rel = 0;
17308 break;
17309
17310 case T_MNEM_addi:
17311 case T_MNEM_addis:
17312 case T_MNEM_subi:
17313 case T_MNEM_subis:
17314 if (fragp->fr_var == 4)
17315 {
17316 insn = THUMB_OP32 (opcode);
17317 insn |= (old_op & 0xf0) << 4;
17318 insn |= (old_op & 0xf) << 16;
17319 put_thumb32_insn (buf, insn);
17320 if (insn & (1 << 20))
17321 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17322 else
17323 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17324 }
17325 else
17326 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17327 pc_rel = 0;
17328 break;
17329 default:
17330 abort ();
17331 }
17332 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
17333 reloc_type);
17334 fixp->fx_file = fragp->fr_file;
17335 fixp->fx_line = fragp->fr_line;
17336 fragp->fr_fix += fragp->fr_var;
17337 }
17338
17339 /* Return the size of a relaxable immediate operand instruction.
17340 SHIFT and SIZE specify the form of the allowable immediate. */
17341 static int
17342 relax_immediate (fragS *fragp, int size, int shift)
17343 {
17344 offsetT offset;
17345 offsetT mask;
17346 offsetT low;
17347
17348 /* ??? Should be able to do better than this. */
17349 if (fragp->fr_symbol)
17350 return 4;
17351
17352 low = (1 << shift) - 1;
17353 mask = (1 << (shift + size)) - (1 << shift);
17354 offset = fragp->fr_offset;
17355 /* Force misaligned offsets to 32-bit variant. */
17356 if (offset & low)
17357 return 4;
17358 if (offset & ~mask)
17359 return 4;
17360 return 2;
17361 }
17362
17363 /* Get the address of a symbol during relaxation. */
17364 static addressT
17365 relaxed_symbol_addr (fragS *fragp, long stretch)
17366 {
17367 fragS *sym_frag;
17368 addressT addr;
17369 symbolS *sym;
17370
17371 sym = fragp->fr_symbol;
17372 sym_frag = symbol_get_frag (sym);
17373 know (S_GET_SEGMENT (sym) != absolute_section
17374 || sym_frag == &zero_address_frag);
17375 addr = S_GET_VALUE (sym) + fragp->fr_offset;
17376
17377 /* If frag has yet to be reached on this pass, assume it will
17378 move by STRETCH just as we did. If this is not so, it will
17379 be because some frag between grows, and that will force
17380 another pass. */
17381
17382 if (stretch != 0
17383 && sym_frag->relax_marker != fragp->relax_marker)
17384 {
17385 fragS *f;
17386
17387 /* Adjust stretch for any alignment frag. Note that if have
17388 been expanding the earlier code, the symbol may be
17389 defined in what appears to be an earlier frag. FIXME:
17390 This doesn't handle the fr_subtype field, which specifies
17391 a maximum number of bytes to skip when doing an
17392 alignment. */
17393 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17394 {
17395 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17396 {
17397 if (stretch < 0)
17398 stretch = - ((- stretch)
17399 & ~ ((1 << (int) f->fr_offset) - 1));
17400 else
17401 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17402 if (stretch == 0)
17403 break;
17404 }
17405 }
17406 if (f != NULL)
17407 addr += stretch;
17408 }
17409
17410 return addr;
17411 }
17412
17413 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
17414 load. */
17415 static int
17416 relax_adr (fragS *fragp, asection *sec, long stretch)
17417 {
17418 addressT addr;
17419 offsetT val;
17420
17421 /* Assume worst case for symbols not known to be in the same section. */
17422 if (!S_IS_DEFINED (fragp->fr_symbol)
17423 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17424 return 4;
17425
17426 val = relaxed_symbol_addr (fragp, stretch);
17427 addr = fragp->fr_address + fragp->fr_fix;
17428 addr = (addr + 4) & ~3;
17429 /* Force misaligned targets to 32-bit variant. */
17430 if (val & 3)
17431 return 4;
17432 val -= addr;
17433 if (val < 0 || val > 1020)
17434 return 4;
17435 return 2;
17436 }
17437
17438 /* Return the size of a relaxable add/sub immediate instruction. */
17439 static int
17440 relax_addsub (fragS *fragp, asection *sec)
17441 {
17442 char *buf;
17443 int op;
17444
17445 buf = fragp->fr_literal + fragp->fr_fix;
17446 op = bfd_get_16(sec->owner, buf);
17447 if ((op & 0xf) == ((op >> 4) & 0xf))
17448 return relax_immediate (fragp, 8, 0);
17449 else
17450 return relax_immediate (fragp, 3, 0);
17451 }
17452
17453
17454 /* Return the size of a relaxable branch instruction. BITS is the
17455 size of the offset field in the narrow instruction. */
17456
17457 static int
17458 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
17459 {
17460 addressT addr;
17461 offsetT val;
17462 offsetT limit;
17463
17464 /* Assume worst case for symbols not known to be in the same section. */
17465 if (!S_IS_DEFINED (fragp->fr_symbol)
17466 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17467 return 4;
17468
17469 val = relaxed_symbol_addr (fragp, stretch);
17470 addr = fragp->fr_address + fragp->fr_fix + 4;
17471 val -= addr;
17472
17473 /* Offset is a signed value *2 */
17474 limit = 1 << bits;
17475 if (val >= limit || val < -limit)
17476 return 4;
17477 return 2;
17478 }
17479
17480
17481 /* Relax a machine dependent frag. This returns the amount by which
17482 the current size of the frag should change. */
17483
17484 int
17485 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
17486 {
17487 int oldsize;
17488 int newsize;
17489
17490 oldsize = fragp->fr_var;
17491 switch (fragp->fr_subtype)
17492 {
17493 case T_MNEM_ldr_pc2:
17494 newsize = relax_adr (fragp, sec, stretch);
17495 break;
17496 case T_MNEM_ldr_pc:
17497 case T_MNEM_ldr_sp:
17498 case T_MNEM_str_sp:
17499 newsize = relax_immediate (fragp, 8, 2);
17500 break;
17501 case T_MNEM_ldr:
17502 case T_MNEM_str:
17503 newsize = relax_immediate (fragp, 5, 2);
17504 break;
17505 case T_MNEM_ldrh:
17506 case T_MNEM_strh:
17507 newsize = relax_immediate (fragp, 5, 1);
17508 break;
17509 case T_MNEM_ldrb:
17510 case T_MNEM_strb:
17511 newsize = relax_immediate (fragp, 5, 0);
17512 break;
17513 case T_MNEM_adr:
17514 newsize = relax_adr (fragp, sec, stretch);
17515 break;
17516 case T_MNEM_mov:
17517 case T_MNEM_movs:
17518 case T_MNEM_cmp:
17519 case T_MNEM_cmn:
17520 newsize = relax_immediate (fragp, 8, 0);
17521 break;
17522 case T_MNEM_b:
17523 newsize = relax_branch (fragp, sec, 11, stretch);
17524 break;
17525 case T_MNEM_bcond:
17526 newsize = relax_branch (fragp, sec, 8, stretch);
17527 break;
17528 case T_MNEM_add_sp:
17529 case T_MNEM_add_pc:
17530 newsize = relax_immediate (fragp, 8, 2);
17531 break;
17532 case T_MNEM_inc_sp:
17533 case T_MNEM_dec_sp:
17534 newsize = relax_immediate (fragp, 7, 2);
17535 break;
17536 case T_MNEM_addi:
17537 case T_MNEM_addis:
17538 case T_MNEM_subi:
17539 case T_MNEM_subis:
17540 newsize = relax_addsub (fragp, sec);
17541 break;
17542 default:
17543 abort ();
17544 }
17545
17546 fragp->fr_var = newsize;
17547 /* Freeze wide instructions that are at or before the same location as
17548 in the previous pass. This avoids infinite loops.
17549 Don't freeze them unconditionally because targets may be artificially
17550 misaligned by the expansion of preceding frags. */
17551 if (stretch <= 0 && newsize > 2)
17552 {
17553 md_convert_frag (sec->owner, sec, fragp);
17554 frag_wane (fragp);
17555 }
17556
17557 return newsize - oldsize;
17558 }
17559
17560 /* Round up a section size to the appropriate boundary. */
17561
17562 valueT
17563 md_section_align (segT segment ATTRIBUTE_UNUSED,
17564 valueT size)
17565 {
17566 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17567 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17568 {
17569 /* For a.out, force the section size to be aligned. If we don't do
17570 this, BFD will align it for us, but it will not write out the
17571 final bytes of the section. This may be a bug in BFD, but it is
17572 easier to fix it here since that is how the other a.out targets
17573 work. */
17574 int align;
17575
17576 align = bfd_get_section_alignment (stdoutput, segment);
17577 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17578 }
17579 #endif
17580
17581 return size;
17582 }
17583
17584 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17585 of an rs_align_code fragment. */
17586
17587 void
17588 arm_handle_align (fragS * fragP)
17589 {
17590 static char const arm_noop[2][2][4] =
17591 {
17592 { /* ARMv1 */
17593 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
17594 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
17595 },
17596 { /* ARMv6k */
17597 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
17598 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
17599 },
17600 };
17601 static char const thumb_noop[2][2][2] =
17602 {
17603 { /* Thumb-1 */
17604 {0xc0, 0x46}, /* LE */
17605 {0x46, 0xc0}, /* BE */
17606 },
17607 { /* Thumb-2 */
17608 {0x00, 0xbf}, /* LE */
17609 {0xbf, 0x00} /* BE */
17610 }
17611 };
17612 static char const wide_thumb_noop[2][4] =
17613 { /* Wide Thumb-2 */
17614 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
17615 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
17616 };
17617
17618 unsigned bytes, fix, noop_size;
17619 char * p;
17620 const char * noop;
17621 const char *narrow_noop = NULL;
17622
17623 if (fragP->fr_type != rs_align_code)
17624 return;
17625
17626 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17627 p = fragP->fr_literal + fragP->fr_fix;
17628 fix = 0;
17629
17630 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17631 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
17632
17633 assert ((fragP->tc_frag_data & MODE_RECORDED) != 0);
17634
17635 if (fragP->tc_frag_data & (~ MODE_RECORDED))
17636 {
17637 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
17638 {
17639 narrow_noop = thumb_noop[1][target_big_endian];
17640 noop = wide_thumb_noop[target_big_endian];
17641 }
17642 else
17643 noop = thumb_noop[0][target_big_endian];
17644 noop_size = 2;
17645 }
17646 else
17647 {
17648 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
17649 [target_big_endian];
17650 noop_size = 4;
17651 }
17652
17653 fragP->fr_var = noop_size;
17654
17655 if (bytes & (noop_size - 1))
17656 {
17657 fix = bytes & (noop_size - 1);
17658 memset (p, 0, fix);
17659 p += fix;
17660 bytes -= fix;
17661 }
17662
17663 if (narrow_noop)
17664 {
17665 if (bytes & noop_size)
17666 {
17667 /* Insert a narrow noop. */
17668 memcpy (p, narrow_noop, noop_size);
17669 p += noop_size;
17670 bytes -= noop_size;
17671 fix += noop_size;
17672 }
17673
17674 /* Use wide noops for the remainder */
17675 noop_size = 4;
17676 }
17677
17678 while (bytes >= noop_size)
17679 {
17680 memcpy (p, noop, noop_size);
17681 p += noop_size;
17682 bytes -= noop_size;
17683 fix += noop_size;
17684 }
17685
17686 fragP->fr_fix += fix;
17687 }
17688
17689 /* Called from md_do_align. Used to create an alignment
17690 frag in a code section. */
17691
17692 void
17693 arm_frag_align_code (int n, int max)
17694 {
17695 char * p;
17696
17697 /* We assume that there will never be a requirement
17698 to support alignments greater than 32 bytes. */
17699 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17700 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
17701
17702 p = frag_var (rs_align_code,
17703 MAX_MEM_FOR_RS_ALIGN_CODE,
17704 1,
17705 (relax_substateT) max,
17706 (symbolS *) NULL,
17707 (offsetT) n,
17708 (char *) NULL);
17709 *p = 0;
17710 }
17711
17712 /* Perform target specific initialisation of a frag.
17713 Note - despite the name this initialisation is not done when the frag
17714 is created, but only when its type is assigned. A frag can be created
17715 and used a long time before its type is set, so beware of assuming that
17716 this initialisationis performed first. */
17717
17718 void
17719 arm_init_frag (fragS * fragP)
17720 {
17721 /* If the current ARM vs THUMB mode has not already
17722 been recorded into this frag then do so now. */
17723 if ((fragP->tc_frag_data & MODE_RECORDED) == 0)
17724 fragP->tc_frag_data = thumb_mode | MODE_RECORDED;
17725 }
17726
17727 #ifdef OBJ_ELF
17728 /* When we change sections we need to issue a new mapping symbol. */
17729
17730 void
17731 arm_elf_change_section (void)
17732 {
17733 flagword flags;
17734 segment_info_type *seginfo;
17735
17736 /* Link an unlinked unwind index table section to the .text section. */
17737 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17738 && elf_linked_to_section (now_seg) == NULL)
17739 elf_linked_to_section (now_seg) = text_section;
17740
17741 if (!SEG_NORMAL (now_seg))
17742 return;
17743
17744 flags = bfd_get_section_flags (stdoutput, now_seg);
17745
17746 /* We can ignore sections that only contain debug info. */
17747 if ((flags & SEC_ALLOC) == 0)
17748 return;
17749
17750 seginfo = seg_info (now_seg);
17751 mapstate = seginfo->tc_segment_info_data.mapstate;
17752 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
17753 }
17754
17755 int
17756 arm_elf_section_type (const char * str, size_t len)
17757 {
17758 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17759 return SHT_ARM_EXIDX;
17760
17761 return -1;
17762 }
17763 \f
17764 /* Code to deal with unwinding tables. */
17765
17766 static void add_unwind_adjustsp (offsetT);
17767
17768 /* Generate any deferred unwind frame offset. */
17769
17770 static void
17771 flush_pending_unwind (void)
17772 {
17773 offsetT offset;
17774
17775 offset = unwind.pending_offset;
17776 unwind.pending_offset = 0;
17777 if (offset != 0)
17778 add_unwind_adjustsp (offset);
17779 }
17780
17781 /* Add an opcode to this list for this function. Two-byte opcodes should
17782 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17783 order. */
17784
17785 static void
17786 add_unwind_opcode (valueT op, int length)
17787 {
17788 /* Add any deferred stack adjustment. */
17789 if (unwind.pending_offset)
17790 flush_pending_unwind ();
17791
17792 unwind.sp_restored = 0;
17793
17794 if (unwind.opcode_count + length > unwind.opcode_alloc)
17795 {
17796 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17797 if (unwind.opcodes)
17798 unwind.opcodes = xrealloc (unwind.opcodes,
17799 unwind.opcode_alloc);
17800 else
17801 unwind.opcodes = xmalloc (unwind.opcode_alloc);
17802 }
17803 while (length > 0)
17804 {
17805 length--;
17806 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17807 op >>= 8;
17808 unwind.opcode_count++;
17809 }
17810 }
17811
17812 /* Add unwind opcodes to adjust the stack pointer. */
17813
17814 static void
17815 add_unwind_adjustsp (offsetT offset)
17816 {
17817 valueT op;
17818
17819 if (offset > 0x200)
17820 {
17821 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17822 char bytes[5];
17823 int n;
17824 valueT o;
17825
17826 /* Long form: 0xb2, uleb128. */
17827 /* This might not fit in a word so add the individual bytes,
17828 remembering the list is built in reverse order. */
17829 o = (valueT) ((offset - 0x204) >> 2);
17830 if (o == 0)
17831 add_unwind_opcode (0, 1);
17832
17833 /* Calculate the uleb128 encoding of the offset. */
17834 n = 0;
17835 while (o)
17836 {
17837 bytes[n] = o & 0x7f;
17838 o >>= 7;
17839 if (o)
17840 bytes[n] |= 0x80;
17841 n++;
17842 }
17843 /* Add the insn. */
17844 for (; n; n--)
17845 add_unwind_opcode (bytes[n - 1], 1);
17846 add_unwind_opcode (0xb2, 1);
17847 }
17848 else if (offset > 0x100)
17849 {
17850 /* Two short opcodes. */
17851 add_unwind_opcode (0x3f, 1);
17852 op = (offset - 0x104) >> 2;
17853 add_unwind_opcode (op, 1);
17854 }
17855 else if (offset > 0)
17856 {
17857 /* Short opcode. */
17858 op = (offset - 4) >> 2;
17859 add_unwind_opcode (op, 1);
17860 }
17861 else if (offset < 0)
17862 {
17863 offset = -offset;
17864 while (offset > 0x100)
17865 {
17866 add_unwind_opcode (0x7f, 1);
17867 offset -= 0x100;
17868 }
17869 op = ((offset - 4) >> 2) | 0x40;
17870 add_unwind_opcode (op, 1);
17871 }
17872 }
17873
17874 /* Finish the list of unwind opcodes for this function. */
17875 static void
17876 finish_unwind_opcodes (void)
17877 {
17878 valueT op;
17879
17880 if (unwind.fp_used)
17881 {
17882 /* Adjust sp as necessary. */
17883 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17884 flush_pending_unwind ();
17885
17886 /* After restoring sp from the frame pointer. */
17887 op = 0x90 | unwind.fp_reg;
17888 add_unwind_opcode (op, 1);
17889 }
17890 else
17891 flush_pending_unwind ();
17892 }
17893
17894
17895 /* Start an exception table entry. If idx is nonzero this is an index table
17896 entry. */
17897
17898 static void
17899 start_unwind_section (const segT text_seg, int idx)
17900 {
17901 const char * text_name;
17902 const char * prefix;
17903 const char * prefix_once;
17904 const char * group_name;
17905 size_t prefix_len;
17906 size_t text_len;
17907 char * sec_name;
17908 size_t sec_name_len;
17909 int type;
17910 int flags;
17911 int linkonce;
17912
17913 if (idx)
17914 {
17915 prefix = ELF_STRING_ARM_unwind;
17916 prefix_once = ELF_STRING_ARM_unwind_once;
17917 type = SHT_ARM_EXIDX;
17918 }
17919 else
17920 {
17921 prefix = ELF_STRING_ARM_unwind_info;
17922 prefix_once = ELF_STRING_ARM_unwind_info_once;
17923 type = SHT_PROGBITS;
17924 }
17925
17926 text_name = segment_name (text_seg);
17927 if (streq (text_name, ".text"))
17928 text_name = "";
17929
17930 if (strncmp (text_name, ".gnu.linkonce.t.",
17931 strlen (".gnu.linkonce.t.")) == 0)
17932 {
17933 prefix = prefix_once;
17934 text_name += strlen (".gnu.linkonce.t.");
17935 }
17936
17937 prefix_len = strlen (prefix);
17938 text_len = strlen (text_name);
17939 sec_name_len = prefix_len + text_len;
17940 sec_name = xmalloc (sec_name_len + 1);
17941 memcpy (sec_name, prefix, prefix_len);
17942 memcpy (sec_name + prefix_len, text_name, text_len);
17943 sec_name[prefix_len + text_len] = '\0';
17944
17945 flags = SHF_ALLOC;
17946 linkonce = 0;
17947 group_name = 0;
17948
17949 /* Handle COMDAT group. */
17950 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
17951 {
17952 group_name = elf_group_name (text_seg);
17953 if (group_name == NULL)
17954 {
17955 as_bad (_("Group section `%s' has no group signature"),
17956 segment_name (text_seg));
17957 ignore_rest_of_line ();
17958 return;
17959 }
17960 flags |= SHF_GROUP;
17961 linkonce = 1;
17962 }
17963
17964 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
17965
17966 /* Set the section link for index tables. */
17967 if (idx)
17968 elf_linked_to_section (now_seg) = text_seg;
17969 }
17970
17971
17972 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17973 personality routine data. Returns zero, or the index table value for
17974 and inline entry. */
17975
17976 static valueT
17977 create_unwind_entry (int have_data)
17978 {
17979 int size;
17980 addressT where;
17981 char *ptr;
17982 /* The current word of data. */
17983 valueT data;
17984 /* The number of bytes left in this word. */
17985 int n;
17986
17987 finish_unwind_opcodes ();
17988
17989 /* Remember the current text section. */
17990 unwind.saved_seg = now_seg;
17991 unwind.saved_subseg = now_subseg;
17992
17993 start_unwind_section (now_seg, 0);
17994
17995 if (unwind.personality_routine == NULL)
17996 {
17997 if (unwind.personality_index == -2)
17998 {
17999 if (have_data)
18000 as_bad (_("handlerdata in cantunwind frame"));
18001 return 1; /* EXIDX_CANTUNWIND. */
18002 }
18003
18004 /* Use a default personality routine if none is specified. */
18005 if (unwind.personality_index == -1)
18006 {
18007 if (unwind.opcode_count > 3)
18008 unwind.personality_index = 1;
18009 else
18010 unwind.personality_index = 0;
18011 }
18012
18013 /* Space for the personality routine entry. */
18014 if (unwind.personality_index == 0)
18015 {
18016 if (unwind.opcode_count > 3)
18017 as_bad (_("too many unwind opcodes for personality routine 0"));
18018
18019 if (!have_data)
18020 {
18021 /* All the data is inline in the index table. */
18022 data = 0x80;
18023 n = 3;
18024 while (unwind.opcode_count > 0)
18025 {
18026 unwind.opcode_count--;
18027 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18028 n--;
18029 }
18030
18031 /* Pad with "finish" opcodes. */
18032 while (n--)
18033 data = (data << 8) | 0xb0;
18034
18035 return data;
18036 }
18037 size = 0;
18038 }
18039 else
18040 /* We get two opcodes "free" in the first word. */
18041 size = unwind.opcode_count - 2;
18042 }
18043 else
18044 /* An extra byte is required for the opcode count. */
18045 size = unwind.opcode_count + 1;
18046
18047 size = (size + 3) >> 2;
18048 if (size > 0xff)
18049 as_bad (_("too many unwind opcodes"));
18050
18051 frag_align (2, 0, 0);
18052 record_alignment (now_seg, 2);
18053 unwind.table_entry = expr_build_dot ();
18054
18055 /* Allocate the table entry. */
18056 ptr = frag_more ((size << 2) + 4);
18057 where = frag_now_fix () - ((size << 2) + 4);
18058
18059 switch (unwind.personality_index)
18060 {
18061 case -1:
18062 /* ??? Should this be a PLT generating relocation? */
18063 /* Custom personality routine. */
18064 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
18065 BFD_RELOC_ARM_PREL31);
18066
18067 where += 4;
18068 ptr += 4;
18069
18070 /* Set the first byte to the number of additional words. */
18071 data = size - 1;
18072 n = 3;
18073 break;
18074
18075 /* ABI defined personality routines. */
18076 case 0:
18077 /* Three opcodes bytes are packed into the first word. */
18078 data = 0x80;
18079 n = 3;
18080 break;
18081
18082 case 1:
18083 case 2:
18084 /* The size and first two opcode bytes go in the first word. */
18085 data = ((0x80 + unwind.personality_index) << 8) | size;
18086 n = 2;
18087 break;
18088
18089 default:
18090 /* Should never happen. */
18091 abort ();
18092 }
18093
18094 /* Pack the opcodes into words (MSB first), reversing the list at the same
18095 time. */
18096 while (unwind.opcode_count > 0)
18097 {
18098 if (n == 0)
18099 {
18100 md_number_to_chars (ptr, data, 4);
18101 ptr += 4;
18102 n = 4;
18103 data = 0;
18104 }
18105 unwind.opcode_count--;
18106 n--;
18107 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18108 }
18109
18110 /* Finish off the last word. */
18111 if (n < 4)
18112 {
18113 /* Pad with "finish" opcodes. */
18114 while (n--)
18115 data = (data << 8) | 0xb0;
18116
18117 md_number_to_chars (ptr, data, 4);
18118 }
18119
18120 if (!have_data)
18121 {
18122 /* Add an empty descriptor if there is no user-specified data. */
18123 ptr = frag_more (4);
18124 md_number_to_chars (ptr, 0, 4);
18125 }
18126
18127 return 0;
18128 }
18129
18130
18131 /* Initialize the DWARF-2 unwind information for this procedure. */
18132
18133 void
18134 tc_arm_frame_initial_instructions (void)
18135 {
18136 cfi_add_CFA_def_cfa (REG_SP, 0);
18137 }
18138 #endif /* OBJ_ELF */
18139
18140 /* Convert REGNAME to a DWARF-2 register number. */
18141
18142 int
18143 tc_arm_regname_to_dw2regnum (char *regname)
18144 {
18145 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
18146
18147 if (reg == FAIL)
18148 return -1;
18149
18150 return reg;
18151 }
18152
18153 #ifdef TE_PE
18154 void
18155 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
18156 {
18157 expressionS expr;
18158
18159 expr.X_op = O_secrel;
18160 expr.X_add_symbol = symbol;
18161 expr.X_add_number = 0;
18162 emit_expr (&expr, size);
18163 }
18164 #endif
18165
18166 /* MD interface: Symbol and relocation handling. */
18167
18168 /* Return the address within the segment that a PC-relative fixup is
18169 relative to. For ARM, PC-relative fixups applied to instructions
18170 are generally relative to the location of the fixup plus 8 bytes.
18171 Thumb branches are offset by 4, and Thumb loads relative to PC
18172 require special handling. */
18173
18174 long
18175 md_pcrel_from_section (fixS * fixP, segT seg)
18176 {
18177 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
18178
18179 /* If this is pc-relative and we are going to emit a relocation
18180 then we just want to put out any pipeline compensation that the linker
18181 will need. Otherwise we want to use the calculated base.
18182 For WinCE we skip the bias for externals as well, since this
18183 is how the MS ARM-CE assembler behaves and we want to be compatible. */
18184 if (fixP->fx_pcrel
18185 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18186 || (arm_force_relocation (fixP)
18187 #ifdef TE_WINCE
18188 && !S_IS_EXTERNAL (fixP->fx_addsy)
18189 #endif
18190 )))
18191 base = 0;
18192
18193 switch (fixP->fx_r_type)
18194 {
18195 /* PC relative addressing on the Thumb is slightly odd as the
18196 bottom two bits of the PC are forced to zero for the
18197 calculation. This happens *after* application of the
18198 pipeline offset. However, Thumb adrl already adjusts for
18199 this, so we need not do it again. */
18200 case BFD_RELOC_ARM_THUMB_ADD:
18201 return base & ~3;
18202
18203 case BFD_RELOC_ARM_THUMB_OFFSET:
18204 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18205 case BFD_RELOC_ARM_T32_ADD_PC12:
18206 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18207 return (base + 4) & ~3;
18208
18209 /* Thumb branches are simply offset by +4. */
18210 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18211 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18212 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18213 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18214 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18215 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18216 case BFD_RELOC_THUMB_PCREL_BLX:
18217 return base + 4;
18218
18219 /* ARM mode branches are offset by +8. However, the Windows CE
18220 loader expects the relocation not to take this into account. */
18221 case BFD_RELOC_ARM_PCREL_BRANCH:
18222 case BFD_RELOC_ARM_PCREL_CALL:
18223 case BFD_RELOC_ARM_PCREL_JUMP:
18224 case BFD_RELOC_ARM_PCREL_BLX:
18225 case BFD_RELOC_ARM_PLT32:
18226 #ifdef TE_WINCE
18227 /* When handling fixups immediately, because we have already
18228 discovered the value of a symbol, or the address of the frag involved
18229 we must account for the offset by +8, as the OS loader will never see the reloc.
18230 see fixup_segment() in write.c
18231 The S_IS_EXTERNAL test handles the case of global symbols.
18232 Those need the calculated base, not just the pipe compensation the linker will need. */
18233 if (fixP->fx_pcrel
18234 && fixP->fx_addsy != NULL
18235 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
18236 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
18237 return base + 8;
18238 return base;
18239 #else
18240 return base + 8;
18241 #endif
18242
18243 /* ARM mode loads relative to PC are also offset by +8. Unlike
18244 branches, the Windows CE loader *does* expect the relocation
18245 to take this into account. */
18246 case BFD_RELOC_ARM_OFFSET_IMM:
18247 case BFD_RELOC_ARM_OFFSET_IMM8:
18248 case BFD_RELOC_ARM_HWLITERAL:
18249 case BFD_RELOC_ARM_LITERAL:
18250 case BFD_RELOC_ARM_CP_OFF_IMM:
18251 return base + 8;
18252
18253
18254 /* Other PC-relative relocations are un-offset. */
18255 default:
18256 return base;
18257 }
18258 }
18259
18260 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
18261 Otherwise we have no need to default values of symbols. */
18262
18263 symbolS *
18264 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
18265 {
18266 #ifdef OBJ_ELF
18267 if (name[0] == '_' && name[1] == 'G'
18268 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
18269 {
18270 if (!GOT_symbol)
18271 {
18272 if (symbol_find (name))
18273 as_bad (_("GOT already in the symbol table"));
18274
18275 GOT_symbol = symbol_new (name, undefined_section,
18276 (valueT) 0, & zero_address_frag);
18277 }
18278
18279 return GOT_symbol;
18280 }
18281 #endif
18282
18283 return 0;
18284 }
18285
18286 /* Subroutine of md_apply_fix. Check to see if an immediate can be
18287 computed as two separate immediate values, added together. We
18288 already know that this value cannot be computed by just one ARM
18289 instruction. */
18290
18291 static unsigned int
18292 validate_immediate_twopart (unsigned int val,
18293 unsigned int * highpart)
18294 {
18295 unsigned int a;
18296 unsigned int i;
18297
18298 for (i = 0; i < 32; i += 2)
18299 if (((a = rotate_left (val, i)) & 0xff) != 0)
18300 {
18301 if (a & 0xff00)
18302 {
18303 if (a & ~ 0xffff)
18304 continue;
18305 * highpart = (a >> 8) | ((i + 24) << 7);
18306 }
18307 else if (a & 0xff0000)
18308 {
18309 if (a & 0xff000000)
18310 continue;
18311 * highpart = (a >> 16) | ((i + 16) << 7);
18312 }
18313 else
18314 {
18315 assert (a & 0xff000000);
18316 * highpart = (a >> 24) | ((i + 8) << 7);
18317 }
18318
18319 return (a & 0xff) | (i << 7);
18320 }
18321
18322 return FAIL;
18323 }
18324
18325 static int
18326 validate_offset_imm (unsigned int val, int hwse)
18327 {
18328 if ((hwse && val > 255) || val > 4095)
18329 return FAIL;
18330 return val;
18331 }
18332
18333 /* Subroutine of md_apply_fix. Do those data_ops which can take a
18334 negative immediate constant by altering the instruction. A bit of
18335 a hack really.
18336 MOV <-> MVN
18337 AND <-> BIC
18338 ADC <-> SBC
18339 by inverting the second operand, and
18340 ADD <-> SUB
18341 CMP <-> CMN
18342 by negating the second operand. */
18343
18344 static int
18345 negate_data_op (unsigned long * instruction,
18346 unsigned long value)
18347 {
18348 int op, new_inst;
18349 unsigned long negated, inverted;
18350
18351 negated = encode_arm_immediate (-value);
18352 inverted = encode_arm_immediate (~value);
18353
18354 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
18355 switch (op)
18356 {
18357 /* First negates. */
18358 case OPCODE_SUB: /* ADD <-> SUB */
18359 new_inst = OPCODE_ADD;
18360 value = negated;
18361 break;
18362
18363 case OPCODE_ADD:
18364 new_inst = OPCODE_SUB;
18365 value = negated;
18366 break;
18367
18368 case OPCODE_CMP: /* CMP <-> CMN */
18369 new_inst = OPCODE_CMN;
18370 value = negated;
18371 break;
18372
18373 case OPCODE_CMN:
18374 new_inst = OPCODE_CMP;
18375 value = negated;
18376 break;
18377
18378 /* Now Inverted ops. */
18379 case OPCODE_MOV: /* MOV <-> MVN */
18380 new_inst = OPCODE_MVN;
18381 value = inverted;
18382 break;
18383
18384 case OPCODE_MVN:
18385 new_inst = OPCODE_MOV;
18386 value = inverted;
18387 break;
18388
18389 case OPCODE_AND: /* AND <-> BIC */
18390 new_inst = OPCODE_BIC;
18391 value = inverted;
18392 break;
18393
18394 case OPCODE_BIC:
18395 new_inst = OPCODE_AND;
18396 value = inverted;
18397 break;
18398
18399 case OPCODE_ADC: /* ADC <-> SBC */
18400 new_inst = OPCODE_SBC;
18401 value = inverted;
18402 break;
18403
18404 case OPCODE_SBC:
18405 new_inst = OPCODE_ADC;
18406 value = inverted;
18407 break;
18408
18409 /* We cannot do anything. */
18410 default:
18411 return FAIL;
18412 }
18413
18414 if (value == (unsigned) FAIL)
18415 return FAIL;
18416
18417 *instruction &= OPCODE_MASK;
18418 *instruction |= new_inst << DATA_OP_SHIFT;
18419 return value;
18420 }
18421
18422 /* Like negate_data_op, but for Thumb-2. */
18423
18424 static unsigned int
18425 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
18426 {
18427 int op, new_inst;
18428 int rd;
18429 unsigned int negated, inverted;
18430
18431 negated = encode_thumb32_immediate (-value);
18432 inverted = encode_thumb32_immediate (~value);
18433
18434 rd = (*instruction >> 8) & 0xf;
18435 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
18436 switch (op)
18437 {
18438 /* ADD <-> SUB. Includes CMP <-> CMN. */
18439 case T2_OPCODE_SUB:
18440 new_inst = T2_OPCODE_ADD;
18441 value = negated;
18442 break;
18443
18444 case T2_OPCODE_ADD:
18445 new_inst = T2_OPCODE_SUB;
18446 value = negated;
18447 break;
18448
18449 /* ORR <-> ORN. Includes MOV <-> MVN. */
18450 case T2_OPCODE_ORR:
18451 new_inst = T2_OPCODE_ORN;
18452 value = inverted;
18453 break;
18454
18455 case T2_OPCODE_ORN:
18456 new_inst = T2_OPCODE_ORR;
18457 value = inverted;
18458 break;
18459
18460 /* AND <-> BIC. TST has no inverted equivalent. */
18461 case T2_OPCODE_AND:
18462 new_inst = T2_OPCODE_BIC;
18463 if (rd == 15)
18464 value = FAIL;
18465 else
18466 value = inverted;
18467 break;
18468
18469 case T2_OPCODE_BIC:
18470 new_inst = T2_OPCODE_AND;
18471 value = inverted;
18472 break;
18473
18474 /* ADC <-> SBC */
18475 case T2_OPCODE_ADC:
18476 new_inst = T2_OPCODE_SBC;
18477 value = inverted;
18478 break;
18479
18480 case T2_OPCODE_SBC:
18481 new_inst = T2_OPCODE_ADC;
18482 value = inverted;
18483 break;
18484
18485 /* We cannot do anything. */
18486 default:
18487 return FAIL;
18488 }
18489
18490 if (value == (unsigned int)FAIL)
18491 return FAIL;
18492
18493 *instruction &= T2_OPCODE_MASK;
18494 *instruction |= new_inst << T2_DATA_OP_SHIFT;
18495 return value;
18496 }
18497
18498 /* Read a 32-bit thumb instruction from buf. */
18499 static unsigned long
18500 get_thumb32_insn (char * buf)
18501 {
18502 unsigned long insn;
18503 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
18504 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18505
18506 return insn;
18507 }
18508
18509
18510 /* We usually want to set the low bit on the address of thumb function
18511 symbols. In particular .word foo - . should have the low bit set.
18512 Generic code tries to fold the difference of two symbols to
18513 a constant. Prevent this and force a relocation when the first symbols
18514 is a thumb function. */
18515 int
18516 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
18517 {
18518 if (op == O_subtract
18519 && l->X_op == O_symbol
18520 && r->X_op == O_symbol
18521 && THUMB_IS_FUNC (l->X_add_symbol))
18522 {
18523 l->X_op = O_subtract;
18524 l->X_op_symbol = r->X_add_symbol;
18525 l->X_add_number -= r->X_add_number;
18526 return 1;
18527 }
18528 /* Process as normal. */
18529 return 0;
18530 }
18531
18532 void
18533 md_apply_fix (fixS * fixP,
18534 valueT * valP,
18535 segT seg)
18536 {
18537 offsetT value = * valP;
18538 offsetT newval;
18539 unsigned int newimm;
18540 unsigned long temp;
18541 int sign;
18542 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
18543
18544 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
18545
18546 /* Note whether this will delete the relocation. */
18547
18548 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
18549 fixP->fx_done = 1;
18550
18551 /* On a 64-bit host, silently truncate 'value' to 32 bits for
18552 consistency with the behaviour on 32-bit hosts. Remember value
18553 for emit_reloc. */
18554 value &= 0xffffffff;
18555 value ^= 0x80000000;
18556 value -= 0x80000000;
18557
18558 *valP = value;
18559 fixP->fx_addnumber = value;
18560
18561 /* Same treatment for fixP->fx_offset. */
18562 fixP->fx_offset &= 0xffffffff;
18563 fixP->fx_offset ^= 0x80000000;
18564 fixP->fx_offset -= 0x80000000;
18565
18566 switch (fixP->fx_r_type)
18567 {
18568 case BFD_RELOC_NONE:
18569 /* This will need to go in the object file. */
18570 fixP->fx_done = 0;
18571 break;
18572
18573 case BFD_RELOC_ARM_IMMEDIATE:
18574 /* We claim that this fixup has been processed here,
18575 even if in fact we generate an error because we do
18576 not have a reloc for it, so tc_gen_reloc will reject it. */
18577 fixP->fx_done = 1;
18578
18579 if (fixP->fx_addsy
18580 && ! S_IS_DEFINED (fixP->fx_addsy))
18581 {
18582 as_bad_where (fixP->fx_file, fixP->fx_line,
18583 _("undefined symbol %s used as an immediate value"),
18584 S_GET_NAME (fixP->fx_addsy));
18585 break;
18586 }
18587
18588 if (fixP->fx_addsy
18589 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18590 {
18591 as_bad_where (fixP->fx_file, fixP->fx_line,
18592 _("symbol %s is in a different section"),
18593 S_GET_NAME (fixP->fx_addsy));
18594 break;
18595 }
18596
18597 newimm = encode_arm_immediate (value);
18598 temp = md_chars_to_number (buf, INSN_SIZE);
18599
18600 /* If the instruction will fail, see if we can fix things up by
18601 changing the opcode. */
18602 if (newimm == (unsigned int) FAIL
18603 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
18604 {
18605 as_bad_where (fixP->fx_file, fixP->fx_line,
18606 _("invalid constant (%lx) after fixup"),
18607 (unsigned long) value);
18608 break;
18609 }
18610
18611 newimm |= (temp & 0xfffff000);
18612 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18613 break;
18614
18615 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18616 {
18617 unsigned int highpart = 0;
18618 unsigned int newinsn = 0xe1a00000; /* nop. */
18619
18620 if (fixP->fx_addsy
18621 && ! S_IS_DEFINED (fixP->fx_addsy))
18622 {
18623 as_bad_where (fixP->fx_file, fixP->fx_line,
18624 _("undefined symbol %s used as an immediate value"),
18625 S_GET_NAME (fixP->fx_addsy));
18626 break;
18627 }
18628
18629 if (fixP->fx_addsy
18630 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18631 {
18632 as_bad_where (fixP->fx_file, fixP->fx_line,
18633 _("symbol %s is in a different section"),
18634 S_GET_NAME (fixP->fx_addsy));
18635 break;
18636 }
18637
18638 newimm = encode_arm_immediate (value);
18639 temp = md_chars_to_number (buf, INSN_SIZE);
18640
18641 /* If the instruction will fail, see if we can fix things up by
18642 changing the opcode. */
18643 if (newimm == (unsigned int) FAIL
18644 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18645 {
18646 /* No ? OK - try using two ADD instructions to generate
18647 the value. */
18648 newimm = validate_immediate_twopart (value, & highpart);
18649
18650 /* Yes - then make sure that the second instruction is
18651 also an add. */
18652 if (newimm != (unsigned int) FAIL)
18653 newinsn = temp;
18654 /* Still No ? Try using a negated value. */
18655 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18656 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18657 /* Otherwise - give up. */
18658 else
18659 {
18660 as_bad_where (fixP->fx_file, fixP->fx_line,
18661 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18662 (long) value);
18663 break;
18664 }
18665
18666 /* Replace the first operand in the 2nd instruction (which
18667 is the PC) with the destination register. We have
18668 already added in the PC in the first instruction and we
18669 do not want to do it again. */
18670 newinsn &= ~ 0xf0000;
18671 newinsn |= ((newinsn & 0x0f000) << 4);
18672 }
18673
18674 newimm |= (temp & 0xfffff000);
18675 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18676
18677 highpart |= (newinsn & 0xfffff000);
18678 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18679 }
18680 break;
18681
18682 case BFD_RELOC_ARM_OFFSET_IMM:
18683 if (!fixP->fx_done && seg->use_rela_p)
18684 value = 0;
18685
18686 case BFD_RELOC_ARM_LITERAL:
18687 sign = value >= 0;
18688
18689 if (value < 0)
18690 value = - value;
18691
18692 if (validate_offset_imm (value, 0) == FAIL)
18693 {
18694 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18695 as_bad_where (fixP->fx_file, fixP->fx_line,
18696 _("invalid literal constant: pool needs to be closer"));
18697 else
18698 as_bad_where (fixP->fx_file, fixP->fx_line,
18699 _("bad immediate value for offset (%ld)"),
18700 (long) value);
18701 break;
18702 }
18703
18704 newval = md_chars_to_number (buf, INSN_SIZE);
18705 newval &= 0xff7ff000;
18706 newval |= value | (sign ? INDEX_UP : 0);
18707 md_number_to_chars (buf, newval, INSN_SIZE);
18708 break;
18709
18710 case BFD_RELOC_ARM_OFFSET_IMM8:
18711 case BFD_RELOC_ARM_HWLITERAL:
18712 sign = value >= 0;
18713
18714 if (value < 0)
18715 value = - value;
18716
18717 if (validate_offset_imm (value, 1) == FAIL)
18718 {
18719 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18720 as_bad_where (fixP->fx_file, fixP->fx_line,
18721 _("invalid literal constant: pool needs to be closer"));
18722 else
18723 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
18724 (long) value);
18725 break;
18726 }
18727
18728 newval = md_chars_to_number (buf, INSN_SIZE);
18729 newval &= 0xff7ff0f0;
18730 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18731 md_number_to_chars (buf, newval, INSN_SIZE);
18732 break;
18733
18734 case BFD_RELOC_ARM_T32_OFFSET_U8:
18735 if (value < 0 || value > 1020 || value % 4 != 0)
18736 as_bad_where (fixP->fx_file, fixP->fx_line,
18737 _("bad immediate value for offset (%ld)"), (long) value);
18738 value /= 4;
18739
18740 newval = md_chars_to_number (buf+2, THUMB_SIZE);
18741 newval |= value;
18742 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18743 break;
18744
18745 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18746 /* This is a complicated relocation used for all varieties of Thumb32
18747 load/store instruction with immediate offset:
18748
18749 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18750 *4, optional writeback(W)
18751 (doubleword load/store)
18752
18753 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18754 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18755 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18756 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18757 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18758
18759 Uppercase letters indicate bits that are already encoded at
18760 this point. Lowercase letters are our problem. For the
18761 second block of instructions, the secondary opcode nybble
18762 (bits 8..11) is present, and bit 23 is zero, even if this is
18763 a PC-relative operation. */
18764 newval = md_chars_to_number (buf, THUMB_SIZE);
18765 newval <<= 16;
18766 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
18767
18768 if ((newval & 0xf0000000) == 0xe0000000)
18769 {
18770 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18771 if (value >= 0)
18772 newval |= (1 << 23);
18773 else
18774 value = -value;
18775 if (value % 4 != 0)
18776 {
18777 as_bad_where (fixP->fx_file, fixP->fx_line,
18778 _("offset not a multiple of 4"));
18779 break;
18780 }
18781 value /= 4;
18782 if (value > 0xff)
18783 {
18784 as_bad_where (fixP->fx_file, fixP->fx_line,
18785 _("offset out of range"));
18786 break;
18787 }
18788 newval &= ~0xff;
18789 }
18790 else if ((newval & 0x000f0000) == 0x000f0000)
18791 {
18792 /* PC-relative, 12-bit offset. */
18793 if (value >= 0)
18794 newval |= (1 << 23);
18795 else
18796 value = -value;
18797 if (value > 0xfff)
18798 {
18799 as_bad_where (fixP->fx_file, fixP->fx_line,
18800 _("offset out of range"));
18801 break;
18802 }
18803 newval &= ~0xfff;
18804 }
18805 else if ((newval & 0x00000100) == 0x00000100)
18806 {
18807 /* Writeback: 8-bit, +/- offset. */
18808 if (value >= 0)
18809 newval |= (1 << 9);
18810 else
18811 value = -value;
18812 if (value > 0xff)
18813 {
18814 as_bad_where (fixP->fx_file, fixP->fx_line,
18815 _("offset out of range"));
18816 break;
18817 }
18818 newval &= ~0xff;
18819 }
18820 else if ((newval & 0x00000f00) == 0x00000e00)
18821 {
18822 /* T-instruction: positive 8-bit offset. */
18823 if (value < 0 || value > 0xff)
18824 {
18825 as_bad_where (fixP->fx_file, fixP->fx_line,
18826 _("offset out of range"));
18827 break;
18828 }
18829 newval &= ~0xff;
18830 newval |= value;
18831 }
18832 else
18833 {
18834 /* Positive 12-bit or negative 8-bit offset. */
18835 int limit;
18836 if (value >= 0)
18837 {
18838 newval |= (1 << 23);
18839 limit = 0xfff;
18840 }
18841 else
18842 {
18843 value = -value;
18844 limit = 0xff;
18845 }
18846 if (value > limit)
18847 {
18848 as_bad_where (fixP->fx_file, fixP->fx_line,
18849 _("offset out of range"));
18850 break;
18851 }
18852 newval &= ~limit;
18853 }
18854
18855 newval |= value;
18856 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18857 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18858 break;
18859
18860 case BFD_RELOC_ARM_SHIFT_IMM:
18861 newval = md_chars_to_number (buf, INSN_SIZE);
18862 if (((unsigned long) value) > 32
18863 || (value == 32
18864 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18865 {
18866 as_bad_where (fixP->fx_file, fixP->fx_line,
18867 _("shift expression is too large"));
18868 break;
18869 }
18870
18871 if (value == 0)
18872 /* Shifts of zero must be done as lsl. */
18873 newval &= ~0x60;
18874 else if (value == 32)
18875 value = 0;
18876 newval &= 0xfffff07f;
18877 newval |= (value & 0x1f) << 7;
18878 md_number_to_chars (buf, newval, INSN_SIZE);
18879 break;
18880
18881 case BFD_RELOC_ARM_T32_IMMEDIATE:
18882 case BFD_RELOC_ARM_T32_ADD_IMM:
18883 case BFD_RELOC_ARM_T32_IMM12:
18884 case BFD_RELOC_ARM_T32_ADD_PC12:
18885 /* We claim that this fixup has been processed here,
18886 even if in fact we generate an error because we do
18887 not have a reloc for it, so tc_gen_reloc will reject it. */
18888 fixP->fx_done = 1;
18889
18890 if (fixP->fx_addsy
18891 && ! S_IS_DEFINED (fixP->fx_addsy))
18892 {
18893 as_bad_where (fixP->fx_file, fixP->fx_line,
18894 _("undefined symbol %s used as an immediate value"),
18895 S_GET_NAME (fixP->fx_addsy));
18896 break;
18897 }
18898
18899 newval = md_chars_to_number (buf, THUMB_SIZE);
18900 newval <<= 16;
18901 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
18902
18903 newimm = FAIL;
18904 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18905 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18906 {
18907 newimm = encode_thumb32_immediate (value);
18908 if (newimm == (unsigned int) FAIL)
18909 newimm = thumb32_negate_data_op (&newval, value);
18910 }
18911 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18912 && newimm == (unsigned int) FAIL)
18913 {
18914 /* Turn add/sum into addw/subw. */
18915 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18916 newval = (newval & 0xfeffffff) | 0x02000000;
18917
18918 /* 12 bit immediate for addw/subw. */
18919 if (value < 0)
18920 {
18921 value = -value;
18922 newval ^= 0x00a00000;
18923 }
18924 if (value > 0xfff)
18925 newimm = (unsigned int) FAIL;
18926 else
18927 newimm = value;
18928 }
18929
18930 if (newimm == (unsigned int)FAIL)
18931 {
18932 as_bad_where (fixP->fx_file, fixP->fx_line,
18933 _("invalid constant (%lx) after fixup"),
18934 (unsigned long) value);
18935 break;
18936 }
18937
18938 newval |= (newimm & 0x800) << 15;
18939 newval |= (newimm & 0x700) << 4;
18940 newval |= (newimm & 0x0ff);
18941
18942 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18943 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18944 break;
18945
18946 case BFD_RELOC_ARM_SMC:
18947 if (((unsigned long) value) > 0xffff)
18948 as_bad_where (fixP->fx_file, fixP->fx_line,
18949 _("invalid smc expression"));
18950 newval = md_chars_to_number (buf, INSN_SIZE);
18951 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18952 md_number_to_chars (buf, newval, INSN_SIZE);
18953 break;
18954
18955 case BFD_RELOC_ARM_SWI:
18956 if (fixP->tc_fix_data != 0)
18957 {
18958 if (((unsigned long) value) > 0xff)
18959 as_bad_where (fixP->fx_file, fixP->fx_line,
18960 _("invalid swi expression"));
18961 newval = md_chars_to_number (buf, THUMB_SIZE);
18962 newval |= value;
18963 md_number_to_chars (buf, newval, THUMB_SIZE);
18964 }
18965 else
18966 {
18967 if (((unsigned long) value) > 0x00ffffff)
18968 as_bad_where (fixP->fx_file, fixP->fx_line,
18969 _("invalid swi expression"));
18970 newval = md_chars_to_number (buf, INSN_SIZE);
18971 newval |= value;
18972 md_number_to_chars (buf, newval, INSN_SIZE);
18973 }
18974 break;
18975
18976 case BFD_RELOC_ARM_MULTI:
18977 if (((unsigned long) value) > 0xffff)
18978 as_bad_where (fixP->fx_file, fixP->fx_line,
18979 _("invalid expression in load/store multiple"));
18980 newval = value | md_chars_to_number (buf, INSN_SIZE);
18981 md_number_to_chars (buf, newval, INSN_SIZE);
18982 break;
18983
18984 #ifdef OBJ_ELF
18985 case BFD_RELOC_ARM_PCREL_CALL:
18986 newval = md_chars_to_number (buf, INSN_SIZE);
18987 if ((newval & 0xf0000000) == 0xf0000000)
18988 temp = 1;
18989 else
18990 temp = 3;
18991 goto arm_branch_common;
18992
18993 case BFD_RELOC_ARM_PCREL_JUMP:
18994 case BFD_RELOC_ARM_PLT32:
18995 #endif
18996 case BFD_RELOC_ARM_PCREL_BRANCH:
18997 temp = 3;
18998 goto arm_branch_common;
18999
19000 case BFD_RELOC_ARM_PCREL_BLX:
19001 temp = 1;
19002 arm_branch_common:
19003 /* We are going to store value (shifted right by two) in the
19004 instruction, in a 24 bit, signed field. Bits 26 through 32 either
19005 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
19006 also be be clear. */
19007 if (value & temp)
19008 as_bad_where (fixP->fx_file, fixP->fx_line,
19009 _("misaligned branch destination"));
19010 if ((value & (offsetT)0xfe000000) != (offsetT)0
19011 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
19012 as_bad_where (fixP->fx_file, fixP->fx_line,
19013 _("branch out of range"));
19014
19015 if (fixP->fx_done || !seg->use_rela_p)
19016 {
19017 newval = md_chars_to_number (buf, INSN_SIZE);
19018 newval |= (value >> 2) & 0x00ffffff;
19019 /* Set the H bit on BLX instructions. */
19020 if (temp == 1)
19021 {
19022 if (value & 2)
19023 newval |= 0x01000000;
19024 else
19025 newval &= ~0x01000000;
19026 }
19027 md_number_to_chars (buf, newval, INSN_SIZE);
19028 }
19029 break;
19030
19031 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
19032 /* CBZ can only branch forward. */
19033
19034 /* Attempts to use CBZ to branch to the next instruction
19035 (which, strictly speaking, are prohibited) will be turned into
19036 no-ops.
19037
19038 FIXME: It may be better to remove the instruction completely and
19039 perform relaxation. */
19040 if (value == -2)
19041 {
19042 newval = md_chars_to_number (buf, THUMB_SIZE);
19043 newval = 0xbf00; /* NOP encoding T1 */
19044 md_number_to_chars (buf, newval, THUMB_SIZE);
19045 }
19046 else
19047 {
19048 if (value & ~0x7e)
19049 as_bad_where (fixP->fx_file, fixP->fx_line,
19050 _("branch out of range"));
19051
19052 if (fixP->fx_done || !seg->use_rela_p)
19053 {
19054 newval = md_chars_to_number (buf, THUMB_SIZE);
19055 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
19056 md_number_to_chars (buf, newval, THUMB_SIZE);
19057 }
19058 }
19059 break;
19060
19061 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
19062 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
19063 as_bad_where (fixP->fx_file, fixP->fx_line,
19064 _("branch out of range"));
19065
19066 if (fixP->fx_done || !seg->use_rela_p)
19067 {
19068 newval = md_chars_to_number (buf, THUMB_SIZE);
19069 newval |= (value & 0x1ff) >> 1;
19070 md_number_to_chars (buf, newval, THUMB_SIZE);
19071 }
19072 break;
19073
19074 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
19075 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
19076 as_bad_where (fixP->fx_file, fixP->fx_line,
19077 _("branch out of range"));
19078
19079 if (fixP->fx_done || !seg->use_rela_p)
19080 {
19081 newval = md_chars_to_number (buf, THUMB_SIZE);
19082 newval |= (value & 0xfff) >> 1;
19083 md_number_to_chars (buf, newval, THUMB_SIZE);
19084 }
19085 break;
19086
19087 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19088 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
19089 as_bad_where (fixP->fx_file, fixP->fx_line,
19090 _("conditional branch out of range"));
19091
19092 if (fixP->fx_done || !seg->use_rela_p)
19093 {
19094 offsetT newval2;
19095 addressT S, J1, J2, lo, hi;
19096
19097 S = (value & 0x00100000) >> 20;
19098 J2 = (value & 0x00080000) >> 19;
19099 J1 = (value & 0x00040000) >> 18;
19100 hi = (value & 0x0003f000) >> 12;
19101 lo = (value & 0x00000ffe) >> 1;
19102
19103 newval = md_chars_to_number (buf, THUMB_SIZE);
19104 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19105 newval |= (S << 10) | hi;
19106 newval2 |= (J1 << 13) | (J2 << 11) | lo;
19107 md_number_to_chars (buf, newval, THUMB_SIZE);
19108 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19109 }
19110 break;
19111
19112 case BFD_RELOC_THUMB_PCREL_BLX:
19113 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19114 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
19115 as_bad_where (fixP->fx_file, fixP->fx_line,
19116 _("branch out of range"));
19117
19118 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19119 /* For a BLX instruction, make sure that the relocation is rounded up
19120 to a word boundary. This follows the semantics of the instruction
19121 which specifies that bit 1 of the target address will come from bit
19122 1 of the base address. */
19123 value = (value + 1) & ~ 1;
19124
19125 if (fixP->fx_done || !seg->use_rela_p)
19126 {
19127 offsetT newval2;
19128
19129 newval = md_chars_to_number (buf, THUMB_SIZE);
19130 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19131 newval |= (value & 0x7fffff) >> 12;
19132 newval2 |= (value & 0xfff) >> 1;
19133 md_number_to_chars (buf, newval, THUMB_SIZE);
19134 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19135 }
19136 break;
19137
19138 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19139 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
19140 as_bad_where (fixP->fx_file, fixP->fx_line,
19141 _("branch out of range"));
19142
19143 if (fixP->fx_done || !seg->use_rela_p)
19144 {
19145 offsetT newval2;
19146 addressT S, I1, I2, lo, hi;
19147
19148 S = (value & 0x01000000) >> 24;
19149 I1 = (value & 0x00800000) >> 23;
19150 I2 = (value & 0x00400000) >> 22;
19151 hi = (value & 0x003ff000) >> 12;
19152 lo = (value & 0x00000ffe) >> 1;
19153
19154 I1 = !(I1 ^ S);
19155 I2 = !(I2 ^ S);
19156
19157 newval = md_chars_to_number (buf, THUMB_SIZE);
19158 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19159 newval |= (S << 10) | hi;
19160 newval2 |= (I1 << 13) | (I2 << 11) | lo;
19161 md_number_to_chars (buf, newval, THUMB_SIZE);
19162 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19163 }
19164 break;
19165
19166 case BFD_RELOC_8:
19167 if (fixP->fx_done || !seg->use_rela_p)
19168 md_number_to_chars (buf, value, 1);
19169 break;
19170
19171 case BFD_RELOC_16:
19172 if (fixP->fx_done || !seg->use_rela_p)
19173 md_number_to_chars (buf, value, 2);
19174 break;
19175
19176 #ifdef OBJ_ELF
19177 case BFD_RELOC_ARM_TLS_GD32:
19178 case BFD_RELOC_ARM_TLS_LE32:
19179 case BFD_RELOC_ARM_TLS_IE32:
19180 case BFD_RELOC_ARM_TLS_LDM32:
19181 case BFD_RELOC_ARM_TLS_LDO32:
19182 S_SET_THREAD_LOCAL (fixP->fx_addsy);
19183 /* fall through */
19184
19185 case BFD_RELOC_ARM_GOT32:
19186 case BFD_RELOC_ARM_GOTOFF:
19187 case BFD_RELOC_ARM_TARGET2:
19188 if (fixP->fx_done || !seg->use_rela_p)
19189 md_number_to_chars (buf, 0, 4);
19190 break;
19191 #endif
19192
19193 case BFD_RELOC_RVA:
19194 case BFD_RELOC_32:
19195 case BFD_RELOC_ARM_TARGET1:
19196 case BFD_RELOC_ARM_ROSEGREL32:
19197 case BFD_RELOC_ARM_SBREL32:
19198 case BFD_RELOC_32_PCREL:
19199 #ifdef TE_PE
19200 case BFD_RELOC_32_SECREL:
19201 #endif
19202 if (fixP->fx_done || !seg->use_rela_p)
19203 #ifdef TE_WINCE
19204 /* For WinCE we only do this for pcrel fixups. */
19205 if (fixP->fx_done || fixP->fx_pcrel)
19206 #endif
19207 md_number_to_chars (buf, value, 4);
19208 break;
19209
19210 #ifdef OBJ_ELF
19211 case BFD_RELOC_ARM_PREL31:
19212 if (fixP->fx_done || !seg->use_rela_p)
19213 {
19214 newval = md_chars_to_number (buf, 4) & 0x80000000;
19215 if ((value ^ (value >> 1)) & 0x40000000)
19216 {
19217 as_bad_where (fixP->fx_file, fixP->fx_line,
19218 _("rel31 relocation overflow"));
19219 }
19220 newval |= value & 0x7fffffff;
19221 md_number_to_chars (buf, newval, 4);
19222 }
19223 break;
19224 #endif
19225
19226 case BFD_RELOC_ARM_CP_OFF_IMM:
19227 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
19228 if (value < -1023 || value > 1023 || (value & 3))
19229 as_bad_where (fixP->fx_file, fixP->fx_line,
19230 _("co-processor offset out of range"));
19231 cp_off_common:
19232 sign = value >= 0;
19233 if (value < 0)
19234 value = -value;
19235 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19236 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19237 newval = md_chars_to_number (buf, INSN_SIZE);
19238 else
19239 newval = get_thumb32_insn (buf);
19240 newval &= 0xff7fff00;
19241 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
19242 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19243 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19244 md_number_to_chars (buf, newval, INSN_SIZE);
19245 else
19246 put_thumb32_insn (buf, newval);
19247 break;
19248
19249 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
19250 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
19251 if (value < -255 || value > 255)
19252 as_bad_where (fixP->fx_file, fixP->fx_line,
19253 _("co-processor offset out of range"));
19254 value *= 4;
19255 goto cp_off_common;
19256
19257 case BFD_RELOC_ARM_THUMB_OFFSET:
19258 newval = md_chars_to_number (buf, THUMB_SIZE);
19259 /* Exactly what ranges, and where the offset is inserted depends
19260 on the type of instruction, we can establish this from the
19261 top 4 bits. */
19262 switch (newval >> 12)
19263 {
19264 case 4: /* PC load. */
19265 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
19266 forced to zero for these loads; md_pcrel_from has already
19267 compensated for this. */
19268 if (value & 3)
19269 as_bad_where (fixP->fx_file, fixP->fx_line,
19270 _("invalid offset, target not word aligned (0x%08lX)"),
19271 (((unsigned long) fixP->fx_frag->fr_address
19272 + (unsigned long) fixP->fx_where) & ~3)
19273 + (unsigned long) value);
19274
19275 if (value & ~0x3fc)
19276 as_bad_where (fixP->fx_file, fixP->fx_line,
19277 _("invalid offset, value too big (0x%08lX)"),
19278 (long) value);
19279
19280 newval |= value >> 2;
19281 break;
19282
19283 case 9: /* SP load/store. */
19284 if (value & ~0x3fc)
19285 as_bad_where (fixP->fx_file, fixP->fx_line,
19286 _("invalid offset, value too big (0x%08lX)"),
19287 (long) value);
19288 newval |= value >> 2;
19289 break;
19290
19291 case 6: /* Word load/store. */
19292 if (value & ~0x7c)
19293 as_bad_where (fixP->fx_file, fixP->fx_line,
19294 _("invalid offset, value too big (0x%08lX)"),
19295 (long) value);
19296 newval |= value << 4; /* 6 - 2. */
19297 break;
19298
19299 case 7: /* Byte load/store. */
19300 if (value & ~0x1f)
19301 as_bad_where (fixP->fx_file, fixP->fx_line,
19302 _("invalid offset, value too big (0x%08lX)"),
19303 (long) value);
19304 newval |= value << 6;
19305 break;
19306
19307 case 8: /* Halfword load/store. */
19308 if (value & ~0x3e)
19309 as_bad_where (fixP->fx_file, fixP->fx_line,
19310 _("invalid offset, value too big (0x%08lX)"),
19311 (long) value);
19312 newval |= value << 5; /* 6 - 1. */
19313 break;
19314
19315 default:
19316 as_bad_where (fixP->fx_file, fixP->fx_line,
19317 "Unable to process relocation for thumb opcode: %lx",
19318 (unsigned long) newval);
19319 break;
19320 }
19321 md_number_to_chars (buf, newval, THUMB_SIZE);
19322 break;
19323
19324 case BFD_RELOC_ARM_THUMB_ADD:
19325 /* This is a complicated relocation, since we use it for all of
19326 the following immediate relocations:
19327
19328 3bit ADD/SUB
19329 8bit ADD/SUB
19330 9bit ADD/SUB SP word-aligned
19331 10bit ADD PC/SP word-aligned
19332
19333 The type of instruction being processed is encoded in the
19334 instruction field:
19335
19336 0x8000 SUB
19337 0x00F0 Rd
19338 0x000F Rs
19339 */
19340 newval = md_chars_to_number (buf, THUMB_SIZE);
19341 {
19342 int rd = (newval >> 4) & 0xf;
19343 int rs = newval & 0xf;
19344 int subtract = !!(newval & 0x8000);
19345
19346 /* Check for HI regs, only very restricted cases allowed:
19347 Adjusting SP, and using PC or SP to get an address. */
19348 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
19349 || (rs > 7 && rs != REG_SP && rs != REG_PC))
19350 as_bad_where (fixP->fx_file, fixP->fx_line,
19351 _("invalid Hi register with immediate"));
19352
19353 /* If value is negative, choose the opposite instruction. */
19354 if (value < 0)
19355 {
19356 value = -value;
19357 subtract = !subtract;
19358 if (value < 0)
19359 as_bad_where (fixP->fx_file, fixP->fx_line,
19360 _("immediate value out of range"));
19361 }
19362
19363 if (rd == REG_SP)
19364 {
19365 if (value & ~0x1fc)
19366 as_bad_where (fixP->fx_file, fixP->fx_line,
19367 _("invalid immediate for stack address calculation"));
19368 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
19369 newval |= value >> 2;
19370 }
19371 else if (rs == REG_PC || rs == REG_SP)
19372 {
19373 if (subtract || value & ~0x3fc)
19374 as_bad_where (fixP->fx_file, fixP->fx_line,
19375 _("invalid immediate for address calculation (value = 0x%08lX)"),
19376 (unsigned long) value);
19377 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
19378 newval |= rd << 8;
19379 newval |= value >> 2;
19380 }
19381 else if (rs == rd)
19382 {
19383 if (value & ~0xff)
19384 as_bad_where (fixP->fx_file, fixP->fx_line,
19385 _("immediate value out of range"));
19386 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
19387 newval |= (rd << 8) | value;
19388 }
19389 else
19390 {
19391 if (value & ~0x7)
19392 as_bad_where (fixP->fx_file, fixP->fx_line,
19393 _("immediate value out of range"));
19394 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
19395 newval |= rd | (rs << 3) | (value << 6);
19396 }
19397 }
19398 md_number_to_chars (buf, newval, THUMB_SIZE);
19399 break;
19400
19401 case BFD_RELOC_ARM_THUMB_IMM:
19402 newval = md_chars_to_number (buf, THUMB_SIZE);
19403 if (value < 0 || value > 255)
19404 as_bad_where (fixP->fx_file, fixP->fx_line,
19405 _("invalid immediate: %ld is out of range"),
19406 (long) value);
19407 newval |= value;
19408 md_number_to_chars (buf, newval, THUMB_SIZE);
19409 break;
19410
19411 case BFD_RELOC_ARM_THUMB_SHIFT:
19412 /* 5bit shift value (0..32). LSL cannot take 32. */
19413 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
19414 temp = newval & 0xf800;
19415 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
19416 as_bad_where (fixP->fx_file, fixP->fx_line,
19417 _("invalid shift value: %ld"), (long) value);
19418 /* Shifts of zero must be encoded as LSL. */
19419 if (value == 0)
19420 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
19421 /* Shifts of 32 are encoded as zero. */
19422 else if (value == 32)
19423 value = 0;
19424 newval |= value << 6;
19425 md_number_to_chars (buf, newval, THUMB_SIZE);
19426 break;
19427
19428 case BFD_RELOC_VTABLE_INHERIT:
19429 case BFD_RELOC_VTABLE_ENTRY:
19430 fixP->fx_done = 0;
19431 return;
19432
19433 case BFD_RELOC_ARM_MOVW:
19434 case BFD_RELOC_ARM_MOVT:
19435 case BFD_RELOC_ARM_THUMB_MOVW:
19436 case BFD_RELOC_ARM_THUMB_MOVT:
19437 if (fixP->fx_done || !seg->use_rela_p)
19438 {
19439 /* REL format relocations are limited to a 16-bit addend. */
19440 if (!fixP->fx_done)
19441 {
19442 if (value < -0x8000 || value > 0x7fff)
19443 as_bad_where (fixP->fx_file, fixP->fx_line,
19444 _("offset out of range"));
19445 }
19446 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
19447 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
19448 {
19449 value >>= 16;
19450 }
19451
19452 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
19453 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
19454 {
19455 newval = get_thumb32_insn (buf);
19456 newval &= 0xfbf08f00;
19457 newval |= (value & 0xf000) << 4;
19458 newval |= (value & 0x0800) << 15;
19459 newval |= (value & 0x0700) << 4;
19460 newval |= (value & 0x00ff);
19461 put_thumb32_insn (buf, newval);
19462 }
19463 else
19464 {
19465 newval = md_chars_to_number (buf, 4);
19466 newval &= 0xfff0f000;
19467 newval |= value & 0x0fff;
19468 newval |= (value & 0xf000) << 4;
19469 md_number_to_chars (buf, newval, 4);
19470 }
19471 }
19472 return;
19473
19474 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19475 case BFD_RELOC_ARM_ALU_PC_G0:
19476 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19477 case BFD_RELOC_ARM_ALU_PC_G1:
19478 case BFD_RELOC_ARM_ALU_PC_G2:
19479 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19480 case BFD_RELOC_ARM_ALU_SB_G0:
19481 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19482 case BFD_RELOC_ARM_ALU_SB_G1:
19483 case BFD_RELOC_ARM_ALU_SB_G2:
19484 assert (!fixP->fx_done);
19485 if (!seg->use_rela_p)
19486 {
19487 bfd_vma insn;
19488 bfd_vma encoded_addend;
19489 bfd_vma addend_abs = abs (value);
19490
19491 /* Check that the absolute value of the addend can be
19492 expressed as an 8-bit constant plus a rotation. */
19493 encoded_addend = encode_arm_immediate (addend_abs);
19494 if (encoded_addend == (unsigned int) FAIL)
19495 as_bad_where (fixP->fx_file, fixP->fx_line,
19496 _("the offset 0x%08lX is not representable"),
19497 (unsigned long) addend_abs);
19498
19499 /* Extract the instruction. */
19500 insn = md_chars_to_number (buf, INSN_SIZE);
19501
19502 /* If the addend is positive, use an ADD instruction.
19503 Otherwise use a SUB. Take care not to destroy the S bit. */
19504 insn &= 0xff1fffff;
19505 if (value < 0)
19506 insn |= 1 << 22;
19507 else
19508 insn |= 1 << 23;
19509
19510 /* Place the encoded addend into the first 12 bits of the
19511 instruction. */
19512 insn &= 0xfffff000;
19513 insn |= encoded_addend;
19514
19515 /* Update the instruction. */
19516 md_number_to_chars (buf, insn, INSN_SIZE);
19517 }
19518 break;
19519
19520 case BFD_RELOC_ARM_LDR_PC_G0:
19521 case BFD_RELOC_ARM_LDR_PC_G1:
19522 case BFD_RELOC_ARM_LDR_PC_G2:
19523 case BFD_RELOC_ARM_LDR_SB_G0:
19524 case BFD_RELOC_ARM_LDR_SB_G1:
19525 case BFD_RELOC_ARM_LDR_SB_G2:
19526 assert (!fixP->fx_done);
19527 if (!seg->use_rela_p)
19528 {
19529 bfd_vma insn;
19530 bfd_vma addend_abs = abs (value);
19531
19532 /* Check that the absolute value of the addend can be
19533 encoded in 12 bits. */
19534 if (addend_abs >= 0x1000)
19535 as_bad_where (fixP->fx_file, fixP->fx_line,
19536 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
19537 (unsigned long) addend_abs);
19538
19539 /* Extract the instruction. */
19540 insn = md_chars_to_number (buf, INSN_SIZE);
19541
19542 /* If the addend is negative, clear bit 23 of the instruction.
19543 Otherwise set it. */
19544 if (value < 0)
19545 insn &= ~(1 << 23);
19546 else
19547 insn |= 1 << 23;
19548
19549 /* Place the absolute value of the addend into the first 12 bits
19550 of the instruction. */
19551 insn &= 0xfffff000;
19552 insn |= addend_abs;
19553
19554 /* Update the instruction. */
19555 md_number_to_chars (buf, insn, INSN_SIZE);
19556 }
19557 break;
19558
19559 case BFD_RELOC_ARM_LDRS_PC_G0:
19560 case BFD_RELOC_ARM_LDRS_PC_G1:
19561 case BFD_RELOC_ARM_LDRS_PC_G2:
19562 case BFD_RELOC_ARM_LDRS_SB_G0:
19563 case BFD_RELOC_ARM_LDRS_SB_G1:
19564 case BFD_RELOC_ARM_LDRS_SB_G2:
19565 assert (!fixP->fx_done);
19566 if (!seg->use_rela_p)
19567 {
19568 bfd_vma insn;
19569 bfd_vma addend_abs = abs (value);
19570
19571 /* Check that the absolute value of the addend can be
19572 encoded in 8 bits. */
19573 if (addend_abs >= 0x100)
19574 as_bad_where (fixP->fx_file, fixP->fx_line,
19575 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
19576 (unsigned long) addend_abs);
19577
19578 /* Extract the instruction. */
19579 insn = md_chars_to_number (buf, INSN_SIZE);
19580
19581 /* If the addend is negative, clear bit 23 of the instruction.
19582 Otherwise set it. */
19583 if (value < 0)
19584 insn &= ~(1 << 23);
19585 else
19586 insn |= 1 << 23;
19587
19588 /* Place the first four bits of the absolute value of the addend
19589 into the first 4 bits of the instruction, and the remaining
19590 four into bits 8 .. 11. */
19591 insn &= 0xfffff0f0;
19592 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
19593
19594 /* Update the instruction. */
19595 md_number_to_chars (buf, insn, INSN_SIZE);
19596 }
19597 break;
19598
19599 case BFD_RELOC_ARM_LDC_PC_G0:
19600 case BFD_RELOC_ARM_LDC_PC_G1:
19601 case BFD_RELOC_ARM_LDC_PC_G2:
19602 case BFD_RELOC_ARM_LDC_SB_G0:
19603 case BFD_RELOC_ARM_LDC_SB_G1:
19604 case BFD_RELOC_ARM_LDC_SB_G2:
19605 assert (!fixP->fx_done);
19606 if (!seg->use_rela_p)
19607 {
19608 bfd_vma insn;
19609 bfd_vma addend_abs = abs (value);
19610
19611 /* Check that the absolute value of the addend is a multiple of
19612 four and, when divided by four, fits in 8 bits. */
19613 if (addend_abs & 0x3)
19614 as_bad_where (fixP->fx_file, fixP->fx_line,
19615 _("bad offset 0x%08lX (must be word-aligned)"),
19616 (unsigned long) addend_abs);
19617
19618 if ((addend_abs >> 2) > 0xff)
19619 as_bad_where (fixP->fx_file, fixP->fx_line,
19620 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
19621 (unsigned long) addend_abs);
19622
19623 /* Extract the instruction. */
19624 insn = md_chars_to_number (buf, INSN_SIZE);
19625
19626 /* If the addend is negative, clear bit 23 of the instruction.
19627 Otherwise set it. */
19628 if (value < 0)
19629 insn &= ~(1 << 23);
19630 else
19631 insn |= 1 << 23;
19632
19633 /* Place the addend (divided by four) into the first eight
19634 bits of the instruction. */
19635 insn &= 0xfffffff0;
19636 insn |= addend_abs >> 2;
19637
19638 /* Update the instruction. */
19639 md_number_to_chars (buf, insn, INSN_SIZE);
19640 }
19641 break;
19642
19643 case BFD_RELOC_ARM_V4BX:
19644 /* This will need to go in the object file. */
19645 fixP->fx_done = 0;
19646 break;
19647
19648 case BFD_RELOC_UNUSED:
19649 default:
19650 as_bad_where (fixP->fx_file, fixP->fx_line,
19651 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19652 }
19653 }
19654
19655 /* Translate internal representation of relocation info to BFD target
19656 format. */
19657
19658 arelent *
19659 tc_gen_reloc (asection *section, fixS *fixp)
19660 {
19661 arelent * reloc;
19662 bfd_reloc_code_real_type code;
19663
19664 reloc = xmalloc (sizeof (arelent));
19665
19666 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19667 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19668 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
19669
19670 if (fixp->fx_pcrel)
19671 {
19672 if (section->use_rela_p)
19673 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19674 else
19675 fixp->fx_offset = reloc->address;
19676 }
19677 reloc->addend = fixp->fx_offset;
19678
19679 switch (fixp->fx_r_type)
19680 {
19681 case BFD_RELOC_8:
19682 if (fixp->fx_pcrel)
19683 {
19684 code = BFD_RELOC_8_PCREL;
19685 break;
19686 }
19687
19688 case BFD_RELOC_16:
19689 if (fixp->fx_pcrel)
19690 {
19691 code = BFD_RELOC_16_PCREL;
19692 break;
19693 }
19694
19695 case BFD_RELOC_32:
19696 if (fixp->fx_pcrel)
19697 {
19698 code = BFD_RELOC_32_PCREL;
19699 break;
19700 }
19701
19702 case BFD_RELOC_ARM_MOVW:
19703 if (fixp->fx_pcrel)
19704 {
19705 code = BFD_RELOC_ARM_MOVW_PCREL;
19706 break;
19707 }
19708
19709 case BFD_RELOC_ARM_MOVT:
19710 if (fixp->fx_pcrel)
19711 {
19712 code = BFD_RELOC_ARM_MOVT_PCREL;
19713 break;
19714 }
19715
19716 case BFD_RELOC_ARM_THUMB_MOVW:
19717 if (fixp->fx_pcrel)
19718 {
19719 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19720 break;
19721 }
19722
19723 case BFD_RELOC_ARM_THUMB_MOVT:
19724 if (fixp->fx_pcrel)
19725 {
19726 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19727 break;
19728 }
19729
19730 case BFD_RELOC_NONE:
19731 case BFD_RELOC_ARM_PCREL_BRANCH:
19732 case BFD_RELOC_ARM_PCREL_BLX:
19733 case BFD_RELOC_RVA:
19734 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19735 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19736 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19737 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19738 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19739 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19740 case BFD_RELOC_THUMB_PCREL_BLX:
19741 case BFD_RELOC_VTABLE_ENTRY:
19742 case BFD_RELOC_VTABLE_INHERIT:
19743 #ifdef TE_PE
19744 case BFD_RELOC_32_SECREL:
19745 #endif
19746 code = fixp->fx_r_type;
19747 break;
19748
19749 case BFD_RELOC_ARM_LITERAL:
19750 case BFD_RELOC_ARM_HWLITERAL:
19751 /* If this is called then the a literal has
19752 been referenced across a section boundary. */
19753 as_bad_where (fixp->fx_file, fixp->fx_line,
19754 _("literal referenced across section boundary"));
19755 return NULL;
19756
19757 #ifdef OBJ_ELF
19758 case BFD_RELOC_ARM_GOT32:
19759 case BFD_RELOC_ARM_GOTOFF:
19760 case BFD_RELOC_ARM_PLT32:
19761 case BFD_RELOC_ARM_TARGET1:
19762 case BFD_RELOC_ARM_ROSEGREL32:
19763 case BFD_RELOC_ARM_SBREL32:
19764 case BFD_RELOC_ARM_PREL31:
19765 case BFD_RELOC_ARM_TARGET2:
19766 case BFD_RELOC_ARM_TLS_LE32:
19767 case BFD_RELOC_ARM_TLS_LDO32:
19768 case BFD_RELOC_ARM_PCREL_CALL:
19769 case BFD_RELOC_ARM_PCREL_JUMP:
19770 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19771 case BFD_RELOC_ARM_ALU_PC_G0:
19772 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19773 case BFD_RELOC_ARM_ALU_PC_G1:
19774 case BFD_RELOC_ARM_ALU_PC_G2:
19775 case BFD_RELOC_ARM_LDR_PC_G0:
19776 case BFD_RELOC_ARM_LDR_PC_G1:
19777 case BFD_RELOC_ARM_LDR_PC_G2:
19778 case BFD_RELOC_ARM_LDRS_PC_G0:
19779 case BFD_RELOC_ARM_LDRS_PC_G1:
19780 case BFD_RELOC_ARM_LDRS_PC_G2:
19781 case BFD_RELOC_ARM_LDC_PC_G0:
19782 case BFD_RELOC_ARM_LDC_PC_G1:
19783 case BFD_RELOC_ARM_LDC_PC_G2:
19784 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19785 case BFD_RELOC_ARM_ALU_SB_G0:
19786 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19787 case BFD_RELOC_ARM_ALU_SB_G1:
19788 case BFD_RELOC_ARM_ALU_SB_G2:
19789 case BFD_RELOC_ARM_LDR_SB_G0:
19790 case BFD_RELOC_ARM_LDR_SB_G1:
19791 case BFD_RELOC_ARM_LDR_SB_G2:
19792 case BFD_RELOC_ARM_LDRS_SB_G0:
19793 case BFD_RELOC_ARM_LDRS_SB_G1:
19794 case BFD_RELOC_ARM_LDRS_SB_G2:
19795 case BFD_RELOC_ARM_LDC_SB_G0:
19796 case BFD_RELOC_ARM_LDC_SB_G1:
19797 case BFD_RELOC_ARM_LDC_SB_G2:
19798 case BFD_RELOC_ARM_V4BX:
19799 code = fixp->fx_r_type;
19800 break;
19801
19802 case BFD_RELOC_ARM_TLS_GD32:
19803 case BFD_RELOC_ARM_TLS_IE32:
19804 case BFD_RELOC_ARM_TLS_LDM32:
19805 /* BFD will include the symbol's address in the addend.
19806 But we don't want that, so subtract it out again here. */
19807 if (!S_IS_COMMON (fixp->fx_addsy))
19808 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19809 code = fixp->fx_r_type;
19810 break;
19811 #endif
19812
19813 case BFD_RELOC_ARM_IMMEDIATE:
19814 as_bad_where (fixp->fx_file, fixp->fx_line,
19815 _("internal relocation (type: IMMEDIATE) not fixed up"));
19816 return NULL;
19817
19818 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19819 as_bad_where (fixp->fx_file, fixp->fx_line,
19820 _("ADRL used for a symbol not defined in the same file"));
19821 return NULL;
19822
19823 case BFD_RELOC_ARM_OFFSET_IMM:
19824 if (section->use_rela_p)
19825 {
19826 code = fixp->fx_r_type;
19827 break;
19828 }
19829
19830 if (fixp->fx_addsy != NULL
19831 && !S_IS_DEFINED (fixp->fx_addsy)
19832 && S_IS_LOCAL (fixp->fx_addsy))
19833 {
19834 as_bad_where (fixp->fx_file, fixp->fx_line,
19835 _("undefined local label `%s'"),
19836 S_GET_NAME (fixp->fx_addsy));
19837 return NULL;
19838 }
19839
19840 as_bad_where (fixp->fx_file, fixp->fx_line,
19841 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19842 return NULL;
19843
19844 default:
19845 {
19846 char * type;
19847
19848 switch (fixp->fx_r_type)
19849 {
19850 case BFD_RELOC_NONE: type = "NONE"; break;
19851 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19852 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
19853 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
19854 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19855 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19856 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
19857 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
19858 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19859 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19860 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19861 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19862 default: type = _("<unknown>"); break;
19863 }
19864 as_bad_where (fixp->fx_file, fixp->fx_line,
19865 _("cannot represent %s relocation in this object file format"),
19866 type);
19867 return NULL;
19868 }
19869 }
19870
19871 #ifdef OBJ_ELF
19872 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19873 && GOT_symbol
19874 && fixp->fx_addsy == GOT_symbol)
19875 {
19876 code = BFD_RELOC_ARM_GOTPC;
19877 reloc->addend = fixp->fx_offset = reloc->address;
19878 }
19879 #endif
19880
19881 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
19882
19883 if (reloc->howto == NULL)
19884 {
19885 as_bad_where (fixp->fx_file, fixp->fx_line,
19886 _("cannot represent %s relocation in this object file format"),
19887 bfd_get_reloc_code_name (code));
19888 return NULL;
19889 }
19890
19891 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19892 vtable entry to be used in the relocation's section offset. */
19893 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19894 reloc->address = fixp->fx_offset;
19895
19896 return reloc;
19897 }
19898
19899 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
19900
19901 void
19902 cons_fix_new_arm (fragS * frag,
19903 int where,
19904 int size,
19905 expressionS * exp)
19906 {
19907 bfd_reloc_code_real_type type;
19908 int pcrel = 0;
19909
19910 /* Pick a reloc.
19911 FIXME: @@ Should look at CPU word size. */
19912 switch (size)
19913 {
19914 case 1:
19915 type = BFD_RELOC_8;
19916 break;
19917 case 2:
19918 type = BFD_RELOC_16;
19919 break;
19920 case 4:
19921 default:
19922 type = BFD_RELOC_32;
19923 break;
19924 case 8:
19925 type = BFD_RELOC_64;
19926 break;
19927 }
19928
19929 #ifdef TE_PE
19930 if (exp->X_op == O_secrel)
19931 {
19932 exp->X_op = O_symbol;
19933 type = BFD_RELOC_32_SECREL;
19934 }
19935 #endif
19936
19937 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19938 }
19939
19940 #if defined (OBJ_COFF)
19941 void
19942 arm_validate_fix (fixS * fixP)
19943 {
19944 /* If the destination of the branch is a defined symbol which does not have
19945 the THUMB_FUNC attribute, then we must be calling a function which has
19946 the (interfacearm) attribute. We look for the Thumb entry point to that
19947 function and change the branch to refer to that function instead. */
19948 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19949 && fixP->fx_addsy != NULL
19950 && S_IS_DEFINED (fixP->fx_addsy)
19951 && ! THUMB_IS_FUNC (fixP->fx_addsy))
19952 {
19953 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
19954 }
19955 }
19956 #endif
19957
19958 int
19959 arm_force_relocation (struct fix * fixp)
19960 {
19961 #if defined (OBJ_COFF) && defined (TE_PE)
19962 if (fixp->fx_r_type == BFD_RELOC_RVA)
19963 return 1;
19964 #endif
19965
19966 /* Resolve these relocations even if the symbol is extern or weak. */
19967 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19968 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
19969 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
19970 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
19971 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19972 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19973 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
19974 return 0;
19975
19976 /* Always leave these relocations for the linker. */
19977 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19978 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19979 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19980 return 1;
19981
19982 /* Always generate relocations against function symbols. */
19983 if (fixp->fx_r_type == BFD_RELOC_32
19984 && fixp->fx_addsy
19985 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19986 return 1;
19987
19988 return generic_force_reloc (fixp);
19989 }
19990
19991 #if defined (OBJ_ELF) || defined (OBJ_COFF)
19992 /* Relocations against function names must be left unadjusted,
19993 so that the linker can use this information to generate interworking
19994 stubs. The MIPS version of this function
19995 also prevents relocations that are mips-16 specific, but I do not
19996 know why it does this.
19997
19998 FIXME:
19999 There is one other problem that ought to be addressed here, but
20000 which currently is not: Taking the address of a label (rather
20001 than a function) and then later jumping to that address. Such
20002 addresses also ought to have their bottom bit set (assuming that
20003 they reside in Thumb code), but at the moment they will not. */
20004
20005 bfd_boolean
20006 arm_fix_adjustable (fixS * fixP)
20007 {
20008 if (fixP->fx_addsy == NULL)
20009 return 1;
20010
20011 /* Preserve relocations against symbols with function type. */
20012 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
20013 return 0;
20014
20015 if (THUMB_IS_FUNC (fixP->fx_addsy)
20016 && fixP->fx_subsy == NULL)
20017 return 0;
20018
20019 /* We need the symbol name for the VTABLE entries. */
20020 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
20021 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20022 return 0;
20023
20024 /* Don't allow symbols to be discarded on GOT related relocs. */
20025 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
20026 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
20027 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
20028 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
20029 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
20030 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
20031 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
20032 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
20033 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
20034 return 0;
20035
20036 /* Similarly for group relocations. */
20037 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20038 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20039 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20040 return 0;
20041
20042 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
20043 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
20044 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20045 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
20046 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
20047 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20048 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
20049 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
20050 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
20051 return 0;
20052
20053 return 1;
20054 }
20055 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
20056
20057 #ifdef OBJ_ELF
20058
20059 const char *
20060 elf32_arm_target_format (void)
20061 {
20062 #ifdef TE_SYMBIAN
20063 return (target_big_endian
20064 ? "elf32-bigarm-symbian"
20065 : "elf32-littlearm-symbian");
20066 #elif defined (TE_VXWORKS)
20067 return (target_big_endian
20068 ? "elf32-bigarm-vxworks"
20069 : "elf32-littlearm-vxworks");
20070 #else
20071 if (target_big_endian)
20072 return "elf32-bigarm";
20073 else
20074 return "elf32-littlearm";
20075 #endif
20076 }
20077
20078 void
20079 armelf_frob_symbol (symbolS * symp,
20080 int * puntp)
20081 {
20082 elf_frob_symbol (symp, puntp);
20083 }
20084 #endif
20085
20086 /* MD interface: Finalization. */
20087
20088 /* A good place to do this, although this was probably not intended
20089 for this kind of use. We need to dump the literal pool before
20090 references are made to a null symbol pointer. */
20091
20092 void
20093 arm_cleanup (void)
20094 {
20095 literal_pool * pool;
20096
20097 for (pool = list_of_pools; pool; pool = pool->next)
20098 {
20099 /* Put it at the end of the relevant section. */
20100 subseg_set (pool->section, pool->sub_section);
20101 #ifdef OBJ_ELF
20102 arm_elf_change_section ();
20103 #endif
20104 s_ltorg (0);
20105 }
20106 }
20107
20108 /* Adjust the symbol table. This marks Thumb symbols as distinct from
20109 ARM ones. */
20110
20111 void
20112 arm_adjust_symtab (void)
20113 {
20114 #ifdef OBJ_COFF
20115 symbolS * sym;
20116
20117 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20118 {
20119 if (ARM_IS_THUMB (sym))
20120 {
20121 if (THUMB_IS_FUNC (sym))
20122 {
20123 /* Mark the symbol as a Thumb function. */
20124 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
20125 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
20126 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
20127
20128 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
20129 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
20130 else
20131 as_bad (_("%s: unexpected function type: %d"),
20132 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
20133 }
20134 else switch (S_GET_STORAGE_CLASS (sym))
20135 {
20136 case C_EXT:
20137 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
20138 break;
20139 case C_STAT:
20140 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
20141 break;
20142 case C_LABEL:
20143 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
20144 break;
20145 default:
20146 /* Do nothing. */
20147 break;
20148 }
20149 }
20150
20151 if (ARM_IS_INTERWORK (sym))
20152 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
20153 }
20154 #endif
20155 #ifdef OBJ_ELF
20156 symbolS * sym;
20157 char bind;
20158
20159 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20160 {
20161 if (ARM_IS_THUMB (sym))
20162 {
20163 elf_symbol_type * elf_sym;
20164
20165 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
20166 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
20167
20168 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
20169 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
20170 {
20171 /* If it's a .thumb_func, declare it as so,
20172 otherwise tag label as .code 16. */
20173 if (THUMB_IS_FUNC (sym))
20174 elf_sym->internal_elf_sym.st_info =
20175 ELF_ST_INFO (bind, STT_ARM_TFUNC);
20176 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20177 elf_sym->internal_elf_sym.st_info =
20178 ELF_ST_INFO (bind, STT_ARM_16BIT);
20179 }
20180 }
20181 }
20182 #endif
20183 }
20184
20185 /* MD interface: Initialization. */
20186
20187 static void
20188 set_constant_flonums (void)
20189 {
20190 int i;
20191
20192 for (i = 0; i < NUM_FLOAT_VALS; i++)
20193 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
20194 abort ();
20195 }
20196
20197 /* Auto-select Thumb mode if it's the only available instruction set for the
20198 given architecture. */
20199
20200 static void
20201 autoselect_thumb_from_cpu_variant (void)
20202 {
20203 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
20204 opcode_select (16);
20205 }
20206
20207 void
20208 md_begin (void)
20209 {
20210 unsigned mach;
20211 unsigned int i;
20212
20213 if ( (arm_ops_hsh = hash_new ()) == NULL
20214 || (arm_cond_hsh = hash_new ()) == NULL
20215 || (arm_shift_hsh = hash_new ()) == NULL
20216 || (arm_psr_hsh = hash_new ()) == NULL
20217 || (arm_v7m_psr_hsh = hash_new ()) == NULL
20218 || (arm_reg_hsh = hash_new ()) == NULL
20219 || (arm_reloc_hsh = hash_new ()) == NULL
20220 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
20221 as_fatal (_("virtual memory exhausted"));
20222
20223 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
20224 hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i));
20225 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
20226 hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i));
20227 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
20228 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
20229 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
20230 hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i));
20231 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
20232 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i));
20233 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
20234 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
20235 for (i = 0;
20236 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
20237 i++)
20238 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
20239 (void *) (barrier_opt_names + i));
20240 #ifdef OBJ_ELF
20241 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
20242 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
20243 #endif
20244
20245 set_constant_flonums ();
20246
20247 /* Set the cpu variant based on the command-line options. We prefer
20248 -mcpu= over -march= if both are set (as for GCC); and we prefer
20249 -mfpu= over any other way of setting the floating point unit.
20250 Use of legacy options with new options are faulted. */
20251 if (legacy_cpu)
20252 {
20253 if (mcpu_cpu_opt || march_cpu_opt)
20254 as_bad (_("use of old and new-style options to set CPU type"));
20255
20256 mcpu_cpu_opt = legacy_cpu;
20257 }
20258 else if (!mcpu_cpu_opt)
20259 mcpu_cpu_opt = march_cpu_opt;
20260
20261 if (legacy_fpu)
20262 {
20263 if (mfpu_opt)
20264 as_bad (_("use of old and new-style options to set FPU type"));
20265
20266 mfpu_opt = legacy_fpu;
20267 }
20268 else if (!mfpu_opt)
20269 {
20270 #if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
20271 /* Some environments specify a default FPU. If they don't, infer it
20272 from the processor. */
20273 if (mcpu_fpu_opt)
20274 mfpu_opt = mcpu_fpu_opt;
20275 else
20276 mfpu_opt = march_fpu_opt;
20277 #else
20278 mfpu_opt = &fpu_default;
20279 #endif
20280 }
20281
20282 if (!mfpu_opt)
20283 {
20284 if (mcpu_cpu_opt != NULL)
20285 mfpu_opt = &fpu_default;
20286 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
20287 mfpu_opt = &fpu_arch_vfp_v2;
20288 else
20289 mfpu_opt = &fpu_arch_fpa;
20290 }
20291
20292 #ifdef CPU_DEFAULT
20293 if (!mcpu_cpu_opt)
20294 {
20295 mcpu_cpu_opt = &cpu_default;
20296 selected_cpu = cpu_default;
20297 }
20298 #else
20299 if (mcpu_cpu_opt)
20300 selected_cpu = *mcpu_cpu_opt;
20301 else
20302 mcpu_cpu_opt = &arm_arch_any;
20303 #endif
20304
20305 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20306
20307 autoselect_thumb_from_cpu_variant ();
20308
20309 arm_arch_used = thumb_arch_used = arm_arch_none;
20310
20311 #if defined OBJ_COFF || defined OBJ_ELF
20312 {
20313 unsigned int flags = 0;
20314
20315 #if defined OBJ_ELF
20316 flags = meabi_flags;
20317
20318 switch (meabi_flags)
20319 {
20320 case EF_ARM_EABI_UNKNOWN:
20321 #endif
20322 /* Set the flags in the private structure. */
20323 if (uses_apcs_26) flags |= F_APCS26;
20324 if (support_interwork) flags |= F_INTERWORK;
20325 if (uses_apcs_float) flags |= F_APCS_FLOAT;
20326 if (pic_code) flags |= F_PIC;
20327 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
20328 flags |= F_SOFT_FLOAT;
20329
20330 switch (mfloat_abi_opt)
20331 {
20332 case ARM_FLOAT_ABI_SOFT:
20333 case ARM_FLOAT_ABI_SOFTFP:
20334 flags |= F_SOFT_FLOAT;
20335 break;
20336
20337 case ARM_FLOAT_ABI_HARD:
20338 if (flags & F_SOFT_FLOAT)
20339 as_bad (_("hard-float conflicts with specified fpu"));
20340 break;
20341 }
20342
20343 /* Using pure-endian doubles (even if soft-float). */
20344 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
20345 flags |= F_VFP_FLOAT;
20346
20347 #if defined OBJ_ELF
20348 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
20349 flags |= EF_ARM_MAVERICK_FLOAT;
20350 break;
20351
20352 case EF_ARM_EABI_VER4:
20353 case EF_ARM_EABI_VER5:
20354 /* No additional flags to set. */
20355 break;
20356
20357 default:
20358 abort ();
20359 }
20360 #endif
20361 bfd_set_private_flags (stdoutput, flags);
20362
20363 /* We have run out flags in the COFF header to encode the
20364 status of ATPCS support, so instead we create a dummy,
20365 empty, debug section called .arm.atpcs. */
20366 if (atpcs)
20367 {
20368 asection * sec;
20369
20370 sec = bfd_make_section (stdoutput, ".arm.atpcs");
20371
20372 if (sec != NULL)
20373 {
20374 bfd_set_section_flags
20375 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
20376 bfd_set_section_size (stdoutput, sec, 0);
20377 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
20378 }
20379 }
20380 }
20381 #endif
20382
20383 /* Record the CPU type as well. */
20384 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
20385 mach = bfd_mach_arm_iWMMXt2;
20386 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
20387 mach = bfd_mach_arm_iWMMXt;
20388 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
20389 mach = bfd_mach_arm_XScale;
20390 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
20391 mach = bfd_mach_arm_ep9312;
20392 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
20393 mach = bfd_mach_arm_5TE;
20394 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
20395 {
20396 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
20397 mach = bfd_mach_arm_5T;
20398 else
20399 mach = bfd_mach_arm_5;
20400 }
20401 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
20402 {
20403 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
20404 mach = bfd_mach_arm_4T;
20405 else
20406 mach = bfd_mach_arm_4;
20407 }
20408 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
20409 mach = bfd_mach_arm_3M;
20410 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
20411 mach = bfd_mach_arm_3;
20412 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
20413 mach = bfd_mach_arm_2a;
20414 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
20415 mach = bfd_mach_arm_2;
20416 else
20417 mach = bfd_mach_arm_unknown;
20418
20419 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
20420 }
20421
20422 /* Command line processing. */
20423
20424 /* md_parse_option
20425 Invocation line includes a switch not recognized by the base assembler.
20426 See if it's a processor-specific option.
20427
20428 This routine is somewhat complicated by the need for backwards
20429 compatibility (since older releases of gcc can't be changed).
20430 The new options try to make the interface as compatible as
20431 possible with GCC.
20432
20433 New options (supported) are:
20434
20435 -mcpu=<cpu name> Assemble for selected processor
20436 -march=<architecture name> Assemble for selected architecture
20437 -mfpu=<fpu architecture> Assemble for selected FPU.
20438 -EB/-mbig-endian Big-endian
20439 -EL/-mlittle-endian Little-endian
20440 -k Generate PIC code
20441 -mthumb Start in Thumb mode
20442 -mthumb-interwork Code supports ARM/Thumb interworking
20443
20444 -m[no-]warn-deprecated Warn about deprecated features
20445
20446 For now we will also provide support for:
20447
20448 -mapcs-32 32-bit Program counter
20449 -mapcs-26 26-bit Program counter
20450 -macps-float Floats passed in FP registers
20451 -mapcs-reentrant Reentrant code
20452 -matpcs
20453 (sometime these will probably be replaced with -mapcs=<list of options>
20454 and -matpcs=<list of options>)
20455
20456 The remaining options are only supported for back-wards compatibility.
20457 Cpu variants, the arm part is optional:
20458 -m[arm]1 Currently not supported.
20459 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
20460 -m[arm]3 Arm 3 processor
20461 -m[arm]6[xx], Arm 6 processors
20462 -m[arm]7[xx][t][[d]m] Arm 7 processors
20463 -m[arm]8[10] Arm 8 processors
20464 -m[arm]9[20][tdmi] Arm 9 processors
20465 -mstrongarm[110[0]] StrongARM processors
20466 -mxscale XScale processors
20467 -m[arm]v[2345[t[e]]] Arm architectures
20468 -mall All (except the ARM1)
20469 FP variants:
20470 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
20471 -mfpe-old (No float load/store multiples)
20472 -mvfpxd VFP Single precision
20473 -mvfp All VFP
20474 -mno-fpu Disable all floating point instructions
20475
20476 The following CPU names are recognized:
20477 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
20478 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
20479 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
20480 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
20481 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
20482 arm10t arm10e, arm1020t, arm1020e, arm10200e,
20483 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
20484
20485 */
20486
20487 const char * md_shortopts = "m:k";
20488
20489 #ifdef ARM_BI_ENDIAN
20490 #define OPTION_EB (OPTION_MD_BASE + 0)
20491 #define OPTION_EL (OPTION_MD_BASE + 1)
20492 #else
20493 #if TARGET_BYTES_BIG_ENDIAN
20494 #define OPTION_EB (OPTION_MD_BASE + 0)
20495 #else
20496 #define OPTION_EL (OPTION_MD_BASE + 1)
20497 #endif
20498 #endif
20499 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
20500
20501 struct option md_longopts[] =
20502 {
20503 #ifdef OPTION_EB
20504 {"EB", no_argument, NULL, OPTION_EB},
20505 #endif
20506 #ifdef OPTION_EL
20507 {"EL", no_argument, NULL, OPTION_EL},
20508 #endif
20509 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
20510 {NULL, no_argument, NULL, 0}
20511 };
20512
20513 size_t md_longopts_size = sizeof (md_longopts);
20514
20515 struct arm_option_table
20516 {
20517 char *option; /* Option name to match. */
20518 char *help; /* Help information. */
20519 int *var; /* Variable to change. */
20520 int value; /* What to change it to. */
20521 char *deprecated; /* If non-null, print this message. */
20522 };
20523
20524 struct arm_option_table arm_opts[] =
20525 {
20526 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
20527 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
20528 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
20529 &support_interwork, 1, NULL},
20530 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
20531 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
20532 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
20533 1, NULL},
20534 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
20535 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
20536 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
20537 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
20538 NULL},
20539
20540 /* These are recognized by the assembler, but have no affect on code. */
20541 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
20542 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
20543
20544 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
20545 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
20546 &warn_on_deprecated, 0, NULL},
20547 {NULL, NULL, NULL, 0, NULL}
20548 };
20549
20550 struct arm_legacy_option_table
20551 {
20552 char *option; /* Option name to match. */
20553 const arm_feature_set **var; /* Variable to change. */
20554 const arm_feature_set value; /* What to change it to. */
20555 char *deprecated; /* If non-null, print this message. */
20556 };
20557
20558 const struct arm_legacy_option_table arm_legacy_opts[] =
20559 {
20560 /* DON'T add any new processors to this list -- we want the whole list
20561 to go away... Add them to the processors table instead. */
20562 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20563 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20564 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20565 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20566 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20567 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20568 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20569 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20570 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20571 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20572 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20573 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20574 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20575 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20576 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20577 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20578 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20579 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20580 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20581 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20582 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20583 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20584 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20585 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20586 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20587 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20588 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20589 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20590 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20591 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20592 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20593 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20594 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20595 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20596 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20597 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20598 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20599 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20600 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20601 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20602 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20603 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20604 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20605 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20606 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20607 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20608 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20609 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20610 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20611 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20612 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20613 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20614 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20615 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20616 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20617 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20618 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20619 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20620 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20621 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20622 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20623 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20624 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20625 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20626 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20627 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20628 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20629 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20630 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
20631 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
20632 N_("use -mcpu=strongarm110")},
20633 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
20634 N_("use -mcpu=strongarm1100")},
20635 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
20636 N_("use -mcpu=strongarm1110")},
20637 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
20638 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
20639 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
20640
20641 /* Architecture variants -- don't add any more to this list either. */
20642 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20643 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20644 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20645 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20646 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20647 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20648 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20649 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20650 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20651 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20652 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20653 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20654 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20655 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20656 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20657 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20658 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20659 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20660
20661 /* Floating point variants -- don't add any more to this list either. */
20662 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20663 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20664 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20665 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
20666 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
20667
20668 {NULL, NULL, ARM_ARCH_NONE, NULL}
20669 };
20670
20671 struct arm_cpu_option_table
20672 {
20673 char *name;
20674 const arm_feature_set value;
20675 /* For some CPUs we assume an FPU unless the user explicitly sets
20676 -mfpu=... */
20677 const arm_feature_set default_fpu;
20678 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20679 case. */
20680 const char *canonical_name;
20681 };
20682
20683 /* This list should, at a minimum, contain all the cpu names
20684 recognized by GCC. */
20685 static const struct arm_cpu_option_table arm_cpus[] =
20686 {
20687 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20688 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20689 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20690 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20691 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20692 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20693 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20694 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20695 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20696 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20697 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20698 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20699 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20700 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20701 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20702 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20703 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20704 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20705 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20706 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20707 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20708 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20709 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20710 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20711 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20712 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20713 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20714 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20715 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20716 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20717 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20718 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20719 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20720 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20721 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20722 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20723 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20724 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20725 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20726 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20727 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20728 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20729 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20730 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20731 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20732 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20733 /* For V5 or later processors we default to using VFP; but the user
20734 should really set the FPU type explicitly. */
20735 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20736 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20737 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20738 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20739 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20740 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20741 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20742 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20743 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20744 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20745 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20746 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20747 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20748 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20749 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20750 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20751 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20752 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20753 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20754 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20755 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20756 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
20757 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20758 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20759 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20760 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20761 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20762 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20763 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20764 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20765 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20766 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20767 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
20768 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20769 | FPU_NEON_EXT_V1),
20770 NULL},
20771 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20772 | FPU_NEON_EXT_V1),
20773 NULL},
20774 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20775 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
20776 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
20777 /* ??? XSCALE is really an architecture. */
20778 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20779 /* ??? iwmmxt is not a processor. */
20780 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
20781 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
20782 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
20783 /* Maverick */
20784 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20785 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
20786 };
20787
20788 struct arm_arch_option_table
20789 {
20790 char *name;
20791 const arm_feature_set value;
20792 const arm_feature_set default_fpu;
20793 };
20794
20795 /* This list should, at a minimum, contain all the architecture names
20796 recognized by GCC. */
20797 static const struct arm_arch_option_table arm_archs[] =
20798 {
20799 {"all", ARM_ANY, FPU_ARCH_FPA},
20800 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20801 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20802 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20803 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20804 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20805 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20806 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20807 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20808 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20809 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20810 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20811 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20812 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20813 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20814 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20815 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20816 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20817 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20818 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20819 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20820 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20821 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20822 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20823 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20824 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
20825 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
20826 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
20827 /* The official spelling of the ARMv7 profile variants is the dashed form.
20828 Accept the non-dashed form for compatibility with old toolchains. */
20829 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20830 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20831 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20832 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20833 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20834 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
20835 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20836 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
20837 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
20838 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
20839 };
20840
20841 /* ISA extensions in the co-processor space. */
20842 struct arm_option_cpu_value_table
20843 {
20844 char *name;
20845 const arm_feature_set value;
20846 };
20847
20848 static const struct arm_option_cpu_value_table arm_extensions[] =
20849 {
20850 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20851 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20852 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
20853 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
20854 {NULL, ARM_ARCH_NONE}
20855 };
20856
20857 /* This list should, at a minimum, contain all the fpu names
20858 recognized by GCC. */
20859 static const struct arm_option_cpu_value_table arm_fpus[] =
20860 {
20861 {"softfpa", FPU_NONE},
20862 {"fpe", FPU_ARCH_FPE},
20863 {"fpe2", FPU_ARCH_FPE},
20864 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20865 {"fpa", FPU_ARCH_FPA},
20866 {"fpa10", FPU_ARCH_FPA},
20867 {"fpa11", FPU_ARCH_FPA},
20868 {"arm7500fe", FPU_ARCH_FPA},
20869 {"softvfp", FPU_ARCH_VFP},
20870 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20871 {"vfp", FPU_ARCH_VFP_V2},
20872 {"vfp9", FPU_ARCH_VFP_V2},
20873 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
20874 {"vfp10", FPU_ARCH_VFP_V2},
20875 {"vfp10-r0", FPU_ARCH_VFP_V1},
20876 {"vfpxd", FPU_ARCH_VFP_V1xD},
20877 {"vfpv2", FPU_ARCH_VFP_V2},
20878 {"vfpv3", FPU_ARCH_VFP_V3},
20879 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
20880 {"arm1020t", FPU_ARCH_VFP_V1},
20881 {"arm1020e", FPU_ARCH_VFP_V2},
20882 {"arm1136jfs", FPU_ARCH_VFP_V2},
20883 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20884 {"maverick", FPU_ARCH_MAVERICK},
20885 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
20886 {"neon-fp16", FPU_ARCH_NEON_FP16},
20887 {NULL, ARM_ARCH_NONE}
20888 };
20889
20890 struct arm_option_value_table
20891 {
20892 char *name;
20893 long value;
20894 };
20895
20896 static const struct arm_option_value_table arm_float_abis[] =
20897 {
20898 {"hard", ARM_FLOAT_ABI_HARD},
20899 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20900 {"soft", ARM_FLOAT_ABI_SOFT},
20901 {NULL, 0}
20902 };
20903
20904 #ifdef OBJ_ELF
20905 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
20906 static const struct arm_option_value_table arm_eabis[] =
20907 {
20908 {"gnu", EF_ARM_EABI_UNKNOWN},
20909 {"4", EF_ARM_EABI_VER4},
20910 {"5", EF_ARM_EABI_VER5},
20911 {NULL, 0}
20912 };
20913 #endif
20914
20915 struct arm_long_option_table
20916 {
20917 char * option; /* Substring to match. */
20918 char * help; /* Help information. */
20919 int (* func) (char * subopt); /* Function to decode sub-option. */
20920 char * deprecated; /* If non-null, print this message. */
20921 };
20922
20923 static int
20924 arm_parse_extension (char * str, const arm_feature_set **opt_p)
20925 {
20926 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20927
20928 /* Copy the feature set, so that we can modify it. */
20929 *ext_set = **opt_p;
20930 *opt_p = ext_set;
20931
20932 while (str != NULL && *str != 0)
20933 {
20934 const struct arm_option_cpu_value_table * opt;
20935 char * ext;
20936 int optlen;
20937
20938 if (*str != '+')
20939 {
20940 as_bad (_("invalid architectural extension"));
20941 return 0;
20942 }
20943
20944 str++;
20945 ext = strchr (str, '+');
20946
20947 if (ext != NULL)
20948 optlen = ext - str;
20949 else
20950 optlen = strlen (str);
20951
20952 if (optlen == 0)
20953 {
20954 as_bad (_("missing architectural extension"));
20955 return 0;
20956 }
20957
20958 for (opt = arm_extensions; opt->name != NULL; opt++)
20959 if (strncmp (opt->name, str, optlen) == 0)
20960 {
20961 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
20962 break;
20963 }
20964
20965 if (opt->name == NULL)
20966 {
20967 as_bad (_("unknown architectural extension `%s'"), str);
20968 return 0;
20969 }
20970
20971 str = ext;
20972 };
20973
20974 return 1;
20975 }
20976
20977 static int
20978 arm_parse_cpu (char * str)
20979 {
20980 const struct arm_cpu_option_table * opt;
20981 char * ext = strchr (str, '+');
20982 int optlen;
20983
20984 if (ext != NULL)
20985 optlen = ext - str;
20986 else
20987 optlen = strlen (str);
20988
20989 if (optlen == 0)
20990 {
20991 as_bad (_("missing cpu name `%s'"), str);
20992 return 0;
20993 }
20994
20995 for (opt = arm_cpus; opt->name != NULL; opt++)
20996 if (strncmp (opt->name, str, optlen) == 0)
20997 {
20998 mcpu_cpu_opt = &opt->value;
20999 mcpu_fpu_opt = &opt->default_fpu;
21000 if (opt->canonical_name)
21001 strcpy (selected_cpu_name, opt->canonical_name);
21002 else
21003 {
21004 int i;
21005 for (i = 0; i < optlen; i++)
21006 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21007 selected_cpu_name[i] = 0;
21008 }
21009
21010 if (ext != NULL)
21011 return arm_parse_extension (ext, &mcpu_cpu_opt);
21012
21013 return 1;
21014 }
21015
21016 as_bad (_("unknown cpu `%s'"), str);
21017 return 0;
21018 }
21019
21020 static int
21021 arm_parse_arch (char * str)
21022 {
21023 const struct arm_arch_option_table *opt;
21024 char *ext = strchr (str, '+');
21025 int optlen;
21026
21027 if (ext != NULL)
21028 optlen = ext - str;
21029 else
21030 optlen = strlen (str);
21031
21032 if (optlen == 0)
21033 {
21034 as_bad (_("missing architecture name `%s'"), str);
21035 return 0;
21036 }
21037
21038 for (opt = arm_archs; opt->name != NULL; opt++)
21039 if (streq (opt->name, str))
21040 {
21041 march_cpu_opt = &opt->value;
21042 march_fpu_opt = &opt->default_fpu;
21043 strcpy (selected_cpu_name, opt->name);
21044
21045 if (ext != NULL)
21046 return arm_parse_extension (ext, &march_cpu_opt);
21047
21048 return 1;
21049 }
21050
21051 as_bad (_("unknown architecture `%s'\n"), str);
21052 return 0;
21053 }
21054
21055 static int
21056 arm_parse_fpu (char * str)
21057 {
21058 const struct arm_option_cpu_value_table * opt;
21059
21060 for (opt = arm_fpus; opt->name != NULL; opt++)
21061 if (streq (opt->name, str))
21062 {
21063 mfpu_opt = &opt->value;
21064 return 1;
21065 }
21066
21067 as_bad (_("unknown floating point format `%s'\n"), str);
21068 return 0;
21069 }
21070
21071 static int
21072 arm_parse_float_abi (char * str)
21073 {
21074 const struct arm_option_value_table * opt;
21075
21076 for (opt = arm_float_abis; opt->name != NULL; opt++)
21077 if (streq (opt->name, str))
21078 {
21079 mfloat_abi_opt = opt->value;
21080 return 1;
21081 }
21082
21083 as_bad (_("unknown floating point abi `%s'\n"), str);
21084 return 0;
21085 }
21086
21087 #ifdef OBJ_ELF
21088 static int
21089 arm_parse_eabi (char * str)
21090 {
21091 const struct arm_option_value_table *opt;
21092
21093 for (opt = arm_eabis; opt->name != NULL; opt++)
21094 if (streq (opt->name, str))
21095 {
21096 meabi_flags = opt->value;
21097 return 1;
21098 }
21099 as_bad (_("unknown EABI `%s'\n"), str);
21100 return 0;
21101 }
21102 #endif
21103
21104 struct arm_long_option_table arm_long_opts[] =
21105 {
21106 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
21107 arm_parse_cpu, NULL},
21108 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
21109 arm_parse_arch, NULL},
21110 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
21111 arm_parse_fpu, NULL},
21112 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
21113 arm_parse_float_abi, NULL},
21114 #ifdef OBJ_ELF
21115 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
21116 arm_parse_eabi, NULL},
21117 #endif
21118 {NULL, NULL, 0, NULL}
21119 };
21120
21121 int
21122 md_parse_option (int c, char * arg)
21123 {
21124 struct arm_option_table *opt;
21125 const struct arm_legacy_option_table *fopt;
21126 struct arm_long_option_table *lopt;
21127
21128 switch (c)
21129 {
21130 #ifdef OPTION_EB
21131 case OPTION_EB:
21132 target_big_endian = 1;
21133 break;
21134 #endif
21135
21136 #ifdef OPTION_EL
21137 case OPTION_EL:
21138 target_big_endian = 0;
21139 break;
21140 #endif
21141
21142 case OPTION_FIX_V4BX:
21143 fix_v4bx = TRUE;
21144 break;
21145
21146 case 'a':
21147 /* Listing option. Just ignore these, we don't support additional
21148 ones. */
21149 return 0;
21150
21151 default:
21152 for (opt = arm_opts; opt->option != NULL; opt++)
21153 {
21154 if (c == opt->option[0]
21155 && ((arg == NULL && opt->option[1] == 0)
21156 || streq (arg, opt->option + 1)))
21157 {
21158 /* If the option is deprecated, tell the user. */
21159 if (warn_on_deprecated && opt->deprecated != NULL)
21160 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21161 arg ? arg : "", _(opt->deprecated));
21162
21163 if (opt->var != NULL)
21164 *opt->var = opt->value;
21165
21166 return 1;
21167 }
21168 }
21169
21170 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
21171 {
21172 if (c == fopt->option[0]
21173 && ((arg == NULL && fopt->option[1] == 0)
21174 || streq (arg, fopt->option + 1)))
21175 {
21176 /* If the option is deprecated, tell the user. */
21177 if (warn_on_deprecated && fopt->deprecated != NULL)
21178 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21179 arg ? arg : "", _(fopt->deprecated));
21180
21181 if (fopt->var != NULL)
21182 *fopt->var = &fopt->value;
21183
21184 return 1;
21185 }
21186 }
21187
21188 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21189 {
21190 /* These options are expected to have an argument. */
21191 if (c == lopt->option[0]
21192 && arg != NULL
21193 && strncmp (arg, lopt->option + 1,
21194 strlen (lopt->option + 1)) == 0)
21195 {
21196 /* If the option is deprecated, tell the user. */
21197 if (warn_on_deprecated && lopt->deprecated != NULL)
21198 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
21199 _(lopt->deprecated));
21200
21201 /* Call the sup-option parser. */
21202 return lopt->func (arg + strlen (lopt->option) - 1);
21203 }
21204 }
21205
21206 return 0;
21207 }
21208
21209 return 1;
21210 }
21211
21212 void
21213 md_show_usage (FILE * fp)
21214 {
21215 struct arm_option_table *opt;
21216 struct arm_long_option_table *lopt;
21217
21218 fprintf (fp, _(" ARM-specific assembler options:\n"));
21219
21220 for (opt = arm_opts; opt->option != NULL; opt++)
21221 if (opt->help != NULL)
21222 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
21223
21224 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21225 if (lopt->help != NULL)
21226 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
21227
21228 #ifdef OPTION_EB
21229 fprintf (fp, _("\
21230 -EB assemble code for a big-endian cpu\n"));
21231 #endif
21232
21233 #ifdef OPTION_EL
21234 fprintf (fp, _("\
21235 -EL assemble code for a little-endian cpu\n"));
21236 #endif
21237
21238 fprintf (fp, _("\
21239 --fix-v4bx Allow BX in ARMv4 code\n"));
21240 }
21241
21242
21243 #ifdef OBJ_ELF
21244 typedef struct
21245 {
21246 int val;
21247 arm_feature_set flags;
21248 } cpu_arch_ver_table;
21249
21250 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
21251 least features first. */
21252 static const cpu_arch_ver_table cpu_arch_ver[] =
21253 {
21254 {1, ARM_ARCH_V4},
21255 {2, ARM_ARCH_V4T},
21256 {3, ARM_ARCH_V5},
21257 {3, ARM_ARCH_V5T},
21258 {4, ARM_ARCH_V5TE},
21259 {5, ARM_ARCH_V5TEJ},
21260 {6, ARM_ARCH_V6},
21261 {7, ARM_ARCH_V6Z},
21262 {9, ARM_ARCH_V6K},
21263 {11, ARM_ARCH_V6M},
21264 {8, ARM_ARCH_V6T2},
21265 {10, ARM_ARCH_V7A},
21266 {10, ARM_ARCH_V7R},
21267 {10, ARM_ARCH_V7M},
21268 {0, ARM_ARCH_NONE}
21269 };
21270
21271 /* Set an attribute if it has not already been set by the user. */
21272 static void
21273 aeabi_set_attribute_int (int tag, int value)
21274 {
21275 if (tag < 1
21276 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21277 || !attributes_set_explicitly[tag])
21278 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
21279 }
21280
21281 static void
21282 aeabi_set_attribute_string (int tag, const char *value)
21283 {
21284 if (tag < 1
21285 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21286 || !attributes_set_explicitly[tag])
21287 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
21288 }
21289
21290 /* Set the public EABI object attributes. */
21291 static void
21292 aeabi_set_public_attributes (void)
21293 {
21294 int arch;
21295 arm_feature_set flags;
21296 arm_feature_set tmp;
21297 const cpu_arch_ver_table *p;
21298
21299 /* Choose the architecture based on the capabilities of the requested cpu
21300 (if any) and/or the instructions actually used. */
21301 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
21302 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
21303 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
21304 /*Allow the user to override the reported architecture. */
21305 if (object_arch)
21306 {
21307 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
21308 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
21309 }
21310
21311 tmp = flags;
21312 arch = 0;
21313 for (p = cpu_arch_ver; p->val; p++)
21314 {
21315 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
21316 {
21317 arch = p->val;
21318 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
21319 }
21320 }
21321
21322 /* Tag_CPU_name. */
21323 if (selected_cpu_name[0])
21324 {
21325 char *p;
21326
21327 p = selected_cpu_name;
21328 if (strncmp (p, "armv", 4) == 0)
21329 {
21330 int i;
21331
21332 p += 4;
21333 for (i = 0; p[i]; i++)
21334 p[i] = TOUPPER (p[i]);
21335 }
21336 aeabi_set_attribute_string (Tag_CPU_name, p);
21337 }
21338 /* Tag_CPU_arch. */
21339 aeabi_set_attribute_int (Tag_CPU_arch, arch);
21340 /* Tag_CPU_arch_profile. */
21341 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
21342 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
21343 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
21344 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
21345 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
21346 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
21347 /* Tag_ARM_ISA_use. */
21348 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
21349 || arch == 0)
21350 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
21351 /* Tag_THUMB_ISA_use. */
21352 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
21353 || arch == 0)
21354 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
21355 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
21356 /* Tag_VFP_arch. */
21357 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
21358 aeabi_set_attribute_int (Tag_VFP_arch, 3);
21359 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3))
21360 aeabi_set_attribute_int (Tag_VFP_arch, 4);
21361 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
21362 aeabi_set_attribute_int (Tag_VFP_arch, 2);
21363 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
21364 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
21365 aeabi_set_attribute_int (Tag_VFP_arch, 1);
21366 /* Tag_WMMX_arch. */
21367 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
21368 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
21369 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
21370 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
21371 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
21372 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
21373 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
21374 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
21375 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16))
21376 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
21377 }
21378
21379 /* Add the default contents for the .ARM.attributes section. */
21380 void
21381 arm_md_end (void)
21382 {
21383 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21384 return;
21385
21386 aeabi_set_public_attributes ();
21387 }
21388 #endif /* OBJ_ELF */
21389
21390
21391 /* Parse a .cpu directive. */
21392
21393 static void
21394 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
21395 {
21396 const struct arm_cpu_option_table *opt;
21397 char *name;
21398 char saved_char;
21399
21400 name = input_line_pointer;
21401 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
21402 input_line_pointer++;
21403 saved_char = *input_line_pointer;
21404 *input_line_pointer = 0;
21405
21406 /* Skip the first "all" entry. */
21407 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
21408 if (streq (opt->name, name))
21409 {
21410 mcpu_cpu_opt = &opt->value;
21411 selected_cpu = opt->value;
21412 if (opt->canonical_name)
21413 strcpy (selected_cpu_name, opt->canonical_name);
21414 else
21415 {
21416 int i;
21417 for (i = 0; opt->name[i]; i++)
21418 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21419 selected_cpu_name[i] = 0;
21420 }
21421 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21422 *input_line_pointer = saved_char;
21423 demand_empty_rest_of_line ();
21424 return;
21425 }
21426 as_bad (_("unknown cpu `%s'"), name);
21427 *input_line_pointer = saved_char;
21428 ignore_rest_of_line ();
21429 }
21430
21431
21432 /* Parse a .arch directive. */
21433
21434 static void
21435 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
21436 {
21437 const struct arm_arch_option_table *opt;
21438 char saved_char;
21439 char *name;
21440
21441 name = input_line_pointer;
21442 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
21443 input_line_pointer++;
21444 saved_char = *input_line_pointer;
21445 *input_line_pointer = 0;
21446
21447 /* Skip the first "all" entry. */
21448 for (opt = arm_archs + 1; opt->name != NULL; opt++)
21449 if (streq (opt->name, name))
21450 {
21451 mcpu_cpu_opt = &opt->value;
21452 selected_cpu = opt->value;
21453 strcpy (selected_cpu_name, opt->name);
21454 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21455 *input_line_pointer = saved_char;
21456 demand_empty_rest_of_line ();
21457 return;
21458 }
21459
21460 as_bad (_("unknown architecture `%s'\n"), name);
21461 *input_line_pointer = saved_char;
21462 ignore_rest_of_line ();
21463 }
21464
21465
21466 /* Parse a .object_arch directive. */
21467
21468 static void
21469 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
21470 {
21471 const struct arm_arch_option_table *opt;
21472 char saved_char;
21473 char *name;
21474
21475 name = input_line_pointer;
21476 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
21477 input_line_pointer++;
21478 saved_char = *input_line_pointer;
21479 *input_line_pointer = 0;
21480
21481 /* Skip the first "all" entry. */
21482 for (opt = arm_archs + 1; opt->name != NULL; opt++)
21483 if (streq (opt->name, name))
21484 {
21485 object_arch = &opt->value;
21486 *input_line_pointer = saved_char;
21487 demand_empty_rest_of_line ();
21488 return;
21489 }
21490
21491 as_bad (_("unknown architecture `%s'\n"), name);
21492 *input_line_pointer = saved_char;
21493 ignore_rest_of_line ();
21494 }
21495
21496 /* Parse a .fpu directive. */
21497
21498 static void
21499 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
21500 {
21501 const struct arm_option_cpu_value_table *opt;
21502 char saved_char;
21503 char *name;
21504
21505 name = input_line_pointer;
21506 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
21507 input_line_pointer++;
21508 saved_char = *input_line_pointer;
21509 *input_line_pointer = 0;
21510
21511 for (opt = arm_fpus; opt->name != NULL; opt++)
21512 if (streq (opt->name, name))
21513 {
21514 mfpu_opt = &opt->value;
21515 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21516 *input_line_pointer = saved_char;
21517 demand_empty_rest_of_line ();
21518 return;
21519 }
21520
21521 as_bad (_("unknown floating point format `%s'\n"), name);
21522 *input_line_pointer = saved_char;
21523 ignore_rest_of_line ();
21524 }
21525
21526 /* Copy symbol information. */
21527
21528 void
21529 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
21530 {
21531 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
21532 }
21533
21534 #ifdef OBJ_ELF
21535 /* Given a symbolic attribute NAME, return the proper integer value.
21536 Returns -1 if the attribute is not known. */
21537
21538 int
21539 arm_convert_symbolic_attribute (const char *name)
21540 {
21541 static const struct
21542 {
21543 const char * name;
21544 const int tag;
21545 }
21546 attribute_table[] =
21547 {
21548 /* When you modify this table you should
21549 also modify the list in doc/c-arm.texi. */
21550 #define T(tag) {#tag, tag}
21551 T (Tag_CPU_raw_name),
21552 T (Tag_CPU_name),
21553 T (Tag_CPU_arch),
21554 T (Tag_CPU_arch_profile),
21555 T (Tag_ARM_ISA_use),
21556 T (Tag_THUMB_ISA_use),
21557 T (Tag_VFP_arch),
21558 T (Tag_WMMX_arch),
21559 T (Tag_Advanced_SIMD_arch),
21560 T (Tag_PCS_config),
21561 T (Tag_ABI_PCS_R9_use),
21562 T (Tag_ABI_PCS_RW_data),
21563 T (Tag_ABI_PCS_RO_data),
21564 T (Tag_ABI_PCS_GOT_use),
21565 T (Tag_ABI_PCS_wchar_t),
21566 T (Tag_ABI_FP_rounding),
21567 T (Tag_ABI_FP_denormal),
21568 T (Tag_ABI_FP_exceptions),
21569 T (Tag_ABI_FP_user_exceptions),
21570 T (Tag_ABI_FP_number_model),
21571 T (Tag_ABI_align8_needed),
21572 T (Tag_ABI_align8_preserved),
21573 T (Tag_ABI_enum_size),
21574 T (Tag_ABI_HardFP_use),
21575 T (Tag_ABI_VFP_args),
21576 T (Tag_ABI_WMMX_args),
21577 T (Tag_ABI_optimization_goals),
21578 T (Tag_ABI_FP_optimization_goals),
21579 T (Tag_compatibility),
21580 T (Tag_CPU_unaligned_access),
21581 T (Tag_VFP_HP_extension),
21582 T (Tag_ABI_FP_16bit_format),
21583 T (Tag_nodefaults),
21584 T (Tag_also_compatible_with),
21585 T (Tag_conformance),
21586 T (Tag_T2EE_use),
21587 T (Tag_Virtualization_use),
21588 T (Tag_MPextension_use)
21589 #undef T
21590 };
21591 unsigned int i;
21592
21593 if (name == NULL)
21594 return -1;
21595
21596 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
21597 if (strcmp (name, attribute_table[i].name) == 0)
21598 return attribute_table[i].tag;
21599
21600 return -1;
21601 }
21602 #endif /* OBJ_ELF */