* bfd/elf32-arm.c (elf32_arm_merge_eabi_attributes): Add support for
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
27
28 #include "as.h"
29 #include <limits.h>
30 #include <stdarg.h>
31 #define NO_RELOC 0
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
35
36 #include "opcode/arm.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
42
43 #include "dwarf2dbg.h"
44
45 #ifdef OBJ_ELF
46 /* Must be at least the size of the largest unwind opcode (currently two). */
47 #define ARM_OPCODE_CHUNK_SIZE 8
48
49 /* This structure holds the unwinding state. */
50
51 static struct
52 {
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
57 /* The segment containing the function. */
58 segT saved_seg;
59 subsegT saved_subseg;
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
62 int opcode_count;
63 int opcode_alloc;
64 /* The number of bytes pushed to the stack. */
65 offsetT frame_size;
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
69 offsetT pending_offset;
70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
74 /* Nonzero if an unwind_setfp directive has been seen. */
75 unsigned fp_used:1;
76 /* Nonzero if the last opcode restores sp from fp_reg. */
77 unsigned sp_restored:1;
78 } unwind;
79
80 #endif /* OBJ_ELF */
81
82 /* Results from operand parsing worker functions. */
83
84 typedef enum
85 {
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89 } parse_operand_result;
90
91 enum arm_float_abi
92 {
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96 };
97
98 /* Types of processor to assemble for. */
99 #ifndef CPU_DEFAULT
100 #if defined __XSCALE__
101 #define CPU_DEFAULT ARM_ARCH_XSCALE
102 #else
103 #if defined __thumb__
104 #define CPU_DEFAULT ARM_ARCH_V5T
105 #endif
106 #endif
107 #endif
108
109 #ifndef FPU_DEFAULT
110 # ifdef TE_LINUX
111 # define FPU_DEFAULT FPU_ARCH_FPA
112 # elif defined (TE_NetBSD)
113 # ifdef OBJ_ELF
114 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115 # else
116 /* Legacy a.out format. */
117 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118 # endif
119 # elif defined (TE_VXWORKS)
120 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
121 # else
122 /* For backwards compatibility, default to FPA. */
123 # define FPU_DEFAULT FPU_ARCH_FPA
124 # endif
125 #endif /* ifndef FPU_DEFAULT */
126
127 #define streq(a, b) (strcmp (a, b) == 0)
128
129 static arm_feature_set cpu_variant;
130 static arm_feature_set arm_arch_used;
131 static arm_feature_set thumb_arch_used;
132
133 /* Flags stored in private area of BFD structure. */
134 static int uses_apcs_26 = FALSE;
135 static int atpcs = FALSE;
136 static int support_interwork = FALSE;
137 static int uses_apcs_float = FALSE;
138 static int pic_code = FALSE;
139 static int fix_v4bx = FALSE;
140 /* Warn on using deprecated features. */
141 static int warn_on_deprecated = TRUE;
142
143
144 /* Variables that we set while parsing command-line options. Once all
145 options have been read we re-process these values to set the real
146 assembly flags. */
147 static const arm_feature_set *legacy_cpu = NULL;
148 static const arm_feature_set *legacy_fpu = NULL;
149
150 static const arm_feature_set *mcpu_cpu_opt = NULL;
151 static const arm_feature_set *mcpu_fpu_opt = NULL;
152 static const arm_feature_set *march_cpu_opt = NULL;
153 static const arm_feature_set *march_fpu_opt = NULL;
154 static const arm_feature_set *mfpu_opt = NULL;
155 static const arm_feature_set *object_arch = NULL;
156
157 /* Constants for known architecture features. */
158 static const arm_feature_set fpu_default = FPU_DEFAULT;
159 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
160 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
161 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
162 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
163 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
164 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
165 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
166 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
167
168 #ifdef CPU_DEFAULT
169 static const arm_feature_set cpu_default = CPU_DEFAULT;
170 #endif
171
172 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
173 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
174 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
175 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
176 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
177 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
178 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
179 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
180 static const arm_feature_set arm_ext_v4t_5 =
181 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
182 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
183 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
184 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
185 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
186 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
187 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
188 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
189 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
190 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
191 static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
192 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
193 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
194 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
195 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
196 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
197 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
198 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
199 static const arm_feature_set arm_ext_m =
200 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
201
202 static const arm_feature_set arm_arch_any = ARM_ANY;
203 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
204 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
205 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
206
207 static const arm_feature_set arm_cext_iwmmxt2 =
208 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
209 static const arm_feature_set arm_cext_iwmmxt =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
211 static const arm_feature_set arm_cext_xscale =
212 ARM_FEATURE (0, ARM_CEXT_XSCALE);
213 static const arm_feature_set arm_cext_maverick =
214 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
215 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
216 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
217 static const arm_feature_set fpu_vfp_ext_v1xd =
218 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
219 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
220 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
221 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
222 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
223 static const arm_feature_set fpu_vfp_ext_d32 =
224 ARM_FEATURE (0, FPU_VFP_EXT_D32);
225 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
226 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
227 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
228 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
229 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
230 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
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 /* Specifies the intrinsic IT insn behavior mode. */
269 enum implicit_it_mode
270 {
271 IMPLICIT_IT_MODE_NEVER = 0x00,
272 IMPLICIT_IT_MODE_ARM = 0x01,
273 IMPLICIT_IT_MODE_THUMB = 0x02,
274 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
275 };
276 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
277
278 /* If unified_syntax is true, we are processing the new unified
279 ARM/Thumb syntax. Important differences from the old ARM mode:
280
281 - Immediate operands do not require a # prefix.
282 - Conditional affixes always appear at the end of the
283 instruction. (For backward compatibility, those instructions
284 that formerly had them in the middle, continue to accept them
285 there.)
286 - The IT instruction may appear, and if it does is validated
287 against subsequent conditional affixes. It does not generate
288 machine code.
289
290 Important differences from the old Thumb mode:
291
292 - Immediate operands do not require a # prefix.
293 - Most of the V6T2 instructions are only available in unified mode.
294 - The .N and .W suffixes are recognized and honored (it is an error
295 if they cannot be honored).
296 - All instructions set the flags if and only if they have an 's' affix.
297 - Conditional affixes may be used. They are validated against
298 preceding IT instructions. Unlike ARM mode, you cannot use a
299 conditional affix except in the scope of an IT instruction. */
300
301 static bfd_boolean unified_syntax = FALSE;
302
303 enum neon_el_type
304 {
305 NT_invtype,
306 NT_untyped,
307 NT_integer,
308 NT_float,
309 NT_poly,
310 NT_signed,
311 NT_unsigned
312 };
313
314 struct neon_type_el
315 {
316 enum neon_el_type type;
317 unsigned size;
318 };
319
320 #define NEON_MAX_TYPE_ELS 4
321
322 struct neon_type
323 {
324 struct neon_type_el el[NEON_MAX_TYPE_ELS];
325 unsigned elems;
326 };
327
328 enum it_instruction_type
329 {
330 OUTSIDE_IT_INSN,
331 INSIDE_IT_INSN,
332 INSIDE_IT_LAST_INSN,
333 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
334 if inside, should be the last one. */
335 NEUTRAL_IT_INSN, /* This could be either inside or outside,
336 i.e. BKPT and NOP. */
337 IT_INSN /* The IT insn has been parsed. */
338 };
339
340 struct arm_it
341 {
342 const char * error;
343 unsigned long instruction;
344 int size;
345 int size_req;
346 int cond;
347 /* "uncond_value" is set to the value in place of the conditional field in
348 unconditional versions of the instruction, or -1 if nothing is
349 appropriate. */
350 int uncond_value;
351 struct neon_type vectype;
352 /* This does not indicate an actual NEON instruction, only that
353 the mnemonic accepts neon-style type suffixes. */
354 int is_neon;
355 /* Set to the opcode if the instruction needs relaxation.
356 Zero if the instruction is not relaxed. */
357 unsigned long relax;
358 struct
359 {
360 bfd_reloc_code_real_type type;
361 expressionS exp;
362 int pc_rel;
363 } reloc;
364
365 enum it_instruction_type it_insn_type;
366
367 struct
368 {
369 unsigned reg;
370 signed int imm;
371 struct neon_type_el vectype;
372 unsigned present : 1; /* Operand present. */
373 unsigned isreg : 1; /* Operand was a register. */
374 unsigned immisreg : 1; /* .imm field is a second register. */
375 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
376 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
377 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
378 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
379 instructions. This allows us to disambiguate ARM <-> vector insns. */
380 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
381 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
382 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
383 unsigned issingle : 1; /* Operand is VFP single-precision register. */
384 unsigned hasreloc : 1; /* Operand has relocation suffix. */
385 unsigned writeback : 1; /* Operand has trailing ! */
386 unsigned preind : 1; /* Preindexed address. */
387 unsigned postind : 1; /* Postindexed address. */
388 unsigned negative : 1; /* Index register was negated. */
389 unsigned shifted : 1; /* Shift applied to operation. */
390 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
391 } operands[6];
392 };
393
394 static struct arm_it inst;
395
396 #define NUM_FLOAT_VALS 8
397
398 const char * fp_const[] =
399 {
400 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
401 };
402
403 /* Number of littlenums required to hold an extended precision number. */
404 #define MAX_LITTLENUMS 6
405
406 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
407
408 #define FAIL (-1)
409 #define SUCCESS (0)
410
411 #define SUFF_S 1
412 #define SUFF_D 2
413 #define SUFF_E 3
414 #define SUFF_P 4
415
416 #define CP_T_X 0x00008000
417 #define CP_T_Y 0x00400000
418
419 #define CONDS_BIT 0x00100000
420 #define LOAD_BIT 0x00100000
421
422 #define DOUBLE_LOAD_FLAG 0x00000001
423
424 struct asm_cond
425 {
426 const char * template_name;
427 unsigned long value;
428 };
429
430 #define COND_ALWAYS 0xE
431
432 struct asm_psr
433 {
434 const char * template_name;
435 unsigned long field;
436 };
437
438 struct asm_barrier_opt
439 {
440 const char * template_name;
441 unsigned long value;
442 };
443
444 /* The bit that distinguishes CPSR and SPSR. */
445 #define SPSR_BIT (1 << 22)
446
447 /* The individual PSR flag bits. */
448 #define PSR_c (1 << 16)
449 #define PSR_x (1 << 17)
450 #define PSR_s (1 << 18)
451 #define PSR_f (1 << 19)
452
453 struct reloc_entry
454 {
455 char * name;
456 bfd_reloc_code_real_type reloc;
457 };
458
459 enum vfp_reg_pos
460 {
461 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
462 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
463 };
464
465 enum vfp_ldstm_type
466 {
467 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
468 };
469
470 /* Bits for DEFINED field in neon_typed_alias. */
471 #define NTA_HASTYPE 1
472 #define NTA_HASINDEX 2
473
474 struct neon_typed_alias
475 {
476 unsigned char defined;
477 unsigned char index;
478 struct neon_type_el eltype;
479 };
480
481 /* ARM register categories. This includes coprocessor numbers and various
482 architecture extensions' registers. */
483 enum arm_reg_type
484 {
485 REG_TYPE_RN,
486 REG_TYPE_CP,
487 REG_TYPE_CN,
488 REG_TYPE_FN,
489 REG_TYPE_VFS,
490 REG_TYPE_VFD,
491 REG_TYPE_NQ,
492 REG_TYPE_VFSD,
493 REG_TYPE_NDQ,
494 REG_TYPE_NSDQ,
495 REG_TYPE_VFC,
496 REG_TYPE_MVF,
497 REG_TYPE_MVD,
498 REG_TYPE_MVFX,
499 REG_TYPE_MVDX,
500 REG_TYPE_MVAX,
501 REG_TYPE_DSPSC,
502 REG_TYPE_MMXWR,
503 REG_TYPE_MMXWC,
504 REG_TYPE_MMXWCG,
505 REG_TYPE_XSCALE,
506 };
507
508 /* Structure for a hash table entry for a register.
509 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
510 information which states whether a vector type or index is specified (for a
511 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
512 struct reg_entry
513 {
514 const char * name;
515 unsigned char number;
516 unsigned char type;
517 unsigned char builtin;
518 struct neon_typed_alias * neon;
519 };
520
521 /* Diagnostics used when we don't get a register of the expected type. */
522 const char * const reg_expected_msgs[] =
523 {
524 N_("ARM register expected"),
525 N_("bad or missing co-processor number"),
526 N_("co-processor register expected"),
527 N_("FPA register expected"),
528 N_("VFP single precision register expected"),
529 N_("VFP/Neon double precision register expected"),
530 N_("Neon quad precision register expected"),
531 N_("VFP single or double precision register expected"),
532 N_("Neon double or quad precision register expected"),
533 N_("VFP single, double or Neon quad precision register expected"),
534 N_("VFP system register expected"),
535 N_("Maverick MVF register expected"),
536 N_("Maverick MVD register expected"),
537 N_("Maverick MVFX register expected"),
538 N_("Maverick MVDX register expected"),
539 N_("Maverick MVAX register expected"),
540 N_("Maverick DSPSC register expected"),
541 N_("iWMMXt data register expected"),
542 N_("iWMMXt control register expected"),
543 N_("iWMMXt scalar register expected"),
544 N_("XScale accumulator register expected"),
545 };
546
547 /* Some well known registers that we refer to directly elsewhere. */
548 #define REG_SP 13
549 #define REG_LR 14
550 #define REG_PC 15
551
552 /* ARM instructions take 4bytes in the object file, Thumb instructions
553 take 2: */
554 #define INSN_SIZE 4
555
556 struct asm_opcode
557 {
558 /* Basic string to match. */
559 const char * template_name;
560
561 /* Parameters to instruction. */
562 unsigned int operands[8];
563
564 /* Conditional tag - see opcode_lookup. */
565 unsigned int tag : 4;
566
567 /* Basic instruction code. */
568 unsigned int avalue : 28;
569
570 /* Thumb-format instruction code. */
571 unsigned int tvalue;
572
573 /* Which architecture variant provides this instruction. */
574 const arm_feature_set * avariant;
575 const arm_feature_set * tvariant;
576
577 /* Function to call to encode instruction in ARM format. */
578 void (* aencode) (void);
579
580 /* Function to call to encode instruction in Thumb format. */
581 void (* tencode) (void);
582 };
583
584 /* Defines for various bits that we will want to toggle. */
585 #define INST_IMMEDIATE 0x02000000
586 #define OFFSET_REG 0x02000000
587 #define HWOFFSET_IMM 0x00400000
588 #define SHIFT_BY_REG 0x00000010
589 #define PRE_INDEX 0x01000000
590 #define INDEX_UP 0x00800000
591 #define WRITE_BACK 0x00200000
592 #define LDM_TYPE_2_OR_3 0x00400000
593 #define CPSI_MMOD 0x00020000
594
595 #define LITERAL_MASK 0xf000f000
596 #define OPCODE_MASK 0xfe1fffff
597 #define V4_STR_BIT 0x00000020
598
599 #define T2_SUBS_PC_LR 0xf3de8f00
600
601 #define DATA_OP_SHIFT 21
602
603 #define T2_OPCODE_MASK 0xfe1fffff
604 #define T2_DATA_OP_SHIFT 21
605
606 /* Codes to distinguish the arithmetic instructions. */
607 #define OPCODE_AND 0
608 #define OPCODE_EOR 1
609 #define OPCODE_SUB 2
610 #define OPCODE_RSB 3
611 #define OPCODE_ADD 4
612 #define OPCODE_ADC 5
613 #define OPCODE_SBC 6
614 #define OPCODE_RSC 7
615 #define OPCODE_TST 8
616 #define OPCODE_TEQ 9
617 #define OPCODE_CMP 10
618 #define OPCODE_CMN 11
619 #define OPCODE_ORR 12
620 #define OPCODE_MOV 13
621 #define OPCODE_BIC 14
622 #define OPCODE_MVN 15
623
624 #define T2_OPCODE_AND 0
625 #define T2_OPCODE_BIC 1
626 #define T2_OPCODE_ORR 2
627 #define T2_OPCODE_ORN 3
628 #define T2_OPCODE_EOR 4
629 #define T2_OPCODE_ADD 8
630 #define T2_OPCODE_ADC 10
631 #define T2_OPCODE_SBC 11
632 #define T2_OPCODE_SUB 13
633 #define T2_OPCODE_RSB 14
634
635 #define T_OPCODE_MUL 0x4340
636 #define T_OPCODE_TST 0x4200
637 #define T_OPCODE_CMN 0x42c0
638 #define T_OPCODE_NEG 0x4240
639 #define T_OPCODE_MVN 0x43c0
640
641 #define T_OPCODE_ADD_R3 0x1800
642 #define T_OPCODE_SUB_R3 0x1a00
643 #define T_OPCODE_ADD_HI 0x4400
644 #define T_OPCODE_ADD_ST 0xb000
645 #define T_OPCODE_SUB_ST 0xb080
646 #define T_OPCODE_ADD_SP 0xa800
647 #define T_OPCODE_ADD_PC 0xa000
648 #define T_OPCODE_ADD_I8 0x3000
649 #define T_OPCODE_SUB_I8 0x3800
650 #define T_OPCODE_ADD_I3 0x1c00
651 #define T_OPCODE_SUB_I3 0x1e00
652
653 #define T_OPCODE_ASR_R 0x4100
654 #define T_OPCODE_LSL_R 0x4080
655 #define T_OPCODE_LSR_R 0x40c0
656 #define T_OPCODE_ROR_R 0x41c0
657 #define T_OPCODE_ASR_I 0x1000
658 #define T_OPCODE_LSL_I 0x0000
659 #define T_OPCODE_LSR_I 0x0800
660
661 #define T_OPCODE_MOV_I8 0x2000
662 #define T_OPCODE_CMP_I8 0x2800
663 #define T_OPCODE_CMP_LR 0x4280
664 #define T_OPCODE_MOV_HR 0x4600
665 #define T_OPCODE_CMP_HR 0x4500
666
667 #define T_OPCODE_LDR_PC 0x4800
668 #define T_OPCODE_LDR_SP 0x9800
669 #define T_OPCODE_STR_SP 0x9000
670 #define T_OPCODE_LDR_IW 0x6800
671 #define T_OPCODE_STR_IW 0x6000
672 #define T_OPCODE_LDR_IH 0x8800
673 #define T_OPCODE_STR_IH 0x8000
674 #define T_OPCODE_LDR_IB 0x7800
675 #define T_OPCODE_STR_IB 0x7000
676 #define T_OPCODE_LDR_RW 0x5800
677 #define T_OPCODE_STR_RW 0x5000
678 #define T_OPCODE_LDR_RH 0x5a00
679 #define T_OPCODE_STR_RH 0x5200
680 #define T_OPCODE_LDR_RB 0x5c00
681 #define T_OPCODE_STR_RB 0x5400
682
683 #define T_OPCODE_PUSH 0xb400
684 #define T_OPCODE_POP 0xbc00
685
686 #define T_OPCODE_BRANCH 0xe000
687
688 #define THUMB_SIZE 2 /* Size of thumb instruction. */
689 #define THUMB_PP_PC_LR 0x0100
690 #define THUMB_LOAD_BIT 0x0800
691 #define THUMB2_LOAD_BIT 0x00100000
692
693 #define BAD_ARGS _("bad arguments to instruction")
694 #define BAD_SP _("r13 not allowed here")
695 #define BAD_PC _("r15 not allowed here")
696 #define BAD_COND _("instruction cannot be conditional")
697 #define BAD_OVERLAP _("registers may not be the same")
698 #define BAD_HIREG _("lo register required")
699 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
700 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
701 #define BAD_BRANCH _("branch must be last instruction in IT block")
702 #define BAD_NOT_IT _("instruction not allowed in IT block")
703 #define BAD_FPU _("selected FPU does not support instruction")
704 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
705 #define BAD_IT_COND _("incorrect condition in IT block")
706 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
707 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
708 #define BAD_PC_ADDRESSING \
709 _("cannot use register index with PC-relative addressing")
710 #define BAD_PC_WRITEBACK \
711 _("cannot use writeback with PC-relative addressing")
712
713 static struct hash_control * arm_ops_hsh;
714 static struct hash_control * arm_cond_hsh;
715 static struct hash_control * arm_shift_hsh;
716 static struct hash_control * arm_psr_hsh;
717 static struct hash_control * arm_v7m_psr_hsh;
718 static struct hash_control * arm_reg_hsh;
719 static struct hash_control * arm_reloc_hsh;
720 static struct hash_control * arm_barrier_opt_hsh;
721
722 /* Stuff needed to resolve the label ambiguity
723 As:
724 ...
725 label: <insn>
726 may differ from:
727 ...
728 label:
729 <insn> */
730
731 symbolS * last_label_seen;
732 static int label_is_thumb_function_name = FALSE;
733
734 /* Literal pool structure. Held on a per-section
735 and per-sub-section basis. */
736
737 #define MAX_LITERAL_POOL_SIZE 1024
738 typedef struct literal_pool
739 {
740 expressionS literals [MAX_LITERAL_POOL_SIZE];
741 unsigned int next_free_entry;
742 unsigned int id;
743 symbolS * symbol;
744 segT section;
745 subsegT sub_section;
746 struct literal_pool * next;
747 } literal_pool;
748
749 /* Pointer to a linked list of literal pools. */
750 literal_pool * list_of_pools = NULL;
751
752 #ifdef OBJ_ELF
753 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
754 #else
755 static struct current_it now_it;
756 #endif
757
758 static inline int
759 now_it_compatible (int cond)
760 {
761 return (cond & ~1) == (now_it.cc & ~1);
762 }
763
764 static inline int
765 conditional_insn (void)
766 {
767 return inst.cond != COND_ALWAYS;
768 }
769
770 static int in_it_block (void);
771
772 static int handle_it_state (void);
773
774 static void force_automatic_it_block_close (void);
775
776 static void it_fsm_post_encode (void);
777
778 #define set_it_insn_type(type) \
779 do \
780 { \
781 inst.it_insn_type = type; \
782 if (handle_it_state () == FAIL) \
783 return; \
784 } \
785 while (0)
786
787 #define set_it_insn_type_nonvoid(type, failret) \
788 do \
789 { \
790 inst.it_insn_type = type; \
791 if (handle_it_state () == FAIL) \
792 return failret; \
793 } \
794 while(0)
795
796 #define set_it_insn_type_last() \
797 do \
798 { \
799 if (inst.cond == COND_ALWAYS) \
800 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
801 else \
802 set_it_insn_type (INSIDE_IT_LAST_INSN); \
803 } \
804 while (0)
805
806 /* Pure syntax. */
807
808 /* This array holds the chars that always start a comment. If the
809 pre-processor is disabled, these aren't very useful. */
810 const char comment_chars[] = "@";
811
812 /* This array holds the chars that only start a comment at the beginning of
813 a line. If the line seems to have the form '# 123 filename'
814 .line and .file directives will appear in the pre-processed output. */
815 /* Note that input_file.c hand checks for '#' at the beginning of the
816 first line of the input file. This is because the compiler outputs
817 #NO_APP at the beginning of its output. */
818 /* Also note that comments like this one will always work. */
819 const char line_comment_chars[] = "#";
820
821 const char line_separator_chars[] = ";";
822
823 /* Chars that can be used to separate mant
824 from exp in floating point numbers. */
825 const char EXP_CHARS[] = "eE";
826
827 /* Chars that mean this number is a floating point constant. */
828 /* As in 0f12.456 */
829 /* or 0d1.2345e12 */
830
831 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
832
833 /* Prefix characters that indicate the start of an immediate
834 value. */
835 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
836
837 /* Separator character handling. */
838
839 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
840
841 static inline int
842 skip_past_char (char ** str, char c)
843 {
844 if (**str == c)
845 {
846 (*str)++;
847 return SUCCESS;
848 }
849 else
850 return FAIL;
851 }
852
853 #define skip_past_comma(str) skip_past_char (str, ',')
854
855 /* Arithmetic expressions (possibly involving symbols). */
856
857 /* Return TRUE if anything in the expression is a bignum. */
858
859 static int
860 walk_no_bignums (symbolS * sp)
861 {
862 if (symbol_get_value_expression (sp)->X_op == O_big)
863 return 1;
864
865 if (symbol_get_value_expression (sp)->X_add_symbol)
866 {
867 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
868 || (symbol_get_value_expression (sp)->X_op_symbol
869 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
870 }
871
872 return 0;
873 }
874
875 static int in_my_get_expression = 0;
876
877 /* Third argument to my_get_expression. */
878 #define GE_NO_PREFIX 0
879 #define GE_IMM_PREFIX 1
880 #define GE_OPT_PREFIX 2
881 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
882 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
883 #define GE_OPT_PREFIX_BIG 3
884
885 static int
886 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
887 {
888 char * save_in;
889 segT seg;
890
891 /* In unified syntax, all prefixes are optional. */
892 if (unified_syntax)
893 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
894 : GE_OPT_PREFIX;
895
896 switch (prefix_mode)
897 {
898 case GE_NO_PREFIX: break;
899 case GE_IMM_PREFIX:
900 if (!is_immediate_prefix (**str))
901 {
902 inst.error = _("immediate expression requires a # prefix");
903 return FAIL;
904 }
905 (*str)++;
906 break;
907 case GE_OPT_PREFIX:
908 case GE_OPT_PREFIX_BIG:
909 if (is_immediate_prefix (**str))
910 (*str)++;
911 break;
912 default: abort ();
913 }
914
915 memset (ep, 0, sizeof (expressionS));
916
917 save_in = input_line_pointer;
918 input_line_pointer = *str;
919 in_my_get_expression = 1;
920 seg = expression (ep);
921 in_my_get_expression = 0;
922
923 if (ep->X_op == O_illegal || ep->X_op == O_absent)
924 {
925 /* We found a bad or missing expression in md_operand(). */
926 *str = input_line_pointer;
927 input_line_pointer = save_in;
928 if (inst.error == NULL)
929 inst.error = (ep->X_op == O_absent
930 ? _("missing expression") :_("bad expression"));
931 return 1;
932 }
933
934 #ifdef OBJ_AOUT
935 if (seg != absolute_section
936 && seg != text_section
937 && seg != data_section
938 && seg != bss_section
939 && seg != undefined_section)
940 {
941 inst.error = _("bad segment");
942 *str = input_line_pointer;
943 input_line_pointer = save_in;
944 return 1;
945 }
946 #endif
947
948 /* Get rid of any bignums now, so that we don't generate an error for which
949 we can't establish a line number later on. Big numbers are never valid
950 in instructions, which is where this routine is always called. */
951 if (prefix_mode != GE_OPT_PREFIX_BIG
952 && (ep->X_op == O_big
953 || (ep->X_add_symbol
954 && (walk_no_bignums (ep->X_add_symbol)
955 || (ep->X_op_symbol
956 && walk_no_bignums (ep->X_op_symbol))))))
957 {
958 inst.error = _("invalid constant");
959 *str = input_line_pointer;
960 input_line_pointer = save_in;
961 return 1;
962 }
963
964 *str = input_line_pointer;
965 input_line_pointer = save_in;
966 return 0;
967 }
968
969 /* Turn a string in input_line_pointer into a floating point constant
970 of type TYPE, and store the appropriate bytes in *LITP. The number
971 of LITTLENUMS emitted is stored in *SIZEP. An error message is
972 returned, or NULL on OK.
973
974 Note that fp constants aren't represent in the normal way on the ARM.
975 In big endian mode, things are as expected. However, in little endian
976 mode fp constants are big-endian word-wise, and little-endian byte-wise
977 within the words. For example, (double) 1.1 in big endian mode is
978 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
979 the byte sequence 99 99 f1 3f 9a 99 99 99.
980
981 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
982
983 char *
984 md_atof (int type, char * litP, int * sizeP)
985 {
986 int prec;
987 LITTLENUM_TYPE words[MAX_LITTLENUMS];
988 char *t;
989 int i;
990
991 switch (type)
992 {
993 case 'f':
994 case 'F':
995 case 's':
996 case 'S':
997 prec = 2;
998 break;
999
1000 case 'd':
1001 case 'D':
1002 case 'r':
1003 case 'R':
1004 prec = 4;
1005 break;
1006
1007 case 'x':
1008 case 'X':
1009 prec = 5;
1010 break;
1011
1012 case 'p':
1013 case 'P':
1014 prec = 5;
1015 break;
1016
1017 default:
1018 *sizeP = 0;
1019 return _("Unrecognized or unsupported floating point constant");
1020 }
1021
1022 t = atof_ieee (input_line_pointer, type, words);
1023 if (t)
1024 input_line_pointer = t;
1025 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1026
1027 if (target_big_endian)
1028 {
1029 for (i = 0; i < prec; i++)
1030 {
1031 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1032 litP += sizeof (LITTLENUM_TYPE);
1033 }
1034 }
1035 else
1036 {
1037 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1038 for (i = prec - 1; i >= 0; i--)
1039 {
1040 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1041 litP += sizeof (LITTLENUM_TYPE);
1042 }
1043 else
1044 /* For a 4 byte float the order of elements in `words' is 1 0.
1045 For an 8 byte float the order is 1 0 3 2. */
1046 for (i = 0; i < prec; i += 2)
1047 {
1048 md_number_to_chars (litP, (valueT) words[i + 1],
1049 sizeof (LITTLENUM_TYPE));
1050 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1051 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1052 litP += 2 * sizeof (LITTLENUM_TYPE);
1053 }
1054 }
1055
1056 return NULL;
1057 }
1058
1059 /* We handle all bad expressions here, so that we can report the faulty
1060 instruction in the error message. */
1061 void
1062 md_operand (expressionS * exp)
1063 {
1064 if (in_my_get_expression)
1065 exp->X_op = O_illegal;
1066 }
1067
1068 /* Immediate values. */
1069
1070 /* Generic immediate-value read function for use in directives.
1071 Accepts anything that 'expression' can fold to a constant.
1072 *val receives the number. */
1073 #ifdef OBJ_ELF
1074 static int
1075 immediate_for_directive (int *val)
1076 {
1077 expressionS exp;
1078 exp.X_op = O_illegal;
1079
1080 if (is_immediate_prefix (*input_line_pointer))
1081 {
1082 input_line_pointer++;
1083 expression (&exp);
1084 }
1085
1086 if (exp.X_op != O_constant)
1087 {
1088 as_bad (_("expected #constant"));
1089 ignore_rest_of_line ();
1090 return FAIL;
1091 }
1092 *val = exp.X_add_number;
1093 return SUCCESS;
1094 }
1095 #endif
1096
1097 /* Register parsing. */
1098
1099 /* Generic register parser. CCP points to what should be the
1100 beginning of a register name. If it is indeed a valid register
1101 name, advance CCP over it and return the reg_entry structure;
1102 otherwise return NULL. Does not issue diagnostics. */
1103
1104 static struct reg_entry *
1105 arm_reg_parse_multi (char **ccp)
1106 {
1107 char *start = *ccp;
1108 char *p;
1109 struct reg_entry *reg;
1110
1111 #ifdef REGISTER_PREFIX
1112 if (*start != REGISTER_PREFIX)
1113 return NULL;
1114 start++;
1115 #endif
1116 #ifdef OPTIONAL_REGISTER_PREFIX
1117 if (*start == OPTIONAL_REGISTER_PREFIX)
1118 start++;
1119 #endif
1120
1121 p = start;
1122 if (!ISALPHA (*p) || !is_name_beginner (*p))
1123 return NULL;
1124
1125 do
1126 p++;
1127 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1128
1129 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1130
1131 if (!reg)
1132 return NULL;
1133
1134 *ccp = p;
1135 return reg;
1136 }
1137
1138 static int
1139 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1140 enum arm_reg_type type)
1141 {
1142 /* Alternative syntaxes are accepted for a few register classes. */
1143 switch (type)
1144 {
1145 case REG_TYPE_MVF:
1146 case REG_TYPE_MVD:
1147 case REG_TYPE_MVFX:
1148 case REG_TYPE_MVDX:
1149 /* Generic coprocessor register names are allowed for these. */
1150 if (reg && reg->type == REG_TYPE_CN)
1151 return reg->number;
1152 break;
1153
1154 case REG_TYPE_CP:
1155 /* For backward compatibility, a bare number is valid here. */
1156 {
1157 unsigned long processor = strtoul (start, ccp, 10);
1158 if (*ccp != start && processor <= 15)
1159 return processor;
1160 }
1161
1162 case REG_TYPE_MMXWC:
1163 /* WC includes WCG. ??? I'm not sure this is true for all
1164 instructions that take WC registers. */
1165 if (reg && reg->type == REG_TYPE_MMXWCG)
1166 return reg->number;
1167 break;
1168
1169 default:
1170 break;
1171 }
1172
1173 return FAIL;
1174 }
1175
1176 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1177 return value is the register number or FAIL. */
1178
1179 static int
1180 arm_reg_parse (char **ccp, enum arm_reg_type type)
1181 {
1182 char *start = *ccp;
1183 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1184 int ret;
1185
1186 /* Do not allow a scalar (reg+index) to parse as a register. */
1187 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1188 return FAIL;
1189
1190 if (reg && reg->type == type)
1191 return reg->number;
1192
1193 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1194 return ret;
1195
1196 *ccp = start;
1197 return FAIL;
1198 }
1199
1200 /* Parse a Neon type specifier. *STR should point at the leading '.'
1201 character. Does no verification at this stage that the type fits the opcode
1202 properly. E.g.,
1203
1204 .i32.i32.s16
1205 .s32.f32
1206 .u16
1207
1208 Can all be legally parsed by this function.
1209
1210 Fills in neon_type struct pointer with parsed information, and updates STR
1211 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1212 type, FAIL if not. */
1213
1214 static int
1215 parse_neon_type (struct neon_type *type, char **str)
1216 {
1217 char *ptr = *str;
1218
1219 if (type)
1220 type->elems = 0;
1221
1222 while (type->elems < NEON_MAX_TYPE_ELS)
1223 {
1224 enum neon_el_type thistype = NT_untyped;
1225 unsigned thissize = -1u;
1226
1227 if (*ptr != '.')
1228 break;
1229
1230 ptr++;
1231
1232 /* Just a size without an explicit type. */
1233 if (ISDIGIT (*ptr))
1234 goto parsesize;
1235
1236 switch (TOLOWER (*ptr))
1237 {
1238 case 'i': thistype = NT_integer; break;
1239 case 'f': thistype = NT_float; break;
1240 case 'p': thistype = NT_poly; break;
1241 case 's': thistype = NT_signed; break;
1242 case 'u': thistype = NT_unsigned; break;
1243 case 'd':
1244 thistype = NT_float;
1245 thissize = 64;
1246 ptr++;
1247 goto done;
1248 default:
1249 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1250 return FAIL;
1251 }
1252
1253 ptr++;
1254
1255 /* .f is an abbreviation for .f32. */
1256 if (thistype == NT_float && !ISDIGIT (*ptr))
1257 thissize = 32;
1258 else
1259 {
1260 parsesize:
1261 thissize = strtoul (ptr, &ptr, 10);
1262
1263 if (thissize != 8 && thissize != 16 && thissize != 32
1264 && thissize != 64)
1265 {
1266 as_bad (_("bad size %d in type specifier"), thissize);
1267 return FAIL;
1268 }
1269 }
1270
1271 done:
1272 if (type)
1273 {
1274 type->el[type->elems].type = thistype;
1275 type->el[type->elems].size = thissize;
1276 type->elems++;
1277 }
1278 }
1279
1280 /* Empty/missing type is not a successful parse. */
1281 if (type->elems == 0)
1282 return FAIL;
1283
1284 *str = ptr;
1285
1286 return SUCCESS;
1287 }
1288
1289 /* Errors may be set multiple times during parsing or bit encoding
1290 (particularly in the Neon bits), but usually the earliest error which is set
1291 will be the most meaningful. Avoid overwriting it with later (cascading)
1292 errors by calling this function. */
1293
1294 static void
1295 first_error (const char *err)
1296 {
1297 if (!inst.error)
1298 inst.error = err;
1299 }
1300
1301 /* Parse a single type, e.g. ".s32", leading period included. */
1302 static int
1303 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1304 {
1305 char *str = *ccp;
1306 struct neon_type optype;
1307
1308 if (*str == '.')
1309 {
1310 if (parse_neon_type (&optype, &str) == SUCCESS)
1311 {
1312 if (optype.elems == 1)
1313 *vectype = optype.el[0];
1314 else
1315 {
1316 first_error (_("only one type should be specified for operand"));
1317 return FAIL;
1318 }
1319 }
1320 else
1321 {
1322 first_error (_("vector type expected"));
1323 return FAIL;
1324 }
1325 }
1326 else
1327 return FAIL;
1328
1329 *ccp = str;
1330
1331 return SUCCESS;
1332 }
1333
1334 /* Special meanings for indices (which have a range of 0-7), which will fit into
1335 a 4-bit integer. */
1336
1337 #define NEON_ALL_LANES 15
1338 #define NEON_INTERLEAVE_LANES 14
1339
1340 /* Parse either a register or a scalar, with an optional type. Return the
1341 register number, and optionally fill in the actual type of the register
1342 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1343 type/index information in *TYPEINFO. */
1344
1345 static int
1346 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1347 enum arm_reg_type *rtype,
1348 struct neon_typed_alias *typeinfo)
1349 {
1350 char *str = *ccp;
1351 struct reg_entry *reg = arm_reg_parse_multi (&str);
1352 struct neon_typed_alias atype;
1353 struct neon_type_el parsetype;
1354
1355 atype.defined = 0;
1356 atype.index = -1;
1357 atype.eltype.type = NT_invtype;
1358 atype.eltype.size = -1;
1359
1360 /* Try alternate syntax for some types of register. Note these are mutually
1361 exclusive with the Neon syntax extensions. */
1362 if (reg == NULL)
1363 {
1364 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1365 if (altreg != FAIL)
1366 *ccp = str;
1367 if (typeinfo)
1368 *typeinfo = atype;
1369 return altreg;
1370 }
1371
1372 /* Undo polymorphism when a set of register types may be accepted. */
1373 if ((type == REG_TYPE_NDQ
1374 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1375 || (type == REG_TYPE_VFSD
1376 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1377 || (type == REG_TYPE_NSDQ
1378 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1379 || reg->type == REG_TYPE_NQ))
1380 || (type == REG_TYPE_MMXWC
1381 && (reg->type == REG_TYPE_MMXWCG)))
1382 type = (enum arm_reg_type) reg->type;
1383
1384 if (type != reg->type)
1385 return FAIL;
1386
1387 if (reg->neon)
1388 atype = *reg->neon;
1389
1390 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1391 {
1392 if ((atype.defined & NTA_HASTYPE) != 0)
1393 {
1394 first_error (_("can't redefine type for operand"));
1395 return FAIL;
1396 }
1397 atype.defined |= NTA_HASTYPE;
1398 atype.eltype = parsetype;
1399 }
1400
1401 if (skip_past_char (&str, '[') == SUCCESS)
1402 {
1403 if (type != REG_TYPE_VFD)
1404 {
1405 first_error (_("only D registers may be indexed"));
1406 return FAIL;
1407 }
1408
1409 if ((atype.defined & NTA_HASINDEX) != 0)
1410 {
1411 first_error (_("can't change index for operand"));
1412 return FAIL;
1413 }
1414
1415 atype.defined |= NTA_HASINDEX;
1416
1417 if (skip_past_char (&str, ']') == SUCCESS)
1418 atype.index = NEON_ALL_LANES;
1419 else
1420 {
1421 expressionS exp;
1422
1423 my_get_expression (&exp, &str, GE_NO_PREFIX);
1424
1425 if (exp.X_op != O_constant)
1426 {
1427 first_error (_("constant expression required"));
1428 return FAIL;
1429 }
1430
1431 if (skip_past_char (&str, ']') == FAIL)
1432 return FAIL;
1433
1434 atype.index = exp.X_add_number;
1435 }
1436 }
1437
1438 if (typeinfo)
1439 *typeinfo = atype;
1440
1441 if (rtype)
1442 *rtype = type;
1443
1444 *ccp = str;
1445
1446 return reg->number;
1447 }
1448
1449 /* Like arm_reg_parse, but allow allow the following extra features:
1450 - If RTYPE is non-zero, return the (possibly restricted) type of the
1451 register (e.g. Neon double or quad reg when either has been requested).
1452 - If this is a Neon vector type with additional type information, fill
1453 in the struct pointed to by VECTYPE (if non-NULL).
1454 This function will fault on encountering a scalar. */
1455
1456 static int
1457 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1458 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1459 {
1460 struct neon_typed_alias atype;
1461 char *str = *ccp;
1462 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1463
1464 if (reg == FAIL)
1465 return FAIL;
1466
1467 /* Do not allow a scalar (reg+index) to parse as a register. */
1468 if ((atype.defined & NTA_HASINDEX) != 0)
1469 {
1470 first_error (_("register operand expected, but got scalar"));
1471 return FAIL;
1472 }
1473
1474 if (vectype)
1475 *vectype = atype.eltype;
1476
1477 *ccp = str;
1478
1479 return reg;
1480 }
1481
1482 #define NEON_SCALAR_REG(X) ((X) >> 4)
1483 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1484
1485 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1486 have enough information to be able to do a good job bounds-checking. So, we
1487 just do easy checks here, and do further checks later. */
1488
1489 static int
1490 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1491 {
1492 int reg;
1493 char *str = *ccp;
1494 struct neon_typed_alias atype;
1495
1496 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1497
1498 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1499 return FAIL;
1500
1501 if (atype.index == NEON_ALL_LANES)
1502 {
1503 first_error (_("scalar must have an index"));
1504 return FAIL;
1505 }
1506 else if (atype.index >= 64 / elsize)
1507 {
1508 first_error (_("scalar index out of range"));
1509 return FAIL;
1510 }
1511
1512 if (type)
1513 *type = atype.eltype;
1514
1515 *ccp = str;
1516
1517 return reg * 16 + atype.index;
1518 }
1519
1520 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1521
1522 static long
1523 parse_reg_list (char ** strp)
1524 {
1525 char * str = * strp;
1526 long range = 0;
1527 int another_range;
1528
1529 /* We come back here if we get ranges concatenated by '+' or '|'. */
1530 do
1531 {
1532 another_range = 0;
1533
1534 if (*str == '{')
1535 {
1536 int in_range = 0;
1537 int cur_reg = -1;
1538
1539 str++;
1540 do
1541 {
1542 int reg;
1543
1544 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1545 {
1546 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1547 return FAIL;
1548 }
1549
1550 if (in_range)
1551 {
1552 int i;
1553
1554 if (reg <= cur_reg)
1555 {
1556 first_error (_("bad range in register list"));
1557 return FAIL;
1558 }
1559
1560 for (i = cur_reg + 1; i < reg; i++)
1561 {
1562 if (range & (1 << i))
1563 as_tsktsk
1564 (_("Warning: duplicated register (r%d) in register list"),
1565 i);
1566 else
1567 range |= 1 << i;
1568 }
1569 in_range = 0;
1570 }
1571
1572 if (range & (1 << reg))
1573 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1574 reg);
1575 else if (reg <= cur_reg)
1576 as_tsktsk (_("Warning: register range not in ascending order"));
1577
1578 range |= 1 << reg;
1579 cur_reg = reg;
1580 }
1581 while (skip_past_comma (&str) != FAIL
1582 || (in_range = 1, *str++ == '-'));
1583 str--;
1584
1585 if (*str++ != '}')
1586 {
1587 first_error (_("missing `}'"));
1588 return FAIL;
1589 }
1590 }
1591 else
1592 {
1593 expressionS exp;
1594
1595 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1596 return FAIL;
1597
1598 if (exp.X_op == O_constant)
1599 {
1600 if (exp.X_add_number
1601 != (exp.X_add_number & 0x0000ffff))
1602 {
1603 inst.error = _("invalid register mask");
1604 return FAIL;
1605 }
1606
1607 if ((range & exp.X_add_number) != 0)
1608 {
1609 int regno = range & exp.X_add_number;
1610
1611 regno &= -regno;
1612 regno = (1 << regno) - 1;
1613 as_tsktsk
1614 (_("Warning: duplicated register (r%d) in register list"),
1615 regno);
1616 }
1617
1618 range |= exp.X_add_number;
1619 }
1620 else
1621 {
1622 if (inst.reloc.type != 0)
1623 {
1624 inst.error = _("expression too complex");
1625 return FAIL;
1626 }
1627
1628 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1629 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1630 inst.reloc.pc_rel = 0;
1631 }
1632 }
1633
1634 if (*str == '|' || *str == '+')
1635 {
1636 str++;
1637 another_range = 1;
1638 }
1639 }
1640 while (another_range);
1641
1642 *strp = str;
1643 return range;
1644 }
1645
1646 /* Types of registers in a list. */
1647
1648 enum reg_list_els
1649 {
1650 REGLIST_VFP_S,
1651 REGLIST_VFP_D,
1652 REGLIST_NEON_D
1653 };
1654
1655 /* Parse a VFP register list. If the string is invalid return FAIL.
1656 Otherwise return the number of registers, and set PBASE to the first
1657 register. Parses registers of type ETYPE.
1658 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1659 - Q registers can be used to specify pairs of D registers
1660 - { } can be omitted from around a singleton register list
1661 FIXME: This is not implemented, as it would require backtracking in
1662 some cases, e.g.:
1663 vtbl.8 d3,d4,d5
1664 This could be done (the meaning isn't really ambiguous), but doesn't
1665 fit in well with the current parsing framework.
1666 - 32 D registers may be used (also true for VFPv3).
1667 FIXME: Types are ignored in these register lists, which is probably a
1668 bug. */
1669
1670 static int
1671 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1672 {
1673 char *str = *ccp;
1674 int base_reg;
1675 int new_base;
1676 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1677 int max_regs = 0;
1678 int count = 0;
1679 int warned = 0;
1680 unsigned long mask = 0;
1681 int i;
1682
1683 if (*str != '{')
1684 {
1685 inst.error = _("expecting {");
1686 return FAIL;
1687 }
1688
1689 str++;
1690
1691 switch (etype)
1692 {
1693 case REGLIST_VFP_S:
1694 regtype = REG_TYPE_VFS;
1695 max_regs = 32;
1696 break;
1697
1698 case REGLIST_VFP_D:
1699 regtype = REG_TYPE_VFD;
1700 break;
1701
1702 case REGLIST_NEON_D:
1703 regtype = REG_TYPE_NDQ;
1704 break;
1705 }
1706
1707 if (etype != REGLIST_VFP_S)
1708 {
1709 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1710 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1711 {
1712 max_regs = 32;
1713 if (thumb_mode)
1714 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1715 fpu_vfp_ext_d32);
1716 else
1717 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1718 fpu_vfp_ext_d32);
1719 }
1720 else
1721 max_regs = 16;
1722 }
1723
1724 base_reg = max_regs;
1725
1726 do
1727 {
1728 int setmask = 1, addregs = 1;
1729
1730 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1731
1732 if (new_base == FAIL)
1733 {
1734 first_error (_(reg_expected_msgs[regtype]));
1735 return FAIL;
1736 }
1737
1738 if (new_base >= max_regs)
1739 {
1740 first_error (_("register out of range in list"));
1741 return FAIL;
1742 }
1743
1744 /* Note: a value of 2 * n is returned for the register Q<n>. */
1745 if (regtype == REG_TYPE_NQ)
1746 {
1747 setmask = 3;
1748 addregs = 2;
1749 }
1750
1751 if (new_base < base_reg)
1752 base_reg = new_base;
1753
1754 if (mask & (setmask << new_base))
1755 {
1756 first_error (_("invalid register list"));
1757 return FAIL;
1758 }
1759
1760 if ((mask >> new_base) != 0 && ! warned)
1761 {
1762 as_tsktsk (_("register list not in ascending order"));
1763 warned = 1;
1764 }
1765
1766 mask |= setmask << new_base;
1767 count += addregs;
1768
1769 if (*str == '-') /* We have the start of a range expression */
1770 {
1771 int high_range;
1772
1773 str++;
1774
1775 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1776 == FAIL)
1777 {
1778 inst.error = gettext (reg_expected_msgs[regtype]);
1779 return FAIL;
1780 }
1781
1782 if (high_range >= max_regs)
1783 {
1784 first_error (_("register out of range in list"));
1785 return FAIL;
1786 }
1787
1788 if (regtype == REG_TYPE_NQ)
1789 high_range = high_range + 1;
1790
1791 if (high_range <= new_base)
1792 {
1793 inst.error = _("register range not in ascending order");
1794 return FAIL;
1795 }
1796
1797 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1798 {
1799 if (mask & (setmask << new_base))
1800 {
1801 inst.error = _("invalid register list");
1802 return FAIL;
1803 }
1804
1805 mask |= setmask << new_base;
1806 count += addregs;
1807 }
1808 }
1809 }
1810 while (skip_past_comma (&str) != FAIL);
1811
1812 str++;
1813
1814 /* Sanity check -- should have raised a parse error above. */
1815 if (count == 0 || count > max_regs)
1816 abort ();
1817
1818 *pbase = base_reg;
1819
1820 /* Final test -- the registers must be consecutive. */
1821 mask >>= base_reg;
1822 for (i = 0; i < count; i++)
1823 {
1824 if ((mask & (1u << i)) == 0)
1825 {
1826 inst.error = _("non-contiguous register range");
1827 return FAIL;
1828 }
1829 }
1830
1831 *ccp = str;
1832
1833 return count;
1834 }
1835
1836 /* True if two alias types are the same. */
1837
1838 static bfd_boolean
1839 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1840 {
1841 if (!a && !b)
1842 return TRUE;
1843
1844 if (!a || !b)
1845 return FALSE;
1846
1847 if (a->defined != b->defined)
1848 return FALSE;
1849
1850 if ((a->defined & NTA_HASTYPE) != 0
1851 && (a->eltype.type != b->eltype.type
1852 || a->eltype.size != b->eltype.size))
1853 return FALSE;
1854
1855 if ((a->defined & NTA_HASINDEX) != 0
1856 && (a->index != b->index))
1857 return FALSE;
1858
1859 return TRUE;
1860 }
1861
1862 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1863 The base register is put in *PBASE.
1864 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1865 the return value.
1866 The register stride (minus one) is put in bit 4 of the return value.
1867 Bits [6:5] encode the list length (minus one).
1868 The type of the list elements is put in *ELTYPE, if non-NULL. */
1869
1870 #define NEON_LANE(X) ((X) & 0xf)
1871 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1872 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1873
1874 static int
1875 parse_neon_el_struct_list (char **str, unsigned *pbase,
1876 struct neon_type_el *eltype)
1877 {
1878 char *ptr = *str;
1879 int base_reg = -1;
1880 int reg_incr = -1;
1881 int count = 0;
1882 int lane = -1;
1883 int leading_brace = 0;
1884 enum arm_reg_type rtype = REG_TYPE_NDQ;
1885 int addregs = 1;
1886 const char *const incr_error = _("register stride must be 1 or 2");
1887 const char *const type_error = _("mismatched element/structure types in list");
1888 struct neon_typed_alias firsttype;
1889
1890 if (skip_past_char (&ptr, '{') == SUCCESS)
1891 leading_brace = 1;
1892
1893 do
1894 {
1895 struct neon_typed_alias atype;
1896 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1897
1898 if (getreg == FAIL)
1899 {
1900 first_error (_(reg_expected_msgs[rtype]));
1901 return FAIL;
1902 }
1903
1904 if (base_reg == -1)
1905 {
1906 base_reg = getreg;
1907 if (rtype == REG_TYPE_NQ)
1908 {
1909 reg_incr = 1;
1910 addregs = 2;
1911 }
1912 firsttype = atype;
1913 }
1914 else if (reg_incr == -1)
1915 {
1916 reg_incr = getreg - base_reg;
1917 if (reg_incr < 1 || reg_incr > 2)
1918 {
1919 first_error (_(incr_error));
1920 return FAIL;
1921 }
1922 }
1923 else if (getreg != base_reg + reg_incr * count)
1924 {
1925 first_error (_(incr_error));
1926 return FAIL;
1927 }
1928
1929 if (! neon_alias_types_same (&atype, &firsttype))
1930 {
1931 first_error (_(type_error));
1932 return FAIL;
1933 }
1934
1935 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1936 modes. */
1937 if (ptr[0] == '-')
1938 {
1939 struct neon_typed_alias htype;
1940 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1941 if (lane == -1)
1942 lane = NEON_INTERLEAVE_LANES;
1943 else if (lane != NEON_INTERLEAVE_LANES)
1944 {
1945 first_error (_(type_error));
1946 return FAIL;
1947 }
1948 if (reg_incr == -1)
1949 reg_incr = 1;
1950 else if (reg_incr != 1)
1951 {
1952 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1953 return FAIL;
1954 }
1955 ptr++;
1956 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1957 if (hireg == FAIL)
1958 {
1959 first_error (_(reg_expected_msgs[rtype]));
1960 return FAIL;
1961 }
1962 if (! neon_alias_types_same (&htype, &firsttype))
1963 {
1964 first_error (_(type_error));
1965 return FAIL;
1966 }
1967 count += hireg + dregs - getreg;
1968 continue;
1969 }
1970
1971 /* If we're using Q registers, we can't use [] or [n] syntax. */
1972 if (rtype == REG_TYPE_NQ)
1973 {
1974 count += 2;
1975 continue;
1976 }
1977
1978 if ((atype.defined & NTA_HASINDEX) != 0)
1979 {
1980 if (lane == -1)
1981 lane = atype.index;
1982 else if (lane != atype.index)
1983 {
1984 first_error (_(type_error));
1985 return FAIL;
1986 }
1987 }
1988 else if (lane == -1)
1989 lane = NEON_INTERLEAVE_LANES;
1990 else if (lane != NEON_INTERLEAVE_LANES)
1991 {
1992 first_error (_(type_error));
1993 return FAIL;
1994 }
1995 count++;
1996 }
1997 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1998
1999 /* No lane set by [x]. We must be interleaving structures. */
2000 if (lane == -1)
2001 lane = NEON_INTERLEAVE_LANES;
2002
2003 /* Sanity check. */
2004 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2005 || (count > 1 && reg_incr == -1))
2006 {
2007 first_error (_("error parsing element/structure list"));
2008 return FAIL;
2009 }
2010
2011 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2012 {
2013 first_error (_("expected }"));
2014 return FAIL;
2015 }
2016
2017 if (reg_incr == -1)
2018 reg_incr = 1;
2019
2020 if (eltype)
2021 *eltype = firsttype.eltype;
2022
2023 *pbase = base_reg;
2024 *str = ptr;
2025
2026 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2027 }
2028
2029 /* Parse an explicit relocation suffix on an expression. This is
2030 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2031 arm_reloc_hsh contains no entries, so this function can only
2032 succeed if there is no () after the word. Returns -1 on error,
2033 BFD_RELOC_UNUSED if there wasn't any suffix. */
2034 static int
2035 parse_reloc (char **str)
2036 {
2037 struct reloc_entry *r;
2038 char *p, *q;
2039
2040 if (**str != '(')
2041 return BFD_RELOC_UNUSED;
2042
2043 p = *str + 1;
2044 q = p;
2045
2046 while (*q && *q != ')' && *q != ',')
2047 q++;
2048 if (*q != ')')
2049 return -1;
2050
2051 if ((r = (struct reloc_entry *)
2052 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2053 return -1;
2054
2055 *str = q + 1;
2056 return r->reloc;
2057 }
2058
2059 /* Directives: register aliases. */
2060
2061 static struct reg_entry *
2062 insert_reg_alias (char *str, int number, int type)
2063 {
2064 struct reg_entry *new_reg;
2065 const char *name;
2066
2067 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2068 {
2069 if (new_reg->builtin)
2070 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2071
2072 /* Only warn about a redefinition if it's not defined as the
2073 same register. */
2074 else if (new_reg->number != number || new_reg->type != type)
2075 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2076
2077 return NULL;
2078 }
2079
2080 name = xstrdup (str);
2081 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2082
2083 new_reg->name = name;
2084 new_reg->number = number;
2085 new_reg->type = type;
2086 new_reg->builtin = FALSE;
2087 new_reg->neon = NULL;
2088
2089 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2090 abort ();
2091
2092 return new_reg;
2093 }
2094
2095 static void
2096 insert_neon_reg_alias (char *str, int number, int type,
2097 struct neon_typed_alias *atype)
2098 {
2099 struct reg_entry *reg = insert_reg_alias (str, number, type);
2100
2101 if (!reg)
2102 {
2103 first_error (_("attempt to redefine typed alias"));
2104 return;
2105 }
2106
2107 if (atype)
2108 {
2109 reg->neon = (struct neon_typed_alias *)
2110 xmalloc (sizeof (struct neon_typed_alias));
2111 *reg->neon = *atype;
2112 }
2113 }
2114
2115 /* Look for the .req directive. This is of the form:
2116
2117 new_register_name .req existing_register_name
2118
2119 If we find one, or if it looks sufficiently like one that we want to
2120 handle any error here, return TRUE. Otherwise return FALSE. */
2121
2122 static bfd_boolean
2123 create_register_alias (char * newname, char *p)
2124 {
2125 struct reg_entry *old;
2126 char *oldname, *nbuf;
2127 size_t nlen;
2128
2129 /* The input scrubber ensures that whitespace after the mnemonic is
2130 collapsed to single spaces. */
2131 oldname = p;
2132 if (strncmp (oldname, " .req ", 6) != 0)
2133 return FALSE;
2134
2135 oldname += 6;
2136 if (*oldname == '\0')
2137 return FALSE;
2138
2139 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2140 if (!old)
2141 {
2142 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2143 return TRUE;
2144 }
2145
2146 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2147 the desired alias name, and p points to its end. If not, then
2148 the desired alias name is in the global original_case_string. */
2149 #ifdef TC_CASE_SENSITIVE
2150 nlen = p - newname;
2151 #else
2152 newname = original_case_string;
2153 nlen = strlen (newname);
2154 #endif
2155
2156 nbuf = (char *) alloca (nlen + 1);
2157 memcpy (nbuf, newname, nlen);
2158 nbuf[nlen] = '\0';
2159
2160 /* Create aliases under the new name as stated; an all-lowercase
2161 version of the new name; and an all-uppercase version of the new
2162 name. */
2163 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2164 {
2165 for (p = nbuf; *p; p++)
2166 *p = TOUPPER (*p);
2167
2168 if (strncmp (nbuf, newname, nlen))
2169 {
2170 /* If this attempt to create an additional alias fails, do not bother
2171 trying to create the all-lower case alias. We will fail and issue
2172 a second, duplicate error message. This situation arises when the
2173 programmer does something like:
2174 foo .req r0
2175 Foo .req r1
2176 The second .req creates the "Foo" alias but then fails to create
2177 the artificial FOO alias because it has already been created by the
2178 first .req. */
2179 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2180 return TRUE;
2181 }
2182
2183 for (p = nbuf; *p; p++)
2184 *p = TOLOWER (*p);
2185
2186 if (strncmp (nbuf, newname, nlen))
2187 insert_reg_alias (nbuf, old->number, old->type);
2188 }
2189
2190 return TRUE;
2191 }
2192
2193 /* Create a Neon typed/indexed register alias using directives, e.g.:
2194 X .dn d5.s32[1]
2195 Y .qn 6.s16
2196 Z .dn d7
2197 T .dn Z[0]
2198 These typed registers can be used instead of the types specified after the
2199 Neon mnemonic, so long as all operands given have types. Types can also be
2200 specified directly, e.g.:
2201 vadd d0.s32, d1.s32, d2.s32 */
2202
2203 static bfd_boolean
2204 create_neon_reg_alias (char *newname, char *p)
2205 {
2206 enum arm_reg_type basetype;
2207 struct reg_entry *basereg;
2208 struct reg_entry mybasereg;
2209 struct neon_type ntype;
2210 struct neon_typed_alias typeinfo;
2211 char *namebuf, *nameend;
2212 int namelen;
2213
2214 typeinfo.defined = 0;
2215 typeinfo.eltype.type = NT_invtype;
2216 typeinfo.eltype.size = -1;
2217 typeinfo.index = -1;
2218
2219 nameend = p;
2220
2221 if (strncmp (p, " .dn ", 5) == 0)
2222 basetype = REG_TYPE_VFD;
2223 else if (strncmp (p, " .qn ", 5) == 0)
2224 basetype = REG_TYPE_NQ;
2225 else
2226 return FALSE;
2227
2228 p += 5;
2229
2230 if (*p == '\0')
2231 return FALSE;
2232
2233 basereg = arm_reg_parse_multi (&p);
2234
2235 if (basereg && basereg->type != basetype)
2236 {
2237 as_bad (_("bad type for register"));
2238 return FALSE;
2239 }
2240
2241 if (basereg == NULL)
2242 {
2243 expressionS exp;
2244 /* Try parsing as an integer. */
2245 my_get_expression (&exp, &p, GE_NO_PREFIX);
2246 if (exp.X_op != O_constant)
2247 {
2248 as_bad (_("expression must be constant"));
2249 return FALSE;
2250 }
2251 basereg = &mybasereg;
2252 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2253 : exp.X_add_number;
2254 basereg->neon = 0;
2255 }
2256
2257 if (basereg->neon)
2258 typeinfo = *basereg->neon;
2259
2260 if (parse_neon_type (&ntype, &p) == SUCCESS)
2261 {
2262 /* We got a type. */
2263 if (typeinfo.defined & NTA_HASTYPE)
2264 {
2265 as_bad (_("can't redefine the type of a register alias"));
2266 return FALSE;
2267 }
2268
2269 typeinfo.defined |= NTA_HASTYPE;
2270 if (ntype.elems != 1)
2271 {
2272 as_bad (_("you must specify a single type only"));
2273 return FALSE;
2274 }
2275 typeinfo.eltype = ntype.el[0];
2276 }
2277
2278 if (skip_past_char (&p, '[') == SUCCESS)
2279 {
2280 expressionS exp;
2281 /* We got a scalar index. */
2282
2283 if (typeinfo.defined & NTA_HASINDEX)
2284 {
2285 as_bad (_("can't redefine the index of a scalar alias"));
2286 return FALSE;
2287 }
2288
2289 my_get_expression (&exp, &p, GE_NO_PREFIX);
2290
2291 if (exp.X_op != O_constant)
2292 {
2293 as_bad (_("scalar index must be constant"));
2294 return FALSE;
2295 }
2296
2297 typeinfo.defined |= NTA_HASINDEX;
2298 typeinfo.index = exp.X_add_number;
2299
2300 if (skip_past_char (&p, ']') == FAIL)
2301 {
2302 as_bad (_("expecting ]"));
2303 return FALSE;
2304 }
2305 }
2306
2307 namelen = nameend - newname;
2308 namebuf = (char *) alloca (namelen + 1);
2309 strncpy (namebuf, newname, namelen);
2310 namebuf[namelen] = '\0';
2311
2312 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2313 typeinfo.defined != 0 ? &typeinfo : NULL);
2314
2315 /* Insert name in all uppercase. */
2316 for (p = namebuf; *p; p++)
2317 *p = TOUPPER (*p);
2318
2319 if (strncmp (namebuf, newname, namelen))
2320 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2321 typeinfo.defined != 0 ? &typeinfo : NULL);
2322
2323 /* Insert name in all lowercase. */
2324 for (p = namebuf; *p; p++)
2325 *p = TOLOWER (*p);
2326
2327 if (strncmp (namebuf, newname, namelen))
2328 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2329 typeinfo.defined != 0 ? &typeinfo : NULL);
2330
2331 return TRUE;
2332 }
2333
2334 /* Should never be called, as .req goes between the alias and the
2335 register name, not at the beginning of the line. */
2336
2337 static void
2338 s_req (int a ATTRIBUTE_UNUSED)
2339 {
2340 as_bad (_("invalid syntax for .req directive"));
2341 }
2342
2343 static void
2344 s_dn (int a ATTRIBUTE_UNUSED)
2345 {
2346 as_bad (_("invalid syntax for .dn directive"));
2347 }
2348
2349 static void
2350 s_qn (int a ATTRIBUTE_UNUSED)
2351 {
2352 as_bad (_("invalid syntax for .qn directive"));
2353 }
2354
2355 /* The .unreq directive deletes an alias which was previously defined
2356 by .req. For example:
2357
2358 my_alias .req r11
2359 .unreq my_alias */
2360
2361 static void
2362 s_unreq (int a ATTRIBUTE_UNUSED)
2363 {
2364 char * name;
2365 char saved_char;
2366
2367 name = input_line_pointer;
2368
2369 while (*input_line_pointer != 0
2370 && *input_line_pointer != ' '
2371 && *input_line_pointer != '\n')
2372 ++input_line_pointer;
2373
2374 saved_char = *input_line_pointer;
2375 *input_line_pointer = 0;
2376
2377 if (!*name)
2378 as_bad (_("invalid syntax for .unreq directive"));
2379 else
2380 {
2381 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2382 name);
2383
2384 if (!reg)
2385 as_bad (_("unknown register alias '%s'"), name);
2386 else if (reg->builtin)
2387 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2388 name);
2389 else
2390 {
2391 char * p;
2392 char * nbuf;
2393
2394 hash_delete (arm_reg_hsh, name, FALSE);
2395 free ((char *) reg->name);
2396 if (reg->neon)
2397 free (reg->neon);
2398 free (reg);
2399
2400 /* Also locate the all upper case and all lower case versions.
2401 Do not complain if we cannot find one or the other as it
2402 was probably deleted above. */
2403
2404 nbuf = strdup (name);
2405 for (p = nbuf; *p; p++)
2406 *p = TOUPPER (*p);
2407 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2408 if (reg)
2409 {
2410 hash_delete (arm_reg_hsh, nbuf, FALSE);
2411 free ((char *) reg->name);
2412 if (reg->neon)
2413 free (reg->neon);
2414 free (reg);
2415 }
2416
2417 for (p = nbuf; *p; p++)
2418 *p = TOLOWER (*p);
2419 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2420 if (reg)
2421 {
2422 hash_delete (arm_reg_hsh, nbuf, FALSE);
2423 free ((char *) reg->name);
2424 if (reg->neon)
2425 free (reg->neon);
2426 free (reg);
2427 }
2428
2429 free (nbuf);
2430 }
2431 }
2432
2433 *input_line_pointer = saved_char;
2434 demand_empty_rest_of_line ();
2435 }
2436
2437 /* Directives: Instruction set selection. */
2438
2439 #ifdef OBJ_ELF
2440 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2441 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2442 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2443 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2444
2445 /* Create a new mapping symbol for the transition to STATE. */
2446
2447 static void
2448 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2449 {
2450 symbolS * symbolP;
2451 const char * symname;
2452 int type;
2453
2454 switch (state)
2455 {
2456 case MAP_DATA:
2457 symname = "$d";
2458 type = BSF_NO_FLAGS;
2459 break;
2460 case MAP_ARM:
2461 symname = "$a";
2462 type = BSF_NO_FLAGS;
2463 break;
2464 case MAP_THUMB:
2465 symname = "$t";
2466 type = BSF_NO_FLAGS;
2467 break;
2468 default:
2469 abort ();
2470 }
2471
2472 symbolP = symbol_new (symname, now_seg, value, frag);
2473 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2474
2475 switch (state)
2476 {
2477 case MAP_ARM:
2478 THUMB_SET_FUNC (symbolP, 0);
2479 ARM_SET_THUMB (symbolP, 0);
2480 ARM_SET_INTERWORK (symbolP, support_interwork);
2481 break;
2482
2483 case MAP_THUMB:
2484 THUMB_SET_FUNC (symbolP, 1);
2485 ARM_SET_THUMB (symbolP, 1);
2486 ARM_SET_INTERWORK (symbolP, support_interwork);
2487 break;
2488
2489 case MAP_DATA:
2490 default:
2491 break;
2492 }
2493
2494 /* Save the mapping symbols for future reference. Also check that
2495 we do not place two mapping symbols at the same offset within a
2496 frag. We'll handle overlap between frags in
2497 check_mapping_symbols. */
2498 if (value == 0)
2499 {
2500 know (frag->tc_frag_data.first_map == NULL);
2501 frag->tc_frag_data.first_map = symbolP;
2502 }
2503 if (frag->tc_frag_data.last_map != NULL)
2504 know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
2505 frag->tc_frag_data.last_map = symbolP;
2506 }
2507
2508 /* We must sometimes convert a region marked as code to data during
2509 code alignment, if an odd number of bytes have to be padded. The
2510 code mapping symbol is pushed to an aligned address. */
2511
2512 static void
2513 insert_data_mapping_symbol (enum mstate state,
2514 valueT value, fragS *frag, offsetT bytes)
2515 {
2516 /* If there was already a mapping symbol, remove it. */
2517 if (frag->tc_frag_data.last_map != NULL
2518 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2519 {
2520 symbolS *symp = frag->tc_frag_data.last_map;
2521
2522 if (value == 0)
2523 {
2524 know (frag->tc_frag_data.first_map == symp);
2525 frag->tc_frag_data.first_map = NULL;
2526 }
2527 frag->tc_frag_data.last_map = NULL;
2528 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2529 }
2530
2531 make_mapping_symbol (MAP_DATA, value, frag);
2532 make_mapping_symbol (state, value + bytes, frag);
2533 }
2534
2535 static void mapping_state_2 (enum mstate state, int max_chars);
2536
2537 /* Set the mapping state to STATE. Only call this when about to
2538 emit some STATE bytes to the file. */
2539
2540 void
2541 mapping_state (enum mstate state)
2542 {
2543 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2544
2545 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2546
2547 if (mapstate == state)
2548 /* The mapping symbol has already been emitted.
2549 There is nothing else to do. */
2550 return;
2551 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2552 /* This case will be evaluated later in the next else. */
2553 return;
2554 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2555 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2556 {
2557 /* Only add the symbol if the offset is > 0:
2558 if we're at the first frag, check it's size > 0;
2559 if we're not at the first frag, then for sure
2560 the offset is > 0. */
2561 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2562 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2563
2564 if (add_symbol)
2565 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2566 }
2567
2568 mapping_state_2 (state, 0);
2569 #undef TRANSITION
2570 }
2571
2572 /* Same as mapping_state, but MAX_CHARS bytes have already been
2573 allocated. Put the mapping symbol that far back. */
2574
2575 static void
2576 mapping_state_2 (enum mstate state, int max_chars)
2577 {
2578 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2579
2580 if (!SEG_NORMAL (now_seg))
2581 return;
2582
2583 if (mapstate == state)
2584 /* The mapping symbol has already been emitted.
2585 There is nothing else to do. */
2586 return;
2587
2588 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2589 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2590 }
2591 #else
2592 #define mapping_state(x) ((void)0)
2593 #define mapping_state_2(x, y) ((void)0)
2594 #endif
2595
2596 /* Find the real, Thumb encoded start of a Thumb function. */
2597
2598 #ifdef OBJ_COFF
2599 static symbolS *
2600 find_real_start (symbolS * symbolP)
2601 {
2602 char * real_start;
2603 const char * name = S_GET_NAME (symbolP);
2604 symbolS * new_target;
2605
2606 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2607 #define STUB_NAME ".real_start_of"
2608
2609 if (name == NULL)
2610 abort ();
2611
2612 /* The compiler may generate BL instructions to local labels because
2613 it needs to perform a branch to a far away location. These labels
2614 do not have a corresponding ".real_start_of" label. We check
2615 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2616 the ".real_start_of" convention for nonlocal branches. */
2617 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2618 return symbolP;
2619
2620 real_start = ACONCAT ((STUB_NAME, name, NULL));
2621 new_target = symbol_find (real_start);
2622
2623 if (new_target == NULL)
2624 {
2625 as_warn (_("Failed to find real start of function: %s\n"), name);
2626 new_target = symbolP;
2627 }
2628
2629 return new_target;
2630 }
2631 #endif
2632
2633 static void
2634 opcode_select (int width)
2635 {
2636 switch (width)
2637 {
2638 case 16:
2639 if (! thumb_mode)
2640 {
2641 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2642 as_bad (_("selected processor does not support THUMB opcodes"));
2643
2644 thumb_mode = 1;
2645 /* No need to force the alignment, since we will have been
2646 coming from ARM mode, which is word-aligned. */
2647 record_alignment (now_seg, 1);
2648 }
2649 break;
2650
2651 case 32:
2652 if (thumb_mode)
2653 {
2654 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2655 as_bad (_("selected processor does not support ARM opcodes"));
2656
2657 thumb_mode = 0;
2658
2659 if (!need_pass_2)
2660 frag_align (2, 0, 0);
2661
2662 record_alignment (now_seg, 1);
2663 }
2664 break;
2665
2666 default:
2667 as_bad (_("invalid instruction size selected (%d)"), width);
2668 }
2669 }
2670
2671 static void
2672 s_arm (int ignore ATTRIBUTE_UNUSED)
2673 {
2674 opcode_select (32);
2675 demand_empty_rest_of_line ();
2676 }
2677
2678 static void
2679 s_thumb (int ignore ATTRIBUTE_UNUSED)
2680 {
2681 opcode_select (16);
2682 demand_empty_rest_of_line ();
2683 }
2684
2685 static void
2686 s_code (int unused ATTRIBUTE_UNUSED)
2687 {
2688 int temp;
2689
2690 temp = get_absolute_expression ();
2691 switch (temp)
2692 {
2693 case 16:
2694 case 32:
2695 opcode_select (temp);
2696 break;
2697
2698 default:
2699 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2700 }
2701 }
2702
2703 static void
2704 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2705 {
2706 /* If we are not already in thumb mode go into it, EVEN if
2707 the target processor does not support thumb instructions.
2708 This is used by gcc/config/arm/lib1funcs.asm for example
2709 to compile interworking support functions even if the
2710 target processor should not support interworking. */
2711 if (! thumb_mode)
2712 {
2713 thumb_mode = 2;
2714 record_alignment (now_seg, 1);
2715 }
2716
2717 demand_empty_rest_of_line ();
2718 }
2719
2720 static void
2721 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2722 {
2723 s_thumb (0);
2724
2725 /* The following label is the name/address of the start of a Thumb function.
2726 We need to know this for the interworking support. */
2727 label_is_thumb_function_name = TRUE;
2728 }
2729
2730 /* Perform a .set directive, but also mark the alias as
2731 being a thumb function. */
2732
2733 static void
2734 s_thumb_set (int equiv)
2735 {
2736 /* XXX the following is a duplicate of the code for s_set() in read.c
2737 We cannot just call that code as we need to get at the symbol that
2738 is created. */
2739 char * name;
2740 char delim;
2741 char * end_name;
2742 symbolS * symbolP;
2743
2744 /* Especial apologies for the random logic:
2745 This just grew, and could be parsed much more simply!
2746 Dean - in haste. */
2747 name = input_line_pointer;
2748 delim = get_symbol_end ();
2749 end_name = input_line_pointer;
2750 *end_name = delim;
2751
2752 if (*input_line_pointer != ',')
2753 {
2754 *end_name = 0;
2755 as_bad (_("expected comma after name \"%s\""), name);
2756 *end_name = delim;
2757 ignore_rest_of_line ();
2758 return;
2759 }
2760
2761 input_line_pointer++;
2762 *end_name = 0;
2763
2764 if (name[0] == '.' && name[1] == '\0')
2765 {
2766 /* XXX - this should not happen to .thumb_set. */
2767 abort ();
2768 }
2769
2770 if ((symbolP = symbol_find (name)) == NULL
2771 && (symbolP = md_undefined_symbol (name)) == NULL)
2772 {
2773 #ifndef NO_LISTING
2774 /* When doing symbol listings, play games with dummy fragments living
2775 outside the normal fragment chain to record the file and line info
2776 for this symbol. */
2777 if (listing & LISTING_SYMBOLS)
2778 {
2779 extern struct list_info_struct * listing_tail;
2780 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2781
2782 memset (dummy_frag, 0, sizeof (fragS));
2783 dummy_frag->fr_type = rs_fill;
2784 dummy_frag->line = listing_tail;
2785 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2786 dummy_frag->fr_symbol = symbolP;
2787 }
2788 else
2789 #endif
2790 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2791
2792 #ifdef OBJ_COFF
2793 /* "set" symbols are local unless otherwise specified. */
2794 SF_SET_LOCAL (symbolP);
2795 #endif /* OBJ_COFF */
2796 } /* Make a new symbol. */
2797
2798 symbol_table_insert (symbolP);
2799
2800 * end_name = delim;
2801
2802 if (equiv
2803 && S_IS_DEFINED (symbolP)
2804 && S_GET_SEGMENT (symbolP) != reg_section)
2805 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2806
2807 pseudo_set (symbolP);
2808
2809 demand_empty_rest_of_line ();
2810
2811 /* XXX Now we come to the Thumb specific bit of code. */
2812
2813 THUMB_SET_FUNC (symbolP, 1);
2814 ARM_SET_THUMB (symbolP, 1);
2815 #if defined OBJ_ELF || defined OBJ_COFF
2816 ARM_SET_INTERWORK (symbolP, support_interwork);
2817 #endif
2818 }
2819
2820 /* Directives: Mode selection. */
2821
2822 /* .syntax [unified|divided] - choose the new unified syntax
2823 (same for Arm and Thumb encoding, modulo slight differences in what
2824 can be represented) or the old divergent syntax for each mode. */
2825 static void
2826 s_syntax (int unused ATTRIBUTE_UNUSED)
2827 {
2828 char *name, delim;
2829
2830 name = input_line_pointer;
2831 delim = get_symbol_end ();
2832
2833 if (!strcasecmp (name, "unified"))
2834 unified_syntax = TRUE;
2835 else if (!strcasecmp (name, "divided"))
2836 unified_syntax = FALSE;
2837 else
2838 {
2839 as_bad (_("unrecognized syntax mode \"%s\""), name);
2840 return;
2841 }
2842 *input_line_pointer = delim;
2843 demand_empty_rest_of_line ();
2844 }
2845
2846 /* Directives: sectioning and alignment. */
2847
2848 /* Same as s_align_ptwo but align 0 => align 2. */
2849
2850 static void
2851 s_align (int unused ATTRIBUTE_UNUSED)
2852 {
2853 int temp;
2854 bfd_boolean fill_p;
2855 long temp_fill;
2856 long max_alignment = 15;
2857
2858 temp = get_absolute_expression ();
2859 if (temp > max_alignment)
2860 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2861 else if (temp < 0)
2862 {
2863 as_bad (_("alignment negative. 0 assumed."));
2864 temp = 0;
2865 }
2866
2867 if (*input_line_pointer == ',')
2868 {
2869 input_line_pointer++;
2870 temp_fill = get_absolute_expression ();
2871 fill_p = TRUE;
2872 }
2873 else
2874 {
2875 fill_p = FALSE;
2876 temp_fill = 0;
2877 }
2878
2879 if (!temp)
2880 temp = 2;
2881
2882 /* Only make a frag if we HAVE to. */
2883 if (temp && !need_pass_2)
2884 {
2885 if (!fill_p && subseg_text_p (now_seg))
2886 frag_align_code (temp, 0);
2887 else
2888 frag_align (temp, (int) temp_fill, 0);
2889 }
2890 demand_empty_rest_of_line ();
2891
2892 record_alignment (now_seg, temp);
2893 }
2894
2895 static void
2896 s_bss (int ignore ATTRIBUTE_UNUSED)
2897 {
2898 /* We don't support putting frags in the BSS segment, we fake it by
2899 marking in_bss, then looking at s_skip for clues. */
2900 subseg_set (bss_section, 0);
2901 demand_empty_rest_of_line ();
2902
2903 #ifdef md_elf_section_change_hook
2904 md_elf_section_change_hook ();
2905 #endif
2906 }
2907
2908 static void
2909 s_even (int ignore ATTRIBUTE_UNUSED)
2910 {
2911 /* Never make frag if expect extra pass. */
2912 if (!need_pass_2)
2913 frag_align (1, 0, 0);
2914
2915 record_alignment (now_seg, 1);
2916
2917 demand_empty_rest_of_line ();
2918 }
2919
2920 /* Directives: Literal pools. */
2921
2922 static literal_pool *
2923 find_literal_pool (void)
2924 {
2925 literal_pool * pool;
2926
2927 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2928 {
2929 if (pool->section == now_seg
2930 && pool->sub_section == now_subseg)
2931 break;
2932 }
2933
2934 return pool;
2935 }
2936
2937 static literal_pool *
2938 find_or_make_literal_pool (void)
2939 {
2940 /* Next literal pool ID number. */
2941 static unsigned int latest_pool_num = 1;
2942 literal_pool * pool;
2943
2944 pool = find_literal_pool ();
2945
2946 if (pool == NULL)
2947 {
2948 /* Create a new pool. */
2949 pool = (literal_pool *) xmalloc (sizeof (* pool));
2950 if (! pool)
2951 return NULL;
2952
2953 pool->next_free_entry = 0;
2954 pool->section = now_seg;
2955 pool->sub_section = now_subseg;
2956 pool->next = list_of_pools;
2957 pool->symbol = NULL;
2958
2959 /* Add it to the list. */
2960 list_of_pools = pool;
2961 }
2962
2963 /* New pools, and emptied pools, will have a NULL symbol. */
2964 if (pool->symbol == NULL)
2965 {
2966 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2967 (valueT) 0, &zero_address_frag);
2968 pool->id = latest_pool_num ++;
2969 }
2970
2971 /* Done. */
2972 return pool;
2973 }
2974
2975 /* Add the literal in the global 'inst'
2976 structure to the relevant literal pool. */
2977
2978 static int
2979 add_to_lit_pool (void)
2980 {
2981 literal_pool * pool;
2982 unsigned int entry;
2983
2984 pool = find_or_make_literal_pool ();
2985
2986 /* Check if this literal value is already in the pool. */
2987 for (entry = 0; entry < pool->next_free_entry; entry ++)
2988 {
2989 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2990 && (inst.reloc.exp.X_op == O_constant)
2991 && (pool->literals[entry].X_add_number
2992 == inst.reloc.exp.X_add_number)
2993 && (pool->literals[entry].X_unsigned
2994 == inst.reloc.exp.X_unsigned))
2995 break;
2996
2997 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2998 && (inst.reloc.exp.X_op == O_symbol)
2999 && (pool->literals[entry].X_add_number
3000 == inst.reloc.exp.X_add_number)
3001 && (pool->literals[entry].X_add_symbol
3002 == inst.reloc.exp.X_add_symbol)
3003 && (pool->literals[entry].X_op_symbol
3004 == inst.reloc.exp.X_op_symbol))
3005 break;
3006 }
3007
3008 /* Do we need to create a new entry? */
3009 if (entry == pool->next_free_entry)
3010 {
3011 if (entry >= MAX_LITERAL_POOL_SIZE)
3012 {
3013 inst.error = _("literal pool overflow");
3014 return FAIL;
3015 }
3016
3017 pool->literals[entry] = inst.reloc.exp;
3018 pool->next_free_entry += 1;
3019 }
3020
3021 inst.reloc.exp.X_op = O_symbol;
3022 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3023 inst.reloc.exp.X_add_symbol = pool->symbol;
3024
3025 return SUCCESS;
3026 }
3027
3028 /* Can't use symbol_new here, so have to create a symbol and then at
3029 a later date assign it a value. Thats what these functions do. */
3030
3031 static void
3032 symbol_locate (symbolS * symbolP,
3033 const char * name, /* It is copied, the caller can modify. */
3034 segT segment, /* Segment identifier (SEG_<something>). */
3035 valueT valu, /* Symbol value. */
3036 fragS * frag) /* Associated fragment. */
3037 {
3038 unsigned int name_length;
3039 char * preserved_copy_of_name;
3040
3041 name_length = strlen (name) + 1; /* +1 for \0. */
3042 obstack_grow (&notes, name, name_length);
3043 preserved_copy_of_name = (char *) obstack_finish (&notes);
3044
3045 #ifdef tc_canonicalize_symbol_name
3046 preserved_copy_of_name =
3047 tc_canonicalize_symbol_name (preserved_copy_of_name);
3048 #endif
3049
3050 S_SET_NAME (symbolP, preserved_copy_of_name);
3051
3052 S_SET_SEGMENT (symbolP, segment);
3053 S_SET_VALUE (symbolP, valu);
3054 symbol_clear_list_pointers (symbolP);
3055
3056 symbol_set_frag (symbolP, frag);
3057
3058 /* Link to end of symbol chain. */
3059 {
3060 extern int symbol_table_frozen;
3061
3062 if (symbol_table_frozen)
3063 abort ();
3064 }
3065
3066 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3067
3068 obj_symbol_new_hook (symbolP);
3069
3070 #ifdef tc_symbol_new_hook
3071 tc_symbol_new_hook (symbolP);
3072 #endif
3073
3074 #ifdef DEBUG_SYMS
3075 verify_symbol_chain (symbol_rootP, symbol_lastP);
3076 #endif /* DEBUG_SYMS */
3077 }
3078
3079
3080 static void
3081 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3082 {
3083 unsigned int entry;
3084 literal_pool * pool;
3085 char sym_name[20];
3086
3087 pool = find_literal_pool ();
3088 if (pool == NULL
3089 || pool->symbol == NULL
3090 || pool->next_free_entry == 0)
3091 return;
3092
3093 mapping_state (MAP_DATA);
3094
3095 /* Align pool as you have word accesses.
3096 Only make a frag if we have to. */
3097 if (!need_pass_2)
3098 frag_align (2, 0, 0);
3099
3100 record_alignment (now_seg, 2);
3101
3102 sprintf (sym_name, "$$lit_\002%x", pool->id);
3103
3104 symbol_locate (pool->symbol, sym_name, now_seg,
3105 (valueT) frag_now_fix (), frag_now);
3106 symbol_table_insert (pool->symbol);
3107
3108 ARM_SET_THUMB (pool->symbol, thumb_mode);
3109
3110 #if defined OBJ_COFF || defined OBJ_ELF
3111 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3112 #endif
3113
3114 for (entry = 0; entry < pool->next_free_entry; entry ++)
3115 /* First output the expression in the instruction to the pool. */
3116 emit_expr (&(pool->literals[entry]), 4); /* .word */
3117
3118 /* Mark the pool as empty. */
3119 pool->next_free_entry = 0;
3120 pool->symbol = NULL;
3121 }
3122
3123 #ifdef OBJ_ELF
3124 /* Forward declarations for functions below, in the MD interface
3125 section. */
3126 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3127 static valueT create_unwind_entry (int);
3128 static void start_unwind_section (const segT, int);
3129 static void add_unwind_opcode (valueT, int);
3130 static void flush_pending_unwind (void);
3131
3132 /* Directives: Data. */
3133
3134 static void
3135 s_arm_elf_cons (int nbytes)
3136 {
3137 expressionS exp;
3138
3139 #ifdef md_flush_pending_output
3140 md_flush_pending_output ();
3141 #endif
3142
3143 if (is_it_end_of_statement ())
3144 {
3145 demand_empty_rest_of_line ();
3146 return;
3147 }
3148
3149 #ifdef md_cons_align
3150 md_cons_align (nbytes);
3151 #endif
3152
3153 mapping_state (MAP_DATA);
3154 do
3155 {
3156 int reloc;
3157 char *base = input_line_pointer;
3158
3159 expression (& exp);
3160
3161 if (exp.X_op != O_symbol)
3162 emit_expr (&exp, (unsigned int) nbytes);
3163 else
3164 {
3165 char *before_reloc = input_line_pointer;
3166 reloc = parse_reloc (&input_line_pointer);
3167 if (reloc == -1)
3168 {
3169 as_bad (_("unrecognized relocation suffix"));
3170 ignore_rest_of_line ();
3171 return;
3172 }
3173 else if (reloc == BFD_RELOC_UNUSED)
3174 emit_expr (&exp, (unsigned int) nbytes);
3175 else
3176 {
3177 reloc_howto_type *howto = (reloc_howto_type *)
3178 bfd_reloc_type_lookup (stdoutput,
3179 (bfd_reloc_code_real_type) reloc);
3180 int size = bfd_get_reloc_size (howto);
3181
3182 if (reloc == BFD_RELOC_ARM_PLT32)
3183 {
3184 as_bad (_("(plt) is only valid on branch targets"));
3185 reloc = BFD_RELOC_UNUSED;
3186 size = 0;
3187 }
3188
3189 if (size > nbytes)
3190 as_bad (_("%s relocations do not fit in %d bytes"),
3191 howto->name, nbytes);
3192 else
3193 {
3194 /* We've parsed an expression stopping at O_symbol.
3195 But there may be more expression left now that we
3196 have parsed the relocation marker. Parse it again.
3197 XXX Surely there is a cleaner way to do this. */
3198 char *p = input_line_pointer;
3199 int offset;
3200 char *save_buf = (char *) alloca (input_line_pointer - base);
3201 memcpy (save_buf, base, input_line_pointer - base);
3202 memmove (base + (input_line_pointer - before_reloc),
3203 base, before_reloc - base);
3204
3205 input_line_pointer = base + (input_line_pointer-before_reloc);
3206 expression (&exp);
3207 memcpy (base, save_buf, p - base);
3208
3209 offset = nbytes - size;
3210 p = frag_more ((int) nbytes);
3211 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3212 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3213 }
3214 }
3215 }
3216 }
3217 while (*input_line_pointer++ == ',');
3218
3219 /* Put terminator back into stream. */
3220 input_line_pointer --;
3221 demand_empty_rest_of_line ();
3222 }
3223
3224 /* Emit an expression containing a 32-bit thumb instruction.
3225 Implementation based on put_thumb32_insn. */
3226
3227 static void
3228 emit_thumb32_expr (expressionS * exp)
3229 {
3230 expressionS exp_high = *exp;
3231
3232 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3233 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3234 exp->X_add_number &= 0xffff;
3235 emit_expr (exp, (unsigned int) THUMB_SIZE);
3236 }
3237
3238 /* Guess the instruction size based on the opcode. */
3239
3240 static int
3241 thumb_insn_size (int opcode)
3242 {
3243 if ((unsigned int) opcode < 0xe800u)
3244 return 2;
3245 else if ((unsigned int) opcode >= 0xe8000000u)
3246 return 4;
3247 else
3248 return 0;
3249 }
3250
3251 static bfd_boolean
3252 emit_insn (expressionS *exp, int nbytes)
3253 {
3254 int size = 0;
3255
3256 if (exp->X_op == O_constant)
3257 {
3258 size = nbytes;
3259
3260 if (size == 0)
3261 size = thumb_insn_size (exp->X_add_number);
3262
3263 if (size != 0)
3264 {
3265 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3266 {
3267 as_bad (_(".inst.n operand too big. "\
3268 "Use .inst.w instead"));
3269 size = 0;
3270 }
3271 else
3272 {
3273 if (now_it.state == AUTOMATIC_IT_BLOCK)
3274 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3275 else
3276 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3277
3278 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3279 emit_thumb32_expr (exp);
3280 else
3281 emit_expr (exp, (unsigned int) size);
3282
3283 it_fsm_post_encode ();
3284 }
3285 }
3286 else
3287 as_bad (_("cannot determine Thumb instruction size. " \
3288 "Use .inst.n/.inst.w instead"));
3289 }
3290 else
3291 as_bad (_("constant expression required"));
3292
3293 return (size != 0);
3294 }
3295
3296 /* Like s_arm_elf_cons but do not use md_cons_align and
3297 set the mapping state to MAP_ARM/MAP_THUMB. */
3298
3299 static void
3300 s_arm_elf_inst (int nbytes)
3301 {
3302 if (is_it_end_of_statement ())
3303 {
3304 demand_empty_rest_of_line ();
3305 return;
3306 }
3307
3308 /* Calling mapping_state () here will not change ARM/THUMB,
3309 but will ensure not to be in DATA state. */
3310
3311 if (thumb_mode)
3312 mapping_state (MAP_THUMB);
3313 else
3314 {
3315 if (nbytes != 0)
3316 {
3317 as_bad (_("width suffixes are invalid in ARM mode"));
3318 ignore_rest_of_line ();
3319 return;
3320 }
3321
3322 nbytes = 4;
3323
3324 mapping_state (MAP_ARM);
3325 }
3326
3327 do
3328 {
3329 expressionS exp;
3330
3331 expression (& exp);
3332
3333 if (! emit_insn (& exp, nbytes))
3334 {
3335 ignore_rest_of_line ();
3336 return;
3337 }
3338 }
3339 while (*input_line_pointer++ == ',');
3340
3341 /* Put terminator back into stream. */
3342 input_line_pointer --;
3343 demand_empty_rest_of_line ();
3344 }
3345
3346 /* Parse a .rel31 directive. */
3347
3348 static void
3349 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3350 {
3351 expressionS exp;
3352 char *p;
3353 valueT highbit;
3354
3355 highbit = 0;
3356 if (*input_line_pointer == '1')
3357 highbit = 0x80000000;
3358 else if (*input_line_pointer != '0')
3359 as_bad (_("expected 0 or 1"));
3360
3361 input_line_pointer++;
3362 if (*input_line_pointer != ',')
3363 as_bad (_("missing comma"));
3364 input_line_pointer++;
3365
3366 #ifdef md_flush_pending_output
3367 md_flush_pending_output ();
3368 #endif
3369
3370 #ifdef md_cons_align
3371 md_cons_align (4);
3372 #endif
3373
3374 mapping_state (MAP_DATA);
3375
3376 expression (&exp);
3377
3378 p = frag_more (4);
3379 md_number_to_chars (p, highbit, 4);
3380 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3381 BFD_RELOC_ARM_PREL31);
3382
3383 demand_empty_rest_of_line ();
3384 }
3385
3386 /* Directives: AEABI stack-unwind tables. */
3387
3388 /* Parse an unwind_fnstart directive. Simply records the current location. */
3389
3390 static void
3391 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3392 {
3393 demand_empty_rest_of_line ();
3394 if (unwind.proc_start)
3395 {
3396 as_bad (_("duplicate .fnstart directive"));
3397 return;
3398 }
3399
3400 /* Mark the start of the function. */
3401 unwind.proc_start = expr_build_dot ();
3402
3403 /* Reset the rest of the unwind info. */
3404 unwind.opcode_count = 0;
3405 unwind.table_entry = NULL;
3406 unwind.personality_routine = NULL;
3407 unwind.personality_index = -1;
3408 unwind.frame_size = 0;
3409 unwind.fp_offset = 0;
3410 unwind.fp_reg = REG_SP;
3411 unwind.fp_used = 0;
3412 unwind.sp_restored = 0;
3413 }
3414
3415
3416 /* Parse a handlerdata directive. Creates the exception handling table entry
3417 for the function. */
3418
3419 static void
3420 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3421 {
3422 demand_empty_rest_of_line ();
3423 if (!unwind.proc_start)
3424 as_bad (MISSING_FNSTART);
3425
3426 if (unwind.table_entry)
3427 as_bad (_("duplicate .handlerdata directive"));
3428
3429 create_unwind_entry (1);
3430 }
3431
3432 /* Parse an unwind_fnend directive. Generates the index table entry. */
3433
3434 static void
3435 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3436 {
3437 long where;
3438 char *ptr;
3439 valueT val;
3440 unsigned int marked_pr_dependency;
3441
3442 demand_empty_rest_of_line ();
3443
3444 if (!unwind.proc_start)
3445 {
3446 as_bad (_(".fnend directive without .fnstart"));
3447 return;
3448 }
3449
3450 /* Add eh table entry. */
3451 if (unwind.table_entry == NULL)
3452 val = create_unwind_entry (0);
3453 else
3454 val = 0;
3455
3456 /* Add index table entry. This is two words. */
3457 start_unwind_section (unwind.saved_seg, 1);
3458 frag_align (2, 0, 0);
3459 record_alignment (now_seg, 2);
3460
3461 ptr = frag_more (8);
3462 where = frag_now_fix () - 8;
3463
3464 /* Self relative offset of the function start. */
3465 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3466 BFD_RELOC_ARM_PREL31);
3467
3468 /* Indicate dependency on EHABI-defined personality routines to the
3469 linker, if it hasn't been done already. */
3470 marked_pr_dependency
3471 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3472 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3473 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3474 {
3475 static const char *const name[] =
3476 {
3477 "__aeabi_unwind_cpp_pr0",
3478 "__aeabi_unwind_cpp_pr1",
3479 "__aeabi_unwind_cpp_pr2"
3480 };
3481 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3482 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3483 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3484 |= 1 << unwind.personality_index;
3485 }
3486
3487 if (val)
3488 /* Inline exception table entry. */
3489 md_number_to_chars (ptr + 4, val, 4);
3490 else
3491 /* Self relative offset of the table entry. */
3492 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3493 BFD_RELOC_ARM_PREL31);
3494
3495 /* Restore the original section. */
3496 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3497
3498 unwind.proc_start = NULL;
3499 }
3500
3501
3502 /* Parse an unwind_cantunwind directive. */
3503
3504 static void
3505 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3506 {
3507 demand_empty_rest_of_line ();
3508 if (!unwind.proc_start)
3509 as_bad (MISSING_FNSTART);
3510
3511 if (unwind.personality_routine || unwind.personality_index != -1)
3512 as_bad (_("personality routine specified for cantunwind frame"));
3513
3514 unwind.personality_index = -2;
3515 }
3516
3517
3518 /* Parse a personalityindex directive. */
3519
3520 static void
3521 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3522 {
3523 expressionS exp;
3524
3525 if (!unwind.proc_start)
3526 as_bad (MISSING_FNSTART);
3527
3528 if (unwind.personality_routine || unwind.personality_index != -1)
3529 as_bad (_("duplicate .personalityindex directive"));
3530
3531 expression (&exp);
3532
3533 if (exp.X_op != O_constant
3534 || exp.X_add_number < 0 || exp.X_add_number > 15)
3535 {
3536 as_bad (_("bad personality routine number"));
3537 ignore_rest_of_line ();
3538 return;
3539 }
3540
3541 unwind.personality_index = exp.X_add_number;
3542
3543 demand_empty_rest_of_line ();
3544 }
3545
3546
3547 /* Parse a personality directive. */
3548
3549 static void
3550 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3551 {
3552 char *name, *p, c;
3553
3554 if (!unwind.proc_start)
3555 as_bad (MISSING_FNSTART);
3556
3557 if (unwind.personality_routine || unwind.personality_index != -1)
3558 as_bad (_("duplicate .personality directive"));
3559
3560 name = input_line_pointer;
3561 c = get_symbol_end ();
3562 p = input_line_pointer;
3563 unwind.personality_routine = symbol_find_or_make (name);
3564 *p = c;
3565 demand_empty_rest_of_line ();
3566 }
3567
3568
3569 /* Parse a directive saving core registers. */
3570
3571 static void
3572 s_arm_unwind_save_core (void)
3573 {
3574 valueT op;
3575 long range;
3576 int n;
3577
3578 range = parse_reg_list (&input_line_pointer);
3579 if (range == FAIL)
3580 {
3581 as_bad (_("expected register list"));
3582 ignore_rest_of_line ();
3583 return;
3584 }
3585
3586 demand_empty_rest_of_line ();
3587
3588 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3589 into .unwind_save {..., sp...}. We aren't bothered about the value of
3590 ip because it is clobbered by calls. */
3591 if (unwind.sp_restored && unwind.fp_reg == 12
3592 && (range & 0x3000) == 0x1000)
3593 {
3594 unwind.opcode_count--;
3595 unwind.sp_restored = 0;
3596 range = (range | 0x2000) & ~0x1000;
3597 unwind.pending_offset = 0;
3598 }
3599
3600 /* Pop r4-r15. */
3601 if (range & 0xfff0)
3602 {
3603 /* See if we can use the short opcodes. These pop a block of up to 8
3604 registers starting with r4, plus maybe r14. */
3605 for (n = 0; n < 8; n++)
3606 {
3607 /* Break at the first non-saved register. */
3608 if ((range & (1 << (n + 4))) == 0)
3609 break;
3610 }
3611 /* See if there are any other bits set. */
3612 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3613 {
3614 /* Use the long form. */
3615 op = 0x8000 | ((range >> 4) & 0xfff);
3616 add_unwind_opcode (op, 2);
3617 }
3618 else
3619 {
3620 /* Use the short form. */
3621 if (range & 0x4000)
3622 op = 0xa8; /* Pop r14. */
3623 else
3624 op = 0xa0; /* Do not pop r14. */
3625 op |= (n - 1);
3626 add_unwind_opcode (op, 1);
3627 }
3628 }
3629
3630 /* Pop r0-r3. */
3631 if (range & 0xf)
3632 {
3633 op = 0xb100 | (range & 0xf);
3634 add_unwind_opcode (op, 2);
3635 }
3636
3637 /* Record the number of bytes pushed. */
3638 for (n = 0; n < 16; n++)
3639 {
3640 if (range & (1 << n))
3641 unwind.frame_size += 4;
3642 }
3643 }
3644
3645
3646 /* Parse a directive saving FPA registers. */
3647
3648 static void
3649 s_arm_unwind_save_fpa (int reg)
3650 {
3651 expressionS exp;
3652 int num_regs;
3653 valueT op;
3654
3655 /* Get Number of registers to transfer. */
3656 if (skip_past_comma (&input_line_pointer) != FAIL)
3657 expression (&exp);
3658 else
3659 exp.X_op = O_illegal;
3660
3661 if (exp.X_op != O_constant)
3662 {
3663 as_bad (_("expected , <constant>"));
3664 ignore_rest_of_line ();
3665 return;
3666 }
3667
3668 num_regs = exp.X_add_number;
3669
3670 if (num_regs < 1 || num_regs > 4)
3671 {
3672 as_bad (_("number of registers must be in the range [1:4]"));
3673 ignore_rest_of_line ();
3674 return;
3675 }
3676
3677 demand_empty_rest_of_line ();
3678
3679 if (reg == 4)
3680 {
3681 /* Short form. */
3682 op = 0xb4 | (num_regs - 1);
3683 add_unwind_opcode (op, 1);
3684 }
3685 else
3686 {
3687 /* Long form. */
3688 op = 0xc800 | (reg << 4) | (num_regs - 1);
3689 add_unwind_opcode (op, 2);
3690 }
3691 unwind.frame_size += num_regs * 12;
3692 }
3693
3694
3695 /* Parse a directive saving VFP registers for ARMv6 and above. */
3696
3697 static void
3698 s_arm_unwind_save_vfp_armv6 (void)
3699 {
3700 int count;
3701 unsigned int start;
3702 valueT op;
3703 int num_vfpv3_regs = 0;
3704 int num_regs_below_16;
3705
3706 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3707 if (count == FAIL)
3708 {
3709 as_bad (_("expected register list"));
3710 ignore_rest_of_line ();
3711 return;
3712 }
3713
3714 demand_empty_rest_of_line ();
3715
3716 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3717 than FSTMX/FLDMX-style ones). */
3718
3719 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3720 if (start >= 16)
3721 num_vfpv3_regs = count;
3722 else if (start + count > 16)
3723 num_vfpv3_regs = start + count - 16;
3724
3725 if (num_vfpv3_regs > 0)
3726 {
3727 int start_offset = start > 16 ? start - 16 : 0;
3728 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3729 add_unwind_opcode (op, 2);
3730 }
3731
3732 /* Generate opcode for registers numbered in the range 0 .. 15. */
3733 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3734 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3735 if (num_regs_below_16 > 0)
3736 {
3737 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3738 add_unwind_opcode (op, 2);
3739 }
3740
3741 unwind.frame_size += count * 8;
3742 }
3743
3744
3745 /* Parse a directive saving VFP registers for pre-ARMv6. */
3746
3747 static void
3748 s_arm_unwind_save_vfp (void)
3749 {
3750 int count;
3751 unsigned int reg;
3752 valueT op;
3753
3754 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3755 if (count == FAIL)
3756 {
3757 as_bad (_("expected register list"));
3758 ignore_rest_of_line ();
3759 return;
3760 }
3761
3762 demand_empty_rest_of_line ();
3763
3764 if (reg == 8)
3765 {
3766 /* Short form. */
3767 op = 0xb8 | (count - 1);
3768 add_unwind_opcode (op, 1);
3769 }
3770 else
3771 {
3772 /* Long form. */
3773 op = 0xb300 | (reg << 4) | (count - 1);
3774 add_unwind_opcode (op, 2);
3775 }
3776 unwind.frame_size += count * 8 + 4;
3777 }
3778
3779
3780 /* Parse a directive saving iWMMXt data registers. */
3781
3782 static void
3783 s_arm_unwind_save_mmxwr (void)
3784 {
3785 int reg;
3786 int hi_reg;
3787 int i;
3788 unsigned mask = 0;
3789 valueT op;
3790
3791 if (*input_line_pointer == '{')
3792 input_line_pointer++;
3793
3794 do
3795 {
3796 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3797
3798 if (reg == FAIL)
3799 {
3800 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3801 goto error;
3802 }
3803
3804 if (mask >> reg)
3805 as_tsktsk (_("register list not in ascending order"));
3806 mask |= 1 << reg;
3807
3808 if (*input_line_pointer == '-')
3809 {
3810 input_line_pointer++;
3811 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3812 if (hi_reg == FAIL)
3813 {
3814 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3815 goto error;
3816 }
3817 else if (reg >= hi_reg)
3818 {
3819 as_bad (_("bad register range"));
3820 goto error;
3821 }
3822 for (; reg < hi_reg; reg++)
3823 mask |= 1 << reg;
3824 }
3825 }
3826 while (skip_past_comma (&input_line_pointer) != FAIL);
3827
3828 if (*input_line_pointer == '}')
3829 input_line_pointer++;
3830
3831 demand_empty_rest_of_line ();
3832
3833 /* Generate any deferred opcodes because we're going to be looking at
3834 the list. */
3835 flush_pending_unwind ();
3836
3837 for (i = 0; i < 16; i++)
3838 {
3839 if (mask & (1 << i))
3840 unwind.frame_size += 8;
3841 }
3842
3843 /* Attempt to combine with a previous opcode. We do this because gcc
3844 likes to output separate unwind directives for a single block of
3845 registers. */
3846 if (unwind.opcode_count > 0)
3847 {
3848 i = unwind.opcodes[unwind.opcode_count - 1];
3849 if ((i & 0xf8) == 0xc0)
3850 {
3851 i &= 7;
3852 /* Only merge if the blocks are contiguous. */
3853 if (i < 6)
3854 {
3855 if ((mask & 0xfe00) == (1 << 9))
3856 {
3857 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3858 unwind.opcode_count--;
3859 }
3860 }
3861 else if (i == 6 && unwind.opcode_count >= 2)
3862 {
3863 i = unwind.opcodes[unwind.opcode_count - 2];
3864 reg = i >> 4;
3865 i &= 0xf;
3866
3867 op = 0xffff << (reg - 1);
3868 if (reg > 0
3869 && ((mask & op) == (1u << (reg - 1))))
3870 {
3871 op = (1 << (reg + i + 1)) - 1;
3872 op &= ~((1 << reg) - 1);
3873 mask |= op;
3874 unwind.opcode_count -= 2;
3875 }
3876 }
3877 }
3878 }
3879
3880 hi_reg = 15;
3881 /* We want to generate opcodes in the order the registers have been
3882 saved, ie. descending order. */
3883 for (reg = 15; reg >= -1; reg--)
3884 {
3885 /* Save registers in blocks. */
3886 if (reg < 0
3887 || !(mask & (1 << reg)))
3888 {
3889 /* We found an unsaved reg. Generate opcodes to save the
3890 preceding block. */
3891 if (reg != hi_reg)
3892 {
3893 if (reg == 9)
3894 {
3895 /* Short form. */
3896 op = 0xc0 | (hi_reg - 10);
3897 add_unwind_opcode (op, 1);
3898 }
3899 else
3900 {
3901 /* Long form. */
3902 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3903 add_unwind_opcode (op, 2);
3904 }
3905 }
3906 hi_reg = reg - 1;
3907 }
3908 }
3909
3910 return;
3911 error:
3912 ignore_rest_of_line ();
3913 }
3914
3915 static void
3916 s_arm_unwind_save_mmxwcg (void)
3917 {
3918 int reg;
3919 int hi_reg;
3920 unsigned mask = 0;
3921 valueT op;
3922
3923 if (*input_line_pointer == '{')
3924 input_line_pointer++;
3925
3926 do
3927 {
3928 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3929
3930 if (reg == FAIL)
3931 {
3932 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3933 goto error;
3934 }
3935
3936 reg -= 8;
3937 if (mask >> reg)
3938 as_tsktsk (_("register list not in ascending order"));
3939 mask |= 1 << reg;
3940
3941 if (*input_line_pointer == '-')
3942 {
3943 input_line_pointer++;
3944 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3945 if (hi_reg == FAIL)
3946 {
3947 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3948 goto error;
3949 }
3950 else if (reg >= hi_reg)
3951 {
3952 as_bad (_("bad register range"));
3953 goto error;
3954 }
3955 for (; reg < hi_reg; reg++)
3956 mask |= 1 << reg;
3957 }
3958 }
3959 while (skip_past_comma (&input_line_pointer) != FAIL);
3960
3961 if (*input_line_pointer == '}')
3962 input_line_pointer++;
3963
3964 demand_empty_rest_of_line ();
3965
3966 /* Generate any deferred opcodes because we're going to be looking at
3967 the list. */
3968 flush_pending_unwind ();
3969
3970 for (reg = 0; reg < 16; reg++)
3971 {
3972 if (mask & (1 << reg))
3973 unwind.frame_size += 4;
3974 }
3975 op = 0xc700 | mask;
3976 add_unwind_opcode (op, 2);
3977 return;
3978 error:
3979 ignore_rest_of_line ();
3980 }
3981
3982
3983 /* Parse an unwind_save directive.
3984 If the argument is non-zero, this is a .vsave directive. */
3985
3986 static void
3987 s_arm_unwind_save (int arch_v6)
3988 {
3989 char *peek;
3990 struct reg_entry *reg;
3991 bfd_boolean had_brace = FALSE;
3992
3993 if (!unwind.proc_start)
3994 as_bad (MISSING_FNSTART);
3995
3996 /* Figure out what sort of save we have. */
3997 peek = input_line_pointer;
3998
3999 if (*peek == '{')
4000 {
4001 had_brace = TRUE;
4002 peek++;
4003 }
4004
4005 reg = arm_reg_parse_multi (&peek);
4006
4007 if (!reg)
4008 {
4009 as_bad (_("register expected"));
4010 ignore_rest_of_line ();
4011 return;
4012 }
4013
4014 switch (reg->type)
4015 {
4016 case REG_TYPE_FN:
4017 if (had_brace)
4018 {
4019 as_bad (_("FPA .unwind_save does not take a register list"));
4020 ignore_rest_of_line ();
4021 return;
4022 }
4023 input_line_pointer = peek;
4024 s_arm_unwind_save_fpa (reg->number);
4025 return;
4026
4027 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4028 case REG_TYPE_VFD:
4029 if (arch_v6)
4030 s_arm_unwind_save_vfp_armv6 ();
4031 else
4032 s_arm_unwind_save_vfp ();
4033 return;
4034 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4035 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4036
4037 default:
4038 as_bad (_(".unwind_save does not support this kind of register"));
4039 ignore_rest_of_line ();
4040 }
4041 }
4042
4043
4044 /* Parse an unwind_movsp directive. */
4045
4046 static void
4047 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4048 {
4049 int reg;
4050 valueT op;
4051 int offset;
4052
4053 if (!unwind.proc_start)
4054 as_bad (MISSING_FNSTART);
4055
4056 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4057 if (reg == FAIL)
4058 {
4059 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4060 ignore_rest_of_line ();
4061 return;
4062 }
4063
4064 /* Optional constant. */
4065 if (skip_past_comma (&input_line_pointer) != FAIL)
4066 {
4067 if (immediate_for_directive (&offset) == FAIL)
4068 return;
4069 }
4070 else
4071 offset = 0;
4072
4073 demand_empty_rest_of_line ();
4074
4075 if (reg == REG_SP || reg == REG_PC)
4076 {
4077 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4078 return;
4079 }
4080
4081 if (unwind.fp_reg != REG_SP)
4082 as_bad (_("unexpected .unwind_movsp directive"));
4083
4084 /* Generate opcode to restore the value. */
4085 op = 0x90 | reg;
4086 add_unwind_opcode (op, 1);
4087
4088 /* Record the information for later. */
4089 unwind.fp_reg = reg;
4090 unwind.fp_offset = unwind.frame_size - offset;
4091 unwind.sp_restored = 1;
4092 }
4093
4094 /* Parse an unwind_pad directive. */
4095
4096 static void
4097 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4098 {
4099 int offset;
4100
4101 if (!unwind.proc_start)
4102 as_bad (MISSING_FNSTART);
4103
4104 if (immediate_for_directive (&offset) == FAIL)
4105 return;
4106
4107 if (offset & 3)
4108 {
4109 as_bad (_("stack increment must be multiple of 4"));
4110 ignore_rest_of_line ();
4111 return;
4112 }
4113
4114 /* Don't generate any opcodes, just record the details for later. */
4115 unwind.frame_size += offset;
4116 unwind.pending_offset += offset;
4117
4118 demand_empty_rest_of_line ();
4119 }
4120
4121 /* Parse an unwind_setfp directive. */
4122
4123 static void
4124 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4125 {
4126 int sp_reg;
4127 int fp_reg;
4128 int offset;
4129
4130 if (!unwind.proc_start)
4131 as_bad (MISSING_FNSTART);
4132
4133 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4134 if (skip_past_comma (&input_line_pointer) == FAIL)
4135 sp_reg = FAIL;
4136 else
4137 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4138
4139 if (fp_reg == FAIL || sp_reg == FAIL)
4140 {
4141 as_bad (_("expected <reg>, <reg>"));
4142 ignore_rest_of_line ();
4143 return;
4144 }
4145
4146 /* Optional constant. */
4147 if (skip_past_comma (&input_line_pointer) != FAIL)
4148 {
4149 if (immediate_for_directive (&offset) == FAIL)
4150 return;
4151 }
4152 else
4153 offset = 0;
4154
4155 demand_empty_rest_of_line ();
4156
4157 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4158 {
4159 as_bad (_("register must be either sp or set by a previous"
4160 "unwind_movsp directive"));
4161 return;
4162 }
4163
4164 /* Don't generate any opcodes, just record the information for later. */
4165 unwind.fp_reg = fp_reg;
4166 unwind.fp_used = 1;
4167 if (sp_reg == REG_SP)
4168 unwind.fp_offset = unwind.frame_size - offset;
4169 else
4170 unwind.fp_offset -= offset;
4171 }
4172
4173 /* Parse an unwind_raw directive. */
4174
4175 static void
4176 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4177 {
4178 expressionS exp;
4179 /* This is an arbitrary limit. */
4180 unsigned char op[16];
4181 int count;
4182
4183 if (!unwind.proc_start)
4184 as_bad (MISSING_FNSTART);
4185
4186 expression (&exp);
4187 if (exp.X_op == O_constant
4188 && skip_past_comma (&input_line_pointer) != FAIL)
4189 {
4190 unwind.frame_size += exp.X_add_number;
4191 expression (&exp);
4192 }
4193 else
4194 exp.X_op = O_illegal;
4195
4196 if (exp.X_op != O_constant)
4197 {
4198 as_bad (_("expected <offset>, <opcode>"));
4199 ignore_rest_of_line ();
4200 return;
4201 }
4202
4203 count = 0;
4204
4205 /* Parse the opcode. */
4206 for (;;)
4207 {
4208 if (count >= 16)
4209 {
4210 as_bad (_("unwind opcode too long"));
4211 ignore_rest_of_line ();
4212 }
4213 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4214 {
4215 as_bad (_("invalid unwind opcode"));
4216 ignore_rest_of_line ();
4217 return;
4218 }
4219 op[count++] = exp.X_add_number;
4220
4221 /* Parse the next byte. */
4222 if (skip_past_comma (&input_line_pointer) == FAIL)
4223 break;
4224
4225 expression (&exp);
4226 }
4227
4228 /* Add the opcode bytes in reverse order. */
4229 while (count--)
4230 add_unwind_opcode (op[count], 1);
4231
4232 demand_empty_rest_of_line ();
4233 }
4234
4235
4236 /* Parse a .eabi_attribute directive. */
4237
4238 static void
4239 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4240 {
4241 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4242
4243 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4244 attributes_set_explicitly[tag] = 1;
4245 }
4246 #endif /* OBJ_ELF */
4247
4248 static void s_arm_arch (int);
4249 static void s_arm_object_arch (int);
4250 static void s_arm_cpu (int);
4251 static void s_arm_fpu (int);
4252
4253 #ifdef TE_PE
4254
4255 static void
4256 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4257 {
4258 expressionS exp;
4259
4260 do
4261 {
4262 expression (&exp);
4263 if (exp.X_op == O_symbol)
4264 exp.X_op = O_secrel;
4265
4266 emit_expr (&exp, 4);
4267 }
4268 while (*input_line_pointer++ == ',');
4269
4270 input_line_pointer--;
4271 demand_empty_rest_of_line ();
4272 }
4273 #endif /* TE_PE */
4274
4275 /* This table describes all the machine specific pseudo-ops the assembler
4276 has to support. The fields are:
4277 pseudo-op name without dot
4278 function to call to execute this pseudo-op
4279 Integer arg to pass to the function. */
4280
4281 const pseudo_typeS md_pseudo_table[] =
4282 {
4283 /* Never called because '.req' does not start a line. */
4284 { "req", s_req, 0 },
4285 /* Following two are likewise never called. */
4286 { "dn", s_dn, 0 },
4287 { "qn", s_qn, 0 },
4288 { "unreq", s_unreq, 0 },
4289 { "bss", s_bss, 0 },
4290 { "align", s_align, 0 },
4291 { "arm", s_arm, 0 },
4292 { "thumb", s_thumb, 0 },
4293 { "code", s_code, 0 },
4294 { "force_thumb", s_force_thumb, 0 },
4295 { "thumb_func", s_thumb_func, 0 },
4296 { "thumb_set", s_thumb_set, 0 },
4297 { "even", s_even, 0 },
4298 { "ltorg", s_ltorg, 0 },
4299 { "pool", s_ltorg, 0 },
4300 { "syntax", s_syntax, 0 },
4301 { "cpu", s_arm_cpu, 0 },
4302 { "arch", s_arm_arch, 0 },
4303 { "object_arch", s_arm_object_arch, 0 },
4304 { "fpu", s_arm_fpu, 0 },
4305 #ifdef OBJ_ELF
4306 { "word", s_arm_elf_cons, 4 },
4307 { "long", s_arm_elf_cons, 4 },
4308 { "inst.n", s_arm_elf_inst, 2 },
4309 { "inst.w", s_arm_elf_inst, 4 },
4310 { "inst", s_arm_elf_inst, 0 },
4311 { "rel31", s_arm_rel31, 0 },
4312 { "fnstart", s_arm_unwind_fnstart, 0 },
4313 { "fnend", s_arm_unwind_fnend, 0 },
4314 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4315 { "personality", s_arm_unwind_personality, 0 },
4316 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4317 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4318 { "save", s_arm_unwind_save, 0 },
4319 { "vsave", s_arm_unwind_save, 1 },
4320 { "movsp", s_arm_unwind_movsp, 0 },
4321 { "pad", s_arm_unwind_pad, 0 },
4322 { "setfp", s_arm_unwind_setfp, 0 },
4323 { "unwind_raw", s_arm_unwind_raw, 0 },
4324 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4325 #else
4326 { "word", cons, 4},
4327
4328 /* These are used for dwarf. */
4329 {"2byte", cons, 2},
4330 {"4byte", cons, 4},
4331 {"8byte", cons, 8},
4332 /* These are used for dwarf2. */
4333 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4334 { "loc", dwarf2_directive_loc, 0 },
4335 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4336 #endif
4337 { "extend", float_cons, 'x' },
4338 { "ldouble", float_cons, 'x' },
4339 { "packed", float_cons, 'p' },
4340 #ifdef TE_PE
4341 {"secrel32", pe_directive_secrel, 0},
4342 #endif
4343 { 0, 0, 0 }
4344 };
4345 \f
4346 /* Parser functions used exclusively in instruction operands. */
4347
4348 /* Generic immediate-value read function for use in insn parsing.
4349 STR points to the beginning of the immediate (the leading #);
4350 VAL receives the value; if the value is outside [MIN, MAX]
4351 issue an error. PREFIX_OPT is true if the immediate prefix is
4352 optional. */
4353
4354 static int
4355 parse_immediate (char **str, int *val, int min, int max,
4356 bfd_boolean prefix_opt)
4357 {
4358 expressionS exp;
4359 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4360 if (exp.X_op != O_constant)
4361 {
4362 inst.error = _("constant expression required");
4363 return FAIL;
4364 }
4365
4366 if (exp.X_add_number < min || exp.X_add_number > max)
4367 {
4368 inst.error = _("immediate value out of range");
4369 return FAIL;
4370 }
4371
4372 *val = exp.X_add_number;
4373 return SUCCESS;
4374 }
4375
4376 /* Less-generic immediate-value read function with the possibility of loading a
4377 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4378 instructions. Puts the result directly in inst.operands[i]. */
4379
4380 static int
4381 parse_big_immediate (char **str, int i)
4382 {
4383 expressionS exp;
4384 char *ptr = *str;
4385
4386 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4387
4388 if (exp.X_op == O_constant)
4389 {
4390 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4391 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4392 O_constant. We have to be careful not to break compilation for
4393 32-bit X_add_number, though. */
4394 if ((exp.X_add_number & ~0xffffffffl) != 0)
4395 {
4396 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4397 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4398 inst.operands[i].regisimm = 1;
4399 }
4400 }
4401 else if (exp.X_op == O_big
4402 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4403 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4404 {
4405 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4406 /* Bignums have their least significant bits in
4407 generic_bignum[0]. Make sure we put 32 bits in imm and
4408 32 bits in reg, in a (hopefully) portable way. */
4409 gas_assert (parts != 0);
4410 inst.operands[i].imm = 0;
4411 for (j = 0; j < parts; j++, idx++)
4412 inst.operands[i].imm |= generic_bignum[idx]
4413 << (LITTLENUM_NUMBER_OF_BITS * j);
4414 inst.operands[i].reg = 0;
4415 for (j = 0; j < parts; j++, idx++)
4416 inst.operands[i].reg |= generic_bignum[idx]
4417 << (LITTLENUM_NUMBER_OF_BITS * j);
4418 inst.operands[i].regisimm = 1;
4419 }
4420 else
4421 return FAIL;
4422
4423 *str = ptr;
4424
4425 return SUCCESS;
4426 }
4427
4428 /* Returns the pseudo-register number of an FPA immediate constant,
4429 or FAIL if there isn't a valid constant here. */
4430
4431 static int
4432 parse_fpa_immediate (char ** str)
4433 {
4434 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4435 char * save_in;
4436 expressionS exp;
4437 int i;
4438 int j;
4439
4440 /* First try and match exact strings, this is to guarantee
4441 that some formats will work even for cross assembly. */
4442
4443 for (i = 0; fp_const[i]; i++)
4444 {
4445 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4446 {
4447 char *start = *str;
4448
4449 *str += strlen (fp_const[i]);
4450 if (is_end_of_line[(unsigned char) **str])
4451 return i + 8;
4452 *str = start;
4453 }
4454 }
4455
4456 /* Just because we didn't get a match doesn't mean that the constant
4457 isn't valid, just that it is in a format that we don't
4458 automatically recognize. Try parsing it with the standard
4459 expression routines. */
4460
4461 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4462
4463 /* Look for a raw floating point number. */
4464 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4465 && is_end_of_line[(unsigned char) *save_in])
4466 {
4467 for (i = 0; i < NUM_FLOAT_VALS; i++)
4468 {
4469 for (j = 0; j < MAX_LITTLENUMS; j++)
4470 {
4471 if (words[j] != fp_values[i][j])
4472 break;
4473 }
4474
4475 if (j == MAX_LITTLENUMS)
4476 {
4477 *str = save_in;
4478 return i + 8;
4479 }
4480 }
4481 }
4482
4483 /* Try and parse a more complex expression, this will probably fail
4484 unless the code uses a floating point prefix (eg "0f"). */
4485 save_in = input_line_pointer;
4486 input_line_pointer = *str;
4487 if (expression (&exp) == absolute_section
4488 && exp.X_op == O_big
4489 && exp.X_add_number < 0)
4490 {
4491 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4492 Ditto for 15. */
4493 if (gen_to_words (words, 5, (long) 15) == 0)
4494 {
4495 for (i = 0; i < NUM_FLOAT_VALS; i++)
4496 {
4497 for (j = 0; j < MAX_LITTLENUMS; j++)
4498 {
4499 if (words[j] != fp_values[i][j])
4500 break;
4501 }
4502
4503 if (j == MAX_LITTLENUMS)
4504 {
4505 *str = input_line_pointer;
4506 input_line_pointer = save_in;
4507 return i + 8;
4508 }
4509 }
4510 }
4511 }
4512
4513 *str = input_line_pointer;
4514 input_line_pointer = save_in;
4515 inst.error = _("invalid FPA immediate expression");
4516 return FAIL;
4517 }
4518
4519 /* Returns 1 if a number has "quarter-precision" float format
4520 0baBbbbbbc defgh000 00000000 00000000. */
4521
4522 static int
4523 is_quarter_float (unsigned imm)
4524 {
4525 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4526 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4527 }
4528
4529 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4530 0baBbbbbbc defgh000 00000000 00000000.
4531 The zero and minus-zero cases need special handling, since they can't be
4532 encoded in the "quarter-precision" float format, but can nonetheless be
4533 loaded as integer constants. */
4534
4535 static unsigned
4536 parse_qfloat_immediate (char **ccp, int *immed)
4537 {
4538 char *str = *ccp;
4539 char *fpnum;
4540 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4541 int found_fpchar = 0;
4542
4543 skip_past_char (&str, '#');
4544
4545 /* We must not accidentally parse an integer as a floating-point number. Make
4546 sure that the value we parse is not an integer by checking for special
4547 characters '.' or 'e'.
4548 FIXME: This is a horrible hack, but doing better is tricky because type
4549 information isn't in a very usable state at parse time. */
4550 fpnum = str;
4551 skip_whitespace (fpnum);
4552
4553 if (strncmp (fpnum, "0x", 2) == 0)
4554 return FAIL;
4555 else
4556 {
4557 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4558 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4559 {
4560 found_fpchar = 1;
4561 break;
4562 }
4563
4564 if (!found_fpchar)
4565 return FAIL;
4566 }
4567
4568 if ((str = atof_ieee (str, 's', words)) != NULL)
4569 {
4570 unsigned fpword = 0;
4571 int i;
4572
4573 /* Our FP word must be 32 bits (single-precision FP). */
4574 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4575 {
4576 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4577 fpword |= words[i];
4578 }
4579
4580 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4581 *immed = fpword;
4582 else
4583 return FAIL;
4584
4585 *ccp = str;
4586
4587 return SUCCESS;
4588 }
4589
4590 return FAIL;
4591 }
4592
4593 /* Shift operands. */
4594 enum shift_kind
4595 {
4596 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4597 };
4598
4599 struct asm_shift_name
4600 {
4601 const char *name;
4602 enum shift_kind kind;
4603 };
4604
4605 /* Third argument to parse_shift. */
4606 enum parse_shift_mode
4607 {
4608 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4609 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4610 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4611 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4612 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4613 };
4614
4615 /* Parse a <shift> specifier on an ARM data processing instruction.
4616 This has three forms:
4617
4618 (LSL|LSR|ASL|ASR|ROR) Rs
4619 (LSL|LSR|ASL|ASR|ROR) #imm
4620 RRX
4621
4622 Note that ASL is assimilated to LSL in the instruction encoding, and
4623 RRX to ROR #0 (which cannot be written as such). */
4624
4625 static int
4626 parse_shift (char **str, int i, enum parse_shift_mode mode)
4627 {
4628 const struct asm_shift_name *shift_name;
4629 enum shift_kind shift;
4630 char *s = *str;
4631 char *p = s;
4632 int reg;
4633
4634 for (p = *str; ISALPHA (*p); p++)
4635 ;
4636
4637 if (p == *str)
4638 {
4639 inst.error = _("shift expression expected");
4640 return FAIL;
4641 }
4642
4643 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4644 p - *str);
4645
4646 if (shift_name == NULL)
4647 {
4648 inst.error = _("shift expression expected");
4649 return FAIL;
4650 }
4651
4652 shift = shift_name->kind;
4653
4654 switch (mode)
4655 {
4656 case NO_SHIFT_RESTRICT:
4657 case SHIFT_IMMEDIATE: break;
4658
4659 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4660 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4661 {
4662 inst.error = _("'LSL' or 'ASR' required");
4663 return FAIL;
4664 }
4665 break;
4666
4667 case SHIFT_LSL_IMMEDIATE:
4668 if (shift != SHIFT_LSL)
4669 {
4670 inst.error = _("'LSL' required");
4671 return FAIL;
4672 }
4673 break;
4674
4675 case SHIFT_ASR_IMMEDIATE:
4676 if (shift != SHIFT_ASR)
4677 {
4678 inst.error = _("'ASR' required");
4679 return FAIL;
4680 }
4681 break;
4682
4683 default: abort ();
4684 }
4685
4686 if (shift != SHIFT_RRX)
4687 {
4688 /* Whitespace can appear here if the next thing is a bare digit. */
4689 skip_whitespace (p);
4690
4691 if (mode == NO_SHIFT_RESTRICT
4692 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4693 {
4694 inst.operands[i].imm = reg;
4695 inst.operands[i].immisreg = 1;
4696 }
4697 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4698 return FAIL;
4699 }
4700 inst.operands[i].shift_kind = shift;
4701 inst.operands[i].shifted = 1;
4702 *str = p;
4703 return SUCCESS;
4704 }
4705
4706 /* Parse a <shifter_operand> for an ARM data processing instruction:
4707
4708 #<immediate>
4709 #<immediate>, <rotate>
4710 <Rm>
4711 <Rm>, <shift>
4712
4713 where <shift> is defined by parse_shift above, and <rotate> is a
4714 multiple of 2 between 0 and 30. Validation of immediate operands
4715 is deferred to md_apply_fix. */
4716
4717 static int
4718 parse_shifter_operand (char **str, int i)
4719 {
4720 int value;
4721 expressionS exp;
4722
4723 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4724 {
4725 inst.operands[i].reg = value;
4726 inst.operands[i].isreg = 1;
4727
4728 /* parse_shift will override this if appropriate */
4729 inst.reloc.exp.X_op = O_constant;
4730 inst.reloc.exp.X_add_number = 0;
4731
4732 if (skip_past_comma (str) == FAIL)
4733 return SUCCESS;
4734
4735 /* Shift operation on register. */
4736 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4737 }
4738
4739 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4740 return FAIL;
4741
4742 if (skip_past_comma (str) == SUCCESS)
4743 {
4744 /* #x, y -- ie explicit rotation by Y. */
4745 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4746 return FAIL;
4747
4748 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4749 {
4750 inst.error = _("constant expression expected");
4751 return FAIL;
4752 }
4753
4754 value = exp.X_add_number;
4755 if (value < 0 || value > 30 || value % 2 != 0)
4756 {
4757 inst.error = _("invalid rotation");
4758 return FAIL;
4759 }
4760 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4761 {
4762 inst.error = _("invalid constant");
4763 return FAIL;
4764 }
4765
4766 /* Convert to decoded value. md_apply_fix will put it back. */
4767 inst.reloc.exp.X_add_number
4768 = (((inst.reloc.exp.X_add_number << (32 - value))
4769 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4770 }
4771
4772 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4773 inst.reloc.pc_rel = 0;
4774 return SUCCESS;
4775 }
4776
4777 /* Group relocation information. Each entry in the table contains the
4778 textual name of the relocation as may appear in assembler source
4779 and must end with a colon.
4780 Along with this textual name are the relocation codes to be used if
4781 the corresponding instruction is an ALU instruction (ADD or SUB only),
4782 an LDR, an LDRS, or an LDC. */
4783
4784 struct group_reloc_table_entry
4785 {
4786 const char *name;
4787 int alu_code;
4788 int ldr_code;
4789 int ldrs_code;
4790 int ldc_code;
4791 };
4792
4793 typedef enum
4794 {
4795 /* Varieties of non-ALU group relocation. */
4796
4797 GROUP_LDR,
4798 GROUP_LDRS,
4799 GROUP_LDC
4800 } group_reloc_type;
4801
4802 static struct group_reloc_table_entry group_reloc_table[] =
4803 { /* Program counter relative: */
4804 { "pc_g0_nc",
4805 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4806 0, /* LDR */
4807 0, /* LDRS */
4808 0 }, /* LDC */
4809 { "pc_g0",
4810 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4811 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4812 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4813 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4814 { "pc_g1_nc",
4815 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4816 0, /* LDR */
4817 0, /* LDRS */
4818 0 }, /* LDC */
4819 { "pc_g1",
4820 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4821 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4822 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4823 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4824 { "pc_g2",
4825 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4826 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4827 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4828 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4829 /* Section base relative */
4830 { "sb_g0_nc",
4831 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4832 0, /* LDR */
4833 0, /* LDRS */
4834 0 }, /* LDC */
4835 { "sb_g0",
4836 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4837 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4838 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4839 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4840 { "sb_g1_nc",
4841 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4842 0, /* LDR */
4843 0, /* LDRS */
4844 0 }, /* LDC */
4845 { "sb_g1",
4846 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4847 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4848 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4849 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4850 { "sb_g2",
4851 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4852 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4853 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4854 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4855
4856 /* Given the address of a pointer pointing to the textual name of a group
4857 relocation as may appear in assembler source, attempt to find its details
4858 in group_reloc_table. The pointer will be updated to the character after
4859 the trailing colon. On failure, FAIL will be returned; SUCCESS
4860 otherwise. On success, *entry will be updated to point at the relevant
4861 group_reloc_table entry. */
4862
4863 static int
4864 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4865 {
4866 unsigned int i;
4867 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4868 {
4869 int length = strlen (group_reloc_table[i].name);
4870
4871 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4872 && (*str)[length] == ':')
4873 {
4874 *out = &group_reloc_table[i];
4875 *str += (length + 1);
4876 return SUCCESS;
4877 }
4878 }
4879
4880 return FAIL;
4881 }
4882
4883 /* Parse a <shifter_operand> for an ARM data processing instruction
4884 (as for parse_shifter_operand) where group relocations are allowed:
4885
4886 #<immediate>
4887 #<immediate>, <rotate>
4888 #:<group_reloc>:<expression>
4889 <Rm>
4890 <Rm>, <shift>
4891
4892 where <group_reloc> is one of the strings defined in group_reloc_table.
4893 The hashes are optional.
4894
4895 Everything else is as for parse_shifter_operand. */
4896
4897 static parse_operand_result
4898 parse_shifter_operand_group_reloc (char **str, int i)
4899 {
4900 /* Determine if we have the sequence of characters #: or just :
4901 coming next. If we do, then we check for a group relocation.
4902 If we don't, punt the whole lot to parse_shifter_operand. */
4903
4904 if (((*str)[0] == '#' && (*str)[1] == ':')
4905 || (*str)[0] == ':')
4906 {
4907 struct group_reloc_table_entry *entry;
4908
4909 if ((*str)[0] == '#')
4910 (*str) += 2;
4911 else
4912 (*str)++;
4913
4914 /* Try to parse a group relocation. Anything else is an error. */
4915 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4916 {
4917 inst.error = _("unknown group relocation");
4918 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4919 }
4920
4921 /* We now have the group relocation table entry corresponding to
4922 the name in the assembler source. Next, we parse the expression. */
4923 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4924 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4925
4926 /* Record the relocation type (always the ALU variant here). */
4927 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
4928 gas_assert (inst.reloc.type != 0);
4929
4930 return PARSE_OPERAND_SUCCESS;
4931 }
4932 else
4933 return parse_shifter_operand (str, i) == SUCCESS
4934 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4935
4936 /* Never reached. */
4937 }
4938
4939 /* Parse all forms of an ARM address expression. Information is written
4940 to inst.operands[i] and/or inst.reloc.
4941
4942 Preindexed addressing (.preind=1):
4943
4944 [Rn, #offset] .reg=Rn .reloc.exp=offset
4945 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4946 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4947 .shift_kind=shift .reloc.exp=shift_imm
4948
4949 These three may have a trailing ! which causes .writeback to be set also.
4950
4951 Postindexed addressing (.postind=1, .writeback=1):
4952
4953 [Rn], #offset .reg=Rn .reloc.exp=offset
4954 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4955 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4956 .shift_kind=shift .reloc.exp=shift_imm
4957
4958 Unindexed addressing (.preind=0, .postind=0):
4959
4960 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4961
4962 Other:
4963
4964 [Rn]{!} shorthand for [Rn,#0]{!}
4965 =immediate .isreg=0 .reloc.exp=immediate
4966 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4967
4968 It is the caller's responsibility to check for addressing modes not
4969 supported by the instruction, and to set inst.reloc.type. */
4970
4971 static parse_operand_result
4972 parse_address_main (char **str, int i, int group_relocations,
4973 group_reloc_type group_type)
4974 {
4975 char *p = *str;
4976 int reg;
4977
4978 if (skip_past_char (&p, '[') == FAIL)
4979 {
4980 if (skip_past_char (&p, '=') == FAIL)
4981 {
4982 /* Bare address - translate to PC-relative offset. */
4983 inst.reloc.pc_rel = 1;
4984 inst.operands[i].reg = REG_PC;
4985 inst.operands[i].isreg = 1;
4986 inst.operands[i].preind = 1;
4987 }
4988 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
4989
4990 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4991 return PARSE_OPERAND_FAIL;
4992
4993 *str = p;
4994 return PARSE_OPERAND_SUCCESS;
4995 }
4996
4997 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4998 {
4999 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5000 return PARSE_OPERAND_FAIL;
5001 }
5002 inst.operands[i].reg = reg;
5003 inst.operands[i].isreg = 1;
5004
5005 if (skip_past_comma (&p) == SUCCESS)
5006 {
5007 inst.operands[i].preind = 1;
5008
5009 if (*p == '+') p++;
5010 else if (*p == '-') p++, inst.operands[i].negative = 1;
5011
5012 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5013 {
5014 inst.operands[i].imm = reg;
5015 inst.operands[i].immisreg = 1;
5016
5017 if (skip_past_comma (&p) == SUCCESS)
5018 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5019 return PARSE_OPERAND_FAIL;
5020 }
5021 else if (skip_past_char (&p, ':') == SUCCESS)
5022 {
5023 /* FIXME: '@' should be used here, but it's filtered out by generic
5024 code before we get to see it here. This may be subject to
5025 change. */
5026 expressionS exp;
5027 my_get_expression (&exp, &p, GE_NO_PREFIX);
5028 if (exp.X_op != O_constant)
5029 {
5030 inst.error = _("alignment must be constant");
5031 return PARSE_OPERAND_FAIL;
5032 }
5033 inst.operands[i].imm = exp.X_add_number << 8;
5034 inst.operands[i].immisalign = 1;
5035 /* Alignments are not pre-indexes. */
5036 inst.operands[i].preind = 0;
5037 }
5038 else
5039 {
5040 if (inst.operands[i].negative)
5041 {
5042 inst.operands[i].negative = 0;
5043 p--;
5044 }
5045
5046 if (group_relocations
5047 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5048 {
5049 struct group_reloc_table_entry *entry;
5050
5051 /* Skip over the #: or : sequence. */
5052 if (*p == '#')
5053 p += 2;
5054 else
5055 p++;
5056
5057 /* Try to parse a group relocation. Anything else is an
5058 error. */
5059 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5060 {
5061 inst.error = _("unknown group relocation");
5062 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5063 }
5064
5065 /* We now have the group relocation table entry corresponding to
5066 the name in the assembler source. Next, we parse the
5067 expression. */
5068 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5069 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5070
5071 /* Record the relocation type. */
5072 switch (group_type)
5073 {
5074 case GROUP_LDR:
5075 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5076 break;
5077
5078 case GROUP_LDRS:
5079 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5080 break;
5081
5082 case GROUP_LDC:
5083 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5084 break;
5085
5086 default:
5087 gas_assert (0);
5088 }
5089
5090 if (inst.reloc.type == 0)
5091 {
5092 inst.error = _("this group relocation is not allowed on this instruction");
5093 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5094 }
5095 }
5096 else
5097 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5098 return PARSE_OPERAND_FAIL;
5099 }
5100 }
5101
5102 if (skip_past_char (&p, ']') == FAIL)
5103 {
5104 inst.error = _("']' expected");
5105 return PARSE_OPERAND_FAIL;
5106 }
5107
5108 if (skip_past_char (&p, '!') == SUCCESS)
5109 inst.operands[i].writeback = 1;
5110
5111 else if (skip_past_comma (&p) == SUCCESS)
5112 {
5113 if (skip_past_char (&p, '{') == SUCCESS)
5114 {
5115 /* [Rn], {expr} - unindexed, with option */
5116 if (parse_immediate (&p, &inst.operands[i].imm,
5117 0, 255, TRUE) == FAIL)
5118 return PARSE_OPERAND_FAIL;
5119
5120 if (skip_past_char (&p, '}') == FAIL)
5121 {
5122 inst.error = _("'}' expected at end of 'option' field");
5123 return PARSE_OPERAND_FAIL;
5124 }
5125 if (inst.operands[i].preind)
5126 {
5127 inst.error = _("cannot combine index with option");
5128 return PARSE_OPERAND_FAIL;
5129 }
5130 *str = p;
5131 return PARSE_OPERAND_SUCCESS;
5132 }
5133 else
5134 {
5135 inst.operands[i].postind = 1;
5136 inst.operands[i].writeback = 1;
5137
5138 if (inst.operands[i].preind)
5139 {
5140 inst.error = _("cannot combine pre- and post-indexing");
5141 return PARSE_OPERAND_FAIL;
5142 }
5143
5144 if (*p == '+') p++;
5145 else if (*p == '-') p++, inst.operands[i].negative = 1;
5146
5147 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5148 {
5149 /* We might be using the immediate for alignment already. If we
5150 are, OR the register number into the low-order bits. */
5151 if (inst.operands[i].immisalign)
5152 inst.operands[i].imm |= reg;
5153 else
5154 inst.operands[i].imm = reg;
5155 inst.operands[i].immisreg = 1;
5156
5157 if (skip_past_comma (&p) == SUCCESS)
5158 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5159 return PARSE_OPERAND_FAIL;
5160 }
5161 else
5162 {
5163 if (inst.operands[i].negative)
5164 {
5165 inst.operands[i].negative = 0;
5166 p--;
5167 }
5168 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5169 return PARSE_OPERAND_FAIL;
5170 }
5171 }
5172 }
5173
5174 /* If at this point neither .preind nor .postind is set, we have a
5175 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5176 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5177 {
5178 inst.operands[i].preind = 1;
5179 inst.reloc.exp.X_op = O_constant;
5180 inst.reloc.exp.X_add_number = 0;
5181 }
5182 *str = p;
5183 return PARSE_OPERAND_SUCCESS;
5184 }
5185
5186 static int
5187 parse_address (char **str, int i)
5188 {
5189 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5190 ? SUCCESS : FAIL;
5191 }
5192
5193 static parse_operand_result
5194 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5195 {
5196 return parse_address_main (str, i, 1, type);
5197 }
5198
5199 /* Parse an operand for a MOVW or MOVT instruction. */
5200 static int
5201 parse_half (char **str)
5202 {
5203 char * p;
5204
5205 p = *str;
5206 skip_past_char (&p, '#');
5207 if (strncasecmp (p, ":lower16:", 9) == 0)
5208 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5209 else if (strncasecmp (p, ":upper16:", 9) == 0)
5210 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5211
5212 if (inst.reloc.type != BFD_RELOC_UNUSED)
5213 {
5214 p += 9;
5215 skip_whitespace (p);
5216 }
5217
5218 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5219 return FAIL;
5220
5221 if (inst.reloc.type == BFD_RELOC_UNUSED)
5222 {
5223 if (inst.reloc.exp.X_op != O_constant)
5224 {
5225 inst.error = _("constant expression expected");
5226 return FAIL;
5227 }
5228 if (inst.reloc.exp.X_add_number < 0
5229 || inst.reloc.exp.X_add_number > 0xffff)
5230 {
5231 inst.error = _("immediate value out of range");
5232 return FAIL;
5233 }
5234 }
5235 *str = p;
5236 return SUCCESS;
5237 }
5238
5239 /* Miscellaneous. */
5240
5241 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5242 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5243 static int
5244 parse_psr (char **str)
5245 {
5246 char *p;
5247 unsigned long psr_field;
5248 const struct asm_psr *psr;
5249 char *start;
5250
5251 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5252 feature for ease of use and backwards compatibility. */
5253 p = *str;
5254 if (strncasecmp (p, "SPSR", 4) == 0)
5255 psr_field = SPSR_BIT;
5256 else if (strncasecmp (p, "CPSR", 4) == 0)
5257 psr_field = 0;
5258 else
5259 {
5260 start = p;
5261 do
5262 p++;
5263 while (ISALNUM (*p) || *p == '_');
5264
5265 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5266 p - start);
5267 if (!psr)
5268 return FAIL;
5269
5270 *str = p;
5271 return psr->field;
5272 }
5273
5274 p += 4;
5275 if (*p == '_')
5276 {
5277 /* A suffix follows. */
5278 p++;
5279 start = p;
5280
5281 do
5282 p++;
5283 while (ISALNUM (*p) || *p == '_');
5284
5285 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5286 p - start);
5287 if (!psr)
5288 goto error;
5289
5290 psr_field |= psr->field;
5291 }
5292 else
5293 {
5294 if (ISALNUM (*p))
5295 goto error; /* Garbage after "[CS]PSR". */
5296
5297 psr_field |= (PSR_c | PSR_f);
5298 }
5299 *str = p;
5300 return psr_field;
5301
5302 error:
5303 inst.error = _("flag for {c}psr instruction expected");
5304 return FAIL;
5305 }
5306
5307 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5308 value suitable for splatting into the AIF field of the instruction. */
5309
5310 static int
5311 parse_cps_flags (char **str)
5312 {
5313 int val = 0;
5314 int saw_a_flag = 0;
5315 char *s = *str;
5316
5317 for (;;)
5318 switch (*s++)
5319 {
5320 case '\0': case ',':
5321 goto done;
5322
5323 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5324 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5325 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5326
5327 default:
5328 inst.error = _("unrecognized CPS flag");
5329 return FAIL;
5330 }
5331
5332 done:
5333 if (saw_a_flag == 0)
5334 {
5335 inst.error = _("missing CPS flags");
5336 return FAIL;
5337 }
5338
5339 *str = s - 1;
5340 return val;
5341 }
5342
5343 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5344 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5345
5346 static int
5347 parse_endian_specifier (char **str)
5348 {
5349 int little_endian;
5350 char *s = *str;
5351
5352 if (strncasecmp (s, "BE", 2))
5353 little_endian = 0;
5354 else if (strncasecmp (s, "LE", 2))
5355 little_endian = 1;
5356 else
5357 {
5358 inst.error = _("valid endian specifiers are be or le");
5359 return FAIL;
5360 }
5361
5362 if (ISALNUM (s[2]) || s[2] == '_')
5363 {
5364 inst.error = _("valid endian specifiers are be or le");
5365 return FAIL;
5366 }
5367
5368 *str = s + 2;
5369 return little_endian;
5370 }
5371
5372 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5373 value suitable for poking into the rotate field of an sxt or sxta
5374 instruction, or FAIL on error. */
5375
5376 static int
5377 parse_ror (char **str)
5378 {
5379 int rot;
5380 char *s = *str;
5381
5382 if (strncasecmp (s, "ROR", 3) == 0)
5383 s += 3;
5384 else
5385 {
5386 inst.error = _("missing rotation field after comma");
5387 return FAIL;
5388 }
5389
5390 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5391 return FAIL;
5392
5393 switch (rot)
5394 {
5395 case 0: *str = s; return 0x0;
5396 case 8: *str = s; return 0x1;
5397 case 16: *str = s; return 0x2;
5398 case 24: *str = s; return 0x3;
5399
5400 default:
5401 inst.error = _("rotation can only be 0, 8, 16, or 24");
5402 return FAIL;
5403 }
5404 }
5405
5406 /* Parse a conditional code (from conds[] below). The value returned is in the
5407 range 0 .. 14, or FAIL. */
5408 static int
5409 parse_cond (char **str)
5410 {
5411 char *q;
5412 const struct asm_cond *c;
5413 int n;
5414 /* Condition codes are always 2 characters, so matching up to
5415 3 characters is sufficient. */
5416 char cond[3];
5417
5418 q = *str;
5419 n = 0;
5420 while (ISALPHA (*q) && n < 3)
5421 {
5422 cond[n] = TOLOWER (*q);
5423 q++;
5424 n++;
5425 }
5426
5427 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5428 if (!c)
5429 {
5430 inst.error = _("condition required");
5431 return FAIL;
5432 }
5433
5434 *str = q;
5435 return c->value;
5436 }
5437
5438 /* Parse an option for a barrier instruction. Returns the encoding for the
5439 option, or FAIL. */
5440 static int
5441 parse_barrier (char **str)
5442 {
5443 char *p, *q;
5444 const struct asm_barrier_opt *o;
5445
5446 p = q = *str;
5447 while (ISALPHA (*q))
5448 q++;
5449
5450 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5451 q - p);
5452 if (!o)
5453 return FAIL;
5454
5455 *str = q;
5456 return o->value;
5457 }
5458
5459 /* Parse the operands of a table branch instruction. Similar to a memory
5460 operand. */
5461 static int
5462 parse_tb (char **str)
5463 {
5464 char * p = *str;
5465 int reg;
5466
5467 if (skip_past_char (&p, '[') == FAIL)
5468 {
5469 inst.error = _("'[' expected");
5470 return FAIL;
5471 }
5472
5473 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5474 {
5475 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5476 return FAIL;
5477 }
5478 inst.operands[0].reg = reg;
5479
5480 if (skip_past_comma (&p) == FAIL)
5481 {
5482 inst.error = _("',' expected");
5483 return FAIL;
5484 }
5485
5486 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5487 {
5488 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5489 return FAIL;
5490 }
5491 inst.operands[0].imm = reg;
5492
5493 if (skip_past_comma (&p) == SUCCESS)
5494 {
5495 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5496 return FAIL;
5497 if (inst.reloc.exp.X_add_number != 1)
5498 {
5499 inst.error = _("invalid shift");
5500 return FAIL;
5501 }
5502 inst.operands[0].shifted = 1;
5503 }
5504
5505 if (skip_past_char (&p, ']') == FAIL)
5506 {
5507 inst.error = _("']' expected");
5508 return FAIL;
5509 }
5510 *str = p;
5511 return SUCCESS;
5512 }
5513
5514 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5515 information on the types the operands can take and how they are encoded.
5516 Up to four operands may be read; this function handles setting the
5517 ".present" field for each read operand itself.
5518 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5519 else returns FAIL. */
5520
5521 static int
5522 parse_neon_mov (char **str, int *which_operand)
5523 {
5524 int i = *which_operand, val;
5525 enum arm_reg_type rtype;
5526 char *ptr = *str;
5527 struct neon_type_el optype;
5528
5529 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5530 {
5531 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5532 inst.operands[i].reg = val;
5533 inst.operands[i].isscalar = 1;
5534 inst.operands[i].vectype = optype;
5535 inst.operands[i++].present = 1;
5536
5537 if (skip_past_comma (&ptr) == FAIL)
5538 goto wanted_comma;
5539
5540 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5541 goto wanted_arm;
5542
5543 inst.operands[i].reg = val;
5544 inst.operands[i].isreg = 1;
5545 inst.operands[i].present = 1;
5546 }
5547 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5548 != FAIL)
5549 {
5550 /* Cases 0, 1, 2, 3, 5 (D only). */
5551 if (skip_past_comma (&ptr) == FAIL)
5552 goto wanted_comma;
5553
5554 inst.operands[i].reg = val;
5555 inst.operands[i].isreg = 1;
5556 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5557 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5558 inst.operands[i].isvec = 1;
5559 inst.operands[i].vectype = optype;
5560 inst.operands[i++].present = 1;
5561
5562 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5563 {
5564 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5565 Case 13: VMOV <Sd>, <Rm> */
5566 inst.operands[i].reg = val;
5567 inst.operands[i].isreg = 1;
5568 inst.operands[i].present = 1;
5569
5570 if (rtype == REG_TYPE_NQ)
5571 {
5572 first_error (_("can't use Neon quad register here"));
5573 return FAIL;
5574 }
5575 else if (rtype != REG_TYPE_VFS)
5576 {
5577 i++;
5578 if (skip_past_comma (&ptr) == FAIL)
5579 goto wanted_comma;
5580 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5581 goto wanted_arm;
5582 inst.operands[i].reg = val;
5583 inst.operands[i].isreg = 1;
5584 inst.operands[i].present = 1;
5585 }
5586 }
5587 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5588 &optype)) != FAIL)
5589 {
5590 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5591 Case 1: VMOV<c><q> <Dd>, <Dm>
5592 Case 8: VMOV.F32 <Sd>, <Sm>
5593 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5594
5595 inst.operands[i].reg = val;
5596 inst.operands[i].isreg = 1;
5597 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5598 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5599 inst.operands[i].isvec = 1;
5600 inst.operands[i].vectype = optype;
5601 inst.operands[i].present = 1;
5602
5603 if (skip_past_comma (&ptr) == SUCCESS)
5604 {
5605 /* Case 15. */
5606 i++;
5607
5608 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5609 goto wanted_arm;
5610
5611 inst.operands[i].reg = val;
5612 inst.operands[i].isreg = 1;
5613 inst.operands[i++].present = 1;
5614
5615 if (skip_past_comma (&ptr) == FAIL)
5616 goto wanted_comma;
5617
5618 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5619 goto wanted_arm;
5620
5621 inst.operands[i].reg = val;
5622 inst.operands[i].isreg = 1;
5623 inst.operands[i++].present = 1;
5624 }
5625 }
5626 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5627 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5628 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5629 Case 10: VMOV.F32 <Sd>, #<imm>
5630 Case 11: VMOV.F64 <Dd>, #<imm> */
5631 inst.operands[i].immisfloat = 1;
5632 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5633 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5634 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5635 ;
5636 else
5637 {
5638 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5639 return FAIL;
5640 }
5641 }
5642 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5643 {
5644 /* Cases 6, 7. */
5645 inst.operands[i].reg = val;
5646 inst.operands[i].isreg = 1;
5647 inst.operands[i++].present = 1;
5648
5649 if (skip_past_comma (&ptr) == FAIL)
5650 goto wanted_comma;
5651
5652 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5653 {
5654 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5655 inst.operands[i].reg = val;
5656 inst.operands[i].isscalar = 1;
5657 inst.operands[i].present = 1;
5658 inst.operands[i].vectype = optype;
5659 }
5660 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5661 {
5662 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5663 inst.operands[i].reg = val;
5664 inst.operands[i].isreg = 1;
5665 inst.operands[i++].present = 1;
5666
5667 if (skip_past_comma (&ptr) == FAIL)
5668 goto wanted_comma;
5669
5670 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5671 == FAIL)
5672 {
5673 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5674 return FAIL;
5675 }
5676
5677 inst.operands[i].reg = val;
5678 inst.operands[i].isreg = 1;
5679 inst.operands[i].isvec = 1;
5680 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5681 inst.operands[i].vectype = optype;
5682 inst.operands[i].present = 1;
5683
5684 if (rtype == REG_TYPE_VFS)
5685 {
5686 /* Case 14. */
5687 i++;
5688 if (skip_past_comma (&ptr) == FAIL)
5689 goto wanted_comma;
5690 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5691 &optype)) == FAIL)
5692 {
5693 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5694 return FAIL;
5695 }
5696 inst.operands[i].reg = val;
5697 inst.operands[i].isreg = 1;
5698 inst.operands[i].isvec = 1;
5699 inst.operands[i].issingle = 1;
5700 inst.operands[i].vectype = optype;
5701 inst.operands[i].present = 1;
5702 }
5703 }
5704 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5705 != FAIL)
5706 {
5707 /* Case 13. */
5708 inst.operands[i].reg = val;
5709 inst.operands[i].isreg = 1;
5710 inst.operands[i].isvec = 1;
5711 inst.operands[i].issingle = 1;
5712 inst.operands[i].vectype = optype;
5713 inst.operands[i++].present = 1;
5714 }
5715 }
5716 else
5717 {
5718 first_error (_("parse error"));
5719 return FAIL;
5720 }
5721
5722 /* Successfully parsed the operands. Update args. */
5723 *which_operand = i;
5724 *str = ptr;
5725 return SUCCESS;
5726
5727 wanted_comma:
5728 first_error (_("expected comma"));
5729 return FAIL;
5730
5731 wanted_arm:
5732 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5733 return FAIL;
5734 }
5735
5736 /* Use this macro when the operand constraints are different
5737 for ARM and THUMB (e.g. ldrd). */
5738 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5739 ((arm_operand) | ((thumb_operand) << 16))
5740
5741 /* Matcher codes for parse_operands. */
5742 enum operand_parse_code
5743 {
5744 OP_stop, /* end of line */
5745
5746 OP_RR, /* ARM register */
5747 OP_RRnpc, /* ARM register, not r15 */
5748 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
5749 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5750 OP_RRw, /* ARM register, not r15, optional trailing ! */
5751 OP_RCP, /* Coprocessor number */
5752 OP_RCN, /* Coprocessor register */
5753 OP_RF, /* FPA register */
5754 OP_RVS, /* VFP single precision register */
5755 OP_RVD, /* VFP double precision register (0..15) */
5756 OP_RND, /* Neon double precision register (0..31) */
5757 OP_RNQ, /* Neon quad precision register */
5758 OP_RVSD, /* VFP single or double precision register */
5759 OP_RNDQ, /* Neon double or quad precision register */
5760 OP_RNSDQ, /* Neon single, double or quad precision register */
5761 OP_RNSC, /* Neon scalar D[X] */
5762 OP_RVC, /* VFP control register */
5763 OP_RMF, /* Maverick F register */
5764 OP_RMD, /* Maverick D register */
5765 OP_RMFX, /* Maverick FX register */
5766 OP_RMDX, /* Maverick DX register */
5767 OP_RMAX, /* Maverick AX register */
5768 OP_RMDS, /* Maverick DSPSC register */
5769 OP_RIWR, /* iWMMXt wR register */
5770 OP_RIWC, /* iWMMXt wC register */
5771 OP_RIWG, /* iWMMXt wCG register */
5772 OP_RXA, /* XScale accumulator register */
5773
5774 OP_REGLST, /* ARM register list */
5775 OP_VRSLST, /* VFP single-precision register list */
5776 OP_VRDLST, /* VFP double-precision register list */
5777 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5778 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5779 OP_NSTRLST, /* Neon element/structure list */
5780
5781 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5782 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5783 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5784 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5785 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5786 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5787 OP_VMOV, /* Neon VMOV operands. */
5788 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5789 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5790 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5791
5792 OP_I0, /* immediate zero */
5793 OP_I7, /* immediate value 0 .. 7 */
5794 OP_I15, /* 0 .. 15 */
5795 OP_I16, /* 1 .. 16 */
5796 OP_I16z, /* 0 .. 16 */
5797 OP_I31, /* 0 .. 31 */
5798 OP_I31w, /* 0 .. 31, optional trailing ! */
5799 OP_I32, /* 1 .. 32 */
5800 OP_I32z, /* 0 .. 32 */
5801 OP_I63, /* 0 .. 63 */
5802 OP_I63s, /* -64 .. 63 */
5803 OP_I64, /* 1 .. 64 */
5804 OP_I64z, /* 0 .. 64 */
5805 OP_I255, /* 0 .. 255 */
5806
5807 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5808 OP_I7b, /* 0 .. 7 */
5809 OP_I15b, /* 0 .. 15 */
5810 OP_I31b, /* 0 .. 31 */
5811
5812 OP_SH, /* shifter operand */
5813 OP_SHG, /* shifter operand with possible group relocation */
5814 OP_ADDR, /* Memory address expression (any mode) */
5815 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5816 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5817 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5818 OP_EXP, /* arbitrary expression */
5819 OP_EXPi, /* same, with optional immediate prefix */
5820 OP_EXPr, /* same, with optional relocation suffix */
5821 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5822
5823 OP_CPSF, /* CPS flags */
5824 OP_ENDI, /* Endianness specifier */
5825 OP_PSR, /* CPSR/SPSR mask for msr */
5826 OP_COND, /* conditional code */
5827 OP_TB, /* Table branch. */
5828
5829 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5830 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5831
5832 OP_RRnpc_I0, /* ARM register or literal 0 */
5833 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5834 OP_RR_EXi, /* ARM register or expression with imm prefix */
5835 OP_RF_IF, /* FPA register or immediate */
5836 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5837 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5838
5839 /* Optional operands. */
5840 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5841 OP_oI31b, /* 0 .. 31 */
5842 OP_oI32b, /* 1 .. 32 */
5843 OP_oIffffb, /* 0 .. 65535 */
5844 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5845
5846 OP_oRR, /* ARM register */
5847 OP_oRRnpc, /* ARM register, not the PC */
5848 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
5849 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5850 OP_oRND, /* Optional Neon double precision register */
5851 OP_oRNQ, /* Optional Neon quad precision register */
5852 OP_oRNDQ, /* Optional Neon double or quad precision register */
5853 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5854 OP_oSHll, /* LSL immediate */
5855 OP_oSHar, /* ASR immediate */
5856 OP_oSHllar, /* LSL or ASR immediate */
5857 OP_oROR, /* ROR 0/8/16/24 */
5858 OP_oBARRIER, /* Option argument for a barrier instruction. */
5859
5860 /* Some pre-defined mixed (ARM/THUMB) operands. */
5861 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5862 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5863 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5864
5865 OP_FIRST_OPTIONAL = OP_oI7b
5866 };
5867
5868 /* Generic instruction operand parser. This does no encoding and no
5869 semantic validation; it merely squirrels values away in the inst
5870 structure. Returns SUCCESS or FAIL depending on whether the
5871 specified grammar matched. */
5872 static int
5873 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
5874 {
5875 unsigned const int *upat = pattern;
5876 char *backtrack_pos = 0;
5877 const char *backtrack_error = 0;
5878 int i, val, backtrack_index = 0;
5879 enum arm_reg_type rtype;
5880 parse_operand_result result;
5881 unsigned int op_parse_code;
5882
5883 #define po_char_or_fail(chr) \
5884 do \
5885 { \
5886 if (skip_past_char (&str, chr) == FAIL) \
5887 goto bad_args; \
5888 } \
5889 while (0)
5890
5891 #define po_reg_or_fail(regtype) \
5892 do \
5893 { \
5894 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5895 & inst.operands[i].vectype); \
5896 if (val == FAIL) \
5897 { \
5898 first_error (_(reg_expected_msgs[regtype])); \
5899 goto failure; \
5900 } \
5901 inst.operands[i].reg = val; \
5902 inst.operands[i].isreg = 1; \
5903 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5904 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5905 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5906 || rtype == REG_TYPE_VFD \
5907 || rtype == REG_TYPE_NQ); \
5908 } \
5909 while (0)
5910
5911 #define po_reg_or_goto(regtype, label) \
5912 do \
5913 { \
5914 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5915 & inst.operands[i].vectype); \
5916 if (val == FAIL) \
5917 goto label; \
5918 \
5919 inst.operands[i].reg = val; \
5920 inst.operands[i].isreg = 1; \
5921 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5922 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5923 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5924 || rtype == REG_TYPE_VFD \
5925 || rtype == REG_TYPE_NQ); \
5926 } \
5927 while (0)
5928
5929 #define po_imm_or_fail(min, max, popt) \
5930 do \
5931 { \
5932 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5933 goto failure; \
5934 inst.operands[i].imm = val; \
5935 } \
5936 while (0)
5937
5938 #define po_scalar_or_goto(elsz, label) \
5939 do \
5940 { \
5941 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5942 if (val == FAIL) \
5943 goto label; \
5944 inst.operands[i].reg = val; \
5945 inst.operands[i].isscalar = 1; \
5946 } \
5947 while (0)
5948
5949 #define po_misc_or_fail(expr) \
5950 do \
5951 { \
5952 if (expr) \
5953 goto failure; \
5954 } \
5955 while (0)
5956
5957 #define po_misc_or_fail_no_backtrack(expr) \
5958 do \
5959 { \
5960 result = expr; \
5961 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5962 backtrack_pos = 0; \
5963 if (result != PARSE_OPERAND_SUCCESS) \
5964 goto failure; \
5965 } \
5966 while (0)
5967
5968 skip_whitespace (str);
5969
5970 for (i = 0; upat[i] != OP_stop; i++)
5971 {
5972 op_parse_code = upat[i];
5973 if (op_parse_code >= 1<<16)
5974 op_parse_code = thumb ? (op_parse_code >> 16)
5975 : (op_parse_code & ((1<<16)-1));
5976
5977 if (op_parse_code >= OP_FIRST_OPTIONAL)
5978 {
5979 /* Remember where we are in case we need to backtrack. */
5980 gas_assert (!backtrack_pos);
5981 backtrack_pos = str;
5982 backtrack_error = inst.error;
5983 backtrack_index = i;
5984 }
5985
5986 if (i > 0 && (i > 1 || inst.operands[0].present))
5987 po_char_or_fail (',');
5988
5989 switch (op_parse_code)
5990 {
5991 /* Registers */
5992 case OP_oRRnpc:
5993 case OP_oRRnpcsp:
5994 case OP_RRnpc:
5995 case OP_RRnpcsp:
5996 case OP_oRR:
5997 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5998 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5999 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6000 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6001 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6002 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6003 case OP_oRND:
6004 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6005 case OP_RVC:
6006 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6007 break;
6008 /* Also accept generic coprocessor regs for unknown registers. */
6009 coproc_reg:
6010 po_reg_or_fail (REG_TYPE_CN);
6011 break;
6012 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6013 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6014 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6015 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6016 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6017 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6018 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6019 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6020 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6021 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6022 case OP_oRNQ:
6023 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6024 case OP_oRNDQ:
6025 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6026 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6027 case OP_oRNSDQ:
6028 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6029
6030 /* Neon scalar. Using an element size of 8 means that some invalid
6031 scalars are accepted here, so deal with those in later code. */
6032 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6033
6034 case OP_RNDQ_I0:
6035 {
6036 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6037 break;
6038 try_imm0:
6039 po_imm_or_fail (0, 0, TRUE);
6040 }
6041 break;
6042
6043 case OP_RVSD_I0:
6044 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6045 break;
6046
6047 case OP_RR_RNSC:
6048 {
6049 po_scalar_or_goto (8, try_rr);
6050 break;
6051 try_rr:
6052 po_reg_or_fail (REG_TYPE_RN);
6053 }
6054 break;
6055
6056 case OP_RNSDQ_RNSC:
6057 {
6058 po_scalar_or_goto (8, try_nsdq);
6059 break;
6060 try_nsdq:
6061 po_reg_or_fail (REG_TYPE_NSDQ);
6062 }
6063 break;
6064
6065 case OP_RNDQ_RNSC:
6066 {
6067 po_scalar_or_goto (8, try_ndq);
6068 break;
6069 try_ndq:
6070 po_reg_or_fail (REG_TYPE_NDQ);
6071 }
6072 break;
6073
6074 case OP_RND_RNSC:
6075 {
6076 po_scalar_or_goto (8, try_vfd);
6077 break;
6078 try_vfd:
6079 po_reg_or_fail (REG_TYPE_VFD);
6080 }
6081 break;
6082
6083 case OP_VMOV:
6084 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6085 not careful then bad things might happen. */
6086 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6087 break;
6088
6089 case OP_RNDQ_Ibig:
6090 {
6091 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6092 break;
6093 try_immbig:
6094 /* There's a possibility of getting a 64-bit immediate here, so
6095 we need special handling. */
6096 if (parse_big_immediate (&str, i) == FAIL)
6097 {
6098 inst.error = _("immediate value is out of range");
6099 goto failure;
6100 }
6101 }
6102 break;
6103
6104 case OP_RNDQ_I63b:
6105 {
6106 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6107 break;
6108 try_shimm:
6109 po_imm_or_fail (0, 63, TRUE);
6110 }
6111 break;
6112
6113 case OP_RRnpcb:
6114 po_char_or_fail ('[');
6115 po_reg_or_fail (REG_TYPE_RN);
6116 po_char_or_fail (']');
6117 break;
6118
6119 case OP_RRw:
6120 case OP_oRRw:
6121 po_reg_or_fail (REG_TYPE_RN);
6122 if (skip_past_char (&str, '!') == SUCCESS)
6123 inst.operands[i].writeback = 1;
6124 break;
6125
6126 /* Immediates */
6127 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6128 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6129 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6130 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6131 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6132 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6133 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6134 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6135 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6136 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6137 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6138 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6139
6140 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6141 case OP_oI7b:
6142 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6143 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6144 case OP_oI31b:
6145 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6146 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6147 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6148
6149 /* Immediate variants */
6150 case OP_oI255c:
6151 po_char_or_fail ('{');
6152 po_imm_or_fail (0, 255, TRUE);
6153 po_char_or_fail ('}');
6154 break;
6155
6156 case OP_I31w:
6157 /* The expression parser chokes on a trailing !, so we have
6158 to find it first and zap it. */
6159 {
6160 char *s = str;
6161 while (*s && *s != ',')
6162 s++;
6163 if (s[-1] == '!')
6164 {
6165 s[-1] = '\0';
6166 inst.operands[i].writeback = 1;
6167 }
6168 po_imm_or_fail (0, 31, TRUE);
6169 if (str == s - 1)
6170 str = s;
6171 }
6172 break;
6173
6174 /* Expressions */
6175 case OP_EXPi: EXPi:
6176 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6177 GE_OPT_PREFIX));
6178 break;
6179
6180 case OP_EXP:
6181 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6182 GE_NO_PREFIX));
6183 break;
6184
6185 case OP_EXPr: EXPr:
6186 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6187 GE_NO_PREFIX));
6188 if (inst.reloc.exp.X_op == O_symbol)
6189 {
6190 val = parse_reloc (&str);
6191 if (val == -1)
6192 {
6193 inst.error = _("unrecognized relocation suffix");
6194 goto failure;
6195 }
6196 else if (val != BFD_RELOC_UNUSED)
6197 {
6198 inst.operands[i].imm = val;
6199 inst.operands[i].hasreloc = 1;
6200 }
6201 }
6202 break;
6203
6204 /* Operand for MOVW or MOVT. */
6205 case OP_HALF:
6206 po_misc_or_fail (parse_half (&str));
6207 break;
6208
6209 /* Register or expression. */
6210 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6211 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6212
6213 /* Register or immediate. */
6214 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6215 I0: po_imm_or_fail (0, 0, FALSE); break;
6216
6217 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6218 IF:
6219 if (!is_immediate_prefix (*str))
6220 goto bad_args;
6221 str++;
6222 val = parse_fpa_immediate (&str);
6223 if (val == FAIL)
6224 goto failure;
6225 /* FPA immediates are encoded as registers 8-15.
6226 parse_fpa_immediate has already applied the offset. */
6227 inst.operands[i].reg = val;
6228 inst.operands[i].isreg = 1;
6229 break;
6230
6231 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6232 I32z: po_imm_or_fail (0, 32, FALSE); break;
6233
6234 /* Two kinds of register. */
6235 case OP_RIWR_RIWC:
6236 {
6237 struct reg_entry *rege = arm_reg_parse_multi (&str);
6238 if (!rege
6239 || (rege->type != REG_TYPE_MMXWR
6240 && rege->type != REG_TYPE_MMXWC
6241 && rege->type != REG_TYPE_MMXWCG))
6242 {
6243 inst.error = _("iWMMXt data or control register expected");
6244 goto failure;
6245 }
6246 inst.operands[i].reg = rege->number;
6247 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6248 }
6249 break;
6250
6251 case OP_RIWC_RIWG:
6252 {
6253 struct reg_entry *rege = arm_reg_parse_multi (&str);
6254 if (!rege
6255 || (rege->type != REG_TYPE_MMXWC
6256 && rege->type != REG_TYPE_MMXWCG))
6257 {
6258 inst.error = _("iWMMXt control register expected");
6259 goto failure;
6260 }
6261 inst.operands[i].reg = rege->number;
6262 inst.operands[i].isreg = 1;
6263 }
6264 break;
6265
6266 /* Misc */
6267 case OP_CPSF: val = parse_cps_flags (&str); break;
6268 case OP_ENDI: val = parse_endian_specifier (&str); break;
6269 case OP_oROR: val = parse_ror (&str); break;
6270 case OP_PSR: val = parse_psr (&str); break;
6271 case OP_COND: val = parse_cond (&str); break;
6272 case OP_oBARRIER:val = parse_barrier (&str); break;
6273
6274 case OP_RVC_PSR:
6275 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6276 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6277 break;
6278 try_psr:
6279 val = parse_psr (&str);
6280 break;
6281
6282 case OP_APSR_RR:
6283 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6284 break;
6285 try_apsr:
6286 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6287 instruction). */
6288 if (strncasecmp (str, "APSR_", 5) == 0)
6289 {
6290 unsigned found = 0;
6291 str += 5;
6292 while (found < 15)
6293 switch (*str++)
6294 {
6295 case 'c': found = (found & 1) ? 16 : found | 1; break;
6296 case 'n': found = (found & 2) ? 16 : found | 2; break;
6297 case 'z': found = (found & 4) ? 16 : found | 4; break;
6298 case 'v': found = (found & 8) ? 16 : found | 8; break;
6299 default: found = 16;
6300 }
6301 if (found != 15)
6302 goto failure;
6303 inst.operands[i].isvec = 1;
6304 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6305 inst.operands[i].reg = REG_PC;
6306 }
6307 else
6308 goto failure;
6309 break;
6310
6311 case OP_TB:
6312 po_misc_or_fail (parse_tb (&str));
6313 break;
6314
6315 /* Register lists. */
6316 case OP_REGLST:
6317 val = parse_reg_list (&str);
6318 if (*str == '^')
6319 {
6320 inst.operands[1].writeback = 1;
6321 str++;
6322 }
6323 break;
6324
6325 case OP_VRSLST:
6326 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6327 break;
6328
6329 case OP_VRDLST:
6330 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6331 break;
6332
6333 case OP_VRSDLST:
6334 /* Allow Q registers too. */
6335 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6336 REGLIST_NEON_D);
6337 if (val == FAIL)
6338 {
6339 inst.error = NULL;
6340 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6341 REGLIST_VFP_S);
6342 inst.operands[i].issingle = 1;
6343 }
6344 break;
6345
6346 case OP_NRDLST:
6347 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6348 REGLIST_NEON_D);
6349 break;
6350
6351 case OP_NSTRLST:
6352 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6353 &inst.operands[i].vectype);
6354 break;
6355
6356 /* Addressing modes */
6357 case OP_ADDR:
6358 po_misc_or_fail (parse_address (&str, i));
6359 break;
6360
6361 case OP_ADDRGLDR:
6362 po_misc_or_fail_no_backtrack (
6363 parse_address_group_reloc (&str, i, GROUP_LDR));
6364 break;
6365
6366 case OP_ADDRGLDRS:
6367 po_misc_or_fail_no_backtrack (
6368 parse_address_group_reloc (&str, i, GROUP_LDRS));
6369 break;
6370
6371 case OP_ADDRGLDC:
6372 po_misc_or_fail_no_backtrack (
6373 parse_address_group_reloc (&str, i, GROUP_LDC));
6374 break;
6375
6376 case OP_SH:
6377 po_misc_or_fail (parse_shifter_operand (&str, i));
6378 break;
6379
6380 case OP_SHG:
6381 po_misc_or_fail_no_backtrack (
6382 parse_shifter_operand_group_reloc (&str, i));
6383 break;
6384
6385 case OP_oSHll:
6386 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6387 break;
6388
6389 case OP_oSHar:
6390 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6391 break;
6392
6393 case OP_oSHllar:
6394 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6395 break;
6396
6397 default:
6398 as_fatal (_("unhandled operand code %d"), op_parse_code);
6399 }
6400
6401 /* Various value-based sanity checks and shared operations. We
6402 do not signal immediate failures for the register constraints;
6403 this allows a syntax error to take precedence. */
6404 switch (op_parse_code)
6405 {
6406 case OP_oRRnpc:
6407 case OP_RRnpc:
6408 case OP_RRnpcb:
6409 case OP_RRw:
6410 case OP_oRRw:
6411 case OP_RRnpc_I0:
6412 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6413 inst.error = BAD_PC;
6414 break;
6415
6416 case OP_oRRnpcsp:
6417 case OP_RRnpcsp:
6418 if (inst.operands[i].isreg)
6419 {
6420 if (inst.operands[i].reg == REG_PC)
6421 inst.error = BAD_PC;
6422 else if (inst.operands[i].reg == REG_SP)
6423 inst.error = BAD_SP;
6424 }
6425 break;
6426
6427 case OP_CPSF:
6428 case OP_ENDI:
6429 case OP_oROR:
6430 case OP_PSR:
6431 case OP_RVC_PSR:
6432 case OP_COND:
6433 case OP_oBARRIER:
6434 case OP_REGLST:
6435 case OP_VRSLST:
6436 case OP_VRDLST:
6437 case OP_VRSDLST:
6438 case OP_NRDLST:
6439 case OP_NSTRLST:
6440 if (val == FAIL)
6441 goto failure;
6442 inst.operands[i].imm = val;
6443 break;
6444
6445 default:
6446 break;
6447 }
6448
6449 /* If we get here, this operand was successfully parsed. */
6450 inst.operands[i].present = 1;
6451 continue;
6452
6453 bad_args:
6454 inst.error = BAD_ARGS;
6455
6456 failure:
6457 if (!backtrack_pos)
6458 {
6459 /* The parse routine should already have set inst.error, but set a
6460 default here just in case. */
6461 if (!inst.error)
6462 inst.error = _("syntax error");
6463 return FAIL;
6464 }
6465
6466 /* Do not backtrack over a trailing optional argument that
6467 absorbed some text. We will only fail again, with the
6468 'garbage following instruction' error message, which is
6469 probably less helpful than the current one. */
6470 if (backtrack_index == i && backtrack_pos != str
6471 && upat[i+1] == OP_stop)
6472 {
6473 if (!inst.error)
6474 inst.error = _("syntax error");
6475 return FAIL;
6476 }
6477
6478 /* Try again, skipping the optional argument at backtrack_pos. */
6479 str = backtrack_pos;
6480 inst.error = backtrack_error;
6481 inst.operands[backtrack_index].present = 0;
6482 i = backtrack_index;
6483 backtrack_pos = 0;
6484 }
6485
6486 /* Check that we have parsed all the arguments. */
6487 if (*str != '\0' && !inst.error)
6488 inst.error = _("garbage following instruction");
6489
6490 return inst.error ? FAIL : SUCCESS;
6491 }
6492
6493 #undef po_char_or_fail
6494 #undef po_reg_or_fail
6495 #undef po_reg_or_goto
6496 #undef po_imm_or_fail
6497 #undef po_scalar_or_fail
6498
6499 /* Shorthand macro for instruction encoding functions issuing errors. */
6500 #define constraint(expr, err) \
6501 do \
6502 { \
6503 if (expr) \
6504 { \
6505 inst.error = err; \
6506 return; \
6507 } \
6508 } \
6509 while (0)
6510
6511 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6512 instructions are unpredictable if these registers are used. This
6513 is the BadReg predicate in ARM's Thumb-2 documentation. */
6514 #define reject_bad_reg(reg) \
6515 do \
6516 if (reg == REG_SP || reg == REG_PC) \
6517 { \
6518 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6519 return; \
6520 } \
6521 while (0)
6522
6523 /* If REG is R13 (the stack pointer), warn that its use is
6524 deprecated. */
6525 #define warn_deprecated_sp(reg) \
6526 do \
6527 if (warn_on_deprecated && reg == REG_SP) \
6528 as_warn (_("use of r13 is deprecated")); \
6529 while (0)
6530
6531 /* Functions for operand encoding. ARM, then Thumb. */
6532
6533 #define rotate_left(v, n) (v << n | v >> (32 - n))
6534
6535 /* If VAL can be encoded in the immediate field of an ARM instruction,
6536 return the encoded form. Otherwise, return FAIL. */
6537
6538 static unsigned int
6539 encode_arm_immediate (unsigned int val)
6540 {
6541 unsigned int a, i;
6542
6543 for (i = 0; i < 32; i += 2)
6544 if ((a = rotate_left (val, i)) <= 0xff)
6545 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6546
6547 return FAIL;
6548 }
6549
6550 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6551 return the encoded form. Otherwise, return FAIL. */
6552 static unsigned int
6553 encode_thumb32_immediate (unsigned int val)
6554 {
6555 unsigned int a, i;
6556
6557 if (val <= 0xff)
6558 return val;
6559
6560 for (i = 1; i <= 24; i++)
6561 {
6562 a = val >> i;
6563 if ((val & ~(0xff << i)) == 0)
6564 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6565 }
6566
6567 a = val & 0xff;
6568 if (val == ((a << 16) | a))
6569 return 0x100 | a;
6570 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6571 return 0x300 | a;
6572
6573 a = val & 0xff00;
6574 if (val == ((a << 16) | a))
6575 return 0x200 | (a >> 8);
6576
6577 return FAIL;
6578 }
6579 /* Encode a VFP SP or DP register number into inst.instruction. */
6580
6581 static void
6582 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6583 {
6584 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6585 && reg > 15)
6586 {
6587 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6588 {
6589 if (thumb_mode)
6590 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6591 fpu_vfp_ext_d32);
6592 else
6593 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6594 fpu_vfp_ext_d32);
6595 }
6596 else
6597 {
6598 first_error (_("D register out of range for selected VFP version"));
6599 return;
6600 }
6601 }
6602
6603 switch (pos)
6604 {
6605 case VFP_REG_Sd:
6606 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6607 break;
6608
6609 case VFP_REG_Sn:
6610 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6611 break;
6612
6613 case VFP_REG_Sm:
6614 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6615 break;
6616
6617 case VFP_REG_Dd:
6618 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6619 break;
6620
6621 case VFP_REG_Dn:
6622 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6623 break;
6624
6625 case VFP_REG_Dm:
6626 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6627 break;
6628
6629 default:
6630 abort ();
6631 }
6632 }
6633
6634 /* Encode a <shift> in an ARM-format instruction. The immediate,
6635 if any, is handled by md_apply_fix. */
6636 static void
6637 encode_arm_shift (int i)
6638 {
6639 if (inst.operands[i].shift_kind == SHIFT_RRX)
6640 inst.instruction |= SHIFT_ROR << 5;
6641 else
6642 {
6643 inst.instruction |= inst.operands[i].shift_kind << 5;
6644 if (inst.operands[i].immisreg)
6645 {
6646 inst.instruction |= SHIFT_BY_REG;
6647 inst.instruction |= inst.operands[i].imm << 8;
6648 }
6649 else
6650 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6651 }
6652 }
6653
6654 static void
6655 encode_arm_shifter_operand (int i)
6656 {
6657 if (inst.operands[i].isreg)
6658 {
6659 inst.instruction |= inst.operands[i].reg;
6660 encode_arm_shift (i);
6661 }
6662 else
6663 inst.instruction |= INST_IMMEDIATE;
6664 }
6665
6666 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6667 static void
6668 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6669 {
6670 gas_assert (inst.operands[i].isreg);
6671 inst.instruction |= inst.operands[i].reg << 16;
6672
6673 if (inst.operands[i].preind)
6674 {
6675 if (is_t)
6676 {
6677 inst.error = _("instruction does not accept preindexed addressing");
6678 return;
6679 }
6680 inst.instruction |= PRE_INDEX;
6681 if (inst.operands[i].writeback)
6682 inst.instruction |= WRITE_BACK;
6683
6684 }
6685 else if (inst.operands[i].postind)
6686 {
6687 gas_assert (inst.operands[i].writeback);
6688 if (is_t)
6689 inst.instruction |= WRITE_BACK;
6690 }
6691 else /* unindexed - only for coprocessor */
6692 {
6693 inst.error = _("instruction does not accept unindexed addressing");
6694 return;
6695 }
6696
6697 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6698 && (((inst.instruction & 0x000f0000) >> 16)
6699 == ((inst.instruction & 0x0000f000) >> 12)))
6700 as_warn ((inst.instruction & LOAD_BIT)
6701 ? _("destination register same as write-back base")
6702 : _("source register same as write-back base"));
6703 }
6704
6705 /* inst.operands[i] was set up by parse_address. Encode it into an
6706 ARM-format mode 2 load or store instruction. If is_t is true,
6707 reject forms that cannot be used with a T instruction (i.e. not
6708 post-indexed). */
6709 static void
6710 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6711 {
6712 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6713
6714 encode_arm_addr_mode_common (i, is_t);
6715
6716 if (inst.operands[i].immisreg)
6717 {
6718 constraint ((inst.operands[i].imm == REG_PC
6719 || (is_pc && inst.operands[i].writeback)),
6720 BAD_PC_ADDRESSING);
6721 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6722 inst.instruction |= inst.operands[i].imm;
6723 if (!inst.operands[i].negative)
6724 inst.instruction |= INDEX_UP;
6725 if (inst.operands[i].shifted)
6726 {
6727 if (inst.operands[i].shift_kind == SHIFT_RRX)
6728 inst.instruction |= SHIFT_ROR << 5;
6729 else
6730 {
6731 inst.instruction |= inst.operands[i].shift_kind << 5;
6732 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6733 }
6734 }
6735 }
6736 else /* immediate offset in inst.reloc */
6737 {
6738 if (is_pc && !inst.reloc.pc_rel)
6739 {
6740 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
6741 /* BAD_PC_ADDRESSING Condition =
6742 is_load => is_t
6743 which becomes !is_load || is_t. */
6744 constraint ((!is_load || is_t),
6745 BAD_PC_ADDRESSING);
6746 }
6747
6748 if (inst.reloc.type == BFD_RELOC_UNUSED)
6749 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6750 }
6751 }
6752
6753 /* inst.operands[i] was set up by parse_address. Encode it into an
6754 ARM-format mode 3 load or store instruction. Reject forms that
6755 cannot be used with such instructions. If is_t is true, reject
6756 forms that cannot be used with a T instruction (i.e. not
6757 post-indexed). */
6758 static void
6759 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6760 {
6761 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6762 {
6763 inst.error = _("instruction does not accept scaled register index");
6764 return;
6765 }
6766
6767 encode_arm_addr_mode_common (i, is_t);
6768
6769 if (inst.operands[i].immisreg)
6770 {
6771 constraint ((inst.operands[i].imm == REG_PC
6772 || inst.operands[i].reg == REG_PC),
6773 BAD_PC_ADDRESSING);
6774 inst.instruction |= inst.operands[i].imm;
6775 if (!inst.operands[i].negative)
6776 inst.instruction |= INDEX_UP;
6777 }
6778 else /* immediate offset in inst.reloc */
6779 {
6780 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6781 && inst.operands[i].writeback),
6782 BAD_PC_WRITEBACK);
6783 inst.instruction |= HWOFFSET_IMM;
6784 if (inst.reloc.type == BFD_RELOC_UNUSED)
6785 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6786 }
6787 }
6788
6789 /* inst.operands[i] was set up by parse_address. Encode it into an
6790 ARM-format instruction. Reject all forms which cannot be encoded
6791 into a coprocessor load/store instruction. If wb_ok is false,
6792 reject use of writeback; if unind_ok is false, reject use of
6793 unindexed addressing. If reloc_override is not 0, use it instead
6794 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6795 (in which case it is preserved). */
6796
6797 static int
6798 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6799 {
6800 inst.instruction |= inst.operands[i].reg << 16;
6801
6802 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
6803
6804 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6805 {
6806 gas_assert (!inst.operands[i].writeback);
6807 if (!unind_ok)
6808 {
6809 inst.error = _("instruction does not support unindexed addressing");
6810 return FAIL;
6811 }
6812 inst.instruction |= inst.operands[i].imm;
6813 inst.instruction |= INDEX_UP;
6814 return SUCCESS;
6815 }
6816
6817 if (inst.operands[i].preind)
6818 inst.instruction |= PRE_INDEX;
6819
6820 if (inst.operands[i].writeback)
6821 {
6822 if (inst.operands[i].reg == REG_PC)
6823 {
6824 inst.error = _("pc may not be used with write-back");
6825 return FAIL;
6826 }
6827 if (!wb_ok)
6828 {
6829 inst.error = _("instruction does not support writeback");
6830 return FAIL;
6831 }
6832 inst.instruction |= WRITE_BACK;
6833 }
6834
6835 if (reloc_override)
6836 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
6837 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6838 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6839 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6840 {
6841 if (thumb_mode)
6842 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6843 else
6844 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6845 }
6846
6847 return SUCCESS;
6848 }
6849
6850 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6851 Determine whether it can be performed with a move instruction; if
6852 it can, convert inst.instruction to that move instruction and
6853 return TRUE; if it can't, convert inst.instruction to a literal-pool
6854 load and return FALSE. If this is not a valid thing to do in the
6855 current context, set inst.error and return TRUE.
6856
6857 inst.operands[i] describes the destination register. */
6858
6859 static bfd_boolean
6860 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6861 {
6862 unsigned long tbit;
6863
6864 if (thumb_p)
6865 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6866 else
6867 tbit = LOAD_BIT;
6868
6869 if ((inst.instruction & tbit) == 0)
6870 {
6871 inst.error = _("invalid pseudo operation");
6872 return TRUE;
6873 }
6874 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6875 {
6876 inst.error = _("constant expression expected");
6877 return TRUE;
6878 }
6879 if (inst.reloc.exp.X_op == O_constant)
6880 {
6881 if (thumb_p)
6882 {
6883 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6884 {
6885 /* This can be done with a mov(1) instruction. */
6886 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6887 inst.instruction |= inst.reloc.exp.X_add_number;
6888 return TRUE;
6889 }
6890 }
6891 else
6892 {
6893 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6894 if (value != FAIL)
6895 {
6896 /* This can be done with a mov instruction. */
6897 inst.instruction &= LITERAL_MASK;
6898 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6899 inst.instruction |= value & 0xfff;
6900 return TRUE;
6901 }
6902
6903 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6904 if (value != FAIL)
6905 {
6906 /* This can be done with a mvn instruction. */
6907 inst.instruction &= LITERAL_MASK;
6908 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6909 inst.instruction |= value & 0xfff;
6910 return TRUE;
6911 }
6912 }
6913 }
6914
6915 if (add_to_lit_pool () == FAIL)
6916 {
6917 inst.error = _("literal pool insertion failed");
6918 return TRUE;
6919 }
6920 inst.operands[1].reg = REG_PC;
6921 inst.operands[1].isreg = 1;
6922 inst.operands[1].preind = 1;
6923 inst.reloc.pc_rel = 1;
6924 inst.reloc.type = (thumb_p
6925 ? BFD_RELOC_ARM_THUMB_OFFSET
6926 : (mode_3
6927 ? BFD_RELOC_ARM_HWLITERAL
6928 : BFD_RELOC_ARM_LITERAL));
6929 return FALSE;
6930 }
6931
6932 /* Functions for instruction encoding, sorted by sub-architecture.
6933 First some generics; their names are taken from the conventional
6934 bit positions for register arguments in ARM format instructions. */
6935
6936 static void
6937 do_noargs (void)
6938 {
6939 }
6940
6941 static void
6942 do_rd (void)
6943 {
6944 inst.instruction |= inst.operands[0].reg << 12;
6945 }
6946
6947 static void
6948 do_rd_rm (void)
6949 {
6950 inst.instruction |= inst.operands[0].reg << 12;
6951 inst.instruction |= inst.operands[1].reg;
6952 }
6953
6954 static void
6955 do_rd_rn (void)
6956 {
6957 inst.instruction |= inst.operands[0].reg << 12;
6958 inst.instruction |= inst.operands[1].reg << 16;
6959 }
6960
6961 static void
6962 do_rn_rd (void)
6963 {
6964 inst.instruction |= inst.operands[0].reg << 16;
6965 inst.instruction |= inst.operands[1].reg << 12;
6966 }
6967
6968 static void
6969 do_rd_rm_rn (void)
6970 {
6971 unsigned Rn = inst.operands[2].reg;
6972 /* Enforce restrictions on SWP instruction. */
6973 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6974 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6975 _("Rn must not overlap other operands"));
6976 inst.instruction |= inst.operands[0].reg << 12;
6977 inst.instruction |= inst.operands[1].reg;
6978 inst.instruction |= Rn << 16;
6979 }
6980
6981 static void
6982 do_rd_rn_rm (void)
6983 {
6984 inst.instruction |= inst.operands[0].reg << 12;
6985 inst.instruction |= inst.operands[1].reg << 16;
6986 inst.instruction |= inst.operands[2].reg;
6987 }
6988
6989 static void
6990 do_rm_rd_rn (void)
6991 {
6992 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
6993 constraint (((inst.reloc.exp.X_op != O_constant
6994 && inst.reloc.exp.X_op != O_illegal)
6995 || inst.reloc.exp.X_add_number != 0),
6996 BAD_ADDR_MODE);
6997 inst.instruction |= inst.operands[0].reg;
6998 inst.instruction |= inst.operands[1].reg << 12;
6999 inst.instruction |= inst.operands[2].reg << 16;
7000 }
7001
7002 static void
7003 do_imm0 (void)
7004 {
7005 inst.instruction |= inst.operands[0].imm;
7006 }
7007
7008 static void
7009 do_rd_cpaddr (void)
7010 {
7011 inst.instruction |= inst.operands[0].reg << 12;
7012 encode_arm_cp_address (1, TRUE, TRUE, 0);
7013 }
7014
7015 /* ARM instructions, in alphabetical order by function name (except
7016 that wrapper functions appear immediately after the function they
7017 wrap). */
7018
7019 /* This is a pseudo-op of the form "adr rd, label" to be converted
7020 into a relative address of the form "add rd, pc, #label-.-8". */
7021
7022 static void
7023 do_adr (void)
7024 {
7025 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7026
7027 /* Frag hacking will turn this into a sub instruction if the offset turns
7028 out to be negative. */
7029 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7030 inst.reloc.pc_rel = 1;
7031 inst.reloc.exp.X_add_number -= 8;
7032 }
7033
7034 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7035 into a relative address of the form:
7036 add rd, pc, #low(label-.-8)"
7037 add rd, rd, #high(label-.-8)" */
7038
7039 static void
7040 do_adrl (void)
7041 {
7042 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7043
7044 /* Frag hacking will turn this into a sub instruction if the offset turns
7045 out to be negative. */
7046 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7047 inst.reloc.pc_rel = 1;
7048 inst.size = INSN_SIZE * 2;
7049 inst.reloc.exp.X_add_number -= 8;
7050 }
7051
7052 static void
7053 do_arit (void)
7054 {
7055 if (!inst.operands[1].present)
7056 inst.operands[1].reg = inst.operands[0].reg;
7057 inst.instruction |= inst.operands[0].reg << 12;
7058 inst.instruction |= inst.operands[1].reg << 16;
7059 encode_arm_shifter_operand (2);
7060 }
7061
7062 static void
7063 do_barrier (void)
7064 {
7065 if (inst.operands[0].present)
7066 {
7067 constraint ((inst.instruction & 0xf0) != 0x40
7068 && inst.operands[0].imm != 0xf,
7069 _("bad barrier type"));
7070 inst.instruction |= inst.operands[0].imm;
7071 }
7072 else
7073 inst.instruction |= 0xf;
7074 }
7075
7076 static void
7077 do_bfc (void)
7078 {
7079 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7080 constraint (msb > 32, _("bit-field extends past end of register"));
7081 /* The instruction encoding stores the LSB and MSB,
7082 not the LSB and width. */
7083 inst.instruction |= inst.operands[0].reg << 12;
7084 inst.instruction |= inst.operands[1].imm << 7;
7085 inst.instruction |= (msb - 1) << 16;
7086 }
7087
7088 static void
7089 do_bfi (void)
7090 {
7091 unsigned int msb;
7092
7093 /* #0 in second position is alternative syntax for bfc, which is
7094 the same instruction but with REG_PC in the Rm field. */
7095 if (!inst.operands[1].isreg)
7096 inst.operands[1].reg = REG_PC;
7097
7098 msb = inst.operands[2].imm + inst.operands[3].imm;
7099 constraint (msb > 32, _("bit-field extends past end of register"));
7100 /* The instruction encoding stores the LSB and MSB,
7101 not the LSB and width. */
7102 inst.instruction |= inst.operands[0].reg << 12;
7103 inst.instruction |= inst.operands[1].reg;
7104 inst.instruction |= inst.operands[2].imm << 7;
7105 inst.instruction |= (msb - 1) << 16;
7106 }
7107
7108 static void
7109 do_bfx (void)
7110 {
7111 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7112 _("bit-field extends past end of register"));
7113 inst.instruction |= inst.operands[0].reg << 12;
7114 inst.instruction |= inst.operands[1].reg;
7115 inst.instruction |= inst.operands[2].imm << 7;
7116 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7117 }
7118
7119 /* ARM V5 breakpoint instruction (argument parse)
7120 BKPT <16 bit unsigned immediate>
7121 Instruction is not conditional.
7122 The bit pattern given in insns[] has the COND_ALWAYS condition,
7123 and it is an error if the caller tried to override that. */
7124
7125 static void
7126 do_bkpt (void)
7127 {
7128 /* Top 12 of 16 bits to bits 19:8. */
7129 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7130
7131 /* Bottom 4 of 16 bits to bits 3:0. */
7132 inst.instruction |= inst.operands[0].imm & 0xf;
7133 }
7134
7135 static void
7136 encode_branch (int default_reloc)
7137 {
7138 if (inst.operands[0].hasreloc)
7139 {
7140 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7141 _("the only suffix valid here is '(plt)'"));
7142 inst.reloc.type = BFD_RELOC_ARM_PLT32;
7143 }
7144 else
7145 {
7146 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7147 }
7148 inst.reloc.pc_rel = 1;
7149 }
7150
7151 static void
7152 do_branch (void)
7153 {
7154 #ifdef OBJ_ELF
7155 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7156 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7157 else
7158 #endif
7159 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7160 }
7161
7162 static void
7163 do_bl (void)
7164 {
7165 #ifdef OBJ_ELF
7166 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7167 {
7168 if (inst.cond == COND_ALWAYS)
7169 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7170 else
7171 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7172 }
7173 else
7174 #endif
7175 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7176 }
7177
7178 /* ARM V5 branch-link-exchange instruction (argument parse)
7179 BLX <target_addr> ie BLX(1)
7180 BLX{<condition>} <Rm> ie BLX(2)
7181 Unfortunately, there are two different opcodes for this mnemonic.
7182 So, the insns[].value is not used, and the code here zaps values
7183 into inst.instruction.
7184 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7185
7186 static void
7187 do_blx (void)
7188 {
7189 if (inst.operands[0].isreg)
7190 {
7191 /* Arg is a register; the opcode provided by insns[] is correct.
7192 It is not illegal to do "blx pc", just useless. */
7193 if (inst.operands[0].reg == REG_PC)
7194 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7195
7196 inst.instruction |= inst.operands[0].reg;
7197 }
7198 else
7199 {
7200 /* Arg is an address; this instruction cannot be executed
7201 conditionally, and the opcode must be adjusted.
7202 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7203 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7204 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7205 inst.instruction = 0xfa000000;
7206 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7207 }
7208 }
7209
7210 static void
7211 do_bx (void)
7212 {
7213 bfd_boolean want_reloc;
7214
7215 if (inst.operands[0].reg == REG_PC)
7216 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7217
7218 inst.instruction |= inst.operands[0].reg;
7219 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7220 it is for ARMv4t or earlier. */
7221 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7222 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7223 want_reloc = TRUE;
7224
7225 #ifdef OBJ_ELF
7226 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7227 #endif
7228 want_reloc = FALSE;
7229
7230 if (want_reloc)
7231 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7232 }
7233
7234
7235 /* ARM v5TEJ. Jump to Jazelle code. */
7236
7237 static void
7238 do_bxj (void)
7239 {
7240 if (inst.operands[0].reg == REG_PC)
7241 as_tsktsk (_("use of r15 in bxj is not really useful"));
7242
7243 inst.instruction |= inst.operands[0].reg;
7244 }
7245
7246 /* Co-processor data operation:
7247 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7248 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7249 static void
7250 do_cdp (void)
7251 {
7252 inst.instruction |= inst.operands[0].reg << 8;
7253 inst.instruction |= inst.operands[1].imm << 20;
7254 inst.instruction |= inst.operands[2].reg << 12;
7255 inst.instruction |= inst.operands[3].reg << 16;
7256 inst.instruction |= inst.operands[4].reg;
7257 inst.instruction |= inst.operands[5].imm << 5;
7258 }
7259
7260 static void
7261 do_cmp (void)
7262 {
7263 inst.instruction |= inst.operands[0].reg << 16;
7264 encode_arm_shifter_operand (1);
7265 }
7266
7267 /* Transfer between coprocessor and ARM registers.
7268 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7269 MRC2
7270 MCR{cond}
7271 MCR2
7272
7273 No special properties. */
7274
7275 static void
7276 do_co_reg (void)
7277 {
7278 unsigned Rd;
7279
7280 Rd = inst.operands[2].reg;
7281 if (thumb_mode)
7282 {
7283 if (inst.instruction == 0xee000010
7284 || inst.instruction == 0xfe000010)
7285 /* MCR, MCR2 */
7286 reject_bad_reg (Rd);
7287 else
7288 /* MRC, MRC2 */
7289 constraint (Rd == REG_SP, BAD_SP);
7290 }
7291 else
7292 {
7293 /* MCR */
7294 if (inst.instruction == 0xe000010)
7295 constraint (Rd == REG_PC, BAD_PC);
7296 }
7297
7298
7299 inst.instruction |= inst.operands[0].reg << 8;
7300 inst.instruction |= inst.operands[1].imm << 21;
7301 inst.instruction |= Rd << 12;
7302 inst.instruction |= inst.operands[3].reg << 16;
7303 inst.instruction |= inst.operands[4].reg;
7304 inst.instruction |= inst.operands[5].imm << 5;
7305 }
7306
7307 /* Transfer between coprocessor register and pair of ARM registers.
7308 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7309 MCRR2
7310 MRRC{cond}
7311 MRRC2
7312
7313 Two XScale instructions are special cases of these:
7314
7315 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7316 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7317
7318 Result unpredictable if Rd or Rn is R15. */
7319
7320 static void
7321 do_co_reg2c (void)
7322 {
7323 unsigned Rd, Rn;
7324
7325 Rd = inst.operands[2].reg;
7326 Rn = inst.operands[3].reg;
7327
7328 if (thumb_mode)
7329 {
7330 reject_bad_reg (Rd);
7331 reject_bad_reg (Rn);
7332 }
7333 else
7334 {
7335 constraint (Rd == REG_PC, BAD_PC);
7336 constraint (Rn == REG_PC, BAD_PC);
7337 }
7338
7339 inst.instruction |= inst.operands[0].reg << 8;
7340 inst.instruction |= inst.operands[1].imm << 4;
7341 inst.instruction |= Rd << 12;
7342 inst.instruction |= Rn << 16;
7343 inst.instruction |= inst.operands[4].reg;
7344 }
7345
7346 static void
7347 do_cpsi (void)
7348 {
7349 inst.instruction |= inst.operands[0].imm << 6;
7350 if (inst.operands[1].present)
7351 {
7352 inst.instruction |= CPSI_MMOD;
7353 inst.instruction |= inst.operands[1].imm;
7354 }
7355 }
7356
7357 static void
7358 do_dbg (void)
7359 {
7360 inst.instruction |= inst.operands[0].imm;
7361 }
7362
7363 static void
7364 do_it (void)
7365 {
7366 /* There is no IT instruction in ARM mode. We
7367 process it to do the validation as if in
7368 thumb mode, just in case the code gets
7369 assembled for thumb using the unified syntax. */
7370
7371 inst.size = 0;
7372 if (unified_syntax)
7373 {
7374 set_it_insn_type (IT_INSN);
7375 now_it.mask = (inst.instruction & 0xf) | 0x10;
7376 now_it.cc = inst.operands[0].imm;
7377 }
7378 }
7379
7380 static void
7381 do_ldmstm (void)
7382 {
7383 int base_reg = inst.operands[0].reg;
7384 int range = inst.operands[1].imm;
7385
7386 inst.instruction |= base_reg << 16;
7387 inst.instruction |= range;
7388
7389 if (inst.operands[1].writeback)
7390 inst.instruction |= LDM_TYPE_2_OR_3;
7391
7392 if (inst.operands[0].writeback)
7393 {
7394 inst.instruction |= WRITE_BACK;
7395 /* Check for unpredictable uses of writeback. */
7396 if (inst.instruction & LOAD_BIT)
7397 {
7398 /* Not allowed in LDM type 2. */
7399 if ((inst.instruction & LDM_TYPE_2_OR_3)
7400 && ((range & (1 << REG_PC)) == 0))
7401 as_warn (_("writeback of base register is UNPREDICTABLE"));
7402 /* Only allowed if base reg not in list for other types. */
7403 else if (range & (1 << base_reg))
7404 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7405 }
7406 else /* STM. */
7407 {
7408 /* Not allowed for type 2. */
7409 if (inst.instruction & LDM_TYPE_2_OR_3)
7410 as_warn (_("writeback of base register is UNPREDICTABLE"));
7411 /* Only allowed if base reg not in list, or first in list. */
7412 else if ((range & (1 << base_reg))
7413 && (range & ((1 << base_reg) - 1)))
7414 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7415 }
7416 }
7417 }
7418
7419 /* ARMv5TE load-consecutive (argument parse)
7420 Mode is like LDRH.
7421
7422 LDRccD R, mode
7423 STRccD R, mode. */
7424
7425 static void
7426 do_ldrd (void)
7427 {
7428 constraint (inst.operands[0].reg % 2 != 0,
7429 _("first destination register must be even"));
7430 constraint (inst.operands[1].present
7431 && inst.operands[1].reg != inst.operands[0].reg + 1,
7432 _("can only load two consecutive registers"));
7433 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7434 constraint (!inst.operands[2].isreg, _("'[' expected"));
7435
7436 if (!inst.operands[1].present)
7437 inst.operands[1].reg = inst.operands[0].reg + 1;
7438
7439 if (inst.instruction & LOAD_BIT)
7440 {
7441 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7442 register and the first register written; we have to diagnose
7443 overlap between the base and the second register written here. */
7444
7445 if (inst.operands[2].reg == inst.operands[1].reg
7446 && (inst.operands[2].writeback || inst.operands[2].postind))
7447 as_warn (_("base register written back, and overlaps "
7448 "second destination register"));
7449
7450 /* For an index-register load, the index register must not overlap the
7451 destination (even if not write-back). */
7452 else if (inst.operands[2].immisreg
7453 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7454 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7455 as_warn (_("index register overlaps destination register"));
7456 }
7457
7458 inst.instruction |= inst.operands[0].reg << 12;
7459 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7460 }
7461
7462 static void
7463 do_ldrex (void)
7464 {
7465 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7466 || inst.operands[1].postind || inst.operands[1].writeback
7467 || inst.operands[1].immisreg || inst.operands[1].shifted
7468 || inst.operands[1].negative
7469 /* This can arise if the programmer has written
7470 strex rN, rM, foo
7471 or if they have mistakenly used a register name as the last
7472 operand, eg:
7473 strex rN, rM, rX
7474 It is very difficult to distinguish between these two cases
7475 because "rX" might actually be a label. ie the register
7476 name has been occluded by a symbol of the same name. So we
7477 just generate a general 'bad addressing mode' type error
7478 message and leave it up to the programmer to discover the
7479 true cause and fix their mistake. */
7480 || (inst.operands[1].reg == REG_PC),
7481 BAD_ADDR_MODE);
7482
7483 constraint (inst.reloc.exp.X_op != O_constant
7484 || inst.reloc.exp.X_add_number != 0,
7485 _("offset must be zero in ARM encoding"));
7486
7487 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7488
7489 inst.instruction |= inst.operands[0].reg << 12;
7490 inst.instruction |= inst.operands[1].reg << 16;
7491 inst.reloc.type = BFD_RELOC_UNUSED;
7492 }
7493
7494 static void
7495 do_ldrexd (void)
7496 {
7497 constraint (inst.operands[0].reg % 2 != 0,
7498 _("even register required"));
7499 constraint (inst.operands[1].present
7500 && inst.operands[1].reg != inst.operands[0].reg + 1,
7501 _("can only load two consecutive registers"));
7502 /* If op 1 were present and equal to PC, this function wouldn't
7503 have been called in the first place. */
7504 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7505
7506 inst.instruction |= inst.operands[0].reg << 12;
7507 inst.instruction |= inst.operands[2].reg << 16;
7508 }
7509
7510 static void
7511 do_ldst (void)
7512 {
7513 inst.instruction |= inst.operands[0].reg << 12;
7514 if (!inst.operands[1].isreg)
7515 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7516 return;
7517 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7518 }
7519
7520 static void
7521 do_ldstt (void)
7522 {
7523 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7524 reject [Rn,...]. */
7525 if (inst.operands[1].preind)
7526 {
7527 constraint (inst.reloc.exp.X_op != O_constant
7528 || inst.reloc.exp.X_add_number != 0,
7529 _("this instruction requires a post-indexed address"));
7530
7531 inst.operands[1].preind = 0;
7532 inst.operands[1].postind = 1;
7533 inst.operands[1].writeback = 1;
7534 }
7535 inst.instruction |= inst.operands[0].reg << 12;
7536 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7537 }
7538
7539 /* Halfword and signed-byte load/store operations. */
7540
7541 static void
7542 do_ldstv4 (void)
7543 {
7544 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7545 inst.instruction |= inst.operands[0].reg << 12;
7546 if (!inst.operands[1].isreg)
7547 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7548 return;
7549 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7550 }
7551
7552 static void
7553 do_ldsttv4 (void)
7554 {
7555 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7556 reject [Rn,...]. */
7557 if (inst.operands[1].preind)
7558 {
7559 constraint (inst.reloc.exp.X_op != O_constant
7560 || inst.reloc.exp.X_add_number != 0,
7561 _("this instruction requires a post-indexed address"));
7562
7563 inst.operands[1].preind = 0;
7564 inst.operands[1].postind = 1;
7565 inst.operands[1].writeback = 1;
7566 }
7567 inst.instruction |= inst.operands[0].reg << 12;
7568 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7569 }
7570
7571 /* Co-processor register load/store.
7572 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7573 static void
7574 do_lstc (void)
7575 {
7576 inst.instruction |= inst.operands[0].reg << 8;
7577 inst.instruction |= inst.operands[1].reg << 12;
7578 encode_arm_cp_address (2, TRUE, TRUE, 0);
7579 }
7580
7581 static void
7582 do_mlas (void)
7583 {
7584 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7585 if (inst.operands[0].reg == inst.operands[1].reg
7586 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7587 && !(inst.instruction & 0x00400000))
7588 as_tsktsk (_("Rd and Rm should be different in mla"));
7589
7590 inst.instruction |= inst.operands[0].reg << 16;
7591 inst.instruction |= inst.operands[1].reg;
7592 inst.instruction |= inst.operands[2].reg << 8;
7593 inst.instruction |= inst.operands[3].reg << 12;
7594 }
7595
7596 static void
7597 do_mov (void)
7598 {
7599 inst.instruction |= inst.operands[0].reg << 12;
7600 encode_arm_shifter_operand (1);
7601 }
7602
7603 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7604 static void
7605 do_mov16 (void)
7606 {
7607 bfd_vma imm;
7608 bfd_boolean top;
7609
7610 top = (inst.instruction & 0x00400000) != 0;
7611 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7612 _(":lower16: not allowed this instruction"));
7613 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7614 _(":upper16: not allowed instruction"));
7615 inst.instruction |= inst.operands[0].reg << 12;
7616 if (inst.reloc.type == BFD_RELOC_UNUSED)
7617 {
7618 imm = inst.reloc.exp.X_add_number;
7619 /* The value is in two pieces: 0:11, 16:19. */
7620 inst.instruction |= (imm & 0x00000fff);
7621 inst.instruction |= (imm & 0x0000f000) << 4;
7622 }
7623 }
7624
7625 static void do_vfp_nsyn_opcode (const char *);
7626
7627 static int
7628 do_vfp_nsyn_mrs (void)
7629 {
7630 if (inst.operands[0].isvec)
7631 {
7632 if (inst.operands[1].reg != 1)
7633 first_error (_("operand 1 must be FPSCR"));
7634 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7635 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7636 do_vfp_nsyn_opcode ("fmstat");
7637 }
7638 else if (inst.operands[1].isvec)
7639 do_vfp_nsyn_opcode ("fmrx");
7640 else
7641 return FAIL;
7642
7643 return SUCCESS;
7644 }
7645
7646 static int
7647 do_vfp_nsyn_msr (void)
7648 {
7649 if (inst.operands[0].isvec)
7650 do_vfp_nsyn_opcode ("fmxr");
7651 else
7652 return FAIL;
7653
7654 return SUCCESS;
7655 }
7656
7657 static void
7658 do_vmrs (void)
7659 {
7660 unsigned Rt = inst.operands[0].reg;
7661
7662 if (thumb_mode && inst.operands[0].reg == REG_SP)
7663 {
7664 inst.error = BAD_SP;
7665 return;
7666 }
7667
7668 /* APSR_ sets isvec. All other refs to PC are illegal. */
7669 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7670 {
7671 inst.error = BAD_PC;
7672 return;
7673 }
7674
7675 if (inst.operands[1].reg != 1)
7676 first_error (_("operand 1 must be FPSCR"));
7677
7678 inst.instruction |= (Rt << 12);
7679 }
7680
7681 static void
7682 do_vmsr (void)
7683 {
7684 unsigned Rt = inst.operands[1].reg;
7685
7686 if (thumb_mode)
7687 reject_bad_reg (Rt);
7688 else if (Rt == REG_PC)
7689 {
7690 inst.error = BAD_PC;
7691 return;
7692 }
7693
7694 if (inst.operands[0].reg != 1)
7695 first_error (_("operand 0 must be FPSCR"));
7696
7697 inst.instruction |= (Rt << 12);
7698 }
7699
7700 static void
7701 do_mrs (void)
7702 {
7703 if (do_vfp_nsyn_mrs () == SUCCESS)
7704 return;
7705
7706 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7707 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7708 != (PSR_c|PSR_f),
7709 _("'CPSR' or 'SPSR' expected"));
7710 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7711 inst.instruction |= inst.operands[0].reg << 12;
7712 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7713 }
7714
7715 /* Two possible forms:
7716 "{C|S}PSR_<field>, Rm",
7717 "{C|S}PSR_f, #expression". */
7718
7719 static void
7720 do_msr (void)
7721 {
7722 if (do_vfp_nsyn_msr () == SUCCESS)
7723 return;
7724
7725 inst.instruction |= inst.operands[0].imm;
7726 if (inst.operands[1].isreg)
7727 inst.instruction |= inst.operands[1].reg;
7728 else
7729 {
7730 inst.instruction |= INST_IMMEDIATE;
7731 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7732 inst.reloc.pc_rel = 0;
7733 }
7734 }
7735
7736 static void
7737 do_mul (void)
7738 {
7739 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7740
7741 if (!inst.operands[2].present)
7742 inst.operands[2].reg = inst.operands[0].reg;
7743 inst.instruction |= inst.operands[0].reg << 16;
7744 inst.instruction |= inst.operands[1].reg;
7745 inst.instruction |= inst.operands[2].reg << 8;
7746
7747 if (inst.operands[0].reg == inst.operands[1].reg
7748 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7749 as_tsktsk (_("Rd and Rm should be different in mul"));
7750 }
7751
7752 /* Long Multiply Parser
7753 UMULL RdLo, RdHi, Rm, Rs
7754 SMULL RdLo, RdHi, Rm, Rs
7755 UMLAL RdLo, RdHi, Rm, Rs
7756 SMLAL RdLo, RdHi, Rm, Rs. */
7757
7758 static void
7759 do_mull (void)
7760 {
7761 inst.instruction |= inst.operands[0].reg << 12;
7762 inst.instruction |= inst.operands[1].reg << 16;
7763 inst.instruction |= inst.operands[2].reg;
7764 inst.instruction |= inst.operands[3].reg << 8;
7765
7766 /* rdhi and rdlo must be different. */
7767 if (inst.operands[0].reg == inst.operands[1].reg)
7768 as_tsktsk (_("rdhi and rdlo must be different"));
7769
7770 /* rdhi, rdlo and rm must all be different before armv6. */
7771 if ((inst.operands[0].reg == inst.operands[2].reg
7772 || inst.operands[1].reg == inst.operands[2].reg)
7773 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7774 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7775 }
7776
7777 static void
7778 do_nop (void)
7779 {
7780 if (inst.operands[0].present
7781 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
7782 {
7783 /* Architectural NOP hints are CPSR sets with no bits selected. */
7784 inst.instruction &= 0xf0000000;
7785 inst.instruction |= 0x0320f000;
7786 if (inst.operands[0].present)
7787 inst.instruction |= inst.operands[0].imm;
7788 }
7789 }
7790
7791 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7792 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7793 Condition defaults to COND_ALWAYS.
7794 Error if Rd, Rn or Rm are R15. */
7795
7796 static void
7797 do_pkhbt (void)
7798 {
7799 inst.instruction |= inst.operands[0].reg << 12;
7800 inst.instruction |= inst.operands[1].reg << 16;
7801 inst.instruction |= inst.operands[2].reg;
7802 if (inst.operands[3].present)
7803 encode_arm_shift (3);
7804 }
7805
7806 /* ARM V6 PKHTB (Argument Parse). */
7807
7808 static void
7809 do_pkhtb (void)
7810 {
7811 if (!inst.operands[3].present)
7812 {
7813 /* If the shift specifier is omitted, turn the instruction
7814 into pkhbt rd, rm, rn. */
7815 inst.instruction &= 0xfff00010;
7816 inst.instruction |= inst.operands[0].reg << 12;
7817 inst.instruction |= inst.operands[1].reg;
7818 inst.instruction |= inst.operands[2].reg << 16;
7819 }
7820 else
7821 {
7822 inst.instruction |= inst.operands[0].reg << 12;
7823 inst.instruction |= inst.operands[1].reg << 16;
7824 inst.instruction |= inst.operands[2].reg;
7825 encode_arm_shift (3);
7826 }
7827 }
7828
7829 /* ARMv5TE: Preload-Cache
7830
7831 PLD <addr_mode>
7832
7833 Syntactically, like LDR with B=1, W=0, L=1. */
7834
7835 static void
7836 do_pld (void)
7837 {
7838 constraint (!inst.operands[0].isreg,
7839 _("'[' expected after PLD mnemonic"));
7840 constraint (inst.operands[0].postind,
7841 _("post-indexed expression used in preload instruction"));
7842 constraint (inst.operands[0].writeback,
7843 _("writeback used in preload instruction"));
7844 constraint (!inst.operands[0].preind,
7845 _("unindexed addressing used in preload instruction"));
7846 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7847 }
7848
7849 /* ARMv7: PLI <addr_mode> */
7850 static void
7851 do_pli (void)
7852 {
7853 constraint (!inst.operands[0].isreg,
7854 _("'[' expected after PLI mnemonic"));
7855 constraint (inst.operands[0].postind,
7856 _("post-indexed expression used in preload instruction"));
7857 constraint (inst.operands[0].writeback,
7858 _("writeback used in preload instruction"));
7859 constraint (!inst.operands[0].preind,
7860 _("unindexed addressing used in preload instruction"));
7861 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7862 inst.instruction &= ~PRE_INDEX;
7863 }
7864
7865 static void
7866 do_push_pop (void)
7867 {
7868 inst.operands[1] = inst.operands[0];
7869 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7870 inst.operands[0].isreg = 1;
7871 inst.operands[0].writeback = 1;
7872 inst.operands[0].reg = REG_SP;
7873 do_ldmstm ();
7874 }
7875
7876 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7877 word at the specified address and the following word
7878 respectively.
7879 Unconditionally executed.
7880 Error if Rn is R15. */
7881
7882 static void
7883 do_rfe (void)
7884 {
7885 inst.instruction |= inst.operands[0].reg << 16;
7886 if (inst.operands[0].writeback)
7887 inst.instruction |= WRITE_BACK;
7888 }
7889
7890 /* ARM V6 ssat (argument parse). */
7891
7892 static void
7893 do_ssat (void)
7894 {
7895 inst.instruction |= inst.operands[0].reg << 12;
7896 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7897 inst.instruction |= inst.operands[2].reg;
7898
7899 if (inst.operands[3].present)
7900 encode_arm_shift (3);
7901 }
7902
7903 /* ARM V6 usat (argument parse). */
7904
7905 static void
7906 do_usat (void)
7907 {
7908 inst.instruction |= inst.operands[0].reg << 12;
7909 inst.instruction |= inst.operands[1].imm << 16;
7910 inst.instruction |= inst.operands[2].reg;
7911
7912 if (inst.operands[3].present)
7913 encode_arm_shift (3);
7914 }
7915
7916 /* ARM V6 ssat16 (argument parse). */
7917
7918 static void
7919 do_ssat16 (void)
7920 {
7921 inst.instruction |= inst.operands[0].reg << 12;
7922 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7923 inst.instruction |= inst.operands[2].reg;
7924 }
7925
7926 static void
7927 do_usat16 (void)
7928 {
7929 inst.instruction |= inst.operands[0].reg << 12;
7930 inst.instruction |= inst.operands[1].imm << 16;
7931 inst.instruction |= inst.operands[2].reg;
7932 }
7933
7934 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7935 preserving the other bits.
7936
7937 setend <endian_specifier>, where <endian_specifier> is either
7938 BE or LE. */
7939
7940 static void
7941 do_setend (void)
7942 {
7943 if (inst.operands[0].imm)
7944 inst.instruction |= 0x200;
7945 }
7946
7947 static void
7948 do_shift (void)
7949 {
7950 unsigned int Rm = (inst.operands[1].present
7951 ? inst.operands[1].reg
7952 : inst.operands[0].reg);
7953
7954 inst.instruction |= inst.operands[0].reg << 12;
7955 inst.instruction |= Rm;
7956 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7957 {
7958 inst.instruction |= inst.operands[2].reg << 8;
7959 inst.instruction |= SHIFT_BY_REG;
7960 }
7961 else
7962 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7963 }
7964
7965 static void
7966 do_smc (void)
7967 {
7968 inst.reloc.type = BFD_RELOC_ARM_SMC;
7969 inst.reloc.pc_rel = 0;
7970 }
7971
7972 static void
7973 do_swi (void)
7974 {
7975 inst.reloc.type = BFD_RELOC_ARM_SWI;
7976 inst.reloc.pc_rel = 0;
7977 }
7978
7979 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7980 SMLAxy{cond} Rd,Rm,Rs,Rn
7981 SMLAWy{cond} Rd,Rm,Rs,Rn
7982 Error if any register is R15. */
7983
7984 static void
7985 do_smla (void)
7986 {
7987 inst.instruction |= inst.operands[0].reg << 16;
7988 inst.instruction |= inst.operands[1].reg;
7989 inst.instruction |= inst.operands[2].reg << 8;
7990 inst.instruction |= inst.operands[3].reg << 12;
7991 }
7992
7993 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7994 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7995 Error if any register is R15.
7996 Warning if Rdlo == Rdhi. */
7997
7998 static void
7999 do_smlal (void)
8000 {
8001 inst.instruction |= inst.operands[0].reg << 12;
8002 inst.instruction |= inst.operands[1].reg << 16;
8003 inst.instruction |= inst.operands[2].reg;
8004 inst.instruction |= inst.operands[3].reg << 8;
8005
8006 if (inst.operands[0].reg == inst.operands[1].reg)
8007 as_tsktsk (_("rdhi and rdlo must be different"));
8008 }
8009
8010 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8011 SMULxy{cond} Rd,Rm,Rs
8012 Error if any register is R15. */
8013
8014 static void
8015 do_smul (void)
8016 {
8017 inst.instruction |= inst.operands[0].reg << 16;
8018 inst.instruction |= inst.operands[1].reg;
8019 inst.instruction |= inst.operands[2].reg << 8;
8020 }
8021
8022 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8023 the same for both ARM and Thumb-2. */
8024
8025 static void
8026 do_srs (void)
8027 {
8028 int reg;
8029
8030 if (inst.operands[0].present)
8031 {
8032 reg = inst.operands[0].reg;
8033 constraint (reg != REG_SP, _("SRS base register must be r13"));
8034 }
8035 else
8036 reg = REG_SP;
8037
8038 inst.instruction |= reg << 16;
8039 inst.instruction |= inst.operands[1].imm;
8040 if (inst.operands[0].writeback || inst.operands[1].writeback)
8041 inst.instruction |= WRITE_BACK;
8042 }
8043
8044 /* ARM V6 strex (argument parse). */
8045
8046 static void
8047 do_strex (void)
8048 {
8049 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8050 || inst.operands[2].postind || inst.operands[2].writeback
8051 || inst.operands[2].immisreg || inst.operands[2].shifted
8052 || inst.operands[2].negative
8053 /* See comment in do_ldrex(). */
8054 || (inst.operands[2].reg == REG_PC),
8055 BAD_ADDR_MODE);
8056
8057 constraint (inst.operands[0].reg == inst.operands[1].reg
8058 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8059
8060 constraint (inst.reloc.exp.X_op != O_constant
8061 || inst.reloc.exp.X_add_number != 0,
8062 _("offset must be zero in ARM encoding"));
8063
8064 inst.instruction |= inst.operands[0].reg << 12;
8065 inst.instruction |= inst.operands[1].reg;
8066 inst.instruction |= inst.operands[2].reg << 16;
8067 inst.reloc.type = BFD_RELOC_UNUSED;
8068 }
8069
8070 static void
8071 do_strexd (void)
8072 {
8073 constraint (inst.operands[1].reg % 2 != 0,
8074 _("even register required"));
8075 constraint (inst.operands[2].present
8076 && inst.operands[2].reg != inst.operands[1].reg + 1,
8077 _("can only store two consecutive registers"));
8078 /* If op 2 were present and equal to PC, this function wouldn't
8079 have been called in the first place. */
8080 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8081
8082 constraint (inst.operands[0].reg == inst.operands[1].reg
8083 || inst.operands[0].reg == inst.operands[1].reg + 1
8084 || inst.operands[0].reg == inst.operands[3].reg,
8085 BAD_OVERLAP);
8086
8087 inst.instruction |= inst.operands[0].reg << 12;
8088 inst.instruction |= inst.operands[1].reg;
8089 inst.instruction |= inst.operands[3].reg << 16;
8090 }
8091
8092 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8093 extends it to 32-bits, and adds the result to a value in another
8094 register. You can specify a rotation by 0, 8, 16, or 24 bits
8095 before extracting the 16-bit value.
8096 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8097 Condition defaults to COND_ALWAYS.
8098 Error if any register uses R15. */
8099
8100 static void
8101 do_sxtah (void)
8102 {
8103 inst.instruction |= inst.operands[0].reg << 12;
8104 inst.instruction |= inst.operands[1].reg << 16;
8105 inst.instruction |= inst.operands[2].reg;
8106 inst.instruction |= inst.operands[3].imm << 10;
8107 }
8108
8109 /* ARM V6 SXTH.
8110
8111 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8112 Condition defaults to COND_ALWAYS.
8113 Error if any register uses R15. */
8114
8115 static void
8116 do_sxth (void)
8117 {
8118 inst.instruction |= inst.operands[0].reg << 12;
8119 inst.instruction |= inst.operands[1].reg;
8120 inst.instruction |= inst.operands[2].imm << 10;
8121 }
8122 \f
8123 /* VFP instructions. In a logical order: SP variant first, monad
8124 before dyad, arithmetic then move then load/store. */
8125
8126 static void
8127 do_vfp_sp_monadic (void)
8128 {
8129 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8130 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8131 }
8132
8133 static void
8134 do_vfp_sp_dyadic (void)
8135 {
8136 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8137 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8138 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8139 }
8140
8141 static void
8142 do_vfp_sp_compare_z (void)
8143 {
8144 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8145 }
8146
8147 static void
8148 do_vfp_dp_sp_cvt (void)
8149 {
8150 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8151 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8152 }
8153
8154 static void
8155 do_vfp_sp_dp_cvt (void)
8156 {
8157 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8158 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8159 }
8160
8161 static void
8162 do_vfp_reg_from_sp (void)
8163 {
8164 inst.instruction |= inst.operands[0].reg << 12;
8165 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8166 }
8167
8168 static void
8169 do_vfp_reg2_from_sp2 (void)
8170 {
8171 constraint (inst.operands[2].imm != 2,
8172 _("only two consecutive VFP SP registers allowed here"));
8173 inst.instruction |= inst.operands[0].reg << 12;
8174 inst.instruction |= inst.operands[1].reg << 16;
8175 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8176 }
8177
8178 static void
8179 do_vfp_sp_from_reg (void)
8180 {
8181 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8182 inst.instruction |= inst.operands[1].reg << 12;
8183 }
8184
8185 static void
8186 do_vfp_sp2_from_reg2 (void)
8187 {
8188 constraint (inst.operands[0].imm != 2,
8189 _("only two consecutive VFP SP registers allowed here"));
8190 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8191 inst.instruction |= inst.operands[1].reg << 12;
8192 inst.instruction |= inst.operands[2].reg << 16;
8193 }
8194
8195 static void
8196 do_vfp_sp_ldst (void)
8197 {
8198 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8199 encode_arm_cp_address (1, FALSE, TRUE, 0);
8200 }
8201
8202 static void
8203 do_vfp_dp_ldst (void)
8204 {
8205 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8206 encode_arm_cp_address (1, FALSE, TRUE, 0);
8207 }
8208
8209
8210 static void
8211 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8212 {
8213 if (inst.operands[0].writeback)
8214 inst.instruction |= WRITE_BACK;
8215 else
8216 constraint (ldstm_type != VFP_LDSTMIA,
8217 _("this addressing mode requires base-register writeback"));
8218 inst.instruction |= inst.operands[0].reg << 16;
8219 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8220 inst.instruction |= inst.operands[1].imm;
8221 }
8222
8223 static void
8224 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8225 {
8226 int count;
8227
8228 if (inst.operands[0].writeback)
8229 inst.instruction |= WRITE_BACK;
8230 else
8231 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8232 _("this addressing mode requires base-register writeback"));
8233
8234 inst.instruction |= inst.operands[0].reg << 16;
8235 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8236
8237 count = inst.operands[1].imm << 1;
8238 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8239 count += 1;
8240
8241 inst.instruction |= count;
8242 }
8243
8244 static void
8245 do_vfp_sp_ldstmia (void)
8246 {
8247 vfp_sp_ldstm (VFP_LDSTMIA);
8248 }
8249
8250 static void
8251 do_vfp_sp_ldstmdb (void)
8252 {
8253 vfp_sp_ldstm (VFP_LDSTMDB);
8254 }
8255
8256 static void
8257 do_vfp_dp_ldstmia (void)
8258 {
8259 vfp_dp_ldstm (VFP_LDSTMIA);
8260 }
8261
8262 static void
8263 do_vfp_dp_ldstmdb (void)
8264 {
8265 vfp_dp_ldstm (VFP_LDSTMDB);
8266 }
8267
8268 static void
8269 do_vfp_xp_ldstmia (void)
8270 {
8271 vfp_dp_ldstm (VFP_LDSTMIAX);
8272 }
8273
8274 static void
8275 do_vfp_xp_ldstmdb (void)
8276 {
8277 vfp_dp_ldstm (VFP_LDSTMDBX);
8278 }
8279
8280 static void
8281 do_vfp_dp_rd_rm (void)
8282 {
8283 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8284 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8285 }
8286
8287 static void
8288 do_vfp_dp_rn_rd (void)
8289 {
8290 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8291 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8292 }
8293
8294 static void
8295 do_vfp_dp_rd_rn (void)
8296 {
8297 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8298 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8299 }
8300
8301 static void
8302 do_vfp_dp_rd_rn_rm (void)
8303 {
8304 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8305 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8306 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8307 }
8308
8309 static void
8310 do_vfp_dp_rd (void)
8311 {
8312 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8313 }
8314
8315 static void
8316 do_vfp_dp_rm_rd_rn (void)
8317 {
8318 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8319 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8320 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8321 }
8322
8323 /* VFPv3 instructions. */
8324 static void
8325 do_vfp_sp_const (void)
8326 {
8327 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8328 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8329 inst.instruction |= (inst.operands[1].imm & 0x0f);
8330 }
8331
8332 static void
8333 do_vfp_dp_const (void)
8334 {
8335 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8336 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8337 inst.instruction |= (inst.operands[1].imm & 0x0f);
8338 }
8339
8340 static void
8341 vfp_conv (int srcsize)
8342 {
8343 unsigned immbits = srcsize - inst.operands[1].imm;
8344 inst.instruction |= (immbits & 1) << 5;
8345 inst.instruction |= (immbits >> 1);
8346 }
8347
8348 static void
8349 do_vfp_sp_conv_16 (void)
8350 {
8351 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8352 vfp_conv (16);
8353 }
8354
8355 static void
8356 do_vfp_dp_conv_16 (void)
8357 {
8358 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8359 vfp_conv (16);
8360 }
8361
8362 static void
8363 do_vfp_sp_conv_32 (void)
8364 {
8365 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8366 vfp_conv (32);
8367 }
8368
8369 static void
8370 do_vfp_dp_conv_32 (void)
8371 {
8372 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8373 vfp_conv (32);
8374 }
8375 \f
8376 /* FPA instructions. Also in a logical order. */
8377
8378 static void
8379 do_fpa_cmp (void)
8380 {
8381 inst.instruction |= inst.operands[0].reg << 16;
8382 inst.instruction |= inst.operands[1].reg;
8383 }
8384
8385 static void
8386 do_fpa_ldmstm (void)
8387 {
8388 inst.instruction |= inst.operands[0].reg << 12;
8389 switch (inst.operands[1].imm)
8390 {
8391 case 1: inst.instruction |= CP_T_X; break;
8392 case 2: inst.instruction |= CP_T_Y; break;
8393 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8394 case 4: break;
8395 default: abort ();
8396 }
8397
8398 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8399 {
8400 /* The instruction specified "ea" or "fd", so we can only accept
8401 [Rn]{!}. The instruction does not really support stacking or
8402 unstacking, so we have to emulate these by setting appropriate
8403 bits and offsets. */
8404 constraint (inst.reloc.exp.X_op != O_constant
8405 || inst.reloc.exp.X_add_number != 0,
8406 _("this instruction does not support indexing"));
8407
8408 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8409 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
8410
8411 if (!(inst.instruction & INDEX_UP))
8412 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
8413
8414 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8415 {
8416 inst.operands[2].preind = 0;
8417 inst.operands[2].postind = 1;
8418 }
8419 }
8420
8421 encode_arm_cp_address (2, TRUE, TRUE, 0);
8422 }
8423 \f
8424 /* iWMMXt instructions: strictly in alphabetical order. */
8425
8426 static void
8427 do_iwmmxt_tandorc (void)
8428 {
8429 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8430 }
8431
8432 static void
8433 do_iwmmxt_textrc (void)
8434 {
8435 inst.instruction |= inst.operands[0].reg << 12;
8436 inst.instruction |= inst.operands[1].imm;
8437 }
8438
8439 static void
8440 do_iwmmxt_textrm (void)
8441 {
8442 inst.instruction |= inst.operands[0].reg << 12;
8443 inst.instruction |= inst.operands[1].reg << 16;
8444 inst.instruction |= inst.operands[2].imm;
8445 }
8446
8447 static void
8448 do_iwmmxt_tinsr (void)
8449 {
8450 inst.instruction |= inst.operands[0].reg << 16;
8451 inst.instruction |= inst.operands[1].reg << 12;
8452 inst.instruction |= inst.operands[2].imm;
8453 }
8454
8455 static void
8456 do_iwmmxt_tmia (void)
8457 {
8458 inst.instruction |= inst.operands[0].reg << 5;
8459 inst.instruction |= inst.operands[1].reg;
8460 inst.instruction |= inst.operands[2].reg << 12;
8461 }
8462
8463 static void
8464 do_iwmmxt_waligni (void)
8465 {
8466 inst.instruction |= inst.operands[0].reg << 12;
8467 inst.instruction |= inst.operands[1].reg << 16;
8468 inst.instruction |= inst.operands[2].reg;
8469 inst.instruction |= inst.operands[3].imm << 20;
8470 }
8471
8472 static void
8473 do_iwmmxt_wmerge (void)
8474 {
8475 inst.instruction |= inst.operands[0].reg << 12;
8476 inst.instruction |= inst.operands[1].reg << 16;
8477 inst.instruction |= inst.operands[2].reg;
8478 inst.instruction |= inst.operands[3].imm << 21;
8479 }
8480
8481 static void
8482 do_iwmmxt_wmov (void)
8483 {
8484 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8485 inst.instruction |= inst.operands[0].reg << 12;
8486 inst.instruction |= inst.operands[1].reg << 16;
8487 inst.instruction |= inst.operands[1].reg;
8488 }
8489
8490 static void
8491 do_iwmmxt_wldstbh (void)
8492 {
8493 int reloc;
8494 inst.instruction |= inst.operands[0].reg << 12;
8495 if (thumb_mode)
8496 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8497 else
8498 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8499 encode_arm_cp_address (1, TRUE, FALSE, reloc);
8500 }
8501
8502 static void
8503 do_iwmmxt_wldstw (void)
8504 {
8505 /* RIWR_RIWC clears .isreg for a control register. */
8506 if (!inst.operands[0].isreg)
8507 {
8508 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8509 inst.instruction |= 0xf0000000;
8510 }
8511
8512 inst.instruction |= inst.operands[0].reg << 12;
8513 encode_arm_cp_address (1, TRUE, TRUE, 0);
8514 }
8515
8516 static void
8517 do_iwmmxt_wldstd (void)
8518 {
8519 inst.instruction |= inst.operands[0].reg << 12;
8520 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8521 && inst.operands[1].immisreg)
8522 {
8523 inst.instruction &= ~0x1a000ff;
8524 inst.instruction |= (0xf << 28);
8525 if (inst.operands[1].preind)
8526 inst.instruction |= PRE_INDEX;
8527 if (!inst.operands[1].negative)
8528 inst.instruction |= INDEX_UP;
8529 if (inst.operands[1].writeback)
8530 inst.instruction |= WRITE_BACK;
8531 inst.instruction |= inst.operands[1].reg << 16;
8532 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8533 inst.instruction |= inst.operands[1].imm;
8534 }
8535 else
8536 encode_arm_cp_address (1, TRUE, FALSE, 0);
8537 }
8538
8539 static void
8540 do_iwmmxt_wshufh (void)
8541 {
8542 inst.instruction |= inst.operands[0].reg << 12;
8543 inst.instruction |= inst.operands[1].reg << 16;
8544 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8545 inst.instruction |= (inst.operands[2].imm & 0x0f);
8546 }
8547
8548 static void
8549 do_iwmmxt_wzero (void)
8550 {
8551 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8552 inst.instruction |= inst.operands[0].reg;
8553 inst.instruction |= inst.operands[0].reg << 12;
8554 inst.instruction |= inst.operands[0].reg << 16;
8555 }
8556
8557 static void
8558 do_iwmmxt_wrwrwr_or_imm5 (void)
8559 {
8560 if (inst.operands[2].isreg)
8561 do_rd_rn_rm ();
8562 else {
8563 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8564 _("immediate operand requires iWMMXt2"));
8565 do_rd_rn ();
8566 if (inst.operands[2].imm == 0)
8567 {
8568 switch ((inst.instruction >> 20) & 0xf)
8569 {
8570 case 4:
8571 case 5:
8572 case 6:
8573 case 7:
8574 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8575 inst.operands[2].imm = 16;
8576 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8577 break;
8578 case 8:
8579 case 9:
8580 case 10:
8581 case 11:
8582 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8583 inst.operands[2].imm = 32;
8584 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8585 break;
8586 case 12:
8587 case 13:
8588 case 14:
8589 case 15:
8590 {
8591 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8592 unsigned long wrn;
8593 wrn = (inst.instruction >> 16) & 0xf;
8594 inst.instruction &= 0xff0fff0f;
8595 inst.instruction |= wrn;
8596 /* Bail out here; the instruction is now assembled. */
8597 return;
8598 }
8599 }
8600 }
8601 /* Map 32 -> 0, etc. */
8602 inst.operands[2].imm &= 0x1f;
8603 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8604 }
8605 }
8606 \f
8607 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8608 operations first, then control, shift, and load/store. */
8609
8610 /* Insns like "foo X,Y,Z". */
8611
8612 static void
8613 do_mav_triple (void)
8614 {
8615 inst.instruction |= inst.operands[0].reg << 16;
8616 inst.instruction |= inst.operands[1].reg;
8617 inst.instruction |= inst.operands[2].reg << 12;
8618 }
8619
8620 /* Insns like "foo W,X,Y,Z".
8621 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8622
8623 static void
8624 do_mav_quad (void)
8625 {
8626 inst.instruction |= inst.operands[0].reg << 5;
8627 inst.instruction |= inst.operands[1].reg << 12;
8628 inst.instruction |= inst.operands[2].reg << 16;
8629 inst.instruction |= inst.operands[3].reg;
8630 }
8631
8632 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8633 static void
8634 do_mav_dspsc (void)
8635 {
8636 inst.instruction |= inst.operands[1].reg << 12;
8637 }
8638
8639 /* Maverick shift immediate instructions.
8640 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8641 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8642
8643 static void
8644 do_mav_shift (void)
8645 {
8646 int imm = inst.operands[2].imm;
8647
8648 inst.instruction |= inst.operands[0].reg << 12;
8649 inst.instruction |= inst.operands[1].reg << 16;
8650
8651 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8652 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8653 Bit 4 should be 0. */
8654 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8655
8656 inst.instruction |= imm;
8657 }
8658 \f
8659 /* XScale instructions. Also sorted arithmetic before move. */
8660
8661 /* Xscale multiply-accumulate (argument parse)
8662 MIAcc acc0,Rm,Rs
8663 MIAPHcc acc0,Rm,Rs
8664 MIAxycc acc0,Rm,Rs. */
8665
8666 static void
8667 do_xsc_mia (void)
8668 {
8669 inst.instruction |= inst.operands[1].reg;
8670 inst.instruction |= inst.operands[2].reg << 12;
8671 }
8672
8673 /* Xscale move-accumulator-register (argument parse)
8674
8675 MARcc acc0,RdLo,RdHi. */
8676
8677 static void
8678 do_xsc_mar (void)
8679 {
8680 inst.instruction |= inst.operands[1].reg << 12;
8681 inst.instruction |= inst.operands[2].reg << 16;
8682 }
8683
8684 /* Xscale move-register-accumulator (argument parse)
8685
8686 MRAcc RdLo,RdHi,acc0. */
8687
8688 static void
8689 do_xsc_mra (void)
8690 {
8691 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8692 inst.instruction |= inst.operands[0].reg << 12;
8693 inst.instruction |= inst.operands[1].reg << 16;
8694 }
8695 \f
8696 /* Encoding functions relevant only to Thumb. */
8697
8698 /* inst.operands[i] is a shifted-register operand; encode
8699 it into inst.instruction in the format used by Thumb32. */
8700
8701 static void
8702 encode_thumb32_shifted_operand (int i)
8703 {
8704 unsigned int value = inst.reloc.exp.X_add_number;
8705 unsigned int shift = inst.operands[i].shift_kind;
8706
8707 constraint (inst.operands[i].immisreg,
8708 _("shift by register not allowed in thumb mode"));
8709 inst.instruction |= inst.operands[i].reg;
8710 if (shift == SHIFT_RRX)
8711 inst.instruction |= SHIFT_ROR << 4;
8712 else
8713 {
8714 constraint (inst.reloc.exp.X_op != O_constant,
8715 _("expression too complex"));
8716
8717 constraint (value > 32
8718 || (value == 32 && (shift == SHIFT_LSL
8719 || shift == SHIFT_ROR)),
8720 _("shift expression is too large"));
8721
8722 if (value == 0)
8723 shift = SHIFT_LSL;
8724 else if (value == 32)
8725 value = 0;
8726
8727 inst.instruction |= shift << 4;
8728 inst.instruction |= (value & 0x1c) << 10;
8729 inst.instruction |= (value & 0x03) << 6;
8730 }
8731 }
8732
8733
8734 /* inst.operands[i] was set up by parse_address. Encode it into a
8735 Thumb32 format load or store instruction. Reject forms that cannot
8736 be used with such instructions. If is_t is true, reject forms that
8737 cannot be used with a T instruction; if is_d is true, reject forms
8738 that cannot be used with a D instruction. If it is a store insn,
8739 reject PC in Rn. */
8740
8741 static void
8742 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8743 {
8744 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8745
8746 constraint (!inst.operands[i].isreg,
8747 _("Instruction does not support =N addresses"));
8748
8749 inst.instruction |= inst.operands[i].reg << 16;
8750 if (inst.operands[i].immisreg)
8751 {
8752 constraint (is_pc, BAD_PC_ADDRESSING);
8753 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8754 constraint (inst.operands[i].negative,
8755 _("Thumb does not support negative register indexing"));
8756 constraint (inst.operands[i].postind,
8757 _("Thumb does not support register post-indexing"));
8758 constraint (inst.operands[i].writeback,
8759 _("Thumb does not support register indexing with writeback"));
8760 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8761 _("Thumb supports only LSL in shifted register indexing"));
8762
8763 inst.instruction |= inst.operands[i].imm;
8764 if (inst.operands[i].shifted)
8765 {
8766 constraint (inst.reloc.exp.X_op != O_constant,
8767 _("expression too complex"));
8768 constraint (inst.reloc.exp.X_add_number < 0
8769 || inst.reloc.exp.X_add_number > 3,
8770 _("shift out of range"));
8771 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8772 }
8773 inst.reloc.type = BFD_RELOC_UNUSED;
8774 }
8775 else if (inst.operands[i].preind)
8776 {
8777 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
8778 constraint (is_t && inst.operands[i].writeback,
8779 _("cannot use writeback with this instruction"));
8780 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8781 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
8782
8783 if (is_d)
8784 {
8785 inst.instruction |= 0x01000000;
8786 if (inst.operands[i].writeback)
8787 inst.instruction |= 0x00200000;
8788 }
8789 else
8790 {
8791 inst.instruction |= 0x00000c00;
8792 if (inst.operands[i].writeback)
8793 inst.instruction |= 0x00000100;
8794 }
8795 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8796 }
8797 else if (inst.operands[i].postind)
8798 {
8799 gas_assert (inst.operands[i].writeback);
8800 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8801 constraint (is_t, _("cannot use post-indexing with this instruction"));
8802
8803 if (is_d)
8804 inst.instruction |= 0x00200000;
8805 else
8806 inst.instruction |= 0x00000900;
8807 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8808 }
8809 else /* unindexed - only for coprocessor */
8810 inst.error = _("instruction does not accept unindexed addressing");
8811 }
8812
8813 /* Table of Thumb instructions which exist in both 16- and 32-bit
8814 encodings (the latter only in post-V6T2 cores). The index is the
8815 value used in the insns table below. When there is more than one
8816 possible 16-bit encoding for the instruction, this table always
8817 holds variant (1).
8818 Also contains several pseudo-instructions used during relaxation. */
8819 #define T16_32_TAB \
8820 X(_adc, 4140, eb400000), \
8821 X(_adcs, 4140, eb500000), \
8822 X(_add, 1c00, eb000000), \
8823 X(_adds, 1c00, eb100000), \
8824 X(_addi, 0000, f1000000), \
8825 X(_addis, 0000, f1100000), \
8826 X(_add_pc,000f, f20f0000), \
8827 X(_add_sp,000d, f10d0000), \
8828 X(_adr, 000f, f20f0000), \
8829 X(_and, 4000, ea000000), \
8830 X(_ands, 4000, ea100000), \
8831 X(_asr, 1000, fa40f000), \
8832 X(_asrs, 1000, fa50f000), \
8833 X(_b, e000, f000b000), \
8834 X(_bcond, d000, f0008000), \
8835 X(_bic, 4380, ea200000), \
8836 X(_bics, 4380, ea300000), \
8837 X(_cmn, 42c0, eb100f00), \
8838 X(_cmp, 2800, ebb00f00), \
8839 X(_cpsie, b660, f3af8400), \
8840 X(_cpsid, b670, f3af8600), \
8841 X(_cpy, 4600, ea4f0000), \
8842 X(_dec_sp,80dd, f1ad0d00), \
8843 X(_eor, 4040, ea800000), \
8844 X(_eors, 4040, ea900000), \
8845 X(_inc_sp,00dd, f10d0d00), \
8846 X(_ldmia, c800, e8900000), \
8847 X(_ldr, 6800, f8500000), \
8848 X(_ldrb, 7800, f8100000), \
8849 X(_ldrh, 8800, f8300000), \
8850 X(_ldrsb, 5600, f9100000), \
8851 X(_ldrsh, 5e00, f9300000), \
8852 X(_ldr_pc,4800, f85f0000), \
8853 X(_ldr_pc2,4800, f85f0000), \
8854 X(_ldr_sp,9800, f85d0000), \
8855 X(_lsl, 0000, fa00f000), \
8856 X(_lsls, 0000, fa10f000), \
8857 X(_lsr, 0800, fa20f000), \
8858 X(_lsrs, 0800, fa30f000), \
8859 X(_mov, 2000, ea4f0000), \
8860 X(_movs, 2000, ea5f0000), \
8861 X(_mul, 4340, fb00f000), \
8862 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8863 X(_mvn, 43c0, ea6f0000), \
8864 X(_mvns, 43c0, ea7f0000), \
8865 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8866 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8867 X(_orr, 4300, ea400000), \
8868 X(_orrs, 4300, ea500000), \
8869 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8870 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8871 X(_rev, ba00, fa90f080), \
8872 X(_rev16, ba40, fa90f090), \
8873 X(_revsh, bac0, fa90f0b0), \
8874 X(_ror, 41c0, fa60f000), \
8875 X(_rors, 41c0, fa70f000), \
8876 X(_sbc, 4180, eb600000), \
8877 X(_sbcs, 4180, eb700000), \
8878 X(_stmia, c000, e8800000), \
8879 X(_str, 6000, f8400000), \
8880 X(_strb, 7000, f8000000), \
8881 X(_strh, 8000, f8200000), \
8882 X(_str_sp,9000, f84d0000), \
8883 X(_sub, 1e00, eba00000), \
8884 X(_subs, 1e00, ebb00000), \
8885 X(_subi, 8000, f1a00000), \
8886 X(_subis, 8000, f1b00000), \
8887 X(_sxtb, b240, fa4ff080), \
8888 X(_sxth, b200, fa0ff080), \
8889 X(_tst, 4200, ea100f00), \
8890 X(_uxtb, b2c0, fa5ff080), \
8891 X(_uxth, b280, fa1ff080), \
8892 X(_nop, bf00, f3af8000), \
8893 X(_yield, bf10, f3af8001), \
8894 X(_wfe, bf20, f3af8002), \
8895 X(_wfi, bf30, f3af8003), \
8896 X(_sev, bf40, f3af8004),
8897
8898 /* To catch errors in encoding functions, the codes are all offset by
8899 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8900 as 16-bit instructions. */
8901 #define X(a,b,c) T_MNEM##a
8902 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8903 #undef X
8904
8905 #define X(a,b,c) 0x##b
8906 static const unsigned short thumb_op16[] = { T16_32_TAB };
8907 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8908 #undef X
8909
8910 #define X(a,b,c) 0x##c
8911 static const unsigned int thumb_op32[] = { T16_32_TAB };
8912 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8913 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8914 #undef X
8915 #undef T16_32_TAB
8916
8917 /* Thumb instruction encoders, in alphabetical order. */
8918
8919 /* ADDW or SUBW. */
8920
8921 static void
8922 do_t_add_sub_w (void)
8923 {
8924 int Rd, Rn;
8925
8926 Rd = inst.operands[0].reg;
8927 Rn = inst.operands[1].reg;
8928
8929 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
8930 is the SP-{plus,minus}-immediate form of the instruction. */
8931 if (Rn == REG_SP)
8932 constraint (Rd == REG_PC, BAD_PC);
8933 else
8934 reject_bad_reg (Rd);
8935
8936 inst.instruction |= (Rn << 16) | (Rd << 8);
8937 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8938 }
8939
8940 /* Parse an add or subtract instruction. We get here with inst.instruction
8941 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8942
8943 static void
8944 do_t_add_sub (void)
8945 {
8946 int Rd, Rs, Rn;
8947
8948 Rd = inst.operands[0].reg;
8949 Rs = (inst.operands[1].present
8950 ? inst.operands[1].reg /* Rd, Rs, foo */
8951 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8952
8953 if (Rd == REG_PC)
8954 set_it_insn_type_last ();
8955
8956 if (unified_syntax)
8957 {
8958 bfd_boolean flags;
8959 bfd_boolean narrow;
8960 int opcode;
8961
8962 flags = (inst.instruction == T_MNEM_adds
8963 || inst.instruction == T_MNEM_subs);
8964 if (flags)
8965 narrow = !in_it_block ();
8966 else
8967 narrow = in_it_block ();
8968 if (!inst.operands[2].isreg)
8969 {
8970 int add;
8971
8972 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8973
8974 add = (inst.instruction == T_MNEM_add
8975 || inst.instruction == T_MNEM_adds);
8976 opcode = 0;
8977 if (inst.size_req != 4)
8978 {
8979 /* Attempt to use a narrow opcode, with relaxation if
8980 appropriate. */
8981 if (Rd == REG_SP && Rs == REG_SP && !flags)
8982 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8983 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8984 opcode = T_MNEM_add_sp;
8985 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8986 opcode = T_MNEM_add_pc;
8987 else if (Rd <= 7 && Rs <= 7 && narrow)
8988 {
8989 if (flags)
8990 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8991 else
8992 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8993 }
8994 if (opcode)
8995 {
8996 inst.instruction = THUMB_OP16(opcode);
8997 inst.instruction |= (Rd << 4) | Rs;
8998 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8999 if (inst.size_req != 2)
9000 inst.relax = opcode;
9001 }
9002 else
9003 constraint (inst.size_req == 2, BAD_HIREG);
9004 }
9005 if (inst.size_req == 4
9006 || (inst.size_req != 2 && !opcode))
9007 {
9008 if (Rd == REG_PC)
9009 {
9010 constraint (add, BAD_PC);
9011 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9012 _("only SUBS PC, LR, #const allowed"));
9013 constraint (inst.reloc.exp.X_op != O_constant,
9014 _("expression too complex"));
9015 constraint (inst.reloc.exp.X_add_number < 0
9016 || inst.reloc.exp.X_add_number > 0xff,
9017 _("immediate value out of range"));
9018 inst.instruction = T2_SUBS_PC_LR
9019 | inst.reloc.exp.X_add_number;
9020 inst.reloc.type = BFD_RELOC_UNUSED;
9021 return;
9022 }
9023 else if (Rs == REG_PC)
9024 {
9025 /* Always use addw/subw. */
9026 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9027 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9028 }
9029 else
9030 {
9031 inst.instruction = THUMB_OP32 (inst.instruction);
9032 inst.instruction = (inst.instruction & 0xe1ffffff)
9033 | 0x10000000;
9034 if (flags)
9035 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9036 else
9037 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9038 }
9039 inst.instruction |= Rd << 8;
9040 inst.instruction |= Rs << 16;
9041 }
9042 }
9043 else
9044 {
9045 Rn = inst.operands[2].reg;
9046 /* See if we can do this with a 16-bit instruction. */
9047 if (!inst.operands[2].shifted && inst.size_req != 4)
9048 {
9049 if (Rd > 7 || Rs > 7 || Rn > 7)
9050 narrow = FALSE;
9051
9052 if (narrow)
9053 {
9054 inst.instruction = ((inst.instruction == T_MNEM_adds
9055 || inst.instruction == T_MNEM_add)
9056 ? T_OPCODE_ADD_R3
9057 : T_OPCODE_SUB_R3);
9058 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9059 return;
9060 }
9061
9062 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9063 {
9064 /* Thumb-1 cores (except v6-M) require at least one high
9065 register in a narrow non flag setting add. */
9066 if (Rd > 7 || Rn > 7
9067 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9068 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9069 {
9070 if (Rd == Rn)
9071 {
9072 Rn = Rs;
9073 Rs = Rd;
9074 }
9075 inst.instruction = T_OPCODE_ADD_HI;
9076 inst.instruction |= (Rd & 8) << 4;
9077 inst.instruction |= (Rd & 7);
9078 inst.instruction |= Rn << 3;
9079 return;
9080 }
9081 }
9082 }
9083
9084 constraint (Rd == REG_PC, BAD_PC);
9085 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9086 constraint (Rs == REG_PC, BAD_PC);
9087 reject_bad_reg (Rn);
9088
9089 /* If we get here, it can't be done in 16 bits. */
9090 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9091 _("shift must be constant"));
9092 inst.instruction = THUMB_OP32 (inst.instruction);
9093 inst.instruction |= Rd << 8;
9094 inst.instruction |= Rs << 16;
9095 encode_thumb32_shifted_operand (2);
9096 }
9097 }
9098 else
9099 {
9100 constraint (inst.instruction == T_MNEM_adds
9101 || inst.instruction == T_MNEM_subs,
9102 BAD_THUMB32);
9103
9104 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9105 {
9106 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9107 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9108 BAD_HIREG);
9109
9110 inst.instruction = (inst.instruction == T_MNEM_add
9111 ? 0x0000 : 0x8000);
9112 inst.instruction |= (Rd << 4) | Rs;
9113 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9114 return;
9115 }
9116
9117 Rn = inst.operands[2].reg;
9118 constraint (inst.operands[2].shifted, _("unshifted register required"));
9119
9120 /* We now have Rd, Rs, and Rn set to registers. */
9121 if (Rd > 7 || Rs > 7 || Rn > 7)
9122 {
9123 /* Can't do this for SUB. */
9124 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9125 inst.instruction = T_OPCODE_ADD_HI;
9126 inst.instruction |= (Rd & 8) << 4;
9127 inst.instruction |= (Rd & 7);
9128 if (Rs == Rd)
9129 inst.instruction |= Rn << 3;
9130 else if (Rn == Rd)
9131 inst.instruction |= Rs << 3;
9132 else
9133 constraint (1, _("dest must overlap one source register"));
9134 }
9135 else
9136 {
9137 inst.instruction = (inst.instruction == T_MNEM_add
9138 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9139 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9140 }
9141 }
9142 }
9143
9144 static void
9145 do_t_adr (void)
9146 {
9147 unsigned Rd;
9148
9149 Rd = inst.operands[0].reg;
9150 reject_bad_reg (Rd);
9151
9152 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9153 {
9154 /* Defer to section relaxation. */
9155 inst.relax = inst.instruction;
9156 inst.instruction = THUMB_OP16 (inst.instruction);
9157 inst.instruction |= Rd << 4;
9158 }
9159 else if (unified_syntax && inst.size_req != 2)
9160 {
9161 /* Generate a 32-bit opcode. */
9162 inst.instruction = THUMB_OP32 (inst.instruction);
9163 inst.instruction |= Rd << 8;
9164 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9165 inst.reloc.pc_rel = 1;
9166 }
9167 else
9168 {
9169 /* Generate a 16-bit opcode. */
9170 inst.instruction = THUMB_OP16 (inst.instruction);
9171 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9172 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9173 inst.reloc.pc_rel = 1;
9174
9175 inst.instruction |= Rd << 4;
9176 }
9177 }
9178
9179 /* Arithmetic instructions for which there is just one 16-bit
9180 instruction encoding, and it allows only two low registers.
9181 For maximal compatibility with ARM syntax, we allow three register
9182 operands even when Thumb-32 instructions are not available, as long
9183 as the first two are identical. For instance, both "sbc r0,r1" and
9184 "sbc r0,r0,r1" are allowed. */
9185 static void
9186 do_t_arit3 (void)
9187 {
9188 int Rd, Rs, Rn;
9189
9190 Rd = inst.operands[0].reg;
9191 Rs = (inst.operands[1].present
9192 ? inst.operands[1].reg /* Rd, Rs, foo */
9193 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9194 Rn = inst.operands[2].reg;
9195
9196 reject_bad_reg (Rd);
9197 reject_bad_reg (Rs);
9198 if (inst.operands[2].isreg)
9199 reject_bad_reg (Rn);
9200
9201 if (unified_syntax)
9202 {
9203 if (!inst.operands[2].isreg)
9204 {
9205 /* For an immediate, we always generate a 32-bit opcode;
9206 section relaxation will shrink it later if possible. */
9207 inst.instruction = THUMB_OP32 (inst.instruction);
9208 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9209 inst.instruction |= Rd << 8;
9210 inst.instruction |= Rs << 16;
9211 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9212 }
9213 else
9214 {
9215 bfd_boolean narrow;
9216
9217 /* See if we can do this with a 16-bit instruction. */
9218 if (THUMB_SETS_FLAGS (inst.instruction))
9219 narrow = !in_it_block ();
9220 else
9221 narrow = in_it_block ();
9222
9223 if (Rd > 7 || Rn > 7 || Rs > 7)
9224 narrow = FALSE;
9225 if (inst.operands[2].shifted)
9226 narrow = FALSE;
9227 if (inst.size_req == 4)
9228 narrow = FALSE;
9229
9230 if (narrow
9231 && Rd == Rs)
9232 {
9233 inst.instruction = THUMB_OP16 (inst.instruction);
9234 inst.instruction |= Rd;
9235 inst.instruction |= Rn << 3;
9236 return;
9237 }
9238
9239 /* If we get here, it can't be done in 16 bits. */
9240 constraint (inst.operands[2].shifted
9241 && inst.operands[2].immisreg,
9242 _("shift must be constant"));
9243 inst.instruction = THUMB_OP32 (inst.instruction);
9244 inst.instruction |= Rd << 8;
9245 inst.instruction |= Rs << 16;
9246 encode_thumb32_shifted_operand (2);
9247 }
9248 }
9249 else
9250 {
9251 /* On its face this is a lie - the instruction does set the
9252 flags. However, the only supported mnemonic in this mode
9253 says it doesn't. */
9254 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9255
9256 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9257 _("unshifted register required"));
9258 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9259 constraint (Rd != Rs,
9260 _("dest and source1 must be the same register"));
9261
9262 inst.instruction = THUMB_OP16 (inst.instruction);
9263 inst.instruction |= Rd;
9264 inst.instruction |= Rn << 3;
9265 }
9266 }
9267
9268 /* Similarly, but for instructions where the arithmetic operation is
9269 commutative, so we can allow either of them to be different from
9270 the destination operand in a 16-bit instruction. For instance, all
9271 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9272 accepted. */
9273 static void
9274 do_t_arit3c (void)
9275 {
9276 int Rd, Rs, Rn;
9277
9278 Rd = inst.operands[0].reg;
9279 Rs = (inst.operands[1].present
9280 ? inst.operands[1].reg /* Rd, Rs, foo */
9281 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9282 Rn = inst.operands[2].reg;
9283
9284 reject_bad_reg (Rd);
9285 reject_bad_reg (Rs);
9286 if (inst.operands[2].isreg)
9287 reject_bad_reg (Rn);
9288
9289 if (unified_syntax)
9290 {
9291 if (!inst.operands[2].isreg)
9292 {
9293 /* For an immediate, we always generate a 32-bit opcode;
9294 section relaxation will shrink it later if possible. */
9295 inst.instruction = THUMB_OP32 (inst.instruction);
9296 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9297 inst.instruction |= Rd << 8;
9298 inst.instruction |= Rs << 16;
9299 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9300 }
9301 else
9302 {
9303 bfd_boolean narrow;
9304
9305 /* See if we can do this with a 16-bit instruction. */
9306 if (THUMB_SETS_FLAGS (inst.instruction))
9307 narrow = !in_it_block ();
9308 else
9309 narrow = in_it_block ();
9310
9311 if (Rd > 7 || Rn > 7 || Rs > 7)
9312 narrow = FALSE;
9313 if (inst.operands[2].shifted)
9314 narrow = FALSE;
9315 if (inst.size_req == 4)
9316 narrow = FALSE;
9317
9318 if (narrow)
9319 {
9320 if (Rd == Rs)
9321 {
9322 inst.instruction = THUMB_OP16 (inst.instruction);
9323 inst.instruction |= Rd;
9324 inst.instruction |= Rn << 3;
9325 return;
9326 }
9327 if (Rd == Rn)
9328 {
9329 inst.instruction = THUMB_OP16 (inst.instruction);
9330 inst.instruction |= Rd;
9331 inst.instruction |= Rs << 3;
9332 return;
9333 }
9334 }
9335
9336 /* If we get here, it can't be done in 16 bits. */
9337 constraint (inst.operands[2].shifted
9338 && inst.operands[2].immisreg,
9339 _("shift must be constant"));
9340 inst.instruction = THUMB_OP32 (inst.instruction);
9341 inst.instruction |= Rd << 8;
9342 inst.instruction |= Rs << 16;
9343 encode_thumb32_shifted_operand (2);
9344 }
9345 }
9346 else
9347 {
9348 /* On its face this is a lie - the instruction does set the
9349 flags. However, the only supported mnemonic in this mode
9350 says it doesn't. */
9351 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9352
9353 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9354 _("unshifted register required"));
9355 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9356
9357 inst.instruction = THUMB_OP16 (inst.instruction);
9358 inst.instruction |= Rd;
9359
9360 if (Rd == Rs)
9361 inst.instruction |= Rn << 3;
9362 else if (Rd == Rn)
9363 inst.instruction |= Rs << 3;
9364 else
9365 constraint (1, _("dest must overlap one source register"));
9366 }
9367 }
9368
9369 static void
9370 do_t_barrier (void)
9371 {
9372 if (inst.operands[0].present)
9373 {
9374 constraint ((inst.instruction & 0xf0) != 0x40
9375 && inst.operands[0].imm != 0xf,
9376 _("bad barrier type"));
9377 inst.instruction |= inst.operands[0].imm;
9378 }
9379 else
9380 inst.instruction |= 0xf;
9381 }
9382
9383 static void
9384 do_t_bfc (void)
9385 {
9386 unsigned Rd;
9387 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9388 constraint (msb > 32, _("bit-field extends past end of register"));
9389 /* The instruction encoding stores the LSB and MSB,
9390 not the LSB and width. */
9391 Rd = inst.operands[0].reg;
9392 reject_bad_reg (Rd);
9393 inst.instruction |= Rd << 8;
9394 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9395 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9396 inst.instruction |= msb - 1;
9397 }
9398
9399 static void
9400 do_t_bfi (void)
9401 {
9402 int Rd, Rn;
9403 unsigned int msb;
9404
9405 Rd = inst.operands[0].reg;
9406 reject_bad_reg (Rd);
9407
9408 /* #0 in second position is alternative syntax for bfc, which is
9409 the same instruction but with REG_PC in the Rm field. */
9410 if (!inst.operands[1].isreg)
9411 Rn = REG_PC;
9412 else
9413 {
9414 Rn = inst.operands[1].reg;
9415 reject_bad_reg (Rn);
9416 }
9417
9418 msb = inst.operands[2].imm + inst.operands[3].imm;
9419 constraint (msb > 32, _("bit-field extends past end of register"));
9420 /* The instruction encoding stores the LSB and MSB,
9421 not the LSB and width. */
9422 inst.instruction |= Rd << 8;
9423 inst.instruction |= Rn << 16;
9424 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9425 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9426 inst.instruction |= msb - 1;
9427 }
9428
9429 static void
9430 do_t_bfx (void)
9431 {
9432 unsigned Rd, Rn;
9433
9434 Rd = inst.operands[0].reg;
9435 Rn = inst.operands[1].reg;
9436
9437 reject_bad_reg (Rd);
9438 reject_bad_reg (Rn);
9439
9440 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9441 _("bit-field extends past end of register"));
9442 inst.instruction |= Rd << 8;
9443 inst.instruction |= Rn << 16;
9444 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9445 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9446 inst.instruction |= inst.operands[3].imm - 1;
9447 }
9448
9449 /* ARM V5 Thumb BLX (argument parse)
9450 BLX <target_addr> which is BLX(1)
9451 BLX <Rm> which is BLX(2)
9452 Unfortunately, there are two different opcodes for this mnemonic.
9453 So, the insns[].value is not used, and the code here zaps values
9454 into inst.instruction.
9455
9456 ??? How to take advantage of the additional two bits of displacement
9457 available in Thumb32 mode? Need new relocation? */
9458
9459 static void
9460 do_t_blx (void)
9461 {
9462 set_it_insn_type_last ();
9463
9464 if (inst.operands[0].isreg)
9465 {
9466 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9467 /* We have a register, so this is BLX(2). */
9468 inst.instruction |= inst.operands[0].reg << 3;
9469 }
9470 else
9471 {
9472 /* No register. This must be BLX(1). */
9473 inst.instruction = 0xf000e800;
9474 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
9475 inst.reloc.pc_rel = 1;
9476 }
9477 }
9478
9479 static void
9480 do_t_branch (void)
9481 {
9482 int opcode;
9483 int cond;
9484
9485 cond = inst.cond;
9486 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9487
9488 if (in_it_block ())
9489 {
9490 /* Conditional branches inside IT blocks are encoded as unconditional
9491 branches. */
9492 cond = COND_ALWAYS;
9493 }
9494 else
9495 cond = inst.cond;
9496
9497 if (cond != COND_ALWAYS)
9498 opcode = T_MNEM_bcond;
9499 else
9500 opcode = inst.instruction;
9501
9502 if (unified_syntax && inst.size_req == 4)
9503 {
9504 inst.instruction = THUMB_OP32(opcode);
9505 if (cond == COND_ALWAYS)
9506 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
9507 else
9508 {
9509 gas_assert (cond != 0xF);
9510 inst.instruction |= cond << 22;
9511 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9512 }
9513 }
9514 else
9515 {
9516 inst.instruction = THUMB_OP16(opcode);
9517 if (cond == COND_ALWAYS)
9518 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9519 else
9520 {
9521 inst.instruction |= cond << 8;
9522 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
9523 }
9524 /* Allow section relaxation. */
9525 if (unified_syntax && inst.size_req != 2)
9526 inst.relax = opcode;
9527 }
9528
9529 inst.reloc.pc_rel = 1;
9530 }
9531
9532 static void
9533 do_t_bkpt (void)
9534 {
9535 constraint (inst.cond != COND_ALWAYS,
9536 _("instruction is always unconditional"));
9537 if (inst.operands[0].present)
9538 {
9539 constraint (inst.operands[0].imm > 255,
9540 _("immediate value out of range"));
9541 inst.instruction |= inst.operands[0].imm;
9542 set_it_insn_type (NEUTRAL_IT_INSN);
9543 }
9544 }
9545
9546 static void
9547 do_t_branch23 (void)
9548 {
9549 set_it_insn_type_last ();
9550 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9551 inst.reloc.pc_rel = 1;
9552
9553 #if defined(OBJ_COFF)
9554 /* If the destination of the branch is a defined symbol which does not have
9555 the THUMB_FUNC attribute, then we must be calling a function which has
9556 the (interfacearm) attribute. We look for the Thumb entry point to that
9557 function and change the branch to refer to that function instead. */
9558 if ( inst.reloc.exp.X_op == O_symbol
9559 && inst.reloc.exp.X_add_symbol != NULL
9560 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9561 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9562 inst.reloc.exp.X_add_symbol =
9563 find_real_start (inst.reloc.exp.X_add_symbol);
9564 #endif
9565 }
9566
9567 static void
9568 do_t_bx (void)
9569 {
9570 set_it_insn_type_last ();
9571 inst.instruction |= inst.operands[0].reg << 3;
9572 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9573 should cause the alignment to be checked once it is known. This is
9574 because BX PC only works if the instruction is word aligned. */
9575 }
9576
9577 static void
9578 do_t_bxj (void)
9579 {
9580 int Rm;
9581
9582 set_it_insn_type_last ();
9583 Rm = inst.operands[0].reg;
9584 reject_bad_reg (Rm);
9585 inst.instruction |= Rm << 16;
9586 }
9587
9588 static void
9589 do_t_clz (void)
9590 {
9591 unsigned Rd;
9592 unsigned Rm;
9593
9594 Rd = inst.operands[0].reg;
9595 Rm = inst.operands[1].reg;
9596
9597 reject_bad_reg (Rd);
9598 reject_bad_reg (Rm);
9599
9600 inst.instruction |= Rd << 8;
9601 inst.instruction |= Rm << 16;
9602 inst.instruction |= Rm;
9603 }
9604
9605 static void
9606 do_t_cps (void)
9607 {
9608 set_it_insn_type (OUTSIDE_IT_INSN);
9609 inst.instruction |= inst.operands[0].imm;
9610 }
9611
9612 static void
9613 do_t_cpsi (void)
9614 {
9615 set_it_insn_type (OUTSIDE_IT_INSN);
9616 if (unified_syntax
9617 && (inst.operands[1].present || inst.size_req == 4)
9618 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9619 {
9620 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9621 inst.instruction = 0xf3af8000;
9622 inst.instruction |= imod << 9;
9623 inst.instruction |= inst.operands[0].imm << 5;
9624 if (inst.operands[1].present)
9625 inst.instruction |= 0x100 | inst.operands[1].imm;
9626 }
9627 else
9628 {
9629 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9630 && (inst.operands[0].imm & 4),
9631 _("selected processor does not support 'A' form "
9632 "of this instruction"));
9633 constraint (inst.operands[1].present || inst.size_req == 4,
9634 _("Thumb does not support the 2-argument "
9635 "form of this instruction"));
9636 inst.instruction |= inst.operands[0].imm;
9637 }
9638 }
9639
9640 /* THUMB CPY instruction (argument parse). */
9641
9642 static void
9643 do_t_cpy (void)
9644 {
9645 if (inst.size_req == 4)
9646 {
9647 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9648 inst.instruction |= inst.operands[0].reg << 8;
9649 inst.instruction |= inst.operands[1].reg;
9650 }
9651 else
9652 {
9653 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9654 inst.instruction |= (inst.operands[0].reg & 0x7);
9655 inst.instruction |= inst.operands[1].reg << 3;
9656 }
9657 }
9658
9659 static void
9660 do_t_cbz (void)
9661 {
9662 set_it_insn_type (OUTSIDE_IT_INSN);
9663 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9664 inst.instruction |= inst.operands[0].reg;
9665 inst.reloc.pc_rel = 1;
9666 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9667 }
9668
9669 static void
9670 do_t_dbg (void)
9671 {
9672 inst.instruction |= inst.operands[0].imm;
9673 }
9674
9675 static void
9676 do_t_div (void)
9677 {
9678 unsigned Rd, Rn, Rm;
9679
9680 Rd = inst.operands[0].reg;
9681 Rn = (inst.operands[1].present
9682 ? inst.operands[1].reg : Rd);
9683 Rm = inst.operands[2].reg;
9684
9685 reject_bad_reg (Rd);
9686 reject_bad_reg (Rn);
9687 reject_bad_reg (Rm);
9688
9689 inst.instruction |= Rd << 8;
9690 inst.instruction |= Rn << 16;
9691 inst.instruction |= Rm;
9692 }
9693
9694 static void
9695 do_t_hint (void)
9696 {
9697 if (unified_syntax && inst.size_req == 4)
9698 inst.instruction = THUMB_OP32 (inst.instruction);
9699 else
9700 inst.instruction = THUMB_OP16 (inst.instruction);
9701 }
9702
9703 static void
9704 do_t_it (void)
9705 {
9706 unsigned int cond = inst.operands[0].imm;
9707
9708 set_it_insn_type (IT_INSN);
9709 now_it.mask = (inst.instruction & 0xf) | 0x10;
9710 now_it.cc = cond;
9711
9712 /* If the condition is a negative condition, invert the mask. */
9713 if ((cond & 0x1) == 0x0)
9714 {
9715 unsigned int mask = inst.instruction & 0x000f;
9716
9717 if ((mask & 0x7) == 0)
9718 /* no conversion needed */;
9719 else if ((mask & 0x3) == 0)
9720 mask ^= 0x8;
9721 else if ((mask & 0x1) == 0)
9722 mask ^= 0xC;
9723 else
9724 mask ^= 0xE;
9725
9726 inst.instruction &= 0xfff0;
9727 inst.instruction |= mask;
9728 }
9729
9730 inst.instruction |= cond << 4;
9731 }
9732
9733 /* Helper function used for both push/pop and ldm/stm. */
9734 static void
9735 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9736 {
9737 bfd_boolean load;
9738
9739 load = (inst.instruction & (1 << 20)) != 0;
9740
9741 if (mask & (1 << 13))
9742 inst.error = _("SP not allowed in register list");
9743 if (load)
9744 {
9745 if (mask & (1 << 15))
9746 {
9747 if (mask & (1 << 14))
9748 inst.error = _("LR and PC should not both be in register list");
9749 else
9750 set_it_insn_type_last ();
9751 }
9752
9753 if ((mask & (1 << base)) != 0
9754 && writeback)
9755 as_warn (_("base register should not be in register list "
9756 "when written back"));
9757 }
9758 else
9759 {
9760 if (mask & (1 << 15))
9761 inst.error = _("PC not allowed in register list");
9762
9763 if (mask & (1 << base))
9764 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9765 }
9766
9767 if ((mask & (mask - 1)) == 0)
9768 {
9769 /* Single register transfers implemented as str/ldr. */
9770 if (writeback)
9771 {
9772 if (inst.instruction & (1 << 23))
9773 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9774 else
9775 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9776 }
9777 else
9778 {
9779 if (inst.instruction & (1 << 23))
9780 inst.instruction = 0x00800000; /* ia -> [base] */
9781 else
9782 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9783 }
9784
9785 inst.instruction |= 0xf8400000;
9786 if (load)
9787 inst.instruction |= 0x00100000;
9788
9789 mask = ffs (mask) - 1;
9790 mask <<= 12;
9791 }
9792 else if (writeback)
9793 inst.instruction |= WRITE_BACK;
9794
9795 inst.instruction |= mask;
9796 inst.instruction |= base << 16;
9797 }
9798
9799 static void
9800 do_t_ldmstm (void)
9801 {
9802 /* This really doesn't seem worth it. */
9803 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9804 _("expression too complex"));
9805 constraint (inst.operands[1].writeback,
9806 _("Thumb load/store multiple does not support {reglist}^"));
9807
9808 if (unified_syntax)
9809 {
9810 bfd_boolean narrow;
9811 unsigned mask;
9812
9813 narrow = FALSE;
9814 /* See if we can use a 16-bit instruction. */
9815 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9816 && inst.size_req != 4
9817 && !(inst.operands[1].imm & ~0xff))
9818 {
9819 mask = 1 << inst.operands[0].reg;
9820
9821 if (inst.operands[0].reg <= 7
9822 && (inst.instruction == T_MNEM_stmia
9823 ? inst.operands[0].writeback
9824 : (inst.operands[0].writeback
9825 == !(inst.operands[1].imm & mask))))
9826 {
9827 if (inst.instruction == T_MNEM_stmia
9828 && (inst.operands[1].imm & mask)
9829 && (inst.operands[1].imm & (mask - 1)))
9830 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9831 inst.operands[0].reg);
9832
9833 inst.instruction = THUMB_OP16 (inst.instruction);
9834 inst.instruction |= inst.operands[0].reg << 8;
9835 inst.instruction |= inst.operands[1].imm;
9836 narrow = TRUE;
9837 }
9838 else if (inst.operands[0] .reg == REG_SP
9839 && inst.operands[0].writeback)
9840 {
9841 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9842 ? T_MNEM_push : T_MNEM_pop);
9843 inst.instruction |= inst.operands[1].imm;
9844 narrow = TRUE;
9845 }
9846 }
9847
9848 if (!narrow)
9849 {
9850 if (inst.instruction < 0xffff)
9851 inst.instruction = THUMB_OP32 (inst.instruction);
9852
9853 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9854 inst.operands[0].writeback);
9855 }
9856 }
9857 else
9858 {
9859 constraint (inst.operands[0].reg > 7
9860 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9861 constraint (inst.instruction != T_MNEM_ldmia
9862 && inst.instruction != T_MNEM_stmia,
9863 _("Thumb-2 instruction only valid in unified syntax"));
9864 if (inst.instruction == T_MNEM_stmia)
9865 {
9866 if (!inst.operands[0].writeback)
9867 as_warn (_("this instruction will write back the base register"));
9868 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9869 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9870 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9871 inst.operands[0].reg);
9872 }
9873 else
9874 {
9875 if (!inst.operands[0].writeback
9876 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9877 as_warn (_("this instruction will write back the base register"));
9878 else if (inst.operands[0].writeback
9879 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9880 as_warn (_("this instruction will not write back the base register"));
9881 }
9882
9883 inst.instruction = THUMB_OP16 (inst.instruction);
9884 inst.instruction |= inst.operands[0].reg << 8;
9885 inst.instruction |= inst.operands[1].imm;
9886 }
9887 }
9888
9889 static void
9890 do_t_ldrex (void)
9891 {
9892 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9893 || inst.operands[1].postind || inst.operands[1].writeback
9894 || inst.operands[1].immisreg || inst.operands[1].shifted
9895 || inst.operands[1].negative,
9896 BAD_ADDR_MODE);
9897
9898 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9899
9900 inst.instruction |= inst.operands[0].reg << 12;
9901 inst.instruction |= inst.operands[1].reg << 16;
9902 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9903 }
9904
9905 static void
9906 do_t_ldrexd (void)
9907 {
9908 if (!inst.operands[1].present)
9909 {
9910 constraint (inst.operands[0].reg == REG_LR,
9911 _("r14 not allowed as first register "
9912 "when second register is omitted"));
9913 inst.operands[1].reg = inst.operands[0].reg + 1;
9914 }
9915 constraint (inst.operands[0].reg == inst.operands[1].reg,
9916 BAD_OVERLAP);
9917
9918 inst.instruction |= inst.operands[0].reg << 12;
9919 inst.instruction |= inst.operands[1].reg << 8;
9920 inst.instruction |= inst.operands[2].reg << 16;
9921 }
9922
9923 static void
9924 do_t_ldst (void)
9925 {
9926 unsigned long opcode;
9927 int Rn;
9928
9929 if (inst.operands[0].isreg
9930 && !inst.operands[0].preind
9931 && inst.operands[0].reg == REG_PC)
9932 set_it_insn_type_last ();
9933
9934 opcode = inst.instruction;
9935 if (unified_syntax)
9936 {
9937 if (!inst.operands[1].isreg)
9938 {
9939 if (opcode <= 0xffff)
9940 inst.instruction = THUMB_OP32 (opcode);
9941 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9942 return;
9943 }
9944 if (inst.operands[1].isreg
9945 && !inst.operands[1].writeback
9946 && !inst.operands[1].shifted && !inst.operands[1].postind
9947 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9948 && opcode <= 0xffff
9949 && inst.size_req != 4)
9950 {
9951 /* Insn may have a 16-bit form. */
9952 Rn = inst.operands[1].reg;
9953 if (inst.operands[1].immisreg)
9954 {
9955 inst.instruction = THUMB_OP16 (opcode);
9956 /* [Rn, Rik] */
9957 if (Rn <= 7 && inst.operands[1].imm <= 7)
9958 goto op16;
9959 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
9960 reject_bad_reg (inst.operands[1].imm);
9961 }
9962 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9963 && opcode != T_MNEM_ldrsb)
9964 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9965 || (Rn == REG_SP && opcode == T_MNEM_str))
9966 {
9967 /* [Rn, #const] */
9968 if (Rn > 7)
9969 {
9970 if (Rn == REG_PC)
9971 {
9972 if (inst.reloc.pc_rel)
9973 opcode = T_MNEM_ldr_pc2;
9974 else
9975 opcode = T_MNEM_ldr_pc;
9976 }
9977 else
9978 {
9979 if (opcode == T_MNEM_ldr)
9980 opcode = T_MNEM_ldr_sp;
9981 else
9982 opcode = T_MNEM_str_sp;
9983 }
9984 inst.instruction = inst.operands[0].reg << 8;
9985 }
9986 else
9987 {
9988 inst.instruction = inst.operands[0].reg;
9989 inst.instruction |= inst.operands[1].reg << 3;
9990 }
9991 inst.instruction |= THUMB_OP16 (opcode);
9992 if (inst.size_req == 2)
9993 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9994 else
9995 inst.relax = opcode;
9996 return;
9997 }
9998 }
9999 /* Definitely a 32-bit variant. */
10000
10001 /* Do some validations regarding addressing modes. */
10002 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10003 && opcode != T_MNEM_str)
10004 reject_bad_reg (inst.operands[1].imm);
10005
10006 inst.instruction = THUMB_OP32 (opcode);
10007 inst.instruction |= inst.operands[0].reg << 12;
10008 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10009 return;
10010 }
10011
10012 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10013
10014 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10015 {
10016 /* Only [Rn,Rm] is acceptable. */
10017 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10018 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10019 || inst.operands[1].postind || inst.operands[1].shifted
10020 || inst.operands[1].negative,
10021 _("Thumb does not support this addressing mode"));
10022 inst.instruction = THUMB_OP16 (inst.instruction);
10023 goto op16;
10024 }
10025
10026 inst.instruction = THUMB_OP16 (inst.instruction);
10027 if (!inst.operands[1].isreg)
10028 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10029 return;
10030
10031 constraint (!inst.operands[1].preind
10032 || inst.operands[1].shifted
10033 || inst.operands[1].writeback,
10034 _("Thumb does not support this addressing mode"));
10035 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10036 {
10037 constraint (inst.instruction & 0x0600,
10038 _("byte or halfword not valid for base register"));
10039 constraint (inst.operands[1].reg == REG_PC
10040 && !(inst.instruction & THUMB_LOAD_BIT),
10041 _("r15 based store not allowed"));
10042 constraint (inst.operands[1].immisreg,
10043 _("invalid base register for register offset"));
10044
10045 if (inst.operands[1].reg == REG_PC)
10046 inst.instruction = T_OPCODE_LDR_PC;
10047 else if (inst.instruction & THUMB_LOAD_BIT)
10048 inst.instruction = T_OPCODE_LDR_SP;
10049 else
10050 inst.instruction = T_OPCODE_STR_SP;
10051
10052 inst.instruction |= inst.operands[0].reg << 8;
10053 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10054 return;
10055 }
10056
10057 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10058 if (!inst.operands[1].immisreg)
10059 {
10060 /* Immediate offset. */
10061 inst.instruction |= inst.operands[0].reg;
10062 inst.instruction |= inst.operands[1].reg << 3;
10063 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10064 return;
10065 }
10066
10067 /* Register offset. */
10068 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10069 constraint (inst.operands[1].negative,
10070 _("Thumb does not support this addressing mode"));
10071
10072 op16:
10073 switch (inst.instruction)
10074 {
10075 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10076 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10077 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10078 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10079 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10080 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10081 case 0x5600 /* ldrsb */:
10082 case 0x5e00 /* ldrsh */: break;
10083 default: abort ();
10084 }
10085
10086 inst.instruction |= inst.operands[0].reg;
10087 inst.instruction |= inst.operands[1].reg << 3;
10088 inst.instruction |= inst.operands[1].imm << 6;
10089 }
10090
10091 static void
10092 do_t_ldstd (void)
10093 {
10094 if (!inst.operands[1].present)
10095 {
10096 inst.operands[1].reg = inst.operands[0].reg + 1;
10097 constraint (inst.operands[0].reg == REG_LR,
10098 _("r14 not allowed here"));
10099 }
10100 inst.instruction |= inst.operands[0].reg << 12;
10101 inst.instruction |= inst.operands[1].reg << 8;
10102 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10103 }
10104
10105 static void
10106 do_t_ldstt (void)
10107 {
10108 inst.instruction |= inst.operands[0].reg << 12;
10109 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10110 }
10111
10112 static void
10113 do_t_mla (void)
10114 {
10115 unsigned Rd, Rn, Rm, Ra;
10116
10117 Rd = inst.operands[0].reg;
10118 Rn = inst.operands[1].reg;
10119 Rm = inst.operands[2].reg;
10120 Ra = inst.operands[3].reg;
10121
10122 reject_bad_reg (Rd);
10123 reject_bad_reg (Rn);
10124 reject_bad_reg (Rm);
10125 reject_bad_reg (Ra);
10126
10127 inst.instruction |= Rd << 8;
10128 inst.instruction |= Rn << 16;
10129 inst.instruction |= Rm;
10130 inst.instruction |= Ra << 12;
10131 }
10132
10133 static void
10134 do_t_mlal (void)
10135 {
10136 unsigned RdLo, RdHi, Rn, Rm;
10137
10138 RdLo = inst.operands[0].reg;
10139 RdHi = inst.operands[1].reg;
10140 Rn = inst.operands[2].reg;
10141 Rm = inst.operands[3].reg;
10142
10143 reject_bad_reg (RdLo);
10144 reject_bad_reg (RdHi);
10145 reject_bad_reg (Rn);
10146 reject_bad_reg (Rm);
10147
10148 inst.instruction |= RdLo << 12;
10149 inst.instruction |= RdHi << 8;
10150 inst.instruction |= Rn << 16;
10151 inst.instruction |= Rm;
10152 }
10153
10154 static void
10155 do_t_mov_cmp (void)
10156 {
10157 unsigned Rn, Rm;
10158
10159 Rn = inst.operands[0].reg;
10160 Rm = inst.operands[1].reg;
10161
10162 if (Rn == REG_PC)
10163 set_it_insn_type_last ();
10164
10165 if (unified_syntax)
10166 {
10167 int r0off = (inst.instruction == T_MNEM_mov
10168 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10169 unsigned long opcode;
10170 bfd_boolean narrow;
10171 bfd_boolean low_regs;
10172
10173 low_regs = (Rn <= 7 && Rm <= 7);
10174 opcode = inst.instruction;
10175 if (in_it_block ())
10176 narrow = opcode != T_MNEM_movs;
10177 else
10178 narrow = opcode != T_MNEM_movs || low_regs;
10179 if (inst.size_req == 4
10180 || inst.operands[1].shifted)
10181 narrow = FALSE;
10182
10183 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10184 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10185 && !inst.operands[1].shifted
10186 && Rn == REG_PC
10187 && Rm == REG_LR)
10188 {
10189 inst.instruction = T2_SUBS_PC_LR;
10190 return;
10191 }
10192
10193 if (opcode == T_MNEM_cmp)
10194 {
10195 constraint (Rn == REG_PC, BAD_PC);
10196 if (narrow)
10197 {
10198 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10199 but valid. */
10200 warn_deprecated_sp (Rm);
10201 /* R15 was documented as a valid choice for Rm in ARMv6,
10202 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10203 tools reject R15, so we do too. */
10204 constraint (Rm == REG_PC, BAD_PC);
10205 }
10206 else
10207 reject_bad_reg (Rm);
10208 }
10209 else if (opcode == T_MNEM_mov
10210 || opcode == T_MNEM_movs)
10211 {
10212 if (inst.operands[1].isreg)
10213 {
10214 if (opcode == T_MNEM_movs)
10215 {
10216 reject_bad_reg (Rn);
10217 reject_bad_reg (Rm);
10218 }
10219 else if ((Rn == REG_SP || Rn == REG_PC)
10220 && (Rm == REG_SP || Rm == REG_PC))
10221 reject_bad_reg (Rm);
10222 }
10223 else
10224 reject_bad_reg (Rn);
10225 }
10226
10227 if (!inst.operands[1].isreg)
10228 {
10229 /* Immediate operand. */
10230 if (!in_it_block () && opcode == T_MNEM_mov)
10231 narrow = 0;
10232 if (low_regs && narrow)
10233 {
10234 inst.instruction = THUMB_OP16 (opcode);
10235 inst.instruction |= Rn << 8;
10236 if (inst.size_req == 2)
10237 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10238 else
10239 inst.relax = opcode;
10240 }
10241 else
10242 {
10243 inst.instruction = THUMB_OP32 (inst.instruction);
10244 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10245 inst.instruction |= Rn << r0off;
10246 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10247 }
10248 }
10249 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10250 && (inst.instruction == T_MNEM_mov
10251 || inst.instruction == T_MNEM_movs))
10252 {
10253 /* Register shifts are encoded as separate shift instructions. */
10254 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10255
10256 if (in_it_block ())
10257 narrow = !flags;
10258 else
10259 narrow = flags;
10260
10261 if (inst.size_req == 4)
10262 narrow = FALSE;
10263
10264 if (!low_regs || inst.operands[1].imm > 7)
10265 narrow = FALSE;
10266
10267 if (Rn != Rm)
10268 narrow = FALSE;
10269
10270 switch (inst.operands[1].shift_kind)
10271 {
10272 case SHIFT_LSL:
10273 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10274 break;
10275 case SHIFT_ASR:
10276 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10277 break;
10278 case SHIFT_LSR:
10279 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10280 break;
10281 case SHIFT_ROR:
10282 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10283 break;
10284 default:
10285 abort ();
10286 }
10287
10288 inst.instruction = opcode;
10289 if (narrow)
10290 {
10291 inst.instruction |= Rn;
10292 inst.instruction |= inst.operands[1].imm << 3;
10293 }
10294 else
10295 {
10296 if (flags)
10297 inst.instruction |= CONDS_BIT;
10298
10299 inst.instruction |= Rn << 8;
10300 inst.instruction |= Rm << 16;
10301 inst.instruction |= inst.operands[1].imm;
10302 }
10303 }
10304 else if (!narrow)
10305 {
10306 /* Some mov with immediate shift have narrow variants.
10307 Register shifts are handled above. */
10308 if (low_regs && inst.operands[1].shifted
10309 && (inst.instruction == T_MNEM_mov
10310 || inst.instruction == T_MNEM_movs))
10311 {
10312 if (in_it_block ())
10313 narrow = (inst.instruction == T_MNEM_mov);
10314 else
10315 narrow = (inst.instruction == T_MNEM_movs);
10316 }
10317
10318 if (narrow)
10319 {
10320 switch (inst.operands[1].shift_kind)
10321 {
10322 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10323 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10324 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10325 default: narrow = FALSE; break;
10326 }
10327 }
10328
10329 if (narrow)
10330 {
10331 inst.instruction |= Rn;
10332 inst.instruction |= Rm << 3;
10333 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10334 }
10335 else
10336 {
10337 inst.instruction = THUMB_OP32 (inst.instruction);
10338 inst.instruction |= Rn << r0off;
10339 encode_thumb32_shifted_operand (1);
10340 }
10341 }
10342 else
10343 switch (inst.instruction)
10344 {
10345 case T_MNEM_mov:
10346 inst.instruction = T_OPCODE_MOV_HR;
10347 inst.instruction |= (Rn & 0x8) << 4;
10348 inst.instruction |= (Rn & 0x7);
10349 inst.instruction |= Rm << 3;
10350 break;
10351
10352 case T_MNEM_movs:
10353 /* We know we have low registers at this point.
10354 Generate ADD Rd, Rs, #0. */
10355 inst.instruction = T_OPCODE_ADD_I3;
10356 inst.instruction |= Rn;
10357 inst.instruction |= Rm << 3;
10358 break;
10359
10360 case T_MNEM_cmp:
10361 if (low_regs)
10362 {
10363 inst.instruction = T_OPCODE_CMP_LR;
10364 inst.instruction |= Rn;
10365 inst.instruction |= Rm << 3;
10366 }
10367 else
10368 {
10369 inst.instruction = T_OPCODE_CMP_HR;
10370 inst.instruction |= (Rn & 0x8) << 4;
10371 inst.instruction |= (Rn & 0x7);
10372 inst.instruction |= Rm << 3;
10373 }
10374 break;
10375 }
10376 return;
10377 }
10378
10379 inst.instruction = THUMB_OP16 (inst.instruction);
10380
10381 /* PR 10443: Do not silently ignore shifted operands. */
10382 constraint (inst.operands[1].shifted,
10383 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10384
10385 if (inst.operands[1].isreg)
10386 {
10387 if (Rn < 8 && Rm < 8)
10388 {
10389 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10390 since a MOV instruction produces unpredictable results. */
10391 if (inst.instruction == T_OPCODE_MOV_I8)
10392 inst.instruction = T_OPCODE_ADD_I3;
10393 else
10394 inst.instruction = T_OPCODE_CMP_LR;
10395
10396 inst.instruction |= Rn;
10397 inst.instruction |= Rm << 3;
10398 }
10399 else
10400 {
10401 if (inst.instruction == T_OPCODE_MOV_I8)
10402 inst.instruction = T_OPCODE_MOV_HR;
10403 else
10404 inst.instruction = T_OPCODE_CMP_HR;
10405 do_t_cpy ();
10406 }
10407 }
10408 else
10409 {
10410 constraint (Rn > 7,
10411 _("only lo regs allowed with immediate"));
10412 inst.instruction |= Rn << 8;
10413 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10414 }
10415 }
10416
10417 static void
10418 do_t_mov16 (void)
10419 {
10420 unsigned Rd;
10421 bfd_vma imm;
10422 bfd_boolean top;
10423
10424 top = (inst.instruction & 0x00800000) != 0;
10425 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10426 {
10427 constraint (top, _(":lower16: not allowed this instruction"));
10428 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10429 }
10430 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10431 {
10432 constraint (!top, _(":upper16: not allowed this instruction"));
10433 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10434 }
10435
10436 Rd = inst.operands[0].reg;
10437 reject_bad_reg (Rd);
10438
10439 inst.instruction |= Rd << 8;
10440 if (inst.reloc.type == BFD_RELOC_UNUSED)
10441 {
10442 imm = inst.reloc.exp.X_add_number;
10443 inst.instruction |= (imm & 0xf000) << 4;
10444 inst.instruction |= (imm & 0x0800) << 15;
10445 inst.instruction |= (imm & 0x0700) << 4;
10446 inst.instruction |= (imm & 0x00ff);
10447 }
10448 }
10449
10450 static void
10451 do_t_mvn_tst (void)
10452 {
10453 unsigned Rn, Rm;
10454
10455 Rn = inst.operands[0].reg;
10456 Rm = inst.operands[1].reg;
10457
10458 if (inst.instruction == T_MNEM_cmp
10459 || inst.instruction == T_MNEM_cmn)
10460 constraint (Rn == REG_PC, BAD_PC);
10461 else
10462 reject_bad_reg (Rn);
10463 reject_bad_reg (Rm);
10464
10465 if (unified_syntax)
10466 {
10467 int r0off = (inst.instruction == T_MNEM_mvn
10468 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
10469 bfd_boolean narrow;
10470
10471 if (inst.size_req == 4
10472 || inst.instruction > 0xffff
10473 || inst.operands[1].shifted
10474 || Rn > 7 || Rm > 7)
10475 narrow = FALSE;
10476 else if (inst.instruction == T_MNEM_cmn)
10477 narrow = TRUE;
10478 else if (THUMB_SETS_FLAGS (inst.instruction))
10479 narrow = !in_it_block ();
10480 else
10481 narrow = in_it_block ();
10482
10483 if (!inst.operands[1].isreg)
10484 {
10485 /* For an immediate, we always generate a 32-bit opcode;
10486 section relaxation will shrink it later if possible. */
10487 if (inst.instruction < 0xffff)
10488 inst.instruction = THUMB_OP32 (inst.instruction);
10489 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10490 inst.instruction |= Rn << r0off;
10491 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10492 }
10493 else
10494 {
10495 /* See if we can do this with a 16-bit instruction. */
10496 if (narrow)
10497 {
10498 inst.instruction = THUMB_OP16 (inst.instruction);
10499 inst.instruction |= Rn;
10500 inst.instruction |= Rm << 3;
10501 }
10502 else
10503 {
10504 constraint (inst.operands[1].shifted
10505 && inst.operands[1].immisreg,
10506 _("shift must be constant"));
10507 if (inst.instruction < 0xffff)
10508 inst.instruction = THUMB_OP32 (inst.instruction);
10509 inst.instruction |= Rn << r0off;
10510 encode_thumb32_shifted_operand (1);
10511 }
10512 }
10513 }
10514 else
10515 {
10516 constraint (inst.instruction > 0xffff
10517 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10518 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10519 _("unshifted register required"));
10520 constraint (Rn > 7 || Rm > 7,
10521 BAD_HIREG);
10522
10523 inst.instruction = THUMB_OP16 (inst.instruction);
10524 inst.instruction |= Rn;
10525 inst.instruction |= Rm << 3;
10526 }
10527 }
10528
10529 static void
10530 do_t_mrs (void)
10531 {
10532 unsigned Rd;
10533 int flags;
10534
10535 if (do_vfp_nsyn_mrs () == SUCCESS)
10536 return;
10537
10538 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10539 if (flags == 0)
10540 {
10541 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10542 _("selected processor does not support "
10543 "requested special purpose register"));
10544 }
10545 else
10546 {
10547 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10548 _("selected processor does not support "
10549 "requested special purpose register"));
10550 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10551 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10552 _("'CPSR' or 'SPSR' expected"));
10553 }
10554
10555 Rd = inst.operands[0].reg;
10556 reject_bad_reg (Rd);
10557
10558 inst.instruction |= Rd << 8;
10559 inst.instruction |= (flags & SPSR_BIT) >> 2;
10560 inst.instruction |= inst.operands[1].imm & 0xff;
10561 }
10562
10563 static void
10564 do_t_msr (void)
10565 {
10566 int flags;
10567 unsigned Rn;
10568
10569 if (do_vfp_nsyn_msr () == SUCCESS)
10570 return;
10571
10572 constraint (!inst.operands[1].isreg,
10573 _("Thumb encoding does not support an immediate here"));
10574 flags = inst.operands[0].imm;
10575 if (flags & ~0xff)
10576 {
10577 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10578 _("selected processor does not support "
10579 "requested special purpose register"));
10580 }
10581 else
10582 {
10583 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10584 _("selected processor does not support "
10585 "requested special purpose register"));
10586 flags |= PSR_f;
10587 }
10588
10589 Rn = inst.operands[1].reg;
10590 reject_bad_reg (Rn);
10591
10592 inst.instruction |= (flags & SPSR_BIT) >> 2;
10593 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10594 inst.instruction |= (flags & 0xff);
10595 inst.instruction |= Rn << 16;
10596 }
10597
10598 static void
10599 do_t_mul (void)
10600 {
10601 bfd_boolean narrow;
10602 unsigned Rd, Rn, Rm;
10603
10604 if (!inst.operands[2].present)
10605 inst.operands[2].reg = inst.operands[0].reg;
10606
10607 Rd = inst.operands[0].reg;
10608 Rn = inst.operands[1].reg;
10609 Rm = inst.operands[2].reg;
10610
10611 if (unified_syntax)
10612 {
10613 if (inst.size_req == 4
10614 || (Rd != Rn
10615 && Rd != Rm)
10616 || Rn > 7
10617 || Rm > 7)
10618 narrow = FALSE;
10619 else if (inst.instruction == T_MNEM_muls)
10620 narrow = !in_it_block ();
10621 else
10622 narrow = in_it_block ();
10623 }
10624 else
10625 {
10626 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
10627 constraint (Rn > 7 || Rm > 7,
10628 BAD_HIREG);
10629 narrow = TRUE;
10630 }
10631
10632 if (narrow)
10633 {
10634 /* 16-bit MULS/Conditional MUL. */
10635 inst.instruction = THUMB_OP16 (inst.instruction);
10636 inst.instruction |= Rd;
10637
10638 if (Rd == Rn)
10639 inst.instruction |= Rm << 3;
10640 else if (Rd == Rm)
10641 inst.instruction |= Rn << 3;
10642 else
10643 constraint (1, _("dest must overlap one source register"));
10644 }
10645 else
10646 {
10647 constraint (inst.instruction != T_MNEM_mul,
10648 _("Thumb-2 MUL must not set flags"));
10649 /* 32-bit MUL. */
10650 inst.instruction = THUMB_OP32 (inst.instruction);
10651 inst.instruction |= Rd << 8;
10652 inst.instruction |= Rn << 16;
10653 inst.instruction |= Rm << 0;
10654
10655 reject_bad_reg (Rd);
10656 reject_bad_reg (Rn);
10657 reject_bad_reg (Rm);
10658 }
10659 }
10660
10661 static void
10662 do_t_mull (void)
10663 {
10664 unsigned RdLo, RdHi, Rn, Rm;
10665
10666 RdLo = inst.operands[0].reg;
10667 RdHi = inst.operands[1].reg;
10668 Rn = inst.operands[2].reg;
10669 Rm = inst.operands[3].reg;
10670
10671 reject_bad_reg (RdLo);
10672 reject_bad_reg (RdHi);
10673 reject_bad_reg (Rn);
10674 reject_bad_reg (Rm);
10675
10676 inst.instruction |= RdLo << 12;
10677 inst.instruction |= RdHi << 8;
10678 inst.instruction |= Rn << 16;
10679 inst.instruction |= Rm;
10680
10681 if (RdLo == RdHi)
10682 as_tsktsk (_("rdhi and rdlo must be different"));
10683 }
10684
10685 static void
10686 do_t_nop (void)
10687 {
10688 set_it_insn_type (NEUTRAL_IT_INSN);
10689
10690 if (unified_syntax)
10691 {
10692 if (inst.size_req == 4 || inst.operands[0].imm > 15)
10693 {
10694 inst.instruction = THUMB_OP32 (inst.instruction);
10695 inst.instruction |= inst.operands[0].imm;
10696 }
10697 else
10698 {
10699 /* PR9722: Check for Thumb2 availability before
10700 generating a thumb2 nop instruction. */
10701 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
10702 {
10703 inst.instruction = THUMB_OP16 (inst.instruction);
10704 inst.instruction |= inst.operands[0].imm << 4;
10705 }
10706 else
10707 inst.instruction = 0x46c0;
10708 }
10709 }
10710 else
10711 {
10712 constraint (inst.operands[0].present,
10713 _("Thumb does not support NOP with hints"));
10714 inst.instruction = 0x46c0;
10715 }
10716 }
10717
10718 static void
10719 do_t_neg (void)
10720 {
10721 if (unified_syntax)
10722 {
10723 bfd_boolean narrow;
10724
10725 if (THUMB_SETS_FLAGS (inst.instruction))
10726 narrow = !in_it_block ();
10727 else
10728 narrow = in_it_block ();
10729 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10730 narrow = FALSE;
10731 if (inst.size_req == 4)
10732 narrow = FALSE;
10733
10734 if (!narrow)
10735 {
10736 inst.instruction = THUMB_OP32 (inst.instruction);
10737 inst.instruction |= inst.operands[0].reg << 8;
10738 inst.instruction |= inst.operands[1].reg << 16;
10739 }
10740 else
10741 {
10742 inst.instruction = THUMB_OP16 (inst.instruction);
10743 inst.instruction |= inst.operands[0].reg;
10744 inst.instruction |= inst.operands[1].reg << 3;
10745 }
10746 }
10747 else
10748 {
10749 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10750 BAD_HIREG);
10751 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10752
10753 inst.instruction = THUMB_OP16 (inst.instruction);
10754 inst.instruction |= inst.operands[0].reg;
10755 inst.instruction |= inst.operands[1].reg << 3;
10756 }
10757 }
10758
10759 static void
10760 do_t_orn (void)
10761 {
10762 unsigned Rd, Rn;
10763
10764 Rd = inst.operands[0].reg;
10765 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10766
10767 reject_bad_reg (Rd);
10768 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10769 reject_bad_reg (Rn);
10770
10771 inst.instruction |= Rd << 8;
10772 inst.instruction |= Rn << 16;
10773
10774 if (!inst.operands[2].isreg)
10775 {
10776 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10777 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10778 }
10779 else
10780 {
10781 unsigned Rm;
10782
10783 Rm = inst.operands[2].reg;
10784 reject_bad_reg (Rm);
10785
10786 constraint (inst.operands[2].shifted
10787 && inst.operands[2].immisreg,
10788 _("shift must be constant"));
10789 encode_thumb32_shifted_operand (2);
10790 }
10791 }
10792
10793 static void
10794 do_t_pkhbt (void)
10795 {
10796 unsigned Rd, Rn, Rm;
10797
10798 Rd = inst.operands[0].reg;
10799 Rn = inst.operands[1].reg;
10800 Rm = inst.operands[2].reg;
10801
10802 reject_bad_reg (Rd);
10803 reject_bad_reg (Rn);
10804 reject_bad_reg (Rm);
10805
10806 inst.instruction |= Rd << 8;
10807 inst.instruction |= Rn << 16;
10808 inst.instruction |= Rm;
10809 if (inst.operands[3].present)
10810 {
10811 unsigned int val = inst.reloc.exp.X_add_number;
10812 constraint (inst.reloc.exp.X_op != O_constant,
10813 _("expression too complex"));
10814 inst.instruction |= (val & 0x1c) << 10;
10815 inst.instruction |= (val & 0x03) << 6;
10816 }
10817 }
10818
10819 static void
10820 do_t_pkhtb (void)
10821 {
10822 if (!inst.operands[3].present)
10823 {
10824 unsigned Rtmp;
10825
10826 inst.instruction &= ~0x00000020;
10827
10828 /* PR 10168. Swap the Rm and Rn registers. */
10829 Rtmp = inst.operands[1].reg;
10830 inst.operands[1].reg = inst.operands[2].reg;
10831 inst.operands[2].reg = Rtmp;
10832 }
10833 do_t_pkhbt ();
10834 }
10835
10836 static void
10837 do_t_pld (void)
10838 {
10839 if (inst.operands[0].immisreg)
10840 reject_bad_reg (inst.operands[0].imm);
10841
10842 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10843 }
10844
10845 static void
10846 do_t_push_pop (void)
10847 {
10848 unsigned mask;
10849
10850 constraint (inst.operands[0].writeback,
10851 _("push/pop do not support {reglist}^"));
10852 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10853 _("expression too complex"));
10854
10855 mask = inst.operands[0].imm;
10856 if ((mask & ~0xff) == 0)
10857 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10858 else if ((inst.instruction == T_MNEM_push
10859 && (mask & ~0xff) == 1 << REG_LR)
10860 || (inst.instruction == T_MNEM_pop
10861 && (mask & ~0xff) == 1 << REG_PC))
10862 {
10863 inst.instruction = THUMB_OP16 (inst.instruction);
10864 inst.instruction |= THUMB_PP_PC_LR;
10865 inst.instruction |= mask & 0xff;
10866 }
10867 else if (unified_syntax)
10868 {
10869 inst.instruction = THUMB_OP32 (inst.instruction);
10870 encode_thumb2_ldmstm (13, mask, TRUE);
10871 }
10872 else
10873 {
10874 inst.error = _("invalid register list to push/pop instruction");
10875 return;
10876 }
10877 }
10878
10879 static void
10880 do_t_rbit (void)
10881 {
10882 unsigned Rd, Rm;
10883
10884 Rd = inst.operands[0].reg;
10885 Rm = inst.operands[1].reg;
10886
10887 reject_bad_reg (Rd);
10888 reject_bad_reg (Rm);
10889
10890 inst.instruction |= Rd << 8;
10891 inst.instruction |= Rm << 16;
10892 inst.instruction |= Rm;
10893 }
10894
10895 static void
10896 do_t_rev (void)
10897 {
10898 unsigned Rd, Rm;
10899
10900 Rd = inst.operands[0].reg;
10901 Rm = inst.operands[1].reg;
10902
10903 reject_bad_reg (Rd);
10904 reject_bad_reg (Rm);
10905
10906 if (Rd <= 7 && Rm <= 7
10907 && inst.size_req != 4)
10908 {
10909 inst.instruction = THUMB_OP16 (inst.instruction);
10910 inst.instruction |= Rd;
10911 inst.instruction |= Rm << 3;
10912 }
10913 else if (unified_syntax)
10914 {
10915 inst.instruction = THUMB_OP32 (inst.instruction);
10916 inst.instruction |= Rd << 8;
10917 inst.instruction |= Rm << 16;
10918 inst.instruction |= Rm;
10919 }
10920 else
10921 inst.error = BAD_HIREG;
10922 }
10923
10924 static void
10925 do_t_rrx (void)
10926 {
10927 unsigned Rd, Rm;
10928
10929 Rd = inst.operands[0].reg;
10930 Rm = inst.operands[1].reg;
10931
10932 reject_bad_reg (Rd);
10933 reject_bad_reg (Rm);
10934
10935 inst.instruction |= Rd << 8;
10936 inst.instruction |= Rm;
10937 }
10938
10939 static void
10940 do_t_rsb (void)
10941 {
10942 unsigned Rd, Rs;
10943
10944 Rd = inst.operands[0].reg;
10945 Rs = (inst.operands[1].present
10946 ? inst.operands[1].reg /* Rd, Rs, foo */
10947 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10948
10949 reject_bad_reg (Rd);
10950 reject_bad_reg (Rs);
10951 if (inst.operands[2].isreg)
10952 reject_bad_reg (inst.operands[2].reg);
10953
10954 inst.instruction |= Rd << 8;
10955 inst.instruction |= Rs << 16;
10956 if (!inst.operands[2].isreg)
10957 {
10958 bfd_boolean narrow;
10959
10960 if ((inst.instruction & 0x00100000) != 0)
10961 narrow = !in_it_block ();
10962 else
10963 narrow = in_it_block ();
10964
10965 if (Rd > 7 || Rs > 7)
10966 narrow = FALSE;
10967
10968 if (inst.size_req == 4 || !unified_syntax)
10969 narrow = FALSE;
10970
10971 if (inst.reloc.exp.X_op != O_constant
10972 || inst.reloc.exp.X_add_number != 0)
10973 narrow = FALSE;
10974
10975 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10976 relaxation, but it doesn't seem worth the hassle. */
10977 if (narrow)
10978 {
10979 inst.reloc.type = BFD_RELOC_UNUSED;
10980 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10981 inst.instruction |= Rs << 3;
10982 inst.instruction |= Rd;
10983 }
10984 else
10985 {
10986 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10987 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10988 }
10989 }
10990 else
10991 encode_thumb32_shifted_operand (2);
10992 }
10993
10994 static void
10995 do_t_setend (void)
10996 {
10997 set_it_insn_type (OUTSIDE_IT_INSN);
10998 if (inst.operands[0].imm)
10999 inst.instruction |= 0x8;
11000 }
11001
11002 static void
11003 do_t_shift (void)
11004 {
11005 if (!inst.operands[1].present)
11006 inst.operands[1].reg = inst.operands[0].reg;
11007
11008 if (unified_syntax)
11009 {
11010 bfd_boolean narrow;
11011 int shift_kind;
11012
11013 switch (inst.instruction)
11014 {
11015 case T_MNEM_asr:
11016 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11017 case T_MNEM_lsl:
11018 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11019 case T_MNEM_lsr:
11020 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11021 case T_MNEM_ror:
11022 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11023 default: abort ();
11024 }
11025
11026 if (THUMB_SETS_FLAGS (inst.instruction))
11027 narrow = !in_it_block ();
11028 else
11029 narrow = in_it_block ();
11030 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11031 narrow = FALSE;
11032 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11033 narrow = FALSE;
11034 if (inst.operands[2].isreg
11035 && (inst.operands[1].reg != inst.operands[0].reg
11036 || inst.operands[2].reg > 7))
11037 narrow = FALSE;
11038 if (inst.size_req == 4)
11039 narrow = FALSE;
11040
11041 reject_bad_reg (inst.operands[0].reg);
11042 reject_bad_reg (inst.operands[1].reg);
11043
11044 if (!narrow)
11045 {
11046 if (inst.operands[2].isreg)
11047 {
11048 reject_bad_reg (inst.operands[2].reg);
11049 inst.instruction = THUMB_OP32 (inst.instruction);
11050 inst.instruction |= inst.operands[0].reg << 8;
11051 inst.instruction |= inst.operands[1].reg << 16;
11052 inst.instruction |= inst.operands[2].reg;
11053 }
11054 else
11055 {
11056 inst.operands[1].shifted = 1;
11057 inst.operands[1].shift_kind = shift_kind;
11058 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11059 ? T_MNEM_movs : T_MNEM_mov);
11060 inst.instruction |= inst.operands[0].reg << 8;
11061 encode_thumb32_shifted_operand (1);
11062 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11063 inst.reloc.type = BFD_RELOC_UNUSED;
11064 }
11065 }
11066 else
11067 {
11068 if (inst.operands[2].isreg)
11069 {
11070 switch (shift_kind)
11071 {
11072 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11073 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11074 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11075 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11076 default: abort ();
11077 }
11078
11079 inst.instruction |= inst.operands[0].reg;
11080 inst.instruction |= inst.operands[2].reg << 3;
11081 }
11082 else
11083 {
11084 switch (shift_kind)
11085 {
11086 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11087 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11088 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11089 default: abort ();
11090 }
11091 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11092 inst.instruction |= inst.operands[0].reg;
11093 inst.instruction |= inst.operands[1].reg << 3;
11094 }
11095 }
11096 }
11097 else
11098 {
11099 constraint (inst.operands[0].reg > 7
11100 || inst.operands[1].reg > 7, BAD_HIREG);
11101 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11102
11103 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11104 {
11105 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11106 constraint (inst.operands[0].reg != inst.operands[1].reg,
11107 _("source1 and dest must be same register"));
11108
11109 switch (inst.instruction)
11110 {
11111 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11112 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11113 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11114 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11115 default: abort ();
11116 }
11117
11118 inst.instruction |= inst.operands[0].reg;
11119 inst.instruction |= inst.operands[2].reg << 3;
11120 }
11121 else
11122 {
11123 switch (inst.instruction)
11124 {
11125 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11126 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11127 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11128 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11129 default: abort ();
11130 }
11131 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11132 inst.instruction |= inst.operands[0].reg;
11133 inst.instruction |= inst.operands[1].reg << 3;
11134 }
11135 }
11136 }
11137
11138 static void
11139 do_t_simd (void)
11140 {
11141 unsigned Rd, Rn, Rm;
11142
11143 Rd = inst.operands[0].reg;
11144 Rn = inst.operands[1].reg;
11145 Rm = inst.operands[2].reg;
11146
11147 reject_bad_reg (Rd);
11148 reject_bad_reg (Rn);
11149 reject_bad_reg (Rm);
11150
11151 inst.instruction |= Rd << 8;
11152 inst.instruction |= Rn << 16;
11153 inst.instruction |= Rm;
11154 }
11155
11156 static void
11157 do_t_simd2 (void)
11158 {
11159 unsigned Rd, Rn, Rm;
11160
11161 Rd = inst.operands[0].reg;
11162 Rm = inst.operands[1].reg;
11163 Rn = inst.operands[2].reg;
11164
11165 reject_bad_reg (Rd);
11166 reject_bad_reg (Rn);
11167 reject_bad_reg (Rm);
11168
11169 inst.instruction |= Rd << 8;
11170 inst.instruction |= Rn << 16;
11171 inst.instruction |= Rm;
11172 }
11173
11174 static void
11175 do_t_smc (void)
11176 {
11177 unsigned int value = inst.reloc.exp.X_add_number;
11178 constraint (inst.reloc.exp.X_op != O_constant,
11179 _("expression too complex"));
11180 inst.reloc.type = BFD_RELOC_UNUSED;
11181 inst.instruction |= (value & 0xf000) >> 12;
11182 inst.instruction |= (value & 0x0ff0);
11183 inst.instruction |= (value & 0x000f) << 16;
11184 }
11185
11186 static void
11187 do_t_ssat_usat (int bias)
11188 {
11189 unsigned Rd, Rn;
11190
11191 Rd = inst.operands[0].reg;
11192 Rn = inst.operands[2].reg;
11193
11194 reject_bad_reg (Rd);
11195 reject_bad_reg (Rn);
11196
11197 inst.instruction |= Rd << 8;
11198 inst.instruction |= inst.operands[1].imm - bias;
11199 inst.instruction |= Rn << 16;
11200
11201 if (inst.operands[3].present)
11202 {
11203 offsetT shift_amount = inst.reloc.exp.X_add_number;
11204
11205 inst.reloc.type = BFD_RELOC_UNUSED;
11206
11207 constraint (inst.reloc.exp.X_op != O_constant,
11208 _("expression too complex"));
11209
11210 if (shift_amount != 0)
11211 {
11212 constraint (shift_amount > 31,
11213 _("shift expression is too large"));
11214
11215 if (inst.operands[3].shift_kind == SHIFT_ASR)
11216 inst.instruction |= 0x00200000; /* sh bit. */
11217
11218 inst.instruction |= (shift_amount & 0x1c) << 10;
11219 inst.instruction |= (shift_amount & 0x03) << 6;
11220 }
11221 }
11222 }
11223
11224 static void
11225 do_t_ssat (void)
11226 {
11227 do_t_ssat_usat (1);
11228 }
11229
11230 static void
11231 do_t_ssat16 (void)
11232 {
11233 unsigned Rd, Rn;
11234
11235 Rd = inst.operands[0].reg;
11236 Rn = inst.operands[2].reg;
11237
11238 reject_bad_reg (Rd);
11239 reject_bad_reg (Rn);
11240
11241 inst.instruction |= Rd << 8;
11242 inst.instruction |= inst.operands[1].imm - 1;
11243 inst.instruction |= Rn << 16;
11244 }
11245
11246 static void
11247 do_t_strex (void)
11248 {
11249 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11250 || inst.operands[2].postind || inst.operands[2].writeback
11251 || inst.operands[2].immisreg || inst.operands[2].shifted
11252 || inst.operands[2].negative,
11253 BAD_ADDR_MODE);
11254
11255 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11256
11257 inst.instruction |= inst.operands[0].reg << 8;
11258 inst.instruction |= inst.operands[1].reg << 12;
11259 inst.instruction |= inst.operands[2].reg << 16;
11260 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11261 }
11262
11263 static void
11264 do_t_strexd (void)
11265 {
11266 if (!inst.operands[2].present)
11267 inst.operands[2].reg = inst.operands[1].reg + 1;
11268
11269 constraint (inst.operands[0].reg == inst.operands[1].reg
11270 || inst.operands[0].reg == inst.operands[2].reg
11271 || inst.operands[0].reg == inst.operands[3].reg
11272 || inst.operands[1].reg == inst.operands[2].reg,
11273 BAD_OVERLAP);
11274
11275 inst.instruction |= inst.operands[0].reg;
11276 inst.instruction |= inst.operands[1].reg << 12;
11277 inst.instruction |= inst.operands[2].reg << 8;
11278 inst.instruction |= inst.operands[3].reg << 16;
11279 }
11280
11281 static void
11282 do_t_sxtah (void)
11283 {
11284 unsigned Rd, Rn, Rm;
11285
11286 Rd = inst.operands[0].reg;
11287 Rn = inst.operands[1].reg;
11288 Rm = inst.operands[2].reg;
11289
11290 reject_bad_reg (Rd);
11291 reject_bad_reg (Rn);
11292 reject_bad_reg (Rm);
11293
11294 inst.instruction |= Rd << 8;
11295 inst.instruction |= Rn << 16;
11296 inst.instruction |= Rm;
11297 inst.instruction |= inst.operands[3].imm << 4;
11298 }
11299
11300 static void
11301 do_t_sxth (void)
11302 {
11303 unsigned Rd, Rm;
11304
11305 Rd = inst.operands[0].reg;
11306 Rm = inst.operands[1].reg;
11307
11308 reject_bad_reg (Rd);
11309 reject_bad_reg (Rm);
11310
11311 if (inst.instruction <= 0xffff
11312 && inst.size_req != 4
11313 && Rd <= 7 && Rm <= 7
11314 && (!inst.operands[2].present || inst.operands[2].imm == 0))
11315 {
11316 inst.instruction = THUMB_OP16 (inst.instruction);
11317 inst.instruction |= Rd;
11318 inst.instruction |= Rm << 3;
11319 }
11320 else if (unified_syntax)
11321 {
11322 if (inst.instruction <= 0xffff)
11323 inst.instruction = THUMB_OP32 (inst.instruction);
11324 inst.instruction |= Rd << 8;
11325 inst.instruction |= Rm;
11326 inst.instruction |= inst.operands[2].imm << 4;
11327 }
11328 else
11329 {
11330 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11331 _("Thumb encoding does not support rotation"));
11332 constraint (1, BAD_HIREG);
11333 }
11334 }
11335
11336 static void
11337 do_t_swi (void)
11338 {
11339 inst.reloc.type = BFD_RELOC_ARM_SWI;
11340 }
11341
11342 static void
11343 do_t_tb (void)
11344 {
11345 unsigned Rn, Rm;
11346 int half;
11347
11348 half = (inst.instruction & 0x10) != 0;
11349 set_it_insn_type_last ();
11350 constraint (inst.operands[0].immisreg,
11351 _("instruction requires register index"));
11352
11353 Rn = inst.operands[0].reg;
11354 Rm = inst.operands[0].imm;
11355
11356 constraint (Rn == REG_SP, BAD_SP);
11357 reject_bad_reg (Rm);
11358
11359 constraint (!half && inst.operands[0].shifted,
11360 _("instruction does not allow shifted index"));
11361 inst.instruction |= (Rn << 16) | Rm;
11362 }
11363
11364 static void
11365 do_t_usat (void)
11366 {
11367 do_t_ssat_usat (0);
11368 }
11369
11370 static void
11371 do_t_usat16 (void)
11372 {
11373 unsigned Rd, Rn;
11374
11375 Rd = inst.operands[0].reg;
11376 Rn = inst.operands[2].reg;
11377
11378 reject_bad_reg (Rd);
11379 reject_bad_reg (Rn);
11380
11381 inst.instruction |= Rd << 8;
11382 inst.instruction |= inst.operands[1].imm;
11383 inst.instruction |= Rn << 16;
11384 }
11385
11386 /* Neon instruction encoder helpers. */
11387
11388 /* Encodings for the different types for various Neon opcodes. */
11389
11390 /* An "invalid" code for the following tables. */
11391 #define N_INV -1u
11392
11393 struct neon_tab_entry
11394 {
11395 unsigned integer;
11396 unsigned float_or_poly;
11397 unsigned scalar_or_imm;
11398 };
11399
11400 /* Map overloaded Neon opcodes to their respective encodings. */
11401 #define NEON_ENC_TAB \
11402 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11403 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11404 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11405 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11406 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11407 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11408 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11409 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11410 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11411 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11412 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11413 /* Register variants of the following two instructions are encoded as
11414 vcge / vcgt with the operands reversed. */ \
11415 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11416 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
11417 X(vfma, N_INV, 0x0000c10, N_INV), \
11418 X(vfms, N_INV, 0x0200c10, N_INV), \
11419 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11420 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11421 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11422 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11423 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11424 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11425 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11426 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11427 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11428 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11429 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11430 X(vshl, 0x0000400, N_INV, 0x0800510), \
11431 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11432 X(vand, 0x0000110, N_INV, 0x0800030), \
11433 X(vbic, 0x0100110, N_INV, 0x0800030), \
11434 X(veor, 0x1000110, N_INV, N_INV), \
11435 X(vorn, 0x0300110, N_INV, 0x0800010), \
11436 X(vorr, 0x0200110, N_INV, 0x0800010), \
11437 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11438 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11439 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11440 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11441 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11442 X(vst1, 0x0000000, 0x0800000, N_INV), \
11443 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11444 X(vst2, 0x0000100, 0x0800100, N_INV), \
11445 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11446 X(vst3, 0x0000200, 0x0800200, N_INV), \
11447 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11448 X(vst4, 0x0000300, 0x0800300, N_INV), \
11449 X(vmovn, 0x1b20200, N_INV, N_INV), \
11450 X(vtrn, 0x1b20080, N_INV, N_INV), \
11451 X(vqmovn, 0x1b20200, N_INV, N_INV), \
11452 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11453 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
11454 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11455 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
11456 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11457 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
11458 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11459 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11460 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11461 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
11462
11463 enum neon_opc
11464 {
11465 #define X(OPC,I,F,S) N_MNEM_##OPC
11466 NEON_ENC_TAB
11467 #undef X
11468 };
11469
11470 static const struct neon_tab_entry neon_enc_tab[] =
11471 {
11472 #define X(OPC,I,F,S) { (I), (F), (S) }
11473 NEON_ENC_TAB
11474 #undef X
11475 };
11476
11477 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
11478 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11479 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11480 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11481 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11482 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11483 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11484 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11485 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11486 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11487 #define NEON_ENC_SINGLE_(X) \
11488 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
11489 #define NEON_ENC_DOUBLE_(X) \
11490 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
11491
11492 #define NEON_ENCODE(type, inst) \
11493 do \
11494 { \
11495 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11496 inst.is_neon = 1; \
11497 } \
11498 while (0)
11499
11500 #define check_neon_suffixes \
11501 do \
11502 { \
11503 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11504 { \
11505 as_bad (_("invalid neon suffix for non neon instruction")); \
11506 return; \
11507 } \
11508 } \
11509 while (0)
11510
11511 /* Define shapes for instruction operands. The following mnemonic characters
11512 are used in this table:
11513
11514 F - VFP S<n> register
11515 D - Neon D<n> register
11516 Q - Neon Q<n> register
11517 I - Immediate
11518 S - Scalar
11519 R - ARM register
11520 L - D<n> register list
11521
11522 This table is used to generate various data:
11523 - enumerations of the form NS_DDR to be used as arguments to
11524 neon_select_shape.
11525 - a table classifying shapes into single, double, quad, mixed.
11526 - a table used to drive neon_select_shape. */
11527
11528 #define NEON_SHAPE_DEF \
11529 X(3, (D, D, D), DOUBLE), \
11530 X(3, (Q, Q, Q), QUAD), \
11531 X(3, (D, D, I), DOUBLE), \
11532 X(3, (Q, Q, I), QUAD), \
11533 X(3, (D, D, S), DOUBLE), \
11534 X(3, (Q, Q, S), QUAD), \
11535 X(2, (D, D), DOUBLE), \
11536 X(2, (Q, Q), QUAD), \
11537 X(2, (D, S), DOUBLE), \
11538 X(2, (Q, S), QUAD), \
11539 X(2, (D, R), DOUBLE), \
11540 X(2, (Q, R), QUAD), \
11541 X(2, (D, I), DOUBLE), \
11542 X(2, (Q, I), QUAD), \
11543 X(3, (D, L, D), DOUBLE), \
11544 X(2, (D, Q), MIXED), \
11545 X(2, (Q, D), MIXED), \
11546 X(3, (D, Q, I), MIXED), \
11547 X(3, (Q, D, I), MIXED), \
11548 X(3, (Q, D, D), MIXED), \
11549 X(3, (D, Q, Q), MIXED), \
11550 X(3, (Q, Q, D), MIXED), \
11551 X(3, (Q, D, S), MIXED), \
11552 X(3, (D, Q, S), MIXED), \
11553 X(4, (D, D, D, I), DOUBLE), \
11554 X(4, (Q, Q, Q, I), QUAD), \
11555 X(2, (F, F), SINGLE), \
11556 X(3, (F, F, F), SINGLE), \
11557 X(2, (F, I), SINGLE), \
11558 X(2, (F, D), MIXED), \
11559 X(2, (D, F), MIXED), \
11560 X(3, (F, F, I), MIXED), \
11561 X(4, (R, R, F, F), SINGLE), \
11562 X(4, (F, F, R, R), SINGLE), \
11563 X(3, (D, R, R), DOUBLE), \
11564 X(3, (R, R, D), DOUBLE), \
11565 X(2, (S, R), SINGLE), \
11566 X(2, (R, S), SINGLE), \
11567 X(2, (F, R), SINGLE), \
11568 X(2, (R, F), SINGLE)
11569
11570 #define S2(A,B) NS_##A##B
11571 #define S3(A,B,C) NS_##A##B##C
11572 #define S4(A,B,C,D) NS_##A##B##C##D
11573
11574 #define X(N, L, C) S##N L
11575
11576 enum neon_shape
11577 {
11578 NEON_SHAPE_DEF,
11579 NS_NULL
11580 };
11581
11582 #undef X
11583 #undef S2
11584 #undef S3
11585 #undef S4
11586
11587 enum neon_shape_class
11588 {
11589 SC_SINGLE,
11590 SC_DOUBLE,
11591 SC_QUAD,
11592 SC_MIXED
11593 };
11594
11595 #define X(N, L, C) SC_##C
11596
11597 static enum neon_shape_class neon_shape_class[] =
11598 {
11599 NEON_SHAPE_DEF
11600 };
11601
11602 #undef X
11603
11604 enum neon_shape_el
11605 {
11606 SE_F,
11607 SE_D,
11608 SE_Q,
11609 SE_I,
11610 SE_S,
11611 SE_R,
11612 SE_L
11613 };
11614
11615 /* Register widths of above. */
11616 static unsigned neon_shape_el_size[] =
11617 {
11618 32,
11619 64,
11620 128,
11621 0,
11622 32,
11623 32,
11624 0
11625 };
11626
11627 struct neon_shape_info
11628 {
11629 unsigned els;
11630 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11631 };
11632
11633 #define S2(A,B) { SE_##A, SE_##B }
11634 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11635 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11636
11637 #define X(N, L, C) { N, S##N L }
11638
11639 static struct neon_shape_info neon_shape_tab[] =
11640 {
11641 NEON_SHAPE_DEF
11642 };
11643
11644 #undef X
11645 #undef S2
11646 #undef S3
11647 #undef S4
11648
11649 /* Bit masks used in type checking given instructions.
11650 'N_EQK' means the type must be the same as (or based on in some way) the key
11651 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11652 set, various other bits can be set as well in order to modify the meaning of
11653 the type constraint. */
11654
11655 enum neon_type_mask
11656 {
11657 N_S8 = 0x0000001,
11658 N_S16 = 0x0000002,
11659 N_S32 = 0x0000004,
11660 N_S64 = 0x0000008,
11661 N_U8 = 0x0000010,
11662 N_U16 = 0x0000020,
11663 N_U32 = 0x0000040,
11664 N_U64 = 0x0000080,
11665 N_I8 = 0x0000100,
11666 N_I16 = 0x0000200,
11667 N_I32 = 0x0000400,
11668 N_I64 = 0x0000800,
11669 N_8 = 0x0001000,
11670 N_16 = 0x0002000,
11671 N_32 = 0x0004000,
11672 N_64 = 0x0008000,
11673 N_P8 = 0x0010000,
11674 N_P16 = 0x0020000,
11675 N_F16 = 0x0040000,
11676 N_F32 = 0x0080000,
11677 N_F64 = 0x0100000,
11678 N_KEY = 0x1000000, /* Key element (main type specifier). */
11679 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
11680 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11681 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11682 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11683 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11684 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11685 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11686 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11687 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
11688 N_UTYP = 0,
11689 N_MAX_NONSPECIAL = N_F64
11690 };
11691
11692 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11693
11694 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11695 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11696 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11697 #define N_SUF_32 (N_SU_32 | N_F32)
11698 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11699 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11700
11701 /* Pass this as the first type argument to neon_check_type to ignore types
11702 altogether. */
11703 #define N_IGNORE_TYPE (N_KEY | N_EQK)
11704
11705 /* Select a "shape" for the current instruction (describing register types or
11706 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11707 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11708 function of operand parsing, so this function doesn't need to be called.
11709 Shapes should be listed in order of decreasing length. */
11710
11711 static enum neon_shape
11712 neon_select_shape (enum neon_shape shape, ...)
11713 {
11714 va_list ap;
11715 enum neon_shape first_shape = shape;
11716
11717 /* Fix missing optional operands. FIXME: we don't know at this point how
11718 many arguments we should have, so this makes the assumption that we have
11719 > 1. This is true of all current Neon opcodes, I think, but may not be
11720 true in the future. */
11721 if (!inst.operands[1].present)
11722 inst.operands[1] = inst.operands[0];
11723
11724 va_start (ap, shape);
11725
11726 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
11727 {
11728 unsigned j;
11729 int matches = 1;
11730
11731 for (j = 0; j < neon_shape_tab[shape].els; j++)
11732 {
11733 if (!inst.operands[j].present)
11734 {
11735 matches = 0;
11736 break;
11737 }
11738
11739 switch (neon_shape_tab[shape].el[j])
11740 {
11741 case SE_F:
11742 if (!(inst.operands[j].isreg
11743 && inst.operands[j].isvec
11744 && inst.operands[j].issingle
11745 && !inst.operands[j].isquad))
11746 matches = 0;
11747 break;
11748
11749 case SE_D:
11750 if (!(inst.operands[j].isreg
11751 && inst.operands[j].isvec
11752 && !inst.operands[j].isquad
11753 && !inst.operands[j].issingle))
11754 matches = 0;
11755 break;
11756
11757 case SE_R:
11758 if (!(inst.operands[j].isreg
11759 && !inst.operands[j].isvec))
11760 matches = 0;
11761 break;
11762
11763 case SE_Q:
11764 if (!(inst.operands[j].isreg
11765 && inst.operands[j].isvec
11766 && inst.operands[j].isquad
11767 && !inst.operands[j].issingle))
11768 matches = 0;
11769 break;
11770
11771 case SE_I:
11772 if (!(!inst.operands[j].isreg
11773 && !inst.operands[j].isscalar))
11774 matches = 0;
11775 break;
11776
11777 case SE_S:
11778 if (!(!inst.operands[j].isreg
11779 && inst.operands[j].isscalar))
11780 matches = 0;
11781 break;
11782
11783 case SE_L:
11784 break;
11785 }
11786 }
11787 if (matches)
11788 break;
11789 }
11790
11791 va_end (ap);
11792
11793 if (shape == NS_NULL && first_shape != NS_NULL)
11794 first_error (_("invalid instruction shape"));
11795
11796 return shape;
11797 }
11798
11799 /* True if SHAPE is predominantly a quadword operation (most of the time, this
11800 means the Q bit should be set). */
11801
11802 static int
11803 neon_quad (enum neon_shape shape)
11804 {
11805 return neon_shape_class[shape] == SC_QUAD;
11806 }
11807
11808 static void
11809 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11810 unsigned *g_size)
11811 {
11812 /* Allow modification to be made to types which are constrained to be
11813 based on the key element, based on bits set alongside N_EQK. */
11814 if ((typebits & N_EQK) != 0)
11815 {
11816 if ((typebits & N_HLF) != 0)
11817 *g_size /= 2;
11818 else if ((typebits & N_DBL) != 0)
11819 *g_size *= 2;
11820 if ((typebits & N_SGN) != 0)
11821 *g_type = NT_signed;
11822 else if ((typebits & N_UNS) != 0)
11823 *g_type = NT_unsigned;
11824 else if ((typebits & N_INT) != 0)
11825 *g_type = NT_integer;
11826 else if ((typebits & N_FLT) != 0)
11827 *g_type = NT_float;
11828 else if ((typebits & N_SIZ) != 0)
11829 *g_type = NT_untyped;
11830 }
11831 }
11832
11833 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11834 operand type, i.e. the single type specified in a Neon instruction when it
11835 is the only one given. */
11836
11837 static struct neon_type_el
11838 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11839 {
11840 struct neon_type_el dest = *key;
11841
11842 gas_assert ((thisarg & N_EQK) != 0);
11843
11844 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11845
11846 return dest;
11847 }
11848
11849 /* Convert Neon type and size into compact bitmask representation. */
11850
11851 static enum neon_type_mask
11852 type_chk_of_el_type (enum neon_el_type type, unsigned size)
11853 {
11854 switch (type)
11855 {
11856 case NT_untyped:
11857 switch (size)
11858 {
11859 case 8: return N_8;
11860 case 16: return N_16;
11861 case 32: return N_32;
11862 case 64: return N_64;
11863 default: ;
11864 }
11865 break;
11866
11867 case NT_integer:
11868 switch (size)
11869 {
11870 case 8: return N_I8;
11871 case 16: return N_I16;
11872 case 32: return N_I32;
11873 case 64: return N_I64;
11874 default: ;
11875 }
11876 break;
11877
11878 case NT_float:
11879 switch (size)
11880 {
11881 case 16: return N_F16;
11882 case 32: return N_F32;
11883 case 64: return N_F64;
11884 default: ;
11885 }
11886 break;
11887
11888 case NT_poly:
11889 switch (size)
11890 {
11891 case 8: return N_P8;
11892 case 16: return N_P16;
11893 default: ;
11894 }
11895 break;
11896
11897 case NT_signed:
11898 switch (size)
11899 {
11900 case 8: return N_S8;
11901 case 16: return N_S16;
11902 case 32: return N_S32;
11903 case 64: return N_S64;
11904 default: ;
11905 }
11906 break;
11907
11908 case NT_unsigned:
11909 switch (size)
11910 {
11911 case 8: return N_U8;
11912 case 16: return N_U16;
11913 case 32: return N_U32;
11914 case 64: return N_U64;
11915 default: ;
11916 }
11917 break;
11918
11919 default: ;
11920 }
11921
11922 return N_UTYP;
11923 }
11924
11925 /* Convert compact Neon bitmask type representation to a type and size. Only
11926 handles the case where a single bit is set in the mask. */
11927
11928 static int
11929 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11930 enum neon_type_mask mask)
11931 {
11932 if ((mask & N_EQK) != 0)
11933 return FAIL;
11934
11935 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11936 *size = 8;
11937 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
11938 *size = 16;
11939 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
11940 *size = 32;
11941 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
11942 *size = 64;
11943 else
11944 return FAIL;
11945
11946 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11947 *type = NT_signed;
11948 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
11949 *type = NT_unsigned;
11950 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
11951 *type = NT_integer;
11952 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
11953 *type = NT_untyped;
11954 else if ((mask & (N_P8 | N_P16)) != 0)
11955 *type = NT_poly;
11956 else if ((mask & (N_F32 | N_F64)) != 0)
11957 *type = NT_float;
11958 else
11959 return FAIL;
11960
11961 return SUCCESS;
11962 }
11963
11964 /* Modify a bitmask of allowed types. This is only needed for type
11965 relaxation. */
11966
11967 static unsigned
11968 modify_types_allowed (unsigned allowed, unsigned mods)
11969 {
11970 unsigned size;
11971 enum neon_el_type type;
11972 unsigned destmask;
11973 int i;
11974
11975 destmask = 0;
11976
11977 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11978 {
11979 if (el_type_of_type_chk (&type, &size,
11980 (enum neon_type_mask) (allowed & i)) == SUCCESS)
11981 {
11982 neon_modify_type_size (mods, &type, &size);
11983 destmask |= type_chk_of_el_type (type, size);
11984 }
11985 }
11986
11987 return destmask;
11988 }
11989
11990 /* Check type and return type classification.
11991 The manual states (paraphrase): If one datatype is given, it indicates the
11992 type given in:
11993 - the second operand, if there is one
11994 - the operand, if there is no second operand
11995 - the result, if there are no operands.
11996 This isn't quite good enough though, so we use a concept of a "key" datatype
11997 which is set on a per-instruction basis, which is the one which matters when
11998 only one data type is written.
11999 Note: this function has side-effects (e.g. filling in missing operands). All
12000 Neon instructions should call it before performing bit encoding. */
12001
12002 static struct neon_type_el
12003 neon_check_type (unsigned els, enum neon_shape ns, ...)
12004 {
12005 va_list ap;
12006 unsigned i, pass, key_el = 0;
12007 unsigned types[NEON_MAX_TYPE_ELS];
12008 enum neon_el_type k_type = NT_invtype;
12009 unsigned k_size = -1u;
12010 struct neon_type_el badtype = {NT_invtype, -1};
12011 unsigned key_allowed = 0;
12012
12013 /* Optional registers in Neon instructions are always (not) in operand 1.
12014 Fill in the missing operand here, if it was omitted. */
12015 if (els > 1 && !inst.operands[1].present)
12016 inst.operands[1] = inst.operands[0];
12017
12018 /* Suck up all the varargs. */
12019 va_start (ap, ns);
12020 for (i = 0; i < els; i++)
12021 {
12022 unsigned thisarg = va_arg (ap, unsigned);
12023 if (thisarg == N_IGNORE_TYPE)
12024 {
12025 va_end (ap);
12026 return badtype;
12027 }
12028 types[i] = thisarg;
12029 if ((thisarg & N_KEY) != 0)
12030 key_el = i;
12031 }
12032 va_end (ap);
12033
12034 if (inst.vectype.elems > 0)
12035 for (i = 0; i < els; i++)
12036 if (inst.operands[i].vectype.type != NT_invtype)
12037 {
12038 first_error (_("types specified in both the mnemonic and operands"));
12039 return badtype;
12040 }
12041
12042 /* Duplicate inst.vectype elements here as necessary.
12043 FIXME: No idea if this is exactly the same as the ARM assembler,
12044 particularly when an insn takes one register and one non-register
12045 operand. */
12046 if (inst.vectype.elems == 1 && els > 1)
12047 {
12048 unsigned j;
12049 inst.vectype.elems = els;
12050 inst.vectype.el[key_el] = inst.vectype.el[0];
12051 for (j = 0; j < els; j++)
12052 if (j != key_el)
12053 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12054 types[j]);
12055 }
12056 else if (inst.vectype.elems == 0 && els > 0)
12057 {
12058 unsigned j;
12059 /* No types were given after the mnemonic, so look for types specified
12060 after each operand. We allow some flexibility here; as long as the
12061 "key" operand has a type, we can infer the others. */
12062 for (j = 0; j < els; j++)
12063 if (inst.operands[j].vectype.type != NT_invtype)
12064 inst.vectype.el[j] = inst.operands[j].vectype;
12065
12066 if (inst.operands[key_el].vectype.type != NT_invtype)
12067 {
12068 for (j = 0; j < els; j++)
12069 if (inst.operands[j].vectype.type == NT_invtype)
12070 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12071 types[j]);
12072 }
12073 else
12074 {
12075 first_error (_("operand types can't be inferred"));
12076 return badtype;
12077 }
12078 }
12079 else if (inst.vectype.elems != els)
12080 {
12081 first_error (_("type specifier has the wrong number of parts"));
12082 return badtype;
12083 }
12084
12085 for (pass = 0; pass < 2; pass++)
12086 {
12087 for (i = 0; i < els; i++)
12088 {
12089 unsigned thisarg = types[i];
12090 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12091 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12092 enum neon_el_type g_type = inst.vectype.el[i].type;
12093 unsigned g_size = inst.vectype.el[i].size;
12094
12095 /* Decay more-specific signed & unsigned types to sign-insensitive
12096 integer types if sign-specific variants are unavailable. */
12097 if ((g_type == NT_signed || g_type == NT_unsigned)
12098 && (types_allowed & N_SU_ALL) == 0)
12099 g_type = NT_integer;
12100
12101 /* If only untyped args are allowed, decay any more specific types to
12102 them. Some instructions only care about signs for some element
12103 sizes, so handle that properly. */
12104 if ((g_size == 8 && (types_allowed & N_8) != 0)
12105 || (g_size == 16 && (types_allowed & N_16) != 0)
12106 || (g_size == 32 && (types_allowed & N_32) != 0)
12107 || (g_size == 64 && (types_allowed & N_64) != 0))
12108 g_type = NT_untyped;
12109
12110 if (pass == 0)
12111 {
12112 if ((thisarg & N_KEY) != 0)
12113 {
12114 k_type = g_type;
12115 k_size = g_size;
12116 key_allowed = thisarg & ~N_KEY;
12117 }
12118 }
12119 else
12120 {
12121 if ((thisarg & N_VFP) != 0)
12122 {
12123 enum neon_shape_el regshape;
12124 unsigned regwidth, match;
12125
12126 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12127 if (ns == NS_NULL)
12128 {
12129 first_error (_("invalid instruction shape"));
12130 return badtype;
12131 }
12132 regshape = neon_shape_tab[ns].el[i];
12133 regwidth = neon_shape_el_size[regshape];
12134
12135 /* In VFP mode, operands must match register widths. If we
12136 have a key operand, use its width, else use the width of
12137 the current operand. */
12138 if (k_size != -1u)
12139 match = k_size;
12140 else
12141 match = g_size;
12142
12143 if (regwidth != match)
12144 {
12145 first_error (_("operand size must match register width"));
12146 return badtype;
12147 }
12148 }
12149
12150 if ((thisarg & N_EQK) == 0)
12151 {
12152 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12153
12154 if ((given_type & types_allowed) == 0)
12155 {
12156 first_error (_("bad type in Neon instruction"));
12157 return badtype;
12158 }
12159 }
12160 else
12161 {
12162 enum neon_el_type mod_k_type = k_type;
12163 unsigned mod_k_size = k_size;
12164 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12165 if (g_type != mod_k_type || g_size != mod_k_size)
12166 {
12167 first_error (_("inconsistent types in Neon instruction"));
12168 return badtype;
12169 }
12170 }
12171 }
12172 }
12173 }
12174
12175 return inst.vectype.el[key_el];
12176 }
12177
12178 /* Neon-style VFP instruction forwarding. */
12179
12180 /* Thumb VFP instructions have 0xE in the condition field. */
12181
12182 static void
12183 do_vfp_cond_or_thumb (void)
12184 {
12185 inst.is_neon = 1;
12186
12187 if (thumb_mode)
12188 inst.instruction |= 0xe0000000;
12189 else
12190 inst.instruction |= inst.cond << 28;
12191 }
12192
12193 /* Look up and encode a simple mnemonic, for use as a helper function for the
12194 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12195 etc. It is assumed that operand parsing has already been done, and that the
12196 operands are in the form expected by the given opcode (this isn't necessarily
12197 the same as the form in which they were parsed, hence some massaging must
12198 take place before this function is called).
12199 Checks current arch version against that in the looked-up opcode. */
12200
12201 static void
12202 do_vfp_nsyn_opcode (const char *opname)
12203 {
12204 const struct asm_opcode *opcode;
12205
12206 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
12207
12208 if (!opcode)
12209 abort ();
12210
12211 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12212 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12213 _(BAD_FPU));
12214
12215 inst.is_neon = 1;
12216
12217 if (thumb_mode)
12218 {
12219 inst.instruction = opcode->tvalue;
12220 opcode->tencode ();
12221 }
12222 else
12223 {
12224 inst.instruction = (inst.cond << 28) | opcode->avalue;
12225 opcode->aencode ();
12226 }
12227 }
12228
12229 static void
12230 do_vfp_nsyn_add_sub (enum neon_shape rs)
12231 {
12232 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12233
12234 if (rs == NS_FFF)
12235 {
12236 if (is_add)
12237 do_vfp_nsyn_opcode ("fadds");
12238 else
12239 do_vfp_nsyn_opcode ("fsubs");
12240 }
12241 else
12242 {
12243 if (is_add)
12244 do_vfp_nsyn_opcode ("faddd");
12245 else
12246 do_vfp_nsyn_opcode ("fsubd");
12247 }
12248 }
12249
12250 /* Check operand types to see if this is a VFP instruction, and if so call
12251 PFN (). */
12252
12253 static int
12254 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12255 {
12256 enum neon_shape rs;
12257 struct neon_type_el et;
12258
12259 switch (args)
12260 {
12261 case 2:
12262 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12263 et = neon_check_type (2, rs,
12264 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12265 break;
12266
12267 case 3:
12268 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12269 et = neon_check_type (3, rs,
12270 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12271 break;
12272
12273 default:
12274 abort ();
12275 }
12276
12277 if (et.type != NT_invtype)
12278 {
12279 pfn (rs);
12280 return SUCCESS;
12281 }
12282
12283 inst.error = NULL;
12284 return FAIL;
12285 }
12286
12287 static void
12288 do_vfp_nsyn_mla_mls (enum neon_shape rs)
12289 {
12290 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
12291
12292 if (rs == NS_FFF)
12293 {
12294 if (is_mla)
12295 do_vfp_nsyn_opcode ("fmacs");
12296 else
12297 do_vfp_nsyn_opcode ("fnmacs");
12298 }
12299 else
12300 {
12301 if (is_mla)
12302 do_vfp_nsyn_opcode ("fmacd");
12303 else
12304 do_vfp_nsyn_opcode ("fnmacd");
12305 }
12306 }
12307
12308 static void
12309 do_vfp_nsyn_fma_fms (enum neon_shape rs)
12310 {
12311 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12312
12313 if (rs == NS_FFF)
12314 {
12315 if (is_fma)
12316 do_vfp_nsyn_opcode ("ffmas");
12317 else
12318 do_vfp_nsyn_opcode ("ffnmas");
12319 }
12320 else
12321 {
12322 if (is_fma)
12323 do_vfp_nsyn_opcode ("ffmad");
12324 else
12325 do_vfp_nsyn_opcode ("ffnmad");
12326 }
12327 }
12328
12329 static void
12330 do_vfp_nsyn_mul (enum neon_shape rs)
12331 {
12332 if (rs == NS_FFF)
12333 do_vfp_nsyn_opcode ("fmuls");
12334 else
12335 do_vfp_nsyn_opcode ("fmuld");
12336 }
12337
12338 static void
12339 do_vfp_nsyn_abs_neg (enum neon_shape rs)
12340 {
12341 int is_neg = (inst.instruction & 0x80) != 0;
12342 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12343
12344 if (rs == NS_FF)
12345 {
12346 if (is_neg)
12347 do_vfp_nsyn_opcode ("fnegs");
12348 else
12349 do_vfp_nsyn_opcode ("fabss");
12350 }
12351 else
12352 {
12353 if (is_neg)
12354 do_vfp_nsyn_opcode ("fnegd");
12355 else
12356 do_vfp_nsyn_opcode ("fabsd");
12357 }
12358 }
12359
12360 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12361 insns belong to Neon, and are handled elsewhere. */
12362
12363 static void
12364 do_vfp_nsyn_ldm_stm (int is_dbmode)
12365 {
12366 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12367 if (is_ldm)
12368 {
12369 if (is_dbmode)
12370 do_vfp_nsyn_opcode ("fldmdbs");
12371 else
12372 do_vfp_nsyn_opcode ("fldmias");
12373 }
12374 else
12375 {
12376 if (is_dbmode)
12377 do_vfp_nsyn_opcode ("fstmdbs");
12378 else
12379 do_vfp_nsyn_opcode ("fstmias");
12380 }
12381 }
12382
12383 static void
12384 do_vfp_nsyn_sqrt (void)
12385 {
12386 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12387 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12388
12389 if (rs == NS_FF)
12390 do_vfp_nsyn_opcode ("fsqrts");
12391 else
12392 do_vfp_nsyn_opcode ("fsqrtd");
12393 }
12394
12395 static void
12396 do_vfp_nsyn_div (void)
12397 {
12398 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12399 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12400 N_F32 | N_F64 | N_KEY | N_VFP);
12401
12402 if (rs == NS_FFF)
12403 do_vfp_nsyn_opcode ("fdivs");
12404 else
12405 do_vfp_nsyn_opcode ("fdivd");
12406 }
12407
12408 static void
12409 do_vfp_nsyn_nmul (void)
12410 {
12411 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12412 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12413 N_F32 | N_F64 | N_KEY | N_VFP);
12414
12415 if (rs == NS_FFF)
12416 {
12417 NEON_ENCODE (SINGLE, inst);
12418 do_vfp_sp_dyadic ();
12419 }
12420 else
12421 {
12422 NEON_ENCODE (DOUBLE, inst);
12423 do_vfp_dp_rd_rn_rm ();
12424 }
12425 do_vfp_cond_or_thumb ();
12426 }
12427
12428 static void
12429 do_vfp_nsyn_cmp (void)
12430 {
12431 if (inst.operands[1].isreg)
12432 {
12433 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12434 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12435
12436 if (rs == NS_FF)
12437 {
12438 NEON_ENCODE (SINGLE, inst);
12439 do_vfp_sp_monadic ();
12440 }
12441 else
12442 {
12443 NEON_ENCODE (DOUBLE, inst);
12444 do_vfp_dp_rd_rm ();
12445 }
12446 }
12447 else
12448 {
12449 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12450 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12451
12452 switch (inst.instruction & 0x0fffffff)
12453 {
12454 case N_MNEM_vcmp:
12455 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12456 break;
12457 case N_MNEM_vcmpe:
12458 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12459 break;
12460 default:
12461 abort ();
12462 }
12463
12464 if (rs == NS_FI)
12465 {
12466 NEON_ENCODE (SINGLE, inst);
12467 do_vfp_sp_compare_z ();
12468 }
12469 else
12470 {
12471 NEON_ENCODE (DOUBLE, inst);
12472 do_vfp_dp_rd ();
12473 }
12474 }
12475 do_vfp_cond_or_thumb ();
12476 }
12477
12478 static void
12479 nsyn_insert_sp (void)
12480 {
12481 inst.operands[1] = inst.operands[0];
12482 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
12483 inst.operands[0].reg = REG_SP;
12484 inst.operands[0].isreg = 1;
12485 inst.operands[0].writeback = 1;
12486 inst.operands[0].present = 1;
12487 }
12488
12489 static void
12490 do_vfp_nsyn_push (void)
12491 {
12492 nsyn_insert_sp ();
12493 if (inst.operands[1].issingle)
12494 do_vfp_nsyn_opcode ("fstmdbs");
12495 else
12496 do_vfp_nsyn_opcode ("fstmdbd");
12497 }
12498
12499 static void
12500 do_vfp_nsyn_pop (void)
12501 {
12502 nsyn_insert_sp ();
12503 if (inst.operands[1].issingle)
12504 do_vfp_nsyn_opcode ("fldmias");
12505 else
12506 do_vfp_nsyn_opcode ("fldmiad");
12507 }
12508
12509 /* Fix up Neon data-processing instructions, ORing in the correct bits for
12510 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12511
12512 static void
12513 neon_dp_fixup (struct arm_it* insn)
12514 {
12515 unsigned int i = insn->instruction;
12516 insn->is_neon = 1;
12517
12518 if (thumb_mode)
12519 {
12520 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12521 if (i & (1 << 24))
12522 i |= 1 << 28;
12523
12524 i &= ~(1 << 24);
12525
12526 i |= 0xef000000;
12527 }
12528 else
12529 i |= 0xf2000000;
12530
12531 insn->instruction = i;
12532 }
12533
12534 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12535 (0, 1, 2, 3). */
12536
12537 static unsigned
12538 neon_logbits (unsigned x)
12539 {
12540 return ffs (x) - 4;
12541 }
12542
12543 #define LOW4(R) ((R) & 0xf)
12544 #define HI1(R) (((R) >> 4) & 1)
12545
12546 /* Encode insns with bit pattern:
12547
12548 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12549 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
12550
12551 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12552 different meaning for some instruction. */
12553
12554 static void
12555 neon_three_same (int isquad, int ubit, int size)
12556 {
12557 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12558 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12559 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12560 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12561 inst.instruction |= LOW4 (inst.operands[2].reg);
12562 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12563 inst.instruction |= (isquad != 0) << 6;
12564 inst.instruction |= (ubit != 0) << 24;
12565 if (size != -1)
12566 inst.instruction |= neon_logbits (size) << 20;
12567
12568 neon_dp_fixup (&inst);
12569 }
12570
12571 /* Encode instructions of the form:
12572
12573 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12574 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
12575
12576 Don't write size if SIZE == -1. */
12577
12578 static void
12579 neon_two_same (int qbit, int ubit, int size)
12580 {
12581 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12582 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12583 inst.instruction |= LOW4 (inst.operands[1].reg);
12584 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12585 inst.instruction |= (qbit != 0) << 6;
12586 inst.instruction |= (ubit != 0) << 24;
12587
12588 if (size != -1)
12589 inst.instruction |= neon_logbits (size) << 18;
12590
12591 neon_dp_fixup (&inst);
12592 }
12593
12594 /* Neon instruction encoders, in approximate order of appearance. */
12595
12596 static void
12597 do_neon_dyadic_i_su (void)
12598 {
12599 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12600 struct neon_type_el et = neon_check_type (3, rs,
12601 N_EQK, N_EQK, N_SU_32 | N_KEY);
12602 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12603 }
12604
12605 static void
12606 do_neon_dyadic_i64_su (void)
12607 {
12608 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12609 struct neon_type_el et = neon_check_type (3, rs,
12610 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12611 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12612 }
12613
12614 static void
12615 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12616 unsigned immbits)
12617 {
12618 unsigned size = et.size >> 3;
12619 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12620 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12621 inst.instruction |= LOW4 (inst.operands[1].reg);
12622 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12623 inst.instruction |= (isquad != 0) << 6;
12624 inst.instruction |= immbits << 16;
12625 inst.instruction |= (size >> 3) << 7;
12626 inst.instruction |= (size & 0x7) << 19;
12627 if (write_ubit)
12628 inst.instruction |= (uval != 0) << 24;
12629
12630 neon_dp_fixup (&inst);
12631 }
12632
12633 static void
12634 do_neon_shl_imm (void)
12635 {
12636 if (!inst.operands[2].isreg)
12637 {
12638 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12639 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12640 NEON_ENCODE (IMMED, inst);
12641 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
12642 }
12643 else
12644 {
12645 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12646 struct neon_type_el et = neon_check_type (3, rs,
12647 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12648 unsigned int tmp;
12649
12650 /* VSHL/VQSHL 3-register variants have syntax such as:
12651 vshl.xx Dd, Dm, Dn
12652 whereas other 3-register operations encoded by neon_three_same have
12653 syntax like:
12654 vadd.xx Dd, Dn, Dm
12655 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12656 here. */
12657 tmp = inst.operands[2].reg;
12658 inst.operands[2].reg = inst.operands[1].reg;
12659 inst.operands[1].reg = tmp;
12660 NEON_ENCODE (INTEGER, inst);
12661 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12662 }
12663 }
12664
12665 static void
12666 do_neon_qshl_imm (void)
12667 {
12668 if (!inst.operands[2].isreg)
12669 {
12670 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12671 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12672
12673 NEON_ENCODE (IMMED, inst);
12674 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12675 inst.operands[2].imm);
12676 }
12677 else
12678 {
12679 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12680 struct neon_type_el et = neon_check_type (3, rs,
12681 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12682 unsigned int tmp;
12683
12684 /* See note in do_neon_shl_imm. */
12685 tmp = inst.operands[2].reg;
12686 inst.operands[2].reg = inst.operands[1].reg;
12687 inst.operands[1].reg = tmp;
12688 NEON_ENCODE (INTEGER, inst);
12689 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12690 }
12691 }
12692
12693 static void
12694 do_neon_rshl (void)
12695 {
12696 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12697 struct neon_type_el et = neon_check_type (3, rs,
12698 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12699 unsigned int tmp;
12700
12701 tmp = inst.operands[2].reg;
12702 inst.operands[2].reg = inst.operands[1].reg;
12703 inst.operands[1].reg = tmp;
12704 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12705 }
12706
12707 static int
12708 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12709 {
12710 /* Handle .I8 pseudo-instructions. */
12711 if (size == 8)
12712 {
12713 /* Unfortunately, this will make everything apart from zero out-of-range.
12714 FIXME is this the intended semantics? There doesn't seem much point in
12715 accepting .I8 if so. */
12716 immediate |= immediate << 8;
12717 size = 16;
12718 }
12719
12720 if (size >= 32)
12721 {
12722 if (immediate == (immediate & 0x000000ff))
12723 {
12724 *immbits = immediate;
12725 return 0x1;
12726 }
12727 else if (immediate == (immediate & 0x0000ff00))
12728 {
12729 *immbits = immediate >> 8;
12730 return 0x3;
12731 }
12732 else if (immediate == (immediate & 0x00ff0000))
12733 {
12734 *immbits = immediate >> 16;
12735 return 0x5;
12736 }
12737 else if (immediate == (immediate & 0xff000000))
12738 {
12739 *immbits = immediate >> 24;
12740 return 0x7;
12741 }
12742 if ((immediate & 0xffff) != (immediate >> 16))
12743 goto bad_immediate;
12744 immediate &= 0xffff;
12745 }
12746
12747 if (immediate == (immediate & 0x000000ff))
12748 {
12749 *immbits = immediate;
12750 return 0x9;
12751 }
12752 else if (immediate == (immediate & 0x0000ff00))
12753 {
12754 *immbits = immediate >> 8;
12755 return 0xb;
12756 }
12757
12758 bad_immediate:
12759 first_error (_("immediate value out of range"));
12760 return FAIL;
12761 }
12762
12763 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12764 A, B, C, D. */
12765
12766 static int
12767 neon_bits_same_in_bytes (unsigned imm)
12768 {
12769 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12770 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12771 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12772 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12773 }
12774
12775 /* For immediate of above form, return 0bABCD. */
12776
12777 static unsigned
12778 neon_squash_bits (unsigned imm)
12779 {
12780 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12781 | ((imm & 0x01000000) >> 21);
12782 }
12783
12784 /* Compress quarter-float representation to 0b...000 abcdefgh. */
12785
12786 static unsigned
12787 neon_qfloat_bits (unsigned imm)
12788 {
12789 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
12790 }
12791
12792 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12793 the instruction. *OP is passed as the initial value of the op field, and
12794 may be set to a different value depending on the constant (i.e.
12795 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
12796 MVN). If the immediate looks like a repeated pattern then also
12797 try smaller element sizes. */
12798
12799 static int
12800 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12801 unsigned *immbits, int *op, int size,
12802 enum neon_el_type type)
12803 {
12804 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12805 float. */
12806 if (type == NT_float && !float_p)
12807 return FAIL;
12808
12809 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12810 {
12811 if (size != 32 || *op == 1)
12812 return FAIL;
12813 *immbits = neon_qfloat_bits (immlo);
12814 return 0xf;
12815 }
12816
12817 if (size == 64)
12818 {
12819 if (neon_bits_same_in_bytes (immhi)
12820 && neon_bits_same_in_bytes (immlo))
12821 {
12822 if (*op == 1)
12823 return FAIL;
12824 *immbits = (neon_squash_bits (immhi) << 4)
12825 | neon_squash_bits (immlo);
12826 *op = 1;
12827 return 0xe;
12828 }
12829
12830 if (immhi != immlo)
12831 return FAIL;
12832 }
12833
12834 if (size >= 32)
12835 {
12836 if (immlo == (immlo & 0x000000ff))
12837 {
12838 *immbits = immlo;
12839 return 0x0;
12840 }
12841 else if (immlo == (immlo & 0x0000ff00))
12842 {
12843 *immbits = immlo >> 8;
12844 return 0x2;
12845 }
12846 else if (immlo == (immlo & 0x00ff0000))
12847 {
12848 *immbits = immlo >> 16;
12849 return 0x4;
12850 }
12851 else if (immlo == (immlo & 0xff000000))
12852 {
12853 *immbits = immlo >> 24;
12854 return 0x6;
12855 }
12856 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12857 {
12858 *immbits = (immlo >> 8) & 0xff;
12859 return 0xc;
12860 }
12861 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12862 {
12863 *immbits = (immlo >> 16) & 0xff;
12864 return 0xd;
12865 }
12866
12867 if ((immlo & 0xffff) != (immlo >> 16))
12868 return FAIL;
12869 immlo &= 0xffff;
12870 }
12871
12872 if (size >= 16)
12873 {
12874 if (immlo == (immlo & 0x000000ff))
12875 {
12876 *immbits = immlo;
12877 return 0x8;
12878 }
12879 else if (immlo == (immlo & 0x0000ff00))
12880 {
12881 *immbits = immlo >> 8;
12882 return 0xa;
12883 }
12884
12885 if ((immlo & 0xff) != (immlo >> 8))
12886 return FAIL;
12887 immlo &= 0xff;
12888 }
12889
12890 if (immlo == (immlo & 0x000000ff))
12891 {
12892 /* Don't allow MVN with 8-bit immediate. */
12893 if (*op == 1)
12894 return FAIL;
12895 *immbits = immlo;
12896 return 0xe;
12897 }
12898
12899 return FAIL;
12900 }
12901
12902 /* Write immediate bits [7:0] to the following locations:
12903
12904 |28/24|23 19|18 16|15 4|3 0|
12905 | 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|
12906
12907 This function is used by VMOV/VMVN/VORR/VBIC. */
12908
12909 static void
12910 neon_write_immbits (unsigned immbits)
12911 {
12912 inst.instruction |= immbits & 0xf;
12913 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12914 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12915 }
12916
12917 /* Invert low-order SIZE bits of XHI:XLO. */
12918
12919 static void
12920 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12921 {
12922 unsigned immlo = xlo ? *xlo : 0;
12923 unsigned immhi = xhi ? *xhi : 0;
12924
12925 switch (size)
12926 {
12927 case 8:
12928 immlo = (~immlo) & 0xff;
12929 break;
12930
12931 case 16:
12932 immlo = (~immlo) & 0xffff;
12933 break;
12934
12935 case 64:
12936 immhi = (~immhi) & 0xffffffff;
12937 /* fall through. */
12938
12939 case 32:
12940 immlo = (~immlo) & 0xffffffff;
12941 break;
12942
12943 default:
12944 abort ();
12945 }
12946
12947 if (xlo)
12948 *xlo = immlo;
12949
12950 if (xhi)
12951 *xhi = immhi;
12952 }
12953
12954 static void
12955 do_neon_logic (void)
12956 {
12957 if (inst.operands[2].present && inst.operands[2].isreg)
12958 {
12959 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12960 neon_check_type (3, rs, N_IGNORE_TYPE);
12961 /* U bit and size field were set as part of the bitmask. */
12962 NEON_ENCODE (INTEGER, inst);
12963 neon_three_same (neon_quad (rs), 0, -1);
12964 }
12965 else
12966 {
12967 const int three_ops_form = (inst.operands[2].present
12968 && !inst.operands[2].isreg);
12969 const int immoperand = (three_ops_form ? 2 : 1);
12970 enum neon_shape rs = (three_ops_form
12971 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
12972 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
12973 struct neon_type_el et = neon_check_type (2, rs,
12974 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12975 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
12976 unsigned immbits;
12977 int cmode;
12978
12979 if (et.type == NT_invtype)
12980 return;
12981
12982 if (three_ops_form)
12983 constraint (inst.operands[0].reg != inst.operands[1].reg,
12984 _("first and second operands shall be the same register"));
12985
12986 NEON_ENCODE (IMMED, inst);
12987
12988 immbits = inst.operands[immoperand].imm;
12989 if (et.size == 64)
12990 {
12991 /* .i64 is a pseudo-op, so the immediate must be a repeating
12992 pattern. */
12993 if (immbits != (inst.operands[immoperand].regisimm ?
12994 inst.operands[immoperand].reg : 0))
12995 {
12996 /* Set immbits to an invalid constant. */
12997 immbits = 0xdeadbeef;
12998 }
12999 }
13000
13001 switch (opcode)
13002 {
13003 case N_MNEM_vbic:
13004 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13005 break;
13006
13007 case N_MNEM_vorr:
13008 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13009 break;
13010
13011 case N_MNEM_vand:
13012 /* Pseudo-instruction for VBIC. */
13013 neon_invert_size (&immbits, 0, et.size);
13014 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13015 break;
13016
13017 case N_MNEM_vorn:
13018 /* Pseudo-instruction for VORR. */
13019 neon_invert_size (&immbits, 0, et.size);
13020 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13021 break;
13022
13023 default:
13024 abort ();
13025 }
13026
13027 if (cmode == FAIL)
13028 return;
13029
13030 inst.instruction |= neon_quad (rs) << 6;
13031 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13032 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13033 inst.instruction |= cmode << 8;
13034 neon_write_immbits (immbits);
13035
13036 neon_dp_fixup (&inst);
13037 }
13038 }
13039
13040 static void
13041 do_neon_bitfield (void)
13042 {
13043 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13044 neon_check_type (3, rs, N_IGNORE_TYPE);
13045 neon_three_same (neon_quad (rs), 0, -1);
13046 }
13047
13048 static void
13049 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13050 unsigned destbits)
13051 {
13052 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13053 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13054 types | N_KEY);
13055 if (et.type == NT_float)
13056 {
13057 NEON_ENCODE (FLOAT, inst);
13058 neon_three_same (neon_quad (rs), 0, -1);
13059 }
13060 else
13061 {
13062 NEON_ENCODE (INTEGER, inst);
13063 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13064 }
13065 }
13066
13067 static void
13068 do_neon_dyadic_if_su (void)
13069 {
13070 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13071 }
13072
13073 static void
13074 do_neon_dyadic_if_su_d (void)
13075 {
13076 /* This version only allow D registers, but that constraint is enforced during
13077 operand parsing so we don't need to do anything extra here. */
13078 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13079 }
13080
13081 static void
13082 do_neon_dyadic_if_i_d (void)
13083 {
13084 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13085 affected if we specify unsigned args. */
13086 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13087 }
13088
13089 enum vfp_or_neon_is_neon_bits
13090 {
13091 NEON_CHECK_CC = 1,
13092 NEON_CHECK_ARCH = 2
13093 };
13094
13095 /* Call this function if an instruction which may have belonged to the VFP or
13096 Neon instruction sets, but turned out to be a Neon instruction (due to the
13097 operand types involved, etc.). We have to check and/or fix-up a couple of
13098 things:
13099
13100 - Make sure the user hasn't attempted to make a Neon instruction
13101 conditional.
13102 - Alter the value in the condition code field if necessary.
13103 - Make sure that the arch supports Neon instructions.
13104
13105 Which of these operations take place depends on bits from enum
13106 vfp_or_neon_is_neon_bits.
13107
13108 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13109 current instruction's condition is COND_ALWAYS, the condition field is
13110 changed to inst.uncond_value. This is necessary because instructions shared
13111 between VFP and Neon may be conditional for the VFP variants only, and the
13112 unconditional Neon version must have, e.g., 0xF in the condition field. */
13113
13114 static int
13115 vfp_or_neon_is_neon (unsigned check)
13116 {
13117 /* Conditions are always legal in Thumb mode (IT blocks). */
13118 if (!thumb_mode && (check & NEON_CHECK_CC))
13119 {
13120 if (inst.cond != COND_ALWAYS)
13121 {
13122 first_error (_(BAD_COND));
13123 return FAIL;
13124 }
13125 if (inst.uncond_value != -1)
13126 inst.instruction |= inst.uncond_value << 28;
13127 }
13128
13129 if ((check & NEON_CHECK_ARCH)
13130 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13131 {
13132 first_error (_(BAD_FPU));
13133 return FAIL;
13134 }
13135
13136 return SUCCESS;
13137 }
13138
13139 static void
13140 do_neon_addsub_if_i (void)
13141 {
13142 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13143 return;
13144
13145 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13146 return;
13147
13148 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13149 affected if we specify unsigned args. */
13150 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
13151 }
13152
13153 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13154 result to be:
13155 V<op> A,B (A is operand 0, B is operand 2)
13156 to mean:
13157 V<op> A,B,A
13158 not:
13159 V<op> A,B,B
13160 so handle that case specially. */
13161
13162 static void
13163 neon_exchange_operands (void)
13164 {
13165 void *scratch = alloca (sizeof (inst.operands[0]));
13166 if (inst.operands[1].present)
13167 {
13168 /* Swap operands[1] and operands[2]. */
13169 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13170 inst.operands[1] = inst.operands[2];
13171 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13172 }
13173 else
13174 {
13175 inst.operands[1] = inst.operands[2];
13176 inst.operands[2] = inst.operands[0];
13177 }
13178 }
13179
13180 static void
13181 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13182 {
13183 if (inst.operands[2].isreg)
13184 {
13185 if (invert)
13186 neon_exchange_operands ();
13187 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
13188 }
13189 else
13190 {
13191 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13192 struct neon_type_el et = neon_check_type (2, rs,
13193 N_EQK | N_SIZ, immtypes | N_KEY);
13194
13195 NEON_ENCODE (IMMED, inst);
13196 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13197 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13198 inst.instruction |= LOW4 (inst.operands[1].reg);
13199 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13200 inst.instruction |= neon_quad (rs) << 6;
13201 inst.instruction |= (et.type == NT_float) << 10;
13202 inst.instruction |= neon_logbits (et.size) << 18;
13203
13204 neon_dp_fixup (&inst);
13205 }
13206 }
13207
13208 static void
13209 do_neon_cmp (void)
13210 {
13211 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13212 }
13213
13214 static void
13215 do_neon_cmp_inv (void)
13216 {
13217 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13218 }
13219
13220 static void
13221 do_neon_ceq (void)
13222 {
13223 neon_compare (N_IF_32, N_IF_32, FALSE);
13224 }
13225
13226 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
13227 scalars, which are encoded in 5 bits, M : Rm.
13228 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13229 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13230 index in M. */
13231
13232 static unsigned
13233 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13234 {
13235 unsigned regno = NEON_SCALAR_REG (scalar);
13236 unsigned elno = NEON_SCALAR_INDEX (scalar);
13237
13238 switch (elsize)
13239 {
13240 case 16:
13241 if (regno > 7 || elno > 3)
13242 goto bad_scalar;
13243 return regno | (elno << 3);
13244
13245 case 32:
13246 if (regno > 15 || elno > 1)
13247 goto bad_scalar;
13248 return regno | (elno << 4);
13249
13250 default:
13251 bad_scalar:
13252 first_error (_("scalar out of range for multiply instruction"));
13253 }
13254
13255 return 0;
13256 }
13257
13258 /* Encode multiply / multiply-accumulate scalar instructions. */
13259
13260 static void
13261 neon_mul_mac (struct neon_type_el et, int ubit)
13262 {
13263 unsigned scalar;
13264
13265 /* Give a more helpful error message if we have an invalid type. */
13266 if (et.type == NT_invtype)
13267 return;
13268
13269 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
13270 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13271 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13272 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13273 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13274 inst.instruction |= LOW4 (scalar);
13275 inst.instruction |= HI1 (scalar) << 5;
13276 inst.instruction |= (et.type == NT_float) << 8;
13277 inst.instruction |= neon_logbits (et.size) << 20;
13278 inst.instruction |= (ubit != 0) << 24;
13279
13280 neon_dp_fixup (&inst);
13281 }
13282
13283 static void
13284 do_neon_mac_maybe_scalar (void)
13285 {
13286 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13287 return;
13288
13289 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13290 return;
13291
13292 if (inst.operands[2].isscalar)
13293 {
13294 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13295 struct neon_type_el et = neon_check_type (3, rs,
13296 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
13297 NEON_ENCODE (SCALAR, inst);
13298 neon_mul_mac (et, neon_quad (rs));
13299 }
13300 else
13301 {
13302 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13303 affected if we specify unsigned args. */
13304 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13305 }
13306 }
13307
13308 static void
13309 do_neon_fmac (void)
13310 {
13311 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13312 return;
13313
13314 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13315 return;
13316
13317 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13318 }
13319
13320 static void
13321 do_neon_tst (void)
13322 {
13323 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13324 struct neon_type_el et = neon_check_type (3, rs,
13325 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
13326 neon_three_same (neon_quad (rs), 0, et.size);
13327 }
13328
13329 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
13330 same types as the MAC equivalents. The polynomial type for this instruction
13331 is encoded the same as the integer type. */
13332
13333 static void
13334 do_neon_mul (void)
13335 {
13336 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13337 return;
13338
13339 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13340 return;
13341
13342 if (inst.operands[2].isscalar)
13343 do_neon_mac_maybe_scalar ();
13344 else
13345 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
13346 }
13347
13348 static void
13349 do_neon_qdmulh (void)
13350 {
13351 if (inst.operands[2].isscalar)
13352 {
13353 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13354 struct neon_type_el et = neon_check_type (3, rs,
13355 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13356 NEON_ENCODE (SCALAR, inst);
13357 neon_mul_mac (et, neon_quad (rs));
13358 }
13359 else
13360 {
13361 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13362 struct neon_type_el et = neon_check_type (3, rs,
13363 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13364 NEON_ENCODE (INTEGER, inst);
13365 /* The U bit (rounding) comes from bit mask. */
13366 neon_three_same (neon_quad (rs), 0, et.size);
13367 }
13368 }
13369
13370 static void
13371 do_neon_fcmp_absolute (void)
13372 {
13373 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13374 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13375 /* Size field comes from bit mask. */
13376 neon_three_same (neon_quad (rs), 1, -1);
13377 }
13378
13379 static void
13380 do_neon_fcmp_absolute_inv (void)
13381 {
13382 neon_exchange_operands ();
13383 do_neon_fcmp_absolute ();
13384 }
13385
13386 static void
13387 do_neon_step (void)
13388 {
13389 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13390 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13391 neon_three_same (neon_quad (rs), 0, -1);
13392 }
13393
13394 static void
13395 do_neon_abs_neg (void)
13396 {
13397 enum neon_shape rs;
13398 struct neon_type_el et;
13399
13400 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13401 return;
13402
13403 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13404 return;
13405
13406 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13407 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
13408
13409 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13410 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13411 inst.instruction |= LOW4 (inst.operands[1].reg);
13412 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13413 inst.instruction |= neon_quad (rs) << 6;
13414 inst.instruction |= (et.type == NT_float) << 10;
13415 inst.instruction |= neon_logbits (et.size) << 18;
13416
13417 neon_dp_fixup (&inst);
13418 }
13419
13420 static void
13421 do_neon_sli (void)
13422 {
13423 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13424 struct neon_type_el et = neon_check_type (2, rs,
13425 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13426 int imm = inst.operands[2].imm;
13427 constraint (imm < 0 || (unsigned)imm >= et.size,
13428 _("immediate out of range for insert"));
13429 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13430 }
13431
13432 static void
13433 do_neon_sri (void)
13434 {
13435 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13436 struct neon_type_el et = neon_check_type (2, rs,
13437 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13438 int imm = inst.operands[2].imm;
13439 constraint (imm < 1 || (unsigned)imm > et.size,
13440 _("immediate out of range for insert"));
13441 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
13442 }
13443
13444 static void
13445 do_neon_qshlu_imm (void)
13446 {
13447 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13448 struct neon_type_el et = neon_check_type (2, rs,
13449 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13450 int imm = inst.operands[2].imm;
13451 constraint (imm < 0 || (unsigned)imm >= et.size,
13452 _("immediate out of range for shift"));
13453 /* Only encodes the 'U present' variant of the instruction.
13454 In this case, signed types have OP (bit 8) set to 0.
13455 Unsigned types have OP set to 1. */
13456 inst.instruction |= (et.type == NT_unsigned) << 8;
13457 /* The rest of the bits are the same as other immediate shifts. */
13458 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13459 }
13460
13461 static void
13462 do_neon_qmovn (void)
13463 {
13464 struct neon_type_el et = neon_check_type (2, NS_DQ,
13465 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13466 /* Saturating move where operands can be signed or unsigned, and the
13467 destination has the same signedness. */
13468 NEON_ENCODE (INTEGER, inst);
13469 if (et.type == NT_unsigned)
13470 inst.instruction |= 0xc0;
13471 else
13472 inst.instruction |= 0x80;
13473 neon_two_same (0, 1, et.size / 2);
13474 }
13475
13476 static void
13477 do_neon_qmovun (void)
13478 {
13479 struct neon_type_el et = neon_check_type (2, NS_DQ,
13480 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13481 /* Saturating move with unsigned results. Operands must be signed. */
13482 NEON_ENCODE (INTEGER, inst);
13483 neon_two_same (0, 1, et.size / 2);
13484 }
13485
13486 static void
13487 do_neon_rshift_sat_narrow (void)
13488 {
13489 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13490 or unsigned. If operands are unsigned, results must also be unsigned. */
13491 struct neon_type_el et = neon_check_type (2, NS_DQI,
13492 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13493 int imm = inst.operands[2].imm;
13494 /* This gets the bounds check, size encoding and immediate bits calculation
13495 right. */
13496 et.size /= 2;
13497
13498 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13499 VQMOVN.I<size> <Dd>, <Qm>. */
13500 if (imm == 0)
13501 {
13502 inst.operands[2].present = 0;
13503 inst.instruction = N_MNEM_vqmovn;
13504 do_neon_qmovn ();
13505 return;
13506 }
13507
13508 constraint (imm < 1 || (unsigned)imm > et.size,
13509 _("immediate out of range"));
13510 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13511 }
13512
13513 static void
13514 do_neon_rshift_sat_narrow_u (void)
13515 {
13516 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13517 or unsigned. If operands are unsigned, results must also be unsigned. */
13518 struct neon_type_el et = neon_check_type (2, NS_DQI,
13519 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13520 int imm = inst.operands[2].imm;
13521 /* This gets the bounds check, size encoding and immediate bits calculation
13522 right. */
13523 et.size /= 2;
13524
13525 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13526 VQMOVUN.I<size> <Dd>, <Qm>. */
13527 if (imm == 0)
13528 {
13529 inst.operands[2].present = 0;
13530 inst.instruction = N_MNEM_vqmovun;
13531 do_neon_qmovun ();
13532 return;
13533 }
13534
13535 constraint (imm < 1 || (unsigned)imm > et.size,
13536 _("immediate out of range"));
13537 /* FIXME: The manual is kind of unclear about what value U should have in
13538 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13539 must be 1. */
13540 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13541 }
13542
13543 static void
13544 do_neon_movn (void)
13545 {
13546 struct neon_type_el et = neon_check_type (2, NS_DQ,
13547 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13548 NEON_ENCODE (INTEGER, inst);
13549 neon_two_same (0, 1, et.size / 2);
13550 }
13551
13552 static void
13553 do_neon_rshift_narrow (void)
13554 {
13555 struct neon_type_el et = neon_check_type (2, NS_DQI,
13556 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13557 int imm = inst.operands[2].imm;
13558 /* This gets the bounds check, size encoding and immediate bits calculation
13559 right. */
13560 et.size /= 2;
13561
13562 /* If immediate is zero then we are a pseudo-instruction for
13563 VMOVN.I<size> <Dd>, <Qm> */
13564 if (imm == 0)
13565 {
13566 inst.operands[2].present = 0;
13567 inst.instruction = N_MNEM_vmovn;
13568 do_neon_movn ();
13569 return;
13570 }
13571
13572 constraint (imm < 1 || (unsigned)imm > et.size,
13573 _("immediate out of range for narrowing operation"));
13574 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13575 }
13576
13577 static void
13578 do_neon_shll (void)
13579 {
13580 /* FIXME: Type checking when lengthening. */
13581 struct neon_type_el et = neon_check_type (2, NS_QDI,
13582 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13583 unsigned imm = inst.operands[2].imm;
13584
13585 if (imm == et.size)
13586 {
13587 /* Maximum shift variant. */
13588 NEON_ENCODE (INTEGER, inst);
13589 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13590 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13591 inst.instruction |= LOW4 (inst.operands[1].reg);
13592 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13593 inst.instruction |= neon_logbits (et.size) << 18;
13594
13595 neon_dp_fixup (&inst);
13596 }
13597 else
13598 {
13599 /* A more-specific type check for non-max versions. */
13600 et = neon_check_type (2, NS_QDI,
13601 N_EQK | N_DBL, N_SU_32 | N_KEY);
13602 NEON_ENCODE (IMMED, inst);
13603 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13604 }
13605 }
13606
13607 /* Check the various types for the VCVT instruction, and return which version
13608 the current instruction is. */
13609
13610 static int
13611 neon_cvt_flavour (enum neon_shape rs)
13612 {
13613 #define CVT_VAR(C,X,Y) \
13614 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13615 if (et.type != NT_invtype) \
13616 { \
13617 inst.error = NULL; \
13618 return (C); \
13619 }
13620 struct neon_type_el et;
13621 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13622 || rs == NS_FF) ? N_VFP : 0;
13623 /* The instruction versions which take an immediate take one register
13624 argument, which is extended to the width of the full register. Thus the
13625 "source" and "destination" registers must have the same width. Hack that
13626 here by making the size equal to the key (wider, in this case) operand. */
13627 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
13628
13629 CVT_VAR (0, N_S32, N_F32);
13630 CVT_VAR (1, N_U32, N_F32);
13631 CVT_VAR (2, N_F32, N_S32);
13632 CVT_VAR (3, N_F32, N_U32);
13633 /* Half-precision conversions. */
13634 CVT_VAR (4, N_F32, N_F16);
13635 CVT_VAR (5, N_F16, N_F32);
13636
13637 whole_reg = N_VFP;
13638
13639 /* VFP instructions. */
13640 CVT_VAR (6, N_F32, N_F64);
13641 CVT_VAR (7, N_F64, N_F32);
13642 CVT_VAR (8, N_S32, N_F64 | key);
13643 CVT_VAR (9, N_U32, N_F64 | key);
13644 CVT_VAR (10, N_F64 | key, N_S32);
13645 CVT_VAR (11, N_F64 | key, N_U32);
13646 /* VFP instructions with bitshift. */
13647 CVT_VAR (12, N_F32 | key, N_S16);
13648 CVT_VAR (13, N_F32 | key, N_U16);
13649 CVT_VAR (14, N_F64 | key, N_S16);
13650 CVT_VAR (15, N_F64 | key, N_U16);
13651 CVT_VAR (16, N_S16, N_F32 | key);
13652 CVT_VAR (17, N_U16, N_F32 | key);
13653 CVT_VAR (18, N_S16, N_F64 | key);
13654 CVT_VAR (19, N_U16, N_F64 | key);
13655
13656 return -1;
13657 #undef CVT_VAR
13658 }
13659
13660 /* Neon-syntax VFP conversions. */
13661
13662 static void
13663 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
13664 {
13665 const char *opname = 0;
13666
13667 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
13668 {
13669 /* Conversions with immediate bitshift. */
13670 const char *enc[] =
13671 {
13672 "ftosls",
13673 "ftouls",
13674 "fsltos",
13675 "fultos",
13676 NULL,
13677 NULL,
13678 NULL,
13679 NULL,
13680 "ftosld",
13681 "ftould",
13682 "fsltod",
13683 "fultod",
13684 "fshtos",
13685 "fuhtos",
13686 "fshtod",
13687 "fuhtod",
13688 "ftoshs",
13689 "ftouhs",
13690 "ftoshd",
13691 "ftouhd"
13692 };
13693
13694 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13695 {
13696 opname = enc[flavour];
13697 constraint (inst.operands[0].reg != inst.operands[1].reg,
13698 _("operands 0 and 1 must be the same register"));
13699 inst.operands[1] = inst.operands[2];
13700 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13701 }
13702 }
13703 else
13704 {
13705 /* Conversions without bitshift. */
13706 const char *enc[] =
13707 {
13708 "ftosis",
13709 "ftouis",
13710 "fsitos",
13711 "fuitos",
13712 "NULL",
13713 "NULL",
13714 "fcvtsd",
13715 "fcvtds",
13716 "ftosid",
13717 "ftouid",
13718 "fsitod",
13719 "fuitod"
13720 };
13721
13722 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13723 opname = enc[flavour];
13724 }
13725
13726 if (opname)
13727 do_vfp_nsyn_opcode (opname);
13728 }
13729
13730 static void
13731 do_vfp_nsyn_cvtz (void)
13732 {
13733 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13734 int flavour = neon_cvt_flavour (rs);
13735 const char *enc[] =
13736 {
13737 "ftosizs",
13738 "ftouizs",
13739 NULL,
13740 NULL,
13741 NULL,
13742 NULL,
13743 NULL,
13744 NULL,
13745 "ftosizd",
13746 "ftouizd"
13747 };
13748
13749 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13750 do_vfp_nsyn_opcode (enc[flavour]);
13751 }
13752
13753 static void
13754 do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
13755 {
13756 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
13757 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
13758 int flavour = neon_cvt_flavour (rs);
13759
13760 /* PR11109: Handle round-to-zero for VCVT conversions. */
13761 if (round_to_zero
13762 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
13763 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
13764 && (rs == NS_FD || rs == NS_FF))
13765 {
13766 do_vfp_nsyn_cvtz ();
13767 return;
13768 }
13769
13770 /* VFP rather than Neon conversions. */
13771 if (flavour >= 6)
13772 {
13773 do_vfp_nsyn_cvt (rs, flavour);
13774 return;
13775 }
13776
13777 switch (rs)
13778 {
13779 case NS_DDI:
13780 case NS_QQI:
13781 {
13782 unsigned immbits;
13783 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13784
13785 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13786 return;
13787
13788 /* Fixed-point conversion with #0 immediate is encoded as an
13789 integer conversion. */
13790 if (inst.operands[2].present && inst.operands[2].imm == 0)
13791 goto int_encode;
13792 immbits = 32 - inst.operands[2].imm;
13793 NEON_ENCODE (IMMED, inst);
13794 if (flavour != -1)
13795 inst.instruction |= enctab[flavour];
13796 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13797 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13798 inst.instruction |= LOW4 (inst.operands[1].reg);
13799 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13800 inst.instruction |= neon_quad (rs) << 6;
13801 inst.instruction |= 1 << 21;
13802 inst.instruction |= immbits << 16;
13803
13804 neon_dp_fixup (&inst);
13805 }
13806 break;
13807
13808 case NS_DD:
13809 case NS_QQ:
13810 int_encode:
13811 {
13812 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13813
13814 NEON_ENCODE (INTEGER, inst);
13815
13816 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13817 return;
13818
13819 if (flavour != -1)
13820 inst.instruction |= enctab[flavour];
13821
13822 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13823 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13824 inst.instruction |= LOW4 (inst.operands[1].reg);
13825 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13826 inst.instruction |= neon_quad (rs) << 6;
13827 inst.instruction |= 2 << 18;
13828
13829 neon_dp_fixup (&inst);
13830 }
13831 break;
13832
13833 /* Half-precision conversions for Advanced SIMD -- neon. */
13834 case NS_QD:
13835 case NS_DQ:
13836
13837 if ((rs == NS_DQ)
13838 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13839 {
13840 as_bad (_("operand size must match register width"));
13841 break;
13842 }
13843
13844 if ((rs == NS_QD)
13845 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13846 {
13847 as_bad (_("operand size must match register width"));
13848 break;
13849 }
13850
13851 if (rs == NS_DQ)
13852 inst.instruction = 0x3b60600;
13853 else
13854 inst.instruction = 0x3b60700;
13855
13856 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13857 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13858 inst.instruction |= LOW4 (inst.operands[1].reg);
13859 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13860 neon_dp_fixup (&inst);
13861 break;
13862
13863 default:
13864 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13865 do_vfp_nsyn_cvt (rs, flavour);
13866 }
13867 }
13868
13869 static void
13870 do_neon_cvtr (void)
13871 {
13872 do_neon_cvt_1 (FALSE);
13873 }
13874
13875 static void
13876 do_neon_cvt (void)
13877 {
13878 do_neon_cvt_1 (TRUE);
13879 }
13880
13881 static void
13882 do_neon_cvtb (void)
13883 {
13884 inst.instruction = 0xeb20a40;
13885
13886 /* The sizes are attached to the mnemonic. */
13887 if (inst.vectype.el[0].type != NT_invtype
13888 && inst.vectype.el[0].size == 16)
13889 inst.instruction |= 0x00010000;
13890
13891 /* Programmer's syntax: the sizes are attached to the operands. */
13892 else if (inst.operands[0].vectype.type != NT_invtype
13893 && inst.operands[0].vectype.size == 16)
13894 inst.instruction |= 0x00010000;
13895
13896 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13897 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13898 do_vfp_cond_or_thumb ();
13899 }
13900
13901
13902 static void
13903 do_neon_cvtt (void)
13904 {
13905 do_neon_cvtb ();
13906 inst.instruction |= 0x80;
13907 }
13908
13909 static void
13910 neon_move_immediate (void)
13911 {
13912 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13913 struct neon_type_el et = neon_check_type (2, rs,
13914 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13915 unsigned immlo, immhi = 0, immbits;
13916 int op, cmode, float_p;
13917
13918 constraint (et.type == NT_invtype,
13919 _("operand size must be specified for immediate VMOV"));
13920
13921 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13922 op = (inst.instruction & (1 << 5)) != 0;
13923
13924 immlo = inst.operands[1].imm;
13925 if (inst.operands[1].regisimm)
13926 immhi = inst.operands[1].reg;
13927
13928 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13929 _("immediate has bits set outside the operand size"));
13930
13931 float_p = inst.operands[1].immisfloat;
13932
13933 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
13934 et.size, et.type)) == FAIL)
13935 {
13936 /* Invert relevant bits only. */
13937 neon_invert_size (&immlo, &immhi, et.size);
13938 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13939 with one or the other; those cases are caught by
13940 neon_cmode_for_move_imm. */
13941 op = !op;
13942 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13943 &op, et.size, et.type)) == FAIL)
13944 {
13945 first_error (_("immediate out of range"));
13946 return;
13947 }
13948 }
13949
13950 inst.instruction &= ~(1 << 5);
13951 inst.instruction |= op << 5;
13952
13953 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13954 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13955 inst.instruction |= neon_quad (rs) << 6;
13956 inst.instruction |= cmode << 8;
13957
13958 neon_write_immbits (immbits);
13959 }
13960
13961 static void
13962 do_neon_mvn (void)
13963 {
13964 if (inst.operands[1].isreg)
13965 {
13966 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13967
13968 NEON_ENCODE (INTEGER, inst);
13969 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13970 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13971 inst.instruction |= LOW4 (inst.operands[1].reg);
13972 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13973 inst.instruction |= neon_quad (rs) << 6;
13974 }
13975 else
13976 {
13977 NEON_ENCODE (IMMED, inst);
13978 neon_move_immediate ();
13979 }
13980
13981 neon_dp_fixup (&inst);
13982 }
13983
13984 /* Encode instructions of form:
13985
13986 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13987 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
13988
13989 static void
13990 neon_mixed_length (struct neon_type_el et, unsigned size)
13991 {
13992 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13993 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13994 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13995 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13996 inst.instruction |= LOW4 (inst.operands[2].reg);
13997 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13998 inst.instruction |= (et.type == NT_unsigned) << 24;
13999 inst.instruction |= neon_logbits (size) << 20;
14000
14001 neon_dp_fixup (&inst);
14002 }
14003
14004 static void
14005 do_neon_dyadic_long (void)
14006 {
14007 /* FIXME: Type checking for lengthening op. */
14008 struct neon_type_el et = neon_check_type (3, NS_QDD,
14009 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14010 neon_mixed_length (et, et.size);
14011 }
14012
14013 static void
14014 do_neon_abal (void)
14015 {
14016 struct neon_type_el et = neon_check_type (3, NS_QDD,
14017 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14018 neon_mixed_length (et, et.size);
14019 }
14020
14021 static void
14022 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14023 {
14024 if (inst.operands[2].isscalar)
14025 {
14026 struct neon_type_el et = neon_check_type (3, NS_QDS,
14027 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
14028 NEON_ENCODE (SCALAR, inst);
14029 neon_mul_mac (et, et.type == NT_unsigned);
14030 }
14031 else
14032 {
14033 struct neon_type_el et = neon_check_type (3, NS_QDD,
14034 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
14035 NEON_ENCODE (INTEGER, inst);
14036 neon_mixed_length (et, et.size);
14037 }
14038 }
14039
14040 static void
14041 do_neon_mac_maybe_scalar_long (void)
14042 {
14043 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14044 }
14045
14046 static void
14047 do_neon_dyadic_wide (void)
14048 {
14049 struct neon_type_el et = neon_check_type (3, NS_QQD,
14050 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14051 neon_mixed_length (et, et.size);
14052 }
14053
14054 static void
14055 do_neon_dyadic_narrow (void)
14056 {
14057 struct neon_type_el et = neon_check_type (3, NS_QDD,
14058 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
14059 /* Operand sign is unimportant, and the U bit is part of the opcode,
14060 so force the operand type to integer. */
14061 et.type = NT_integer;
14062 neon_mixed_length (et, et.size / 2);
14063 }
14064
14065 static void
14066 do_neon_mul_sat_scalar_long (void)
14067 {
14068 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14069 }
14070
14071 static void
14072 do_neon_vmull (void)
14073 {
14074 if (inst.operands[2].isscalar)
14075 do_neon_mac_maybe_scalar_long ();
14076 else
14077 {
14078 struct neon_type_el et = neon_check_type (3, NS_QDD,
14079 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14080 if (et.type == NT_poly)
14081 NEON_ENCODE (POLY, inst);
14082 else
14083 NEON_ENCODE (INTEGER, inst);
14084 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14085 zero. Should be OK as-is. */
14086 neon_mixed_length (et, et.size);
14087 }
14088 }
14089
14090 static void
14091 do_neon_ext (void)
14092 {
14093 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
14094 struct neon_type_el et = neon_check_type (3, rs,
14095 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14096 unsigned imm = (inst.operands[3].imm * et.size) / 8;
14097
14098 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14099 _("shift out of range"));
14100 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14101 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14102 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14103 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14104 inst.instruction |= LOW4 (inst.operands[2].reg);
14105 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14106 inst.instruction |= neon_quad (rs) << 6;
14107 inst.instruction |= imm << 8;
14108
14109 neon_dp_fixup (&inst);
14110 }
14111
14112 static void
14113 do_neon_rev (void)
14114 {
14115 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14116 struct neon_type_el et = neon_check_type (2, rs,
14117 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14118 unsigned op = (inst.instruction >> 7) & 3;
14119 /* N (width of reversed regions) is encoded as part of the bitmask. We
14120 extract it here to check the elements to be reversed are smaller.
14121 Otherwise we'd get a reserved instruction. */
14122 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
14123 gas_assert (elsize != 0);
14124 constraint (et.size >= elsize,
14125 _("elements must be smaller than reversal region"));
14126 neon_two_same (neon_quad (rs), 1, et.size);
14127 }
14128
14129 static void
14130 do_neon_dup (void)
14131 {
14132 if (inst.operands[1].isscalar)
14133 {
14134 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
14135 struct neon_type_el et = neon_check_type (2, rs,
14136 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14137 unsigned sizebits = et.size >> 3;
14138 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
14139 int logsize = neon_logbits (et.size);
14140 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
14141
14142 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14143 return;
14144
14145 NEON_ENCODE (SCALAR, inst);
14146 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14147 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14148 inst.instruction |= LOW4 (dm);
14149 inst.instruction |= HI1 (dm) << 5;
14150 inst.instruction |= neon_quad (rs) << 6;
14151 inst.instruction |= x << 17;
14152 inst.instruction |= sizebits << 16;
14153
14154 neon_dp_fixup (&inst);
14155 }
14156 else
14157 {
14158 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14159 struct neon_type_el et = neon_check_type (2, rs,
14160 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14161 /* Duplicate ARM register to lanes of vector. */
14162 NEON_ENCODE (ARMREG, inst);
14163 switch (et.size)
14164 {
14165 case 8: inst.instruction |= 0x400000; break;
14166 case 16: inst.instruction |= 0x000020; break;
14167 case 32: inst.instruction |= 0x000000; break;
14168 default: break;
14169 }
14170 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14171 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14172 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
14173 inst.instruction |= neon_quad (rs) << 21;
14174 /* The encoding for this instruction is identical for the ARM and Thumb
14175 variants, except for the condition field. */
14176 do_vfp_cond_or_thumb ();
14177 }
14178 }
14179
14180 /* VMOV has particularly many variations. It can be one of:
14181 0. VMOV<c><q> <Qd>, <Qm>
14182 1. VMOV<c><q> <Dd>, <Dm>
14183 (Register operations, which are VORR with Rm = Rn.)
14184 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14185 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14186 (Immediate loads.)
14187 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14188 (ARM register to scalar.)
14189 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14190 (Two ARM registers to vector.)
14191 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14192 (Scalar to ARM register.)
14193 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14194 (Vector to two ARM registers.)
14195 8. VMOV.F32 <Sd>, <Sm>
14196 9. VMOV.F64 <Dd>, <Dm>
14197 (VFP register moves.)
14198 10. VMOV.F32 <Sd>, #imm
14199 11. VMOV.F64 <Dd>, #imm
14200 (VFP float immediate load.)
14201 12. VMOV <Rd>, <Sm>
14202 (VFP single to ARM reg.)
14203 13. VMOV <Sd>, <Rm>
14204 (ARM reg to VFP single.)
14205 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14206 (Two ARM regs to two VFP singles.)
14207 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14208 (Two VFP singles to two ARM regs.)
14209
14210 These cases can be disambiguated using neon_select_shape, except cases 1/9
14211 and 3/11 which depend on the operand type too.
14212
14213 All the encoded bits are hardcoded by this function.
14214
14215 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14216 Cases 5, 7 may be used with VFPv2 and above.
14217
14218 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
14219 can specify a type where it doesn't make sense to, and is ignored). */
14220
14221 static void
14222 do_neon_mov (void)
14223 {
14224 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14225 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14226 NS_NULL);
14227 struct neon_type_el et;
14228 const char *ldconst = 0;
14229
14230 switch (rs)
14231 {
14232 case NS_DD: /* case 1/9. */
14233 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14234 /* It is not an error here if no type is given. */
14235 inst.error = NULL;
14236 if (et.type == NT_float && et.size == 64)
14237 {
14238 do_vfp_nsyn_opcode ("fcpyd");
14239 break;
14240 }
14241 /* fall through. */
14242
14243 case NS_QQ: /* case 0/1. */
14244 {
14245 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14246 return;
14247 /* The architecture manual I have doesn't explicitly state which
14248 value the U bit should have for register->register moves, but
14249 the equivalent VORR instruction has U = 0, so do that. */
14250 inst.instruction = 0x0200110;
14251 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14252 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14253 inst.instruction |= LOW4 (inst.operands[1].reg);
14254 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14255 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14256 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14257 inst.instruction |= neon_quad (rs) << 6;
14258
14259 neon_dp_fixup (&inst);
14260 }
14261 break;
14262
14263 case NS_DI: /* case 3/11. */
14264 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14265 inst.error = NULL;
14266 if (et.type == NT_float && et.size == 64)
14267 {
14268 /* case 11 (fconstd). */
14269 ldconst = "fconstd";
14270 goto encode_fconstd;
14271 }
14272 /* fall through. */
14273
14274 case NS_QI: /* case 2/3. */
14275 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14276 return;
14277 inst.instruction = 0x0800010;
14278 neon_move_immediate ();
14279 neon_dp_fixup (&inst);
14280 break;
14281
14282 case NS_SR: /* case 4. */
14283 {
14284 unsigned bcdebits = 0;
14285 int logsize;
14286 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14287 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14288
14289 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14290 logsize = neon_logbits (et.size);
14291
14292 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14293 _(BAD_FPU));
14294 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14295 && et.size != 32, _(BAD_FPU));
14296 constraint (et.type == NT_invtype, _("bad type for scalar"));
14297 constraint (x >= 64 / et.size, _("scalar index out of range"));
14298
14299 switch (et.size)
14300 {
14301 case 8: bcdebits = 0x8; break;
14302 case 16: bcdebits = 0x1; break;
14303 case 32: bcdebits = 0x0; break;
14304 default: ;
14305 }
14306
14307 bcdebits |= x << logsize;
14308
14309 inst.instruction = 0xe000b10;
14310 do_vfp_cond_or_thumb ();
14311 inst.instruction |= LOW4 (dn) << 16;
14312 inst.instruction |= HI1 (dn) << 7;
14313 inst.instruction |= inst.operands[1].reg << 12;
14314 inst.instruction |= (bcdebits & 3) << 5;
14315 inst.instruction |= (bcdebits >> 2) << 21;
14316 }
14317 break;
14318
14319 case NS_DRR: /* case 5 (fmdrr). */
14320 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14321 _(BAD_FPU));
14322
14323 inst.instruction = 0xc400b10;
14324 do_vfp_cond_or_thumb ();
14325 inst.instruction |= LOW4 (inst.operands[0].reg);
14326 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14327 inst.instruction |= inst.operands[1].reg << 12;
14328 inst.instruction |= inst.operands[2].reg << 16;
14329 break;
14330
14331 case NS_RS: /* case 6. */
14332 {
14333 unsigned logsize;
14334 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14335 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14336 unsigned abcdebits = 0;
14337
14338 et = neon_check_type (2, NS_NULL,
14339 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14340 logsize = neon_logbits (et.size);
14341
14342 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14343 _(BAD_FPU));
14344 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14345 && et.size != 32, _(BAD_FPU));
14346 constraint (et.type == NT_invtype, _("bad type for scalar"));
14347 constraint (x >= 64 / et.size, _("scalar index out of range"));
14348
14349 switch (et.size)
14350 {
14351 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14352 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14353 case 32: abcdebits = 0x00; break;
14354 default: ;
14355 }
14356
14357 abcdebits |= x << logsize;
14358 inst.instruction = 0xe100b10;
14359 do_vfp_cond_or_thumb ();
14360 inst.instruction |= LOW4 (dn) << 16;
14361 inst.instruction |= HI1 (dn) << 7;
14362 inst.instruction |= inst.operands[0].reg << 12;
14363 inst.instruction |= (abcdebits & 3) << 5;
14364 inst.instruction |= (abcdebits >> 2) << 21;
14365 }
14366 break;
14367
14368 case NS_RRD: /* case 7 (fmrrd). */
14369 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14370 _(BAD_FPU));
14371
14372 inst.instruction = 0xc500b10;
14373 do_vfp_cond_or_thumb ();
14374 inst.instruction |= inst.operands[0].reg << 12;
14375 inst.instruction |= inst.operands[1].reg << 16;
14376 inst.instruction |= LOW4 (inst.operands[2].reg);
14377 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14378 break;
14379
14380 case NS_FF: /* case 8 (fcpys). */
14381 do_vfp_nsyn_opcode ("fcpys");
14382 break;
14383
14384 case NS_FI: /* case 10 (fconsts). */
14385 ldconst = "fconsts";
14386 encode_fconstd:
14387 if (is_quarter_float (inst.operands[1].imm))
14388 {
14389 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14390 do_vfp_nsyn_opcode (ldconst);
14391 }
14392 else
14393 first_error (_("immediate out of range"));
14394 break;
14395
14396 case NS_RF: /* case 12 (fmrs). */
14397 do_vfp_nsyn_opcode ("fmrs");
14398 break;
14399
14400 case NS_FR: /* case 13 (fmsr). */
14401 do_vfp_nsyn_opcode ("fmsr");
14402 break;
14403
14404 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14405 (one of which is a list), but we have parsed four. Do some fiddling to
14406 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14407 expect. */
14408 case NS_RRFF: /* case 14 (fmrrs). */
14409 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14410 _("VFP registers must be adjacent"));
14411 inst.operands[2].imm = 2;
14412 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14413 do_vfp_nsyn_opcode ("fmrrs");
14414 break;
14415
14416 case NS_FFRR: /* case 15 (fmsrr). */
14417 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14418 _("VFP registers must be adjacent"));
14419 inst.operands[1] = inst.operands[2];
14420 inst.operands[2] = inst.operands[3];
14421 inst.operands[0].imm = 2;
14422 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14423 do_vfp_nsyn_opcode ("fmsrr");
14424 break;
14425
14426 default:
14427 abort ();
14428 }
14429 }
14430
14431 static void
14432 do_neon_rshift_round_imm (void)
14433 {
14434 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14435 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14436 int imm = inst.operands[2].imm;
14437
14438 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14439 if (imm == 0)
14440 {
14441 inst.operands[2].present = 0;
14442 do_neon_mov ();
14443 return;
14444 }
14445
14446 constraint (imm < 1 || (unsigned)imm > et.size,
14447 _("immediate out of range for shift"));
14448 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
14449 et.size - imm);
14450 }
14451
14452 static void
14453 do_neon_movl (void)
14454 {
14455 struct neon_type_el et = neon_check_type (2, NS_QD,
14456 N_EQK | N_DBL, N_SU_32 | N_KEY);
14457 unsigned sizebits = et.size >> 3;
14458 inst.instruction |= sizebits << 19;
14459 neon_two_same (0, et.type == NT_unsigned, -1);
14460 }
14461
14462 static void
14463 do_neon_trn (void)
14464 {
14465 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14466 struct neon_type_el et = neon_check_type (2, rs,
14467 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14468 NEON_ENCODE (INTEGER, inst);
14469 neon_two_same (neon_quad (rs), 1, et.size);
14470 }
14471
14472 static void
14473 do_neon_zip_uzp (void)
14474 {
14475 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14476 struct neon_type_el et = neon_check_type (2, rs,
14477 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14478 if (rs == NS_DD && et.size == 32)
14479 {
14480 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14481 inst.instruction = N_MNEM_vtrn;
14482 do_neon_trn ();
14483 return;
14484 }
14485 neon_two_same (neon_quad (rs), 1, et.size);
14486 }
14487
14488 static void
14489 do_neon_sat_abs_neg (void)
14490 {
14491 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14492 struct neon_type_el et = neon_check_type (2, rs,
14493 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14494 neon_two_same (neon_quad (rs), 1, et.size);
14495 }
14496
14497 static void
14498 do_neon_pair_long (void)
14499 {
14500 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14501 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14502 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14503 inst.instruction |= (et.type == NT_unsigned) << 7;
14504 neon_two_same (neon_quad (rs), 1, et.size);
14505 }
14506
14507 static void
14508 do_neon_recip_est (void)
14509 {
14510 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14511 struct neon_type_el et = neon_check_type (2, rs,
14512 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14513 inst.instruction |= (et.type == NT_float) << 8;
14514 neon_two_same (neon_quad (rs), 1, et.size);
14515 }
14516
14517 static void
14518 do_neon_cls (void)
14519 {
14520 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14521 struct neon_type_el et = neon_check_type (2, rs,
14522 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14523 neon_two_same (neon_quad (rs), 1, et.size);
14524 }
14525
14526 static void
14527 do_neon_clz (void)
14528 {
14529 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14530 struct neon_type_el et = neon_check_type (2, rs,
14531 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
14532 neon_two_same (neon_quad (rs), 1, et.size);
14533 }
14534
14535 static void
14536 do_neon_cnt (void)
14537 {
14538 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14539 struct neon_type_el et = neon_check_type (2, rs,
14540 N_EQK | N_INT, N_8 | N_KEY);
14541 neon_two_same (neon_quad (rs), 1, et.size);
14542 }
14543
14544 static void
14545 do_neon_swp (void)
14546 {
14547 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14548 neon_two_same (neon_quad (rs), 1, -1);
14549 }
14550
14551 static void
14552 do_neon_tbl_tbx (void)
14553 {
14554 unsigned listlenbits;
14555 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
14556
14557 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14558 {
14559 first_error (_("bad list length for table lookup"));
14560 return;
14561 }
14562
14563 listlenbits = inst.operands[1].imm - 1;
14564 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14565 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14566 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14567 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14568 inst.instruction |= LOW4 (inst.operands[2].reg);
14569 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14570 inst.instruction |= listlenbits << 8;
14571
14572 neon_dp_fixup (&inst);
14573 }
14574
14575 static void
14576 do_neon_ldm_stm (void)
14577 {
14578 /* P, U and L bits are part of bitmask. */
14579 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14580 unsigned offsetbits = inst.operands[1].imm * 2;
14581
14582 if (inst.operands[1].issingle)
14583 {
14584 do_vfp_nsyn_ldm_stm (is_dbmode);
14585 return;
14586 }
14587
14588 constraint (is_dbmode && !inst.operands[0].writeback,
14589 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14590
14591 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14592 _("register list must contain at least 1 and at most 16 "
14593 "registers"));
14594
14595 inst.instruction |= inst.operands[0].reg << 16;
14596 inst.instruction |= inst.operands[0].writeback << 21;
14597 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14598 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14599
14600 inst.instruction |= offsetbits;
14601
14602 do_vfp_cond_or_thumb ();
14603 }
14604
14605 static void
14606 do_neon_ldr_str (void)
14607 {
14608 int is_ldr = (inst.instruction & (1 << 20)) != 0;
14609
14610 if (inst.operands[0].issingle)
14611 {
14612 if (is_ldr)
14613 do_vfp_nsyn_opcode ("flds");
14614 else
14615 do_vfp_nsyn_opcode ("fsts");
14616 }
14617 else
14618 {
14619 if (is_ldr)
14620 do_vfp_nsyn_opcode ("fldd");
14621 else
14622 do_vfp_nsyn_opcode ("fstd");
14623 }
14624 }
14625
14626 /* "interleave" version also handles non-interleaving register VLD1/VST1
14627 instructions. */
14628
14629 static void
14630 do_neon_ld_st_interleave (void)
14631 {
14632 struct neon_type_el et = neon_check_type (1, NS_NULL,
14633 N_8 | N_16 | N_32 | N_64);
14634 unsigned alignbits = 0;
14635 unsigned idx;
14636 /* The bits in this table go:
14637 0: register stride of one (0) or two (1)
14638 1,2: register list length, minus one (1, 2, 3, 4).
14639 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14640 We use -1 for invalid entries. */
14641 const int typetable[] =
14642 {
14643 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14644 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14645 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14646 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14647 };
14648 int typebits;
14649
14650 if (et.type == NT_invtype)
14651 return;
14652
14653 if (inst.operands[1].immisalign)
14654 switch (inst.operands[1].imm >> 8)
14655 {
14656 case 64: alignbits = 1; break;
14657 case 128:
14658 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14659 goto bad_alignment;
14660 alignbits = 2;
14661 break;
14662 case 256:
14663 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14664 goto bad_alignment;
14665 alignbits = 3;
14666 break;
14667 default:
14668 bad_alignment:
14669 first_error (_("bad alignment"));
14670 return;
14671 }
14672
14673 inst.instruction |= alignbits << 4;
14674 inst.instruction |= neon_logbits (et.size) << 6;
14675
14676 /* Bits [4:6] of the immediate in a list specifier encode register stride
14677 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14678 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14679 up the right value for "type" in a table based on this value and the given
14680 list style, then stick it back. */
14681 idx = ((inst.operands[0].imm >> 4) & 7)
14682 | (((inst.instruction >> 8) & 3) << 3);
14683
14684 typebits = typetable[idx];
14685
14686 constraint (typebits == -1, _("bad list type for instruction"));
14687
14688 inst.instruction &= ~0xf00;
14689 inst.instruction |= typebits << 8;
14690 }
14691
14692 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14693 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14694 otherwise. The variable arguments are a list of pairs of legal (size, align)
14695 values, terminated with -1. */
14696
14697 static int
14698 neon_alignment_bit (int size, int align, int *do_align, ...)
14699 {
14700 va_list ap;
14701 int result = FAIL, thissize, thisalign;
14702
14703 if (!inst.operands[1].immisalign)
14704 {
14705 *do_align = 0;
14706 return SUCCESS;
14707 }
14708
14709 va_start (ap, do_align);
14710
14711 do
14712 {
14713 thissize = va_arg (ap, int);
14714 if (thissize == -1)
14715 break;
14716 thisalign = va_arg (ap, int);
14717
14718 if (size == thissize && align == thisalign)
14719 result = SUCCESS;
14720 }
14721 while (result != SUCCESS);
14722
14723 va_end (ap);
14724
14725 if (result == SUCCESS)
14726 *do_align = 1;
14727 else
14728 first_error (_("unsupported alignment for instruction"));
14729
14730 return result;
14731 }
14732
14733 static void
14734 do_neon_ld_st_lane (void)
14735 {
14736 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14737 int align_good, do_align = 0;
14738 int logsize = neon_logbits (et.size);
14739 int align = inst.operands[1].imm >> 8;
14740 int n = (inst.instruction >> 8) & 3;
14741 int max_el = 64 / et.size;
14742
14743 if (et.type == NT_invtype)
14744 return;
14745
14746 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14747 _("bad list length"));
14748 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14749 _("scalar index out of range"));
14750 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14751 && et.size == 8,
14752 _("stride of 2 unavailable when element size is 8"));
14753
14754 switch (n)
14755 {
14756 case 0: /* VLD1 / VST1. */
14757 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14758 32, 32, -1);
14759 if (align_good == FAIL)
14760 return;
14761 if (do_align)
14762 {
14763 unsigned alignbits = 0;
14764 switch (et.size)
14765 {
14766 case 16: alignbits = 0x1; break;
14767 case 32: alignbits = 0x3; break;
14768 default: ;
14769 }
14770 inst.instruction |= alignbits << 4;
14771 }
14772 break;
14773
14774 case 1: /* VLD2 / VST2. */
14775 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14776 32, 64, -1);
14777 if (align_good == FAIL)
14778 return;
14779 if (do_align)
14780 inst.instruction |= 1 << 4;
14781 break;
14782
14783 case 2: /* VLD3 / VST3. */
14784 constraint (inst.operands[1].immisalign,
14785 _("can't use alignment with this instruction"));
14786 break;
14787
14788 case 3: /* VLD4 / VST4. */
14789 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14790 16, 64, 32, 64, 32, 128, -1);
14791 if (align_good == FAIL)
14792 return;
14793 if (do_align)
14794 {
14795 unsigned alignbits = 0;
14796 switch (et.size)
14797 {
14798 case 8: alignbits = 0x1; break;
14799 case 16: alignbits = 0x1; break;
14800 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14801 default: ;
14802 }
14803 inst.instruction |= alignbits << 4;
14804 }
14805 break;
14806
14807 default: ;
14808 }
14809
14810 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14811 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14812 inst.instruction |= 1 << (4 + logsize);
14813
14814 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14815 inst.instruction |= logsize << 10;
14816 }
14817
14818 /* Encode single n-element structure to all lanes VLD<n> instructions. */
14819
14820 static void
14821 do_neon_ld_dup (void)
14822 {
14823 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14824 int align_good, do_align = 0;
14825
14826 if (et.type == NT_invtype)
14827 return;
14828
14829 switch ((inst.instruction >> 8) & 3)
14830 {
14831 case 0: /* VLD1. */
14832 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
14833 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14834 &do_align, 16, 16, 32, 32, -1);
14835 if (align_good == FAIL)
14836 return;
14837 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14838 {
14839 case 1: break;
14840 case 2: inst.instruction |= 1 << 5; break;
14841 default: first_error (_("bad list length")); return;
14842 }
14843 inst.instruction |= neon_logbits (et.size) << 6;
14844 break;
14845
14846 case 1: /* VLD2. */
14847 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14848 &do_align, 8, 16, 16, 32, 32, 64, -1);
14849 if (align_good == FAIL)
14850 return;
14851 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14852 _("bad list length"));
14853 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14854 inst.instruction |= 1 << 5;
14855 inst.instruction |= neon_logbits (et.size) << 6;
14856 break;
14857
14858 case 2: /* VLD3. */
14859 constraint (inst.operands[1].immisalign,
14860 _("can't use alignment with this instruction"));
14861 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14862 _("bad list length"));
14863 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14864 inst.instruction |= 1 << 5;
14865 inst.instruction |= neon_logbits (et.size) << 6;
14866 break;
14867
14868 case 3: /* VLD4. */
14869 {
14870 int align = inst.operands[1].imm >> 8;
14871 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14872 16, 64, 32, 64, 32, 128, -1);
14873 if (align_good == FAIL)
14874 return;
14875 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14876 _("bad list length"));
14877 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14878 inst.instruction |= 1 << 5;
14879 if (et.size == 32 && align == 128)
14880 inst.instruction |= 0x3 << 6;
14881 else
14882 inst.instruction |= neon_logbits (et.size) << 6;
14883 }
14884 break;
14885
14886 default: ;
14887 }
14888
14889 inst.instruction |= do_align << 4;
14890 }
14891
14892 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14893 apart from bits [11:4]. */
14894
14895 static void
14896 do_neon_ldx_stx (void)
14897 {
14898 if (inst.operands[1].isreg)
14899 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
14900
14901 switch (NEON_LANE (inst.operands[0].imm))
14902 {
14903 case NEON_INTERLEAVE_LANES:
14904 NEON_ENCODE (INTERLV, inst);
14905 do_neon_ld_st_interleave ();
14906 break;
14907
14908 case NEON_ALL_LANES:
14909 NEON_ENCODE (DUP, inst);
14910 do_neon_ld_dup ();
14911 break;
14912
14913 default:
14914 NEON_ENCODE (LANE, inst);
14915 do_neon_ld_st_lane ();
14916 }
14917
14918 /* L bit comes from bit mask. */
14919 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14920 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14921 inst.instruction |= inst.operands[1].reg << 16;
14922
14923 if (inst.operands[1].postind)
14924 {
14925 int postreg = inst.operands[1].imm & 0xf;
14926 constraint (!inst.operands[1].immisreg,
14927 _("post-index must be a register"));
14928 constraint (postreg == 0xd || postreg == 0xf,
14929 _("bad register for post-index"));
14930 inst.instruction |= postreg;
14931 }
14932 else if (inst.operands[1].writeback)
14933 {
14934 inst.instruction |= 0xd;
14935 }
14936 else
14937 inst.instruction |= 0xf;
14938
14939 if (thumb_mode)
14940 inst.instruction |= 0xf9000000;
14941 else
14942 inst.instruction |= 0xf4000000;
14943 }
14944 \f
14945 /* Overall per-instruction processing. */
14946
14947 /* We need to be able to fix up arbitrary expressions in some statements.
14948 This is so that we can handle symbols that are an arbitrary distance from
14949 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14950 which returns part of an address in a form which will be valid for
14951 a data instruction. We do this by pushing the expression into a symbol
14952 in the expr_section, and creating a fix for that. */
14953
14954 static void
14955 fix_new_arm (fragS * frag,
14956 int where,
14957 short int size,
14958 expressionS * exp,
14959 int pc_rel,
14960 int reloc)
14961 {
14962 fixS * new_fix;
14963
14964 switch (exp->X_op)
14965 {
14966 case O_constant:
14967 case O_symbol:
14968 case O_add:
14969 case O_subtract:
14970 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
14971 (enum bfd_reloc_code_real) reloc);
14972 break;
14973
14974 default:
14975 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
14976 pc_rel, (enum bfd_reloc_code_real) reloc);
14977 break;
14978 }
14979
14980 /* Mark whether the fix is to a THUMB instruction, or an ARM
14981 instruction. */
14982 new_fix->tc_fix_data = thumb_mode;
14983 }
14984
14985 /* Create a frg for an instruction requiring relaxation. */
14986 static void
14987 output_relax_insn (void)
14988 {
14989 char * to;
14990 symbolS *sym;
14991 int offset;
14992
14993 /* The size of the instruction is unknown, so tie the debug info to the
14994 start of the instruction. */
14995 dwarf2_emit_insn (0);
14996
14997 switch (inst.reloc.exp.X_op)
14998 {
14999 case O_symbol:
15000 sym = inst.reloc.exp.X_add_symbol;
15001 offset = inst.reloc.exp.X_add_number;
15002 break;
15003 case O_constant:
15004 sym = NULL;
15005 offset = inst.reloc.exp.X_add_number;
15006 break;
15007 default:
15008 sym = make_expr_symbol (&inst.reloc.exp);
15009 offset = 0;
15010 break;
15011 }
15012 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15013 inst.relax, sym, offset, NULL/*offset, opcode*/);
15014 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
15015 }
15016
15017 /* Write a 32-bit thumb instruction to buf. */
15018 static void
15019 put_thumb32_insn (char * buf, unsigned long insn)
15020 {
15021 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15022 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15023 }
15024
15025 static void
15026 output_inst (const char * str)
15027 {
15028 char * to = NULL;
15029
15030 if (inst.error)
15031 {
15032 as_bad ("%s -- `%s'", inst.error, str);
15033 return;
15034 }
15035 if (inst.relax)
15036 {
15037 output_relax_insn ();
15038 return;
15039 }
15040 if (inst.size == 0)
15041 return;
15042
15043 to = frag_more (inst.size);
15044 /* PR 9814: Record the thumb mode into the current frag so that we know
15045 what type of NOP padding to use, if necessary. We override any previous
15046 setting so that if the mode has changed then the NOPS that we use will
15047 match the encoding of the last instruction in the frag. */
15048 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
15049
15050 if (thumb_mode && (inst.size > THUMB_SIZE))
15051 {
15052 gas_assert (inst.size == (2 * THUMB_SIZE));
15053 put_thumb32_insn (to, inst.instruction);
15054 }
15055 else if (inst.size > INSN_SIZE)
15056 {
15057 gas_assert (inst.size == (2 * INSN_SIZE));
15058 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15059 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
15060 }
15061 else
15062 md_number_to_chars (to, inst.instruction, inst.size);
15063
15064 if (inst.reloc.type != BFD_RELOC_UNUSED)
15065 fix_new_arm (frag_now, to - frag_now->fr_literal,
15066 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15067 inst.reloc.type);
15068
15069 dwarf2_emit_insn (inst.size);
15070 }
15071
15072 static char *
15073 output_it_inst (int cond, int mask, char * to)
15074 {
15075 unsigned long instruction = 0xbf00;
15076
15077 mask &= 0xf;
15078 instruction |= mask;
15079 instruction |= cond << 4;
15080
15081 if (to == NULL)
15082 {
15083 to = frag_more (2);
15084 #ifdef OBJ_ELF
15085 dwarf2_emit_insn (2);
15086 #endif
15087 }
15088
15089 md_number_to_chars (to, instruction, 2);
15090
15091 return to;
15092 }
15093
15094 /* Tag values used in struct asm_opcode's tag field. */
15095 enum opcode_tag
15096 {
15097 OT_unconditional, /* Instruction cannot be conditionalized.
15098 The ARM condition field is still 0xE. */
15099 OT_unconditionalF, /* Instruction cannot be conditionalized
15100 and carries 0xF in its ARM condition field. */
15101 OT_csuffix, /* Instruction takes a conditional suffix. */
15102 OT_csuffixF, /* Some forms of the instruction take a conditional
15103 suffix, others place 0xF where the condition field
15104 would be. */
15105 OT_cinfix3, /* Instruction takes a conditional infix,
15106 beginning at character index 3. (In
15107 unified mode, it becomes a suffix.) */
15108 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15109 tsts, cmps, cmns, and teqs. */
15110 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15111 character index 3, even in unified mode. Used for
15112 legacy instructions where suffix and infix forms
15113 may be ambiguous. */
15114 OT_csuf_or_in3, /* Instruction takes either a conditional
15115 suffix or an infix at character index 3. */
15116 OT_odd_infix_unc, /* This is the unconditional variant of an
15117 instruction that takes a conditional infix
15118 at an unusual position. In unified mode,
15119 this variant will accept a suffix. */
15120 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15121 are the conditional variants of instructions that
15122 take conditional infixes in unusual positions.
15123 The infix appears at character index
15124 (tag - OT_odd_infix_0). These are not accepted
15125 in unified mode. */
15126 };
15127
15128 /* Subroutine of md_assemble, responsible for looking up the primary
15129 opcode from the mnemonic the user wrote. STR points to the
15130 beginning of the mnemonic.
15131
15132 This is not simply a hash table lookup, because of conditional
15133 variants. Most instructions have conditional variants, which are
15134 expressed with a _conditional affix_ to the mnemonic. If we were
15135 to encode each conditional variant as a literal string in the opcode
15136 table, it would have approximately 20,000 entries.
15137
15138 Most mnemonics take this affix as a suffix, and in unified syntax,
15139 'most' is upgraded to 'all'. However, in the divided syntax, some
15140 instructions take the affix as an infix, notably the s-variants of
15141 the arithmetic instructions. Of those instructions, all but six
15142 have the infix appear after the third character of the mnemonic.
15143
15144 Accordingly, the algorithm for looking up primary opcodes given
15145 an identifier is:
15146
15147 1. Look up the identifier in the opcode table.
15148 If we find a match, go to step U.
15149
15150 2. Look up the last two characters of the identifier in the
15151 conditions table. If we find a match, look up the first N-2
15152 characters of the identifier in the opcode table. If we
15153 find a match, go to step CE.
15154
15155 3. Look up the fourth and fifth characters of the identifier in
15156 the conditions table. If we find a match, extract those
15157 characters from the identifier, and look up the remaining
15158 characters in the opcode table. If we find a match, go
15159 to step CM.
15160
15161 4. Fail.
15162
15163 U. Examine the tag field of the opcode structure, in case this is
15164 one of the six instructions with its conditional infix in an
15165 unusual place. If it is, the tag tells us where to find the
15166 infix; look it up in the conditions table and set inst.cond
15167 accordingly. Otherwise, this is an unconditional instruction.
15168 Again set inst.cond accordingly. Return the opcode structure.
15169
15170 CE. Examine the tag field to make sure this is an instruction that
15171 should receive a conditional suffix. If it is not, fail.
15172 Otherwise, set inst.cond from the suffix we already looked up,
15173 and return the opcode structure.
15174
15175 CM. Examine the tag field to make sure this is an instruction that
15176 should receive a conditional infix after the third character.
15177 If it is not, fail. Otherwise, undo the edits to the current
15178 line of input and proceed as for case CE. */
15179
15180 static const struct asm_opcode *
15181 opcode_lookup (char **str)
15182 {
15183 char *end, *base;
15184 char *affix;
15185 const struct asm_opcode *opcode;
15186 const struct asm_cond *cond;
15187 char save[2];
15188
15189 /* Scan up to the end of the mnemonic, which must end in white space,
15190 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
15191 for (base = end = *str; *end != '\0'; end++)
15192 if (*end == ' ' || *end == '.')
15193 break;
15194
15195 if (end == base)
15196 return NULL;
15197
15198 /* Handle a possible width suffix and/or Neon type suffix. */
15199 if (end[0] == '.')
15200 {
15201 int offset = 2;
15202
15203 /* The .w and .n suffixes are only valid if the unified syntax is in
15204 use. */
15205 if (unified_syntax && end[1] == 'w')
15206 inst.size_req = 4;
15207 else if (unified_syntax && end[1] == 'n')
15208 inst.size_req = 2;
15209 else
15210 offset = 0;
15211
15212 inst.vectype.elems = 0;
15213
15214 *str = end + offset;
15215
15216 if (end[offset] == '.')
15217 {
15218 /* See if we have a Neon type suffix (possible in either unified or
15219 non-unified ARM syntax mode). */
15220 if (parse_neon_type (&inst.vectype, str) == FAIL)
15221 return NULL;
15222 }
15223 else if (end[offset] != '\0' && end[offset] != ' ')
15224 return NULL;
15225 }
15226 else
15227 *str = end;
15228
15229 /* Look for unaffixed or special-case affixed mnemonic. */
15230 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15231 end - base);
15232 if (opcode)
15233 {
15234 /* step U */
15235 if (opcode->tag < OT_odd_infix_0)
15236 {
15237 inst.cond = COND_ALWAYS;
15238 return opcode;
15239 }
15240
15241 if (warn_on_deprecated && unified_syntax)
15242 as_warn (_("conditional infixes are deprecated in unified syntax"));
15243 affix = base + (opcode->tag - OT_odd_infix_0);
15244 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15245 gas_assert (cond);
15246
15247 inst.cond = cond->value;
15248 return opcode;
15249 }
15250
15251 /* Cannot have a conditional suffix on a mnemonic of less than two
15252 characters. */
15253 if (end - base < 3)
15254 return NULL;
15255
15256 /* Look for suffixed mnemonic. */
15257 affix = end - 2;
15258 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15259 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15260 affix - base);
15261 if (opcode && cond)
15262 {
15263 /* step CE */
15264 switch (opcode->tag)
15265 {
15266 case OT_cinfix3_legacy:
15267 /* Ignore conditional suffixes matched on infix only mnemonics. */
15268 break;
15269
15270 case OT_cinfix3:
15271 case OT_cinfix3_deprecated:
15272 case OT_odd_infix_unc:
15273 if (!unified_syntax)
15274 return 0;
15275 /* else fall through */
15276
15277 case OT_csuffix:
15278 case OT_csuffixF:
15279 case OT_csuf_or_in3:
15280 inst.cond = cond->value;
15281 return opcode;
15282
15283 case OT_unconditional:
15284 case OT_unconditionalF:
15285 if (thumb_mode)
15286 inst.cond = cond->value;
15287 else
15288 {
15289 /* Delayed diagnostic. */
15290 inst.error = BAD_COND;
15291 inst.cond = COND_ALWAYS;
15292 }
15293 return opcode;
15294
15295 default:
15296 return NULL;
15297 }
15298 }
15299
15300 /* Cannot have a usual-position infix on a mnemonic of less than
15301 six characters (five would be a suffix). */
15302 if (end - base < 6)
15303 return NULL;
15304
15305 /* Look for infixed mnemonic in the usual position. */
15306 affix = base + 3;
15307 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15308 if (!cond)
15309 return NULL;
15310
15311 memcpy (save, affix, 2);
15312 memmove (affix, affix + 2, (end - affix) - 2);
15313 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15314 (end - base) - 2);
15315 memmove (affix + 2, affix, (end - affix) - 2);
15316 memcpy (affix, save, 2);
15317
15318 if (opcode
15319 && (opcode->tag == OT_cinfix3
15320 || opcode->tag == OT_cinfix3_deprecated
15321 || opcode->tag == OT_csuf_or_in3
15322 || opcode->tag == OT_cinfix3_legacy))
15323 {
15324 /* Step CM. */
15325 if (warn_on_deprecated && unified_syntax
15326 && (opcode->tag == OT_cinfix3
15327 || opcode->tag == OT_cinfix3_deprecated))
15328 as_warn (_("conditional infixes are deprecated in unified syntax"));
15329
15330 inst.cond = cond->value;
15331 return opcode;
15332 }
15333
15334 return NULL;
15335 }
15336
15337 /* This function generates an initial IT instruction, leaving its block
15338 virtually open for the new instructions. Eventually,
15339 the mask will be updated by now_it_add_mask () each time
15340 a new instruction needs to be included in the IT block.
15341 Finally, the block is closed with close_automatic_it_block ().
15342 The block closure can be requested either from md_assemble (),
15343 a tencode (), or due to a label hook. */
15344
15345 static void
15346 new_automatic_it_block (int cond)
15347 {
15348 now_it.state = AUTOMATIC_IT_BLOCK;
15349 now_it.mask = 0x18;
15350 now_it.cc = cond;
15351 now_it.block_length = 1;
15352 mapping_state (MAP_THUMB);
15353 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15354 }
15355
15356 /* Close an automatic IT block.
15357 See comments in new_automatic_it_block (). */
15358
15359 static void
15360 close_automatic_it_block (void)
15361 {
15362 now_it.mask = 0x10;
15363 now_it.block_length = 0;
15364 }
15365
15366 /* Update the mask of the current automatically-generated IT
15367 instruction. See comments in new_automatic_it_block (). */
15368
15369 static void
15370 now_it_add_mask (int cond)
15371 {
15372 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15373 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15374 | ((bitvalue) << (nbit)))
15375 const int resulting_bit = (cond & 1);
15376
15377 now_it.mask &= 0xf;
15378 now_it.mask = SET_BIT_VALUE (now_it.mask,
15379 resulting_bit,
15380 (5 - now_it.block_length));
15381 now_it.mask = SET_BIT_VALUE (now_it.mask,
15382 1,
15383 ((5 - now_it.block_length) - 1) );
15384 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15385
15386 #undef CLEAR_BIT
15387 #undef SET_BIT_VALUE
15388 }
15389
15390 /* The IT blocks handling machinery is accessed through the these functions:
15391 it_fsm_pre_encode () from md_assemble ()
15392 set_it_insn_type () optional, from the tencode functions
15393 set_it_insn_type_last () ditto
15394 in_it_block () ditto
15395 it_fsm_post_encode () from md_assemble ()
15396 force_automatic_it_block_close () from label habdling functions
15397
15398 Rationale:
15399 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15400 initializing the IT insn type with a generic initial value depending
15401 on the inst.condition.
15402 2) During the tencode function, two things may happen:
15403 a) The tencode function overrides the IT insn type by
15404 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15405 b) The tencode function queries the IT block state by
15406 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15407
15408 Both set_it_insn_type and in_it_block run the internal FSM state
15409 handling function (handle_it_state), because: a) setting the IT insn
15410 type may incur in an invalid state (exiting the function),
15411 and b) querying the state requires the FSM to be updated.
15412 Specifically we want to avoid creating an IT block for conditional
15413 branches, so it_fsm_pre_encode is actually a guess and we can't
15414 determine whether an IT block is required until the tencode () routine
15415 has decided what type of instruction this actually it.
15416 Because of this, if set_it_insn_type and in_it_block have to be used,
15417 set_it_insn_type has to be called first.
15418
15419 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15420 determines the insn IT type depending on the inst.cond code.
15421 When a tencode () routine encodes an instruction that can be
15422 either outside an IT block, or, in the case of being inside, has to be
15423 the last one, set_it_insn_type_last () will determine the proper
15424 IT instruction type based on the inst.cond code. Otherwise,
15425 set_it_insn_type can be called for overriding that logic or
15426 for covering other cases.
15427
15428 Calling handle_it_state () may not transition the IT block state to
15429 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15430 still queried. Instead, if the FSM determines that the state should
15431 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15432 after the tencode () function: that's what it_fsm_post_encode () does.
15433
15434 Since in_it_block () calls the state handling function to get an
15435 updated state, an error may occur (due to invalid insns combination).
15436 In that case, inst.error is set.
15437 Therefore, inst.error has to be checked after the execution of
15438 the tencode () routine.
15439
15440 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15441 any pending state change (if any) that didn't take place in
15442 handle_it_state () as explained above. */
15443
15444 static void
15445 it_fsm_pre_encode (void)
15446 {
15447 if (inst.cond != COND_ALWAYS)
15448 inst.it_insn_type = INSIDE_IT_INSN;
15449 else
15450 inst.it_insn_type = OUTSIDE_IT_INSN;
15451
15452 now_it.state_handled = 0;
15453 }
15454
15455 /* IT state FSM handling function. */
15456
15457 static int
15458 handle_it_state (void)
15459 {
15460 now_it.state_handled = 1;
15461
15462 switch (now_it.state)
15463 {
15464 case OUTSIDE_IT_BLOCK:
15465 switch (inst.it_insn_type)
15466 {
15467 case OUTSIDE_IT_INSN:
15468 break;
15469
15470 case INSIDE_IT_INSN:
15471 case INSIDE_IT_LAST_INSN:
15472 if (thumb_mode == 0)
15473 {
15474 if (unified_syntax
15475 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15476 as_tsktsk (_("Warning: conditional outside an IT block"\
15477 " for Thumb."));
15478 }
15479 else
15480 {
15481 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15482 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15483 {
15484 /* Automatically generate the IT instruction. */
15485 new_automatic_it_block (inst.cond);
15486 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15487 close_automatic_it_block ();
15488 }
15489 else
15490 {
15491 inst.error = BAD_OUT_IT;
15492 return FAIL;
15493 }
15494 }
15495 break;
15496
15497 case IF_INSIDE_IT_LAST_INSN:
15498 case NEUTRAL_IT_INSN:
15499 break;
15500
15501 case IT_INSN:
15502 now_it.state = MANUAL_IT_BLOCK;
15503 now_it.block_length = 0;
15504 break;
15505 }
15506 break;
15507
15508 case AUTOMATIC_IT_BLOCK:
15509 /* Three things may happen now:
15510 a) We should increment current it block size;
15511 b) We should close current it block (closing insn or 4 insns);
15512 c) We should close current it block and start a new one (due
15513 to incompatible conditions or
15514 4 insns-length block reached). */
15515
15516 switch (inst.it_insn_type)
15517 {
15518 case OUTSIDE_IT_INSN:
15519 /* The closure of the block shall happen immediatelly,
15520 so any in_it_block () call reports the block as closed. */
15521 force_automatic_it_block_close ();
15522 break;
15523
15524 case INSIDE_IT_INSN:
15525 case INSIDE_IT_LAST_INSN:
15526 case IF_INSIDE_IT_LAST_INSN:
15527 now_it.block_length++;
15528
15529 if (now_it.block_length > 4
15530 || !now_it_compatible (inst.cond))
15531 {
15532 force_automatic_it_block_close ();
15533 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15534 new_automatic_it_block (inst.cond);
15535 }
15536 else
15537 {
15538 now_it_add_mask (inst.cond);
15539 }
15540
15541 if (now_it.state == AUTOMATIC_IT_BLOCK
15542 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15543 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15544 close_automatic_it_block ();
15545 break;
15546
15547 case NEUTRAL_IT_INSN:
15548 now_it.block_length++;
15549
15550 if (now_it.block_length > 4)
15551 force_automatic_it_block_close ();
15552 else
15553 now_it_add_mask (now_it.cc & 1);
15554 break;
15555
15556 case IT_INSN:
15557 close_automatic_it_block ();
15558 now_it.state = MANUAL_IT_BLOCK;
15559 break;
15560 }
15561 break;
15562
15563 case MANUAL_IT_BLOCK:
15564 {
15565 /* Check conditional suffixes. */
15566 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15567 int is_last;
15568 now_it.mask <<= 1;
15569 now_it.mask &= 0x1f;
15570 is_last = (now_it.mask == 0x10);
15571
15572 switch (inst.it_insn_type)
15573 {
15574 case OUTSIDE_IT_INSN:
15575 inst.error = BAD_NOT_IT;
15576 return FAIL;
15577
15578 case INSIDE_IT_INSN:
15579 if (cond != inst.cond)
15580 {
15581 inst.error = BAD_IT_COND;
15582 return FAIL;
15583 }
15584 break;
15585
15586 case INSIDE_IT_LAST_INSN:
15587 case IF_INSIDE_IT_LAST_INSN:
15588 if (cond != inst.cond)
15589 {
15590 inst.error = BAD_IT_COND;
15591 return FAIL;
15592 }
15593 if (!is_last)
15594 {
15595 inst.error = BAD_BRANCH;
15596 return FAIL;
15597 }
15598 break;
15599
15600 case NEUTRAL_IT_INSN:
15601 /* The BKPT instruction is unconditional even in an IT block. */
15602 break;
15603
15604 case IT_INSN:
15605 inst.error = BAD_IT_IT;
15606 return FAIL;
15607 }
15608 }
15609 break;
15610 }
15611
15612 return SUCCESS;
15613 }
15614
15615 static void
15616 it_fsm_post_encode (void)
15617 {
15618 int is_last;
15619
15620 if (!now_it.state_handled)
15621 handle_it_state ();
15622
15623 is_last = (now_it.mask == 0x10);
15624 if (is_last)
15625 {
15626 now_it.state = OUTSIDE_IT_BLOCK;
15627 now_it.mask = 0;
15628 }
15629 }
15630
15631 static void
15632 force_automatic_it_block_close (void)
15633 {
15634 if (now_it.state == AUTOMATIC_IT_BLOCK)
15635 {
15636 close_automatic_it_block ();
15637 now_it.state = OUTSIDE_IT_BLOCK;
15638 now_it.mask = 0;
15639 }
15640 }
15641
15642 static int
15643 in_it_block (void)
15644 {
15645 if (!now_it.state_handled)
15646 handle_it_state ();
15647
15648 return now_it.state != OUTSIDE_IT_BLOCK;
15649 }
15650
15651 void
15652 md_assemble (char *str)
15653 {
15654 char *p = str;
15655 const struct asm_opcode * opcode;
15656
15657 /* Align the previous label if needed. */
15658 if (last_label_seen != NULL)
15659 {
15660 symbol_set_frag (last_label_seen, frag_now);
15661 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15662 S_SET_SEGMENT (last_label_seen, now_seg);
15663 }
15664
15665 memset (&inst, '\0', sizeof (inst));
15666 inst.reloc.type = BFD_RELOC_UNUSED;
15667
15668 opcode = opcode_lookup (&p);
15669 if (!opcode)
15670 {
15671 /* It wasn't an instruction, but it might be a register alias of
15672 the form alias .req reg, or a Neon .dn/.qn directive. */
15673 if (! create_register_alias (str, p)
15674 && ! create_neon_reg_alias (str, p))
15675 as_bad (_("bad instruction `%s'"), str);
15676
15677 return;
15678 }
15679
15680 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
15681 as_warn (_("s suffix on comparison instruction is deprecated"));
15682
15683 /* The value which unconditional instructions should have in place of the
15684 condition field. */
15685 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15686
15687 if (thumb_mode)
15688 {
15689 arm_feature_set variant;
15690
15691 variant = cpu_variant;
15692 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
15693 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15694 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
15695 /* Check that this instruction is supported for this CPU. */
15696 if (!opcode->tvariant
15697 || (thumb_mode == 1
15698 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
15699 {
15700 as_bad (_("selected processor does not support `%s'"), str);
15701 return;
15702 }
15703 if (inst.cond != COND_ALWAYS && !unified_syntax
15704 && opcode->tencode != do_t_branch)
15705 {
15706 as_bad (_("Thumb does not support conditional execution"));
15707 return;
15708 }
15709
15710 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
15711 {
15712 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
15713 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15714 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15715 {
15716 /* Two things are addressed here.
15717 1) Implicit require narrow instructions on Thumb-1.
15718 This avoids relaxation accidentally introducing Thumb-2
15719 instructions.
15720 2) Reject wide instructions in non Thumb-2 cores. */
15721 if (inst.size_req == 0)
15722 inst.size_req = 2;
15723 else if (inst.size_req == 4)
15724 {
15725 as_bad (_("selected processor does not support `%s'"), str);
15726 return;
15727 }
15728 }
15729 }
15730
15731 inst.instruction = opcode->tvalue;
15732
15733 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
15734 {
15735 /* Prepare the it_insn_type for those encodings that don't set
15736 it. */
15737 it_fsm_pre_encode ();
15738
15739 opcode->tencode ();
15740
15741 it_fsm_post_encode ();
15742 }
15743
15744 if (!(inst.error || inst.relax))
15745 {
15746 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
15747 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15748 if (inst.size_req && inst.size_req != inst.size)
15749 {
15750 as_bad (_("cannot honor width suffix -- `%s'"), str);
15751 return;
15752 }
15753 }
15754
15755 /* Something has gone badly wrong if we try to relax a fixed size
15756 instruction. */
15757 gas_assert (inst.size_req == 0 || !inst.relax);
15758
15759 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15760 *opcode->tvariant);
15761 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
15762 set those bits when Thumb-2 32-bit instructions are seen. ie.
15763 anything other than bl/blx and v6-M instructions.
15764 This is overly pessimistic for relaxable instructions. */
15765 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15766 || inst.relax)
15767 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15768 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
15769 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15770 arm_ext_v6t2);
15771
15772 check_neon_suffixes;
15773
15774 if (!inst.error)
15775 {
15776 mapping_state (MAP_THUMB);
15777 }
15778 }
15779 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
15780 {
15781 bfd_boolean is_bx;
15782
15783 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15784 is_bx = (opcode->aencode == do_bx);
15785
15786 /* Check that this instruction is supported for this CPU. */
15787 if (!(is_bx && fix_v4bx)
15788 && !(opcode->avariant &&
15789 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
15790 {
15791 as_bad (_("selected processor does not support `%s'"), str);
15792 return;
15793 }
15794 if (inst.size_req)
15795 {
15796 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15797 return;
15798 }
15799
15800 inst.instruction = opcode->avalue;
15801 if (opcode->tag == OT_unconditionalF)
15802 inst.instruction |= 0xF << 28;
15803 else
15804 inst.instruction |= inst.cond << 28;
15805 inst.size = INSN_SIZE;
15806 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
15807 {
15808 it_fsm_pre_encode ();
15809 opcode->aencode ();
15810 it_fsm_post_encode ();
15811 }
15812 /* Arm mode bx is marked as both v4T and v5 because it's still required
15813 on a hypothetical non-thumb v5 core. */
15814 if (is_bx)
15815 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
15816 else
15817 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15818 *opcode->avariant);
15819
15820 check_neon_suffixes;
15821
15822 if (!inst.error)
15823 {
15824 mapping_state (MAP_ARM);
15825 }
15826 }
15827 else
15828 {
15829 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15830 "-- `%s'"), str);
15831 return;
15832 }
15833 output_inst (str);
15834 }
15835
15836 static void
15837 check_it_blocks_finished (void)
15838 {
15839 #ifdef OBJ_ELF
15840 asection *sect;
15841
15842 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15843 if (seg_info (sect)->tc_segment_info_data.current_it.state
15844 == MANUAL_IT_BLOCK)
15845 {
15846 as_warn (_("section '%s' finished with an open IT block."),
15847 sect->name);
15848 }
15849 #else
15850 if (now_it.state == MANUAL_IT_BLOCK)
15851 as_warn (_("file finished with an open IT block."));
15852 #endif
15853 }
15854
15855 /* Various frobbings of labels and their addresses. */
15856
15857 void
15858 arm_start_line_hook (void)
15859 {
15860 last_label_seen = NULL;
15861 }
15862
15863 void
15864 arm_frob_label (symbolS * sym)
15865 {
15866 last_label_seen = sym;
15867
15868 ARM_SET_THUMB (sym, thumb_mode);
15869
15870 #if defined OBJ_COFF || defined OBJ_ELF
15871 ARM_SET_INTERWORK (sym, support_interwork);
15872 #endif
15873
15874 force_automatic_it_block_close ();
15875
15876 /* Note - do not allow local symbols (.Lxxx) to be labelled
15877 as Thumb functions. This is because these labels, whilst
15878 they exist inside Thumb code, are not the entry points for
15879 possible ARM->Thumb calls. Also, these labels can be used
15880 as part of a computed goto or switch statement. eg gcc
15881 can generate code that looks like this:
15882
15883 ldr r2, [pc, .Laaa]
15884 lsl r3, r3, #2
15885 ldr r2, [r3, r2]
15886 mov pc, r2
15887
15888 .Lbbb: .word .Lxxx
15889 .Lccc: .word .Lyyy
15890 ..etc...
15891 .Laaa: .word Lbbb
15892
15893 The first instruction loads the address of the jump table.
15894 The second instruction converts a table index into a byte offset.
15895 The third instruction gets the jump address out of the table.
15896 The fourth instruction performs the jump.
15897
15898 If the address stored at .Laaa is that of a symbol which has the
15899 Thumb_Func bit set, then the linker will arrange for this address
15900 to have the bottom bit set, which in turn would mean that the
15901 address computation performed by the third instruction would end
15902 up with the bottom bit set. Since the ARM is capable of unaligned
15903 word loads, the instruction would then load the incorrect address
15904 out of the jump table, and chaos would ensue. */
15905 if (label_is_thumb_function_name
15906 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15907 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
15908 {
15909 /* When the address of a Thumb function is taken the bottom
15910 bit of that address should be set. This will allow
15911 interworking between Arm and Thumb functions to work
15912 correctly. */
15913
15914 THUMB_SET_FUNC (sym, 1);
15915
15916 label_is_thumb_function_name = FALSE;
15917 }
15918
15919 dwarf2_emit_label (sym);
15920 }
15921
15922 bfd_boolean
15923 arm_data_in_code (void)
15924 {
15925 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
15926 {
15927 *input_line_pointer = '/';
15928 input_line_pointer += 5;
15929 *input_line_pointer = 0;
15930 return TRUE;
15931 }
15932
15933 return FALSE;
15934 }
15935
15936 char *
15937 arm_canonicalize_symbol_name (char * name)
15938 {
15939 int len;
15940
15941 if (thumb_mode && (len = strlen (name)) > 5
15942 && streq (name + len - 5, "/data"))
15943 *(name + len - 5) = 0;
15944
15945 return name;
15946 }
15947 \f
15948 /* Table of all register names defined by default. The user can
15949 define additional names with .req. Note that all register names
15950 should appear in both upper and lowercase variants. Some registers
15951 also have mixed-case names. */
15952
15953 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
15954 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
15955 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
15956 #define REGSET(p,t) \
15957 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15958 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15959 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15960 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
15961 #define REGSETH(p,t) \
15962 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15963 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15964 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15965 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15966 #define REGSET2(p,t) \
15967 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15968 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15969 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15970 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
15971
15972 static const struct reg_entry reg_names[] =
15973 {
15974 /* ARM integer registers. */
15975 REGSET(r, RN), REGSET(R, RN),
15976
15977 /* ATPCS synonyms. */
15978 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15979 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
15980 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
15981
15982 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
15983 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
15984 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
15985
15986 /* Well-known aliases. */
15987 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
15988 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
15989
15990 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
15991 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
15992
15993 /* Coprocessor numbers. */
15994 REGSET(p, CP), REGSET(P, CP),
15995
15996 /* Coprocessor register numbers. The "cr" variants are for backward
15997 compatibility. */
15998 REGSET(c, CN), REGSET(C, CN),
15999 REGSET(cr, CN), REGSET(CR, CN),
16000
16001 /* FPA registers. */
16002 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16003 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16004
16005 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16006 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16007
16008 /* VFP SP registers. */
16009 REGSET(s,VFS), REGSET(S,VFS),
16010 REGSETH(s,VFS), REGSETH(S,VFS),
16011
16012 /* VFP DP Registers. */
16013 REGSET(d,VFD), REGSET(D,VFD),
16014 /* Extra Neon DP registers. */
16015 REGSETH(d,VFD), REGSETH(D,VFD),
16016
16017 /* Neon QP registers. */
16018 REGSET2(q,NQ), REGSET2(Q,NQ),
16019
16020 /* VFP control registers. */
16021 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16022 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
16023 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16024 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16025 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16026 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
16027
16028 /* Maverick DSP coprocessor registers. */
16029 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16030 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16031
16032 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16033 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16034 REGDEF(dspsc,0,DSPSC),
16035
16036 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16037 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16038 REGDEF(DSPSC,0,DSPSC),
16039
16040 /* iWMMXt data registers - p0, c0-15. */
16041 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16042
16043 /* iWMMXt control registers - p1, c0-3. */
16044 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16045 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16046 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16047 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16048
16049 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16050 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16051 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16052 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16053 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16054
16055 /* XScale accumulator registers. */
16056 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16057 };
16058 #undef REGDEF
16059 #undef REGNUM
16060 #undef REGSET
16061
16062 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16063 within psr_required_here. */
16064 static const struct asm_psr psrs[] =
16065 {
16066 /* Backward compatibility notation. Note that "all" is no longer
16067 truly all possible PSR bits. */
16068 {"all", PSR_c | PSR_f},
16069 {"flg", PSR_f},
16070 {"ctl", PSR_c},
16071
16072 /* Individual flags. */
16073 {"f", PSR_f},
16074 {"c", PSR_c},
16075 {"x", PSR_x},
16076 {"s", PSR_s},
16077 /* Combinations of flags. */
16078 {"fs", PSR_f | PSR_s},
16079 {"fx", PSR_f | PSR_x},
16080 {"fc", PSR_f | PSR_c},
16081 {"sf", PSR_s | PSR_f},
16082 {"sx", PSR_s | PSR_x},
16083 {"sc", PSR_s | PSR_c},
16084 {"xf", PSR_x | PSR_f},
16085 {"xs", PSR_x | PSR_s},
16086 {"xc", PSR_x | PSR_c},
16087 {"cf", PSR_c | PSR_f},
16088 {"cs", PSR_c | PSR_s},
16089 {"cx", PSR_c | PSR_x},
16090 {"fsx", PSR_f | PSR_s | PSR_x},
16091 {"fsc", PSR_f | PSR_s | PSR_c},
16092 {"fxs", PSR_f | PSR_x | PSR_s},
16093 {"fxc", PSR_f | PSR_x | PSR_c},
16094 {"fcs", PSR_f | PSR_c | PSR_s},
16095 {"fcx", PSR_f | PSR_c | PSR_x},
16096 {"sfx", PSR_s | PSR_f | PSR_x},
16097 {"sfc", PSR_s | PSR_f | PSR_c},
16098 {"sxf", PSR_s | PSR_x | PSR_f},
16099 {"sxc", PSR_s | PSR_x | PSR_c},
16100 {"scf", PSR_s | PSR_c | PSR_f},
16101 {"scx", PSR_s | PSR_c | PSR_x},
16102 {"xfs", PSR_x | PSR_f | PSR_s},
16103 {"xfc", PSR_x | PSR_f | PSR_c},
16104 {"xsf", PSR_x | PSR_s | PSR_f},
16105 {"xsc", PSR_x | PSR_s | PSR_c},
16106 {"xcf", PSR_x | PSR_c | PSR_f},
16107 {"xcs", PSR_x | PSR_c | PSR_s},
16108 {"cfs", PSR_c | PSR_f | PSR_s},
16109 {"cfx", PSR_c | PSR_f | PSR_x},
16110 {"csf", PSR_c | PSR_s | PSR_f},
16111 {"csx", PSR_c | PSR_s | PSR_x},
16112 {"cxf", PSR_c | PSR_x | PSR_f},
16113 {"cxs", PSR_c | PSR_x | PSR_s},
16114 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16115 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16116 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16117 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16118 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16119 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16120 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16121 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16122 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16123 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16124 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16125 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16126 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16127 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16128 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16129 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16130 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16131 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16132 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16133 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16134 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16135 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16136 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16137 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16138 };
16139
16140 /* Table of V7M psr names. */
16141 static const struct asm_psr v7m_psrs[] =
16142 {
16143 {"apsr", 0 }, {"APSR", 0 },
16144 {"iapsr", 1 }, {"IAPSR", 1 },
16145 {"eapsr", 2 }, {"EAPSR", 2 },
16146 {"psr", 3 }, {"PSR", 3 },
16147 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16148 {"ipsr", 5 }, {"IPSR", 5 },
16149 {"epsr", 6 }, {"EPSR", 6 },
16150 {"iepsr", 7 }, {"IEPSR", 7 },
16151 {"msp", 8 }, {"MSP", 8 },
16152 {"psp", 9 }, {"PSP", 9 },
16153 {"primask", 16}, {"PRIMASK", 16},
16154 {"basepri", 17}, {"BASEPRI", 17},
16155 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16156 {"faultmask", 19}, {"FAULTMASK", 19},
16157 {"control", 20}, {"CONTROL", 20}
16158 };
16159
16160 /* Table of all shift-in-operand names. */
16161 static const struct asm_shift_name shift_names [] =
16162 {
16163 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16164 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16165 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16166 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16167 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16168 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16169 };
16170
16171 /* Table of all explicit relocation names. */
16172 #ifdef OBJ_ELF
16173 static struct reloc_entry reloc_names[] =
16174 {
16175 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16176 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16177 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16178 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16179 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16180 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16181 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16182 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16183 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16184 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16185 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
16186 };
16187 #endif
16188
16189 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
16190 static const struct asm_cond conds[] =
16191 {
16192 {"eq", 0x0},
16193 {"ne", 0x1},
16194 {"cs", 0x2}, {"hs", 0x2},
16195 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16196 {"mi", 0x4},
16197 {"pl", 0x5},
16198 {"vs", 0x6},
16199 {"vc", 0x7},
16200 {"hi", 0x8},
16201 {"ls", 0x9},
16202 {"ge", 0xa},
16203 {"lt", 0xb},
16204 {"gt", 0xc},
16205 {"le", 0xd},
16206 {"al", 0xe}
16207 };
16208
16209 static struct asm_barrier_opt barrier_opt_names[] =
16210 {
16211 { "sy", 0xf },
16212 { "un", 0x7 },
16213 { "st", 0xe },
16214 { "unst", 0x6 }
16215 };
16216
16217 /* Table of ARM-format instructions. */
16218
16219 /* Macros for gluing together operand strings. N.B. In all cases
16220 other than OPS0, the trailing OP_stop comes from default
16221 zero-initialization of the unspecified elements of the array. */
16222 #define OPS0() { OP_stop, }
16223 #define OPS1(a) { OP_##a, }
16224 #define OPS2(a,b) { OP_##a,OP_##b, }
16225 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16226 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16227 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16228 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16229
16230 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16231 This is useful when mixing operands for ARM and THUMB, i.e. using the
16232 MIX_ARM_THUMB_OPERANDS macro.
16233 In order to use these macros, prefix the number of operands with _
16234 e.g. _3. */
16235 #define OPS_1(a) { a, }
16236 #define OPS_2(a,b) { a,b, }
16237 #define OPS_3(a,b,c) { a,b,c, }
16238 #define OPS_4(a,b,c,d) { a,b,c,d, }
16239 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16240 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16241
16242 /* These macros abstract out the exact format of the mnemonic table and
16243 save some repeated characters. */
16244
16245 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16246 #define TxCE(mnem, op, top, nops, ops, ae, te) \
16247 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
16248 THUMB_VARIANT, do_##ae, do_##te }
16249
16250 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16251 a T_MNEM_xyz enumerator. */
16252 #define TCE(mnem, aop, top, nops, ops, ae, te) \
16253 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
16254 #define tCE(mnem, aop, top, nops, ops, ae, te) \
16255 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16256
16257 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16258 infix after the third character. */
16259 #define TxC3(mnem, op, top, nops, ops, ae, te) \
16260 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
16261 THUMB_VARIANT, do_##ae, do_##te }
16262 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
16263 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
16264 THUMB_VARIANT, do_##ae, do_##te }
16265 #define TC3(mnem, aop, top, nops, ops, ae, te) \
16266 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
16267 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
16268 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
16269 #define tC3(mnem, aop, top, nops, ops, ae, te) \
16270 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16271 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
16272 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16273
16274 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16275 appear in the condition table. */
16276 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
16277 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16278 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
16279
16280 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
16281 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16282 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16283 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16284 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16285 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16286 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16287 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16288 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16289 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16290 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16291 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16292 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16293 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16294 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16295 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16296 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16297 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16298 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16299 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
16300
16301 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
16302 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16303 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
16304 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
16305
16306 /* Mnemonic that cannot be conditionalized. The ARM condition-code
16307 field is still 0xE. Many of the Thumb variants can be executed
16308 conditionally, so this is checked separately. */
16309 #define TUE(mnem, op, top, nops, ops, ae, te) \
16310 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
16311 THUMB_VARIANT, do_##ae, do_##te }
16312
16313 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16314 condition code field. */
16315 #define TUF(mnem, op, top, nops, ops, ae, te) \
16316 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
16317 THUMB_VARIANT, do_##ae, do_##te }
16318
16319 /* ARM-only variants of all the above. */
16320 #define CE(mnem, op, nops, ops, ae) \
16321 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16322
16323 #define C3(mnem, op, nops, ops, ae) \
16324 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16325
16326 /* Legacy mnemonics that always have conditional infix after the third
16327 character. */
16328 #define CL(mnem, op, nops, ops, ae) \
16329 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16330 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16331
16332 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16333 #define cCE(mnem, op, nops, ops, ae) \
16334 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16335
16336 /* Legacy coprocessor instructions where conditional infix and conditional
16337 suffix are ambiguous. For consistency this includes all FPA instructions,
16338 not just the potentially ambiguous ones. */
16339 #define cCL(mnem, op, nops, ops, ae) \
16340 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16341 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16342
16343 /* Coprocessor, takes either a suffix or a position-3 infix
16344 (for an FPA corner case). */
16345 #define C3E(mnem, op, nops, ops, ae) \
16346 { mnem, OPS##nops ops, OT_csuf_or_in3, \
16347 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16348
16349 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
16350 { m1 #m2 m3, OPS##nops ops, \
16351 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16352 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16353
16354 #define CM(m1, m2, op, nops, ops, ae) \
16355 xCM_ (m1, , m2, op, nops, ops, ae), \
16356 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16357 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16358 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16359 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16360 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16361 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16362 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16363 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16364 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16365 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16366 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16367 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16368 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16369 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16370 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16371 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16372 xCM_ (m1, le, m2, op, nops, ops, ae), \
16373 xCM_ (m1, al, m2, op, nops, ops, ae)
16374
16375 #define UE(mnem, op, nops, ops, ae) \
16376 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16377
16378 #define UF(mnem, op, nops, ops, ae) \
16379 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16380
16381 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
16382 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16383 use the same encoding function for each. */
16384 #define NUF(mnem, op, nops, ops, enc) \
16385 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16386 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16387
16388 /* Neon data processing, version which indirects through neon_enc_tab for
16389 the various overloaded versions of opcodes. */
16390 #define nUF(mnem, op, nops, ops, enc) \
16391 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
16392 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16393
16394 /* Neon insn with conditional suffix for the ARM version, non-overloaded
16395 version. */
16396 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
16397 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
16398 THUMB_VARIANT, do_##enc, do_##enc }
16399
16400 #define NCE(mnem, op, nops, ops, enc) \
16401 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16402
16403 #define NCEF(mnem, op, nops, ops, enc) \
16404 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16405
16406 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
16407 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
16408 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
16409 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16410
16411 #define nCE(mnem, op, nops, ops, enc) \
16412 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16413
16414 #define nCEF(mnem, op, nops, ops, enc) \
16415 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16416
16417 #define do_0 0
16418
16419 /* Thumb-only, unconditional. */
16420 #define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te)
16421
16422 static const struct asm_opcode insns[] =
16423 {
16424 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16425 #define THUMB_VARIANT &arm_ext_v4t
16426 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16427 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16428 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16429 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16430 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16431 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16432 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16433 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16434 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16435 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16436 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16437 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16438 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16439 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16440 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16441 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
16442
16443 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16444 for setting PSR flag bits. They are obsolete in V6 and do not
16445 have Thumb equivalents. */
16446 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16447 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16448 CL("tstp", 110f000, 2, (RR, SH), cmp),
16449 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16450 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16451 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16452 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16453 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16454 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16455
16456 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16457 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16458 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16459 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16460
16461 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
16462 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16463 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16464 OP_RRnpc),
16465 OP_ADDRGLDR),ldst, t_ldst),
16466 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16467
16468 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16469 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16470 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16471 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16472 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16473 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16474
16475 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16476 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16477 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16478 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
16479
16480 /* Pseudo ops. */
16481 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
16482 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
16483 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
16484
16485 /* Thumb-compatibility pseudo ops. */
16486 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16487 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16488 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16489 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16490 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16491 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16492 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16493 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16494 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16495 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16496 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16497 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
16498
16499 /* These may simplify to neg. */
16500 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16501 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16502
16503 #undef THUMB_VARIANT
16504 #define THUMB_VARIANT & arm_ext_v6
16505
16506 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
16507
16508 /* V1 instructions with no Thumb analogue prior to V6T2. */
16509 #undef THUMB_VARIANT
16510 #define THUMB_VARIANT & arm_ext_v6t2
16511
16512 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16513 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16514 CL("teqp", 130f000, 2, (RR, SH), cmp),
16515
16516 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16517 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16518 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16519 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16520
16521 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16522 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16523
16524 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16525 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16526
16527 /* V1 instructions with no Thumb analogue at all. */
16528 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
16529 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16530
16531 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16532 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16533 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16534 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16535 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16536 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16537 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16538 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16539
16540 #undef ARM_VARIANT
16541 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16542 #undef THUMB_VARIANT
16543 #define THUMB_VARIANT & arm_ext_v4t
16544
16545 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16546 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16547
16548 #undef THUMB_VARIANT
16549 #define THUMB_VARIANT & arm_ext_v6t2
16550
16551 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16552 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16553
16554 /* Generic coprocessor instructions. */
16555 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16556 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16557 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16558 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16559 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16560 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16561 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16562
16563 #undef ARM_VARIANT
16564 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16565
16566 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16567 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16568
16569 #undef ARM_VARIANT
16570 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16571 #undef THUMB_VARIANT
16572 #define THUMB_VARIANT & arm_ext_msr
16573
16574 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16575 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
16576
16577 #undef ARM_VARIANT
16578 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16579 #undef THUMB_VARIANT
16580 #define THUMB_VARIANT & arm_ext_v6t2
16581
16582 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16583 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16584 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16585 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16586 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16587 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16588 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16589 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16590
16591 #undef ARM_VARIANT
16592 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16593 #undef THUMB_VARIANT
16594 #define THUMB_VARIANT & arm_ext_v4t
16595
16596 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16597 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16598 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16599 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16600 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16601 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16602
16603 #undef ARM_VARIANT
16604 #define ARM_VARIANT & arm_ext_v4t_5
16605
16606 /* ARM Architecture 4T. */
16607 /* Note: bx (and blx) are required on V5, even if the processor does
16608 not support Thumb. */
16609 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
16610
16611 #undef ARM_VARIANT
16612 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16613 #undef THUMB_VARIANT
16614 #define THUMB_VARIANT & arm_ext_v5t
16615
16616 /* Note: blx has 2 variants; the .value coded here is for
16617 BLX(2). Only this variant has conditional execution. */
16618 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16619 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
16620
16621 #undef THUMB_VARIANT
16622 #define THUMB_VARIANT & arm_ext_v6t2
16623
16624 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16625 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16626 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16627 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16628 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16629 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16630 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16631 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16632
16633 #undef ARM_VARIANT
16634 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
16635 #undef THUMB_VARIANT
16636 #define THUMB_VARIANT &arm_ext_v5exp
16637
16638 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16639 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16640 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16641 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16642
16643 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16644 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16645
16646 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16647 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16648 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16649 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16650
16651 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16652 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16653 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16654 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16655
16656 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16657 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16658
16659 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16660 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16661 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16662 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16663
16664 #undef ARM_VARIANT
16665 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
16666 #undef THUMB_VARIANT
16667 #define THUMB_VARIANT &arm_ext_v6t2
16668
16669 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
16670 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16671 ldrd, t_ldstd),
16672 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16673 ADDRGLDRS), ldrd, t_ldstd),
16674
16675 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16676 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16677
16678 #undef ARM_VARIANT
16679 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16680
16681 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
16682
16683 #undef ARM_VARIANT
16684 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16685 #undef THUMB_VARIANT
16686 #define THUMB_VARIANT & arm_ext_v6
16687
16688 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16689 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16690 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16691 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16692 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16693 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16694 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16695 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16696 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16697 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
16698
16699 #undef THUMB_VARIANT
16700 #define THUMB_VARIANT & arm_ext_v6t2
16701
16702 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
16703 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16704 strex, t_strex),
16705 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16706 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16707
16708 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16709 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
16710
16711 /* ARM V6 not included in V7M. */
16712 #undef THUMB_VARIANT
16713 #define THUMB_VARIANT & arm_ext_v6_notm
16714 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16715 UF(rfeib, 9900a00, 1, (RRw), rfe),
16716 UF(rfeda, 8100a00, 1, (RRw), rfe),
16717 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16718 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16719 UF(rfefa, 9900a00, 1, (RRw), rfe),
16720 UF(rfeea, 8100a00, 1, (RRw), rfe),
16721 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16722 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16723 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16724 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16725 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
16726
16727 /* ARM V6 not included in V7M (eg. integer SIMD). */
16728 #undef THUMB_VARIANT
16729 #define THUMB_VARIANT & arm_ext_v6_dsp
16730 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16731 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16732 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16733 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16734 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16735 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16736 /* Old name for QASX. */
16737 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16738 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16739 /* Old name for QSAX. */
16740 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16741 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16742 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16743 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16744 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16745 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16746 /* Old name for SASX. */
16747 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16748 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16749 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16750 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16751 /* Old name for SHASX. */
16752 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16753 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16754 /* Old name for SHSAX. */
16755 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16756 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16757 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16758 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16759 /* Old name for SSAX. */
16760 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16761 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16762 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16763 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16764 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16765 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16766 /* Old name for UASX. */
16767 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16768 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16769 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16770 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16771 /* Old name for UHASX. */
16772 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16773 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16774 /* Old name for UHSAX. */
16775 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16776 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16777 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16778 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16779 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16780 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16781 /* Old name for UQASX. */
16782 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16783 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16784 /* Old name for UQSAX. */
16785 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16786 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16787 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16788 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16789 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16790 /* Old name for USAX. */
16791 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16792 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16793 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16794 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16795 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16796 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16797 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16798 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16799 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16800 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16801 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16802 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16803 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16804 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16805 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16806 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16807 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16808 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16809 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16810 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16811 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16812 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16813 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16814 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16815 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16816 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16817 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16818 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16819 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16820 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16821 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16822 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16823 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16824 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
16825
16826 #undef ARM_VARIANT
16827 #define ARM_VARIANT & arm_ext_v6k
16828 #undef THUMB_VARIANT
16829 #define THUMB_VARIANT & arm_ext_v6k
16830
16831 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16832 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16833 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16834 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
16835
16836 #undef THUMB_VARIANT
16837 #define THUMB_VARIANT & arm_ext_v6_notm
16838 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
16839 ldrexd, t_ldrexd),
16840 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
16841 RRnpcb), strexd, t_strexd),
16842
16843 #undef THUMB_VARIANT
16844 #define THUMB_VARIANT & arm_ext_v6t2
16845 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
16846 rd_rn, rd_rn),
16847 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
16848 rd_rn, rd_rn),
16849 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16850 strex, rm_rd_rn),
16851 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16852 strex, rm_rd_rn),
16853 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
16854
16855 #undef ARM_VARIANT
16856 #define ARM_VARIANT & arm_ext_v6z
16857
16858 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
16859
16860 #undef ARM_VARIANT
16861 #define ARM_VARIANT & arm_ext_v6t2
16862
16863 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16864 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16865 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16866 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16867
16868 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16869 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16870 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16871 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
16872
16873 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16874 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16875 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16876 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16877
16878 UT("cbnz", b900, 2, (RR, EXP), t_cbz),
16879 UT("cbz", b100, 2, (RR, EXP), t_cbz),
16880
16881 /* ARM does not really have an IT instruction, so always allow it.
16882 The opcode is copied from Thumb in order to allow warnings in
16883 -mimplicit-it=[never | arm] modes. */
16884 #undef ARM_VARIANT
16885 #define ARM_VARIANT & arm_ext_v1
16886
16887 TUE("it", bf08, bf08, 1, (COND), it, t_it),
16888 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
16889 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
16890 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
16891 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
16892 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
16893 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
16894 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
16895 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
16896 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
16897 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
16898 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
16899 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
16900 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
16901 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
16902 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
16903 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16904 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
16905
16906 /* Thumb2 only instructions. */
16907 #undef ARM_VARIANT
16908 #define ARM_VARIANT NULL
16909
16910 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16911 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16912 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16913 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16914 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
16915 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
16916
16917 /* Thumb-2 hardware division instructions (R and M profiles only). */
16918 #undef THUMB_VARIANT
16919 #define THUMB_VARIANT & arm_ext_div
16920
16921 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16922 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
16923
16924 /* ARM V6M/V7 instructions. */
16925 #undef ARM_VARIANT
16926 #define ARM_VARIANT & arm_ext_barrier
16927 #undef THUMB_VARIANT
16928 #define THUMB_VARIANT & arm_ext_barrier
16929
16930 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16931 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16932 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
16933
16934 /* ARM V7 instructions. */
16935 #undef ARM_VARIANT
16936 #define ARM_VARIANT & arm_ext_v7
16937 #undef THUMB_VARIANT
16938 #define THUMB_VARIANT & arm_ext_v7
16939
16940 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
16941 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
16942
16943 #undef ARM_VARIANT
16944 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
16945
16946 cCE("wfs", e200110, 1, (RR), rd),
16947 cCE("rfs", e300110, 1, (RR), rd),
16948 cCE("wfc", e400110, 1, (RR), rd),
16949 cCE("rfc", e500110, 1, (RR), rd),
16950
16951 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16952 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16953 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16954 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
16955
16956 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16957 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16958 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16959 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
16960
16961 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
16962 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
16963 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
16964 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
16965 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
16966 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
16967 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
16968 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
16969 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
16970 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
16971 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
16972 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
16973
16974 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
16975 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
16976 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
16977 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
16978 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
16979 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
16980 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
16981 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
16982 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
16983 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
16984 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
16985 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
16986
16987 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
16988 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
16989 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
16990 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
16991 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
16992 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
16993 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
16994 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
16995 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
16996 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
16997 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
16998 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
16999
17000 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17001 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17002 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17003 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17004 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17005 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17006 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17007 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17008 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17009 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17010 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17011 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17012
17013 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17014 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17015 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17016 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17017 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17018 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17019 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17020 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17021 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17022 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17023 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17024 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17025
17026 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17027 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17028 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17029 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17030 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17031 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17032 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17033 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17034 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17035 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17036 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17037 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17038
17039 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17040 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17041 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17042 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17043 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17044 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17045 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17046 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17047 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17048 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17049 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17050 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17051
17052 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17053 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17054 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17055 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17056 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17057 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17058 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17059 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17060 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17061 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17062 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17063 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17064
17065 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17066 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17067 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17068 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17069 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17070 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17071 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17072 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17073 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17074 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17075 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17076 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17077
17078 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17079 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17080 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17081 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17082 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17083 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17084 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17085 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17086 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17087 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17088 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17089 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17090
17091 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17092 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17093 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17094 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17095 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17096 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17097 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17098 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17099 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17100 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17101 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17102 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17103
17104 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17105 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17106 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17107 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17108 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17109 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17110 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17111 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17112 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17113 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17114 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17115 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17116
17117 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17118 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17119 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17120 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17121 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17122 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17123 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17124 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17125 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17126 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17127 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17128 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17129
17130 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17131 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17132 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17133 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17134 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17135 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17136 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17137 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17138 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17139 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17140 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17141 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17142
17143 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17144 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17145 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17146 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17147 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17148 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17149 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17150 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17151 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17152 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17153 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17154 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17155
17156 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17157 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17158 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17159 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17160 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17161 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17162 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17163 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17164 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17165 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17166 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17167 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17168
17169 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17170 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17171 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17172 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17173 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17174 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17175 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17176 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17177 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17178 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17179 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17180 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17181
17182 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17183 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17184 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17185 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17186 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17187 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17188 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17189 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17190 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17191 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17192 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17193 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17194
17195 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17196 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17197 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17198 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17199 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17200 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17201 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17202 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17203 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17204 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17205 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17206 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17207
17208 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17209 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17210 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17211 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17212 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17213 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17214 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17215 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17216 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17217 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17218 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17219 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17220
17221 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17222 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17223 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17224 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17225 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17226 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17227 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17228 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17229 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17230 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17231 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17232 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17233
17234 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17235 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17236 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17237 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17238 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17239 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17240 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17241 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17242 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17243 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17244 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17245 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17246
17247 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17248 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17249 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17250 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17251 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17252 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17253 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17254 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17255 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17256 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17257 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17258 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17259
17260 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17261 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17262 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17263 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17264 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17265 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17266 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17267 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17268 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17269 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17270 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17271 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17272
17273 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17274 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17275 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17276 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17277 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17278 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17279 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17280 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17281 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17282 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17283 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17284 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17285
17286 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17287 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17288 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17289 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17290 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17291 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17292 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17293 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17294 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17295 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17296 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17297 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17298
17299 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17300 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17301 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17302 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17303 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17304 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17305 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17306 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17307 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17308 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17309 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17310 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17311
17312 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17313 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17314 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17315 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17316 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17317 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17318 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17319 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17320 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17321 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17322 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17323 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17324
17325 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17326 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17327 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17328 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17329 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17330 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17331 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17332 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17333 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17334 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17335 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17336 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17337
17338 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17339 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17340 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17341 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17342
17343 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17344 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17345 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17346 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17347 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17348 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17349 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17350 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17351 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17352 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17353 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17354 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
17355
17356 /* The implementation of the FIX instruction is broken on some
17357 assemblers, in that it accepts a precision specifier as well as a
17358 rounding specifier, despite the fact that this is meaningless.
17359 To be more compatible, we accept it as well, though of course it
17360 does not set any bits. */
17361 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17362 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17363 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17364 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17365 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17366 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17367 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17368 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17369 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17370 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17371 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17372 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17373 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
17374
17375 /* Instructions that were new with the real FPA, call them V2. */
17376 #undef ARM_VARIANT
17377 #define ARM_VARIANT & fpu_fpa_ext_v2
17378
17379 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17380 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17381 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17382 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17383 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17384 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17385
17386 #undef ARM_VARIANT
17387 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17388
17389 /* Moves and type conversions. */
17390 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17391 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17392 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17393 cCE("fmstat", ef1fa10, 0, (), noargs),
17394 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17395 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
17396 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17397 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17398 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17399 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17400 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17401 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17402 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17403 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
17404
17405 /* Memory operations. */
17406 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17407 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17408 cCE("fldmias", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17409 cCE("fldmfds", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17410 cCE("fldmdbs", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17411 cCE("fldmeas", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17412 cCE("fldmiax", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17413 cCE("fldmfdx", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17414 cCE("fldmdbx", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17415 cCE("fldmeax", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17416 cCE("fstmias", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17417 cCE("fstmeas", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17418 cCE("fstmdbs", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17419 cCE("fstmfds", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17420 cCE("fstmiax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17421 cCE("fstmeax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17422 cCE("fstmdbx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17423 cCE("fstmfdx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17424
17425 /* Monadic operations. */
17426 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17427 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17428 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
17429
17430 /* Dyadic operations. */
17431 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17432 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17433 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17434 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17435 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17436 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17437 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17438 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17439 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17440
17441 /* Comparisons. */
17442 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17443 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17444 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17445 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
17446
17447 /* Double precision load/store are still present on single precision
17448 implementations. */
17449 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17450 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17451 cCE("fldmiad", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17452 cCE("fldmfdd", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17453 cCE("fldmdbd", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17454 cCE("fldmead", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17455 cCE("fstmiad", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17456 cCE("fstmead", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17457 cCE("fstmdbd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17458 cCE("fstmfdd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17459
17460 #undef ARM_VARIANT
17461 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17462
17463 /* Moves and type conversions. */
17464 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17465 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17466 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17467 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17468 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17469 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17470 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17471 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17472 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17473 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17474 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17475 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17476 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17477
17478 /* Monadic operations. */
17479 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17480 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17481 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17482
17483 /* Dyadic operations. */
17484 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17485 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17486 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17487 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17488 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17489 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17490 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17491 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17492 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17493
17494 /* Comparisons. */
17495 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17496 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17497 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17498 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
17499
17500 #undef ARM_VARIANT
17501 #define ARM_VARIANT & fpu_vfp_ext_v2
17502
17503 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17504 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17505 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17506 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
17507
17508 /* Instructions which may belong to either the Neon or VFP instruction sets.
17509 Individual encoder functions perform additional architecture checks. */
17510 #undef ARM_VARIANT
17511 #define ARM_VARIANT & fpu_vfp_ext_v1xd
17512 #undef THUMB_VARIANT
17513 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
17514
17515 /* These mnemonics are unique to VFP. */
17516 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17517 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
17518 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17519 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17520 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17521 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17522 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17523 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17524 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17525 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17526
17527 /* Mnemonics shared by Neon and VFP. */
17528 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17529 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17530 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17531
17532 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17533 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17534
17535 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17536 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17537
17538 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17539 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17540 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17541 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17542 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17543 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17544 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17545 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17546
17547 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17548 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
17549 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17550 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
17551
17552
17553 /* NOTE: All VMOV encoding is special-cased! */
17554 NCE(vmov, 0, 1, (VMOV), neon_mov),
17555 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17556
17557 #undef THUMB_VARIANT
17558 #define THUMB_VARIANT & fpu_neon_ext_v1
17559 #undef ARM_VARIANT
17560 #define ARM_VARIANT & fpu_neon_ext_v1
17561
17562 /* Data processing with three registers of the same length. */
17563 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17564 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17565 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17566 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17567 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17568 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17569 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17570 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17571 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17572 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17573 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17574 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17575 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17576 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17577 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17578 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17579 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17580 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17581 /* If not immediate, fall back to neon_dyadic_i64_su.
17582 shl_imm should accept I8 I16 I32 I64,
17583 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
17584 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17585 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17586 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17587 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
17588 /* Logic ops, types optional & ignored. */
17589 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17590 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17591 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17592 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17593 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17594 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17595 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17596 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17597 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17598 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
17599 /* Bitfield ops, untyped. */
17600 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17601 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17602 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17603 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17604 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17605 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17606 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
17607 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17608 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17609 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17610 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17611 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17612 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17613 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17614 back to neon_dyadic_if_su. */
17615 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17616 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17617 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17618 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17619 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17620 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17621 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17622 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17623 /* Comparison. Type I8 I16 I32 F32. */
17624 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17625 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
17626 /* As above, D registers only. */
17627 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17628 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17629 /* Int and float variants, signedness unimportant. */
17630 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17631 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17632 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
17633 /* Add/sub take types I8 I16 I32 I64 F32. */
17634 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17635 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17636 /* vtst takes sizes 8, 16, 32. */
17637 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17638 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17639 /* VMUL takes I8 I16 I32 F32 P8. */
17640 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
17641 /* VQD{R}MULH takes S16 S32. */
17642 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17643 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17644 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17645 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17646 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17647 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17648 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17649 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17650 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17651 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17652 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17653 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17654 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17655 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17656 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17657 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17658
17659 /* Two address, int/float. Types S8 S16 S32 F32. */
17660 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
17661 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17662
17663 /* Data processing with two registers and a shift amount. */
17664 /* Right shifts, and variants with rounding.
17665 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17666 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17667 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17668 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17669 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17670 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17671 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17672 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17673 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17674 /* Shift and insert. Sizes accepted 8 16 32 64. */
17675 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17676 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17677 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17678 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17679 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17680 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17681 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17682 /* Right shift immediate, saturating & narrowing, with rounding variants.
17683 Types accepted S16 S32 S64 U16 U32 U64. */
17684 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17685 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17686 /* As above, unsigned. Types accepted S16 S32 S64. */
17687 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17688 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17689 /* Right shift narrowing. Types accepted I16 I32 I64. */
17690 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17691 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17692 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
17693 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
17694 /* CVT with optional immediate for fixed-point variant. */
17695 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
17696
17697 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17698 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
17699
17700 /* Data processing, three registers of different lengths. */
17701 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17702 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17703 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17704 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17705 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17706 /* If not scalar, fall back to neon_dyadic_long.
17707 Vector types as above, scalar types S16 S32 U16 U32. */
17708 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17709 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17710 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17711 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17712 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17713 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17714 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17715 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17716 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17717 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17718 /* Saturating doubling multiplies. Types S16 S32. */
17719 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17720 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17721 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17722 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17723 S16 S32 U16 U32. */
17724 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
17725
17726 /* Extract. Size 8. */
17727 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17728 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
17729
17730 /* Two registers, miscellaneous. */
17731 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17732 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17733 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17734 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17735 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17736 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17737 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17738 /* Vector replicate. Sizes 8 16 32. */
17739 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17740 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
17741 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17742 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17743 /* VMOVN. Types I16 I32 I64. */
17744 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
17745 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
17746 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
17747 /* VQMOVUN. Types S16 S32 S64. */
17748 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
17749 /* VZIP / VUZP. Sizes 8 16 32. */
17750 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17751 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17752 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17753 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17754 /* VQABS / VQNEG. Types S8 S16 S32. */
17755 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17756 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17757 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17758 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17759 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17760 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17761 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17762 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17763 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17764 /* Reciprocal estimates. Types U32 F32. */
17765 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17766 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17767 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17768 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17769 /* VCLS. Types S8 S16 S32. */
17770 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17771 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17772 /* VCLZ. Types I8 I16 I32. */
17773 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17774 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17775 /* VCNT. Size 8. */
17776 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17777 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17778 /* Two address, untyped. */
17779 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17780 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17781 /* VTRN. Sizes 8 16 32. */
17782 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17783 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
17784
17785 /* Table lookup. Size 8. */
17786 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17787 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17788
17789 #undef THUMB_VARIANT
17790 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17791 #undef ARM_VARIANT
17792 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17793
17794 /* Neon element/structure load/store. */
17795 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17796 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17797 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17798 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17799 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17800 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17801 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17802 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17803
17804 #undef THUMB_VARIANT
17805 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
17806 #undef ARM_VARIANT
17807 #define ARM_VARIANT &fpu_vfp_ext_v3xd
17808 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17809 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17810 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17811 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17812 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17813 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17814 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17815 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17816 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17817
17818 #undef THUMB_VARIANT
17819 #define THUMB_VARIANT & fpu_vfp_ext_v3
17820 #undef ARM_VARIANT
17821 #define ARM_VARIANT & fpu_vfp_ext_v3
17822
17823 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
17824 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17825 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17826 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17827 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17828 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17829 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17830 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17831 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17832
17833 #undef ARM_VARIANT
17834 #define ARM_VARIANT &fpu_vfp_ext_fma
17835 #undef THUMB_VARIANT
17836 #define THUMB_VARIANT &fpu_vfp_ext_fma
17837 /* Mnemonics shared by Neon and VFP. These are included in the
17838 VFP FMA variant; NEON and VFP FMA always includes the NEON
17839 FMA instructions. */
17840 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17841 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17842 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17843 the v form should always be used. */
17844 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17845 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17846 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17847 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17848 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17849 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17850
17851 #undef THUMB_VARIANT
17852 #undef ARM_VARIANT
17853 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17854
17855 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17856 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17857 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17858 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17859 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17860 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17861 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17862 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
17863
17864 #undef ARM_VARIANT
17865 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17866
17867 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17868 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17869 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17870 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17871 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17872 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17873 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17874 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17875 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17876 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17877 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17878 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17879 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17880 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17881 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17882 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17883 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17884 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17885 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
17886 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17887 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17888 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17889 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17890 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17891 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17892 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17893 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
17894 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
17895 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
17896 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
17897 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17898 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
17899 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
17900 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
17901 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
17902 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
17903 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
17904 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17905 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17906 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17907 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17908 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17909 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17910 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17911 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17912 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17913 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17914 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17915 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17916 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17917 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17918 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17919 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17920 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17921 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17922 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17923 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17924 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17925 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17926 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17927 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17928 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17929 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17930 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17931 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17932 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17933 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17934 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17935 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17936 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17937 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17938 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17939 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17940 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17941 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17942 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17943 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17944 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17945 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17946 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17947 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17948 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17949 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17950 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17951 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17952 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17953 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17954 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17955 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17956 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17957 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17958 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17959 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17960 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17961 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17962 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17963 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17964 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17965 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17966 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17967 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17968 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17969 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17970 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17971 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17972 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17973 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17974 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17975 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17976 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17977 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
17978 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17979 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17980 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17981 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17982 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17983 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17984 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17985 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17986 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17987 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17988 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17989 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17990 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17991 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17992 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17993 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17994 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17995 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17996 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17997 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17998 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17999 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18000 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18001 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18002 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18003 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18004 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18005 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18006 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18007 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18008 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18009 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18010 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18011 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18012 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18013 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18014 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18015 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18016 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18017 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18018 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18019 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18020 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18021 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18022 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18023 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18024 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18025 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18026 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18027 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18028 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
18029
18030 #undef ARM_VARIANT
18031 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18032
18033 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18034 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18035 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18036 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18037 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18038 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18039 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18040 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18041 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18042 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18043 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18044 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18045 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18046 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18047 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18048 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18049 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18050 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18051 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18052 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18053 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18054 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18055 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18056 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18057 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18058 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18059 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18060 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18061 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18062 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18063 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18064 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18065 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18066 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18067 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18068 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18069 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18070 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18071 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18072 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18073 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18074 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18075 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18076 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18077 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18078 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18079 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18080 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18081 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18082 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18083 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18084 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18085 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18086 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18087 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18088 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18089 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18090
18091 #undef ARM_VARIANT
18092 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18093
18094 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18095 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18096 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18097 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18098 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18099 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18100 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18101 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18102 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18103 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18104 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18105 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18106 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18107 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18108 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18109 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18110 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18111 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18112 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18113 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18114 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18115 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18116 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18117 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18118 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18119 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18120 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18121 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18122 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18123 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18124 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18125 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18126 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18127 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18128 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18129 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18130 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18131 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18132 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18133 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18134 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18135 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18136 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18137 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18138 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18139 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18140 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18141 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18142 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18143 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18144 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18145 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18146 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18147 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18148 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18149 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18150 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18151 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18152 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18153 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18154 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18155 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18156 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18157 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18158 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18159 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18160 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18161 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18162 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18163 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18164 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18165 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18166 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18167 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18168 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18169 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18170 };
18171 #undef ARM_VARIANT
18172 #undef THUMB_VARIANT
18173 #undef TCE
18174 #undef TCM
18175 #undef TUE
18176 #undef TUF
18177 #undef TCC
18178 #undef cCE
18179 #undef cCL
18180 #undef C3E
18181 #undef CE
18182 #undef CM
18183 #undef UE
18184 #undef UF
18185 #undef UT
18186 #undef NUF
18187 #undef nUF
18188 #undef NCE
18189 #undef nCE
18190 #undef OPS0
18191 #undef OPS1
18192 #undef OPS2
18193 #undef OPS3
18194 #undef OPS4
18195 #undef OPS5
18196 #undef OPS6
18197 #undef do_0
18198 \f
18199 /* MD interface: bits in the object file. */
18200
18201 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18202 for use in the a.out file, and stores them in the array pointed to by buf.
18203 This knows about the endian-ness of the target machine and does
18204 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18205 2 (short) and 4 (long) Floating numbers are put out as a series of
18206 LITTLENUMS (shorts, here at least). */
18207
18208 void
18209 md_number_to_chars (char * buf, valueT val, int n)
18210 {
18211 if (target_big_endian)
18212 number_to_chars_bigendian (buf, val, n);
18213 else
18214 number_to_chars_littleendian (buf, val, n);
18215 }
18216
18217 static valueT
18218 md_chars_to_number (char * buf, int n)
18219 {
18220 valueT result = 0;
18221 unsigned char * where = (unsigned char *) buf;
18222
18223 if (target_big_endian)
18224 {
18225 while (n--)
18226 {
18227 result <<= 8;
18228 result |= (*where++ & 255);
18229 }
18230 }
18231 else
18232 {
18233 while (n--)
18234 {
18235 result <<= 8;
18236 result |= (where[n] & 255);
18237 }
18238 }
18239
18240 return result;
18241 }
18242
18243 /* MD interface: Sections. */
18244
18245 /* Estimate the size of a frag before relaxing. Assume everything fits in
18246 2 bytes. */
18247
18248 int
18249 md_estimate_size_before_relax (fragS * fragp,
18250 segT segtype ATTRIBUTE_UNUSED)
18251 {
18252 fragp->fr_var = 2;
18253 return 2;
18254 }
18255
18256 /* Convert a machine dependent frag. */
18257
18258 void
18259 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18260 {
18261 unsigned long insn;
18262 unsigned long old_op;
18263 char *buf;
18264 expressionS exp;
18265 fixS *fixp;
18266 int reloc_type;
18267 int pc_rel;
18268 int opcode;
18269
18270 buf = fragp->fr_literal + fragp->fr_fix;
18271
18272 old_op = bfd_get_16(abfd, buf);
18273 if (fragp->fr_symbol)
18274 {
18275 exp.X_op = O_symbol;
18276 exp.X_add_symbol = fragp->fr_symbol;
18277 }
18278 else
18279 {
18280 exp.X_op = O_constant;
18281 }
18282 exp.X_add_number = fragp->fr_offset;
18283 opcode = fragp->fr_subtype;
18284 switch (opcode)
18285 {
18286 case T_MNEM_ldr_pc:
18287 case T_MNEM_ldr_pc2:
18288 case T_MNEM_ldr_sp:
18289 case T_MNEM_str_sp:
18290 case T_MNEM_ldr:
18291 case T_MNEM_ldrb:
18292 case T_MNEM_ldrh:
18293 case T_MNEM_str:
18294 case T_MNEM_strb:
18295 case T_MNEM_strh:
18296 if (fragp->fr_var == 4)
18297 {
18298 insn = THUMB_OP32 (opcode);
18299 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18300 {
18301 insn |= (old_op & 0x700) << 4;
18302 }
18303 else
18304 {
18305 insn |= (old_op & 7) << 12;
18306 insn |= (old_op & 0x38) << 13;
18307 }
18308 insn |= 0x00000c00;
18309 put_thumb32_insn (buf, insn);
18310 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18311 }
18312 else
18313 {
18314 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18315 }
18316 pc_rel = (opcode == T_MNEM_ldr_pc2);
18317 break;
18318 case T_MNEM_adr:
18319 if (fragp->fr_var == 4)
18320 {
18321 insn = THUMB_OP32 (opcode);
18322 insn |= (old_op & 0xf0) << 4;
18323 put_thumb32_insn (buf, insn);
18324 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18325 }
18326 else
18327 {
18328 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18329 exp.X_add_number -= 4;
18330 }
18331 pc_rel = 1;
18332 break;
18333 case T_MNEM_mov:
18334 case T_MNEM_movs:
18335 case T_MNEM_cmp:
18336 case T_MNEM_cmn:
18337 if (fragp->fr_var == 4)
18338 {
18339 int r0off = (opcode == T_MNEM_mov
18340 || opcode == T_MNEM_movs) ? 0 : 8;
18341 insn = THUMB_OP32 (opcode);
18342 insn = (insn & 0xe1ffffff) | 0x10000000;
18343 insn |= (old_op & 0x700) << r0off;
18344 put_thumb32_insn (buf, insn);
18345 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18346 }
18347 else
18348 {
18349 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18350 }
18351 pc_rel = 0;
18352 break;
18353 case T_MNEM_b:
18354 if (fragp->fr_var == 4)
18355 {
18356 insn = THUMB_OP32(opcode);
18357 put_thumb32_insn (buf, insn);
18358 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18359 }
18360 else
18361 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18362 pc_rel = 1;
18363 break;
18364 case T_MNEM_bcond:
18365 if (fragp->fr_var == 4)
18366 {
18367 insn = THUMB_OP32(opcode);
18368 insn |= (old_op & 0xf00) << 14;
18369 put_thumb32_insn (buf, insn);
18370 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18371 }
18372 else
18373 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18374 pc_rel = 1;
18375 break;
18376 case T_MNEM_add_sp:
18377 case T_MNEM_add_pc:
18378 case T_MNEM_inc_sp:
18379 case T_MNEM_dec_sp:
18380 if (fragp->fr_var == 4)
18381 {
18382 /* ??? Choose between add and addw. */
18383 insn = THUMB_OP32 (opcode);
18384 insn |= (old_op & 0xf0) << 4;
18385 put_thumb32_insn (buf, insn);
18386 if (opcode == T_MNEM_add_pc)
18387 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18388 else
18389 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18390 }
18391 else
18392 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18393 pc_rel = 0;
18394 break;
18395
18396 case T_MNEM_addi:
18397 case T_MNEM_addis:
18398 case T_MNEM_subi:
18399 case T_MNEM_subis:
18400 if (fragp->fr_var == 4)
18401 {
18402 insn = THUMB_OP32 (opcode);
18403 insn |= (old_op & 0xf0) << 4;
18404 insn |= (old_op & 0xf) << 16;
18405 put_thumb32_insn (buf, insn);
18406 if (insn & (1 << 20))
18407 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18408 else
18409 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18410 }
18411 else
18412 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18413 pc_rel = 0;
18414 break;
18415 default:
18416 abort ();
18417 }
18418 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
18419 (enum bfd_reloc_code_real) reloc_type);
18420 fixp->fx_file = fragp->fr_file;
18421 fixp->fx_line = fragp->fr_line;
18422 fragp->fr_fix += fragp->fr_var;
18423 }
18424
18425 /* Return the size of a relaxable immediate operand instruction.
18426 SHIFT and SIZE specify the form of the allowable immediate. */
18427 static int
18428 relax_immediate (fragS *fragp, int size, int shift)
18429 {
18430 offsetT offset;
18431 offsetT mask;
18432 offsetT low;
18433
18434 /* ??? Should be able to do better than this. */
18435 if (fragp->fr_symbol)
18436 return 4;
18437
18438 low = (1 << shift) - 1;
18439 mask = (1 << (shift + size)) - (1 << shift);
18440 offset = fragp->fr_offset;
18441 /* Force misaligned offsets to 32-bit variant. */
18442 if (offset & low)
18443 return 4;
18444 if (offset & ~mask)
18445 return 4;
18446 return 2;
18447 }
18448
18449 /* Get the address of a symbol during relaxation. */
18450 static addressT
18451 relaxed_symbol_addr (fragS *fragp, long stretch)
18452 {
18453 fragS *sym_frag;
18454 addressT addr;
18455 symbolS *sym;
18456
18457 sym = fragp->fr_symbol;
18458 sym_frag = symbol_get_frag (sym);
18459 know (S_GET_SEGMENT (sym) != absolute_section
18460 || sym_frag == &zero_address_frag);
18461 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18462
18463 /* If frag has yet to be reached on this pass, assume it will
18464 move by STRETCH just as we did. If this is not so, it will
18465 be because some frag between grows, and that will force
18466 another pass. */
18467
18468 if (stretch != 0
18469 && sym_frag->relax_marker != fragp->relax_marker)
18470 {
18471 fragS *f;
18472
18473 /* Adjust stretch for any alignment frag. Note that if have
18474 been expanding the earlier code, the symbol may be
18475 defined in what appears to be an earlier frag. FIXME:
18476 This doesn't handle the fr_subtype field, which specifies
18477 a maximum number of bytes to skip when doing an
18478 alignment. */
18479 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18480 {
18481 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18482 {
18483 if (stretch < 0)
18484 stretch = - ((- stretch)
18485 & ~ ((1 << (int) f->fr_offset) - 1));
18486 else
18487 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18488 if (stretch == 0)
18489 break;
18490 }
18491 }
18492 if (f != NULL)
18493 addr += stretch;
18494 }
18495
18496 return addr;
18497 }
18498
18499 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
18500 load. */
18501 static int
18502 relax_adr (fragS *fragp, asection *sec, long stretch)
18503 {
18504 addressT addr;
18505 offsetT val;
18506
18507 /* Assume worst case for symbols not known to be in the same section. */
18508 if (fragp->fr_symbol == NULL
18509 || !S_IS_DEFINED (fragp->fr_symbol)
18510 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18511 return 4;
18512
18513 val = relaxed_symbol_addr (fragp, stretch);
18514 addr = fragp->fr_address + fragp->fr_fix;
18515 addr = (addr + 4) & ~3;
18516 /* Force misaligned targets to 32-bit variant. */
18517 if (val & 3)
18518 return 4;
18519 val -= addr;
18520 if (val < 0 || val > 1020)
18521 return 4;
18522 return 2;
18523 }
18524
18525 /* Return the size of a relaxable add/sub immediate instruction. */
18526 static int
18527 relax_addsub (fragS *fragp, asection *sec)
18528 {
18529 char *buf;
18530 int op;
18531
18532 buf = fragp->fr_literal + fragp->fr_fix;
18533 op = bfd_get_16(sec->owner, buf);
18534 if ((op & 0xf) == ((op >> 4) & 0xf))
18535 return relax_immediate (fragp, 8, 0);
18536 else
18537 return relax_immediate (fragp, 3, 0);
18538 }
18539
18540
18541 /* Return the size of a relaxable branch instruction. BITS is the
18542 size of the offset field in the narrow instruction. */
18543
18544 static int
18545 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
18546 {
18547 addressT addr;
18548 offsetT val;
18549 offsetT limit;
18550
18551 /* Assume worst case for symbols not known to be in the same section. */
18552 if (!S_IS_DEFINED (fragp->fr_symbol)
18553 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18554 return 4;
18555
18556 #ifdef OBJ_ELF
18557 if (S_IS_DEFINED (fragp->fr_symbol)
18558 && ARM_IS_FUNC (fragp->fr_symbol))
18559 return 4;
18560 #endif
18561
18562 val = relaxed_symbol_addr (fragp, stretch);
18563 addr = fragp->fr_address + fragp->fr_fix + 4;
18564 val -= addr;
18565
18566 /* Offset is a signed value *2 */
18567 limit = 1 << bits;
18568 if (val >= limit || val < -limit)
18569 return 4;
18570 return 2;
18571 }
18572
18573
18574 /* Relax a machine dependent frag. This returns the amount by which
18575 the current size of the frag should change. */
18576
18577 int
18578 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
18579 {
18580 int oldsize;
18581 int newsize;
18582
18583 oldsize = fragp->fr_var;
18584 switch (fragp->fr_subtype)
18585 {
18586 case T_MNEM_ldr_pc2:
18587 newsize = relax_adr (fragp, sec, stretch);
18588 break;
18589 case T_MNEM_ldr_pc:
18590 case T_MNEM_ldr_sp:
18591 case T_MNEM_str_sp:
18592 newsize = relax_immediate (fragp, 8, 2);
18593 break;
18594 case T_MNEM_ldr:
18595 case T_MNEM_str:
18596 newsize = relax_immediate (fragp, 5, 2);
18597 break;
18598 case T_MNEM_ldrh:
18599 case T_MNEM_strh:
18600 newsize = relax_immediate (fragp, 5, 1);
18601 break;
18602 case T_MNEM_ldrb:
18603 case T_MNEM_strb:
18604 newsize = relax_immediate (fragp, 5, 0);
18605 break;
18606 case T_MNEM_adr:
18607 newsize = relax_adr (fragp, sec, stretch);
18608 break;
18609 case T_MNEM_mov:
18610 case T_MNEM_movs:
18611 case T_MNEM_cmp:
18612 case T_MNEM_cmn:
18613 newsize = relax_immediate (fragp, 8, 0);
18614 break;
18615 case T_MNEM_b:
18616 newsize = relax_branch (fragp, sec, 11, stretch);
18617 break;
18618 case T_MNEM_bcond:
18619 newsize = relax_branch (fragp, sec, 8, stretch);
18620 break;
18621 case T_MNEM_add_sp:
18622 case T_MNEM_add_pc:
18623 newsize = relax_immediate (fragp, 8, 2);
18624 break;
18625 case T_MNEM_inc_sp:
18626 case T_MNEM_dec_sp:
18627 newsize = relax_immediate (fragp, 7, 2);
18628 break;
18629 case T_MNEM_addi:
18630 case T_MNEM_addis:
18631 case T_MNEM_subi:
18632 case T_MNEM_subis:
18633 newsize = relax_addsub (fragp, sec);
18634 break;
18635 default:
18636 abort ();
18637 }
18638
18639 fragp->fr_var = newsize;
18640 /* Freeze wide instructions that are at or before the same location as
18641 in the previous pass. This avoids infinite loops.
18642 Don't freeze them unconditionally because targets may be artificially
18643 misaligned by the expansion of preceding frags. */
18644 if (stretch <= 0 && newsize > 2)
18645 {
18646 md_convert_frag (sec->owner, sec, fragp);
18647 frag_wane (fragp);
18648 }
18649
18650 return newsize - oldsize;
18651 }
18652
18653 /* Round up a section size to the appropriate boundary. */
18654
18655 valueT
18656 md_section_align (segT segment ATTRIBUTE_UNUSED,
18657 valueT size)
18658 {
18659 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18660 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18661 {
18662 /* For a.out, force the section size to be aligned. If we don't do
18663 this, BFD will align it for us, but it will not write out the
18664 final bytes of the section. This may be a bug in BFD, but it is
18665 easier to fix it here since that is how the other a.out targets
18666 work. */
18667 int align;
18668
18669 align = bfd_get_section_alignment (stdoutput, segment);
18670 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18671 }
18672 #endif
18673
18674 return size;
18675 }
18676
18677 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18678 of an rs_align_code fragment. */
18679
18680 void
18681 arm_handle_align (fragS * fragP)
18682 {
18683 static char const arm_noop[2][2][4] =
18684 {
18685 { /* ARMv1 */
18686 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18687 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18688 },
18689 { /* ARMv6k */
18690 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18691 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18692 },
18693 };
18694 static char const thumb_noop[2][2][2] =
18695 {
18696 { /* Thumb-1 */
18697 {0xc0, 0x46}, /* LE */
18698 {0x46, 0xc0}, /* BE */
18699 },
18700 { /* Thumb-2 */
18701 {0x00, 0xbf}, /* LE */
18702 {0xbf, 0x00} /* BE */
18703 }
18704 };
18705 static char const wide_thumb_noop[2][4] =
18706 { /* Wide Thumb-2 */
18707 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18708 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18709 };
18710
18711 unsigned bytes, fix, noop_size;
18712 char * p;
18713 const char * noop;
18714 const char *narrow_noop = NULL;
18715 #ifdef OBJ_ELF
18716 enum mstate state;
18717 #endif
18718
18719 if (fragP->fr_type != rs_align_code)
18720 return;
18721
18722 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18723 p = fragP->fr_literal + fragP->fr_fix;
18724 fix = 0;
18725
18726 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18727 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
18728
18729 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
18730
18731 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
18732 {
18733 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18734 {
18735 narrow_noop = thumb_noop[1][target_big_endian];
18736 noop = wide_thumb_noop[target_big_endian];
18737 }
18738 else
18739 noop = thumb_noop[0][target_big_endian];
18740 noop_size = 2;
18741 #ifdef OBJ_ELF
18742 state = MAP_THUMB;
18743 #endif
18744 }
18745 else
18746 {
18747 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18748 [target_big_endian];
18749 noop_size = 4;
18750 #ifdef OBJ_ELF
18751 state = MAP_ARM;
18752 #endif
18753 }
18754
18755 fragP->fr_var = noop_size;
18756
18757 if (bytes & (noop_size - 1))
18758 {
18759 fix = bytes & (noop_size - 1);
18760 #ifdef OBJ_ELF
18761 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18762 #endif
18763 memset (p, 0, fix);
18764 p += fix;
18765 bytes -= fix;
18766 }
18767
18768 if (narrow_noop)
18769 {
18770 if (bytes & noop_size)
18771 {
18772 /* Insert a narrow noop. */
18773 memcpy (p, narrow_noop, noop_size);
18774 p += noop_size;
18775 bytes -= noop_size;
18776 fix += noop_size;
18777 }
18778
18779 /* Use wide noops for the remainder */
18780 noop_size = 4;
18781 }
18782
18783 while (bytes >= noop_size)
18784 {
18785 memcpy (p, noop, noop_size);
18786 p += noop_size;
18787 bytes -= noop_size;
18788 fix += noop_size;
18789 }
18790
18791 fragP->fr_fix += fix;
18792 }
18793
18794 /* Called from md_do_align. Used to create an alignment
18795 frag in a code section. */
18796
18797 void
18798 arm_frag_align_code (int n, int max)
18799 {
18800 char * p;
18801
18802 /* We assume that there will never be a requirement
18803 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
18804 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
18805 {
18806 char err_msg[128];
18807
18808 sprintf (err_msg,
18809 _("alignments greater than %d bytes not supported in .text sections."),
18810 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
18811 as_fatal ("%s", err_msg);
18812 }
18813
18814 p = frag_var (rs_align_code,
18815 MAX_MEM_FOR_RS_ALIGN_CODE,
18816 1,
18817 (relax_substateT) max,
18818 (symbolS *) NULL,
18819 (offsetT) n,
18820 (char *) NULL);
18821 *p = 0;
18822 }
18823
18824 /* Perform target specific initialisation of a frag.
18825 Note - despite the name this initialisation is not done when the frag
18826 is created, but only when its type is assigned. A frag can be created
18827 and used a long time before its type is set, so beware of assuming that
18828 this initialisationis performed first. */
18829
18830 #ifndef OBJ_ELF
18831 void
18832 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18833 {
18834 /* Record whether this frag is in an ARM or a THUMB area. */
18835 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18836 }
18837
18838 #else /* OBJ_ELF is defined. */
18839 void
18840 arm_init_frag (fragS * fragP, int max_chars)
18841 {
18842 /* If the current ARM vs THUMB mode has not already
18843 been recorded into this frag then do so now. */
18844 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18845 {
18846 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18847
18848 /* Record a mapping symbol for alignment frags. We will delete this
18849 later if the alignment ends up empty. */
18850 switch (fragP->fr_type)
18851 {
18852 case rs_align:
18853 case rs_align_test:
18854 case rs_fill:
18855 mapping_state_2 (MAP_DATA, max_chars);
18856 break;
18857 case rs_align_code:
18858 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18859 break;
18860 default:
18861 break;
18862 }
18863 }
18864 }
18865
18866 /* When we change sections we need to issue a new mapping symbol. */
18867
18868 void
18869 arm_elf_change_section (void)
18870 {
18871 /* Link an unlinked unwind index table section to the .text section. */
18872 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18873 && elf_linked_to_section (now_seg) == NULL)
18874 elf_linked_to_section (now_seg) = text_section;
18875 }
18876
18877 int
18878 arm_elf_section_type (const char * str, size_t len)
18879 {
18880 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18881 return SHT_ARM_EXIDX;
18882
18883 return -1;
18884 }
18885 \f
18886 /* Code to deal with unwinding tables. */
18887
18888 static void add_unwind_adjustsp (offsetT);
18889
18890 /* Generate any deferred unwind frame offset. */
18891
18892 static void
18893 flush_pending_unwind (void)
18894 {
18895 offsetT offset;
18896
18897 offset = unwind.pending_offset;
18898 unwind.pending_offset = 0;
18899 if (offset != 0)
18900 add_unwind_adjustsp (offset);
18901 }
18902
18903 /* Add an opcode to this list for this function. Two-byte opcodes should
18904 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18905 order. */
18906
18907 static void
18908 add_unwind_opcode (valueT op, int length)
18909 {
18910 /* Add any deferred stack adjustment. */
18911 if (unwind.pending_offset)
18912 flush_pending_unwind ();
18913
18914 unwind.sp_restored = 0;
18915
18916 if (unwind.opcode_count + length > unwind.opcode_alloc)
18917 {
18918 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18919 if (unwind.opcodes)
18920 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
18921 unwind.opcode_alloc);
18922 else
18923 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
18924 }
18925 while (length > 0)
18926 {
18927 length--;
18928 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18929 op >>= 8;
18930 unwind.opcode_count++;
18931 }
18932 }
18933
18934 /* Add unwind opcodes to adjust the stack pointer. */
18935
18936 static void
18937 add_unwind_adjustsp (offsetT offset)
18938 {
18939 valueT op;
18940
18941 if (offset > 0x200)
18942 {
18943 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18944 char bytes[5];
18945 int n;
18946 valueT o;
18947
18948 /* Long form: 0xb2, uleb128. */
18949 /* This might not fit in a word so add the individual bytes,
18950 remembering the list is built in reverse order. */
18951 o = (valueT) ((offset - 0x204) >> 2);
18952 if (o == 0)
18953 add_unwind_opcode (0, 1);
18954
18955 /* Calculate the uleb128 encoding of the offset. */
18956 n = 0;
18957 while (o)
18958 {
18959 bytes[n] = o & 0x7f;
18960 o >>= 7;
18961 if (o)
18962 bytes[n] |= 0x80;
18963 n++;
18964 }
18965 /* Add the insn. */
18966 for (; n; n--)
18967 add_unwind_opcode (bytes[n - 1], 1);
18968 add_unwind_opcode (0xb2, 1);
18969 }
18970 else if (offset > 0x100)
18971 {
18972 /* Two short opcodes. */
18973 add_unwind_opcode (0x3f, 1);
18974 op = (offset - 0x104) >> 2;
18975 add_unwind_opcode (op, 1);
18976 }
18977 else if (offset > 0)
18978 {
18979 /* Short opcode. */
18980 op = (offset - 4) >> 2;
18981 add_unwind_opcode (op, 1);
18982 }
18983 else if (offset < 0)
18984 {
18985 offset = -offset;
18986 while (offset > 0x100)
18987 {
18988 add_unwind_opcode (0x7f, 1);
18989 offset -= 0x100;
18990 }
18991 op = ((offset - 4) >> 2) | 0x40;
18992 add_unwind_opcode (op, 1);
18993 }
18994 }
18995
18996 /* Finish the list of unwind opcodes for this function. */
18997 static void
18998 finish_unwind_opcodes (void)
18999 {
19000 valueT op;
19001
19002 if (unwind.fp_used)
19003 {
19004 /* Adjust sp as necessary. */
19005 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19006 flush_pending_unwind ();
19007
19008 /* After restoring sp from the frame pointer. */
19009 op = 0x90 | unwind.fp_reg;
19010 add_unwind_opcode (op, 1);
19011 }
19012 else
19013 flush_pending_unwind ();
19014 }
19015
19016
19017 /* Start an exception table entry. If idx is nonzero this is an index table
19018 entry. */
19019
19020 static void
19021 start_unwind_section (const segT text_seg, int idx)
19022 {
19023 const char * text_name;
19024 const char * prefix;
19025 const char * prefix_once;
19026 const char * group_name;
19027 size_t prefix_len;
19028 size_t text_len;
19029 char * sec_name;
19030 size_t sec_name_len;
19031 int type;
19032 int flags;
19033 int linkonce;
19034
19035 if (idx)
19036 {
19037 prefix = ELF_STRING_ARM_unwind;
19038 prefix_once = ELF_STRING_ARM_unwind_once;
19039 type = SHT_ARM_EXIDX;
19040 }
19041 else
19042 {
19043 prefix = ELF_STRING_ARM_unwind_info;
19044 prefix_once = ELF_STRING_ARM_unwind_info_once;
19045 type = SHT_PROGBITS;
19046 }
19047
19048 text_name = segment_name (text_seg);
19049 if (streq (text_name, ".text"))
19050 text_name = "";
19051
19052 if (strncmp (text_name, ".gnu.linkonce.t.",
19053 strlen (".gnu.linkonce.t.")) == 0)
19054 {
19055 prefix = prefix_once;
19056 text_name += strlen (".gnu.linkonce.t.");
19057 }
19058
19059 prefix_len = strlen (prefix);
19060 text_len = strlen (text_name);
19061 sec_name_len = prefix_len + text_len;
19062 sec_name = (char *) xmalloc (sec_name_len + 1);
19063 memcpy (sec_name, prefix, prefix_len);
19064 memcpy (sec_name + prefix_len, text_name, text_len);
19065 sec_name[prefix_len + text_len] = '\0';
19066
19067 flags = SHF_ALLOC;
19068 linkonce = 0;
19069 group_name = 0;
19070
19071 /* Handle COMDAT group. */
19072 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
19073 {
19074 group_name = elf_group_name (text_seg);
19075 if (group_name == NULL)
19076 {
19077 as_bad (_("Group section `%s' has no group signature"),
19078 segment_name (text_seg));
19079 ignore_rest_of_line ();
19080 return;
19081 }
19082 flags |= SHF_GROUP;
19083 linkonce = 1;
19084 }
19085
19086 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
19087
19088 /* Set the section link for index tables. */
19089 if (idx)
19090 elf_linked_to_section (now_seg) = text_seg;
19091 }
19092
19093
19094 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19095 personality routine data. Returns zero, or the index table value for
19096 and inline entry. */
19097
19098 static valueT
19099 create_unwind_entry (int have_data)
19100 {
19101 int size;
19102 addressT where;
19103 char *ptr;
19104 /* The current word of data. */
19105 valueT data;
19106 /* The number of bytes left in this word. */
19107 int n;
19108
19109 finish_unwind_opcodes ();
19110
19111 /* Remember the current text section. */
19112 unwind.saved_seg = now_seg;
19113 unwind.saved_subseg = now_subseg;
19114
19115 start_unwind_section (now_seg, 0);
19116
19117 if (unwind.personality_routine == NULL)
19118 {
19119 if (unwind.personality_index == -2)
19120 {
19121 if (have_data)
19122 as_bad (_("handlerdata in cantunwind frame"));
19123 return 1; /* EXIDX_CANTUNWIND. */
19124 }
19125
19126 /* Use a default personality routine if none is specified. */
19127 if (unwind.personality_index == -1)
19128 {
19129 if (unwind.opcode_count > 3)
19130 unwind.personality_index = 1;
19131 else
19132 unwind.personality_index = 0;
19133 }
19134
19135 /* Space for the personality routine entry. */
19136 if (unwind.personality_index == 0)
19137 {
19138 if (unwind.opcode_count > 3)
19139 as_bad (_("too many unwind opcodes for personality routine 0"));
19140
19141 if (!have_data)
19142 {
19143 /* All the data is inline in the index table. */
19144 data = 0x80;
19145 n = 3;
19146 while (unwind.opcode_count > 0)
19147 {
19148 unwind.opcode_count--;
19149 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19150 n--;
19151 }
19152
19153 /* Pad with "finish" opcodes. */
19154 while (n--)
19155 data = (data << 8) | 0xb0;
19156
19157 return data;
19158 }
19159 size = 0;
19160 }
19161 else
19162 /* We get two opcodes "free" in the first word. */
19163 size = unwind.opcode_count - 2;
19164 }
19165 else
19166 /* An extra byte is required for the opcode count. */
19167 size = unwind.opcode_count + 1;
19168
19169 size = (size + 3) >> 2;
19170 if (size > 0xff)
19171 as_bad (_("too many unwind opcodes"));
19172
19173 frag_align (2, 0, 0);
19174 record_alignment (now_seg, 2);
19175 unwind.table_entry = expr_build_dot ();
19176
19177 /* Allocate the table entry. */
19178 ptr = frag_more ((size << 2) + 4);
19179 where = frag_now_fix () - ((size << 2) + 4);
19180
19181 switch (unwind.personality_index)
19182 {
19183 case -1:
19184 /* ??? Should this be a PLT generating relocation? */
19185 /* Custom personality routine. */
19186 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19187 BFD_RELOC_ARM_PREL31);
19188
19189 where += 4;
19190 ptr += 4;
19191
19192 /* Set the first byte to the number of additional words. */
19193 data = size - 1;
19194 n = 3;
19195 break;
19196
19197 /* ABI defined personality routines. */
19198 case 0:
19199 /* Three opcodes bytes are packed into the first word. */
19200 data = 0x80;
19201 n = 3;
19202 break;
19203
19204 case 1:
19205 case 2:
19206 /* The size and first two opcode bytes go in the first word. */
19207 data = ((0x80 + unwind.personality_index) << 8) | size;
19208 n = 2;
19209 break;
19210
19211 default:
19212 /* Should never happen. */
19213 abort ();
19214 }
19215
19216 /* Pack the opcodes into words (MSB first), reversing the list at the same
19217 time. */
19218 while (unwind.opcode_count > 0)
19219 {
19220 if (n == 0)
19221 {
19222 md_number_to_chars (ptr, data, 4);
19223 ptr += 4;
19224 n = 4;
19225 data = 0;
19226 }
19227 unwind.opcode_count--;
19228 n--;
19229 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19230 }
19231
19232 /* Finish off the last word. */
19233 if (n < 4)
19234 {
19235 /* Pad with "finish" opcodes. */
19236 while (n--)
19237 data = (data << 8) | 0xb0;
19238
19239 md_number_to_chars (ptr, data, 4);
19240 }
19241
19242 if (!have_data)
19243 {
19244 /* Add an empty descriptor if there is no user-specified data. */
19245 ptr = frag_more (4);
19246 md_number_to_chars (ptr, 0, 4);
19247 }
19248
19249 return 0;
19250 }
19251
19252
19253 /* Initialize the DWARF-2 unwind information for this procedure. */
19254
19255 void
19256 tc_arm_frame_initial_instructions (void)
19257 {
19258 cfi_add_CFA_def_cfa (REG_SP, 0);
19259 }
19260 #endif /* OBJ_ELF */
19261
19262 /* Convert REGNAME to a DWARF-2 register number. */
19263
19264 int
19265 tc_arm_regname_to_dw2regnum (char *regname)
19266 {
19267 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
19268
19269 if (reg == FAIL)
19270 return -1;
19271
19272 return reg;
19273 }
19274
19275 #ifdef TE_PE
19276 void
19277 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
19278 {
19279 expressionS exp;
19280
19281 exp.X_op = O_secrel;
19282 exp.X_add_symbol = symbol;
19283 exp.X_add_number = 0;
19284 emit_expr (&exp, size);
19285 }
19286 #endif
19287
19288 /* MD interface: Symbol and relocation handling. */
19289
19290 /* Return the address within the segment that a PC-relative fixup is
19291 relative to. For ARM, PC-relative fixups applied to instructions
19292 are generally relative to the location of the fixup plus 8 bytes.
19293 Thumb branches are offset by 4, and Thumb loads relative to PC
19294 require special handling. */
19295
19296 long
19297 md_pcrel_from_section (fixS * fixP, segT seg)
19298 {
19299 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19300
19301 /* If this is pc-relative and we are going to emit a relocation
19302 then we just want to put out any pipeline compensation that the linker
19303 will need. Otherwise we want to use the calculated base.
19304 For WinCE we skip the bias for externals as well, since this
19305 is how the MS ARM-CE assembler behaves and we want to be compatible. */
19306 if (fixP->fx_pcrel
19307 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19308 || (arm_force_relocation (fixP)
19309 #ifdef TE_WINCE
19310 && !S_IS_EXTERNAL (fixP->fx_addsy)
19311 #endif
19312 )))
19313 base = 0;
19314
19315
19316 switch (fixP->fx_r_type)
19317 {
19318 /* PC relative addressing on the Thumb is slightly odd as the
19319 bottom two bits of the PC are forced to zero for the
19320 calculation. This happens *after* application of the
19321 pipeline offset. However, Thumb adrl already adjusts for
19322 this, so we need not do it again. */
19323 case BFD_RELOC_ARM_THUMB_ADD:
19324 return base & ~3;
19325
19326 case BFD_RELOC_ARM_THUMB_OFFSET:
19327 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19328 case BFD_RELOC_ARM_T32_ADD_PC12:
19329 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
19330 return (base + 4) & ~3;
19331
19332 /* Thumb branches are simply offset by +4. */
19333 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19334 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19335 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19336 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19337 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19338 return base + 4;
19339
19340 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19341 if (fixP->fx_addsy
19342 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19343 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19344 && ARM_IS_FUNC (fixP->fx_addsy)
19345 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19346 base = fixP->fx_where + fixP->fx_frag->fr_address;
19347 return base + 4;
19348
19349 /* BLX is like branches above, but forces the low two bits of PC to
19350 zero. */
19351 case BFD_RELOC_THUMB_PCREL_BLX:
19352 if (fixP->fx_addsy
19353 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19354 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19355 && THUMB_IS_FUNC (fixP->fx_addsy)
19356 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19357 base = fixP->fx_where + fixP->fx_frag->fr_address;
19358 return (base + 4) & ~3;
19359
19360 /* ARM mode branches are offset by +8. However, the Windows CE
19361 loader expects the relocation not to take this into account. */
19362 case BFD_RELOC_ARM_PCREL_BLX:
19363 if (fixP->fx_addsy
19364 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19365 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19366 && ARM_IS_FUNC (fixP->fx_addsy)
19367 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19368 base = fixP->fx_where + fixP->fx_frag->fr_address;
19369 return base + 8;
19370
19371 case BFD_RELOC_ARM_PCREL_CALL:
19372 if (fixP->fx_addsy
19373 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19374 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19375 && THUMB_IS_FUNC (fixP->fx_addsy)
19376 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19377 base = fixP->fx_where + fixP->fx_frag->fr_address;
19378 return base + 8;
19379
19380 case BFD_RELOC_ARM_PCREL_BRANCH:
19381 case BFD_RELOC_ARM_PCREL_JUMP:
19382 case BFD_RELOC_ARM_PLT32:
19383 #ifdef TE_WINCE
19384 /* When handling fixups immediately, because we have already
19385 discovered the value of a symbol, or the address of the frag involved
19386 we must account for the offset by +8, as the OS loader will never see the reloc.
19387 see fixup_segment() in write.c
19388 The S_IS_EXTERNAL test handles the case of global symbols.
19389 Those need the calculated base, not just the pipe compensation the linker will need. */
19390 if (fixP->fx_pcrel
19391 && fixP->fx_addsy != NULL
19392 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19393 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19394 return base + 8;
19395 return base;
19396 #else
19397 return base + 8;
19398 #endif
19399
19400
19401 /* ARM mode loads relative to PC are also offset by +8. Unlike
19402 branches, the Windows CE loader *does* expect the relocation
19403 to take this into account. */
19404 case BFD_RELOC_ARM_OFFSET_IMM:
19405 case BFD_RELOC_ARM_OFFSET_IMM8:
19406 case BFD_RELOC_ARM_HWLITERAL:
19407 case BFD_RELOC_ARM_LITERAL:
19408 case BFD_RELOC_ARM_CP_OFF_IMM:
19409 return base + 8;
19410
19411
19412 /* Other PC-relative relocations are un-offset. */
19413 default:
19414 return base;
19415 }
19416 }
19417
19418 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19419 Otherwise we have no need to default values of symbols. */
19420
19421 symbolS *
19422 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
19423 {
19424 #ifdef OBJ_ELF
19425 if (name[0] == '_' && name[1] == 'G'
19426 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19427 {
19428 if (!GOT_symbol)
19429 {
19430 if (symbol_find (name))
19431 as_bad (_("GOT already in the symbol table"));
19432
19433 GOT_symbol = symbol_new (name, undefined_section,
19434 (valueT) 0, & zero_address_frag);
19435 }
19436
19437 return GOT_symbol;
19438 }
19439 #endif
19440
19441 return NULL;
19442 }
19443
19444 /* Subroutine of md_apply_fix. Check to see if an immediate can be
19445 computed as two separate immediate values, added together. We
19446 already know that this value cannot be computed by just one ARM
19447 instruction. */
19448
19449 static unsigned int
19450 validate_immediate_twopart (unsigned int val,
19451 unsigned int * highpart)
19452 {
19453 unsigned int a;
19454 unsigned int i;
19455
19456 for (i = 0; i < 32; i += 2)
19457 if (((a = rotate_left (val, i)) & 0xff) != 0)
19458 {
19459 if (a & 0xff00)
19460 {
19461 if (a & ~ 0xffff)
19462 continue;
19463 * highpart = (a >> 8) | ((i + 24) << 7);
19464 }
19465 else if (a & 0xff0000)
19466 {
19467 if (a & 0xff000000)
19468 continue;
19469 * highpart = (a >> 16) | ((i + 16) << 7);
19470 }
19471 else
19472 {
19473 gas_assert (a & 0xff000000);
19474 * highpart = (a >> 24) | ((i + 8) << 7);
19475 }
19476
19477 return (a & 0xff) | (i << 7);
19478 }
19479
19480 return FAIL;
19481 }
19482
19483 static int
19484 validate_offset_imm (unsigned int val, int hwse)
19485 {
19486 if ((hwse && val > 255) || val > 4095)
19487 return FAIL;
19488 return val;
19489 }
19490
19491 /* Subroutine of md_apply_fix. Do those data_ops which can take a
19492 negative immediate constant by altering the instruction. A bit of
19493 a hack really.
19494 MOV <-> MVN
19495 AND <-> BIC
19496 ADC <-> SBC
19497 by inverting the second operand, and
19498 ADD <-> SUB
19499 CMP <-> CMN
19500 by negating the second operand. */
19501
19502 static int
19503 negate_data_op (unsigned long * instruction,
19504 unsigned long value)
19505 {
19506 int op, new_inst;
19507 unsigned long negated, inverted;
19508
19509 negated = encode_arm_immediate (-value);
19510 inverted = encode_arm_immediate (~value);
19511
19512 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19513 switch (op)
19514 {
19515 /* First negates. */
19516 case OPCODE_SUB: /* ADD <-> SUB */
19517 new_inst = OPCODE_ADD;
19518 value = negated;
19519 break;
19520
19521 case OPCODE_ADD:
19522 new_inst = OPCODE_SUB;
19523 value = negated;
19524 break;
19525
19526 case OPCODE_CMP: /* CMP <-> CMN */
19527 new_inst = OPCODE_CMN;
19528 value = negated;
19529 break;
19530
19531 case OPCODE_CMN:
19532 new_inst = OPCODE_CMP;
19533 value = negated;
19534 break;
19535
19536 /* Now Inverted ops. */
19537 case OPCODE_MOV: /* MOV <-> MVN */
19538 new_inst = OPCODE_MVN;
19539 value = inverted;
19540 break;
19541
19542 case OPCODE_MVN:
19543 new_inst = OPCODE_MOV;
19544 value = inverted;
19545 break;
19546
19547 case OPCODE_AND: /* AND <-> BIC */
19548 new_inst = OPCODE_BIC;
19549 value = inverted;
19550 break;
19551
19552 case OPCODE_BIC:
19553 new_inst = OPCODE_AND;
19554 value = inverted;
19555 break;
19556
19557 case OPCODE_ADC: /* ADC <-> SBC */
19558 new_inst = OPCODE_SBC;
19559 value = inverted;
19560 break;
19561
19562 case OPCODE_SBC:
19563 new_inst = OPCODE_ADC;
19564 value = inverted;
19565 break;
19566
19567 /* We cannot do anything. */
19568 default:
19569 return FAIL;
19570 }
19571
19572 if (value == (unsigned) FAIL)
19573 return FAIL;
19574
19575 *instruction &= OPCODE_MASK;
19576 *instruction |= new_inst << DATA_OP_SHIFT;
19577 return value;
19578 }
19579
19580 /* Like negate_data_op, but for Thumb-2. */
19581
19582 static unsigned int
19583 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
19584 {
19585 int op, new_inst;
19586 int rd;
19587 unsigned int negated, inverted;
19588
19589 negated = encode_thumb32_immediate (-value);
19590 inverted = encode_thumb32_immediate (~value);
19591
19592 rd = (*instruction >> 8) & 0xf;
19593 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19594 switch (op)
19595 {
19596 /* ADD <-> SUB. Includes CMP <-> CMN. */
19597 case T2_OPCODE_SUB:
19598 new_inst = T2_OPCODE_ADD;
19599 value = negated;
19600 break;
19601
19602 case T2_OPCODE_ADD:
19603 new_inst = T2_OPCODE_SUB;
19604 value = negated;
19605 break;
19606
19607 /* ORR <-> ORN. Includes MOV <-> MVN. */
19608 case T2_OPCODE_ORR:
19609 new_inst = T2_OPCODE_ORN;
19610 value = inverted;
19611 break;
19612
19613 case T2_OPCODE_ORN:
19614 new_inst = T2_OPCODE_ORR;
19615 value = inverted;
19616 break;
19617
19618 /* AND <-> BIC. TST has no inverted equivalent. */
19619 case T2_OPCODE_AND:
19620 new_inst = T2_OPCODE_BIC;
19621 if (rd == 15)
19622 value = FAIL;
19623 else
19624 value = inverted;
19625 break;
19626
19627 case T2_OPCODE_BIC:
19628 new_inst = T2_OPCODE_AND;
19629 value = inverted;
19630 break;
19631
19632 /* ADC <-> SBC */
19633 case T2_OPCODE_ADC:
19634 new_inst = T2_OPCODE_SBC;
19635 value = inverted;
19636 break;
19637
19638 case T2_OPCODE_SBC:
19639 new_inst = T2_OPCODE_ADC;
19640 value = inverted;
19641 break;
19642
19643 /* We cannot do anything. */
19644 default:
19645 return FAIL;
19646 }
19647
19648 if (value == (unsigned int)FAIL)
19649 return FAIL;
19650
19651 *instruction &= T2_OPCODE_MASK;
19652 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19653 return value;
19654 }
19655
19656 /* Read a 32-bit thumb instruction from buf. */
19657 static unsigned long
19658 get_thumb32_insn (char * buf)
19659 {
19660 unsigned long insn;
19661 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19662 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19663
19664 return insn;
19665 }
19666
19667
19668 /* We usually want to set the low bit on the address of thumb function
19669 symbols. In particular .word foo - . should have the low bit set.
19670 Generic code tries to fold the difference of two symbols to
19671 a constant. Prevent this and force a relocation when the first symbols
19672 is a thumb function. */
19673
19674 bfd_boolean
19675 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19676 {
19677 if (op == O_subtract
19678 && l->X_op == O_symbol
19679 && r->X_op == O_symbol
19680 && THUMB_IS_FUNC (l->X_add_symbol))
19681 {
19682 l->X_op = O_subtract;
19683 l->X_op_symbol = r->X_add_symbol;
19684 l->X_add_number -= r->X_add_number;
19685 return TRUE;
19686 }
19687
19688 /* Process as normal. */
19689 return FALSE;
19690 }
19691
19692 /* Encode Thumb2 unconditional branches and calls. The encoding
19693 for the 2 are identical for the immediate values. */
19694
19695 static void
19696 encode_thumb2_b_bl_offset (char * buf, offsetT value)
19697 {
19698 #define T2I1I2MASK ((1 << 13) | (1 << 11))
19699 offsetT newval;
19700 offsetT newval2;
19701 addressT S, I1, I2, lo, hi;
19702
19703 S = (value >> 24) & 0x01;
19704 I1 = (value >> 23) & 0x01;
19705 I2 = (value >> 22) & 0x01;
19706 hi = (value >> 12) & 0x3ff;
19707 lo = (value >> 1) & 0x7ff;
19708 newval = md_chars_to_number (buf, THUMB_SIZE);
19709 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19710 newval |= (S << 10) | hi;
19711 newval2 &= ~T2I1I2MASK;
19712 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19713 md_number_to_chars (buf, newval, THUMB_SIZE);
19714 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19715 }
19716
19717 void
19718 md_apply_fix (fixS * fixP,
19719 valueT * valP,
19720 segT seg)
19721 {
19722 offsetT value = * valP;
19723 offsetT newval;
19724 unsigned int newimm;
19725 unsigned long temp;
19726 int sign;
19727 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
19728
19729 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
19730
19731 /* Note whether this will delete the relocation. */
19732
19733 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19734 fixP->fx_done = 1;
19735
19736 /* On a 64-bit host, silently truncate 'value' to 32 bits for
19737 consistency with the behaviour on 32-bit hosts. Remember value
19738 for emit_reloc. */
19739 value &= 0xffffffff;
19740 value ^= 0x80000000;
19741 value -= 0x80000000;
19742
19743 *valP = value;
19744 fixP->fx_addnumber = value;
19745
19746 /* Same treatment for fixP->fx_offset. */
19747 fixP->fx_offset &= 0xffffffff;
19748 fixP->fx_offset ^= 0x80000000;
19749 fixP->fx_offset -= 0x80000000;
19750
19751 switch (fixP->fx_r_type)
19752 {
19753 case BFD_RELOC_NONE:
19754 /* This will need to go in the object file. */
19755 fixP->fx_done = 0;
19756 break;
19757
19758 case BFD_RELOC_ARM_IMMEDIATE:
19759 /* We claim that this fixup has been processed here,
19760 even if in fact we generate an error because we do
19761 not have a reloc for it, so tc_gen_reloc will reject it. */
19762 fixP->fx_done = 1;
19763
19764 if (fixP->fx_addsy
19765 && ! S_IS_DEFINED (fixP->fx_addsy))
19766 {
19767 as_bad_where (fixP->fx_file, fixP->fx_line,
19768 _("undefined symbol %s used as an immediate value"),
19769 S_GET_NAME (fixP->fx_addsy));
19770 break;
19771 }
19772
19773 if (fixP->fx_addsy
19774 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19775 {
19776 as_bad_where (fixP->fx_file, fixP->fx_line,
19777 _("symbol %s is in a different section"),
19778 S_GET_NAME (fixP->fx_addsy));
19779 break;
19780 }
19781
19782 newimm = encode_arm_immediate (value);
19783 temp = md_chars_to_number (buf, INSN_SIZE);
19784
19785 /* If the instruction will fail, see if we can fix things up by
19786 changing the opcode. */
19787 if (newimm == (unsigned int) FAIL
19788 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
19789 {
19790 as_bad_where (fixP->fx_file, fixP->fx_line,
19791 _("invalid constant (%lx) after fixup"),
19792 (unsigned long) value);
19793 break;
19794 }
19795
19796 newimm |= (temp & 0xfffff000);
19797 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19798 break;
19799
19800 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19801 {
19802 unsigned int highpart = 0;
19803 unsigned int newinsn = 0xe1a00000; /* nop. */
19804
19805 if (fixP->fx_addsy
19806 && ! S_IS_DEFINED (fixP->fx_addsy))
19807 {
19808 as_bad_where (fixP->fx_file, fixP->fx_line,
19809 _("undefined symbol %s used as an immediate value"),
19810 S_GET_NAME (fixP->fx_addsy));
19811 break;
19812 }
19813
19814 if (fixP->fx_addsy
19815 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19816 {
19817 as_bad_where (fixP->fx_file, fixP->fx_line,
19818 _("symbol %s is in a different section"),
19819 S_GET_NAME (fixP->fx_addsy));
19820 break;
19821 }
19822
19823 newimm = encode_arm_immediate (value);
19824 temp = md_chars_to_number (buf, INSN_SIZE);
19825
19826 /* If the instruction will fail, see if we can fix things up by
19827 changing the opcode. */
19828 if (newimm == (unsigned int) FAIL
19829 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19830 {
19831 /* No ? OK - try using two ADD instructions to generate
19832 the value. */
19833 newimm = validate_immediate_twopart (value, & highpart);
19834
19835 /* Yes - then make sure that the second instruction is
19836 also an add. */
19837 if (newimm != (unsigned int) FAIL)
19838 newinsn = temp;
19839 /* Still No ? Try using a negated value. */
19840 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19841 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19842 /* Otherwise - give up. */
19843 else
19844 {
19845 as_bad_where (fixP->fx_file, fixP->fx_line,
19846 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19847 (long) value);
19848 break;
19849 }
19850
19851 /* Replace the first operand in the 2nd instruction (which
19852 is the PC) with the destination register. We have
19853 already added in the PC in the first instruction and we
19854 do not want to do it again. */
19855 newinsn &= ~ 0xf0000;
19856 newinsn |= ((newinsn & 0x0f000) << 4);
19857 }
19858
19859 newimm |= (temp & 0xfffff000);
19860 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19861
19862 highpart |= (newinsn & 0xfffff000);
19863 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19864 }
19865 break;
19866
19867 case BFD_RELOC_ARM_OFFSET_IMM:
19868 if (!fixP->fx_done && seg->use_rela_p)
19869 value = 0;
19870
19871 case BFD_RELOC_ARM_LITERAL:
19872 sign = value >= 0;
19873
19874 if (value < 0)
19875 value = - value;
19876
19877 if (validate_offset_imm (value, 0) == FAIL)
19878 {
19879 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19880 as_bad_where (fixP->fx_file, fixP->fx_line,
19881 _("invalid literal constant: pool needs to be closer"));
19882 else
19883 as_bad_where (fixP->fx_file, fixP->fx_line,
19884 _("bad immediate value for offset (%ld)"),
19885 (long) value);
19886 break;
19887 }
19888
19889 newval = md_chars_to_number (buf, INSN_SIZE);
19890 newval &= 0xff7ff000;
19891 newval |= value | (sign ? INDEX_UP : 0);
19892 md_number_to_chars (buf, newval, INSN_SIZE);
19893 break;
19894
19895 case BFD_RELOC_ARM_OFFSET_IMM8:
19896 case BFD_RELOC_ARM_HWLITERAL:
19897 sign = value >= 0;
19898
19899 if (value < 0)
19900 value = - value;
19901
19902 if (validate_offset_imm (value, 1) == FAIL)
19903 {
19904 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19905 as_bad_where (fixP->fx_file, fixP->fx_line,
19906 _("invalid literal constant: pool needs to be closer"));
19907 else
19908 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
19909 (long) value);
19910 break;
19911 }
19912
19913 newval = md_chars_to_number (buf, INSN_SIZE);
19914 newval &= 0xff7ff0f0;
19915 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19916 md_number_to_chars (buf, newval, INSN_SIZE);
19917 break;
19918
19919 case BFD_RELOC_ARM_T32_OFFSET_U8:
19920 if (value < 0 || value > 1020 || value % 4 != 0)
19921 as_bad_where (fixP->fx_file, fixP->fx_line,
19922 _("bad immediate value for offset (%ld)"), (long) value);
19923 value /= 4;
19924
19925 newval = md_chars_to_number (buf+2, THUMB_SIZE);
19926 newval |= value;
19927 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19928 break;
19929
19930 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19931 /* This is a complicated relocation used for all varieties of Thumb32
19932 load/store instruction with immediate offset:
19933
19934 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19935 *4, optional writeback(W)
19936 (doubleword load/store)
19937
19938 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19939 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19940 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19941 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19942 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19943
19944 Uppercase letters indicate bits that are already encoded at
19945 this point. Lowercase letters are our problem. For the
19946 second block of instructions, the secondary opcode nybble
19947 (bits 8..11) is present, and bit 23 is zero, even if this is
19948 a PC-relative operation. */
19949 newval = md_chars_to_number (buf, THUMB_SIZE);
19950 newval <<= 16;
19951 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
19952
19953 if ((newval & 0xf0000000) == 0xe0000000)
19954 {
19955 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19956 if (value >= 0)
19957 newval |= (1 << 23);
19958 else
19959 value = -value;
19960 if (value % 4 != 0)
19961 {
19962 as_bad_where (fixP->fx_file, fixP->fx_line,
19963 _("offset not a multiple of 4"));
19964 break;
19965 }
19966 value /= 4;
19967 if (value > 0xff)
19968 {
19969 as_bad_where (fixP->fx_file, fixP->fx_line,
19970 _("offset out of range"));
19971 break;
19972 }
19973 newval &= ~0xff;
19974 }
19975 else if ((newval & 0x000f0000) == 0x000f0000)
19976 {
19977 /* PC-relative, 12-bit offset. */
19978 if (value >= 0)
19979 newval |= (1 << 23);
19980 else
19981 value = -value;
19982 if (value > 0xfff)
19983 {
19984 as_bad_where (fixP->fx_file, fixP->fx_line,
19985 _("offset out of range"));
19986 break;
19987 }
19988 newval &= ~0xfff;
19989 }
19990 else if ((newval & 0x00000100) == 0x00000100)
19991 {
19992 /* Writeback: 8-bit, +/- offset. */
19993 if (value >= 0)
19994 newval |= (1 << 9);
19995 else
19996 value = -value;
19997 if (value > 0xff)
19998 {
19999 as_bad_where (fixP->fx_file, fixP->fx_line,
20000 _("offset out of range"));
20001 break;
20002 }
20003 newval &= ~0xff;
20004 }
20005 else if ((newval & 0x00000f00) == 0x00000e00)
20006 {
20007 /* T-instruction: positive 8-bit offset. */
20008 if (value < 0 || value > 0xff)
20009 {
20010 as_bad_where (fixP->fx_file, fixP->fx_line,
20011 _("offset out of range"));
20012 break;
20013 }
20014 newval &= ~0xff;
20015 newval |= value;
20016 }
20017 else
20018 {
20019 /* Positive 12-bit or negative 8-bit offset. */
20020 int limit;
20021 if (value >= 0)
20022 {
20023 newval |= (1 << 23);
20024 limit = 0xfff;
20025 }
20026 else
20027 {
20028 value = -value;
20029 limit = 0xff;
20030 }
20031 if (value > limit)
20032 {
20033 as_bad_where (fixP->fx_file, fixP->fx_line,
20034 _("offset out of range"));
20035 break;
20036 }
20037 newval &= ~limit;
20038 }
20039
20040 newval |= value;
20041 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20042 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20043 break;
20044
20045 case BFD_RELOC_ARM_SHIFT_IMM:
20046 newval = md_chars_to_number (buf, INSN_SIZE);
20047 if (((unsigned long) value) > 32
20048 || (value == 32
20049 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20050 {
20051 as_bad_where (fixP->fx_file, fixP->fx_line,
20052 _("shift expression is too large"));
20053 break;
20054 }
20055
20056 if (value == 0)
20057 /* Shifts of zero must be done as lsl. */
20058 newval &= ~0x60;
20059 else if (value == 32)
20060 value = 0;
20061 newval &= 0xfffff07f;
20062 newval |= (value & 0x1f) << 7;
20063 md_number_to_chars (buf, newval, INSN_SIZE);
20064 break;
20065
20066 case BFD_RELOC_ARM_T32_IMMEDIATE:
20067 case BFD_RELOC_ARM_T32_ADD_IMM:
20068 case BFD_RELOC_ARM_T32_IMM12:
20069 case BFD_RELOC_ARM_T32_ADD_PC12:
20070 /* We claim that this fixup has been processed here,
20071 even if in fact we generate an error because we do
20072 not have a reloc for it, so tc_gen_reloc will reject it. */
20073 fixP->fx_done = 1;
20074
20075 if (fixP->fx_addsy
20076 && ! S_IS_DEFINED (fixP->fx_addsy))
20077 {
20078 as_bad_where (fixP->fx_file, fixP->fx_line,
20079 _("undefined symbol %s used as an immediate value"),
20080 S_GET_NAME (fixP->fx_addsy));
20081 break;
20082 }
20083
20084 newval = md_chars_to_number (buf, THUMB_SIZE);
20085 newval <<= 16;
20086 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
20087
20088 newimm = FAIL;
20089 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20090 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20091 {
20092 newimm = encode_thumb32_immediate (value);
20093 if (newimm == (unsigned int) FAIL)
20094 newimm = thumb32_negate_data_op (&newval, value);
20095 }
20096 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20097 && newimm == (unsigned int) FAIL)
20098 {
20099 /* Turn add/sum into addw/subw. */
20100 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20101 newval = (newval & 0xfeffffff) | 0x02000000;
20102
20103 /* 12 bit immediate for addw/subw. */
20104 if (value < 0)
20105 {
20106 value = -value;
20107 newval ^= 0x00a00000;
20108 }
20109 if (value > 0xfff)
20110 newimm = (unsigned int) FAIL;
20111 else
20112 newimm = value;
20113 }
20114
20115 if (newimm == (unsigned int)FAIL)
20116 {
20117 as_bad_where (fixP->fx_file, fixP->fx_line,
20118 _("invalid constant (%lx) after fixup"),
20119 (unsigned long) value);
20120 break;
20121 }
20122
20123 newval |= (newimm & 0x800) << 15;
20124 newval |= (newimm & 0x700) << 4;
20125 newval |= (newimm & 0x0ff);
20126
20127 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20128 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20129 break;
20130
20131 case BFD_RELOC_ARM_SMC:
20132 if (((unsigned long) value) > 0xffff)
20133 as_bad_where (fixP->fx_file, fixP->fx_line,
20134 _("invalid smc expression"));
20135 newval = md_chars_to_number (buf, INSN_SIZE);
20136 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20137 md_number_to_chars (buf, newval, INSN_SIZE);
20138 break;
20139
20140 case BFD_RELOC_ARM_SWI:
20141 if (fixP->tc_fix_data != 0)
20142 {
20143 if (((unsigned long) value) > 0xff)
20144 as_bad_where (fixP->fx_file, fixP->fx_line,
20145 _("invalid swi expression"));
20146 newval = md_chars_to_number (buf, THUMB_SIZE);
20147 newval |= value;
20148 md_number_to_chars (buf, newval, THUMB_SIZE);
20149 }
20150 else
20151 {
20152 if (((unsigned long) value) > 0x00ffffff)
20153 as_bad_where (fixP->fx_file, fixP->fx_line,
20154 _("invalid swi expression"));
20155 newval = md_chars_to_number (buf, INSN_SIZE);
20156 newval |= value;
20157 md_number_to_chars (buf, newval, INSN_SIZE);
20158 }
20159 break;
20160
20161 case BFD_RELOC_ARM_MULTI:
20162 if (((unsigned long) value) > 0xffff)
20163 as_bad_where (fixP->fx_file, fixP->fx_line,
20164 _("invalid expression in load/store multiple"));
20165 newval = value | md_chars_to_number (buf, INSN_SIZE);
20166 md_number_to_chars (buf, newval, INSN_SIZE);
20167 break;
20168
20169 #ifdef OBJ_ELF
20170 case BFD_RELOC_ARM_PCREL_CALL:
20171
20172 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20173 && fixP->fx_addsy
20174 && !S_IS_EXTERNAL (fixP->fx_addsy)
20175 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20176 && THUMB_IS_FUNC (fixP->fx_addsy))
20177 /* Flip the bl to blx. This is a simple flip
20178 bit here because we generate PCREL_CALL for
20179 unconditional bls. */
20180 {
20181 newval = md_chars_to_number (buf, INSN_SIZE);
20182 newval = newval | 0x10000000;
20183 md_number_to_chars (buf, newval, INSN_SIZE);
20184 temp = 1;
20185 fixP->fx_done = 1;
20186 }
20187 else
20188 temp = 3;
20189 goto arm_branch_common;
20190
20191 case BFD_RELOC_ARM_PCREL_JUMP:
20192 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20193 && fixP->fx_addsy
20194 && !S_IS_EXTERNAL (fixP->fx_addsy)
20195 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20196 && THUMB_IS_FUNC (fixP->fx_addsy))
20197 {
20198 /* This would map to a bl<cond>, b<cond>,
20199 b<always> to a Thumb function. We
20200 need to force a relocation for this particular
20201 case. */
20202 newval = md_chars_to_number (buf, INSN_SIZE);
20203 fixP->fx_done = 0;
20204 }
20205
20206 case BFD_RELOC_ARM_PLT32:
20207 #endif
20208 case BFD_RELOC_ARM_PCREL_BRANCH:
20209 temp = 3;
20210 goto arm_branch_common;
20211
20212 case BFD_RELOC_ARM_PCREL_BLX:
20213
20214 temp = 1;
20215 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20216 && fixP->fx_addsy
20217 && !S_IS_EXTERNAL (fixP->fx_addsy)
20218 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20219 && ARM_IS_FUNC (fixP->fx_addsy))
20220 {
20221 /* Flip the blx to a bl and warn. */
20222 const char *name = S_GET_NAME (fixP->fx_addsy);
20223 newval = 0xeb000000;
20224 as_warn_where (fixP->fx_file, fixP->fx_line,
20225 _("blx to '%s' an ARM ISA state function changed to bl"),
20226 name);
20227 md_number_to_chars (buf, newval, INSN_SIZE);
20228 temp = 3;
20229 fixP->fx_done = 1;
20230 }
20231
20232 #ifdef OBJ_ELF
20233 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20234 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20235 #endif
20236
20237 arm_branch_common:
20238 /* We are going to store value (shifted right by two) in the
20239 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20240 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20241 also be be clear. */
20242 if (value & temp)
20243 as_bad_where (fixP->fx_file, fixP->fx_line,
20244 _("misaligned branch destination"));
20245 if ((value & (offsetT)0xfe000000) != (offsetT)0
20246 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20247 as_bad_where (fixP->fx_file, fixP->fx_line,
20248 _("branch out of range"));
20249
20250 if (fixP->fx_done || !seg->use_rela_p)
20251 {
20252 newval = md_chars_to_number (buf, INSN_SIZE);
20253 newval |= (value >> 2) & 0x00ffffff;
20254 /* Set the H bit on BLX instructions. */
20255 if (temp == 1)
20256 {
20257 if (value & 2)
20258 newval |= 0x01000000;
20259 else
20260 newval &= ~0x01000000;
20261 }
20262 md_number_to_chars (buf, newval, INSN_SIZE);
20263 }
20264 break;
20265
20266 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20267 /* CBZ can only branch forward. */
20268
20269 /* Attempts to use CBZ to branch to the next instruction
20270 (which, strictly speaking, are prohibited) will be turned into
20271 no-ops.
20272
20273 FIXME: It may be better to remove the instruction completely and
20274 perform relaxation. */
20275 if (value == -2)
20276 {
20277 newval = md_chars_to_number (buf, THUMB_SIZE);
20278 newval = 0xbf00; /* NOP encoding T1 */
20279 md_number_to_chars (buf, newval, THUMB_SIZE);
20280 }
20281 else
20282 {
20283 if (value & ~0x7e)
20284 as_bad_where (fixP->fx_file, fixP->fx_line,
20285 _("branch out of range"));
20286
20287 if (fixP->fx_done || !seg->use_rela_p)
20288 {
20289 newval = md_chars_to_number (buf, THUMB_SIZE);
20290 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20291 md_number_to_chars (buf, newval, THUMB_SIZE);
20292 }
20293 }
20294 break;
20295
20296 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
20297 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20298 as_bad_where (fixP->fx_file, fixP->fx_line,
20299 _("branch out of range"));
20300
20301 if (fixP->fx_done || !seg->use_rela_p)
20302 {
20303 newval = md_chars_to_number (buf, THUMB_SIZE);
20304 newval |= (value & 0x1ff) >> 1;
20305 md_number_to_chars (buf, newval, THUMB_SIZE);
20306 }
20307 break;
20308
20309 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
20310 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20311 as_bad_where (fixP->fx_file, fixP->fx_line,
20312 _("branch out of range"));
20313
20314 if (fixP->fx_done || !seg->use_rela_p)
20315 {
20316 newval = md_chars_to_number (buf, THUMB_SIZE);
20317 newval |= (value & 0xfff) >> 1;
20318 md_number_to_chars (buf, newval, THUMB_SIZE);
20319 }
20320 break;
20321
20322 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20323 if (fixP->fx_addsy
20324 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20325 && !S_IS_EXTERNAL (fixP->fx_addsy)
20326 && S_IS_DEFINED (fixP->fx_addsy)
20327 && ARM_IS_FUNC (fixP->fx_addsy)
20328 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20329 {
20330 /* Force a relocation for a branch 20 bits wide. */
20331 fixP->fx_done = 0;
20332 }
20333 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20334 as_bad_where (fixP->fx_file, fixP->fx_line,
20335 _("conditional branch out of range"));
20336
20337 if (fixP->fx_done || !seg->use_rela_p)
20338 {
20339 offsetT newval2;
20340 addressT S, J1, J2, lo, hi;
20341
20342 S = (value & 0x00100000) >> 20;
20343 J2 = (value & 0x00080000) >> 19;
20344 J1 = (value & 0x00040000) >> 18;
20345 hi = (value & 0x0003f000) >> 12;
20346 lo = (value & 0x00000ffe) >> 1;
20347
20348 newval = md_chars_to_number (buf, THUMB_SIZE);
20349 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20350 newval |= (S << 10) | hi;
20351 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20352 md_number_to_chars (buf, newval, THUMB_SIZE);
20353 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20354 }
20355 break;
20356
20357 case BFD_RELOC_THUMB_PCREL_BLX:
20358
20359 /* If there is a blx from a thumb state function to
20360 another thumb function flip this to a bl and warn
20361 about it. */
20362
20363 if (fixP->fx_addsy
20364 && S_IS_DEFINED (fixP->fx_addsy)
20365 && !S_IS_EXTERNAL (fixP->fx_addsy)
20366 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20367 && THUMB_IS_FUNC (fixP->fx_addsy))
20368 {
20369 const char *name = S_GET_NAME (fixP->fx_addsy);
20370 as_warn_where (fixP->fx_file, fixP->fx_line,
20371 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20372 name);
20373 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20374 newval = newval | 0x1000;
20375 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20376 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20377 fixP->fx_done = 1;
20378 }
20379
20380
20381 goto thumb_bl_common;
20382
20383 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20384
20385 /* A bl from Thumb state ISA to an internal ARM state function
20386 is converted to a blx. */
20387 if (fixP->fx_addsy
20388 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20389 && !S_IS_EXTERNAL (fixP->fx_addsy)
20390 && S_IS_DEFINED (fixP->fx_addsy)
20391 && ARM_IS_FUNC (fixP->fx_addsy)
20392 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20393 {
20394 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20395 newval = newval & ~0x1000;
20396 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20397 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20398 fixP->fx_done = 1;
20399 }
20400
20401 thumb_bl_common:
20402
20403 #ifdef OBJ_ELF
20404 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20405 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20406 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20407 #endif
20408
20409 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20410 /* For a BLX instruction, make sure that the relocation is rounded up
20411 to a word boundary. This follows the semantics of the instruction
20412 which specifies that bit 1 of the target address will come from bit
20413 1 of the base address. */
20414 value = (value + 1) & ~ 1;
20415
20416
20417 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20418 {
20419 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20420 {
20421 as_bad_where (fixP->fx_file, fixP->fx_line,
20422 _("branch out of range"));
20423 }
20424 else if ((value & ~0x1ffffff)
20425 && ((value & ~0x1ffffff) != ~0x1ffffff))
20426 {
20427 as_bad_where (fixP->fx_file, fixP->fx_line,
20428 _("Thumb2 branch out of range"));
20429 }
20430 }
20431
20432 if (fixP->fx_done || !seg->use_rela_p)
20433 encode_thumb2_b_bl_offset (buf, value);
20434
20435 break;
20436
20437 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20438 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20439 as_bad_where (fixP->fx_file, fixP->fx_line,
20440 _("branch out of range"));
20441
20442 if (fixP->fx_done || !seg->use_rela_p)
20443 encode_thumb2_b_bl_offset (buf, value);
20444
20445 break;
20446
20447 case BFD_RELOC_8:
20448 if (fixP->fx_done || !seg->use_rela_p)
20449 md_number_to_chars (buf, value, 1);
20450 break;
20451
20452 case BFD_RELOC_16:
20453 if (fixP->fx_done || !seg->use_rela_p)
20454 md_number_to_chars (buf, value, 2);
20455 break;
20456
20457 #ifdef OBJ_ELF
20458 case BFD_RELOC_ARM_TLS_GD32:
20459 case BFD_RELOC_ARM_TLS_LE32:
20460 case BFD_RELOC_ARM_TLS_IE32:
20461 case BFD_RELOC_ARM_TLS_LDM32:
20462 case BFD_RELOC_ARM_TLS_LDO32:
20463 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20464 /* fall through */
20465
20466 case BFD_RELOC_ARM_GOT32:
20467 case BFD_RELOC_ARM_GOTOFF:
20468 if (fixP->fx_done || !seg->use_rela_p)
20469 md_number_to_chars (buf, 0, 4);
20470 break;
20471
20472 case BFD_RELOC_ARM_TARGET2:
20473 /* TARGET2 is not partial-inplace, so we need to write the
20474 addend here for REL targets, because it won't be written out
20475 during reloc processing later. */
20476 if (fixP->fx_done || !seg->use_rela_p)
20477 md_number_to_chars (buf, fixP->fx_offset, 4);
20478 break;
20479 #endif
20480
20481 case BFD_RELOC_RVA:
20482 case BFD_RELOC_32:
20483 case BFD_RELOC_ARM_TARGET1:
20484 case BFD_RELOC_ARM_ROSEGREL32:
20485 case BFD_RELOC_ARM_SBREL32:
20486 case BFD_RELOC_32_PCREL:
20487 #ifdef TE_PE
20488 case BFD_RELOC_32_SECREL:
20489 #endif
20490 if (fixP->fx_done || !seg->use_rela_p)
20491 #ifdef TE_WINCE
20492 /* For WinCE we only do this for pcrel fixups. */
20493 if (fixP->fx_done || fixP->fx_pcrel)
20494 #endif
20495 md_number_to_chars (buf, value, 4);
20496 break;
20497
20498 #ifdef OBJ_ELF
20499 case BFD_RELOC_ARM_PREL31:
20500 if (fixP->fx_done || !seg->use_rela_p)
20501 {
20502 newval = md_chars_to_number (buf, 4) & 0x80000000;
20503 if ((value ^ (value >> 1)) & 0x40000000)
20504 {
20505 as_bad_where (fixP->fx_file, fixP->fx_line,
20506 _("rel31 relocation overflow"));
20507 }
20508 newval |= value & 0x7fffffff;
20509 md_number_to_chars (buf, newval, 4);
20510 }
20511 break;
20512 #endif
20513
20514 case BFD_RELOC_ARM_CP_OFF_IMM:
20515 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20516 if (value < -1023 || value > 1023 || (value & 3))
20517 as_bad_where (fixP->fx_file, fixP->fx_line,
20518 _("co-processor offset out of range"));
20519 cp_off_common:
20520 sign = value >= 0;
20521 if (value < 0)
20522 value = -value;
20523 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20524 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20525 newval = md_chars_to_number (buf, INSN_SIZE);
20526 else
20527 newval = get_thumb32_insn (buf);
20528 newval &= 0xff7fff00;
20529 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
20530 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20531 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20532 md_number_to_chars (buf, newval, INSN_SIZE);
20533 else
20534 put_thumb32_insn (buf, newval);
20535 break;
20536
20537 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
20538 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
20539 if (value < -255 || value > 255)
20540 as_bad_where (fixP->fx_file, fixP->fx_line,
20541 _("co-processor offset out of range"));
20542 value *= 4;
20543 goto cp_off_common;
20544
20545 case BFD_RELOC_ARM_THUMB_OFFSET:
20546 newval = md_chars_to_number (buf, THUMB_SIZE);
20547 /* Exactly what ranges, and where the offset is inserted depends
20548 on the type of instruction, we can establish this from the
20549 top 4 bits. */
20550 switch (newval >> 12)
20551 {
20552 case 4: /* PC load. */
20553 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20554 forced to zero for these loads; md_pcrel_from has already
20555 compensated for this. */
20556 if (value & 3)
20557 as_bad_where (fixP->fx_file, fixP->fx_line,
20558 _("invalid offset, target not word aligned (0x%08lX)"),
20559 (((unsigned long) fixP->fx_frag->fr_address
20560 + (unsigned long) fixP->fx_where) & ~3)
20561 + (unsigned long) value);
20562
20563 if (value & ~0x3fc)
20564 as_bad_where (fixP->fx_file, fixP->fx_line,
20565 _("invalid offset, value too big (0x%08lX)"),
20566 (long) value);
20567
20568 newval |= value >> 2;
20569 break;
20570
20571 case 9: /* SP load/store. */
20572 if (value & ~0x3fc)
20573 as_bad_where (fixP->fx_file, fixP->fx_line,
20574 _("invalid offset, value too big (0x%08lX)"),
20575 (long) value);
20576 newval |= value >> 2;
20577 break;
20578
20579 case 6: /* Word load/store. */
20580 if (value & ~0x7c)
20581 as_bad_where (fixP->fx_file, fixP->fx_line,
20582 _("invalid offset, value too big (0x%08lX)"),
20583 (long) value);
20584 newval |= value << 4; /* 6 - 2. */
20585 break;
20586
20587 case 7: /* Byte load/store. */
20588 if (value & ~0x1f)
20589 as_bad_where (fixP->fx_file, fixP->fx_line,
20590 _("invalid offset, value too big (0x%08lX)"),
20591 (long) value);
20592 newval |= value << 6;
20593 break;
20594
20595 case 8: /* Halfword load/store. */
20596 if (value & ~0x3e)
20597 as_bad_where (fixP->fx_file, fixP->fx_line,
20598 _("invalid offset, value too big (0x%08lX)"),
20599 (long) value);
20600 newval |= value << 5; /* 6 - 1. */
20601 break;
20602
20603 default:
20604 as_bad_where (fixP->fx_file, fixP->fx_line,
20605 "Unable to process relocation for thumb opcode: %lx",
20606 (unsigned long) newval);
20607 break;
20608 }
20609 md_number_to_chars (buf, newval, THUMB_SIZE);
20610 break;
20611
20612 case BFD_RELOC_ARM_THUMB_ADD:
20613 /* This is a complicated relocation, since we use it for all of
20614 the following immediate relocations:
20615
20616 3bit ADD/SUB
20617 8bit ADD/SUB
20618 9bit ADD/SUB SP word-aligned
20619 10bit ADD PC/SP word-aligned
20620
20621 The type of instruction being processed is encoded in the
20622 instruction field:
20623
20624 0x8000 SUB
20625 0x00F0 Rd
20626 0x000F Rs
20627 */
20628 newval = md_chars_to_number (buf, THUMB_SIZE);
20629 {
20630 int rd = (newval >> 4) & 0xf;
20631 int rs = newval & 0xf;
20632 int subtract = !!(newval & 0x8000);
20633
20634 /* Check for HI regs, only very restricted cases allowed:
20635 Adjusting SP, and using PC or SP to get an address. */
20636 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20637 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20638 as_bad_where (fixP->fx_file, fixP->fx_line,
20639 _("invalid Hi register with immediate"));
20640
20641 /* If value is negative, choose the opposite instruction. */
20642 if (value < 0)
20643 {
20644 value = -value;
20645 subtract = !subtract;
20646 if (value < 0)
20647 as_bad_where (fixP->fx_file, fixP->fx_line,
20648 _("immediate value out of range"));
20649 }
20650
20651 if (rd == REG_SP)
20652 {
20653 if (value & ~0x1fc)
20654 as_bad_where (fixP->fx_file, fixP->fx_line,
20655 _("invalid immediate for stack address calculation"));
20656 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20657 newval |= value >> 2;
20658 }
20659 else if (rs == REG_PC || rs == REG_SP)
20660 {
20661 if (subtract || value & ~0x3fc)
20662 as_bad_where (fixP->fx_file, fixP->fx_line,
20663 _("invalid immediate for address calculation (value = 0x%08lX)"),
20664 (unsigned long) value);
20665 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20666 newval |= rd << 8;
20667 newval |= value >> 2;
20668 }
20669 else if (rs == rd)
20670 {
20671 if (value & ~0xff)
20672 as_bad_where (fixP->fx_file, fixP->fx_line,
20673 _("immediate value out of range"));
20674 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20675 newval |= (rd << 8) | value;
20676 }
20677 else
20678 {
20679 if (value & ~0x7)
20680 as_bad_where (fixP->fx_file, fixP->fx_line,
20681 _("immediate value out of range"));
20682 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20683 newval |= rd | (rs << 3) | (value << 6);
20684 }
20685 }
20686 md_number_to_chars (buf, newval, THUMB_SIZE);
20687 break;
20688
20689 case BFD_RELOC_ARM_THUMB_IMM:
20690 newval = md_chars_to_number (buf, THUMB_SIZE);
20691 if (value < 0 || value > 255)
20692 as_bad_where (fixP->fx_file, fixP->fx_line,
20693 _("invalid immediate: %ld is out of range"),
20694 (long) value);
20695 newval |= value;
20696 md_number_to_chars (buf, newval, THUMB_SIZE);
20697 break;
20698
20699 case BFD_RELOC_ARM_THUMB_SHIFT:
20700 /* 5bit shift value (0..32). LSL cannot take 32. */
20701 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20702 temp = newval & 0xf800;
20703 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20704 as_bad_where (fixP->fx_file, fixP->fx_line,
20705 _("invalid shift value: %ld"), (long) value);
20706 /* Shifts of zero must be encoded as LSL. */
20707 if (value == 0)
20708 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20709 /* Shifts of 32 are encoded as zero. */
20710 else if (value == 32)
20711 value = 0;
20712 newval |= value << 6;
20713 md_number_to_chars (buf, newval, THUMB_SIZE);
20714 break;
20715
20716 case BFD_RELOC_VTABLE_INHERIT:
20717 case BFD_RELOC_VTABLE_ENTRY:
20718 fixP->fx_done = 0;
20719 return;
20720
20721 case BFD_RELOC_ARM_MOVW:
20722 case BFD_RELOC_ARM_MOVT:
20723 case BFD_RELOC_ARM_THUMB_MOVW:
20724 case BFD_RELOC_ARM_THUMB_MOVT:
20725 if (fixP->fx_done || !seg->use_rela_p)
20726 {
20727 /* REL format relocations are limited to a 16-bit addend. */
20728 if (!fixP->fx_done)
20729 {
20730 if (value < -0x8000 || value > 0x7fff)
20731 as_bad_where (fixP->fx_file, fixP->fx_line,
20732 _("offset out of range"));
20733 }
20734 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20735 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20736 {
20737 value >>= 16;
20738 }
20739
20740 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20741 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20742 {
20743 newval = get_thumb32_insn (buf);
20744 newval &= 0xfbf08f00;
20745 newval |= (value & 0xf000) << 4;
20746 newval |= (value & 0x0800) << 15;
20747 newval |= (value & 0x0700) << 4;
20748 newval |= (value & 0x00ff);
20749 put_thumb32_insn (buf, newval);
20750 }
20751 else
20752 {
20753 newval = md_chars_to_number (buf, 4);
20754 newval &= 0xfff0f000;
20755 newval |= value & 0x0fff;
20756 newval |= (value & 0xf000) << 4;
20757 md_number_to_chars (buf, newval, 4);
20758 }
20759 }
20760 return;
20761
20762 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20763 case BFD_RELOC_ARM_ALU_PC_G0:
20764 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20765 case BFD_RELOC_ARM_ALU_PC_G1:
20766 case BFD_RELOC_ARM_ALU_PC_G2:
20767 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20768 case BFD_RELOC_ARM_ALU_SB_G0:
20769 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20770 case BFD_RELOC_ARM_ALU_SB_G1:
20771 case BFD_RELOC_ARM_ALU_SB_G2:
20772 gas_assert (!fixP->fx_done);
20773 if (!seg->use_rela_p)
20774 {
20775 bfd_vma insn;
20776 bfd_vma encoded_addend;
20777 bfd_vma addend_abs = abs (value);
20778
20779 /* Check that the absolute value of the addend can be
20780 expressed as an 8-bit constant plus a rotation. */
20781 encoded_addend = encode_arm_immediate (addend_abs);
20782 if (encoded_addend == (unsigned int) FAIL)
20783 as_bad_where (fixP->fx_file, fixP->fx_line,
20784 _("the offset 0x%08lX is not representable"),
20785 (unsigned long) addend_abs);
20786
20787 /* Extract the instruction. */
20788 insn = md_chars_to_number (buf, INSN_SIZE);
20789
20790 /* If the addend is positive, use an ADD instruction.
20791 Otherwise use a SUB. Take care not to destroy the S bit. */
20792 insn &= 0xff1fffff;
20793 if (value < 0)
20794 insn |= 1 << 22;
20795 else
20796 insn |= 1 << 23;
20797
20798 /* Place the encoded addend into the first 12 bits of the
20799 instruction. */
20800 insn &= 0xfffff000;
20801 insn |= encoded_addend;
20802
20803 /* Update the instruction. */
20804 md_number_to_chars (buf, insn, INSN_SIZE);
20805 }
20806 break;
20807
20808 case BFD_RELOC_ARM_LDR_PC_G0:
20809 case BFD_RELOC_ARM_LDR_PC_G1:
20810 case BFD_RELOC_ARM_LDR_PC_G2:
20811 case BFD_RELOC_ARM_LDR_SB_G0:
20812 case BFD_RELOC_ARM_LDR_SB_G1:
20813 case BFD_RELOC_ARM_LDR_SB_G2:
20814 gas_assert (!fixP->fx_done);
20815 if (!seg->use_rela_p)
20816 {
20817 bfd_vma insn;
20818 bfd_vma addend_abs = abs (value);
20819
20820 /* Check that the absolute value of the addend can be
20821 encoded in 12 bits. */
20822 if (addend_abs >= 0x1000)
20823 as_bad_where (fixP->fx_file, fixP->fx_line,
20824 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
20825 (unsigned long) addend_abs);
20826
20827 /* Extract the instruction. */
20828 insn = md_chars_to_number (buf, INSN_SIZE);
20829
20830 /* If the addend is negative, clear bit 23 of the instruction.
20831 Otherwise set it. */
20832 if (value < 0)
20833 insn &= ~(1 << 23);
20834 else
20835 insn |= 1 << 23;
20836
20837 /* Place the absolute value of the addend into the first 12 bits
20838 of the instruction. */
20839 insn &= 0xfffff000;
20840 insn |= addend_abs;
20841
20842 /* Update the instruction. */
20843 md_number_to_chars (buf, insn, INSN_SIZE);
20844 }
20845 break;
20846
20847 case BFD_RELOC_ARM_LDRS_PC_G0:
20848 case BFD_RELOC_ARM_LDRS_PC_G1:
20849 case BFD_RELOC_ARM_LDRS_PC_G2:
20850 case BFD_RELOC_ARM_LDRS_SB_G0:
20851 case BFD_RELOC_ARM_LDRS_SB_G1:
20852 case BFD_RELOC_ARM_LDRS_SB_G2:
20853 gas_assert (!fixP->fx_done);
20854 if (!seg->use_rela_p)
20855 {
20856 bfd_vma insn;
20857 bfd_vma addend_abs = abs (value);
20858
20859 /* Check that the absolute value of the addend can be
20860 encoded in 8 bits. */
20861 if (addend_abs >= 0x100)
20862 as_bad_where (fixP->fx_file, fixP->fx_line,
20863 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
20864 (unsigned long) addend_abs);
20865
20866 /* Extract the instruction. */
20867 insn = md_chars_to_number (buf, INSN_SIZE);
20868
20869 /* If the addend is negative, clear bit 23 of the instruction.
20870 Otherwise set it. */
20871 if (value < 0)
20872 insn &= ~(1 << 23);
20873 else
20874 insn |= 1 << 23;
20875
20876 /* Place the first four bits of the absolute value of the addend
20877 into the first 4 bits of the instruction, and the remaining
20878 four into bits 8 .. 11. */
20879 insn &= 0xfffff0f0;
20880 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
20881
20882 /* Update the instruction. */
20883 md_number_to_chars (buf, insn, INSN_SIZE);
20884 }
20885 break;
20886
20887 case BFD_RELOC_ARM_LDC_PC_G0:
20888 case BFD_RELOC_ARM_LDC_PC_G1:
20889 case BFD_RELOC_ARM_LDC_PC_G2:
20890 case BFD_RELOC_ARM_LDC_SB_G0:
20891 case BFD_RELOC_ARM_LDC_SB_G1:
20892 case BFD_RELOC_ARM_LDC_SB_G2:
20893 gas_assert (!fixP->fx_done);
20894 if (!seg->use_rela_p)
20895 {
20896 bfd_vma insn;
20897 bfd_vma addend_abs = abs (value);
20898
20899 /* Check that the absolute value of the addend is a multiple of
20900 four and, when divided by four, fits in 8 bits. */
20901 if (addend_abs & 0x3)
20902 as_bad_where (fixP->fx_file, fixP->fx_line,
20903 _("bad offset 0x%08lX (must be word-aligned)"),
20904 (unsigned long) addend_abs);
20905
20906 if ((addend_abs >> 2) > 0xff)
20907 as_bad_where (fixP->fx_file, fixP->fx_line,
20908 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
20909 (unsigned long) addend_abs);
20910
20911 /* Extract the instruction. */
20912 insn = md_chars_to_number (buf, INSN_SIZE);
20913
20914 /* If the addend is negative, clear bit 23 of the instruction.
20915 Otherwise set it. */
20916 if (value < 0)
20917 insn &= ~(1 << 23);
20918 else
20919 insn |= 1 << 23;
20920
20921 /* Place the addend (divided by four) into the first eight
20922 bits of the instruction. */
20923 insn &= 0xfffffff0;
20924 insn |= addend_abs >> 2;
20925
20926 /* Update the instruction. */
20927 md_number_to_chars (buf, insn, INSN_SIZE);
20928 }
20929 break;
20930
20931 case BFD_RELOC_ARM_V4BX:
20932 /* This will need to go in the object file. */
20933 fixP->fx_done = 0;
20934 break;
20935
20936 case BFD_RELOC_UNUSED:
20937 default:
20938 as_bad_where (fixP->fx_file, fixP->fx_line,
20939 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20940 }
20941 }
20942
20943 /* Translate internal representation of relocation info to BFD target
20944 format. */
20945
20946 arelent *
20947 tc_gen_reloc (asection *section, fixS *fixp)
20948 {
20949 arelent * reloc;
20950 bfd_reloc_code_real_type code;
20951
20952 reloc = (arelent *) xmalloc (sizeof (arelent));
20953
20954 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
20955 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20956 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
20957
20958 if (fixp->fx_pcrel)
20959 {
20960 if (section->use_rela_p)
20961 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20962 else
20963 fixp->fx_offset = reloc->address;
20964 }
20965 reloc->addend = fixp->fx_offset;
20966
20967 switch (fixp->fx_r_type)
20968 {
20969 case BFD_RELOC_8:
20970 if (fixp->fx_pcrel)
20971 {
20972 code = BFD_RELOC_8_PCREL;
20973 break;
20974 }
20975
20976 case BFD_RELOC_16:
20977 if (fixp->fx_pcrel)
20978 {
20979 code = BFD_RELOC_16_PCREL;
20980 break;
20981 }
20982
20983 case BFD_RELOC_32:
20984 if (fixp->fx_pcrel)
20985 {
20986 code = BFD_RELOC_32_PCREL;
20987 break;
20988 }
20989
20990 case BFD_RELOC_ARM_MOVW:
20991 if (fixp->fx_pcrel)
20992 {
20993 code = BFD_RELOC_ARM_MOVW_PCREL;
20994 break;
20995 }
20996
20997 case BFD_RELOC_ARM_MOVT:
20998 if (fixp->fx_pcrel)
20999 {
21000 code = BFD_RELOC_ARM_MOVT_PCREL;
21001 break;
21002 }
21003
21004 case BFD_RELOC_ARM_THUMB_MOVW:
21005 if (fixp->fx_pcrel)
21006 {
21007 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21008 break;
21009 }
21010
21011 case BFD_RELOC_ARM_THUMB_MOVT:
21012 if (fixp->fx_pcrel)
21013 {
21014 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21015 break;
21016 }
21017
21018 case BFD_RELOC_NONE:
21019 case BFD_RELOC_ARM_PCREL_BRANCH:
21020 case BFD_RELOC_ARM_PCREL_BLX:
21021 case BFD_RELOC_RVA:
21022 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21023 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21024 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21025 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21026 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21027 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21028 case BFD_RELOC_VTABLE_ENTRY:
21029 case BFD_RELOC_VTABLE_INHERIT:
21030 #ifdef TE_PE
21031 case BFD_RELOC_32_SECREL:
21032 #endif
21033 code = fixp->fx_r_type;
21034 break;
21035
21036 case BFD_RELOC_THUMB_PCREL_BLX:
21037 #ifdef OBJ_ELF
21038 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21039 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21040 else
21041 #endif
21042 code = BFD_RELOC_THUMB_PCREL_BLX;
21043 break;
21044
21045 case BFD_RELOC_ARM_LITERAL:
21046 case BFD_RELOC_ARM_HWLITERAL:
21047 /* If this is called then the a literal has
21048 been referenced across a section boundary. */
21049 as_bad_where (fixp->fx_file, fixp->fx_line,
21050 _("literal referenced across section boundary"));
21051 return NULL;
21052
21053 #ifdef OBJ_ELF
21054 case BFD_RELOC_ARM_GOT32:
21055 case BFD_RELOC_ARM_GOTOFF:
21056 case BFD_RELOC_ARM_PLT32:
21057 case BFD_RELOC_ARM_TARGET1:
21058 case BFD_RELOC_ARM_ROSEGREL32:
21059 case BFD_RELOC_ARM_SBREL32:
21060 case BFD_RELOC_ARM_PREL31:
21061 case BFD_RELOC_ARM_TARGET2:
21062 case BFD_RELOC_ARM_TLS_LE32:
21063 case BFD_RELOC_ARM_TLS_LDO32:
21064 case BFD_RELOC_ARM_PCREL_CALL:
21065 case BFD_RELOC_ARM_PCREL_JUMP:
21066 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21067 case BFD_RELOC_ARM_ALU_PC_G0:
21068 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21069 case BFD_RELOC_ARM_ALU_PC_G1:
21070 case BFD_RELOC_ARM_ALU_PC_G2:
21071 case BFD_RELOC_ARM_LDR_PC_G0:
21072 case BFD_RELOC_ARM_LDR_PC_G1:
21073 case BFD_RELOC_ARM_LDR_PC_G2:
21074 case BFD_RELOC_ARM_LDRS_PC_G0:
21075 case BFD_RELOC_ARM_LDRS_PC_G1:
21076 case BFD_RELOC_ARM_LDRS_PC_G2:
21077 case BFD_RELOC_ARM_LDC_PC_G0:
21078 case BFD_RELOC_ARM_LDC_PC_G1:
21079 case BFD_RELOC_ARM_LDC_PC_G2:
21080 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21081 case BFD_RELOC_ARM_ALU_SB_G0:
21082 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21083 case BFD_RELOC_ARM_ALU_SB_G1:
21084 case BFD_RELOC_ARM_ALU_SB_G2:
21085 case BFD_RELOC_ARM_LDR_SB_G0:
21086 case BFD_RELOC_ARM_LDR_SB_G1:
21087 case BFD_RELOC_ARM_LDR_SB_G2:
21088 case BFD_RELOC_ARM_LDRS_SB_G0:
21089 case BFD_RELOC_ARM_LDRS_SB_G1:
21090 case BFD_RELOC_ARM_LDRS_SB_G2:
21091 case BFD_RELOC_ARM_LDC_SB_G0:
21092 case BFD_RELOC_ARM_LDC_SB_G1:
21093 case BFD_RELOC_ARM_LDC_SB_G2:
21094 case BFD_RELOC_ARM_V4BX:
21095 code = fixp->fx_r_type;
21096 break;
21097
21098 case BFD_RELOC_ARM_TLS_GD32:
21099 case BFD_RELOC_ARM_TLS_IE32:
21100 case BFD_RELOC_ARM_TLS_LDM32:
21101 /* BFD will include the symbol's address in the addend.
21102 But we don't want that, so subtract it out again here. */
21103 if (!S_IS_COMMON (fixp->fx_addsy))
21104 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21105 code = fixp->fx_r_type;
21106 break;
21107 #endif
21108
21109 case BFD_RELOC_ARM_IMMEDIATE:
21110 as_bad_where (fixp->fx_file, fixp->fx_line,
21111 _("internal relocation (type: IMMEDIATE) not fixed up"));
21112 return NULL;
21113
21114 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21115 as_bad_where (fixp->fx_file, fixp->fx_line,
21116 _("ADRL used for a symbol not defined in the same file"));
21117 return NULL;
21118
21119 case BFD_RELOC_ARM_OFFSET_IMM:
21120 if (section->use_rela_p)
21121 {
21122 code = fixp->fx_r_type;
21123 break;
21124 }
21125
21126 if (fixp->fx_addsy != NULL
21127 && !S_IS_DEFINED (fixp->fx_addsy)
21128 && S_IS_LOCAL (fixp->fx_addsy))
21129 {
21130 as_bad_where (fixp->fx_file, fixp->fx_line,
21131 _("undefined local label `%s'"),
21132 S_GET_NAME (fixp->fx_addsy));
21133 return NULL;
21134 }
21135
21136 as_bad_where (fixp->fx_file, fixp->fx_line,
21137 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21138 return NULL;
21139
21140 default:
21141 {
21142 char * type;
21143
21144 switch (fixp->fx_r_type)
21145 {
21146 case BFD_RELOC_NONE: type = "NONE"; break;
21147 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21148 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
21149 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
21150 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21151 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21152 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
21153 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
21154 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21155 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21156 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21157 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21158 default: type = _("<unknown>"); break;
21159 }
21160 as_bad_where (fixp->fx_file, fixp->fx_line,
21161 _("cannot represent %s relocation in this object file format"),
21162 type);
21163 return NULL;
21164 }
21165 }
21166
21167 #ifdef OBJ_ELF
21168 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21169 && GOT_symbol
21170 && fixp->fx_addsy == GOT_symbol)
21171 {
21172 code = BFD_RELOC_ARM_GOTPC;
21173 reloc->addend = fixp->fx_offset = reloc->address;
21174 }
21175 #endif
21176
21177 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
21178
21179 if (reloc->howto == NULL)
21180 {
21181 as_bad_where (fixp->fx_file, fixp->fx_line,
21182 _("cannot represent %s relocation in this object file format"),
21183 bfd_get_reloc_code_name (code));
21184 return NULL;
21185 }
21186
21187 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21188 vtable entry to be used in the relocation's section offset. */
21189 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21190 reloc->address = fixp->fx_offset;
21191
21192 return reloc;
21193 }
21194
21195 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
21196
21197 void
21198 cons_fix_new_arm (fragS * frag,
21199 int where,
21200 int size,
21201 expressionS * exp)
21202 {
21203 bfd_reloc_code_real_type type;
21204 int pcrel = 0;
21205
21206 /* Pick a reloc.
21207 FIXME: @@ Should look at CPU word size. */
21208 switch (size)
21209 {
21210 case 1:
21211 type = BFD_RELOC_8;
21212 break;
21213 case 2:
21214 type = BFD_RELOC_16;
21215 break;
21216 case 4:
21217 default:
21218 type = BFD_RELOC_32;
21219 break;
21220 case 8:
21221 type = BFD_RELOC_64;
21222 break;
21223 }
21224
21225 #ifdef TE_PE
21226 if (exp->X_op == O_secrel)
21227 {
21228 exp->X_op = O_symbol;
21229 type = BFD_RELOC_32_SECREL;
21230 }
21231 #endif
21232
21233 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21234 }
21235
21236 #if defined (OBJ_COFF)
21237 void
21238 arm_validate_fix (fixS * fixP)
21239 {
21240 /* If the destination of the branch is a defined symbol which does not have
21241 the THUMB_FUNC attribute, then we must be calling a function which has
21242 the (interfacearm) attribute. We look for the Thumb entry point to that
21243 function and change the branch to refer to that function instead. */
21244 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21245 && fixP->fx_addsy != NULL
21246 && S_IS_DEFINED (fixP->fx_addsy)
21247 && ! THUMB_IS_FUNC (fixP->fx_addsy))
21248 {
21249 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
21250 }
21251 }
21252 #endif
21253
21254
21255 int
21256 arm_force_relocation (struct fix * fixp)
21257 {
21258 #if defined (OBJ_COFF) && defined (TE_PE)
21259 if (fixp->fx_r_type == BFD_RELOC_RVA)
21260 return 1;
21261 #endif
21262
21263 /* In case we have a call or a branch to a function in ARM ISA mode from
21264 a thumb function or vice-versa force the relocation. These relocations
21265 are cleared off for some cores that might have blx and simple transformations
21266 are possible. */
21267
21268 #ifdef OBJ_ELF
21269 switch (fixp->fx_r_type)
21270 {
21271 case BFD_RELOC_ARM_PCREL_JUMP:
21272 case BFD_RELOC_ARM_PCREL_CALL:
21273 case BFD_RELOC_THUMB_PCREL_BLX:
21274 if (THUMB_IS_FUNC (fixp->fx_addsy))
21275 return 1;
21276 break;
21277
21278 case BFD_RELOC_ARM_PCREL_BLX:
21279 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21280 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21281 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21282 if (ARM_IS_FUNC (fixp->fx_addsy))
21283 return 1;
21284 break;
21285
21286 default:
21287 break;
21288 }
21289 #endif
21290
21291 /* Resolve these relocations even if the symbol is extern or weak. */
21292 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21293 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
21294 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
21295 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
21296 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21297 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21298 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
21299 return 0;
21300
21301 /* Always leave these relocations for the linker. */
21302 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21303 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21304 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21305 return 1;
21306
21307 /* Always generate relocations against function symbols. */
21308 if (fixp->fx_r_type == BFD_RELOC_32
21309 && fixp->fx_addsy
21310 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21311 return 1;
21312
21313 return generic_force_reloc (fixp);
21314 }
21315
21316 #if defined (OBJ_ELF) || defined (OBJ_COFF)
21317 /* Relocations against function names must be left unadjusted,
21318 so that the linker can use this information to generate interworking
21319 stubs. The MIPS version of this function
21320 also prevents relocations that are mips-16 specific, but I do not
21321 know why it does this.
21322
21323 FIXME:
21324 There is one other problem that ought to be addressed here, but
21325 which currently is not: Taking the address of a label (rather
21326 than a function) and then later jumping to that address. Such
21327 addresses also ought to have their bottom bit set (assuming that
21328 they reside in Thumb code), but at the moment they will not. */
21329
21330 bfd_boolean
21331 arm_fix_adjustable (fixS * fixP)
21332 {
21333 if (fixP->fx_addsy == NULL)
21334 return 1;
21335
21336 /* Preserve relocations against symbols with function type. */
21337 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
21338 return FALSE;
21339
21340 if (THUMB_IS_FUNC (fixP->fx_addsy)
21341 && fixP->fx_subsy == NULL)
21342 return FALSE;
21343
21344 /* We need the symbol name for the VTABLE entries. */
21345 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21346 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21347 return FALSE;
21348
21349 /* Don't allow symbols to be discarded on GOT related relocs. */
21350 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21351 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21352 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21353 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21354 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21355 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21356 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21357 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21358 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
21359 return FALSE;
21360
21361 /* Similarly for group relocations. */
21362 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21363 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21364 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21365 return FALSE;
21366
21367 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21368 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21369 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21370 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21371 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21372 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21373 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21374 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21375 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
21376 return FALSE;
21377
21378 return TRUE;
21379 }
21380 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21381
21382 #ifdef OBJ_ELF
21383
21384 const char *
21385 elf32_arm_target_format (void)
21386 {
21387 #ifdef TE_SYMBIAN
21388 return (target_big_endian
21389 ? "elf32-bigarm-symbian"
21390 : "elf32-littlearm-symbian");
21391 #elif defined (TE_VXWORKS)
21392 return (target_big_endian
21393 ? "elf32-bigarm-vxworks"
21394 : "elf32-littlearm-vxworks");
21395 #else
21396 if (target_big_endian)
21397 return "elf32-bigarm";
21398 else
21399 return "elf32-littlearm";
21400 #endif
21401 }
21402
21403 void
21404 armelf_frob_symbol (symbolS * symp,
21405 int * puntp)
21406 {
21407 elf_frob_symbol (symp, puntp);
21408 }
21409 #endif
21410
21411 /* MD interface: Finalization. */
21412
21413 void
21414 arm_cleanup (void)
21415 {
21416 literal_pool * pool;
21417
21418 /* Ensure that all the IT blocks are properly closed. */
21419 check_it_blocks_finished ();
21420
21421 for (pool = list_of_pools; pool; pool = pool->next)
21422 {
21423 /* Put it at the end of the relevant section. */
21424 subseg_set (pool->section, pool->sub_section);
21425 #ifdef OBJ_ELF
21426 arm_elf_change_section ();
21427 #endif
21428 s_ltorg (0);
21429 }
21430 }
21431
21432 #ifdef OBJ_ELF
21433 /* Remove any excess mapping symbols generated for alignment frags in
21434 SEC. We may have created a mapping symbol before a zero byte
21435 alignment; remove it if there's a mapping symbol after the
21436 alignment. */
21437 static void
21438 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21439 void *dummy ATTRIBUTE_UNUSED)
21440 {
21441 segment_info_type *seginfo = seg_info (sec);
21442 fragS *fragp;
21443
21444 if (seginfo == NULL || seginfo->frchainP == NULL)
21445 return;
21446
21447 for (fragp = seginfo->frchainP->frch_root;
21448 fragp != NULL;
21449 fragp = fragp->fr_next)
21450 {
21451 symbolS *sym = fragp->tc_frag_data.last_map;
21452 fragS *next = fragp->fr_next;
21453
21454 /* Variable-sized frags have been converted to fixed size by
21455 this point. But if this was variable-sized to start with,
21456 there will be a fixed-size frag after it. So don't handle
21457 next == NULL. */
21458 if (sym == NULL || next == NULL)
21459 continue;
21460
21461 if (S_GET_VALUE (sym) < next->fr_address)
21462 /* Not at the end of this frag. */
21463 continue;
21464 know (S_GET_VALUE (sym) == next->fr_address);
21465
21466 do
21467 {
21468 if (next->tc_frag_data.first_map != NULL)
21469 {
21470 /* Next frag starts with a mapping symbol. Discard this
21471 one. */
21472 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21473 break;
21474 }
21475
21476 if (next->fr_next == NULL)
21477 {
21478 /* This mapping symbol is at the end of the section. Discard
21479 it. */
21480 know (next->fr_fix == 0 && next->fr_var == 0);
21481 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21482 break;
21483 }
21484
21485 /* As long as we have empty frags without any mapping symbols,
21486 keep looking. */
21487 /* If the next frag is non-empty and does not start with a
21488 mapping symbol, then this mapping symbol is required. */
21489 if (next->fr_address != next->fr_next->fr_address)
21490 break;
21491
21492 next = next->fr_next;
21493 }
21494 while (next != NULL);
21495 }
21496 }
21497 #endif
21498
21499 /* Adjust the symbol table. This marks Thumb symbols as distinct from
21500 ARM ones. */
21501
21502 void
21503 arm_adjust_symtab (void)
21504 {
21505 #ifdef OBJ_COFF
21506 symbolS * sym;
21507
21508 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21509 {
21510 if (ARM_IS_THUMB (sym))
21511 {
21512 if (THUMB_IS_FUNC (sym))
21513 {
21514 /* Mark the symbol as a Thumb function. */
21515 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21516 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21517 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
21518
21519 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21520 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21521 else
21522 as_bad (_("%s: unexpected function type: %d"),
21523 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21524 }
21525 else switch (S_GET_STORAGE_CLASS (sym))
21526 {
21527 case C_EXT:
21528 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21529 break;
21530 case C_STAT:
21531 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21532 break;
21533 case C_LABEL:
21534 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21535 break;
21536 default:
21537 /* Do nothing. */
21538 break;
21539 }
21540 }
21541
21542 if (ARM_IS_INTERWORK (sym))
21543 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
21544 }
21545 #endif
21546 #ifdef OBJ_ELF
21547 symbolS * sym;
21548 char bind;
21549
21550 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21551 {
21552 if (ARM_IS_THUMB (sym))
21553 {
21554 elf_symbol_type * elf_sym;
21555
21556 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21557 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
21558
21559 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21560 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
21561 {
21562 /* If it's a .thumb_func, declare it as so,
21563 otherwise tag label as .code 16. */
21564 if (THUMB_IS_FUNC (sym))
21565 elf_sym->internal_elf_sym.st_info =
21566 ELF_ST_INFO (bind, STT_ARM_TFUNC);
21567 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21568 elf_sym->internal_elf_sym.st_info =
21569 ELF_ST_INFO (bind, STT_ARM_16BIT);
21570 }
21571 }
21572 }
21573
21574 /* Remove any overlapping mapping symbols generated by alignment frags. */
21575 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
21576 #endif
21577 }
21578
21579 /* MD interface: Initialization. */
21580
21581 static void
21582 set_constant_flonums (void)
21583 {
21584 int i;
21585
21586 for (i = 0; i < NUM_FLOAT_VALS; i++)
21587 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21588 abort ();
21589 }
21590
21591 /* Auto-select Thumb mode if it's the only available instruction set for the
21592 given architecture. */
21593
21594 static void
21595 autoselect_thumb_from_cpu_variant (void)
21596 {
21597 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21598 opcode_select (16);
21599 }
21600
21601 void
21602 md_begin (void)
21603 {
21604 unsigned mach;
21605 unsigned int i;
21606
21607 if ( (arm_ops_hsh = hash_new ()) == NULL
21608 || (arm_cond_hsh = hash_new ()) == NULL
21609 || (arm_shift_hsh = hash_new ()) == NULL
21610 || (arm_psr_hsh = hash_new ()) == NULL
21611 || (arm_v7m_psr_hsh = hash_new ()) == NULL
21612 || (arm_reg_hsh = hash_new ()) == NULL
21613 || (arm_reloc_hsh = hash_new ()) == NULL
21614 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
21615 as_fatal (_("virtual memory exhausted"));
21616
21617 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
21618 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
21619 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
21620 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
21621 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
21622 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
21623 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
21624 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
21625 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
21626 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21627 (void *) (v7m_psrs + i));
21628 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
21629 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
21630 for (i = 0;
21631 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21632 i++)
21633 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
21634 (void *) (barrier_opt_names + i));
21635 #ifdef OBJ_ELF
21636 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
21637 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
21638 #endif
21639
21640 set_constant_flonums ();
21641
21642 /* Set the cpu variant based on the command-line options. We prefer
21643 -mcpu= over -march= if both are set (as for GCC); and we prefer
21644 -mfpu= over any other way of setting the floating point unit.
21645 Use of legacy options with new options are faulted. */
21646 if (legacy_cpu)
21647 {
21648 if (mcpu_cpu_opt || march_cpu_opt)
21649 as_bad (_("use of old and new-style options to set CPU type"));
21650
21651 mcpu_cpu_opt = legacy_cpu;
21652 }
21653 else if (!mcpu_cpu_opt)
21654 mcpu_cpu_opt = march_cpu_opt;
21655
21656 if (legacy_fpu)
21657 {
21658 if (mfpu_opt)
21659 as_bad (_("use of old and new-style options to set FPU type"));
21660
21661 mfpu_opt = legacy_fpu;
21662 }
21663 else if (!mfpu_opt)
21664 {
21665 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21666 || defined (TE_NetBSD) || defined (TE_VXWORKS))
21667 /* Some environments specify a default FPU. If they don't, infer it
21668 from the processor. */
21669 if (mcpu_fpu_opt)
21670 mfpu_opt = mcpu_fpu_opt;
21671 else
21672 mfpu_opt = march_fpu_opt;
21673 #else
21674 mfpu_opt = &fpu_default;
21675 #endif
21676 }
21677
21678 if (!mfpu_opt)
21679 {
21680 if (mcpu_cpu_opt != NULL)
21681 mfpu_opt = &fpu_default;
21682 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
21683 mfpu_opt = &fpu_arch_vfp_v2;
21684 else
21685 mfpu_opt = &fpu_arch_fpa;
21686 }
21687
21688 #ifdef CPU_DEFAULT
21689 if (!mcpu_cpu_opt)
21690 {
21691 mcpu_cpu_opt = &cpu_default;
21692 selected_cpu = cpu_default;
21693 }
21694 #else
21695 if (mcpu_cpu_opt)
21696 selected_cpu = *mcpu_cpu_opt;
21697 else
21698 mcpu_cpu_opt = &arm_arch_any;
21699 #endif
21700
21701 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21702
21703 autoselect_thumb_from_cpu_variant ();
21704
21705 arm_arch_used = thumb_arch_used = arm_arch_none;
21706
21707 #if defined OBJ_COFF || defined OBJ_ELF
21708 {
21709 unsigned int flags = 0;
21710
21711 #if defined OBJ_ELF
21712 flags = meabi_flags;
21713
21714 switch (meabi_flags)
21715 {
21716 case EF_ARM_EABI_UNKNOWN:
21717 #endif
21718 /* Set the flags in the private structure. */
21719 if (uses_apcs_26) flags |= F_APCS26;
21720 if (support_interwork) flags |= F_INTERWORK;
21721 if (uses_apcs_float) flags |= F_APCS_FLOAT;
21722 if (pic_code) flags |= F_PIC;
21723 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
21724 flags |= F_SOFT_FLOAT;
21725
21726 switch (mfloat_abi_opt)
21727 {
21728 case ARM_FLOAT_ABI_SOFT:
21729 case ARM_FLOAT_ABI_SOFTFP:
21730 flags |= F_SOFT_FLOAT;
21731 break;
21732
21733 case ARM_FLOAT_ABI_HARD:
21734 if (flags & F_SOFT_FLOAT)
21735 as_bad (_("hard-float conflicts with specified fpu"));
21736 break;
21737 }
21738
21739 /* Using pure-endian doubles (even if soft-float). */
21740 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
21741 flags |= F_VFP_FLOAT;
21742
21743 #if defined OBJ_ELF
21744 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
21745 flags |= EF_ARM_MAVERICK_FLOAT;
21746 break;
21747
21748 case EF_ARM_EABI_VER4:
21749 case EF_ARM_EABI_VER5:
21750 /* No additional flags to set. */
21751 break;
21752
21753 default:
21754 abort ();
21755 }
21756 #endif
21757 bfd_set_private_flags (stdoutput, flags);
21758
21759 /* We have run out flags in the COFF header to encode the
21760 status of ATPCS support, so instead we create a dummy,
21761 empty, debug section called .arm.atpcs. */
21762 if (atpcs)
21763 {
21764 asection * sec;
21765
21766 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21767
21768 if (sec != NULL)
21769 {
21770 bfd_set_section_flags
21771 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21772 bfd_set_section_size (stdoutput, sec, 0);
21773 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21774 }
21775 }
21776 }
21777 #endif
21778
21779 /* Record the CPU type as well. */
21780 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21781 mach = bfd_mach_arm_iWMMXt2;
21782 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
21783 mach = bfd_mach_arm_iWMMXt;
21784 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
21785 mach = bfd_mach_arm_XScale;
21786 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
21787 mach = bfd_mach_arm_ep9312;
21788 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
21789 mach = bfd_mach_arm_5TE;
21790 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
21791 {
21792 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21793 mach = bfd_mach_arm_5T;
21794 else
21795 mach = bfd_mach_arm_5;
21796 }
21797 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
21798 {
21799 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21800 mach = bfd_mach_arm_4T;
21801 else
21802 mach = bfd_mach_arm_4;
21803 }
21804 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
21805 mach = bfd_mach_arm_3M;
21806 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21807 mach = bfd_mach_arm_3;
21808 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21809 mach = bfd_mach_arm_2a;
21810 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21811 mach = bfd_mach_arm_2;
21812 else
21813 mach = bfd_mach_arm_unknown;
21814
21815 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21816 }
21817
21818 /* Command line processing. */
21819
21820 /* md_parse_option
21821 Invocation line includes a switch not recognized by the base assembler.
21822 See if it's a processor-specific option.
21823
21824 This routine is somewhat complicated by the need for backwards
21825 compatibility (since older releases of gcc can't be changed).
21826 The new options try to make the interface as compatible as
21827 possible with GCC.
21828
21829 New options (supported) are:
21830
21831 -mcpu=<cpu name> Assemble for selected processor
21832 -march=<architecture name> Assemble for selected architecture
21833 -mfpu=<fpu architecture> Assemble for selected FPU.
21834 -EB/-mbig-endian Big-endian
21835 -EL/-mlittle-endian Little-endian
21836 -k Generate PIC code
21837 -mthumb Start in Thumb mode
21838 -mthumb-interwork Code supports ARM/Thumb interworking
21839
21840 -m[no-]warn-deprecated Warn about deprecated features
21841
21842 For now we will also provide support for:
21843
21844 -mapcs-32 32-bit Program counter
21845 -mapcs-26 26-bit Program counter
21846 -macps-float Floats passed in FP registers
21847 -mapcs-reentrant Reentrant code
21848 -matpcs
21849 (sometime these will probably be replaced with -mapcs=<list of options>
21850 and -matpcs=<list of options>)
21851
21852 The remaining options are only supported for back-wards compatibility.
21853 Cpu variants, the arm part is optional:
21854 -m[arm]1 Currently not supported.
21855 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21856 -m[arm]3 Arm 3 processor
21857 -m[arm]6[xx], Arm 6 processors
21858 -m[arm]7[xx][t][[d]m] Arm 7 processors
21859 -m[arm]8[10] Arm 8 processors
21860 -m[arm]9[20][tdmi] Arm 9 processors
21861 -mstrongarm[110[0]] StrongARM processors
21862 -mxscale XScale processors
21863 -m[arm]v[2345[t[e]]] Arm architectures
21864 -mall All (except the ARM1)
21865 FP variants:
21866 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21867 -mfpe-old (No float load/store multiples)
21868 -mvfpxd VFP Single precision
21869 -mvfp All VFP
21870 -mno-fpu Disable all floating point instructions
21871
21872 The following CPU names are recognized:
21873 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21874 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21875 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21876 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21877 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21878 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21879 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
21880
21881 */
21882
21883 const char * md_shortopts = "m:k";
21884
21885 #ifdef ARM_BI_ENDIAN
21886 #define OPTION_EB (OPTION_MD_BASE + 0)
21887 #define OPTION_EL (OPTION_MD_BASE + 1)
21888 #else
21889 #if TARGET_BYTES_BIG_ENDIAN
21890 #define OPTION_EB (OPTION_MD_BASE + 0)
21891 #else
21892 #define OPTION_EL (OPTION_MD_BASE + 1)
21893 #endif
21894 #endif
21895 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
21896
21897 struct option md_longopts[] =
21898 {
21899 #ifdef OPTION_EB
21900 {"EB", no_argument, NULL, OPTION_EB},
21901 #endif
21902 #ifdef OPTION_EL
21903 {"EL", no_argument, NULL, OPTION_EL},
21904 #endif
21905 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
21906 {NULL, no_argument, NULL, 0}
21907 };
21908
21909 size_t md_longopts_size = sizeof (md_longopts);
21910
21911 struct arm_option_table
21912 {
21913 char *option; /* Option name to match. */
21914 char *help; /* Help information. */
21915 int *var; /* Variable to change. */
21916 int value; /* What to change it to. */
21917 char *deprecated; /* If non-null, print this message. */
21918 };
21919
21920 struct arm_option_table arm_opts[] =
21921 {
21922 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21923 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21924 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21925 &support_interwork, 1, NULL},
21926 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21927 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21928 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21929 1, NULL},
21930 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21931 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21932 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21933 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21934 NULL},
21935
21936 /* These are recognized by the assembler, but have no affect on code. */
21937 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21938 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
21939
21940 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21941 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21942 &warn_on_deprecated, 0, NULL},
21943 {NULL, NULL, NULL, 0, NULL}
21944 };
21945
21946 struct arm_legacy_option_table
21947 {
21948 char *option; /* Option name to match. */
21949 const arm_feature_set **var; /* Variable to change. */
21950 const arm_feature_set value; /* What to change it to. */
21951 char *deprecated; /* If non-null, print this message. */
21952 };
21953
21954 const struct arm_legacy_option_table arm_legacy_opts[] =
21955 {
21956 /* DON'T add any new processors to this list -- we want the whole list
21957 to go away... Add them to the processors table instead. */
21958 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21959 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21960 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21961 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21962 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21963 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21964 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21965 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21966 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21967 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21968 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21969 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21970 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21971 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21972 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21973 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21974 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21975 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21976 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21977 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21978 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21979 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21980 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21981 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21982 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21983 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21984 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21985 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21986 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21987 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21988 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21989 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21990 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21991 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21992 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21993 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21994 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21995 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21996 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21997 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21998 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21999 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22000 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22001 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22002 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22003 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22004 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22005 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22006 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22007 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22008 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22009 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22010 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22011 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22012 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22013 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22014 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22015 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22016 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22017 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22018 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22019 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22020 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22021 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22022 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22023 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22024 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22025 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22026 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22027 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
22028 N_("use -mcpu=strongarm110")},
22029 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
22030 N_("use -mcpu=strongarm1100")},
22031 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
22032 N_("use -mcpu=strongarm1110")},
22033 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22034 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22035 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
22036
22037 /* Architecture variants -- don't add any more to this list either. */
22038 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22039 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22040 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22041 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22042 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22043 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22044 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22045 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22046 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22047 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22048 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22049 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22050 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22051 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22052 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22053 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22054 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22055 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22056
22057 /* Floating point variants -- don't add any more to this list either. */
22058 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22059 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22060 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22061 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
22062 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
22063
22064 {NULL, NULL, ARM_ARCH_NONE, NULL}
22065 };
22066
22067 struct arm_cpu_option_table
22068 {
22069 char *name;
22070 const arm_feature_set value;
22071 /* For some CPUs we assume an FPU unless the user explicitly sets
22072 -mfpu=... */
22073 const arm_feature_set default_fpu;
22074 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22075 case. */
22076 const char *canonical_name;
22077 };
22078
22079 /* This list should, at a minimum, contain all the cpu names
22080 recognized by GCC. */
22081 static const struct arm_cpu_option_table arm_cpus[] =
22082 {
22083 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22084 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22085 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22086 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22087 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22088 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22089 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22090 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22091 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22092 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22093 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22094 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22095 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22096 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22097 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22098 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22099 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22100 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22101 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22102 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22103 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22104 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22105 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22106 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22107 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22108 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22109 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22110 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22111 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22112 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22113 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22114 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22115 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22116 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22117 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22118 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22119 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22120 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22121 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22122 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22123 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22124 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22125 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22126 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22127 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22128 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22129 /* For V5 or later processors we default to using VFP; but the user
22130 should really set the FPU type explicitly. */
22131 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22132 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22133 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22134 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22135 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22136 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22137 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22138 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22139 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22140 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22141 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22142 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22143 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22144 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22145 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22146 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22147 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22148 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22149 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22150 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22151 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22152 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22153 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22154 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22155 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22156 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22157 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22158 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
22159 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
22160 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22161 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22162 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22163 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
22164 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
22165 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
22166 | FPU_NEON_EXT_V1),
22167 NULL},
22168 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
22169 | FPU_NEON_EXT_V1),
22170 NULL},
22171 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
22172 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
22173 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
22174 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
22175 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
22176 /* ??? XSCALE is really an architecture. */
22177 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22178 /* ??? iwmmxt is not a processor. */
22179 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
22180 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
22181 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22182 /* Maverick */
22183 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
22184 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
22185 };
22186
22187 struct arm_arch_option_table
22188 {
22189 char *name;
22190 const arm_feature_set value;
22191 const arm_feature_set default_fpu;
22192 };
22193
22194 /* This list should, at a minimum, contain all the architecture names
22195 recognized by GCC. */
22196 static const struct arm_arch_option_table arm_archs[] =
22197 {
22198 {"all", ARM_ANY, FPU_ARCH_FPA},
22199 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22200 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22201 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22202 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22203 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22204 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22205 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22206 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22207 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22208 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22209 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22210 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22211 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22212 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22213 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22214 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22215 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22216 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22217 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22218 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22219 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22220 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22221 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22222 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22223 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
22224 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
22225 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
22226 /* The official spelling of the ARMv7 profile variants is the dashed form.
22227 Accept the non-dashed form for compatibility with old toolchains. */
22228 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22229 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22230 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22231 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22232 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22233 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22234 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
22235 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22236 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
22237 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
22238 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
22239 };
22240
22241 /* ISA extensions in the co-processor space. */
22242 struct arm_option_cpu_value_table
22243 {
22244 char *name;
22245 const arm_feature_set value;
22246 };
22247
22248 static const struct arm_option_cpu_value_table arm_extensions[] =
22249 {
22250 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22251 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22252 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
22253 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
22254 {NULL, ARM_ARCH_NONE}
22255 };
22256
22257 /* This list should, at a minimum, contain all the fpu names
22258 recognized by GCC. */
22259 static const struct arm_option_cpu_value_table arm_fpus[] =
22260 {
22261 {"softfpa", FPU_NONE},
22262 {"fpe", FPU_ARCH_FPE},
22263 {"fpe2", FPU_ARCH_FPE},
22264 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22265 {"fpa", FPU_ARCH_FPA},
22266 {"fpa10", FPU_ARCH_FPA},
22267 {"fpa11", FPU_ARCH_FPA},
22268 {"arm7500fe", FPU_ARCH_FPA},
22269 {"softvfp", FPU_ARCH_VFP},
22270 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22271 {"vfp", FPU_ARCH_VFP_V2},
22272 {"vfp9", FPU_ARCH_VFP_V2},
22273 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
22274 {"vfp10", FPU_ARCH_VFP_V2},
22275 {"vfp10-r0", FPU_ARCH_VFP_V1},
22276 {"vfpxd", FPU_ARCH_VFP_V1xD},
22277 {"vfpv2", FPU_ARCH_VFP_V2},
22278 {"vfpv3", FPU_ARCH_VFP_V3},
22279 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
22280 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
22281 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22282 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22283 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
22284 {"arm1020t", FPU_ARCH_VFP_V1},
22285 {"arm1020e", FPU_ARCH_VFP_V2},
22286 {"arm1136jfs", FPU_ARCH_VFP_V2},
22287 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22288 {"maverick", FPU_ARCH_MAVERICK},
22289 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
22290 {"neon-fp16", FPU_ARCH_NEON_FP16},
22291 {"vfpv4", FPU_ARCH_VFP_V4},
22292 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
22293 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
22294 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
22295 {NULL, ARM_ARCH_NONE}
22296 };
22297
22298 struct arm_option_value_table
22299 {
22300 char *name;
22301 long value;
22302 };
22303
22304 static const struct arm_option_value_table arm_float_abis[] =
22305 {
22306 {"hard", ARM_FLOAT_ABI_HARD},
22307 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22308 {"soft", ARM_FLOAT_ABI_SOFT},
22309 {NULL, 0}
22310 };
22311
22312 #ifdef OBJ_ELF
22313 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
22314 static const struct arm_option_value_table arm_eabis[] =
22315 {
22316 {"gnu", EF_ARM_EABI_UNKNOWN},
22317 {"4", EF_ARM_EABI_VER4},
22318 {"5", EF_ARM_EABI_VER5},
22319 {NULL, 0}
22320 };
22321 #endif
22322
22323 struct arm_long_option_table
22324 {
22325 char * option; /* Substring to match. */
22326 char * help; /* Help information. */
22327 int (* func) (char * subopt); /* Function to decode sub-option. */
22328 char * deprecated; /* If non-null, print this message. */
22329 };
22330
22331 static bfd_boolean
22332 arm_parse_extension (char * str, const arm_feature_set **opt_p)
22333 {
22334 arm_feature_set *ext_set = (arm_feature_set *)
22335 xmalloc (sizeof (arm_feature_set));
22336
22337 /* Copy the feature set, so that we can modify it. */
22338 *ext_set = **opt_p;
22339 *opt_p = ext_set;
22340
22341 while (str != NULL && *str != 0)
22342 {
22343 const struct arm_option_cpu_value_table * opt;
22344 char * ext;
22345 int optlen;
22346
22347 if (*str != '+')
22348 {
22349 as_bad (_("invalid architectural extension"));
22350 return FALSE;
22351 }
22352
22353 str++;
22354 ext = strchr (str, '+');
22355
22356 if (ext != NULL)
22357 optlen = ext - str;
22358 else
22359 optlen = strlen (str);
22360
22361 if (optlen == 0)
22362 {
22363 as_bad (_("missing architectural extension"));
22364 return FALSE;
22365 }
22366
22367 for (opt = arm_extensions; opt->name != NULL; opt++)
22368 if (strncmp (opt->name, str, optlen) == 0)
22369 {
22370 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
22371 break;
22372 }
22373
22374 if (opt->name == NULL)
22375 {
22376 as_bad (_("unknown architectural extension `%s'"), str);
22377 return FALSE;
22378 }
22379
22380 str = ext;
22381 };
22382
22383 return TRUE;
22384 }
22385
22386 static bfd_boolean
22387 arm_parse_cpu (char * str)
22388 {
22389 const struct arm_cpu_option_table * opt;
22390 char * ext = strchr (str, '+');
22391 int optlen;
22392
22393 if (ext != NULL)
22394 optlen = ext - str;
22395 else
22396 optlen = strlen (str);
22397
22398 if (optlen == 0)
22399 {
22400 as_bad (_("missing cpu name `%s'"), str);
22401 return FALSE;
22402 }
22403
22404 for (opt = arm_cpus; opt->name != NULL; opt++)
22405 if (strncmp (opt->name, str, optlen) == 0)
22406 {
22407 mcpu_cpu_opt = &opt->value;
22408 mcpu_fpu_opt = &opt->default_fpu;
22409 if (opt->canonical_name)
22410 strcpy (selected_cpu_name, opt->canonical_name);
22411 else
22412 {
22413 int i;
22414
22415 for (i = 0; i < optlen; i++)
22416 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22417 selected_cpu_name[i] = 0;
22418 }
22419
22420 if (ext != NULL)
22421 return arm_parse_extension (ext, &mcpu_cpu_opt);
22422
22423 return TRUE;
22424 }
22425
22426 as_bad (_("unknown cpu `%s'"), str);
22427 return FALSE;
22428 }
22429
22430 static bfd_boolean
22431 arm_parse_arch (char * str)
22432 {
22433 const struct arm_arch_option_table *opt;
22434 char *ext = strchr (str, '+');
22435 int optlen;
22436
22437 if (ext != NULL)
22438 optlen = ext - str;
22439 else
22440 optlen = strlen (str);
22441
22442 if (optlen == 0)
22443 {
22444 as_bad (_("missing architecture name `%s'"), str);
22445 return FALSE;
22446 }
22447
22448 for (opt = arm_archs; opt->name != NULL; opt++)
22449 if (streq (opt->name, str))
22450 {
22451 march_cpu_opt = &opt->value;
22452 march_fpu_opt = &opt->default_fpu;
22453 strcpy (selected_cpu_name, opt->name);
22454
22455 if (ext != NULL)
22456 return arm_parse_extension (ext, &march_cpu_opt);
22457
22458 return TRUE;
22459 }
22460
22461 as_bad (_("unknown architecture `%s'\n"), str);
22462 return FALSE;
22463 }
22464
22465 static bfd_boolean
22466 arm_parse_fpu (char * str)
22467 {
22468 const struct arm_option_cpu_value_table * opt;
22469
22470 for (opt = arm_fpus; opt->name != NULL; opt++)
22471 if (streq (opt->name, str))
22472 {
22473 mfpu_opt = &opt->value;
22474 return TRUE;
22475 }
22476
22477 as_bad (_("unknown floating point format `%s'\n"), str);
22478 return FALSE;
22479 }
22480
22481 static bfd_boolean
22482 arm_parse_float_abi (char * str)
22483 {
22484 const struct arm_option_value_table * opt;
22485
22486 for (opt = arm_float_abis; opt->name != NULL; opt++)
22487 if (streq (opt->name, str))
22488 {
22489 mfloat_abi_opt = opt->value;
22490 return TRUE;
22491 }
22492
22493 as_bad (_("unknown floating point abi `%s'\n"), str);
22494 return FALSE;
22495 }
22496
22497 #ifdef OBJ_ELF
22498 static bfd_boolean
22499 arm_parse_eabi (char * str)
22500 {
22501 const struct arm_option_value_table *opt;
22502
22503 for (opt = arm_eabis; opt->name != NULL; opt++)
22504 if (streq (opt->name, str))
22505 {
22506 meabi_flags = opt->value;
22507 return TRUE;
22508 }
22509 as_bad (_("unknown EABI `%s'\n"), str);
22510 return FALSE;
22511 }
22512 #endif
22513
22514 static bfd_boolean
22515 arm_parse_it_mode (char * str)
22516 {
22517 bfd_boolean ret = TRUE;
22518
22519 if (streq ("arm", str))
22520 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22521 else if (streq ("thumb", str))
22522 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22523 else if (streq ("always", str))
22524 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22525 else if (streq ("never", str))
22526 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22527 else
22528 {
22529 as_bad (_("unknown implicit IT mode `%s', should be "\
22530 "arm, thumb, always, or never."), str);
22531 ret = FALSE;
22532 }
22533
22534 return ret;
22535 }
22536
22537 struct arm_long_option_table arm_long_opts[] =
22538 {
22539 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22540 arm_parse_cpu, NULL},
22541 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22542 arm_parse_arch, NULL},
22543 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22544 arm_parse_fpu, NULL},
22545 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22546 arm_parse_float_abi, NULL},
22547 #ifdef OBJ_ELF
22548 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
22549 arm_parse_eabi, NULL},
22550 #endif
22551 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22552 arm_parse_it_mode, NULL},
22553 {NULL, NULL, 0, NULL}
22554 };
22555
22556 int
22557 md_parse_option (int c, char * arg)
22558 {
22559 struct arm_option_table *opt;
22560 const struct arm_legacy_option_table *fopt;
22561 struct arm_long_option_table *lopt;
22562
22563 switch (c)
22564 {
22565 #ifdef OPTION_EB
22566 case OPTION_EB:
22567 target_big_endian = 1;
22568 break;
22569 #endif
22570
22571 #ifdef OPTION_EL
22572 case OPTION_EL:
22573 target_big_endian = 0;
22574 break;
22575 #endif
22576
22577 case OPTION_FIX_V4BX:
22578 fix_v4bx = TRUE;
22579 break;
22580
22581 case 'a':
22582 /* Listing option. Just ignore these, we don't support additional
22583 ones. */
22584 return 0;
22585
22586 default:
22587 for (opt = arm_opts; opt->option != NULL; opt++)
22588 {
22589 if (c == opt->option[0]
22590 && ((arg == NULL && opt->option[1] == 0)
22591 || streq (arg, opt->option + 1)))
22592 {
22593 /* If the option is deprecated, tell the user. */
22594 if (warn_on_deprecated && opt->deprecated != NULL)
22595 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22596 arg ? arg : "", _(opt->deprecated));
22597
22598 if (opt->var != NULL)
22599 *opt->var = opt->value;
22600
22601 return 1;
22602 }
22603 }
22604
22605 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22606 {
22607 if (c == fopt->option[0]
22608 && ((arg == NULL && fopt->option[1] == 0)
22609 || streq (arg, fopt->option + 1)))
22610 {
22611 /* If the option is deprecated, tell the user. */
22612 if (warn_on_deprecated && fopt->deprecated != NULL)
22613 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22614 arg ? arg : "", _(fopt->deprecated));
22615
22616 if (fopt->var != NULL)
22617 *fopt->var = &fopt->value;
22618
22619 return 1;
22620 }
22621 }
22622
22623 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22624 {
22625 /* These options are expected to have an argument. */
22626 if (c == lopt->option[0]
22627 && arg != NULL
22628 && strncmp (arg, lopt->option + 1,
22629 strlen (lopt->option + 1)) == 0)
22630 {
22631 /* If the option is deprecated, tell the user. */
22632 if (warn_on_deprecated && lopt->deprecated != NULL)
22633 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22634 _(lopt->deprecated));
22635
22636 /* Call the sup-option parser. */
22637 return lopt->func (arg + strlen (lopt->option) - 1);
22638 }
22639 }
22640
22641 return 0;
22642 }
22643
22644 return 1;
22645 }
22646
22647 void
22648 md_show_usage (FILE * fp)
22649 {
22650 struct arm_option_table *opt;
22651 struct arm_long_option_table *lopt;
22652
22653 fprintf (fp, _(" ARM-specific assembler options:\n"));
22654
22655 for (opt = arm_opts; opt->option != NULL; opt++)
22656 if (opt->help != NULL)
22657 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
22658
22659 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22660 if (lopt->help != NULL)
22661 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
22662
22663 #ifdef OPTION_EB
22664 fprintf (fp, _("\
22665 -EB assemble code for a big-endian cpu\n"));
22666 #endif
22667
22668 #ifdef OPTION_EL
22669 fprintf (fp, _("\
22670 -EL assemble code for a little-endian cpu\n"));
22671 #endif
22672
22673 fprintf (fp, _("\
22674 --fix-v4bx Allow BX in ARMv4 code\n"));
22675 }
22676
22677
22678 #ifdef OBJ_ELF
22679 typedef struct
22680 {
22681 int val;
22682 arm_feature_set flags;
22683 } cpu_arch_ver_table;
22684
22685 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22686 least features first. */
22687 static const cpu_arch_ver_table cpu_arch_ver[] =
22688 {
22689 {1, ARM_ARCH_V4},
22690 {2, ARM_ARCH_V4T},
22691 {3, ARM_ARCH_V5},
22692 {3, ARM_ARCH_V5T},
22693 {4, ARM_ARCH_V5TE},
22694 {5, ARM_ARCH_V5TEJ},
22695 {6, ARM_ARCH_V6},
22696 {7, ARM_ARCH_V6Z},
22697 {9, ARM_ARCH_V6K},
22698 {11, ARM_ARCH_V6M},
22699 {8, ARM_ARCH_V6T2},
22700 {10, ARM_ARCH_V7A},
22701 {10, ARM_ARCH_V7R},
22702 {10, ARM_ARCH_V7M},
22703 {0, ARM_ARCH_NONE}
22704 };
22705
22706 /* Set an attribute if it has not already been set by the user. */
22707 static void
22708 aeabi_set_attribute_int (int tag, int value)
22709 {
22710 if (tag < 1
22711 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22712 || !attributes_set_explicitly[tag])
22713 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22714 }
22715
22716 static void
22717 aeabi_set_attribute_string (int tag, const char *value)
22718 {
22719 if (tag < 1
22720 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22721 || !attributes_set_explicitly[tag])
22722 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22723 }
22724
22725 /* Set the public EABI object attributes. */
22726 static void
22727 aeabi_set_public_attributes (void)
22728 {
22729 int arch;
22730 arm_feature_set flags;
22731 arm_feature_set tmp;
22732 const cpu_arch_ver_table *p;
22733
22734 /* Choose the architecture based on the capabilities of the requested cpu
22735 (if any) and/or the instructions actually used. */
22736 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22737 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22738 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
22739 /*Allow the user to override the reported architecture. */
22740 if (object_arch)
22741 {
22742 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22743 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22744 }
22745
22746 tmp = flags;
22747 arch = 0;
22748 for (p = cpu_arch_ver; p->val; p++)
22749 {
22750 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22751 {
22752 arch = p->val;
22753 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22754 }
22755 }
22756
22757 /* The table lookup above finds the last architecture to contribute
22758 a new feature. Unfortunately, Tag13 is a subset of the union of
22759 v6T2 and v7-M, so it is never seen as contributing a new feature.
22760 We can not search for the last entry which is entirely used,
22761 because if no CPU is specified we build up only those flags
22762 actually used. Perhaps we should separate out the specified
22763 and implicit cases. Avoid taking this path for -march=all by
22764 checking for contradictory v7-A / v7-M features. */
22765 if (arch == 10
22766 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22767 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22768 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22769 arch = 13;
22770
22771 /* Tag_CPU_name. */
22772 if (selected_cpu_name[0])
22773 {
22774 char *q;
22775
22776 q = selected_cpu_name;
22777 if (strncmp (q, "armv", 4) == 0)
22778 {
22779 int i;
22780
22781 q += 4;
22782 for (i = 0; q[i]; i++)
22783 q[i] = TOUPPER (q[i]);
22784 }
22785 aeabi_set_attribute_string (Tag_CPU_name, q);
22786 }
22787
22788 /* Tag_CPU_arch. */
22789 aeabi_set_attribute_int (Tag_CPU_arch, arch);
22790
22791 /* Tag_CPU_arch_profile. */
22792 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
22793 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
22794 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
22795 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
22796 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
22797 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
22798
22799 /* Tag_ARM_ISA_use. */
22800 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22801 || arch == 0)
22802 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
22803
22804 /* Tag_THUMB_ISA_use. */
22805 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22806 || arch == 0)
22807 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22808 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
22809
22810 /* Tag_VFP_arch. */
22811 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22812 aeabi_set_attribute_int (Tag_VFP_arch,
22813 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22814 ? 5 : 6);
22815 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
22816 aeabi_set_attribute_int (Tag_VFP_arch, 3);
22817 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
22818 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22819 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22820 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22821 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22822 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22823 aeabi_set_attribute_int (Tag_VFP_arch, 1);
22824
22825 /* Tag_WMMX_arch. */
22826 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22827 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22828 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22829 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
22830
22831 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
22832 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
22833 aeabi_set_attribute_int
22834 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22835 ? 2 : 1));
22836
22837 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
22838 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
22839 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
22840 }
22841
22842 /* Add the default contents for the .ARM.attributes section. */
22843 void
22844 arm_md_end (void)
22845 {
22846 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22847 return;
22848
22849 aeabi_set_public_attributes ();
22850 }
22851 #endif /* OBJ_ELF */
22852
22853
22854 /* Parse a .cpu directive. */
22855
22856 static void
22857 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22858 {
22859 const struct arm_cpu_option_table *opt;
22860 char *name;
22861 char saved_char;
22862
22863 name = input_line_pointer;
22864 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22865 input_line_pointer++;
22866 saved_char = *input_line_pointer;
22867 *input_line_pointer = 0;
22868
22869 /* Skip the first "all" entry. */
22870 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22871 if (streq (opt->name, name))
22872 {
22873 mcpu_cpu_opt = &opt->value;
22874 selected_cpu = opt->value;
22875 if (opt->canonical_name)
22876 strcpy (selected_cpu_name, opt->canonical_name);
22877 else
22878 {
22879 int i;
22880 for (i = 0; opt->name[i]; i++)
22881 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22882 selected_cpu_name[i] = 0;
22883 }
22884 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22885 *input_line_pointer = saved_char;
22886 demand_empty_rest_of_line ();
22887 return;
22888 }
22889 as_bad (_("unknown cpu `%s'"), name);
22890 *input_line_pointer = saved_char;
22891 ignore_rest_of_line ();
22892 }
22893
22894
22895 /* Parse a .arch directive. */
22896
22897 static void
22898 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22899 {
22900 const struct arm_arch_option_table *opt;
22901 char saved_char;
22902 char *name;
22903
22904 name = input_line_pointer;
22905 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22906 input_line_pointer++;
22907 saved_char = *input_line_pointer;
22908 *input_line_pointer = 0;
22909
22910 /* Skip the first "all" entry. */
22911 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22912 if (streq (opt->name, name))
22913 {
22914 mcpu_cpu_opt = &opt->value;
22915 selected_cpu = opt->value;
22916 strcpy (selected_cpu_name, opt->name);
22917 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22918 *input_line_pointer = saved_char;
22919 demand_empty_rest_of_line ();
22920 return;
22921 }
22922
22923 as_bad (_("unknown architecture `%s'\n"), name);
22924 *input_line_pointer = saved_char;
22925 ignore_rest_of_line ();
22926 }
22927
22928
22929 /* Parse a .object_arch directive. */
22930
22931 static void
22932 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22933 {
22934 const struct arm_arch_option_table *opt;
22935 char saved_char;
22936 char *name;
22937
22938 name = input_line_pointer;
22939 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22940 input_line_pointer++;
22941 saved_char = *input_line_pointer;
22942 *input_line_pointer = 0;
22943
22944 /* Skip the first "all" entry. */
22945 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22946 if (streq (opt->name, name))
22947 {
22948 object_arch = &opt->value;
22949 *input_line_pointer = saved_char;
22950 demand_empty_rest_of_line ();
22951 return;
22952 }
22953
22954 as_bad (_("unknown architecture `%s'\n"), name);
22955 *input_line_pointer = saved_char;
22956 ignore_rest_of_line ();
22957 }
22958
22959 /* Parse a .fpu directive. */
22960
22961 static void
22962 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
22963 {
22964 const struct arm_option_cpu_value_table *opt;
22965 char saved_char;
22966 char *name;
22967
22968 name = input_line_pointer;
22969 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22970 input_line_pointer++;
22971 saved_char = *input_line_pointer;
22972 *input_line_pointer = 0;
22973
22974 for (opt = arm_fpus; opt->name != NULL; opt++)
22975 if (streq (opt->name, name))
22976 {
22977 mfpu_opt = &opt->value;
22978 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22979 *input_line_pointer = saved_char;
22980 demand_empty_rest_of_line ();
22981 return;
22982 }
22983
22984 as_bad (_("unknown floating point format `%s'\n"), name);
22985 *input_line_pointer = saved_char;
22986 ignore_rest_of_line ();
22987 }
22988
22989 /* Copy symbol information. */
22990
22991 void
22992 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
22993 {
22994 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
22995 }
22996
22997 #ifdef OBJ_ELF
22998 /* Given a symbolic attribute NAME, return the proper integer value.
22999 Returns -1 if the attribute is not known. */
23000
23001 int
23002 arm_convert_symbolic_attribute (const char *name)
23003 {
23004 static const struct
23005 {
23006 const char * name;
23007 const int tag;
23008 }
23009 attribute_table[] =
23010 {
23011 /* When you modify this table you should
23012 also modify the list in doc/c-arm.texi. */
23013 #define T(tag) {#tag, tag}
23014 T (Tag_CPU_raw_name),
23015 T (Tag_CPU_name),
23016 T (Tag_CPU_arch),
23017 T (Tag_CPU_arch_profile),
23018 T (Tag_ARM_ISA_use),
23019 T (Tag_THUMB_ISA_use),
23020 T (Tag_VFP_arch),
23021 T (Tag_WMMX_arch),
23022 T (Tag_Advanced_SIMD_arch),
23023 T (Tag_PCS_config),
23024 T (Tag_ABI_PCS_R9_use),
23025 T (Tag_ABI_PCS_RW_data),
23026 T (Tag_ABI_PCS_RO_data),
23027 T (Tag_ABI_PCS_GOT_use),
23028 T (Tag_ABI_PCS_wchar_t),
23029 T (Tag_ABI_FP_rounding),
23030 T (Tag_ABI_FP_denormal),
23031 T (Tag_ABI_FP_exceptions),
23032 T (Tag_ABI_FP_user_exceptions),
23033 T (Tag_ABI_FP_number_model),
23034 T (Tag_ABI_align8_needed),
23035 T (Tag_ABI_align8_preserved),
23036 T (Tag_ABI_enum_size),
23037 T (Tag_ABI_HardFP_use),
23038 T (Tag_ABI_VFP_args),
23039 T (Tag_ABI_WMMX_args),
23040 T (Tag_ABI_optimization_goals),
23041 T (Tag_ABI_FP_optimization_goals),
23042 T (Tag_compatibility),
23043 T (Tag_CPU_unaligned_access),
23044 T (Tag_VFP_HP_extension),
23045 T (Tag_ABI_FP_16bit_format),
23046 T (Tag_MPextension_use),
23047 T (Tag_DIV_use),
23048 T (Tag_nodefaults),
23049 T (Tag_also_compatible_with),
23050 T (Tag_conformance),
23051 T (Tag_T2EE_use),
23052 T (Tag_Virtualization_use),
23053 /* We deliberately do not include Tag_MPextension_use_legacy. */
23054 #undef T
23055 };
23056 unsigned int i;
23057
23058 if (name == NULL)
23059 return -1;
23060
23061 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
23062 if (streq (name, attribute_table[i].name))
23063 return attribute_table[i].tag;
23064
23065 return -1;
23066 }
23067
23068
23069 /* Apply sym value for relocations only in the case that
23070 they are for local symbols and you have the respective
23071 architectural feature for blx and simple switches. */
23072 int
23073 arm_apply_sym_value (struct fix * fixP)
23074 {
23075 if (fixP->fx_addsy
23076 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23077 && !S_IS_EXTERNAL (fixP->fx_addsy))
23078 {
23079 switch (fixP->fx_r_type)
23080 {
23081 case BFD_RELOC_ARM_PCREL_BLX:
23082 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23083 if (ARM_IS_FUNC (fixP->fx_addsy))
23084 return 1;
23085 break;
23086
23087 case BFD_RELOC_ARM_PCREL_CALL:
23088 case BFD_RELOC_THUMB_PCREL_BLX:
23089 if (THUMB_IS_FUNC (fixP->fx_addsy))
23090 return 1;
23091 break;
23092
23093 default:
23094 break;
23095 }
23096
23097 }
23098 return 0;
23099 }
23100 #endif /* OBJ_ELF */
This page took 0.661483 seconds and 4 git commands to generate.