* gas/config/tc-arm.c (do_t_mov_cmp): In unified syntax encode movs as
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
27
28 #include "as.h"
29 #include <limits.h>
30 #include <stdarg.h>
31 #define NO_RELOC 0
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
35
36 #include "opcode/arm.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
42
43 #include "dwarf2dbg.h"
44
45 #ifdef OBJ_ELF
46 /* Must be at least the size of the largest unwind opcode (currently two). */
47 #define ARM_OPCODE_CHUNK_SIZE 8
48
49 /* This structure holds the unwinding state. */
50
51 static struct
52 {
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
57 /* The segment containing the function. */
58 segT saved_seg;
59 subsegT saved_subseg;
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
62 int opcode_count;
63 int opcode_alloc;
64 /* The number of bytes pushed to the stack. */
65 offsetT frame_size;
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
69 offsetT pending_offset;
70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
74 /* Nonzero if an unwind_setfp directive has been seen. */
75 unsigned fp_used:1;
76 /* Nonzero if the last opcode restores sp from fp_reg. */
77 unsigned sp_restored:1;
78 } unwind;
79
80 #endif /* OBJ_ELF */
81
82 /* Results from operand parsing worker functions. */
83
84 typedef enum
85 {
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89 } parse_operand_result;
90
91 enum arm_float_abi
92 {
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96 };
97
98 /* Types of processor to assemble for. */
99 #ifndef CPU_DEFAULT
100 /* The code that was here used to select a default CPU depending on compiler
101 pre-defines which were only present when doing native builds, thus
102 changing gas' default behaviour depending upon the build host.
103
104 If you have a target that requires a default CPU option then the you
105 should define CPU_DEFAULT here. */
106 #endif
107
108 #ifndef FPU_DEFAULT
109 # ifdef TE_LINUX
110 # define FPU_DEFAULT FPU_ARCH_FPA
111 # elif defined (TE_NetBSD)
112 # ifdef OBJ_ELF
113 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
114 # else
115 /* Legacy a.out format. */
116 # define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
117 # endif
118 # elif defined (TE_VXWORKS)
119 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
120 # else
121 /* For backwards compatibility, default to FPA. */
122 # define FPU_DEFAULT FPU_ARCH_FPA
123 # endif
124 #endif /* ifndef FPU_DEFAULT */
125
126 #define streq(a, b) (strcmp (a, b) == 0)
127
128 static arm_feature_set cpu_variant;
129 static arm_feature_set arm_arch_used;
130 static arm_feature_set thumb_arch_used;
131
132 /* Flags stored in private area of BFD structure. */
133 static int uses_apcs_26 = FALSE;
134 static int atpcs = FALSE;
135 static int support_interwork = FALSE;
136 static int uses_apcs_float = FALSE;
137 static int pic_code = FALSE;
138 static int fix_v4bx = FALSE;
139 /* Warn on using deprecated features. */
140 static int warn_on_deprecated = TRUE;
141
142
143 /* Variables that we set while parsing command-line options. Once all
144 options have been read we re-process these values to set the real
145 assembly flags. */
146 static const arm_feature_set *legacy_cpu = NULL;
147 static const arm_feature_set *legacy_fpu = NULL;
148
149 static const arm_feature_set *mcpu_cpu_opt = NULL;
150 static const arm_feature_set *mcpu_fpu_opt = NULL;
151 static const arm_feature_set *march_cpu_opt = NULL;
152 static const arm_feature_set *march_fpu_opt = NULL;
153 static const arm_feature_set *mfpu_opt = NULL;
154 static const arm_feature_set *object_arch = NULL;
155
156 /* Constants for known architecture features. */
157 static const arm_feature_set fpu_default = FPU_DEFAULT;
158 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
159 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
160 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
161 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
162 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
163 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
164 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
165 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
166
167 #ifdef CPU_DEFAULT
168 static const arm_feature_set cpu_default = CPU_DEFAULT;
169 #endif
170
171 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
172 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
173 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
174 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
175 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
176 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
177 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
178 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
179 static const arm_feature_set arm_ext_v4t_5 =
180 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
181 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
182 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
183 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
184 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
185 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
186 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
187 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
188 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
189 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
190 static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
191 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
192 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
193 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
197 static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
198 static const arm_feature_set arm_ext_m =
199 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
200
201 static const arm_feature_set arm_arch_any = ARM_ANY;
202 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
203 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
204 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
205
206 static const arm_feature_set arm_cext_iwmmxt2 =
207 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
208 static const arm_feature_set arm_cext_iwmmxt =
209 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
210 static const arm_feature_set arm_cext_xscale =
211 ARM_FEATURE (0, ARM_CEXT_XSCALE);
212 static const arm_feature_set arm_cext_maverick =
213 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
214 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
215 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
216 static const arm_feature_set fpu_vfp_ext_v1xd =
217 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
218 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
219 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
220 static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
221 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
222 static const arm_feature_set fpu_vfp_ext_d32 =
223 ARM_FEATURE (0, FPU_VFP_EXT_D32);
224 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
225 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
226 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
227 static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
228 static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
229 static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
230
231 static int mfloat_abi_opt = -1;
232 /* Record user cpu selection for object attributes. */
233 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
234 /* Must be long enough to hold any of the names in arm_cpus. */
235 static char selected_cpu_name[16];
236 #ifdef OBJ_ELF
237 # ifdef EABI_DEFAULT
238 static int meabi_flags = EABI_DEFAULT;
239 # else
240 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
241 # endif
242
243 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
244
245 bfd_boolean
246 arm_is_eabi (void)
247 {
248 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
249 }
250 #endif
251
252 #ifdef OBJ_ELF
253 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
254 symbolS * GOT_symbol;
255 #endif
256
257 /* 0: assemble for ARM,
258 1: assemble for Thumb,
259 2: assemble for Thumb even though target CPU does not support thumb
260 instructions. */
261 static int thumb_mode = 0;
262 /* A value distinct from the possible values for thumb_mode that we
263 can use to record whether thumb_mode has been copied into the
264 tc_frag_data field of a frag. */
265 #define MODE_RECORDED (1 << 4)
266
267 /* Specifies the intrinsic IT insn behavior mode. */
268 enum implicit_it_mode
269 {
270 IMPLICIT_IT_MODE_NEVER = 0x00,
271 IMPLICIT_IT_MODE_ARM = 0x01,
272 IMPLICIT_IT_MODE_THUMB = 0x02,
273 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
274 };
275 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
276
277 /* If unified_syntax is true, we are processing the new unified
278 ARM/Thumb syntax. Important differences from the old ARM mode:
279
280 - Immediate operands do not require a # prefix.
281 - Conditional affixes always appear at the end of the
282 instruction. (For backward compatibility, those instructions
283 that formerly had them in the middle, continue to accept them
284 there.)
285 - The IT instruction may appear, and if it does is validated
286 against subsequent conditional affixes. It does not generate
287 machine code.
288
289 Important differences from the old Thumb mode:
290
291 - Immediate operands do not require a # prefix.
292 - Most of the V6T2 instructions are only available in unified mode.
293 - The .N and .W suffixes are recognized and honored (it is an error
294 if they cannot be honored).
295 - All instructions set the flags if and only if they have an 's' affix.
296 - Conditional affixes may be used. They are validated against
297 preceding IT instructions. Unlike ARM mode, you cannot use a
298 conditional affix except in the scope of an IT instruction. */
299
300 static bfd_boolean unified_syntax = FALSE;
301
302 enum neon_el_type
303 {
304 NT_invtype,
305 NT_untyped,
306 NT_integer,
307 NT_float,
308 NT_poly,
309 NT_signed,
310 NT_unsigned
311 };
312
313 struct neon_type_el
314 {
315 enum neon_el_type type;
316 unsigned size;
317 };
318
319 #define NEON_MAX_TYPE_ELS 4
320
321 struct neon_type
322 {
323 struct neon_type_el el[NEON_MAX_TYPE_ELS];
324 unsigned elems;
325 };
326
327 enum it_instruction_type
328 {
329 OUTSIDE_IT_INSN,
330 INSIDE_IT_INSN,
331 INSIDE_IT_LAST_INSN,
332 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
333 if inside, should be the last one. */
334 NEUTRAL_IT_INSN, /* This could be either inside or outside,
335 i.e. BKPT and NOP. */
336 IT_INSN /* The IT insn has been parsed. */
337 };
338
339 struct arm_it
340 {
341 const char * error;
342 unsigned long instruction;
343 int size;
344 int size_req;
345 int cond;
346 /* "uncond_value" is set to the value in place of the conditional field in
347 unconditional versions of the instruction, or -1 if nothing is
348 appropriate. */
349 int uncond_value;
350 struct neon_type vectype;
351 /* This does not indicate an actual NEON instruction, only that
352 the mnemonic accepts neon-style type suffixes. */
353 int is_neon;
354 /* Set to the opcode if the instruction needs relaxation.
355 Zero if the instruction is not relaxed. */
356 unsigned long relax;
357 struct
358 {
359 bfd_reloc_code_real_type type;
360 expressionS exp;
361 int pc_rel;
362 } reloc;
363
364 enum it_instruction_type it_insn_type;
365
366 struct
367 {
368 unsigned reg;
369 signed int imm;
370 struct neon_type_el vectype;
371 unsigned present : 1; /* Operand present. */
372 unsigned isreg : 1; /* Operand was a register. */
373 unsigned immisreg : 1; /* .imm field is a second register. */
374 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
375 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
376 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
377 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
378 instructions. This allows us to disambiguate ARM <-> vector insns. */
379 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
380 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
381 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
382 unsigned issingle : 1; /* Operand is VFP single-precision register. */
383 unsigned hasreloc : 1; /* Operand has relocation suffix. */
384 unsigned writeback : 1; /* Operand has trailing ! */
385 unsigned preind : 1; /* Preindexed address. */
386 unsigned postind : 1; /* Postindexed address. */
387 unsigned negative : 1; /* Index register was negated. */
388 unsigned shifted : 1; /* Shift applied to operation. */
389 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
390 } operands[6];
391 };
392
393 static struct arm_it inst;
394
395 #define NUM_FLOAT_VALS 8
396
397 const char * fp_const[] =
398 {
399 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
400 };
401
402 /* Number of littlenums required to hold an extended precision number. */
403 #define MAX_LITTLENUMS 6
404
405 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
406
407 #define FAIL (-1)
408 #define SUCCESS (0)
409
410 #define SUFF_S 1
411 #define SUFF_D 2
412 #define SUFF_E 3
413 #define SUFF_P 4
414
415 #define CP_T_X 0x00008000
416 #define CP_T_Y 0x00400000
417
418 #define CONDS_BIT 0x00100000
419 #define LOAD_BIT 0x00100000
420
421 #define DOUBLE_LOAD_FLAG 0x00000001
422
423 struct asm_cond
424 {
425 const char * template_name;
426 unsigned long value;
427 };
428
429 #define COND_ALWAYS 0xE
430
431 struct asm_psr
432 {
433 const char * template_name;
434 unsigned long field;
435 };
436
437 struct asm_barrier_opt
438 {
439 const char * template_name;
440 unsigned long value;
441 };
442
443 /* The bit that distinguishes CPSR and SPSR. */
444 #define SPSR_BIT (1 << 22)
445
446 /* The individual PSR flag bits. */
447 #define PSR_c (1 << 16)
448 #define PSR_x (1 << 17)
449 #define PSR_s (1 << 18)
450 #define PSR_f (1 << 19)
451
452 struct reloc_entry
453 {
454 char * name;
455 bfd_reloc_code_real_type reloc;
456 };
457
458 enum vfp_reg_pos
459 {
460 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
461 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
462 };
463
464 enum vfp_ldstm_type
465 {
466 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
467 };
468
469 /* Bits for DEFINED field in neon_typed_alias. */
470 #define NTA_HASTYPE 1
471 #define NTA_HASINDEX 2
472
473 struct neon_typed_alias
474 {
475 unsigned char defined;
476 unsigned char index;
477 struct neon_type_el eltype;
478 };
479
480 /* ARM register categories. This includes coprocessor numbers and various
481 architecture extensions' registers. */
482 enum arm_reg_type
483 {
484 REG_TYPE_RN,
485 REG_TYPE_CP,
486 REG_TYPE_CN,
487 REG_TYPE_FN,
488 REG_TYPE_VFS,
489 REG_TYPE_VFD,
490 REG_TYPE_NQ,
491 REG_TYPE_VFSD,
492 REG_TYPE_NDQ,
493 REG_TYPE_NSDQ,
494 REG_TYPE_VFC,
495 REG_TYPE_MVF,
496 REG_TYPE_MVD,
497 REG_TYPE_MVFX,
498 REG_TYPE_MVDX,
499 REG_TYPE_MVAX,
500 REG_TYPE_DSPSC,
501 REG_TYPE_MMXWR,
502 REG_TYPE_MMXWC,
503 REG_TYPE_MMXWCG,
504 REG_TYPE_XSCALE,
505 };
506
507 /* Structure for a hash table entry for a register.
508 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
509 information which states whether a vector type or index is specified (for a
510 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
511 struct reg_entry
512 {
513 const char * name;
514 unsigned char number;
515 unsigned char type;
516 unsigned char builtin;
517 struct neon_typed_alias * neon;
518 };
519
520 /* Diagnostics used when we don't get a register of the expected type. */
521 const char * const reg_expected_msgs[] =
522 {
523 N_("ARM register expected"),
524 N_("bad or missing co-processor number"),
525 N_("co-processor register expected"),
526 N_("FPA register expected"),
527 N_("VFP single precision register expected"),
528 N_("VFP/Neon double precision register expected"),
529 N_("Neon quad precision register expected"),
530 N_("VFP single or double precision register expected"),
531 N_("Neon double or quad precision register expected"),
532 N_("VFP single, double or Neon quad precision register expected"),
533 N_("VFP system register expected"),
534 N_("Maverick MVF register expected"),
535 N_("Maverick MVD register expected"),
536 N_("Maverick MVFX register expected"),
537 N_("Maverick MVDX register expected"),
538 N_("Maverick MVAX register expected"),
539 N_("Maverick DSPSC register expected"),
540 N_("iWMMXt data register expected"),
541 N_("iWMMXt control register expected"),
542 N_("iWMMXt scalar register expected"),
543 N_("XScale accumulator register expected"),
544 };
545
546 /* Some well known registers that we refer to directly elsewhere. */
547 #define REG_SP 13
548 #define REG_LR 14
549 #define REG_PC 15
550
551 /* ARM instructions take 4bytes in the object file, Thumb instructions
552 take 2: */
553 #define INSN_SIZE 4
554
555 struct asm_opcode
556 {
557 /* Basic string to match. */
558 const char * template_name;
559
560 /* Parameters to instruction. */
561 unsigned int operands[8];
562
563 /* Conditional tag - see opcode_lookup. */
564 unsigned int tag : 4;
565
566 /* Basic instruction code. */
567 unsigned int avalue : 28;
568
569 /* Thumb-format instruction code. */
570 unsigned int tvalue;
571
572 /* Which architecture variant provides this instruction. */
573 const arm_feature_set * avariant;
574 const arm_feature_set * tvariant;
575
576 /* Function to call to encode instruction in ARM format. */
577 void (* aencode) (void);
578
579 /* Function to call to encode instruction in Thumb format. */
580 void (* tencode) (void);
581 };
582
583 /* Defines for various bits that we will want to toggle. */
584 #define INST_IMMEDIATE 0x02000000
585 #define OFFSET_REG 0x02000000
586 #define HWOFFSET_IMM 0x00400000
587 #define SHIFT_BY_REG 0x00000010
588 #define PRE_INDEX 0x01000000
589 #define INDEX_UP 0x00800000
590 #define WRITE_BACK 0x00200000
591 #define LDM_TYPE_2_OR_3 0x00400000
592 #define CPSI_MMOD 0x00020000
593
594 #define LITERAL_MASK 0xf000f000
595 #define OPCODE_MASK 0xfe1fffff
596 #define V4_STR_BIT 0x00000020
597
598 #define T2_SUBS_PC_LR 0xf3de8f00
599
600 #define DATA_OP_SHIFT 21
601
602 #define T2_OPCODE_MASK 0xfe1fffff
603 #define T2_DATA_OP_SHIFT 21
604
605 /* Codes to distinguish the arithmetic instructions. */
606 #define OPCODE_AND 0
607 #define OPCODE_EOR 1
608 #define OPCODE_SUB 2
609 #define OPCODE_RSB 3
610 #define OPCODE_ADD 4
611 #define OPCODE_ADC 5
612 #define OPCODE_SBC 6
613 #define OPCODE_RSC 7
614 #define OPCODE_TST 8
615 #define OPCODE_TEQ 9
616 #define OPCODE_CMP 10
617 #define OPCODE_CMN 11
618 #define OPCODE_ORR 12
619 #define OPCODE_MOV 13
620 #define OPCODE_BIC 14
621 #define OPCODE_MVN 15
622
623 #define T2_OPCODE_AND 0
624 #define T2_OPCODE_BIC 1
625 #define T2_OPCODE_ORR 2
626 #define T2_OPCODE_ORN 3
627 #define T2_OPCODE_EOR 4
628 #define T2_OPCODE_ADD 8
629 #define T2_OPCODE_ADC 10
630 #define T2_OPCODE_SBC 11
631 #define T2_OPCODE_SUB 13
632 #define T2_OPCODE_RSB 14
633
634 #define T_OPCODE_MUL 0x4340
635 #define T_OPCODE_TST 0x4200
636 #define T_OPCODE_CMN 0x42c0
637 #define T_OPCODE_NEG 0x4240
638 #define T_OPCODE_MVN 0x43c0
639
640 #define T_OPCODE_ADD_R3 0x1800
641 #define T_OPCODE_SUB_R3 0x1a00
642 #define T_OPCODE_ADD_HI 0x4400
643 #define T_OPCODE_ADD_ST 0xb000
644 #define T_OPCODE_SUB_ST 0xb080
645 #define T_OPCODE_ADD_SP 0xa800
646 #define T_OPCODE_ADD_PC 0xa000
647 #define T_OPCODE_ADD_I8 0x3000
648 #define T_OPCODE_SUB_I8 0x3800
649 #define T_OPCODE_ADD_I3 0x1c00
650 #define T_OPCODE_SUB_I3 0x1e00
651
652 #define T_OPCODE_ASR_R 0x4100
653 #define T_OPCODE_LSL_R 0x4080
654 #define T_OPCODE_LSR_R 0x40c0
655 #define T_OPCODE_ROR_R 0x41c0
656 #define T_OPCODE_ASR_I 0x1000
657 #define T_OPCODE_LSL_I 0x0000
658 #define T_OPCODE_LSR_I 0x0800
659
660 #define T_OPCODE_MOV_I8 0x2000
661 #define T_OPCODE_CMP_I8 0x2800
662 #define T_OPCODE_CMP_LR 0x4280
663 #define T_OPCODE_MOV_HR 0x4600
664 #define T_OPCODE_CMP_HR 0x4500
665
666 #define T_OPCODE_LDR_PC 0x4800
667 #define T_OPCODE_LDR_SP 0x9800
668 #define T_OPCODE_STR_SP 0x9000
669 #define T_OPCODE_LDR_IW 0x6800
670 #define T_OPCODE_STR_IW 0x6000
671 #define T_OPCODE_LDR_IH 0x8800
672 #define T_OPCODE_STR_IH 0x8000
673 #define T_OPCODE_LDR_IB 0x7800
674 #define T_OPCODE_STR_IB 0x7000
675 #define T_OPCODE_LDR_RW 0x5800
676 #define T_OPCODE_STR_RW 0x5000
677 #define T_OPCODE_LDR_RH 0x5a00
678 #define T_OPCODE_STR_RH 0x5200
679 #define T_OPCODE_LDR_RB 0x5c00
680 #define T_OPCODE_STR_RB 0x5400
681
682 #define T_OPCODE_PUSH 0xb400
683 #define T_OPCODE_POP 0xbc00
684
685 #define T_OPCODE_BRANCH 0xe000
686
687 #define THUMB_SIZE 2 /* Size of thumb instruction. */
688 #define THUMB_PP_PC_LR 0x0100
689 #define THUMB_LOAD_BIT 0x0800
690 #define THUMB2_LOAD_BIT 0x00100000
691
692 #define BAD_ARGS _("bad arguments to instruction")
693 #define BAD_SP _("r13 not allowed here")
694 #define BAD_PC _("r15 not allowed here")
695 #define BAD_COND _("instruction cannot be conditional")
696 #define BAD_OVERLAP _("registers may not be the same")
697 #define BAD_HIREG _("lo register required")
698 #define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
699 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
700 #define BAD_BRANCH _("branch must be last instruction in IT block")
701 #define BAD_NOT_IT _("instruction not allowed in IT block")
702 #define BAD_FPU _("selected FPU does not support instruction")
703 #define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
704 #define BAD_IT_COND _("incorrect condition in IT block")
705 #define BAD_IT_IT _("IT falling in the range of a previous IT block")
706 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
707 #define BAD_PC_ADDRESSING \
708 _("cannot use register index with PC-relative addressing")
709 #define BAD_PC_WRITEBACK \
710 _("cannot use writeback with PC-relative addressing")
711
712 static struct hash_control * arm_ops_hsh;
713 static struct hash_control * arm_cond_hsh;
714 static struct hash_control * arm_shift_hsh;
715 static struct hash_control * arm_psr_hsh;
716 static struct hash_control * arm_v7m_psr_hsh;
717 static struct hash_control * arm_reg_hsh;
718 static struct hash_control * arm_reloc_hsh;
719 static struct hash_control * arm_barrier_opt_hsh;
720
721 /* Stuff needed to resolve the label ambiguity
722 As:
723 ...
724 label: <insn>
725 may differ from:
726 ...
727 label:
728 <insn> */
729
730 symbolS * last_label_seen;
731 static int label_is_thumb_function_name = FALSE;
732
733 /* Literal pool structure. Held on a per-section
734 and per-sub-section basis. */
735
736 #define MAX_LITERAL_POOL_SIZE 1024
737 typedef struct literal_pool
738 {
739 expressionS literals [MAX_LITERAL_POOL_SIZE];
740 unsigned int next_free_entry;
741 unsigned int id;
742 symbolS * symbol;
743 segT section;
744 subsegT sub_section;
745 struct literal_pool * next;
746 } literal_pool;
747
748 /* Pointer to a linked list of literal pools. */
749 literal_pool * list_of_pools = NULL;
750
751 #ifdef OBJ_ELF
752 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
753 #else
754 static struct current_it now_it;
755 #endif
756
757 static inline int
758 now_it_compatible (int cond)
759 {
760 return (cond & ~1) == (now_it.cc & ~1);
761 }
762
763 static inline int
764 conditional_insn (void)
765 {
766 return inst.cond != COND_ALWAYS;
767 }
768
769 static int in_it_block (void);
770
771 static int handle_it_state (void);
772
773 static void force_automatic_it_block_close (void);
774
775 static void it_fsm_post_encode (void);
776
777 #define set_it_insn_type(type) \
778 do \
779 { \
780 inst.it_insn_type = type; \
781 if (handle_it_state () == FAIL) \
782 return; \
783 } \
784 while (0)
785
786 #define set_it_insn_type_nonvoid(type, failret) \
787 do \
788 { \
789 inst.it_insn_type = type; \
790 if (handle_it_state () == FAIL) \
791 return failret; \
792 } \
793 while(0)
794
795 #define set_it_insn_type_last() \
796 do \
797 { \
798 if (inst.cond == COND_ALWAYS) \
799 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
800 else \
801 set_it_insn_type (INSIDE_IT_LAST_INSN); \
802 } \
803 while (0)
804
805 /* Pure syntax. */
806
807 /* This array holds the chars that always start a comment. If the
808 pre-processor is disabled, these aren't very useful. */
809 const char comment_chars[] = "@";
810
811 /* This array holds the chars that only start a comment at the beginning of
812 a line. If the line seems to have the form '# 123 filename'
813 .line and .file directives will appear in the pre-processed output. */
814 /* Note that input_file.c hand checks for '#' at the beginning of the
815 first line of the input file. This is because the compiler outputs
816 #NO_APP at the beginning of its output. */
817 /* Also note that comments like this one will always work. */
818 const char line_comment_chars[] = "#";
819
820 const char line_separator_chars[] = ";";
821
822 /* Chars that can be used to separate mant
823 from exp in floating point numbers. */
824 const char EXP_CHARS[] = "eE";
825
826 /* Chars that mean this number is a floating point constant. */
827 /* As in 0f12.456 */
828 /* or 0d1.2345e12 */
829
830 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
831
832 /* Prefix characters that indicate the start of an immediate
833 value. */
834 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
835
836 /* Separator character handling. */
837
838 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
839
840 static inline int
841 skip_past_char (char ** str, char c)
842 {
843 if (**str == c)
844 {
845 (*str)++;
846 return SUCCESS;
847 }
848 else
849 return FAIL;
850 }
851
852 #define skip_past_comma(str) skip_past_char (str, ',')
853
854 /* Arithmetic expressions (possibly involving symbols). */
855
856 /* Return TRUE if anything in the expression is a bignum. */
857
858 static int
859 walk_no_bignums (symbolS * sp)
860 {
861 if (symbol_get_value_expression (sp)->X_op == O_big)
862 return 1;
863
864 if (symbol_get_value_expression (sp)->X_add_symbol)
865 {
866 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
867 || (symbol_get_value_expression (sp)->X_op_symbol
868 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
869 }
870
871 return 0;
872 }
873
874 static int in_my_get_expression = 0;
875
876 /* Third argument to my_get_expression. */
877 #define GE_NO_PREFIX 0
878 #define GE_IMM_PREFIX 1
879 #define GE_OPT_PREFIX 2
880 /* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
881 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
882 #define GE_OPT_PREFIX_BIG 3
883
884 static int
885 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
886 {
887 char * save_in;
888 segT seg;
889
890 /* In unified syntax, all prefixes are optional. */
891 if (unified_syntax)
892 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
893 : GE_OPT_PREFIX;
894
895 switch (prefix_mode)
896 {
897 case GE_NO_PREFIX: break;
898 case GE_IMM_PREFIX:
899 if (!is_immediate_prefix (**str))
900 {
901 inst.error = _("immediate expression requires a # prefix");
902 return FAIL;
903 }
904 (*str)++;
905 break;
906 case GE_OPT_PREFIX:
907 case GE_OPT_PREFIX_BIG:
908 if (is_immediate_prefix (**str))
909 (*str)++;
910 break;
911 default: abort ();
912 }
913
914 memset (ep, 0, sizeof (expressionS));
915
916 save_in = input_line_pointer;
917 input_line_pointer = *str;
918 in_my_get_expression = 1;
919 seg = expression (ep);
920 in_my_get_expression = 0;
921
922 if (ep->X_op == O_illegal || ep->X_op == O_absent)
923 {
924 /* We found a bad or missing expression in md_operand(). */
925 *str = input_line_pointer;
926 input_line_pointer = save_in;
927 if (inst.error == NULL)
928 inst.error = (ep->X_op == O_absent
929 ? _("missing expression") :_("bad expression"));
930 return 1;
931 }
932
933 #ifdef OBJ_AOUT
934 if (seg != absolute_section
935 && seg != text_section
936 && seg != data_section
937 && seg != bss_section
938 && seg != undefined_section)
939 {
940 inst.error = _("bad segment");
941 *str = input_line_pointer;
942 input_line_pointer = save_in;
943 return 1;
944 }
945 #endif
946
947 /* Get rid of any bignums now, so that we don't generate an error for which
948 we can't establish a line number later on. Big numbers are never valid
949 in instructions, which is where this routine is always called. */
950 if (prefix_mode != GE_OPT_PREFIX_BIG
951 && (ep->X_op == O_big
952 || (ep->X_add_symbol
953 && (walk_no_bignums (ep->X_add_symbol)
954 || (ep->X_op_symbol
955 && walk_no_bignums (ep->X_op_symbol))))))
956 {
957 inst.error = _("invalid constant");
958 *str = input_line_pointer;
959 input_line_pointer = save_in;
960 return 1;
961 }
962
963 *str = input_line_pointer;
964 input_line_pointer = save_in;
965 return 0;
966 }
967
968 /* Turn a string in input_line_pointer into a floating point constant
969 of type TYPE, and store the appropriate bytes in *LITP. The number
970 of LITTLENUMS emitted is stored in *SIZEP. An error message is
971 returned, or NULL on OK.
972
973 Note that fp constants aren't represent in the normal way on the ARM.
974 In big endian mode, things are as expected. However, in little endian
975 mode fp constants are big-endian word-wise, and little-endian byte-wise
976 within the words. For example, (double) 1.1 in big endian mode is
977 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
978 the byte sequence 99 99 f1 3f 9a 99 99 99.
979
980 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
981
982 char *
983 md_atof (int type, char * litP, int * sizeP)
984 {
985 int prec;
986 LITTLENUM_TYPE words[MAX_LITTLENUMS];
987 char *t;
988 int i;
989
990 switch (type)
991 {
992 case 'f':
993 case 'F':
994 case 's':
995 case 'S':
996 prec = 2;
997 break;
998
999 case 'd':
1000 case 'D':
1001 case 'r':
1002 case 'R':
1003 prec = 4;
1004 break;
1005
1006 case 'x':
1007 case 'X':
1008 prec = 5;
1009 break;
1010
1011 case 'p':
1012 case 'P':
1013 prec = 5;
1014 break;
1015
1016 default:
1017 *sizeP = 0;
1018 return _("Unrecognized or unsupported floating point constant");
1019 }
1020
1021 t = atof_ieee (input_line_pointer, type, words);
1022 if (t)
1023 input_line_pointer = t;
1024 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1025
1026 if (target_big_endian)
1027 {
1028 for (i = 0; i < prec; i++)
1029 {
1030 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1031 litP += sizeof (LITTLENUM_TYPE);
1032 }
1033 }
1034 else
1035 {
1036 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1037 for (i = prec - 1; i >= 0; i--)
1038 {
1039 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1040 litP += sizeof (LITTLENUM_TYPE);
1041 }
1042 else
1043 /* For a 4 byte float the order of elements in `words' is 1 0.
1044 For an 8 byte float the order is 1 0 3 2. */
1045 for (i = 0; i < prec; i += 2)
1046 {
1047 md_number_to_chars (litP, (valueT) words[i + 1],
1048 sizeof (LITTLENUM_TYPE));
1049 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1050 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1051 litP += 2 * sizeof (LITTLENUM_TYPE);
1052 }
1053 }
1054
1055 return NULL;
1056 }
1057
1058 /* We handle all bad expressions here, so that we can report the faulty
1059 instruction in the error message. */
1060 void
1061 md_operand (expressionS * exp)
1062 {
1063 if (in_my_get_expression)
1064 exp->X_op = O_illegal;
1065 }
1066
1067 /* Immediate values. */
1068
1069 /* Generic immediate-value read function for use in directives.
1070 Accepts anything that 'expression' can fold to a constant.
1071 *val receives the number. */
1072 #ifdef OBJ_ELF
1073 static int
1074 immediate_for_directive (int *val)
1075 {
1076 expressionS exp;
1077 exp.X_op = O_illegal;
1078
1079 if (is_immediate_prefix (*input_line_pointer))
1080 {
1081 input_line_pointer++;
1082 expression (&exp);
1083 }
1084
1085 if (exp.X_op != O_constant)
1086 {
1087 as_bad (_("expected #constant"));
1088 ignore_rest_of_line ();
1089 return FAIL;
1090 }
1091 *val = exp.X_add_number;
1092 return SUCCESS;
1093 }
1094 #endif
1095
1096 /* Register parsing. */
1097
1098 /* Generic register parser. CCP points to what should be the
1099 beginning of a register name. If it is indeed a valid register
1100 name, advance CCP over it and return the reg_entry structure;
1101 otherwise return NULL. Does not issue diagnostics. */
1102
1103 static struct reg_entry *
1104 arm_reg_parse_multi (char **ccp)
1105 {
1106 char *start = *ccp;
1107 char *p;
1108 struct reg_entry *reg;
1109
1110 #ifdef REGISTER_PREFIX
1111 if (*start != REGISTER_PREFIX)
1112 return NULL;
1113 start++;
1114 #endif
1115 #ifdef OPTIONAL_REGISTER_PREFIX
1116 if (*start == OPTIONAL_REGISTER_PREFIX)
1117 start++;
1118 #endif
1119
1120 p = start;
1121 if (!ISALPHA (*p) || !is_name_beginner (*p))
1122 return NULL;
1123
1124 do
1125 p++;
1126 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1127
1128 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1129
1130 if (!reg)
1131 return NULL;
1132
1133 *ccp = p;
1134 return reg;
1135 }
1136
1137 static int
1138 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1139 enum arm_reg_type type)
1140 {
1141 /* Alternative syntaxes are accepted for a few register classes. */
1142 switch (type)
1143 {
1144 case REG_TYPE_MVF:
1145 case REG_TYPE_MVD:
1146 case REG_TYPE_MVFX:
1147 case REG_TYPE_MVDX:
1148 /* Generic coprocessor register names are allowed for these. */
1149 if (reg && reg->type == REG_TYPE_CN)
1150 return reg->number;
1151 break;
1152
1153 case REG_TYPE_CP:
1154 /* For backward compatibility, a bare number is valid here. */
1155 {
1156 unsigned long processor = strtoul (start, ccp, 10);
1157 if (*ccp != start && processor <= 15)
1158 return processor;
1159 }
1160
1161 case REG_TYPE_MMXWC:
1162 /* WC includes WCG. ??? I'm not sure this is true for all
1163 instructions that take WC registers. */
1164 if (reg && reg->type == REG_TYPE_MMXWCG)
1165 return reg->number;
1166 break;
1167
1168 default:
1169 break;
1170 }
1171
1172 return FAIL;
1173 }
1174
1175 /* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1176 return value is the register number or FAIL. */
1177
1178 static int
1179 arm_reg_parse (char **ccp, enum arm_reg_type type)
1180 {
1181 char *start = *ccp;
1182 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1183 int ret;
1184
1185 /* Do not allow a scalar (reg+index) to parse as a register. */
1186 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1187 return FAIL;
1188
1189 if (reg && reg->type == type)
1190 return reg->number;
1191
1192 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1193 return ret;
1194
1195 *ccp = start;
1196 return FAIL;
1197 }
1198
1199 /* Parse a Neon type specifier. *STR should point at the leading '.'
1200 character. Does no verification at this stage that the type fits the opcode
1201 properly. E.g.,
1202
1203 .i32.i32.s16
1204 .s32.f32
1205 .u16
1206
1207 Can all be legally parsed by this function.
1208
1209 Fills in neon_type struct pointer with parsed information, and updates STR
1210 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1211 type, FAIL if not. */
1212
1213 static int
1214 parse_neon_type (struct neon_type *type, char **str)
1215 {
1216 char *ptr = *str;
1217
1218 if (type)
1219 type->elems = 0;
1220
1221 while (type->elems < NEON_MAX_TYPE_ELS)
1222 {
1223 enum neon_el_type thistype = NT_untyped;
1224 unsigned thissize = -1u;
1225
1226 if (*ptr != '.')
1227 break;
1228
1229 ptr++;
1230
1231 /* Just a size without an explicit type. */
1232 if (ISDIGIT (*ptr))
1233 goto parsesize;
1234
1235 switch (TOLOWER (*ptr))
1236 {
1237 case 'i': thistype = NT_integer; break;
1238 case 'f': thistype = NT_float; break;
1239 case 'p': thistype = NT_poly; break;
1240 case 's': thistype = NT_signed; break;
1241 case 'u': thistype = NT_unsigned; break;
1242 case 'd':
1243 thistype = NT_float;
1244 thissize = 64;
1245 ptr++;
1246 goto done;
1247 default:
1248 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1249 return FAIL;
1250 }
1251
1252 ptr++;
1253
1254 /* .f is an abbreviation for .f32. */
1255 if (thistype == NT_float && !ISDIGIT (*ptr))
1256 thissize = 32;
1257 else
1258 {
1259 parsesize:
1260 thissize = strtoul (ptr, &ptr, 10);
1261
1262 if (thissize != 8 && thissize != 16 && thissize != 32
1263 && thissize != 64)
1264 {
1265 as_bad (_("bad size %d in type specifier"), thissize);
1266 return FAIL;
1267 }
1268 }
1269
1270 done:
1271 if (type)
1272 {
1273 type->el[type->elems].type = thistype;
1274 type->el[type->elems].size = thissize;
1275 type->elems++;
1276 }
1277 }
1278
1279 /* Empty/missing type is not a successful parse. */
1280 if (type->elems == 0)
1281 return FAIL;
1282
1283 *str = ptr;
1284
1285 return SUCCESS;
1286 }
1287
1288 /* Errors may be set multiple times during parsing or bit encoding
1289 (particularly in the Neon bits), but usually the earliest error which is set
1290 will be the most meaningful. Avoid overwriting it with later (cascading)
1291 errors by calling this function. */
1292
1293 static void
1294 first_error (const char *err)
1295 {
1296 if (!inst.error)
1297 inst.error = err;
1298 }
1299
1300 /* Parse a single type, e.g. ".s32", leading period included. */
1301 static int
1302 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1303 {
1304 char *str = *ccp;
1305 struct neon_type optype;
1306
1307 if (*str == '.')
1308 {
1309 if (parse_neon_type (&optype, &str) == SUCCESS)
1310 {
1311 if (optype.elems == 1)
1312 *vectype = optype.el[0];
1313 else
1314 {
1315 first_error (_("only one type should be specified for operand"));
1316 return FAIL;
1317 }
1318 }
1319 else
1320 {
1321 first_error (_("vector type expected"));
1322 return FAIL;
1323 }
1324 }
1325 else
1326 return FAIL;
1327
1328 *ccp = str;
1329
1330 return SUCCESS;
1331 }
1332
1333 /* Special meanings for indices (which have a range of 0-7), which will fit into
1334 a 4-bit integer. */
1335
1336 #define NEON_ALL_LANES 15
1337 #define NEON_INTERLEAVE_LANES 14
1338
1339 /* Parse either a register or a scalar, with an optional type. Return the
1340 register number, and optionally fill in the actual type of the register
1341 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1342 type/index information in *TYPEINFO. */
1343
1344 static int
1345 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1346 enum arm_reg_type *rtype,
1347 struct neon_typed_alias *typeinfo)
1348 {
1349 char *str = *ccp;
1350 struct reg_entry *reg = arm_reg_parse_multi (&str);
1351 struct neon_typed_alias atype;
1352 struct neon_type_el parsetype;
1353
1354 atype.defined = 0;
1355 atype.index = -1;
1356 atype.eltype.type = NT_invtype;
1357 atype.eltype.size = -1;
1358
1359 /* Try alternate syntax for some types of register. Note these are mutually
1360 exclusive with the Neon syntax extensions. */
1361 if (reg == NULL)
1362 {
1363 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1364 if (altreg != FAIL)
1365 *ccp = str;
1366 if (typeinfo)
1367 *typeinfo = atype;
1368 return altreg;
1369 }
1370
1371 /* Undo polymorphism when a set of register types may be accepted. */
1372 if ((type == REG_TYPE_NDQ
1373 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1374 || (type == REG_TYPE_VFSD
1375 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1376 || (type == REG_TYPE_NSDQ
1377 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1378 || reg->type == REG_TYPE_NQ))
1379 || (type == REG_TYPE_MMXWC
1380 && (reg->type == REG_TYPE_MMXWCG)))
1381 type = (enum arm_reg_type) reg->type;
1382
1383 if (type != reg->type)
1384 return FAIL;
1385
1386 if (reg->neon)
1387 atype = *reg->neon;
1388
1389 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1390 {
1391 if ((atype.defined & NTA_HASTYPE) != 0)
1392 {
1393 first_error (_("can't redefine type for operand"));
1394 return FAIL;
1395 }
1396 atype.defined |= NTA_HASTYPE;
1397 atype.eltype = parsetype;
1398 }
1399
1400 if (skip_past_char (&str, '[') == SUCCESS)
1401 {
1402 if (type != REG_TYPE_VFD)
1403 {
1404 first_error (_("only D registers may be indexed"));
1405 return FAIL;
1406 }
1407
1408 if ((atype.defined & NTA_HASINDEX) != 0)
1409 {
1410 first_error (_("can't change index for operand"));
1411 return FAIL;
1412 }
1413
1414 atype.defined |= NTA_HASINDEX;
1415
1416 if (skip_past_char (&str, ']') == SUCCESS)
1417 atype.index = NEON_ALL_LANES;
1418 else
1419 {
1420 expressionS exp;
1421
1422 my_get_expression (&exp, &str, GE_NO_PREFIX);
1423
1424 if (exp.X_op != O_constant)
1425 {
1426 first_error (_("constant expression required"));
1427 return FAIL;
1428 }
1429
1430 if (skip_past_char (&str, ']') == FAIL)
1431 return FAIL;
1432
1433 atype.index = exp.X_add_number;
1434 }
1435 }
1436
1437 if (typeinfo)
1438 *typeinfo = atype;
1439
1440 if (rtype)
1441 *rtype = type;
1442
1443 *ccp = str;
1444
1445 return reg->number;
1446 }
1447
1448 /* Like arm_reg_parse, but allow allow the following extra features:
1449 - If RTYPE is non-zero, return the (possibly restricted) type of the
1450 register (e.g. Neon double or quad reg when either has been requested).
1451 - If this is a Neon vector type with additional type information, fill
1452 in the struct pointed to by VECTYPE (if non-NULL).
1453 This function will fault on encountering a scalar. */
1454
1455 static int
1456 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1457 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1458 {
1459 struct neon_typed_alias atype;
1460 char *str = *ccp;
1461 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1462
1463 if (reg == FAIL)
1464 return FAIL;
1465
1466 /* Do not allow a scalar (reg+index) to parse as a register. */
1467 if ((atype.defined & NTA_HASINDEX) != 0)
1468 {
1469 first_error (_("register operand expected, but got scalar"));
1470 return FAIL;
1471 }
1472
1473 if (vectype)
1474 *vectype = atype.eltype;
1475
1476 *ccp = str;
1477
1478 return reg;
1479 }
1480
1481 #define NEON_SCALAR_REG(X) ((X) >> 4)
1482 #define NEON_SCALAR_INDEX(X) ((X) & 15)
1483
1484 /* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1485 have enough information to be able to do a good job bounds-checking. So, we
1486 just do easy checks here, and do further checks later. */
1487
1488 static int
1489 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1490 {
1491 int reg;
1492 char *str = *ccp;
1493 struct neon_typed_alias atype;
1494
1495 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1496
1497 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1498 return FAIL;
1499
1500 if (atype.index == NEON_ALL_LANES)
1501 {
1502 first_error (_("scalar must have an index"));
1503 return FAIL;
1504 }
1505 else if (atype.index >= 64 / elsize)
1506 {
1507 first_error (_("scalar index out of range"));
1508 return FAIL;
1509 }
1510
1511 if (type)
1512 *type = atype.eltype;
1513
1514 *ccp = str;
1515
1516 return reg * 16 + atype.index;
1517 }
1518
1519 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1520
1521 static long
1522 parse_reg_list (char ** strp)
1523 {
1524 char * str = * strp;
1525 long range = 0;
1526 int another_range;
1527
1528 /* We come back here if we get ranges concatenated by '+' or '|'. */
1529 do
1530 {
1531 another_range = 0;
1532
1533 if (*str == '{')
1534 {
1535 int in_range = 0;
1536 int cur_reg = -1;
1537
1538 str++;
1539 do
1540 {
1541 int reg;
1542
1543 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1544 {
1545 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1546 return FAIL;
1547 }
1548
1549 if (in_range)
1550 {
1551 int i;
1552
1553 if (reg <= cur_reg)
1554 {
1555 first_error (_("bad range in register list"));
1556 return FAIL;
1557 }
1558
1559 for (i = cur_reg + 1; i < reg; i++)
1560 {
1561 if (range & (1 << i))
1562 as_tsktsk
1563 (_("Warning: duplicated register (r%d) in register list"),
1564 i);
1565 else
1566 range |= 1 << i;
1567 }
1568 in_range = 0;
1569 }
1570
1571 if (range & (1 << reg))
1572 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1573 reg);
1574 else if (reg <= cur_reg)
1575 as_tsktsk (_("Warning: register range not in ascending order"));
1576
1577 range |= 1 << reg;
1578 cur_reg = reg;
1579 }
1580 while (skip_past_comma (&str) != FAIL
1581 || (in_range = 1, *str++ == '-'));
1582 str--;
1583
1584 if (*str++ != '}')
1585 {
1586 first_error (_("missing `}'"));
1587 return FAIL;
1588 }
1589 }
1590 else
1591 {
1592 expressionS exp;
1593
1594 if (my_get_expression (&exp, &str, GE_NO_PREFIX))
1595 return FAIL;
1596
1597 if (exp.X_op == O_constant)
1598 {
1599 if (exp.X_add_number
1600 != (exp.X_add_number & 0x0000ffff))
1601 {
1602 inst.error = _("invalid register mask");
1603 return FAIL;
1604 }
1605
1606 if ((range & exp.X_add_number) != 0)
1607 {
1608 int regno = range & exp.X_add_number;
1609
1610 regno &= -regno;
1611 regno = (1 << regno) - 1;
1612 as_tsktsk
1613 (_("Warning: duplicated register (r%d) in register list"),
1614 regno);
1615 }
1616
1617 range |= exp.X_add_number;
1618 }
1619 else
1620 {
1621 if (inst.reloc.type != 0)
1622 {
1623 inst.error = _("expression too complex");
1624 return FAIL;
1625 }
1626
1627 memcpy (&inst.reloc.exp, &exp, sizeof (expressionS));
1628 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1629 inst.reloc.pc_rel = 0;
1630 }
1631 }
1632
1633 if (*str == '|' || *str == '+')
1634 {
1635 str++;
1636 another_range = 1;
1637 }
1638 }
1639 while (another_range);
1640
1641 *strp = str;
1642 return range;
1643 }
1644
1645 /* Types of registers in a list. */
1646
1647 enum reg_list_els
1648 {
1649 REGLIST_VFP_S,
1650 REGLIST_VFP_D,
1651 REGLIST_NEON_D
1652 };
1653
1654 /* Parse a VFP register list. If the string is invalid return FAIL.
1655 Otherwise return the number of registers, and set PBASE to the first
1656 register. Parses registers of type ETYPE.
1657 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1658 - Q registers can be used to specify pairs of D registers
1659 - { } can be omitted from around a singleton register list
1660 FIXME: This is not implemented, as it would require backtracking in
1661 some cases, e.g.:
1662 vtbl.8 d3,d4,d5
1663 This could be done (the meaning isn't really ambiguous), but doesn't
1664 fit in well with the current parsing framework.
1665 - 32 D registers may be used (also true for VFPv3).
1666 FIXME: Types are ignored in these register lists, which is probably a
1667 bug. */
1668
1669 static int
1670 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1671 {
1672 char *str = *ccp;
1673 int base_reg;
1674 int new_base;
1675 enum arm_reg_type regtype = (enum arm_reg_type) 0;
1676 int max_regs = 0;
1677 int count = 0;
1678 int warned = 0;
1679 unsigned long mask = 0;
1680 int i;
1681
1682 if (*str != '{')
1683 {
1684 inst.error = _("expecting {");
1685 return FAIL;
1686 }
1687
1688 str++;
1689
1690 switch (etype)
1691 {
1692 case REGLIST_VFP_S:
1693 regtype = REG_TYPE_VFS;
1694 max_regs = 32;
1695 break;
1696
1697 case REGLIST_VFP_D:
1698 regtype = REG_TYPE_VFD;
1699 break;
1700
1701 case REGLIST_NEON_D:
1702 regtype = REG_TYPE_NDQ;
1703 break;
1704 }
1705
1706 if (etype != REGLIST_VFP_S)
1707 {
1708 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1709 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1710 {
1711 max_regs = 32;
1712 if (thumb_mode)
1713 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1714 fpu_vfp_ext_d32);
1715 else
1716 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1717 fpu_vfp_ext_d32);
1718 }
1719 else
1720 max_regs = 16;
1721 }
1722
1723 base_reg = max_regs;
1724
1725 do
1726 {
1727 int setmask = 1, addregs = 1;
1728
1729 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1730
1731 if (new_base == FAIL)
1732 {
1733 first_error (_(reg_expected_msgs[regtype]));
1734 return FAIL;
1735 }
1736
1737 if (new_base >= max_regs)
1738 {
1739 first_error (_("register out of range in list"));
1740 return FAIL;
1741 }
1742
1743 /* Note: a value of 2 * n is returned for the register Q<n>. */
1744 if (regtype == REG_TYPE_NQ)
1745 {
1746 setmask = 3;
1747 addregs = 2;
1748 }
1749
1750 if (new_base < base_reg)
1751 base_reg = new_base;
1752
1753 if (mask & (setmask << new_base))
1754 {
1755 first_error (_("invalid register list"));
1756 return FAIL;
1757 }
1758
1759 if ((mask >> new_base) != 0 && ! warned)
1760 {
1761 as_tsktsk (_("register list not in ascending order"));
1762 warned = 1;
1763 }
1764
1765 mask |= setmask << new_base;
1766 count += addregs;
1767
1768 if (*str == '-') /* We have the start of a range expression */
1769 {
1770 int high_range;
1771
1772 str++;
1773
1774 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1775 == FAIL)
1776 {
1777 inst.error = gettext (reg_expected_msgs[regtype]);
1778 return FAIL;
1779 }
1780
1781 if (high_range >= max_regs)
1782 {
1783 first_error (_("register out of range in list"));
1784 return FAIL;
1785 }
1786
1787 if (regtype == REG_TYPE_NQ)
1788 high_range = high_range + 1;
1789
1790 if (high_range <= new_base)
1791 {
1792 inst.error = _("register range not in ascending order");
1793 return FAIL;
1794 }
1795
1796 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1797 {
1798 if (mask & (setmask << new_base))
1799 {
1800 inst.error = _("invalid register list");
1801 return FAIL;
1802 }
1803
1804 mask |= setmask << new_base;
1805 count += addregs;
1806 }
1807 }
1808 }
1809 while (skip_past_comma (&str) != FAIL);
1810
1811 str++;
1812
1813 /* Sanity check -- should have raised a parse error above. */
1814 if (count == 0 || count > max_regs)
1815 abort ();
1816
1817 *pbase = base_reg;
1818
1819 /* Final test -- the registers must be consecutive. */
1820 mask >>= base_reg;
1821 for (i = 0; i < count; i++)
1822 {
1823 if ((mask & (1u << i)) == 0)
1824 {
1825 inst.error = _("non-contiguous register range");
1826 return FAIL;
1827 }
1828 }
1829
1830 *ccp = str;
1831
1832 return count;
1833 }
1834
1835 /* True if two alias types are the same. */
1836
1837 static bfd_boolean
1838 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1839 {
1840 if (!a && !b)
1841 return TRUE;
1842
1843 if (!a || !b)
1844 return FALSE;
1845
1846 if (a->defined != b->defined)
1847 return FALSE;
1848
1849 if ((a->defined & NTA_HASTYPE) != 0
1850 && (a->eltype.type != b->eltype.type
1851 || a->eltype.size != b->eltype.size))
1852 return FALSE;
1853
1854 if ((a->defined & NTA_HASINDEX) != 0
1855 && (a->index != b->index))
1856 return FALSE;
1857
1858 return TRUE;
1859 }
1860
1861 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1862 The base register is put in *PBASE.
1863 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1864 the return value.
1865 The register stride (minus one) is put in bit 4 of the return value.
1866 Bits [6:5] encode the list length (minus one).
1867 The type of the list elements is put in *ELTYPE, if non-NULL. */
1868
1869 #define NEON_LANE(X) ((X) & 0xf)
1870 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1871 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1872
1873 static int
1874 parse_neon_el_struct_list (char **str, unsigned *pbase,
1875 struct neon_type_el *eltype)
1876 {
1877 char *ptr = *str;
1878 int base_reg = -1;
1879 int reg_incr = -1;
1880 int count = 0;
1881 int lane = -1;
1882 int leading_brace = 0;
1883 enum arm_reg_type rtype = REG_TYPE_NDQ;
1884 int addregs = 1;
1885 const char *const incr_error = _("register stride must be 1 or 2");
1886 const char *const type_error = _("mismatched element/structure types in list");
1887 struct neon_typed_alias firsttype;
1888
1889 if (skip_past_char (&ptr, '{') == SUCCESS)
1890 leading_brace = 1;
1891
1892 do
1893 {
1894 struct neon_typed_alias atype;
1895 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1896
1897 if (getreg == FAIL)
1898 {
1899 first_error (_(reg_expected_msgs[rtype]));
1900 return FAIL;
1901 }
1902
1903 if (base_reg == -1)
1904 {
1905 base_reg = getreg;
1906 if (rtype == REG_TYPE_NQ)
1907 {
1908 reg_incr = 1;
1909 addregs = 2;
1910 }
1911 firsttype = atype;
1912 }
1913 else if (reg_incr == -1)
1914 {
1915 reg_incr = getreg - base_reg;
1916 if (reg_incr < 1 || reg_incr > 2)
1917 {
1918 first_error (_(incr_error));
1919 return FAIL;
1920 }
1921 }
1922 else if (getreg != base_reg + reg_incr * count)
1923 {
1924 first_error (_(incr_error));
1925 return FAIL;
1926 }
1927
1928 if (! neon_alias_types_same (&atype, &firsttype))
1929 {
1930 first_error (_(type_error));
1931 return FAIL;
1932 }
1933
1934 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1935 modes. */
1936 if (ptr[0] == '-')
1937 {
1938 struct neon_typed_alias htype;
1939 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1940 if (lane == -1)
1941 lane = NEON_INTERLEAVE_LANES;
1942 else if (lane != NEON_INTERLEAVE_LANES)
1943 {
1944 first_error (_(type_error));
1945 return FAIL;
1946 }
1947 if (reg_incr == -1)
1948 reg_incr = 1;
1949 else if (reg_incr != 1)
1950 {
1951 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1952 return FAIL;
1953 }
1954 ptr++;
1955 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1956 if (hireg == FAIL)
1957 {
1958 first_error (_(reg_expected_msgs[rtype]));
1959 return FAIL;
1960 }
1961 if (! neon_alias_types_same (&htype, &firsttype))
1962 {
1963 first_error (_(type_error));
1964 return FAIL;
1965 }
1966 count += hireg + dregs - getreg;
1967 continue;
1968 }
1969
1970 /* If we're using Q registers, we can't use [] or [n] syntax. */
1971 if (rtype == REG_TYPE_NQ)
1972 {
1973 count += 2;
1974 continue;
1975 }
1976
1977 if ((atype.defined & NTA_HASINDEX) != 0)
1978 {
1979 if (lane == -1)
1980 lane = atype.index;
1981 else if (lane != atype.index)
1982 {
1983 first_error (_(type_error));
1984 return FAIL;
1985 }
1986 }
1987 else if (lane == -1)
1988 lane = NEON_INTERLEAVE_LANES;
1989 else if (lane != NEON_INTERLEAVE_LANES)
1990 {
1991 first_error (_(type_error));
1992 return FAIL;
1993 }
1994 count++;
1995 }
1996 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1997
1998 /* No lane set by [x]. We must be interleaving structures. */
1999 if (lane == -1)
2000 lane = NEON_INTERLEAVE_LANES;
2001
2002 /* Sanity check. */
2003 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
2004 || (count > 1 && reg_incr == -1))
2005 {
2006 first_error (_("error parsing element/structure list"));
2007 return FAIL;
2008 }
2009
2010 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2011 {
2012 first_error (_("expected }"));
2013 return FAIL;
2014 }
2015
2016 if (reg_incr == -1)
2017 reg_incr = 1;
2018
2019 if (eltype)
2020 *eltype = firsttype.eltype;
2021
2022 *pbase = base_reg;
2023 *str = ptr;
2024
2025 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2026 }
2027
2028 /* Parse an explicit relocation suffix on an expression. This is
2029 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2030 arm_reloc_hsh contains no entries, so this function can only
2031 succeed if there is no () after the word. Returns -1 on error,
2032 BFD_RELOC_UNUSED if there wasn't any suffix. */
2033 static int
2034 parse_reloc (char **str)
2035 {
2036 struct reloc_entry *r;
2037 char *p, *q;
2038
2039 if (**str != '(')
2040 return BFD_RELOC_UNUSED;
2041
2042 p = *str + 1;
2043 q = p;
2044
2045 while (*q && *q != ')' && *q != ',')
2046 q++;
2047 if (*q != ')')
2048 return -1;
2049
2050 if ((r = (struct reloc_entry *)
2051 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2052 return -1;
2053
2054 *str = q + 1;
2055 return r->reloc;
2056 }
2057
2058 /* Directives: register aliases. */
2059
2060 static struct reg_entry *
2061 insert_reg_alias (char *str, int number, int type)
2062 {
2063 struct reg_entry *new_reg;
2064 const char *name;
2065
2066 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
2067 {
2068 if (new_reg->builtin)
2069 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
2070
2071 /* Only warn about a redefinition if it's not defined as the
2072 same register. */
2073 else if (new_reg->number != number || new_reg->type != type)
2074 as_warn (_("ignoring redefinition of register alias '%s'"), str);
2075
2076 return NULL;
2077 }
2078
2079 name = xstrdup (str);
2080 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
2081
2082 new_reg->name = name;
2083 new_reg->number = number;
2084 new_reg->type = type;
2085 new_reg->builtin = FALSE;
2086 new_reg->neon = NULL;
2087
2088 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
2089 abort ();
2090
2091 return new_reg;
2092 }
2093
2094 static void
2095 insert_neon_reg_alias (char *str, int number, int type,
2096 struct neon_typed_alias *atype)
2097 {
2098 struct reg_entry *reg = insert_reg_alias (str, number, type);
2099
2100 if (!reg)
2101 {
2102 first_error (_("attempt to redefine typed alias"));
2103 return;
2104 }
2105
2106 if (atype)
2107 {
2108 reg->neon = (struct neon_typed_alias *)
2109 xmalloc (sizeof (struct neon_typed_alias));
2110 *reg->neon = *atype;
2111 }
2112 }
2113
2114 /* Look for the .req directive. This is of the form:
2115
2116 new_register_name .req existing_register_name
2117
2118 If we find one, or if it looks sufficiently like one that we want to
2119 handle any error here, return TRUE. Otherwise return FALSE. */
2120
2121 static bfd_boolean
2122 create_register_alias (char * newname, char *p)
2123 {
2124 struct reg_entry *old;
2125 char *oldname, *nbuf;
2126 size_t nlen;
2127
2128 /* The input scrubber ensures that whitespace after the mnemonic is
2129 collapsed to single spaces. */
2130 oldname = p;
2131 if (strncmp (oldname, " .req ", 6) != 0)
2132 return FALSE;
2133
2134 oldname += 6;
2135 if (*oldname == '\0')
2136 return FALSE;
2137
2138 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
2139 if (!old)
2140 {
2141 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2142 return TRUE;
2143 }
2144
2145 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2146 the desired alias name, and p points to its end. If not, then
2147 the desired alias name is in the global original_case_string. */
2148 #ifdef TC_CASE_SENSITIVE
2149 nlen = p - newname;
2150 #else
2151 newname = original_case_string;
2152 nlen = strlen (newname);
2153 #endif
2154
2155 nbuf = (char *) alloca (nlen + 1);
2156 memcpy (nbuf, newname, nlen);
2157 nbuf[nlen] = '\0';
2158
2159 /* Create aliases under the new name as stated; an all-lowercase
2160 version of the new name; and an all-uppercase version of the new
2161 name. */
2162 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2163 {
2164 for (p = nbuf; *p; p++)
2165 *p = TOUPPER (*p);
2166
2167 if (strncmp (nbuf, newname, nlen))
2168 {
2169 /* If this attempt to create an additional alias fails, do not bother
2170 trying to create the all-lower case alias. We will fail and issue
2171 a second, duplicate error message. This situation arises when the
2172 programmer does something like:
2173 foo .req r0
2174 Foo .req r1
2175 The second .req creates the "Foo" alias but then fails to create
2176 the artificial FOO alias because it has already been created by the
2177 first .req. */
2178 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2179 return TRUE;
2180 }
2181
2182 for (p = nbuf; *p; p++)
2183 *p = TOLOWER (*p);
2184
2185 if (strncmp (nbuf, newname, nlen))
2186 insert_reg_alias (nbuf, old->number, old->type);
2187 }
2188
2189 return TRUE;
2190 }
2191
2192 /* Create a Neon typed/indexed register alias using directives, e.g.:
2193 X .dn d5.s32[1]
2194 Y .qn 6.s16
2195 Z .dn d7
2196 T .dn Z[0]
2197 These typed registers can be used instead of the types specified after the
2198 Neon mnemonic, so long as all operands given have types. Types can also be
2199 specified directly, e.g.:
2200 vadd d0.s32, d1.s32, d2.s32 */
2201
2202 static bfd_boolean
2203 create_neon_reg_alias (char *newname, char *p)
2204 {
2205 enum arm_reg_type basetype;
2206 struct reg_entry *basereg;
2207 struct reg_entry mybasereg;
2208 struct neon_type ntype;
2209 struct neon_typed_alias typeinfo;
2210 char *namebuf, *nameend;
2211 int namelen;
2212
2213 typeinfo.defined = 0;
2214 typeinfo.eltype.type = NT_invtype;
2215 typeinfo.eltype.size = -1;
2216 typeinfo.index = -1;
2217
2218 nameend = p;
2219
2220 if (strncmp (p, " .dn ", 5) == 0)
2221 basetype = REG_TYPE_VFD;
2222 else if (strncmp (p, " .qn ", 5) == 0)
2223 basetype = REG_TYPE_NQ;
2224 else
2225 return FALSE;
2226
2227 p += 5;
2228
2229 if (*p == '\0')
2230 return FALSE;
2231
2232 basereg = arm_reg_parse_multi (&p);
2233
2234 if (basereg && basereg->type != basetype)
2235 {
2236 as_bad (_("bad type for register"));
2237 return FALSE;
2238 }
2239
2240 if (basereg == NULL)
2241 {
2242 expressionS exp;
2243 /* Try parsing as an integer. */
2244 my_get_expression (&exp, &p, GE_NO_PREFIX);
2245 if (exp.X_op != O_constant)
2246 {
2247 as_bad (_("expression must be constant"));
2248 return FALSE;
2249 }
2250 basereg = &mybasereg;
2251 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2252 : exp.X_add_number;
2253 basereg->neon = 0;
2254 }
2255
2256 if (basereg->neon)
2257 typeinfo = *basereg->neon;
2258
2259 if (parse_neon_type (&ntype, &p) == SUCCESS)
2260 {
2261 /* We got a type. */
2262 if (typeinfo.defined & NTA_HASTYPE)
2263 {
2264 as_bad (_("can't redefine the type of a register alias"));
2265 return FALSE;
2266 }
2267
2268 typeinfo.defined |= NTA_HASTYPE;
2269 if (ntype.elems != 1)
2270 {
2271 as_bad (_("you must specify a single type only"));
2272 return FALSE;
2273 }
2274 typeinfo.eltype = ntype.el[0];
2275 }
2276
2277 if (skip_past_char (&p, '[') == SUCCESS)
2278 {
2279 expressionS exp;
2280 /* We got a scalar index. */
2281
2282 if (typeinfo.defined & NTA_HASINDEX)
2283 {
2284 as_bad (_("can't redefine the index of a scalar alias"));
2285 return FALSE;
2286 }
2287
2288 my_get_expression (&exp, &p, GE_NO_PREFIX);
2289
2290 if (exp.X_op != O_constant)
2291 {
2292 as_bad (_("scalar index must be constant"));
2293 return FALSE;
2294 }
2295
2296 typeinfo.defined |= NTA_HASINDEX;
2297 typeinfo.index = exp.X_add_number;
2298
2299 if (skip_past_char (&p, ']') == FAIL)
2300 {
2301 as_bad (_("expecting ]"));
2302 return FALSE;
2303 }
2304 }
2305
2306 namelen = nameend - newname;
2307 namebuf = (char *) alloca (namelen + 1);
2308 strncpy (namebuf, newname, namelen);
2309 namebuf[namelen] = '\0';
2310
2311 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2312 typeinfo.defined != 0 ? &typeinfo : NULL);
2313
2314 /* Insert name in all uppercase. */
2315 for (p = namebuf; *p; p++)
2316 *p = TOUPPER (*p);
2317
2318 if (strncmp (namebuf, newname, namelen))
2319 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2320 typeinfo.defined != 0 ? &typeinfo : NULL);
2321
2322 /* Insert name in all lowercase. */
2323 for (p = namebuf; *p; p++)
2324 *p = TOLOWER (*p);
2325
2326 if (strncmp (namebuf, newname, namelen))
2327 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2328 typeinfo.defined != 0 ? &typeinfo : NULL);
2329
2330 return TRUE;
2331 }
2332
2333 /* Should never be called, as .req goes between the alias and the
2334 register name, not at the beginning of the line. */
2335
2336 static void
2337 s_req (int a ATTRIBUTE_UNUSED)
2338 {
2339 as_bad (_("invalid syntax for .req directive"));
2340 }
2341
2342 static void
2343 s_dn (int a ATTRIBUTE_UNUSED)
2344 {
2345 as_bad (_("invalid syntax for .dn directive"));
2346 }
2347
2348 static void
2349 s_qn (int a ATTRIBUTE_UNUSED)
2350 {
2351 as_bad (_("invalid syntax for .qn directive"));
2352 }
2353
2354 /* The .unreq directive deletes an alias which was previously defined
2355 by .req. For example:
2356
2357 my_alias .req r11
2358 .unreq my_alias */
2359
2360 static void
2361 s_unreq (int a ATTRIBUTE_UNUSED)
2362 {
2363 char * name;
2364 char saved_char;
2365
2366 name = input_line_pointer;
2367
2368 while (*input_line_pointer != 0
2369 && *input_line_pointer != ' '
2370 && *input_line_pointer != '\n')
2371 ++input_line_pointer;
2372
2373 saved_char = *input_line_pointer;
2374 *input_line_pointer = 0;
2375
2376 if (!*name)
2377 as_bad (_("invalid syntax for .unreq directive"));
2378 else
2379 {
2380 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2381 name);
2382
2383 if (!reg)
2384 as_bad (_("unknown register alias '%s'"), name);
2385 else if (reg->builtin)
2386 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2387 name);
2388 else
2389 {
2390 char * p;
2391 char * nbuf;
2392
2393 hash_delete (arm_reg_hsh, name, FALSE);
2394 free ((char *) reg->name);
2395 if (reg->neon)
2396 free (reg->neon);
2397 free (reg);
2398
2399 /* Also locate the all upper case and all lower case versions.
2400 Do not complain if we cannot find one or the other as it
2401 was probably deleted above. */
2402
2403 nbuf = strdup (name);
2404 for (p = nbuf; *p; p++)
2405 *p = TOUPPER (*p);
2406 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2407 if (reg)
2408 {
2409 hash_delete (arm_reg_hsh, nbuf, FALSE);
2410 free ((char *) reg->name);
2411 if (reg->neon)
2412 free (reg->neon);
2413 free (reg);
2414 }
2415
2416 for (p = nbuf; *p; p++)
2417 *p = TOLOWER (*p);
2418 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
2419 if (reg)
2420 {
2421 hash_delete (arm_reg_hsh, nbuf, FALSE);
2422 free ((char *) reg->name);
2423 if (reg->neon)
2424 free (reg->neon);
2425 free (reg);
2426 }
2427
2428 free (nbuf);
2429 }
2430 }
2431
2432 *input_line_pointer = saved_char;
2433 demand_empty_rest_of_line ();
2434 }
2435
2436 /* Directives: Instruction set selection. */
2437
2438 #ifdef OBJ_ELF
2439 /* This code is to handle mapping symbols as defined in the ARM ELF spec.
2440 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2441 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2442 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2443
2444 /* Create a new mapping symbol for the transition to STATE. */
2445
2446 static void
2447 make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
2448 {
2449 symbolS * symbolP;
2450 const char * symname;
2451 int type;
2452
2453 switch (state)
2454 {
2455 case MAP_DATA:
2456 symname = "$d";
2457 type = BSF_NO_FLAGS;
2458 break;
2459 case MAP_ARM:
2460 symname = "$a";
2461 type = BSF_NO_FLAGS;
2462 break;
2463 case MAP_THUMB:
2464 symname = "$t";
2465 type = BSF_NO_FLAGS;
2466 break;
2467 default:
2468 abort ();
2469 }
2470
2471 symbolP = symbol_new (symname, now_seg, value, frag);
2472 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2473
2474 switch (state)
2475 {
2476 case MAP_ARM:
2477 THUMB_SET_FUNC (symbolP, 0);
2478 ARM_SET_THUMB (symbolP, 0);
2479 ARM_SET_INTERWORK (symbolP, support_interwork);
2480 break;
2481
2482 case MAP_THUMB:
2483 THUMB_SET_FUNC (symbolP, 1);
2484 ARM_SET_THUMB (symbolP, 1);
2485 ARM_SET_INTERWORK (symbolP, support_interwork);
2486 break;
2487
2488 case MAP_DATA:
2489 default:
2490 break;
2491 }
2492
2493 /* Save the mapping symbols for future reference. Also check that
2494 we do not place two mapping symbols at the same offset within a
2495 frag. We'll handle overlap between frags in
2496 check_mapping_symbols.
2497
2498 If .fill or other data filling directive generates zero sized data,
2499 the mapping symbol for the following code will have the same value
2500 as the one generated for the data filling directive. In this case,
2501 we replace the old symbol with the new one at the same address. */
2502 if (value == 0)
2503 {
2504 if (frag->tc_frag_data.first_map != NULL)
2505 {
2506 know (S_GET_VALUE (frag->tc_frag_data.first_map) == 0);
2507 symbol_remove (frag->tc_frag_data.first_map, &symbol_rootP, &symbol_lastP);
2508 }
2509 frag->tc_frag_data.first_map = symbolP;
2510 }
2511 if (frag->tc_frag_data.last_map != NULL)
2512 {
2513 know (S_GET_VALUE (frag->tc_frag_data.last_map) <= S_GET_VALUE (symbolP));
2514 if (S_GET_VALUE (frag->tc_frag_data.last_map) == S_GET_VALUE (symbolP))
2515 symbol_remove (frag->tc_frag_data.last_map, &symbol_rootP, &symbol_lastP);
2516 }
2517 frag->tc_frag_data.last_map = symbolP;
2518 }
2519
2520 /* We must sometimes convert a region marked as code to data during
2521 code alignment, if an odd number of bytes have to be padded. The
2522 code mapping symbol is pushed to an aligned address. */
2523
2524 static void
2525 insert_data_mapping_symbol (enum mstate state,
2526 valueT value, fragS *frag, offsetT bytes)
2527 {
2528 /* If there was already a mapping symbol, remove it. */
2529 if (frag->tc_frag_data.last_map != NULL
2530 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2531 {
2532 symbolS *symp = frag->tc_frag_data.last_map;
2533
2534 if (value == 0)
2535 {
2536 know (frag->tc_frag_data.first_map == symp);
2537 frag->tc_frag_data.first_map = NULL;
2538 }
2539 frag->tc_frag_data.last_map = NULL;
2540 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
2541 }
2542
2543 make_mapping_symbol (MAP_DATA, value, frag);
2544 make_mapping_symbol (state, value + bytes, frag);
2545 }
2546
2547 static void mapping_state_2 (enum mstate state, int max_chars);
2548
2549 /* Set the mapping state to STATE. Only call this when about to
2550 emit some STATE bytes to the file. */
2551
2552 void
2553 mapping_state (enum mstate state)
2554 {
2555 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2556
2557 #define TRANSITION(from, to) (mapstate == (from) && state == (to))
2558
2559 if (mapstate == state)
2560 /* The mapping symbol has already been emitted.
2561 There is nothing else to do. */
2562 return;
2563 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2564 /* This case will be evaluated later in the next else. */
2565 return;
2566 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2567 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2568 {
2569 /* Only add the symbol if the offset is > 0:
2570 if we're at the first frag, check it's size > 0;
2571 if we're not at the first frag, then for sure
2572 the offset is > 0. */
2573 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2574 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2575
2576 if (add_symbol)
2577 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2578 }
2579
2580 mapping_state_2 (state, 0);
2581 #undef TRANSITION
2582 }
2583
2584 /* Same as mapping_state, but MAX_CHARS bytes have already been
2585 allocated. Put the mapping symbol that far back. */
2586
2587 static void
2588 mapping_state_2 (enum mstate state, int max_chars)
2589 {
2590 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2591
2592 if (!SEG_NORMAL (now_seg))
2593 return;
2594
2595 if (mapstate == state)
2596 /* The mapping symbol has already been emitted.
2597 There is nothing else to do. */
2598 return;
2599
2600 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2601 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
2602 }
2603 #else
2604 #define mapping_state(x) ((void)0)
2605 #define mapping_state_2(x, y) ((void)0)
2606 #endif
2607
2608 /* Find the real, Thumb encoded start of a Thumb function. */
2609
2610 #ifdef OBJ_COFF
2611 static symbolS *
2612 find_real_start (symbolS * symbolP)
2613 {
2614 char * real_start;
2615 const char * name = S_GET_NAME (symbolP);
2616 symbolS * new_target;
2617
2618 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2619 #define STUB_NAME ".real_start_of"
2620
2621 if (name == NULL)
2622 abort ();
2623
2624 /* The compiler may generate BL instructions to local labels because
2625 it needs to perform a branch to a far away location. These labels
2626 do not have a corresponding ".real_start_of" label. We check
2627 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2628 the ".real_start_of" convention for nonlocal branches. */
2629 if (S_IS_LOCAL (symbolP) || name[0] == '.')
2630 return symbolP;
2631
2632 real_start = ACONCAT ((STUB_NAME, name, NULL));
2633 new_target = symbol_find (real_start);
2634
2635 if (new_target == NULL)
2636 {
2637 as_warn (_("Failed to find real start of function: %s\n"), name);
2638 new_target = symbolP;
2639 }
2640
2641 return new_target;
2642 }
2643 #endif
2644
2645 static void
2646 opcode_select (int width)
2647 {
2648 switch (width)
2649 {
2650 case 16:
2651 if (! thumb_mode)
2652 {
2653 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2654 as_bad (_("selected processor does not support THUMB opcodes"));
2655
2656 thumb_mode = 1;
2657 /* No need to force the alignment, since we will have been
2658 coming from ARM mode, which is word-aligned. */
2659 record_alignment (now_seg, 1);
2660 }
2661 break;
2662
2663 case 32:
2664 if (thumb_mode)
2665 {
2666 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2667 as_bad (_("selected processor does not support ARM opcodes"));
2668
2669 thumb_mode = 0;
2670
2671 if (!need_pass_2)
2672 frag_align (2, 0, 0);
2673
2674 record_alignment (now_seg, 1);
2675 }
2676 break;
2677
2678 default:
2679 as_bad (_("invalid instruction size selected (%d)"), width);
2680 }
2681 }
2682
2683 static void
2684 s_arm (int ignore ATTRIBUTE_UNUSED)
2685 {
2686 opcode_select (32);
2687 demand_empty_rest_of_line ();
2688 }
2689
2690 static void
2691 s_thumb (int ignore ATTRIBUTE_UNUSED)
2692 {
2693 opcode_select (16);
2694 demand_empty_rest_of_line ();
2695 }
2696
2697 static void
2698 s_code (int unused ATTRIBUTE_UNUSED)
2699 {
2700 int temp;
2701
2702 temp = get_absolute_expression ();
2703 switch (temp)
2704 {
2705 case 16:
2706 case 32:
2707 opcode_select (temp);
2708 break;
2709
2710 default:
2711 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2712 }
2713 }
2714
2715 static void
2716 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2717 {
2718 /* If we are not already in thumb mode go into it, EVEN if
2719 the target processor does not support thumb instructions.
2720 This is used by gcc/config/arm/lib1funcs.asm for example
2721 to compile interworking support functions even if the
2722 target processor should not support interworking. */
2723 if (! thumb_mode)
2724 {
2725 thumb_mode = 2;
2726 record_alignment (now_seg, 1);
2727 }
2728
2729 demand_empty_rest_of_line ();
2730 }
2731
2732 static void
2733 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2734 {
2735 s_thumb (0);
2736
2737 /* The following label is the name/address of the start of a Thumb function.
2738 We need to know this for the interworking support. */
2739 label_is_thumb_function_name = TRUE;
2740 }
2741
2742 /* Perform a .set directive, but also mark the alias as
2743 being a thumb function. */
2744
2745 static void
2746 s_thumb_set (int equiv)
2747 {
2748 /* XXX the following is a duplicate of the code for s_set() in read.c
2749 We cannot just call that code as we need to get at the symbol that
2750 is created. */
2751 char * name;
2752 char delim;
2753 char * end_name;
2754 symbolS * symbolP;
2755
2756 /* Especial apologies for the random logic:
2757 This just grew, and could be parsed much more simply!
2758 Dean - in haste. */
2759 name = input_line_pointer;
2760 delim = get_symbol_end ();
2761 end_name = input_line_pointer;
2762 *end_name = delim;
2763
2764 if (*input_line_pointer != ',')
2765 {
2766 *end_name = 0;
2767 as_bad (_("expected comma after name \"%s\""), name);
2768 *end_name = delim;
2769 ignore_rest_of_line ();
2770 return;
2771 }
2772
2773 input_line_pointer++;
2774 *end_name = 0;
2775
2776 if (name[0] == '.' && name[1] == '\0')
2777 {
2778 /* XXX - this should not happen to .thumb_set. */
2779 abort ();
2780 }
2781
2782 if ((symbolP = symbol_find (name)) == NULL
2783 && (symbolP = md_undefined_symbol (name)) == NULL)
2784 {
2785 #ifndef NO_LISTING
2786 /* When doing symbol listings, play games with dummy fragments living
2787 outside the normal fragment chain to record the file and line info
2788 for this symbol. */
2789 if (listing & LISTING_SYMBOLS)
2790 {
2791 extern struct list_info_struct * listing_tail;
2792 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
2793
2794 memset (dummy_frag, 0, sizeof (fragS));
2795 dummy_frag->fr_type = rs_fill;
2796 dummy_frag->line = listing_tail;
2797 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2798 dummy_frag->fr_symbol = symbolP;
2799 }
2800 else
2801 #endif
2802 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2803
2804 #ifdef OBJ_COFF
2805 /* "set" symbols are local unless otherwise specified. */
2806 SF_SET_LOCAL (symbolP);
2807 #endif /* OBJ_COFF */
2808 } /* Make a new symbol. */
2809
2810 symbol_table_insert (symbolP);
2811
2812 * end_name = delim;
2813
2814 if (equiv
2815 && S_IS_DEFINED (symbolP)
2816 && S_GET_SEGMENT (symbolP) != reg_section)
2817 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2818
2819 pseudo_set (symbolP);
2820
2821 demand_empty_rest_of_line ();
2822
2823 /* XXX Now we come to the Thumb specific bit of code. */
2824
2825 THUMB_SET_FUNC (symbolP, 1);
2826 ARM_SET_THUMB (symbolP, 1);
2827 #if defined OBJ_ELF || defined OBJ_COFF
2828 ARM_SET_INTERWORK (symbolP, support_interwork);
2829 #endif
2830 }
2831
2832 /* Directives: Mode selection. */
2833
2834 /* .syntax [unified|divided] - choose the new unified syntax
2835 (same for Arm and Thumb encoding, modulo slight differences in what
2836 can be represented) or the old divergent syntax for each mode. */
2837 static void
2838 s_syntax (int unused ATTRIBUTE_UNUSED)
2839 {
2840 char *name, delim;
2841
2842 name = input_line_pointer;
2843 delim = get_symbol_end ();
2844
2845 if (!strcasecmp (name, "unified"))
2846 unified_syntax = TRUE;
2847 else if (!strcasecmp (name, "divided"))
2848 unified_syntax = FALSE;
2849 else
2850 {
2851 as_bad (_("unrecognized syntax mode \"%s\""), name);
2852 return;
2853 }
2854 *input_line_pointer = delim;
2855 demand_empty_rest_of_line ();
2856 }
2857
2858 /* Directives: sectioning and alignment. */
2859
2860 /* Same as s_align_ptwo but align 0 => align 2. */
2861
2862 static void
2863 s_align (int unused ATTRIBUTE_UNUSED)
2864 {
2865 int temp;
2866 bfd_boolean fill_p;
2867 long temp_fill;
2868 long max_alignment = 15;
2869
2870 temp = get_absolute_expression ();
2871 if (temp > max_alignment)
2872 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2873 else if (temp < 0)
2874 {
2875 as_bad (_("alignment negative. 0 assumed."));
2876 temp = 0;
2877 }
2878
2879 if (*input_line_pointer == ',')
2880 {
2881 input_line_pointer++;
2882 temp_fill = get_absolute_expression ();
2883 fill_p = TRUE;
2884 }
2885 else
2886 {
2887 fill_p = FALSE;
2888 temp_fill = 0;
2889 }
2890
2891 if (!temp)
2892 temp = 2;
2893
2894 /* Only make a frag if we HAVE to. */
2895 if (temp && !need_pass_2)
2896 {
2897 if (!fill_p && subseg_text_p (now_seg))
2898 frag_align_code (temp, 0);
2899 else
2900 frag_align (temp, (int) temp_fill, 0);
2901 }
2902 demand_empty_rest_of_line ();
2903
2904 record_alignment (now_seg, temp);
2905 }
2906
2907 static void
2908 s_bss (int ignore ATTRIBUTE_UNUSED)
2909 {
2910 /* We don't support putting frags in the BSS segment, we fake it by
2911 marking in_bss, then looking at s_skip for clues. */
2912 subseg_set (bss_section, 0);
2913 demand_empty_rest_of_line ();
2914
2915 #ifdef md_elf_section_change_hook
2916 md_elf_section_change_hook ();
2917 #endif
2918 }
2919
2920 static void
2921 s_even (int ignore ATTRIBUTE_UNUSED)
2922 {
2923 /* Never make frag if expect extra pass. */
2924 if (!need_pass_2)
2925 frag_align (1, 0, 0);
2926
2927 record_alignment (now_seg, 1);
2928
2929 demand_empty_rest_of_line ();
2930 }
2931
2932 /* Directives: Literal pools. */
2933
2934 static literal_pool *
2935 find_literal_pool (void)
2936 {
2937 literal_pool * pool;
2938
2939 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2940 {
2941 if (pool->section == now_seg
2942 && pool->sub_section == now_subseg)
2943 break;
2944 }
2945
2946 return pool;
2947 }
2948
2949 static literal_pool *
2950 find_or_make_literal_pool (void)
2951 {
2952 /* Next literal pool ID number. */
2953 static unsigned int latest_pool_num = 1;
2954 literal_pool * pool;
2955
2956 pool = find_literal_pool ();
2957
2958 if (pool == NULL)
2959 {
2960 /* Create a new pool. */
2961 pool = (literal_pool *) xmalloc (sizeof (* pool));
2962 if (! pool)
2963 return NULL;
2964
2965 pool->next_free_entry = 0;
2966 pool->section = now_seg;
2967 pool->sub_section = now_subseg;
2968 pool->next = list_of_pools;
2969 pool->symbol = NULL;
2970
2971 /* Add it to the list. */
2972 list_of_pools = pool;
2973 }
2974
2975 /* New pools, and emptied pools, will have a NULL symbol. */
2976 if (pool->symbol == NULL)
2977 {
2978 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2979 (valueT) 0, &zero_address_frag);
2980 pool->id = latest_pool_num ++;
2981 }
2982
2983 /* Done. */
2984 return pool;
2985 }
2986
2987 /* Add the literal in the global 'inst'
2988 structure to the relevant literal pool. */
2989
2990 static int
2991 add_to_lit_pool (void)
2992 {
2993 literal_pool * pool;
2994 unsigned int entry;
2995
2996 pool = find_or_make_literal_pool ();
2997
2998 /* Check if this literal value is already in the pool. */
2999 for (entry = 0; entry < pool->next_free_entry; entry ++)
3000 {
3001 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3002 && (inst.reloc.exp.X_op == O_constant)
3003 && (pool->literals[entry].X_add_number
3004 == inst.reloc.exp.X_add_number)
3005 && (pool->literals[entry].X_unsigned
3006 == inst.reloc.exp.X_unsigned))
3007 break;
3008
3009 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
3010 && (inst.reloc.exp.X_op == O_symbol)
3011 && (pool->literals[entry].X_add_number
3012 == inst.reloc.exp.X_add_number)
3013 && (pool->literals[entry].X_add_symbol
3014 == inst.reloc.exp.X_add_symbol)
3015 && (pool->literals[entry].X_op_symbol
3016 == inst.reloc.exp.X_op_symbol))
3017 break;
3018 }
3019
3020 /* Do we need to create a new entry? */
3021 if (entry == pool->next_free_entry)
3022 {
3023 if (entry >= MAX_LITERAL_POOL_SIZE)
3024 {
3025 inst.error = _("literal pool overflow");
3026 return FAIL;
3027 }
3028
3029 pool->literals[entry] = inst.reloc.exp;
3030 pool->next_free_entry += 1;
3031 }
3032
3033 inst.reloc.exp.X_op = O_symbol;
3034 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3035 inst.reloc.exp.X_add_symbol = pool->symbol;
3036
3037 return SUCCESS;
3038 }
3039
3040 /* Can't use symbol_new here, so have to create a symbol and then at
3041 a later date assign it a value. Thats what these functions do. */
3042
3043 static void
3044 symbol_locate (symbolS * symbolP,
3045 const char * name, /* It is copied, the caller can modify. */
3046 segT segment, /* Segment identifier (SEG_<something>). */
3047 valueT valu, /* Symbol value. */
3048 fragS * frag) /* Associated fragment. */
3049 {
3050 unsigned int name_length;
3051 char * preserved_copy_of_name;
3052
3053 name_length = strlen (name) + 1; /* +1 for \0. */
3054 obstack_grow (&notes, name, name_length);
3055 preserved_copy_of_name = (char *) obstack_finish (&notes);
3056
3057 #ifdef tc_canonicalize_symbol_name
3058 preserved_copy_of_name =
3059 tc_canonicalize_symbol_name (preserved_copy_of_name);
3060 #endif
3061
3062 S_SET_NAME (symbolP, preserved_copy_of_name);
3063
3064 S_SET_SEGMENT (symbolP, segment);
3065 S_SET_VALUE (symbolP, valu);
3066 symbol_clear_list_pointers (symbolP);
3067
3068 symbol_set_frag (symbolP, frag);
3069
3070 /* Link to end of symbol chain. */
3071 {
3072 extern int symbol_table_frozen;
3073
3074 if (symbol_table_frozen)
3075 abort ();
3076 }
3077
3078 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
3079
3080 obj_symbol_new_hook (symbolP);
3081
3082 #ifdef tc_symbol_new_hook
3083 tc_symbol_new_hook (symbolP);
3084 #endif
3085
3086 #ifdef DEBUG_SYMS
3087 verify_symbol_chain (symbol_rootP, symbol_lastP);
3088 #endif /* DEBUG_SYMS */
3089 }
3090
3091
3092 static void
3093 s_ltorg (int ignored ATTRIBUTE_UNUSED)
3094 {
3095 unsigned int entry;
3096 literal_pool * pool;
3097 char sym_name[20];
3098
3099 pool = find_literal_pool ();
3100 if (pool == NULL
3101 || pool->symbol == NULL
3102 || pool->next_free_entry == 0)
3103 return;
3104
3105 mapping_state (MAP_DATA);
3106
3107 /* Align pool as you have word accesses.
3108 Only make a frag if we have to. */
3109 if (!need_pass_2)
3110 frag_align (2, 0, 0);
3111
3112 record_alignment (now_seg, 2);
3113
3114 sprintf (sym_name, "$$lit_\002%x", pool->id);
3115
3116 symbol_locate (pool->symbol, sym_name, now_seg,
3117 (valueT) frag_now_fix (), frag_now);
3118 symbol_table_insert (pool->symbol);
3119
3120 ARM_SET_THUMB (pool->symbol, thumb_mode);
3121
3122 #if defined OBJ_COFF || defined OBJ_ELF
3123 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3124 #endif
3125
3126 for (entry = 0; entry < pool->next_free_entry; entry ++)
3127 /* First output the expression in the instruction to the pool. */
3128 emit_expr (&(pool->literals[entry]), 4); /* .word */
3129
3130 /* Mark the pool as empty. */
3131 pool->next_free_entry = 0;
3132 pool->symbol = NULL;
3133 }
3134
3135 #ifdef OBJ_ELF
3136 /* Forward declarations for functions below, in the MD interface
3137 section. */
3138 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3139 static valueT create_unwind_entry (int);
3140 static void start_unwind_section (const segT, int);
3141 static void add_unwind_opcode (valueT, int);
3142 static void flush_pending_unwind (void);
3143
3144 /* Directives: Data. */
3145
3146 static void
3147 s_arm_elf_cons (int nbytes)
3148 {
3149 expressionS exp;
3150
3151 #ifdef md_flush_pending_output
3152 md_flush_pending_output ();
3153 #endif
3154
3155 if (is_it_end_of_statement ())
3156 {
3157 demand_empty_rest_of_line ();
3158 return;
3159 }
3160
3161 #ifdef md_cons_align
3162 md_cons_align (nbytes);
3163 #endif
3164
3165 mapping_state (MAP_DATA);
3166 do
3167 {
3168 int reloc;
3169 char *base = input_line_pointer;
3170
3171 expression (& exp);
3172
3173 if (exp.X_op != O_symbol)
3174 emit_expr (&exp, (unsigned int) nbytes);
3175 else
3176 {
3177 char *before_reloc = input_line_pointer;
3178 reloc = parse_reloc (&input_line_pointer);
3179 if (reloc == -1)
3180 {
3181 as_bad (_("unrecognized relocation suffix"));
3182 ignore_rest_of_line ();
3183 return;
3184 }
3185 else if (reloc == BFD_RELOC_UNUSED)
3186 emit_expr (&exp, (unsigned int) nbytes);
3187 else
3188 {
3189 reloc_howto_type *howto = (reloc_howto_type *)
3190 bfd_reloc_type_lookup (stdoutput,
3191 (bfd_reloc_code_real_type) reloc);
3192 int size = bfd_get_reloc_size (howto);
3193
3194 if (reloc == BFD_RELOC_ARM_PLT32)
3195 {
3196 as_bad (_("(plt) is only valid on branch targets"));
3197 reloc = BFD_RELOC_UNUSED;
3198 size = 0;
3199 }
3200
3201 if (size > nbytes)
3202 as_bad (_("%s relocations do not fit in %d bytes"),
3203 howto->name, nbytes);
3204 else
3205 {
3206 /* We've parsed an expression stopping at O_symbol.
3207 But there may be more expression left now that we
3208 have parsed the relocation marker. Parse it again.
3209 XXX Surely there is a cleaner way to do this. */
3210 char *p = input_line_pointer;
3211 int offset;
3212 char *save_buf = (char *) alloca (input_line_pointer - base);
3213 memcpy (save_buf, base, input_line_pointer - base);
3214 memmove (base + (input_line_pointer - before_reloc),
3215 base, before_reloc - base);
3216
3217 input_line_pointer = base + (input_line_pointer-before_reloc);
3218 expression (&exp);
3219 memcpy (base, save_buf, p - base);
3220
3221 offset = nbytes - size;
3222 p = frag_more ((int) nbytes);
3223 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3224 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
3225 }
3226 }
3227 }
3228 }
3229 while (*input_line_pointer++ == ',');
3230
3231 /* Put terminator back into stream. */
3232 input_line_pointer --;
3233 demand_empty_rest_of_line ();
3234 }
3235
3236 /* Emit an expression containing a 32-bit thumb instruction.
3237 Implementation based on put_thumb32_insn. */
3238
3239 static void
3240 emit_thumb32_expr (expressionS * exp)
3241 {
3242 expressionS exp_high = *exp;
3243
3244 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3245 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3246 exp->X_add_number &= 0xffff;
3247 emit_expr (exp, (unsigned int) THUMB_SIZE);
3248 }
3249
3250 /* Guess the instruction size based on the opcode. */
3251
3252 static int
3253 thumb_insn_size (int opcode)
3254 {
3255 if ((unsigned int) opcode < 0xe800u)
3256 return 2;
3257 else if ((unsigned int) opcode >= 0xe8000000u)
3258 return 4;
3259 else
3260 return 0;
3261 }
3262
3263 static bfd_boolean
3264 emit_insn (expressionS *exp, int nbytes)
3265 {
3266 int size = 0;
3267
3268 if (exp->X_op == O_constant)
3269 {
3270 size = nbytes;
3271
3272 if (size == 0)
3273 size = thumb_insn_size (exp->X_add_number);
3274
3275 if (size != 0)
3276 {
3277 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3278 {
3279 as_bad (_(".inst.n operand too big. "\
3280 "Use .inst.w instead"));
3281 size = 0;
3282 }
3283 else
3284 {
3285 if (now_it.state == AUTOMATIC_IT_BLOCK)
3286 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3287 else
3288 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3289
3290 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3291 emit_thumb32_expr (exp);
3292 else
3293 emit_expr (exp, (unsigned int) size);
3294
3295 it_fsm_post_encode ();
3296 }
3297 }
3298 else
3299 as_bad (_("cannot determine Thumb instruction size. " \
3300 "Use .inst.n/.inst.w instead"));
3301 }
3302 else
3303 as_bad (_("constant expression required"));
3304
3305 return (size != 0);
3306 }
3307
3308 /* Like s_arm_elf_cons but do not use md_cons_align and
3309 set the mapping state to MAP_ARM/MAP_THUMB. */
3310
3311 static void
3312 s_arm_elf_inst (int nbytes)
3313 {
3314 if (is_it_end_of_statement ())
3315 {
3316 demand_empty_rest_of_line ();
3317 return;
3318 }
3319
3320 /* Calling mapping_state () here will not change ARM/THUMB,
3321 but will ensure not to be in DATA state. */
3322
3323 if (thumb_mode)
3324 mapping_state (MAP_THUMB);
3325 else
3326 {
3327 if (nbytes != 0)
3328 {
3329 as_bad (_("width suffixes are invalid in ARM mode"));
3330 ignore_rest_of_line ();
3331 return;
3332 }
3333
3334 nbytes = 4;
3335
3336 mapping_state (MAP_ARM);
3337 }
3338
3339 do
3340 {
3341 expressionS exp;
3342
3343 expression (& exp);
3344
3345 if (! emit_insn (& exp, nbytes))
3346 {
3347 ignore_rest_of_line ();
3348 return;
3349 }
3350 }
3351 while (*input_line_pointer++ == ',');
3352
3353 /* Put terminator back into stream. */
3354 input_line_pointer --;
3355 demand_empty_rest_of_line ();
3356 }
3357
3358 /* Parse a .rel31 directive. */
3359
3360 static void
3361 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3362 {
3363 expressionS exp;
3364 char *p;
3365 valueT highbit;
3366
3367 highbit = 0;
3368 if (*input_line_pointer == '1')
3369 highbit = 0x80000000;
3370 else if (*input_line_pointer != '0')
3371 as_bad (_("expected 0 or 1"));
3372
3373 input_line_pointer++;
3374 if (*input_line_pointer != ',')
3375 as_bad (_("missing comma"));
3376 input_line_pointer++;
3377
3378 #ifdef md_flush_pending_output
3379 md_flush_pending_output ();
3380 #endif
3381
3382 #ifdef md_cons_align
3383 md_cons_align (4);
3384 #endif
3385
3386 mapping_state (MAP_DATA);
3387
3388 expression (&exp);
3389
3390 p = frag_more (4);
3391 md_number_to_chars (p, highbit, 4);
3392 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3393 BFD_RELOC_ARM_PREL31);
3394
3395 demand_empty_rest_of_line ();
3396 }
3397
3398 /* Directives: AEABI stack-unwind tables. */
3399
3400 /* Parse an unwind_fnstart directive. Simply records the current location. */
3401
3402 static void
3403 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3404 {
3405 demand_empty_rest_of_line ();
3406 if (unwind.proc_start)
3407 {
3408 as_bad (_("duplicate .fnstart directive"));
3409 return;
3410 }
3411
3412 /* Mark the start of the function. */
3413 unwind.proc_start = expr_build_dot ();
3414
3415 /* Reset the rest of the unwind info. */
3416 unwind.opcode_count = 0;
3417 unwind.table_entry = NULL;
3418 unwind.personality_routine = NULL;
3419 unwind.personality_index = -1;
3420 unwind.frame_size = 0;
3421 unwind.fp_offset = 0;
3422 unwind.fp_reg = REG_SP;
3423 unwind.fp_used = 0;
3424 unwind.sp_restored = 0;
3425 }
3426
3427
3428 /* Parse a handlerdata directive. Creates the exception handling table entry
3429 for the function. */
3430
3431 static void
3432 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3433 {
3434 demand_empty_rest_of_line ();
3435 if (!unwind.proc_start)
3436 as_bad (MISSING_FNSTART);
3437
3438 if (unwind.table_entry)
3439 as_bad (_("duplicate .handlerdata directive"));
3440
3441 create_unwind_entry (1);
3442 }
3443
3444 /* Parse an unwind_fnend directive. Generates the index table entry. */
3445
3446 static void
3447 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3448 {
3449 long where;
3450 char *ptr;
3451 valueT val;
3452 unsigned int marked_pr_dependency;
3453
3454 demand_empty_rest_of_line ();
3455
3456 if (!unwind.proc_start)
3457 {
3458 as_bad (_(".fnend directive without .fnstart"));
3459 return;
3460 }
3461
3462 /* Add eh table entry. */
3463 if (unwind.table_entry == NULL)
3464 val = create_unwind_entry (0);
3465 else
3466 val = 0;
3467
3468 /* Add index table entry. This is two words. */
3469 start_unwind_section (unwind.saved_seg, 1);
3470 frag_align (2, 0, 0);
3471 record_alignment (now_seg, 2);
3472
3473 ptr = frag_more (8);
3474 where = frag_now_fix () - 8;
3475
3476 /* Self relative offset of the function start. */
3477 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3478 BFD_RELOC_ARM_PREL31);
3479
3480 /* Indicate dependency on EHABI-defined personality routines to the
3481 linker, if it hasn't been done already. */
3482 marked_pr_dependency
3483 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
3484 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3485 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3486 {
3487 static const char *const name[] =
3488 {
3489 "__aeabi_unwind_cpp_pr0",
3490 "__aeabi_unwind_cpp_pr1",
3491 "__aeabi_unwind_cpp_pr2"
3492 };
3493 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3494 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3495 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3496 |= 1 << unwind.personality_index;
3497 }
3498
3499 if (val)
3500 /* Inline exception table entry. */
3501 md_number_to_chars (ptr + 4, val, 4);
3502 else
3503 /* Self relative offset of the table entry. */
3504 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3505 BFD_RELOC_ARM_PREL31);
3506
3507 /* Restore the original section. */
3508 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3509
3510 unwind.proc_start = NULL;
3511 }
3512
3513
3514 /* Parse an unwind_cantunwind directive. */
3515
3516 static void
3517 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3518 {
3519 demand_empty_rest_of_line ();
3520 if (!unwind.proc_start)
3521 as_bad (MISSING_FNSTART);
3522
3523 if (unwind.personality_routine || unwind.personality_index != -1)
3524 as_bad (_("personality routine specified for cantunwind frame"));
3525
3526 unwind.personality_index = -2;
3527 }
3528
3529
3530 /* Parse a personalityindex directive. */
3531
3532 static void
3533 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3534 {
3535 expressionS exp;
3536
3537 if (!unwind.proc_start)
3538 as_bad (MISSING_FNSTART);
3539
3540 if (unwind.personality_routine || unwind.personality_index != -1)
3541 as_bad (_("duplicate .personalityindex directive"));
3542
3543 expression (&exp);
3544
3545 if (exp.X_op != O_constant
3546 || exp.X_add_number < 0 || exp.X_add_number > 15)
3547 {
3548 as_bad (_("bad personality routine number"));
3549 ignore_rest_of_line ();
3550 return;
3551 }
3552
3553 unwind.personality_index = exp.X_add_number;
3554
3555 demand_empty_rest_of_line ();
3556 }
3557
3558
3559 /* Parse a personality directive. */
3560
3561 static void
3562 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3563 {
3564 char *name, *p, c;
3565
3566 if (!unwind.proc_start)
3567 as_bad (MISSING_FNSTART);
3568
3569 if (unwind.personality_routine || unwind.personality_index != -1)
3570 as_bad (_("duplicate .personality directive"));
3571
3572 name = input_line_pointer;
3573 c = get_symbol_end ();
3574 p = input_line_pointer;
3575 unwind.personality_routine = symbol_find_or_make (name);
3576 *p = c;
3577 demand_empty_rest_of_line ();
3578 }
3579
3580
3581 /* Parse a directive saving core registers. */
3582
3583 static void
3584 s_arm_unwind_save_core (void)
3585 {
3586 valueT op;
3587 long range;
3588 int n;
3589
3590 range = parse_reg_list (&input_line_pointer);
3591 if (range == FAIL)
3592 {
3593 as_bad (_("expected register list"));
3594 ignore_rest_of_line ();
3595 return;
3596 }
3597
3598 demand_empty_rest_of_line ();
3599
3600 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3601 into .unwind_save {..., sp...}. We aren't bothered about the value of
3602 ip because it is clobbered by calls. */
3603 if (unwind.sp_restored && unwind.fp_reg == 12
3604 && (range & 0x3000) == 0x1000)
3605 {
3606 unwind.opcode_count--;
3607 unwind.sp_restored = 0;
3608 range = (range | 0x2000) & ~0x1000;
3609 unwind.pending_offset = 0;
3610 }
3611
3612 /* Pop r4-r15. */
3613 if (range & 0xfff0)
3614 {
3615 /* See if we can use the short opcodes. These pop a block of up to 8
3616 registers starting with r4, plus maybe r14. */
3617 for (n = 0; n < 8; n++)
3618 {
3619 /* Break at the first non-saved register. */
3620 if ((range & (1 << (n + 4))) == 0)
3621 break;
3622 }
3623 /* See if there are any other bits set. */
3624 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3625 {
3626 /* Use the long form. */
3627 op = 0x8000 | ((range >> 4) & 0xfff);
3628 add_unwind_opcode (op, 2);
3629 }
3630 else
3631 {
3632 /* Use the short form. */
3633 if (range & 0x4000)
3634 op = 0xa8; /* Pop r14. */
3635 else
3636 op = 0xa0; /* Do not pop r14. */
3637 op |= (n - 1);
3638 add_unwind_opcode (op, 1);
3639 }
3640 }
3641
3642 /* Pop r0-r3. */
3643 if (range & 0xf)
3644 {
3645 op = 0xb100 | (range & 0xf);
3646 add_unwind_opcode (op, 2);
3647 }
3648
3649 /* Record the number of bytes pushed. */
3650 for (n = 0; n < 16; n++)
3651 {
3652 if (range & (1 << n))
3653 unwind.frame_size += 4;
3654 }
3655 }
3656
3657
3658 /* Parse a directive saving FPA registers. */
3659
3660 static void
3661 s_arm_unwind_save_fpa (int reg)
3662 {
3663 expressionS exp;
3664 int num_regs;
3665 valueT op;
3666
3667 /* Get Number of registers to transfer. */
3668 if (skip_past_comma (&input_line_pointer) != FAIL)
3669 expression (&exp);
3670 else
3671 exp.X_op = O_illegal;
3672
3673 if (exp.X_op != O_constant)
3674 {
3675 as_bad (_("expected , <constant>"));
3676 ignore_rest_of_line ();
3677 return;
3678 }
3679
3680 num_regs = exp.X_add_number;
3681
3682 if (num_regs < 1 || num_regs > 4)
3683 {
3684 as_bad (_("number of registers must be in the range [1:4]"));
3685 ignore_rest_of_line ();
3686 return;
3687 }
3688
3689 demand_empty_rest_of_line ();
3690
3691 if (reg == 4)
3692 {
3693 /* Short form. */
3694 op = 0xb4 | (num_regs - 1);
3695 add_unwind_opcode (op, 1);
3696 }
3697 else
3698 {
3699 /* Long form. */
3700 op = 0xc800 | (reg << 4) | (num_regs - 1);
3701 add_unwind_opcode (op, 2);
3702 }
3703 unwind.frame_size += num_regs * 12;
3704 }
3705
3706
3707 /* Parse a directive saving VFP registers for ARMv6 and above. */
3708
3709 static void
3710 s_arm_unwind_save_vfp_armv6 (void)
3711 {
3712 int count;
3713 unsigned int start;
3714 valueT op;
3715 int num_vfpv3_regs = 0;
3716 int num_regs_below_16;
3717
3718 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3719 if (count == FAIL)
3720 {
3721 as_bad (_("expected register list"));
3722 ignore_rest_of_line ();
3723 return;
3724 }
3725
3726 demand_empty_rest_of_line ();
3727
3728 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3729 than FSTMX/FLDMX-style ones). */
3730
3731 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3732 if (start >= 16)
3733 num_vfpv3_regs = count;
3734 else if (start + count > 16)
3735 num_vfpv3_regs = start + count - 16;
3736
3737 if (num_vfpv3_regs > 0)
3738 {
3739 int start_offset = start > 16 ? start - 16 : 0;
3740 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3741 add_unwind_opcode (op, 2);
3742 }
3743
3744 /* Generate opcode for registers numbered in the range 0 .. 15. */
3745 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3746 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3747 if (num_regs_below_16 > 0)
3748 {
3749 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3750 add_unwind_opcode (op, 2);
3751 }
3752
3753 unwind.frame_size += count * 8;
3754 }
3755
3756
3757 /* Parse a directive saving VFP registers for pre-ARMv6. */
3758
3759 static void
3760 s_arm_unwind_save_vfp (void)
3761 {
3762 int count;
3763 unsigned int reg;
3764 valueT op;
3765
3766 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3767 if (count == FAIL)
3768 {
3769 as_bad (_("expected register list"));
3770 ignore_rest_of_line ();
3771 return;
3772 }
3773
3774 demand_empty_rest_of_line ();
3775
3776 if (reg == 8)
3777 {
3778 /* Short form. */
3779 op = 0xb8 | (count - 1);
3780 add_unwind_opcode (op, 1);
3781 }
3782 else
3783 {
3784 /* Long form. */
3785 op = 0xb300 | (reg << 4) | (count - 1);
3786 add_unwind_opcode (op, 2);
3787 }
3788 unwind.frame_size += count * 8 + 4;
3789 }
3790
3791
3792 /* Parse a directive saving iWMMXt data registers. */
3793
3794 static void
3795 s_arm_unwind_save_mmxwr (void)
3796 {
3797 int reg;
3798 int hi_reg;
3799 int i;
3800 unsigned mask = 0;
3801 valueT op;
3802
3803 if (*input_line_pointer == '{')
3804 input_line_pointer++;
3805
3806 do
3807 {
3808 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3809
3810 if (reg == FAIL)
3811 {
3812 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3813 goto error;
3814 }
3815
3816 if (mask >> reg)
3817 as_tsktsk (_("register list not in ascending order"));
3818 mask |= 1 << reg;
3819
3820 if (*input_line_pointer == '-')
3821 {
3822 input_line_pointer++;
3823 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3824 if (hi_reg == FAIL)
3825 {
3826 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3827 goto error;
3828 }
3829 else if (reg >= hi_reg)
3830 {
3831 as_bad (_("bad register range"));
3832 goto error;
3833 }
3834 for (; reg < hi_reg; reg++)
3835 mask |= 1 << reg;
3836 }
3837 }
3838 while (skip_past_comma (&input_line_pointer) != FAIL);
3839
3840 if (*input_line_pointer == '}')
3841 input_line_pointer++;
3842
3843 demand_empty_rest_of_line ();
3844
3845 /* Generate any deferred opcodes because we're going to be looking at
3846 the list. */
3847 flush_pending_unwind ();
3848
3849 for (i = 0; i < 16; i++)
3850 {
3851 if (mask & (1 << i))
3852 unwind.frame_size += 8;
3853 }
3854
3855 /* Attempt to combine with a previous opcode. We do this because gcc
3856 likes to output separate unwind directives for a single block of
3857 registers. */
3858 if (unwind.opcode_count > 0)
3859 {
3860 i = unwind.opcodes[unwind.opcode_count - 1];
3861 if ((i & 0xf8) == 0xc0)
3862 {
3863 i &= 7;
3864 /* Only merge if the blocks are contiguous. */
3865 if (i < 6)
3866 {
3867 if ((mask & 0xfe00) == (1 << 9))
3868 {
3869 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3870 unwind.opcode_count--;
3871 }
3872 }
3873 else if (i == 6 && unwind.opcode_count >= 2)
3874 {
3875 i = unwind.opcodes[unwind.opcode_count - 2];
3876 reg = i >> 4;
3877 i &= 0xf;
3878
3879 op = 0xffff << (reg - 1);
3880 if (reg > 0
3881 && ((mask & op) == (1u << (reg - 1))))
3882 {
3883 op = (1 << (reg + i + 1)) - 1;
3884 op &= ~((1 << reg) - 1);
3885 mask |= op;
3886 unwind.opcode_count -= 2;
3887 }
3888 }
3889 }
3890 }
3891
3892 hi_reg = 15;
3893 /* We want to generate opcodes in the order the registers have been
3894 saved, ie. descending order. */
3895 for (reg = 15; reg >= -1; reg--)
3896 {
3897 /* Save registers in blocks. */
3898 if (reg < 0
3899 || !(mask & (1 << reg)))
3900 {
3901 /* We found an unsaved reg. Generate opcodes to save the
3902 preceding block. */
3903 if (reg != hi_reg)
3904 {
3905 if (reg == 9)
3906 {
3907 /* Short form. */
3908 op = 0xc0 | (hi_reg - 10);
3909 add_unwind_opcode (op, 1);
3910 }
3911 else
3912 {
3913 /* Long form. */
3914 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3915 add_unwind_opcode (op, 2);
3916 }
3917 }
3918 hi_reg = reg - 1;
3919 }
3920 }
3921
3922 return;
3923 error:
3924 ignore_rest_of_line ();
3925 }
3926
3927 static void
3928 s_arm_unwind_save_mmxwcg (void)
3929 {
3930 int reg;
3931 int hi_reg;
3932 unsigned mask = 0;
3933 valueT op;
3934
3935 if (*input_line_pointer == '{')
3936 input_line_pointer++;
3937
3938 do
3939 {
3940 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3941
3942 if (reg == FAIL)
3943 {
3944 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3945 goto error;
3946 }
3947
3948 reg -= 8;
3949 if (mask >> reg)
3950 as_tsktsk (_("register list not in ascending order"));
3951 mask |= 1 << reg;
3952
3953 if (*input_line_pointer == '-')
3954 {
3955 input_line_pointer++;
3956 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3957 if (hi_reg == FAIL)
3958 {
3959 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3960 goto error;
3961 }
3962 else if (reg >= hi_reg)
3963 {
3964 as_bad (_("bad register range"));
3965 goto error;
3966 }
3967 for (; reg < hi_reg; reg++)
3968 mask |= 1 << reg;
3969 }
3970 }
3971 while (skip_past_comma (&input_line_pointer) != FAIL);
3972
3973 if (*input_line_pointer == '}')
3974 input_line_pointer++;
3975
3976 demand_empty_rest_of_line ();
3977
3978 /* Generate any deferred opcodes because we're going to be looking at
3979 the list. */
3980 flush_pending_unwind ();
3981
3982 for (reg = 0; reg < 16; reg++)
3983 {
3984 if (mask & (1 << reg))
3985 unwind.frame_size += 4;
3986 }
3987 op = 0xc700 | mask;
3988 add_unwind_opcode (op, 2);
3989 return;
3990 error:
3991 ignore_rest_of_line ();
3992 }
3993
3994
3995 /* Parse an unwind_save directive.
3996 If the argument is non-zero, this is a .vsave directive. */
3997
3998 static void
3999 s_arm_unwind_save (int arch_v6)
4000 {
4001 char *peek;
4002 struct reg_entry *reg;
4003 bfd_boolean had_brace = FALSE;
4004
4005 if (!unwind.proc_start)
4006 as_bad (MISSING_FNSTART);
4007
4008 /* Figure out what sort of save we have. */
4009 peek = input_line_pointer;
4010
4011 if (*peek == '{')
4012 {
4013 had_brace = TRUE;
4014 peek++;
4015 }
4016
4017 reg = arm_reg_parse_multi (&peek);
4018
4019 if (!reg)
4020 {
4021 as_bad (_("register expected"));
4022 ignore_rest_of_line ();
4023 return;
4024 }
4025
4026 switch (reg->type)
4027 {
4028 case REG_TYPE_FN:
4029 if (had_brace)
4030 {
4031 as_bad (_("FPA .unwind_save does not take a register list"));
4032 ignore_rest_of_line ();
4033 return;
4034 }
4035 input_line_pointer = peek;
4036 s_arm_unwind_save_fpa (reg->number);
4037 return;
4038
4039 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
4040 case REG_TYPE_VFD:
4041 if (arch_v6)
4042 s_arm_unwind_save_vfp_armv6 ();
4043 else
4044 s_arm_unwind_save_vfp ();
4045 return;
4046 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4047 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4048
4049 default:
4050 as_bad (_(".unwind_save does not support this kind of register"));
4051 ignore_rest_of_line ();
4052 }
4053 }
4054
4055
4056 /* Parse an unwind_movsp directive. */
4057
4058 static void
4059 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4060 {
4061 int reg;
4062 valueT op;
4063 int offset;
4064
4065 if (!unwind.proc_start)
4066 as_bad (MISSING_FNSTART);
4067
4068 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4069 if (reg == FAIL)
4070 {
4071 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
4072 ignore_rest_of_line ();
4073 return;
4074 }
4075
4076 /* Optional constant. */
4077 if (skip_past_comma (&input_line_pointer) != FAIL)
4078 {
4079 if (immediate_for_directive (&offset) == FAIL)
4080 return;
4081 }
4082 else
4083 offset = 0;
4084
4085 demand_empty_rest_of_line ();
4086
4087 if (reg == REG_SP || reg == REG_PC)
4088 {
4089 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
4090 return;
4091 }
4092
4093 if (unwind.fp_reg != REG_SP)
4094 as_bad (_("unexpected .unwind_movsp directive"));
4095
4096 /* Generate opcode to restore the value. */
4097 op = 0x90 | reg;
4098 add_unwind_opcode (op, 1);
4099
4100 /* Record the information for later. */
4101 unwind.fp_reg = reg;
4102 unwind.fp_offset = unwind.frame_size - offset;
4103 unwind.sp_restored = 1;
4104 }
4105
4106 /* Parse an unwind_pad directive. */
4107
4108 static void
4109 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
4110 {
4111 int offset;
4112
4113 if (!unwind.proc_start)
4114 as_bad (MISSING_FNSTART);
4115
4116 if (immediate_for_directive (&offset) == FAIL)
4117 return;
4118
4119 if (offset & 3)
4120 {
4121 as_bad (_("stack increment must be multiple of 4"));
4122 ignore_rest_of_line ();
4123 return;
4124 }
4125
4126 /* Don't generate any opcodes, just record the details for later. */
4127 unwind.frame_size += offset;
4128 unwind.pending_offset += offset;
4129
4130 demand_empty_rest_of_line ();
4131 }
4132
4133 /* Parse an unwind_setfp directive. */
4134
4135 static void
4136 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
4137 {
4138 int sp_reg;
4139 int fp_reg;
4140 int offset;
4141
4142 if (!unwind.proc_start)
4143 as_bad (MISSING_FNSTART);
4144
4145 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4146 if (skip_past_comma (&input_line_pointer) == FAIL)
4147 sp_reg = FAIL;
4148 else
4149 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
4150
4151 if (fp_reg == FAIL || sp_reg == FAIL)
4152 {
4153 as_bad (_("expected <reg>, <reg>"));
4154 ignore_rest_of_line ();
4155 return;
4156 }
4157
4158 /* Optional constant. */
4159 if (skip_past_comma (&input_line_pointer) != FAIL)
4160 {
4161 if (immediate_for_directive (&offset) == FAIL)
4162 return;
4163 }
4164 else
4165 offset = 0;
4166
4167 demand_empty_rest_of_line ();
4168
4169 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
4170 {
4171 as_bad (_("register must be either sp or set by a previous"
4172 "unwind_movsp directive"));
4173 return;
4174 }
4175
4176 /* Don't generate any opcodes, just record the information for later. */
4177 unwind.fp_reg = fp_reg;
4178 unwind.fp_used = 1;
4179 if (sp_reg == REG_SP)
4180 unwind.fp_offset = unwind.frame_size - offset;
4181 else
4182 unwind.fp_offset -= offset;
4183 }
4184
4185 /* Parse an unwind_raw directive. */
4186
4187 static void
4188 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
4189 {
4190 expressionS exp;
4191 /* This is an arbitrary limit. */
4192 unsigned char op[16];
4193 int count;
4194
4195 if (!unwind.proc_start)
4196 as_bad (MISSING_FNSTART);
4197
4198 expression (&exp);
4199 if (exp.X_op == O_constant
4200 && skip_past_comma (&input_line_pointer) != FAIL)
4201 {
4202 unwind.frame_size += exp.X_add_number;
4203 expression (&exp);
4204 }
4205 else
4206 exp.X_op = O_illegal;
4207
4208 if (exp.X_op != O_constant)
4209 {
4210 as_bad (_("expected <offset>, <opcode>"));
4211 ignore_rest_of_line ();
4212 return;
4213 }
4214
4215 count = 0;
4216
4217 /* Parse the opcode. */
4218 for (;;)
4219 {
4220 if (count >= 16)
4221 {
4222 as_bad (_("unwind opcode too long"));
4223 ignore_rest_of_line ();
4224 }
4225 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
4226 {
4227 as_bad (_("invalid unwind opcode"));
4228 ignore_rest_of_line ();
4229 return;
4230 }
4231 op[count++] = exp.X_add_number;
4232
4233 /* Parse the next byte. */
4234 if (skip_past_comma (&input_line_pointer) == FAIL)
4235 break;
4236
4237 expression (&exp);
4238 }
4239
4240 /* Add the opcode bytes in reverse order. */
4241 while (count--)
4242 add_unwind_opcode (op[count], 1);
4243
4244 demand_empty_rest_of_line ();
4245 }
4246
4247
4248 /* Parse a .eabi_attribute directive. */
4249
4250 static void
4251 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4252 {
4253 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4254
4255 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4256 attributes_set_explicitly[tag] = 1;
4257 }
4258 #endif /* OBJ_ELF */
4259
4260 static void s_arm_arch (int);
4261 static void s_arm_object_arch (int);
4262 static void s_arm_cpu (int);
4263 static void s_arm_fpu (int);
4264
4265 #ifdef TE_PE
4266
4267 static void
4268 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4269 {
4270 expressionS exp;
4271
4272 do
4273 {
4274 expression (&exp);
4275 if (exp.X_op == O_symbol)
4276 exp.X_op = O_secrel;
4277
4278 emit_expr (&exp, 4);
4279 }
4280 while (*input_line_pointer++ == ',');
4281
4282 input_line_pointer--;
4283 demand_empty_rest_of_line ();
4284 }
4285 #endif /* TE_PE */
4286
4287 /* This table describes all the machine specific pseudo-ops the assembler
4288 has to support. The fields are:
4289 pseudo-op name without dot
4290 function to call to execute this pseudo-op
4291 Integer arg to pass to the function. */
4292
4293 const pseudo_typeS md_pseudo_table[] =
4294 {
4295 /* Never called because '.req' does not start a line. */
4296 { "req", s_req, 0 },
4297 /* Following two are likewise never called. */
4298 { "dn", s_dn, 0 },
4299 { "qn", s_qn, 0 },
4300 { "unreq", s_unreq, 0 },
4301 { "bss", s_bss, 0 },
4302 { "align", s_align, 0 },
4303 { "arm", s_arm, 0 },
4304 { "thumb", s_thumb, 0 },
4305 { "code", s_code, 0 },
4306 { "force_thumb", s_force_thumb, 0 },
4307 { "thumb_func", s_thumb_func, 0 },
4308 { "thumb_set", s_thumb_set, 0 },
4309 { "even", s_even, 0 },
4310 { "ltorg", s_ltorg, 0 },
4311 { "pool", s_ltorg, 0 },
4312 { "syntax", s_syntax, 0 },
4313 { "cpu", s_arm_cpu, 0 },
4314 { "arch", s_arm_arch, 0 },
4315 { "object_arch", s_arm_object_arch, 0 },
4316 { "fpu", s_arm_fpu, 0 },
4317 #ifdef OBJ_ELF
4318 { "word", s_arm_elf_cons, 4 },
4319 { "long", s_arm_elf_cons, 4 },
4320 { "inst.n", s_arm_elf_inst, 2 },
4321 { "inst.w", s_arm_elf_inst, 4 },
4322 { "inst", s_arm_elf_inst, 0 },
4323 { "rel31", s_arm_rel31, 0 },
4324 { "fnstart", s_arm_unwind_fnstart, 0 },
4325 { "fnend", s_arm_unwind_fnend, 0 },
4326 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4327 { "personality", s_arm_unwind_personality, 0 },
4328 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4329 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4330 { "save", s_arm_unwind_save, 0 },
4331 { "vsave", s_arm_unwind_save, 1 },
4332 { "movsp", s_arm_unwind_movsp, 0 },
4333 { "pad", s_arm_unwind_pad, 0 },
4334 { "setfp", s_arm_unwind_setfp, 0 },
4335 { "unwind_raw", s_arm_unwind_raw, 0 },
4336 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4337 #else
4338 { "word", cons, 4},
4339
4340 /* These are used for dwarf. */
4341 {"2byte", cons, 2},
4342 {"4byte", cons, 4},
4343 {"8byte", cons, 8},
4344 /* These are used for dwarf2. */
4345 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4346 { "loc", dwarf2_directive_loc, 0 },
4347 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
4348 #endif
4349 { "extend", float_cons, 'x' },
4350 { "ldouble", float_cons, 'x' },
4351 { "packed", float_cons, 'p' },
4352 #ifdef TE_PE
4353 {"secrel32", pe_directive_secrel, 0},
4354 #endif
4355 { 0, 0, 0 }
4356 };
4357 \f
4358 /* Parser functions used exclusively in instruction operands. */
4359
4360 /* Generic immediate-value read function for use in insn parsing.
4361 STR points to the beginning of the immediate (the leading #);
4362 VAL receives the value; if the value is outside [MIN, MAX]
4363 issue an error. PREFIX_OPT is true if the immediate prefix is
4364 optional. */
4365
4366 static int
4367 parse_immediate (char **str, int *val, int min, int max,
4368 bfd_boolean prefix_opt)
4369 {
4370 expressionS exp;
4371 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4372 if (exp.X_op != O_constant)
4373 {
4374 inst.error = _("constant expression required");
4375 return FAIL;
4376 }
4377
4378 if (exp.X_add_number < min || exp.X_add_number > max)
4379 {
4380 inst.error = _("immediate value out of range");
4381 return FAIL;
4382 }
4383
4384 *val = exp.X_add_number;
4385 return SUCCESS;
4386 }
4387
4388 /* Less-generic immediate-value read function with the possibility of loading a
4389 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4390 instructions. Puts the result directly in inst.operands[i]. */
4391
4392 static int
4393 parse_big_immediate (char **str, int i)
4394 {
4395 expressionS exp;
4396 char *ptr = *str;
4397
4398 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4399
4400 if (exp.X_op == O_constant)
4401 {
4402 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4403 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4404 O_constant. We have to be careful not to break compilation for
4405 32-bit X_add_number, though. */
4406 if ((exp.X_add_number & ~0xffffffffl) != 0)
4407 {
4408 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4409 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4410 inst.operands[i].regisimm = 1;
4411 }
4412 }
4413 else if (exp.X_op == O_big
4414 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4415 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4416 {
4417 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4418 /* Bignums have their least significant bits in
4419 generic_bignum[0]. Make sure we put 32 bits in imm and
4420 32 bits in reg, in a (hopefully) portable way. */
4421 gas_assert (parts != 0);
4422 inst.operands[i].imm = 0;
4423 for (j = 0; j < parts; j++, idx++)
4424 inst.operands[i].imm |= generic_bignum[idx]
4425 << (LITTLENUM_NUMBER_OF_BITS * j);
4426 inst.operands[i].reg = 0;
4427 for (j = 0; j < parts; j++, idx++)
4428 inst.operands[i].reg |= generic_bignum[idx]
4429 << (LITTLENUM_NUMBER_OF_BITS * j);
4430 inst.operands[i].regisimm = 1;
4431 }
4432 else
4433 return FAIL;
4434
4435 *str = ptr;
4436
4437 return SUCCESS;
4438 }
4439
4440 /* Returns the pseudo-register number of an FPA immediate constant,
4441 or FAIL if there isn't a valid constant here. */
4442
4443 static int
4444 parse_fpa_immediate (char ** str)
4445 {
4446 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4447 char * save_in;
4448 expressionS exp;
4449 int i;
4450 int j;
4451
4452 /* First try and match exact strings, this is to guarantee
4453 that some formats will work even for cross assembly. */
4454
4455 for (i = 0; fp_const[i]; i++)
4456 {
4457 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4458 {
4459 char *start = *str;
4460
4461 *str += strlen (fp_const[i]);
4462 if (is_end_of_line[(unsigned char) **str])
4463 return i + 8;
4464 *str = start;
4465 }
4466 }
4467
4468 /* Just because we didn't get a match doesn't mean that the constant
4469 isn't valid, just that it is in a format that we don't
4470 automatically recognize. Try parsing it with the standard
4471 expression routines. */
4472
4473 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
4474
4475 /* Look for a raw floating point number. */
4476 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4477 && is_end_of_line[(unsigned char) *save_in])
4478 {
4479 for (i = 0; i < NUM_FLOAT_VALS; i++)
4480 {
4481 for (j = 0; j < MAX_LITTLENUMS; j++)
4482 {
4483 if (words[j] != fp_values[i][j])
4484 break;
4485 }
4486
4487 if (j == MAX_LITTLENUMS)
4488 {
4489 *str = save_in;
4490 return i + 8;
4491 }
4492 }
4493 }
4494
4495 /* Try and parse a more complex expression, this will probably fail
4496 unless the code uses a floating point prefix (eg "0f"). */
4497 save_in = input_line_pointer;
4498 input_line_pointer = *str;
4499 if (expression (&exp) == absolute_section
4500 && exp.X_op == O_big
4501 && exp.X_add_number < 0)
4502 {
4503 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4504 Ditto for 15. */
4505 if (gen_to_words (words, 5, (long) 15) == 0)
4506 {
4507 for (i = 0; i < NUM_FLOAT_VALS; i++)
4508 {
4509 for (j = 0; j < MAX_LITTLENUMS; j++)
4510 {
4511 if (words[j] != fp_values[i][j])
4512 break;
4513 }
4514
4515 if (j == MAX_LITTLENUMS)
4516 {
4517 *str = input_line_pointer;
4518 input_line_pointer = save_in;
4519 return i + 8;
4520 }
4521 }
4522 }
4523 }
4524
4525 *str = input_line_pointer;
4526 input_line_pointer = save_in;
4527 inst.error = _("invalid FPA immediate expression");
4528 return FAIL;
4529 }
4530
4531 /* Returns 1 if a number has "quarter-precision" float format
4532 0baBbbbbbc defgh000 00000000 00000000. */
4533
4534 static int
4535 is_quarter_float (unsigned imm)
4536 {
4537 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4538 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4539 }
4540
4541 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4542 0baBbbbbbc defgh000 00000000 00000000.
4543 The zero and minus-zero cases need special handling, since they can't be
4544 encoded in the "quarter-precision" float format, but can nonetheless be
4545 loaded as integer constants. */
4546
4547 static unsigned
4548 parse_qfloat_immediate (char **ccp, int *immed)
4549 {
4550 char *str = *ccp;
4551 char *fpnum;
4552 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4553 int found_fpchar = 0;
4554
4555 skip_past_char (&str, '#');
4556
4557 /* We must not accidentally parse an integer as a floating-point number. Make
4558 sure that the value we parse is not an integer by checking for special
4559 characters '.' or 'e'.
4560 FIXME: This is a horrible hack, but doing better is tricky because type
4561 information isn't in a very usable state at parse time. */
4562 fpnum = str;
4563 skip_whitespace (fpnum);
4564
4565 if (strncmp (fpnum, "0x", 2) == 0)
4566 return FAIL;
4567 else
4568 {
4569 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4570 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4571 {
4572 found_fpchar = 1;
4573 break;
4574 }
4575
4576 if (!found_fpchar)
4577 return FAIL;
4578 }
4579
4580 if ((str = atof_ieee (str, 's', words)) != NULL)
4581 {
4582 unsigned fpword = 0;
4583 int i;
4584
4585 /* Our FP word must be 32 bits (single-precision FP). */
4586 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4587 {
4588 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4589 fpword |= words[i];
4590 }
4591
4592 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4593 *immed = fpword;
4594 else
4595 return FAIL;
4596
4597 *ccp = str;
4598
4599 return SUCCESS;
4600 }
4601
4602 return FAIL;
4603 }
4604
4605 /* Shift operands. */
4606 enum shift_kind
4607 {
4608 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4609 };
4610
4611 struct asm_shift_name
4612 {
4613 const char *name;
4614 enum shift_kind kind;
4615 };
4616
4617 /* Third argument to parse_shift. */
4618 enum parse_shift_mode
4619 {
4620 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4621 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4622 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4623 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4624 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4625 };
4626
4627 /* Parse a <shift> specifier on an ARM data processing instruction.
4628 This has three forms:
4629
4630 (LSL|LSR|ASL|ASR|ROR) Rs
4631 (LSL|LSR|ASL|ASR|ROR) #imm
4632 RRX
4633
4634 Note that ASL is assimilated to LSL in the instruction encoding, and
4635 RRX to ROR #0 (which cannot be written as such). */
4636
4637 static int
4638 parse_shift (char **str, int i, enum parse_shift_mode mode)
4639 {
4640 const struct asm_shift_name *shift_name;
4641 enum shift_kind shift;
4642 char *s = *str;
4643 char *p = s;
4644 int reg;
4645
4646 for (p = *str; ISALPHA (*p); p++)
4647 ;
4648
4649 if (p == *str)
4650 {
4651 inst.error = _("shift expression expected");
4652 return FAIL;
4653 }
4654
4655 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4656 p - *str);
4657
4658 if (shift_name == NULL)
4659 {
4660 inst.error = _("shift expression expected");
4661 return FAIL;
4662 }
4663
4664 shift = shift_name->kind;
4665
4666 switch (mode)
4667 {
4668 case NO_SHIFT_RESTRICT:
4669 case SHIFT_IMMEDIATE: break;
4670
4671 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4672 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4673 {
4674 inst.error = _("'LSL' or 'ASR' required");
4675 return FAIL;
4676 }
4677 break;
4678
4679 case SHIFT_LSL_IMMEDIATE:
4680 if (shift != SHIFT_LSL)
4681 {
4682 inst.error = _("'LSL' required");
4683 return FAIL;
4684 }
4685 break;
4686
4687 case SHIFT_ASR_IMMEDIATE:
4688 if (shift != SHIFT_ASR)
4689 {
4690 inst.error = _("'ASR' required");
4691 return FAIL;
4692 }
4693 break;
4694
4695 default: abort ();
4696 }
4697
4698 if (shift != SHIFT_RRX)
4699 {
4700 /* Whitespace can appear here if the next thing is a bare digit. */
4701 skip_whitespace (p);
4702
4703 if (mode == NO_SHIFT_RESTRICT
4704 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4705 {
4706 inst.operands[i].imm = reg;
4707 inst.operands[i].immisreg = 1;
4708 }
4709 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4710 return FAIL;
4711 }
4712 inst.operands[i].shift_kind = shift;
4713 inst.operands[i].shifted = 1;
4714 *str = p;
4715 return SUCCESS;
4716 }
4717
4718 /* Parse a <shifter_operand> for an ARM data processing instruction:
4719
4720 #<immediate>
4721 #<immediate>, <rotate>
4722 <Rm>
4723 <Rm>, <shift>
4724
4725 where <shift> is defined by parse_shift above, and <rotate> is a
4726 multiple of 2 between 0 and 30. Validation of immediate operands
4727 is deferred to md_apply_fix. */
4728
4729 static int
4730 parse_shifter_operand (char **str, int i)
4731 {
4732 int value;
4733 expressionS exp;
4734
4735 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4736 {
4737 inst.operands[i].reg = value;
4738 inst.operands[i].isreg = 1;
4739
4740 /* parse_shift will override this if appropriate */
4741 inst.reloc.exp.X_op = O_constant;
4742 inst.reloc.exp.X_add_number = 0;
4743
4744 if (skip_past_comma (str) == FAIL)
4745 return SUCCESS;
4746
4747 /* Shift operation on register. */
4748 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4749 }
4750
4751 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4752 return FAIL;
4753
4754 if (skip_past_comma (str) == SUCCESS)
4755 {
4756 /* #x, y -- ie explicit rotation by Y. */
4757 if (my_get_expression (&exp, str, GE_NO_PREFIX))
4758 return FAIL;
4759
4760 if (exp.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4761 {
4762 inst.error = _("constant expression expected");
4763 return FAIL;
4764 }
4765
4766 value = exp.X_add_number;
4767 if (value < 0 || value > 30 || value % 2 != 0)
4768 {
4769 inst.error = _("invalid rotation");
4770 return FAIL;
4771 }
4772 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4773 {
4774 inst.error = _("invalid constant");
4775 return FAIL;
4776 }
4777
4778 /* Convert to decoded value. md_apply_fix will put it back. */
4779 inst.reloc.exp.X_add_number
4780 = (((inst.reloc.exp.X_add_number << (32 - value))
4781 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
4782 }
4783
4784 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4785 inst.reloc.pc_rel = 0;
4786 return SUCCESS;
4787 }
4788
4789 /* Group relocation information. Each entry in the table contains the
4790 textual name of the relocation as may appear in assembler source
4791 and must end with a colon.
4792 Along with this textual name are the relocation codes to be used if
4793 the corresponding instruction is an ALU instruction (ADD or SUB only),
4794 an LDR, an LDRS, or an LDC. */
4795
4796 struct group_reloc_table_entry
4797 {
4798 const char *name;
4799 int alu_code;
4800 int ldr_code;
4801 int ldrs_code;
4802 int ldc_code;
4803 };
4804
4805 typedef enum
4806 {
4807 /* Varieties of non-ALU group relocation. */
4808
4809 GROUP_LDR,
4810 GROUP_LDRS,
4811 GROUP_LDC
4812 } group_reloc_type;
4813
4814 static struct group_reloc_table_entry group_reloc_table[] =
4815 { /* Program counter relative: */
4816 { "pc_g0_nc",
4817 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4818 0, /* LDR */
4819 0, /* LDRS */
4820 0 }, /* LDC */
4821 { "pc_g0",
4822 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4823 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4824 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4825 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4826 { "pc_g1_nc",
4827 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4828 0, /* LDR */
4829 0, /* LDRS */
4830 0 }, /* LDC */
4831 { "pc_g1",
4832 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4833 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4834 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4835 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4836 { "pc_g2",
4837 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4838 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4839 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4840 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4841 /* Section base relative */
4842 { "sb_g0_nc",
4843 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4844 0, /* LDR */
4845 0, /* LDRS */
4846 0 }, /* LDC */
4847 { "sb_g0",
4848 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4849 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4850 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4851 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4852 { "sb_g1_nc",
4853 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4854 0, /* LDR */
4855 0, /* LDRS */
4856 0 }, /* LDC */
4857 { "sb_g1",
4858 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4859 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4860 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4861 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4862 { "sb_g2",
4863 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4864 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4865 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4866 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4867
4868 /* Given the address of a pointer pointing to the textual name of a group
4869 relocation as may appear in assembler source, attempt to find its details
4870 in group_reloc_table. The pointer will be updated to the character after
4871 the trailing colon. On failure, FAIL will be returned; SUCCESS
4872 otherwise. On success, *entry will be updated to point at the relevant
4873 group_reloc_table entry. */
4874
4875 static int
4876 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4877 {
4878 unsigned int i;
4879 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4880 {
4881 int length = strlen (group_reloc_table[i].name);
4882
4883 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4884 && (*str)[length] == ':')
4885 {
4886 *out = &group_reloc_table[i];
4887 *str += (length + 1);
4888 return SUCCESS;
4889 }
4890 }
4891
4892 return FAIL;
4893 }
4894
4895 /* Parse a <shifter_operand> for an ARM data processing instruction
4896 (as for parse_shifter_operand) where group relocations are allowed:
4897
4898 #<immediate>
4899 #<immediate>, <rotate>
4900 #:<group_reloc>:<expression>
4901 <Rm>
4902 <Rm>, <shift>
4903
4904 where <group_reloc> is one of the strings defined in group_reloc_table.
4905 The hashes are optional.
4906
4907 Everything else is as for parse_shifter_operand. */
4908
4909 static parse_operand_result
4910 parse_shifter_operand_group_reloc (char **str, int i)
4911 {
4912 /* Determine if we have the sequence of characters #: or just :
4913 coming next. If we do, then we check for a group relocation.
4914 If we don't, punt the whole lot to parse_shifter_operand. */
4915
4916 if (((*str)[0] == '#' && (*str)[1] == ':')
4917 || (*str)[0] == ':')
4918 {
4919 struct group_reloc_table_entry *entry;
4920
4921 if ((*str)[0] == '#')
4922 (*str) += 2;
4923 else
4924 (*str)++;
4925
4926 /* Try to parse a group relocation. Anything else is an error. */
4927 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4928 {
4929 inst.error = _("unknown group relocation");
4930 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4931 }
4932
4933 /* We now have the group relocation table entry corresponding to
4934 the name in the assembler source. Next, we parse the expression. */
4935 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4936 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4937
4938 /* Record the relocation type (always the ALU variant here). */
4939 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
4940 gas_assert (inst.reloc.type != 0);
4941
4942 return PARSE_OPERAND_SUCCESS;
4943 }
4944 else
4945 return parse_shifter_operand (str, i) == SUCCESS
4946 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4947
4948 /* Never reached. */
4949 }
4950
4951 /* Parse all forms of an ARM address expression. Information is written
4952 to inst.operands[i] and/or inst.reloc.
4953
4954 Preindexed addressing (.preind=1):
4955
4956 [Rn, #offset] .reg=Rn .reloc.exp=offset
4957 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4958 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4959 .shift_kind=shift .reloc.exp=shift_imm
4960
4961 These three may have a trailing ! which causes .writeback to be set also.
4962
4963 Postindexed addressing (.postind=1, .writeback=1):
4964
4965 [Rn], #offset .reg=Rn .reloc.exp=offset
4966 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4967 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4968 .shift_kind=shift .reloc.exp=shift_imm
4969
4970 Unindexed addressing (.preind=0, .postind=0):
4971
4972 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4973
4974 Other:
4975
4976 [Rn]{!} shorthand for [Rn,#0]{!}
4977 =immediate .isreg=0 .reloc.exp=immediate
4978 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4979
4980 It is the caller's responsibility to check for addressing modes not
4981 supported by the instruction, and to set inst.reloc.type. */
4982
4983 static parse_operand_result
4984 parse_address_main (char **str, int i, int group_relocations,
4985 group_reloc_type group_type)
4986 {
4987 char *p = *str;
4988 int reg;
4989
4990 if (skip_past_char (&p, '[') == FAIL)
4991 {
4992 if (skip_past_char (&p, '=') == FAIL)
4993 {
4994 /* Bare address - translate to PC-relative offset. */
4995 inst.reloc.pc_rel = 1;
4996 inst.operands[i].reg = REG_PC;
4997 inst.operands[i].isreg = 1;
4998 inst.operands[i].preind = 1;
4999 }
5000 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
5001
5002 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5003 return PARSE_OPERAND_FAIL;
5004
5005 *str = p;
5006 return PARSE_OPERAND_SUCCESS;
5007 }
5008
5009 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5010 {
5011 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5012 return PARSE_OPERAND_FAIL;
5013 }
5014 inst.operands[i].reg = reg;
5015 inst.operands[i].isreg = 1;
5016
5017 if (skip_past_comma (&p) == SUCCESS)
5018 {
5019 inst.operands[i].preind = 1;
5020
5021 if (*p == '+') p++;
5022 else if (*p == '-') p++, inst.operands[i].negative = 1;
5023
5024 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5025 {
5026 inst.operands[i].imm = reg;
5027 inst.operands[i].immisreg = 1;
5028
5029 if (skip_past_comma (&p) == SUCCESS)
5030 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5031 return PARSE_OPERAND_FAIL;
5032 }
5033 else if (skip_past_char (&p, ':') == SUCCESS)
5034 {
5035 /* FIXME: '@' should be used here, but it's filtered out by generic
5036 code before we get to see it here. This may be subject to
5037 change. */
5038 expressionS exp;
5039 my_get_expression (&exp, &p, GE_NO_PREFIX);
5040 if (exp.X_op != O_constant)
5041 {
5042 inst.error = _("alignment must be constant");
5043 return PARSE_OPERAND_FAIL;
5044 }
5045 inst.operands[i].imm = exp.X_add_number << 8;
5046 inst.operands[i].immisalign = 1;
5047 /* Alignments are not pre-indexes. */
5048 inst.operands[i].preind = 0;
5049 }
5050 else
5051 {
5052 if (inst.operands[i].negative)
5053 {
5054 inst.operands[i].negative = 0;
5055 p--;
5056 }
5057
5058 if (group_relocations
5059 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
5060 {
5061 struct group_reloc_table_entry *entry;
5062
5063 /* Skip over the #: or : sequence. */
5064 if (*p == '#')
5065 p += 2;
5066 else
5067 p++;
5068
5069 /* Try to parse a group relocation. Anything else is an
5070 error. */
5071 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5072 {
5073 inst.error = _("unknown group relocation");
5074 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5075 }
5076
5077 /* We now have the group relocation table entry corresponding to
5078 the name in the assembler source. Next, we parse the
5079 expression. */
5080 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5081 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5082
5083 /* Record the relocation type. */
5084 switch (group_type)
5085 {
5086 case GROUP_LDR:
5087 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
5088 break;
5089
5090 case GROUP_LDRS:
5091 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
5092 break;
5093
5094 case GROUP_LDC:
5095 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
5096 break;
5097
5098 default:
5099 gas_assert (0);
5100 }
5101
5102 if (inst.reloc.type == 0)
5103 {
5104 inst.error = _("this group relocation is not allowed on this instruction");
5105 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5106 }
5107 }
5108 else
5109 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5110 return PARSE_OPERAND_FAIL;
5111 }
5112 }
5113
5114 if (skip_past_char (&p, ']') == FAIL)
5115 {
5116 inst.error = _("']' expected");
5117 return PARSE_OPERAND_FAIL;
5118 }
5119
5120 if (skip_past_char (&p, '!') == SUCCESS)
5121 inst.operands[i].writeback = 1;
5122
5123 else if (skip_past_comma (&p) == SUCCESS)
5124 {
5125 if (skip_past_char (&p, '{') == SUCCESS)
5126 {
5127 /* [Rn], {expr} - unindexed, with option */
5128 if (parse_immediate (&p, &inst.operands[i].imm,
5129 0, 255, TRUE) == FAIL)
5130 return PARSE_OPERAND_FAIL;
5131
5132 if (skip_past_char (&p, '}') == FAIL)
5133 {
5134 inst.error = _("'}' expected at end of 'option' field");
5135 return PARSE_OPERAND_FAIL;
5136 }
5137 if (inst.operands[i].preind)
5138 {
5139 inst.error = _("cannot combine index with option");
5140 return PARSE_OPERAND_FAIL;
5141 }
5142 *str = p;
5143 return PARSE_OPERAND_SUCCESS;
5144 }
5145 else
5146 {
5147 inst.operands[i].postind = 1;
5148 inst.operands[i].writeback = 1;
5149
5150 if (inst.operands[i].preind)
5151 {
5152 inst.error = _("cannot combine pre- and post-indexing");
5153 return PARSE_OPERAND_FAIL;
5154 }
5155
5156 if (*p == '+') p++;
5157 else if (*p == '-') p++, inst.operands[i].negative = 1;
5158
5159 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
5160 {
5161 /* We might be using the immediate for alignment already. If we
5162 are, OR the register number into the low-order bits. */
5163 if (inst.operands[i].immisalign)
5164 inst.operands[i].imm |= reg;
5165 else
5166 inst.operands[i].imm = reg;
5167 inst.operands[i].immisreg = 1;
5168
5169 if (skip_past_comma (&p) == SUCCESS)
5170 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
5171 return PARSE_OPERAND_FAIL;
5172 }
5173 else
5174 {
5175 if (inst.operands[i].negative)
5176 {
5177 inst.operands[i].negative = 0;
5178 p--;
5179 }
5180 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5181 return PARSE_OPERAND_FAIL;
5182 }
5183 }
5184 }
5185
5186 /* If at this point neither .preind nor .postind is set, we have a
5187 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5188 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5189 {
5190 inst.operands[i].preind = 1;
5191 inst.reloc.exp.X_op = O_constant;
5192 inst.reloc.exp.X_add_number = 0;
5193 }
5194 *str = p;
5195 return PARSE_OPERAND_SUCCESS;
5196 }
5197
5198 static int
5199 parse_address (char **str, int i)
5200 {
5201 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
5202 ? SUCCESS : FAIL;
5203 }
5204
5205 static parse_operand_result
5206 parse_address_group_reloc (char **str, int i, group_reloc_type type)
5207 {
5208 return parse_address_main (str, i, 1, type);
5209 }
5210
5211 /* Parse an operand for a MOVW or MOVT instruction. */
5212 static int
5213 parse_half (char **str)
5214 {
5215 char * p;
5216
5217 p = *str;
5218 skip_past_char (&p, '#');
5219 if (strncasecmp (p, ":lower16:", 9) == 0)
5220 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5221 else if (strncasecmp (p, ":upper16:", 9) == 0)
5222 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5223
5224 if (inst.reloc.type != BFD_RELOC_UNUSED)
5225 {
5226 p += 9;
5227 skip_whitespace (p);
5228 }
5229
5230 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5231 return FAIL;
5232
5233 if (inst.reloc.type == BFD_RELOC_UNUSED)
5234 {
5235 if (inst.reloc.exp.X_op != O_constant)
5236 {
5237 inst.error = _("constant expression expected");
5238 return FAIL;
5239 }
5240 if (inst.reloc.exp.X_add_number < 0
5241 || inst.reloc.exp.X_add_number > 0xffff)
5242 {
5243 inst.error = _("immediate value out of range");
5244 return FAIL;
5245 }
5246 }
5247 *str = p;
5248 return SUCCESS;
5249 }
5250
5251 /* Miscellaneous. */
5252
5253 /* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5254 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5255 static int
5256 parse_psr (char **str)
5257 {
5258 char *p;
5259 unsigned long psr_field;
5260 const struct asm_psr *psr;
5261 char *start;
5262
5263 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5264 feature for ease of use and backwards compatibility. */
5265 p = *str;
5266 if (strncasecmp (p, "SPSR", 4) == 0)
5267 psr_field = SPSR_BIT;
5268 else if (strncasecmp (p, "CPSR", 4) == 0)
5269 psr_field = 0;
5270 else
5271 {
5272 start = p;
5273 do
5274 p++;
5275 while (ISALNUM (*p) || *p == '_');
5276
5277 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5278 p - start);
5279 if (!psr)
5280 return FAIL;
5281
5282 *str = p;
5283 return psr->field;
5284 }
5285
5286 p += 4;
5287 if (*p == '_')
5288 {
5289 /* A suffix follows. */
5290 p++;
5291 start = p;
5292
5293 do
5294 p++;
5295 while (ISALNUM (*p) || *p == '_');
5296
5297 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5298 p - start);
5299 if (!psr)
5300 goto error;
5301
5302 psr_field |= psr->field;
5303 }
5304 else
5305 {
5306 if (ISALNUM (*p))
5307 goto error; /* Garbage after "[CS]PSR". */
5308
5309 psr_field |= (PSR_c | PSR_f);
5310 }
5311 *str = p;
5312 return psr_field;
5313
5314 error:
5315 inst.error = _("flag for {c}psr instruction expected");
5316 return FAIL;
5317 }
5318
5319 /* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5320 value suitable for splatting into the AIF field of the instruction. */
5321
5322 static int
5323 parse_cps_flags (char **str)
5324 {
5325 int val = 0;
5326 int saw_a_flag = 0;
5327 char *s = *str;
5328
5329 for (;;)
5330 switch (*s++)
5331 {
5332 case '\0': case ',':
5333 goto done;
5334
5335 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5336 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5337 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
5338
5339 default:
5340 inst.error = _("unrecognized CPS flag");
5341 return FAIL;
5342 }
5343
5344 done:
5345 if (saw_a_flag == 0)
5346 {
5347 inst.error = _("missing CPS flags");
5348 return FAIL;
5349 }
5350
5351 *str = s - 1;
5352 return val;
5353 }
5354
5355 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5356 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5357
5358 static int
5359 parse_endian_specifier (char **str)
5360 {
5361 int little_endian;
5362 char *s = *str;
5363
5364 if (strncasecmp (s, "BE", 2))
5365 little_endian = 0;
5366 else if (strncasecmp (s, "LE", 2))
5367 little_endian = 1;
5368 else
5369 {
5370 inst.error = _("valid endian specifiers are be or le");
5371 return FAIL;
5372 }
5373
5374 if (ISALNUM (s[2]) || s[2] == '_')
5375 {
5376 inst.error = _("valid endian specifiers are be or le");
5377 return FAIL;
5378 }
5379
5380 *str = s + 2;
5381 return little_endian;
5382 }
5383
5384 /* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5385 value suitable for poking into the rotate field of an sxt or sxta
5386 instruction, or FAIL on error. */
5387
5388 static int
5389 parse_ror (char **str)
5390 {
5391 int rot;
5392 char *s = *str;
5393
5394 if (strncasecmp (s, "ROR", 3) == 0)
5395 s += 3;
5396 else
5397 {
5398 inst.error = _("missing rotation field after comma");
5399 return FAIL;
5400 }
5401
5402 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5403 return FAIL;
5404
5405 switch (rot)
5406 {
5407 case 0: *str = s; return 0x0;
5408 case 8: *str = s; return 0x1;
5409 case 16: *str = s; return 0x2;
5410 case 24: *str = s; return 0x3;
5411
5412 default:
5413 inst.error = _("rotation can only be 0, 8, 16, or 24");
5414 return FAIL;
5415 }
5416 }
5417
5418 /* Parse a conditional code (from conds[] below). The value returned is in the
5419 range 0 .. 14, or FAIL. */
5420 static int
5421 parse_cond (char **str)
5422 {
5423 char *q;
5424 const struct asm_cond *c;
5425 int n;
5426 /* Condition codes are always 2 characters, so matching up to
5427 3 characters is sufficient. */
5428 char cond[3];
5429
5430 q = *str;
5431 n = 0;
5432 while (ISALPHA (*q) && n < 3)
5433 {
5434 cond[n] = TOLOWER (*q);
5435 q++;
5436 n++;
5437 }
5438
5439 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
5440 if (!c)
5441 {
5442 inst.error = _("condition required");
5443 return FAIL;
5444 }
5445
5446 *str = q;
5447 return c->value;
5448 }
5449
5450 /* Parse an option for a barrier instruction. Returns the encoding for the
5451 option, or FAIL. */
5452 static int
5453 parse_barrier (char **str)
5454 {
5455 char *p, *q;
5456 const struct asm_barrier_opt *o;
5457
5458 p = q = *str;
5459 while (ISALPHA (*q))
5460 q++;
5461
5462 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5463 q - p);
5464 if (!o)
5465 return FAIL;
5466
5467 *str = q;
5468 return o->value;
5469 }
5470
5471 /* Parse the operands of a table branch instruction. Similar to a memory
5472 operand. */
5473 static int
5474 parse_tb (char **str)
5475 {
5476 char * p = *str;
5477 int reg;
5478
5479 if (skip_past_char (&p, '[') == FAIL)
5480 {
5481 inst.error = _("'[' expected");
5482 return FAIL;
5483 }
5484
5485 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5486 {
5487 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5488 return FAIL;
5489 }
5490 inst.operands[0].reg = reg;
5491
5492 if (skip_past_comma (&p) == FAIL)
5493 {
5494 inst.error = _("',' expected");
5495 return FAIL;
5496 }
5497
5498 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5499 {
5500 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5501 return FAIL;
5502 }
5503 inst.operands[0].imm = reg;
5504
5505 if (skip_past_comma (&p) == SUCCESS)
5506 {
5507 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5508 return FAIL;
5509 if (inst.reloc.exp.X_add_number != 1)
5510 {
5511 inst.error = _("invalid shift");
5512 return FAIL;
5513 }
5514 inst.operands[0].shifted = 1;
5515 }
5516
5517 if (skip_past_char (&p, ']') == FAIL)
5518 {
5519 inst.error = _("']' expected");
5520 return FAIL;
5521 }
5522 *str = p;
5523 return SUCCESS;
5524 }
5525
5526 /* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5527 information on the types the operands can take and how they are encoded.
5528 Up to four operands may be read; this function handles setting the
5529 ".present" field for each read operand itself.
5530 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5531 else returns FAIL. */
5532
5533 static int
5534 parse_neon_mov (char **str, int *which_operand)
5535 {
5536 int i = *which_operand, val;
5537 enum arm_reg_type rtype;
5538 char *ptr = *str;
5539 struct neon_type_el optype;
5540
5541 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5542 {
5543 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5544 inst.operands[i].reg = val;
5545 inst.operands[i].isscalar = 1;
5546 inst.operands[i].vectype = optype;
5547 inst.operands[i++].present = 1;
5548
5549 if (skip_past_comma (&ptr) == FAIL)
5550 goto wanted_comma;
5551
5552 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5553 goto wanted_arm;
5554
5555 inst.operands[i].reg = val;
5556 inst.operands[i].isreg = 1;
5557 inst.operands[i].present = 1;
5558 }
5559 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5560 != FAIL)
5561 {
5562 /* Cases 0, 1, 2, 3, 5 (D only). */
5563 if (skip_past_comma (&ptr) == FAIL)
5564 goto wanted_comma;
5565
5566 inst.operands[i].reg = val;
5567 inst.operands[i].isreg = 1;
5568 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5569 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5570 inst.operands[i].isvec = 1;
5571 inst.operands[i].vectype = optype;
5572 inst.operands[i++].present = 1;
5573
5574 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5575 {
5576 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5577 Case 13: VMOV <Sd>, <Rm> */
5578 inst.operands[i].reg = val;
5579 inst.operands[i].isreg = 1;
5580 inst.operands[i].present = 1;
5581
5582 if (rtype == REG_TYPE_NQ)
5583 {
5584 first_error (_("can't use Neon quad register here"));
5585 return FAIL;
5586 }
5587 else if (rtype != REG_TYPE_VFS)
5588 {
5589 i++;
5590 if (skip_past_comma (&ptr) == FAIL)
5591 goto wanted_comma;
5592 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5593 goto wanted_arm;
5594 inst.operands[i].reg = val;
5595 inst.operands[i].isreg = 1;
5596 inst.operands[i].present = 1;
5597 }
5598 }
5599 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5600 &optype)) != FAIL)
5601 {
5602 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5603 Case 1: VMOV<c><q> <Dd>, <Dm>
5604 Case 8: VMOV.F32 <Sd>, <Sm>
5605 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5606
5607 inst.operands[i].reg = val;
5608 inst.operands[i].isreg = 1;
5609 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5610 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5611 inst.operands[i].isvec = 1;
5612 inst.operands[i].vectype = optype;
5613 inst.operands[i].present = 1;
5614
5615 if (skip_past_comma (&ptr) == SUCCESS)
5616 {
5617 /* Case 15. */
5618 i++;
5619
5620 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5621 goto wanted_arm;
5622
5623 inst.operands[i].reg = val;
5624 inst.operands[i].isreg = 1;
5625 inst.operands[i++].present = 1;
5626
5627 if (skip_past_comma (&ptr) == FAIL)
5628 goto wanted_comma;
5629
5630 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5631 goto wanted_arm;
5632
5633 inst.operands[i].reg = val;
5634 inst.operands[i].isreg = 1;
5635 inst.operands[i++].present = 1;
5636 }
5637 }
5638 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5639 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5640 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5641 Case 10: VMOV.F32 <Sd>, #<imm>
5642 Case 11: VMOV.F64 <Dd>, #<imm> */
5643 inst.operands[i].immisfloat = 1;
5644 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5645 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5646 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5647 ;
5648 else
5649 {
5650 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5651 return FAIL;
5652 }
5653 }
5654 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5655 {
5656 /* Cases 6, 7. */
5657 inst.operands[i].reg = val;
5658 inst.operands[i].isreg = 1;
5659 inst.operands[i++].present = 1;
5660
5661 if (skip_past_comma (&ptr) == FAIL)
5662 goto wanted_comma;
5663
5664 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5665 {
5666 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5667 inst.operands[i].reg = val;
5668 inst.operands[i].isscalar = 1;
5669 inst.operands[i].present = 1;
5670 inst.operands[i].vectype = optype;
5671 }
5672 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5673 {
5674 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5675 inst.operands[i].reg = val;
5676 inst.operands[i].isreg = 1;
5677 inst.operands[i++].present = 1;
5678
5679 if (skip_past_comma (&ptr) == FAIL)
5680 goto wanted_comma;
5681
5682 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5683 == FAIL)
5684 {
5685 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5686 return FAIL;
5687 }
5688
5689 inst.operands[i].reg = val;
5690 inst.operands[i].isreg = 1;
5691 inst.operands[i].isvec = 1;
5692 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5693 inst.operands[i].vectype = optype;
5694 inst.operands[i].present = 1;
5695
5696 if (rtype == REG_TYPE_VFS)
5697 {
5698 /* Case 14. */
5699 i++;
5700 if (skip_past_comma (&ptr) == FAIL)
5701 goto wanted_comma;
5702 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5703 &optype)) == FAIL)
5704 {
5705 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5706 return FAIL;
5707 }
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 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5717 != FAIL)
5718 {
5719 /* Case 13. */
5720 inst.operands[i].reg = val;
5721 inst.operands[i].isreg = 1;
5722 inst.operands[i].isvec = 1;
5723 inst.operands[i].issingle = 1;
5724 inst.operands[i].vectype = optype;
5725 inst.operands[i++].present = 1;
5726 }
5727 }
5728 else
5729 {
5730 first_error (_("parse error"));
5731 return FAIL;
5732 }
5733
5734 /* Successfully parsed the operands. Update args. */
5735 *which_operand = i;
5736 *str = ptr;
5737 return SUCCESS;
5738
5739 wanted_comma:
5740 first_error (_("expected comma"));
5741 return FAIL;
5742
5743 wanted_arm:
5744 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5745 return FAIL;
5746 }
5747
5748 /* Use this macro when the operand constraints are different
5749 for ARM and THUMB (e.g. ldrd). */
5750 #define MIX_ARM_THUMB_OPERANDS(arm_operand, thumb_operand) \
5751 ((arm_operand) | ((thumb_operand) << 16))
5752
5753 /* Matcher codes for parse_operands. */
5754 enum operand_parse_code
5755 {
5756 OP_stop, /* end of line */
5757
5758 OP_RR, /* ARM register */
5759 OP_RRnpc, /* ARM register, not r15 */
5760 OP_RRnpcsp, /* ARM register, neither r15 nor r13 (a.k.a. 'BadReg') */
5761 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5762 OP_RRw, /* ARM register, not r15, optional trailing ! */
5763 OP_RCP, /* Coprocessor number */
5764 OP_RCN, /* Coprocessor register */
5765 OP_RF, /* FPA register */
5766 OP_RVS, /* VFP single precision register */
5767 OP_RVD, /* VFP double precision register (0..15) */
5768 OP_RND, /* Neon double precision register (0..31) */
5769 OP_RNQ, /* Neon quad precision register */
5770 OP_RVSD, /* VFP single or double precision register */
5771 OP_RNDQ, /* Neon double or quad precision register */
5772 OP_RNSDQ, /* Neon single, double or quad precision register */
5773 OP_RNSC, /* Neon scalar D[X] */
5774 OP_RVC, /* VFP control register */
5775 OP_RMF, /* Maverick F register */
5776 OP_RMD, /* Maverick D register */
5777 OP_RMFX, /* Maverick FX register */
5778 OP_RMDX, /* Maverick DX register */
5779 OP_RMAX, /* Maverick AX register */
5780 OP_RMDS, /* Maverick DSPSC register */
5781 OP_RIWR, /* iWMMXt wR register */
5782 OP_RIWC, /* iWMMXt wC register */
5783 OP_RIWG, /* iWMMXt wCG register */
5784 OP_RXA, /* XScale accumulator register */
5785
5786 OP_REGLST, /* ARM register list */
5787 OP_VRSLST, /* VFP single-precision register list */
5788 OP_VRDLST, /* VFP double-precision register list */
5789 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5790 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5791 OP_NSTRLST, /* Neon element/structure list */
5792
5793 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
5794 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5795 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5796 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5797 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5798 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5799 OP_VMOV, /* Neon VMOV operands. */
5800 OP_RNDQ_Ibig, /* Neon D or Q reg, or big immediate for logic and VMVN. */
5801 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5802 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5803
5804 OP_I0, /* immediate zero */
5805 OP_I7, /* immediate value 0 .. 7 */
5806 OP_I15, /* 0 .. 15 */
5807 OP_I16, /* 1 .. 16 */
5808 OP_I16z, /* 0 .. 16 */
5809 OP_I31, /* 0 .. 31 */
5810 OP_I31w, /* 0 .. 31, optional trailing ! */
5811 OP_I32, /* 1 .. 32 */
5812 OP_I32z, /* 0 .. 32 */
5813 OP_I63, /* 0 .. 63 */
5814 OP_I63s, /* -64 .. 63 */
5815 OP_I64, /* 1 .. 64 */
5816 OP_I64z, /* 0 .. 64 */
5817 OP_I255, /* 0 .. 255 */
5818
5819 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5820 OP_I7b, /* 0 .. 7 */
5821 OP_I15b, /* 0 .. 15 */
5822 OP_I31b, /* 0 .. 31 */
5823
5824 OP_SH, /* shifter operand */
5825 OP_SHG, /* shifter operand with possible group relocation */
5826 OP_ADDR, /* Memory address expression (any mode) */
5827 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5828 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5829 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
5830 OP_EXP, /* arbitrary expression */
5831 OP_EXPi, /* same, with optional immediate prefix */
5832 OP_EXPr, /* same, with optional relocation suffix */
5833 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5834
5835 OP_CPSF, /* CPS flags */
5836 OP_ENDI, /* Endianness specifier */
5837 OP_PSR, /* CPSR/SPSR mask for msr */
5838 OP_COND, /* conditional code */
5839 OP_TB, /* Table branch. */
5840
5841 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5842 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5843
5844 OP_RRnpc_I0, /* ARM register or literal 0 */
5845 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5846 OP_RR_EXi, /* ARM register or expression with imm prefix */
5847 OP_RF_IF, /* FPA register or immediate */
5848 OP_RIWR_RIWC, /* iWMMXt R or C reg */
5849 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5850
5851 /* Optional operands. */
5852 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5853 OP_oI31b, /* 0 .. 31 */
5854 OP_oI32b, /* 1 .. 32 */
5855 OP_oIffffb, /* 0 .. 65535 */
5856 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5857
5858 OP_oRR, /* ARM register */
5859 OP_oRRnpc, /* ARM register, not the PC */
5860 OP_oRRnpcsp, /* ARM register, neither the PC nor the SP (a.k.a. BadReg) */
5861 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5862 OP_oRND, /* Optional Neon double precision register */
5863 OP_oRNQ, /* Optional Neon quad precision register */
5864 OP_oRNDQ, /* Optional Neon double or quad precision register */
5865 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
5866 OP_oSHll, /* LSL immediate */
5867 OP_oSHar, /* ASR immediate */
5868 OP_oSHllar, /* LSL or ASR immediate */
5869 OP_oROR, /* ROR 0/8/16/24 */
5870 OP_oBARRIER, /* Option argument for a barrier instruction. */
5871
5872 /* Some pre-defined mixed (ARM/THUMB) operands. */
5873 OP_RR_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RR, OP_RRnpcsp),
5874 OP_RRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_RRnpc, OP_RRnpcsp),
5875 OP_oRRnpc_npcsp = MIX_ARM_THUMB_OPERANDS (OP_oRRnpc, OP_oRRnpcsp),
5876
5877 OP_FIRST_OPTIONAL = OP_oI7b
5878 };
5879
5880 /* Generic instruction operand parser. This does no encoding and no
5881 semantic validation; it merely squirrels values away in the inst
5882 structure. Returns SUCCESS or FAIL depending on whether the
5883 specified grammar matched. */
5884 static int
5885 parse_operands (char *str, const unsigned int *pattern, bfd_boolean thumb)
5886 {
5887 unsigned const int *upat = pattern;
5888 char *backtrack_pos = 0;
5889 const char *backtrack_error = 0;
5890 int i, val, backtrack_index = 0;
5891 enum arm_reg_type rtype;
5892 parse_operand_result result;
5893 unsigned int op_parse_code;
5894
5895 #define po_char_or_fail(chr) \
5896 do \
5897 { \
5898 if (skip_past_char (&str, chr) == FAIL) \
5899 goto bad_args; \
5900 } \
5901 while (0)
5902
5903 #define po_reg_or_fail(regtype) \
5904 do \
5905 { \
5906 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5907 & inst.operands[i].vectype); \
5908 if (val == FAIL) \
5909 { \
5910 first_error (_(reg_expected_msgs[regtype])); \
5911 goto failure; \
5912 } \
5913 inst.operands[i].reg = val; \
5914 inst.operands[i].isreg = 1; \
5915 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5916 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5917 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5918 || rtype == REG_TYPE_VFD \
5919 || rtype == REG_TYPE_NQ); \
5920 } \
5921 while (0)
5922
5923 #define po_reg_or_goto(regtype, label) \
5924 do \
5925 { \
5926 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5927 & inst.operands[i].vectype); \
5928 if (val == FAIL) \
5929 goto label; \
5930 \
5931 inst.operands[i].reg = val; \
5932 inst.operands[i].isreg = 1; \
5933 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5934 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5935 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5936 || rtype == REG_TYPE_VFD \
5937 || rtype == REG_TYPE_NQ); \
5938 } \
5939 while (0)
5940
5941 #define po_imm_or_fail(min, max, popt) \
5942 do \
5943 { \
5944 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5945 goto failure; \
5946 inst.operands[i].imm = val; \
5947 } \
5948 while (0)
5949
5950 #define po_scalar_or_goto(elsz, label) \
5951 do \
5952 { \
5953 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5954 if (val == FAIL) \
5955 goto label; \
5956 inst.operands[i].reg = val; \
5957 inst.operands[i].isscalar = 1; \
5958 } \
5959 while (0)
5960
5961 #define po_misc_or_fail(expr) \
5962 do \
5963 { \
5964 if (expr) \
5965 goto failure; \
5966 } \
5967 while (0)
5968
5969 #define po_misc_or_fail_no_backtrack(expr) \
5970 do \
5971 { \
5972 result = expr; \
5973 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5974 backtrack_pos = 0; \
5975 if (result != PARSE_OPERAND_SUCCESS) \
5976 goto failure; \
5977 } \
5978 while (0)
5979
5980 skip_whitespace (str);
5981
5982 for (i = 0; upat[i] != OP_stop; i++)
5983 {
5984 op_parse_code = upat[i];
5985 if (op_parse_code >= 1<<16)
5986 op_parse_code = thumb ? (op_parse_code >> 16)
5987 : (op_parse_code & ((1<<16)-1));
5988
5989 if (op_parse_code >= OP_FIRST_OPTIONAL)
5990 {
5991 /* Remember where we are in case we need to backtrack. */
5992 gas_assert (!backtrack_pos);
5993 backtrack_pos = str;
5994 backtrack_error = inst.error;
5995 backtrack_index = i;
5996 }
5997
5998 if (i > 0 && (i > 1 || inst.operands[0].present))
5999 po_char_or_fail (',');
6000
6001 switch (op_parse_code)
6002 {
6003 /* Registers */
6004 case OP_oRRnpc:
6005 case OP_oRRnpcsp:
6006 case OP_RRnpc:
6007 case OP_RRnpcsp:
6008 case OP_oRR:
6009 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
6010 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
6011 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
6012 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
6013 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
6014 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
6015 case OP_oRND:
6016 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
6017 case OP_RVC:
6018 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
6019 break;
6020 /* Also accept generic coprocessor regs for unknown registers. */
6021 coproc_reg:
6022 po_reg_or_fail (REG_TYPE_CN);
6023 break;
6024 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
6025 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
6026 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
6027 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
6028 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
6029 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
6030 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
6031 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
6032 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
6033 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
6034 case OP_oRNQ:
6035 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
6036 case OP_oRNDQ:
6037 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
6038 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6039 case OP_oRNSDQ:
6040 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
6041
6042 /* Neon scalar. Using an element size of 8 means that some invalid
6043 scalars are accepted here, so deal with those in later code. */
6044 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6045
6046 case OP_RNDQ_I0:
6047 {
6048 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6049 break;
6050 try_imm0:
6051 po_imm_or_fail (0, 0, TRUE);
6052 }
6053 break;
6054
6055 case OP_RVSD_I0:
6056 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6057 break;
6058
6059 case OP_RR_RNSC:
6060 {
6061 po_scalar_or_goto (8, try_rr);
6062 break;
6063 try_rr:
6064 po_reg_or_fail (REG_TYPE_RN);
6065 }
6066 break;
6067
6068 case OP_RNSDQ_RNSC:
6069 {
6070 po_scalar_or_goto (8, try_nsdq);
6071 break;
6072 try_nsdq:
6073 po_reg_or_fail (REG_TYPE_NSDQ);
6074 }
6075 break;
6076
6077 case OP_RNDQ_RNSC:
6078 {
6079 po_scalar_or_goto (8, try_ndq);
6080 break;
6081 try_ndq:
6082 po_reg_or_fail (REG_TYPE_NDQ);
6083 }
6084 break;
6085
6086 case OP_RND_RNSC:
6087 {
6088 po_scalar_or_goto (8, try_vfd);
6089 break;
6090 try_vfd:
6091 po_reg_or_fail (REG_TYPE_VFD);
6092 }
6093 break;
6094
6095 case OP_VMOV:
6096 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6097 not careful then bad things might happen. */
6098 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6099 break;
6100
6101 case OP_RNDQ_Ibig:
6102 {
6103 po_reg_or_goto (REG_TYPE_NDQ, try_immbig);
6104 break;
6105 try_immbig:
6106 /* There's a possibility of getting a 64-bit immediate here, so
6107 we need special handling. */
6108 if (parse_big_immediate (&str, i) == FAIL)
6109 {
6110 inst.error = _("immediate value is out of range");
6111 goto failure;
6112 }
6113 }
6114 break;
6115
6116 case OP_RNDQ_I63b:
6117 {
6118 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6119 break;
6120 try_shimm:
6121 po_imm_or_fail (0, 63, TRUE);
6122 }
6123 break;
6124
6125 case OP_RRnpcb:
6126 po_char_or_fail ('[');
6127 po_reg_or_fail (REG_TYPE_RN);
6128 po_char_or_fail (']');
6129 break;
6130
6131 case OP_RRw:
6132 case OP_oRRw:
6133 po_reg_or_fail (REG_TYPE_RN);
6134 if (skip_past_char (&str, '!') == SUCCESS)
6135 inst.operands[i].writeback = 1;
6136 break;
6137
6138 /* Immediates */
6139 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6140 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6141 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
6142 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
6143 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6144 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
6145 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
6146 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
6147 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6148 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6149 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
6150 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
6151
6152 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6153 case OP_oI7b:
6154 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6155 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6156 case OP_oI31b:
6157 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
6158 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
6159 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6160
6161 /* Immediate variants */
6162 case OP_oI255c:
6163 po_char_or_fail ('{');
6164 po_imm_or_fail (0, 255, TRUE);
6165 po_char_or_fail ('}');
6166 break;
6167
6168 case OP_I31w:
6169 /* The expression parser chokes on a trailing !, so we have
6170 to find it first and zap it. */
6171 {
6172 char *s = str;
6173 while (*s && *s != ',')
6174 s++;
6175 if (s[-1] == '!')
6176 {
6177 s[-1] = '\0';
6178 inst.operands[i].writeback = 1;
6179 }
6180 po_imm_or_fail (0, 31, TRUE);
6181 if (str == s - 1)
6182 str = s;
6183 }
6184 break;
6185
6186 /* Expressions */
6187 case OP_EXPi: EXPi:
6188 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6189 GE_OPT_PREFIX));
6190 break;
6191
6192 case OP_EXP:
6193 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6194 GE_NO_PREFIX));
6195 break;
6196
6197 case OP_EXPr: EXPr:
6198 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6199 GE_NO_PREFIX));
6200 if (inst.reloc.exp.X_op == O_symbol)
6201 {
6202 val = parse_reloc (&str);
6203 if (val == -1)
6204 {
6205 inst.error = _("unrecognized relocation suffix");
6206 goto failure;
6207 }
6208 else if (val != BFD_RELOC_UNUSED)
6209 {
6210 inst.operands[i].imm = val;
6211 inst.operands[i].hasreloc = 1;
6212 }
6213 }
6214 break;
6215
6216 /* Operand for MOVW or MOVT. */
6217 case OP_HALF:
6218 po_misc_or_fail (parse_half (&str));
6219 break;
6220
6221 /* Register or expression. */
6222 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6223 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
6224
6225 /* Register or immediate. */
6226 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6227 I0: po_imm_or_fail (0, 0, FALSE); break;
6228
6229 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6230 IF:
6231 if (!is_immediate_prefix (*str))
6232 goto bad_args;
6233 str++;
6234 val = parse_fpa_immediate (&str);
6235 if (val == FAIL)
6236 goto failure;
6237 /* FPA immediates are encoded as registers 8-15.
6238 parse_fpa_immediate has already applied the offset. */
6239 inst.operands[i].reg = val;
6240 inst.operands[i].isreg = 1;
6241 break;
6242
6243 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6244 I32z: po_imm_or_fail (0, 32, FALSE); break;
6245
6246 /* Two kinds of register. */
6247 case OP_RIWR_RIWC:
6248 {
6249 struct reg_entry *rege = arm_reg_parse_multi (&str);
6250 if (!rege
6251 || (rege->type != REG_TYPE_MMXWR
6252 && rege->type != REG_TYPE_MMXWC
6253 && rege->type != REG_TYPE_MMXWCG))
6254 {
6255 inst.error = _("iWMMXt data or control register expected");
6256 goto failure;
6257 }
6258 inst.operands[i].reg = rege->number;
6259 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6260 }
6261 break;
6262
6263 case OP_RIWC_RIWG:
6264 {
6265 struct reg_entry *rege = arm_reg_parse_multi (&str);
6266 if (!rege
6267 || (rege->type != REG_TYPE_MMXWC
6268 && rege->type != REG_TYPE_MMXWCG))
6269 {
6270 inst.error = _("iWMMXt control register expected");
6271 goto failure;
6272 }
6273 inst.operands[i].reg = rege->number;
6274 inst.operands[i].isreg = 1;
6275 }
6276 break;
6277
6278 /* Misc */
6279 case OP_CPSF: val = parse_cps_flags (&str); break;
6280 case OP_ENDI: val = parse_endian_specifier (&str); break;
6281 case OP_oROR: val = parse_ror (&str); break;
6282 case OP_PSR: val = parse_psr (&str); break;
6283 case OP_COND: val = parse_cond (&str); break;
6284 case OP_oBARRIER:val = parse_barrier (&str); break;
6285
6286 case OP_RVC_PSR:
6287 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6288 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6289 break;
6290 try_psr:
6291 val = parse_psr (&str);
6292 break;
6293
6294 case OP_APSR_RR:
6295 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6296 break;
6297 try_apsr:
6298 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6299 instruction). */
6300 if (strncasecmp (str, "APSR_", 5) == 0)
6301 {
6302 unsigned found = 0;
6303 str += 5;
6304 while (found < 15)
6305 switch (*str++)
6306 {
6307 case 'c': found = (found & 1) ? 16 : found | 1; break;
6308 case 'n': found = (found & 2) ? 16 : found | 2; break;
6309 case 'z': found = (found & 4) ? 16 : found | 4; break;
6310 case 'v': found = (found & 8) ? 16 : found | 8; break;
6311 default: found = 16;
6312 }
6313 if (found != 15)
6314 goto failure;
6315 inst.operands[i].isvec = 1;
6316 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6317 inst.operands[i].reg = REG_PC;
6318 }
6319 else
6320 goto failure;
6321 break;
6322
6323 case OP_TB:
6324 po_misc_or_fail (parse_tb (&str));
6325 break;
6326
6327 /* Register lists. */
6328 case OP_REGLST:
6329 val = parse_reg_list (&str);
6330 if (*str == '^')
6331 {
6332 inst.operands[1].writeback = 1;
6333 str++;
6334 }
6335 break;
6336
6337 case OP_VRSLST:
6338 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6339 break;
6340
6341 case OP_VRDLST:
6342 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6343 break;
6344
6345 case OP_VRSDLST:
6346 /* Allow Q registers too. */
6347 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6348 REGLIST_NEON_D);
6349 if (val == FAIL)
6350 {
6351 inst.error = NULL;
6352 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6353 REGLIST_VFP_S);
6354 inst.operands[i].issingle = 1;
6355 }
6356 break;
6357
6358 case OP_NRDLST:
6359 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6360 REGLIST_NEON_D);
6361 break;
6362
6363 case OP_NSTRLST:
6364 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6365 &inst.operands[i].vectype);
6366 break;
6367
6368 /* Addressing modes */
6369 case OP_ADDR:
6370 po_misc_or_fail (parse_address (&str, i));
6371 break;
6372
6373 case OP_ADDRGLDR:
6374 po_misc_or_fail_no_backtrack (
6375 parse_address_group_reloc (&str, i, GROUP_LDR));
6376 break;
6377
6378 case OP_ADDRGLDRS:
6379 po_misc_or_fail_no_backtrack (
6380 parse_address_group_reloc (&str, i, GROUP_LDRS));
6381 break;
6382
6383 case OP_ADDRGLDC:
6384 po_misc_or_fail_no_backtrack (
6385 parse_address_group_reloc (&str, i, GROUP_LDC));
6386 break;
6387
6388 case OP_SH:
6389 po_misc_or_fail (parse_shifter_operand (&str, i));
6390 break;
6391
6392 case OP_SHG:
6393 po_misc_or_fail_no_backtrack (
6394 parse_shifter_operand_group_reloc (&str, i));
6395 break;
6396
6397 case OP_oSHll:
6398 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6399 break;
6400
6401 case OP_oSHar:
6402 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6403 break;
6404
6405 case OP_oSHllar:
6406 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6407 break;
6408
6409 default:
6410 as_fatal (_("unhandled operand code %d"), op_parse_code);
6411 }
6412
6413 /* Various value-based sanity checks and shared operations. We
6414 do not signal immediate failures for the register constraints;
6415 this allows a syntax error to take precedence. */
6416 switch (op_parse_code)
6417 {
6418 case OP_oRRnpc:
6419 case OP_RRnpc:
6420 case OP_RRnpcb:
6421 case OP_RRw:
6422 case OP_oRRw:
6423 case OP_RRnpc_I0:
6424 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6425 inst.error = BAD_PC;
6426 break;
6427
6428 case OP_oRRnpcsp:
6429 case OP_RRnpcsp:
6430 if (inst.operands[i].isreg)
6431 {
6432 if (inst.operands[i].reg == REG_PC)
6433 inst.error = BAD_PC;
6434 else if (inst.operands[i].reg == REG_SP)
6435 inst.error = BAD_SP;
6436 }
6437 break;
6438
6439 case OP_CPSF:
6440 case OP_ENDI:
6441 case OP_oROR:
6442 case OP_PSR:
6443 case OP_RVC_PSR:
6444 case OP_COND:
6445 case OP_oBARRIER:
6446 case OP_REGLST:
6447 case OP_VRSLST:
6448 case OP_VRDLST:
6449 case OP_VRSDLST:
6450 case OP_NRDLST:
6451 case OP_NSTRLST:
6452 if (val == FAIL)
6453 goto failure;
6454 inst.operands[i].imm = val;
6455 break;
6456
6457 default:
6458 break;
6459 }
6460
6461 /* If we get here, this operand was successfully parsed. */
6462 inst.operands[i].present = 1;
6463 continue;
6464
6465 bad_args:
6466 inst.error = BAD_ARGS;
6467
6468 failure:
6469 if (!backtrack_pos)
6470 {
6471 /* The parse routine should already have set inst.error, but set a
6472 default here just in case. */
6473 if (!inst.error)
6474 inst.error = _("syntax error");
6475 return FAIL;
6476 }
6477
6478 /* Do not backtrack over a trailing optional argument that
6479 absorbed some text. We will only fail again, with the
6480 'garbage following instruction' error message, which is
6481 probably less helpful than the current one. */
6482 if (backtrack_index == i && backtrack_pos != str
6483 && upat[i+1] == OP_stop)
6484 {
6485 if (!inst.error)
6486 inst.error = _("syntax error");
6487 return FAIL;
6488 }
6489
6490 /* Try again, skipping the optional argument at backtrack_pos. */
6491 str = backtrack_pos;
6492 inst.error = backtrack_error;
6493 inst.operands[backtrack_index].present = 0;
6494 i = backtrack_index;
6495 backtrack_pos = 0;
6496 }
6497
6498 /* Check that we have parsed all the arguments. */
6499 if (*str != '\0' && !inst.error)
6500 inst.error = _("garbage following instruction");
6501
6502 return inst.error ? FAIL : SUCCESS;
6503 }
6504
6505 #undef po_char_or_fail
6506 #undef po_reg_or_fail
6507 #undef po_reg_or_goto
6508 #undef po_imm_or_fail
6509 #undef po_scalar_or_fail
6510
6511 /* Shorthand macro for instruction encoding functions issuing errors. */
6512 #define constraint(expr, err) \
6513 do \
6514 { \
6515 if (expr) \
6516 { \
6517 inst.error = err; \
6518 return; \
6519 } \
6520 } \
6521 while (0)
6522
6523 /* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6524 instructions are unpredictable if these registers are used. This
6525 is the BadReg predicate in ARM's Thumb-2 documentation. */
6526 #define reject_bad_reg(reg) \
6527 do \
6528 if (reg == REG_SP || reg == REG_PC) \
6529 { \
6530 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6531 return; \
6532 } \
6533 while (0)
6534
6535 /* If REG is R13 (the stack pointer), warn that its use is
6536 deprecated. */
6537 #define warn_deprecated_sp(reg) \
6538 do \
6539 if (warn_on_deprecated && reg == REG_SP) \
6540 as_warn (_("use of r13 is deprecated")); \
6541 while (0)
6542
6543 /* Functions for operand encoding. ARM, then Thumb. */
6544
6545 #define rotate_left(v, n) (v << n | v >> (32 - n))
6546
6547 /* If VAL can be encoded in the immediate field of an ARM instruction,
6548 return the encoded form. Otherwise, return FAIL. */
6549
6550 static unsigned int
6551 encode_arm_immediate (unsigned int val)
6552 {
6553 unsigned int a, i;
6554
6555 for (i = 0; i < 32; i += 2)
6556 if ((a = rotate_left (val, i)) <= 0xff)
6557 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6558
6559 return FAIL;
6560 }
6561
6562 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6563 return the encoded form. Otherwise, return FAIL. */
6564 static unsigned int
6565 encode_thumb32_immediate (unsigned int val)
6566 {
6567 unsigned int a, i;
6568
6569 if (val <= 0xff)
6570 return val;
6571
6572 for (i = 1; i <= 24; i++)
6573 {
6574 a = val >> i;
6575 if ((val & ~(0xff << i)) == 0)
6576 return ((val >> i) & 0x7f) | ((32 - i) << 7);
6577 }
6578
6579 a = val & 0xff;
6580 if (val == ((a << 16) | a))
6581 return 0x100 | a;
6582 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6583 return 0x300 | a;
6584
6585 a = val & 0xff00;
6586 if (val == ((a << 16) | a))
6587 return 0x200 | (a >> 8);
6588
6589 return FAIL;
6590 }
6591 /* Encode a VFP SP or DP register number into inst.instruction. */
6592
6593 static void
6594 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6595 {
6596 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6597 && reg > 15)
6598 {
6599 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6600 {
6601 if (thumb_mode)
6602 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6603 fpu_vfp_ext_d32);
6604 else
6605 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6606 fpu_vfp_ext_d32);
6607 }
6608 else
6609 {
6610 first_error (_("D register out of range for selected VFP version"));
6611 return;
6612 }
6613 }
6614
6615 switch (pos)
6616 {
6617 case VFP_REG_Sd:
6618 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6619 break;
6620
6621 case VFP_REG_Sn:
6622 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6623 break;
6624
6625 case VFP_REG_Sm:
6626 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6627 break;
6628
6629 case VFP_REG_Dd:
6630 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6631 break;
6632
6633 case VFP_REG_Dn:
6634 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6635 break;
6636
6637 case VFP_REG_Dm:
6638 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6639 break;
6640
6641 default:
6642 abort ();
6643 }
6644 }
6645
6646 /* Encode a <shift> in an ARM-format instruction. The immediate,
6647 if any, is handled by md_apply_fix. */
6648 static void
6649 encode_arm_shift (int i)
6650 {
6651 if (inst.operands[i].shift_kind == SHIFT_RRX)
6652 inst.instruction |= SHIFT_ROR << 5;
6653 else
6654 {
6655 inst.instruction |= inst.operands[i].shift_kind << 5;
6656 if (inst.operands[i].immisreg)
6657 {
6658 inst.instruction |= SHIFT_BY_REG;
6659 inst.instruction |= inst.operands[i].imm << 8;
6660 }
6661 else
6662 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6663 }
6664 }
6665
6666 static void
6667 encode_arm_shifter_operand (int i)
6668 {
6669 if (inst.operands[i].isreg)
6670 {
6671 inst.instruction |= inst.operands[i].reg;
6672 encode_arm_shift (i);
6673 }
6674 else
6675 inst.instruction |= INST_IMMEDIATE;
6676 }
6677
6678 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6679 static void
6680 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6681 {
6682 gas_assert (inst.operands[i].isreg);
6683 inst.instruction |= inst.operands[i].reg << 16;
6684
6685 if (inst.operands[i].preind)
6686 {
6687 if (is_t)
6688 {
6689 inst.error = _("instruction does not accept preindexed addressing");
6690 return;
6691 }
6692 inst.instruction |= PRE_INDEX;
6693 if (inst.operands[i].writeback)
6694 inst.instruction |= WRITE_BACK;
6695
6696 }
6697 else if (inst.operands[i].postind)
6698 {
6699 gas_assert (inst.operands[i].writeback);
6700 if (is_t)
6701 inst.instruction |= WRITE_BACK;
6702 }
6703 else /* unindexed - only for coprocessor */
6704 {
6705 inst.error = _("instruction does not accept unindexed addressing");
6706 return;
6707 }
6708
6709 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6710 && (((inst.instruction & 0x000f0000) >> 16)
6711 == ((inst.instruction & 0x0000f000) >> 12)))
6712 as_warn ((inst.instruction & LOAD_BIT)
6713 ? _("destination register same as write-back base")
6714 : _("source register same as write-back base"));
6715 }
6716
6717 /* inst.operands[i] was set up by parse_address. Encode it into an
6718 ARM-format mode 2 load or store instruction. If is_t is true,
6719 reject forms that cannot be used with a T instruction (i.e. not
6720 post-indexed). */
6721 static void
6722 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6723 {
6724 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
6725
6726 encode_arm_addr_mode_common (i, is_t);
6727
6728 if (inst.operands[i].immisreg)
6729 {
6730 constraint ((inst.operands[i].imm == REG_PC
6731 || (is_pc && inst.operands[i].writeback)),
6732 BAD_PC_ADDRESSING);
6733 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6734 inst.instruction |= inst.operands[i].imm;
6735 if (!inst.operands[i].negative)
6736 inst.instruction |= INDEX_UP;
6737 if (inst.operands[i].shifted)
6738 {
6739 if (inst.operands[i].shift_kind == SHIFT_RRX)
6740 inst.instruction |= SHIFT_ROR << 5;
6741 else
6742 {
6743 inst.instruction |= inst.operands[i].shift_kind << 5;
6744 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6745 }
6746 }
6747 }
6748 else /* immediate offset in inst.reloc */
6749 {
6750 if (is_pc && !inst.reloc.pc_rel)
6751 {
6752 const bfd_boolean is_load = ((inst.instruction & LOAD_BIT) != 0);
6753 /* BAD_PC_ADDRESSING Condition =
6754 is_load => is_t
6755 which becomes !is_load || is_t. */
6756 constraint ((!is_load || is_t),
6757 BAD_PC_ADDRESSING);
6758 }
6759
6760 if (inst.reloc.type == BFD_RELOC_UNUSED)
6761 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
6762 }
6763 }
6764
6765 /* inst.operands[i] was set up by parse_address. Encode it into an
6766 ARM-format mode 3 load or store instruction. Reject forms that
6767 cannot be used with such instructions. If is_t is true, reject
6768 forms that cannot be used with a T instruction (i.e. not
6769 post-indexed). */
6770 static void
6771 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6772 {
6773 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6774 {
6775 inst.error = _("instruction does not accept scaled register index");
6776 return;
6777 }
6778
6779 encode_arm_addr_mode_common (i, is_t);
6780
6781 if (inst.operands[i].immisreg)
6782 {
6783 constraint ((inst.operands[i].imm == REG_PC
6784 || inst.operands[i].reg == REG_PC),
6785 BAD_PC_ADDRESSING);
6786 inst.instruction |= inst.operands[i].imm;
6787 if (!inst.operands[i].negative)
6788 inst.instruction |= INDEX_UP;
6789 }
6790 else /* immediate offset in inst.reloc */
6791 {
6792 constraint ((inst.operands[i].reg == REG_PC && !inst.reloc.pc_rel
6793 && inst.operands[i].writeback),
6794 BAD_PC_WRITEBACK);
6795 inst.instruction |= HWOFFSET_IMM;
6796 if (inst.reloc.type == BFD_RELOC_UNUSED)
6797 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
6798 }
6799 }
6800
6801 /* inst.operands[i] was set up by parse_address. Encode it into an
6802 ARM-format instruction. Reject all forms which cannot be encoded
6803 into a coprocessor load/store instruction. If wb_ok is false,
6804 reject use of writeback; if unind_ok is false, reject use of
6805 unindexed addressing. If reloc_override is not 0, use it instead
6806 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6807 (in which case it is preserved). */
6808
6809 static int
6810 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6811 {
6812 inst.instruction |= inst.operands[i].reg << 16;
6813
6814 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
6815
6816 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6817 {
6818 gas_assert (!inst.operands[i].writeback);
6819 if (!unind_ok)
6820 {
6821 inst.error = _("instruction does not support unindexed addressing");
6822 return FAIL;
6823 }
6824 inst.instruction |= inst.operands[i].imm;
6825 inst.instruction |= INDEX_UP;
6826 return SUCCESS;
6827 }
6828
6829 if (inst.operands[i].preind)
6830 inst.instruction |= PRE_INDEX;
6831
6832 if (inst.operands[i].writeback)
6833 {
6834 if (inst.operands[i].reg == REG_PC)
6835 {
6836 inst.error = _("pc may not be used with write-back");
6837 return FAIL;
6838 }
6839 if (!wb_ok)
6840 {
6841 inst.error = _("instruction does not support writeback");
6842 return FAIL;
6843 }
6844 inst.instruction |= WRITE_BACK;
6845 }
6846
6847 if (reloc_override)
6848 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
6849 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6850 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6851 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6852 {
6853 if (thumb_mode)
6854 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6855 else
6856 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6857 }
6858
6859 return SUCCESS;
6860 }
6861
6862 /* inst.reloc.exp describes an "=expr" load pseudo-operation.
6863 Determine whether it can be performed with a move instruction; if
6864 it can, convert inst.instruction to that move instruction and
6865 return TRUE; if it can't, convert inst.instruction to a literal-pool
6866 load and return FALSE. If this is not a valid thing to do in the
6867 current context, set inst.error and return TRUE.
6868
6869 inst.operands[i] describes the destination register. */
6870
6871 static bfd_boolean
6872 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6873 {
6874 unsigned long tbit;
6875
6876 if (thumb_p)
6877 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6878 else
6879 tbit = LOAD_BIT;
6880
6881 if ((inst.instruction & tbit) == 0)
6882 {
6883 inst.error = _("invalid pseudo operation");
6884 return TRUE;
6885 }
6886 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6887 {
6888 inst.error = _("constant expression expected");
6889 return TRUE;
6890 }
6891 if (inst.reloc.exp.X_op == O_constant)
6892 {
6893 if (thumb_p)
6894 {
6895 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
6896 {
6897 /* This can be done with a mov(1) instruction. */
6898 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6899 inst.instruction |= inst.reloc.exp.X_add_number;
6900 return TRUE;
6901 }
6902 }
6903 else
6904 {
6905 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6906 if (value != FAIL)
6907 {
6908 /* This can be done with a mov instruction. */
6909 inst.instruction &= LITERAL_MASK;
6910 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6911 inst.instruction |= value & 0xfff;
6912 return TRUE;
6913 }
6914
6915 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6916 if (value != FAIL)
6917 {
6918 /* This can be done with a mvn instruction. */
6919 inst.instruction &= LITERAL_MASK;
6920 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6921 inst.instruction |= value & 0xfff;
6922 return TRUE;
6923 }
6924 }
6925 }
6926
6927 if (add_to_lit_pool () == FAIL)
6928 {
6929 inst.error = _("literal pool insertion failed");
6930 return TRUE;
6931 }
6932 inst.operands[1].reg = REG_PC;
6933 inst.operands[1].isreg = 1;
6934 inst.operands[1].preind = 1;
6935 inst.reloc.pc_rel = 1;
6936 inst.reloc.type = (thumb_p
6937 ? BFD_RELOC_ARM_THUMB_OFFSET
6938 : (mode_3
6939 ? BFD_RELOC_ARM_HWLITERAL
6940 : BFD_RELOC_ARM_LITERAL));
6941 return FALSE;
6942 }
6943
6944 /* Functions for instruction encoding, sorted by sub-architecture.
6945 First some generics; their names are taken from the conventional
6946 bit positions for register arguments in ARM format instructions. */
6947
6948 static void
6949 do_noargs (void)
6950 {
6951 }
6952
6953 static void
6954 do_rd (void)
6955 {
6956 inst.instruction |= inst.operands[0].reg << 12;
6957 }
6958
6959 static void
6960 do_rd_rm (void)
6961 {
6962 inst.instruction |= inst.operands[0].reg << 12;
6963 inst.instruction |= inst.operands[1].reg;
6964 }
6965
6966 static void
6967 do_rd_rn (void)
6968 {
6969 inst.instruction |= inst.operands[0].reg << 12;
6970 inst.instruction |= inst.operands[1].reg << 16;
6971 }
6972
6973 static void
6974 do_rn_rd (void)
6975 {
6976 inst.instruction |= inst.operands[0].reg << 16;
6977 inst.instruction |= inst.operands[1].reg << 12;
6978 }
6979
6980 static void
6981 do_rd_rm_rn (void)
6982 {
6983 unsigned Rn = inst.operands[2].reg;
6984 /* Enforce restrictions on SWP instruction. */
6985 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6986 {
6987 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6988 _("Rn must not overlap other operands"));
6989
6990 /* SWP{b} is deprecated for ARMv6* and ARMv7. */
6991 if (warn_on_deprecated
6992 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
6993 as_warn (_("swp{b} use is deprecated for this architecture"));
6994
6995 }
6996 inst.instruction |= inst.operands[0].reg << 12;
6997 inst.instruction |= inst.operands[1].reg;
6998 inst.instruction |= Rn << 16;
6999 }
7000
7001 static void
7002 do_rd_rn_rm (void)
7003 {
7004 inst.instruction |= inst.operands[0].reg << 12;
7005 inst.instruction |= inst.operands[1].reg << 16;
7006 inst.instruction |= inst.operands[2].reg;
7007 }
7008
7009 static void
7010 do_rm_rd_rn (void)
7011 {
7012 constraint ((inst.operands[2].reg == REG_PC), BAD_PC);
7013 constraint (((inst.reloc.exp.X_op != O_constant
7014 && inst.reloc.exp.X_op != O_illegal)
7015 || inst.reloc.exp.X_add_number != 0),
7016 BAD_ADDR_MODE);
7017 inst.instruction |= inst.operands[0].reg;
7018 inst.instruction |= inst.operands[1].reg << 12;
7019 inst.instruction |= inst.operands[2].reg << 16;
7020 }
7021
7022 static void
7023 do_imm0 (void)
7024 {
7025 inst.instruction |= inst.operands[0].imm;
7026 }
7027
7028 static void
7029 do_rd_cpaddr (void)
7030 {
7031 inst.instruction |= inst.operands[0].reg << 12;
7032 encode_arm_cp_address (1, TRUE, TRUE, 0);
7033 }
7034
7035 /* ARM instructions, in alphabetical order by function name (except
7036 that wrapper functions appear immediately after the function they
7037 wrap). */
7038
7039 /* This is a pseudo-op of the form "adr rd, label" to be converted
7040 into a relative address of the form "add rd, pc, #label-.-8". */
7041
7042 static void
7043 do_adr (void)
7044 {
7045 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7046
7047 /* Frag hacking will turn this into a sub instruction if the offset turns
7048 out to be negative. */
7049 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7050 inst.reloc.pc_rel = 1;
7051 inst.reloc.exp.X_add_number -= 8;
7052 }
7053
7054 /* This is a pseudo-op of the form "adrl rd, label" to be converted
7055 into a relative address of the form:
7056 add rd, pc, #low(label-.-8)"
7057 add rd, rd, #high(label-.-8)" */
7058
7059 static void
7060 do_adrl (void)
7061 {
7062 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
7063
7064 /* Frag hacking will turn this into a sub instruction if the offset turns
7065 out to be negative. */
7066 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
7067 inst.reloc.pc_rel = 1;
7068 inst.size = INSN_SIZE * 2;
7069 inst.reloc.exp.X_add_number -= 8;
7070 }
7071
7072 static void
7073 do_arit (void)
7074 {
7075 if (!inst.operands[1].present)
7076 inst.operands[1].reg = inst.operands[0].reg;
7077 inst.instruction |= inst.operands[0].reg << 12;
7078 inst.instruction |= inst.operands[1].reg << 16;
7079 encode_arm_shifter_operand (2);
7080 }
7081
7082 static void
7083 do_barrier (void)
7084 {
7085 if (inst.operands[0].present)
7086 {
7087 constraint ((inst.instruction & 0xf0) != 0x40
7088 && inst.operands[0].imm != 0xf,
7089 _("bad barrier type"));
7090 inst.instruction |= inst.operands[0].imm;
7091 }
7092 else
7093 inst.instruction |= 0xf;
7094 }
7095
7096 static void
7097 do_bfc (void)
7098 {
7099 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7100 constraint (msb > 32, _("bit-field extends past end of register"));
7101 /* The instruction encoding stores the LSB and MSB,
7102 not the LSB and width. */
7103 inst.instruction |= inst.operands[0].reg << 12;
7104 inst.instruction |= inst.operands[1].imm << 7;
7105 inst.instruction |= (msb - 1) << 16;
7106 }
7107
7108 static void
7109 do_bfi (void)
7110 {
7111 unsigned int msb;
7112
7113 /* #0 in second position is alternative syntax for bfc, which is
7114 the same instruction but with REG_PC in the Rm field. */
7115 if (!inst.operands[1].isreg)
7116 inst.operands[1].reg = REG_PC;
7117
7118 msb = inst.operands[2].imm + inst.operands[3].imm;
7119 constraint (msb > 32, _("bit-field extends past end of register"));
7120 /* The instruction encoding stores the LSB and MSB,
7121 not the LSB and width. */
7122 inst.instruction |= inst.operands[0].reg << 12;
7123 inst.instruction |= inst.operands[1].reg;
7124 inst.instruction |= inst.operands[2].imm << 7;
7125 inst.instruction |= (msb - 1) << 16;
7126 }
7127
7128 static void
7129 do_bfx (void)
7130 {
7131 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7132 _("bit-field extends past end of register"));
7133 inst.instruction |= inst.operands[0].reg << 12;
7134 inst.instruction |= inst.operands[1].reg;
7135 inst.instruction |= inst.operands[2].imm << 7;
7136 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7137 }
7138
7139 /* ARM V5 breakpoint instruction (argument parse)
7140 BKPT <16 bit unsigned immediate>
7141 Instruction is not conditional.
7142 The bit pattern given in insns[] has the COND_ALWAYS condition,
7143 and it is an error if the caller tried to override that. */
7144
7145 static void
7146 do_bkpt (void)
7147 {
7148 /* Top 12 of 16 bits to bits 19:8. */
7149 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
7150
7151 /* Bottom 4 of 16 bits to bits 3:0. */
7152 inst.instruction |= inst.operands[0].imm & 0xf;
7153 }
7154
7155 static void
7156 encode_branch (int default_reloc)
7157 {
7158 if (inst.operands[0].hasreloc)
7159 {
7160 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7161 _("the only suffix valid here is '(plt)'"));
7162 inst.reloc.type = BFD_RELOC_ARM_PLT32;
7163 }
7164 else
7165 {
7166 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
7167 }
7168 inst.reloc.pc_rel = 1;
7169 }
7170
7171 static void
7172 do_branch (void)
7173 {
7174 #ifdef OBJ_ELF
7175 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7176 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7177 else
7178 #endif
7179 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7180 }
7181
7182 static void
7183 do_bl (void)
7184 {
7185 #ifdef OBJ_ELF
7186 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7187 {
7188 if (inst.cond == COND_ALWAYS)
7189 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7190 else
7191 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7192 }
7193 else
7194 #endif
7195 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7196 }
7197
7198 /* ARM V5 branch-link-exchange instruction (argument parse)
7199 BLX <target_addr> ie BLX(1)
7200 BLX{<condition>} <Rm> ie BLX(2)
7201 Unfortunately, there are two different opcodes for this mnemonic.
7202 So, the insns[].value is not used, and the code here zaps values
7203 into inst.instruction.
7204 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
7205
7206 static void
7207 do_blx (void)
7208 {
7209 if (inst.operands[0].isreg)
7210 {
7211 /* Arg is a register; the opcode provided by insns[] is correct.
7212 It is not illegal to do "blx pc", just useless. */
7213 if (inst.operands[0].reg == REG_PC)
7214 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
7215
7216 inst.instruction |= inst.operands[0].reg;
7217 }
7218 else
7219 {
7220 /* Arg is an address; this instruction cannot be executed
7221 conditionally, and the opcode must be adjusted.
7222 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7223 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
7224 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7225 inst.instruction = 0xfa000000;
7226 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
7227 }
7228 }
7229
7230 static void
7231 do_bx (void)
7232 {
7233 bfd_boolean want_reloc;
7234
7235 if (inst.operands[0].reg == REG_PC)
7236 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
7237
7238 inst.instruction |= inst.operands[0].reg;
7239 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7240 it is for ARMv4t or earlier. */
7241 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7242 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7243 want_reloc = TRUE;
7244
7245 #ifdef OBJ_ELF
7246 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
7247 #endif
7248 want_reloc = FALSE;
7249
7250 if (want_reloc)
7251 inst.reloc.type = BFD_RELOC_ARM_V4BX;
7252 }
7253
7254
7255 /* ARM v5TEJ. Jump to Jazelle code. */
7256
7257 static void
7258 do_bxj (void)
7259 {
7260 if (inst.operands[0].reg == REG_PC)
7261 as_tsktsk (_("use of r15 in bxj is not really useful"));
7262
7263 inst.instruction |= inst.operands[0].reg;
7264 }
7265
7266 /* Co-processor data operation:
7267 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7268 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7269 static void
7270 do_cdp (void)
7271 {
7272 inst.instruction |= inst.operands[0].reg << 8;
7273 inst.instruction |= inst.operands[1].imm << 20;
7274 inst.instruction |= inst.operands[2].reg << 12;
7275 inst.instruction |= inst.operands[3].reg << 16;
7276 inst.instruction |= inst.operands[4].reg;
7277 inst.instruction |= inst.operands[5].imm << 5;
7278 }
7279
7280 static void
7281 do_cmp (void)
7282 {
7283 inst.instruction |= inst.operands[0].reg << 16;
7284 encode_arm_shifter_operand (1);
7285 }
7286
7287 /* Transfer between coprocessor and ARM registers.
7288 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7289 MRC2
7290 MCR{cond}
7291 MCR2
7292
7293 No special properties. */
7294
7295 static void
7296 do_co_reg (void)
7297 {
7298 unsigned Rd;
7299
7300 Rd = inst.operands[2].reg;
7301 if (thumb_mode)
7302 {
7303 if (inst.instruction == 0xee000010
7304 || inst.instruction == 0xfe000010)
7305 /* MCR, MCR2 */
7306 reject_bad_reg (Rd);
7307 else
7308 /* MRC, MRC2 */
7309 constraint (Rd == REG_SP, BAD_SP);
7310 }
7311 else
7312 {
7313 /* MCR */
7314 if (inst.instruction == 0xe000010)
7315 constraint (Rd == REG_PC, BAD_PC);
7316 }
7317
7318
7319 inst.instruction |= inst.operands[0].reg << 8;
7320 inst.instruction |= inst.operands[1].imm << 21;
7321 inst.instruction |= Rd << 12;
7322 inst.instruction |= inst.operands[3].reg << 16;
7323 inst.instruction |= inst.operands[4].reg;
7324 inst.instruction |= inst.operands[5].imm << 5;
7325 }
7326
7327 /* Transfer between coprocessor register and pair of ARM registers.
7328 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7329 MCRR2
7330 MRRC{cond}
7331 MRRC2
7332
7333 Two XScale instructions are special cases of these:
7334
7335 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7336 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
7337
7338 Result unpredictable if Rd or Rn is R15. */
7339
7340 static void
7341 do_co_reg2c (void)
7342 {
7343 unsigned Rd, Rn;
7344
7345 Rd = inst.operands[2].reg;
7346 Rn = inst.operands[3].reg;
7347
7348 if (thumb_mode)
7349 {
7350 reject_bad_reg (Rd);
7351 reject_bad_reg (Rn);
7352 }
7353 else
7354 {
7355 constraint (Rd == REG_PC, BAD_PC);
7356 constraint (Rn == REG_PC, BAD_PC);
7357 }
7358
7359 inst.instruction |= inst.operands[0].reg << 8;
7360 inst.instruction |= inst.operands[1].imm << 4;
7361 inst.instruction |= Rd << 12;
7362 inst.instruction |= Rn << 16;
7363 inst.instruction |= inst.operands[4].reg;
7364 }
7365
7366 static void
7367 do_cpsi (void)
7368 {
7369 inst.instruction |= inst.operands[0].imm << 6;
7370 if (inst.operands[1].present)
7371 {
7372 inst.instruction |= CPSI_MMOD;
7373 inst.instruction |= inst.operands[1].imm;
7374 }
7375 }
7376
7377 static void
7378 do_dbg (void)
7379 {
7380 inst.instruction |= inst.operands[0].imm;
7381 }
7382
7383 static void
7384 do_it (void)
7385 {
7386 /* There is no IT instruction in ARM mode. We
7387 process it to do the validation as if in
7388 thumb mode, just in case the code gets
7389 assembled for thumb using the unified syntax. */
7390
7391 inst.size = 0;
7392 if (unified_syntax)
7393 {
7394 set_it_insn_type (IT_INSN);
7395 now_it.mask = (inst.instruction & 0xf) | 0x10;
7396 now_it.cc = inst.operands[0].imm;
7397 }
7398 }
7399
7400 static void
7401 do_ldmstm (void)
7402 {
7403 int base_reg = inst.operands[0].reg;
7404 int range = inst.operands[1].imm;
7405
7406 inst.instruction |= base_reg << 16;
7407 inst.instruction |= range;
7408
7409 if (inst.operands[1].writeback)
7410 inst.instruction |= LDM_TYPE_2_OR_3;
7411
7412 if (inst.operands[0].writeback)
7413 {
7414 inst.instruction |= WRITE_BACK;
7415 /* Check for unpredictable uses of writeback. */
7416 if (inst.instruction & LOAD_BIT)
7417 {
7418 /* Not allowed in LDM type 2. */
7419 if ((inst.instruction & LDM_TYPE_2_OR_3)
7420 && ((range & (1 << REG_PC)) == 0))
7421 as_warn (_("writeback of base register is UNPREDICTABLE"));
7422 /* Only allowed if base reg not in list for other types. */
7423 else if (range & (1 << base_reg))
7424 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7425 }
7426 else /* STM. */
7427 {
7428 /* Not allowed for type 2. */
7429 if (inst.instruction & LDM_TYPE_2_OR_3)
7430 as_warn (_("writeback of base register is UNPREDICTABLE"));
7431 /* Only allowed if base reg not in list, or first in list. */
7432 else if ((range & (1 << base_reg))
7433 && (range & ((1 << base_reg) - 1)))
7434 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
7435 }
7436 }
7437 }
7438
7439 /* ARMv5TE load-consecutive (argument parse)
7440 Mode is like LDRH.
7441
7442 LDRccD R, mode
7443 STRccD R, mode. */
7444
7445 static void
7446 do_ldrd (void)
7447 {
7448 constraint (inst.operands[0].reg % 2 != 0,
7449 _("first destination register must be even"));
7450 constraint (inst.operands[1].present
7451 && inst.operands[1].reg != inst.operands[0].reg + 1,
7452 _("can only load two consecutive registers"));
7453 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7454 constraint (!inst.operands[2].isreg, _("'[' expected"));
7455
7456 if (!inst.operands[1].present)
7457 inst.operands[1].reg = inst.operands[0].reg + 1;
7458
7459 if (inst.instruction & LOAD_BIT)
7460 {
7461 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7462 register and the first register written; we have to diagnose
7463 overlap between the base and the second register written here. */
7464
7465 if (inst.operands[2].reg == inst.operands[1].reg
7466 && (inst.operands[2].writeback || inst.operands[2].postind))
7467 as_warn (_("base register written back, and overlaps "
7468 "second destination register"));
7469
7470 /* For an index-register load, the index register must not overlap the
7471 destination (even if not write-back). */
7472 else if (inst.operands[2].immisreg
7473 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7474 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7475 as_warn (_("index register overlaps destination register"));
7476 }
7477
7478 inst.instruction |= inst.operands[0].reg << 12;
7479 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7480 }
7481
7482 static void
7483 do_ldrex (void)
7484 {
7485 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7486 || inst.operands[1].postind || inst.operands[1].writeback
7487 || inst.operands[1].immisreg || inst.operands[1].shifted
7488 || inst.operands[1].negative
7489 /* This can arise if the programmer has written
7490 strex rN, rM, foo
7491 or if they have mistakenly used a register name as the last
7492 operand, eg:
7493 strex rN, rM, rX
7494 It is very difficult to distinguish between these two cases
7495 because "rX" might actually be a label. ie the register
7496 name has been occluded by a symbol of the same name. So we
7497 just generate a general 'bad addressing mode' type error
7498 message and leave it up to the programmer to discover the
7499 true cause and fix their mistake. */
7500 || (inst.operands[1].reg == REG_PC),
7501 BAD_ADDR_MODE);
7502
7503 constraint (inst.reloc.exp.X_op != O_constant
7504 || inst.reloc.exp.X_add_number != 0,
7505 _("offset must be zero in ARM encoding"));
7506
7507 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
7508
7509 inst.instruction |= inst.operands[0].reg << 12;
7510 inst.instruction |= inst.operands[1].reg << 16;
7511 inst.reloc.type = BFD_RELOC_UNUSED;
7512 }
7513
7514 static void
7515 do_ldrexd (void)
7516 {
7517 constraint (inst.operands[0].reg % 2 != 0,
7518 _("even register required"));
7519 constraint (inst.operands[1].present
7520 && inst.operands[1].reg != inst.operands[0].reg + 1,
7521 _("can only load two consecutive registers"));
7522 /* If op 1 were present and equal to PC, this function wouldn't
7523 have been called in the first place. */
7524 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7525
7526 inst.instruction |= inst.operands[0].reg << 12;
7527 inst.instruction |= inst.operands[2].reg << 16;
7528 }
7529
7530 static void
7531 do_ldst (void)
7532 {
7533 inst.instruction |= inst.operands[0].reg << 12;
7534 if (!inst.operands[1].isreg)
7535 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
7536 return;
7537 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7538 }
7539
7540 static void
7541 do_ldstt (void)
7542 {
7543 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7544 reject [Rn,...]. */
7545 if (inst.operands[1].preind)
7546 {
7547 constraint (inst.reloc.exp.X_op != O_constant
7548 || inst.reloc.exp.X_add_number != 0,
7549 _("this instruction requires a post-indexed address"));
7550
7551 inst.operands[1].preind = 0;
7552 inst.operands[1].postind = 1;
7553 inst.operands[1].writeback = 1;
7554 }
7555 inst.instruction |= inst.operands[0].reg << 12;
7556 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7557 }
7558
7559 /* Halfword and signed-byte load/store operations. */
7560
7561 static void
7562 do_ldstv4 (void)
7563 {
7564 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7565 inst.instruction |= inst.operands[0].reg << 12;
7566 if (!inst.operands[1].isreg)
7567 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
7568 return;
7569 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7570 }
7571
7572 static void
7573 do_ldsttv4 (void)
7574 {
7575 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7576 reject [Rn,...]. */
7577 if (inst.operands[1].preind)
7578 {
7579 constraint (inst.reloc.exp.X_op != O_constant
7580 || inst.reloc.exp.X_add_number != 0,
7581 _("this instruction requires a post-indexed address"));
7582
7583 inst.operands[1].preind = 0;
7584 inst.operands[1].postind = 1;
7585 inst.operands[1].writeback = 1;
7586 }
7587 inst.instruction |= inst.operands[0].reg << 12;
7588 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7589 }
7590
7591 /* Co-processor register load/store.
7592 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7593 static void
7594 do_lstc (void)
7595 {
7596 inst.instruction |= inst.operands[0].reg << 8;
7597 inst.instruction |= inst.operands[1].reg << 12;
7598 encode_arm_cp_address (2, TRUE, TRUE, 0);
7599 }
7600
7601 static void
7602 do_mlas (void)
7603 {
7604 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7605 if (inst.operands[0].reg == inst.operands[1].reg
7606 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7607 && !(inst.instruction & 0x00400000))
7608 as_tsktsk (_("Rd and Rm should be different in mla"));
7609
7610 inst.instruction |= inst.operands[0].reg << 16;
7611 inst.instruction |= inst.operands[1].reg;
7612 inst.instruction |= inst.operands[2].reg << 8;
7613 inst.instruction |= inst.operands[3].reg << 12;
7614 }
7615
7616 static void
7617 do_mov (void)
7618 {
7619 inst.instruction |= inst.operands[0].reg << 12;
7620 encode_arm_shifter_operand (1);
7621 }
7622
7623 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7624 static void
7625 do_mov16 (void)
7626 {
7627 bfd_vma imm;
7628 bfd_boolean top;
7629
7630 top = (inst.instruction & 0x00400000) != 0;
7631 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7632 _(":lower16: not allowed this instruction"));
7633 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7634 _(":upper16: not allowed instruction"));
7635 inst.instruction |= inst.operands[0].reg << 12;
7636 if (inst.reloc.type == BFD_RELOC_UNUSED)
7637 {
7638 imm = inst.reloc.exp.X_add_number;
7639 /* The value is in two pieces: 0:11, 16:19. */
7640 inst.instruction |= (imm & 0x00000fff);
7641 inst.instruction |= (imm & 0x0000f000) << 4;
7642 }
7643 }
7644
7645 static void do_vfp_nsyn_opcode (const char *);
7646
7647 static int
7648 do_vfp_nsyn_mrs (void)
7649 {
7650 if (inst.operands[0].isvec)
7651 {
7652 if (inst.operands[1].reg != 1)
7653 first_error (_("operand 1 must be FPSCR"));
7654 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7655 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7656 do_vfp_nsyn_opcode ("fmstat");
7657 }
7658 else if (inst.operands[1].isvec)
7659 do_vfp_nsyn_opcode ("fmrx");
7660 else
7661 return FAIL;
7662
7663 return SUCCESS;
7664 }
7665
7666 static int
7667 do_vfp_nsyn_msr (void)
7668 {
7669 if (inst.operands[0].isvec)
7670 do_vfp_nsyn_opcode ("fmxr");
7671 else
7672 return FAIL;
7673
7674 return SUCCESS;
7675 }
7676
7677 static void
7678 do_vmrs (void)
7679 {
7680 unsigned Rt = inst.operands[0].reg;
7681
7682 if (thumb_mode && inst.operands[0].reg == REG_SP)
7683 {
7684 inst.error = BAD_SP;
7685 return;
7686 }
7687
7688 /* APSR_ sets isvec. All other refs to PC are illegal. */
7689 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7690 {
7691 inst.error = BAD_PC;
7692 return;
7693 }
7694
7695 if (inst.operands[1].reg != 1)
7696 first_error (_("operand 1 must be FPSCR"));
7697
7698 inst.instruction |= (Rt << 12);
7699 }
7700
7701 static void
7702 do_vmsr (void)
7703 {
7704 unsigned Rt = inst.operands[1].reg;
7705
7706 if (thumb_mode)
7707 reject_bad_reg (Rt);
7708 else if (Rt == REG_PC)
7709 {
7710 inst.error = BAD_PC;
7711 return;
7712 }
7713
7714 if (inst.operands[0].reg != 1)
7715 first_error (_("operand 0 must be FPSCR"));
7716
7717 inst.instruction |= (Rt << 12);
7718 }
7719
7720 static void
7721 do_mrs (void)
7722 {
7723 if (do_vfp_nsyn_mrs () == SUCCESS)
7724 return;
7725
7726 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7727 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7728 != (PSR_c|PSR_f),
7729 _("'CPSR' or 'SPSR' expected"));
7730 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
7731 inst.instruction |= inst.operands[0].reg << 12;
7732 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7733 }
7734
7735 /* Two possible forms:
7736 "{C|S}PSR_<field>, Rm",
7737 "{C|S}PSR_f, #expression". */
7738
7739 static void
7740 do_msr (void)
7741 {
7742 if (do_vfp_nsyn_msr () == SUCCESS)
7743 return;
7744
7745 inst.instruction |= inst.operands[0].imm;
7746 if (inst.operands[1].isreg)
7747 inst.instruction |= inst.operands[1].reg;
7748 else
7749 {
7750 inst.instruction |= INST_IMMEDIATE;
7751 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7752 inst.reloc.pc_rel = 0;
7753 }
7754 }
7755
7756 static void
7757 do_mul (void)
7758 {
7759 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
7760
7761 if (!inst.operands[2].present)
7762 inst.operands[2].reg = inst.operands[0].reg;
7763 inst.instruction |= inst.operands[0].reg << 16;
7764 inst.instruction |= inst.operands[1].reg;
7765 inst.instruction |= inst.operands[2].reg << 8;
7766
7767 if (inst.operands[0].reg == inst.operands[1].reg
7768 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7769 as_tsktsk (_("Rd and Rm should be different in mul"));
7770 }
7771
7772 /* Long Multiply Parser
7773 UMULL RdLo, RdHi, Rm, Rs
7774 SMULL RdLo, RdHi, Rm, Rs
7775 UMLAL RdLo, RdHi, Rm, Rs
7776 SMLAL RdLo, RdHi, Rm, Rs. */
7777
7778 static void
7779 do_mull (void)
7780 {
7781 inst.instruction |= inst.operands[0].reg << 12;
7782 inst.instruction |= inst.operands[1].reg << 16;
7783 inst.instruction |= inst.operands[2].reg;
7784 inst.instruction |= inst.operands[3].reg << 8;
7785
7786 /* rdhi and rdlo must be different. */
7787 if (inst.operands[0].reg == inst.operands[1].reg)
7788 as_tsktsk (_("rdhi and rdlo must be different"));
7789
7790 /* rdhi, rdlo and rm must all be different before armv6. */
7791 if ((inst.operands[0].reg == inst.operands[2].reg
7792 || inst.operands[1].reg == inst.operands[2].reg)
7793 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7794 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7795 }
7796
7797 static void
7798 do_nop (void)
7799 {
7800 if (inst.operands[0].present
7801 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
7802 {
7803 /* Architectural NOP hints are CPSR sets with no bits selected. */
7804 inst.instruction &= 0xf0000000;
7805 inst.instruction |= 0x0320f000;
7806 if (inst.operands[0].present)
7807 inst.instruction |= inst.operands[0].imm;
7808 }
7809 }
7810
7811 /* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7812 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7813 Condition defaults to COND_ALWAYS.
7814 Error if Rd, Rn or Rm are R15. */
7815
7816 static void
7817 do_pkhbt (void)
7818 {
7819 inst.instruction |= inst.operands[0].reg << 12;
7820 inst.instruction |= inst.operands[1].reg << 16;
7821 inst.instruction |= inst.operands[2].reg;
7822 if (inst.operands[3].present)
7823 encode_arm_shift (3);
7824 }
7825
7826 /* ARM V6 PKHTB (Argument Parse). */
7827
7828 static void
7829 do_pkhtb (void)
7830 {
7831 if (!inst.operands[3].present)
7832 {
7833 /* If the shift specifier is omitted, turn the instruction
7834 into pkhbt rd, rm, rn. */
7835 inst.instruction &= 0xfff00010;
7836 inst.instruction |= inst.operands[0].reg << 12;
7837 inst.instruction |= inst.operands[1].reg;
7838 inst.instruction |= inst.operands[2].reg << 16;
7839 }
7840 else
7841 {
7842 inst.instruction |= inst.operands[0].reg << 12;
7843 inst.instruction |= inst.operands[1].reg << 16;
7844 inst.instruction |= inst.operands[2].reg;
7845 encode_arm_shift (3);
7846 }
7847 }
7848
7849 /* ARMv5TE: Preload-Cache
7850
7851 PLD <addr_mode>
7852
7853 Syntactically, like LDR with B=1, W=0, L=1. */
7854
7855 static void
7856 do_pld (void)
7857 {
7858 constraint (!inst.operands[0].isreg,
7859 _("'[' expected after PLD mnemonic"));
7860 constraint (inst.operands[0].postind,
7861 _("post-indexed expression used in preload instruction"));
7862 constraint (inst.operands[0].writeback,
7863 _("writeback used in preload instruction"));
7864 constraint (!inst.operands[0].preind,
7865 _("unindexed addressing used in preload instruction"));
7866 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7867 }
7868
7869 /* ARMv7: PLI <addr_mode> */
7870 static void
7871 do_pli (void)
7872 {
7873 constraint (!inst.operands[0].isreg,
7874 _("'[' expected after PLI mnemonic"));
7875 constraint (inst.operands[0].postind,
7876 _("post-indexed expression used in preload instruction"));
7877 constraint (inst.operands[0].writeback,
7878 _("writeback used in preload instruction"));
7879 constraint (!inst.operands[0].preind,
7880 _("unindexed addressing used in preload instruction"));
7881 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7882 inst.instruction &= ~PRE_INDEX;
7883 }
7884
7885 static void
7886 do_push_pop (void)
7887 {
7888 inst.operands[1] = inst.operands[0];
7889 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7890 inst.operands[0].isreg = 1;
7891 inst.operands[0].writeback = 1;
7892 inst.operands[0].reg = REG_SP;
7893 do_ldmstm ();
7894 }
7895
7896 /* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7897 word at the specified address and the following word
7898 respectively.
7899 Unconditionally executed.
7900 Error if Rn is R15. */
7901
7902 static void
7903 do_rfe (void)
7904 {
7905 inst.instruction |= inst.operands[0].reg << 16;
7906 if (inst.operands[0].writeback)
7907 inst.instruction |= WRITE_BACK;
7908 }
7909
7910 /* ARM V6 ssat (argument parse). */
7911
7912 static void
7913 do_ssat (void)
7914 {
7915 inst.instruction |= inst.operands[0].reg << 12;
7916 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7917 inst.instruction |= inst.operands[2].reg;
7918
7919 if (inst.operands[3].present)
7920 encode_arm_shift (3);
7921 }
7922
7923 /* ARM V6 usat (argument parse). */
7924
7925 static void
7926 do_usat (void)
7927 {
7928 inst.instruction |= inst.operands[0].reg << 12;
7929 inst.instruction |= inst.operands[1].imm << 16;
7930 inst.instruction |= inst.operands[2].reg;
7931
7932 if (inst.operands[3].present)
7933 encode_arm_shift (3);
7934 }
7935
7936 /* ARM V6 ssat16 (argument parse). */
7937
7938 static void
7939 do_ssat16 (void)
7940 {
7941 inst.instruction |= inst.operands[0].reg << 12;
7942 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7943 inst.instruction |= inst.operands[2].reg;
7944 }
7945
7946 static void
7947 do_usat16 (void)
7948 {
7949 inst.instruction |= inst.operands[0].reg << 12;
7950 inst.instruction |= inst.operands[1].imm << 16;
7951 inst.instruction |= inst.operands[2].reg;
7952 }
7953
7954 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7955 preserving the other bits.
7956
7957 setend <endian_specifier>, where <endian_specifier> is either
7958 BE or LE. */
7959
7960 static void
7961 do_setend (void)
7962 {
7963 if (inst.operands[0].imm)
7964 inst.instruction |= 0x200;
7965 }
7966
7967 static void
7968 do_shift (void)
7969 {
7970 unsigned int Rm = (inst.operands[1].present
7971 ? inst.operands[1].reg
7972 : inst.operands[0].reg);
7973
7974 inst.instruction |= inst.operands[0].reg << 12;
7975 inst.instruction |= Rm;
7976 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7977 {
7978 inst.instruction |= inst.operands[2].reg << 8;
7979 inst.instruction |= SHIFT_BY_REG;
7980 }
7981 else
7982 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7983 }
7984
7985 static void
7986 do_smc (void)
7987 {
7988 inst.reloc.type = BFD_RELOC_ARM_SMC;
7989 inst.reloc.pc_rel = 0;
7990 }
7991
7992 static void
7993 do_swi (void)
7994 {
7995 inst.reloc.type = BFD_RELOC_ARM_SWI;
7996 inst.reloc.pc_rel = 0;
7997 }
7998
7999 /* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
8000 SMLAxy{cond} Rd,Rm,Rs,Rn
8001 SMLAWy{cond} Rd,Rm,Rs,Rn
8002 Error if any register is R15. */
8003
8004 static void
8005 do_smla (void)
8006 {
8007 inst.instruction |= inst.operands[0].reg << 16;
8008 inst.instruction |= inst.operands[1].reg;
8009 inst.instruction |= inst.operands[2].reg << 8;
8010 inst.instruction |= inst.operands[3].reg << 12;
8011 }
8012
8013 /* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
8014 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
8015 Error if any register is R15.
8016 Warning if Rdlo == Rdhi. */
8017
8018 static void
8019 do_smlal (void)
8020 {
8021 inst.instruction |= inst.operands[0].reg << 12;
8022 inst.instruction |= inst.operands[1].reg << 16;
8023 inst.instruction |= inst.operands[2].reg;
8024 inst.instruction |= inst.operands[3].reg << 8;
8025
8026 if (inst.operands[0].reg == inst.operands[1].reg)
8027 as_tsktsk (_("rdhi and rdlo must be different"));
8028 }
8029
8030 /* ARM V5E (El Segundo) signed-multiply (argument parse)
8031 SMULxy{cond} Rd,Rm,Rs
8032 Error if any register is R15. */
8033
8034 static void
8035 do_smul (void)
8036 {
8037 inst.instruction |= inst.operands[0].reg << 16;
8038 inst.instruction |= inst.operands[1].reg;
8039 inst.instruction |= inst.operands[2].reg << 8;
8040 }
8041
8042 /* ARM V6 srs (argument parse). The variable fields in the encoding are
8043 the same for both ARM and Thumb-2. */
8044
8045 static void
8046 do_srs (void)
8047 {
8048 int reg;
8049
8050 if (inst.operands[0].present)
8051 {
8052 reg = inst.operands[0].reg;
8053 constraint (reg != REG_SP, _("SRS base register must be r13"));
8054 }
8055 else
8056 reg = REG_SP;
8057
8058 inst.instruction |= reg << 16;
8059 inst.instruction |= inst.operands[1].imm;
8060 if (inst.operands[0].writeback || inst.operands[1].writeback)
8061 inst.instruction |= WRITE_BACK;
8062 }
8063
8064 /* ARM V6 strex (argument parse). */
8065
8066 static void
8067 do_strex (void)
8068 {
8069 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8070 || inst.operands[2].postind || inst.operands[2].writeback
8071 || inst.operands[2].immisreg || inst.operands[2].shifted
8072 || inst.operands[2].negative
8073 /* See comment in do_ldrex(). */
8074 || (inst.operands[2].reg == REG_PC),
8075 BAD_ADDR_MODE);
8076
8077 constraint (inst.operands[0].reg == inst.operands[1].reg
8078 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
8079
8080 constraint (inst.reloc.exp.X_op != O_constant
8081 || inst.reloc.exp.X_add_number != 0,
8082 _("offset must be zero in ARM encoding"));
8083
8084 inst.instruction |= inst.operands[0].reg << 12;
8085 inst.instruction |= inst.operands[1].reg;
8086 inst.instruction |= inst.operands[2].reg << 16;
8087 inst.reloc.type = BFD_RELOC_UNUSED;
8088 }
8089
8090 static void
8091 do_strexd (void)
8092 {
8093 constraint (inst.operands[1].reg % 2 != 0,
8094 _("even register required"));
8095 constraint (inst.operands[2].present
8096 && inst.operands[2].reg != inst.operands[1].reg + 1,
8097 _("can only store two consecutive registers"));
8098 /* If op 2 were present and equal to PC, this function wouldn't
8099 have been called in the first place. */
8100 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
8101
8102 constraint (inst.operands[0].reg == inst.operands[1].reg
8103 || inst.operands[0].reg == inst.operands[1].reg + 1
8104 || inst.operands[0].reg == inst.operands[3].reg,
8105 BAD_OVERLAP);
8106
8107 inst.instruction |= inst.operands[0].reg << 12;
8108 inst.instruction |= inst.operands[1].reg;
8109 inst.instruction |= inst.operands[3].reg << 16;
8110 }
8111
8112 /* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8113 extends it to 32-bits, and adds the result to a value in another
8114 register. You can specify a rotation by 0, 8, 16, or 24 bits
8115 before extracting the 16-bit value.
8116 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8117 Condition defaults to COND_ALWAYS.
8118 Error if any register uses R15. */
8119
8120 static void
8121 do_sxtah (void)
8122 {
8123 inst.instruction |= inst.operands[0].reg << 12;
8124 inst.instruction |= inst.operands[1].reg << 16;
8125 inst.instruction |= inst.operands[2].reg;
8126 inst.instruction |= inst.operands[3].imm << 10;
8127 }
8128
8129 /* ARM V6 SXTH.
8130
8131 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8132 Condition defaults to COND_ALWAYS.
8133 Error if any register uses R15. */
8134
8135 static void
8136 do_sxth (void)
8137 {
8138 inst.instruction |= inst.operands[0].reg << 12;
8139 inst.instruction |= inst.operands[1].reg;
8140 inst.instruction |= inst.operands[2].imm << 10;
8141 }
8142 \f
8143 /* VFP instructions. In a logical order: SP variant first, monad
8144 before dyad, arithmetic then move then load/store. */
8145
8146 static void
8147 do_vfp_sp_monadic (void)
8148 {
8149 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8150 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8151 }
8152
8153 static void
8154 do_vfp_sp_dyadic (void)
8155 {
8156 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8157 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8158 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8159 }
8160
8161 static void
8162 do_vfp_sp_compare_z (void)
8163 {
8164 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8165 }
8166
8167 static void
8168 do_vfp_dp_sp_cvt (void)
8169 {
8170 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8171 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
8172 }
8173
8174 static void
8175 do_vfp_sp_dp_cvt (void)
8176 {
8177 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8178 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8179 }
8180
8181 static void
8182 do_vfp_reg_from_sp (void)
8183 {
8184 inst.instruction |= inst.operands[0].reg << 12;
8185 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8186 }
8187
8188 static void
8189 do_vfp_reg2_from_sp2 (void)
8190 {
8191 constraint (inst.operands[2].imm != 2,
8192 _("only two consecutive VFP SP registers allowed here"));
8193 inst.instruction |= inst.operands[0].reg << 12;
8194 inst.instruction |= inst.operands[1].reg << 16;
8195 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
8196 }
8197
8198 static void
8199 do_vfp_sp_from_reg (void)
8200 {
8201 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
8202 inst.instruction |= inst.operands[1].reg << 12;
8203 }
8204
8205 static void
8206 do_vfp_sp2_from_reg2 (void)
8207 {
8208 constraint (inst.operands[0].imm != 2,
8209 _("only two consecutive VFP SP registers allowed here"));
8210 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
8211 inst.instruction |= inst.operands[1].reg << 12;
8212 inst.instruction |= inst.operands[2].reg << 16;
8213 }
8214
8215 static void
8216 do_vfp_sp_ldst (void)
8217 {
8218 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8219 encode_arm_cp_address (1, FALSE, TRUE, 0);
8220 }
8221
8222 static void
8223 do_vfp_dp_ldst (void)
8224 {
8225 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8226 encode_arm_cp_address (1, FALSE, TRUE, 0);
8227 }
8228
8229
8230 static void
8231 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
8232 {
8233 if (inst.operands[0].writeback)
8234 inst.instruction |= WRITE_BACK;
8235 else
8236 constraint (ldstm_type != VFP_LDSTMIA,
8237 _("this addressing mode requires base-register writeback"));
8238 inst.instruction |= inst.operands[0].reg << 16;
8239 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
8240 inst.instruction |= inst.operands[1].imm;
8241 }
8242
8243 static void
8244 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
8245 {
8246 int count;
8247
8248 if (inst.operands[0].writeback)
8249 inst.instruction |= WRITE_BACK;
8250 else
8251 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8252 _("this addressing mode requires base-register writeback"));
8253
8254 inst.instruction |= inst.operands[0].reg << 16;
8255 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8256
8257 count = inst.operands[1].imm << 1;
8258 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8259 count += 1;
8260
8261 inst.instruction |= count;
8262 }
8263
8264 static void
8265 do_vfp_sp_ldstmia (void)
8266 {
8267 vfp_sp_ldstm (VFP_LDSTMIA);
8268 }
8269
8270 static void
8271 do_vfp_sp_ldstmdb (void)
8272 {
8273 vfp_sp_ldstm (VFP_LDSTMDB);
8274 }
8275
8276 static void
8277 do_vfp_dp_ldstmia (void)
8278 {
8279 vfp_dp_ldstm (VFP_LDSTMIA);
8280 }
8281
8282 static void
8283 do_vfp_dp_ldstmdb (void)
8284 {
8285 vfp_dp_ldstm (VFP_LDSTMDB);
8286 }
8287
8288 static void
8289 do_vfp_xp_ldstmia (void)
8290 {
8291 vfp_dp_ldstm (VFP_LDSTMIAX);
8292 }
8293
8294 static void
8295 do_vfp_xp_ldstmdb (void)
8296 {
8297 vfp_dp_ldstm (VFP_LDSTMDBX);
8298 }
8299
8300 static void
8301 do_vfp_dp_rd_rm (void)
8302 {
8303 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8304 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8305 }
8306
8307 static void
8308 do_vfp_dp_rn_rd (void)
8309 {
8310 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8311 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8312 }
8313
8314 static void
8315 do_vfp_dp_rd_rn (void)
8316 {
8317 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8318 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8319 }
8320
8321 static void
8322 do_vfp_dp_rd_rn_rm (void)
8323 {
8324 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8325 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8326 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8327 }
8328
8329 static void
8330 do_vfp_dp_rd (void)
8331 {
8332 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8333 }
8334
8335 static void
8336 do_vfp_dp_rm_rd_rn (void)
8337 {
8338 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8339 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8340 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8341 }
8342
8343 /* VFPv3 instructions. */
8344 static void
8345 do_vfp_sp_const (void)
8346 {
8347 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8348 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8349 inst.instruction |= (inst.operands[1].imm & 0x0f);
8350 }
8351
8352 static void
8353 do_vfp_dp_const (void)
8354 {
8355 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8356 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8357 inst.instruction |= (inst.operands[1].imm & 0x0f);
8358 }
8359
8360 static void
8361 vfp_conv (int srcsize)
8362 {
8363 unsigned immbits = srcsize - inst.operands[1].imm;
8364 inst.instruction |= (immbits & 1) << 5;
8365 inst.instruction |= (immbits >> 1);
8366 }
8367
8368 static void
8369 do_vfp_sp_conv_16 (void)
8370 {
8371 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8372 vfp_conv (16);
8373 }
8374
8375 static void
8376 do_vfp_dp_conv_16 (void)
8377 {
8378 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8379 vfp_conv (16);
8380 }
8381
8382 static void
8383 do_vfp_sp_conv_32 (void)
8384 {
8385 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8386 vfp_conv (32);
8387 }
8388
8389 static void
8390 do_vfp_dp_conv_32 (void)
8391 {
8392 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8393 vfp_conv (32);
8394 }
8395 \f
8396 /* FPA instructions. Also in a logical order. */
8397
8398 static void
8399 do_fpa_cmp (void)
8400 {
8401 inst.instruction |= inst.operands[0].reg << 16;
8402 inst.instruction |= inst.operands[1].reg;
8403 }
8404
8405 static void
8406 do_fpa_ldmstm (void)
8407 {
8408 inst.instruction |= inst.operands[0].reg << 12;
8409 switch (inst.operands[1].imm)
8410 {
8411 case 1: inst.instruction |= CP_T_X; break;
8412 case 2: inst.instruction |= CP_T_Y; break;
8413 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8414 case 4: break;
8415 default: abort ();
8416 }
8417
8418 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8419 {
8420 /* The instruction specified "ea" or "fd", so we can only accept
8421 [Rn]{!}. The instruction does not really support stacking or
8422 unstacking, so we have to emulate these by setting appropriate
8423 bits and offsets. */
8424 constraint (inst.reloc.exp.X_op != O_constant
8425 || inst.reloc.exp.X_add_number != 0,
8426 _("this instruction does not support indexing"));
8427
8428 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8429 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
8430
8431 if (!(inst.instruction & INDEX_UP))
8432 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
8433
8434 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8435 {
8436 inst.operands[2].preind = 0;
8437 inst.operands[2].postind = 1;
8438 }
8439 }
8440
8441 encode_arm_cp_address (2, TRUE, TRUE, 0);
8442 }
8443 \f
8444 /* iWMMXt instructions: strictly in alphabetical order. */
8445
8446 static void
8447 do_iwmmxt_tandorc (void)
8448 {
8449 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8450 }
8451
8452 static void
8453 do_iwmmxt_textrc (void)
8454 {
8455 inst.instruction |= inst.operands[0].reg << 12;
8456 inst.instruction |= inst.operands[1].imm;
8457 }
8458
8459 static void
8460 do_iwmmxt_textrm (void)
8461 {
8462 inst.instruction |= inst.operands[0].reg << 12;
8463 inst.instruction |= inst.operands[1].reg << 16;
8464 inst.instruction |= inst.operands[2].imm;
8465 }
8466
8467 static void
8468 do_iwmmxt_tinsr (void)
8469 {
8470 inst.instruction |= inst.operands[0].reg << 16;
8471 inst.instruction |= inst.operands[1].reg << 12;
8472 inst.instruction |= inst.operands[2].imm;
8473 }
8474
8475 static void
8476 do_iwmmxt_tmia (void)
8477 {
8478 inst.instruction |= inst.operands[0].reg << 5;
8479 inst.instruction |= inst.operands[1].reg;
8480 inst.instruction |= inst.operands[2].reg << 12;
8481 }
8482
8483 static void
8484 do_iwmmxt_waligni (void)
8485 {
8486 inst.instruction |= inst.operands[0].reg << 12;
8487 inst.instruction |= inst.operands[1].reg << 16;
8488 inst.instruction |= inst.operands[2].reg;
8489 inst.instruction |= inst.operands[3].imm << 20;
8490 }
8491
8492 static void
8493 do_iwmmxt_wmerge (void)
8494 {
8495 inst.instruction |= inst.operands[0].reg << 12;
8496 inst.instruction |= inst.operands[1].reg << 16;
8497 inst.instruction |= inst.operands[2].reg;
8498 inst.instruction |= inst.operands[3].imm << 21;
8499 }
8500
8501 static void
8502 do_iwmmxt_wmov (void)
8503 {
8504 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8505 inst.instruction |= inst.operands[0].reg << 12;
8506 inst.instruction |= inst.operands[1].reg << 16;
8507 inst.instruction |= inst.operands[1].reg;
8508 }
8509
8510 static void
8511 do_iwmmxt_wldstbh (void)
8512 {
8513 int reloc;
8514 inst.instruction |= inst.operands[0].reg << 12;
8515 if (thumb_mode)
8516 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8517 else
8518 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8519 encode_arm_cp_address (1, TRUE, FALSE, reloc);
8520 }
8521
8522 static void
8523 do_iwmmxt_wldstw (void)
8524 {
8525 /* RIWR_RIWC clears .isreg for a control register. */
8526 if (!inst.operands[0].isreg)
8527 {
8528 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8529 inst.instruction |= 0xf0000000;
8530 }
8531
8532 inst.instruction |= inst.operands[0].reg << 12;
8533 encode_arm_cp_address (1, TRUE, TRUE, 0);
8534 }
8535
8536 static void
8537 do_iwmmxt_wldstd (void)
8538 {
8539 inst.instruction |= inst.operands[0].reg << 12;
8540 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8541 && inst.operands[1].immisreg)
8542 {
8543 inst.instruction &= ~0x1a000ff;
8544 inst.instruction |= (0xf << 28);
8545 if (inst.operands[1].preind)
8546 inst.instruction |= PRE_INDEX;
8547 if (!inst.operands[1].negative)
8548 inst.instruction |= INDEX_UP;
8549 if (inst.operands[1].writeback)
8550 inst.instruction |= WRITE_BACK;
8551 inst.instruction |= inst.operands[1].reg << 16;
8552 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8553 inst.instruction |= inst.operands[1].imm;
8554 }
8555 else
8556 encode_arm_cp_address (1, TRUE, FALSE, 0);
8557 }
8558
8559 static void
8560 do_iwmmxt_wshufh (void)
8561 {
8562 inst.instruction |= inst.operands[0].reg << 12;
8563 inst.instruction |= inst.operands[1].reg << 16;
8564 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8565 inst.instruction |= (inst.operands[2].imm & 0x0f);
8566 }
8567
8568 static void
8569 do_iwmmxt_wzero (void)
8570 {
8571 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8572 inst.instruction |= inst.operands[0].reg;
8573 inst.instruction |= inst.operands[0].reg << 12;
8574 inst.instruction |= inst.operands[0].reg << 16;
8575 }
8576
8577 static void
8578 do_iwmmxt_wrwrwr_or_imm5 (void)
8579 {
8580 if (inst.operands[2].isreg)
8581 do_rd_rn_rm ();
8582 else {
8583 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8584 _("immediate operand requires iWMMXt2"));
8585 do_rd_rn ();
8586 if (inst.operands[2].imm == 0)
8587 {
8588 switch ((inst.instruction >> 20) & 0xf)
8589 {
8590 case 4:
8591 case 5:
8592 case 6:
8593 case 7:
8594 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8595 inst.operands[2].imm = 16;
8596 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8597 break;
8598 case 8:
8599 case 9:
8600 case 10:
8601 case 11:
8602 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8603 inst.operands[2].imm = 32;
8604 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8605 break;
8606 case 12:
8607 case 13:
8608 case 14:
8609 case 15:
8610 {
8611 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8612 unsigned long wrn;
8613 wrn = (inst.instruction >> 16) & 0xf;
8614 inst.instruction &= 0xff0fff0f;
8615 inst.instruction |= wrn;
8616 /* Bail out here; the instruction is now assembled. */
8617 return;
8618 }
8619 }
8620 }
8621 /* Map 32 -> 0, etc. */
8622 inst.operands[2].imm &= 0x1f;
8623 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8624 }
8625 }
8626 \f
8627 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8628 operations first, then control, shift, and load/store. */
8629
8630 /* Insns like "foo X,Y,Z". */
8631
8632 static void
8633 do_mav_triple (void)
8634 {
8635 inst.instruction |= inst.operands[0].reg << 16;
8636 inst.instruction |= inst.operands[1].reg;
8637 inst.instruction |= inst.operands[2].reg << 12;
8638 }
8639
8640 /* Insns like "foo W,X,Y,Z".
8641 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8642
8643 static void
8644 do_mav_quad (void)
8645 {
8646 inst.instruction |= inst.operands[0].reg << 5;
8647 inst.instruction |= inst.operands[1].reg << 12;
8648 inst.instruction |= inst.operands[2].reg << 16;
8649 inst.instruction |= inst.operands[3].reg;
8650 }
8651
8652 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8653 static void
8654 do_mav_dspsc (void)
8655 {
8656 inst.instruction |= inst.operands[1].reg << 12;
8657 }
8658
8659 /* Maverick shift immediate instructions.
8660 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8661 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
8662
8663 static void
8664 do_mav_shift (void)
8665 {
8666 int imm = inst.operands[2].imm;
8667
8668 inst.instruction |= inst.operands[0].reg << 12;
8669 inst.instruction |= inst.operands[1].reg << 16;
8670
8671 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8672 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8673 Bit 4 should be 0. */
8674 imm = (imm & 0xf) | ((imm & 0x70) << 1);
8675
8676 inst.instruction |= imm;
8677 }
8678 \f
8679 /* XScale instructions. Also sorted arithmetic before move. */
8680
8681 /* Xscale multiply-accumulate (argument parse)
8682 MIAcc acc0,Rm,Rs
8683 MIAPHcc acc0,Rm,Rs
8684 MIAxycc acc0,Rm,Rs. */
8685
8686 static void
8687 do_xsc_mia (void)
8688 {
8689 inst.instruction |= inst.operands[1].reg;
8690 inst.instruction |= inst.operands[2].reg << 12;
8691 }
8692
8693 /* Xscale move-accumulator-register (argument parse)
8694
8695 MARcc acc0,RdLo,RdHi. */
8696
8697 static void
8698 do_xsc_mar (void)
8699 {
8700 inst.instruction |= inst.operands[1].reg << 12;
8701 inst.instruction |= inst.operands[2].reg << 16;
8702 }
8703
8704 /* Xscale move-register-accumulator (argument parse)
8705
8706 MRAcc RdLo,RdHi,acc0. */
8707
8708 static void
8709 do_xsc_mra (void)
8710 {
8711 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8712 inst.instruction |= inst.operands[0].reg << 12;
8713 inst.instruction |= inst.operands[1].reg << 16;
8714 }
8715 \f
8716 /* Encoding functions relevant only to Thumb. */
8717
8718 /* inst.operands[i] is a shifted-register operand; encode
8719 it into inst.instruction in the format used by Thumb32. */
8720
8721 static void
8722 encode_thumb32_shifted_operand (int i)
8723 {
8724 unsigned int value = inst.reloc.exp.X_add_number;
8725 unsigned int shift = inst.operands[i].shift_kind;
8726
8727 constraint (inst.operands[i].immisreg,
8728 _("shift by register not allowed in thumb mode"));
8729 inst.instruction |= inst.operands[i].reg;
8730 if (shift == SHIFT_RRX)
8731 inst.instruction |= SHIFT_ROR << 4;
8732 else
8733 {
8734 constraint (inst.reloc.exp.X_op != O_constant,
8735 _("expression too complex"));
8736
8737 constraint (value > 32
8738 || (value == 32 && (shift == SHIFT_LSL
8739 || shift == SHIFT_ROR)),
8740 _("shift expression is too large"));
8741
8742 if (value == 0)
8743 shift = SHIFT_LSL;
8744 else if (value == 32)
8745 value = 0;
8746
8747 inst.instruction |= shift << 4;
8748 inst.instruction |= (value & 0x1c) << 10;
8749 inst.instruction |= (value & 0x03) << 6;
8750 }
8751 }
8752
8753
8754 /* inst.operands[i] was set up by parse_address. Encode it into a
8755 Thumb32 format load or store instruction. Reject forms that cannot
8756 be used with such instructions. If is_t is true, reject forms that
8757 cannot be used with a T instruction; if is_d is true, reject forms
8758 that cannot be used with a D instruction. If it is a store insn,
8759 reject PC in Rn. */
8760
8761 static void
8762 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8763 {
8764 const bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8765
8766 constraint (!inst.operands[i].isreg,
8767 _("Instruction does not support =N addresses"));
8768
8769 inst.instruction |= inst.operands[i].reg << 16;
8770 if (inst.operands[i].immisreg)
8771 {
8772 constraint (is_pc, BAD_PC_ADDRESSING);
8773 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8774 constraint (inst.operands[i].negative,
8775 _("Thumb does not support negative register indexing"));
8776 constraint (inst.operands[i].postind,
8777 _("Thumb does not support register post-indexing"));
8778 constraint (inst.operands[i].writeback,
8779 _("Thumb does not support register indexing with writeback"));
8780 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8781 _("Thumb supports only LSL in shifted register indexing"));
8782
8783 inst.instruction |= inst.operands[i].imm;
8784 if (inst.operands[i].shifted)
8785 {
8786 constraint (inst.reloc.exp.X_op != O_constant,
8787 _("expression too complex"));
8788 constraint (inst.reloc.exp.X_add_number < 0
8789 || inst.reloc.exp.X_add_number > 3,
8790 _("shift out of range"));
8791 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8792 }
8793 inst.reloc.type = BFD_RELOC_UNUSED;
8794 }
8795 else if (inst.operands[i].preind)
8796 {
8797 constraint (is_pc && inst.operands[i].writeback, BAD_PC_WRITEBACK);
8798 constraint (is_t && inst.operands[i].writeback,
8799 _("cannot use writeback with this instruction"));
8800 constraint (is_pc && ((inst.instruction & THUMB2_LOAD_BIT) == 0)
8801 && !inst.reloc.pc_rel, BAD_PC_ADDRESSING);
8802
8803 if (is_d)
8804 {
8805 inst.instruction |= 0x01000000;
8806 if (inst.operands[i].writeback)
8807 inst.instruction |= 0x00200000;
8808 }
8809 else
8810 {
8811 inst.instruction |= 0x00000c00;
8812 if (inst.operands[i].writeback)
8813 inst.instruction |= 0x00000100;
8814 }
8815 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8816 }
8817 else if (inst.operands[i].postind)
8818 {
8819 gas_assert (inst.operands[i].writeback);
8820 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8821 constraint (is_t, _("cannot use post-indexing with this instruction"));
8822
8823 if (is_d)
8824 inst.instruction |= 0x00200000;
8825 else
8826 inst.instruction |= 0x00000900;
8827 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8828 }
8829 else /* unindexed - only for coprocessor */
8830 inst.error = _("instruction does not accept unindexed addressing");
8831 }
8832
8833 /* Table of Thumb instructions which exist in both 16- and 32-bit
8834 encodings (the latter only in post-V6T2 cores). The index is the
8835 value used in the insns table below. When there is more than one
8836 possible 16-bit encoding for the instruction, this table always
8837 holds variant (1).
8838 Also contains several pseudo-instructions used during relaxation. */
8839 #define T16_32_TAB \
8840 X(_adc, 4140, eb400000), \
8841 X(_adcs, 4140, eb500000), \
8842 X(_add, 1c00, eb000000), \
8843 X(_adds, 1c00, eb100000), \
8844 X(_addi, 0000, f1000000), \
8845 X(_addis, 0000, f1100000), \
8846 X(_add_pc,000f, f20f0000), \
8847 X(_add_sp,000d, f10d0000), \
8848 X(_adr, 000f, f20f0000), \
8849 X(_and, 4000, ea000000), \
8850 X(_ands, 4000, ea100000), \
8851 X(_asr, 1000, fa40f000), \
8852 X(_asrs, 1000, fa50f000), \
8853 X(_b, e000, f000b000), \
8854 X(_bcond, d000, f0008000), \
8855 X(_bic, 4380, ea200000), \
8856 X(_bics, 4380, ea300000), \
8857 X(_cmn, 42c0, eb100f00), \
8858 X(_cmp, 2800, ebb00f00), \
8859 X(_cpsie, b660, f3af8400), \
8860 X(_cpsid, b670, f3af8600), \
8861 X(_cpy, 4600, ea4f0000), \
8862 X(_dec_sp,80dd, f1ad0d00), \
8863 X(_eor, 4040, ea800000), \
8864 X(_eors, 4040, ea900000), \
8865 X(_inc_sp,00dd, f10d0d00), \
8866 X(_ldmia, c800, e8900000), \
8867 X(_ldr, 6800, f8500000), \
8868 X(_ldrb, 7800, f8100000), \
8869 X(_ldrh, 8800, f8300000), \
8870 X(_ldrsb, 5600, f9100000), \
8871 X(_ldrsh, 5e00, f9300000), \
8872 X(_ldr_pc,4800, f85f0000), \
8873 X(_ldr_pc2,4800, f85f0000), \
8874 X(_ldr_sp,9800, f85d0000), \
8875 X(_lsl, 0000, fa00f000), \
8876 X(_lsls, 0000, fa10f000), \
8877 X(_lsr, 0800, fa20f000), \
8878 X(_lsrs, 0800, fa30f000), \
8879 X(_mov, 2000, ea4f0000), \
8880 X(_movs, 2000, ea5f0000), \
8881 X(_mul, 4340, fb00f000), \
8882 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8883 X(_mvn, 43c0, ea6f0000), \
8884 X(_mvns, 43c0, ea7f0000), \
8885 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8886 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8887 X(_orr, 4300, ea400000), \
8888 X(_orrs, 4300, ea500000), \
8889 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8890 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8891 X(_rev, ba00, fa90f080), \
8892 X(_rev16, ba40, fa90f090), \
8893 X(_revsh, bac0, fa90f0b0), \
8894 X(_ror, 41c0, fa60f000), \
8895 X(_rors, 41c0, fa70f000), \
8896 X(_sbc, 4180, eb600000), \
8897 X(_sbcs, 4180, eb700000), \
8898 X(_stmia, c000, e8800000), \
8899 X(_str, 6000, f8400000), \
8900 X(_strb, 7000, f8000000), \
8901 X(_strh, 8000, f8200000), \
8902 X(_str_sp,9000, f84d0000), \
8903 X(_sub, 1e00, eba00000), \
8904 X(_subs, 1e00, ebb00000), \
8905 X(_subi, 8000, f1a00000), \
8906 X(_subis, 8000, f1b00000), \
8907 X(_sxtb, b240, fa4ff080), \
8908 X(_sxth, b200, fa0ff080), \
8909 X(_tst, 4200, ea100f00), \
8910 X(_uxtb, b2c0, fa5ff080), \
8911 X(_uxth, b280, fa1ff080), \
8912 X(_nop, bf00, f3af8000), \
8913 X(_yield, bf10, f3af8001), \
8914 X(_wfe, bf20, f3af8002), \
8915 X(_wfi, bf30, f3af8003), \
8916 X(_sev, bf40, f3af8004),
8917
8918 /* To catch errors in encoding functions, the codes are all offset by
8919 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8920 as 16-bit instructions. */
8921 #define X(a,b,c) T_MNEM##a
8922 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8923 #undef X
8924
8925 #define X(a,b,c) 0x##b
8926 static const unsigned short thumb_op16[] = { T16_32_TAB };
8927 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8928 #undef X
8929
8930 #define X(a,b,c) 0x##c
8931 static const unsigned int thumb_op32[] = { T16_32_TAB };
8932 #define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8933 #define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8934 #undef X
8935 #undef T16_32_TAB
8936
8937 /* Thumb instruction encoders, in alphabetical order. */
8938
8939 /* ADDW or SUBW. */
8940
8941 static void
8942 do_t_add_sub_w (void)
8943 {
8944 int Rd, Rn;
8945
8946 Rd = inst.operands[0].reg;
8947 Rn = inst.operands[1].reg;
8948
8949 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
8950 is the SP-{plus,minus}-immediate form of the instruction. */
8951 if (Rn == REG_SP)
8952 constraint (Rd == REG_PC, BAD_PC);
8953 else
8954 reject_bad_reg (Rd);
8955
8956 inst.instruction |= (Rn << 16) | (Rd << 8);
8957 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8958 }
8959
8960 /* Parse an add or subtract instruction. We get here with inst.instruction
8961 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8962
8963 static void
8964 do_t_add_sub (void)
8965 {
8966 int Rd, Rs, Rn;
8967
8968 Rd = inst.operands[0].reg;
8969 Rs = (inst.operands[1].present
8970 ? inst.operands[1].reg /* Rd, Rs, foo */
8971 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8972
8973 if (Rd == REG_PC)
8974 set_it_insn_type_last ();
8975
8976 if (unified_syntax)
8977 {
8978 bfd_boolean flags;
8979 bfd_boolean narrow;
8980 int opcode;
8981
8982 flags = (inst.instruction == T_MNEM_adds
8983 || inst.instruction == T_MNEM_subs);
8984 if (flags)
8985 narrow = !in_it_block ();
8986 else
8987 narrow = in_it_block ();
8988 if (!inst.operands[2].isreg)
8989 {
8990 int add;
8991
8992 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8993
8994 add = (inst.instruction == T_MNEM_add
8995 || inst.instruction == T_MNEM_adds);
8996 opcode = 0;
8997 if (inst.size_req != 4)
8998 {
8999 /* Attempt to use a narrow opcode, with relaxation if
9000 appropriate. */
9001 if (Rd == REG_SP && Rs == REG_SP && !flags)
9002 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
9003 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
9004 opcode = T_MNEM_add_sp;
9005 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
9006 opcode = T_MNEM_add_pc;
9007 else if (Rd <= 7 && Rs <= 7 && narrow)
9008 {
9009 if (flags)
9010 opcode = add ? T_MNEM_addis : T_MNEM_subis;
9011 else
9012 opcode = add ? T_MNEM_addi : T_MNEM_subi;
9013 }
9014 if (opcode)
9015 {
9016 inst.instruction = THUMB_OP16(opcode);
9017 inst.instruction |= (Rd << 4) | Rs;
9018 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9019 if (inst.size_req != 2)
9020 inst.relax = opcode;
9021 }
9022 else
9023 constraint (inst.size_req == 2, BAD_HIREG);
9024 }
9025 if (inst.size_req == 4
9026 || (inst.size_req != 2 && !opcode))
9027 {
9028 if (Rd == REG_PC)
9029 {
9030 constraint (add, BAD_PC);
9031 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
9032 _("only SUBS PC, LR, #const allowed"));
9033 constraint (inst.reloc.exp.X_op != O_constant,
9034 _("expression too complex"));
9035 constraint (inst.reloc.exp.X_add_number < 0
9036 || inst.reloc.exp.X_add_number > 0xff,
9037 _("immediate value out of range"));
9038 inst.instruction = T2_SUBS_PC_LR
9039 | inst.reloc.exp.X_add_number;
9040 inst.reloc.type = BFD_RELOC_UNUSED;
9041 return;
9042 }
9043 else if (Rs == REG_PC)
9044 {
9045 /* Always use addw/subw. */
9046 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
9047 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
9048 }
9049 else
9050 {
9051 inst.instruction = THUMB_OP32 (inst.instruction);
9052 inst.instruction = (inst.instruction & 0xe1ffffff)
9053 | 0x10000000;
9054 if (flags)
9055 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9056 else
9057 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
9058 }
9059 inst.instruction |= Rd << 8;
9060 inst.instruction |= Rs << 16;
9061 }
9062 }
9063 else
9064 {
9065 Rn = inst.operands[2].reg;
9066 /* See if we can do this with a 16-bit instruction. */
9067 if (!inst.operands[2].shifted && inst.size_req != 4)
9068 {
9069 if (Rd > 7 || Rs > 7 || Rn > 7)
9070 narrow = FALSE;
9071
9072 if (narrow)
9073 {
9074 inst.instruction = ((inst.instruction == T_MNEM_adds
9075 || inst.instruction == T_MNEM_add)
9076 ? T_OPCODE_ADD_R3
9077 : T_OPCODE_SUB_R3);
9078 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9079 return;
9080 }
9081
9082 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
9083 {
9084 /* Thumb-1 cores (except v6-M) require at least one high
9085 register in a narrow non flag setting add. */
9086 if (Rd > 7 || Rn > 7
9087 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9088 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
9089 {
9090 if (Rd == Rn)
9091 {
9092 Rn = Rs;
9093 Rs = Rd;
9094 }
9095 inst.instruction = T_OPCODE_ADD_HI;
9096 inst.instruction |= (Rd & 8) << 4;
9097 inst.instruction |= (Rd & 7);
9098 inst.instruction |= Rn << 3;
9099 return;
9100 }
9101 }
9102 }
9103
9104 constraint (Rd == REG_PC, BAD_PC);
9105 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9106 constraint (Rs == REG_PC, BAD_PC);
9107 reject_bad_reg (Rn);
9108
9109 /* If we get here, it can't be done in 16 bits. */
9110 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9111 _("shift must be constant"));
9112 inst.instruction = THUMB_OP32 (inst.instruction);
9113 inst.instruction |= Rd << 8;
9114 inst.instruction |= Rs << 16;
9115 encode_thumb32_shifted_operand (2);
9116 }
9117 }
9118 else
9119 {
9120 constraint (inst.instruction == T_MNEM_adds
9121 || inst.instruction == T_MNEM_subs,
9122 BAD_THUMB32);
9123
9124 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
9125 {
9126 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9127 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9128 BAD_HIREG);
9129
9130 inst.instruction = (inst.instruction == T_MNEM_add
9131 ? 0x0000 : 0x8000);
9132 inst.instruction |= (Rd << 4) | Rs;
9133 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9134 return;
9135 }
9136
9137 Rn = inst.operands[2].reg;
9138 constraint (inst.operands[2].shifted, _("unshifted register required"));
9139
9140 /* We now have Rd, Rs, and Rn set to registers. */
9141 if (Rd > 7 || Rs > 7 || Rn > 7)
9142 {
9143 /* Can't do this for SUB. */
9144 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9145 inst.instruction = T_OPCODE_ADD_HI;
9146 inst.instruction |= (Rd & 8) << 4;
9147 inst.instruction |= (Rd & 7);
9148 if (Rs == Rd)
9149 inst.instruction |= Rn << 3;
9150 else if (Rn == Rd)
9151 inst.instruction |= Rs << 3;
9152 else
9153 constraint (1, _("dest must overlap one source register"));
9154 }
9155 else
9156 {
9157 inst.instruction = (inst.instruction == T_MNEM_add
9158 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9159 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9160 }
9161 }
9162 }
9163
9164 static void
9165 do_t_adr (void)
9166 {
9167 unsigned Rd;
9168
9169 Rd = inst.operands[0].reg;
9170 reject_bad_reg (Rd);
9171
9172 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
9173 {
9174 /* Defer to section relaxation. */
9175 inst.relax = inst.instruction;
9176 inst.instruction = THUMB_OP16 (inst.instruction);
9177 inst.instruction |= Rd << 4;
9178 }
9179 else if (unified_syntax && inst.size_req != 2)
9180 {
9181 /* Generate a 32-bit opcode. */
9182 inst.instruction = THUMB_OP32 (inst.instruction);
9183 inst.instruction |= Rd << 8;
9184 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9185 inst.reloc.pc_rel = 1;
9186 }
9187 else
9188 {
9189 /* Generate a 16-bit opcode. */
9190 inst.instruction = THUMB_OP16 (inst.instruction);
9191 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9192 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9193 inst.reloc.pc_rel = 1;
9194
9195 inst.instruction |= Rd << 4;
9196 }
9197 }
9198
9199 /* Arithmetic instructions for which there is just one 16-bit
9200 instruction encoding, and it allows only two low registers.
9201 For maximal compatibility with ARM syntax, we allow three register
9202 operands even when Thumb-32 instructions are not available, as long
9203 as the first two are identical. For instance, both "sbc r0,r1" and
9204 "sbc r0,r0,r1" are allowed. */
9205 static void
9206 do_t_arit3 (void)
9207 {
9208 int Rd, Rs, Rn;
9209
9210 Rd = inst.operands[0].reg;
9211 Rs = (inst.operands[1].present
9212 ? inst.operands[1].reg /* Rd, Rs, foo */
9213 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9214 Rn = inst.operands[2].reg;
9215
9216 reject_bad_reg (Rd);
9217 reject_bad_reg (Rs);
9218 if (inst.operands[2].isreg)
9219 reject_bad_reg (Rn);
9220
9221 if (unified_syntax)
9222 {
9223 if (!inst.operands[2].isreg)
9224 {
9225 /* For an immediate, we always generate a 32-bit opcode;
9226 section relaxation will shrink it later if possible. */
9227 inst.instruction = THUMB_OP32 (inst.instruction);
9228 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9229 inst.instruction |= Rd << 8;
9230 inst.instruction |= Rs << 16;
9231 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9232 }
9233 else
9234 {
9235 bfd_boolean narrow;
9236
9237 /* See if we can do this with a 16-bit instruction. */
9238 if (THUMB_SETS_FLAGS (inst.instruction))
9239 narrow = !in_it_block ();
9240 else
9241 narrow = in_it_block ();
9242
9243 if (Rd > 7 || Rn > 7 || Rs > 7)
9244 narrow = FALSE;
9245 if (inst.operands[2].shifted)
9246 narrow = FALSE;
9247 if (inst.size_req == 4)
9248 narrow = FALSE;
9249
9250 if (narrow
9251 && Rd == Rs)
9252 {
9253 inst.instruction = THUMB_OP16 (inst.instruction);
9254 inst.instruction |= Rd;
9255 inst.instruction |= Rn << 3;
9256 return;
9257 }
9258
9259 /* If we get here, it can't be done in 16 bits. */
9260 constraint (inst.operands[2].shifted
9261 && inst.operands[2].immisreg,
9262 _("shift must be constant"));
9263 inst.instruction = THUMB_OP32 (inst.instruction);
9264 inst.instruction |= Rd << 8;
9265 inst.instruction |= Rs << 16;
9266 encode_thumb32_shifted_operand (2);
9267 }
9268 }
9269 else
9270 {
9271 /* On its face this is a lie - the instruction does set the
9272 flags. However, the only supported mnemonic in this mode
9273 says it doesn't. */
9274 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9275
9276 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9277 _("unshifted register required"));
9278 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9279 constraint (Rd != Rs,
9280 _("dest and source1 must be the same register"));
9281
9282 inst.instruction = THUMB_OP16 (inst.instruction);
9283 inst.instruction |= Rd;
9284 inst.instruction |= Rn << 3;
9285 }
9286 }
9287
9288 /* Similarly, but for instructions where the arithmetic operation is
9289 commutative, so we can allow either of them to be different from
9290 the destination operand in a 16-bit instruction. For instance, all
9291 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9292 accepted. */
9293 static void
9294 do_t_arit3c (void)
9295 {
9296 int Rd, Rs, Rn;
9297
9298 Rd = inst.operands[0].reg;
9299 Rs = (inst.operands[1].present
9300 ? inst.operands[1].reg /* Rd, Rs, foo */
9301 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9302 Rn = inst.operands[2].reg;
9303
9304 reject_bad_reg (Rd);
9305 reject_bad_reg (Rs);
9306 if (inst.operands[2].isreg)
9307 reject_bad_reg (Rn);
9308
9309 if (unified_syntax)
9310 {
9311 if (!inst.operands[2].isreg)
9312 {
9313 /* For an immediate, we always generate a 32-bit opcode;
9314 section relaxation will shrink it later if possible. */
9315 inst.instruction = THUMB_OP32 (inst.instruction);
9316 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9317 inst.instruction |= Rd << 8;
9318 inst.instruction |= Rs << 16;
9319 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9320 }
9321 else
9322 {
9323 bfd_boolean narrow;
9324
9325 /* See if we can do this with a 16-bit instruction. */
9326 if (THUMB_SETS_FLAGS (inst.instruction))
9327 narrow = !in_it_block ();
9328 else
9329 narrow = in_it_block ();
9330
9331 if (Rd > 7 || Rn > 7 || Rs > 7)
9332 narrow = FALSE;
9333 if (inst.operands[2].shifted)
9334 narrow = FALSE;
9335 if (inst.size_req == 4)
9336 narrow = FALSE;
9337
9338 if (narrow)
9339 {
9340 if (Rd == Rs)
9341 {
9342 inst.instruction = THUMB_OP16 (inst.instruction);
9343 inst.instruction |= Rd;
9344 inst.instruction |= Rn << 3;
9345 return;
9346 }
9347 if (Rd == Rn)
9348 {
9349 inst.instruction = THUMB_OP16 (inst.instruction);
9350 inst.instruction |= Rd;
9351 inst.instruction |= Rs << 3;
9352 return;
9353 }
9354 }
9355
9356 /* If we get here, it can't be done in 16 bits. */
9357 constraint (inst.operands[2].shifted
9358 && inst.operands[2].immisreg,
9359 _("shift must be constant"));
9360 inst.instruction = THUMB_OP32 (inst.instruction);
9361 inst.instruction |= Rd << 8;
9362 inst.instruction |= Rs << 16;
9363 encode_thumb32_shifted_operand (2);
9364 }
9365 }
9366 else
9367 {
9368 /* On its face this is a lie - the instruction does set the
9369 flags. However, the only supported mnemonic in this mode
9370 says it doesn't. */
9371 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9372
9373 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9374 _("unshifted register required"));
9375 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9376
9377 inst.instruction = THUMB_OP16 (inst.instruction);
9378 inst.instruction |= Rd;
9379
9380 if (Rd == Rs)
9381 inst.instruction |= Rn << 3;
9382 else if (Rd == Rn)
9383 inst.instruction |= Rs << 3;
9384 else
9385 constraint (1, _("dest must overlap one source register"));
9386 }
9387 }
9388
9389 static void
9390 do_t_barrier (void)
9391 {
9392 if (inst.operands[0].present)
9393 {
9394 constraint ((inst.instruction & 0xf0) != 0x40
9395 && inst.operands[0].imm != 0xf,
9396 _("bad barrier type"));
9397 inst.instruction |= inst.operands[0].imm;
9398 }
9399 else
9400 inst.instruction |= 0xf;
9401 }
9402
9403 static void
9404 do_t_bfc (void)
9405 {
9406 unsigned Rd;
9407 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9408 constraint (msb > 32, _("bit-field extends past end of register"));
9409 /* The instruction encoding stores the LSB and MSB,
9410 not the LSB and width. */
9411 Rd = inst.operands[0].reg;
9412 reject_bad_reg (Rd);
9413 inst.instruction |= Rd << 8;
9414 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9415 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9416 inst.instruction |= msb - 1;
9417 }
9418
9419 static void
9420 do_t_bfi (void)
9421 {
9422 int Rd, Rn;
9423 unsigned int msb;
9424
9425 Rd = inst.operands[0].reg;
9426 reject_bad_reg (Rd);
9427
9428 /* #0 in second position is alternative syntax for bfc, which is
9429 the same instruction but with REG_PC in the Rm field. */
9430 if (!inst.operands[1].isreg)
9431 Rn = REG_PC;
9432 else
9433 {
9434 Rn = inst.operands[1].reg;
9435 reject_bad_reg (Rn);
9436 }
9437
9438 msb = inst.operands[2].imm + inst.operands[3].imm;
9439 constraint (msb > 32, _("bit-field extends past end of register"));
9440 /* The instruction encoding stores the LSB and MSB,
9441 not the LSB and width. */
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 |= msb - 1;
9447 }
9448
9449 static void
9450 do_t_bfx (void)
9451 {
9452 unsigned Rd, Rn;
9453
9454 Rd = inst.operands[0].reg;
9455 Rn = inst.operands[1].reg;
9456
9457 reject_bad_reg (Rd);
9458 reject_bad_reg (Rn);
9459
9460 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9461 _("bit-field extends past end of register"));
9462 inst.instruction |= Rd << 8;
9463 inst.instruction |= Rn << 16;
9464 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9465 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9466 inst.instruction |= inst.operands[3].imm - 1;
9467 }
9468
9469 /* ARM V5 Thumb BLX (argument parse)
9470 BLX <target_addr> which is BLX(1)
9471 BLX <Rm> which is BLX(2)
9472 Unfortunately, there are two different opcodes for this mnemonic.
9473 So, the insns[].value is not used, and the code here zaps values
9474 into inst.instruction.
9475
9476 ??? How to take advantage of the additional two bits of displacement
9477 available in Thumb32 mode? Need new relocation? */
9478
9479 static void
9480 do_t_blx (void)
9481 {
9482 set_it_insn_type_last ();
9483
9484 if (inst.operands[0].isreg)
9485 {
9486 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9487 /* We have a register, so this is BLX(2). */
9488 inst.instruction |= inst.operands[0].reg << 3;
9489 }
9490 else
9491 {
9492 /* No register. This must be BLX(1). */
9493 inst.instruction = 0xf000e800;
9494 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
9495 inst.reloc.pc_rel = 1;
9496 }
9497 }
9498
9499 static void
9500 do_t_branch (void)
9501 {
9502 int opcode;
9503 int cond;
9504
9505 cond = inst.cond;
9506 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9507
9508 if (in_it_block ())
9509 {
9510 /* Conditional branches inside IT blocks are encoded as unconditional
9511 branches. */
9512 cond = COND_ALWAYS;
9513 }
9514 else
9515 cond = inst.cond;
9516
9517 if (cond != COND_ALWAYS)
9518 opcode = T_MNEM_bcond;
9519 else
9520 opcode = inst.instruction;
9521
9522 if (unified_syntax && inst.size_req == 4)
9523 {
9524 inst.instruction = THUMB_OP32(opcode);
9525 if (cond == COND_ALWAYS)
9526 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
9527 else
9528 {
9529 gas_assert (cond != 0xF);
9530 inst.instruction |= cond << 22;
9531 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9532 }
9533 }
9534 else
9535 {
9536 inst.instruction = THUMB_OP16(opcode);
9537 if (cond == COND_ALWAYS)
9538 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9539 else
9540 {
9541 inst.instruction |= cond << 8;
9542 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
9543 }
9544 /* Allow section relaxation. */
9545 if (unified_syntax && inst.size_req != 2)
9546 inst.relax = opcode;
9547 }
9548
9549 inst.reloc.pc_rel = 1;
9550 }
9551
9552 static void
9553 do_t_bkpt (void)
9554 {
9555 constraint (inst.cond != COND_ALWAYS,
9556 _("instruction is always unconditional"));
9557 if (inst.operands[0].present)
9558 {
9559 constraint (inst.operands[0].imm > 255,
9560 _("immediate value out of range"));
9561 inst.instruction |= inst.operands[0].imm;
9562 set_it_insn_type (NEUTRAL_IT_INSN);
9563 }
9564 }
9565
9566 static void
9567 do_t_branch23 (void)
9568 {
9569 set_it_insn_type_last ();
9570 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9571 inst.reloc.pc_rel = 1;
9572
9573 #if defined(OBJ_COFF)
9574 /* If the destination of the branch is a defined symbol which does not have
9575 the THUMB_FUNC attribute, then we must be calling a function which has
9576 the (interfacearm) attribute. We look for the Thumb entry point to that
9577 function and change the branch to refer to that function instead. */
9578 if ( inst.reloc.exp.X_op == O_symbol
9579 && inst.reloc.exp.X_add_symbol != NULL
9580 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9581 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9582 inst.reloc.exp.X_add_symbol =
9583 find_real_start (inst.reloc.exp.X_add_symbol);
9584 #endif
9585 }
9586
9587 static void
9588 do_t_bx (void)
9589 {
9590 set_it_insn_type_last ();
9591 inst.instruction |= inst.operands[0].reg << 3;
9592 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9593 should cause the alignment to be checked once it is known. This is
9594 because BX PC only works if the instruction is word aligned. */
9595 }
9596
9597 static void
9598 do_t_bxj (void)
9599 {
9600 int Rm;
9601
9602 set_it_insn_type_last ();
9603 Rm = inst.operands[0].reg;
9604 reject_bad_reg (Rm);
9605 inst.instruction |= Rm << 16;
9606 }
9607
9608 static void
9609 do_t_clz (void)
9610 {
9611 unsigned Rd;
9612 unsigned Rm;
9613
9614 Rd = inst.operands[0].reg;
9615 Rm = inst.operands[1].reg;
9616
9617 reject_bad_reg (Rd);
9618 reject_bad_reg (Rm);
9619
9620 inst.instruction |= Rd << 8;
9621 inst.instruction |= Rm << 16;
9622 inst.instruction |= Rm;
9623 }
9624
9625 static void
9626 do_t_cps (void)
9627 {
9628 set_it_insn_type (OUTSIDE_IT_INSN);
9629 inst.instruction |= inst.operands[0].imm;
9630 }
9631
9632 static void
9633 do_t_cpsi (void)
9634 {
9635 set_it_insn_type (OUTSIDE_IT_INSN);
9636 if (unified_syntax
9637 && (inst.operands[1].present || inst.size_req == 4)
9638 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
9639 {
9640 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9641 inst.instruction = 0xf3af8000;
9642 inst.instruction |= imod << 9;
9643 inst.instruction |= inst.operands[0].imm << 5;
9644 if (inst.operands[1].present)
9645 inst.instruction |= 0x100 | inst.operands[1].imm;
9646 }
9647 else
9648 {
9649 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9650 && (inst.operands[0].imm & 4),
9651 _("selected processor does not support 'A' form "
9652 "of this instruction"));
9653 constraint (inst.operands[1].present || inst.size_req == 4,
9654 _("Thumb does not support the 2-argument "
9655 "form of this instruction"));
9656 inst.instruction |= inst.operands[0].imm;
9657 }
9658 }
9659
9660 /* THUMB CPY instruction (argument parse). */
9661
9662 static void
9663 do_t_cpy (void)
9664 {
9665 if (inst.size_req == 4)
9666 {
9667 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9668 inst.instruction |= inst.operands[0].reg << 8;
9669 inst.instruction |= inst.operands[1].reg;
9670 }
9671 else
9672 {
9673 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9674 inst.instruction |= (inst.operands[0].reg & 0x7);
9675 inst.instruction |= inst.operands[1].reg << 3;
9676 }
9677 }
9678
9679 static void
9680 do_t_cbz (void)
9681 {
9682 set_it_insn_type (OUTSIDE_IT_INSN);
9683 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9684 inst.instruction |= inst.operands[0].reg;
9685 inst.reloc.pc_rel = 1;
9686 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9687 }
9688
9689 static void
9690 do_t_dbg (void)
9691 {
9692 inst.instruction |= inst.operands[0].imm;
9693 }
9694
9695 static void
9696 do_t_div (void)
9697 {
9698 unsigned Rd, Rn, Rm;
9699
9700 Rd = inst.operands[0].reg;
9701 Rn = (inst.operands[1].present
9702 ? inst.operands[1].reg : Rd);
9703 Rm = inst.operands[2].reg;
9704
9705 reject_bad_reg (Rd);
9706 reject_bad_reg (Rn);
9707 reject_bad_reg (Rm);
9708
9709 inst.instruction |= Rd << 8;
9710 inst.instruction |= Rn << 16;
9711 inst.instruction |= Rm;
9712 }
9713
9714 static void
9715 do_t_hint (void)
9716 {
9717 if (unified_syntax && inst.size_req == 4)
9718 inst.instruction = THUMB_OP32 (inst.instruction);
9719 else
9720 inst.instruction = THUMB_OP16 (inst.instruction);
9721 }
9722
9723 static void
9724 do_t_it (void)
9725 {
9726 unsigned int cond = inst.operands[0].imm;
9727
9728 set_it_insn_type (IT_INSN);
9729 now_it.mask = (inst.instruction & 0xf) | 0x10;
9730 now_it.cc = cond;
9731
9732 /* If the condition is a negative condition, invert the mask. */
9733 if ((cond & 0x1) == 0x0)
9734 {
9735 unsigned int mask = inst.instruction & 0x000f;
9736
9737 if ((mask & 0x7) == 0)
9738 /* no conversion needed */;
9739 else if ((mask & 0x3) == 0)
9740 mask ^= 0x8;
9741 else if ((mask & 0x1) == 0)
9742 mask ^= 0xC;
9743 else
9744 mask ^= 0xE;
9745
9746 inst.instruction &= 0xfff0;
9747 inst.instruction |= mask;
9748 }
9749
9750 inst.instruction |= cond << 4;
9751 }
9752
9753 /* Helper function used for both push/pop and ldm/stm. */
9754 static void
9755 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9756 {
9757 bfd_boolean load;
9758
9759 load = (inst.instruction & (1 << 20)) != 0;
9760
9761 if (mask & (1 << 13))
9762 inst.error = _("SP not allowed in register list");
9763
9764 if ((mask & (1 << base)) != 0
9765 && writeback)
9766 inst.error = _("having the base register in the register list when "
9767 "using write back is UNPREDICTABLE");
9768
9769 if (load)
9770 {
9771 if (mask & (1 << 15))
9772 {
9773 if (mask & (1 << 14))
9774 inst.error = _("LR and PC should not both be in register list");
9775 else
9776 set_it_insn_type_last ();
9777 }
9778 }
9779 else
9780 {
9781 if (mask & (1 << 15))
9782 inst.error = _("PC not allowed in register list");
9783 }
9784
9785 if ((mask & (mask - 1)) == 0)
9786 {
9787 /* Single register transfers implemented as str/ldr. */
9788 if (writeback)
9789 {
9790 if (inst.instruction & (1 << 23))
9791 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9792 else
9793 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9794 }
9795 else
9796 {
9797 if (inst.instruction & (1 << 23))
9798 inst.instruction = 0x00800000; /* ia -> [base] */
9799 else
9800 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9801 }
9802
9803 inst.instruction |= 0xf8400000;
9804 if (load)
9805 inst.instruction |= 0x00100000;
9806
9807 mask = ffs (mask) - 1;
9808 mask <<= 12;
9809 }
9810 else if (writeback)
9811 inst.instruction |= WRITE_BACK;
9812
9813 inst.instruction |= mask;
9814 inst.instruction |= base << 16;
9815 }
9816
9817 static void
9818 do_t_ldmstm (void)
9819 {
9820 /* This really doesn't seem worth it. */
9821 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9822 _("expression too complex"));
9823 constraint (inst.operands[1].writeback,
9824 _("Thumb load/store multiple does not support {reglist}^"));
9825
9826 if (unified_syntax)
9827 {
9828 bfd_boolean narrow;
9829 unsigned mask;
9830
9831 narrow = FALSE;
9832 /* See if we can use a 16-bit instruction. */
9833 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9834 && inst.size_req != 4
9835 && !(inst.operands[1].imm & ~0xff))
9836 {
9837 mask = 1 << inst.operands[0].reg;
9838
9839 if (inst.operands[0].reg <= 7
9840 && (inst.instruction == T_MNEM_stmia
9841 ? inst.operands[0].writeback
9842 : (inst.operands[0].writeback
9843 == !(inst.operands[1].imm & mask))))
9844 {
9845 if (inst.instruction == T_MNEM_stmia
9846 && (inst.operands[1].imm & mask)
9847 && (inst.operands[1].imm & (mask - 1)))
9848 as_warn (_("value stored for r%d is UNKNOWN"),
9849 inst.operands[0].reg);
9850
9851 inst.instruction = THUMB_OP16 (inst.instruction);
9852 inst.instruction |= inst.operands[0].reg << 8;
9853 inst.instruction |= inst.operands[1].imm;
9854 narrow = TRUE;
9855 }
9856 else if (inst.operands[0] .reg == REG_SP
9857 && inst.operands[0].writeback)
9858 {
9859 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9860 ? T_MNEM_push : T_MNEM_pop);
9861 inst.instruction |= inst.operands[1].imm;
9862 narrow = TRUE;
9863 }
9864 }
9865
9866 if (!narrow)
9867 {
9868 if (inst.instruction < 0xffff)
9869 inst.instruction = THUMB_OP32 (inst.instruction);
9870
9871 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9872 inst.operands[0].writeback);
9873 }
9874 }
9875 else
9876 {
9877 constraint (inst.operands[0].reg > 7
9878 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9879 constraint (inst.instruction != T_MNEM_ldmia
9880 && inst.instruction != T_MNEM_stmia,
9881 _("Thumb-2 instruction only valid in unified syntax"));
9882 if (inst.instruction == T_MNEM_stmia)
9883 {
9884 if (!inst.operands[0].writeback)
9885 as_warn (_("this instruction will write back the base register"));
9886 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9887 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9888 as_warn (_("value stored for r%d is UNKNOWN"),
9889 inst.operands[0].reg);
9890 }
9891 else
9892 {
9893 if (!inst.operands[0].writeback
9894 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9895 as_warn (_("this instruction will write back the base register"));
9896 else if (inst.operands[0].writeback
9897 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9898 as_warn (_("this instruction will not write back the base register"));
9899 }
9900
9901 inst.instruction = THUMB_OP16 (inst.instruction);
9902 inst.instruction |= inst.operands[0].reg << 8;
9903 inst.instruction |= inst.operands[1].imm;
9904 }
9905 }
9906
9907 static void
9908 do_t_ldrex (void)
9909 {
9910 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9911 || inst.operands[1].postind || inst.operands[1].writeback
9912 || inst.operands[1].immisreg || inst.operands[1].shifted
9913 || inst.operands[1].negative,
9914 BAD_ADDR_MODE);
9915
9916 constraint ((inst.operands[1].reg == REG_PC), BAD_PC);
9917
9918 inst.instruction |= inst.operands[0].reg << 12;
9919 inst.instruction |= inst.operands[1].reg << 16;
9920 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9921 }
9922
9923 static void
9924 do_t_ldrexd (void)
9925 {
9926 if (!inst.operands[1].present)
9927 {
9928 constraint (inst.operands[0].reg == REG_LR,
9929 _("r14 not allowed as first register "
9930 "when second register is omitted"));
9931 inst.operands[1].reg = inst.operands[0].reg + 1;
9932 }
9933 constraint (inst.operands[0].reg == inst.operands[1].reg,
9934 BAD_OVERLAP);
9935
9936 inst.instruction |= inst.operands[0].reg << 12;
9937 inst.instruction |= inst.operands[1].reg << 8;
9938 inst.instruction |= inst.operands[2].reg << 16;
9939 }
9940
9941 static void
9942 do_t_ldst (void)
9943 {
9944 unsigned long opcode;
9945 int Rn;
9946
9947 if (inst.operands[0].isreg
9948 && !inst.operands[0].preind
9949 && inst.operands[0].reg == REG_PC)
9950 set_it_insn_type_last ();
9951
9952 opcode = inst.instruction;
9953 if (unified_syntax)
9954 {
9955 if (!inst.operands[1].isreg)
9956 {
9957 if (opcode <= 0xffff)
9958 inst.instruction = THUMB_OP32 (opcode);
9959 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9960 return;
9961 }
9962 if (inst.operands[1].isreg
9963 && !inst.operands[1].writeback
9964 && !inst.operands[1].shifted && !inst.operands[1].postind
9965 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9966 && opcode <= 0xffff
9967 && inst.size_req != 4)
9968 {
9969 /* Insn may have a 16-bit form. */
9970 Rn = inst.operands[1].reg;
9971 if (inst.operands[1].immisreg)
9972 {
9973 inst.instruction = THUMB_OP16 (opcode);
9974 /* [Rn, Rik] */
9975 if (Rn <= 7 && inst.operands[1].imm <= 7)
9976 goto op16;
9977 else if (opcode != T_MNEM_ldr && opcode != T_MNEM_str)
9978 reject_bad_reg (inst.operands[1].imm);
9979 }
9980 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9981 && opcode != T_MNEM_ldrsb)
9982 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9983 || (Rn == REG_SP && opcode == T_MNEM_str))
9984 {
9985 /* [Rn, #const] */
9986 if (Rn > 7)
9987 {
9988 if (Rn == REG_PC)
9989 {
9990 if (inst.reloc.pc_rel)
9991 opcode = T_MNEM_ldr_pc2;
9992 else
9993 opcode = T_MNEM_ldr_pc;
9994 }
9995 else
9996 {
9997 if (opcode == T_MNEM_ldr)
9998 opcode = T_MNEM_ldr_sp;
9999 else
10000 opcode = T_MNEM_str_sp;
10001 }
10002 inst.instruction = inst.operands[0].reg << 8;
10003 }
10004 else
10005 {
10006 inst.instruction = inst.operands[0].reg;
10007 inst.instruction |= inst.operands[1].reg << 3;
10008 }
10009 inst.instruction |= THUMB_OP16 (opcode);
10010 if (inst.size_req == 2)
10011 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10012 else
10013 inst.relax = opcode;
10014 return;
10015 }
10016 }
10017 /* Definitely a 32-bit variant. */
10018
10019 /* Do some validations regarding addressing modes. */
10020 if (inst.operands[1].immisreg && opcode != T_MNEM_ldr
10021 && opcode != T_MNEM_str)
10022 reject_bad_reg (inst.operands[1].imm);
10023
10024 inst.instruction = THUMB_OP32 (opcode);
10025 inst.instruction |= inst.operands[0].reg << 12;
10026 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
10027 return;
10028 }
10029
10030 constraint (inst.operands[0].reg > 7, BAD_HIREG);
10031
10032 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
10033 {
10034 /* Only [Rn,Rm] is acceptable. */
10035 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
10036 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
10037 || inst.operands[1].postind || inst.operands[1].shifted
10038 || inst.operands[1].negative,
10039 _("Thumb does not support this addressing mode"));
10040 inst.instruction = THUMB_OP16 (inst.instruction);
10041 goto op16;
10042 }
10043
10044 inst.instruction = THUMB_OP16 (inst.instruction);
10045 if (!inst.operands[1].isreg)
10046 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
10047 return;
10048
10049 constraint (!inst.operands[1].preind
10050 || inst.operands[1].shifted
10051 || inst.operands[1].writeback,
10052 _("Thumb does not support this addressing mode"));
10053 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
10054 {
10055 constraint (inst.instruction & 0x0600,
10056 _("byte or halfword not valid for base register"));
10057 constraint (inst.operands[1].reg == REG_PC
10058 && !(inst.instruction & THUMB_LOAD_BIT),
10059 _("r15 based store not allowed"));
10060 constraint (inst.operands[1].immisreg,
10061 _("invalid base register for register offset"));
10062
10063 if (inst.operands[1].reg == REG_PC)
10064 inst.instruction = T_OPCODE_LDR_PC;
10065 else if (inst.instruction & THUMB_LOAD_BIT)
10066 inst.instruction = T_OPCODE_LDR_SP;
10067 else
10068 inst.instruction = T_OPCODE_STR_SP;
10069
10070 inst.instruction |= inst.operands[0].reg << 8;
10071 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10072 return;
10073 }
10074
10075 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10076 if (!inst.operands[1].immisreg)
10077 {
10078 /* Immediate offset. */
10079 inst.instruction |= inst.operands[0].reg;
10080 inst.instruction |= inst.operands[1].reg << 3;
10081 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10082 return;
10083 }
10084
10085 /* Register offset. */
10086 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10087 constraint (inst.operands[1].negative,
10088 _("Thumb does not support this addressing mode"));
10089
10090 op16:
10091 switch (inst.instruction)
10092 {
10093 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10094 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10095 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10096 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10097 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10098 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10099 case 0x5600 /* ldrsb */:
10100 case 0x5e00 /* ldrsh */: break;
10101 default: abort ();
10102 }
10103
10104 inst.instruction |= inst.operands[0].reg;
10105 inst.instruction |= inst.operands[1].reg << 3;
10106 inst.instruction |= inst.operands[1].imm << 6;
10107 }
10108
10109 static void
10110 do_t_ldstd (void)
10111 {
10112 if (!inst.operands[1].present)
10113 {
10114 inst.operands[1].reg = inst.operands[0].reg + 1;
10115 constraint (inst.operands[0].reg == REG_LR,
10116 _("r14 not allowed here"));
10117 }
10118 inst.instruction |= inst.operands[0].reg << 12;
10119 inst.instruction |= inst.operands[1].reg << 8;
10120 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
10121 }
10122
10123 static void
10124 do_t_ldstt (void)
10125 {
10126 inst.instruction |= inst.operands[0].reg << 12;
10127 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10128 }
10129
10130 static void
10131 do_t_mla (void)
10132 {
10133 unsigned Rd, Rn, Rm, Ra;
10134
10135 Rd = inst.operands[0].reg;
10136 Rn = inst.operands[1].reg;
10137 Rm = inst.operands[2].reg;
10138 Ra = inst.operands[3].reg;
10139
10140 reject_bad_reg (Rd);
10141 reject_bad_reg (Rn);
10142 reject_bad_reg (Rm);
10143 reject_bad_reg (Ra);
10144
10145 inst.instruction |= Rd << 8;
10146 inst.instruction |= Rn << 16;
10147 inst.instruction |= Rm;
10148 inst.instruction |= Ra << 12;
10149 }
10150
10151 static void
10152 do_t_mlal (void)
10153 {
10154 unsigned RdLo, RdHi, Rn, Rm;
10155
10156 RdLo = inst.operands[0].reg;
10157 RdHi = inst.operands[1].reg;
10158 Rn = inst.operands[2].reg;
10159 Rm = inst.operands[3].reg;
10160
10161 reject_bad_reg (RdLo);
10162 reject_bad_reg (RdHi);
10163 reject_bad_reg (Rn);
10164 reject_bad_reg (Rm);
10165
10166 inst.instruction |= RdLo << 12;
10167 inst.instruction |= RdHi << 8;
10168 inst.instruction |= Rn << 16;
10169 inst.instruction |= Rm;
10170 }
10171
10172 static void
10173 do_t_mov_cmp (void)
10174 {
10175 unsigned Rn, Rm;
10176
10177 Rn = inst.operands[0].reg;
10178 Rm = inst.operands[1].reg;
10179
10180 if (Rn == REG_PC)
10181 set_it_insn_type_last ();
10182
10183 if (unified_syntax)
10184 {
10185 int r0off = (inst.instruction == T_MNEM_mov
10186 || inst.instruction == T_MNEM_movs) ? 8 : 16;
10187 unsigned long opcode;
10188 bfd_boolean narrow;
10189 bfd_boolean low_regs;
10190
10191 low_regs = (Rn <= 7 && Rm <= 7);
10192 opcode = inst.instruction;
10193 if (in_it_block ())
10194 narrow = opcode != T_MNEM_movs;
10195 else
10196 narrow = opcode != T_MNEM_movs || low_regs;
10197 if (inst.size_req == 4
10198 || inst.operands[1].shifted)
10199 narrow = FALSE;
10200
10201 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10202 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10203 && !inst.operands[1].shifted
10204 && Rn == REG_PC
10205 && Rm == REG_LR)
10206 {
10207 inst.instruction = T2_SUBS_PC_LR;
10208 return;
10209 }
10210
10211 if (opcode == T_MNEM_cmp)
10212 {
10213 constraint (Rn == REG_PC, BAD_PC);
10214 if (narrow)
10215 {
10216 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10217 but valid. */
10218 warn_deprecated_sp (Rm);
10219 /* R15 was documented as a valid choice for Rm in ARMv6,
10220 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10221 tools reject R15, so we do too. */
10222 constraint (Rm == REG_PC, BAD_PC);
10223 }
10224 else
10225 reject_bad_reg (Rm);
10226 }
10227 else if (opcode == T_MNEM_mov
10228 || opcode == T_MNEM_movs)
10229 {
10230 if (inst.operands[1].isreg)
10231 {
10232 if (opcode == T_MNEM_movs)
10233 {
10234 reject_bad_reg (Rn);
10235 reject_bad_reg (Rm);
10236 }
10237 else if ((Rn == REG_SP || Rn == REG_PC)
10238 && (Rm == REG_SP || Rm == REG_PC))
10239 reject_bad_reg (Rm);
10240 }
10241 else
10242 reject_bad_reg (Rn);
10243 }
10244
10245 if (!inst.operands[1].isreg)
10246 {
10247 /* Immediate operand. */
10248 if (!in_it_block () && opcode == T_MNEM_mov)
10249 narrow = 0;
10250 if (low_regs && narrow)
10251 {
10252 inst.instruction = THUMB_OP16 (opcode);
10253 inst.instruction |= Rn << 8;
10254 if (inst.size_req == 2)
10255 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10256 else
10257 inst.relax = opcode;
10258 }
10259 else
10260 {
10261 inst.instruction = THUMB_OP32 (inst.instruction);
10262 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10263 inst.instruction |= Rn << r0off;
10264 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10265 }
10266 }
10267 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10268 && (inst.instruction == T_MNEM_mov
10269 || inst.instruction == T_MNEM_movs))
10270 {
10271 /* Register shifts are encoded as separate shift instructions. */
10272 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10273
10274 if (in_it_block ())
10275 narrow = !flags;
10276 else
10277 narrow = flags;
10278
10279 if (inst.size_req == 4)
10280 narrow = FALSE;
10281
10282 if (!low_regs || inst.operands[1].imm > 7)
10283 narrow = FALSE;
10284
10285 if (Rn != Rm)
10286 narrow = FALSE;
10287
10288 switch (inst.operands[1].shift_kind)
10289 {
10290 case SHIFT_LSL:
10291 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10292 break;
10293 case SHIFT_ASR:
10294 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10295 break;
10296 case SHIFT_LSR:
10297 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10298 break;
10299 case SHIFT_ROR:
10300 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10301 break;
10302 default:
10303 abort ();
10304 }
10305
10306 inst.instruction = opcode;
10307 if (narrow)
10308 {
10309 inst.instruction |= Rn;
10310 inst.instruction |= inst.operands[1].imm << 3;
10311 }
10312 else
10313 {
10314 if (flags)
10315 inst.instruction |= CONDS_BIT;
10316
10317 inst.instruction |= Rn << 8;
10318 inst.instruction |= Rm << 16;
10319 inst.instruction |= inst.operands[1].imm;
10320 }
10321 }
10322 else if (!narrow)
10323 {
10324 /* Some mov with immediate shift have narrow variants.
10325 Register shifts are handled above. */
10326 if (low_regs && inst.operands[1].shifted
10327 && (inst.instruction == T_MNEM_mov
10328 || inst.instruction == T_MNEM_movs))
10329 {
10330 if (in_it_block ())
10331 narrow = (inst.instruction == T_MNEM_mov);
10332 else
10333 narrow = (inst.instruction == T_MNEM_movs);
10334 }
10335
10336 if (narrow)
10337 {
10338 switch (inst.operands[1].shift_kind)
10339 {
10340 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10341 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10342 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10343 default: narrow = FALSE; break;
10344 }
10345 }
10346
10347 if (narrow)
10348 {
10349 inst.instruction |= Rn;
10350 inst.instruction |= Rm << 3;
10351 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10352 }
10353 else
10354 {
10355 inst.instruction = THUMB_OP32 (inst.instruction);
10356 inst.instruction |= Rn << r0off;
10357 encode_thumb32_shifted_operand (1);
10358 }
10359 }
10360 else
10361 switch (inst.instruction)
10362 {
10363 case T_MNEM_mov:
10364 inst.instruction = T_OPCODE_MOV_HR;
10365 inst.instruction |= (Rn & 0x8) << 4;
10366 inst.instruction |= (Rn & 0x7);
10367 inst.instruction |= Rm << 3;
10368 break;
10369
10370 case T_MNEM_movs:
10371 /* We know we have low registers at this point.
10372 Generate LSLS Rd, Rs, #0. */
10373 inst.instruction = T_OPCODE_LSL_I;
10374 inst.instruction |= Rn;
10375 inst.instruction |= Rm << 3;
10376 break;
10377
10378 case T_MNEM_cmp:
10379 if (low_regs)
10380 {
10381 inst.instruction = T_OPCODE_CMP_LR;
10382 inst.instruction |= Rn;
10383 inst.instruction |= Rm << 3;
10384 }
10385 else
10386 {
10387 inst.instruction = T_OPCODE_CMP_HR;
10388 inst.instruction |= (Rn & 0x8) << 4;
10389 inst.instruction |= (Rn & 0x7);
10390 inst.instruction |= Rm << 3;
10391 }
10392 break;
10393 }
10394 return;
10395 }
10396
10397 inst.instruction = THUMB_OP16 (inst.instruction);
10398
10399 /* PR 10443: Do not silently ignore shifted operands. */
10400 constraint (inst.operands[1].shifted,
10401 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10402
10403 if (inst.operands[1].isreg)
10404 {
10405 if (Rn < 8 && Rm < 8)
10406 {
10407 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10408 since a MOV instruction produces unpredictable results. */
10409 if (inst.instruction == T_OPCODE_MOV_I8)
10410 inst.instruction = T_OPCODE_ADD_I3;
10411 else
10412 inst.instruction = T_OPCODE_CMP_LR;
10413
10414 inst.instruction |= Rn;
10415 inst.instruction |= Rm << 3;
10416 }
10417 else
10418 {
10419 if (inst.instruction == T_OPCODE_MOV_I8)
10420 inst.instruction = T_OPCODE_MOV_HR;
10421 else
10422 inst.instruction = T_OPCODE_CMP_HR;
10423 do_t_cpy ();
10424 }
10425 }
10426 else
10427 {
10428 constraint (Rn > 7,
10429 _("only lo regs allowed with immediate"));
10430 inst.instruction |= Rn << 8;
10431 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10432 }
10433 }
10434
10435 static void
10436 do_t_mov16 (void)
10437 {
10438 unsigned Rd;
10439 bfd_vma imm;
10440 bfd_boolean top;
10441
10442 top = (inst.instruction & 0x00800000) != 0;
10443 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10444 {
10445 constraint (top, _(":lower16: not allowed this instruction"));
10446 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10447 }
10448 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10449 {
10450 constraint (!top, _(":upper16: not allowed this instruction"));
10451 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10452 }
10453
10454 Rd = inst.operands[0].reg;
10455 reject_bad_reg (Rd);
10456
10457 inst.instruction |= Rd << 8;
10458 if (inst.reloc.type == BFD_RELOC_UNUSED)
10459 {
10460 imm = inst.reloc.exp.X_add_number;
10461 inst.instruction |= (imm & 0xf000) << 4;
10462 inst.instruction |= (imm & 0x0800) << 15;
10463 inst.instruction |= (imm & 0x0700) << 4;
10464 inst.instruction |= (imm & 0x00ff);
10465 }
10466 }
10467
10468 static void
10469 do_t_mvn_tst (void)
10470 {
10471 unsigned Rn, Rm;
10472
10473 Rn = inst.operands[0].reg;
10474 Rm = inst.operands[1].reg;
10475
10476 if (inst.instruction == T_MNEM_cmp
10477 || inst.instruction == T_MNEM_cmn)
10478 constraint (Rn == REG_PC, BAD_PC);
10479 else
10480 reject_bad_reg (Rn);
10481 reject_bad_reg (Rm);
10482
10483 if (unified_syntax)
10484 {
10485 int r0off = (inst.instruction == T_MNEM_mvn
10486 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
10487 bfd_boolean narrow;
10488
10489 if (inst.size_req == 4
10490 || inst.instruction > 0xffff
10491 || inst.operands[1].shifted
10492 || Rn > 7 || Rm > 7)
10493 narrow = FALSE;
10494 else if (inst.instruction == T_MNEM_cmn)
10495 narrow = TRUE;
10496 else if (THUMB_SETS_FLAGS (inst.instruction))
10497 narrow = !in_it_block ();
10498 else
10499 narrow = in_it_block ();
10500
10501 if (!inst.operands[1].isreg)
10502 {
10503 /* For an immediate, we always generate a 32-bit opcode;
10504 section relaxation will shrink it later if possible. */
10505 if (inst.instruction < 0xffff)
10506 inst.instruction = THUMB_OP32 (inst.instruction);
10507 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10508 inst.instruction |= Rn << r0off;
10509 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10510 }
10511 else
10512 {
10513 /* See if we can do this with a 16-bit instruction. */
10514 if (narrow)
10515 {
10516 inst.instruction = THUMB_OP16 (inst.instruction);
10517 inst.instruction |= Rn;
10518 inst.instruction |= Rm << 3;
10519 }
10520 else
10521 {
10522 constraint (inst.operands[1].shifted
10523 && inst.operands[1].immisreg,
10524 _("shift must be constant"));
10525 if (inst.instruction < 0xffff)
10526 inst.instruction = THUMB_OP32 (inst.instruction);
10527 inst.instruction |= Rn << r0off;
10528 encode_thumb32_shifted_operand (1);
10529 }
10530 }
10531 }
10532 else
10533 {
10534 constraint (inst.instruction > 0xffff
10535 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10536 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10537 _("unshifted register required"));
10538 constraint (Rn > 7 || Rm > 7,
10539 BAD_HIREG);
10540
10541 inst.instruction = THUMB_OP16 (inst.instruction);
10542 inst.instruction |= Rn;
10543 inst.instruction |= Rm << 3;
10544 }
10545 }
10546
10547 static void
10548 do_t_mrs (void)
10549 {
10550 unsigned Rd;
10551 int flags;
10552
10553 if (do_vfp_nsyn_mrs () == SUCCESS)
10554 return;
10555
10556 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10557 if (flags == 0)
10558 {
10559 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10560 _("selected processor does not support "
10561 "requested special purpose register"));
10562 }
10563 else
10564 {
10565 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10566 _("selected processor does not support "
10567 "requested special purpose register"));
10568 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10569 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10570 _("'CPSR' or 'SPSR' expected"));
10571 }
10572
10573 Rd = inst.operands[0].reg;
10574 reject_bad_reg (Rd);
10575
10576 inst.instruction |= Rd << 8;
10577 inst.instruction |= (flags & SPSR_BIT) >> 2;
10578 inst.instruction |= inst.operands[1].imm & 0xff;
10579 }
10580
10581 static void
10582 do_t_msr (void)
10583 {
10584 int flags;
10585 unsigned Rn;
10586
10587 if (do_vfp_nsyn_msr () == SUCCESS)
10588 return;
10589
10590 constraint (!inst.operands[1].isreg,
10591 _("Thumb encoding does not support an immediate here"));
10592 flags = inst.operands[0].imm;
10593 if (flags & ~0xff)
10594 {
10595 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10596 _("selected processor does not support "
10597 "requested special purpose register"));
10598 }
10599 else
10600 {
10601 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10602 _("selected processor does not support "
10603 "requested special purpose register"));
10604 flags |= PSR_f;
10605 }
10606
10607 Rn = inst.operands[1].reg;
10608 reject_bad_reg (Rn);
10609
10610 inst.instruction |= (flags & SPSR_BIT) >> 2;
10611 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10612 inst.instruction |= (flags & 0xff);
10613 inst.instruction |= Rn << 16;
10614 }
10615
10616 static void
10617 do_t_mul (void)
10618 {
10619 bfd_boolean narrow;
10620 unsigned Rd, Rn, Rm;
10621
10622 if (!inst.operands[2].present)
10623 inst.operands[2].reg = inst.operands[0].reg;
10624
10625 Rd = inst.operands[0].reg;
10626 Rn = inst.operands[1].reg;
10627 Rm = inst.operands[2].reg;
10628
10629 if (unified_syntax)
10630 {
10631 if (inst.size_req == 4
10632 || (Rd != Rn
10633 && Rd != Rm)
10634 || Rn > 7
10635 || Rm > 7)
10636 narrow = FALSE;
10637 else if (inst.instruction == T_MNEM_muls)
10638 narrow = !in_it_block ();
10639 else
10640 narrow = in_it_block ();
10641 }
10642 else
10643 {
10644 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
10645 constraint (Rn > 7 || Rm > 7,
10646 BAD_HIREG);
10647 narrow = TRUE;
10648 }
10649
10650 if (narrow)
10651 {
10652 /* 16-bit MULS/Conditional MUL. */
10653 inst.instruction = THUMB_OP16 (inst.instruction);
10654 inst.instruction |= Rd;
10655
10656 if (Rd == Rn)
10657 inst.instruction |= Rm << 3;
10658 else if (Rd == Rm)
10659 inst.instruction |= Rn << 3;
10660 else
10661 constraint (1, _("dest must overlap one source register"));
10662 }
10663 else
10664 {
10665 constraint (inst.instruction != T_MNEM_mul,
10666 _("Thumb-2 MUL must not set flags"));
10667 /* 32-bit MUL. */
10668 inst.instruction = THUMB_OP32 (inst.instruction);
10669 inst.instruction |= Rd << 8;
10670 inst.instruction |= Rn << 16;
10671 inst.instruction |= Rm << 0;
10672
10673 reject_bad_reg (Rd);
10674 reject_bad_reg (Rn);
10675 reject_bad_reg (Rm);
10676 }
10677 }
10678
10679 static void
10680 do_t_mull (void)
10681 {
10682 unsigned RdLo, RdHi, Rn, Rm;
10683
10684 RdLo = inst.operands[0].reg;
10685 RdHi = inst.operands[1].reg;
10686 Rn = inst.operands[2].reg;
10687 Rm = inst.operands[3].reg;
10688
10689 reject_bad_reg (RdLo);
10690 reject_bad_reg (RdHi);
10691 reject_bad_reg (Rn);
10692 reject_bad_reg (Rm);
10693
10694 inst.instruction |= RdLo << 12;
10695 inst.instruction |= RdHi << 8;
10696 inst.instruction |= Rn << 16;
10697 inst.instruction |= Rm;
10698
10699 if (RdLo == RdHi)
10700 as_tsktsk (_("rdhi and rdlo must be different"));
10701 }
10702
10703 static void
10704 do_t_nop (void)
10705 {
10706 set_it_insn_type (NEUTRAL_IT_INSN);
10707
10708 if (unified_syntax)
10709 {
10710 if (inst.size_req == 4 || inst.operands[0].imm > 15)
10711 {
10712 inst.instruction = THUMB_OP32 (inst.instruction);
10713 inst.instruction |= inst.operands[0].imm;
10714 }
10715 else
10716 {
10717 /* PR9722: Check for Thumb2 availability before
10718 generating a thumb2 nop instruction. */
10719 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
10720 {
10721 inst.instruction = THUMB_OP16 (inst.instruction);
10722 inst.instruction |= inst.operands[0].imm << 4;
10723 }
10724 else
10725 inst.instruction = 0x46c0;
10726 }
10727 }
10728 else
10729 {
10730 constraint (inst.operands[0].present,
10731 _("Thumb does not support NOP with hints"));
10732 inst.instruction = 0x46c0;
10733 }
10734 }
10735
10736 static void
10737 do_t_neg (void)
10738 {
10739 if (unified_syntax)
10740 {
10741 bfd_boolean narrow;
10742
10743 if (THUMB_SETS_FLAGS (inst.instruction))
10744 narrow = !in_it_block ();
10745 else
10746 narrow = in_it_block ();
10747 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10748 narrow = FALSE;
10749 if (inst.size_req == 4)
10750 narrow = FALSE;
10751
10752 if (!narrow)
10753 {
10754 inst.instruction = THUMB_OP32 (inst.instruction);
10755 inst.instruction |= inst.operands[0].reg << 8;
10756 inst.instruction |= inst.operands[1].reg << 16;
10757 }
10758 else
10759 {
10760 inst.instruction = THUMB_OP16 (inst.instruction);
10761 inst.instruction |= inst.operands[0].reg;
10762 inst.instruction |= inst.operands[1].reg << 3;
10763 }
10764 }
10765 else
10766 {
10767 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10768 BAD_HIREG);
10769 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10770
10771 inst.instruction = THUMB_OP16 (inst.instruction);
10772 inst.instruction |= inst.operands[0].reg;
10773 inst.instruction |= inst.operands[1].reg << 3;
10774 }
10775 }
10776
10777 static void
10778 do_t_orn (void)
10779 {
10780 unsigned Rd, Rn;
10781
10782 Rd = inst.operands[0].reg;
10783 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10784
10785 reject_bad_reg (Rd);
10786 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10787 reject_bad_reg (Rn);
10788
10789 inst.instruction |= Rd << 8;
10790 inst.instruction |= Rn << 16;
10791
10792 if (!inst.operands[2].isreg)
10793 {
10794 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10795 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10796 }
10797 else
10798 {
10799 unsigned Rm;
10800
10801 Rm = inst.operands[2].reg;
10802 reject_bad_reg (Rm);
10803
10804 constraint (inst.operands[2].shifted
10805 && inst.operands[2].immisreg,
10806 _("shift must be constant"));
10807 encode_thumb32_shifted_operand (2);
10808 }
10809 }
10810
10811 static void
10812 do_t_pkhbt (void)
10813 {
10814 unsigned Rd, Rn, Rm;
10815
10816 Rd = inst.operands[0].reg;
10817 Rn = inst.operands[1].reg;
10818 Rm = inst.operands[2].reg;
10819
10820 reject_bad_reg (Rd);
10821 reject_bad_reg (Rn);
10822 reject_bad_reg (Rm);
10823
10824 inst.instruction |= Rd << 8;
10825 inst.instruction |= Rn << 16;
10826 inst.instruction |= Rm;
10827 if (inst.operands[3].present)
10828 {
10829 unsigned int val = inst.reloc.exp.X_add_number;
10830 constraint (inst.reloc.exp.X_op != O_constant,
10831 _("expression too complex"));
10832 inst.instruction |= (val & 0x1c) << 10;
10833 inst.instruction |= (val & 0x03) << 6;
10834 }
10835 }
10836
10837 static void
10838 do_t_pkhtb (void)
10839 {
10840 if (!inst.operands[3].present)
10841 {
10842 unsigned Rtmp;
10843
10844 inst.instruction &= ~0x00000020;
10845
10846 /* PR 10168. Swap the Rm and Rn registers. */
10847 Rtmp = inst.operands[1].reg;
10848 inst.operands[1].reg = inst.operands[2].reg;
10849 inst.operands[2].reg = Rtmp;
10850 }
10851 do_t_pkhbt ();
10852 }
10853
10854 static void
10855 do_t_pld (void)
10856 {
10857 if (inst.operands[0].immisreg)
10858 reject_bad_reg (inst.operands[0].imm);
10859
10860 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10861 }
10862
10863 static void
10864 do_t_push_pop (void)
10865 {
10866 unsigned mask;
10867
10868 constraint (inst.operands[0].writeback,
10869 _("push/pop do not support {reglist}^"));
10870 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10871 _("expression too complex"));
10872
10873 mask = inst.operands[0].imm;
10874 if ((mask & ~0xff) == 0)
10875 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10876 else if ((inst.instruction == T_MNEM_push
10877 && (mask & ~0xff) == 1 << REG_LR)
10878 || (inst.instruction == T_MNEM_pop
10879 && (mask & ~0xff) == 1 << REG_PC))
10880 {
10881 inst.instruction = THUMB_OP16 (inst.instruction);
10882 inst.instruction |= THUMB_PP_PC_LR;
10883 inst.instruction |= mask & 0xff;
10884 }
10885 else if (unified_syntax)
10886 {
10887 inst.instruction = THUMB_OP32 (inst.instruction);
10888 encode_thumb2_ldmstm (13, mask, TRUE);
10889 }
10890 else
10891 {
10892 inst.error = _("invalid register list to push/pop instruction");
10893 return;
10894 }
10895 }
10896
10897 static void
10898 do_t_rbit (void)
10899 {
10900 unsigned Rd, Rm;
10901
10902 Rd = inst.operands[0].reg;
10903 Rm = inst.operands[1].reg;
10904
10905 reject_bad_reg (Rd);
10906 reject_bad_reg (Rm);
10907
10908 inst.instruction |= Rd << 8;
10909 inst.instruction |= Rm << 16;
10910 inst.instruction |= Rm;
10911 }
10912
10913 static void
10914 do_t_rev (void)
10915 {
10916 unsigned Rd, Rm;
10917
10918 Rd = inst.operands[0].reg;
10919 Rm = inst.operands[1].reg;
10920
10921 reject_bad_reg (Rd);
10922 reject_bad_reg (Rm);
10923
10924 if (Rd <= 7 && Rm <= 7
10925 && inst.size_req != 4)
10926 {
10927 inst.instruction = THUMB_OP16 (inst.instruction);
10928 inst.instruction |= Rd;
10929 inst.instruction |= Rm << 3;
10930 }
10931 else if (unified_syntax)
10932 {
10933 inst.instruction = THUMB_OP32 (inst.instruction);
10934 inst.instruction |= Rd << 8;
10935 inst.instruction |= Rm << 16;
10936 inst.instruction |= Rm;
10937 }
10938 else
10939 inst.error = BAD_HIREG;
10940 }
10941
10942 static void
10943 do_t_rrx (void)
10944 {
10945 unsigned Rd, Rm;
10946
10947 Rd = inst.operands[0].reg;
10948 Rm = inst.operands[1].reg;
10949
10950 reject_bad_reg (Rd);
10951 reject_bad_reg (Rm);
10952
10953 inst.instruction |= Rd << 8;
10954 inst.instruction |= Rm;
10955 }
10956
10957 static void
10958 do_t_rsb (void)
10959 {
10960 unsigned Rd, Rs;
10961
10962 Rd = inst.operands[0].reg;
10963 Rs = (inst.operands[1].present
10964 ? inst.operands[1].reg /* Rd, Rs, foo */
10965 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
10966
10967 reject_bad_reg (Rd);
10968 reject_bad_reg (Rs);
10969 if (inst.operands[2].isreg)
10970 reject_bad_reg (inst.operands[2].reg);
10971
10972 inst.instruction |= Rd << 8;
10973 inst.instruction |= Rs << 16;
10974 if (!inst.operands[2].isreg)
10975 {
10976 bfd_boolean narrow;
10977
10978 if ((inst.instruction & 0x00100000) != 0)
10979 narrow = !in_it_block ();
10980 else
10981 narrow = in_it_block ();
10982
10983 if (Rd > 7 || Rs > 7)
10984 narrow = FALSE;
10985
10986 if (inst.size_req == 4 || !unified_syntax)
10987 narrow = FALSE;
10988
10989 if (inst.reloc.exp.X_op != O_constant
10990 || inst.reloc.exp.X_add_number != 0)
10991 narrow = FALSE;
10992
10993 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10994 relaxation, but it doesn't seem worth the hassle. */
10995 if (narrow)
10996 {
10997 inst.reloc.type = BFD_RELOC_UNUSED;
10998 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10999 inst.instruction |= Rs << 3;
11000 inst.instruction |= Rd;
11001 }
11002 else
11003 {
11004 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
11005 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
11006 }
11007 }
11008 else
11009 encode_thumb32_shifted_operand (2);
11010 }
11011
11012 static void
11013 do_t_setend (void)
11014 {
11015 set_it_insn_type (OUTSIDE_IT_INSN);
11016 if (inst.operands[0].imm)
11017 inst.instruction |= 0x8;
11018 }
11019
11020 static void
11021 do_t_shift (void)
11022 {
11023 if (!inst.operands[1].present)
11024 inst.operands[1].reg = inst.operands[0].reg;
11025
11026 if (unified_syntax)
11027 {
11028 bfd_boolean narrow;
11029 int shift_kind;
11030
11031 switch (inst.instruction)
11032 {
11033 case T_MNEM_asr:
11034 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
11035 case T_MNEM_lsl:
11036 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
11037 case T_MNEM_lsr:
11038 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
11039 case T_MNEM_ror:
11040 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
11041 default: abort ();
11042 }
11043
11044 if (THUMB_SETS_FLAGS (inst.instruction))
11045 narrow = !in_it_block ();
11046 else
11047 narrow = in_it_block ();
11048 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
11049 narrow = FALSE;
11050 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
11051 narrow = FALSE;
11052 if (inst.operands[2].isreg
11053 && (inst.operands[1].reg != inst.operands[0].reg
11054 || inst.operands[2].reg > 7))
11055 narrow = FALSE;
11056 if (inst.size_req == 4)
11057 narrow = FALSE;
11058
11059 reject_bad_reg (inst.operands[0].reg);
11060 reject_bad_reg (inst.operands[1].reg);
11061
11062 if (!narrow)
11063 {
11064 if (inst.operands[2].isreg)
11065 {
11066 reject_bad_reg (inst.operands[2].reg);
11067 inst.instruction = THUMB_OP32 (inst.instruction);
11068 inst.instruction |= inst.operands[0].reg << 8;
11069 inst.instruction |= inst.operands[1].reg << 16;
11070 inst.instruction |= inst.operands[2].reg;
11071 }
11072 else
11073 {
11074 inst.operands[1].shifted = 1;
11075 inst.operands[1].shift_kind = shift_kind;
11076 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11077 ? T_MNEM_movs : T_MNEM_mov);
11078 inst.instruction |= inst.operands[0].reg << 8;
11079 encode_thumb32_shifted_operand (1);
11080 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11081 inst.reloc.type = BFD_RELOC_UNUSED;
11082 }
11083 }
11084 else
11085 {
11086 if (inst.operands[2].isreg)
11087 {
11088 switch (shift_kind)
11089 {
11090 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11091 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11092 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11093 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
11094 default: abort ();
11095 }
11096
11097 inst.instruction |= inst.operands[0].reg;
11098 inst.instruction |= inst.operands[2].reg << 3;
11099 }
11100 else
11101 {
11102 switch (shift_kind)
11103 {
11104 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11105 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11106 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
11107 default: abort ();
11108 }
11109 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11110 inst.instruction |= inst.operands[0].reg;
11111 inst.instruction |= inst.operands[1].reg << 3;
11112 }
11113 }
11114 }
11115 else
11116 {
11117 constraint (inst.operands[0].reg > 7
11118 || inst.operands[1].reg > 7, BAD_HIREG);
11119 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
11120
11121 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11122 {
11123 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11124 constraint (inst.operands[0].reg != inst.operands[1].reg,
11125 _("source1 and dest must be same register"));
11126
11127 switch (inst.instruction)
11128 {
11129 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11130 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11131 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11132 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11133 default: abort ();
11134 }
11135
11136 inst.instruction |= inst.operands[0].reg;
11137 inst.instruction |= inst.operands[2].reg << 3;
11138 }
11139 else
11140 {
11141 switch (inst.instruction)
11142 {
11143 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11144 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11145 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11146 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11147 default: abort ();
11148 }
11149 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11150 inst.instruction |= inst.operands[0].reg;
11151 inst.instruction |= inst.operands[1].reg << 3;
11152 }
11153 }
11154 }
11155
11156 static void
11157 do_t_simd (void)
11158 {
11159 unsigned Rd, Rn, Rm;
11160
11161 Rd = inst.operands[0].reg;
11162 Rn = inst.operands[1].reg;
11163 Rm = 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_simd2 (void)
11176 {
11177 unsigned Rd, Rn, Rm;
11178
11179 Rd = inst.operands[0].reg;
11180 Rm = inst.operands[1].reg;
11181 Rn = inst.operands[2].reg;
11182
11183 reject_bad_reg (Rd);
11184 reject_bad_reg (Rn);
11185 reject_bad_reg (Rm);
11186
11187 inst.instruction |= Rd << 8;
11188 inst.instruction |= Rn << 16;
11189 inst.instruction |= Rm;
11190 }
11191
11192 static void
11193 do_t_smc (void)
11194 {
11195 unsigned int value = inst.reloc.exp.X_add_number;
11196 constraint (inst.reloc.exp.X_op != O_constant,
11197 _("expression too complex"));
11198 inst.reloc.type = BFD_RELOC_UNUSED;
11199 inst.instruction |= (value & 0xf000) >> 12;
11200 inst.instruction |= (value & 0x0ff0);
11201 inst.instruction |= (value & 0x000f) << 16;
11202 }
11203
11204 static void
11205 do_t_ssat_usat (int bias)
11206 {
11207 unsigned Rd, Rn;
11208
11209 Rd = inst.operands[0].reg;
11210 Rn = inst.operands[2].reg;
11211
11212 reject_bad_reg (Rd);
11213 reject_bad_reg (Rn);
11214
11215 inst.instruction |= Rd << 8;
11216 inst.instruction |= inst.operands[1].imm - bias;
11217 inst.instruction |= Rn << 16;
11218
11219 if (inst.operands[3].present)
11220 {
11221 offsetT shift_amount = inst.reloc.exp.X_add_number;
11222
11223 inst.reloc.type = BFD_RELOC_UNUSED;
11224
11225 constraint (inst.reloc.exp.X_op != O_constant,
11226 _("expression too complex"));
11227
11228 if (shift_amount != 0)
11229 {
11230 constraint (shift_amount > 31,
11231 _("shift expression is too large"));
11232
11233 if (inst.operands[3].shift_kind == SHIFT_ASR)
11234 inst.instruction |= 0x00200000; /* sh bit. */
11235
11236 inst.instruction |= (shift_amount & 0x1c) << 10;
11237 inst.instruction |= (shift_amount & 0x03) << 6;
11238 }
11239 }
11240 }
11241
11242 static void
11243 do_t_ssat (void)
11244 {
11245 do_t_ssat_usat (1);
11246 }
11247
11248 static void
11249 do_t_ssat16 (void)
11250 {
11251 unsigned Rd, Rn;
11252
11253 Rd = inst.operands[0].reg;
11254 Rn = inst.operands[2].reg;
11255
11256 reject_bad_reg (Rd);
11257 reject_bad_reg (Rn);
11258
11259 inst.instruction |= Rd << 8;
11260 inst.instruction |= inst.operands[1].imm - 1;
11261 inst.instruction |= Rn << 16;
11262 }
11263
11264 static void
11265 do_t_strex (void)
11266 {
11267 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11268 || inst.operands[2].postind || inst.operands[2].writeback
11269 || inst.operands[2].immisreg || inst.operands[2].shifted
11270 || inst.operands[2].negative,
11271 BAD_ADDR_MODE);
11272
11273 constraint (inst.operands[2].reg == REG_PC, BAD_PC);
11274
11275 inst.instruction |= inst.operands[0].reg << 8;
11276 inst.instruction |= inst.operands[1].reg << 12;
11277 inst.instruction |= inst.operands[2].reg << 16;
11278 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
11279 }
11280
11281 static void
11282 do_t_strexd (void)
11283 {
11284 if (!inst.operands[2].present)
11285 inst.operands[2].reg = inst.operands[1].reg + 1;
11286
11287 constraint (inst.operands[0].reg == inst.operands[1].reg
11288 || inst.operands[0].reg == inst.operands[2].reg
11289 || inst.operands[0].reg == inst.operands[3].reg,
11290 BAD_OVERLAP);
11291
11292 inst.instruction |= inst.operands[0].reg;
11293 inst.instruction |= inst.operands[1].reg << 12;
11294 inst.instruction |= inst.operands[2].reg << 8;
11295 inst.instruction |= inst.operands[3].reg << 16;
11296 }
11297
11298 static void
11299 do_t_sxtah (void)
11300 {
11301 unsigned Rd, Rn, Rm;
11302
11303 Rd = inst.operands[0].reg;
11304 Rn = inst.operands[1].reg;
11305 Rm = inst.operands[2].reg;
11306
11307 reject_bad_reg (Rd);
11308 reject_bad_reg (Rn);
11309 reject_bad_reg (Rm);
11310
11311 inst.instruction |= Rd << 8;
11312 inst.instruction |= Rn << 16;
11313 inst.instruction |= Rm;
11314 inst.instruction |= inst.operands[3].imm << 4;
11315 }
11316
11317 static void
11318 do_t_sxth (void)
11319 {
11320 unsigned Rd, Rm;
11321
11322 Rd = inst.operands[0].reg;
11323 Rm = inst.operands[1].reg;
11324
11325 reject_bad_reg (Rd);
11326 reject_bad_reg (Rm);
11327
11328 if (inst.instruction <= 0xffff
11329 && inst.size_req != 4
11330 && Rd <= 7 && Rm <= 7
11331 && (!inst.operands[2].present || inst.operands[2].imm == 0))
11332 {
11333 inst.instruction = THUMB_OP16 (inst.instruction);
11334 inst.instruction |= Rd;
11335 inst.instruction |= Rm << 3;
11336 }
11337 else if (unified_syntax)
11338 {
11339 if (inst.instruction <= 0xffff)
11340 inst.instruction = THUMB_OP32 (inst.instruction);
11341 inst.instruction |= Rd << 8;
11342 inst.instruction |= Rm;
11343 inst.instruction |= inst.operands[2].imm << 4;
11344 }
11345 else
11346 {
11347 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11348 _("Thumb encoding does not support rotation"));
11349 constraint (1, BAD_HIREG);
11350 }
11351 }
11352
11353 static void
11354 do_t_swi (void)
11355 {
11356 inst.reloc.type = BFD_RELOC_ARM_SWI;
11357 }
11358
11359 static void
11360 do_t_tb (void)
11361 {
11362 unsigned Rn, Rm;
11363 int half;
11364
11365 half = (inst.instruction & 0x10) != 0;
11366 set_it_insn_type_last ();
11367 constraint (inst.operands[0].immisreg,
11368 _("instruction requires register index"));
11369
11370 Rn = inst.operands[0].reg;
11371 Rm = inst.operands[0].imm;
11372
11373 constraint (Rn == REG_SP, BAD_SP);
11374 reject_bad_reg (Rm);
11375
11376 constraint (!half && inst.operands[0].shifted,
11377 _("instruction does not allow shifted index"));
11378 inst.instruction |= (Rn << 16) | Rm;
11379 }
11380
11381 static void
11382 do_t_usat (void)
11383 {
11384 do_t_ssat_usat (0);
11385 }
11386
11387 static void
11388 do_t_usat16 (void)
11389 {
11390 unsigned Rd, Rn;
11391
11392 Rd = inst.operands[0].reg;
11393 Rn = inst.operands[2].reg;
11394
11395 reject_bad_reg (Rd);
11396 reject_bad_reg (Rn);
11397
11398 inst.instruction |= Rd << 8;
11399 inst.instruction |= inst.operands[1].imm;
11400 inst.instruction |= Rn << 16;
11401 }
11402
11403 /* Neon instruction encoder helpers. */
11404
11405 /* Encodings for the different types for various Neon opcodes. */
11406
11407 /* An "invalid" code for the following tables. */
11408 #define N_INV -1u
11409
11410 struct neon_tab_entry
11411 {
11412 unsigned integer;
11413 unsigned float_or_poly;
11414 unsigned scalar_or_imm;
11415 };
11416
11417 /* Map overloaded Neon opcodes to their respective encodings. */
11418 #define NEON_ENC_TAB \
11419 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11420 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11421 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11422 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11423 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11424 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11425 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11426 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11427 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11428 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11429 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11430 /* Register variants of the following two instructions are encoded as
11431 vcge / vcgt with the operands reversed. */ \
11432 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11433 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
11434 X(vfma, N_INV, 0x0000c10, N_INV), \
11435 X(vfms, N_INV, 0x0200c10, N_INV), \
11436 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11437 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11438 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11439 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11440 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11441 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11442 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11443 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11444 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11445 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11446 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11447 X(vshl, 0x0000400, N_INV, 0x0800510), \
11448 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11449 X(vand, 0x0000110, N_INV, 0x0800030), \
11450 X(vbic, 0x0100110, N_INV, 0x0800030), \
11451 X(veor, 0x1000110, N_INV, N_INV), \
11452 X(vorn, 0x0300110, N_INV, 0x0800010), \
11453 X(vorr, 0x0200110, N_INV, 0x0800010), \
11454 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11455 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11456 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11457 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11458 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11459 X(vst1, 0x0000000, 0x0800000, N_INV), \
11460 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11461 X(vst2, 0x0000100, 0x0800100, N_INV), \
11462 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11463 X(vst3, 0x0000200, 0x0800200, N_INV), \
11464 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11465 X(vst4, 0x0000300, 0x0800300, N_INV), \
11466 X(vmovn, 0x1b20200, N_INV, N_INV), \
11467 X(vtrn, 0x1b20080, N_INV, N_INV), \
11468 X(vqmovn, 0x1b20200, N_INV, N_INV), \
11469 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11470 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
11471 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11472 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
11473 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11474 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
11475 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11476 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11477 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11478 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
11479
11480 enum neon_opc
11481 {
11482 #define X(OPC,I,F,S) N_MNEM_##OPC
11483 NEON_ENC_TAB
11484 #undef X
11485 };
11486
11487 static const struct neon_tab_entry neon_enc_tab[] =
11488 {
11489 #define X(OPC,I,F,S) { (I), (F), (S) }
11490 NEON_ENC_TAB
11491 #undef X
11492 };
11493
11494 /* Do not use these macros; instead, use NEON_ENCODE defined below. */
11495 #define NEON_ENC_INTEGER_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11496 #define NEON_ENC_ARMREG_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11497 #define NEON_ENC_POLY_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11498 #define NEON_ENC_FLOAT_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11499 #define NEON_ENC_SCALAR_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11500 #define NEON_ENC_IMMED_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11501 #define NEON_ENC_INTERLV_(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11502 #define NEON_ENC_LANE_(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11503 #define NEON_ENC_DUP_(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11504 #define NEON_ENC_SINGLE_(X) \
11505 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
11506 #define NEON_ENC_DOUBLE_(X) \
11507 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
11508
11509 #define NEON_ENCODE(type, inst) \
11510 do \
11511 { \
11512 inst.instruction = NEON_ENC_##type##_ (inst.instruction); \
11513 inst.is_neon = 1; \
11514 } \
11515 while (0)
11516
11517 #define check_neon_suffixes \
11518 do \
11519 { \
11520 if (!inst.error && inst.vectype.elems > 0 && !inst.is_neon) \
11521 { \
11522 as_bad (_("invalid neon suffix for non neon instruction")); \
11523 return; \
11524 } \
11525 } \
11526 while (0)
11527
11528 /* Define shapes for instruction operands. The following mnemonic characters
11529 are used in this table:
11530
11531 F - VFP S<n> register
11532 D - Neon D<n> register
11533 Q - Neon Q<n> register
11534 I - Immediate
11535 S - Scalar
11536 R - ARM register
11537 L - D<n> register list
11538
11539 This table is used to generate various data:
11540 - enumerations of the form NS_DDR to be used as arguments to
11541 neon_select_shape.
11542 - a table classifying shapes into single, double, quad, mixed.
11543 - a table used to drive neon_select_shape. */
11544
11545 #define NEON_SHAPE_DEF \
11546 X(3, (D, D, D), DOUBLE), \
11547 X(3, (Q, Q, Q), QUAD), \
11548 X(3, (D, D, I), DOUBLE), \
11549 X(3, (Q, Q, I), QUAD), \
11550 X(3, (D, D, S), DOUBLE), \
11551 X(3, (Q, Q, S), QUAD), \
11552 X(2, (D, D), DOUBLE), \
11553 X(2, (Q, Q), QUAD), \
11554 X(2, (D, S), DOUBLE), \
11555 X(2, (Q, S), QUAD), \
11556 X(2, (D, R), DOUBLE), \
11557 X(2, (Q, R), QUAD), \
11558 X(2, (D, I), DOUBLE), \
11559 X(2, (Q, I), QUAD), \
11560 X(3, (D, L, D), DOUBLE), \
11561 X(2, (D, Q), MIXED), \
11562 X(2, (Q, D), MIXED), \
11563 X(3, (D, Q, I), MIXED), \
11564 X(3, (Q, D, I), MIXED), \
11565 X(3, (Q, D, D), MIXED), \
11566 X(3, (D, Q, Q), MIXED), \
11567 X(3, (Q, Q, D), MIXED), \
11568 X(3, (Q, D, S), MIXED), \
11569 X(3, (D, Q, S), MIXED), \
11570 X(4, (D, D, D, I), DOUBLE), \
11571 X(4, (Q, Q, Q, I), QUAD), \
11572 X(2, (F, F), SINGLE), \
11573 X(3, (F, F, F), SINGLE), \
11574 X(2, (F, I), SINGLE), \
11575 X(2, (F, D), MIXED), \
11576 X(2, (D, F), MIXED), \
11577 X(3, (F, F, I), MIXED), \
11578 X(4, (R, R, F, F), SINGLE), \
11579 X(4, (F, F, R, R), SINGLE), \
11580 X(3, (D, R, R), DOUBLE), \
11581 X(3, (R, R, D), DOUBLE), \
11582 X(2, (S, R), SINGLE), \
11583 X(2, (R, S), SINGLE), \
11584 X(2, (F, R), SINGLE), \
11585 X(2, (R, F), SINGLE)
11586
11587 #define S2(A,B) NS_##A##B
11588 #define S3(A,B,C) NS_##A##B##C
11589 #define S4(A,B,C,D) NS_##A##B##C##D
11590
11591 #define X(N, L, C) S##N L
11592
11593 enum neon_shape
11594 {
11595 NEON_SHAPE_DEF,
11596 NS_NULL
11597 };
11598
11599 #undef X
11600 #undef S2
11601 #undef S3
11602 #undef S4
11603
11604 enum neon_shape_class
11605 {
11606 SC_SINGLE,
11607 SC_DOUBLE,
11608 SC_QUAD,
11609 SC_MIXED
11610 };
11611
11612 #define X(N, L, C) SC_##C
11613
11614 static enum neon_shape_class neon_shape_class[] =
11615 {
11616 NEON_SHAPE_DEF
11617 };
11618
11619 #undef X
11620
11621 enum neon_shape_el
11622 {
11623 SE_F,
11624 SE_D,
11625 SE_Q,
11626 SE_I,
11627 SE_S,
11628 SE_R,
11629 SE_L
11630 };
11631
11632 /* Register widths of above. */
11633 static unsigned neon_shape_el_size[] =
11634 {
11635 32,
11636 64,
11637 128,
11638 0,
11639 32,
11640 32,
11641 0
11642 };
11643
11644 struct neon_shape_info
11645 {
11646 unsigned els;
11647 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11648 };
11649
11650 #define S2(A,B) { SE_##A, SE_##B }
11651 #define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11652 #define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11653
11654 #define X(N, L, C) { N, S##N L }
11655
11656 static struct neon_shape_info neon_shape_tab[] =
11657 {
11658 NEON_SHAPE_DEF
11659 };
11660
11661 #undef X
11662 #undef S2
11663 #undef S3
11664 #undef S4
11665
11666 /* Bit masks used in type checking given instructions.
11667 'N_EQK' means the type must be the same as (or based on in some way) the key
11668 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11669 set, various other bits can be set as well in order to modify the meaning of
11670 the type constraint. */
11671
11672 enum neon_type_mask
11673 {
11674 N_S8 = 0x0000001,
11675 N_S16 = 0x0000002,
11676 N_S32 = 0x0000004,
11677 N_S64 = 0x0000008,
11678 N_U8 = 0x0000010,
11679 N_U16 = 0x0000020,
11680 N_U32 = 0x0000040,
11681 N_U64 = 0x0000080,
11682 N_I8 = 0x0000100,
11683 N_I16 = 0x0000200,
11684 N_I32 = 0x0000400,
11685 N_I64 = 0x0000800,
11686 N_8 = 0x0001000,
11687 N_16 = 0x0002000,
11688 N_32 = 0x0004000,
11689 N_64 = 0x0008000,
11690 N_P8 = 0x0010000,
11691 N_P16 = 0x0020000,
11692 N_F16 = 0x0040000,
11693 N_F32 = 0x0080000,
11694 N_F64 = 0x0100000,
11695 N_KEY = 0x1000000, /* Key element (main type specifier). */
11696 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
11697 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11698 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11699 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11700 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11701 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11702 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11703 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11704 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
11705 N_UTYP = 0,
11706 N_MAX_NONSPECIAL = N_F64
11707 };
11708
11709 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11710
11711 #define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11712 #define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11713 #define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11714 #define N_SUF_32 (N_SU_32 | N_F32)
11715 #define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11716 #define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11717
11718 /* Pass this as the first type argument to neon_check_type to ignore types
11719 altogether. */
11720 #define N_IGNORE_TYPE (N_KEY | N_EQK)
11721
11722 /* Select a "shape" for the current instruction (describing register types or
11723 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11724 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11725 function of operand parsing, so this function doesn't need to be called.
11726 Shapes should be listed in order of decreasing length. */
11727
11728 static enum neon_shape
11729 neon_select_shape (enum neon_shape shape, ...)
11730 {
11731 va_list ap;
11732 enum neon_shape first_shape = shape;
11733
11734 /* Fix missing optional operands. FIXME: we don't know at this point how
11735 many arguments we should have, so this makes the assumption that we have
11736 > 1. This is true of all current Neon opcodes, I think, but may not be
11737 true in the future. */
11738 if (!inst.operands[1].present)
11739 inst.operands[1] = inst.operands[0];
11740
11741 va_start (ap, shape);
11742
11743 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
11744 {
11745 unsigned j;
11746 int matches = 1;
11747
11748 for (j = 0; j < neon_shape_tab[shape].els; j++)
11749 {
11750 if (!inst.operands[j].present)
11751 {
11752 matches = 0;
11753 break;
11754 }
11755
11756 switch (neon_shape_tab[shape].el[j])
11757 {
11758 case SE_F:
11759 if (!(inst.operands[j].isreg
11760 && inst.operands[j].isvec
11761 && inst.operands[j].issingle
11762 && !inst.operands[j].isquad))
11763 matches = 0;
11764 break;
11765
11766 case SE_D:
11767 if (!(inst.operands[j].isreg
11768 && inst.operands[j].isvec
11769 && !inst.operands[j].isquad
11770 && !inst.operands[j].issingle))
11771 matches = 0;
11772 break;
11773
11774 case SE_R:
11775 if (!(inst.operands[j].isreg
11776 && !inst.operands[j].isvec))
11777 matches = 0;
11778 break;
11779
11780 case SE_Q:
11781 if (!(inst.operands[j].isreg
11782 && inst.operands[j].isvec
11783 && inst.operands[j].isquad
11784 && !inst.operands[j].issingle))
11785 matches = 0;
11786 break;
11787
11788 case SE_I:
11789 if (!(!inst.operands[j].isreg
11790 && !inst.operands[j].isscalar))
11791 matches = 0;
11792 break;
11793
11794 case SE_S:
11795 if (!(!inst.operands[j].isreg
11796 && inst.operands[j].isscalar))
11797 matches = 0;
11798 break;
11799
11800 case SE_L:
11801 break;
11802 }
11803 if (!matches)
11804 break;
11805 }
11806 if (matches)
11807 break;
11808 }
11809
11810 va_end (ap);
11811
11812 if (shape == NS_NULL && first_shape != NS_NULL)
11813 first_error (_("invalid instruction shape"));
11814
11815 return shape;
11816 }
11817
11818 /* True if SHAPE is predominantly a quadword operation (most of the time, this
11819 means the Q bit should be set). */
11820
11821 static int
11822 neon_quad (enum neon_shape shape)
11823 {
11824 return neon_shape_class[shape] == SC_QUAD;
11825 }
11826
11827 static void
11828 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11829 unsigned *g_size)
11830 {
11831 /* Allow modification to be made to types which are constrained to be
11832 based on the key element, based on bits set alongside N_EQK. */
11833 if ((typebits & N_EQK) != 0)
11834 {
11835 if ((typebits & N_HLF) != 0)
11836 *g_size /= 2;
11837 else if ((typebits & N_DBL) != 0)
11838 *g_size *= 2;
11839 if ((typebits & N_SGN) != 0)
11840 *g_type = NT_signed;
11841 else if ((typebits & N_UNS) != 0)
11842 *g_type = NT_unsigned;
11843 else if ((typebits & N_INT) != 0)
11844 *g_type = NT_integer;
11845 else if ((typebits & N_FLT) != 0)
11846 *g_type = NT_float;
11847 else if ((typebits & N_SIZ) != 0)
11848 *g_type = NT_untyped;
11849 }
11850 }
11851
11852 /* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11853 operand type, i.e. the single type specified in a Neon instruction when it
11854 is the only one given. */
11855
11856 static struct neon_type_el
11857 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11858 {
11859 struct neon_type_el dest = *key;
11860
11861 gas_assert ((thisarg & N_EQK) != 0);
11862
11863 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11864
11865 return dest;
11866 }
11867
11868 /* Convert Neon type and size into compact bitmask representation. */
11869
11870 static enum neon_type_mask
11871 type_chk_of_el_type (enum neon_el_type type, unsigned size)
11872 {
11873 switch (type)
11874 {
11875 case NT_untyped:
11876 switch (size)
11877 {
11878 case 8: return N_8;
11879 case 16: return N_16;
11880 case 32: return N_32;
11881 case 64: return N_64;
11882 default: ;
11883 }
11884 break;
11885
11886 case NT_integer:
11887 switch (size)
11888 {
11889 case 8: return N_I8;
11890 case 16: return N_I16;
11891 case 32: return N_I32;
11892 case 64: return N_I64;
11893 default: ;
11894 }
11895 break;
11896
11897 case NT_float:
11898 switch (size)
11899 {
11900 case 16: return N_F16;
11901 case 32: return N_F32;
11902 case 64: return N_F64;
11903 default: ;
11904 }
11905 break;
11906
11907 case NT_poly:
11908 switch (size)
11909 {
11910 case 8: return N_P8;
11911 case 16: return N_P16;
11912 default: ;
11913 }
11914 break;
11915
11916 case NT_signed:
11917 switch (size)
11918 {
11919 case 8: return N_S8;
11920 case 16: return N_S16;
11921 case 32: return N_S32;
11922 case 64: return N_S64;
11923 default: ;
11924 }
11925 break;
11926
11927 case NT_unsigned:
11928 switch (size)
11929 {
11930 case 8: return N_U8;
11931 case 16: return N_U16;
11932 case 32: return N_U32;
11933 case 64: return N_U64;
11934 default: ;
11935 }
11936 break;
11937
11938 default: ;
11939 }
11940
11941 return N_UTYP;
11942 }
11943
11944 /* Convert compact Neon bitmask type representation to a type and size. Only
11945 handles the case where a single bit is set in the mask. */
11946
11947 static int
11948 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11949 enum neon_type_mask mask)
11950 {
11951 if ((mask & N_EQK) != 0)
11952 return FAIL;
11953
11954 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11955 *size = 8;
11956 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
11957 *size = 16;
11958 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
11959 *size = 32;
11960 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
11961 *size = 64;
11962 else
11963 return FAIL;
11964
11965 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11966 *type = NT_signed;
11967 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
11968 *type = NT_unsigned;
11969 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
11970 *type = NT_integer;
11971 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
11972 *type = NT_untyped;
11973 else if ((mask & (N_P8 | N_P16)) != 0)
11974 *type = NT_poly;
11975 else if ((mask & (N_F32 | N_F64)) != 0)
11976 *type = NT_float;
11977 else
11978 return FAIL;
11979
11980 return SUCCESS;
11981 }
11982
11983 /* Modify a bitmask of allowed types. This is only needed for type
11984 relaxation. */
11985
11986 static unsigned
11987 modify_types_allowed (unsigned allowed, unsigned mods)
11988 {
11989 unsigned size;
11990 enum neon_el_type type;
11991 unsigned destmask;
11992 int i;
11993
11994 destmask = 0;
11995
11996 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11997 {
11998 if (el_type_of_type_chk (&type, &size,
11999 (enum neon_type_mask) (allowed & i)) == SUCCESS)
12000 {
12001 neon_modify_type_size (mods, &type, &size);
12002 destmask |= type_chk_of_el_type (type, size);
12003 }
12004 }
12005
12006 return destmask;
12007 }
12008
12009 /* Check type and return type classification.
12010 The manual states (paraphrase): If one datatype is given, it indicates the
12011 type given in:
12012 - the second operand, if there is one
12013 - the operand, if there is no second operand
12014 - the result, if there are no operands.
12015 This isn't quite good enough though, so we use a concept of a "key" datatype
12016 which is set on a per-instruction basis, which is the one which matters when
12017 only one data type is written.
12018 Note: this function has side-effects (e.g. filling in missing operands). All
12019 Neon instructions should call it before performing bit encoding. */
12020
12021 static struct neon_type_el
12022 neon_check_type (unsigned els, enum neon_shape ns, ...)
12023 {
12024 va_list ap;
12025 unsigned i, pass, key_el = 0;
12026 unsigned types[NEON_MAX_TYPE_ELS];
12027 enum neon_el_type k_type = NT_invtype;
12028 unsigned k_size = -1u;
12029 struct neon_type_el badtype = {NT_invtype, -1};
12030 unsigned key_allowed = 0;
12031
12032 /* Optional registers in Neon instructions are always (not) in operand 1.
12033 Fill in the missing operand here, if it was omitted. */
12034 if (els > 1 && !inst.operands[1].present)
12035 inst.operands[1] = inst.operands[0];
12036
12037 /* Suck up all the varargs. */
12038 va_start (ap, ns);
12039 for (i = 0; i < els; i++)
12040 {
12041 unsigned thisarg = va_arg (ap, unsigned);
12042 if (thisarg == N_IGNORE_TYPE)
12043 {
12044 va_end (ap);
12045 return badtype;
12046 }
12047 types[i] = thisarg;
12048 if ((thisarg & N_KEY) != 0)
12049 key_el = i;
12050 }
12051 va_end (ap);
12052
12053 if (inst.vectype.elems > 0)
12054 for (i = 0; i < els; i++)
12055 if (inst.operands[i].vectype.type != NT_invtype)
12056 {
12057 first_error (_("types specified in both the mnemonic and operands"));
12058 return badtype;
12059 }
12060
12061 /* Duplicate inst.vectype elements here as necessary.
12062 FIXME: No idea if this is exactly the same as the ARM assembler,
12063 particularly when an insn takes one register and one non-register
12064 operand. */
12065 if (inst.vectype.elems == 1 && els > 1)
12066 {
12067 unsigned j;
12068 inst.vectype.elems = els;
12069 inst.vectype.el[key_el] = inst.vectype.el[0];
12070 for (j = 0; j < els; j++)
12071 if (j != key_el)
12072 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12073 types[j]);
12074 }
12075 else if (inst.vectype.elems == 0 && els > 0)
12076 {
12077 unsigned j;
12078 /* No types were given after the mnemonic, so look for types specified
12079 after each operand. We allow some flexibility here; as long as the
12080 "key" operand has a type, we can infer the others. */
12081 for (j = 0; j < els; j++)
12082 if (inst.operands[j].vectype.type != NT_invtype)
12083 inst.vectype.el[j] = inst.operands[j].vectype;
12084
12085 if (inst.operands[key_el].vectype.type != NT_invtype)
12086 {
12087 for (j = 0; j < els; j++)
12088 if (inst.operands[j].vectype.type == NT_invtype)
12089 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
12090 types[j]);
12091 }
12092 else
12093 {
12094 first_error (_("operand types can't be inferred"));
12095 return badtype;
12096 }
12097 }
12098 else if (inst.vectype.elems != els)
12099 {
12100 first_error (_("type specifier has the wrong number of parts"));
12101 return badtype;
12102 }
12103
12104 for (pass = 0; pass < 2; pass++)
12105 {
12106 for (i = 0; i < els; i++)
12107 {
12108 unsigned thisarg = types[i];
12109 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12110 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12111 enum neon_el_type g_type = inst.vectype.el[i].type;
12112 unsigned g_size = inst.vectype.el[i].size;
12113
12114 /* Decay more-specific signed & unsigned types to sign-insensitive
12115 integer types if sign-specific variants are unavailable. */
12116 if ((g_type == NT_signed || g_type == NT_unsigned)
12117 && (types_allowed & N_SU_ALL) == 0)
12118 g_type = NT_integer;
12119
12120 /* If only untyped args are allowed, decay any more specific types to
12121 them. Some instructions only care about signs for some element
12122 sizes, so handle that properly. */
12123 if ((g_size == 8 && (types_allowed & N_8) != 0)
12124 || (g_size == 16 && (types_allowed & N_16) != 0)
12125 || (g_size == 32 && (types_allowed & N_32) != 0)
12126 || (g_size == 64 && (types_allowed & N_64) != 0))
12127 g_type = NT_untyped;
12128
12129 if (pass == 0)
12130 {
12131 if ((thisarg & N_KEY) != 0)
12132 {
12133 k_type = g_type;
12134 k_size = g_size;
12135 key_allowed = thisarg & ~N_KEY;
12136 }
12137 }
12138 else
12139 {
12140 if ((thisarg & N_VFP) != 0)
12141 {
12142 enum neon_shape_el regshape;
12143 unsigned regwidth, match;
12144
12145 /* PR 11136: Catch the case where we are passed a shape of NS_NULL. */
12146 if (ns == NS_NULL)
12147 {
12148 first_error (_("invalid instruction shape"));
12149 return badtype;
12150 }
12151 regshape = neon_shape_tab[ns].el[i];
12152 regwidth = neon_shape_el_size[regshape];
12153
12154 /* In VFP mode, operands must match register widths. If we
12155 have a key operand, use its width, else use the width of
12156 the current operand. */
12157 if (k_size != -1u)
12158 match = k_size;
12159 else
12160 match = g_size;
12161
12162 if (regwidth != match)
12163 {
12164 first_error (_("operand size must match register width"));
12165 return badtype;
12166 }
12167 }
12168
12169 if ((thisarg & N_EQK) == 0)
12170 {
12171 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12172
12173 if ((given_type & types_allowed) == 0)
12174 {
12175 first_error (_("bad type in Neon instruction"));
12176 return badtype;
12177 }
12178 }
12179 else
12180 {
12181 enum neon_el_type mod_k_type = k_type;
12182 unsigned mod_k_size = k_size;
12183 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12184 if (g_type != mod_k_type || g_size != mod_k_size)
12185 {
12186 first_error (_("inconsistent types in Neon instruction"));
12187 return badtype;
12188 }
12189 }
12190 }
12191 }
12192 }
12193
12194 return inst.vectype.el[key_el];
12195 }
12196
12197 /* Neon-style VFP instruction forwarding. */
12198
12199 /* Thumb VFP instructions have 0xE in the condition field. */
12200
12201 static void
12202 do_vfp_cond_or_thumb (void)
12203 {
12204 inst.is_neon = 1;
12205
12206 if (thumb_mode)
12207 inst.instruction |= 0xe0000000;
12208 else
12209 inst.instruction |= inst.cond << 28;
12210 }
12211
12212 /* Look up and encode a simple mnemonic, for use as a helper function for the
12213 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12214 etc. It is assumed that operand parsing has already been done, and that the
12215 operands are in the form expected by the given opcode (this isn't necessarily
12216 the same as the form in which they were parsed, hence some massaging must
12217 take place before this function is called).
12218 Checks current arch version against that in the looked-up opcode. */
12219
12220 static void
12221 do_vfp_nsyn_opcode (const char *opname)
12222 {
12223 const struct asm_opcode *opcode;
12224
12225 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
12226
12227 if (!opcode)
12228 abort ();
12229
12230 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12231 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12232 _(BAD_FPU));
12233
12234 inst.is_neon = 1;
12235
12236 if (thumb_mode)
12237 {
12238 inst.instruction = opcode->tvalue;
12239 opcode->tencode ();
12240 }
12241 else
12242 {
12243 inst.instruction = (inst.cond << 28) | opcode->avalue;
12244 opcode->aencode ();
12245 }
12246 }
12247
12248 static void
12249 do_vfp_nsyn_add_sub (enum neon_shape rs)
12250 {
12251 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12252
12253 if (rs == NS_FFF)
12254 {
12255 if (is_add)
12256 do_vfp_nsyn_opcode ("fadds");
12257 else
12258 do_vfp_nsyn_opcode ("fsubs");
12259 }
12260 else
12261 {
12262 if (is_add)
12263 do_vfp_nsyn_opcode ("faddd");
12264 else
12265 do_vfp_nsyn_opcode ("fsubd");
12266 }
12267 }
12268
12269 /* Check operand types to see if this is a VFP instruction, and if so call
12270 PFN (). */
12271
12272 static int
12273 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12274 {
12275 enum neon_shape rs;
12276 struct neon_type_el et;
12277
12278 switch (args)
12279 {
12280 case 2:
12281 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12282 et = neon_check_type (2, rs,
12283 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12284 break;
12285
12286 case 3:
12287 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12288 et = neon_check_type (3, rs,
12289 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12290 break;
12291
12292 default:
12293 abort ();
12294 }
12295
12296 if (et.type != NT_invtype)
12297 {
12298 pfn (rs);
12299 return SUCCESS;
12300 }
12301
12302 inst.error = NULL;
12303 return FAIL;
12304 }
12305
12306 static void
12307 do_vfp_nsyn_mla_mls (enum neon_shape rs)
12308 {
12309 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
12310
12311 if (rs == NS_FFF)
12312 {
12313 if (is_mla)
12314 do_vfp_nsyn_opcode ("fmacs");
12315 else
12316 do_vfp_nsyn_opcode ("fnmacs");
12317 }
12318 else
12319 {
12320 if (is_mla)
12321 do_vfp_nsyn_opcode ("fmacd");
12322 else
12323 do_vfp_nsyn_opcode ("fnmacd");
12324 }
12325 }
12326
12327 static void
12328 do_vfp_nsyn_fma_fms (enum neon_shape rs)
12329 {
12330 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12331
12332 if (rs == NS_FFF)
12333 {
12334 if (is_fma)
12335 do_vfp_nsyn_opcode ("ffmas");
12336 else
12337 do_vfp_nsyn_opcode ("ffnmas");
12338 }
12339 else
12340 {
12341 if (is_fma)
12342 do_vfp_nsyn_opcode ("ffmad");
12343 else
12344 do_vfp_nsyn_opcode ("ffnmad");
12345 }
12346 }
12347
12348 static void
12349 do_vfp_nsyn_mul (enum neon_shape rs)
12350 {
12351 if (rs == NS_FFF)
12352 do_vfp_nsyn_opcode ("fmuls");
12353 else
12354 do_vfp_nsyn_opcode ("fmuld");
12355 }
12356
12357 static void
12358 do_vfp_nsyn_abs_neg (enum neon_shape rs)
12359 {
12360 int is_neg = (inst.instruction & 0x80) != 0;
12361 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12362
12363 if (rs == NS_FF)
12364 {
12365 if (is_neg)
12366 do_vfp_nsyn_opcode ("fnegs");
12367 else
12368 do_vfp_nsyn_opcode ("fabss");
12369 }
12370 else
12371 {
12372 if (is_neg)
12373 do_vfp_nsyn_opcode ("fnegd");
12374 else
12375 do_vfp_nsyn_opcode ("fabsd");
12376 }
12377 }
12378
12379 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12380 insns belong to Neon, and are handled elsewhere. */
12381
12382 static void
12383 do_vfp_nsyn_ldm_stm (int is_dbmode)
12384 {
12385 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12386 if (is_ldm)
12387 {
12388 if (is_dbmode)
12389 do_vfp_nsyn_opcode ("fldmdbs");
12390 else
12391 do_vfp_nsyn_opcode ("fldmias");
12392 }
12393 else
12394 {
12395 if (is_dbmode)
12396 do_vfp_nsyn_opcode ("fstmdbs");
12397 else
12398 do_vfp_nsyn_opcode ("fstmias");
12399 }
12400 }
12401
12402 static void
12403 do_vfp_nsyn_sqrt (void)
12404 {
12405 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12406 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12407
12408 if (rs == NS_FF)
12409 do_vfp_nsyn_opcode ("fsqrts");
12410 else
12411 do_vfp_nsyn_opcode ("fsqrtd");
12412 }
12413
12414 static void
12415 do_vfp_nsyn_div (void)
12416 {
12417 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12418 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12419 N_F32 | N_F64 | N_KEY | N_VFP);
12420
12421 if (rs == NS_FFF)
12422 do_vfp_nsyn_opcode ("fdivs");
12423 else
12424 do_vfp_nsyn_opcode ("fdivd");
12425 }
12426
12427 static void
12428 do_vfp_nsyn_nmul (void)
12429 {
12430 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12431 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12432 N_F32 | N_F64 | N_KEY | N_VFP);
12433
12434 if (rs == NS_FFF)
12435 {
12436 NEON_ENCODE (SINGLE, inst);
12437 do_vfp_sp_dyadic ();
12438 }
12439 else
12440 {
12441 NEON_ENCODE (DOUBLE, inst);
12442 do_vfp_dp_rd_rn_rm ();
12443 }
12444 do_vfp_cond_or_thumb ();
12445 }
12446
12447 static void
12448 do_vfp_nsyn_cmp (void)
12449 {
12450 if (inst.operands[1].isreg)
12451 {
12452 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12453 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12454
12455 if (rs == NS_FF)
12456 {
12457 NEON_ENCODE (SINGLE, inst);
12458 do_vfp_sp_monadic ();
12459 }
12460 else
12461 {
12462 NEON_ENCODE (DOUBLE, inst);
12463 do_vfp_dp_rd_rm ();
12464 }
12465 }
12466 else
12467 {
12468 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12469 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12470
12471 switch (inst.instruction & 0x0fffffff)
12472 {
12473 case N_MNEM_vcmp:
12474 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12475 break;
12476 case N_MNEM_vcmpe:
12477 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12478 break;
12479 default:
12480 abort ();
12481 }
12482
12483 if (rs == NS_FI)
12484 {
12485 NEON_ENCODE (SINGLE, inst);
12486 do_vfp_sp_compare_z ();
12487 }
12488 else
12489 {
12490 NEON_ENCODE (DOUBLE, inst);
12491 do_vfp_dp_rd ();
12492 }
12493 }
12494 do_vfp_cond_or_thumb ();
12495 }
12496
12497 static void
12498 nsyn_insert_sp (void)
12499 {
12500 inst.operands[1] = inst.operands[0];
12501 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
12502 inst.operands[0].reg = REG_SP;
12503 inst.operands[0].isreg = 1;
12504 inst.operands[0].writeback = 1;
12505 inst.operands[0].present = 1;
12506 }
12507
12508 static void
12509 do_vfp_nsyn_push (void)
12510 {
12511 nsyn_insert_sp ();
12512 if (inst.operands[1].issingle)
12513 do_vfp_nsyn_opcode ("fstmdbs");
12514 else
12515 do_vfp_nsyn_opcode ("fstmdbd");
12516 }
12517
12518 static void
12519 do_vfp_nsyn_pop (void)
12520 {
12521 nsyn_insert_sp ();
12522 if (inst.operands[1].issingle)
12523 do_vfp_nsyn_opcode ("fldmias");
12524 else
12525 do_vfp_nsyn_opcode ("fldmiad");
12526 }
12527
12528 /* Fix up Neon data-processing instructions, ORing in the correct bits for
12529 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12530
12531 static void
12532 neon_dp_fixup (struct arm_it* insn)
12533 {
12534 unsigned int i = insn->instruction;
12535 insn->is_neon = 1;
12536
12537 if (thumb_mode)
12538 {
12539 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12540 if (i & (1 << 24))
12541 i |= 1 << 28;
12542
12543 i &= ~(1 << 24);
12544
12545 i |= 0xef000000;
12546 }
12547 else
12548 i |= 0xf2000000;
12549
12550 insn->instruction = i;
12551 }
12552
12553 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12554 (0, 1, 2, 3). */
12555
12556 static unsigned
12557 neon_logbits (unsigned x)
12558 {
12559 return ffs (x) - 4;
12560 }
12561
12562 #define LOW4(R) ((R) & 0xf)
12563 #define HI1(R) (((R) >> 4) & 1)
12564
12565 /* Encode insns with bit pattern:
12566
12567 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12568 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
12569
12570 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12571 different meaning for some instruction. */
12572
12573 static void
12574 neon_three_same (int isquad, int ubit, int size)
12575 {
12576 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12577 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12578 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12579 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12580 inst.instruction |= LOW4 (inst.operands[2].reg);
12581 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12582 inst.instruction |= (isquad != 0) << 6;
12583 inst.instruction |= (ubit != 0) << 24;
12584 if (size != -1)
12585 inst.instruction |= neon_logbits (size) << 20;
12586
12587 neon_dp_fixup (&inst);
12588 }
12589
12590 /* Encode instructions of the form:
12591
12592 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12593 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
12594
12595 Don't write size if SIZE == -1. */
12596
12597 static void
12598 neon_two_same (int qbit, int ubit, int size)
12599 {
12600 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12601 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12602 inst.instruction |= LOW4 (inst.operands[1].reg);
12603 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12604 inst.instruction |= (qbit != 0) << 6;
12605 inst.instruction |= (ubit != 0) << 24;
12606
12607 if (size != -1)
12608 inst.instruction |= neon_logbits (size) << 18;
12609
12610 neon_dp_fixup (&inst);
12611 }
12612
12613 /* Neon instruction encoders, in approximate order of appearance. */
12614
12615 static void
12616 do_neon_dyadic_i_su (void)
12617 {
12618 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12619 struct neon_type_el et = neon_check_type (3, rs,
12620 N_EQK, N_EQK, N_SU_32 | N_KEY);
12621 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12622 }
12623
12624 static void
12625 do_neon_dyadic_i64_su (void)
12626 {
12627 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12628 struct neon_type_el et = neon_check_type (3, rs,
12629 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12630 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12631 }
12632
12633 static void
12634 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12635 unsigned immbits)
12636 {
12637 unsigned size = et.size >> 3;
12638 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12639 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12640 inst.instruction |= LOW4 (inst.operands[1].reg);
12641 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12642 inst.instruction |= (isquad != 0) << 6;
12643 inst.instruction |= immbits << 16;
12644 inst.instruction |= (size >> 3) << 7;
12645 inst.instruction |= (size & 0x7) << 19;
12646 if (write_ubit)
12647 inst.instruction |= (uval != 0) << 24;
12648
12649 neon_dp_fixup (&inst);
12650 }
12651
12652 static void
12653 do_neon_shl_imm (void)
12654 {
12655 if (!inst.operands[2].isreg)
12656 {
12657 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12658 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12659 NEON_ENCODE (IMMED, inst);
12660 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
12661 }
12662 else
12663 {
12664 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12665 struct neon_type_el et = neon_check_type (3, rs,
12666 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12667 unsigned int tmp;
12668
12669 /* VSHL/VQSHL 3-register variants have syntax such as:
12670 vshl.xx Dd, Dm, Dn
12671 whereas other 3-register operations encoded by neon_three_same have
12672 syntax like:
12673 vadd.xx Dd, Dn, Dm
12674 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12675 here. */
12676 tmp = inst.operands[2].reg;
12677 inst.operands[2].reg = inst.operands[1].reg;
12678 inst.operands[1].reg = tmp;
12679 NEON_ENCODE (INTEGER, inst);
12680 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12681 }
12682 }
12683
12684 static void
12685 do_neon_qshl_imm (void)
12686 {
12687 if (!inst.operands[2].isreg)
12688 {
12689 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12690 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12691
12692 NEON_ENCODE (IMMED, inst);
12693 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12694 inst.operands[2].imm);
12695 }
12696 else
12697 {
12698 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12699 struct neon_type_el et = neon_check_type (3, rs,
12700 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12701 unsigned int tmp;
12702
12703 /* See note in do_neon_shl_imm. */
12704 tmp = inst.operands[2].reg;
12705 inst.operands[2].reg = inst.operands[1].reg;
12706 inst.operands[1].reg = tmp;
12707 NEON_ENCODE (INTEGER, inst);
12708 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12709 }
12710 }
12711
12712 static void
12713 do_neon_rshl (void)
12714 {
12715 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12716 struct neon_type_el et = neon_check_type (3, rs,
12717 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12718 unsigned int tmp;
12719
12720 tmp = inst.operands[2].reg;
12721 inst.operands[2].reg = inst.operands[1].reg;
12722 inst.operands[1].reg = tmp;
12723 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12724 }
12725
12726 static int
12727 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12728 {
12729 /* Handle .I8 pseudo-instructions. */
12730 if (size == 8)
12731 {
12732 /* Unfortunately, this will make everything apart from zero out-of-range.
12733 FIXME is this the intended semantics? There doesn't seem much point in
12734 accepting .I8 if so. */
12735 immediate |= immediate << 8;
12736 size = 16;
12737 }
12738
12739 if (size >= 32)
12740 {
12741 if (immediate == (immediate & 0x000000ff))
12742 {
12743 *immbits = immediate;
12744 return 0x1;
12745 }
12746 else if (immediate == (immediate & 0x0000ff00))
12747 {
12748 *immbits = immediate >> 8;
12749 return 0x3;
12750 }
12751 else if (immediate == (immediate & 0x00ff0000))
12752 {
12753 *immbits = immediate >> 16;
12754 return 0x5;
12755 }
12756 else if (immediate == (immediate & 0xff000000))
12757 {
12758 *immbits = immediate >> 24;
12759 return 0x7;
12760 }
12761 if ((immediate & 0xffff) != (immediate >> 16))
12762 goto bad_immediate;
12763 immediate &= 0xffff;
12764 }
12765
12766 if (immediate == (immediate & 0x000000ff))
12767 {
12768 *immbits = immediate;
12769 return 0x9;
12770 }
12771 else if (immediate == (immediate & 0x0000ff00))
12772 {
12773 *immbits = immediate >> 8;
12774 return 0xb;
12775 }
12776
12777 bad_immediate:
12778 first_error (_("immediate value out of range"));
12779 return FAIL;
12780 }
12781
12782 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12783 A, B, C, D. */
12784
12785 static int
12786 neon_bits_same_in_bytes (unsigned imm)
12787 {
12788 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12789 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12790 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12791 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12792 }
12793
12794 /* For immediate of above form, return 0bABCD. */
12795
12796 static unsigned
12797 neon_squash_bits (unsigned imm)
12798 {
12799 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12800 | ((imm & 0x01000000) >> 21);
12801 }
12802
12803 /* Compress quarter-float representation to 0b...000 abcdefgh. */
12804
12805 static unsigned
12806 neon_qfloat_bits (unsigned imm)
12807 {
12808 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
12809 }
12810
12811 /* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12812 the instruction. *OP is passed as the initial value of the op field, and
12813 may be set to a different value depending on the constant (i.e.
12814 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
12815 MVN). If the immediate looks like a repeated pattern then also
12816 try smaller element sizes. */
12817
12818 static int
12819 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12820 unsigned *immbits, int *op, int size,
12821 enum neon_el_type type)
12822 {
12823 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12824 float. */
12825 if (type == NT_float && !float_p)
12826 return FAIL;
12827
12828 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12829 {
12830 if (size != 32 || *op == 1)
12831 return FAIL;
12832 *immbits = neon_qfloat_bits (immlo);
12833 return 0xf;
12834 }
12835
12836 if (size == 64)
12837 {
12838 if (neon_bits_same_in_bytes (immhi)
12839 && neon_bits_same_in_bytes (immlo))
12840 {
12841 if (*op == 1)
12842 return FAIL;
12843 *immbits = (neon_squash_bits (immhi) << 4)
12844 | neon_squash_bits (immlo);
12845 *op = 1;
12846 return 0xe;
12847 }
12848
12849 if (immhi != immlo)
12850 return FAIL;
12851 }
12852
12853 if (size >= 32)
12854 {
12855 if (immlo == (immlo & 0x000000ff))
12856 {
12857 *immbits = immlo;
12858 return 0x0;
12859 }
12860 else if (immlo == (immlo & 0x0000ff00))
12861 {
12862 *immbits = immlo >> 8;
12863 return 0x2;
12864 }
12865 else if (immlo == (immlo & 0x00ff0000))
12866 {
12867 *immbits = immlo >> 16;
12868 return 0x4;
12869 }
12870 else if (immlo == (immlo & 0xff000000))
12871 {
12872 *immbits = immlo >> 24;
12873 return 0x6;
12874 }
12875 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12876 {
12877 *immbits = (immlo >> 8) & 0xff;
12878 return 0xc;
12879 }
12880 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12881 {
12882 *immbits = (immlo >> 16) & 0xff;
12883 return 0xd;
12884 }
12885
12886 if ((immlo & 0xffff) != (immlo >> 16))
12887 return FAIL;
12888 immlo &= 0xffff;
12889 }
12890
12891 if (size >= 16)
12892 {
12893 if (immlo == (immlo & 0x000000ff))
12894 {
12895 *immbits = immlo;
12896 return 0x8;
12897 }
12898 else if (immlo == (immlo & 0x0000ff00))
12899 {
12900 *immbits = immlo >> 8;
12901 return 0xa;
12902 }
12903
12904 if ((immlo & 0xff) != (immlo >> 8))
12905 return FAIL;
12906 immlo &= 0xff;
12907 }
12908
12909 if (immlo == (immlo & 0x000000ff))
12910 {
12911 /* Don't allow MVN with 8-bit immediate. */
12912 if (*op == 1)
12913 return FAIL;
12914 *immbits = immlo;
12915 return 0xe;
12916 }
12917
12918 return FAIL;
12919 }
12920
12921 /* Write immediate bits [7:0] to the following locations:
12922
12923 |28/24|23 19|18 16|15 4|3 0|
12924 | 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|
12925
12926 This function is used by VMOV/VMVN/VORR/VBIC. */
12927
12928 static void
12929 neon_write_immbits (unsigned immbits)
12930 {
12931 inst.instruction |= immbits & 0xf;
12932 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12933 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12934 }
12935
12936 /* Invert low-order SIZE bits of XHI:XLO. */
12937
12938 static void
12939 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12940 {
12941 unsigned immlo = xlo ? *xlo : 0;
12942 unsigned immhi = xhi ? *xhi : 0;
12943
12944 switch (size)
12945 {
12946 case 8:
12947 immlo = (~immlo) & 0xff;
12948 break;
12949
12950 case 16:
12951 immlo = (~immlo) & 0xffff;
12952 break;
12953
12954 case 64:
12955 immhi = (~immhi) & 0xffffffff;
12956 /* fall through. */
12957
12958 case 32:
12959 immlo = (~immlo) & 0xffffffff;
12960 break;
12961
12962 default:
12963 abort ();
12964 }
12965
12966 if (xlo)
12967 *xlo = immlo;
12968
12969 if (xhi)
12970 *xhi = immhi;
12971 }
12972
12973 static void
12974 do_neon_logic (void)
12975 {
12976 if (inst.operands[2].present && inst.operands[2].isreg)
12977 {
12978 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12979 neon_check_type (3, rs, N_IGNORE_TYPE);
12980 /* U bit and size field were set as part of the bitmask. */
12981 NEON_ENCODE (INTEGER, inst);
12982 neon_three_same (neon_quad (rs), 0, -1);
12983 }
12984 else
12985 {
12986 const int three_ops_form = (inst.operands[2].present
12987 && !inst.operands[2].isreg);
12988 const int immoperand = (three_ops_form ? 2 : 1);
12989 enum neon_shape rs = (three_ops_form
12990 ? neon_select_shape (NS_DDI, NS_QQI, NS_NULL)
12991 : neon_select_shape (NS_DI, NS_QI, NS_NULL));
12992 struct neon_type_el et = neon_check_type (2, rs,
12993 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
12994 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
12995 unsigned immbits;
12996 int cmode;
12997
12998 if (et.type == NT_invtype)
12999 return;
13000
13001 if (three_ops_form)
13002 constraint (inst.operands[0].reg != inst.operands[1].reg,
13003 _("first and second operands shall be the same register"));
13004
13005 NEON_ENCODE (IMMED, inst);
13006
13007 immbits = inst.operands[immoperand].imm;
13008 if (et.size == 64)
13009 {
13010 /* .i64 is a pseudo-op, so the immediate must be a repeating
13011 pattern. */
13012 if (immbits != (inst.operands[immoperand].regisimm ?
13013 inst.operands[immoperand].reg : 0))
13014 {
13015 /* Set immbits to an invalid constant. */
13016 immbits = 0xdeadbeef;
13017 }
13018 }
13019
13020 switch (opcode)
13021 {
13022 case N_MNEM_vbic:
13023 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13024 break;
13025
13026 case N_MNEM_vorr:
13027 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13028 break;
13029
13030 case N_MNEM_vand:
13031 /* Pseudo-instruction for VBIC. */
13032 neon_invert_size (&immbits, 0, et.size);
13033 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13034 break;
13035
13036 case N_MNEM_vorn:
13037 /* Pseudo-instruction for VORR. */
13038 neon_invert_size (&immbits, 0, et.size);
13039 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
13040 break;
13041
13042 default:
13043 abort ();
13044 }
13045
13046 if (cmode == FAIL)
13047 return;
13048
13049 inst.instruction |= neon_quad (rs) << 6;
13050 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13051 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13052 inst.instruction |= cmode << 8;
13053 neon_write_immbits (immbits);
13054
13055 neon_dp_fixup (&inst);
13056 }
13057 }
13058
13059 static void
13060 do_neon_bitfield (void)
13061 {
13062 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13063 neon_check_type (3, rs, N_IGNORE_TYPE);
13064 neon_three_same (neon_quad (rs), 0, -1);
13065 }
13066
13067 static void
13068 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
13069 unsigned destbits)
13070 {
13071 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13072 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
13073 types | N_KEY);
13074 if (et.type == NT_float)
13075 {
13076 NEON_ENCODE (FLOAT, inst);
13077 neon_three_same (neon_quad (rs), 0, -1);
13078 }
13079 else
13080 {
13081 NEON_ENCODE (INTEGER, inst);
13082 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
13083 }
13084 }
13085
13086 static void
13087 do_neon_dyadic_if_su (void)
13088 {
13089 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13090 }
13091
13092 static void
13093 do_neon_dyadic_if_su_d (void)
13094 {
13095 /* This version only allow D registers, but that constraint is enforced during
13096 operand parsing so we don't need to do anything extra here. */
13097 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
13098 }
13099
13100 static void
13101 do_neon_dyadic_if_i_d (void)
13102 {
13103 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13104 affected if we specify unsigned args. */
13105 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13106 }
13107
13108 enum vfp_or_neon_is_neon_bits
13109 {
13110 NEON_CHECK_CC = 1,
13111 NEON_CHECK_ARCH = 2
13112 };
13113
13114 /* Call this function if an instruction which may have belonged to the VFP or
13115 Neon instruction sets, but turned out to be a Neon instruction (due to the
13116 operand types involved, etc.). We have to check and/or fix-up a couple of
13117 things:
13118
13119 - Make sure the user hasn't attempted to make a Neon instruction
13120 conditional.
13121 - Alter the value in the condition code field if necessary.
13122 - Make sure that the arch supports Neon instructions.
13123
13124 Which of these operations take place depends on bits from enum
13125 vfp_or_neon_is_neon_bits.
13126
13127 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
13128 current instruction's condition is COND_ALWAYS, the condition field is
13129 changed to inst.uncond_value. This is necessary because instructions shared
13130 between VFP and Neon may be conditional for the VFP variants only, and the
13131 unconditional Neon version must have, e.g., 0xF in the condition field. */
13132
13133 static int
13134 vfp_or_neon_is_neon (unsigned check)
13135 {
13136 /* Conditions are always legal in Thumb mode (IT blocks). */
13137 if (!thumb_mode && (check & NEON_CHECK_CC))
13138 {
13139 if (inst.cond != COND_ALWAYS)
13140 {
13141 first_error (_(BAD_COND));
13142 return FAIL;
13143 }
13144 if (inst.uncond_value != -1)
13145 inst.instruction |= inst.uncond_value << 28;
13146 }
13147
13148 if ((check & NEON_CHECK_ARCH)
13149 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13150 {
13151 first_error (_(BAD_FPU));
13152 return FAIL;
13153 }
13154
13155 return SUCCESS;
13156 }
13157
13158 static void
13159 do_neon_addsub_if_i (void)
13160 {
13161 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13162 return;
13163
13164 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13165 return;
13166
13167 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13168 affected if we specify unsigned args. */
13169 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
13170 }
13171
13172 /* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13173 result to be:
13174 V<op> A,B (A is operand 0, B is operand 2)
13175 to mean:
13176 V<op> A,B,A
13177 not:
13178 V<op> A,B,B
13179 so handle that case specially. */
13180
13181 static void
13182 neon_exchange_operands (void)
13183 {
13184 void *scratch = alloca (sizeof (inst.operands[0]));
13185 if (inst.operands[1].present)
13186 {
13187 /* Swap operands[1] and operands[2]. */
13188 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13189 inst.operands[1] = inst.operands[2];
13190 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13191 }
13192 else
13193 {
13194 inst.operands[1] = inst.operands[2];
13195 inst.operands[2] = inst.operands[0];
13196 }
13197 }
13198
13199 static void
13200 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13201 {
13202 if (inst.operands[2].isreg)
13203 {
13204 if (invert)
13205 neon_exchange_operands ();
13206 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
13207 }
13208 else
13209 {
13210 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13211 struct neon_type_el et = neon_check_type (2, rs,
13212 N_EQK | N_SIZ, immtypes | N_KEY);
13213
13214 NEON_ENCODE (IMMED, inst);
13215 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13216 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13217 inst.instruction |= LOW4 (inst.operands[1].reg);
13218 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13219 inst.instruction |= neon_quad (rs) << 6;
13220 inst.instruction |= (et.type == NT_float) << 10;
13221 inst.instruction |= neon_logbits (et.size) << 18;
13222
13223 neon_dp_fixup (&inst);
13224 }
13225 }
13226
13227 static void
13228 do_neon_cmp (void)
13229 {
13230 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13231 }
13232
13233 static void
13234 do_neon_cmp_inv (void)
13235 {
13236 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13237 }
13238
13239 static void
13240 do_neon_ceq (void)
13241 {
13242 neon_compare (N_IF_32, N_IF_32, FALSE);
13243 }
13244
13245 /* For multiply instructions, we have the possibility of 16-bit or 32-bit
13246 scalars, which are encoded in 5 bits, M : Rm.
13247 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13248 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13249 index in M. */
13250
13251 static unsigned
13252 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13253 {
13254 unsigned regno = NEON_SCALAR_REG (scalar);
13255 unsigned elno = NEON_SCALAR_INDEX (scalar);
13256
13257 switch (elsize)
13258 {
13259 case 16:
13260 if (regno > 7 || elno > 3)
13261 goto bad_scalar;
13262 return regno | (elno << 3);
13263
13264 case 32:
13265 if (regno > 15 || elno > 1)
13266 goto bad_scalar;
13267 return regno | (elno << 4);
13268
13269 default:
13270 bad_scalar:
13271 first_error (_("scalar out of range for multiply instruction"));
13272 }
13273
13274 return 0;
13275 }
13276
13277 /* Encode multiply / multiply-accumulate scalar instructions. */
13278
13279 static void
13280 neon_mul_mac (struct neon_type_el et, int ubit)
13281 {
13282 unsigned scalar;
13283
13284 /* Give a more helpful error message if we have an invalid type. */
13285 if (et.type == NT_invtype)
13286 return;
13287
13288 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
13289 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13290 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13291 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13292 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13293 inst.instruction |= LOW4 (scalar);
13294 inst.instruction |= HI1 (scalar) << 5;
13295 inst.instruction |= (et.type == NT_float) << 8;
13296 inst.instruction |= neon_logbits (et.size) << 20;
13297 inst.instruction |= (ubit != 0) << 24;
13298
13299 neon_dp_fixup (&inst);
13300 }
13301
13302 static void
13303 do_neon_mac_maybe_scalar (void)
13304 {
13305 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13306 return;
13307
13308 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13309 return;
13310
13311 if (inst.operands[2].isscalar)
13312 {
13313 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13314 struct neon_type_el et = neon_check_type (3, rs,
13315 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
13316 NEON_ENCODE (SCALAR, inst);
13317 neon_mul_mac (et, neon_quad (rs));
13318 }
13319 else
13320 {
13321 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13322 affected if we specify unsigned args. */
13323 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13324 }
13325 }
13326
13327 static void
13328 do_neon_fmac (void)
13329 {
13330 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13331 return;
13332
13333 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13334 return;
13335
13336 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13337 }
13338
13339 static void
13340 do_neon_tst (void)
13341 {
13342 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13343 struct neon_type_el et = neon_check_type (3, rs,
13344 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
13345 neon_three_same (neon_quad (rs), 0, et.size);
13346 }
13347
13348 /* VMUL with 3 registers allows the P8 type. The scalar version supports the
13349 same types as the MAC equivalents. The polynomial type for this instruction
13350 is encoded the same as the integer type. */
13351
13352 static void
13353 do_neon_mul (void)
13354 {
13355 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13356 return;
13357
13358 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13359 return;
13360
13361 if (inst.operands[2].isscalar)
13362 do_neon_mac_maybe_scalar ();
13363 else
13364 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
13365 }
13366
13367 static void
13368 do_neon_qdmulh (void)
13369 {
13370 if (inst.operands[2].isscalar)
13371 {
13372 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
13373 struct neon_type_el et = neon_check_type (3, rs,
13374 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13375 NEON_ENCODE (SCALAR, inst);
13376 neon_mul_mac (et, neon_quad (rs));
13377 }
13378 else
13379 {
13380 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13381 struct neon_type_el et = neon_check_type (3, rs,
13382 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13383 NEON_ENCODE (INTEGER, inst);
13384 /* The U bit (rounding) comes from bit mask. */
13385 neon_three_same (neon_quad (rs), 0, et.size);
13386 }
13387 }
13388
13389 static void
13390 do_neon_fcmp_absolute (void)
13391 {
13392 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13393 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13394 /* Size field comes from bit mask. */
13395 neon_three_same (neon_quad (rs), 1, -1);
13396 }
13397
13398 static void
13399 do_neon_fcmp_absolute_inv (void)
13400 {
13401 neon_exchange_operands ();
13402 do_neon_fcmp_absolute ();
13403 }
13404
13405 static void
13406 do_neon_step (void)
13407 {
13408 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
13409 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13410 neon_three_same (neon_quad (rs), 0, -1);
13411 }
13412
13413 static void
13414 do_neon_abs_neg (void)
13415 {
13416 enum neon_shape rs;
13417 struct neon_type_el et;
13418
13419 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13420 return;
13421
13422 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13423 return;
13424
13425 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13426 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
13427
13428 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13429 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13430 inst.instruction |= LOW4 (inst.operands[1].reg);
13431 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13432 inst.instruction |= neon_quad (rs) << 6;
13433 inst.instruction |= (et.type == NT_float) << 10;
13434 inst.instruction |= neon_logbits (et.size) << 18;
13435
13436 neon_dp_fixup (&inst);
13437 }
13438
13439 static void
13440 do_neon_sli (void)
13441 {
13442 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13443 struct neon_type_el et = neon_check_type (2, rs,
13444 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13445 int imm = inst.operands[2].imm;
13446 constraint (imm < 0 || (unsigned)imm >= et.size,
13447 _("immediate out of range for insert"));
13448 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13449 }
13450
13451 static void
13452 do_neon_sri (void)
13453 {
13454 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13455 struct neon_type_el et = neon_check_type (2, rs,
13456 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13457 int imm = inst.operands[2].imm;
13458 constraint (imm < 1 || (unsigned)imm > et.size,
13459 _("immediate out of range for insert"));
13460 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
13461 }
13462
13463 static void
13464 do_neon_qshlu_imm (void)
13465 {
13466 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
13467 struct neon_type_el et = neon_check_type (2, rs,
13468 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13469 int imm = inst.operands[2].imm;
13470 constraint (imm < 0 || (unsigned)imm >= et.size,
13471 _("immediate out of range for shift"));
13472 /* Only encodes the 'U present' variant of the instruction.
13473 In this case, signed types have OP (bit 8) set to 0.
13474 Unsigned types have OP set to 1. */
13475 inst.instruction |= (et.type == NT_unsigned) << 8;
13476 /* The rest of the bits are the same as other immediate shifts. */
13477 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13478 }
13479
13480 static void
13481 do_neon_qmovn (void)
13482 {
13483 struct neon_type_el et = neon_check_type (2, NS_DQ,
13484 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13485 /* Saturating move where operands can be signed or unsigned, and the
13486 destination has the same signedness. */
13487 NEON_ENCODE (INTEGER, inst);
13488 if (et.type == NT_unsigned)
13489 inst.instruction |= 0xc0;
13490 else
13491 inst.instruction |= 0x80;
13492 neon_two_same (0, 1, et.size / 2);
13493 }
13494
13495 static void
13496 do_neon_qmovun (void)
13497 {
13498 struct neon_type_el et = neon_check_type (2, NS_DQ,
13499 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13500 /* Saturating move with unsigned results. Operands must be signed. */
13501 NEON_ENCODE (INTEGER, inst);
13502 neon_two_same (0, 1, et.size / 2);
13503 }
13504
13505 static void
13506 do_neon_rshift_sat_narrow (void)
13507 {
13508 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13509 or unsigned. If operands are unsigned, results must also be unsigned. */
13510 struct neon_type_el et = neon_check_type (2, NS_DQI,
13511 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13512 int imm = inst.operands[2].imm;
13513 /* This gets the bounds check, size encoding and immediate bits calculation
13514 right. */
13515 et.size /= 2;
13516
13517 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13518 VQMOVN.I<size> <Dd>, <Qm>. */
13519 if (imm == 0)
13520 {
13521 inst.operands[2].present = 0;
13522 inst.instruction = N_MNEM_vqmovn;
13523 do_neon_qmovn ();
13524 return;
13525 }
13526
13527 constraint (imm < 1 || (unsigned)imm > et.size,
13528 _("immediate out of range"));
13529 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13530 }
13531
13532 static void
13533 do_neon_rshift_sat_narrow_u (void)
13534 {
13535 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13536 or unsigned. If operands are unsigned, results must also be unsigned. */
13537 struct neon_type_el et = neon_check_type (2, NS_DQI,
13538 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13539 int imm = inst.operands[2].imm;
13540 /* This gets the bounds check, size encoding and immediate bits calculation
13541 right. */
13542 et.size /= 2;
13543
13544 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13545 VQMOVUN.I<size> <Dd>, <Qm>. */
13546 if (imm == 0)
13547 {
13548 inst.operands[2].present = 0;
13549 inst.instruction = N_MNEM_vqmovun;
13550 do_neon_qmovun ();
13551 return;
13552 }
13553
13554 constraint (imm < 1 || (unsigned)imm > et.size,
13555 _("immediate out of range"));
13556 /* FIXME: The manual is kind of unclear about what value U should have in
13557 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13558 must be 1. */
13559 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13560 }
13561
13562 static void
13563 do_neon_movn (void)
13564 {
13565 struct neon_type_el et = neon_check_type (2, NS_DQ,
13566 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13567 NEON_ENCODE (INTEGER, inst);
13568 neon_two_same (0, 1, et.size / 2);
13569 }
13570
13571 static void
13572 do_neon_rshift_narrow (void)
13573 {
13574 struct neon_type_el et = neon_check_type (2, NS_DQI,
13575 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13576 int imm = inst.operands[2].imm;
13577 /* This gets the bounds check, size encoding and immediate bits calculation
13578 right. */
13579 et.size /= 2;
13580
13581 /* If immediate is zero then we are a pseudo-instruction for
13582 VMOVN.I<size> <Dd>, <Qm> */
13583 if (imm == 0)
13584 {
13585 inst.operands[2].present = 0;
13586 inst.instruction = N_MNEM_vmovn;
13587 do_neon_movn ();
13588 return;
13589 }
13590
13591 constraint (imm < 1 || (unsigned)imm > et.size,
13592 _("immediate out of range for narrowing operation"));
13593 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13594 }
13595
13596 static void
13597 do_neon_shll (void)
13598 {
13599 /* FIXME: Type checking when lengthening. */
13600 struct neon_type_el et = neon_check_type (2, NS_QDI,
13601 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13602 unsigned imm = inst.operands[2].imm;
13603
13604 if (imm == et.size)
13605 {
13606 /* Maximum shift variant. */
13607 NEON_ENCODE (INTEGER, inst);
13608 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13609 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13610 inst.instruction |= LOW4 (inst.operands[1].reg);
13611 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13612 inst.instruction |= neon_logbits (et.size) << 18;
13613
13614 neon_dp_fixup (&inst);
13615 }
13616 else
13617 {
13618 /* A more-specific type check for non-max versions. */
13619 et = neon_check_type (2, NS_QDI,
13620 N_EQK | N_DBL, N_SU_32 | N_KEY);
13621 NEON_ENCODE (IMMED, inst);
13622 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13623 }
13624 }
13625
13626 /* Check the various types for the VCVT instruction, and return which version
13627 the current instruction is. */
13628
13629 static int
13630 neon_cvt_flavour (enum neon_shape rs)
13631 {
13632 #define CVT_VAR(C,X,Y) \
13633 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13634 if (et.type != NT_invtype) \
13635 { \
13636 inst.error = NULL; \
13637 return (C); \
13638 }
13639 struct neon_type_el et;
13640 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13641 || rs == NS_FF) ? N_VFP : 0;
13642 /* The instruction versions which take an immediate take one register
13643 argument, which is extended to the width of the full register. Thus the
13644 "source" and "destination" registers must have the same width. Hack that
13645 here by making the size equal to the key (wider, in this case) operand. */
13646 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
13647
13648 CVT_VAR (0, N_S32, N_F32);
13649 CVT_VAR (1, N_U32, N_F32);
13650 CVT_VAR (2, N_F32, N_S32);
13651 CVT_VAR (3, N_F32, N_U32);
13652 /* Half-precision conversions. */
13653 CVT_VAR (4, N_F32, N_F16);
13654 CVT_VAR (5, N_F16, N_F32);
13655
13656 whole_reg = N_VFP;
13657
13658 /* VFP instructions. */
13659 CVT_VAR (6, N_F32, N_F64);
13660 CVT_VAR (7, N_F64, N_F32);
13661 CVT_VAR (8, N_S32, N_F64 | key);
13662 CVT_VAR (9, N_U32, N_F64 | key);
13663 CVT_VAR (10, N_F64 | key, N_S32);
13664 CVT_VAR (11, N_F64 | key, N_U32);
13665 /* VFP instructions with bitshift. */
13666 CVT_VAR (12, N_F32 | key, N_S16);
13667 CVT_VAR (13, N_F32 | key, N_U16);
13668 CVT_VAR (14, N_F64 | key, N_S16);
13669 CVT_VAR (15, N_F64 | key, N_U16);
13670 CVT_VAR (16, N_S16, N_F32 | key);
13671 CVT_VAR (17, N_U16, N_F32 | key);
13672 CVT_VAR (18, N_S16, N_F64 | key);
13673 CVT_VAR (19, N_U16, N_F64 | key);
13674
13675 return -1;
13676 #undef CVT_VAR
13677 }
13678
13679 /* Neon-syntax VFP conversions. */
13680
13681 static void
13682 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
13683 {
13684 const char *opname = 0;
13685
13686 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
13687 {
13688 /* Conversions with immediate bitshift. */
13689 const char *enc[] =
13690 {
13691 "ftosls",
13692 "ftouls",
13693 "fsltos",
13694 "fultos",
13695 NULL,
13696 NULL,
13697 NULL,
13698 NULL,
13699 "ftosld",
13700 "ftould",
13701 "fsltod",
13702 "fultod",
13703 "fshtos",
13704 "fuhtos",
13705 "fshtod",
13706 "fuhtod",
13707 "ftoshs",
13708 "ftouhs",
13709 "ftoshd",
13710 "ftouhd"
13711 };
13712
13713 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13714 {
13715 opname = enc[flavour];
13716 constraint (inst.operands[0].reg != inst.operands[1].reg,
13717 _("operands 0 and 1 must be the same register"));
13718 inst.operands[1] = inst.operands[2];
13719 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13720 }
13721 }
13722 else
13723 {
13724 /* Conversions without bitshift. */
13725 const char *enc[] =
13726 {
13727 "ftosis",
13728 "ftouis",
13729 "fsitos",
13730 "fuitos",
13731 "NULL",
13732 "NULL",
13733 "fcvtsd",
13734 "fcvtds",
13735 "ftosid",
13736 "ftouid",
13737 "fsitod",
13738 "fuitod"
13739 };
13740
13741 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13742 opname = enc[flavour];
13743 }
13744
13745 if (opname)
13746 do_vfp_nsyn_opcode (opname);
13747 }
13748
13749 static void
13750 do_vfp_nsyn_cvtz (void)
13751 {
13752 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13753 int flavour = neon_cvt_flavour (rs);
13754 const char *enc[] =
13755 {
13756 "ftosizs",
13757 "ftouizs",
13758 NULL,
13759 NULL,
13760 NULL,
13761 NULL,
13762 NULL,
13763 NULL,
13764 "ftosizd",
13765 "ftouizd"
13766 };
13767
13768 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13769 do_vfp_nsyn_opcode (enc[flavour]);
13770 }
13771
13772 static void
13773 do_neon_cvt_1 (bfd_boolean round_to_zero ATTRIBUTE_UNUSED)
13774 {
13775 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
13776 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
13777 int flavour = neon_cvt_flavour (rs);
13778
13779 /* PR11109: Handle round-to-zero for VCVT conversions. */
13780 if (round_to_zero
13781 && ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_vfp_v2)
13782 && (flavour == 0 || flavour == 1 || flavour == 8 || flavour == 9)
13783 && (rs == NS_FD || rs == NS_FF))
13784 {
13785 do_vfp_nsyn_cvtz ();
13786 return;
13787 }
13788
13789 /* VFP rather than Neon conversions. */
13790 if (flavour >= 6)
13791 {
13792 do_vfp_nsyn_cvt (rs, flavour);
13793 return;
13794 }
13795
13796 switch (rs)
13797 {
13798 case NS_DDI:
13799 case NS_QQI:
13800 {
13801 unsigned immbits;
13802 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13803
13804 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13805 return;
13806
13807 /* Fixed-point conversion with #0 immediate is encoded as an
13808 integer conversion. */
13809 if (inst.operands[2].present && inst.operands[2].imm == 0)
13810 goto int_encode;
13811 immbits = 32 - inst.operands[2].imm;
13812 NEON_ENCODE (IMMED, inst);
13813 if (flavour != -1)
13814 inst.instruction |= enctab[flavour];
13815 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13816 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13817 inst.instruction |= LOW4 (inst.operands[1].reg);
13818 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13819 inst.instruction |= neon_quad (rs) << 6;
13820 inst.instruction |= 1 << 21;
13821 inst.instruction |= immbits << 16;
13822
13823 neon_dp_fixup (&inst);
13824 }
13825 break;
13826
13827 case NS_DD:
13828 case NS_QQ:
13829 int_encode:
13830 {
13831 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13832
13833 NEON_ENCODE (INTEGER, inst);
13834
13835 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13836 return;
13837
13838 if (flavour != -1)
13839 inst.instruction |= enctab[flavour];
13840
13841 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13842 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13843 inst.instruction |= LOW4 (inst.operands[1].reg);
13844 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13845 inst.instruction |= neon_quad (rs) << 6;
13846 inst.instruction |= 2 << 18;
13847
13848 neon_dp_fixup (&inst);
13849 }
13850 break;
13851
13852 /* Half-precision conversions for Advanced SIMD -- neon. */
13853 case NS_QD:
13854 case NS_DQ:
13855
13856 if ((rs == NS_DQ)
13857 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13858 {
13859 as_bad (_("operand size must match register width"));
13860 break;
13861 }
13862
13863 if ((rs == NS_QD)
13864 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13865 {
13866 as_bad (_("operand size must match register width"));
13867 break;
13868 }
13869
13870 if (rs == NS_DQ)
13871 inst.instruction = 0x3b60600;
13872 else
13873 inst.instruction = 0x3b60700;
13874
13875 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13876 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13877 inst.instruction |= LOW4 (inst.operands[1].reg);
13878 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13879 neon_dp_fixup (&inst);
13880 break;
13881
13882 default:
13883 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13884 do_vfp_nsyn_cvt (rs, flavour);
13885 }
13886 }
13887
13888 static void
13889 do_neon_cvtr (void)
13890 {
13891 do_neon_cvt_1 (FALSE);
13892 }
13893
13894 static void
13895 do_neon_cvt (void)
13896 {
13897 do_neon_cvt_1 (TRUE);
13898 }
13899
13900 static void
13901 do_neon_cvtb (void)
13902 {
13903 inst.instruction = 0xeb20a40;
13904
13905 /* The sizes are attached to the mnemonic. */
13906 if (inst.vectype.el[0].type != NT_invtype
13907 && inst.vectype.el[0].size == 16)
13908 inst.instruction |= 0x00010000;
13909
13910 /* Programmer's syntax: the sizes are attached to the operands. */
13911 else if (inst.operands[0].vectype.type != NT_invtype
13912 && inst.operands[0].vectype.size == 16)
13913 inst.instruction |= 0x00010000;
13914
13915 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13916 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13917 do_vfp_cond_or_thumb ();
13918 }
13919
13920
13921 static void
13922 do_neon_cvtt (void)
13923 {
13924 do_neon_cvtb ();
13925 inst.instruction |= 0x80;
13926 }
13927
13928 static void
13929 neon_move_immediate (void)
13930 {
13931 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13932 struct neon_type_el et = neon_check_type (2, rs,
13933 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
13934 unsigned immlo, immhi = 0, immbits;
13935 int op, cmode, float_p;
13936
13937 constraint (et.type == NT_invtype,
13938 _("operand size must be specified for immediate VMOV"));
13939
13940 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13941 op = (inst.instruction & (1 << 5)) != 0;
13942
13943 immlo = inst.operands[1].imm;
13944 if (inst.operands[1].regisimm)
13945 immhi = inst.operands[1].reg;
13946
13947 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13948 _("immediate has bits set outside the operand size"));
13949
13950 float_p = inst.operands[1].immisfloat;
13951
13952 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
13953 et.size, et.type)) == FAIL)
13954 {
13955 /* Invert relevant bits only. */
13956 neon_invert_size (&immlo, &immhi, et.size);
13957 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13958 with one or the other; those cases are caught by
13959 neon_cmode_for_move_imm. */
13960 op = !op;
13961 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13962 &op, et.size, et.type)) == FAIL)
13963 {
13964 first_error (_("immediate out of range"));
13965 return;
13966 }
13967 }
13968
13969 inst.instruction &= ~(1 << 5);
13970 inst.instruction |= op << 5;
13971
13972 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13973 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13974 inst.instruction |= neon_quad (rs) << 6;
13975 inst.instruction |= cmode << 8;
13976
13977 neon_write_immbits (immbits);
13978 }
13979
13980 static void
13981 do_neon_mvn (void)
13982 {
13983 if (inst.operands[1].isreg)
13984 {
13985 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13986
13987 NEON_ENCODE (INTEGER, inst);
13988 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13989 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13990 inst.instruction |= LOW4 (inst.operands[1].reg);
13991 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13992 inst.instruction |= neon_quad (rs) << 6;
13993 }
13994 else
13995 {
13996 NEON_ENCODE (IMMED, inst);
13997 neon_move_immediate ();
13998 }
13999
14000 neon_dp_fixup (&inst);
14001 }
14002
14003 /* Encode instructions of form:
14004
14005 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
14006 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
14007
14008 static void
14009 neon_mixed_length (struct neon_type_el et, unsigned size)
14010 {
14011 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14012 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14013 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14014 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14015 inst.instruction |= LOW4 (inst.operands[2].reg);
14016 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14017 inst.instruction |= (et.type == NT_unsigned) << 24;
14018 inst.instruction |= neon_logbits (size) << 20;
14019
14020 neon_dp_fixup (&inst);
14021 }
14022
14023 static void
14024 do_neon_dyadic_long (void)
14025 {
14026 /* FIXME: Type checking for lengthening op. */
14027 struct neon_type_el et = neon_check_type (3, NS_QDD,
14028 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
14029 neon_mixed_length (et, et.size);
14030 }
14031
14032 static void
14033 do_neon_abal (void)
14034 {
14035 struct neon_type_el et = neon_check_type (3, NS_QDD,
14036 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
14037 neon_mixed_length (et, et.size);
14038 }
14039
14040 static void
14041 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
14042 {
14043 if (inst.operands[2].isscalar)
14044 {
14045 struct neon_type_el et = neon_check_type (3, NS_QDS,
14046 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
14047 NEON_ENCODE (SCALAR, inst);
14048 neon_mul_mac (et, et.type == NT_unsigned);
14049 }
14050 else
14051 {
14052 struct neon_type_el et = neon_check_type (3, NS_QDD,
14053 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
14054 NEON_ENCODE (INTEGER, inst);
14055 neon_mixed_length (et, et.size);
14056 }
14057 }
14058
14059 static void
14060 do_neon_mac_maybe_scalar_long (void)
14061 {
14062 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
14063 }
14064
14065 static void
14066 do_neon_dyadic_wide (void)
14067 {
14068 struct neon_type_el et = neon_check_type (3, NS_QQD,
14069 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
14070 neon_mixed_length (et, et.size);
14071 }
14072
14073 static void
14074 do_neon_dyadic_narrow (void)
14075 {
14076 struct neon_type_el et = neon_check_type (3, NS_QDD,
14077 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
14078 /* Operand sign is unimportant, and the U bit is part of the opcode,
14079 so force the operand type to integer. */
14080 et.type = NT_integer;
14081 neon_mixed_length (et, et.size / 2);
14082 }
14083
14084 static void
14085 do_neon_mul_sat_scalar_long (void)
14086 {
14087 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
14088 }
14089
14090 static void
14091 do_neon_vmull (void)
14092 {
14093 if (inst.operands[2].isscalar)
14094 do_neon_mac_maybe_scalar_long ();
14095 else
14096 {
14097 struct neon_type_el et = neon_check_type (3, NS_QDD,
14098 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
14099 if (et.type == NT_poly)
14100 NEON_ENCODE (POLY, inst);
14101 else
14102 NEON_ENCODE (INTEGER, inst);
14103 /* For polynomial encoding, size field must be 0b00 and the U bit must be
14104 zero. Should be OK as-is. */
14105 neon_mixed_length (et, et.size);
14106 }
14107 }
14108
14109 static void
14110 do_neon_ext (void)
14111 {
14112 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
14113 struct neon_type_el et = neon_check_type (3, rs,
14114 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
14115 unsigned imm = (inst.operands[3].imm * et.size) / 8;
14116
14117 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
14118 _("shift out of range"));
14119 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14120 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14121 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14122 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14123 inst.instruction |= LOW4 (inst.operands[2].reg);
14124 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14125 inst.instruction |= neon_quad (rs) << 6;
14126 inst.instruction |= imm << 8;
14127
14128 neon_dp_fixup (&inst);
14129 }
14130
14131 static void
14132 do_neon_rev (void)
14133 {
14134 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, 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 op = (inst.instruction >> 7) & 3;
14138 /* N (width of reversed regions) is encoded as part of the bitmask. We
14139 extract it here to check the elements to be reversed are smaller.
14140 Otherwise we'd get a reserved instruction. */
14141 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
14142 gas_assert (elsize != 0);
14143 constraint (et.size >= elsize,
14144 _("elements must be smaller than reversal region"));
14145 neon_two_same (neon_quad (rs), 1, et.size);
14146 }
14147
14148 static void
14149 do_neon_dup (void)
14150 {
14151 if (inst.operands[1].isscalar)
14152 {
14153 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
14154 struct neon_type_el et = neon_check_type (2, rs,
14155 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14156 unsigned sizebits = et.size >> 3;
14157 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
14158 int logsize = neon_logbits (et.size);
14159 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
14160
14161 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14162 return;
14163
14164 NEON_ENCODE (SCALAR, inst);
14165 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14166 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14167 inst.instruction |= LOW4 (dm);
14168 inst.instruction |= HI1 (dm) << 5;
14169 inst.instruction |= neon_quad (rs) << 6;
14170 inst.instruction |= x << 17;
14171 inst.instruction |= sizebits << 16;
14172
14173 neon_dp_fixup (&inst);
14174 }
14175 else
14176 {
14177 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14178 struct neon_type_el et = neon_check_type (2, rs,
14179 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14180 /* Duplicate ARM register to lanes of vector. */
14181 NEON_ENCODE (ARMREG, inst);
14182 switch (et.size)
14183 {
14184 case 8: inst.instruction |= 0x400000; break;
14185 case 16: inst.instruction |= 0x000020; break;
14186 case 32: inst.instruction |= 0x000000; break;
14187 default: break;
14188 }
14189 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14190 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14191 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
14192 inst.instruction |= neon_quad (rs) << 21;
14193 /* The encoding for this instruction is identical for the ARM and Thumb
14194 variants, except for the condition field. */
14195 do_vfp_cond_or_thumb ();
14196 }
14197 }
14198
14199 /* VMOV has particularly many variations. It can be one of:
14200 0. VMOV<c><q> <Qd>, <Qm>
14201 1. VMOV<c><q> <Dd>, <Dm>
14202 (Register operations, which are VORR with Rm = Rn.)
14203 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14204 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14205 (Immediate loads.)
14206 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14207 (ARM register to scalar.)
14208 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14209 (Two ARM registers to vector.)
14210 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14211 (Scalar to ARM register.)
14212 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14213 (Vector to two ARM registers.)
14214 8. VMOV.F32 <Sd>, <Sm>
14215 9. VMOV.F64 <Dd>, <Dm>
14216 (VFP register moves.)
14217 10. VMOV.F32 <Sd>, #imm
14218 11. VMOV.F64 <Dd>, #imm
14219 (VFP float immediate load.)
14220 12. VMOV <Rd>, <Sm>
14221 (VFP single to ARM reg.)
14222 13. VMOV <Sd>, <Rm>
14223 (ARM reg to VFP single.)
14224 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14225 (Two ARM regs to two VFP singles.)
14226 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14227 (Two VFP singles to two ARM regs.)
14228
14229 These cases can be disambiguated using neon_select_shape, except cases 1/9
14230 and 3/11 which depend on the operand type too.
14231
14232 All the encoded bits are hardcoded by this function.
14233
14234 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14235 Cases 5, 7 may be used with VFPv2 and above.
14236
14237 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
14238 can specify a type where it doesn't make sense to, and is ignored). */
14239
14240 static void
14241 do_neon_mov (void)
14242 {
14243 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14244 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14245 NS_NULL);
14246 struct neon_type_el et;
14247 const char *ldconst = 0;
14248
14249 switch (rs)
14250 {
14251 case NS_DD: /* case 1/9. */
14252 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14253 /* It is not an error here if no type is given. */
14254 inst.error = NULL;
14255 if (et.type == NT_float && et.size == 64)
14256 {
14257 do_vfp_nsyn_opcode ("fcpyd");
14258 break;
14259 }
14260 /* fall through. */
14261
14262 case NS_QQ: /* case 0/1. */
14263 {
14264 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14265 return;
14266 /* The architecture manual I have doesn't explicitly state which
14267 value the U bit should have for register->register moves, but
14268 the equivalent VORR instruction has U = 0, so do that. */
14269 inst.instruction = 0x0200110;
14270 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14271 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14272 inst.instruction |= LOW4 (inst.operands[1].reg);
14273 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14274 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14275 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14276 inst.instruction |= neon_quad (rs) << 6;
14277
14278 neon_dp_fixup (&inst);
14279 }
14280 break;
14281
14282 case NS_DI: /* case 3/11. */
14283 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14284 inst.error = NULL;
14285 if (et.type == NT_float && et.size == 64)
14286 {
14287 /* case 11 (fconstd). */
14288 ldconst = "fconstd";
14289 goto encode_fconstd;
14290 }
14291 /* fall through. */
14292
14293 case NS_QI: /* case 2/3. */
14294 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14295 return;
14296 inst.instruction = 0x0800010;
14297 neon_move_immediate ();
14298 neon_dp_fixup (&inst);
14299 break;
14300
14301 case NS_SR: /* case 4. */
14302 {
14303 unsigned bcdebits = 0;
14304 int logsize;
14305 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14306 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14307
14308 et = neon_check_type (2, NS_NULL, N_8 | N_16 | N_32 | N_KEY, N_EQK);
14309 logsize = neon_logbits (et.size);
14310
14311 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14312 _(BAD_FPU));
14313 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14314 && et.size != 32, _(BAD_FPU));
14315 constraint (et.type == NT_invtype, _("bad type for scalar"));
14316 constraint (x >= 64 / et.size, _("scalar index out of range"));
14317
14318 switch (et.size)
14319 {
14320 case 8: bcdebits = 0x8; break;
14321 case 16: bcdebits = 0x1; break;
14322 case 32: bcdebits = 0x0; break;
14323 default: ;
14324 }
14325
14326 bcdebits |= x << logsize;
14327
14328 inst.instruction = 0xe000b10;
14329 do_vfp_cond_or_thumb ();
14330 inst.instruction |= LOW4 (dn) << 16;
14331 inst.instruction |= HI1 (dn) << 7;
14332 inst.instruction |= inst.operands[1].reg << 12;
14333 inst.instruction |= (bcdebits & 3) << 5;
14334 inst.instruction |= (bcdebits >> 2) << 21;
14335 }
14336 break;
14337
14338 case NS_DRR: /* case 5 (fmdrr). */
14339 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14340 _(BAD_FPU));
14341
14342 inst.instruction = 0xc400b10;
14343 do_vfp_cond_or_thumb ();
14344 inst.instruction |= LOW4 (inst.operands[0].reg);
14345 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14346 inst.instruction |= inst.operands[1].reg << 12;
14347 inst.instruction |= inst.operands[2].reg << 16;
14348 break;
14349
14350 case NS_RS: /* case 6. */
14351 {
14352 unsigned logsize;
14353 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14354 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14355 unsigned abcdebits = 0;
14356
14357 et = neon_check_type (2, NS_NULL,
14358 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14359 logsize = neon_logbits (et.size);
14360
14361 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14362 _(BAD_FPU));
14363 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14364 && et.size != 32, _(BAD_FPU));
14365 constraint (et.type == NT_invtype, _("bad type for scalar"));
14366 constraint (x >= 64 / et.size, _("scalar index out of range"));
14367
14368 switch (et.size)
14369 {
14370 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14371 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14372 case 32: abcdebits = 0x00; break;
14373 default: ;
14374 }
14375
14376 abcdebits |= x << logsize;
14377 inst.instruction = 0xe100b10;
14378 do_vfp_cond_or_thumb ();
14379 inst.instruction |= LOW4 (dn) << 16;
14380 inst.instruction |= HI1 (dn) << 7;
14381 inst.instruction |= inst.operands[0].reg << 12;
14382 inst.instruction |= (abcdebits & 3) << 5;
14383 inst.instruction |= (abcdebits >> 2) << 21;
14384 }
14385 break;
14386
14387 case NS_RRD: /* case 7 (fmrrd). */
14388 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14389 _(BAD_FPU));
14390
14391 inst.instruction = 0xc500b10;
14392 do_vfp_cond_or_thumb ();
14393 inst.instruction |= inst.operands[0].reg << 12;
14394 inst.instruction |= inst.operands[1].reg << 16;
14395 inst.instruction |= LOW4 (inst.operands[2].reg);
14396 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14397 break;
14398
14399 case NS_FF: /* case 8 (fcpys). */
14400 do_vfp_nsyn_opcode ("fcpys");
14401 break;
14402
14403 case NS_FI: /* case 10 (fconsts). */
14404 ldconst = "fconsts";
14405 encode_fconstd:
14406 if (is_quarter_float (inst.operands[1].imm))
14407 {
14408 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14409 do_vfp_nsyn_opcode (ldconst);
14410 }
14411 else
14412 first_error (_("immediate out of range"));
14413 break;
14414
14415 case NS_RF: /* case 12 (fmrs). */
14416 do_vfp_nsyn_opcode ("fmrs");
14417 break;
14418
14419 case NS_FR: /* case 13 (fmsr). */
14420 do_vfp_nsyn_opcode ("fmsr");
14421 break;
14422
14423 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14424 (one of which is a list), but we have parsed four. Do some fiddling to
14425 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14426 expect. */
14427 case NS_RRFF: /* case 14 (fmrrs). */
14428 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14429 _("VFP registers must be adjacent"));
14430 inst.operands[2].imm = 2;
14431 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14432 do_vfp_nsyn_opcode ("fmrrs");
14433 break;
14434
14435 case NS_FFRR: /* case 15 (fmsrr). */
14436 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14437 _("VFP registers must be adjacent"));
14438 inst.operands[1] = inst.operands[2];
14439 inst.operands[2] = inst.operands[3];
14440 inst.operands[0].imm = 2;
14441 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14442 do_vfp_nsyn_opcode ("fmsrr");
14443 break;
14444
14445 default:
14446 abort ();
14447 }
14448 }
14449
14450 static void
14451 do_neon_rshift_round_imm (void)
14452 {
14453 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
14454 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14455 int imm = inst.operands[2].imm;
14456
14457 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14458 if (imm == 0)
14459 {
14460 inst.operands[2].present = 0;
14461 do_neon_mov ();
14462 return;
14463 }
14464
14465 constraint (imm < 1 || (unsigned)imm > et.size,
14466 _("immediate out of range for shift"));
14467 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
14468 et.size - imm);
14469 }
14470
14471 static void
14472 do_neon_movl (void)
14473 {
14474 struct neon_type_el et = neon_check_type (2, NS_QD,
14475 N_EQK | N_DBL, N_SU_32 | N_KEY);
14476 unsigned sizebits = et.size >> 3;
14477 inst.instruction |= sizebits << 19;
14478 neon_two_same (0, et.type == NT_unsigned, -1);
14479 }
14480
14481 static void
14482 do_neon_trn (void)
14483 {
14484 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14485 struct neon_type_el et = neon_check_type (2, rs,
14486 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14487 NEON_ENCODE (INTEGER, inst);
14488 neon_two_same (neon_quad (rs), 1, et.size);
14489 }
14490
14491 static void
14492 do_neon_zip_uzp (void)
14493 {
14494 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14495 struct neon_type_el et = neon_check_type (2, rs,
14496 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14497 if (rs == NS_DD && et.size == 32)
14498 {
14499 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14500 inst.instruction = N_MNEM_vtrn;
14501 do_neon_trn ();
14502 return;
14503 }
14504 neon_two_same (neon_quad (rs), 1, et.size);
14505 }
14506
14507 static void
14508 do_neon_sat_abs_neg (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_S8 | N_S16 | N_S32 | N_KEY);
14513 neon_two_same (neon_quad (rs), 1, et.size);
14514 }
14515
14516 static void
14517 do_neon_pair_long (void)
14518 {
14519 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14520 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14521 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14522 inst.instruction |= (et.type == NT_unsigned) << 7;
14523 neon_two_same (neon_quad (rs), 1, et.size);
14524 }
14525
14526 static void
14527 do_neon_recip_est (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_FLT, N_F32 | N_U32 | N_KEY);
14532 inst.instruction |= (et.type == NT_float) << 8;
14533 neon_two_same (neon_quad (rs), 1, et.size);
14534 }
14535
14536 static void
14537 do_neon_cls (void)
14538 {
14539 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14540 struct neon_type_el et = neon_check_type (2, rs,
14541 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14542 neon_two_same (neon_quad (rs), 1, et.size);
14543 }
14544
14545 static void
14546 do_neon_clz (void)
14547 {
14548 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14549 struct neon_type_el et = neon_check_type (2, rs,
14550 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
14551 neon_two_same (neon_quad (rs), 1, et.size);
14552 }
14553
14554 static void
14555 do_neon_cnt (void)
14556 {
14557 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14558 struct neon_type_el et = neon_check_type (2, rs,
14559 N_EQK | N_INT, N_8 | N_KEY);
14560 neon_two_same (neon_quad (rs), 1, et.size);
14561 }
14562
14563 static void
14564 do_neon_swp (void)
14565 {
14566 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14567 neon_two_same (neon_quad (rs), 1, -1);
14568 }
14569
14570 static void
14571 do_neon_tbl_tbx (void)
14572 {
14573 unsigned listlenbits;
14574 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
14575
14576 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14577 {
14578 first_error (_("bad list length for table lookup"));
14579 return;
14580 }
14581
14582 listlenbits = inst.operands[1].imm - 1;
14583 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14584 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14585 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14586 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14587 inst.instruction |= LOW4 (inst.operands[2].reg);
14588 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14589 inst.instruction |= listlenbits << 8;
14590
14591 neon_dp_fixup (&inst);
14592 }
14593
14594 static void
14595 do_neon_ldm_stm (void)
14596 {
14597 /* P, U and L bits are part of bitmask. */
14598 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14599 unsigned offsetbits = inst.operands[1].imm * 2;
14600
14601 if (inst.operands[1].issingle)
14602 {
14603 do_vfp_nsyn_ldm_stm (is_dbmode);
14604 return;
14605 }
14606
14607 constraint (is_dbmode && !inst.operands[0].writeback,
14608 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14609
14610 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14611 _("register list must contain at least 1 and at most 16 "
14612 "registers"));
14613
14614 inst.instruction |= inst.operands[0].reg << 16;
14615 inst.instruction |= inst.operands[0].writeback << 21;
14616 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14617 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14618
14619 inst.instruction |= offsetbits;
14620
14621 do_vfp_cond_or_thumb ();
14622 }
14623
14624 static void
14625 do_neon_ldr_str (void)
14626 {
14627 int is_ldr = (inst.instruction & (1 << 20)) != 0;
14628
14629 if (inst.operands[0].issingle)
14630 {
14631 if (is_ldr)
14632 do_vfp_nsyn_opcode ("flds");
14633 else
14634 do_vfp_nsyn_opcode ("fsts");
14635 }
14636 else
14637 {
14638 if (is_ldr)
14639 do_vfp_nsyn_opcode ("fldd");
14640 else
14641 do_vfp_nsyn_opcode ("fstd");
14642 }
14643 }
14644
14645 /* "interleave" version also handles non-interleaving register VLD1/VST1
14646 instructions. */
14647
14648 static void
14649 do_neon_ld_st_interleave (void)
14650 {
14651 struct neon_type_el et = neon_check_type (1, NS_NULL,
14652 N_8 | N_16 | N_32 | N_64);
14653 unsigned alignbits = 0;
14654 unsigned idx;
14655 /* The bits in this table go:
14656 0: register stride of one (0) or two (1)
14657 1,2: register list length, minus one (1, 2, 3, 4).
14658 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14659 We use -1 for invalid entries. */
14660 const int typetable[] =
14661 {
14662 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14663 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14664 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14665 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14666 };
14667 int typebits;
14668
14669 if (et.type == NT_invtype)
14670 return;
14671
14672 if (inst.operands[1].immisalign)
14673 switch (inst.operands[1].imm >> 8)
14674 {
14675 case 64: alignbits = 1; break;
14676 case 128:
14677 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2
14678 && NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
14679 goto bad_alignment;
14680 alignbits = 2;
14681 break;
14682 case 256:
14683 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4)
14684 goto bad_alignment;
14685 alignbits = 3;
14686 break;
14687 default:
14688 bad_alignment:
14689 first_error (_("bad alignment"));
14690 return;
14691 }
14692
14693 inst.instruction |= alignbits << 4;
14694 inst.instruction |= neon_logbits (et.size) << 6;
14695
14696 /* Bits [4:6] of the immediate in a list specifier encode register stride
14697 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14698 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14699 up the right value for "type" in a table based on this value and the given
14700 list style, then stick it back. */
14701 idx = ((inst.operands[0].imm >> 4) & 7)
14702 | (((inst.instruction >> 8) & 3) << 3);
14703
14704 typebits = typetable[idx];
14705
14706 constraint (typebits == -1, _("bad list type for instruction"));
14707
14708 inst.instruction &= ~0xf00;
14709 inst.instruction |= typebits << 8;
14710 }
14711
14712 /* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14713 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14714 otherwise. The variable arguments are a list of pairs of legal (size, align)
14715 values, terminated with -1. */
14716
14717 static int
14718 neon_alignment_bit (int size, int align, int *do_align, ...)
14719 {
14720 va_list ap;
14721 int result = FAIL, thissize, thisalign;
14722
14723 if (!inst.operands[1].immisalign)
14724 {
14725 *do_align = 0;
14726 return SUCCESS;
14727 }
14728
14729 va_start (ap, do_align);
14730
14731 do
14732 {
14733 thissize = va_arg (ap, int);
14734 if (thissize == -1)
14735 break;
14736 thisalign = va_arg (ap, int);
14737
14738 if (size == thissize && align == thisalign)
14739 result = SUCCESS;
14740 }
14741 while (result != SUCCESS);
14742
14743 va_end (ap);
14744
14745 if (result == SUCCESS)
14746 *do_align = 1;
14747 else
14748 first_error (_("unsupported alignment for instruction"));
14749
14750 return result;
14751 }
14752
14753 static void
14754 do_neon_ld_st_lane (void)
14755 {
14756 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14757 int align_good, do_align = 0;
14758 int logsize = neon_logbits (et.size);
14759 int align = inst.operands[1].imm >> 8;
14760 int n = (inst.instruction >> 8) & 3;
14761 int max_el = 64 / et.size;
14762
14763 if (et.type == NT_invtype)
14764 return;
14765
14766 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14767 _("bad list length"));
14768 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14769 _("scalar index out of range"));
14770 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14771 && et.size == 8,
14772 _("stride of 2 unavailable when element size is 8"));
14773
14774 switch (n)
14775 {
14776 case 0: /* VLD1 / VST1. */
14777 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14778 32, 32, -1);
14779 if (align_good == FAIL)
14780 return;
14781 if (do_align)
14782 {
14783 unsigned alignbits = 0;
14784 switch (et.size)
14785 {
14786 case 16: alignbits = 0x1; break;
14787 case 32: alignbits = 0x3; break;
14788 default: ;
14789 }
14790 inst.instruction |= alignbits << 4;
14791 }
14792 break;
14793
14794 case 1: /* VLD2 / VST2. */
14795 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14796 32, 64, -1);
14797 if (align_good == FAIL)
14798 return;
14799 if (do_align)
14800 inst.instruction |= 1 << 4;
14801 break;
14802
14803 case 2: /* VLD3 / VST3. */
14804 constraint (inst.operands[1].immisalign,
14805 _("can't use alignment with this instruction"));
14806 break;
14807
14808 case 3: /* VLD4 / VST4. */
14809 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14810 16, 64, 32, 64, 32, 128, -1);
14811 if (align_good == FAIL)
14812 return;
14813 if (do_align)
14814 {
14815 unsigned alignbits = 0;
14816 switch (et.size)
14817 {
14818 case 8: alignbits = 0x1; break;
14819 case 16: alignbits = 0x1; break;
14820 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14821 default: ;
14822 }
14823 inst.instruction |= alignbits << 4;
14824 }
14825 break;
14826
14827 default: ;
14828 }
14829
14830 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14831 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14832 inst.instruction |= 1 << (4 + logsize);
14833
14834 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14835 inst.instruction |= logsize << 10;
14836 }
14837
14838 /* Encode single n-element structure to all lanes VLD<n> instructions. */
14839
14840 static void
14841 do_neon_ld_dup (void)
14842 {
14843 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14844 int align_good, do_align = 0;
14845
14846 if (et.type == NT_invtype)
14847 return;
14848
14849 switch ((inst.instruction >> 8) & 3)
14850 {
14851 case 0: /* VLD1. */
14852 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
14853 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14854 &do_align, 16, 16, 32, 32, -1);
14855 if (align_good == FAIL)
14856 return;
14857 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14858 {
14859 case 1: break;
14860 case 2: inst.instruction |= 1 << 5; break;
14861 default: first_error (_("bad list length")); return;
14862 }
14863 inst.instruction |= neon_logbits (et.size) << 6;
14864 break;
14865
14866 case 1: /* VLD2. */
14867 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14868 &do_align, 8, 16, 16, 32, 32, 64, -1);
14869 if (align_good == FAIL)
14870 return;
14871 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14872 _("bad list length"));
14873 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14874 inst.instruction |= 1 << 5;
14875 inst.instruction |= neon_logbits (et.size) << 6;
14876 break;
14877
14878 case 2: /* VLD3. */
14879 constraint (inst.operands[1].immisalign,
14880 _("can't use alignment with this instruction"));
14881 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14882 _("bad list length"));
14883 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14884 inst.instruction |= 1 << 5;
14885 inst.instruction |= neon_logbits (et.size) << 6;
14886 break;
14887
14888 case 3: /* VLD4. */
14889 {
14890 int align = inst.operands[1].imm >> 8;
14891 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14892 16, 64, 32, 64, 32, 128, -1);
14893 if (align_good == FAIL)
14894 return;
14895 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14896 _("bad list length"));
14897 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14898 inst.instruction |= 1 << 5;
14899 if (et.size == 32 && align == 128)
14900 inst.instruction |= 0x3 << 6;
14901 else
14902 inst.instruction |= neon_logbits (et.size) << 6;
14903 }
14904 break;
14905
14906 default: ;
14907 }
14908
14909 inst.instruction |= do_align << 4;
14910 }
14911
14912 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14913 apart from bits [11:4]. */
14914
14915 static void
14916 do_neon_ldx_stx (void)
14917 {
14918 if (inst.operands[1].isreg)
14919 constraint (inst.operands[1].reg == REG_PC, BAD_PC);
14920
14921 switch (NEON_LANE (inst.operands[0].imm))
14922 {
14923 case NEON_INTERLEAVE_LANES:
14924 NEON_ENCODE (INTERLV, inst);
14925 do_neon_ld_st_interleave ();
14926 break;
14927
14928 case NEON_ALL_LANES:
14929 NEON_ENCODE (DUP, inst);
14930 do_neon_ld_dup ();
14931 break;
14932
14933 default:
14934 NEON_ENCODE (LANE, inst);
14935 do_neon_ld_st_lane ();
14936 }
14937
14938 /* L bit comes from bit mask. */
14939 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14940 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14941 inst.instruction |= inst.operands[1].reg << 16;
14942
14943 if (inst.operands[1].postind)
14944 {
14945 int postreg = inst.operands[1].imm & 0xf;
14946 constraint (!inst.operands[1].immisreg,
14947 _("post-index must be a register"));
14948 constraint (postreg == 0xd || postreg == 0xf,
14949 _("bad register for post-index"));
14950 inst.instruction |= postreg;
14951 }
14952 else if (inst.operands[1].writeback)
14953 {
14954 inst.instruction |= 0xd;
14955 }
14956 else
14957 inst.instruction |= 0xf;
14958
14959 if (thumb_mode)
14960 inst.instruction |= 0xf9000000;
14961 else
14962 inst.instruction |= 0xf4000000;
14963 }
14964 \f
14965 /* Overall per-instruction processing. */
14966
14967 /* We need to be able to fix up arbitrary expressions in some statements.
14968 This is so that we can handle symbols that are an arbitrary distance from
14969 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14970 which returns part of an address in a form which will be valid for
14971 a data instruction. We do this by pushing the expression into a symbol
14972 in the expr_section, and creating a fix for that. */
14973
14974 static void
14975 fix_new_arm (fragS * frag,
14976 int where,
14977 short int size,
14978 expressionS * exp,
14979 int pc_rel,
14980 int reloc)
14981 {
14982 fixS * new_fix;
14983
14984 switch (exp->X_op)
14985 {
14986 case O_constant:
14987 case O_symbol:
14988 case O_add:
14989 case O_subtract:
14990 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
14991 (enum bfd_reloc_code_real) reloc);
14992 break;
14993
14994 default:
14995 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
14996 pc_rel, (enum bfd_reloc_code_real) reloc);
14997 break;
14998 }
14999
15000 /* Mark whether the fix is to a THUMB instruction, or an ARM
15001 instruction. */
15002 new_fix->tc_fix_data = thumb_mode;
15003 }
15004
15005 /* Create a frg for an instruction requiring relaxation. */
15006 static void
15007 output_relax_insn (void)
15008 {
15009 char * to;
15010 symbolS *sym;
15011 int offset;
15012
15013 /* The size of the instruction is unknown, so tie the debug info to the
15014 start of the instruction. */
15015 dwarf2_emit_insn (0);
15016
15017 switch (inst.reloc.exp.X_op)
15018 {
15019 case O_symbol:
15020 sym = inst.reloc.exp.X_add_symbol;
15021 offset = inst.reloc.exp.X_add_number;
15022 break;
15023 case O_constant:
15024 sym = NULL;
15025 offset = inst.reloc.exp.X_add_number;
15026 break;
15027 default:
15028 sym = make_expr_symbol (&inst.reloc.exp);
15029 offset = 0;
15030 break;
15031 }
15032 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
15033 inst.relax, sym, offset, NULL/*offset, opcode*/);
15034 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
15035 }
15036
15037 /* Write a 32-bit thumb instruction to buf. */
15038 static void
15039 put_thumb32_insn (char * buf, unsigned long insn)
15040 {
15041 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
15042 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
15043 }
15044
15045 static void
15046 output_inst (const char * str)
15047 {
15048 char * to = NULL;
15049
15050 if (inst.error)
15051 {
15052 as_bad ("%s -- `%s'", inst.error, str);
15053 return;
15054 }
15055 if (inst.relax)
15056 {
15057 output_relax_insn ();
15058 return;
15059 }
15060 if (inst.size == 0)
15061 return;
15062
15063 to = frag_more (inst.size);
15064 /* PR 9814: Record the thumb mode into the current frag so that we know
15065 what type of NOP padding to use, if necessary. We override any previous
15066 setting so that if the mode has changed then the NOPS that we use will
15067 match the encoding of the last instruction in the frag. */
15068 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
15069
15070 if (thumb_mode && (inst.size > THUMB_SIZE))
15071 {
15072 gas_assert (inst.size == (2 * THUMB_SIZE));
15073 put_thumb32_insn (to, inst.instruction);
15074 }
15075 else if (inst.size > INSN_SIZE)
15076 {
15077 gas_assert (inst.size == (2 * INSN_SIZE));
15078 md_number_to_chars (to, inst.instruction, INSN_SIZE);
15079 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
15080 }
15081 else
15082 md_number_to_chars (to, inst.instruction, inst.size);
15083
15084 if (inst.reloc.type != BFD_RELOC_UNUSED)
15085 fix_new_arm (frag_now, to - frag_now->fr_literal,
15086 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
15087 inst.reloc.type);
15088
15089 dwarf2_emit_insn (inst.size);
15090 }
15091
15092 static char *
15093 output_it_inst (int cond, int mask, char * to)
15094 {
15095 unsigned long instruction = 0xbf00;
15096
15097 mask &= 0xf;
15098 instruction |= mask;
15099 instruction |= cond << 4;
15100
15101 if (to == NULL)
15102 {
15103 to = frag_more (2);
15104 #ifdef OBJ_ELF
15105 dwarf2_emit_insn (2);
15106 #endif
15107 }
15108
15109 md_number_to_chars (to, instruction, 2);
15110
15111 return to;
15112 }
15113
15114 /* Tag values used in struct asm_opcode's tag field. */
15115 enum opcode_tag
15116 {
15117 OT_unconditional, /* Instruction cannot be conditionalized.
15118 The ARM condition field is still 0xE. */
15119 OT_unconditionalF, /* Instruction cannot be conditionalized
15120 and carries 0xF in its ARM condition field. */
15121 OT_csuffix, /* Instruction takes a conditional suffix. */
15122 OT_csuffixF, /* Some forms of the instruction take a conditional
15123 suffix, others place 0xF where the condition field
15124 would be. */
15125 OT_cinfix3, /* Instruction takes a conditional infix,
15126 beginning at character index 3. (In
15127 unified mode, it becomes a suffix.) */
15128 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
15129 tsts, cmps, cmns, and teqs. */
15130 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
15131 character index 3, even in unified mode. Used for
15132 legacy instructions where suffix and infix forms
15133 may be ambiguous. */
15134 OT_csuf_or_in3, /* Instruction takes either a conditional
15135 suffix or an infix at character index 3. */
15136 OT_odd_infix_unc, /* This is the unconditional variant of an
15137 instruction that takes a conditional infix
15138 at an unusual position. In unified mode,
15139 this variant will accept a suffix. */
15140 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
15141 are the conditional variants of instructions that
15142 take conditional infixes in unusual positions.
15143 The infix appears at character index
15144 (tag - OT_odd_infix_0). These are not accepted
15145 in unified mode. */
15146 };
15147
15148 /* Subroutine of md_assemble, responsible for looking up the primary
15149 opcode from the mnemonic the user wrote. STR points to the
15150 beginning of the mnemonic.
15151
15152 This is not simply a hash table lookup, because of conditional
15153 variants. Most instructions have conditional variants, which are
15154 expressed with a _conditional affix_ to the mnemonic. If we were
15155 to encode each conditional variant as a literal string in the opcode
15156 table, it would have approximately 20,000 entries.
15157
15158 Most mnemonics take this affix as a suffix, and in unified syntax,
15159 'most' is upgraded to 'all'. However, in the divided syntax, some
15160 instructions take the affix as an infix, notably the s-variants of
15161 the arithmetic instructions. Of those instructions, all but six
15162 have the infix appear after the third character of the mnemonic.
15163
15164 Accordingly, the algorithm for looking up primary opcodes given
15165 an identifier is:
15166
15167 1. Look up the identifier in the opcode table.
15168 If we find a match, go to step U.
15169
15170 2. Look up the last two characters of the identifier in the
15171 conditions table. If we find a match, look up the first N-2
15172 characters of the identifier in the opcode table. If we
15173 find a match, go to step CE.
15174
15175 3. Look up the fourth and fifth characters of the identifier in
15176 the conditions table. If we find a match, extract those
15177 characters from the identifier, and look up the remaining
15178 characters in the opcode table. If we find a match, go
15179 to step CM.
15180
15181 4. Fail.
15182
15183 U. Examine the tag field of the opcode structure, in case this is
15184 one of the six instructions with its conditional infix in an
15185 unusual place. If it is, the tag tells us where to find the
15186 infix; look it up in the conditions table and set inst.cond
15187 accordingly. Otherwise, this is an unconditional instruction.
15188 Again set inst.cond accordingly. Return the opcode structure.
15189
15190 CE. Examine the tag field to make sure this is an instruction that
15191 should receive a conditional suffix. If it is not, fail.
15192 Otherwise, set inst.cond from the suffix we already looked up,
15193 and return the opcode structure.
15194
15195 CM. Examine the tag field to make sure this is an instruction that
15196 should receive a conditional infix after the third character.
15197 If it is not, fail. Otherwise, undo the edits to the current
15198 line of input and proceed as for case CE. */
15199
15200 static const struct asm_opcode *
15201 opcode_lookup (char **str)
15202 {
15203 char *end, *base;
15204 char *affix;
15205 const struct asm_opcode *opcode;
15206 const struct asm_cond *cond;
15207 char save[2];
15208
15209 /* Scan up to the end of the mnemonic, which must end in white space,
15210 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
15211 for (base = end = *str; *end != '\0'; end++)
15212 if (*end == ' ' || *end == '.')
15213 break;
15214
15215 if (end == base)
15216 return NULL;
15217
15218 /* Handle a possible width suffix and/or Neon type suffix. */
15219 if (end[0] == '.')
15220 {
15221 int offset = 2;
15222
15223 /* The .w and .n suffixes are only valid if the unified syntax is in
15224 use. */
15225 if (unified_syntax && end[1] == 'w')
15226 inst.size_req = 4;
15227 else if (unified_syntax && end[1] == 'n')
15228 inst.size_req = 2;
15229 else
15230 offset = 0;
15231
15232 inst.vectype.elems = 0;
15233
15234 *str = end + offset;
15235
15236 if (end[offset] == '.')
15237 {
15238 /* See if we have a Neon type suffix (possible in either unified or
15239 non-unified ARM syntax mode). */
15240 if (parse_neon_type (&inst.vectype, str) == FAIL)
15241 return NULL;
15242 }
15243 else if (end[offset] != '\0' && end[offset] != ' ')
15244 return NULL;
15245 }
15246 else
15247 *str = end;
15248
15249 /* Look for unaffixed or special-case affixed mnemonic. */
15250 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15251 end - base);
15252 if (opcode)
15253 {
15254 /* step U */
15255 if (opcode->tag < OT_odd_infix_0)
15256 {
15257 inst.cond = COND_ALWAYS;
15258 return opcode;
15259 }
15260
15261 if (warn_on_deprecated && unified_syntax)
15262 as_warn (_("conditional infixes are deprecated in unified syntax"));
15263 affix = base + (opcode->tag - OT_odd_infix_0);
15264 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15265 gas_assert (cond);
15266
15267 inst.cond = cond->value;
15268 return opcode;
15269 }
15270
15271 /* Cannot have a conditional suffix on a mnemonic of less than two
15272 characters. */
15273 if (end - base < 3)
15274 return NULL;
15275
15276 /* Look for suffixed mnemonic. */
15277 affix = end - 2;
15278 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15279 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15280 affix - base);
15281 if (opcode && cond)
15282 {
15283 /* step CE */
15284 switch (opcode->tag)
15285 {
15286 case OT_cinfix3_legacy:
15287 /* Ignore conditional suffixes matched on infix only mnemonics. */
15288 break;
15289
15290 case OT_cinfix3:
15291 case OT_cinfix3_deprecated:
15292 case OT_odd_infix_unc:
15293 if (!unified_syntax)
15294 return 0;
15295 /* else fall through */
15296
15297 case OT_csuffix:
15298 case OT_csuffixF:
15299 case OT_csuf_or_in3:
15300 inst.cond = cond->value;
15301 return opcode;
15302
15303 case OT_unconditional:
15304 case OT_unconditionalF:
15305 if (thumb_mode)
15306 inst.cond = cond->value;
15307 else
15308 {
15309 /* Delayed diagnostic. */
15310 inst.error = BAD_COND;
15311 inst.cond = COND_ALWAYS;
15312 }
15313 return opcode;
15314
15315 default:
15316 return NULL;
15317 }
15318 }
15319
15320 /* Cannot have a usual-position infix on a mnemonic of less than
15321 six characters (five would be a suffix). */
15322 if (end - base < 6)
15323 return NULL;
15324
15325 /* Look for infixed mnemonic in the usual position. */
15326 affix = base + 3;
15327 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15328 if (!cond)
15329 return NULL;
15330
15331 memcpy (save, affix, 2);
15332 memmove (affix, affix + 2, (end - affix) - 2);
15333 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15334 (end - base) - 2);
15335 memmove (affix + 2, affix, (end - affix) - 2);
15336 memcpy (affix, save, 2);
15337
15338 if (opcode
15339 && (opcode->tag == OT_cinfix3
15340 || opcode->tag == OT_cinfix3_deprecated
15341 || opcode->tag == OT_csuf_or_in3
15342 || opcode->tag == OT_cinfix3_legacy))
15343 {
15344 /* Step CM. */
15345 if (warn_on_deprecated && unified_syntax
15346 && (opcode->tag == OT_cinfix3
15347 || opcode->tag == OT_cinfix3_deprecated))
15348 as_warn (_("conditional infixes are deprecated in unified syntax"));
15349
15350 inst.cond = cond->value;
15351 return opcode;
15352 }
15353
15354 return NULL;
15355 }
15356
15357 /* This function generates an initial IT instruction, leaving its block
15358 virtually open for the new instructions. Eventually,
15359 the mask will be updated by now_it_add_mask () each time
15360 a new instruction needs to be included in the IT block.
15361 Finally, the block is closed with close_automatic_it_block ().
15362 The block closure can be requested either from md_assemble (),
15363 a tencode (), or due to a label hook. */
15364
15365 static void
15366 new_automatic_it_block (int cond)
15367 {
15368 now_it.state = AUTOMATIC_IT_BLOCK;
15369 now_it.mask = 0x18;
15370 now_it.cc = cond;
15371 now_it.block_length = 1;
15372 mapping_state (MAP_THUMB);
15373 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15374 }
15375
15376 /* Close an automatic IT block.
15377 See comments in new_automatic_it_block (). */
15378
15379 static void
15380 close_automatic_it_block (void)
15381 {
15382 now_it.mask = 0x10;
15383 now_it.block_length = 0;
15384 }
15385
15386 /* Update the mask of the current automatically-generated IT
15387 instruction. See comments in new_automatic_it_block (). */
15388
15389 static void
15390 now_it_add_mask (int cond)
15391 {
15392 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15393 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15394 | ((bitvalue) << (nbit)))
15395 const int resulting_bit = (cond & 1);
15396
15397 now_it.mask &= 0xf;
15398 now_it.mask = SET_BIT_VALUE (now_it.mask,
15399 resulting_bit,
15400 (5 - now_it.block_length));
15401 now_it.mask = SET_BIT_VALUE (now_it.mask,
15402 1,
15403 ((5 - now_it.block_length) - 1) );
15404 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15405
15406 #undef CLEAR_BIT
15407 #undef SET_BIT_VALUE
15408 }
15409
15410 /* The IT blocks handling machinery is accessed through the these functions:
15411 it_fsm_pre_encode () from md_assemble ()
15412 set_it_insn_type () optional, from the tencode functions
15413 set_it_insn_type_last () ditto
15414 in_it_block () ditto
15415 it_fsm_post_encode () from md_assemble ()
15416 force_automatic_it_block_close () from label habdling functions
15417
15418 Rationale:
15419 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15420 initializing the IT insn type with a generic initial value depending
15421 on the inst.condition.
15422 2) During the tencode function, two things may happen:
15423 a) The tencode function overrides the IT insn type by
15424 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15425 b) The tencode function queries the IT block state by
15426 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15427
15428 Both set_it_insn_type and in_it_block run the internal FSM state
15429 handling function (handle_it_state), because: a) setting the IT insn
15430 type may incur in an invalid state (exiting the function),
15431 and b) querying the state requires the FSM to be updated.
15432 Specifically we want to avoid creating an IT block for conditional
15433 branches, so it_fsm_pre_encode is actually a guess and we can't
15434 determine whether an IT block is required until the tencode () routine
15435 has decided what type of instruction this actually it.
15436 Because of this, if set_it_insn_type and in_it_block have to be used,
15437 set_it_insn_type has to be called first.
15438
15439 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15440 determines the insn IT type depending on the inst.cond code.
15441 When a tencode () routine encodes an instruction that can be
15442 either outside an IT block, or, in the case of being inside, has to be
15443 the last one, set_it_insn_type_last () will determine the proper
15444 IT instruction type based on the inst.cond code. Otherwise,
15445 set_it_insn_type can be called for overriding that logic or
15446 for covering other cases.
15447
15448 Calling handle_it_state () may not transition the IT block state to
15449 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15450 still queried. Instead, if the FSM determines that the state should
15451 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15452 after the tencode () function: that's what it_fsm_post_encode () does.
15453
15454 Since in_it_block () calls the state handling function to get an
15455 updated state, an error may occur (due to invalid insns combination).
15456 In that case, inst.error is set.
15457 Therefore, inst.error has to be checked after the execution of
15458 the tencode () routine.
15459
15460 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15461 any pending state change (if any) that didn't take place in
15462 handle_it_state () as explained above. */
15463
15464 static void
15465 it_fsm_pre_encode (void)
15466 {
15467 if (inst.cond != COND_ALWAYS)
15468 inst.it_insn_type = INSIDE_IT_INSN;
15469 else
15470 inst.it_insn_type = OUTSIDE_IT_INSN;
15471
15472 now_it.state_handled = 0;
15473 }
15474
15475 /* IT state FSM handling function. */
15476
15477 static int
15478 handle_it_state (void)
15479 {
15480 now_it.state_handled = 1;
15481
15482 switch (now_it.state)
15483 {
15484 case OUTSIDE_IT_BLOCK:
15485 switch (inst.it_insn_type)
15486 {
15487 case OUTSIDE_IT_INSN:
15488 break;
15489
15490 case INSIDE_IT_INSN:
15491 case INSIDE_IT_LAST_INSN:
15492 if (thumb_mode == 0)
15493 {
15494 if (unified_syntax
15495 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15496 as_tsktsk (_("Warning: conditional outside an IT block"\
15497 " for Thumb."));
15498 }
15499 else
15500 {
15501 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15502 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15503 {
15504 /* Automatically generate the IT instruction. */
15505 new_automatic_it_block (inst.cond);
15506 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15507 close_automatic_it_block ();
15508 }
15509 else
15510 {
15511 inst.error = BAD_OUT_IT;
15512 return FAIL;
15513 }
15514 }
15515 break;
15516
15517 case IF_INSIDE_IT_LAST_INSN:
15518 case NEUTRAL_IT_INSN:
15519 break;
15520
15521 case IT_INSN:
15522 now_it.state = MANUAL_IT_BLOCK;
15523 now_it.block_length = 0;
15524 break;
15525 }
15526 break;
15527
15528 case AUTOMATIC_IT_BLOCK:
15529 /* Three things may happen now:
15530 a) We should increment current it block size;
15531 b) We should close current it block (closing insn or 4 insns);
15532 c) We should close current it block and start a new one (due
15533 to incompatible conditions or
15534 4 insns-length block reached). */
15535
15536 switch (inst.it_insn_type)
15537 {
15538 case OUTSIDE_IT_INSN:
15539 /* The closure of the block shall happen immediatelly,
15540 so any in_it_block () call reports the block as closed. */
15541 force_automatic_it_block_close ();
15542 break;
15543
15544 case INSIDE_IT_INSN:
15545 case INSIDE_IT_LAST_INSN:
15546 case IF_INSIDE_IT_LAST_INSN:
15547 now_it.block_length++;
15548
15549 if (now_it.block_length > 4
15550 || !now_it_compatible (inst.cond))
15551 {
15552 force_automatic_it_block_close ();
15553 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15554 new_automatic_it_block (inst.cond);
15555 }
15556 else
15557 {
15558 now_it_add_mask (inst.cond);
15559 }
15560
15561 if (now_it.state == AUTOMATIC_IT_BLOCK
15562 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15563 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15564 close_automatic_it_block ();
15565 break;
15566
15567 case NEUTRAL_IT_INSN:
15568 now_it.block_length++;
15569
15570 if (now_it.block_length > 4)
15571 force_automatic_it_block_close ();
15572 else
15573 now_it_add_mask (now_it.cc & 1);
15574 break;
15575
15576 case IT_INSN:
15577 close_automatic_it_block ();
15578 now_it.state = MANUAL_IT_BLOCK;
15579 break;
15580 }
15581 break;
15582
15583 case MANUAL_IT_BLOCK:
15584 {
15585 /* Check conditional suffixes. */
15586 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15587 int is_last;
15588 now_it.mask <<= 1;
15589 now_it.mask &= 0x1f;
15590 is_last = (now_it.mask == 0x10);
15591
15592 switch (inst.it_insn_type)
15593 {
15594 case OUTSIDE_IT_INSN:
15595 inst.error = BAD_NOT_IT;
15596 return FAIL;
15597
15598 case INSIDE_IT_INSN:
15599 if (cond != inst.cond)
15600 {
15601 inst.error = BAD_IT_COND;
15602 return FAIL;
15603 }
15604 break;
15605
15606 case INSIDE_IT_LAST_INSN:
15607 case IF_INSIDE_IT_LAST_INSN:
15608 if (cond != inst.cond)
15609 {
15610 inst.error = BAD_IT_COND;
15611 return FAIL;
15612 }
15613 if (!is_last)
15614 {
15615 inst.error = BAD_BRANCH;
15616 return FAIL;
15617 }
15618 break;
15619
15620 case NEUTRAL_IT_INSN:
15621 /* The BKPT instruction is unconditional even in an IT block. */
15622 break;
15623
15624 case IT_INSN:
15625 inst.error = BAD_IT_IT;
15626 return FAIL;
15627 }
15628 }
15629 break;
15630 }
15631
15632 return SUCCESS;
15633 }
15634
15635 static void
15636 it_fsm_post_encode (void)
15637 {
15638 int is_last;
15639
15640 if (!now_it.state_handled)
15641 handle_it_state ();
15642
15643 is_last = (now_it.mask == 0x10);
15644 if (is_last)
15645 {
15646 now_it.state = OUTSIDE_IT_BLOCK;
15647 now_it.mask = 0;
15648 }
15649 }
15650
15651 static void
15652 force_automatic_it_block_close (void)
15653 {
15654 if (now_it.state == AUTOMATIC_IT_BLOCK)
15655 {
15656 close_automatic_it_block ();
15657 now_it.state = OUTSIDE_IT_BLOCK;
15658 now_it.mask = 0;
15659 }
15660 }
15661
15662 static int
15663 in_it_block (void)
15664 {
15665 if (!now_it.state_handled)
15666 handle_it_state ();
15667
15668 return now_it.state != OUTSIDE_IT_BLOCK;
15669 }
15670
15671 void
15672 md_assemble (char *str)
15673 {
15674 char *p = str;
15675 const struct asm_opcode * opcode;
15676
15677 /* Align the previous label if needed. */
15678 if (last_label_seen != NULL)
15679 {
15680 symbol_set_frag (last_label_seen, frag_now);
15681 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15682 S_SET_SEGMENT (last_label_seen, now_seg);
15683 }
15684
15685 memset (&inst, '\0', sizeof (inst));
15686 inst.reloc.type = BFD_RELOC_UNUSED;
15687
15688 opcode = opcode_lookup (&p);
15689 if (!opcode)
15690 {
15691 /* It wasn't an instruction, but it might be a register alias of
15692 the form alias .req reg, or a Neon .dn/.qn directive. */
15693 if (! create_register_alias (str, p)
15694 && ! create_neon_reg_alias (str, p))
15695 as_bad (_("bad instruction `%s'"), str);
15696
15697 return;
15698 }
15699
15700 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
15701 as_warn (_("s suffix on comparison instruction is deprecated"));
15702
15703 /* The value which unconditional instructions should have in place of the
15704 condition field. */
15705 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15706
15707 if (thumb_mode)
15708 {
15709 arm_feature_set variant;
15710
15711 variant = cpu_variant;
15712 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
15713 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15714 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
15715 /* Check that this instruction is supported for this CPU. */
15716 if (!opcode->tvariant
15717 || (thumb_mode == 1
15718 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
15719 {
15720 as_bad (_("selected processor does not support Thumb mode `%s'"), str);
15721 return;
15722 }
15723 if (inst.cond != COND_ALWAYS && !unified_syntax
15724 && opcode->tencode != do_t_branch)
15725 {
15726 as_bad (_("Thumb does not support conditional execution"));
15727 return;
15728 }
15729
15730 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
15731 {
15732 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
15733 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15734 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15735 {
15736 /* Two things are addressed here.
15737 1) Implicit require narrow instructions on Thumb-1.
15738 This avoids relaxation accidentally introducing Thumb-2
15739 instructions.
15740 2) Reject wide instructions in non Thumb-2 cores. */
15741 if (inst.size_req == 0)
15742 inst.size_req = 2;
15743 else if (inst.size_req == 4)
15744 {
15745 as_bad (_("selected processor does not support Thumb-2 mode `%s'"), str);
15746 return;
15747 }
15748 }
15749 }
15750
15751 inst.instruction = opcode->tvalue;
15752
15753 if (!parse_operands (p, opcode->operands, /*thumb=*/TRUE))
15754 {
15755 /* Prepare the it_insn_type for those encodings that don't set
15756 it. */
15757 it_fsm_pre_encode ();
15758
15759 opcode->tencode ();
15760
15761 it_fsm_post_encode ();
15762 }
15763
15764 if (!(inst.error || inst.relax))
15765 {
15766 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
15767 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15768 if (inst.size_req && inst.size_req != inst.size)
15769 {
15770 as_bad (_("cannot honor width suffix -- `%s'"), str);
15771 return;
15772 }
15773 }
15774
15775 /* Something has gone badly wrong if we try to relax a fixed size
15776 instruction. */
15777 gas_assert (inst.size_req == 0 || !inst.relax);
15778
15779 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15780 *opcode->tvariant);
15781 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
15782 set those bits when Thumb-2 32-bit instructions are seen. ie.
15783 anything other than bl/blx and v6-M instructions.
15784 This is overly pessimistic for relaxable instructions. */
15785 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15786 || inst.relax)
15787 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15788 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
15789 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15790 arm_ext_v6t2);
15791
15792 check_neon_suffixes;
15793
15794 if (!inst.error)
15795 {
15796 mapping_state (MAP_THUMB);
15797 }
15798 }
15799 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
15800 {
15801 bfd_boolean is_bx;
15802
15803 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15804 is_bx = (opcode->aencode == do_bx);
15805
15806 /* Check that this instruction is supported for this CPU. */
15807 if (!(is_bx && fix_v4bx)
15808 && !(opcode->avariant &&
15809 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
15810 {
15811 as_bad (_("selected processor does not support ARM mode `%s'"), str);
15812 return;
15813 }
15814 if (inst.size_req)
15815 {
15816 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15817 return;
15818 }
15819
15820 inst.instruction = opcode->avalue;
15821 if (opcode->tag == OT_unconditionalF)
15822 inst.instruction |= 0xF << 28;
15823 else
15824 inst.instruction |= inst.cond << 28;
15825 inst.size = INSN_SIZE;
15826 if (!parse_operands (p, opcode->operands, /*thumb=*/FALSE))
15827 {
15828 it_fsm_pre_encode ();
15829 opcode->aencode ();
15830 it_fsm_post_encode ();
15831 }
15832 /* Arm mode bx is marked as both v4T and v5 because it's still required
15833 on a hypothetical non-thumb v5 core. */
15834 if (is_bx)
15835 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
15836 else
15837 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15838 *opcode->avariant);
15839
15840 check_neon_suffixes;
15841
15842 if (!inst.error)
15843 {
15844 mapping_state (MAP_ARM);
15845 }
15846 }
15847 else
15848 {
15849 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15850 "-- `%s'"), str);
15851 return;
15852 }
15853 output_inst (str);
15854 }
15855
15856 static void
15857 check_it_blocks_finished (void)
15858 {
15859 #ifdef OBJ_ELF
15860 asection *sect;
15861
15862 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15863 if (seg_info (sect)->tc_segment_info_data.current_it.state
15864 == MANUAL_IT_BLOCK)
15865 {
15866 as_warn (_("section '%s' finished with an open IT block."),
15867 sect->name);
15868 }
15869 #else
15870 if (now_it.state == MANUAL_IT_BLOCK)
15871 as_warn (_("file finished with an open IT block."));
15872 #endif
15873 }
15874
15875 /* Various frobbings of labels and their addresses. */
15876
15877 void
15878 arm_start_line_hook (void)
15879 {
15880 last_label_seen = NULL;
15881 }
15882
15883 void
15884 arm_frob_label (symbolS * sym)
15885 {
15886 last_label_seen = sym;
15887
15888 ARM_SET_THUMB (sym, thumb_mode);
15889
15890 #if defined OBJ_COFF || defined OBJ_ELF
15891 ARM_SET_INTERWORK (sym, support_interwork);
15892 #endif
15893
15894 force_automatic_it_block_close ();
15895
15896 /* Note - do not allow local symbols (.Lxxx) to be labelled
15897 as Thumb functions. This is because these labels, whilst
15898 they exist inside Thumb code, are not the entry points for
15899 possible ARM->Thumb calls. Also, these labels can be used
15900 as part of a computed goto or switch statement. eg gcc
15901 can generate code that looks like this:
15902
15903 ldr r2, [pc, .Laaa]
15904 lsl r3, r3, #2
15905 ldr r2, [r3, r2]
15906 mov pc, r2
15907
15908 .Lbbb: .word .Lxxx
15909 .Lccc: .word .Lyyy
15910 ..etc...
15911 .Laaa: .word Lbbb
15912
15913 The first instruction loads the address of the jump table.
15914 The second instruction converts a table index into a byte offset.
15915 The third instruction gets the jump address out of the table.
15916 The fourth instruction performs the jump.
15917
15918 If the address stored at .Laaa is that of a symbol which has the
15919 Thumb_Func bit set, then the linker will arrange for this address
15920 to have the bottom bit set, which in turn would mean that the
15921 address computation performed by the third instruction would end
15922 up with the bottom bit set. Since the ARM is capable of unaligned
15923 word loads, the instruction would then load the incorrect address
15924 out of the jump table, and chaos would ensue. */
15925 if (label_is_thumb_function_name
15926 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15927 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
15928 {
15929 /* When the address of a Thumb function is taken the bottom
15930 bit of that address should be set. This will allow
15931 interworking between Arm and Thumb functions to work
15932 correctly. */
15933
15934 THUMB_SET_FUNC (sym, 1);
15935
15936 label_is_thumb_function_name = FALSE;
15937 }
15938
15939 dwarf2_emit_label (sym);
15940 }
15941
15942 bfd_boolean
15943 arm_data_in_code (void)
15944 {
15945 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
15946 {
15947 *input_line_pointer = '/';
15948 input_line_pointer += 5;
15949 *input_line_pointer = 0;
15950 return TRUE;
15951 }
15952
15953 return FALSE;
15954 }
15955
15956 char *
15957 arm_canonicalize_symbol_name (char * name)
15958 {
15959 int len;
15960
15961 if (thumb_mode && (len = strlen (name)) > 5
15962 && streq (name + len - 5, "/data"))
15963 *(name + len - 5) = 0;
15964
15965 return name;
15966 }
15967 \f
15968 /* Table of all register names defined by default. The user can
15969 define additional names with .req. Note that all register names
15970 should appear in both upper and lowercase variants. Some registers
15971 also have mixed-case names. */
15972
15973 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
15974 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
15975 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
15976 #define REGSET(p,t) \
15977 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15978 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15979 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15980 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
15981 #define REGSETH(p,t) \
15982 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15983 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15984 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15985 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15986 #define REGSET2(p,t) \
15987 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15988 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15989 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15990 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
15991
15992 static const struct reg_entry reg_names[] =
15993 {
15994 /* ARM integer registers. */
15995 REGSET(r, RN), REGSET(R, RN),
15996
15997 /* ATPCS synonyms. */
15998 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15999 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
16000 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
16001
16002 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
16003 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
16004 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
16005
16006 /* Well-known aliases. */
16007 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
16008 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
16009
16010 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
16011 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
16012
16013 /* Coprocessor numbers. */
16014 REGSET(p, CP), REGSET(P, CP),
16015
16016 /* Coprocessor register numbers. The "cr" variants are for backward
16017 compatibility. */
16018 REGSET(c, CN), REGSET(C, CN),
16019 REGSET(cr, CN), REGSET(CR, CN),
16020
16021 /* FPA registers. */
16022 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
16023 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
16024
16025 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
16026 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
16027
16028 /* VFP SP registers. */
16029 REGSET(s,VFS), REGSET(S,VFS),
16030 REGSETH(s,VFS), REGSETH(S,VFS),
16031
16032 /* VFP DP Registers. */
16033 REGSET(d,VFD), REGSET(D,VFD),
16034 /* Extra Neon DP registers. */
16035 REGSETH(d,VFD), REGSETH(D,VFD),
16036
16037 /* Neon QP registers. */
16038 REGSET2(q,NQ), REGSET2(Q,NQ),
16039
16040 /* VFP control registers. */
16041 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
16042 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
16043 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
16044 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
16045 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
16046 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
16047
16048 /* Maverick DSP coprocessor registers. */
16049 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
16050 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
16051
16052 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
16053 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
16054 REGDEF(dspsc,0,DSPSC),
16055
16056 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
16057 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
16058 REGDEF(DSPSC,0,DSPSC),
16059
16060 /* iWMMXt data registers - p0, c0-15. */
16061 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
16062
16063 /* iWMMXt control registers - p1, c0-3. */
16064 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
16065 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
16066 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
16067 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
16068
16069 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
16070 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
16071 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
16072 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
16073 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
16074
16075 /* XScale accumulator registers. */
16076 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
16077 };
16078 #undef REGDEF
16079 #undef REGNUM
16080 #undef REGSET
16081
16082 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
16083 within psr_required_here. */
16084 static const struct asm_psr psrs[] =
16085 {
16086 /* Backward compatibility notation. Note that "all" is no longer
16087 truly all possible PSR bits. */
16088 {"all", PSR_c | PSR_f},
16089 {"flg", PSR_f},
16090 {"ctl", PSR_c},
16091
16092 /* Individual flags. */
16093 {"f", PSR_f},
16094 {"c", PSR_c},
16095 {"x", PSR_x},
16096 {"s", PSR_s},
16097 /* Combinations of flags. */
16098 {"fs", PSR_f | PSR_s},
16099 {"fx", PSR_f | PSR_x},
16100 {"fc", PSR_f | PSR_c},
16101 {"sf", PSR_s | PSR_f},
16102 {"sx", PSR_s | PSR_x},
16103 {"sc", PSR_s | PSR_c},
16104 {"xf", PSR_x | PSR_f},
16105 {"xs", PSR_x | PSR_s},
16106 {"xc", PSR_x | PSR_c},
16107 {"cf", PSR_c | PSR_f},
16108 {"cs", PSR_c | PSR_s},
16109 {"cx", PSR_c | PSR_x},
16110 {"fsx", PSR_f | PSR_s | PSR_x},
16111 {"fsc", PSR_f | PSR_s | PSR_c},
16112 {"fxs", PSR_f | PSR_x | PSR_s},
16113 {"fxc", PSR_f | PSR_x | PSR_c},
16114 {"fcs", PSR_f | PSR_c | PSR_s},
16115 {"fcx", PSR_f | PSR_c | PSR_x},
16116 {"sfx", PSR_s | PSR_f | PSR_x},
16117 {"sfc", PSR_s | PSR_f | PSR_c},
16118 {"sxf", PSR_s | PSR_x | PSR_f},
16119 {"sxc", PSR_s | PSR_x | PSR_c},
16120 {"scf", PSR_s | PSR_c | PSR_f},
16121 {"scx", PSR_s | PSR_c | PSR_x},
16122 {"xfs", PSR_x | PSR_f | PSR_s},
16123 {"xfc", PSR_x | PSR_f | PSR_c},
16124 {"xsf", PSR_x | PSR_s | PSR_f},
16125 {"xsc", PSR_x | PSR_s | PSR_c},
16126 {"xcf", PSR_x | PSR_c | PSR_f},
16127 {"xcs", PSR_x | PSR_c | PSR_s},
16128 {"cfs", PSR_c | PSR_f | PSR_s},
16129 {"cfx", PSR_c | PSR_f | PSR_x},
16130 {"csf", PSR_c | PSR_s | PSR_f},
16131 {"csx", PSR_c | PSR_s | PSR_x},
16132 {"cxf", PSR_c | PSR_x | PSR_f},
16133 {"cxs", PSR_c | PSR_x | PSR_s},
16134 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
16135 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
16136 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
16137 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
16138 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
16139 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
16140 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
16141 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
16142 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
16143 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
16144 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
16145 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
16146 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
16147 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
16148 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
16149 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
16150 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
16151 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
16152 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
16153 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
16154 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
16155 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
16156 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
16157 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
16158 };
16159
16160 /* Table of V7M psr names. */
16161 static const struct asm_psr v7m_psrs[] =
16162 {
16163 {"apsr", 0 }, {"APSR", 0 },
16164 {"iapsr", 1 }, {"IAPSR", 1 },
16165 {"eapsr", 2 }, {"EAPSR", 2 },
16166 {"psr", 3 }, {"PSR", 3 },
16167 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16168 {"ipsr", 5 }, {"IPSR", 5 },
16169 {"epsr", 6 }, {"EPSR", 6 },
16170 {"iepsr", 7 }, {"IEPSR", 7 },
16171 {"msp", 8 }, {"MSP", 8 },
16172 {"psp", 9 }, {"PSP", 9 },
16173 {"primask", 16}, {"PRIMASK", 16},
16174 {"basepri", 17}, {"BASEPRI", 17},
16175 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16176 {"faultmask", 19}, {"FAULTMASK", 19},
16177 {"control", 20}, {"CONTROL", 20}
16178 };
16179
16180 /* Table of all shift-in-operand names. */
16181 static const struct asm_shift_name shift_names [] =
16182 {
16183 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16184 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16185 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16186 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16187 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16188 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16189 };
16190
16191 /* Table of all explicit relocation names. */
16192 #ifdef OBJ_ELF
16193 static struct reloc_entry reloc_names[] =
16194 {
16195 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16196 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16197 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16198 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16199 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16200 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16201 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16202 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16203 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16204 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16205 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
16206 { "got_prel", BFD_RELOC_ARM_GOT_PREL}, { "GOT_PREL", BFD_RELOC_ARM_GOT_PREL}
16207 };
16208 #endif
16209
16210 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
16211 static const struct asm_cond conds[] =
16212 {
16213 {"eq", 0x0},
16214 {"ne", 0x1},
16215 {"cs", 0x2}, {"hs", 0x2},
16216 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16217 {"mi", 0x4},
16218 {"pl", 0x5},
16219 {"vs", 0x6},
16220 {"vc", 0x7},
16221 {"hi", 0x8},
16222 {"ls", 0x9},
16223 {"ge", 0xa},
16224 {"lt", 0xb},
16225 {"gt", 0xc},
16226 {"le", 0xd},
16227 {"al", 0xe}
16228 };
16229
16230 static struct asm_barrier_opt barrier_opt_names[] =
16231 {
16232 { "sy", 0xf },
16233 { "un", 0x7 },
16234 { "st", 0xe },
16235 { "unst", 0x6 }
16236 };
16237
16238 /* Table of ARM-format instructions. */
16239
16240 /* Macros for gluing together operand strings. N.B. In all cases
16241 other than OPS0, the trailing OP_stop comes from default
16242 zero-initialization of the unspecified elements of the array. */
16243 #define OPS0() { OP_stop, }
16244 #define OPS1(a) { OP_##a, }
16245 #define OPS2(a,b) { OP_##a,OP_##b, }
16246 #define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16247 #define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16248 #define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16249 #define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16250
16251 /* These macros are similar to the OPSn, but do not prepend the OP_ prefix.
16252 This is useful when mixing operands for ARM and THUMB, i.e. using the
16253 MIX_ARM_THUMB_OPERANDS macro.
16254 In order to use these macros, prefix the number of operands with _
16255 e.g. _3. */
16256 #define OPS_1(a) { a, }
16257 #define OPS_2(a,b) { a,b, }
16258 #define OPS_3(a,b,c) { a,b,c, }
16259 #define OPS_4(a,b,c,d) { a,b,c,d, }
16260 #define OPS_5(a,b,c,d,e) { a,b,c,d,e, }
16261 #define OPS_6(a,b,c,d,e,f) { a,b,c,d,e,f, }
16262
16263 /* These macros abstract out the exact format of the mnemonic table and
16264 save some repeated characters. */
16265
16266 /* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16267 #define TxCE(mnem, op, top, nops, ops, ae, te) \
16268 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
16269 THUMB_VARIANT, do_##ae, do_##te }
16270
16271 /* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16272 a T_MNEM_xyz enumerator. */
16273 #define TCE(mnem, aop, top, nops, ops, ae, te) \
16274 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
16275 #define tCE(mnem, aop, top, nops, ops, ae, te) \
16276 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16277
16278 /* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16279 infix after the third character. */
16280 #define TxC3(mnem, op, top, nops, ops, ae, te) \
16281 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
16282 THUMB_VARIANT, do_##ae, do_##te }
16283 #define TxC3w(mnem, op, top, nops, ops, ae, te) \
16284 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
16285 THUMB_VARIANT, do_##ae, do_##te }
16286 #define TC3(mnem, aop, top, nops, ops, ae, te) \
16287 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
16288 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
16289 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
16290 #define tC3(mnem, aop, top, nops, ops, ae, te) \
16291 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16292 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
16293 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
16294
16295 /* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16296 appear in the condition table. */
16297 #define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
16298 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16299 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
16300
16301 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
16302 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16303 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16304 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16305 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16306 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16307 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16308 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16309 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16310 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16311 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16312 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16313 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16314 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16315 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16316 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16317 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16318 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16319 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16320 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
16321
16322 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
16323 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16324 #define tCM(m1,m2, aop, top, nops, ops, ae, te) \
16325 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
16326
16327 /* Mnemonic that cannot be conditionalized. The ARM condition-code
16328 field is still 0xE. Many of the Thumb variants can be executed
16329 conditionally, so this is checked separately. */
16330 #define TUE(mnem, op, top, nops, ops, ae, te) \
16331 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
16332 THUMB_VARIANT, do_##ae, do_##te }
16333
16334 /* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16335 condition code field. */
16336 #define TUF(mnem, op, top, nops, ops, ae, te) \
16337 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
16338 THUMB_VARIANT, do_##ae, do_##te }
16339
16340 /* ARM-only variants of all the above. */
16341 #define CE(mnem, op, nops, ops, ae) \
16342 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16343
16344 #define C3(mnem, op, nops, ops, ae) \
16345 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16346
16347 /* Legacy mnemonics that always have conditional infix after the third
16348 character. */
16349 #define CL(mnem, op, nops, ops, ae) \
16350 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16351 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16352
16353 /* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16354 #define cCE(mnem, op, nops, ops, ae) \
16355 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16356
16357 /* Legacy coprocessor instructions where conditional infix and conditional
16358 suffix are ambiguous. For consistency this includes all FPA instructions,
16359 not just the potentially ambiguous ones. */
16360 #define cCL(mnem, op, nops, ops, ae) \
16361 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
16362 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16363
16364 /* Coprocessor, takes either a suffix or a position-3 infix
16365 (for an FPA corner case). */
16366 #define C3E(mnem, op, nops, ops, ae) \
16367 { mnem, OPS##nops ops, OT_csuf_or_in3, \
16368 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16369
16370 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
16371 { m1 #m2 m3, OPS##nops ops, \
16372 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
16373 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16374
16375 #define CM(m1, m2, op, nops, ops, ae) \
16376 xCM_ (m1, , m2, op, nops, ops, ae), \
16377 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16378 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16379 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16380 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16381 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16382 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16383 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16384 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16385 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16386 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16387 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16388 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16389 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16390 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16391 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16392 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16393 xCM_ (m1, le, m2, op, nops, ops, ae), \
16394 xCM_ (m1, al, m2, op, nops, ops, ae)
16395
16396 #define UE(mnem, op, nops, ops, ae) \
16397 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16398
16399 #define UF(mnem, op, nops, ops, ae) \
16400 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16401
16402 /* Neon data-processing. ARM versions are unconditional with cond=0xf.
16403 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16404 use the same encoding function for each. */
16405 #define NUF(mnem, op, nops, ops, enc) \
16406 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16407 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16408
16409 /* Neon data processing, version which indirects through neon_enc_tab for
16410 the various overloaded versions of opcodes. */
16411 #define nUF(mnem, op, nops, ops, enc) \
16412 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
16413 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16414
16415 /* Neon insn with conditional suffix for the ARM version, non-overloaded
16416 version. */
16417 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
16418 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
16419 THUMB_VARIANT, do_##enc, do_##enc }
16420
16421 #define NCE(mnem, op, nops, ops, enc) \
16422 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16423
16424 #define NCEF(mnem, op, nops, ops, enc) \
16425 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16426
16427 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
16428 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
16429 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
16430 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16431
16432 #define nCE(mnem, op, nops, ops, enc) \
16433 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
16434
16435 #define nCEF(mnem, op, nops, ops, enc) \
16436 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
16437
16438 #define do_0 0
16439
16440 static const struct asm_opcode insns[] =
16441 {
16442 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16443 #define THUMB_VARIANT &arm_ext_v4t
16444 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16445 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16446 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16447 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16448 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16449 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16450 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16451 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16452 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16453 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16454 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16455 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16456 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16457 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16458 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16459 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
16460
16461 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16462 for setting PSR flag bits. They are obsolete in V6 and do not
16463 have Thumb equivalents. */
16464 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16465 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16466 CL("tstp", 110f000, 2, (RR, SH), cmp),
16467 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16468 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16469 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16470 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16471 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16472 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16473
16474 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16475 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16476 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16477 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16478
16479 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
16480 tC3("ldrb", 4500000, _ldrb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16481 tCE("str", 4000000, _str, _2, (MIX_ARM_THUMB_OPERANDS (OP_RR,
16482 OP_RRnpc),
16483 OP_ADDRGLDR),ldst, t_ldst),
16484 tC3("strb", 4400000, _strb, 2, (RRnpc_npcsp, ADDRGLDR),ldst, t_ldst),
16485
16486 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16487 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16488 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16489 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16490 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16491 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16492
16493 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16494 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16495 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16496 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
16497
16498 /* Pseudo ops. */
16499 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
16500 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
16501 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
16502
16503 /* Thumb-compatibility pseudo ops. */
16504 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16505 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16506 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16507 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16508 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16509 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16510 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16511 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16512 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16513 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16514 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16515 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
16516
16517 /* These may simplify to neg. */
16518 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16519 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16520
16521 #undef THUMB_VARIANT
16522 #define THUMB_VARIANT & arm_ext_v6
16523
16524 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
16525
16526 /* V1 instructions with no Thumb analogue prior to V6T2. */
16527 #undef THUMB_VARIANT
16528 #define THUMB_VARIANT & arm_ext_v6t2
16529
16530 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16531 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16532 CL("teqp", 130f000, 2, (RR, SH), cmp),
16533
16534 TC3("ldrt", 4300000, f8500e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16535 TC3("ldrbt", 4700000, f8100e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16536 TC3("strt", 4200000, f8400e00, 2, (RR_npcsp, ADDR), ldstt, t_ldstt),
16537 TC3("strbt", 4600000, f8000e00, 2, (RRnpc_npcsp, ADDR),ldstt, t_ldstt),
16538
16539 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16540 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16541
16542 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16543 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16544
16545 /* V1 instructions with no Thumb analogue at all. */
16546 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
16547 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16548
16549 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16550 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16551 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16552 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16553 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16554 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16555 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16556 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16557
16558 #undef ARM_VARIANT
16559 #define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16560 #undef THUMB_VARIANT
16561 #define THUMB_VARIANT & arm_ext_v4t
16562
16563 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16564 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16565
16566 #undef THUMB_VARIANT
16567 #define THUMB_VARIANT & arm_ext_v6t2
16568
16569 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16570 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16571
16572 /* Generic coprocessor instructions. */
16573 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16574 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16575 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16576 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16577 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16578 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16579 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16580
16581 #undef ARM_VARIANT
16582 #define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16583
16584 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16585 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16586
16587 #undef ARM_VARIANT
16588 #define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16589 #undef THUMB_VARIANT
16590 #define THUMB_VARIANT & arm_ext_msr
16591
16592 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16593 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
16594
16595 #undef ARM_VARIANT
16596 #define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16597 #undef THUMB_VARIANT
16598 #define THUMB_VARIANT & arm_ext_v6t2
16599
16600 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16601 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16602 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16603 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16604 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16605 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16606 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16607 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16608
16609 #undef ARM_VARIANT
16610 #define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16611 #undef THUMB_VARIANT
16612 #define THUMB_VARIANT & arm_ext_v4t
16613
16614 tC3("ldrh", 01000b0, _ldrh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16615 tC3("strh", 00000b0, _strh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16616 tC3("ldrsh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16617 tC3("ldrsb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16618 tCM("ld","sh", 01000f0, _ldrsh, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16619 tCM("ld","sb", 01000d0, _ldrsb, 2, (RRnpc_npcsp, ADDRGLDRS), ldstv4, t_ldst),
16620
16621 #undef ARM_VARIANT
16622 #define ARM_VARIANT & arm_ext_v4t_5
16623
16624 /* ARM Architecture 4T. */
16625 /* Note: bx (and blx) are required on V5, even if the processor does
16626 not support Thumb. */
16627 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
16628
16629 #undef ARM_VARIANT
16630 #define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16631 #undef THUMB_VARIANT
16632 #define THUMB_VARIANT & arm_ext_v5t
16633
16634 /* Note: blx has 2 variants; the .value coded here is for
16635 BLX(2). Only this variant has conditional execution. */
16636 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16637 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
16638
16639 #undef THUMB_VARIANT
16640 #define THUMB_VARIANT & arm_ext_v6t2
16641
16642 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16643 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16644 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16645 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16646 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16647 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16648 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16649 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16650
16651 #undef ARM_VARIANT
16652 #define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
16653 #undef THUMB_VARIANT
16654 #define THUMB_VARIANT &arm_ext_v5exp
16655
16656 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16657 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16658 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16659 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16660
16661 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16662 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16663
16664 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16665 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16666 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16667 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16668
16669 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16670 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16671 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16672 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16673
16674 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16675 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16676
16677 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16678 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16679 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16680 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd2),
16681
16682 #undef ARM_VARIANT
16683 #define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
16684 #undef THUMB_VARIANT
16685 #define THUMB_VARIANT &arm_ext_v6t2
16686
16687 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
16688 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc_npcsp, oRRnpc_npcsp, ADDRGLDRS),
16689 ldrd, t_ldstd),
16690 TC3("strd", 00000f0, e8400000, 3, (RRnpc_npcsp, oRRnpc_npcsp,
16691 ADDRGLDRS), ldrd, t_ldstd),
16692
16693 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16694 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16695
16696 #undef ARM_VARIANT
16697 #define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16698
16699 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
16700
16701 #undef ARM_VARIANT
16702 #define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16703 #undef THUMB_VARIANT
16704 #define THUMB_VARIANT & arm_ext_v6
16705
16706 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16707 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16708 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16709 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16710 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16711 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16712 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16713 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16714 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16715 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
16716
16717 #undef THUMB_VARIANT
16718 #define THUMB_VARIANT & arm_ext_v6t2
16719
16720 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc_npcsp, ADDR), ldrex, t_ldrex),
16721 TCE("strex", 1800f90, e8400000, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16722 strex, t_strex),
16723 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16724 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16725
16726 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16727 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
16728
16729 /* ARM V6 not included in V7M. */
16730 #undef THUMB_VARIANT
16731 #define THUMB_VARIANT & arm_ext_v6_notm
16732 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16733 UF(rfeib, 9900a00, 1, (RRw), rfe),
16734 UF(rfeda, 8100a00, 1, (RRw), rfe),
16735 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16736 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16737 UF(rfefa, 9900a00, 1, (RRw), rfe),
16738 UF(rfeea, 8100a00, 1, (RRw), rfe),
16739 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16740 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16741 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16742 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16743 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
16744
16745 /* ARM V6 not included in V7M (eg. integer SIMD). */
16746 #undef THUMB_VARIANT
16747 #define THUMB_VARIANT & arm_ext_v6_dsp
16748 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16749 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16750 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16751 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16752 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16753 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16754 /* Old name for QASX. */
16755 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16756 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16757 /* Old name for QSAX. */
16758 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16759 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16760 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16761 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16762 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16763 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16764 /* Old name for SASX. */
16765 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16766 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16767 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16768 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16769 /* Old name for SHASX. */
16770 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16771 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16772 /* Old name for SHSAX. */
16773 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16774 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16775 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16776 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16777 /* Old name for SSAX. */
16778 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16779 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16780 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16781 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16782 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16783 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16784 /* Old name for UASX. */
16785 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16786 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16787 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16788 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16789 /* Old name for UHASX. */
16790 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16791 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16792 /* Old name for UHSAX. */
16793 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16794 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16795 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16796 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16797 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16798 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16799 /* Old name for UQASX. */
16800 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16801 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16802 /* Old name for UQSAX. */
16803 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16804 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16805 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16806 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16807 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16808 /* Old name for USAX. */
16809 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16810 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16811 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16812 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16813 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16814 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16815 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16816 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16817 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16818 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16819 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16820 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16821 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16822 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16823 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16824 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16825 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16826 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16827 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16828 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16829 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16830 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16831 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16832 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16833 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16834 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16835 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16836 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16837 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16838 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16839 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16840 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16841 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16842 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
16843
16844 #undef ARM_VARIANT
16845 #define ARM_VARIANT & arm_ext_v6k
16846 #undef THUMB_VARIANT
16847 #define THUMB_VARIANT & arm_ext_v6k
16848
16849 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16850 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16851 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16852 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
16853
16854 #undef THUMB_VARIANT
16855 #define THUMB_VARIANT & arm_ext_v6_notm
16856 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc_npcsp, oRRnpc_npcsp, RRnpcb),
16857 ldrexd, t_ldrexd),
16858 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc_npcsp, RRnpc_npcsp, oRRnpc_npcsp,
16859 RRnpcb), strexd, t_strexd),
16860
16861 #undef THUMB_VARIANT
16862 #define THUMB_VARIANT & arm_ext_v6t2
16863 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc_npcsp,RRnpcb),
16864 rd_rn, rd_rn),
16865 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc_npcsp, RRnpcb),
16866 rd_rn, rd_rn),
16867 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16868 strex, rm_rd_rn),
16869 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc_npcsp, RRnpc_npcsp, ADDR),
16870 strex, rm_rd_rn),
16871 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
16872
16873 #undef ARM_VARIANT
16874 #define ARM_VARIANT & arm_ext_v6z
16875
16876 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
16877
16878 #undef ARM_VARIANT
16879 #define ARM_VARIANT & arm_ext_v6t2
16880
16881 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16882 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16883 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16884 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16885
16886 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16887 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16888 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16889 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
16890
16891 TC3("ldrht", 03000b0, f8300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16892 TC3("ldrsht", 03000f0, f9300e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16893 TC3("ldrsbt", 03000d0, f9100e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16894 TC3("strht", 02000b0, f8200e00, 2, (RRnpc_npcsp, ADDR), ldsttv4, t_ldstt),
16895
16896 /* Thumb-only instructions. */
16897 #undef ARM_VARIANT
16898 #define ARM_VARIANT NULL
16899 TUE("cbnz", 0, b900, 2, (RR, EXP), 0, t_cbz),
16900 TUE("cbz", 0, b100, 2, (RR, EXP), 0, t_cbz),
16901
16902 /* ARM does not really have an IT instruction, so always allow it.
16903 The opcode is copied from Thumb in order to allow warnings in
16904 -mimplicit-it=[never | arm] modes. */
16905 #undef ARM_VARIANT
16906 #define ARM_VARIANT & arm_ext_v1
16907
16908 TUE("it", bf08, bf08, 1, (COND), it, t_it),
16909 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
16910 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
16911 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
16912 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
16913 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
16914 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
16915 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
16916 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
16917 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
16918 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
16919 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
16920 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
16921 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
16922 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
16923 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
16924 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16925 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
16926
16927 /* Thumb2 only instructions. */
16928 #undef ARM_VARIANT
16929 #define ARM_VARIANT NULL
16930
16931 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16932 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16933 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16934 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16935 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
16936 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
16937
16938 /* Thumb-2 hardware division instructions (R and M profiles only). */
16939 #undef THUMB_VARIANT
16940 #define THUMB_VARIANT & arm_ext_div
16941
16942 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16943 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
16944
16945 /* ARM V6M/V7 instructions. */
16946 #undef ARM_VARIANT
16947 #define ARM_VARIANT & arm_ext_barrier
16948 #undef THUMB_VARIANT
16949 #define THUMB_VARIANT & arm_ext_barrier
16950
16951 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16952 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16953 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
16954
16955 /* ARM V7 instructions. */
16956 #undef ARM_VARIANT
16957 #define ARM_VARIANT & arm_ext_v7
16958 #undef THUMB_VARIANT
16959 #define THUMB_VARIANT & arm_ext_v7
16960
16961 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
16962 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
16963
16964 #undef ARM_VARIANT
16965 #define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
16966
16967 cCE("wfs", e200110, 1, (RR), rd),
16968 cCE("rfs", e300110, 1, (RR), rd),
16969 cCE("wfc", e400110, 1, (RR), rd),
16970 cCE("rfc", e500110, 1, (RR), rd),
16971
16972 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16973 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16974 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16975 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
16976
16977 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16978 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16979 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16980 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
16981
16982 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
16983 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
16984 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
16985 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
16986 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
16987 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
16988 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
16989 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
16990 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
16991 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
16992 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
16993 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
16994
16995 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
16996 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
16997 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
16998 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
16999 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
17000 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
17001 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
17002 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
17003 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
17004 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
17005 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
17006 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
17007
17008 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
17009 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
17010 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
17011 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
17012 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
17013 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
17014 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
17015 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
17016 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
17017 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
17018 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
17019 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
17020
17021 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
17022 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
17023 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
17024 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
17025 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
17026 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
17027 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
17028 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
17029 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
17030 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
17031 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
17032 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
17033
17034 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
17035 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
17036 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
17037 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
17038 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
17039 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
17040 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
17041 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
17042 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
17043 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
17044 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
17045 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
17046
17047 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
17048 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
17049 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
17050 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
17051 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
17052 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
17053 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
17054 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
17055 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
17056 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
17057 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
17058 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
17059
17060 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
17061 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
17062 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
17063 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
17064 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
17065 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
17066 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
17067 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
17068 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
17069 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
17070 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
17071 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
17072
17073 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
17074 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
17075 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
17076 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
17077 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
17078 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
17079 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
17080 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
17081 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
17082 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
17083 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
17084 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
17085
17086 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
17087 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
17088 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
17089 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
17090 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
17091 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
17092 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
17093 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
17094 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
17095 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
17096 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
17097 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
17098
17099 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
17100 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
17101 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
17102 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
17103 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
17104 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
17105 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
17106 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
17107 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
17108 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
17109 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
17110 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
17111
17112 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
17113 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
17114 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
17115 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
17116 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
17117 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
17118 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
17119 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
17120 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
17121 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
17122 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
17123 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
17124
17125 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
17126 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
17127 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
17128 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
17129 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
17130 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
17131 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
17132 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
17133 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
17134 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
17135 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
17136 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
17137
17138 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
17139 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
17140 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
17141 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
17142 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
17143 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
17144 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
17145 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
17146 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
17147 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
17148 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
17149 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
17150
17151 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
17152 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
17153 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
17154 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
17155 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
17156 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
17157 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
17158 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
17159 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
17160 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
17161 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
17162 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
17163
17164 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
17165 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
17166 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
17167 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
17168 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
17169 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
17170 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
17171 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
17172 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
17173 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
17174 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
17175 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
17176
17177 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
17178 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
17179 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
17180 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
17181 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
17182 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
17183 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
17184 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
17185 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
17186 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
17187 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
17188 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
17189
17190 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17191 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17192 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17193 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17194 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17195 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17196 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17197 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17198 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17199 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17200 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17201 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17202
17203 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17204 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17205 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17206 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17207 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17208 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17209 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17210 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17211 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17212 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17213 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17214 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17215
17216 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17217 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17218 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17219 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17220 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17221 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17222 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17223 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17224 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17225 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17226 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17227 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17228
17229 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17230 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17231 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17232 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17233 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17234 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17235 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17236 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17237 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17238 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17239 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17240 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17241
17242 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17243 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17244 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17245 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17246 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17247 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17248 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17249 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17250 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17251 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17252 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17253 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17254
17255 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17256 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17257 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17258 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17259 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17260 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17261 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17262 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17263 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17264 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17265 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17266 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17267
17268 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17269 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17270 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17271 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17272 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17273 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17274 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17275 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17276 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17277 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17278 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17279 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17280
17281 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17282 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17283 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17284 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17285 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17286 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17287 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17288 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17289 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17290 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17291 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17292 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17293
17294 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17295 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17296 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17297 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17298 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17299 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17300 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17301 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17302 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17303 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17304 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17305 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17306
17307 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17308 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17309 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17310 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17311 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17312 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17313 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17314 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17315 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17316 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17317 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17318 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17319
17320 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17321 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17322 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17323 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17324 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17325 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17326 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17327 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17328 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17329 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17330 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17331 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17332
17333 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17334 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17335 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17336 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17337 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17338 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17339 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17340 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17341 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17342 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17343 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17344 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17345
17346 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17347 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17348 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17349 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17350 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17351 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17352 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17353 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17354 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17355 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17356 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17357 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17358
17359 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17360 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17361 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17362 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17363
17364 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17365 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17366 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17367 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17368 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17369 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17370 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17371 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17372 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17373 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17374 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17375 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
17376
17377 /* The implementation of the FIX instruction is broken on some
17378 assemblers, in that it accepts a precision specifier as well as a
17379 rounding specifier, despite the fact that this is meaningless.
17380 To be more compatible, we accept it as well, though of course it
17381 does not set any bits. */
17382 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17383 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17384 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17385 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17386 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17387 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17388 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17389 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17390 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17391 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17392 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17393 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17394 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
17395
17396 /* Instructions that were new with the real FPA, call them V2. */
17397 #undef ARM_VARIANT
17398 #define ARM_VARIANT & fpu_fpa_ext_v2
17399
17400 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17401 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17402 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17403 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17404 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17405 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17406
17407 #undef ARM_VARIANT
17408 #define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17409
17410 /* Moves and type conversions. */
17411 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17412 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17413 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17414 cCE("fmstat", ef1fa10, 0, (), noargs),
17415 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17416 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
17417 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17418 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17419 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17420 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17421 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17422 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17423 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17424 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
17425
17426 /* Memory operations. */
17427 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17428 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17429 cCE("fldmias", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17430 cCE("fldmfds", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17431 cCE("fldmdbs", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17432 cCE("fldmeas", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17433 cCE("fldmiax", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17434 cCE("fldmfdx", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17435 cCE("fldmdbx", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17436 cCE("fldmeax", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17437 cCE("fstmias", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17438 cCE("fstmeas", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17439 cCE("fstmdbs", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17440 cCE("fstmfds", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17441 cCE("fstmiax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17442 cCE("fstmeax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17443 cCE("fstmdbx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17444 cCE("fstmfdx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17445
17446 /* Monadic operations. */
17447 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17448 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17449 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
17450
17451 /* Dyadic operations. */
17452 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17453 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17454 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17455 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17456 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17457 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17458 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17459 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17460 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17461
17462 /* Comparisons. */
17463 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17464 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17465 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17466 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
17467
17468 /* Double precision load/store are still present on single precision
17469 implementations. */
17470 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17471 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17472 cCE("fldmiad", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17473 cCE("fldmfdd", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17474 cCE("fldmdbd", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17475 cCE("fldmead", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17476 cCE("fstmiad", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17477 cCE("fstmead", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17478 cCE("fstmdbd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17479 cCE("fstmfdd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17480
17481 #undef ARM_VARIANT
17482 #define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17483
17484 /* Moves and type conversions. */
17485 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17486 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17487 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17488 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17489 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17490 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17491 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17492 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17493 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17494 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17495 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17496 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17497 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17498
17499 /* Monadic operations. */
17500 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17501 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17502 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17503
17504 /* Dyadic operations. */
17505 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17506 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17507 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17508 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17509 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17510 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17511 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17512 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17513 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17514
17515 /* Comparisons. */
17516 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17517 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17518 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17519 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
17520
17521 #undef ARM_VARIANT
17522 #define ARM_VARIANT & fpu_vfp_ext_v2
17523
17524 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17525 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17526 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17527 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
17528
17529 /* Instructions which may belong to either the Neon or VFP instruction sets.
17530 Individual encoder functions perform additional architecture checks. */
17531 #undef ARM_VARIANT
17532 #define ARM_VARIANT & fpu_vfp_ext_v1xd
17533 #undef THUMB_VARIANT
17534 #define THUMB_VARIANT & fpu_vfp_ext_v1xd
17535
17536 /* These mnemonics are unique to VFP. */
17537 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17538 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
17539 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17540 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17541 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17542 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17543 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17544 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17545 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17546 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17547
17548 /* Mnemonics shared by Neon and VFP. */
17549 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17550 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17551 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17552
17553 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17554 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17555
17556 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17557 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17558
17559 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17560 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17561 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17562 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17563 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17564 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17565 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17566 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17567
17568 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17569 nCEF(vcvtr, _vcvt, 2, (RNSDQ, RNSDQ), neon_cvtr),
17570 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17571 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
17572
17573
17574 /* NOTE: All VMOV encoding is special-cased! */
17575 NCE(vmov, 0, 1, (VMOV), neon_mov),
17576 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17577
17578 #undef THUMB_VARIANT
17579 #define THUMB_VARIANT & fpu_neon_ext_v1
17580 #undef ARM_VARIANT
17581 #define ARM_VARIANT & fpu_neon_ext_v1
17582
17583 /* Data processing with three registers of the same length. */
17584 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17585 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17586 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17587 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17588 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17589 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17590 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17591 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17592 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17593 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17594 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17595 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17596 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17597 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17598 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17599 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17600 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17601 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17602 /* If not immediate, fall back to neon_dyadic_i64_su.
17603 shl_imm should accept I8 I16 I32 I64,
17604 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
17605 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17606 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17607 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17608 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
17609 /* Logic ops, types optional & ignored. */
17610 nUF(vand, _vand, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17611 nUF(vandq, _vand, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17612 nUF(vbic, _vbic, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17613 nUF(vbicq, _vbic, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17614 nUF(vorr, _vorr, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17615 nUF(vorrq, _vorr, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17616 nUF(vorn, _vorn, 3, (RNDQ, oRNDQ, RNDQ_Ibig), neon_logic),
17617 nUF(vornq, _vorn, 3, (RNQ, oRNQ, RNDQ_Ibig), neon_logic),
17618 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17619 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
17620 /* Bitfield ops, untyped. */
17621 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17622 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17623 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17624 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17625 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17626 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17627 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
17628 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17629 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17630 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17631 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17632 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17633 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17634 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17635 back to neon_dyadic_if_su. */
17636 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17637 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17638 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17639 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17640 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17641 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17642 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17643 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17644 /* Comparison. Type I8 I16 I32 F32. */
17645 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17646 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
17647 /* As above, D registers only. */
17648 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17649 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17650 /* Int and float variants, signedness unimportant. */
17651 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17652 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17653 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
17654 /* Add/sub take types I8 I16 I32 I64 F32. */
17655 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17656 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17657 /* vtst takes sizes 8, 16, 32. */
17658 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17659 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17660 /* VMUL takes I8 I16 I32 F32 P8. */
17661 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
17662 /* VQD{R}MULH takes S16 S32. */
17663 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17664 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17665 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17666 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17667 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17668 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17669 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17670 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17671 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17672 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17673 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17674 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17675 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17676 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17677 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17678 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17679
17680 /* Two address, int/float. Types S8 S16 S32 F32. */
17681 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
17682 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17683
17684 /* Data processing with two registers and a shift amount. */
17685 /* Right shifts, and variants with rounding.
17686 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17687 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17688 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17689 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17690 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17691 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17692 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17693 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17694 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17695 /* Shift and insert. Sizes accepted 8 16 32 64. */
17696 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17697 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17698 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17699 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17700 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17701 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17702 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17703 /* Right shift immediate, saturating & narrowing, with rounding variants.
17704 Types accepted S16 S32 S64 U16 U32 U64. */
17705 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17706 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17707 /* As above, unsigned. Types accepted S16 S32 S64. */
17708 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17709 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17710 /* Right shift narrowing. Types accepted I16 I32 I64. */
17711 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17712 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17713 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
17714 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
17715 /* CVT with optional immediate for fixed-point variant. */
17716 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
17717
17718 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_Ibig), neon_mvn),
17719 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_Ibig), neon_mvn),
17720
17721 /* Data processing, three registers of different lengths. */
17722 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17723 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17724 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17725 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17726 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17727 /* If not scalar, fall back to neon_dyadic_long.
17728 Vector types as above, scalar types S16 S32 U16 U32. */
17729 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17730 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17731 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17732 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17733 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17734 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17735 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17736 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17737 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17738 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17739 /* Saturating doubling multiplies. Types S16 S32. */
17740 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17741 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17742 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17743 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17744 S16 S32 U16 U32. */
17745 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
17746
17747 /* Extract. Size 8. */
17748 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17749 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
17750
17751 /* Two registers, miscellaneous. */
17752 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17753 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17754 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17755 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17756 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17757 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17758 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17759 /* Vector replicate. Sizes 8 16 32. */
17760 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17761 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
17762 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17763 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17764 /* VMOVN. Types I16 I32 I64. */
17765 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
17766 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
17767 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
17768 /* VQMOVUN. Types S16 S32 S64. */
17769 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
17770 /* VZIP / VUZP. Sizes 8 16 32. */
17771 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17772 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17773 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17774 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17775 /* VQABS / VQNEG. Types S8 S16 S32. */
17776 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17777 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17778 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17779 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17780 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17781 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17782 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17783 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17784 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17785 /* Reciprocal estimates. Types U32 F32. */
17786 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17787 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17788 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17789 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17790 /* VCLS. Types S8 S16 S32. */
17791 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17792 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17793 /* VCLZ. Types I8 I16 I32. */
17794 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17795 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17796 /* VCNT. Size 8. */
17797 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17798 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17799 /* Two address, untyped. */
17800 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17801 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17802 /* VTRN. Sizes 8 16 32. */
17803 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17804 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
17805
17806 /* Table lookup. Size 8. */
17807 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17808 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17809
17810 #undef THUMB_VARIANT
17811 #define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17812 #undef ARM_VARIANT
17813 #define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17814
17815 /* Neon element/structure load/store. */
17816 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17817 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17818 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17819 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17820 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17821 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17822 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17823 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17824
17825 #undef THUMB_VARIANT
17826 #define THUMB_VARIANT &fpu_vfp_ext_v3xd
17827 #undef ARM_VARIANT
17828 #define ARM_VARIANT &fpu_vfp_ext_v3xd
17829 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17830 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17831 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17832 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17833 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17834 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17835 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17836 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17837 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17838
17839 #undef THUMB_VARIANT
17840 #define THUMB_VARIANT & fpu_vfp_ext_v3
17841 #undef ARM_VARIANT
17842 #define ARM_VARIANT & fpu_vfp_ext_v3
17843
17844 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
17845 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17846 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17847 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17848 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17849 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17850 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17851 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17852 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17853
17854 #undef ARM_VARIANT
17855 #define ARM_VARIANT &fpu_vfp_ext_fma
17856 #undef THUMB_VARIANT
17857 #define THUMB_VARIANT &fpu_vfp_ext_fma
17858 /* Mnemonics shared by Neon and VFP. These are included in the
17859 VFP FMA variant; NEON and VFP FMA always includes the NEON
17860 FMA instructions. */
17861 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17862 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17863 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17864 the v form should always be used. */
17865 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17866 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17867 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17868 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17869 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17870 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17871
17872 #undef THUMB_VARIANT
17873 #undef ARM_VARIANT
17874 #define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17875
17876 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17877 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17878 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17879 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17880 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17881 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17882 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17883 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
17884
17885 #undef ARM_VARIANT
17886 #define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17887
17888 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17889 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17890 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17891 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17892 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17893 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17894 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17895 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17896 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17897 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17898 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17899 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17900 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17901 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17902 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17903 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17904 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17905 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17906 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
17907 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17908 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17909 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17910 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17911 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17912 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17913 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17914 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
17915 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
17916 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
17917 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
17918 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17919 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
17920 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
17921 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
17922 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
17923 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
17924 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
17925 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17926 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17927 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17928 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17929 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17930 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17931 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17932 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17933 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17934 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17935 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17936 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17937 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17938 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17939 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17940 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17941 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17942 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17943 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17944 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17945 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17946 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17947 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17948 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17949 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17950 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17951 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17952 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17953 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17954 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17955 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17956 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17957 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17958 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17959 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17960 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17961 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17962 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17963 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17964 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17965 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17966 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17967 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17968 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17969 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17970 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17971 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17972 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17973 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17974 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17975 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17976 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17977 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17978 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17979 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17980 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17981 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17982 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17983 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17984 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17985 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17986 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17987 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17988 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17989 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17990 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17991 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17992 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17993 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17994 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17995 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17996 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17997 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17998 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
17999 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18000 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18001 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18002 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18003 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18004 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18005 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18006 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18007 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18008 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18009 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18010 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18011 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18012 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18013 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18014 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18015 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
18016 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
18017 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18018 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
18019 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
18020 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
18021 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18022 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18023 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18024 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18025 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18026 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18027 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18028 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18029 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18030 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
18031 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
18032 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
18033 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
18034 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
18035 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
18036 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18037 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18038 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18039 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
18040 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
18041 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
18042 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
18043 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
18044 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
18045 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18046 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18047 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18048 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18049 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
18050
18051 #undef ARM_VARIANT
18052 #define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
18053
18054 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
18055 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
18056 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
18057 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
18058 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
18059 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
18060 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18061 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18062 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18063 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18064 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18065 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18066 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18067 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18068 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18069 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18070 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18071 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18072 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18073 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18074 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
18075 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18076 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18077 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18078 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18079 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18080 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18081 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18082 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18083 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18084 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18085 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18086 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18087 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18088 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18089 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18090 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18091 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18092 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18093 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18094 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18095 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18096 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18097 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18098 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18099 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18100 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18101 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18102 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18103 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18104 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18105 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18106 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18107 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18108 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18109 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18110 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
18111
18112 #undef ARM_VARIANT
18113 #define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
18114
18115 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18116 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18117 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18118 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18119 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
18120 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
18121 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
18122 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
18123 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
18124 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
18125 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
18126 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
18127 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
18128 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
18129 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
18130 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
18131 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
18132 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
18133 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
18134 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
18135 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
18136 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
18137 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
18138 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
18139 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
18140 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
18141 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
18142 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
18143 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
18144 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
18145 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
18146 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
18147 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
18148 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
18149 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
18150 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
18151 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
18152 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
18153 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
18154 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
18155 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
18156 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
18157 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
18158 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
18159 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
18160 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
18161 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
18162 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
18163 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
18164 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
18165 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
18166 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
18167 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
18168 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
18169 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
18170 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
18171 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
18172 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
18173 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
18174 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
18175 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
18176 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
18177 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
18178 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
18179 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18180 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18181 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18182 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18183 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18184 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
18185 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18186 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
18187 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18188 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
18189 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18190 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
18191 };
18192 #undef ARM_VARIANT
18193 #undef THUMB_VARIANT
18194 #undef TCE
18195 #undef TCM
18196 #undef TUE
18197 #undef TUF
18198 #undef TCC
18199 #undef cCE
18200 #undef cCL
18201 #undef C3E
18202 #undef CE
18203 #undef CM
18204 #undef UE
18205 #undef UF
18206 #undef UT
18207 #undef NUF
18208 #undef nUF
18209 #undef NCE
18210 #undef nCE
18211 #undef OPS0
18212 #undef OPS1
18213 #undef OPS2
18214 #undef OPS3
18215 #undef OPS4
18216 #undef OPS5
18217 #undef OPS6
18218 #undef do_0
18219 \f
18220 /* MD interface: bits in the object file. */
18221
18222 /* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18223 for use in the a.out file, and stores them in the array pointed to by buf.
18224 This knows about the endian-ness of the target machine and does
18225 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18226 2 (short) and 4 (long) Floating numbers are put out as a series of
18227 LITTLENUMS (shorts, here at least). */
18228
18229 void
18230 md_number_to_chars (char * buf, valueT val, int n)
18231 {
18232 if (target_big_endian)
18233 number_to_chars_bigendian (buf, val, n);
18234 else
18235 number_to_chars_littleendian (buf, val, n);
18236 }
18237
18238 static valueT
18239 md_chars_to_number (char * buf, int n)
18240 {
18241 valueT result = 0;
18242 unsigned char * where = (unsigned char *) buf;
18243
18244 if (target_big_endian)
18245 {
18246 while (n--)
18247 {
18248 result <<= 8;
18249 result |= (*where++ & 255);
18250 }
18251 }
18252 else
18253 {
18254 while (n--)
18255 {
18256 result <<= 8;
18257 result |= (where[n] & 255);
18258 }
18259 }
18260
18261 return result;
18262 }
18263
18264 /* MD interface: Sections. */
18265
18266 /* Estimate the size of a frag before relaxing. Assume everything fits in
18267 2 bytes. */
18268
18269 int
18270 md_estimate_size_before_relax (fragS * fragp,
18271 segT segtype ATTRIBUTE_UNUSED)
18272 {
18273 fragp->fr_var = 2;
18274 return 2;
18275 }
18276
18277 /* Convert a machine dependent frag. */
18278
18279 void
18280 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18281 {
18282 unsigned long insn;
18283 unsigned long old_op;
18284 char *buf;
18285 expressionS exp;
18286 fixS *fixp;
18287 int reloc_type;
18288 int pc_rel;
18289 int opcode;
18290
18291 buf = fragp->fr_literal + fragp->fr_fix;
18292
18293 old_op = bfd_get_16(abfd, buf);
18294 if (fragp->fr_symbol)
18295 {
18296 exp.X_op = O_symbol;
18297 exp.X_add_symbol = fragp->fr_symbol;
18298 }
18299 else
18300 {
18301 exp.X_op = O_constant;
18302 }
18303 exp.X_add_number = fragp->fr_offset;
18304 opcode = fragp->fr_subtype;
18305 switch (opcode)
18306 {
18307 case T_MNEM_ldr_pc:
18308 case T_MNEM_ldr_pc2:
18309 case T_MNEM_ldr_sp:
18310 case T_MNEM_str_sp:
18311 case T_MNEM_ldr:
18312 case T_MNEM_ldrb:
18313 case T_MNEM_ldrh:
18314 case T_MNEM_str:
18315 case T_MNEM_strb:
18316 case T_MNEM_strh:
18317 if (fragp->fr_var == 4)
18318 {
18319 insn = THUMB_OP32 (opcode);
18320 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18321 {
18322 insn |= (old_op & 0x700) << 4;
18323 }
18324 else
18325 {
18326 insn |= (old_op & 7) << 12;
18327 insn |= (old_op & 0x38) << 13;
18328 }
18329 insn |= 0x00000c00;
18330 put_thumb32_insn (buf, insn);
18331 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18332 }
18333 else
18334 {
18335 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18336 }
18337 pc_rel = (opcode == T_MNEM_ldr_pc2);
18338 break;
18339 case T_MNEM_adr:
18340 if (fragp->fr_var == 4)
18341 {
18342 insn = THUMB_OP32 (opcode);
18343 insn |= (old_op & 0xf0) << 4;
18344 put_thumb32_insn (buf, insn);
18345 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18346 }
18347 else
18348 {
18349 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18350 exp.X_add_number -= 4;
18351 }
18352 pc_rel = 1;
18353 break;
18354 case T_MNEM_mov:
18355 case T_MNEM_movs:
18356 case T_MNEM_cmp:
18357 case T_MNEM_cmn:
18358 if (fragp->fr_var == 4)
18359 {
18360 int r0off = (opcode == T_MNEM_mov
18361 || opcode == T_MNEM_movs) ? 0 : 8;
18362 insn = THUMB_OP32 (opcode);
18363 insn = (insn & 0xe1ffffff) | 0x10000000;
18364 insn |= (old_op & 0x700) << r0off;
18365 put_thumb32_insn (buf, insn);
18366 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18367 }
18368 else
18369 {
18370 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18371 }
18372 pc_rel = 0;
18373 break;
18374 case T_MNEM_b:
18375 if (fragp->fr_var == 4)
18376 {
18377 insn = THUMB_OP32(opcode);
18378 put_thumb32_insn (buf, insn);
18379 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18380 }
18381 else
18382 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18383 pc_rel = 1;
18384 break;
18385 case T_MNEM_bcond:
18386 if (fragp->fr_var == 4)
18387 {
18388 insn = THUMB_OP32(opcode);
18389 insn |= (old_op & 0xf00) << 14;
18390 put_thumb32_insn (buf, insn);
18391 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18392 }
18393 else
18394 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18395 pc_rel = 1;
18396 break;
18397 case T_MNEM_add_sp:
18398 case T_MNEM_add_pc:
18399 case T_MNEM_inc_sp:
18400 case T_MNEM_dec_sp:
18401 if (fragp->fr_var == 4)
18402 {
18403 /* ??? Choose between add and addw. */
18404 insn = THUMB_OP32 (opcode);
18405 insn |= (old_op & 0xf0) << 4;
18406 put_thumb32_insn (buf, insn);
18407 if (opcode == T_MNEM_add_pc)
18408 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18409 else
18410 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18411 }
18412 else
18413 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18414 pc_rel = 0;
18415 break;
18416
18417 case T_MNEM_addi:
18418 case T_MNEM_addis:
18419 case T_MNEM_subi:
18420 case T_MNEM_subis:
18421 if (fragp->fr_var == 4)
18422 {
18423 insn = THUMB_OP32 (opcode);
18424 insn |= (old_op & 0xf0) << 4;
18425 insn |= (old_op & 0xf) << 16;
18426 put_thumb32_insn (buf, insn);
18427 if (insn & (1 << 20))
18428 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18429 else
18430 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18431 }
18432 else
18433 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18434 pc_rel = 0;
18435 break;
18436 default:
18437 abort ();
18438 }
18439 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
18440 (enum bfd_reloc_code_real) reloc_type);
18441 fixp->fx_file = fragp->fr_file;
18442 fixp->fx_line = fragp->fr_line;
18443 fragp->fr_fix += fragp->fr_var;
18444 }
18445
18446 /* Return the size of a relaxable immediate operand instruction.
18447 SHIFT and SIZE specify the form of the allowable immediate. */
18448 static int
18449 relax_immediate (fragS *fragp, int size, int shift)
18450 {
18451 offsetT offset;
18452 offsetT mask;
18453 offsetT low;
18454
18455 /* ??? Should be able to do better than this. */
18456 if (fragp->fr_symbol)
18457 return 4;
18458
18459 low = (1 << shift) - 1;
18460 mask = (1 << (shift + size)) - (1 << shift);
18461 offset = fragp->fr_offset;
18462 /* Force misaligned offsets to 32-bit variant. */
18463 if (offset & low)
18464 return 4;
18465 if (offset & ~mask)
18466 return 4;
18467 return 2;
18468 }
18469
18470 /* Get the address of a symbol during relaxation. */
18471 static addressT
18472 relaxed_symbol_addr (fragS *fragp, long stretch)
18473 {
18474 fragS *sym_frag;
18475 addressT addr;
18476 symbolS *sym;
18477
18478 sym = fragp->fr_symbol;
18479 sym_frag = symbol_get_frag (sym);
18480 know (S_GET_SEGMENT (sym) != absolute_section
18481 || sym_frag == &zero_address_frag);
18482 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18483
18484 /* If frag has yet to be reached on this pass, assume it will
18485 move by STRETCH just as we did. If this is not so, it will
18486 be because some frag between grows, and that will force
18487 another pass. */
18488
18489 if (stretch != 0
18490 && sym_frag->relax_marker != fragp->relax_marker)
18491 {
18492 fragS *f;
18493
18494 /* Adjust stretch for any alignment frag. Note that if have
18495 been expanding the earlier code, the symbol may be
18496 defined in what appears to be an earlier frag. FIXME:
18497 This doesn't handle the fr_subtype field, which specifies
18498 a maximum number of bytes to skip when doing an
18499 alignment. */
18500 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18501 {
18502 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18503 {
18504 if (stretch < 0)
18505 stretch = - ((- stretch)
18506 & ~ ((1 << (int) f->fr_offset) - 1));
18507 else
18508 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18509 if (stretch == 0)
18510 break;
18511 }
18512 }
18513 if (f != NULL)
18514 addr += stretch;
18515 }
18516
18517 return addr;
18518 }
18519
18520 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
18521 load. */
18522 static int
18523 relax_adr (fragS *fragp, asection *sec, long stretch)
18524 {
18525 addressT addr;
18526 offsetT val;
18527
18528 /* Assume worst case for symbols not known to be in the same section. */
18529 if (fragp->fr_symbol == NULL
18530 || !S_IS_DEFINED (fragp->fr_symbol)
18531 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18532 || S_IS_WEAK (fragp->fr_symbol))
18533 return 4;
18534
18535 val = relaxed_symbol_addr (fragp, stretch);
18536 addr = fragp->fr_address + fragp->fr_fix;
18537 addr = (addr + 4) & ~3;
18538 /* Force misaligned targets to 32-bit variant. */
18539 if (val & 3)
18540 return 4;
18541 val -= addr;
18542 if (val < 0 || val > 1020)
18543 return 4;
18544 return 2;
18545 }
18546
18547 /* Return the size of a relaxable add/sub immediate instruction. */
18548 static int
18549 relax_addsub (fragS *fragp, asection *sec)
18550 {
18551 char *buf;
18552 int op;
18553
18554 buf = fragp->fr_literal + fragp->fr_fix;
18555 op = bfd_get_16(sec->owner, buf);
18556 if ((op & 0xf) == ((op >> 4) & 0xf))
18557 return relax_immediate (fragp, 8, 0);
18558 else
18559 return relax_immediate (fragp, 3, 0);
18560 }
18561
18562
18563 /* Return the size of a relaxable branch instruction. BITS is the
18564 size of the offset field in the narrow instruction. */
18565
18566 static int
18567 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
18568 {
18569 addressT addr;
18570 offsetT val;
18571 offsetT limit;
18572
18573 /* Assume worst case for symbols not known to be in the same section. */
18574 if (!S_IS_DEFINED (fragp->fr_symbol)
18575 || sec != S_GET_SEGMENT (fragp->fr_symbol)
18576 || S_IS_WEAK (fragp->fr_symbol))
18577 return 4;
18578
18579 #ifdef OBJ_ELF
18580 if (S_IS_DEFINED (fragp->fr_symbol)
18581 && ARM_IS_FUNC (fragp->fr_symbol))
18582 return 4;
18583 #endif
18584
18585 val = relaxed_symbol_addr (fragp, stretch);
18586 addr = fragp->fr_address + fragp->fr_fix + 4;
18587 val -= addr;
18588
18589 /* Offset is a signed value *2 */
18590 limit = 1 << bits;
18591 if (val >= limit || val < -limit)
18592 return 4;
18593 return 2;
18594 }
18595
18596
18597 /* Relax a machine dependent frag. This returns the amount by which
18598 the current size of the frag should change. */
18599
18600 int
18601 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
18602 {
18603 int oldsize;
18604 int newsize;
18605
18606 oldsize = fragp->fr_var;
18607 switch (fragp->fr_subtype)
18608 {
18609 case T_MNEM_ldr_pc2:
18610 newsize = relax_adr (fragp, sec, stretch);
18611 break;
18612 case T_MNEM_ldr_pc:
18613 case T_MNEM_ldr_sp:
18614 case T_MNEM_str_sp:
18615 newsize = relax_immediate (fragp, 8, 2);
18616 break;
18617 case T_MNEM_ldr:
18618 case T_MNEM_str:
18619 newsize = relax_immediate (fragp, 5, 2);
18620 break;
18621 case T_MNEM_ldrh:
18622 case T_MNEM_strh:
18623 newsize = relax_immediate (fragp, 5, 1);
18624 break;
18625 case T_MNEM_ldrb:
18626 case T_MNEM_strb:
18627 newsize = relax_immediate (fragp, 5, 0);
18628 break;
18629 case T_MNEM_adr:
18630 newsize = relax_adr (fragp, sec, stretch);
18631 break;
18632 case T_MNEM_mov:
18633 case T_MNEM_movs:
18634 case T_MNEM_cmp:
18635 case T_MNEM_cmn:
18636 newsize = relax_immediate (fragp, 8, 0);
18637 break;
18638 case T_MNEM_b:
18639 newsize = relax_branch (fragp, sec, 11, stretch);
18640 break;
18641 case T_MNEM_bcond:
18642 newsize = relax_branch (fragp, sec, 8, stretch);
18643 break;
18644 case T_MNEM_add_sp:
18645 case T_MNEM_add_pc:
18646 newsize = relax_immediate (fragp, 8, 2);
18647 break;
18648 case T_MNEM_inc_sp:
18649 case T_MNEM_dec_sp:
18650 newsize = relax_immediate (fragp, 7, 2);
18651 break;
18652 case T_MNEM_addi:
18653 case T_MNEM_addis:
18654 case T_MNEM_subi:
18655 case T_MNEM_subis:
18656 newsize = relax_addsub (fragp, sec);
18657 break;
18658 default:
18659 abort ();
18660 }
18661
18662 fragp->fr_var = newsize;
18663 /* Freeze wide instructions that are at or before the same location as
18664 in the previous pass. This avoids infinite loops.
18665 Don't freeze them unconditionally because targets may be artificially
18666 misaligned by the expansion of preceding frags. */
18667 if (stretch <= 0 && newsize > 2)
18668 {
18669 md_convert_frag (sec->owner, sec, fragp);
18670 frag_wane (fragp);
18671 }
18672
18673 return newsize - oldsize;
18674 }
18675
18676 /* Round up a section size to the appropriate boundary. */
18677
18678 valueT
18679 md_section_align (segT segment ATTRIBUTE_UNUSED,
18680 valueT size)
18681 {
18682 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18683 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18684 {
18685 /* For a.out, force the section size to be aligned. If we don't do
18686 this, BFD will align it for us, but it will not write out the
18687 final bytes of the section. This may be a bug in BFD, but it is
18688 easier to fix it here since that is how the other a.out targets
18689 work. */
18690 int align;
18691
18692 align = bfd_get_section_alignment (stdoutput, segment);
18693 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18694 }
18695 #endif
18696
18697 return size;
18698 }
18699
18700 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18701 of an rs_align_code fragment. */
18702
18703 void
18704 arm_handle_align (fragS * fragP)
18705 {
18706 static char const arm_noop[2][2][4] =
18707 {
18708 { /* ARMv1 */
18709 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18710 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18711 },
18712 { /* ARMv6k */
18713 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18714 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18715 },
18716 };
18717 static char const thumb_noop[2][2][2] =
18718 {
18719 { /* Thumb-1 */
18720 {0xc0, 0x46}, /* LE */
18721 {0x46, 0xc0}, /* BE */
18722 },
18723 { /* Thumb-2 */
18724 {0x00, 0xbf}, /* LE */
18725 {0xbf, 0x00} /* BE */
18726 }
18727 };
18728 static char const wide_thumb_noop[2][4] =
18729 { /* Wide Thumb-2 */
18730 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18731 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18732 };
18733
18734 unsigned bytes, fix, noop_size;
18735 char * p;
18736 const char * noop;
18737 const char *narrow_noop = NULL;
18738 #ifdef OBJ_ELF
18739 enum mstate state;
18740 #endif
18741
18742 if (fragP->fr_type != rs_align_code)
18743 return;
18744
18745 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18746 p = fragP->fr_literal + fragP->fr_fix;
18747 fix = 0;
18748
18749 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18750 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
18751
18752 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
18753
18754 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
18755 {
18756 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18757 {
18758 narrow_noop = thumb_noop[1][target_big_endian];
18759 noop = wide_thumb_noop[target_big_endian];
18760 }
18761 else
18762 noop = thumb_noop[0][target_big_endian];
18763 noop_size = 2;
18764 #ifdef OBJ_ELF
18765 state = MAP_THUMB;
18766 #endif
18767 }
18768 else
18769 {
18770 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18771 [target_big_endian];
18772 noop_size = 4;
18773 #ifdef OBJ_ELF
18774 state = MAP_ARM;
18775 #endif
18776 }
18777
18778 fragP->fr_var = noop_size;
18779
18780 if (bytes & (noop_size - 1))
18781 {
18782 fix = bytes & (noop_size - 1);
18783 #ifdef OBJ_ELF
18784 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18785 #endif
18786 memset (p, 0, fix);
18787 p += fix;
18788 bytes -= fix;
18789 }
18790
18791 if (narrow_noop)
18792 {
18793 if (bytes & noop_size)
18794 {
18795 /* Insert a narrow noop. */
18796 memcpy (p, narrow_noop, noop_size);
18797 p += noop_size;
18798 bytes -= noop_size;
18799 fix += noop_size;
18800 }
18801
18802 /* Use wide noops for the remainder */
18803 noop_size = 4;
18804 }
18805
18806 while (bytes >= noop_size)
18807 {
18808 memcpy (p, noop, noop_size);
18809 p += noop_size;
18810 bytes -= noop_size;
18811 fix += noop_size;
18812 }
18813
18814 fragP->fr_fix += fix;
18815 }
18816
18817 /* Called from md_do_align. Used to create an alignment
18818 frag in a code section. */
18819
18820 void
18821 arm_frag_align_code (int n, int max)
18822 {
18823 char * p;
18824
18825 /* We assume that there will never be a requirement
18826 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
18827 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
18828 {
18829 char err_msg[128];
18830
18831 sprintf (err_msg,
18832 _("alignments greater than %d bytes not supported in .text sections."),
18833 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
18834 as_fatal ("%s", err_msg);
18835 }
18836
18837 p = frag_var (rs_align_code,
18838 MAX_MEM_FOR_RS_ALIGN_CODE,
18839 1,
18840 (relax_substateT) max,
18841 (symbolS *) NULL,
18842 (offsetT) n,
18843 (char *) NULL);
18844 *p = 0;
18845 }
18846
18847 /* Perform target specific initialisation of a frag.
18848 Note - despite the name this initialisation is not done when the frag
18849 is created, but only when its type is assigned. A frag can be created
18850 and used a long time before its type is set, so beware of assuming that
18851 this initialisationis performed first. */
18852
18853 #ifndef OBJ_ELF
18854 void
18855 arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18856 {
18857 /* Record whether this frag is in an ARM or a THUMB area. */
18858 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18859 }
18860
18861 #else /* OBJ_ELF is defined. */
18862 void
18863 arm_init_frag (fragS * fragP, int max_chars)
18864 {
18865 /* If the current ARM vs THUMB mode has not already
18866 been recorded into this frag then do so now. */
18867 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18868 {
18869 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18870
18871 /* Record a mapping symbol for alignment frags. We will delete this
18872 later if the alignment ends up empty. */
18873 switch (fragP->fr_type)
18874 {
18875 case rs_align:
18876 case rs_align_test:
18877 case rs_fill:
18878 mapping_state_2 (MAP_DATA, max_chars);
18879 break;
18880 case rs_align_code:
18881 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18882 break;
18883 default:
18884 break;
18885 }
18886 }
18887 }
18888
18889 /* When we change sections we need to issue a new mapping symbol. */
18890
18891 void
18892 arm_elf_change_section (void)
18893 {
18894 /* Link an unlinked unwind index table section to the .text section. */
18895 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18896 && elf_linked_to_section (now_seg) == NULL)
18897 elf_linked_to_section (now_seg) = text_section;
18898 }
18899
18900 int
18901 arm_elf_section_type (const char * str, size_t len)
18902 {
18903 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18904 return SHT_ARM_EXIDX;
18905
18906 return -1;
18907 }
18908 \f
18909 /* Code to deal with unwinding tables. */
18910
18911 static void add_unwind_adjustsp (offsetT);
18912
18913 /* Generate any deferred unwind frame offset. */
18914
18915 static void
18916 flush_pending_unwind (void)
18917 {
18918 offsetT offset;
18919
18920 offset = unwind.pending_offset;
18921 unwind.pending_offset = 0;
18922 if (offset != 0)
18923 add_unwind_adjustsp (offset);
18924 }
18925
18926 /* Add an opcode to this list for this function. Two-byte opcodes should
18927 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18928 order. */
18929
18930 static void
18931 add_unwind_opcode (valueT op, int length)
18932 {
18933 /* Add any deferred stack adjustment. */
18934 if (unwind.pending_offset)
18935 flush_pending_unwind ();
18936
18937 unwind.sp_restored = 0;
18938
18939 if (unwind.opcode_count + length > unwind.opcode_alloc)
18940 {
18941 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18942 if (unwind.opcodes)
18943 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
18944 unwind.opcode_alloc);
18945 else
18946 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
18947 }
18948 while (length > 0)
18949 {
18950 length--;
18951 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18952 op >>= 8;
18953 unwind.opcode_count++;
18954 }
18955 }
18956
18957 /* Add unwind opcodes to adjust the stack pointer. */
18958
18959 static void
18960 add_unwind_adjustsp (offsetT offset)
18961 {
18962 valueT op;
18963
18964 if (offset > 0x200)
18965 {
18966 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18967 char bytes[5];
18968 int n;
18969 valueT o;
18970
18971 /* Long form: 0xb2, uleb128. */
18972 /* This might not fit in a word so add the individual bytes,
18973 remembering the list is built in reverse order. */
18974 o = (valueT) ((offset - 0x204) >> 2);
18975 if (o == 0)
18976 add_unwind_opcode (0, 1);
18977
18978 /* Calculate the uleb128 encoding of the offset. */
18979 n = 0;
18980 while (o)
18981 {
18982 bytes[n] = o & 0x7f;
18983 o >>= 7;
18984 if (o)
18985 bytes[n] |= 0x80;
18986 n++;
18987 }
18988 /* Add the insn. */
18989 for (; n; n--)
18990 add_unwind_opcode (bytes[n - 1], 1);
18991 add_unwind_opcode (0xb2, 1);
18992 }
18993 else if (offset > 0x100)
18994 {
18995 /* Two short opcodes. */
18996 add_unwind_opcode (0x3f, 1);
18997 op = (offset - 0x104) >> 2;
18998 add_unwind_opcode (op, 1);
18999 }
19000 else if (offset > 0)
19001 {
19002 /* Short opcode. */
19003 op = (offset - 4) >> 2;
19004 add_unwind_opcode (op, 1);
19005 }
19006 else if (offset < 0)
19007 {
19008 offset = -offset;
19009 while (offset > 0x100)
19010 {
19011 add_unwind_opcode (0x7f, 1);
19012 offset -= 0x100;
19013 }
19014 op = ((offset - 4) >> 2) | 0x40;
19015 add_unwind_opcode (op, 1);
19016 }
19017 }
19018
19019 /* Finish the list of unwind opcodes for this function. */
19020 static void
19021 finish_unwind_opcodes (void)
19022 {
19023 valueT op;
19024
19025 if (unwind.fp_used)
19026 {
19027 /* Adjust sp as necessary. */
19028 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
19029 flush_pending_unwind ();
19030
19031 /* After restoring sp from the frame pointer. */
19032 op = 0x90 | unwind.fp_reg;
19033 add_unwind_opcode (op, 1);
19034 }
19035 else
19036 flush_pending_unwind ();
19037 }
19038
19039
19040 /* Start an exception table entry. If idx is nonzero this is an index table
19041 entry. */
19042
19043 static void
19044 start_unwind_section (const segT text_seg, int idx)
19045 {
19046 const char * text_name;
19047 const char * prefix;
19048 const char * prefix_once;
19049 const char * group_name;
19050 size_t prefix_len;
19051 size_t text_len;
19052 char * sec_name;
19053 size_t sec_name_len;
19054 int type;
19055 int flags;
19056 int linkonce;
19057
19058 if (idx)
19059 {
19060 prefix = ELF_STRING_ARM_unwind;
19061 prefix_once = ELF_STRING_ARM_unwind_once;
19062 type = SHT_ARM_EXIDX;
19063 }
19064 else
19065 {
19066 prefix = ELF_STRING_ARM_unwind_info;
19067 prefix_once = ELF_STRING_ARM_unwind_info_once;
19068 type = SHT_PROGBITS;
19069 }
19070
19071 text_name = segment_name (text_seg);
19072 if (streq (text_name, ".text"))
19073 text_name = "";
19074
19075 if (strncmp (text_name, ".gnu.linkonce.t.",
19076 strlen (".gnu.linkonce.t.")) == 0)
19077 {
19078 prefix = prefix_once;
19079 text_name += strlen (".gnu.linkonce.t.");
19080 }
19081
19082 prefix_len = strlen (prefix);
19083 text_len = strlen (text_name);
19084 sec_name_len = prefix_len + text_len;
19085 sec_name = (char *) xmalloc (sec_name_len + 1);
19086 memcpy (sec_name, prefix, prefix_len);
19087 memcpy (sec_name + prefix_len, text_name, text_len);
19088 sec_name[prefix_len + text_len] = '\0';
19089
19090 flags = SHF_ALLOC;
19091 linkonce = 0;
19092 group_name = 0;
19093
19094 /* Handle COMDAT group. */
19095 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
19096 {
19097 group_name = elf_group_name (text_seg);
19098 if (group_name == NULL)
19099 {
19100 as_bad (_("Group section `%s' has no group signature"),
19101 segment_name (text_seg));
19102 ignore_rest_of_line ();
19103 return;
19104 }
19105 flags |= SHF_GROUP;
19106 linkonce = 1;
19107 }
19108
19109 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
19110
19111 /* Set the section link for index tables. */
19112 if (idx)
19113 elf_linked_to_section (now_seg) = text_seg;
19114 }
19115
19116
19117 /* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
19118 personality routine data. Returns zero, or the index table value for
19119 and inline entry. */
19120
19121 static valueT
19122 create_unwind_entry (int have_data)
19123 {
19124 int size;
19125 addressT where;
19126 char *ptr;
19127 /* The current word of data. */
19128 valueT data;
19129 /* The number of bytes left in this word. */
19130 int n;
19131
19132 finish_unwind_opcodes ();
19133
19134 /* Remember the current text section. */
19135 unwind.saved_seg = now_seg;
19136 unwind.saved_subseg = now_subseg;
19137
19138 start_unwind_section (now_seg, 0);
19139
19140 if (unwind.personality_routine == NULL)
19141 {
19142 if (unwind.personality_index == -2)
19143 {
19144 if (have_data)
19145 as_bad (_("handlerdata in cantunwind frame"));
19146 return 1; /* EXIDX_CANTUNWIND. */
19147 }
19148
19149 /* Use a default personality routine if none is specified. */
19150 if (unwind.personality_index == -1)
19151 {
19152 if (unwind.opcode_count > 3)
19153 unwind.personality_index = 1;
19154 else
19155 unwind.personality_index = 0;
19156 }
19157
19158 /* Space for the personality routine entry. */
19159 if (unwind.personality_index == 0)
19160 {
19161 if (unwind.opcode_count > 3)
19162 as_bad (_("too many unwind opcodes for personality routine 0"));
19163
19164 if (!have_data)
19165 {
19166 /* All the data is inline in the index table. */
19167 data = 0x80;
19168 n = 3;
19169 while (unwind.opcode_count > 0)
19170 {
19171 unwind.opcode_count--;
19172 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19173 n--;
19174 }
19175
19176 /* Pad with "finish" opcodes. */
19177 while (n--)
19178 data = (data << 8) | 0xb0;
19179
19180 return data;
19181 }
19182 size = 0;
19183 }
19184 else
19185 /* We get two opcodes "free" in the first word. */
19186 size = unwind.opcode_count - 2;
19187 }
19188 else
19189 /* An extra byte is required for the opcode count. */
19190 size = unwind.opcode_count + 1;
19191
19192 size = (size + 3) >> 2;
19193 if (size > 0xff)
19194 as_bad (_("too many unwind opcodes"));
19195
19196 frag_align (2, 0, 0);
19197 record_alignment (now_seg, 2);
19198 unwind.table_entry = expr_build_dot ();
19199
19200 /* Allocate the table entry. */
19201 ptr = frag_more ((size << 2) + 4);
19202 where = frag_now_fix () - ((size << 2) + 4);
19203
19204 switch (unwind.personality_index)
19205 {
19206 case -1:
19207 /* ??? Should this be a PLT generating relocation? */
19208 /* Custom personality routine. */
19209 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19210 BFD_RELOC_ARM_PREL31);
19211
19212 where += 4;
19213 ptr += 4;
19214
19215 /* Set the first byte to the number of additional words. */
19216 data = size - 1;
19217 n = 3;
19218 break;
19219
19220 /* ABI defined personality routines. */
19221 case 0:
19222 /* Three opcodes bytes are packed into the first word. */
19223 data = 0x80;
19224 n = 3;
19225 break;
19226
19227 case 1:
19228 case 2:
19229 /* The size and first two opcode bytes go in the first word. */
19230 data = ((0x80 + unwind.personality_index) << 8) | size;
19231 n = 2;
19232 break;
19233
19234 default:
19235 /* Should never happen. */
19236 abort ();
19237 }
19238
19239 /* Pack the opcodes into words (MSB first), reversing the list at the same
19240 time. */
19241 while (unwind.opcode_count > 0)
19242 {
19243 if (n == 0)
19244 {
19245 md_number_to_chars (ptr, data, 4);
19246 ptr += 4;
19247 n = 4;
19248 data = 0;
19249 }
19250 unwind.opcode_count--;
19251 n--;
19252 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19253 }
19254
19255 /* Finish off the last word. */
19256 if (n < 4)
19257 {
19258 /* Pad with "finish" opcodes. */
19259 while (n--)
19260 data = (data << 8) | 0xb0;
19261
19262 md_number_to_chars (ptr, data, 4);
19263 }
19264
19265 if (!have_data)
19266 {
19267 /* Add an empty descriptor if there is no user-specified data. */
19268 ptr = frag_more (4);
19269 md_number_to_chars (ptr, 0, 4);
19270 }
19271
19272 return 0;
19273 }
19274
19275
19276 /* Initialize the DWARF-2 unwind information for this procedure. */
19277
19278 void
19279 tc_arm_frame_initial_instructions (void)
19280 {
19281 cfi_add_CFA_def_cfa (REG_SP, 0);
19282 }
19283 #endif /* OBJ_ELF */
19284
19285 /* Convert REGNAME to a DWARF-2 register number. */
19286
19287 int
19288 tc_arm_regname_to_dw2regnum (char *regname)
19289 {
19290 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
19291
19292 if (reg == FAIL)
19293 return -1;
19294
19295 return reg;
19296 }
19297
19298 #ifdef TE_PE
19299 void
19300 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
19301 {
19302 expressionS exp;
19303
19304 exp.X_op = O_secrel;
19305 exp.X_add_symbol = symbol;
19306 exp.X_add_number = 0;
19307 emit_expr (&exp, size);
19308 }
19309 #endif
19310
19311 /* MD interface: Symbol and relocation handling. */
19312
19313 /* Return the address within the segment that a PC-relative fixup is
19314 relative to. For ARM, PC-relative fixups applied to instructions
19315 are generally relative to the location of the fixup plus 8 bytes.
19316 Thumb branches are offset by 4, and Thumb loads relative to PC
19317 require special handling. */
19318
19319 long
19320 md_pcrel_from_section (fixS * fixP, segT seg)
19321 {
19322 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19323
19324 /* If this is pc-relative and we are going to emit a relocation
19325 then we just want to put out any pipeline compensation that the linker
19326 will need. Otherwise we want to use the calculated base.
19327 For WinCE we skip the bias for externals as well, since this
19328 is how the MS ARM-CE assembler behaves and we want to be compatible. */
19329 if (fixP->fx_pcrel
19330 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19331 || (arm_force_relocation (fixP)
19332 #ifdef TE_WINCE
19333 && !S_IS_EXTERNAL (fixP->fx_addsy)
19334 #endif
19335 )))
19336 base = 0;
19337
19338
19339 switch (fixP->fx_r_type)
19340 {
19341 /* PC relative addressing on the Thumb is slightly odd as the
19342 bottom two bits of the PC are forced to zero for the
19343 calculation. This happens *after* application of the
19344 pipeline offset. However, Thumb adrl already adjusts for
19345 this, so we need not do it again. */
19346 case BFD_RELOC_ARM_THUMB_ADD:
19347 return base & ~3;
19348
19349 case BFD_RELOC_ARM_THUMB_OFFSET:
19350 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19351 case BFD_RELOC_ARM_T32_ADD_PC12:
19352 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
19353 return (base + 4) & ~3;
19354
19355 /* Thumb branches are simply offset by +4. */
19356 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19357 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19358 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19359 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19360 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19361 return base + 4;
19362
19363 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19364 if (fixP->fx_addsy
19365 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19366 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19367 && ARM_IS_FUNC (fixP->fx_addsy)
19368 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19369 base = fixP->fx_where + fixP->fx_frag->fr_address;
19370 return base + 4;
19371
19372 /* BLX is like branches above, but forces the low two bits of PC to
19373 zero. */
19374 case BFD_RELOC_THUMB_PCREL_BLX:
19375 if (fixP->fx_addsy
19376 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19377 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19378 && THUMB_IS_FUNC (fixP->fx_addsy)
19379 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19380 base = fixP->fx_where + fixP->fx_frag->fr_address;
19381 return (base + 4) & ~3;
19382
19383 /* ARM mode branches are offset by +8. However, the Windows CE
19384 loader expects the relocation not to take this into account. */
19385 case BFD_RELOC_ARM_PCREL_BLX:
19386 if (fixP->fx_addsy
19387 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19388 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19389 && ARM_IS_FUNC (fixP->fx_addsy)
19390 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19391 base = fixP->fx_where + fixP->fx_frag->fr_address;
19392 return base + 8;
19393
19394 case BFD_RELOC_ARM_PCREL_CALL:
19395 if (fixP->fx_addsy
19396 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19397 && (!S_IS_EXTERNAL (fixP->fx_addsy))
19398 && THUMB_IS_FUNC (fixP->fx_addsy)
19399 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19400 base = fixP->fx_where + fixP->fx_frag->fr_address;
19401 return base + 8;
19402
19403 case BFD_RELOC_ARM_PCREL_BRANCH:
19404 case BFD_RELOC_ARM_PCREL_JUMP:
19405 case BFD_RELOC_ARM_PLT32:
19406 #ifdef TE_WINCE
19407 /* When handling fixups immediately, because we have already
19408 discovered the value of a symbol, or the address of the frag involved
19409 we must account for the offset by +8, as the OS loader will never see the reloc.
19410 see fixup_segment() in write.c
19411 The S_IS_EXTERNAL test handles the case of global symbols.
19412 Those need the calculated base, not just the pipe compensation the linker will need. */
19413 if (fixP->fx_pcrel
19414 && fixP->fx_addsy != NULL
19415 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19416 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19417 return base + 8;
19418 return base;
19419 #else
19420 return base + 8;
19421 #endif
19422
19423
19424 /* ARM mode loads relative to PC are also offset by +8. Unlike
19425 branches, the Windows CE loader *does* expect the relocation
19426 to take this into account. */
19427 case BFD_RELOC_ARM_OFFSET_IMM:
19428 case BFD_RELOC_ARM_OFFSET_IMM8:
19429 case BFD_RELOC_ARM_HWLITERAL:
19430 case BFD_RELOC_ARM_LITERAL:
19431 case BFD_RELOC_ARM_CP_OFF_IMM:
19432 return base + 8;
19433
19434
19435 /* Other PC-relative relocations are un-offset. */
19436 default:
19437 return base;
19438 }
19439 }
19440
19441 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19442 Otherwise we have no need to default values of symbols. */
19443
19444 symbolS *
19445 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
19446 {
19447 #ifdef OBJ_ELF
19448 if (name[0] == '_' && name[1] == 'G'
19449 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19450 {
19451 if (!GOT_symbol)
19452 {
19453 if (symbol_find (name))
19454 as_bad (_("GOT already in the symbol table"));
19455
19456 GOT_symbol = symbol_new (name, undefined_section,
19457 (valueT) 0, & zero_address_frag);
19458 }
19459
19460 return GOT_symbol;
19461 }
19462 #endif
19463
19464 return NULL;
19465 }
19466
19467 /* Subroutine of md_apply_fix. Check to see if an immediate can be
19468 computed as two separate immediate values, added together. We
19469 already know that this value cannot be computed by just one ARM
19470 instruction. */
19471
19472 static unsigned int
19473 validate_immediate_twopart (unsigned int val,
19474 unsigned int * highpart)
19475 {
19476 unsigned int a;
19477 unsigned int i;
19478
19479 for (i = 0; i < 32; i += 2)
19480 if (((a = rotate_left (val, i)) & 0xff) != 0)
19481 {
19482 if (a & 0xff00)
19483 {
19484 if (a & ~ 0xffff)
19485 continue;
19486 * highpart = (a >> 8) | ((i + 24) << 7);
19487 }
19488 else if (a & 0xff0000)
19489 {
19490 if (a & 0xff000000)
19491 continue;
19492 * highpart = (a >> 16) | ((i + 16) << 7);
19493 }
19494 else
19495 {
19496 gas_assert (a & 0xff000000);
19497 * highpart = (a >> 24) | ((i + 8) << 7);
19498 }
19499
19500 return (a & 0xff) | (i << 7);
19501 }
19502
19503 return FAIL;
19504 }
19505
19506 static int
19507 validate_offset_imm (unsigned int val, int hwse)
19508 {
19509 if ((hwse && val > 255) || val > 4095)
19510 return FAIL;
19511 return val;
19512 }
19513
19514 /* Subroutine of md_apply_fix. Do those data_ops which can take a
19515 negative immediate constant by altering the instruction. A bit of
19516 a hack really.
19517 MOV <-> MVN
19518 AND <-> BIC
19519 ADC <-> SBC
19520 by inverting the second operand, and
19521 ADD <-> SUB
19522 CMP <-> CMN
19523 by negating the second operand. */
19524
19525 static int
19526 negate_data_op (unsigned long * instruction,
19527 unsigned long value)
19528 {
19529 int op, new_inst;
19530 unsigned long negated, inverted;
19531
19532 negated = encode_arm_immediate (-value);
19533 inverted = encode_arm_immediate (~value);
19534
19535 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19536 switch (op)
19537 {
19538 /* First negates. */
19539 case OPCODE_SUB: /* ADD <-> SUB */
19540 new_inst = OPCODE_ADD;
19541 value = negated;
19542 break;
19543
19544 case OPCODE_ADD:
19545 new_inst = OPCODE_SUB;
19546 value = negated;
19547 break;
19548
19549 case OPCODE_CMP: /* CMP <-> CMN */
19550 new_inst = OPCODE_CMN;
19551 value = negated;
19552 break;
19553
19554 case OPCODE_CMN:
19555 new_inst = OPCODE_CMP;
19556 value = negated;
19557 break;
19558
19559 /* Now Inverted ops. */
19560 case OPCODE_MOV: /* MOV <-> MVN */
19561 new_inst = OPCODE_MVN;
19562 value = inverted;
19563 break;
19564
19565 case OPCODE_MVN:
19566 new_inst = OPCODE_MOV;
19567 value = inverted;
19568 break;
19569
19570 case OPCODE_AND: /* AND <-> BIC */
19571 new_inst = OPCODE_BIC;
19572 value = inverted;
19573 break;
19574
19575 case OPCODE_BIC:
19576 new_inst = OPCODE_AND;
19577 value = inverted;
19578 break;
19579
19580 case OPCODE_ADC: /* ADC <-> SBC */
19581 new_inst = OPCODE_SBC;
19582 value = inverted;
19583 break;
19584
19585 case OPCODE_SBC:
19586 new_inst = OPCODE_ADC;
19587 value = inverted;
19588 break;
19589
19590 /* We cannot do anything. */
19591 default:
19592 return FAIL;
19593 }
19594
19595 if (value == (unsigned) FAIL)
19596 return FAIL;
19597
19598 *instruction &= OPCODE_MASK;
19599 *instruction |= new_inst << DATA_OP_SHIFT;
19600 return value;
19601 }
19602
19603 /* Like negate_data_op, but for Thumb-2. */
19604
19605 static unsigned int
19606 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
19607 {
19608 int op, new_inst;
19609 int rd;
19610 unsigned int negated, inverted;
19611
19612 negated = encode_thumb32_immediate (-value);
19613 inverted = encode_thumb32_immediate (~value);
19614
19615 rd = (*instruction >> 8) & 0xf;
19616 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19617 switch (op)
19618 {
19619 /* ADD <-> SUB. Includes CMP <-> CMN. */
19620 case T2_OPCODE_SUB:
19621 new_inst = T2_OPCODE_ADD;
19622 value = negated;
19623 break;
19624
19625 case T2_OPCODE_ADD:
19626 new_inst = T2_OPCODE_SUB;
19627 value = negated;
19628 break;
19629
19630 /* ORR <-> ORN. Includes MOV <-> MVN. */
19631 case T2_OPCODE_ORR:
19632 new_inst = T2_OPCODE_ORN;
19633 value = inverted;
19634 break;
19635
19636 case T2_OPCODE_ORN:
19637 new_inst = T2_OPCODE_ORR;
19638 value = inverted;
19639 break;
19640
19641 /* AND <-> BIC. TST has no inverted equivalent. */
19642 case T2_OPCODE_AND:
19643 new_inst = T2_OPCODE_BIC;
19644 if (rd == 15)
19645 value = FAIL;
19646 else
19647 value = inverted;
19648 break;
19649
19650 case T2_OPCODE_BIC:
19651 new_inst = T2_OPCODE_AND;
19652 value = inverted;
19653 break;
19654
19655 /* ADC <-> SBC */
19656 case T2_OPCODE_ADC:
19657 new_inst = T2_OPCODE_SBC;
19658 value = inverted;
19659 break;
19660
19661 case T2_OPCODE_SBC:
19662 new_inst = T2_OPCODE_ADC;
19663 value = inverted;
19664 break;
19665
19666 /* We cannot do anything. */
19667 default:
19668 return FAIL;
19669 }
19670
19671 if (value == (unsigned int)FAIL)
19672 return FAIL;
19673
19674 *instruction &= T2_OPCODE_MASK;
19675 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19676 return value;
19677 }
19678
19679 /* Read a 32-bit thumb instruction from buf. */
19680 static unsigned long
19681 get_thumb32_insn (char * buf)
19682 {
19683 unsigned long insn;
19684 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19685 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19686
19687 return insn;
19688 }
19689
19690
19691 /* We usually want to set the low bit on the address of thumb function
19692 symbols. In particular .word foo - . should have the low bit set.
19693 Generic code tries to fold the difference of two symbols to
19694 a constant. Prevent this and force a relocation when the first symbols
19695 is a thumb function. */
19696
19697 bfd_boolean
19698 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19699 {
19700 if (op == O_subtract
19701 && l->X_op == O_symbol
19702 && r->X_op == O_symbol
19703 && THUMB_IS_FUNC (l->X_add_symbol))
19704 {
19705 l->X_op = O_subtract;
19706 l->X_op_symbol = r->X_add_symbol;
19707 l->X_add_number -= r->X_add_number;
19708 return TRUE;
19709 }
19710
19711 /* Process as normal. */
19712 return FALSE;
19713 }
19714
19715 /* Encode Thumb2 unconditional branches and calls. The encoding
19716 for the 2 are identical for the immediate values. */
19717
19718 static void
19719 encode_thumb2_b_bl_offset (char * buf, offsetT value)
19720 {
19721 #define T2I1I2MASK ((1 << 13) | (1 << 11))
19722 offsetT newval;
19723 offsetT newval2;
19724 addressT S, I1, I2, lo, hi;
19725
19726 S = (value >> 24) & 0x01;
19727 I1 = (value >> 23) & 0x01;
19728 I2 = (value >> 22) & 0x01;
19729 hi = (value >> 12) & 0x3ff;
19730 lo = (value >> 1) & 0x7ff;
19731 newval = md_chars_to_number (buf, THUMB_SIZE);
19732 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19733 newval |= (S << 10) | hi;
19734 newval2 &= ~T2I1I2MASK;
19735 newval2 |= (((I1 ^ S) << 13) | ((I2 ^ S) << 11) | lo) ^ T2I1I2MASK;
19736 md_number_to_chars (buf, newval, THUMB_SIZE);
19737 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19738 }
19739
19740 void
19741 md_apply_fix (fixS * fixP,
19742 valueT * valP,
19743 segT seg)
19744 {
19745 offsetT value = * valP;
19746 offsetT newval;
19747 unsigned int newimm;
19748 unsigned long temp;
19749 int sign;
19750 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
19751
19752 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
19753
19754 /* Note whether this will delete the relocation. */
19755
19756 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19757 fixP->fx_done = 1;
19758
19759 /* On a 64-bit host, silently truncate 'value' to 32 bits for
19760 consistency with the behaviour on 32-bit hosts. Remember value
19761 for emit_reloc. */
19762 value &= 0xffffffff;
19763 value ^= 0x80000000;
19764 value -= 0x80000000;
19765
19766 *valP = value;
19767 fixP->fx_addnumber = value;
19768
19769 /* Same treatment for fixP->fx_offset. */
19770 fixP->fx_offset &= 0xffffffff;
19771 fixP->fx_offset ^= 0x80000000;
19772 fixP->fx_offset -= 0x80000000;
19773
19774 switch (fixP->fx_r_type)
19775 {
19776 case BFD_RELOC_NONE:
19777 /* This will need to go in the object file. */
19778 fixP->fx_done = 0;
19779 break;
19780
19781 case BFD_RELOC_ARM_IMMEDIATE:
19782 /* We claim that this fixup has been processed here,
19783 even if in fact we generate an error because we do
19784 not have a reloc for it, so tc_gen_reloc will reject it. */
19785 fixP->fx_done = 1;
19786
19787 if (fixP->fx_addsy)
19788 {
19789 const char *msg = 0;
19790
19791 if (! S_IS_DEFINED (fixP->fx_addsy))
19792 msg = _("undefined symbol %s used as an immediate value");
19793 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19794 msg = _("symbol %s is in a different section");
19795 else if (S_IS_WEAK (fixP->fx_addsy))
19796 msg = _("symbol %s is weak and may be overridden later");
19797
19798 if (msg)
19799 {
19800 as_bad_where (fixP->fx_file, fixP->fx_line,
19801 msg, S_GET_NAME (fixP->fx_addsy));
19802 break;
19803 }
19804 }
19805
19806 newimm = encode_arm_immediate (value);
19807 temp = md_chars_to_number (buf, INSN_SIZE);
19808
19809 /* If the instruction will fail, see if we can fix things up by
19810 changing the opcode. */
19811 if (newimm == (unsigned int) FAIL
19812 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
19813 {
19814 as_bad_where (fixP->fx_file, fixP->fx_line,
19815 _("invalid constant (%lx) after fixup"),
19816 (unsigned long) value);
19817 break;
19818 }
19819
19820 newimm |= (temp & 0xfffff000);
19821 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19822 break;
19823
19824 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19825 {
19826 unsigned int highpart = 0;
19827 unsigned int newinsn = 0xe1a00000; /* nop. */
19828
19829 if (fixP->fx_addsy)
19830 {
19831 const char *msg = 0;
19832
19833 if (! S_IS_DEFINED (fixP->fx_addsy))
19834 msg = _("undefined symbol %s used as an immediate value");
19835 else if (S_GET_SEGMENT (fixP->fx_addsy) != seg)
19836 msg = _("symbol %s is in a different section");
19837 else if (S_IS_WEAK (fixP->fx_addsy))
19838 msg = _("symbol %s is weak and may be overridden later");
19839
19840 if (msg)
19841 {
19842 as_bad_where (fixP->fx_file, fixP->fx_line,
19843 msg, S_GET_NAME (fixP->fx_addsy));
19844 break;
19845 }
19846 }
19847
19848 newimm = encode_arm_immediate (value);
19849 temp = md_chars_to_number (buf, INSN_SIZE);
19850
19851 /* If the instruction will fail, see if we can fix things up by
19852 changing the opcode. */
19853 if (newimm == (unsigned int) FAIL
19854 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19855 {
19856 /* No ? OK - try using two ADD instructions to generate
19857 the value. */
19858 newimm = validate_immediate_twopart (value, & highpart);
19859
19860 /* Yes - then make sure that the second instruction is
19861 also an add. */
19862 if (newimm != (unsigned int) FAIL)
19863 newinsn = temp;
19864 /* Still No ? Try using a negated value. */
19865 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19866 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19867 /* Otherwise - give up. */
19868 else
19869 {
19870 as_bad_where (fixP->fx_file, fixP->fx_line,
19871 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19872 (long) value);
19873 break;
19874 }
19875
19876 /* Replace the first operand in the 2nd instruction (which
19877 is the PC) with the destination register. We have
19878 already added in the PC in the first instruction and we
19879 do not want to do it again. */
19880 newinsn &= ~ 0xf0000;
19881 newinsn |= ((newinsn & 0x0f000) << 4);
19882 }
19883
19884 newimm |= (temp & 0xfffff000);
19885 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19886
19887 highpart |= (newinsn & 0xfffff000);
19888 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19889 }
19890 break;
19891
19892 case BFD_RELOC_ARM_OFFSET_IMM:
19893 if (!fixP->fx_done && seg->use_rela_p)
19894 value = 0;
19895
19896 case BFD_RELOC_ARM_LITERAL:
19897 sign = value >= 0;
19898
19899 if (value < 0)
19900 value = - value;
19901
19902 if (validate_offset_imm (value, 0) == FAIL)
19903 {
19904 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19905 as_bad_where (fixP->fx_file, fixP->fx_line,
19906 _("invalid literal constant: pool needs to be closer"));
19907 else
19908 as_bad_where (fixP->fx_file, fixP->fx_line,
19909 _("bad immediate value for offset (%ld)"),
19910 (long) value);
19911 break;
19912 }
19913
19914 newval = md_chars_to_number (buf, INSN_SIZE);
19915 newval &= 0xff7ff000;
19916 newval |= value | (sign ? INDEX_UP : 0);
19917 md_number_to_chars (buf, newval, INSN_SIZE);
19918 break;
19919
19920 case BFD_RELOC_ARM_OFFSET_IMM8:
19921 case BFD_RELOC_ARM_HWLITERAL:
19922 sign = value >= 0;
19923
19924 if (value < 0)
19925 value = - value;
19926
19927 if (validate_offset_imm (value, 1) == FAIL)
19928 {
19929 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19930 as_bad_where (fixP->fx_file, fixP->fx_line,
19931 _("invalid literal constant: pool needs to be closer"));
19932 else
19933 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
19934 (long) value);
19935 break;
19936 }
19937
19938 newval = md_chars_to_number (buf, INSN_SIZE);
19939 newval &= 0xff7ff0f0;
19940 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19941 md_number_to_chars (buf, newval, INSN_SIZE);
19942 break;
19943
19944 case BFD_RELOC_ARM_T32_OFFSET_U8:
19945 if (value < 0 || value > 1020 || value % 4 != 0)
19946 as_bad_where (fixP->fx_file, fixP->fx_line,
19947 _("bad immediate value for offset (%ld)"), (long) value);
19948 value /= 4;
19949
19950 newval = md_chars_to_number (buf+2, THUMB_SIZE);
19951 newval |= value;
19952 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19953 break;
19954
19955 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19956 /* This is a complicated relocation used for all varieties of Thumb32
19957 load/store instruction with immediate offset:
19958
19959 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19960 *4, optional writeback(W)
19961 (doubleword load/store)
19962
19963 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19964 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19965 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19966 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19967 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19968
19969 Uppercase letters indicate bits that are already encoded at
19970 this point. Lowercase letters are our problem. For the
19971 second block of instructions, the secondary opcode nybble
19972 (bits 8..11) is present, and bit 23 is zero, even if this is
19973 a PC-relative operation. */
19974 newval = md_chars_to_number (buf, THUMB_SIZE);
19975 newval <<= 16;
19976 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
19977
19978 if ((newval & 0xf0000000) == 0xe0000000)
19979 {
19980 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19981 if (value >= 0)
19982 newval |= (1 << 23);
19983 else
19984 value = -value;
19985 if (value % 4 != 0)
19986 {
19987 as_bad_where (fixP->fx_file, fixP->fx_line,
19988 _("offset not a multiple of 4"));
19989 break;
19990 }
19991 value /= 4;
19992 if (value > 0xff)
19993 {
19994 as_bad_where (fixP->fx_file, fixP->fx_line,
19995 _("offset out of range"));
19996 break;
19997 }
19998 newval &= ~0xff;
19999 }
20000 else if ((newval & 0x000f0000) == 0x000f0000)
20001 {
20002 /* PC-relative, 12-bit offset. */
20003 if (value >= 0)
20004 newval |= (1 << 23);
20005 else
20006 value = -value;
20007 if (value > 0xfff)
20008 {
20009 as_bad_where (fixP->fx_file, fixP->fx_line,
20010 _("offset out of range"));
20011 break;
20012 }
20013 newval &= ~0xfff;
20014 }
20015 else if ((newval & 0x00000100) == 0x00000100)
20016 {
20017 /* Writeback: 8-bit, +/- offset. */
20018 if (value >= 0)
20019 newval |= (1 << 9);
20020 else
20021 value = -value;
20022 if (value > 0xff)
20023 {
20024 as_bad_where (fixP->fx_file, fixP->fx_line,
20025 _("offset out of range"));
20026 break;
20027 }
20028 newval &= ~0xff;
20029 }
20030 else if ((newval & 0x00000f00) == 0x00000e00)
20031 {
20032 /* T-instruction: positive 8-bit offset. */
20033 if (value < 0 || value > 0xff)
20034 {
20035 as_bad_where (fixP->fx_file, fixP->fx_line,
20036 _("offset out of range"));
20037 break;
20038 }
20039 newval &= ~0xff;
20040 newval |= value;
20041 }
20042 else
20043 {
20044 /* Positive 12-bit or negative 8-bit offset. */
20045 int limit;
20046 if (value >= 0)
20047 {
20048 newval |= (1 << 23);
20049 limit = 0xfff;
20050 }
20051 else
20052 {
20053 value = -value;
20054 limit = 0xff;
20055 }
20056 if (value > limit)
20057 {
20058 as_bad_where (fixP->fx_file, fixP->fx_line,
20059 _("offset out of range"));
20060 break;
20061 }
20062 newval &= ~limit;
20063 }
20064
20065 newval |= value;
20066 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
20067 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
20068 break;
20069
20070 case BFD_RELOC_ARM_SHIFT_IMM:
20071 newval = md_chars_to_number (buf, INSN_SIZE);
20072 if (((unsigned long) value) > 32
20073 || (value == 32
20074 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
20075 {
20076 as_bad_where (fixP->fx_file, fixP->fx_line,
20077 _("shift expression is too large"));
20078 break;
20079 }
20080
20081 if (value == 0)
20082 /* Shifts of zero must be done as lsl. */
20083 newval &= ~0x60;
20084 else if (value == 32)
20085 value = 0;
20086 newval &= 0xfffff07f;
20087 newval |= (value & 0x1f) << 7;
20088 md_number_to_chars (buf, newval, INSN_SIZE);
20089 break;
20090
20091 case BFD_RELOC_ARM_T32_IMMEDIATE:
20092 case BFD_RELOC_ARM_T32_ADD_IMM:
20093 case BFD_RELOC_ARM_T32_IMM12:
20094 case BFD_RELOC_ARM_T32_ADD_PC12:
20095 /* We claim that this fixup has been processed here,
20096 even if in fact we generate an error because we do
20097 not have a reloc for it, so tc_gen_reloc will reject it. */
20098 fixP->fx_done = 1;
20099
20100 if (fixP->fx_addsy
20101 && ! S_IS_DEFINED (fixP->fx_addsy))
20102 {
20103 as_bad_where (fixP->fx_file, fixP->fx_line,
20104 _("undefined symbol %s used as an immediate value"),
20105 S_GET_NAME (fixP->fx_addsy));
20106 break;
20107 }
20108
20109 newval = md_chars_to_number (buf, THUMB_SIZE);
20110 newval <<= 16;
20111 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
20112
20113 newimm = FAIL;
20114 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20115 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20116 {
20117 newimm = encode_thumb32_immediate (value);
20118 if (newimm == (unsigned int) FAIL)
20119 newimm = thumb32_negate_data_op (&newval, value);
20120 }
20121 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
20122 && newimm == (unsigned int) FAIL)
20123 {
20124 /* Turn add/sum into addw/subw. */
20125 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
20126 newval = (newval & 0xfeffffff) | 0x02000000;
20127
20128 /* 12 bit immediate for addw/subw. */
20129 if (value < 0)
20130 {
20131 value = -value;
20132 newval ^= 0x00a00000;
20133 }
20134 if (value > 0xfff)
20135 newimm = (unsigned int) FAIL;
20136 else
20137 newimm = value;
20138 }
20139
20140 if (newimm == (unsigned int)FAIL)
20141 {
20142 as_bad_where (fixP->fx_file, fixP->fx_line,
20143 _("invalid constant (%lx) after fixup"),
20144 (unsigned long) value);
20145 break;
20146 }
20147
20148 newval |= (newimm & 0x800) << 15;
20149 newval |= (newimm & 0x700) << 4;
20150 newval |= (newimm & 0x0ff);
20151
20152 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
20153 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
20154 break;
20155
20156 case BFD_RELOC_ARM_SMC:
20157 if (((unsigned long) value) > 0xffff)
20158 as_bad_where (fixP->fx_file, fixP->fx_line,
20159 _("invalid smc expression"));
20160 newval = md_chars_to_number (buf, INSN_SIZE);
20161 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
20162 md_number_to_chars (buf, newval, INSN_SIZE);
20163 break;
20164
20165 case BFD_RELOC_ARM_SWI:
20166 if (fixP->tc_fix_data != 0)
20167 {
20168 if (((unsigned long) value) > 0xff)
20169 as_bad_where (fixP->fx_file, fixP->fx_line,
20170 _("invalid swi expression"));
20171 newval = md_chars_to_number (buf, THUMB_SIZE);
20172 newval |= value;
20173 md_number_to_chars (buf, newval, THUMB_SIZE);
20174 }
20175 else
20176 {
20177 if (((unsigned long) value) > 0x00ffffff)
20178 as_bad_where (fixP->fx_file, fixP->fx_line,
20179 _("invalid swi expression"));
20180 newval = md_chars_to_number (buf, INSN_SIZE);
20181 newval |= value;
20182 md_number_to_chars (buf, newval, INSN_SIZE);
20183 }
20184 break;
20185
20186 case BFD_RELOC_ARM_MULTI:
20187 if (((unsigned long) value) > 0xffff)
20188 as_bad_where (fixP->fx_file, fixP->fx_line,
20189 _("invalid expression in load/store multiple"));
20190 newval = value | md_chars_to_number (buf, INSN_SIZE);
20191 md_number_to_chars (buf, newval, INSN_SIZE);
20192 break;
20193
20194 #ifdef OBJ_ELF
20195 case BFD_RELOC_ARM_PCREL_CALL:
20196
20197 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20198 && fixP->fx_addsy
20199 && !S_IS_EXTERNAL (fixP->fx_addsy)
20200 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20201 && THUMB_IS_FUNC (fixP->fx_addsy))
20202 /* Flip the bl to blx. This is a simple flip
20203 bit here because we generate PCREL_CALL for
20204 unconditional bls. */
20205 {
20206 newval = md_chars_to_number (buf, INSN_SIZE);
20207 newval = newval | 0x10000000;
20208 md_number_to_chars (buf, newval, INSN_SIZE);
20209 temp = 1;
20210 fixP->fx_done = 1;
20211 }
20212 else
20213 temp = 3;
20214 goto arm_branch_common;
20215
20216 case BFD_RELOC_ARM_PCREL_JUMP:
20217 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20218 && fixP->fx_addsy
20219 && !S_IS_EXTERNAL (fixP->fx_addsy)
20220 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20221 && THUMB_IS_FUNC (fixP->fx_addsy))
20222 {
20223 /* This would map to a bl<cond>, b<cond>,
20224 b<always> to a Thumb function. We
20225 need to force a relocation for this particular
20226 case. */
20227 newval = md_chars_to_number (buf, INSN_SIZE);
20228 fixP->fx_done = 0;
20229 }
20230
20231 case BFD_RELOC_ARM_PLT32:
20232 #endif
20233 case BFD_RELOC_ARM_PCREL_BRANCH:
20234 temp = 3;
20235 goto arm_branch_common;
20236
20237 case BFD_RELOC_ARM_PCREL_BLX:
20238
20239 temp = 1;
20240 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20241 && fixP->fx_addsy
20242 && !S_IS_EXTERNAL (fixP->fx_addsy)
20243 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20244 && ARM_IS_FUNC (fixP->fx_addsy))
20245 {
20246 /* Flip the blx to a bl and warn. */
20247 const char *name = S_GET_NAME (fixP->fx_addsy);
20248 newval = 0xeb000000;
20249 as_warn_where (fixP->fx_file, fixP->fx_line,
20250 _("blx to '%s' an ARM ISA state function changed to bl"),
20251 name);
20252 md_number_to_chars (buf, newval, INSN_SIZE);
20253 temp = 3;
20254 fixP->fx_done = 1;
20255 }
20256
20257 #ifdef OBJ_ELF
20258 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20259 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20260 #endif
20261
20262 arm_branch_common:
20263 /* We are going to store value (shifted right by two) in the
20264 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20265 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20266 also be be clear. */
20267 if (value & temp)
20268 as_bad_where (fixP->fx_file, fixP->fx_line,
20269 _("misaligned branch destination"));
20270 if ((value & (offsetT)0xfe000000) != (offsetT)0
20271 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20272 as_bad_where (fixP->fx_file, fixP->fx_line,
20273 _("branch out of range"));
20274
20275 if (fixP->fx_done || !seg->use_rela_p)
20276 {
20277 newval = md_chars_to_number (buf, INSN_SIZE);
20278 newval |= (value >> 2) & 0x00ffffff;
20279 /* Set the H bit on BLX instructions. */
20280 if (temp == 1)
20281 {
20282 if (value & 2)
20283 newval |= 0x01000000;
20284 else
20285 newval &= ~0x01000000;
20286 }
20287 md_number_to_chars (buf, newval, INSN_SIZE);
20288 }
20289 break;
20290
20291 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20292 /* CBZ can only branch forward. */
20293
20294 /* Attempts to use CBZ to branch to the next instruction
20295 (which, strictly speaking, are prohibited) will be turned into
20296 no-ops.
20297
20298 FIXME: It may be better to remove the instruction completely and
20299 perform relaxation. */
20300 if (value == -2)
20301 {
20302 newval = md_chars_to_number (buf, THUMB_SIZE);
20303 newval = 0xbf00; /* NOP encoding T1 */
20304 md_number_to_chars (buf, newval, THUMB_SIZE);
20305 }
20306 else
20307 {
20308 if (value & ~0x7e)
20309 as_bad_where (fixP->fx_file, fixP->fx_line,
20310 _("branch out of range"));
20311
20312 if (fixP->fx_done || !seg->use_rela_p)
20313 {
20314 newval = md_chars_to_number (buf, THUMB_SIZE);
20315 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20316 md_number_to_chars (buf, newval, THUMB_SIZE);
20317 }
20318 }
20319 break;
20320
20321 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
20322 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20323 as_bad_where (fixP->fx_file, fixP->fx_line,
20324 _("branch out of range"));
20325
20326 if (fixP->fx_done || !seg->use_rela_p)
20327 {
20328 newval = md_chars_to_number (buf, THUMB_SIZE);
20329 newval |= (value & 0x1ff) >> 1;
20330 md_number_to_chars (buf, newval, THUMB_SIZE);
20331 }
20332 break;
20333
20334 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
20335 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20336 as_bad_where (fixP->fx_file, fixP->fx_line,
20337 _("branch out of range"));
20338
20339 if (fixP->fx_done || !seg->use_rela_p)
20340 {
20341 newval = md_chars_to_number (buf, THUMB_SIZE);
20342 newval |= (value & 0xfff) >> 1;
20343 md_number_to_chars (buf, newval, THUMB_SIZE);
20344 }
20345 break;
20346
20347 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20348 if (fixP->fx_addsy
20349 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20350 && !S_IS_EXTERNAL (fixP->fx_addsy)
20351 && S_IS_DEFINED (fixP->fx_addsy)
20352 && ARM_IS_FUNC (fixP->fx_addsy)
20353 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20354 {
20355 /* Force a relocation for a branch 20 bits wide. */
20356 fixP->fx_done = 0;
20357 }
20358 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20359 as_bad_where (fixP->fx_file, fixP->fx_line,
20360 _("conditional branch out of range"));
20361
20362 if (fixP->fx_done || !seg->use_rela_p)
20363 {
20364 offsetT newval2;
20365 addressT S, J1, J2, lo, hi;
20366
20367 S = (value & 0x00100000) >> 20;
20368 J2 = (value & 0x00080000) >> 19;
20369 J1 = (value & 0x00040000) >> 18;
20370 hi = (value & 0x0003f000) >> 12;
20371 lo = (value & 0x00000ffe) >> 1;
20372
20373 newval = md_chars_to_number (buf, THUMB_SIZE);
20374 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20375 newval |= (S << 10) | hi;
20376 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20377 md_number_to_chars (buf, newval, THUMB_SIZE);
20378 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20379 }
20380 break;
20381
20382 case BFD_RELOC_THUMB_PCREL_BLX:
20383
20384 /* If there is a blx from a thumb state function to
20385 another thumb function flip this to a bl and warn
20386 about it. */
20387
20388 if (fixP->fx_addsy
20389 && S_IS_DEFINED (fixP->fx_addsy)
20390 && !S_IS_EXTERNAL (fixP->fx_addsy)
20391 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20392 && THUMB_IS_FUNC (fixP->fx_addsy))
20393 {
20394 const char *name = S_GET_NAME (fixP->fx_addsy);
20395 as_warn_where (fixP->fx_file, fixP->fx_line,
20396 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20397 name);
20398 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20399 newval = newval | 0x1000;
20400 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20401 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20402 fixP->fx_done = 1;
20403 }
20404
20405
20406 goto thumb_bl_common;
20407
20408 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20409
20410 /* A bl from Thumb state ISA to an internal ARM state function
20411 is converted to a blx. */
20412 if (fixP->fx_addsy
20413 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20414 && !S_IS_EXTERNAL (fixP->fx_addsy)
20415 && S_IS_DEFINED (fixP->fx_addsy)
20416 && ARM_IS_FUNC (fixP->fx_addsy)
20417 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20418 {
20419 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20420 newval = newval & ~0x1000;
20421 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20422 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20423 fixP->fx_done = 1;
20424 }
20425
20426 thumb_bl_common:
20427
20428 #ifdef OBJ_ELF
20429 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20430 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20431 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20432 #endif
20433
20434 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20435 /* For a BLX instruction, make sure that the relocation is rounded up
20436 to a word boundary. This follows the semantics of the instruction
20437 which specifies that bit 1 of the target address will come from bit
20438 1 of the base address. */
20439 value = (value + 1) & ~ 1;
20440
20441
20442 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20443 {
20444 if (!(ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2)))
20445 {
20446 as_bad_where (fixP->fx_file, fixP->fx_line,
20447 _("branch out of range"));
20448 }
20449 else if ((value & ~0x1ffffff)
20450 && ((value & ~0x1ffffff) != ~0x1ffffff))
20451 {
20452 as_bad_where (fixP->fx_file, fixP->fx_line,
20453 _("Thumb2 branch out of range"));
20454 }
20455 }
20456
20457 if (fixP->fx_done || !seg->use_rela_p)
20458 encode_thumb2_b_bl_offset (buf, value);
20459
20460 break;
20461
20462 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20463 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20464 as_bad_where (fixP->fx_file, fixP->fx_line,
20465 _("branch out of range"));
20466
20467 if (fixP->fx_done || !seg->use_rela_p)
20468 encode_thumb2_b_bl_offset (buf, value);
20469
20470 break;
20471
20472 case BFD_RELOC_8:
20473 if (fixP->fx_done || !seg->use_rela_p)
20474 md_number_to_chars (buf, value, 1);
20475 break;
20476
20477 case BFD_RELOC_16:
20478 if (fixP->fx_done || !seg->use_rela_p)
20479 md_number_to_chars (buf, value, 2);
20480 break;
20481
20482 #ifdef OBJ_ELF
20483 case BFD_RELOC_ARM_TLS_GD32:
20484 case BFD_RELOC_ARM_TLS_LE32:
20485 case BFD_RELOC_ARM_TLS_IE32:
20486 case BFD_RELOC_ARM_TLS_LDM32:
20487 case BFD_RELOC_ARM_TLS_LDO32:
20488 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20489 /* fall through */
20490
20491 case BFD_RELOC_ARM_GOT32:
20492 case BFD_RELOC_ARM_GOTOFF:
20493 if (fixP->fx_done || !seg->use_rela_p)
20494 md_number_to_chars (buf, 0, 4);
20495 break;
20496
20497 case BFD_RELOC_ARM_GOT_PREL:
20498 if (fixP->fx_done || !seg->use_rela_p)
20499 md_number_to_chars (buf, value, 4);
20500 break;
20501
20502 case BFD_RELOC_ARM_TARGET2:
20503 /* TARGET2 is not partial-inplace, so we need to write the
20504 addend here for REL targets, because it won't be written out
20505 during reloc processing later. */
20506 if (fixP->fx_done || !seg->use_rela_p)
20507 md_number_to_chars (buf, fixP->fx_offset, 4);
20508 break;
20509 #endif
20510
20511 case BFD_RELOC_RVA:
20512 case BFD_RELOC_32:
20513 case BFD_RELOC_ARM_TARGET1:
20514 case BFD_RELOC_ARM_ROSEGREL32:
20515 case BFD_RELOC_ARM_SBREL32:
20516 case BFD_RELOC_32_PCREL:
20517 #ifdef TE_PE
20518 case BFD_RELOC_32_SECREL:
20519 #endif
20520 if (fixP->fx_done || !seg->use_rela_p)
20521 #ifdef TE_WINCE
20522 /* For WinCE we only do this for pcrel fixups. */
20523 if (fixP->fx_done || fixP->fx_pcrel)
20524 #endif
20525 md_number_to_chars (buf, value, 4);
20526 break;
20527
20528 #ifdef OBJ_ELF
20529 case BFD_RELOC_ARM_PREL31:
20530 if (fixP->fx_done || !seg->use_rela_p)
20531 {
20532 newval = md_chars_to_number (buf, 4) & 0x80000000;
20533 if ((value ^ (value >> 1)) & 0x40000000)
20534 {
20535 as_bad_where (fixP->fx_file, fixP->fx_line,
20536 _("rel31 relocation overflow"));
20537 }
20538 newval |= value & 0x7fffffff;
20539 md_number_to_chars (buf, newval, 4);
20540 }
20541 break;
20542 #endif
20543
20544 case BFD_RELOC_ARM_CP_OFF_IMM:
20545 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
20546 if (value < -1023 || value > 1023 || (value & 3))
20547 as_bad_where (fixP->fx_file, fixP->fx_line,
20548 _("co-processor offset out of range"));
20549 cp_off_common:
20550 sign = value >= 0;
20551 if (value < 0)
20552 value = -value;
20553 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20554 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20555 newval = md_chars_to_number (buf, INSN_SIZE);
20556 else
20557 newval = get_thumb32_insn (buf);
20558 newval &= 0xff7fff00;
20559 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
20560 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20561 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20562 md_number_to_chars (buf, newval, INSN_SIZE);
20563 else
20564 put_thumb32_insn (buf, newval);
20565 break;
20566
20567 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
20568 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
20569 if (value < -255 || value > 255)
20570 as_bad_where (fixP->fx_file, fixP->fx_line,
20571 _("co-processor offset out of range"));
20572 value *= 4;
20573 goto cp_off_common;
20574
20575 case BFD_RELOC_ARM_THUMB_OFFSET:
20576 newval = md_chars_to_number (buf, THUMB_SIZE);
20577 /* Exactly what ranges, and where the offset is inserted depends
20578 on the type of instruction, we can establish this from the
20579 top 4 bits. */
20580 switch (newval >> 12)
20581 {
20582 case 4: /* PC load. */
20583 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20584 forced to zero for these loads; md_pcrel_from has already
20585 compensated for this. */
20586 if (value & 3)
20587 as_bad_where (fixP->fx_file, fixP->fx_line,
20588 _("invalid offset, target not word aligned (0x%08lX)"),
20589 (((unsigned long) fixP->fx_frag->fr_address
20590 + (unsigned long) fixP->fx_where) & ~3)
20591 + (unsigned long) value);
20592
20593 if (value & ~0x3fc)
20594 as_bad_where (fixP->fx_file, fixP->fx_line,
20595 _("invalid offset, value too big (0x%08lX)"),
20596 (long) value);
20597
20598 newval |= value >> 2;
20599 break;
20600
20601 case 9: /* SP load/store. */
20602 if (value & ~0x3fc)
20603 as_bad_where (fixP->fx_file, fixP->fx_line,
20604 _("invalid offset, value too big (0x%08lX)"),
20605 (long) value);
20606 newval |= value >> 2;
20607 break;
20608
20609 case 6: /* Word load/store. */
20610 if (value & ~0x7c)
20611 as_bad_where (fixP->fx_file, fixP->fx_line,
20612 _("invalid offset, value too big (0x%08lX)"),
20613 (long) value);
20614 newval |= value << 4; /* 6 - 2. */
20615 break;
20616
20617 case 7: /* Byte load/store. */
20618 if (value & ~0x1f)
20619 as_bad_where (fixP->fx_file, fixP->fx_line,
20620 _("invalid offset, value too big (0x%08lX)"),
20621 (long) value);
20622 newval |= value << 6;
20623 break;
20624
20625 case 8: /* Halfword load/store. */
20626 if (value & ~0x3e)
20627 as_bad_where (fixP->fx_file, fixP->fx_line,
20628 _("invalid offset, value too big (0x%08lX)"),
20629 (long) value);
20630 newval |= value << 5; /* 6 - 1. */
20631 break;
20632
20633 default:
20634 as_bad_where (fixP->fx_file, fixP->fx_line,
20635 "Unable to process relocation for thumb opcode: %lx",
20636 (unsigned long) newval);
20637 break;
20638 }
20639 md_number_to_chars (buf, newval, THUMB_SIZE);
20640 break;
20641
20642 case BFD_RELOC_ARM_THUMB_ADD:
20643 /* This is a complicated relocation, since we use it for all of
20644 the following immediate relocations:
20645
20646 3bit ADD/SUB
20647 8bit ADD/SUB
20648 9bit ADD/SUB SP word-aligned
20649 10bit ADD PC/SP word-aligned
20650
20651 The type of instruction being processed is encoded in the
20652 instruction field:
20653
20654 0x8000 SUB
20655 0x00F0 Rd
20656 0x000F Rs
20657 */
20658 newval = md_chars_to_number (buf, THUMB_SIZE);
20659 {
20660 int rd = (newval >> 4) & 0xf;
20661 int rs = newval & 0xf;
20662 int subtract = !!(newval & 0x8000);
20663
20664 /* Check for HI regs, only very restricted cases allowed:
20665 Adjusting SP, and using PC or SP to get an address. */
20666 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20667 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20668 as_bad_where (fixP->fx_file, fixP->fx_line,
20669 _("invalid Hi register with immediate"));
20670
20671 /* If value is negative, choose the opposite instruction. */
20672 if (value < 0)
20673 {
20674 value = -value;
20675 subtract = !subtract;
20676 if (value < 0)
20677 as_bad_where (fixP->fx_file, fixP->fx_line,
20678 _("immediate value out of range"));
20679 }
20680
20681 if (rd == REG_SP)
20682 {
20683 if (value & ~0x1fc)
20684 as_bad_where (fixP->fx_file, fixP->fx_line,
20685 _("invalid immediate for stack address calculation"));
20686 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20687 newval |= value >> 2;
20688 }
20689 else if (rs == REG_PC || rs == REG_SP)
20690 {
20691 if (subtract || value & ~0x3fc)
20692 as_bad_where (fixP->fx_file, fixP->fx_line,
20693 _("invalid immediate for address calculation (value = 0x%08lX)"),
20694 (unsigned long) value);
20695 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20696 newval |= rd << 8;
20697 newval |= value >> 2;
20698 }
20699 else if (rs == rd)
20700 {
20701 if (value & ~0xff)
20702 as_bad_where (fixP->fx_file, fixP->fx_line,
20703 _("immediate value out of range"));
20704 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20705 newval |= (rd << 8) | value;
20706 }
20707 else
20708 {
20709 if (value & ~0x7)
20710 as_bad_where (fixP->fx_file, fixP->fx_line,
20711 _("immediate value out of range"));
20712 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20713 newval |= rd | (rs << 3) | (value << 6);
20714 }
20715 }
20716 md_number_to_chars (buf, newval, THUMB_SIZE);
20717 break;
20718
20719 case BFD_RELOC_ARM_THUMB_IMM:
20720 newval = md_chars_to_number (buf, THUMB_SIZE);
20721 if (value < 0 || value > 255)
20722 as_bad_where (fixP->fx_file, fixP->fx_line,
20723 _("invalid immediate: %ld is out of range"),
20724 (long) value);
20725 newval |= value;
20726 md_number_to_chars (buf, newval, THUMB_SIZE);
20727 break;
20728
20729 case BFD_RELOC_ARM_THUMB_SHIFT:
20730 /* 5bit shift value (0..32). LSL cannot take 32. */
20731 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20732 temp = newval & 0xf800;
20733 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20734 as_bad_where (fixP->fx_file, fixP->fx_line,
20735 _("invalid shift value: %ld"), (long) value);
20736 /* Shifts of zero must be encoded as LSL. */
20737 if (value == 0)
20738 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20739 /* Shifts of 32 are encoded as zero. */
20740 else if (value == 32)
20741 value = 0;
20742 newval |= value << 6;
20743 md_number_to_chars (buf, newval, THUMB_SIZE);
20744 break;
20745
20746 case BFD_RELOC_VTABLE_INHERIT:
20747 case BFD_RELOC_VTABLE_ENTRY:
20748 fixP->fx_done = 0;
20749 return;
20750
20751 case BFD_RELOC_ARM_MOVW:
20752 case BFD_RELOC_ARM_MOVT:
20753 case BFD_RELOC_ARM_THUMB_MOVW:
20754 case BFD_RELOC_ARM_THUMB_MOVT:
20755 if (fixP->fx_done || !seg->use_rela_p)
20756 {
20757 /* REL format relocations are limited to a 16-bit addend. */
20758 if (!fixP->fx_done)
20759 {
20760 if (value < -0x8000 || value > 0x7fff)
20761 as_bad_where (fixP->fx_file, fixP->fx_line,
20762 _("offset out of range"));
20763 }
20764 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20765 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20766 {
20767 value >>= 16;
20768 }
20769
20770 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20771 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20772 {
20773 newval = get_thumb32_insn (buf);
20774 newval &= 0xfbf08f00;
20775 newval |= (value & 0xf000) << 4;
20776 newval |= (value & 0x0800) << 15;
20777 newval |= (value & 0x0700) << 4;
20778 newval |= (value & 0x00ff);
20779 put_thumb32_insn (buf, newval);
20780 }
20781 else
20782 {
20783 newval = md_chars_to_number (buf, 4);
20784 newval &= 0xfff0f000;
20785 newval |= value & 0x0fff;
20786 newval |= (value & 0xf000) << 4;
20787 md_number_to_chars (buf, newval, 4);
20788 }
20789 }
20790 return;
20791
20792 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20793 case BFD_RELOC_ARM_ALU_PC_G0:
20794 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20795 case BFD_RELOC_ARM_ALU_PC_G1:
20796 case BFD_RELOC_ARM_ALU_PC_G2:
20797 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20798 case BFD_RELOC_ARM_ALU_SB_G0:
20799 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20800 case BFD_RELOC_ARM_ALU_SB_G1:
20801 case BFD_RELOC_ARM_ALU_SB_G2:
20802 gas_assert (!fixP->fx_done);
20803 if (!seg->use_rela_p)
20804 {
20805 bfd_vma insn;
20806 bfd_vma encoded_addend;
20807 bfd_vma addend_abs = abs (value);
20808
20809 /* Check that the absolute value of the addend can be
20810 expressed as an 8-bit constant plus a rotation. */
20811 encoded_addend = encode_arm_immediate (addend_abs);
20812 if (encoded_addend == (unsigned int) FAIL)
20813 as_bad_where (fixP->fx_file, fixP->fx_line,
20814 _("the offset 0x%08lX is not representable"),
20815 (unsigned long) addend_abs);
20816
20817 /* Extract the instruction. */
20818 insn = md_chars_to_number (buf, INSN_SIZE);
20819
20820 /* If the addend is positive, use an ADD instruction.
20821 Otherwise use a SUB. Take care not to destroy the S bit. */
20822 insn &= 0xff1fffff;
20823 if (value < 0)
20824 insn |= 1 << 22;
20825 else
20826 insn |= 1 << 23;
20827
20828 /* Place the encoded addend into the first 12 bits of the
20829 instruction. */
20830 insn &= 0xfffff000;
20831 insn |= encoded_addend;
20832
20833 /* Update the instruction. */
20834 md_number_to_chars (buf, insn, INSN_SIZE);
20835 }
20836 break;
20837
20838 case BFD_RELOC_ARM_LDR_PC_G0:
20839 case BFD_RELOC_ARM_LDR_PC_G1:
20840 case BFD_RELOC_ARM_LDR_PC_G2:
20841 case BFD_RELOC_ARM_LDR_SB_G0:
20842 case BFD_RELOC_ARM_LDR_SB_G1:
20843 case BFD_RELOC_ARM_LDR_SB_G2:
20844 gas_assert (!fixP->fx_done);
20845 if (!seg->use_rela_p)
20846 {
20847 bfd_vma insn;
20848 bfd_vma addend_abs = abs (value);
20849
20850 /* Check that the absolute value of the addend can be
20851 encoded in 12 bits. */
20852 if (addend_abs >= 0x1000)
20853 as_bad_where (fixP->fx_file, fixP->fx_line,
20854 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
20855 (unsigned long) addend_abs);
20856
20857 /* Extract the instruction. */
20858 insn = md_chars_to_number (buf, INSN_SIZE);
20859
20860 /* If the addend is negative, clear bit 23 of the instruction.
20861 Otherwise set it. */
20862 if (value < 0)
20863 insn &= ~(1 << 23);
20864 else
20865 insn |= 1 << 23;
20866
20867 /* Place the absolute value of the addend into the first 12 bits
20868 of the instruction. */
20869 insn &= 0xfffff000;
20870 insn |= addend_abs;
20871
20872 /* Update the instruction. */
20873 md_number_to_chars (buf, insn, INSN_SIZE);
20874 }
20875 break;
20876
20877 case BFD_RELOC_ARM_LDRS_PC_G0:
20878 case BFD_RELOC_ARM_LDRS_PC_G1:
20879 case BFD_RELOC_ARM_LDRS_PC_G2:
20880 case BFD_RELOC_ARM_LDRS_SB_G0:
20881 case BFD_RELOC_ARM_LDRS_SB_G1:
20882 case BFD_RELOC_ARM_LDRS_SB_G2:
20883 gas_assert (!fixP->fx_done);
20884 if (!seg->use_rela_p)
20885 {
20886 bfd_vma insn;
20887 bfd_vma addend_abs = abs (value);
20888
20889 /* Check that the absolute value of the addend can be
20890 encoded in 8 bits. */
20891 if (addend_abs >= 0x100)
20892 as_bad_where (fixP->fx_file, fixP->fx_line,
20893 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
20894 (unsigned long) addend_abs);
20895
20896 /* Extract the instruction. */
20897 insn = md_chars_to_number (buf, INSN_SIZE);
20898
20899 /* If the addend is negative, clear bit 23 of the instruction.
20900 Otherwise set it. */
20901 if (value < 0)
20902 insn &= ~(1 << 23);
20903 else
20904 insn |= 1 << 23;
20905
20906 /* Place the first four bits of the absolute value of the addend
20907 into the first 4 bits of the instruction, and the remaining
20908 four into bits 8 .. 11. */
20909 insn &= 0xfffff0f0;
20910 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
20911
20912 /* Update the instruction. */
20913 md_number_to_chars (buf, insn, INSN_SIZE);
20914 }
20915 break;
20916
20917 case BFD_RELOC_ARM_LDC_PC_G0:
20918 case BFD_RELOC_ARM_LDC_PC_G1:
20919 case BFD_RELOC_ARM_LDC_PC_G2:
20920 case BFD_RELOC_ARM_LDC_SB_G0:
20921 case BFD_RELOC_ARM_LDC_SB_G1:
20922 case BFD_RELOC_ARM_LDC_SB_G2:
20923 gas_assert (!fixP->fx_done);
20924 if (!seg->use_rela_p)
20925 {
20926 bfd_vma insn;
20927 bfd_vma addend_abs = abs (value);
20928
20929 /* Check that the absolute value of the addend is a multiple of
20930 four and, when divided by four, fits in 8 bits. */
20931 if (addend_abs & 0x3)
20932 as_bad_where (fixP->fx_file, fixP->fx_line,
20933 _("bad offset 0x%08lX (must be word-aligned)"),
20934 (unsigned long) addend_abs);
20935
20936 if ((addend_abs >> 2) > 0xff)
20937 as_bad_where (fixP->fx_file, fixP->fx_line,
20938 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
20939 (unsigned long) addend_abs);
20940
20941 /* Extract the instruction. */
20942 insn = md_chars_to_number (buf, INSN_SIZE);
20943
20944 /* If the addend is negative, clear bit 23 of the instruction.
20945 Otherwise set it. */
20946 if (value < 0)
20947 insn &= ~(1 << 23);
20948 else
20949 insn |= 1 << 23;
20950
20951 /* Place the addend (divided by four) into the first eight
20952 bits of the instruction. */
20953 insn &= 0xfffffff0;
20954 insn |= addend_abs >> 2;
20955
20956 /* Update the instruction. */
20957 md_number_to_chars (buf, insn, INSN_SIZE);
20958 }
20959 break;
20960
20961 case BFD_RELOC_ARM_V4BX:
20962 /* This will need to go in the object file. */
20963 fixP->fx_done = 0;
20964 break;
20965
20966 case BFD_RELOC_UNUSED:
20967 default:
20968 as_bad_where (fixP->fx_file, fixP->fx_line,
20969 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20970 }
20971 }
20972
20973 /* Translate internal representation of relocation info to BFD target
20974 format. */
20975
20976 arelent *
20977 tc_gen_reloc (asection *section, fixS *fixp)
20978 {
20979 arelent * reloc;
20980 bfd_reloc_code_real_type code;
20981
20982 reloc = (arelent *) xmalloc (sizeof (arelent));
20983
20984 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
20985 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20986 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
20987
20988 if (fixp->fx_pcrel)
20989 {
20990 if (section->use_rela_p)
20991 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20992 else
20993 fixp->fx_offset = reloc->address;
20994 }
20995 reloc->addend = fixp->fx_offset;
20996
20997 switch (fixp->fx_r_type)
20998 {
20999 case BFD_RELOC_8:
21000 if (fixp->fx_pcrel)
21001 {
21002 code = BFD_RELOC_8_PCREL;
21003 break;
21004 }
21005
21006 case BFD_RELOC_16:
21007 if (fixp->fx_pcrel)
21008 {
21009 code = BFD_RELOC_16_PCREL;
21010 break;
21011 }
21012
21013 case BFD_RELOC_32:
21014 if (fixp->fx_pcrel)
21015 {
21016 code = BFD_RELOC_32_PCREL;
21017 break;
21018 }
21019
21020 case BFD_RELOC_ARM_MOVW:
21021 if (fixp->fx_pcrel)
21022 {
21023 code = BFD_RELOC_ARM_MOVW_PCREL;
21024 break;
21025 }
21026
21027 case BFD_RELOC_ARM_MOVT:
21028 if (fixp->fx_pcrel)
21029 {
21030 code = BFD_RELOC_ARM_MOVT_PCREL;
21031 break;
21032 }
21033
21034 case BFD_RELOC_ARM_THUMB_MOVW:
21035 if (fixp->fx_pcrel)
21036 {
21037 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
21038 break;
21039 }
21040
21041 case BFD_RELOC_ARM_THUMB_MOVT:
21042 if (fixp->fx_pcrel)
21043 {
21044 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
21045 break;
21046 }
21047
21048 case BFD_RELOC_NONE:
21049 case BFD_RELOC_ARM_PCREL_BRANCH:
21050 case BFD_RELOC_ARM_PCREL_BLX:
21051 case BFD_RELOC_RVA:
21052 case BFD_RELOC_THUMB_PCREL_BRANCH7:
21053 case BFD_RELOC_THUMB_PCREL_BRANCH9:
21054 case BFD_RELOC_THUMB_PCREL_BRANCH12:
21055 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21056 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21057 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21058 case BFD_RELOC_VTABLE_ENTRY:
21059 case BFD_RELOC_VTABLE_INHERIT:
21060 #ifdef TE_PE
21061 case BFD_RELOC_32_SECREL:
21062 #endif
21063 code = fixp->fx_r_type;
21064 break;
21065
21066 case BFD_RELOC_THUMB_PCREL_BLX:
21067 #ifdef OBJ_ELF
21068 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
21069 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
21070 else
21071 #endif
21072 code = BFD_RELOC_THUMB_PCREL_BLX;
21073 break;
21074
21075 case BFD_RELOC_ARM_LITERAL:
21076 case BFD_RELOC_ARM_HWLITERAL:
21077 /* If this is called then the a literal has
21078 been referenced across a section boundary. */
21079 as_bad_where (fixp->fx_file, fixp->fx_line,
21080 _("literal referenced across section boundary"));
21081 return NULL;
21082
21083 #ifdef OBJ_ELF
21084 case BFD_RELOC_ARM_GOT32:
21085 case BFD_RELOC_ARM_GOTOFF:
21086 case BFD_RELOC_ARM_GOT_PREL:
21087 case BFD_RELOC_ARM_PLT32:
21088 case BFD_RELOC_ARM_TARGET1:
21089 case BFD_RELOC_ARM_ROSEGREL32:
21090 case BFD_RELOC_ARM_SBREL32:
21091 case BFD_RELOC_ARM_PREL31:
21092 case BFD_RELOC_ARM_TARGET2:
21093 case BFD_RELOC_ARM_TLS_LE32:
21094 case BFD_RELOC_ARM_TLS_LDO32:
21095 case BFD_RELOC_ARM_PCREL_CALL:
21096 case BFD_RELOC_ARM_PCREL_JUMP:
21097 case BFD_RELOC_ARM_ALU_PC_G0_NC:
21098 case BFD_RELOC_ARM_ALU_PC_G0:
21099 case BFD_RELOC_ARM_ALU_PC_G1_NC:
21100 case BFD_RELOC_ARM_ALU_PC_G1:
21101 case BFD_RELOC_ARM_ALU_PC_G2:
21102 case BFD_RELOC_ARM_LDR_PC_G0:
21103 case BFD_RELOC_ARM_LDR_PC_G1:
21104 case BFD_RELOC_ARM_LDR_PC_G2:
21105 case BFD_RELOC_ARM_LDRS_PC_G0:
21106 case BFD_RELOC_ARM_LDRS_PC_G1:
21107 case BFD_RELOC_ARM_LDRS_PC_G2:
21108 case BFD_RELOC_ARM_LDC_PC_G0:
21109 case BFD_RELOC_ARM_LDC_PC_G1:
21110 case BFD_RELOC_ARM_LDC_PC_G2:
21111 case BFD_RELOC_ARM_ALU_SB_G0_NC:
21112 case BFD_RELOC_ARM_ALU_SB_G0:
21113 case BFD_RELOC_ARM_ALU_SB_G1_NC:
21114 case BFD_RELOC_ARM_ALU_SB_G1:
21115 case BFD_RELOC_ARM_ALU_SB_G2:
21116 case BFD_RELOC_ARM_LDR_SB_G0:
21117 case BFD_RELOC_ARM_LDR_SB_G1:
21118 case BFD_RELOC_ARM_LDR_SB_G2:
21119 case BFD_RELOC_ARM_LDRS_SB_G0:
21120 case BFD_RELOC_ARM_LDRS_SB_G1:
21121 case BFD_RELOC_ARM_LDRS_SB_G2:
21122 case BFD_RELOC_ARM_LDC_SB_G0:
21123 case BFD_RELOC_ARM_LDC_SB_G1:
21124 case BFD_RELOC_ARM_LDC_SB_G2:
21125 case BFD_RELOC_ARM_V4BX:
21126 code = fixp->fx_r_type;
21127 break;
21128
21129 case BFD_RELOC_ARM_TLS_GD32:
21130 case BFD_RELOC_ARM_TLS_IE32:
21131 case BFD_RELOC_ARM_TLS_LDM32:
21132 /* BFD will include the symbol's address in the addend.
21133 But we don't want that, so subtract it out again here. */
21134 if (!S_IS_COMMON (fixp->fx_addsy))
21135 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
21136 code = fixp->fx_r_type;
21137 break;
21138 #endif
21139
21140 case BFD_RELOC_ARM_IMMEDIATE:
21141 as_bad_where (fixp->fx_file, fixp->fx_line,
21142 _("internal relocation (type: IMMEDIATE) not fixed up"));
21143 return NULL;
21144
21145 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
21146 as_bad_where (fixp->fx_file, fixp->fx_line,
21147 _("ADRL used for a symbol not defined in the same file"));
21148 return NULL;
21149
21150 case BFD_RELOC_ARM_OFFSET_IMM:
21151 if (section->use_rela_p)
21152 {
21153 code = fixp->fx_r_type;
21154 break;
21155 }
21156
21157 if (fixp->fx_addsy != NULL
21158 && !S_IS_DEFINED (fixp->fx_addsy)
21159 && S_IS_LOCAL (fixp->fx_addsy))
21160 {
21161 as_bad_where (fixp->fx_file, fixp->fx_line,
21162 _("undefined local label `%s'"),
21163 S_GET_NAME (fixp->fx_addsy));
21164 return NULL;
21165 }
21166
21167 as_bad_where (fixp->fx_file, fixp->fx_line,
21168 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
21169 return NULL;
21170
21171 default:
21172 {
21173 char * type;
21174
21175 switch (fixp->fx_r_type)
21176 {
21177 case BFD_RELOC_NONE: type = "NONE"; break;
21178 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
21179 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
21180 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
21181 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
21182 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
21183 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
21184 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
21185 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
21186 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
21187 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
21188 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
21189 default: type = _("<unknown>"); break;
21190 }
21191 as_bad_where (fixp->fx_file, fixp->fx_line,
21192 _("cannot represent %s relocation in this object file format"),
21193 type);
21194 return NULL;
21195 }
21196 }
21197
21198 #ifdef OBJ_ELF
21199 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
21200 && GOT_symbol
21201 && fixp->fx_addsy == GOT_symbol)
21202 {
21203 code = BFD_RELOC_ARM_GOTPC;
21204 reloc->addend = fixp->fx_offset = reloc->address;
21205 }
21206 #endif
21207
21208 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
21209
21210 if (reloc->howto == NULL)
21211 {
21212 as_bad_where (fixp->fx_file, fixp->fx_line,
21213 _("cannot represent %s relocation in this object file format"),
21214 bfd_get_reloc_code_name (code));
21215 return NULL;
21216 }
21217
21218 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21219 vtable entry to be used in the relocation's section offset. */
21220 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21221 reloc->address = fixp->fx_offset;
21222
21223 return reloc;
21224 }
21225
21226 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
21227
21228 void
21229 cons_fix_new_arm (fragS * frag,
21230 int where,
21231 int size,
21232 expressionS * exp)
21233 {
21234 bfd_reloc_code_real_type type;
21235 int pcrel = 0;
21236
21237 /* Pick a reloc.
21238 FIXME: @@ Should look at CPU word size. */
21239 switch (size)
21240 {
21241 case 1:
21242 type = BFD_RELOC_8;
21243 break;
21244 case 2:
21245 type = BFD_RELOC_16;
21246 break;
21247 case 4:
21248 default:
21249 type = BFD_RELOC_32;
21250 break;
21251 case 8:
21252 type = BFD_RELOC_64;
21253 break;
21254 }
21255
21256 #ifdef TE_PE
21257 if (exp->X_op == O_secrel)
21258 {
21259 exp->X_op = O_symbol;
21260 type = BFD_RELOC_32_SECREL;
21261 }
21262 #endif
21263
21264 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21265 }
21266
21267 #if defined (OBJ_COFF)
21268 void
21269 arm_validate_fix (fixS * fixP)
21270 {
21271 /* If the destination of the branch is a defined symbol which does not have
21272 the THUMB_FUNC attribute, then we must be calling a function which has
21273 the (interfacearm) attribute. We look for the Thumb entry point to that
21274 function and change the branch to refer to that function instead. */
21275 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21276 && fixP->fx_addsy != NULL
21277 && S_IS_DEFINED (fixP->fx_addsy)
21278 && ! THUMB_IS_FUNC (fixP->fx_addsy))
21279 {
21280 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
21281 }
21282 }
21283 #endif
21284
21285
21286 int
21287 arm_force_relocation (struct fix * fixp)
21288 {
21289 #if defined (OBJ_COFF) && defined (TE_PE)
21290 if (fixp->fx_r_type == BFD_RELOC_RVA)
21291 return 1;
21292 #endif
21293
21294 /* In case we have a call or a branch to a function in ARM ISA mode from
21295 a thumb function or vice-versa force the relocation. These relocations
21296 are cleared off for some cores that might have blx and simple transformations
21297 are possible. */
21298
21299 #ifdef OBJ_ELF
21300 switch (fixp->fx_r_type)
21301 {
21302 case BFD_RELOC_ARM_PCREL_JUMP:
21303 case BFD_RELOC_ARM_PCREL_CALL:
21304 case BFD_RELOC_THUMB_PCREL_BLX:
21305 if (THUMB_IS_FUNC (fixp->fx_addsy))
21306 return 1;
21307 break;
21308
21309 case BFD_RELOC_ARM_PCREL_BLX:
21310 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21311 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21312 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21313 if (ARM_IS_FUNC (fixp->fx_addsy))
21314 return 1;
21315 break;
21316
21317 default:
21318 break;
21319 }
21320 #endif
21321
21322 /* Resolve these relocations even if the symbol is extern or weak. */
21323 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21324 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
21325 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
21326 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
21327 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21328 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21329 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
21330 return 0;
21331
21332 /* Always leave these relocations for the linker. */
21333 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21334 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21335 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21336 return 1;
21337
21338 /* Always generate relocations against function symbols. */
21339 if (fixp->fx_r_type == BFD_RELOC_32
21340 && fixp->fx_addsy
21341 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21342 return 1;
21343
21344 return generic_force_reloc (fixp);
21345 }
21346
21347 #if defined (OBJ_ELF) || defined (OBJ_COFF)
21348 /* Relocations against function names must be left unadjusted,
21349 so that the linker can use this information to generate interworking
21350 stubs. The MIPS version of this function
21351 also prevents relocations that are mips-16 specific, but I do not
21352 know why it does this.
21353
21354 FIXME:
21355 There is one other problem that ought to be addressed here, but
21356 which currently is not: Taking the address of a label (rather
21357 than a function) and then later jumping to that address. Such
21358 addresses also ought to have their bottom bit set (assuming that
21359 they reside in Thumb code), but at the moment they will not. */
21360
21361 bfd_boolean
21362 arm_fix_adjustable (fixS * fixP)
21363 {
21364 if (fixP->fx_addsy == NULL)
21365 return 1;
21366
21367 /* Preserve relocations against symbols with function type. */
21368 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
21369 return FALSE;
21370
21371 if (THUMB_IS_FUNC (fixP->fx_addsy)
21372 && fixP->fx_subsy == NULL)
21373 return FALSE;
21374
21375 /* We need the symbol name for the VTABLE entries. */
21376 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21377 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21378 return FALSE;
21379
21380 /* Don't allow symbols to be discarded on GOT related relocs. */
21381 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21382 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21383 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21384 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21385 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21386 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21387 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21388 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21389 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
21390 return FALSE;
21391
21392 /* Similarly for group relocations. */
21393 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21394 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21395 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21396 return FALSE;
21397
21398 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21399 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21400 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21401 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21402 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21403 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21404 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21405 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21406 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
21407 return FALSE;
21408
21409 return TRUE;
21410 }
21411 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21412
21413 #ifdef OBJ_ELF
21414
21415 const char *
21416 elf32_arm_target_format (void)
21417 {
21418 #ifdef TE_SYMBIAN
21419 return (target_big_endian
21420 ? "elf32-bigarm-symbian"
21421 : "elf32-littlearm-symbian");
21422 #elif defined (TE_VXWORKS)
21423 return (target_big_endian
21424 ? "elf32-bigarm-vxworks"
21425 : "elf32-littlearm-vxworks");
21426 #else
21427 if (target_big_endian)
21428 return "elf32-bigarm";
21429 else
21430 return "elf32-littlearm";
21431 #endif
21432 }
21433
21434 void
21435 armelf_frob_symbol (symbolS * symp,
21436 int * puntp)
21437 {
21438 elf_frob_symbol (symp, puntp);
21439 }
21440 #endif
21441
21442 /* MD interface: Finalization. */
21443
21444 void
21445 arm_cleanup (void)
21446 {
21447 literal_pool * pool;
21448
21449 /* Ensure that all the IT blocks are properly closed. */
21450 check_it_blocks_finished ();
21451
21452 for (pool = list_of_pools; pool; pool = pool->next)
21453 {
21454 /* Put it at the end of the relevant section. */
21455 subseg_set (pool->section, pool->sub_section);
21456 #ifdef OBJ_ELF
21457 arm_elf_change_section ();
21458 #endif
21459 s_ltorg (0);
21460 }
21461 }
21462
21463 #ifdef OBJ_ELF
21464 /* Remove any excess mapping symbols generated for alignment frags in
21465 SEC. We may have created a mapping symbol before a zero byte
21466 alignment; remove it if there's a mapping symbol after the
21467 alignment. */
21468 static void
21469 check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21470 void *dummy ATTRIBUTE_UNUSED)
21471 {
21472 segment_info_type *seginfo = seg_info (sec);
21473 fragS *fragp;
21474
21475 if (seginfo == NULL || seginfo->frchainP == NULL)
21476 return;
21477
21478 for (fragp = seginfo->frchainP->frch_root;
21479 fragp != NULL;
21480 fragp = fragp->fr_next)
21481 {
21482 symbolS *sym = fragp->tc_frag_data.last_map;
21483 fragS *next = fragp->fr_next;
21484
21485 /* Variable-sized frags have been converted to fixed size by
21486 this point. But if this was variable-sized to start with,
21487 there will be a fixed-size frag after it. So don't handle
21488 next == NULL. */
21489 if (sym == NULL || next == NULL)
21490 continue;
21491
21492 if (S_GET_VALUE (sym) < next->fr_address)
21493 /* Not at the end of this frag. */
21494 continue;
21495 know (S_GET_VALUE (sym) == next->fr_address);
21496
21497 do
21498 {
21499 if (next->tc_frag_data.first_map != NULL)
21500 {
21501 /* Next frag starts with a mapping symbol. Discard this
21502 one. */
21503 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21504 break;
21505 }
21506
21507 if (next->fr_next == NULL)
21508 {
21509 /* This mapping symbol is at the end of the section. Discard
21510 it. */
21511 know (next->fr_fix == 0 && next->fr_var == 0);
21512 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21513 break;
21514 }
21515
21516 /* As long as we have empty frags without any mapping symbols,
21517 keep looking. */
21518 /* If the next frag is non-empty and does not start with a
21519 mapping symbol, then this mapping symbol is required. */
21520 if (next->fr_address != next->fr_next->fr_address)
21521 break;
21522
21523 next = next->fr_next;
21524 }
21525 while (next != NULL);
21526 }
21527 }
21528 #endif
21529
21530 /* Adjust the symbol table. This marks Thumb symbols as distinct from
21531 ARM ones. */
21532
21533 void
21534 arm_adjust_symtab (void)
21535 {
21536 #ifdef OBJ_COFF
21537 symbolS * sym;
21538
21539 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21540 {
21541 if (ARM_IS_THUMB (sym))
21542 {
21543 if (THUMB_IS_FUNC (sym))
21544 {
21545 /* Mark the symbol as a Thumb function. */
21546 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21547 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21548 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
21549
21550 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21551 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21552 else
21553 as_bad (_("%s: unexpected function type: %d"),
21554 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21555 }
21556 else switch (S_GET_STORAGE_CLASS (sym))
21557 {
21558 case C_EXT:
21559 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21560 break;
21561 case C_STAT:
21562 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21563 break;
21564 case C_LABEL:
21565 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21566 break;
21567 default:
21568 /* Do nothing. */
21569 break;
21570 }
21571 }
21572
21573 if (ARM_IS_INTERWORK (sym))
21574 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
21575 }
21576 #endif
21577 #ifdef OBJ_ELF
21578 symbolS * sym;
21579 char bind;
21580
21581 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21582 {
21583 if (ARM_IS_THUMB (sym))
21584 {
21585 elf_symbol_type * elf_sym;
21586
21587 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21588 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
21589
21590 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21591 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
21592 {
21593 /* If it's a .thumb_func, declare it as so,
21594 otherwise tag label as .code 16. */
21595 if (THUMB_IS_FUNC (sym))
21596 elf_sym->internal_elf_sym.st_info =
21597 ELF_ST_INFO (bind, STT_ARM_TFUNC);
21598 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21599 elf_sym->internal_elf_sym.st_info =
21600 ELF_ST_INFO (bind, STT_ARM_16BIT);
21601 }
21602 }
21603 }
21604
21605 /* Remove any overlapping mapping symbols generated by alignment frags. */
21606 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
21607 #endif
21608 }
21609
21610 /* MD interface: Initialization. */
21611
21612 static void
21613 set_constant_flonums (void)
21614 {
21615 int i;
21616
21617 for (i = 0; i < NUM_FLOAT_VALS; i++)
21618 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21619 abort ();
21620 }
21621
21622 /* Auto-select Thumb mode if it's the only available instruction set for the
21623 given architecture. */
21624
21625 static void
21626 autoselect_thumb_from_cpu_variant (void)
21627 {
21628 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21629 opcode_select (16);
21630 }
21631
21632 void
21633 md_begin (void)
21634 {
21635 unsigned mach;
21636 unsigned int i;
21637
21638 if ( (arm_ops_hsh = hash_new ()) == NULL
21639 || (arm_cond_hsh = hash_new ()) == NULL
21640 || (arm_shift_hsh = hash_new ()) == NULL
21641 || (arm_psr_hsh = hash_new ()) == NULL
21642 || (arm_v7m_psr_hsh = hash_new ()) == NULL
21643 || (arm_reg_hsh = hash_new ()) == NULL
21644 || (arm_reloc_hsh = hash_new ()) == NULL
21645 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
21646 as_fatal (_("virtual memory exhausted"));
21647
21648 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
21649 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
21650 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
21651 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
21652 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
21653 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
21654 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
21655 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
21656 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
21657 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21658 (void *) (v7m_psrs + i));
21659 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
21660 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
21661 for (i = 0;
21662 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21663 i++)
21664 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
21665 (void *) (barrier_opt_names + i));
21666 #ifdef OBJ_ELF
21667 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
21668 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
21669 #endif
21670
21671 set_constant_flonums ();
21672
21673 /* Set the cpu variant based on the command-line options. We prefer
21674 -mcpu= over -march= if both are set (as for GCC); and we prefer
21675 -mfpu= over any other way of setting the floating point unit.
21676 Use of legacy options with new options are faulted. */
21677 if (legacy_cpu)
21678 {
21679 if (mcpu_cpu_opt || march_cpu_opt)
21680 as_bad (_("use of old and new-style options to set CPU type"));
21681
21682 mcpu_cpu_opt = legacy_cpu;
21683 }
21684 else if (!mcpu_cpu_opt)
21685 mcpu_cpu_opt = march_cpu_opt;
21686
21687 if (legacy_fpu)
21688 {
21689 if (mfpu_opt)
21690 as_bad (_("use of old and new-style options to set FPU type"));
21691
21692 mfpu_opt = legacy_fpu;
21693 }
21694 else if (!mfpu_opt)
21695 {
21696 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21697 || defined (TE_NetBSD) || defined (TE_VXWORKS))
21698 /* Some environments specify a default FPU. If they don't, infer it
21699 from the processor. */
21700 if (mcpu_fpu_opt)
21701 mfpu_opt = mcpu_fpu_opt;
21702 else
21703 mfpu_opt = march_fpu_opt;
21704 #else
21705 mfpu_opt = &fpu_default;
21706 #endif
21707 }
21708
21709 if (!mfpu_opt)
21710 {
21711 if (mcpu_cpu_opt != NULL)
21712 mfpu_opt = &fpu_default;
21713 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
21714 mfpu_opt = &fpu_arch_vfp_v2;
21715 else
21716 mfpu_opt = &fpu_arch_fpa;
21717 }
21718
21719 #ifdef CPU_DEFAULT
21720 if (!mcpu_cpu_opt)
21721 {
21722 mcpu_cpu_opt = &cpu_default;
21723 selected_cpu = cpu_default;
21724 }
21725 #else
21726 if (mcpu_cpu_opt)
21727 selected_cpu = *mcpu_cpu_opt;
21728 else
21729 mcpu_cpu_opt = &arm_arch_any;
21730 #endif
21731
21732 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
21733
21734 autoselect_thumb_from_cpu_variant ();
21735
21736 arm_arch_used = thumb_arch_used = arm_arch_none;
21737
21738 #if defined OBJ_COFF || defined OBJ_ELF
21739 {
21740 unsigned int flags = 0;
21741
21742 #if defined OBJ_ELF
21743 flags = meabi_flags;
21744
21745 switch (meabi_flags)
21746 {
21747 case EF_ARM_EABI_UNKNOWN:
21748 #endif
21749 /* Set the flags in the private structure. */
21750 if (uses_apcs_26) flags |= F_APCS26;
21751 if (support_interwork) flags |= F_INTERWORK;
21752 if (uses_apcs_float) flags |= F_APCS_FLOAT;
21753 if (pic_code) flags |= F_PIC;
21754 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
21755 flags |= F_SOFT_FLOAT;
21756
21757 switch (mfloat_abi_opt)
21758 {
21759 case ARM_FLOAT_ABI_SOFT:
21760 case ARM_FLOAT_ABI_SOFTFP:
21761 flags |= F_SOFT_FLOAT;
21762 break;
21763
21764 case ARM_FLOAT_ABI_HARD:
21765 if (flags & F_SOFT_FLOAT)
21766 as_bad (_("hard-float conflicts with specified fpu"));
21767 break;
21768 }
21769
21770 /* Using pure-endian doubles (even if soft-float). */
21771 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
21772 flags |= F_VFP_FLOAT;
21773
21774 #if defined OBJ_ELF
21775 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
21776 flags |= EF_ARM_MAVERICK_FLOAT;
21777 break;
21778
21779 case EF_ARM_EABI_VER4:
21780 case EF_ARM_EABI_VER5:
21781 /* No additional flags to set. */
21782 break;
21783
21784 default:
21785 abort ();
21786 }
21787 #endif
21788 bfd_set_private_flags (stdoutput, flags);
21789
21790 /* We have run out flags in the COFF header to encode the
21791 status of ATPCS support, so instead we create a dummy,
21792 empty, debug section called .arm.atpcs. */
21793 if (atpcs)
21794 {
21795 asection * sec;
21796
21797 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21798
21799 if (sec != NULL)
21800 {
21801 bfd_set_section_flags
21802 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21803 bfd_set_section_size (stdoutput, sec, 0);
21804 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21805 }
21806 }
21807 }
21808 #endif
21809
21810 /* Record the CPU type as well. */
21811 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21812 mach = bfd_mach_arm_iWMMXt2;
21813 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
21814 mach = bfd_mach_arm_iWMMXt;
21815 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
21816 mach = bfd_mach_arm_XScale;
21817 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
21818 mach = bfd_mach_arm_ep9312;
21819 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
21820 mach = bfd_mach_arm_5TE;
21821 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
21822 {
21823 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21824 mach = bfd_mach_arm_5T;
21825 else
21826 mach = bfd_mach_arm_5;
21827 }
21828 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
21829 {
21830 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21831 mach = bfd_mach_arm_4T;
21832 else
21833 mach = bfd_mach_arm_4;
21834 }
21835 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
21836 mach = bfd_mach_arm_3M;
21837 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21838 mach = bfd_mach_arm_3;
21839 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21840 mach = bfd_mach_arm_2a;
21841 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21842 mach = bfd_mach_arm_2;
21843 else
21844 mach = bfd_mach_arm_unknown;
21845
21846 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21847 }
21848
21849 /* Command line processing. */
21850
21851 /* md_parse_option
21852 Invocation line includes a switch not recognized by the base assembler.
21853 See if it's a processor-specific option.
21854
21855 This routine is somewhat complicated by the need for backwards
21856 compatibility (since older releases of gcc can't be changed).
21857 The new options try to make the interface as compatible as
21858 possible with GCC.
21859
21860 New options (supported) are:
21861
21862 -mcpu=<cpu name> Assemble for selected processor
21863 -march=<architecture name> Assemble for selected architecture
21864 -mfpu=<fpu architecture> Assemble for selected FPU.
21865 -EB/-mbig-endian Big-endian
21866 -EL/-mlittle-endian Little-endian
21867 -k Generate PIC code
21868 -mthumb Start in Thumb mode
21869 -mthumb-interwork Code supports ARM/Thumb interworking
21870
21871 -m[no-]warn-deprecated Warn about deprecated features
21872
21873 For now we will also provide support for:
21874
21875 -mapcs-32 32-bit Program counter
21876 -mapcs-26 26-bit Program counter
21877 -macps-float Floats passed in FP registers
21878 -mapcs-reentrant Reentrant code
21879 -matpcs
21880 (sometime these will probably be replaced with -mapcs=<list of options>
21881 and -matpcs=<list of options>)
21882
21883 The remaining options are only supported for back-wards compatibility.
21884 Cpu variants, the arm part is optional:
21885 -m[arm]1 Currently not supported.
21886 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21887 -m[arm]3 Arm 3 processor
21888 -m[arm]6[xx], Arm 6 processors
21889 -m[arm]7[xx][t][[d]m] Arm 7 processors
21890 -m[arm]8[10] Arm 8 processors
21891 -m[arm]9[20][tdmi] Arm 9 processors
21892 -mstrongarm[110[0]] StrongARM processors
21893 -mxscale XScale processors
21894 -m[arm]v[2345[t[e]]] Arm architectures
21895 -mall All (except the ARM1)
21896 FP variants:
21897 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21898 -mfpe-old (No float load/store multiples)
21899 -mvfpxd VFP Single precision
21900 -mvfp All VFP
21901 -mno-fpu Disable all floating point instructions
21902
21903 The following CPU names are recognized:
21904 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21905 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21906 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21907 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21908 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21909 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21910 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
21911
21912 */
21913
21914 const char * md_shortopts = "m:k";
21915
21916 #ifdef ARM_BI_ENDIAN
21917 #define OPTION_EB (OPTION_MD_BASE + 0)
21918 #define OPTION_EL (OPTION_MD_BASE + 1)
21919 #else
21920 #if TARGET_BYTES_BIG_ENDIAN
21921 #define OPTION_EB (OPTION_MD_BASE + 0)
21922 #else
21923 #define OPTION_EL (OPTION_MD_BASE + 1)
21924 #endif
21925 #endif
21926 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
21927
21928 struct option md_longopts[] =
21929 {
21930 #ifdef OPTION_EB
21931 {"EB", no_argument, NULL, OPTION_EB},
21932 #endif
21933 #ifdef OPTION_EL
21934 {"EL", no_argument, NULL, OPTION_EL},
21935 #endif
21936 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
21937 {NULL, no_argument, NULL, 0}
21938 };
21939
21940 size_t md_longopts_size = sizeof (md_longopts);
21941
21942 struct arm_option_table
21943 {
21944 char *option; /* Option name to match. */
21945 char *help; /* Help information. */
21946 int *var; /* Variable to change. */
21947 int value; /* What to change it to. */
21948 char *deprecated; /* If non-null, print this message. */
21949 };
21950
21951 struct arm_option_table arm_opts[] =
21952 {
21953 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21954 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21955 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21956 &support_interwork, 1, NULL},
21957 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21958 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21959 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21960 1, NULL},
21961 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21962 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21963 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21964 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21965 NULL},
21966
21967 /* These are recognized by the assembler, but have no affect on code. */
21968 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21969 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
21970
21971 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21972 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21973 &warn_on_deprecated, 0, NULL},
21974 {NULL, NULL, NULL, 0, NULL}
21975 };
21976
21977 struct arm_legacy_option_table
21978 {
21979 char *option; /* Option name to match. */
21980 const arm_feature_set **var; /* Variable to change. */
21981 const arm_feature_set value; /* What to change it to. */
21982 char *deprecated; /* If non-null, print this message. */
21983 };
21984
21985 const struct arm_legacy_option_table arm_legacy_opts[] =
21986 {
21987 /* DON'T add any new processors to this list -- we want the whole list
21988 to go away... Add them to the processors table instead. */
21989 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21990 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21991 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21992 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21993 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21994 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21995 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21996 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21997 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21998 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21999 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22000 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
22001 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22002 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
22003 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22004 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
22005 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22006 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
22007 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22008 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
22009 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22010 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
22011 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22012 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
22013 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22014 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
22015 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22016 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
22017 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22018 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
22019 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22020 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
22021 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22022 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
22023 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22024 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
22025 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22026 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
22027 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22028 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
22029 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22030 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
22031 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22032 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
22033 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22034 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
22035 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22036 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22037 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22038 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
22039 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22040 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
22041 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22042 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
22043 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22044 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
22045 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22046 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
22047 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22048 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
22049 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22050 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
22051 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22052 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
22053 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22054 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
22055 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22056 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
22057 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
22058 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
22059 N_("use -mcpu=strongarm110")},
22060 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
22061 N_("use -mcpu=strongarm1100")},
22062 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
22063 N_("use -mcpu=strongarm1110")},
22064 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
22065 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
22066 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
22067
22068 /* Architecture variants -- don't add any more to this list either. */
22069 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22070 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
22071 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22072 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
22073 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22074 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
22075 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22076 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
22077 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22078 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
22079 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22080 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
22081 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22082 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
22083 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22084 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
22085 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22086 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
22087
22088 /* Floating point variants -- don't add any more to this list either. */
22089 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
22090 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
22091 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
22092 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
22093 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
22094
22095 {NULL, NULL, ARM_ARCH_NONE, NULL}
22096 };
22097
22098 struct arm_cpu_option_table
22099 {
22100 char *name;
22101 const arm_feature_set value;
22102 /* For some CPUs we assume an FPU unless the user explicitly sets
22103 -mfpu=... */
22104 const arm_feature_set default_fpu;
22105 /* The canonical name of the CPU, or NULL to use NAME converted to upper
22106 case. */
22107 const char *canonical_name;
22108 };
22109
22110 /* This list should, at a minimum, contain all the cpu names
22111 recognized by GCC. */
22112 static const struct arm_cpu_option_table arm_cpus[] =
22113 {
22114 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
22115 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
22116 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
22117 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22118 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
22119 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22120 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22121 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22122 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22123 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22124 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22125 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22126 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22127 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22128 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22129 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
22130 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22131 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22132 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22133 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22134 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22135 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22136 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22137 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22138 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22139 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22140 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22141 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
22142 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22143 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22144 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22145 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22146 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22147 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22148 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22149 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22150 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22151 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22152 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22153 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
22154 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22155 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22156 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22157 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
22158 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22159 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
22160 /* For V5 or later processors we default to using VFP; but the user
22161 should really set the FPU type explicitly. */
22162 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22163 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22164 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22165 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
22166 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22167 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22168 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
22169 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22170 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
22171 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
22172 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22173 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22174 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22175 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22176 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22177 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
22178 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
22179 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22180 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22181 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
22182 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
22183 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
22184 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
22185 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
22186 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
22187 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
22188 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
22189 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
22190 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
22191 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
22192 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
22193 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
22194 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
22195 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
22196 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
22197 | FPU_NEON_EXT_V1),
22198 NULL},
22199 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
22200 | FPU_NEON_EXT_V1),
22201 NULL},
22202 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
22203 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
22204 {"cortex-m4", ARM_ARCH_V7EM, FPU_NONE, NULL},
22205 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
22206 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
22207 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
22208 /* ??? XSCALE is really an architecture. */
22209 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22210 /* ??? iwmmxt is not a processor. */
22211 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
22212 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
22213 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
22214 /* Maverick */
22215 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
22216 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
22217 };
22218
22219 struct arm_arch_option_table
22220 {
22221 char *name;
22222 const arm_feature_set value;
22223 const arm_feature_set default_fpu;
22224 };
22225
22226 /* This list should, at a minimum, contain all the architecture names
22227 recognized by GCC. */
22228 static const struct arm_arch_option_table arm_archs[] =
22229 {
22230 {"all", ARM_ANY, FPU_ARCH_FPA},
22231 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22232 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22233 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22234 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22235 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22236 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22237 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22238 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22239 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22240 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22241 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22242 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22243 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22244 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22245 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22246 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22247 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22248 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22249 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22250 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22251 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22252 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22253 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22254 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22255 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
22256 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
22257 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
22258 /* The official spelling of the ARMv7 profile variants is the dashed form.
22259 Accept the non-dashed form for compatibility with old toolchains. */
22260 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22261 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22262 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22263 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22264 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22265 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
22266 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
22267 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22268 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
22269 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
22270 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
22271 };
22272
22273 /* ISA extensions in the co-processor space. */
22274 struct arm_option_cpu_value_table
22275 {
22276 char *name;
22277 const arm_feature_set value;
22278 };
22279
22280 static const struct arm_option_cpu_value_table arm_extensions[] =
22281 {
22282 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22283 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22284 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
22285 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
22286 {NULL, ARM_ARCH_NONE}
22287 };
22288
22289 /* This list should, at a minimum, contain all the fpu names
22290 recognized by GCC. */
22291 static const struct arm_option_cpu_value_table arm_fpus[] =
22292 {
22293 {"softfpa", FPU_NONE},
22294 {"fpe", FPU_ARCH_FPE},
22295 {"fpe2", FPU_ARCH_FPE},
22296 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22297 {"fpa", FPU_ARCH_FPA},
22298 {"fpa10", FPU_ARCH_FPA},
22299 {"fpa11", FPU_ARCH_FPA},
22300 {"arm7500fe", FPU_ARCH_FPA},
22301 {"softvfp", FPU_ARCH_VFP},
22302 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22303 {"vfp", FPU_ARCH_VFP_V2},
22304 {"vfp9", FPU_ARCH_VFP_V2},
22305 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
22306 {"vfp10", FPU_ARCH_VFP_V2},
22307 {"vfp10-r0", FPU_ARCH_VFP_V1},
22308 {"vfpxd", FPU_ARCH_VFP_V1xD},
22309 {"vfpv2", FPU_ARCH_VFP_V2},
22310 {"vfpv3", FPU_ARCH_VFP_V3},
22311 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
22312 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
22313 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22314 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22315 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
22316 {"arm1020t", FPU_ARCH_VFP_V1},
22317 {"arm1020e", FPU_ARCH_VFP_V2},
22318 {"arm1136jfs", FPU_ARCH_VFP_V2},
22319 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22320 {"maverick", FPU_ARCH_MAVERICK},
22321 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
22322 {"neon-fp16", FPU_ARCH_NEON_FP16},
22323 {"vfpv4", FPU_ARCH_VFP_V4},
22324 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
22325 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
22326 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
22327 {NULL, ARM_ARCH_NONE}
22328 };
22329
22330 struct arm_option_value_table
22331 {
22332 char *name;
22333 long value;
22334 };
22335
22336 static const struct arm_option_value_table arm_float_abis[] =
22337 {
22338 {"hard", ARM_FLOAT_ABI_HARD},
22339 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22340 {"soft", ARM_FLOAT_ABI_SOFT},
22341 {NULL, 0}
22342 };
22343
22344 #ifdef OBJ_ELF
22345 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
22346 static const struct arm_option_value_table arm_eabis[] =
22347 {
22348 {"gnu", EF_ARM_EABI_UNKNOWN},
22349 {"4", EF_ARM_EABI_VER4},
22350 {"5", EF_ARM_EABI_VER5},
22351 {NULL, 0}
22352 };
22353 #endif
22354
22355 struct arm_long_option_table
22356 {
22357 char * option; /* Substring to match. */
22358 char * help; /* Help information. */
22359 int (* func) (char * subopt); /* Function to decode sub-option. */
22360 char * deprecated; /* If non-null, print this message. */
22361 };
22362
22363 static bfd_boolean
22364 arm_parse_extension (char * str, const arm_feature_set **opt_p)
22365 {
22366 arm_feature_set *ext_set = (arm_feature_set *)
22367 xmalloc (sizeof (arm_feature_set));
22368
22369 /* Copy the feature set, so that we can modify it. */
22370 *ext_set = **opt_p;
22371 *opt_p = ext_set;
22372
22373 while (str != NULL && *str != 0)
22374 {
22375 const struct arm_option_cpu_value_table * opt;
22376 char * ext;
22377 int optlen;
22378
22379 if (*str != '+')
22380 {
22381 as_bad (_("invalid architectural extension"));
22382 return FALSE;
22383 }
22384
22385 str++;
22386 ext = strchr (str, '+');
22387
22388 if (ext != NULL)
22389 optlen = ext - str;
22390 else
22391 optlen = strlen (str);
22392
22393 if (optlen == 0)
22394 {
22395 as_bad (_("missing architectural extension"));
22396 return FALSE;
22397 }
22398
22399 for (opt = arm_extensions; opt->name != NULL; opt++)
22400 if (strncmp (opt->name, str, optlen) == 0)
22401 {
22402 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
22403 break;
22404 }
22405
22406 if (opt->name == NULL)
22407 {
22408 as_bad (_("unknown architectural extension `%s'"), str);
22409 return FALSE;
22410 }
22411
22412 str = ext;
22413 };
22414
22415 return TRUE;
22416 }
22417
22418 static bfd_boolean
22419 arm_parse_cpu (char * str)
22420 {
22421 const struct arm_cpu_option_table * opt;
22422 char * ext = strchr (str, '+');
22423 int optlen;
22424
22425 if (ext != NULL)
22426 optlen = ext - str;
22427 else
22428 optlen = strlen (str);
22429
22430 if (optlen == 0)
22431 {
22432 as_bad (_("missing cpu name `%s'"), str);
22433 return FALSE;
22434 }
22435
22436 for (opt = arm_cpus; opt->name != NULL; opt++)
22437 if (strncmp (opt->name, str, optlen) == 0)
22438 {
22439 mcpu_cpu_opt = &opt->value;
22440 mcpu_fpu_opt = &opt->default_fpu;
22441 if (opt->canonical_name)
22442 strcpy (selected_cpu_name, opt->canonical_name);
22443 else
22444 {
22445 int i;
22446
22447 for (i = 0; i < optlen; i++)
22448 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22449 selected_cpu_name[i] = 0;
22450 }
22451
22452 if (ext != NULL)
22453 return arm_parse_extension (ext, &mcpu_cpu_opt);
22454
22455 return TRUE;
22456 }
22457
22458 as_bad (_("unknown cpu `%s'"), str);
22459 return FALSE;
22460 }
22461
22462 static bfd_boolean
22463 arm_parse_arch (char * str)
22464 {
22465 const struct arm_arch_option_table *opt;
22466 char *ext = strchr (str, '+');
22467 int optlen;
22468
22469 if (ext != NULL)
22470 optlen = ext - str;
22471 else
22472 optlen = strlen (str);
22473
22474 if (optlen == 0)
22475 {
22476 as_bad (_("missing architecture name `%s'"), str);
22477 return FALSE;
22478 }
22479
22480 for (opt = arm_archs; opt->name != NULL; opt++)
22481 if (streq (opt->name, str))
22482 {
22483 march_cpu_opt = &opt->value;
22484 march_fpu_opt = &opt->default_fpu;
22485 strcpy (selected_cpu_name, opt->name);
22486
22487 if (ext != NULL)
22488 return arm_parse_extension (ext, &march_cpu_opt);
22489
22490 return TRUE;
22491 }
22492
22493 as_bad (_("unknown architecture `%s'\n"), str);
22494 return FALSE;
22495 }
22496
22497 static bfd_boolean
22498 arm_parse_fpu (char * str)
22499 {
22500 const struct arm_option_cpu_value_table * opt;
22501
22502 for (opt = arm_fpus; opt->name != NULL; opt++)
22503 if (streq (opt->name, str))
22504 {
22505 mfpu_opt = &opt->value;
22506 return TRUE;
22507 }
22508
22509 as_bad (_("unknown floating point format `%s'\n"), str);
22510 return FALSE;
22511 }
22512
22513 static bfd_boolean
22514 arm_parse_float_abi (char * str)
22515 {
22516 const struct arm_option_value_table * opt;
22517
22518 for (opt = arm_float_abis; opt->name != NULL; opt++)
22519 if (streq (opt->name, str))
22520 {
22521 mfloat_abi_opt = opt->value;
22522 return TRUE;
22523 }
22524
22525 as_bad (_("unknown floating point abi `%s'\n"), str);
22526 return FALSE;
22527 }
22528
22529 #ifdef OBJ_ELF
22530 static bfd_boolean
22531 arm_parse_eabi (char * str)
22532 {
22533 const struct arm_option_value_table *opt;
22534
22535 for (opt = arm_eabis; opt->name != NULL; opt++)
22536 if (streq (opt->name, str))
22537 {
22538 meabi_flags = opt->value;
22539 return TRUE;
22540 }
22541 as_bad (_("unknown EABI `%s'\n"), str);
22542 return FALSE;
22543 }
22544 #endif
22545
22546 static bfd_boolean
22547 arm_parse_it_mode (char * str)
22548 {
22549 bfd_boolean ret = TRUE;
22550
22551 if (streq ("arm", str))
22552 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22553 else if (streq ("thumb", str))
22554 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22555 else if (streq ("always", str))
22556 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22557 else if (streq ("never", str))
22558 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22559 else
22560 {
22561 as_bad (_("unknown implicit IT mode `%s', should be "\
22562 "arm, thumb, always, or never."), str);
22563 ret = FALSE;
22564 }
22565
22566 return ret;
22567 }
22568
22569 struct arm_long_option_table arm_long_opts[] =
22570 {
22571 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22572 arm_parse_cpu, NULL},
22573 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22574 arm_parse_arch, NULL},
22575 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22576 arm_parse_fpu, NULL},
22577 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22578 arm_parse_float_abi, NULL},
22579 #ifdef OBJ_ELF
22580 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
22581 arm_parse_eabi, NULL},
22582 #endif
22583 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22584 arm_parse_it_mode, NULL},
22585 {NULL, NULL, 0, NULL}
22586 };
22587
22588 int
22589 md_parse_option (int c, char * arg)
22590 {
22591 struct arm_option_table *opt;
22592 const struct arm_legacy_option_table *fopt;
22593 struct arm_long_option_table *lopt;
22594
22595 switch (c)
22596 {
22597 #ifdef OPTION_EB
22598 case OPTION_EB:
22599 target_big_endian = 1;
22600 break;
22601 #endif
22602
22603 #ifdef OPTION_EL
22604 case OPTION_EL:
22605 target_big_endian = 0;
22606 break;
22607 #endif
22608
22609 case OPTION_FIX_V4BX:
22610 fix_v4bx = TRUE;
22611 break;
22612
22613 case 'a':
22614 /* Listing option. Just ignore these, we don't support additional
22615 ones. */
22616 return 0;
22617
22618 default:
22619 for (opt = arm_opts; opt->option != NULL; opt++)
22620 {
22621 if (c == opt->option[0]
22622 && ((arg == NULL && opt->option[1] == 0)
22623 || streq (arg, opt->option + 1)))
22624 {
22625 /* If the option is deprecated, tell the user. */
22626 if (warn_on_deprecated && opt->deprecated != NULL)
22627 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22628 arg ? arg : "", _(opt->deprecated));
22629
22630 if (opt->var != NULL)
22631 *opt->var = opt->value;
22632
22633 return 1;
22634 }
22635 }
22636
22637 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22638 {
22639 if (c == fopt->option[0]
22640 && ((arg == NULL && fopt->option[1] == 0)
22641 || streq (arg, fopt->option + 1)))
22642 {
22643 /* If the option is deprecated, tell the user. */
22644 if (warn_on_deprecated && fopt->deprecated != NULL)
22645 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22646 arg ? arg : "", _(fopt->deprecated));
22647
22648 if (fopt->var != NULL)
22649 *fopt->var = &fopt->value;
22650
22651 return 1;
22652 }
22653 }
22654
22655 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22656 {
22657 /* These options are expected to have an argument. */
22658 if (c == lopt->option[0]
22659 && arg != NULL
22660 && strncmp (arg, lopt->option + 1,
22661 strlen (lopt->option + 1)) == 0)
22662 {
22663 /* If the option is deprecated, tell the user. */
22664 if (warn_on_deprecated && lopt->deprecated != NULL)
22665 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22666 _(lopt->deprecated));
22667
22668 /* Call the sup-option parser. */
22669 return lopt->func (arg + strlen (lopt->option) - 1);
22670 }
22671 }
22672
22673 return 0;
22674 }
22675
22676 return 1;
22677 }
22678
22679 void
22680 md_show_usage (FILE * fp)
22681 {
22682 struct arm_option_table *opt;
22683 struct arm_long_option_table *lopt;
22684
22685 fprintf (fp, _(" ARM-specific assembler options:\n"));
22686
22687 for (opt = arm_opts; opt->option != NULL; opt++)
22688 if (opt->help != NULL)
22689 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
22690
22691 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22692 if (lopt->help != NULL)
22693 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
22694
22695 #ifdef OPTION_EB
22696 fprintf (fp, _("\
22697 -EB assemble code for a big-endian cpu\n"));
22698 #endif
22699
22700 #ifdef OPTION_EL
22701 fprintf (fp, _("\
22702 -EL assemble code for a little-endian cpu\n"));
22703 #endif
22704
22705 fprintf (fp, _("\
22706 --fix-v4bx Allow BX in ARMv4 code\n"));
22707 }
22708
22709
22710 #ifdef OBJ_ELF
22711 typedef struct
22712 {
22713 int val;
22714 arm_feature_set flags;
22715 } cpu_arch_ver_table;
22716
22717 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22718 least features first. */
22719 static const cpu_arch_ver_table cpu_arch_ver[] =
22720 {
22721 {1, ARM_ARCH_V4},
22722 {2, ARM_ARCH_V4T},
22723 {3, ARM_ARCH_V5},
22724 {3, ARM_ARCH_V5T},
22725 {4, ARM_ARCH_V5TE},
22726 {5, ARM_ARCH_V5TEJ},
22727 {6, ARM_ARCH_V6},
22728 {7, ARM_ARCH_V6Z},
22729 {9, ARM_ARCH_V6K},
22730 {11, ARM_ARCH_V6M},
22731 {8, ARM_ARCH_V6T2},
22732 {10, ARM_ARCH_V7A},
22733 {10, ARM_ARCH_V7R},
22734 {10, ARM_ARCH_V7M},
22735 {0, ARM_ARCH_NONE}
22736 };
22737
22738 /* Set an attribute if it has not already been set by the user. */
22739 static void
22740 aeabi_set_attribute_int (int tag, int value)
22741 {
22742 if (tag < 1
22743 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22744 || !attributes_set_explicitly[tag])
22745 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22746 }
22747
22748 static void
22749 aeabi_set_attribute_string (int tag, const char *value)
22750 {
22751 if (tag < 1
22752 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22753 || !attributes_set_explicitly[tag])
22754 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22755 }
22756
22757 /* Set the public EABI object attributes. */
22758 static void
22759 aeabi_set_public_attributes (void)
22760 {
22761 int arch;
22762 arm_feature_set flags;
22763 arm_feature_set tmp;
22764 const cpu_arch_ver_table *p;
22765
22766 /* Choose the architecture based on the capabilities of the requested cpu
22767 (if any) and/or the instructions actually used. */
22768 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22769 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22770 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
22771 /*Allow the user to override the reported architecture. */
22772 if (object_arch)
22773 {
22774 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22775 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22776 }
22777
22778 tmp = flags;
22779 arch = 0;
22780 for (p = cpu_arch_ver; p->val; p++)
22781 {
22782 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22783 {
22784 arch = p->val;
22785 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22786 }
22787 }
22788
22789 /* The table lookup above finds the last architecture to contribute
22790 a new feature. Unfortunately, Tag13 is a subset of the union of
22791 v6T2 and v7-M, so it is never seen as contributing a new feature.
22792 We can not search for the last entry which is entirely used,
22793 because if no CPU is specified we build up only those flags
22794 actually used. Perhaps we should separate out the specified
22795 and implicit cases. Avoid taking this path for -march=all by
22796 checking for contradictory v7-A / v7-M features. */
22797 if (arch == 10
22798 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22799 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22800 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22801 arch = 13;
22802
22803 /* Tag_CPU_name. */
22804 if (selected_cpu_name[0])
22805 {
22806 char *q;
22807
22808 q = selected_cpu_name;
22809 if (strncmp (q, "armv", 4) == 0)
22810 {
22811 int i;
22812
22813 q += 4;
22814 for (i = 0; q[i]; i++)
22815 q[i] = TOUPPER (q[i]);
22816 }
22817 aeabi_set_attribute_string (Tag_CPU_name, q);
22818 }
22819
22820 /* Tag_CPU_arch. */
22821 aeabi_set_attribute_int (Tag_CPU_arch, arch);
22822
22823 /* Tag_CPU_arch_profile. */
22824 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
22825 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
22826 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
22827 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
22828 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
22829 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
22830
22831 /* Tag_ARM_ISA_use. */
22832 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22833 || arch == 0)
22834 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
22835
22836 /* Tag_THUMB_ISA_use. */
22837 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22838 || arch == 0)
22839 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22840 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
22841
22842 /* Tag_VFP_arch. */
22843 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22844 aeabi_set_attribute_int (Tag_VFP_arch,
22845 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22846 ? 5 : 6);
22847 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
22848 aeabi_set_attribute_int (Tag_VFP_arch, 3);
22849 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
22850 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22851 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22852 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22853 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22854 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22855 aeabi_set_attribute_int (Tag_VFP_arch, 1);
22856
22857 /* Tag_ABI_HardFP_use. */
22858 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd)
22859 && !ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1))
22860 aeabi_set_attribute_int (Tag_ABI_HardFP_use, 1);
22861
22862 /* Tag_WMMX_arch. */
22863 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22864 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22865 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22866 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
22867
22868 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
22869 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
22870 aeabi_set_attribute_int
22871 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22872 ? 2 : 1));
22873
22874 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
22875 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
22876 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
22877
22878 /* Tag_DIV_use. */
22879 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_div))
22880 aeabi_set_attribute_int (Tag_DIV_use, 0);
22881 /* Fill this in when gas supports v7a sdiv/udiv.
22882 else if (... v7a with div extension used ...)
22883 aeabi_set_attribute_int (Tag_DIV_use, 2); */
22884 else
22885 aeabi_set_attribute_int (Tag_DIV_use, 1);
22886 }
22887
22888 /* Add the default contents for the .ARM.attributes section. */
22889 void
22890 arm_md_end (void)
22891 {
22892 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22893 return;
22894
22895 aeabi_set_public_attributes ();
22896 }
22897 #endif /* OBJ_ELF */
22898
22899
22900 /* Parse a .cpu directive. */
22901
22902 static void
22903 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22904 {
22905 const struct arm_cpu_option_table *opt;
22906 char *name;
22907 char saved_char;
22908
22909 name = input_line_pointer;
22910 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22911 input_line_pointer++;
22912 saved_char = *input_line_pointer;
22913 *input_line_pointer = 0;
22914
22915 /* Skip the first "all" entry. */
22916 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22917 if (streq (opt->name, name))
22918 {
22919 mcpu_cpu_opt = &opt->value;
22920 selected_cpu = opt->value;
22921 if (opt->canonical_name)
22922 strcpy (selected_cpu_name, opt->canonical_name);
22923 else
22924 {
22925 int i;
22926 for (i = 0; opt->name[i]; i++)
22927 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22928 selected_cpu_name[i] = 0;
22929 }
22930 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22931 *input_line_pointer = saved_char;
22932 demand_empty_rest_of_line ();
22933 return;
22934 }
22935 as_bad (_("unknown cpu `%s'"), name);
22936 *input_line_pointer = saved_char;
22937 ignore_rest_of_line ();
22938 }
22939
22940
22941 /* Parse a .arch directive. */
22942
22943 static void
22944 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22945 {
22946 const struct arm_arch_option_table *opt;
22947 char saved_char;
22948 char *name;
22949
22950 name = input_line_pointer;
22951 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22952 input_line_pointer++;
22953 saved_char = *input_line_pointer;
22954 *input_line_pointer = 0;
22955
22956 /* Skip the first "all" entry. */
22957 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22958 if (streq (opt->name, name))
22959 {
22960 mcpu_cpu_opt = &opt->value;
22961 selected_cpu = opt->value;
22962 strcpy (selected_cpu_name, opt->name);
22963 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22964 *input_line_pointer = saved_char;
22965 demand_empty_rest_of_line ();
22966 return;
22967 }
22968
22969 as_bad (_("unknown architecture `%s'\n"), name);
22970 *input_line_pointer = saved_char;
22971 ignore_rest_of_line ();
22972 }
22973
22974
22975 /* Parse a .object_arch directive. */
22976
22977 static void
22978 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22979 {
22980 const struct arm_arch_option_table *opt;
22981 char saved_char;
22982 char *name;
22983
22984 name = input_line_pointer;
22985 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22986 input_line_pointer++;
22987 saved_char = *input_line_pointer;
22988 *input_line_pointer = 0;
22989
22990 /* Skip the first "all" entry. */
22991 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22992 if (streq (opt->name, name))
22993 {
22994 object_arch = &opt->value;
22995 *input_line_pointer = saved_char;
22996 demand_empty_rest_of_line ();
22997 return;
22998 }
22999
23000 as_bad (_("unknown architecture `%s'\n"), name);
23001 *input_line_pointer = saved_char;
23002 ignore_rest_of_line ();
23003 }
23004
23005 /* Parse a .fpu directive. */
23006
23007 static void
23008 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
23009 {
23010 const struct arm_option_cpu_value_table *opt;
23011 char saved_char;
23012 char *name;
23013
23014 name = input_line_pointer;
23015 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
23016 input_line_pointer++;
23017 saved_char = *input_line_pointer;
23018 *input_line_pointer = 0;
23019
23020 for (opt = arm_fpus; opt->name != NULL; opt++)
23021 if (streq (opt->name, name))
23022 {
23023 mfpu_opt = &opt->value;
23024 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
23025 *input_line_pointer = saved_char;
23026 demand_empty_rest_of_line ();
23027 return;
23028 }
23029
23030 as_bad (_("unknown floating point format `%s'\n"), name);
23031 *input_line_pointer = saved_char;
23032 ignore_rest_of_line ();
23033 }
23034
23035 /* Copy symbol information. */
23036
23037 void
23038 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
23039 {
23040 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
23041 }
23042
23043 #ifdef OBJ_ELF
23044 /* Given a symbolic attribute NAME, return the proper integer value.
23045 Returns -1 if the attribute is not known. */
23046
23047 int
23048 arm_convert_symbolic_attribute (const char *name)
23049 {
23050 static const struct
23051 {
23052 const char * name;
23053 const int tag;
23054 }
23055 attribute_table[] =
23056 {
23057 /* When you modify this table you should
23058 also modify the list in doc/c-arm.texi. */
23059 #define T(tag) {#tag, tag}
23060 T (Tag_CPU_raw_name),
23061 T (Tag_CPU_name),
23062 T (Tag_CPU_arch),
23063 T (Tag_CPU_arch_profile),
23064 T (Tag_ARM_ISA_use),
23065 T (Tag_THUMB_ISA_use),
23066 T (Tag_FP_arch),
23067 T (Tag_VFP_arch),
23068 T (Tag_WMMX_arch),
23069 T (Tag_Advanced_SIMD_arch),
23070 T (Tag_PCS_config),
23071 T (Tag_ABI_PCS_R9_use),
23072 T (Tag_ABI_PCS_RW_data),
23073 T (Tag_ABI_PCS_RO_data),
23074 T (Tag_ABI_PCS_GOT_use),
23075 T (Tag_ABI_PCS_wchar_t),
23076 T (Tag_ABI_FP_rounding),
23077 T (Tag_ABI_FP_denormal),
23078 T (Tag_ABI_FP_exceptions),
23079 T (Tag_ABI_FP_user_exceptions),
23080 T (Tag_ABI_FP_number_model),
23081 T (Tag_ABI_align_needed),
23082 T (Tag_ABI_align8_needed),
23083 T (Tag_ABI_align_preserved),
23084 T (Tag_ABI_align8_preserved),
23085 T (Tag_ABI_enum_size),
23086 T (Tag_ABI_HardFP_use),
23087 T (Tag_ABI_VFP_args),
23088 T (Tag_ABI_WMMX_args),
23089 T (Tag_ABI_optimization_goals),
23090 T (Tag_ABI_FP_optimization_goals),
23091 T (Tag_compatibility),
23092 T (Tag_CPU_unaligned_access),
23093 T (Tag_FP_HP_extension),
23094 T (Tag_VFP_HP_extension),
23095 T (Tag_ABI_FP_16bit_format),
23096 T (Tag_MPextension_use),
23097 T (Tag_DIV_use),
23098 T (Tag_nodefaults),
23099 T (Tag_also_compatible_with),
23100 T (Tag_conformance),
23101 T (Tag_T2EE_use),
23102 T (Tag_Virtualization_use),
23103 /* We deliberately do not include Tag_MPextension_use_legacy. */
23104 #undef T
23105 };
23106 unsigned int i;
23107
23108 if (name == NULL)
23109 return -1;
23110
23111 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
23112 if (streq (name, attribute_table[i].name))
23113 return attribute_table[i].tag;
23114
23115 return -1;
23116 }
23117
23118
23119 /* Apply sym value for relocations only in the case that
23120 they are for local symbols and you have the respective
23121 architectural feature for blx and simple switches. */
23122 int
23123 arm_apply_sym_value (struct fix * fixP)
23124 {
23125 if (fixP->fx_addsy
23126 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
23127 && !S_IS_EXTERNAL (fixP->fx_addsy))
23128 {
23129 switch (fixP->fx_r_type)
23130 {
23131 case BFD_RELOC_ARM_PCREL_BLX:
23132 case BFD_RELOC_THUMB_PCREL_BRANCH23:
23133 if (ARM_IS_FUNC (fixP->fx_addsy))
23134 return 1;
23135 break;
23136
23137 case BFD_RELOC_ARM_PCREL_CALL:
23138 case BFD_RELOC_THUMB_PCREL_BLX:
23139 if (THUMB_IS_FUNC (fixP->fx_addsy))
23140 return 1;
23141 break;
23142
23143 default:
23144 break;
23145 }
23146
23147 }
23148 return 0;
23149 }
23150 #endif /* OBJ_ELF */
This page took 0.532978 seconds and 5 git commands to generate.